1 | function _nullishCoalesce$1(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
2 |
|
3 |
|
4 |
|
5 | function toArray(v) {
|
6 | if (Array.isArray(v))
|
7 | return v;
|
8 | return [v];
|
9 | }
|
10 |
|
11 | function hash(str) {
|
12 | str = str.replace(/\r/g, '');
|
13 | let hash = 5381;
|
14 | let i = str.length;
|
15 |
|
16 | while (i--) hash = ((hash << 5) - hash) ^ str.charCodeAt(i);
|
17 | return (hash >>> 0).toString(36);
|
18 | }
|
19 |
|
20 | function type(val) {
|
21 | return val === null
|
22 | ? 'Null'
|
23 | : val === undefined
|
24 | ? 'Undefined'
|
25 | : Object.prototype.toString.call(val).slice(8, -1);
|
26 | }
|
27 |
|
28 | function indent(code, tab = 2) {
|
29 | const spaces = Array(tab).fill(' ').join('');
|
30 | return code
|
31 | .split('\n')
|
32 | .map((line) => spaces + line)
|
33 | .join('\n');
|
34 | }
|
35 |
|
36 | function wrapit(
|
37 | code,
|
38 | start = '{',
|
39 | end = '}',
|
40 | tab = 2,
|
41 | minify = false
|
42 | ) {
|
43 | if (minify) return `${start}${code}${end}`;
|
44 | return `${start}\n${indent(code, tab)}\n${end}`;
|
45 | }
|
46 |
|
47 | function isNumber(
|
48 | amount,
|
49 | start = -Infinity,
|
50 | end = Infinity,
|
51 | type = 'int'
|
52 | ) {
|
53 | const isInt = /^-?\d+$/.test(amount);
|
54 | if (type === 'int') {
|
55 | if (!isInt) return false;
|
56 | } else {
|
57 | const isFloat = /^-?\d+\.\d+$/.test(amount);
|
58 | if (!(isInt || isFloat)) return false;
|
59 | }
|
60 | const num = parseFloat(amount);
|
61 | return num >= start && num <= end;
|
62 | }
|
63 |
|
64 | function isFraction(amount) {
|
65 | return /^\d+\/\d+$/.test(amount);
|
66 | }
|
67 |
|
68 | function isSize(amount) {
|
69 | return /^-?(\d+(\.\d+)?)+(rem|em|px|rpx|vh|vw|ch|ex)$/.test(amount);
|
70 | }
|
71 |
|
72 | function isSpace(str) {
|
73 | return /^\s*$/.test(str);
|
74 | }
|
75 |
|
76 | function roundUp(num, precision = 0) {
|
77 | precision = Math.pow(10, precision);
|
78 | return Math.round(num * precision) / precision;
|
79 | }
|
80 |
|
81 | function fracToPercent(amount) {
|
82 | const matches = amount.match(/[^/]+/g);
|
83 | if (!matches || matches.length < 2) return;
|
84 | const a = +matches[0];
|
85 | const b = +matches[1];
|
86 | return roundUp((a / b) * 100, 6) + '%';
|
87 | }
|
88 |
|
89 | function hex2RGB(hex) {
|
90 | const RGB_HEX = /^#?(?:([\da-f]{3})[\da-f]?|([\da-f]{6})(?:[\da-f]{2})?)$/i;
|
91 | const [, short, long] = String(hex).match(RGB_HEX) || [];
|
92 |
|
93 | if (long) {
|
94 | const value = Number.parseInt(long, 16);
|
95 | return [value >> 16, (value >> 8) & 0xff, value & 0xff];
|
96 | } else if (short) {
|
97 | return Array.from(short, (s) => Number.parseInt(s, 16)).map(
|
98 | (n) => (n << 4) | n
|
99 | );
|
100 | }
|
101 | }
|
102 |
|
103 | function camelToDash(str) {
|
104 |
|
105 | return str.replace(/([A-Z])/g, '-$1').replace(/^ms-/, '-ms-').toLowerCase();
|
106 | }
|
107 |
|
108 | function dashToCamel(str) {
|
109 | if (!/-/.test(str)) return str;
|
110 | return str.toLowerCase().replace(/-(.)/g, (_, group) => group.toUpperCase());
|
111 | }
|
112 |
|
113 |
|
114 | function getNestedValue(obj, key) {
|
115 | const topKey = key.match(/^[^.[]+/);
|
116 | if (!topKey) return;
|
117 | let topValue = obj[topKey[0]];
|
118 | if (!topValue) return;
|
119 | let index = topKey[0].length;
|
120 | while(index < key.length) {
|
121 | const square = key.slice(index, ).match(/\[[^\s\]]+?\]/);
|
122 | const dot = key.slice(index, ).match(/\.[^.[]+$|\.[^.[]+(?=\.)/);
|
123 | if (( !square && !dot ) || ( _optionalChain$2([square, 'optionalAccess', _2 => _2.index]) === undefined && _optionalChain$2([dot, 'optionalAccess', _3 => _3.index]) === undefined )) return topValue;
|
124 | if (typeof topValue !== 'object') return;
|
125 | if (dot && dot.index !== undefined && (_optionalChain$2([square, 'optionalAccess', _4 => _4.index]) === undefined || dot.index < square.index)) {
|
126 | const arg = dot[0].slice(1,);
|
127 | topValue = topValue[arg];
|
128 | index += dot.index + dot[0].length;
|
129 | } else if (square && square.index !== undefined) {
|
130 | const arg = square[0].slice(1, -1).trim().replace(/^['"]+|['"]+$/g, '');
|
131 | topValue = topValue[arg];
|
132 | index += square.index + square[0].length;
|
133 | }
|
134 | }
|
135 | return topValue;
|
136 | }
|
137 |
|
138 | function negateValue(value) {
|
139 | if (/(^0\w)|(^-)|(^0$)/.test(value)) return value;
|
140 | return '-' + value;
|
141 | }
|
142 |
|
143 | function searchFrom(
|
144 | text,
|
145 | target,
|
146 | startIndex = 0,
|
147 | endIndex
|
148 | ) {
|
149 |
|
150 | const subText = text.substring(startIndex, endIndex);
|
151 | const relativeIndex = subText.search(target);
|
152 | return relativeIndex === -1 ? -1 : startIndex + relativeIndex;
|
153 | }
|
154 |
|
155 | function connectList(a, b, append = true) {
|
156 | return append ? [...(_nullishCoalesce$1(a, () => ( []))), ...(_nullishCoalesce$1(b, () => ( [])))] : [...(_nullishCoalesce$1(b, () => ( []))), ...(_nullishCoalesce$1(a, () => ( [])))];
|
157 | }
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 | function toType(
|
166 | value,
|
167 | type
|
168 | ) {
|
169 | switch (type) {
|
170 | case 'object':
|
171 | return value && typeof value === 'object' ? value : {};
|
172 | case 'string':
|
173 | if (typeof value === 'string') return value ;
|
174 | break;
|
175 | case 'number':
|
176 | if (typeof value === 'number') return value ;
|
177 | break;
|
178 | }
|
179 | }
|
180 |
|
181 | function deepCopy(source) {
|
182 | return Array.isArray(source)
|
183 | ? (source ).map((item) => deepCopy(item))
|
184 | : source instanceof Date
|
185 | ? new Date(source.getTime())
|
186 | : source && typeof source === 'object'
|
187 | ? Object.getOwnPropertyNames(source).reduce((o, prop) => {
|
188 | const descriptor = Object.getOwnPropertyDescriptor(source, prop);
|
189 | if (descriptor) {
|
190 | Object.defineProperty(o, prop, descriptor);
|
191 | if (source && typeof source === 'object') {
|
192 | o[prop] = deepCopy(
|
193 | ((source ) )[prop]
|
194 | );
|
195 | }
|
196 | }
|
197 | return o;
|
198 | }, Object.create(Object.getPrototypeOf(source)))
|
199 | : (source );
|
200 | }
|
201 |
|
202 | function isTagName(name) {
|
203 | return ['a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embd', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'svg', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr'].includes(name);
|
204 | }
|
205 |
|
206 | function flatColors(colors, head) {
|
207 | let flatten = {};
|
208 | for (const [key, value] of Object.entries(colors)) {
|
209 | if (typeof value === 'string' || typeof value === 'function') {
|
210 | flatten[(head && key === 'DEFAULT') ? head : head ? `${head}-${key}`: key] = value;
|
211 | } else {
|
212 | flatten = { ...flatten, ...flatColors(value, head ? `${head}-${key}`: key) };
|
213 | }
|
214 | }
|
215 | return flatten;
|
216 | }
|
217 |
|
218 | function testRegexr(text, expressions) {
|
219 | for (const exp of expressions) {
|
220 | if (exp.test(text)) return true;
|
221 | }
|
222 | return false;
|
223 | }
|
224 |
|
225 | function searchPropEnd(text, startIndex = 0) {
|
226 | let index = startIndex;
|
227 | let output = -1;
|
228 | let openSingleQuote = false;
|
229 | let openDoubleQuote = false;
|
230 | let openBracket = false;
|
231 | let isEscaped = false;
|
232 | while (index < text.length) {
|
233 | switch (text.charAt(index)) {
|
234 | case '\\':
|
235 | isEscaped = !isEscaped;
|
236 | break;
|
237 | case '\'':
|
238 | if (!openDoubleQuote && !openBracket && !isEscaped) openSingleQuote = !openSingleQuote;
|
239 | isEscaped = false;
|
240 | break;
|
241 | case '"':
|
242 | if (!openSingleQuote && !openBracket && !isEscaped) openDoubleQuote = !openDoubleQuote;
|
243 | isEscaped = false;
|
244 | break;
|
245 | case '(':
|
246 | if (!openBracket && !openSingleQuote && !openDoubleQuote && !isEscaped) openBracket = true;
|
247 | isEscaped = false;
|
248 | break;
|
249 | case ')':
|
250 | if (openBracket && !isEscaped) openBracket = false;
|
251 | isEscaped = false;
|
252 | break;
|
253 | case ';':
|
254 | if (!isEscaped && !openSingleQuote && !openDoubleQuote && !openBracket) output = index;
|
255 | isEscaped = false;
|
256 | break;
|
257 | default:
|
258 | isEscaped = false;
|
259 | break;
|
260 | }
|
261 | if (output !== -1) break;
|
262 | index++;
|
263 | }
|
264 | return output;
|
265 | }
|
266 |
|
267 | function searchNotEscape(text, chars = ['{']) {
|
268 | if (!Array.isArray(chars)) chars = [ chars ];
|
269 | let i = 0;
|
270 | while (i < text.length) {
|
271 | if (chars.includes(text.charAt(i)) && text.charAt(i - 1) !== '\\') {
|
272 | return i;
|
273 | }
|
274 | i ++;
|
275 | }
|
276 | return -1;
|
277 | }
|
278 |
|
279 | function splitSelectors(selectors) {
|
280 | const splitted = [];
|
281 | let parens = 0;
|
282 | let angulars = 0;
|
283 | let soFar = '';
|
284 | for (let i = 0, len = selectors.length; i < len; i++) {
|
285 | const char = selectors[i];
|
286 | if (char === '(') {
|
287 | parens += 1;
|
288 | } else if (char === ')') {
|
289 | parens -= 1;
|
290 | } else if (char === '[') {
|
291 | angulars += 1;
|
292 | } else if (char === ']') {
|
293 | angulars -= 1;
|
294 | } else if (char === ',') {
|
295 | if (!parens && !angulars) {
|
296 | splitted.push(soFar.trim());
|
297 | soFar = '';
|
298 | continue;
|
299 | }
|
300 | }
|
301 | soFar += char;
|
302 | }
|
303 | splitted.push(soFar.trim());
|
304 | return splitted;
|
305 | }
|
306 |
|
307 | function guessClassName(selector) {
|
308 | if (selector.indexOf(',') >= 0) return splitSelectors(selector).map(i => guessClassName(i) );
|
309 |
|
310 | if (selector.charAt(0) !== '.' || searchNotEscape(selector, ['[', '>', '+', '~']) >= 0 || selector.trim().indexOf(' ') >= 0 || searchNotEscape(selector.slice(1), '.') >=0)
|
311 | return { selector, isClass: false };
|
312 | const pseudo = searchNotEscape(selector, ':');
|
313 | const className = (_optionalChain$2([selector, 'access', _5 => _5.match, 'call', _6 => _6(/^\.([\w-]|(\\\W))+/), 'optionalAccess', _7 => _7[0], 'access', _8 => _8.slice, 'call', _9 => _9(1,)]) || '').replace(/\\/g, '');
|
314 | if (pseudo === -1) return { selector: className, isClass: true };
|
315 | return { selector: className, isClass: true, pseudo: selector.slice(pseudo,) };
|
316 | }
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 |
|
326 | function increaseWithUnit(target, delta) {
|
327 | if (typeof target === 'number')
|
328 | return target + delta;
|
329 | const value = _optionalChain$2([target, 'access', _10 => _10.match, 'call', _11 => _11(/^-?[0-9]+\.?[0-9]*/), 'optionalAccess', _12 => _12[0]]) || '';
|
330 | const unit = target.slice(value.length);
|
331 | const result = (parseFloat(value) + delta);
|
332 | if (Number.isNaN(result))
|
333 | return target;
|
334 | return result + unit;
|
335 | }
|
336 |
|
337 |
|
338 | function splitColorGroup(color) {
|
339 | const sep = color.indexOf('/');
|
340 | if (sep === -1) return [ color, undefined ];
|
341 | return [ color.slice(0, sep), color.slice(sep+1) ];
|
342 | }
|
343 |
|
344 | function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain$1(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
345 |
|
346 |
|
347 |
|
348 |
|
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 |
|
359 | class Property {
|
360 | __init() {this.meta = { type: 'utilities', group: 'plugin', order: 0, offset: 0, corePlugin: false };}
|
361 |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 | constructor(
|
367 | name,
|
368 | value,
|
369 | comment,
|
370 | important = false
|
371 | ) {Property.prototype.__init.call(this);
|
372 | this.name = name;
|
373 | this.value = value;
|
374 | this.comment = comment;
|
375 | this.important = important;
|
376 | }
|
377 |
|
378 | static _singleParse(
|
379 | css
|
380 | ) {
|
381 | css = css.trim();
|
382 | if (!css) return;
|
383 | if (css.charAt(0) === '@') return InlineAtRule.parse(css);
|
384 | const split = css.search(':');
|
385 | const end = searchPropEnd(css);
|
386 | if (split === -1) return;
|
387 | let important = false;
|
388 | let prop = css.substring(split + 1, end === -1 ? undefined : end).trim();
|
389 | if (/!important;?$/.test(prop)) {
|
390 | important = true;
|
391 | prop = prop.replace(/!important/, '').trimRight();
|
392 | }
|
393 | return new Property(
|
394 | css.substring(0, split).trim(),
|
395 | prop,
|
396 | undefined,
|
397 | important
|
398 | );
|
399 | }
|
400 |
|
401 | static parse(
|
402 | css
|
403 | ) {
|
404 | if (!/;\s*$/.test(css)) css += ';';
|
405 | const properties = [];
|
406 | let index = 0;
|
407 | let end = searchPropEnd(css, index);
|
408 | while (end !== -1) {
|
409 | const parsed = this._singleParse(css.substring(searchFrom(css, /\S/, index), end + 1));
|
410 | if (parsed) properties.push(parsed);
|
411 | index = end + 1;
|
412 | end = searchPropEnd(css, index);
|
413 | }
|
414 | const count = properties.length;
|
415 | if (count > 1) return properties;
|
416 | if (count === 1) return properties[0];
|
417 | }
|
418 |
|
419 | clone() {
|
420 | return deepCopy(this);
|
421 | }
|
422 |
|
423 | toStyle(selector) {
|
424 | const style = new Style(selector, this, this.important);
|
425 | style.meta = this.meta;
|
426 | return style;
|
427 | }
|
428 |
|
429 | build(minify = false) {
|
430 | const createProperty = (name, value) => {
|
431 | if (minify) {
|
432 | return `${name}:${value}${this.important ? '!important' : ''};`;
|
433 | } else {
|
434 | const p = `${name}: ${value}${this.important ? ' !important' : ''};`;
|
435 | return this.comment ? p + ` /* ${this.comment} */` : p;
|
436 | }
|
437 | };
|
438 | if (!this.value) return '';
|
439 | return typeof this.name === 'string'
|
440 | ? createProperty(this.name, this.value)
|
441 | : this.name
|
442 | .map((i) => createProperty(i, this.value))
|
443 | .join(minify ? '' : '\n');
|
444 | }
|
445 |
|
446 | updateMeta(type, group, order, offset = 0, corePlugin = false) {
|
447 | this.meta = {
|
448 | type,
|
449 | group,
|
450 | order,
|
451 | offset,
|
452 | corePlugin,
|
453 | };
|
454 | return this;
|
455 | }
|
456 | }
|
457 |
|
458 | class InlineAtRule extends Property {
|
459 |
|
460 | constructor(name, value, important = false) {
|
461 | super(name, value, undefined, important);
|
462 | this.name = name;
|
463 | }
|
464 | static parse(css) {
|
465 | const matchName = css.match(/@[^\s;{}]+/);
|
466 | if (matchName) {
|
467 | const name = matchName[0].substring(1);
|
468 | let important = false;
|
469 | let expression =
|
470 | matchName.index !== undefined
|
471 | ? _optionalChain$1([css
|
472 | , 'access', _ => _.substring, 'call', _2 => _2(matchName.index + name.length + 1)
|
473 | , 'access', _3 => _3.match, 'call', _4 => _4(/(?:(['"]).*?\1|[^;])*/), 'optionalAccess', _5 => _5[0]
|
474 | , 'access', _6 => _6.trim, 'call', _7 => _7()])
|
475 | : undefined;
|
476 | if (expression && /!important;?$/.test(expression)) {
|
477 | important = true;
|
478 | expression = expression.replace(/!important/, '').trimRight();
|
479 | }
|
480 | return new InlineAtRule(
|
481 | name,
|
482 | expression === '' ? undefined : expression,
|
483 | important
|
484 | );
|
485 | }
|
486 | }
|
487 | build() {
|
488 | return this.value
|
489 | ? `@${this.name} ${this.value}${this.important ? ' !important' : ''};`
|
490 | : `@${this.name}${this.important ? ' !important' : ''};`;
|
491 | }
|
492 | }
|
493 |
|
494 | class Style {
|
495 | __init2() {this.meta = { type: 'components', group: 'plugin', order: 0, offset: 0, corePlugin: false };}
|
496 |
|
497 |
|
498 |
|
499 |
|
500 |
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 |
|
507 |
|
508 |
|
509 | constructor(
|
510 | selector,
|
511 | property,
|
512 | important = false
|
513 | ) {Style.prototype.__init2.call(this);
|
514 | this.selector = selector;
|
515 | this.important = important;
|
516 | this.property = toArray(property || []);
|
517 | }
|
518 |
|
519 | get rule() {
|
520 | let selectors = (_nullishCoalesce(this.selector, () => ( ''))).trim().split(/\s*,\s*/g);
|
521 | this._parentSelectors && (selectors = selectors.map(i => `${_optionalChain$1([this, 'access', _8 => _8._parentSelectors, 'optionalAccess', _9 => _9.join, 'call', _10 => _10(' ')])} ${i}`));
|
522 | (_nullishCoalesce(this._wrapSelectors, () => ( []))).forEach((func) => (selectors = selectors.map(i => func(i))));
|
523 | this._pseudoClasses && (selectors = selectors.map(i => i + `:${_optionalChain$1([this, 'access', _11 => _11._pseudoClasses, 'optionalAccess', _12 => _12.join, 'call', _13 => _13(':')])}`));
|
524 | this._pseudoElements && (selectors = selectors.map(i => i + `::${_optionalChain$1([this, 'access', _14 => _14._pseudoElements, 'optionalAccess', _15 => _15.join, 'call', _16 => _16('::')])}`));
|
525 | this._brotherSelectors && (selectors = selectors.map(i => i + `.${_optionalChain$1([this, 'access', _17 => _17._brotherSelectors, 'optionalAccess', _18 => _18.join, 'call', _19 => _19('.')])}`));
|
526 | this._childSelectors && (selectors = selectors.map(i => i + ` ${_optionalChain$1([this, 'access', _20 => _20._childSelectors, 'optionalAccess', _21 => _21.join, 'call', _22 => _22(' ')])}`));
|
527 | (_nullishCoalesce(this._wrapRules, () => ( []))).forEach((func) => (selectors = selectors.map(i => func(i))));
|
528 | return selectors.join(', ');
|
529 | }
|
530 |
|
531 | get pseudoClasses() {
|
532 | return this._pseudoClasses;
|
533 | }
|
534 |
|
535 | get pseudoElements() {
|
536 | return this._pseudoElements;
|
537 | }
|
538 |
|
539 | get parentSelectors() {
|
540 | return this._parentSelectors;
|
541 | }
|
542 |
|
543 | get childSelectors() {
|
544 | return this._childSelectors;
|
545 | }
|
546 |
|
547 | get brotherSelectors() {
|
548 | return this._brotherSelectors;
|
549 | }
|
550 |
|
551 | get wrapProperties() {
|
552 | return this._wrapProperties;
|
553 | }
|
554 |
|
555 | get wrapSelectors() {
|
556 | return this._wrapSelectors;
|
557 | }
|
558 |
|
559 | get wrapRules() {
|
560 | return this._wrapRules;
|
561 | }
|
562 |
|
563 | get simple() {
|
564 |
|
565 | return !(this.atRules || this._pseudoClasses || this._pseudoElements || this._parentSelectors || this._childSelectors || this._brotherSelectors || this._wrapProperties || this._wrapSelectors || this._wrapRules);
|
566 | }
|
567 |
|
568 | get isAtrule() {
|
569 | return !(this.atRules === undefined || this.atRules.length === 0);
|
570 | }
|
571 |
|
572 | static generate(
|
573 | parent,
|
574 | property,
|
575 | root,
|
576 | ) {
|
577 | if (!root)
|
578 | root = _optionalChain$1([parent, 'optionalAccess', _23 => _23.startsWith, 'call', _24 => _24('@')])
|
579 | ? new Style().atRule(parent)
|
580 | : new Style(parent);
|
581 |
|
582 | let output = [];
|
583 |
|
584 | for (const [key, value] of Object.entries(_nullishCoalesce(property, () => ( {})))) {
|
585 | if (typeof value === 'string') {
|
586 | root.add(new Property(camelToDash(key), value));
|
587 | } else if (Array.isArray(value)) {
|
588 | value.map(i => _optionalChain$1([root, 'optionalAccess', _25 => _25.add, 'call', _26 => _26(new Property(camelToDash(key), i))]));
|
589 | } else {
|
590 | const wrap = deepCopy(root);
|
591 | wrap.property = [];
|
592 | let child;
|
593 | if (key.startsWith('@')) {
|
594 | child = wrap.atRule(key, false);
|
595 | } else {
|
596 | if (wrap.selector === undefined) {
|
597 | wrap.selector = key;
|
598 | child = wrap;
|
599 | } else {
|
600 | if (/^[a-z]+$/.test(key) && !isTagName(key)) {
|
601 | wrap.wrapProperty(property => `${key}-${property}`);
|
602 | child = wrap;
|
603 | } else {
|
604 | const _hKey = (selector, key) => (/&/.test(key) ? key : `& ${key}`).replace('&', selector);
|
605 | wrap.wrapSelector((selector) =>
|
606 | selector
|
607 | .trim()
|
608 | .split(/\s*,\s*/g)
|
609 | .map((s) =>
|
610 | key
|
611 | .split(/\s*,\s*/g)
|
612 | .map((i) => _hKey(s, i))
|
613 | .join(', ')
|
614 | )
|
615 | .join(', ')
|
616 | );
|
617 | child = wrap;
|
618 | }
|
619 | }
|
620 | }
|
621 | output = output.concat(Style.generate(key.startsWith('@') ? undefined : key, value, child));
|
622 | }
|
623 | }
|
624 | if (root.property.length > 0) output.unshift(root);
|
625 | return output;
|
626 | }
|
627 |
|
628 | atRule(atrule, append = true) {
|
629 | if (!atrule) return this;
|
630 | if (this.atRules) {
|
631 | append ? this.atRules.push(atrule) : this.atRules.unshift(atrule);
|
632 | } else {
|
633 | this.atRules = [atrule];
|
634 | }
|
635 | return this;
|
636 | }
|
637 |
|
638 | pseudoClass(string) {
|
639 | if (this._pseudoClasses) {
|
640 | this._pseudoClasses.push(string);
|
641 | } else {
|
642 | this._pseudoClasses = [string];
|
643 | }
|
644 | return this;
|
645 | }
|
646 |
|
647 | pseudoElement(string) {
|
648 | if (this._pseudoElements) {
|
649 | this._pseudoElements.push(string);
|
650 | } else {
|
651 | this._pseudoElements = [string];
|
652 | }
|
653 | return this;
|
654 | }
|
655 |
|
656 | brother(string) {
|
657 | if (this._brotherSelectors) {
|
658 | this._brotherSelectors.push(string);
|
659 | } else {
|
660 | this._brotherSelectors = [string];
|
661 | }
|
662 | return this;
|
663 | }
|
664 |
|
665 | parent(string) {
|
666 | if (this._parentSelectors) {
|
667 | this._parentSelectors.push(string);
|
668 | } else {
|
669 | this._parentSelectors = [string];
|
670 | }
|
671 | return this;
|
672 | }
|
673 |
|
674 | child(string) {
|
675 | if (this._childSelectors) {
|
676 | this._childSelectors.push(string);
|
677 | } else {
|
678 | this._childSelectors = [string];
|
679 | }
|
680 | return this;
|
681 | }
|
682 |
|
683 | wrapProperty(func) {
|
684 | if (this._wrapProperties) {
|
685 | this._wrapProperties.push(func);
|
686 | } else {
|
687 | this._wrapProperties = [func];
|
688 | }
|
689 | return this;
|
690 | }
|
691 |
|
692 | wrapSelector(func) {
|
693 | if (this._wrapSelectors) {
|
694 | this._wrapSelectors.push(func);
|
695 | } else {
|
696 | this._wrapSelectors = [func];
|
697 | }
|
698 | return this;
|
699 | }
|
700 |
|
701 | wrapRule(func) {
|
702 | if (this._wrapRules) {
|
703 | this._wrapRules.push(func);
|
704 | } else {
|
705 | this._wrapRules = [func];
|
706 | }
|
707 | return this;
|
708 | }
|
709 |
|
710 | add(item) {
|
711 | item = toArray(item);
|
712 | if (this.important) item.forEach((i) => (i.important = true));
|
713 | this.property = [...this.property, ...item];
|
714 | return this;
|
715 | }
|
716 |
|
717 | extend(item, onlyProperty = false, append = true) {
|
718 | if (!item) return this;
|
719 | if (item.wrapProperties) {
|
720 | const props = [];
|
721 | item.property.forEach((p) => {
|
722 | const pc = new Property(p.name, p.value, p.comment);
|
723 | _optionalChain$1([item, 'access', _27 => _27.wrapProperties, 'optionalAccess', _28 => _28.forEach, 'call', _29 => _29((wrap) => {
|
724 | pc.name = Array.isArray(pc.name)
|
725 | ? pc.name.map((i) => wrap(i))
|
726 | : wrap(pc.name);
|
727 | })]);
|
728 | if (item.important) pc.important = true;
|
729 | props.push(pc);
|
730 | });
|
731 | this.property = connectList(this.property, props, append);
|
732 | } else {
|
733 | if (item.important) item.property.forEach((i) => (i.important = true));
|
734 | this.property = connectList(this.property, item.property, append);
|
735 | }
|
736 | if (onlyProperty) return this;
|
737 | item.selector && (this.selector = item.selector);
|
738 | this.meta = item.meta;
|
739 | item.atRules &&
|
740 | (this.atRules = connectList(item.atRules, this.atRules, append));
|
741 | item._brotherSelectors &&
|
742 | (this._brotherSelectors = connectList(
|
743 | this._brotherSelectors,
|
744 | item._brotherSelectors,
|
745 | append
|
746 | ));
|
747 | item._childSelectors &&
|
748 | (this._childSelectors = connectList(
|
749 | this._childSelectors,
|
750 | item._childSelectors,
|
751 | append
|
752 | ));
|
753 | item._parentSelectors &&
|
754 | (this._parentSelectors = connectList(
|
755 | this._parentSelectors,
|
756 | item._parentSelectors,
|
757 | append
|
758 | ));
|
759 | item._pseudoClasses &&
|
760 | (this._pseudoClasses = connectList(
|
761 | this._pseudoClasses,
|
762 | item._pseudoClasses,
|
763 | append
|
764 | ));
|
765 | item._pseudoElements &&
|
766 | (this._pseudoElements = connectList(
|
767 | this._pseudoElements,
|
768 | item._pseudoElements,
|
769 | append
|
770 | ));
|
771 | item._wrapRules &&
|
772 | (this._wrapRules = connectList(this._wrapRules, item._wrapRules, append));
|
773 | item._wrapSelectors &&
|
774 | (this._wrapSelectors = connectList(
|
775 | this._wrapSelectors,
|
776 | item._wrapSelectors,
|
777 | append
|
778 | ));
|
779 | return this;
|
780 | }
|
781 |
|
782 | clean() {
|
783 |
|
784 | const property = [];
|
785 | const cache = [];
|
786 | this.property.forEach((i) => {
|
787 | const inline = i.build();
|
788 | if (!cache.includes(inline)) {
|
789 | cache.push(inline);
|
790 | property.push(i);
|
791 | }
|
792 | });
|
793 | this.property = property;
|
794 | return this;
|
795 | }
|
796 |
|
797 | flat() {
|
798 | const properties = [];
|
799 | this.property.forEach((p) => {
|
800 | if (Array.isArray(p.name)) {
|
801 | p.name.forEach((i) => {
|
802 | properties.push(new Property(i, p.value, p.comment));
|
803 | });
|
804 | } else {
|
805 | properties.push(p);
|
806 | }
|
807 | });
|
808 | this.property = properties;
|
809 | return this;
|
810 | }
|
811 |
|
812 | clone(selector, property) {
|
813 | const newStyle = deepCopy(this);
|
814 | if (selector) newStyle.selector = selector;
|
815 | if (property) newStyle.property = Array.isArray(property) ? property: [ property ];
|
816 | return newStyle;
|
817 | }
|
818 |
|
819 | sort() {
|
820 |
|
821 | this.property = this.property.sort((a, b) => {
|
822 | return `${a.name}`.substring(0, 2) > `${b.name}`.substring(0, 2) ? 1 : -1;
|
823 | });
|
824 | return this;
|
825 | }
|
826 |
|
827 | build(minify = false, prefixer = true) {
|
828 | let properties = this.property;
|
829 | if (!prefixer) properties = properties.filter(p => {
|
830 | if (p.value && /-(webkit|ms|moz|o)-/.test(p.value)) return false;
|
831 | if (Array.isArray(p.name)) {
|
832 | p.name = p.name.filter(i => !/^-(webkit|ms|moz|o)-/.test(i));
|
833 | return true;
|
834 | }
|
835 | return !/^-(webkit|ms|moz|o)-/.test(p.name);
|
836 | });
|
837 | let result = properties.map(p => {
|
838 | if (this._wrapProperties) {
|
839 | let name = p.name;
|
840 | this._wrapProperties.forEach(w => (name = Array.isArray(name) ? name.map(n => w(n)) : w(name)));
|
841 | return new Property(name, p.value, p.comment, this.important ? true : p.important).build(minify);
|
842 | }
|
843 | return this.important ? new Property(p.name, p.value, p.comment, true).build(minify) : p.build(minify);
|
844 | }).join(minify ? '' : '\n');
|
845 | if (!this.selector && !this.atRules) return result.replace(/;}/g, '}');
|
846 | if (this.selector) result = (minify ? this.rule.replace(/,\s/g, ',') : this.rule + ' ') + wrapit(result, undefined, undefined, undefined, result !== '' ? minify : true);
|
847 | if (this.atRules) {
|
848 | for (const rule of this.atRules) {
|
849 | result = minify ? `${rule.replace(/\s/g, '')}${wrapit(result, undefined, undefined, undefined, minify)}` : `${rule} ${wrapit(result, undefined, undefined, undefined, result !== '' ? minify : true)}`;
|
850 | }
|
851 | }
|
852 | return minify ? result.replace(/;}/g, '}') : result;
|
853 | }
|
854 |
|
855 | updateMeta(type, group, order, offset = 0, corePlugin = false, respectSelector = false) {
|
856 | this.meta = {
|
857 | type,
|
858 | group,
|
859 | order,
|
860 | offset,
|
861 | corePlugin,
|
862 | respectSelector,
|
863 | };
|
864 | return this;
|
865 | }
|
866 | }
|
867 |
|
868 | function isString(value) {
|
869 | return typeof value === 'string';
|
870 | }
|
871 |
|
872 | function negative$1(scale
|
873 |
|
874 | ) {
|
875 | return Object.keys(scale)
|
876 | .filter((key) => scale[key] !== '0')
|
877 | .reduce(
|
878 | (negativeScale, key) => ({
|
879 | ...negativeScale,
|
880 | [`-${key}`]: negateValue(scale[key]),
|
881 | }),
|
882 | {}
|
883 | );
|
884 | }
|
885 |
|
886 | function breakpoints(
|
887 | screens = {}
|
888 | ) {
|
889 | return Object.keys(screens)
|
890 | .filter((key) => typeof screens[key] === 'string')
|
891 | .reduce(
|
892 | (breakpoints, key) => ({
|
893 | ...breakpoints,
|
894 | [`screen-${key}`]: screens[key],
|
895 | }),
|
896 | {}
|
897 | );
|
898 | }
|
899 |
|
900 | function generateFontSize(font) {
|
901 | if (typeof font === 'string') return [ new Property('font-size', font) ];
|
902 | const properties = [];
|
903 | if (font[0]) properties.push(new Property('font-size', font[0]));
|
904 | if (typeof font[1] === 'string') {
|
905 | properties.push(new Property('line-height', font[1]));
|
906 | } else if (font[1]){
|
907 | if (font[1].lineHeight) properties.push(new Property('line-height', font[1].lineHeight));
|
908 | if (font[1].letterSpacing) properties.push(new Property('letter-spacing', font[1].letterSpacing));
|
909 | }
|
910 | return properties;
|
911 | }
|
912 |
|
913 | function expandDirection(
|
914 | value,
|
915 | divide = false
|
916 | ) {
|
917 | const map = {
|
918 | '': ['*'],
|
919 | y: ['top', 'bottom'],
|
920 | x: ['left', 'right'],
|
921 | t: divide ? ['top-left', 'top-right'] : ['top'],
|
922 | r: divide ? ['top-right', 'bottom-right'] : ['right'],
|
923 | b: divide ? ['bottom-right', 'bottom-left'] : ['bottom'],
|
924 | l: divide ? ['top-left', 'bottom-left'] : ['left'],
|
925 | tl: ['top-left'],
|
926 | tr: ['top-right'],
|
927 | br: ['bottom-right'],
|
928 | bl: ['bottom-left'],
|
929 | };
|
930 | if (value in map) return map[value];
|
931 | }
|
932 |
|
933 | function generatePlaceholder(selector, property, prefixer = false) {
|
934 | if (!prefixer) return [ new Style(selector, property).pseudoElement('placeholder') ];
|
935 | return [
|
936 | new Style(selector, property).pseudoElement('-webkit-input-placeholder'),
|
937 | new Style(selector, property).pseudoElement('-moz-placeholder'),
|
938 | new Style(selector, property).pseudoClass('-ms-input-placeholder'),
|
939 | new Style(selector, property).pseudoElement('-ms-input-placeholder'),
|
940 | new Style(selector, property).pseudoElement('placeholder'),
|
941 | ];
|
942 | }
|
943 |
|
944 |
|
945 |
|
946 | function toDarkStyle(style, mode) {
|
947 | if (!mode) return style;
|
948 | if (Array.isArray(style)) {
|
949 | if (mode === 'media') return style.map(i => new Style().atRule('@media (prefers-color-scheme: dark)').extend(i));
|
950 | return style.map(i => new Style().parent('.dark').extend(i));
|
951 | }
|
952 | if (mode === 'media') return new Style().atRule('@media (prefers-color-scheme: dark)').extend(style);
|
953 | return new Style().parent('.dark').extend(style);
|
954 | }
|
955 |
|
956 | function createCommonjsModule(fn) {
|
957 | var module = { exports: {} };
|
958 | return fn(module, module.exports), module.exports;
|
959 | }
|
960 |
|
961 | var colorName = {
|
962 | "aliceblue": [240, 248, 255],
|
963 | "antiquewhite": [250, 235, 215],
|
964 | "aqua": [0, 255, 255],
|
965 | "aquamarine": [127, 255, 212],
|
966 | "azure": [240, 255, 255],
|
967 | "beige": [245, 245, 220],
|
968 | "bisque": [255, 228, 196],
|
969 | "black": [0, 0, 0],
|
970 | "blanchedalmond": [255, 235, 205],
|
971 | "blue": [0, 0, 255],
|
972 | "blueviolet": [138, 43, 226],
|
973 | "brown": [165, 42, 42],
|
974 | "burlywood": [222, 184, 135],
|
975 | "cadetblue": [95, 158, 160],
|
976 | "chartreuse": [127, 255, 0],
|
977 | "chocolate": [210, 105, 30],
|
978 | "coral": [255, 127, 80],
|
979 | "cornflowerblue": [100, 149, 237],
|
980 | "cornsilk": [255, 248, 220],
|
981 | "crimson": [220, 20, 60],
|
982 | "cyan": [0, 255, 255],
|
983 | "darkblue": [0, 0, 139],
|
984 | "darkcyan": [0, 139, 139],
|
985 | "darkgoldenrod": [184, 134, 11],
|
986 | "darkgray": [169, 169, 169],
|
987 | "darkgreen": [0, 100, 0],
|
988 | "darkgrey": [169, 169, 169],
|
989 | "darkkhaki": [189, 183, 107],
|
990 | "darkmagenta": [139, 0, 139],
|
991 | "darkolivegreen": [85, 107, 47],
|
992 | "darkorange": [255, 140, 0],
|
993 | "darkorchid": [153, 50, 204],
|
994 | "darkred": [139, 0, 0],
|
995 | "darksalmon": [233, 150, 122],
|
996 | "darkseagreen": [143, 188, 143],
|
997 | "darkslateblue": [72, 61, 139],
|
998 | "darkslategray": [47, 79, 79],
|
999 | "darkslategrey": [47, 79, 79],
|
1000 | "darkturquoise": [0, 206, 209],
|
1001 | "darkviolet": [148, 0, 211],
|
1002 | "deeppink": [255, 20, 147],
|
1003 | "deepskyblue": [0, 191, 255],
|
1004 | "dimgray": [105, 105, 105],
|
1005 | "dimgrey": [105, 105, 105],
|
1006 | "dodgerblue": [30, 144, 255],
|
1007 | "firebrick": [178, 34, 34],
|
1008 | "floralwhite": [255, 250, 240],
|
1009 | "forestgreen": [34, 139, 34],
|
1010 | "fuchsia": [255, 0, 255],
|
1011 | "gainsboro": [220, 220, 220],
|
1012 | "ghostwhite": [248, 248, 255],
|
1013 | "gold": [255, 215, 0],
|
1014 | "goldenrod": [218, 165, 32],
|
1015 | "gray": [128, 128, 128],
|
1016 | "green": [0, 128, 0],
|
1017 | "greenyellow": [173, 255, 47],
|
1018 | "grey": [128, 128, 128],
|
1019 | "honeydew": [240, 255, 240],
|
1020 | "hotpink": [255, 105, 180],
|
1021 | "indianred": [205, 92, 92],
|
1022 | "indigo": [75, 0, 130],
|
1023 | "ivory": [255, 255, 240],
|
1024 | "khaki": [240, 230, 140],
|
1025 | "lavender": [230, 230, 250],
|
1026 | "lavenderblush": [255, 240, 245],
|
1027 | "lawngreen": [124, 252, 0],
|
1028 | "lemonchiffon": [255, 250, 205],
|
1029 | "lightblue": [173, 216, 230],
|
1030 | "lightcoral": [240, 128, 128],
|
1031 | "lightcyan": [224, 255, 255],
|
1032 | "lightgoldenrodyellow": [250, 250, 210],
|
1033 | "lightgray": [211, 211, 211],
|
1034 | "lightgreen": [144, 238, 144],
|
1035 | "lightgrey": [211, 211, 211],
|
1036 | "lightpink": [255, 182, 193],
|
1037 | "lightsalmon": [255, 160, 122],
|
1038 | "lightseagreen": [32, 178, 170],
|
1039 | "lightskyblue": [135, 206, 250],
|
1040 | "lightslategray": [119, 136, 153],
|
1041 | "lightslategrey": [119, 136, 153],
|
1042 | "lightsteelblue": [176, 196, 222],
|
1043 | "lightyellow": [255, 255, 224],
|
1044 | "lime": [0, 255, 0],
|
1045 | "limegreen": [50, 205, 50],
|
1046 | "linen": [250, 240, 230],
|
1047 | "magenta": [255, 0, 255],
|
1048 | "maroon": [128, 0, 0],
|
1049 | "mediumaquamarine": [102, 205, 170],
|
1050 | "mediumblue": [0, 0, 205],
|
1051 | "mediumorchid": [186, 85, 211],
|
1052 | "mediumpurple": [147, 112, 219],
|
1053 | "mediumseagreen": [60, 179, 113],
|
1054 | "mediumslateblue": [123, 104, 238],
|
1055 | "mediumspringgreen": [0, 250, 154],
|
1056 | "mediumturquoise": [72, 209, 204],
|
1057 | "mediumvioletred": [199, 21, 133],
|
1058 | "midnightblue": [25, 25, 112],
|
1059 | "mintcream": [245, 255, 250],
|
1060 | "mistyrose": [255, 228, 225],
|
1061 | "moccasin": [255, 228, 181],
|
1062 | "navajowhite": [255, 222, 173],
|
1063 | "navy": [0, 0, 128],
|
1064 | "oldlace": [253, 245, 230],
|
1065 | "olive": [128, 128, 0],
|
1066 | "olivedrab": [107, 142, 35],
|
1067 | "orange": [255, 165, 0],
|
1068 | "orangered": [255, 69, 0],
|
1069 | "orchid": [218, 112, 214],
|
1070 | "palegoldenrod": [238, 232, 170],
|
1071 | "palegreen": [152, 251, 152],
|
1072 | "paleturquoise": [175, 238, 238],
|
1073 | "palevioletred": [219, 112, 147],
|
1074 | "papayawhip": [255, 239, 213],
|
1075 | "peachpuff": [255, 218, 185],
|
1076 | "peru": [205, 133, 63],
|
1077 | "pink": [255, 192, 203],
|
1078 | "plum": [221, 160, 221],
|
1079 | "powderblue": [176, 224, 230],
|
1080 | "purple": [128, 0, 128],
|
1081 | "rebeccapurple": [102, 51, 153],
|
1082 | "red": [255, 0, 0],
|
1083 | "rosybrown": [188, 143, 143],
|
1084 | "royalblue": [65, 105, 225],
|
1085 | "saddlebrown": [139, 69, 19],
|
1086 | "salmon": [250, 128, 114],
|
1087 | "sandybrown": [244, 164, 96],
|
1088 | "seagreen": [46, 139, 87],
|
1089 | "seashell": [255, 245, 238],
|
1090 | "sienna": [160, 82, 45],
|
1091 | "silver": [192, 192, 192],
|
1092 | "skyblue": [135, 206, 235],
|
1093 | "slateblue": [106, 90, 205],
|
1094 | "slategray": [112, 128, 144],
|
1095 | "slategrey": [112, 128, 144],
|
1096 | "snow": [255, 250, 250],
|
1097 | "springgreen": [0, 255, 127],
|
1098 | "steelblue": [70, 130, 180],
|
1099 | "tan": [210, 180, 140],
|
1100 | "teal": [0, 128, 128],
|
1101 | "thistle": [216, 191, 216],
|
1102 | "tomato": [255, 99, 71],
|
1103 | "turquoise": [64, 224, 208],
|
1104 | "violet": [238, 130, 238],
|
1105 | "wheat": [245, 222, 179],
|
1106 | "white": [255, 255, 255],
|
1107 | "whitesmoke": [245, 245, 245],
|
1108 | "yellow": [255, 255, 0],
|
1109 | "yellowgreen": [154, 205, 50]
|
1110 | };
|
1111 |
|
1112 | var isArrayish = function isArrayish(obj) {
|
1113 | if (!obj || typeof obj === 'string') {
|
1114 | return false;
|
1115 | }
|
1116 |
|
1117 | return obj instanceof Array || Array.isArray(obj) ||
|
1118 | (obj.length >= 0 && (obj.splice instanceof Function ||
|
1119 | (Object.getOwnPropertyDescriptor(obj, (obj.length - 1)) && obj.constructor.name !== 'String')));
|
1120 | };
|
1121 |
|
1122 | var simpleSwizzle = createCommonjsModule(function (module) {
|
1123 |
|
1124 |
|
1125 |
|
1126 | var concat = Array.prototype.concat;
|
1127 | var slice = Array.prototype.slice;
|
1128 |
|
1129 | var swizzle = module.exports = function swizzle(args) {
|
1130 | var results = [];
|
1131 |
|
1132 | for (var i = 0, len = args.length; i < len; i++) {
|
1133 | var arg = args[i];
|
1134 |
|
1135 | if (isArrayish(arg)) {
|
1136 |
|
1137 | results = concat.call(results, slice.call(arg));
|
1138 | } else {
|
1139 | results.push(arg);
|
1140 | }
|
1141 | }
|
1142 |
|
1143 | return results;
|
1144 | };
|
1145 |
|
1146 | swizzle.wrap = function (fn) {
|
1147 | return function () {
|
1148 | return fn(swizzle(arguments));
|
1149 | };
|
1150 | };
|
1151 | });
|
1152 |
|
1153 |
|
1154 |
|
1155 | var colorString = createCommonjsModule(function (module) {
|
1156 | var reverseNames = {};
|
1157 |
|
1158 |
|
1159 | for (var name in colorName) {
|
1160 | if (colorName.hasOwnProperty(name)) {
|
1161 | reverseNames[colorName[name]] = name;
|
1162 | }
|
1163 | }
|
1164 |
|
1165 | var cs = module.exports = {
|
1166 | to: {},
|
1167 | get: {}
|
1168 | };
|
1169 |
|
1170 | cs.get = function (string) {
|
1171 | var prefix = string.substring(0, 3).toLowerCase();
|
1172 | var val;
|
1173 | var model;
|
1174 | switch (prefix) {
|
1175 | case 'hsl':
|
1176 | val = cs.get.hsl(string);
|
1177 | model = 'hsl';
|
1178 | break;
|
1179 | case 'hwb':
|
1180 | val = cs.get.hwb(string);
|
1181 | model = 'hwb';
|
1182 | break;
|
1183 | default:
|
1184 | val = cs.get.rgb(string);
|
1185 | model = 'rgb';
|
1186 | break;
|
1187 | }
|
1188 |
|
1189 | if (!val) {
|
1190 | return null;
|
1191 | }
|
1192 |
|
1193 | return {model: model, value: val};
|
1194 | };
|
1195 |
|
1196 | cs.get.rgb = function (string) {
|
1197 | if (!string) {
|
1198 | return null;
|
1199 | }
|
1200 |
|
1201 | var abbr = /^#([a-f0-9]{3,4})$/i;
|
1202 | var hex = /^#([a-f0-9]{6})([a-f0-9]{2})?$/i;
|
1203 | var rgba = /^rgba?\(\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*,\s*([+-]?\d+)\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
|
1204 | var per = /^rgba?\(\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*,\s*([+-]?[\d\.]+)\%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
|
1205 | var keyword = /(\D+)/;
|
1206 |
|
1207 | var rgb = [0, 0, 0, 1];
|
1208 | var match;
|
1209 | var i;
|
1210 | var hexAlpha;
|
1211 |
|
1212 | if (match = string.match(hex)) {
|
1213 | hexAlpha = match[2];
|
1214 | match = match[1];
|
1215 |
|
1216 | for (i = 0; i < 3; i++) {
|
1217 |
|
1218 | var i2 = i * 2;
|
1219 | rgb[i] = parseInt(match.slice(i2, i2 + 2), 16);
|
1220 | }
|
1221 |
|
1222 | if (hexAlpha) {
|
1223 | rgb[3] = parseInt(hexAlpha, 16) / 255;
|
1224 | }
|
1225 | } else if (match = string.match(abbr)) {
|
1226 | match = match[1];
|
1227 | hexAlpha = match[3];
|
1228 |
|
1229 | for (i = 0; i < 3; i++) {
|
1230 | rgb[i] = parseInt(match[i] + match[i], 16);
|
1231 | }
|
1232 |
|
1233 | if (hexAlpha) {
|
1234 | rgb[3] = parseInt(hexAlpha + hexAlpha, 16) / 255;
|
1235 | }
|
1236 | } else if (match = string.match(rgba)) {
|
1237 | for (i = 0; i < 3; i++) {
|
1238 | rgb[i] = parseInt(match[i + 1], 0);
|
1239 | }
|
1240 |
|
1241 | if (match[4]) {
|
1242 | rgb[3] = parseFloat(match[4]);
|
1243 | }
|
1244 | } else if (match = string.match(per)) {
|
1245 | for (i = 0; i < 3; i++) {
|
1246 | rgb[i] = Math.round(parseFloat(match[i + 1]) * 2.55);
|
1247 | }
|
1248 |
|
1249 | if (match[4]) {
|
1250 | rgb[3] = parseFloat(match[4]);
|
1251 | }
|
1252 | } else if (match = string.match(keyword)) {
|
1253 | if (match[1] === 'transparent') {
|
1254 | return [0, 0, 0, 0];
|
1255 | }
|
1256 |
|
1257 | rgb = colorName[match[1]];
|
1258 |
|
1259 | if (!rgb) {
|
1260 | return null;
|
1261 | }
|
1262 |
|
1263 | rgb[3] = 1;
|
1264 |
|
1265 | return rgb;
|
1266 | } else {
|
1267 | return null;
|
1268 | }
|
1269 |
|
1270 | for (i = 0; i < 3; i++) {
|
1271 | rgb[i] = clamp(rgb[i], 0, 255);
|
1272 | }
|
1273 | rgb[3] = clamp(rgb[3], 0, 1);
|
1274 |
|
1275 | return rgb;
|
1276 | };
|
1277 |
|
1278 | cs.get.hsl = function (string) {
|
1279 | if (!string) {
|
1280 | return null;
|
1281 | }
|
1282 |
|
1283 | var hsl = /^hsla?\(\s*([+-]?(?:\d{0,3}\.)?\d+)(?:deg)?\s*,?\s*([+-]?[\d\.]+)%\s*,?\s*([+-]?[\d\.]+)%\s*(?:[,|\/]\s*([+-]?[\d\.]+)\s*)?\)$/;
|
1284 | var match = string.match(hsl);
|
1285 |
|
1286 | if (match) {
|
1287 | var alpha = parseFloat(match[4]);
|
1288 | var h = (parseFloat(match[1]) + 360) % 360;
|
1289 | var s = clamp(parseFloat(match[2]), 0, 100);
|
1290 | var l = clamp(parseFloat(match[3]), 0, 100);
|
1291 | var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
|
1292 |
|
1293 | return [h, s, l, a];
|
1294 | }
|
1295 |
|
1296 | return null;
|
1297 | };
|
1298 |
|
1299 | cs.get.hwb = function (string) {
|
1300 | if (!string) {
|
1301 | return null;
|
1302 | }
|
1303 |
|
1304 | var hwb = /^hwb\(\s*([+-]?\d{0,3}(?:\.\d+)?)(?:deg)?\s*,\s*([+-]?[\d\.]+)%\s*,\s*([+-]?[\d\.]+)%\s*(?:,\s*([+-]?[\d\.]+)\s*)?\)$/;
|
1305 | var match = string.match(hwb);
|
1306 |
|
1307 | if (match) {
|
1308 | var alpha = parseFloat(match[4]);
|
1309 | var h = ((parseFloat(match[1]) % 360) + 360) % 360;
|
1310 | var w = clamp(parseFloat(match[2]), 0, 100);
|
1311 | var b = clamp(parseFloat(match[3]), 0, 100);
|
1312 | var a = clamp(isNaN(alpha) ? 1 : alpha, 0, 1);
|
1313 | return [h, w, b, a];
|
1314 | }
|
1315 |
|
1316 | return null;
|
1317 | };
|
1318 |
|
1319 | cs.to.hex = function () {
|
1320 | var rgba = simpleSwizzle(arguments);
|
1321 |
|
1322 | return (
|
1323 | '#' +
|
1324 | hexDouble(rgba[0]) +
|
1325 | hexDouble(rgba[1]) +
|
1326 | hexDouble(rgba[2]) +
|
1327 | (rgba[3] < 1
|
1328 | ? (hexDouble(Math.round(rgba[3] * 255)))
|
1329 | : '')
|
1330 | );
|
1331 | };
|
1332 |
|
1333 | cs.to.rgb = function () {
|
1334 | var rgba = simpleSwizzle(arguments);
|
1335 |
|
1336 | return rgba.length < 4 || rgba[3] === 1
|
1337 | ? 'rgb(' + Math.round(rgba[0]) + ', ' + Math.round(rgba[1]) + ', ' + Math.round(rgba[2]) + ')'
|
1338 | : 'rgba(' + Math.round(rgba[0]) + ', ' + Math.round(rgba[1]) + ', ' + Math.round(rgba[2]) + ', ' + rgba[3] + ')';
|
1339 | };
|
1340 |
|
1341 | cs.to.rgb.percent = function () {
|
1342 | var rgba = simpleSwizzle(arguments);
|
1343 |
|
1344 | var r = Math.round(rgba[0] / 255 * 100);
|
1345 | var g = Math.round(rgba[1] / 255 * 100);
|
1346 | var b = Math.round(rgba[2] / 255 * 100);
|
1347 |
|
1348 | return rgba.length < 4 || rgba[3] === 1
|
1349 | ? 'rgb(' + r + '%, ' + g + '%, ' + b + '%)'
|
1350 | : 'rgba(' + r + '%, ' + g + '%, ' + b + '%, ' + rgba[3] + ')';
|
1351 | };
|
1352 |
|
1353 | cs.to.hsl = function () {
|
1354 | var hsla = simpleSwizzle(arguments);
|
1355 | return hsla.length < 4 || hsla[3] === 1
|
1356 | ? 'hsl(' + hsla[0] + ', ' + hsla[1] + '%, ' + hsla[2] + '%)'
|
1357 | : 'hsla(' + hsla[0] + ', ' + hsla[1] + '%, ' + hsla[2] + '%, ' + hsla[3] + ')';
|
1358 | };
|
1359 |
|
1360 |
|
1361 |
|
1362 | cs.to.hwb = function () {
|
1363 | var hwba = simpleSwizzle(arguments);
|
1364 |
|
1365 | var a = '';
|
1366 | if (hwba.length >= 4 && hwba[3] !== 1) {
|
1367 | a = ', ' + hwba[3];
|
1368 | }
|
1369 |
|
1370 | return 'hwb(' + hwba[0] + ', ' + hwba[1] + '%, ' + hwba[2] + '%' + a + ')';
|
1371 | };
|
1372 |
|
1373 | cs.to.keyword = function (rgb) {
|
1374 | return reverseNames[rgb.slice(0, 3)];
|
1375 | };
|
1376 |
|
1377 |
|
1378 | function clamp(num, min, max) {
|
1379 | return Math.min(Math.max(min, num), max);
|
1380 | }
|
1381 |
|
1382 | function hexDouble(num) {
|
1383 | var str = num.toString(16).toUpperCase();
|
1384 | return (str.length < 2) ? '0' + str : str;
|
1385 | }
|
1386 | });
|
1387 |
|
1388 | function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
1389 |
|
1390 | function hsl2rgb(h, s, l) {
|
1391 | s = s / 100,
|
1392 | l = l / 100;
|
1393 | if (h >= 360)
|
1394 | h %= 360;
|
1395 |
|
1396 | const c = (1 - Math.abs(2 * l - 1)) * s;
|
1397 | const x = c * (1 - Math.abs((h / 60) % 2 - 1));
|
1398 | const m = l - c/2;
|
1399 | let r = 0;
|
1400 | let g = 0;
|
1401 | let b = 0;
|
1402 |
|
1403 | if (0 <= h && h < 60) {
|
1404 | r = c; g = x; b = 0;
|
1405 | } else if (60 <= h && h < 120) {
|
1406 | r = x; g = c; b = 0;
|
1407 | } else if (120 <= h && h < 180) {
|
1408 | r = 0; g = c; b = x;
|
1409 | } else if (180 <= h && h < 240) {
|
1410 | r = 0; g = x; b = c;
|
1411 | } else if (240 <= h && h < 300) {
|
1412 | r = x; g = 0; b = c;
|
1413 | } else if (300 <= h && h < 360) {
|
1414 | r = c; g = 0; b = x;
|
1415 | }
|
1416 |
|
1417 | r = Math.round((r + m) * 255);
|
1418 | g = Math.round((g + m) * 255);
|
1419 | b = Math.round((b + m) * 255);
|
1420 | return [r, g, b];
|
1421 | }
|
1422 |
|
1423 | function hwb2rgb(h, w, b) {
|
1424 | const rgb = hsl2rgb(h, 100, 50);
|
1425 |
|
1426 | for (let i = 0; i < 3; ++i) {
|
1427 | let c = rgb[i] / 255;
|
1428 |
|
1429 | c *= 1 - w/100 - b/100;
|
1430 | c += w/100;
|
1431 |
|
1432 | rgb[i] = Math.round(c * 255);
|
1433 | }
|
1434 |
|
1435 | return rgb;
|
1436 | }
|
1437 |
|
1438 | function toRGBA(color) {
|
1439 | if (/^hsla?/.test(color)) {
|
1440 | const colorTuple = colorString.get.hsl(color);
|
1441 | if (!colorTuple) return;
|
1442 | return [...hsl2rgb(colorTuple[0], colorTuple[1], colorTuple[2]), colorTuple[3]];
|
1443 | } else if (/^rgba?/.test(color)) {
|
1444 | const colorTuple = colorString.get.rgb(color);
|
1445 | if (!colorTuple) return;
|
1446 | return colorTuple;
|
1447 | } else if (color.startsWith('hwb')) {
|
1448 | const colorTuple = colorString.get.hwb(color);
|
1449 | if (!colorTuple) return;
|
1450 | return [...hwb2rgb(colorTuple[0], colorTuple[1], colorTuple[2]), colorTuple[3]];
|
1451 | }
|
1452 | return _optionalChain([colorString, 'access', _ => _.get, 'call', _2 => _2(color), 'optionalAccess', _3 => _3.value]);
|
1453 | }
|
1454 |
|
1455 | function toRGB(color) {
|
1456 | return _optionalChain([toRGBA, 'call', _4 => _4(color), 'optionalAccess', _5 => _5.slice, 'call', _6 => _6(0, 3)]);
|
1457 | }
|
1458 |
|
1459 | function toColor(colorStr) {
|
1460 | const rgba = toRGBA(colorStr);
|
1461 | const color = rgba ? rgba.slice(0, 3).join(', ') : colorStr;
|
1462 | const opacity = rgba ? rgba[3].toString() : '1';
|
1463 |
|
1464 | return {
|
1465 | color,
|
1466 | opacity,
|
1467 | };
|
1468 | }
|
1469 |
|
1470 | const utilities = {
|
1471 |
|
1472 | container: [
|
1473 | 'container',
|
1474 | ],
|
1475 | objectPosition: [
|
1476 | 'object-${static}',
|
1477 | ],
|
1478 | inset: [
|
1479 | 'inset-${static}',
|
1480 | 'inset-${float}',
|
1481 | 'inset-${fraction}',
|
1482 | 'inset-${size}',
|
1483 |
|
1484 | 'inset-y-${static}',
|
1485 | 'inset-y-${float}',
|
1486 | 'inset-y-${fraction}',
|
1487 | 'inset-y-${size}',
|
1488 |
|
1489 | 'inset-x-${static}',
|
1490 | 'inset-x-${float}',
|
1491 | 'inset-x-${fraction}',
|
1492 | 'inset-x-${size}',
|
1493 |
|
1494 | 'top-${static}',
|
1495 | 'top-${float}',
|
1496 | 'top-${fraction}',
|
1497 | 'top-${size}',
|
1498 |
|
1499 | 'right-${static}',
|
1500 | 'right-${float}',
|
1501 | 'right-${fraction}',
|
1502 | 'right-${size}',
|
1503 |
|
1504 | 'bottom-${static}',
|
1505 | 'bottom-${float}',
|
1506 | 'bottom-${fraction}',
|
1507 | 'bottom-${size}',
|
1508 |
|
1509 | 'left-${static}',
|
1510 | 'left-${float}',
|
1511 | 'left-${fraction}',
|
1512 | 'left-${size}',
|
1513 | ],
|
1514 | zIndex: [
|
1515 | 'z-${static}',
|
1516 | 'z-${int}',
|
1517 | ],
|
1518 |
|
1519 | flex: [
|
1520 | 'flex-${static}',
|
1521 | ],
|
1522 | flexGrow: [
|
1523 | 'flex-grow-${static}',
|
1524 | ],
|
1525 | flexShrink: [
|
1526 | 'flex-shrink-${static}',
|
1527 | ],
|
1528 | order: [
|
1529 | 'order-${static}',
|
1530 | 'order-${int}',
|
1531 | ],
|
1532 |
|
1533 | gridTemplateColumns: [
|
1534 | 'grid-cols-${static}',
|
1535 | 'grid-cols-${int}',
|
1536 | ],
|
1537 | gridTemplateRows: [
|
1538 | 'grid-rows-${static}',
|
1539 | 'grid-rows-${int}',
|
1540 | ],
|
1541 | gridColumn: [
|
1542 | 'col-${static}',
|
1543 | 'col-span-${int}',
|
1544 | ],
|
1545 | gridColumnEnd: [
|
1546 | 'col-end-${static}',
|
1547 | 'col-end-${int}',
|
1548 | ],
|
1549 | gridColumnStart: [
|
1550 | 'col-start-${static}',
|
1551 | 'col-start-${int}',
|
1552 | ],
|
1553 | gridRow: [
|
1554 | 'row-${static}',
|
1555 | 'row-span-${int}',
|
1556 | ],
|
1557 | gridRowEnd: [
|
1558 | 'row-end-${static}',
|
1559 | 'row-end-${int}',
|
1560 | ],
|
1561 | gridRowStart: [
|
1562 | 'row-start-${static}',
|
1563 | 'row-start-${int}',
|
1564 | ],
|
1565 | gap: [
|
1566 | 'gap-${static}',
|
1567 | 'gap-x-${static}',
|
1568 | 'gap-y-${static}',
|
1569 |
|
1570 | 'gap-${float}',
|
1571 | 'gap-x-${float}',
|
1572 | 'gap-y-${float}',
|
1573 |
|
1574 | 'gap-${size}',
|
1575 | 'gap-x-${size}',
|
1576 | 'gap-y-${size}',
|
1577 | ],
|
1578 |
|
1579 |
|
1580 | padding: [
|
1581 | 'p-${static}',
|
1582 | 'py-${static}',
|
1583 | 'px-${static}',
|
1584 | 'pt-${static}',
|
1585 | 'pr-${static}',
|
1586 | 'pb-${static}',
|
1587 | 'pl-${static}',
|
1588 |
|
1589 | 'p-${float}',
|
1590 | 'py-${float}',
|
1591 | 'px-${float}',
|
1592 | 'pt-${float}',
|
1593 | 'pr-${float}',
|
1594 | 'pb-${float}',
|
1595 | 'pl-${float}',
|
1596 |
|
1597 | 'p-${size}',
|
1598 | 'py-${size}',
|
1599 | 'px-${size}',
|
1600 | 'pt-${size}',
|
1601 | 'pr-${size}',
|
1602 | 'pb-${size}',
|
1603 | 'pl-${size}',
|
1604 | ],
|
1605 | margin: [
|
1606 | 'm-${static}',
|
1607 | 'my-${static}',
|
1608 | 'mx-${static}',
|
1609 | 'mt-${static}',
|
1610 | 'mr-${static}',
|
1611 | 'mb-${static}',
|
1612 | 'ml-${static}',
|
1613 |
|
1614 | 'm-${float}',
|
1615 | 'my-${float}',
|
1616 | 'mx-${float}',
|
1617 | 'mt-${float}',
|
1618 | 'mr-${float}',
|
1619 | 'mb-${float}',
|
1620 | 'ml-${float}',
|
1621 |
|
1622 | 'm-${size}',
|
1623 | 'my-${size}',
|
1624 | 'mx-${size}',
|
1625 | 'mt-${size}',
|
1626 | 'mr-${size}',
|
1627 | 'mb-${size}',
|
1628 | 'ml-${size}',
|
1629 | ],
|
1630 | space: [
|
1631 | 'space-y-${static}',
|
1632 | 'space-y-reverse',
|
1633 | 'space-x-${static}',
|
1634 | 'space-x-reverse',
|
1635 | 'space-y-${float}',
|
1636 | 'space-x-${float}',
|
1637 | ],
|
1638 | width: [
|
1639 | 'w-${static}',
|
1640 | 'w-${float}',
|
1641 | 'w-${fraction}',
|
1642 | 'w-${int}xl',
|
1643 | 'w-${size}',
|
1644 | ],
|
1645 | minWidth: [
|
1646 | 'min-w-${static}',
|
1647 | 'min-w-${float}',
|
1648 | 'min-w-${fraction}',
|
1649 | 'min-w-${int}xl',
|
1650 | 'min-w-${size}',
|
1651 | ],
|
1652 | maxWidth: [
|
1653 | 'max-w-${static}',
|
1654 | 'max-w-${float}',
|
1655 | 'max-w-${fraction}',
|
1656 | 'max-w-${int}xl',
|
1657 | 'max-w-${size}',
|
1658 | ],
|
1659 | height: [
|
1660 | 'h-${static}',
|
1661 | 'h-${float}',
|
1662 | 'h-${fraction}',
|
1663 | 'h-${int}xl',
|
1664 | 'h-${size}',
|
1665 | ],
|
1666 | minHeight: [
|
1667 | 'min-h-${static}',
|
1668 | 'min-h-${float}',
|
1669 | 'min-h-${fraction}',
|
1670 | 'min-h-${int}xl',
|
1671 | 'min-h-${size}',
|
1672 | ],
|
1673 | maxHeight: [
|
1674 | 'max-h-${static}',
|
1675 | 'max-h-${float}',
|
1676 | 'max-h-${fraction}',
|
1677 | 'max-h-${int}xl',
|
1678 | 'max-h-${size}',
|
1679 | ],
|
1680 |
|
1681 | fontSize: [
|
1682 | 'text-${static}',
|
1683 | 'text-${int}xl',
|
1684 | ],
|
1685 | textOpacity: [
|
1686 | 'text-opacity-${static}',
|
1687 | 'text-opacity-${int<=100}',
|
1688 | ],
|
1689 | textColor: [
|
1690 | 'text-${color}',
|
1691 | ],
|
1692 | fontFamily: [
|
1693 | 'font-${static}',
|
1694 | ],
|
1695 | fontWeight: [
|
1696 | 'font-${static}',
|
1697 | 'font-${int}',
|
1698 | ],
|
1699 | letterSpacing: [
|
1700 | 'tracking-${static}',
|
1701 | 'tracking-${size}',
|
1702 | ],
|
1703 | lineHeight: [
|
1704 | 'leading-${static}',
|
1705 | 'leading-${int}',
|
1706 | 'leading-${size}',
|
1707 | ],
|
1708 | listStyleType: [
|
1709 | 'list-${static}',
|
1710 | ],
|
1711 | placeholderColor: [
|
1712 | 'placeholder-${color}',
|
1713 | ],
|
1714 | placeholderOpacity: [
|
1715 | 'placeholder-opacity-${static}',
|
1716 | 'placeholder-opacity-${int<=100}',
|
1717 | ],
|
1718 |
|
1719 | backgroundColor: [
|
1720 | 'bg-${color}',
|
1721 | ],
|
1722 | backgroundOpacity: [
|
1723 | 'bg-opacity-${static}',
|
1724 | 'bg-opacity-${int<=100}',
|
1725 | ],
|
1726 | backgroundPosition: [
|
1727 | 'bg-${static}',
|
1728 | ],
|
1729 | backgroundSize: [
|
1730 | 'bg-${static}',
|
1731 | ],
|
1732 | backgroundImage: [
|
1733 | 'bg-${static}',
|
1734 | ],
|
1735 | gradientColorStops: [
|
1736 | 'from-${color}',
|
1737 | 'via-${color}',
|
1738 | 'to-${color}',
|
1739 | ],
|
1740 |
|
1741 | borderRadius: [
|
1742 | 'rounded-${static}',
|
1743 | 'rounded-t-${static}',
|
1744 | 'rounded-l-${static}',
|
1745 | 'rounded-r-${static}',
|
1746 | 'rounded-b-${static}',
|
1747 | 'rounded-tl-${static}',
|
1748 | 'rounded-tr-${static}',
|
1749 | 'rounded-br-${static}',
|
1750 | 'rounded-bl-${static}',
|
1751 |
|
1752 | 'rounded-${int}xl',
|
1753 | 'rounded-${size}',
|
1754 | 'rounded-t-${int}xl',
|
1755 | 'rounded-t-${size}',
|
1756 | 'rounded-l-${int}xl',
|
1757 | 'rounded-l-${size}',
|
1758 | 'rounded-r-${int}xl',
|
1759 | 'rounded-r-${size}',
|
1760 | 'rounded-b-${int}xl',
|
1761 | 'rounded-b-${size}',
|
1762 | 'rounded-tl-${int}xl',
|
1763 | 'rounded-tl-${size}',
|
1764 | 'rounded-tr-${int}xl',
|
1765 | 'rounded-tr-${size}',
|
1766 | 'rounded-br-${int}xl',
|
1767 | 'rounded-br-${size}',
|
1768 | 'rounded-bl-${int}xl',
|
1769 | 'rounded-bl-${size}',
|
1770 | ],
|
1771 | borderWidth: [
|
1772 | 'border-${static}',
|
1773 | 'border-${int}',
|
1774 | 'border-${size}',
|
1775 | 'border-t-${int}',
|
1776 | 'border-t-${size}',
|
1777 | 'border-r-${int}',
|
1778 | 'border-r-${size}',
|
1779 | 'border-b-${int}',
|
1780 | 'border-b-${size}',
|
1781 | 'border-l-${int}',
|
1782 | 'border-l-${size}',
|
1783 | ],
|
1784 | borderColor: [
|
1785 | 'border-${color}',
|
1786 | ],
|
1787 | borderOpacity: [
|
1788 | 'border-opacity-${static}',
|
1789 | 'border-opacity-${int<=100}',
|
1790 | ],
|
1791 | divideWidth: [
|
1792 | 'divide-y-reverse',
|
1793 | 'divide-x-reverse',
|
1794 | 'divide-y-${int}',
|
1795 | 'divide-x-${int}',
|
1796 | ],
|
1797 | divideColor: [
|
1798 | 'divide-${color}',
|
1799 | ],
|
1800 | divideOpacity: [
|
1801 | 'divide-${static}',
|
1802 | 'divide-opacity-${int<=100}',
|
1803 | ],
|
1804 | ringOffsetWidth: [
|
1805 | 'ring-offset-${static}',
|
1806 | 'ring-offset-${int}',
|
1807 | ],
|
1808 | ringOffsetColor: [
|
1809 | 'ring-offset-${color}',
|
1810 | ],
|
1811 | ringWidth: [
|
1812 | 'ring-${static}',
|
1813 | 'ring-${int}',
|
1814 | ],
|
1815 | ringColor: [
|
1816 | 'ring-${color}',
|
1817 | ],
|
1818 | ringOpacity: [
|
1819 | 'ring-${static}',
|
1820 | 'ring-opacity-${int<=100}',
|
1821 | ],
|
1822 |
|
1823 | boxShadow: [
|
1824 | 'shadow-${static}',
|
1825 | ],
|
1826 | opacity: [
|
1827 | 'opacity-${static}',
|
1828 | 'opacity-${int<=100}',
|
1829 | ],
|
1830 | transition: [
|
1831 | 'transition-${static}',
|
1832 | ],
|
1833 | transitionDuration: [
|
1834 | 'duration-${static}',
|
1835 | 'duration-${int}',
|
1836 | ],
|
1837 | transitionTimingFunction: [
|
1838 | 'ease-${static}',
|
1839 | ],
|
1840 | transitionDelay: [
|
1841 | 'delay-${static}',
|
1842 | 'delay-${int}',
|
1843 | ],
|
1844 | animation: [
|
1845 | 'animate-${static}',
|
1846 | ],
|
1847 |
|
1848 | transformOrigin: [
|
1849 | 'origin-${static}',
|
1850 | ],
|
1851 | scale: [
|
1852 | 'scale-${static}',
|
1853 | 'scale-${int}',
|
1854 | 'scale-x-${static}',
|
1855 | 'scale-x-${int}',
|
1856 | 'scale-y-${static}',
|
1857 | 'scale-y-${int}',
|
1858 | ],
|
1859 | rotate: [
|
1860 | 'rotate-${static}',
|
1861 | 'rotate-${float}',
|
1862 | ],
|
1863 | translate: [
|
1864 | 'translate-${static}',
|
1865 | 'translate-x-${static}',
|
1866 | 'translate-y-${static}',
|
1867 | 'translate-x-${float}',
|
1868 | 'translate-x-${fraction}',
|
1869 | 'translate-x-${size}',
|
1870 | 'translate-y-${float}',
|
1871 | 'translate-y-${fraction}',
|
1872 | 'translate-y-${size}',
|
1873 | ],
|
1874 | skew: [
|
1875 | 'skew-x-${static}',
|
1876 | 'skew-x-${float}',
|
1877 | 'skew-y-${static}',
|
1878 | 'skew-y-${float}',
|
1879 | ],
|
1880 | cursor: [
|
1881 | 'cursor-${static}',
|
1882 | ],
|
1883 |
|
1884 | outline: [
|
1885 | 'outline-${static}',
|
1886 | ],
|
1887 | outlineColor: [
|
1888 | 'outline-${color}',
|
1889 | 'outline-solid-${color}',
|
1890 | 'outline-dotted-${color}',
|
1891 | ],
|
1892 |
|
1893 | fill: [
|
1894 | 'fill-${color}',
|
1895 | ],
|
1896 |
|
1897 | stroke: [
|
1898 | 'stroke-${color}',
|
1899 | ],
|
1900 | strokeWidth: [
|
1901 | 'stroke-${int}',
|
1902 | ],
|
1903 |
|
1904 |
|
1905 | typography: [
|
1906 | 'prose-sm',
|
1907 | 'prose',
|
1908 | 'prose-lg',
|
1909 | 'prose-xl',
|
1910 | 'prose-2xl',
|
1911 | 'prose-red',
|
1912 | 'prose-yellow',
|
1913 | 'prose-green',
|
1914 | 'prose-blue',
|
1915 | 'prose-indigo',
|
1916 | 'prose-purple',
|
1917 | 'prose-pink',
|
1918 | ],
|
1919 | aspectRatio: [
|
1920 | 'aspect-none',
|
1921 | 'aspect-w-${float}',
|
1922 | 'aspect-h-${float}',
|
1923 | 'aspect-${fraction}',
|
1924 | ],
|
1925 | lineClamp: [
|
1926 | 'line-clamp-none',
|
1927 | 'line-clamp-${int}',
|
1928 | ],
|
1929 | filter: [
|
1930 | 'filter-${static}',
|
1931 | ],
|
1932 | backdropFilter: [
|
1933 | 'backdrop-${static}',
|
1934 | ],
|
1935 | blur: [
|
1936 | 'blur-${static}',
|
1937 | 'blur-${float}',
|
1938 | 'blur-${size}',
|
1939 | ],
|
1940 | };
|
1941 |
|
1942 | const negative = {
|
1943 | inset: true,
|
1944 | zIndex: true,
|
1945 | order: true,
|
1946 | margin: true,
|
1947 | space: true,
|
1948 | letterSpacing: true,
|
1949 | rotate: true,
|
1950 | translate: true,
|
1951 | skew: true,
|
1952 | };
|
1953 |
|
1954 | function generateCompletions(processor) {
|
1955 | const completions
|
1956 |
|
1957 |
|
1958 |
|
1959 | = { static: [], color: [], dynamic: [] };
|
1960 | const colors = flatColors(processor.theme('colors') );
|
1961 | for (const [config, list] of Object.entries(utilities)) {
|
1962 | list.forEach(utility => {
|
1963 | const mark = utility.search(/\$/);
|
1964 | if (mark === -1) {
|
1965 | completions.static.push(utility);
|
1966 | } else {
|
1967 | const prefix = utility.slice(0, mark-1);
|
1968 | const suffix = utility.slice(mark);
|
1969 | switch(suffix) {
|
1970 | case '${static}':
|
1971 | completions.static = completions.static.concat(Object.keys(processor.theme(config, {}) ).map(i => i === 'DEFAULT' ? prefix : i.charAt(0) === '-' ? `-${prefix}${i}` : `${prefix}-${i}`));
|
1972 | break;
|
1973 | case '${color}':
|
1974 | for (const key of Object.keys(flatColors(processor.theme(config, colors) ))) {
|
1975 | if (key !== 'DEFAULT')
|
1976 | completions.color.push(`${prefix}-${key}`);
|
1977 | }
|
1978 | break;
|
1979 | default:
|
1980 | completions.dynamic.push(utility);
|
1981 | if (config in negative) completions.dynamic.push(`-${utility}`);
|
1982 | break;
|
1983 | }
|
1984 | }
|
1985 | });
|
1986 | }
|
1987 | return completions;
|
1988 | }
|
1989 |
|
1990 | export { breakpoints, camelToDash, connectList, dashToCamel, deepCopy, expandDirection, flatColors, fracToPercent, generateCompletions, generateFontSize, generatePlaceholder, getNestedValue, guessClassName, hash, hex2RGB, hsl2rgb, hwb2rgb, increaseWithUnit, indent, isFraction, isNumber, isSize, isSpace, isString, isTagName, negateValue, negative$1 as negative, roundUp, searchFrom, searchNotEscape, searchPropEnd, splitColorGroup, splitSelectors, testRegexr, toArray, toColor, toDarkStyle, toRGB, toRGBA, toType, type, wrapit };
|