1
+ "use strict" ;
2
+
3
+ Object . defineProperty ( exports , "__esModule" , {
4
+ value : true
5
+ } ) ;
6
+ exports . default = void 0 ;
7
+
8
+ function _objectSpread ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] != null ? arguments [ i ] : { } ; var ownKeys = Object . keys ( source ) ; if ( typeof Object . getOwnPropertySymbols === 'function' ) { ownKeys = ownKeys . concat ( Object . getOwnPropertySymbols ( source ) . filter ( function ( sym ) { return Object . getOwnPropertyDescriptor ( source , sym ) . enumerable ; } ) ) ; } ownKeys . forEach ( function ( key ) { _defineProperty ( target , key , source [ key ] ) ; } ) ; } return target ; }
9
+
10
+ function _defineProperty ( obj , key , value ) { if ( key in obj ) { Object . defineProperty ( obj , key , { value : value , enumerable : true , configurable : true , writable : true } ) ; } else { obj [ key ] = value ; } return obj ; }
11
+
12
+ const importPattern = / ^ : i m p o r t \( ( " [ ^ " ] * " | ' [ ^ ' ] * ' ) (?: \s ( .+ ) ) ? \) $ / ;
13
+
14
+ const getDeclsObject = rule => {
15
+ const object = { } ;
16
+ rule . walkDecls ( decl => {
17
+ object [ decl . raws . before . trim ( ) + decl . prop ] = decl . value ;
18
+ } ) ;
19
+ return object ;
20
+ } ;
21
+
22
+ const extractICSS = ( css , removeRules = true ) => {
23
+ const icssImports = { } ;
24
+ const icssExports = { } ;
25
+ css . each ( node => {
26
+ if ( node . type === "rule" ) {
27
+ if ( node . selector . slice ( 0 , 7 ) === ":import" ) {
28
+ const matches = importPattern . exec ( node . selector ) ;
29
+
30
+ if ( matches ) {
31
+ const path = matches [ 1 ] . replace ( / ' | " / g, "" ) ;
32
+ const extra = matches [ 2 ] ? matches [ 2 ] : "" ;
33
+ const dep = `"${ path } "${ extra ? ` ${ extra } ` : "" } ` ;
34
+ icssImports [ dep ] = Object . assign ( icssImports [ dep ] || { } , _objectSpread ( {
35
+ path
36
+ } , extra ? {
37
+ extra
38
+ } : { } , {
39
+ tokens : Object . assign ( icssImports [ dep ] ? icssImports [ dep ] . tokens : { } , getDeclsObject ( node ) )
40
+ } ) ) ;
41
+
42
+ if ( removeRules ) {
43
+ node . remove ( ) ;
44
+ }
45
+ }
46
+ }
47
+
48
+ if ( node . selector === ":export" ) {
49
+ Object . assign ( icssExports , getDeclsObject ( node ) ) ;
50
+
51
+ if ( removeRules ) {
52
+ node . remove ( ) ;
53
+ }
54
+ }
55
+ }
56
+ } ) ;
57
+ return {
58
+ icssImports,
59
+ icssExports
60
+ } ;
61
+ } ;
62
+
63
+ var _default = extractICSS ;
64
+ exports . default = _default ;
0 commit comments