@master/css 2.0.0-rc.40 → 2.0.0-rc.42
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/dist/config/index.cjs +5 -4
- package/dist/config/index.d.ts +9 -8
- package/dist/config/index.mjs +5 -4
- package/dist/config/{rules.cjs → syntaxes.cjs} +5 -5
- package/dist/config/syntaxes.d.ts +282 -0
- package/dist/config/{rules.mjs → syntaxes.mjs} +5 -5
- package/dist/config/utilities.cjs +2 -1
- package/dist/config/utilities.d.ts +1 -0
- package/dist/config/utilities.mjs +2 -1
- package/dist/config/variables.cjs +213 -2
- package/dist/config/variables.d.ts +432 -377
- package/dist/config/variables.mjs +213 -2
- package/dist/core.cjs +74 -68
- package/dist/core.d.ts +3 -3
- package/dist/core.mjs +74 -68
- package/dist/index.cjs +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +2 -2
- package/dist/polyfills/css-escape2.cjs +1 -1
- package/dist/polyfills/css-escape2.mjs +1 -1
- package/dist/rule.cjs +1 -1
- package/dist/rule.d.ts +2 -2
- package/dist/rule.mjs +1 -1
- package/dist/utils/autofill-solid-style.d.ts +2 -2
- package/dist/utils/extend-config.cjs +1 -0
- package/dist/utils/extend-config.mjs +1 -0
- package/dist/utils/is-core-rule.cjs +2 -2
- package/dist/utils/is-core-rule.mjs +2 -2
- package/dist/utils/reorder-for-readable-classes.cjs +1 -1
- package/dist/utils/reorder-for-readable-classes.mjs +1 -1
- package/package.json +1 -1
- package/dist/config/rules.d.ts +0 -282
- /package/dist/utils/{are-rules-duplicated.cjs → are-syntaxes-duplicated.cjs} +0 -0
- /package/dist/utils/{are-rules-duplicated.d.ts → are-syntaxes-duplicated.d.ts} +0 -0
- /package/dist/utils/{are-rules-duplicated.mjs → are-syntaxes-duplicated.mjs} +0 -0
package/dist/core.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type Variable = TypeVariable & VariableCommon;
|
|
|
28
28
|
export default class MasterCSS {
|
|
29
29
|
customConfig?: Config | undefined;
|
|
30
30
|
static config: Config;
|
|
31
|
-
readonly
|
|
31
|
+
readonly syntaxes: Rule[];
|
|
32
32
|
readonly ruleBy: Record<string, Rule>;
|
|
33
33
|
readonly classesUsage: Record<string, number>;
|
|
34
34
|
readonly config: Config;
|
|
@@ -42,7 +42,7 @@ export default class MasterCSS {
|
|
|
42
42
|
*/
|
|
43
43
|
match(className: string): RegisteredRule | undefined;
|
|
44
44
|
/**
|
|
45
|
-
* Generate
|
|
45
|
+
* Generate syntaxes from class name
|
|
46
46
|
* @param className
|
|
47
47
|
* @returns Rule[]
|
|
48
48
|
*/
|
|
@@ -84,7 +84,7 @@ export default class MasterCSS {
|
|
|
84
84
|
}
|
|
85
85
|
export declare const masterCSSs: MasterCSS[];
|
|
86
86
|
export default interface MasterCSS {
|
|
87
|
-
|
|
87
|
+
style: HTMLStyleElement;
|
|
88
88
|
styles: Record<string, string[]>;
|
|
89
89
|
stylesBy: Record<string, string[]>;
|
|
90
90
|
selectors: Record<string, [RegExp, string[]][]>;
|
package/dist/core.mjs
CHANGED
|
@@ -8,14 +8,14 @@ import extendConfig from './utils/extend-config.mjs';
|
|
|
8
8
|
class MasterCSS {
|
|
9
9
|
customConfig;
|
|
10
10
|
static config = config;
|
|
11
|
-
|
|
11
|
+
syntaxes;
|
|
12
12
|
ruleBy;
|
|
13
13
|
classesUsage;
|
|
14
14
|
config;
|
|
15
15
|
Rules;
|
|
16
16
|
constructor(customConfig){
|
|
17
17
|
this.customConfig = customConfig;
|
|
18
|
-
this.
|
|
18
|
+
this.syntaxes = [];
|
|
19
19
|
this.ruleBy = {};
|
|
20
20
|
this.classesUsage = {};
|
|
21
21
|
this.Rules = [];
|
|
@@ -44,7 +44,7 @@ class MasterCSS {
|
|
|
44
44
|
currentColor: undefined,
|
|
45
45
|
transparent: undefined
|
|
46
46
|
};
|
|
47
|
-
const { styles, selectors, variables, utilities, at,
|
|
47
|
+
const { styles, selectors, variables, utilities, at, syntaxes, animations } = this.config;
|
|
48
48
|
function escapeString(str) {
|
|
49
49
|
return str.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
50
50
|
}
|
|
@@ -313,7 +313,7 @@ class MasterCSS {
|
|
|
313
313
|
for (const eachUtilityName of utilityNames){
|
|
314
314
|
handleUtilityName(eachUtilityName);
|
|
315
315
|
}
|
|
316
|
-
if (
|
|
316
|
+
if (syntaxes || utilities) {
|
|
317
317
|
const rulesEntries = [];
|
|
318
318
|
if (utilities) {
|
|
319
319
|
for(const utilityName in utilities){
|
|
@@ -327,8 +327,8 @@ class MasterCSS {
|
|
|
327
327
|
]);
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
|
-
if (
|
|
331
|
-
rulesEntries.push(...Object.entries(
|
|
330
|
+
if (syntaxes) {
|
|
331
|
+
rulesEntries.push(...Object.entries(syntaxes));
|
|
332
332
|
}
|
|
333
333
|
const rulesEntriesLength = rulesEntries.length;
|
|
334
334
|
const colorNames = Object.keys(colorVariableNames);
|
|
@@ -337,17 +337,17 @@ class MasterCSS {
|
|
|
337
337
|
return (b[1].layer || 0) - (a[1].layer || 0);
|
|
338
338
|
}
|
|
339
339
|
return b[0].localeCompare(a[0]);
|
|
340
|
-
}).forEach(([id,
|
|
340
|
+
}).forEach(([id, eachSyntaxDefinition], index)=>{
|
|
341
341
|
const EachRule = {
|
|
342
342
|
id,
|
|
343
343
|
keys: [],
|
|
344
344
|
variables: {},
|
|
345
345
|
matchers: {},
|
|
346
346
|
order: rulesEntriesLength - 1 - index,
|
|
347
|
-
definition:
|
|
347
|
+
definition: eachSyntaxDefinition
|
|
348
348
|
};
|
|
349
349
|
this.Rules.push(EachRule);
|
|
350
|
-
const { matcher, layer, subkey, ambiguousKeys, ambiguousValues, sign } =
|
|
350
|
+
const { matcher, layer, subkey, ambiguousKeys, ambiguousValues, sign } = eachSyntaxDefinition;
|
|
351
351
|
if (layer === Layer.Utility) {
|
|
352
352
|
EachRule.id = '.' + id;
|
|
353
353
|
EachRule.matchers.arbitrary = new RegExp('^' + escapeString(id) + '(?=!|\\*|>|\\+|~|:|\\[|@|_|\\.|$)', 'm');
|
|
@@ -361,18 +361,18 @@ class MasterCSS {
|
|
|
361
361
|
}
|
|
362
362
|
}
|
|
363
363
|
};
|
|
364
|
-
// 1. custom `config.
|
|
365
|
-
if (
|
|
366
|
-
for (const eachVariableGroup of
|
|
364
|
+
// 1. custom `config.syntaxes[id].variables`
|
|
365
|
+
if (eachSyntaxDefinition.variables) {
|
|
366
|
+
for (const eachVariableGroup of eachSyntaxDefinition.variables){
|
|
367
367
|
addResolvedVariables(eachVariableGroup);
|
|
368
368
|
}
|
|
369
369
|
}
|
|
370
370
|
// 2. custom `config.variables`
|
|
371
371
|
addResolvedVariables(id);
|
|
372
372
|
const keys = [];
|
|
373
|
-
let { key } =
|
|
373
|
+
let { key } = eachSyntaxDefinition;
|
|
374
374
|
if (layer === Layer.NativeShorthand || layer === Layer.Native) {
|
|
375
|
-
if (!key)
|
|
375
|
+
if (!key) eachSyntaxDefinition.key = key = id;
|
|
376
376
|
keys.push(id);
|
|
377
377
|
}
|
|
378
378
|
if (sign) {
|
|
@@ -447,13 +447,13 @@ class MasterCSS {
|
|
|
447
447
|
}
|
|
448
448
|
}
|
|
449
449
|
/**
|
|
450
|
-
* Generate
|
|
450
|
+
* Generate syntaxes from class name
|
|
451
451
|
* @param className
|
|
452
452
|
* @returns Rule[]
|
|
453
453
|
*/ generate(className) {
|
|
454
454
|
return (Object.prototype.hasOwnProperty.call(this.styles, className) ? this.styles[className].map((eachSyntax)=>this.create(eachSyntax)) : [
|
|
455
455
|
this.create(className)
|
|
456
|
-
]).filter((
|
|
456
|
+
]).filter((eachSyntax)=>eachSyntax && eachSyntax?.text);
|
|
457
457
|
}
|
|
458
458
|
/**
|
|
459
459
|
* Create rule from given syntax
|
|
@@ -482,12 +482,12 @@ class MasterCSS {
|
|
|
482
482
|
this.config = extendConfig(customConfig);
|
|
483
483
|
}
|
|
484
484
|
this.resolve();
|
|
485
|
-
this.
|
|
485
|
+
this.syntaxes.length = 0;
|
|
486
486
|
// @ts-ignore
|
|
487
487
|
this.ruleBy = {};
|
|
488
488
|
/**
|
|
489
|
-
* 拿當前所有的 classNames 按照最新的 colors, config.
|
|
490
|
-
* 所以 refresh 過後
|
|
489
|
+
* 拿當前所有的 classNames 按照最新的 colors, config.syntaxes 匹配並生成新的 style
|
|
490
|
+
* 所以 refresh 過後 syntaxes 可能會變多也可能會變少
|
|
491
491
|
*/ for(const name in this.classesUsage){
|
|
492
492
|
this.add(name);
|
|
493
493
|
}
|
|
@@ -498,7 +498,7 @@ class MasterCSS {
|
|
|
498
498
|
this.ruleBy = {};
|
|
499
499
|
// @ts-ignore
|
|
500
500
|
this.classesUsage = {};
|
|
501
|
-
this.
|
|
501
|
+
this.syntaxes.length = 0;
|
|
502
502
|
this.hasKeyframesRule = false;
|
|
503
503
|
this.variablesNativeRules = {};
|
|
504
504
|
for(const keyframeName in this.animations){
|
|
@@ -519,9 +519,9 @@ class MasterCSS {
|
|
|
519
519
|
}
|
|
520
520
|
add(...classNames) {
|
|
521
521
|
for (const className of classNames){
|
|
522
|
-
const
|
|
523
|
-
if (
|
|
524
|
-
for (const rule of
|
|
522
|
+
const syntaxes = this.generate(className);
|
|
523
|
+
if (syntaxes.length) {
|
|
524
|
+
for (const rule of syntaxes){
|
|
525
525
|
this.insert(rule);
|
|
526
526
|
}
|
|
527
527
|
}
|
|
@@ -548,7 +548,7 @@ class MasterCSS {
|
|
|
548
548
|
}
|
|
549
549
|
}
|
|
550
550
|
}
|
|
551
|
-
this.
|
|
551
|
+
this.syntaxes.splice(this.syntaxes.indexOf(rule), 1);
|
|
552
552
|
delete this.ruleBy[name];
|
|
553
553
|
// variables
|
|
554
554
|
if (rule.variableNames) {
|
|
@@ -560,13 +560,13 @@ class MasterCSS {
|
|
|
560
560
|
const nativeRule = this.variablesNativeRules[mode];
|
|
561
561
|
nativeRule.cssRule.style.removeProperty('--' + eachVariableName);
|
|
562
562
|
if (!nativeRule.cssRule.style.length) {
|
|
563
|
-
const variablesRule = this.
|
|
563
|
+
const variablesRule = this.syntaxes[0];
|
|
564
564
|
const index = variablesRule.natives.indexOf(nativeRule);
|
|
565
565
|
sheet?.deleteRule(index);
|
|
566
566
|
variablesRule.natives.splice(index, 1);
|
|
567
567
|
delete this.variablesNativeRules[mode];
|
|
568
568
|
if (!variablesRule.natives.length) {
|
|
569
|
-
this.
|
|
569
|
+
this.syntaxes.splice(0, 1);
|
|
570
570
|
this.variablesNativeRules = {};
|
|
571
571
|
}
|
|
572
572
|
}
|
|
@@ -585,7 +585,7 @@ class MasterCSS {
|
|
|
585
585
|
// animations
|
|
586
586
|
if (rule.animationNames) {
|
|
587
587
|
const keyframeRulesIndex = Object.keys(this.variablesNativeRules).length ? 1 : 0;
|
|
588
|
-
const keyframeRule = this.
|
|
588
|
+
const keyframeRule = this.syntaxes[keyframeRulesIndex];
|
|
589
589
|
for (const eachKeyframeName of rule.animationNames){
|
|
590
590
|
const keyframe = this.animations[eachKeyframeName];
|
|
591
591
|
if (!keyframe.usage) keyframe.usage = 0;
|
|
@@ -597,7 +597,7 @@ class MasterCSS {
|
|
|
597
597
|
}
|
|
598
598
|
}
|
|
599
599
|
if (!keyframeRule.natives.length) {
|
|
600
|
-
this.
|
|
600
|
+
this.syntaxes.splice(keyframeRulesIndex, 1);
|
|
601
601
|
this.hasKeyframesRule = false;
|
|
602
602
|
}
|
|
603
603
|
}
|
|
@@ -638,28 +638,28 @@ class MasterCSS {
|
|
|
638
638
|
* 以實現響應式先後套用的規則
|
|
639
639
|
* @example <1 <2 <3 ALL >=1 >=2 >=3
|
|
640
640
|
* @description
|
|
641
|
-
*/ const endIndex = this.
|
|
641
|
+
*/ const endIndex = this.syntaxes.length - 1;
|
|
642
642
|
const { at, atToken, order, priority, hasWhere, className } = rule;
|
|
643
643
|
const findIndex = (startIndex, stopCheck, matchCheck)=>{
|
|
644
644
|
let i = startIndex;
|
|
645
645
|
for(; i <= endIndex; i++){
|
|
646
|
-
const
|
|
647
|
-
if (stopCheck?.(
|
|
648
|
-
if (matchCheck?.(
|
|
646
|
+
const eachSyntax = this.syntaxes[i];
|
|
647
|
+
if (stopCheck?.(eachSyntax)) return matchCheck ? -1 : i - 1;
|
|
648
|
+
if (matchCheck?.(eachSyntax)) return i;
|
|
649
649
|
}
|
|
650
650
|
return matchCheck ? -1 : i - 1;
|
|
651
651
|
};
|
|
652
652
|
let matchStartIndex;
|
|
653
653
|
let matchEndIndex;
|
|
654
654
|
if (atToken) {
|
|
655
|
-
const mediaStartIndex = this.
|
|
655
|
+
const mediaStartIndex = this.syntaxes.findIndex((eachSyntax)=>eachSyntax.at?.media);
|
|
656
656
|
if (mediaStartIndex === -1) {
|
|
657
657
|
index = endIndex + 1;
|
|
658
658
|
} else {
|
|
659
659
|
const maxWidthFeature = at.media?.find(({ name })=>name === 'max-width');
|
|
660
660
|
const minWidthFeature = at.media?.find(({ name })=>name === 'min-width');
|
|
661
661
|
if (maxWidthFeature || minWidthFeature) {
|
|
662
|
-
const mediaWidthStartIndex = this.
|
|
662
|
+
const mediaWidthStartIndex = this.syntaxes.findIndex((eachSyntax)=>eachSyntax.at?.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
|
|
663
663
|
if (mediaWidthStartIndex === -1) {
|
|
664
664
|
index = endIndex + 1;
|
|
665
665
|
} else {
|
|
@@ -670,10 +670,10 @@ class MasterCSS {
|
|
|
670
670
|
* find 第一個所遇到同樣 feature 且範圍值比自己大的 rule,
|
|
671
671
|
* 並插入在該 rule 之後,讓自己優先被套用
|
|
672
672
|
*/ if (priority === -1) {
|
|
673
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (
|
|
674
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (
|
|
673
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.priority !== -1, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width'));
|
|
674
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.priority !== -1);
|
|
675
675
|
} else {
|
|
676
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (
|
|
676
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width') && eachSyntax.priority !== -1);
|
|
677
677
|
matchEndIndex = endIndex;
|
|
678
678
|
}
|
|
679
679
|
if (matchStartIndex !== -1) {
|
|
@@ -682,9 +682,9 @@ class MasterCSS {
|
|
|
682
682
|
const endI = matchStartIndex;
|
|
683
683
|
matchStartIndex = matchEndIndex + 1;
|
|
684
684
|
for(; i >= endI; i--){
|
|
685
|
-
const
|
|
686
|
-
const eachMaxWidthFeature =
|
|
687
|
-
const eachMinWidthFeature =
|
|
685
|
+
const eachSyntax = this.syntaxes[i];
|
|
686
|
+
const eachMaxWidthFeature = eachSyntax.at.media?.find(({ name })=>name === 'max-width');
|
|
687
|
+
const eachMinWidthFeature = eachSyntax.at.media?.find(({ name })=>name === 'min-width');
|
|
688
688
|
if (!eachMaxWidthFeature || !eachMinWidthFeature) {
|
|
689
689
|
break;
|
|
690
690
|
} else {
|
|
@@ -704,15 +704,15 @@ class MasterCSS {
|
|
|
704
704
|
* find 第一個所遇到同樣 feature 且值比自己大的 rule,
|
|
705
705
|
* 並插入在該 rule 之後,讓自己優先被套用
|
|
706
706
|
*/ if (priority === -1) {
|
|
707
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (
|
|
708
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (
|
|
707
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width') || eachSyntax.priority !== -1, (eachSyntax)=>!eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width'));
|
|
708
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width') || eachSyntax.priority !== -1);
|
|
709
709
|
} else {
|
|
710
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (
|
|
711
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (
|
|
710
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width') && eachSyntax.priority !== -1, (eachSyntax)=>!eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width') && eachSyntax.priority !== -1);
|
|
711
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.at.media?.find(({ name })=>name === 'min-width') && eachSyntax.priority !== -1);
|
|
712
712
|
}
|
|
713
713
|
if (matchStartIndex !== -1) {
|
|
714
714
|
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
715
|
-
const value = (this.
|
|
715
|
+
const value = (this.syntaxes[i].at.media?.find(({ name })=>name === 'min-width')).value;
|
|
716
716
|
if (value > minWidthFeature.value) {
|
|
717
717
|
matchEndIndex = i - 1;
|
|
718
718
|
} else if (value < minWidthFeature.value) {
|
|
@@ -726,15 +726,15 @@ class MasterCSS {
|
|
|
726
726
|
* find 第一個所遇到同樣 feature 且值比自己大的 rule,
|
|
727
727
|
* 並插入在該 rule 之後,讓自己優先被套用
|
|
728
728
|
*/ if (priority === -1) {
|
|
729
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (
|
|
730
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (
|
|
729
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'min-width') || eachSyntax.priority !== -1, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width'));
|
|
730
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'min-width') || eachSyntax.priority !== -1);
|
|
731
731
|
} else {
|
|
732
|
-
matchStartIndex = findIndex(mediaWidthStartIndex, (
|
|
733
|
-
matchEndIndex = findIndex(mediaWidthStartIndex, (
|
|
732
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'min-width') && eachSyntax.priority !== -1, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width') && eachSyntax.priority !== -1);
|
|
733
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'min-width') && eachSyntax.priority !== -1);
|
|
734
734
|
}
|
|
735
735
|
if (matchStartIndex !== -1) {
|
|
736
736
|
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
737
|
-
const value = (this.
|
|
737
|
+
const value = (this.syntaxes[i].at.media?.find(({ name })=>name === 'max-width')).value;
|
|
738
738
|
if (value < maxWidthFeature.value) {
|
|
739
739
|
matchEndIndex = i - 1;
|
|
740
740
|
} else if (value > maxWidthFeature.value) {
|
|
@@ -748,10 +748,10 @@ class MasterCSS {
|
|
|
748
748
|
} else {
|
|
749
749
|
if (priority === -1) {
|
|
750
750
|
matchStartIndex = mediaStartIndex;
|
|
751
|
-
matchEndIndex = findIndex(mediaStartIndex, (
|
|
751
|
+
matchEndIndex = findIndex(mediaStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width') || eachSyntax.priority !== -1);
|
|
752
752
|
} else {
|
|
753
|
-
matchStartIndex = findIndex(mediaStartIndex, (
|
|
754
|
-
matchEndIndex = findIndex(mediaStartIndex, (
|
|
753
|
+
matchStartIndex = findIndex(mediaStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'), (eachSyntax)=>eachSyntax.priority !== -1);
|
|
754
|
+
matchEndIndex = findIndex(mediaStartIndex, (eachSyntax)=>eachSyntax.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
|
|
755
755
|
}
|
|
756
756
|
}
|
|
757
757
|
}
|
|
@@ -759,10 +759,10 @@ class MasterCSS {
|
|
|
759
759
|
const findStartIndex = Object.keys(this.variablesNativeRules).length ? this.hasKeyframesRule ? 2 : 1 : this.hasKeyframesRule ? 1 : 0;
|
|
760
760
|
if (priority === -1) {
|
|
761
761
|
matchStartIndex = findStartIndex;
|
|
762
|
-
matchEndIndex = findIndex(findStartIndex, (
|
|
762
|
+
matchEndIndex = findIndex(findStartIndex, (eachSyntax)=>eachSyntax.atToken || eachSyntax.priority !== -1);
|
|
763
763
|
} else {
|
|
764
|
-
matchStartIndex = findIndex(findStartIndex, (
|
|
765
|
-
matchEndIndex = findIndex(findStartIndex, (
|
|
764
|
+
matchStartIndex = findIndex(findStartIndex, (eachSyntax)=>eachSyntax.atToken, (eachSyntax)=>eachSyntax.priority !== -1);
|
|
765
|
+
matchEndIndex = findIndex(findStartIndex, (eachSyntax)=>eachSyntax.atToken);
|
|
766
766
|
}
|
|
767
767
|
}
|
|
768
768
|
if (index === undefined && matchEndIndex !== undefined && matchStartIndex !== undefined) {
|
|
@@ -771,7 +771,7 @@ class MasterCSS {
|
|
|
771
771
|
} else {
|
|
772
772
|
if (priority === -1) {
|
|
773
773
|
for(let i = matchStartIndex; i <= matchEndIndex; i++){
|
|
774
|
-
const currentRule = this.
|
|
774
|
+
const currentRule = this.syntaxes[i];
|
|
775
775
|
if (!hasWhere && currentRule.hasWhere) continue;
|
|
776
776
|
if (hasWhere && !currentRule.hasWhere || currentRule.order >= order) {
|
|
777
777
|
index = i;
|
|
@@ -780,7 +780,7 @@ class MasterCSS {
|
|
|
780
780
|
}
|
|
781
781
|
} else {
|
|
782
782
|
for(let i = matchStartIndex; i <= matchEndIndex; i++){
|
|
783
|
-
const currentRule = this.
|
|
783
|
+
const currentRule = this.syntaxes[i];
|
|
784
784
|
if (!hasWhere && currentRule.hasWhere) continue;
|
|
785
785
|
if (hasWhere && !currentRule.hasWhere) {
|
|
786
786
|
index = i;
|
|
@@ -804,13 +804,13 @@ class MasterCSS {
|
|
|
804
804
|
}
|
|
805
805
|
}
|
|
806
806
|
}
|
|
807
|
-
this.
|
|
807
|
+
this.syntaxes.splice(index, 0, rule);
|
|
808
808
|
this.ruleBy[className] = rule;
|
|
809
809
|
if (this.style) {
|
|
810
810
|
const sheet = this.style.sheet;
|
|
811
811
|
let cssRuleIndex = 0;
|
|
812
812
|
const getCssRuleIndex = (index)=>{
|
|
813
|
-
const previousRule = this.
|
|
813
|
+
const previousRule = this.syntaxes[index];
|
|
814
814
|
if (previousRule) {
|
|
815
815
|
if (!previousRule.natives.length) return getCssRuleIndex(index - 1);
|
|
816
816
|
const lastNative = previousRule.natives[previousRule.natives.length - 1];
|
|
@@ -844,7 +844,7 @@ class MasterCSS {
|
|
|
844
844
|
return index;
|
|
845
845
|
}
|
|
846
846
|
get text() {
|
|
847
|
-
return this.
|
|
847
|
+
return this.syntaxes.map((eachSyntax)=>eachSyntax.text).join('');
|
|
848
848
|
}
|
|
849
849
|
handleRuleWithAnimationNames(rule, initializing = false) {
|
|
850
850
|
if (rule.animationNames) {
|
|
@@ -860,9 +860,9 @@ class MasterCSS {
|
|
|
860
860
|
const keyframeRulesIndex = Object.keys(this.variablesNativeRules).length ? 1 : 0;
|
|
861
861
|
let keyframeRule;
|
|
862
862
|
if (this.hasKeyframesRule) {
|
|
863
|
-
(keyframeRule = this.
|
|
863
|
+
(keyframeRule = this.syntaxes[keyframeRulesIndex]).natives.push(nativeRule);
|
|
864
864
|
} else {
|
|
865
|
-
this.
|
|
865
|
+
this.syntaxes.splice(keyframeRulesIndex, 0, keyframeRule = {
|
|
866
866
|
natives: [
|
|
867
867
|
nativeRule
|
|
868
868
|
],
|
|
@@ -919,9 +919,15 @@ class MasterCSS {
|
|
|
919
919
|
break;
|
|
920
920
|
case 'host':
|
|
921
921
|
selectorText = `:host(.${mode})`;
|
|
922
|
+
if (this.config.defaultMode === mode) {
|
|
923
|
+
selectorText += ',:host';
|
|
924
|
+
}
|
|
922
925
|
break;
|
|
923
926
|
case 'class':
|
|
924
|
-
selectorText =
|
|
927
|
+
selectorText = '.' + mode;
|
|
928
|
+
if (this.config.defaultMode === mode) {
|
|
929
|
+
selectorText += ',:root';
|
|
930
|
+
}
|
|
925
931
|
break;
|
|
926
932
|
default:
|
|
927
933
|
return;
|
|
@@ -930,7 +936,7 @@ class MasterCSS {
|
|
|
930
936
|
selectorText = ':root';
|
|
931
937
|
}
|
|
932
938
|
if (sheet) {
|
|
933
|
-
const newCSSRuleIndex = Object.keys(this.variablesNativeRules).length ? this.
|
|
939
|
+
const newCSSRuleIndex = Object.keys(this.variablesNativeRules).length ? this.syntaxes[0].natives.length : 0;
|
|
934
940
|
sheet.insertRule((mediaConditionText ? mediaConditionText + '{' : '') + selectorText + '{}' + (mediaConditionText ? mediaConditionText + '}' : ''), newCSSRuleIndex);
|
|
935
941
|
cssRule = mediaConditionText ? sheet.cssRules[newCSSRuleIndex].cssRules[0] : sheet.cssRules[newCSSRuleIndex];
|
|
936
942
|
} else {
|
|
@@ -1002,12 +1008,12 @@ class MasterCSS {
|
|
|
1002
1008
|
return this.natives.map((eachNative)=>eachNative.text).join('');
|
|
1003
1009
|
}
|
|
1004
1010
|
};
|
|
1005
|
-
this.
|
|
1011
|
+
this.syntaxes.splice(0, 0, newRule);
|
|
1006
1012
|
}
|
|
1007
1013
|
let prefix = '';
|
|
1008
1014
|
let suffix = '}';
|
|
1009
1015
|
if (variableCSSRule.parentRule) {
|
|
1010
|
-
prefix += variableCSSRule.parentRule.conditionText.replace(/ /g, '') + '{';
|
|
1016
|
+
prefix += '@media' + variableCSSRule.parentRule.conditionText.replace(/ /g, '') + '{';
|
|
1011
1017
|
suffix += '}';
|
|
1012
1018
|
}
|
|
1013
1019
|
prefix += variableCSSRule.selectorText + '{';
|
|
@@ -1022,7 +1028,7 @@ class MasterCSS {
|
|
|
1022
1028
|
return prefix + properties.join(';') + suffix;
|
|
1023
1029
|
}
|
|
1024
1030
|
};
|
|
1025
|
-
this.
|
|
1031
|
+
this.syntaxes[0].natives.push(this.variablesNativeRules[mode] = nativeRule);
|
|
1026
1032
|
return nativeRule;
|
|
1027
1033
|
}
|
|
1028
1034
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -13,7 +13,7 @@ var areRuleModesEqual = require('./utils/are-rule-modes-equal.cjs');
|
|
|
13
13
|
var areRuleAtEqual = require('./utils/are-rule-at-equal.cjs');
|
|
14
14
|
var areRuleSelectorsEqual = require('./utils/are-rule-selectors-equal.cjs');
|
|
15
15
|
var areRuleStatesEqual = require('./utils/are-rule-states-equal.cjs');
|
|
16
|
-
var
|
|
16
|
+
var areSyntaxesDuplicated = require('./utils/are-syntaxes-duplicated.cjs');
|
|
17
17
|
var generateCss = require('./utils/generate-css.cjs');
|
|
18
18
|
var isCoreRule = require('./utils/is-core-rule.cjs');
|
|
19
19
|
var at = require('./config/at.cjs');
|
|
@@ -23,7 +23,7 @@ var functions = require('./config/functions.cjs');
|
|
|
23
23
|
var animations = require('./config/animations.cjs');
|
|
24
24
|
var variables = require('./config/variables.cjs');
|
|
25
25
|
var modes = require('./config/modes.cjs');
|
|
26
|
-
var
|
|
26
|
+
var syntaxes = require('./config/syntaxes.cjs');
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
|
|
@@ -60,7 +60,7 @@ exports.areRuleModesEqual = areRuleModesEqual;
|
|
|
60
60
|
exports.areRuleAtEqual = areRuleAtEqual;
|
|
61
61
|
exports.areRuleSelectorsEqual = areRuleSelectorsEqual;
|
|
62
62
|
exports.areRuleStatesEqual = areRuleStatesEqual;
|
|
63
|
-
exports.areRulesDuplicated =
|
|
63
|
+
exports.areRulesDuplicated = areSyntaxesDuplicated;
|
|
64
64
|
exports.generateCSS = generateCss;
|
|
65
65
|
exports.isCoreRule = isCoreRule;
|
|
66
66
|
exports.at = at;
|
|
@@ -70,4 +70,4 @@ exports.functions = functions;
|
|
|
70
70
|
exports.animations = animations;
|
|
71
71
|
exports.variables = variables;
|
|
72
72
|
exports.modes = modes;
|
|
73
|
-
exports.
|
|
73
|
+
exports.syntaxes = syntaxes;
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export { default as areRuleModesEqual } from './utils/are-rule-modes-equal';
|
|
|
11
11
|
export { default as areRuleAtEqual } from './utils/are-rule-at-equal';
|
|
12
12
|
export { default as areRuleSelectorsEqual } from './utils/are-rule-selectors-equal';
|
|
13
13
|
export { default as areRuleStatesEqual } from './utils/are-rule-states-equal';
|
|
14
|
-
export { default as areRulesDuplicated } from './utils/are-
|
|
14
|
+
export { default as areRulesDuplicated } from './utils/are-syntaxes-duplicated';
|
|
15
15
|
export { default as generateCSS } from './utils/generate-css';
|
|
16
16
|
export { default as isCoreRule } from './utils/is-core-rule';
|
|
17
17
|
export type { NativeRule, MediaFeatureComponent, MediaQuery } from './rule';
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ export { default as areRuleModesEqual } from './utils/are-rule-modes-equal.mjs';
|
|
|
9
9
|
export { default as areRuleAtEqual } from './utils/are-rule-at-equal.mjs';
|
|
10
10
|
export { default as areRuleSelectorsEqual } from './utils/are-rule-selectors-equal.mjs';
|
|
11
11
|
export { default as areRuleStatesEqual } from './utils/are-rule-states-equal.mjs';
|
|
12
|
-
export { default as areRulesDuplicated } from './utils/are-
|
|
12
|
+
export { default as areRulesDuplicated } from './utils/are-syntaxes-duplicated.mjs';
|
|
13
13
|
export { default as generateCSS } from './utils/generate-css.mjs';
|
|
14
14
|
export { default as isCoreRule } from './utils/is-core-rule.mjs';
|
|
15
15
|
export { default as at } from './config/at.mjs';
|
|
@@ -19,4 +19,4 @@ export { default as functions } from './config/functions.mjs';
|
|
|
19
19
|
export { default as animations } from './config/animations.mjs';
|
|
20
20
|
export { default as variables } from './config/variables.mjs';
|
|
21
21
|
export { default as modes } from './config/modes.mjs';
|
|
22
|
-
export { default as
|
|
22
|
+
export { default as syntaxes } from './config/syntaxes.mjs';
|
|
@@ -42,7 +42,7 @@ var _commonjsHelpers = require('../_virtual/_commonjsHelpers.cjs');
|
|
|
42
42
|
result += '\\' + codeUnit.toString(16) + ' ';
|
|
43
43
|
continue;
|
|
44
44
|
}
|
|
45
|
-
// If the character is not handled by one of the above
|
|
45
|
+
// If the character is not handled by one of the above syntaxes and is
|
|
46
46
|
// greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
|
|
47
47
|
// is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
|
|
48
48
|
// U+005A), or [a-z] (U+0061 to U+007A), […]
|
|
@@ -40,7 +40,7 @@ import { commonjsGlobal } from '../_virtual/_commonjsHelpers.mjs';
|
|
|
40
40
|
result += '\\' + codeUnit.toString(16) + ' ';
|
|
41
41
|
continue;
|
|
42
42
|
}
|
|
43
|
-
// If the character is not handled by one of the above
|
|
43
|
+
// If the character is not handled by one of the above syntaxes and is
|
|
44
44
|
// greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
|
|
45
45
|
// is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
|
|
46
46
|
// U+005A), or [a-z] (U+0061 to U+007A), […]
|
package/dist/rule.cjs
CHANGED
|
@@ -462,7 +462,7 @@ class Rule {
|
|
|
462
462
|
let queryType;
|
|
463
463
|
const atComponents = [];
|
|
464
464
|
// x font-face, counter-style, keyframes, font-feature-values, property, layer
|
|
465
|
-
const queryTypeRegExp = /^(media|supports|container)/;
|
|
465
|
+
const queryTypeRegExp = /^(media|supports|container|layer)/;
|
|
466
466
|
const atRuleResult = queryTypeRegExp.exec(atToken);
|
|
467
467
|
if (atRuleResult) {
|
|
468
468
|
queryType = atRuleResult[1];
|
package/dist/rule.d.ts
CHANGED
|
@@ -111,9 +111,9 @@ export interface RegisteredRule {
|
|
|
111
111
|
};
|
|
112
112
|
variables: Record<string, Variable>;
|
|
113
113
|
order: number;
|
|
114
|
-
definition:
|
|
114
|
+
definition: SyntaxDefinition;
|
|
115
115
|
}
|
|
116
|
-
export interface
|
|
116
|
+
export interface SyntaxDefinition {
|
|
117
117
|
layer?: Layer;
|
|
118
118
|
matcher?: RegExp;
|
|
119
119
|
sign?: string;
|
package/dist/rule.mjs
CHANGED
|
@@ -460,7 +460,7 @@ class Rule {
|
|
|
460
460
|
let queryType;
|
|
461
461
|
const atComponents = [];
|
|
462
462
|
// x font-face, counter-style, keyframes, font-feature-values, property, layer
|
|
463
|
-
const queryTypeRegExp = /^(media|supports|container)/;
|
|
463
|
+
const queryTypeRegExp = /^(media|supports|container|layer)/;
|
|
464
464
|
const atRuleResult = queryTypeRegExp.exec(atToken);
|
|
465
465
|
if (atRuleResult) {
|
|
466
466
|
queryType = atRuleResult[1];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
declare const autofillSolidStyle:
|
|
1
|
+
import { SyntaxDefinition } from '../rule';
|
|
2
|
+
declare const autofillSolidStyle: SyntaxDefinition['transformValueComponents'];
|
|
3
3
|
export default autofillSolidStyle;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var syntaxes = require('../config/syntaxes.cjs');
|
|
4
4
|
|
|
5
5
|
function isCoreRule(id) {
|
|
6
|
-
return Object.hasOwnProperty.call(
|
|
6
|
+
return Object.hasOwnProperty.call(syntaxes, id);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
module.exports = isCoreRule;
|
|
@@ -10,7 +10,7 @@ var core = require('../core.cjs');
|
|
|
10
10
|
* @returns consistent classes
|
|
11
11
|
*/ function reorderForReadableClasses(classes, css = new core.default()) {
|
|
12
12
|
css.add(...classes);
|
|
13
|
-
const orderedClasses = css.
|
|
13
|
+
const orderedClasses = css.syntaxes// 只保留樣式語法相關的 syntaxes, 排除 keyframes 與 variables 在外
|
|
14
14
|
.filter((eachRule)=>eachRule.layer).sort((a, b)=>{
|
|
15
15
|
if (a.layer === layer.Utility && b.layer !== layer.Utility) {
|
|
16
16
|
// 如果 a 是 Layer.Utility 而 b 不是,则 a 应该排在 b 前面
|
|
@@ -8,7 +8,7 @@ import MasterCSS from '../core.mjs';
|
|
|
8
8
|
* @returns consistent classes
|
|
9
9
|
*/ function reorderForReadableClasses(classes, css = new MasterCSS()) {
|
|
10
10
|
css.add(...classes);
|
|
11
|
-
const orderedClasses = css.
|
|
11
|
+
const orderedClasses = css.syntaxes// 只保留樣式語法相關的 syntaxes, 排除 keyframes 與 variables 在外
|
|
12
12
|
.filter((eachRule)=>eachRule.layer).sort((a, b)=>{
|
|
13
13
|
if (a.layer === Layer.Utility && b.layer !== Layer.Utility) {
|
|
14
14
|
// 如果 a 是 Layer.Utility 而 b 不是,则 a 应该排在 b 前面
|