aliascss 1.4.4 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/aliascss.config.js +32 -32
- package/dist/aliascss.js +1 -1
- package/lib/compilers/color.js +5 -5
- package/lib/compilers/gradient.js +3 -3
- package/lib/compilers/stringAndContent.js +2 -1
- package/lib/component-elements.d.ts +155 -0
- package/lib/component-elements.js +223 -0
- package/lib/config.d.ts +1 -0
- package/lib/config.js +2 -1
- package/lib/css-properties-all.js +337 -202
- package/lib/custom-css-compilers.js +54 -54
- package/lib/extras-elements.d.ts +87 -0
- package/lib/extras-elements.js +184 -0
- package/lib/form-elements.d.ts +75 -0
- package/lib/form-elements.js +186 -0
- package/lib/layout-elements.d.ts +59 -0
- package/lib/layout-elements.js +113 -0
- package/lib/nav-elements.d.ts +71 -0
- package/lib/nav-elements.js +243 -0
- package/lib/node/compileFile-bk.d.ts +27 -0
- package/lib/node/compileFile-bk.js +379 -0
- package/lib/node/compileFile.d.ts +11 -11
- package/lib/node/compileFile.js +170 -235
- package/lib/prebuild.d.ts +520 -12
- package/lib/prebuild.js +9 -852
- package/lib/prefix/PseudoPrefixNew.js +301 -16
- package/lib/prefix/attribute-selector.js +4 -2
- package/lib/prefix/pseudoSelectorNew.js +184 -49
- package/lib/prefix/responsive.d.ts +13 -9
- package/lib/prefix/responsive.js +131 -9
- package/lib/returnPropertyAndValue.js +9 -4
- package/lib/returnStatement-bk.d.ts +5 -0
- package/lib/returnStatement-bk.js +311 -0
- package/lib/returnStatement.js +165 -2
- package/lib/static/customStaticClassNames.js +35 -35
- package/lib/static/staticClassNamesAlias.js +18 -16
- package/lib/table-elements.d.ts +39 -0
- package/lib/table-elements.js +90 -0
- package/lib/utils/helper.d.ts +6 -0
- package/lib/utils/helper.js +52 -0
- package/lib/x-classes/x-bundle.d.ts +563 -0
- package/lib/x-classes/x-bundle.js +11 -0
- package/lib/x-classes/x-comps.d.ts +87 -0
- package/lib/x-classes/x-comps.js +189 -0
- package/lib/x-classes/x-extras.d.ts +155 -0
- package/lib/x-classes/x-extras.js +223 -0
- package/lib/x-classes/x-form-components.d.ts +75 -0
- package/lib/x-classes/x-form-components.js +186 -0
- package/lib/x-classes/x-helper-components.d.ts +63 -0
- package/lib/x-classes/x-helper-components.js +91 -0
- package/lib/x-classes/x-layout-components.d.ts +59 -0
- package/lib/x-classes/x-layout-components.js +113 -0
- package/lib/x-classes/x-menu.d.ts +23 -0
- package/lib/x-classes/x-menu.js +55 -0
- package/lib/x-classes/x-navs.d.ts +71 -0
- package/lib/x-classes/x-navs.js +243 -0
- package/lib/x-classes/x-table.d.ts +39 -0
- package/lib/x-classes/x-table.js +90 -0
- package/lib/x-classes/x-theme.d.ts +15 -0
- package/lib/x-classes/x-theme.js +32 -0
- package/lib/x-imports.d.ts +31 -0
- package/lib/x-imports.js +748 -0
- package/package.json +1 -1
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// AliasCSS navigation + content components
|
|
2
|
+
// tabs, breadcrumb, pagination, dropdown, prose, kbd, code
|
|
3
|
+
// ------------------------------------------------------------------
|
|
4
|
+
// Same conventions: @components layer, --x-* variables with token
|
|
5
|
+
// fallbacks, plain utilities override everything.
|
|
6
|
+
// ------------------------------------------------------------------
|
|
7
|
+
const focusRing = `outline-style-solid,outline-width-2px,outline-color--x-form-accent-color:primary600,outline-offset-2px`;
|
|
8
|
+
const mono = `ff-ui-monospace__SFMono-Regular__Menlo__Consolas__monospace`;
|
|
9
|
+
const navContent = {
|
|
10
|
+
// ================================================================
|
|
11
|
+
// TABS (styles for the ARIA tabs pattern; switching needs a few lines of JS)
|
|
12
|
+
// <div role="tablist" class="x-tab-list" aria-label="Settings">
|
|
13
|
+
// <button role="tab" class="x-tab" aria-selected="true" aria-controls="p1" id="t1">Profile</button>
|
|
14
|
+
// <button role="tab" class="x-tab" aria-selected="false" aria-controls="p2" id="t2" tabindex="-1">Billing</button>
|
|
15
|
+
// </div>
|
|
16
|
+
// <div role="tabpanel" class="x-tab-panel" id="p1" aria-labelledby="t1">…</div>
|
|
17
|
+
// <div role="tabpanel" class="x-tab-panel" id="p2" aria-labelledby="t2" hidden>…</div>
|
|
18
|
+
//
|
|
19
|
+
// Variant: x-tab-list-pills (segmented control look)
|
|
20
|
+
// vars: --x-tab-gap, --x-tab-height, --x-tab-padding, --x-tab-radius, --x-tab-color,
|
|
21
|
+
// --x-tab-hover-color, --x-tab-selected-color, --x-tab-selected-bg,
|
|
22
|
+
// --x-tab-indicator-color, --x-tab-border-color
|
|
23
|
+
// ================================================================
|
|
24
|
+
'x-tab-list': {
|
|
25
|
+
type: 'statement',
|
|
26
|
+
statement: `@components[d-flex,g--x-tab-gap:20px,overflow-x-auto,scrollbar-width(none),box-shadow(inset_0_-1px_0_var(--x-tab-border-color,#EAECF0))]`
|
|
27
|
+
},
|
|
28
|
+
'x-tab': {
|
|
29
|
+
type: 'statement',
|
|
30
|
+
statement: `
|
|
31
|
+
@base-all-unset
|
|
32
|
+
@components[position-relative,d-inline-flex,aic,jcc,g-6px,flex-shrink-0,h--x-tab-height:40px,padding-inline--x-tab-padding:4px,box-sizing-border-box,br--x-tab-radius:0px,fs-14px,fw-500,white-space-nowrap,cursor-pointer,c--x-tab-color:gray500,bgc--x-tab-bg:transparent,transition-property-color__background-color__box-shadow,transition-duration-0.15s]
|
|
33
|
+
@components--after[cont,position-absolute,l-0,r-0,btm-0,h-2px,br-2px,bgc-transparent,transition-property-background-color,transition-duration-0.15s]
|
|
34
|
+
@components--hover-c--x-tab-hover-color:gray700
|
|
35
|
+
@components-[aria-selected=true][c--x-tab-selected-color:gray900,bgc--x-tab-selected-bg:transparent,box-shadow(var(--x-tab-selected-shadow,none))]
|
|
36
|
+
@components-[aria-selected=true]--after-bgc--x-tab-indicator-color:primary600
|
|
37
|
+
@components--focus-visible[${focusRing},outline-offset--2px]
|
|
38
|
+
@components--disabled[o-0.5,cursor-not-allowed]
|
|
39
|
+
`
|
|
40
|
+
},
|
|
41
|
+
'x-tab-panel': {
|
|
42
|
+
type: 'statement',
|
|
43
|
+
statement: `
|
|
44
|
+
@components[padding-block-16px]
|
|
45
|
+
@components--focus-visible[${focusRing},br-6px]
|
|
46
|
+
`
|
|
47
|
+
},
|
|
48
|
+
'x-tab-list-pills': {
|
|
49
|
+
type: 'statement',
|
|
50
|
+
statement: `
|
|
51
|
+
--x-tab-gap:4px
|
|
52
|
+
--x-tab-height:32px
|
|
53
|
+
--x-tab-padding:12px
|
|
54
|
+
--x-tab-radius:8px
|
|
55
|
+
--x-tab-selected-bg:white
|
|
56
|
+
--x-tab-indicator-color:transparent
|
|
57
|
+
--x-tab-selected-shadow:(0_1px_3px_rgb(16_24_40_/_0.12))
|
|
58
|
+
@components-[class][d-inline-flex,p-4px,br-10px,bgc--x-tab-list-bg:gray100,box-shadow(none)]
|
|
59
|
+
`
|
|
60
|
+
},
|
|
61
|
+
// ================================================================
|
|
62
|
+
// BREADCRUMB
|
|
63
|
+
// <nav aria-label="Breadcrumb">
|
|
64
|
+
// <ol class="x-breadcrumb">
|
|
65
|
+
// <li><a href="/">Home</a></li>
|
|
66
|
+
// <li><a href="/docs">Docs</a></li>
|
|
67
|
+
// <li><span aria-current="page">Tabs</span></li>
|
|
68
|
+
// </ol>
|
|
69
|
+
// </nav>
|
|
70
|
+
// vars: --x-breadcrumb-color, --x-breadcrumb-hover-color, --x-breadcrumb-current-color
|
|
71
|
+
// ================================================================
|
|
72
|
+
'x-breadcrumb': {
|
|
73
|
+
type: 'statement',
|
|
74
|
+
statement: `
|
|
75
|
+
@components[d-flex,flex-wrap-wrap,aic,g-8px,list-style-none,m-0,p-0,fs-14px,lh-20px,c--x-breadcrumb-color:gray500]
|
|
76
|
+
@components__li[d-inline-flex,aic,g-8px]
|
|
77
|
+
@components__li--not(--first-child)--before[cont,w-6px,h-6px,box-sizing-border-box,border-style-solid,border-color-currentColor,border-width-1.5px-1.5px-0px-0px,tf-rotate-45deg,o-0.6]
|
|
78
|
+
@components_a[c-inherit,td-none,br-4px]
|
|
79
|
+
@components_a--hover[c--x-breadcrumb-hover-color:gray900,td-underline]
|
|
80
|
+
@components_a--focus-visible[${focusRing}]
|
|
81
|
+
@components_all[aria-current=page][c--x-breadcrumb-current-color:gray900,fw-500]
|
|
82
|
+
`
|
|
83
|
+
},
|
|
84
|
+
// ================================================================
|
|
85
|
+
// PAGINATION
|
|
86
|
+
// <nav aria-label="Pagination">
|
|
87
|
+
// <ul class="x-pagination">
|
|
88
|
+
// <li><a href="?p=1" aria-label="Previous page">‹</a></li>
|
|
89
|
+
// <li><a href="?p=1">1</a></li>
|
|
90
|
+
// <li><a href="?p=2" aria-current="page">2</a></li>
|
|
91
|
+
// <li><span>…</span></li>
|
|
92
|
+
// <li><a href="?p=3" aria-label="Next page">›</a></li>
|
|
93
|
+
// </ul>
|
|
94
|
+
// </nav>
|
|
95
|
+
// Works with <a> or <button> inside each <li>. Disable with aria-disabled="true".
|
|
96
|
+
// vars: --x-pagination-size (36px), --x-pagination-radius, --x-pagination-color,
|
|
97
|
+
// --x-pagination-hover-bg, --x-pagination-current-color, --x-form-accent-color
|
|
98
|
+
// ================================================================
|
|
99
|
+
'x-pagination': {
|
|
100
|
+
type: 'statement',
|
|
101
|
+
statement: `
|
|
102
|
+
@components[d-flex,flex-wrap-wrap,aic,g-4px,list-style-none,m-0,p-0]
|
|
103
|
+
@base_button-all-unset
|
|
104
|
+
@components_li__all[d-inline-flex,aic,jcc,mw--x-pagination-size:36px,h--x-pagination-size:36px,padding-inline-8px,box-sizing-border-box,br--x-pagination-radius:8px,fs-14px,fw-500,c--x-pagination-color:gray600,td-none,transition-property-background-color__color,transition-duration-0.15s]
|
|
105
|
+
@components_a--hover-bgc--x-pagination-hover-bg:gray100
|
|
106
|
+
@components_button--hover-bgc--x-pagination-hover-bg:gray100
|
|
107
|
+
@components_button-cursor-pointer
|
|
108
|
+
@components_li__all--focus-visible[${focusRing}]
|
|
109
|
+
@components_all[aria-current=page][bgc--x-form-accent-color:primary600,c--x-pagination-current-color:white]
|
|
110
|
+
@components_all[aria-disabled=true][o-0.4,pointer-events-none]
|
|
111
|
+
`
|
|
112
|
+
},
|
|
113
|
+
// ================================================================
|
|
114
|
+
// DROPDOWN (native popover)
|
|
115
|
+
// <button class="x-button x-button-secondary" popovertarget="menu1">Options</button>
|
|
116
|
+
// <div id="menu1" popover class="x-dropdown">
|
|
117
|
+
// <p class="x-dropdown-label">Project</p>
|
|
118
|
+
// <button class="x-dropdown-item">Rename</button>
|
|
119
|
+
// <a class="x-dropdown-item" href="#">Open in new tab</a>
|
|
120
|
+
// <hr class="x-dropdown-divider">
|
|
121
|
+
// <button class="x-dropdown-item x-dropdown-item-danger">Delete</button>
|
|
122
|
+
// </div>
|
|
123
|
+
// Opens/closes with no JS (click outside or Esc closes it). Positioned under the
|
|
124
|
+
// button with anchor positioning (position-area + position-try-fallbacks) where
|
|
125
|
+
// supported; elsewhere the browser shows it centered.
|
|
126
|
+
// vars: --x-dropdown-min-width (180px), --x-dropdown-bg, --x-dropdown-color,
|
|
127
|
+
// --x-dropdown-border-color, --x-dropdown-radius, --x-dropdown-hover-bg
|
|
128
|
+
// ================================================================
|
|
129
|
+
'x-dropdown': {
|
|
130
|
+
type: 'statement',
|
|
131
|
+
statement: `
|
|
132
|
+
@components[m-0,inset-auto,margin-top-4px,position-area(bottom_span-right),position-try-fallbacks(flip-block),mw--x-dropdown-min-width:180px,p-4px,box-sizing-border-box,bgc--x-dropdown-bg:white,c--x-dropdown-color:gray700,border-width-1px,border-style-solid,border-color--x-dropdown-border-color:gray200,br--x-dropdown-radius:10px,box-shadow(0_12px_24px_-6px_rgb(16_24_40_/_0.15))]
|
|
133
|
+
@components[o-0,transform(translateY(-4px)),transition-property-opacity__transform__display__overlay,transition-duration-0.15s,transition-timing-function-ease-out,transition-behavior-allow-discrete]
|
|
134
|
+
@components--popover-open[o-1,tf-none]
|
|
135
|
+
@[components,starting-style]--popover-open[o-0,transform(translateY(-4px))]
|
|
136
|
+
@motion-reduce-transition-duration-0s
|
|
137
|
+
`
|
|
138
|
+
},
|
|
139
|
+
'x-dropdown-item': {
|
|
140
|
+
type: 'statement',
|
|
141
|
+
statement: `
|
|
142
|
+
@base-all-unset
|
|
143
|
+
@components[d-flex,aic,g-8px,w-100%,box-sizing-border-box,padding(8px_10px),br-6px,fs-14px,lh-20px,c-inherit,text-align-left,cursor-pointer]
|
|
144
|
+
@components--hover-bgc--x-dropdown-hover-bg:gray100
|
|
145
|
+
@components--focus-visible[bgc--x-dropdown-hover-bg:gray100,outline-none]
|
|
146
|
+
@components--disabled[o-0.5,cursor-not-allowed]
|
|
147
|
+
@components-[aria-disabled=true][o-0.5,pointer-events-none]
|
|
148
|
+
`
|
|
149
|
+
},
|
|
150
|
+
'x-dropdown-item-danger': {
|
|
151
|
+
type: 'statement',
|
|
152
|
+
statement: `
|
|
153
|
+
--x-dropdown-hover-bg:error50
|
|
154
|
+
@components-[class]-c-error600
|
|
155
|
+
`
|
|
156
|
+
},
|
|
157
|
+
'x-dropdown-divider': {
|
|
158
|
+
type: 'statement',
|
|
159
|
+
statement: `
|
|
160
|
+
@base-all-unset
|
|
161
|
+
@components[d-block,h-1px,margin-block-4px,bgc--x-dropdown-border-color:gray200]
|
|
162
|
+
`
|
|
163
|
+
},
|
|
164
|
+
'x-dropdown-label': {
|
|
165
|
+
type: 'statement',
|
|
166
|
+
statement: `@components[m-0,padding(6px_10px_4px),fs-12px,fw-600,lh-16px,c--x-dropdown-label-color:gray500]`
|
|
167
|
+
},
|
|
168
|
+
// ================================================================
|
|
169
|
+
// PROSE (long-form content: blog posts, docs, CMS HTML)
|
|
170
|
+
// <article class="x-prose"> …plain HTML… </article>
|
|
171
|
+
// Sizes: x-prose-sm, x-prose-lg (everything scales in em)
|
|
172
|
+
// vars: --x-prose-font-size (16px), --x-prose-max (68ch), --x-prose-color,
|
|
173
|
+
// --x-prose-heading-color, --x-prose-link-color, --x-prose-muted-color,
|
|
174
|
+
// --x-prose-border-color, --x-prose-code-bg, --x-prose-pre-bg, --x-prose-pre-color
|
|
175
|
+
// ================================================================
|
|
176
|
+
'x-prose': {
|
|
177
|
+
type: 'statement',
|
|
178
|
+
statement: `
|
|
179
|
+
@components[xw--x-prose-max:68ch,fs--x-prose-font-size:16px,lh-1.75,c--x-prose-color:gray700]
|
|
180
|
+
|
|
181
|
+
@components_h1[margin(0_0_0.9em),fs-2.25em,fw-800,lh-1.15,les--0.02em,c--x-prose-heading-color:gray900]
|
|
182
|
+
@components_h2[margin(2em_0_0.8em),fs-1.5em,fw-700,lh-1.35,les--0.01em,c--x-prose-heading-color:gray900]
|
|
183
|
+
@components_h3[margin(1.6em_0_0.6em),fs-1.25em,fw-600,lh-1.5,c--x-prose-heading-color:gray900]
|
|
184
|
+
@components_h4[margin(1.5em_0_0.5em),fs-1em,fw-600,lh-1.5,c--x-prose-heading-color:gray900]
|
|
185
|
+
|
|
186
|
+
@components_p[margin-block-1.25em]
|
|
187
|
+
@components_a[c--x-prose-link-color:primary700,fw-500,td-underline,text-underline-offset-2px]
|
|
188
|
+
@components_a--hover-text-decoration-thickness-2px
|
|
189
|
+
@components_strong[fw-600,c--x-prose-heading-color:gray900]
|
|
190
|
+
|
|
191
|
+
@components_ul[margin-block-1.25em,padding-left-1.5em,list-style-type-disc]
|
|
192
|
+
@components_ol[margin-block-1.25em,padding-left-1.5em,list-style-type-decimal]
|
|
193
|
+
@components_li[margin-block-0.4em]
|
|
194
|
+
@components_li--marker-c--x-prose-muted-color:gray400
|
|
195
|
+
@components_li_ul[margin-block-0.4em]
|
|
196
|
+
@components_li_ol[margin-block-0.4em]
|
|
197
|
+
|
|
198
|
+
@components_blockquote[margin(1.6em_0),padding-left-1em,border-left-width-3px,border-left-style-solid,border-left-color--x-prose-border-color:gray200,font-style-italic,c--x-prose-muted-color:gray600]
|
|
199
|
+
|
|
200
|
+
@components_code[padding(0.15em_0.35em),br-4px,fs-0.875em,fw-600,c--x-prose-heading-color:gray900,bgc--x-prose-code-bg:gray100,${mono}]
|
|
201
|
+
@components_pre[margin(1.6em_0),padding(1em_1.25em),br-8px,overflow-x-auto,fs-0.875em,lh-1.7,bgc--x-prose-pre-bg:gray900,c--x-prose-pre-color:gray100,${mono}]
|
|
202
|
+
@components_pre_code[p-0,fs-inherit,fw-400,c-inherit,bgc-transparent]
|
|
203
|
+
|
|
204
|
+
@components_hr[margin(3em_0),border-width-0px,border-top-width-1px,border-top-style-solid,border-top-color--x-prose-border-color:gray200]
|
|
205
|
+
@components_img[d-block,xw-100%,h-auto,br-8px,margin(2em_0)]
|
|
206
|
+
@components_video[d-block,xw-100%,h-auto,br-8px,margin(2em_0)]
|
|
207
|
+
@components_figure[margin(2em_0)]
|
|
208
|
+
@components_figure_img[margin-block-0px]
|
|
209
|
+
@components_figcaption[margin-top-0.75em,fs-0.875em,c--x-prose-muted-color:gray500]
|
|
210
|
+
|
|
211
|
+
@components_table[w-100%,margin(2em_0),border-collapse-collapse,fs-0.875em]
|
|
212
|
+
@components_th[padding(0.6em_0.75em),text-align-left,fw-600,c--x-prose-heading-color:gray900,border-bottom-width-1px,border-bottom-style-solid,border-bottom-color--x-prose-border-color:gray300]
|
|
213
|
+
@components_td[padding(0.6em_0.75em),border-bottom-width-1px,border-bottom-style-solid,border-bottom-color--x-prose-border-color:gray200]
|
|
214
|
+
|
|
215
|
+
@components__all--first-child-margin-top-0px
|
|
216
|
+
@components__all--last-child-margin-bottom-0px
|
|
217
|
+
`
|
|
218
|
+
},
|
|
219
|
+
'x-prose-sm': { type: 'statement', statement: `--x-prose-font-size:14px` },
|
|
220
|
+
'x-prose-lg': { type: 'statement', statement: `--x-prose-font-size:18px` },
|
|
221
|
+
// ================================================================
|
|
222
|
+
// KBD + CODE
|
|
223
|
+
// Press <kbd class="x-kbd">Ctrl</kbd> + <kbd class="x-kbd">K</kbd>
|
|
224
|
+
// Use <code class="x-code">npm i aliascss</code> inline
|
|
225
|
+
// <pre class="x-code-block"><code>…</code></pre>
|
|
226
|
+
// ================================================================
|
|
227
|
+
'x-kbd': {
|
|
228
|
+
type: 'statement',
|
|
229
|
+
statement: `@components[d-inline-flex,aic,jcc,mw-1.75em,padding(0.1em_0.45em),box-sizing-border-box,br-6px,fs-0.8em,fw-500,lh-1.4,white-space-nowrap,vertical-align-baseline,${mono},c--x-kbd-color:gray700,bgc--x-kbd-bg:gray50,border-width-1px,border-style-solid,border-color--x-kbd-border-color:gray300,border-bottom-width-2px]`
|
|
230
|
+
},
|
|
231
|
+
'x-code': {
|
|
232
|
+
type: 'statement',
|
|
233
|
+
statement: `@components[padding(0.15em_0.35em),br-4px,fs-0.875em,${mono},c--x-code-color:gray900,bgc--x-code-bg:gray100,overflow-wrap-break-word]`
|
|
234
|
+
},
|
|
235
|
+
'x-code-block': {
|
|
236
|
+
type: 'statement',
|
|
237
|
+
statement: `
|
|
238
|
+
@components[d-block,m-0,padding(16px_20px),br--x-code-radius:10px,overflow-x-auto,white-space-pre,tab-size-2,fs-13px,lh-1.7,${mono},c--x-code-block-color:gray100,bgc--x-code-block-bg:gray900]
|
|
239
|
+
@components_code[p-0,fs-inherit,c-inherit,bgc-transparent]
|
|
240
|
+
`
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
export default navContent;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export default function main(config: {
|
|
2
|
+
['input']: string | string[];
|
|
3
|
+
[key: string]: any;
|
|
4
|
+
}): void;
|
|
5
|
+
export declare function globalCSSCompiler(): void;
|
|
6
|
+
export declare function compileFile(file: string, config: any, statementMaker: {
|
|
7
|
+
['make']: (a: string) => string;
|
|
8
|
+
group: (a: string, b: string) => string;
|
|
9
|
+
['rawCSS']?: string;
|
|
10
|
+
['customGroupStatement']?: string;
|
|
11
|
+
}, globalClassList: string[]): string[];
|
|
12
|
+
export declare function groupStatement(name: string, classNames: string, statementMaker: {
|
|
13
|
+
['group']: (a: string, b: string) => string;
|
|
14
|
+
}): string;
|
|
15
|
+
export declare function keyframesStatement(name: string, timeLine: string, statementMaker: {
|
|
16
|
+
['make']: (a: string, b?: string | null, c?: boolean) => string;
|
|
17
|
+
}): string;
|
|
18
|
+
export declare function createCSSFileByFile(file: string, bool?: boolean): void;
|
|
19
|
+
export declare function postify(file: string, plugin: any[], minify?: boolean, sort?: "mobile-first" | "desktop-first"): void;
|
|
20
|
+
export declare function writeStatementToFile(file: string, content: string, from?: string): void;
|
|
21
|
+
export declare function initialize(configFile: {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}): void;
|
|
24
|
+
export declare function watch(config: {
|
|
25
|
+
['input']: string | string[];
|
|
26
|
+
[key: string]: any;
|
|
27
|
+
}): void;
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import extractClassNamesFromFile from "./extractClassNamesFromFile.js";
|
|
2
|
+
import { compiler as statementMaker } from "../returnStatement.js";
|
|
3
|
+
import config from '../config.js';
|
|
4
|
+
import fs from "fs";
|
|
5
|
+
import fg from "fast-glob";
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import postcss from 'postcss';
|
|
8
|
+
import postcssDiscardDuplicates from 'postcss-discard-duplicates';
|
|
9
|
+
import cssnano from 'cssnano';
|
|
10
|
+
import chokidar from 'chokidar';
|
|
11
|
+
import sortMediaQueries from 'postcss-sort-media-queries';
|
|
12
|
+
import { splitByCommaOutsideParens } from '../utils/helper.js';
|
|
13
|
+
const init = {
|
|
14
|
+
classList: [], // hold className for MasterCSS to avoid repeating
|
|
15
|
+
groups: [],
|
|
16
|
+
input: '', // input glob pattern
|
|
17
|
+
output: '', // location off output
|
|
18
|
+
'--file': false, // if set true compileFileByFile to [filename].css
|
|
19
|
+
statementMaker,
|
|
20
|
+
config,
|
|
21
|
+
'--module': false,
|
|
22
|
+
rawCSS: '',
|
|
23
|
+
layers: [],
|
|
24
|
+
initializedLayer: false,
|
|
25
|
+
customGroupStatement: '',
|
|
26
|
+
minify: false,
|
|
27
|
+
globPattern: '', // Use this to check valid new created file to add to watch during watch.on
|
|
28
|
+
};
|
|
29
|
+
export default function main(config) {
|
|
30
|
+
// initialize
|
|
31
|
+
initialize(config);
|
|
32
|
+
if (init.config.prefix)
|
|
33
|
+
init.statementMaker.prefix = init.config.prefix;
|
|
34
|
+
if (init.input && (init.output || init['--file'])) {
|
|
35
|
+
const input = fg.sync(init.input, { dot: true });
|
|
36
|
+
// console.log(input);
|
|
37
|
+
input.forEach((file) => {
|
|
38
|
+
createCSSFileByFile(file);
|
|
39
|
+
});
|
|
40
|
+
postify(init.output, [postcssDiscardDuplicates], init.minify);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
console.error("Please Provide input, output or set '--file' to true");
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
export function globalCSSCompiler() {
|
|
47
|
+
const classList = [];
|
|
48
|
+
if (init.globPattern && init.output) {
|
|
49
|
+
fs.truncateSync(init.output);
|
|
50
|
+
// 1. Write @layer once at the top of the freshly truncated file
|
|
51
|
+
if (Array.isArray(init.layers) && init.layers.length > 0) {
|
|
52
|
+
fs.writeFileSync(init.output, `@layer ${init.layers.join(', ')};\n\n`, { flag: 'a+' });
|
|
53
|
+
init.initializedLayer = true;
|
|
54
|
+
}
|
|
55
|
+
const input = fg.sync(init.globPattern, { dot: true });
|
|
56
|
+
// console.log(input);
|
|
57
|
+
input.forEach((file) => {
|
|
58
|
+
const [gbContent,] = compileFile(file, config, statementMaker, classList);
|
|
59
|
+
try {
|
|
60
|
+
fs.writeFileSync(init.output, `/* Start :-----------ACSS ${path.relative('.', file)}------------------------*/\n${gbContent}
|
|
61
|
+
\n/* End :-----------ACSS ${path.relative('.', file)}----------------------------*/\n
|
|
62
|
+
`, { flag: 'a+' });
|
|
63
|
+
console.log('AliasCSS compiled', path.relative('.', file), 'to main css file :' + init.output);
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.log('\x1b[31m', "Couldn't able to append/create to main css file :" + init.output);
|
|
67
|
+
console.log(error);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
postify(init.output, [postcssDiscardDuplicates], init.minify);
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
console.error("Please Provide input, output or set '--file' to true");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export function compileFile(file, config, statementMaker, globalClassList) {
|
|
77
|
+
let [globalStatement, compiledStatement, moduleStatement] = ['', '', ''];
|
|
78
|
+
// inject config.group and config.statement
|
|
79
|
+
if (statementMaker.rawCSS) {
|
|
80
|
+
compiledStatement += `/* From:aliacss.config.statement */\n${statementMaker.rawCSS}\n/* -----End:aliacss.config.statement----- */\n\n`;
|
|
81
|
+
moduleStatement += `/* From:aliacss.config.statement */\n${statementMaker.rawCSS}\n/* ------End:aliacss.config.statement----- */\n\n`;
|
|
82
|
+
}
|
|
83
|
+
if (statementMaker.customGroupStatement) {
|
|
84
|
+
compiledStatement += `/* From:aliacss.config.group */\n${statementMaker.customGroupStatement}\n/* -----End:aliacss.config.group----- */\n\n`;
|
|
85
|
+
moduleStatement += `/* From:aliacss.config.group */\n${statementMaker.customGroupStatement}\n/* -----End:aliacss.config.group----- */\n\n`;
|
|
86
|
+
}
|
|
87
|
+
const [classList, groups, keyframe, rawCSSStatement] = extractClassNamesFromFile(file, config);
|
|
88
|
+
// 1. raw-css
|
|
89
|
+
if (rawCSSStatement) {
|
|
90
|
+
globalStatement += rawCSSStatement + '\n';
|
|
91
|
+
compiledStatement += rawCSSStatement + '\n';
|
|
92
|
+
}
|
|
93
|
+
// 2. group
|
|
94
|
+
for (const key in groups) {
|
|
95
|
+
if (groups.hasOwnProperty(key)) {
|
|
96
|
+
// --------------ModuleStatement
|
|
97
|
+
if (/^module=/.test(key)) {
|
|
98
|
+
const mdStatement = statementMaker.group(groups[key], key.replace(/module=/, ''));
|
|
99
|
+
moduleStatement += mdStatement + '\n';
|
|
100
|
+
}
|
|
101
|
+
// -------------EndOfModule
|
|
102
|
+
else {
|
|
103
|
+
const gpStatement = statementMaker.group(groups[key], key);
|
|
104
|
+
globalStatement += gpStatement + '\n';
|
|
105
|
+
compiledStatement += gpStatement + '\n';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
// 2. ClassList
|
|
110
|
+
classList.forEach((e) => {
|
|
111
|
+
const statement = statementMaker.make(e);
|
|
112
|
+
if (statement) {
|
|
113
|
+
console.log('\x1b[32m', statement);
|
|
114
|
+
if (globalClassList.indexOf(e) === -1) {
|
|
115
|
+
globalStatement += statement + '\n';
|
|
116
|
+
globalClassList.push(e);
|
|
117
|
+
// console.log(e);
|
|
118
|
+
}
|
|
119
|
+
compiledStatement += statement + '\n';
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
// 3. Keyframe
|
|
123
|
+
for (const key in keyframe) {
|
|
124
|
+
if (keyframe.hasOwnProperty(key)) {
|
|
125
|
+
const kfStatement = keyframesStatement(key, keyframe[key], statementMaker);
|
|
126
|
+
globalStatement += kfStatement + '\n';
|
|
127
|
+
compiledStatement += kfStatement + '\n';
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return [globalStatement, compiledStatement, moduleStatement];
|
|
131
|
+
}
|
|
132
|
+
export function groupStatement(name, classNames, statementMaker) {
|
|
133
|
+
return statementMaker.group(classNames, name) + '\n';
|
|
134
|
+
}
|
|
135
|
+
export function keyframesStatement(name, timeLine, statementMaker) {
|
|
136
|
+
let kfStatement = '@keyframes ' + name + "{\n";
|
|
137
|
+
const returnPnV = (e) => e.map((i) => statementMaker.make(i, null, true)).join(";");
|
|
138
|
+
const split = timeLine.split(/\s+/);
|
|
139
|
+
split.forEach((each) => {
|
|
140
|
+
try {
|
|
141
|
+
const [at, pNv] = each.replace(/\]\[/, ']-[').replace("-", "=").split("=");
|
|
142
|
+
// kfStatement+=` ${at.replace('@','').replace(/:/g,',').replace(/,/g,"%,").replace(/[\[|\]]/g,'')}% {${returnPnV(pNv.replace(/^\[|\]$/g,'').split(','))}}`
|
|
143
|
+
kfStatement += ` ${at.replace('@', '').replace(/:/g, ',').replace(/,/g, "%,").replace(/[\[|\]]/g, '')}% {${returnPnV(splitByCommaOutsideParens(pNv.replace(/^\[|\]$/g, '')))}}`;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error('Not a valid entry for AliasCSS keyframes processor : ' + each, error);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
return kfStatement + "\n}\n";
|
|
150
|
+
}
|
|
151
|
+
export function createCSSFileByFile(file, bool = false) {
|
|
152
|
+
const [gbContent, content, module] = compileFile(file, config, statementMaker, init.classList);
|
|
153
|
+
// console.log(init.classList);
|
|
154
|
+
// If its fileByFile
|
|
155
|
+
if (init["--module"] && module.trim()) {
|
|
156
|
+
try {
|
|
157
|
+
fs.writeFileSync(file + '.module.css', module);
|
|
158
|
+
// console.log(content);
|
|
159
|
+
console.log('AliasCSS compiled', path.relative('.', file), 'module Locally ');
|
|
160
|
+
}
|
|
161
|
+
catch (error) {
|
|
162
|
+
console.log('\x1b[31m', "Couldn't able to append/create locally from " + file);
|
|
163
|
+
console.log(error);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (init["--file"]) {
|
|
167
|
+
try {
|
|
168
|
+
fs.writeFileSync(file + '.css', content);
|
|
169
|
+
postify(file + '.css', [postcssDiscardDuplicates], init.minify);
|
|
170
|
+
// console.log(content);
|
|
171
|
+
console.log('AliasCSS compiled', path.relative('.', file), 'Locally');
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.log('\x1b[31m', "Couldn't able to append/create locally from " + file);
|
|
175
|
+
console.log(error);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// Check for Global
|
|
179
|
+
if (!bool && init.output) {
|
|
180
|
+
try {
|
|
181
|
+
fs.writeFileSync(init.output, `\n/* Start :-----------ACSS ${path.relative('.', file)}------------------------*/\n${postcss([postcssDiscardDuplicates]).process(gbContent)}
|
|
182
|
+
\n/* End :-----------ACSS ${path.relative('.', file)}----------------------------*/\n
|
|
183
|
+
`, { flag: 'a+' });
|
|
184
|
+
console.log('AliasCSS compiled', path.relative('.', file), 'to main css file :' + init.output);
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
console.log('\x1b[31m', "Couldn't able to append/create to main css file :" + init.output);
|
|
188
|
+
console.log(error);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
export function postify(file, plugin, minify = false, sort = "mobile-first") {
|
|
193
|
+
const data = fs.readFileSync(file, 'utf-8');
|
|
194
|
+
plugin.push(sortMediaQueries({
|
|
195
|
+
sort
|
|
196
|
+
}));
|
|
197
|
+
if (fs.existsSync(file)) {
|
|
198
|
+
if (minify === true)
|
|
199
|
+
plugin.push(cssnano);
|
|
200
|
+
postcss(plugin).process(data, { from: undefined }).then(result => {
|
|
201
|
+
fs.truncateSync(file);
|
|
202
|
+
fs.writeFileSync(file, result.css);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
// fs.readFile(file, (err, css) => {
|
|
206
|
+
// postcss(plugin)
|
|
207
|
+
// .process(css, { from: file, to: file+"post.css" })
|
|
208
|
+
// .then(result => {
|
|
209
|
+
// fs.writeFile(file+"post.css", result.css, () => true)
|
|
210
|
+
// // if ( result.map ) {
|
|
211
|
+
// // fs.writeFile(file+'.map', result.map.toString(), () => true)
|
|
212
|
+
// // }
|
|
213
|
+
// })
|
|
214
|
+
// })
|
|
215
|
+
}
|
|
216
|
+
export function writeStatementToFile(file, content, from) {
|
|
217
|
+
// Check for Global
|
|
218
|
+
if (init.output) {
|
|
219
|
+
try {
|
|
220
|
+
fs.writeFileSync(init.output, `\n/* Start :-----------ACSS:From aliasCSSConfig.${from}------------------------*/\n${content}
|
|
221
|
+
\n/* End :-----------ACSS aliasCSSConfig.${from}----------------------------*/\n
|
|
222
|
+
`, { flag: 'a+' });
|
|
223
|
+
console.log('AliasCSS compiled', '[aliasCSSConfig.statement]', 'aliascss.config.js');
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
console.log('\x1b[31m', "Couldn't able to append/create [key:statement] from alias.config.js ");
|
|
227
|
+
console.log(error);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
// Initialize
|
|
232
|
+
export function initialize(configFile) {
|
|
233
|
+
// ----------------input-------------------
|
|
234
|
+
if (configFile.hasOwnProperty('input')) {
|
|
235
|
+
init.input = configFile.input;
|
|
236
|
+
init.globPattern = configFile.input;
|
|
237
|
+
}
|
|
238
|
+
// ----------------input-------------------
|
|
239
|
+
if (configFile.hasOwnProperty('layers') && Array.isArray(configFile.layers)) {
|
|
240
|
+
init.layers = configFile.layers;
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
init.layers = config.layers;
|
|
244
|
+
}
|
|
245
|
+
// ----------------Prefix-------------------
|
|
246
|
+
if (configFile.hasOwnProperty('prefix')) {
|
|
247
|
+
init.config.prefix = configFile.prefix;
|
|
248
|
+
}
|
|
249
|
+
// ----------------output-------------------
|
|
250
|
+
if (configFile.hasOwnProperty('output')) {
|
|
251
|
+
const op = configFile.output;
|
|
252
|
+
if (op.hasOwnProperty('location')) {
|
|
253
|
+
init.output = op.location;
|
|
254
|
+
}
|
|
255
|
+
if (op.hasOwnProperty('--file') && op['--file'] === true) {
|
|
256
|
+
init["--file"] = true;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// Adding Custom color, length etc
|
|
260
|
+
if (configFile.hasOwnProperty('custom') && typeof configFile.custom === 'object') {
|
|
261
|
+
Object.keys(configFile.custom).forEach((key) => {
|
|
262
|
+
init.statementMaker.addCustom(key, configFile.custom[key]);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
// Extend custom class name define {'border-color-native":'border-color: skyBlue',}
|
|
266
|
+
if (configFile.hasOwnProperty('prebuild')) {
|
|
267
|
+
init.statementMaker.prebuild(configFile.prebuild);
|
|
268
|
+
}
|
|
269
|
+
// Ignore these class name
|
|
270
|
+
if (configFile.hasOwnProperty('ignore')) {
|
|
271
|
+
if (Array.isArray(configFile.ignore)) {
|
|
272
|
+
configFile.ignore.forEach((each) => init.config.ignore.push(each.trim()));
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// --module
|
|
276
|
+
if (configFile.hasOwnProperty('--module') && configFile.hasOwnProperty('importModuleAs')) {
|
|
277
|
+
init["--module"] = true;
|
|
278
|
+
init.config.useCSSModule = init["--module"] ? true : false;
|
|
279
|
+
if (init.config.useCSSModule)
|
|
280
|
+
init.config.matchCSSModuleFunction = init.config.createCSSModuleRegex(configFile.importModuleAs);
|
|
281
|
+
}
|
|
282
|
+
// ---------output Minify
|
|
283
|
+
if (configFile.hasOwnProperty('minify')) {
|
|
284
|
+
init.minify = configFile.minify;
|
|
285
|
+
}
|
|
286
|
+
// ------------Extractor function-------
|
|
287
|
+
if (configFile.hasOwnProperty('extractorFunction')) {
|
|
288
|
+
init.config.useExtractorFunction = configFile.extractorFunction.trim() ? true : false;
|
|
289
|
+
if (init.config.useExtractorFunction)
|
|
290
|
+
init.config.matchExtractorFunction = init.config.createExtractorRegex(configFile.extractorFunction);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
init.config.useExtractorFunction = true;
|
|
294
|
+
init.config.matchExtractorFunction = init.config.createExtractorRegex('String');
|
|
295
|
+
}
|
|
296
|
+
// ---------Extend----------------
|
|
297
|
+
if (configFile.hasOwnProperty('extend') && typeof configFile.extend === 'object') {
|
|
298
|
+
const filteredObj = {};
|
|
299
|
+
Object.keys(configFile.extend).map((key) => {
|
|
300
|
+
// if (configFile.extend[key].hasOwnProperty('compiler') && (typeof configFile.extend[key].compiler === 'function')){
|
|
301
|
+
filteredObj[key] = configFile.extend[key];
|
|
302
|
+
// }
|
|
303
|
+
});
|
|
304
|
+
init.statementMaker.extend(filteredObj);
|
|
305
|
+
}
|
|
306
|
+
// -----------------useColon----------------------------
|
|
307
|
+
if (configFile.hasOwnProperty('useColon')) {
|
|
308
|
+
init.config.useColon = configFile.useColon;
|
|
309
|
+
}
|
|
310
|
+
// ---------------addMedia----------------
|
|
311
|
+
if (configFile.hasOwnProperty('media') && typeof configFile.media === 'object') {
|
|
312
|
+
init.statementMaker.addMedia(configFile.media);
|
|
313
|
+
}
|
|
314
|
+
// /Truncate File every time we bundle
|
|
315
|
+
if (configFile.hasOwnProperty('truncate') && configFile.truncate === false) {
|
|
316
|
+
// do nothing
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
if (fs.existsSync(init.output))
|
|
320
|
+
fs.truncateSync(path.resolve(init.output));
|
|
321
|
+
writeStatementToFile(init.output, `@layer ${init.layers.join(', ')};`, 'Initializating @layer,');
|
|
322
|
+
}
|
|
323
|
+
// Custom CSS statement
|
|
324
|
+
if (configFile.hasOwnProperty('statement')) {
|
|
325
|
+
init.rawCSS = configFile.statement;
|
|
326
|
+
init.statementMaker.rawCSS = configFile.statement;
|
|
327
|
+
writeStatementToFile(init.output, configFile.statement, 'config.statement');
|
|
328
|
+
}
|
|
329
|
+
// Custom Groups bundling acss classnames in single class name
|
|
330
|
+
if (configFile.hasOwnProperty('group')) {
|
|
331
|
+
init.customGroupStatement = init.statementMaker.groupObj(configFile.group);
|
|
332
|
+
init.statementMaker.customGroupStatement = init.statementMaker.groupObj(configFile.group);
|
|
333
|
+
if (init.customGroupStatement)
|
|
334
|
+
writeStatementToFile(init.output, init.customGroupStatement, 'config.group');
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
// ----------------WATCH-------------------------------
|
|
338
|
+
export function watch(config) {
|
|
339
|
+
main(config);
|
|
340
|
+
const watcher = chokidar.watch(init.input, {
|
|
341
|
+
ignored: '*.css', // ignore dot-files
|
|
342
|
+
persistent: true
|
|
343
|
+
});
|
|
344
|
+
const compileFile = (file) => {
|
|
345
|
+
console.log(`--processing file : ${file}`);
|
|
346
|
+
createCSSFileByFile(file, true);
|
|
347
|
+
globalCSSCompiler();
|
|
348
|
+
postify(init.output, [postcssDiscardDuplicates], init.minify);
|
|
349
|
+
console.log('Done! ');
|
|
350
|
+
};
|
|
351
|
+
// Something to use when events are received.
|
|
352
|
+
const log = console.log.bind(console);
|
|
353
|
+
// Add event listeners.
|
|
354
|
+
watcher
|
|
355
|
+
.on('add', path => log(`File ${path} has been added to watch`))
|
|
356
|
+
.on('change', path => compileFile(path));
|
|
357
|
+
// .on('unlink', path => log(`File ${path} has been removed`));
|
|
358
|
+
// More possible events.
|
|
359
|
+
watcher
|
|
360
|
+
.on('addDir', path => log(`Directory ${path} has been added`))
|
|
361
|
+
.on('unlinkDir', path => log(`Directory ${path} has been removed`))
|
|
362
|
+
// .on('error', error => log(`Watcher error: ${error}`))
|
|
363
|
+
// .on('ready', () => log('Initial scan complete. Ready for changes'))
|
|
364
|
+
.on('raw', (event, path, details) => {
|
|
365
|
+
// log('Raw event info:', event, path, details);
|
|
366
|
+
if (event === 'created' && details.type === 'file') {
|
|
367
|
+
if (init.globPattern) {
|
|
368
|
+
const files = fg.sync(init.globPattern, { absolute: true });
|
|
369
|
+
if (files.indexOf(path) !== -1) {
|
|
370
|
+
watcher.add(path);
|
|
371
|
+
// console.log(path,123123);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
else {
|
|
375
|
+
watcher.add(path);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
}
|