@master/css 2.0.0-rc.5 → 2.0.0-rc.50
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/README.md +4 -43
- package/dist/_virtual/_commonjsHelpers.cjs +10 -0
- package/dist/_virtual/_commonjsHelpers.mjs +7 -0
- package/dist/_virtual/css-escape.cjs +5 -0
- package/dist/_virtual/css-escape.mjs +3 -0
- package/dist/bin/index.cjs +11 -0
- package/dist/bin/index.d.ts +0 -1
- package/dist/bin/index.mjs +9 -0
- package/dist/common.cjs +159 -0
- package/dist/common.d.ts +26 -0
- package/dist/common.mjs +137 -0
- package/dist/config/animations.cjs +113 -0
- package/dist/config/animations.mjs +111 -0
- package/dist/config/at.cjs +14 -0
- package/dist/config/at.d.ts +11 -0
- package/dist/config/at.mjs +12 -0
- package/dist/config/functions.cjs +375 -0
- package/dist/config/functions.d.ts +1 -1
- package/dist/config/functions.mjs +373 -0
- package/dist/config/index.cjs +37 -0
- package/dist/config/index.d.ts +5 -62
- package/dist/config/index.mjs +27 -0
- package/dist/config/modes.cjs +8 -0
- package/dist/config/modes.d.ts +3 -0
- package/dist/config/modes.mjs +6 -0
- package/dist/config/rules.cjs +2327 -0
- package/dist/config/rules.d.ts +277 -274
- package/dist/config/rules.mjs +2325 -0
- package/dist/config/selectors.cjs +28 -0
- package/dist/config/selectors.d.ts +0 -1
- package/dist/config/selectors.mjs +26 -0
- package/dist/config/styles.cjs +2 -0
- package/dist/config/styles.d.ts +2 -2
- package/dist/config/styles.mjs +1 -0
- package/dist/config/utilities.cjs +204 -0
- package/dist/config/{semantics.d.ts → utilities.d.ts} +15 -5
- package/dist/config/utilities.mjs +202 -0
- package/dist/config/variables.cjs +484 -0
- package/dist/config/variables.d.ts +208 -312
- package/dist/config/variables.mjs +482 -0
- package/dist/core.cjs +664 -0
- package/dist/core.d.ts +44 -73
- package/dist/core.mjs +659 -0
- package/dist/index.cjs +81 -0
- package/dist/index.d.ts +20 -9
- package/dist/index.mjs +26 -0
- package/dist/layer.cjs +116 -0
- package/dist/layer.d.ts +13 -10
- package/dist/layer.mjs +114 -0
- package/dist/non-layer.cjs +65 -0
- package/dist/non-layer.d.ts +12 -0
- package/dist/non-layer.mjs +63 -0
- package/dist/polyfills/css-escape.cjs +9 -0
- package/dist/polyfills/css-escape.mjs +7 -0
- package/dist/polyfills/css-escape2.cjs +76 -0
- package/dist/polyfills/css-escape2.mjs +74 -0
- package/dist/rule.cjs +18 -0
- package/dist/rule.d.ts +6 -111
- package/dist/rule.mjs +16 -0
- package/dist/shared/utils/css-escape.cjs +56 -0
- package/dist/shared/utils/css-escape.mjs +54 -0
- package/dist/shared/utils/find-native-css-rule-index.cjs +12 -0
- package/dist/shared/utils/find-native-css-rule-index.mjs +10 -0
- package/dist/syntax-layer.cjs +291 -0
- package/dist/syntax-layer.d.ts +17 -0
- package/dist/syntax-layer.mjs +289 -0
- package/dist/syntax-rule-type.cjs +27 -0
- package/dist/syntax-rule-type.d.ts +28 -0
- package/dist/syntax-rule-type.mjs +25 -0
- package/dist/syntax-rule.cjs +717 -0
- package/dist/syntax-rule.d.ts +47 -0
- package/dist/syntax-rule.mjs +715 -0
- package/dist/types/config.cjs +2 -0
- package/dist/types/config.d.ts +70 -0
- package/dist/types/config.mjs +1 -0
- package/dist/types/global.cjs +2 -0
- package/dist/types/global.d.ts +3 -3
- package/dist/types/global.mjs +1 -0
- package/dist/types/syntax.cjs +2 -0
- package/dist/types/syntax.d.ts +106 -0
- package/dist/types/syntax.mjs +1 -0
- package/dist/utils/are-rule-at-equal.cjs +22 -0
- package/dist/utils/are-rule-at-equal.d.ts +2 -0
- package/dist/utils/are-rule-at-equal.mjs +20 -0
- package/dist/utils/are-rule-modes-equal.cjs +7 -0
- package/dist/utils/are-rule-modes-equal.d.ts +2 -0
- package/dist/utils/are-rule-modes-equal.mjs +5 -0
- package/dist/utils/are-rule-selectors-equal.cjs +29 -0
- package/dist/utils/are-rule-selectors-equal.d.ts +2 -0
- package/dist/utils/are-rule-selectors-equal.mjs +27 -0
- package/dist/utils/are-rule-states-equal.cjs +11 -0
- package/dist/utils/are-rule-states-equal.d.ts +2 -0
- package/dist/utils/are-rule-states-equal.mjs +9 -0
- package/dist/utils/are-rules-duplicated.cjs +17 -0
- package/dist/utils/are-rules-duplicated.d.ts +2 -0
- package/dist/utils/are-rules-duplicated.mjs +15 -0
- package/dist/utils/autofill-solid-style.cjs +31 -0
- package/dist/utils/autofill-solid-style.d.ts +3 -0
- package/dist/utils/autofill-solid-style.mjs +29 -0
- package/dist/utils/extend-config.cjs +73 -0
- package/dist/utils/extend-config.d.ts +2 -2
- package/dist/utils/extend-config.mjs +71 -0
- package/dist/utils/flatten-object.cjs +15 -0
- package/dist/utils/flatten-object.mjs +13 -0
- package/dist/utils/generate-css.cjs +13 -0
- package/dist/utils/generate-css.d.ts +2 -0
- package/dist/utils/generate-css.mjs +11 -0
- package/dist/utils/hex-to-rgb.cjs +30 -0
- package/dist/utils/hex-to-rgb.d.ts +1 -1
- package/dist/utils/hex-to-rgb.mjs +28 -0
- package/dist/utils/is-core-rule.cjs +9 -0
- package/dist/utils/is-core-rule.d.ts +1 -0
- package/dist/utils/is-core-rule.mjs +7 -0
- package/dist/utils/reorder-for-readable-classes.cjs +62 -0
- package/dist/{functions → utils}/reorder-for-readable-classes.d.ts +2 -6
- package/dist/utils/reorder-for-readable-classes.mjs +60 -0
- package/package.json +1 -1
- package/dist/bin/index.bundle.js +0 -36
- package/dist/config/media-queries.d.ts +0 -1
- package/dist/constants/base-unit-regex.d.ts +0 -1
- package/dist/constants/config-esm-text.d.ts +0 -1
- package/dist/constants/config-text.d.ts +0 -1
- package/dist/constants/config-ts-text.d.ts +0 -1
- package/dist/constants/start-symbol.d.ts +0 -6
- package/dist/functions/transform-color-with-opacity.d.ts +0 -1
- package/dist/index.bundle.js +0 -35
- package/dist/index.bundle.mjs +0 -35
- package/dist/tokens/screen-sizes.d.ts +0 -14
- package/dist/utils/concat-arrays.d.ts +0 -1
- package/dist/utils/get-type.d.ts +0 -7
- package/dist/utils/is-plain-object.d.ts +0 -8
- package/dist/utils/is-symbol.d.ts +0 -7
- package/dist/utils/rgb-to-hex.d.ts +0 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { commonjsGlobal } from '../_virtual/_commonjsHelpers.mjs';
|
|
2
|
+
import { __exports as cssEscape } from '../_virtual/css-escape.mjs';
|
|
3
|
+
|
|
4
|
+
var hasRequiredCssEscape;
|
|
5
|
+
|
|
6
|
+
function requireCssEscape () {
|
|
7
|
+
if (hasRequiredCssEscape) return cssEscape;
|
|
8
|
+
hasRequiredCssEscape = 1;
|
|
9
|
+
(()=>{
|
|
10
|
+
const root = typeof commonjsGlobal !== 'undefined' ? commonjsGlobal : window;
|
|
11
|
+
if (!root.CSS && !root.CSS?.escape) {
|
|
12
|
+
// https://drafts.csswg.org/cssom/#serialize-an-identifier
|
|
13
|
+
const cssEscape = function(value) {
|
|
14
|
+
if (arguments.length == 0) {
|
|
15
|
+
throw new TypeError('`CSS.escape` requires an argument.');
|
|
16
|
+
}
|
|
17
|
+
const string = String(value);
|
|
18
|
+
const length = string.length;
|
|
19
|
+
let index = -1;
|
|
20
|
+
let result = '';
|
|
21
|
+
let codeUnit;
|
|
22
|
+
const firstCodeUnit = string.charCodeAt(0);
|
|
23
|
+
if (// If the character is the first character and is a `-` (U+002D), and
|
|
24
|
+
// there is no second character, […]
|
|
25
|
+
length == 1 && firstCodeUnit == 0x002D) {
|
|
26
|
+
return '\\' + string;
|
|
27
|
+
}
|
|
28
|
+
while(++index < length){
|
|
29
|
+
codeUnit = string.charCodeAt(index);
|
|
30
|
+
// Note: there’s no need to special-case astral symbols, surrogate
|
|
31
|
+
// pairs, or lone surrogates.
|
|
32
|
+
// If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
|
|
33
|
+
// (U+FFFD).
|
|
34
|
+
if (codeUnit == 0x0000) {
|
|
35
|
+
result += '\uFFFD';
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (// If the character is in the range [\1-\1F] (U+0001 to U+001F) or is
|
|
39
|
+
// U+007F, […]
|
|
40
|
+
codeUnit >= 0x0001 && codeUnit <= 0x001F || codeUnit == 0x007F || // If the character is the first character and is in the range [0-9]
|
|
41
|
+
// (U+0030 to U+0039), […]
|
|
42
|
+
index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039 || // If the character is the second character and is in the range [0-9]
|
|
43
|
+
// (U+0030 to U+0039) and the first character is a `-` (U+002D), […]
|
|
44
|
+
index == 1 && codeUnit >= 0x0030 && codeUnit <= 0x0039 && firstCodeUnit == 0x002D) {
|
|
45
|
+
// https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
|
|
46
|
+
result += '\\' + codeUnit.toString(16) + ' ';
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
// If the character is not handled by one of the above syntaxes and is
|
|
50
|
+
// greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
|
|
51
|
+
// is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
|
|
52
|
+
// U+005A), or [a-z] (U+0061 to U+007A), […]
|
|
53
|
+
if (codeUnit >= 0x0080 || codeUnit == 0x002D || codeUnit == 0x005F || codeUnit >= 0x0030 && codeUnit <= 0x0039 || codeUnit >= 0x0041 && codeUnit <= 0x005A || codeUnit >= 0x0061 && codeUnit <= 0x007A) {
|
|
54
|
+
// the character itself
|
|
55
|
+
result += string.charAt(index);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
// Otherwise, the escaped character.
|
|
59
|
+
// https://drafts.csswg.org/cssom/#escape-a-character
|
|
60
|
+
result += '\\' + string.charAt(index);
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
};
|
|
64
|
+
if (!root.CSS) {
|
|
65
|
+
root.CSS = {};
|
|
66
|
+
}
|
|
67
|
+
root.CSS.escape = cssEscape;
|
|
68
|
+
globalThis.CSS.escape = cssEscape;
|
|
69
|
+
}
|
|
70
|
+
})();
|
|
71
|
+
return cssEscape;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export { requireCssEscape as __require };
|
package/dist/rule.cjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
class Rule {
|
|
4
|
+
name;
|
|
5
|
+
nodes;
|
|
6
|
+
constructor(name, nodes = []){
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.nodes = nodes;
|
|
9
|
+
}
|
|
10
|
+
get key() {
|
|
11
|
+
return this.name;
|
|
12
|
+
}
|
|
13
|
+
get text() {
|
|
14
|
+
return this.nodes.map(({ text })=>text).join('');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.Rule = Rule;
|
package/dist/rule.d.ts
CHANGED
|
@@ -1,116 +1,11 @@
|
|
|
1
|
-
import type { MasterCSS, Variable } from './core';
|
|
2
|
-
import { Layer } from './layer';
|
|
3
|
-
import { PropertiesHyphen } from 'csstype';
|
|
4
1
|
export declare class Rule {
|
|
5
|
-
readonly
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
readonly natives: NativeRule[];
|
|
10
|
-
readonly order: number;
|
|
11
|
-
readonly layer: Layer;
|
|
12
|
-
readonly stateToken: string;
|
|
13
|
-
readonly declarations?: PropertiesHyphen;
|
|
14
|
-
animationNames?: string[];
|
|
15
|
-
variableNames?: string[];
|
|
16
|
-
constructor(className: string, RegisteredRule: RegisteredRule, css: MasterCSS);
|
|
17
|
-
resolveValue: (valueComponents: ValueComponent[], unit: string, bypassVariableNames: string[], bypassParsing: boolean) => string;
|
|
2
|
+
readonly name: string;
|
|
3
|
+
nodes: RuleNode[];
|
|
4
|
+
constructor(name: string, nodes?: RuleNode[]);
|
|
5
|
+
get key(): string;
|
|
18
6
|
get text(): string;
|
|
19
|
-
parseValue: (currentValueComponents: ValueComponent[], i: number, value: string, unit: string, endSymbol: string, parentFunctionName?: string, bypassParsing?: boolean, bypassVariableNames?: string[]) => number;
|
|
20
|
-
parseValueComponent(token: string | number, unit?: any): StringValueComponent | NumericValueComponent;
|
|
21
7
|
}
|
|
22
|
-
export
|
|
23
|
-
export interface StringValueComponent {
|
|
24
|
-
text?: string;
|
|
25
|
-
token?: string;
|
|
26
|
-
type: 'string';
|
|
27
|
-
value: string;
|
|
28
|
-
}
|
|
29
|
-
export interface NumericValueComponent {
|
|
30
|
-
text?: string;
|
|
31
|
-
token?: string;
|
|
32
|
-
type: 'number';
|
|
33
|
-
value: number;
|
|
34
|
-
unit?: string;
|
|
35
|
-
}
|
|
36
|
-
export interface FunctionValueComponent {
|
|
37
|
-
text?: string;
|
|
38
|
-
token?: string;
|
|
39
|
-
type: 'function';
|
|
40
|
-
name: string;
|
|
41
|
-
symbol: string;
|
|
42
|
-
children: ValueComponent[];
|
|
43
|
-
bypassTransform?: boolean;
|
|
44
|
-
}
|
|
45
|
-
export interface VariableValueComponent {
|
|
46
|
-
text?: string;
|
|
47
|
-
token?: string;
|
|
48
|
-
type: 'variable';
|
|
49
|
-
name: string;
|
|
50
|
-
alpha?: string;
|
|
51
|
-
fallback?: string;
|
|
52
|
-
variable?: Variable;
|
|
53
|
-
}
|
|
54
|
-
export interface SeparatorValueComponent {
|
|
55
|
-
text?: string;
|
|
56
|
-
type: 'separator';
|
|
57
|
-
value: string;
|
|
58
|
-
}
|
|
59
|
-
export interface Rule extends RegisteredRule {
|
|
60
|
-
colored: boolean;
|
|
61
|
-
prefix: string;
|
|
62
|
-
token: string;
|
|
63
|
-
vendorPrefixSelectors: Record<string, string[]>;
|
|
64
|
-
vendorSuffixSelectors: Record<string, string[]>;
|
|
65
|
-
important: boolean;
|
|
66
|
-
media: MediaQuery;
|
|
67
|
-
direction: string;
|
|
68
|
-
theme: string;
|
|
69
|
-
unitToken: string;
|
|
70
|
-
hasWhere: boolean;
|
|
71
|
-
valueComponents: Array<ValueComponent>;
|
|
72
|
-
}
|
|
73
|
-
export interface RegisteredRule {
|
|
74
|
-
id: string;
|
|
75
|
-
match?: RegExp;
|
|
76
|
-
variables?: any;
|
|
77
|
-
order: number;
|
|
78
|
-
definition: RuleDefinition;
|
|
79
|
-
}
|
|
80
|
-
export interface RuleDefinition {
|
|
81
|
-
layer?: Layer;
|
|
82
|
-
match?: RegExp | [string, string[]?];
|
|
83
|
-
variables?: string[];
|
|
84
|
-
separators?: string[];
|
|
85
|
-
shorthand?: string;
|
|
86
|
-
colored?: boolean;
|
|
87
|
-
numeric?: boolean;
|
|
88
|
-
unit?: any;
|
|
89
|
-
native?: boolean;
|
|
90
|
-
declarations?: PropertiesHyphen;
|
|
91
|
-
analyze?: (this: Rule, className: string) => [valueToken: string, prefixToken?: string];
|
|
92
|
-
transformValue?(this: Rule, value: string): string;
|
|
93
|
-
transformValueComponents?(this: Rule, valueComponents: ValueComponent[]): ValueComponent[];
|
|
94
|
-
declare?(this: Rule, value: string, valueComponents: ValueComponent[]): PropertiesHyphen;
|
|
95
|
-
delete?(this: Rule, className: string): void;
|
|
96
|
-
create?(this: Rule, className: string): void;
|
|
97
|
-
insert?(this: Rule): void;
|
|
98
|
-
}
|
|
99
|
-
export interface NativeRule {
|
|
8
|
+
export interface RuleNode {
|
|
100
9
|
text: string;
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
export type MediaFeatureComponent = {
|
|
104
|
-
type: string;
|
|
105
|
-
tokenType?: string;
|
|
106
|
-
operator?: string;
|
|
107
|
-
value: number;
|
|
108
|
-
unit: string;
|
|
109
|
-
};
|
|
110
|
-
export interface MediaQuery {
|
|
111
|
-
token: string;
|
|
112
|
-
features: {
|
|
113
|
-
[key: string]: MediaFeatureComponent;
|
|
114
|
-
};
|
|
115
|
-
type?: string;
|
|
10
|
+
native?: CSSRule;
|
|
116
11
|
}
|
package/dist/rule.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class Rule {
|
|
2
|
+
name;
|
|
3
|
+
nodes;
|
|
4
|
+
constructor(name, nodes = []){
|
|
5
|
+
this.name = name;
|
|
6
|
+
this.nodes = nodes;
|
|
7
|
+
}
|
|
8
|
+
get key() {
|
|
9
|
+
return this.name;
|
|
10
|
+
}
|
|
11
|
+
get text() {
|
|
12
|
+
return this.nodes.map(({ text })=>text).join('');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { Rule };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function cssEscape(value) {
|
|
4
|
+
if (typeof CSS !== 'undefined') return CSS.escape(value);
|
|
5
|
+
if (arguments.length == 0) {
|
|
6
|
+
throw new TypeError('`CSS.escape` requires an argument.');
|
|
7
|
+
}
|
|
8
|
+
const string = String(value);
|
|
9
|
+
const length = string.length;
|
|
10
|
+
let index = -1;
|
|
11
|
+
let result = '';
|
|
12
|
+
let codeUnit;
|
|
13
|
+
const firstCodeUnit = string.charCodeAt(0);
|
|
14
|
+
if (// If the character is the first character and is a `-` (U+002D), and
|
|
15
|
+
// there is no second character, […]
|
|
16
|
+
length == 1 && firstCodeUnit == 0x002D) {
|
|
17
|
+
return '\\' + string;
|
|
18
|
+
}
|
|
19
|
+
while(++index < length){
|
|
20
|
+
codeUnit = string.charCodeAt(index);
|
|
21
|
+
// Note: there’s no need to special-case astral symbols, surrogate
|
|
22
|
+
// pairs, or lone surrogates.
|
|
23
|
+
// If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
|
|
24
|
+
// (U+FFFD).
|
|
25
|
+
if (codeUnit == 0x0000) {
|
|
26
|
+
result += '\uFFFD';
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (// If the character is in the range [\1-\1F] (U+0001 to U+001F) or is
|
|
30
|
+
// U+007F, […]
|
|
31
|
+
codeUnit >= 0x0001 && codeUnit <= 0x001F || codeUnit == 0x007F || // If the character is the first character and is in the range [0-9]
|
|
32
|
+
// (U+0030 to U+0039), […]
|
|
33
|
+
index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039 || // If the character is the second character and is in the range [0-9]
|
|
34
|
+
// (U+0030 to U+0039) and the first character is a `-` (U+002D), […]
|
|
35
|
+
index == 1 && codeUnit >= 0x0030 && codeUnit <= 0x0039 && firstCodeUnit == 0x002D) {
|
|
36
|
+
// https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
|
|
37
|
+
result += '\\' + codeUnit.toString(16) + ' ';
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
// If the character is not handled by one of the above rules and is
|
|
41
|
+
// greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
|
|
42
|
+
// is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
|
|
43
|
+
// U+005A), or [a-z] (U+0061 to U+007A), […]
|
|
44
|
+
if (codeUnit >= 0x0080 || codeUnit == 0x002D || codeUnit == 0x005F || codeUnit >= 0x0030 && codeUnit <= 0x0039 || codeUnit >= 0x0041 && codeUnit <= 0x005A || codeUnit >= 0x0061 && codeUnit <= 0x007A) {
|
|
45
|
+
// the character itself
|
|
46
|
+
result += string.charAt(index);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
// Otherwise, the escaped character.
|
|
50
|
+
// https://drafts.csswg.org/cssom/#escape-a-character
|
|
51
|
+
result += '\\' + string.charAt(index);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
module.exports = cssEscape;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function cssEscape(value) {
|
|
2
|
+
if (typeof CSS !== 'undefined') return CSS.escape(value);
|
|
3
|
+
if (arguments.length == 0) {
|
|
4
|
+
throw new TypeError('`CSS.escape` requires an argument.');
|
|
5
|
+
}
|
|
6
|
+
const string = String(value);
|
|
7
|
+
const length = string.length;
|
|
8
|
+
let index = -1;
|
|
9
|
+
let result = '';
|
|
10
|
+
let codeUnit;
|
|
11
|
+
const firstCodeUnit = string.charCodeAt(0);
|
|
12
|
+
if (// If the character is the first character and is a `-` (U+002D), and
|
|
13
|
+
// there is no second character, […]
|
|
14
|
+
length == 1 && firstCodeUnit == 0x002D) {
|
|
15
|
+
return '\\' + string;
|
|
16
|
+
}
|
|
17
|
+
while(++index < length){
|
|
18
|
+
codeUnit = string.charCodeAt(index);
|
|
19
|
+
// Note: there’s no need to special-case astral symbols, surrogate
|
|
20
|
+
// pairs, or lone surrogates.
|
|
21
|
+
// If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
|
|
22
|
+
// (U+FFFD).
|
|
23
|
+
if (codeUnit == 0x0000) {
|
|
24
|
+
result += '\uFFFD';
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (// If the character is in the range [\1-\1F] (U+0001 to U+001F) or is
|
|
28
|
+
// U+007F, […]
|
|
29
|
+
codeUnit >= 0x0001 && codeUnit <= 0x001F || codeUnit == 0x007F || // If the character is the first character and is in the range [0-9]
|
|
30
|
+
// (U+0030 to U+0039), […]
|
|
31
|
+
index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039 || // If the character is the second character and is in the range [0-9]
|
|
32
|
+
// (U+0030 to U+0039) and the first character is a `-` (U+002D), […]
|
|
33
|
+
index == 1 && codeUnit >= 0x0030 && codeUnit <= 0x0039 && firstCodeUnit == 0x002D) {
|
|
34
|
+
// https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
|
|
35
|
+
result += '\\' + codeUnit.toString(16) + ' ';
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
// If the character is not handled by one of the above rules and is
|
|
39
|
+
// greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
|
|
40
|
+
// is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
|
|
41
|
+
// U+005A), or [a-z] (U+0061 to U+007A), […]
|
|
42
|
+
if (codeUnit >= 0x0080 || codeUnit == 0x002D || codeUnit == 0x005F || codeUnit >= 0x0030 && codeUnit <= 0x0039 || codeUnit >= 0x0041 && codeUnit <= 0x005A || codeUnit >= 0x0061 && codeUnit <= 0x007A) {
|
|
43
|
+
// the character itself
|
|
44
|
+
result += string.charAt(index);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
// Otherwise, the escaped character.
|
|
48
|
+
// https://drafts.csswg.org/cssom/#escape-a-character
|
|
49
|
+
result += '\\' + string.charAt(index);
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { cssEscape as default };
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var layer = require('./layer.cjs');
|
|
4
|
+
var rule = require('./rule.cjs');
|
|
5
|
+
|
|
6
|
+
class SyntaxLayer extends layer {
|
|
7
|
+
rules = [];
|
|
8
|
+
/**
|
|
9
|
+
* normal
|
|
10
|
+
* normal selectors
|
|
11
|
+
* media normal
|
|
12
|
+
* media selectors
|
|
13
|
+
* media width
|
|
14
|
+
* media width selectors
|
|
15
|
+
*/ insert(syntaxRule) {
|
|
16
|
+
if (this.rules.includes(syntaxRule)) return;
|
|
17
|
+
let index;
|
|
18
|
+
/**
|
|
19
|
+
* 必須按斷點值遞增,並透過索引插入,
|
|
20
|
+
* 以實現響應式先後套用的規則
|
|
21
|
+
* @example <1 <2 <3 ALL >=1 >=2 >=3
|
|
22
|
+
* @description
|
|
23
|
+
*/ const endIndex = this.rules.length - 1;
|
|
24
|
+
const { at, atToken, order, priority } = syntaxRule;
|
|
25
|
+
const findIndex = (startIndex, stopCheck, matchCheck)=>{
|
|
26
|
+
let i = startIndex;
|
|
27
|
+
for(; i <= endIndex; i++){
|
|
28
|
+
const eachSyntaxRule = this.rules[i];
|
|
29
|
+
if (stopCheck?.(eachSyntaxRule)) return matchCheck ? -1 : i - 1;
|
|
30
|
+
if (matchCheck?.(eachSyntaxRule)) return i;
|
|
31
|
+
}
|
|
32
|
+
return matchCheck ? -1 : i - 1;
|
|
33
|
+
};
|
|
34
|
+
let matchStartIndex;
|
|
35
|
+
let matchEndIndex;
|
|
36
|
+
if (atToken) {
|
|
37
|
+
const mediaStartIndex = this.rules.findIndex((eachSyntaxRule)=>eachSyntaxRule.at?.media);
|
|
38
|
+
if (mediaStartIndex === -1) {
|
|
39
|
+
index = endIndex + 1;
|
|
40
|
+
} else {
|
|
41
|
+
const maxWidthFeature = at.media?.find(({ name })=>name === 'max-width');
|
|
42
|
+
const minWidthFeature = at.media?.find(({ name })=>name === 'min-width');
|
|
43
|
+
if (maxWidthFeature || minWidthFeature) {
|
|
44
|
+
const mediaWidthStartIndex = this.rules.findIndex((eachSyntaxRule)=>eachSyntaxRule.at?.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
|
|
45
|
+
if (mediaWidthStartIndex === -1) {
|
|
46
|
+
index = endIndex + 1;
|
|
47
|
+
} else {
|
|
48
|
+
if (maxWidthFeature && minWidthFeature) {
|
|
49
|
+
/**
|
|
50
|
+
* 範圍越小 ( 越限定 越侷限 ) 越優先,
|
|
51
|
+
* 按照範圍 max-width - min-width 遞減排序
|
|
52
|
+
* find 第一個所遇到同樣 feature 且範圍值比自己大的 rule,
|
|
53
|
+
* 並插入在該 rule 之後,讓自己優先被套用
|
|
54
|
+
*/ if (priority === -1) {
|
|
55
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width'));
|
|
56
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.priority !== -1);
|
|
57
|
+
} else {
|
|
58
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, undefined, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
|
|
59
|
+
matchEndIndex = endIndex;
|
|
60
|
+
}
|
|
61
|
+
if (matchStartIndex !== -1) {
|
|
62
|
+
const range = maxWidthFeature.value - minWidthFeature.value;
|
|
63
|
+
let i = matchEndIndex;
|
|
64
|
+
const endI = matchStartIndex;
|
|
65
|
+
matchStartIndex = matchEndIndex + 1;
|
|
66
|
+
for(; i >= endI; i--){
|
|
67
|
+
const eachSyntaxRule = this.rules[i];
|
|
68
|
+
const eachMaxWidthFeature = eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width');
|
|
69
|
+
const eachMinWidthFeature = eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width');
|
|
70
|
+
if (!eachMaxWidthFeature || !eachMinWidthFeature) {
|
|
71
|
+
break;
|
|
72
|
+
} else {
|
|
73
|
+
const eachRange = eachMaxWidthFeature.value - eachMinWidthFeature.value;
|
|
74
|
+
if (eachRange < range) {
|
|
75
|
+
matchEndIndex = i - 1;
|
|
76
|
+
} else if (eachRange === range) {
|
|
77
|
+
matchStartIndex = i;
|
|
78
|
+
} else {
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} else if (minWidthFeature) {
|
|
85
|
+
/**
|
|
86
|
+
* find 第一個所遇到同樣 feature 且值比自己大的 rule,
|
|
87
|
+
* 並插入在該 rule 之後,讓自己優先被套用
|
|
88
|
+
*/ if (priority === -1) {
|
|
89
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>!eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width'));
|
|
90
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1);
|
|
91
|
+
} else {
|
|
92
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>!eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
|
|
93
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
|
|
94
|
+
}
|
|
95
|
+
if (matchStartIndex !== -1) {
|
|
96
|
+
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
97
|
+
const value = (this.rules[i].at.media?.find(({ name })=>name === 'min-width')).value;
|
|
98
|
+
if (value > minWidthFeature.value) {
|
|
99
|
+
matchEndIndex = i - 1;
|
|
100
|
+
} else if (value < minWidthFeature.value) {
|
|
101
|
+
matchStartIndex = i + 1;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
/**
|
|
108
|
+
* find 第一個所遇到同樣 feature 且值比自己大的 rule,
|
|
109
|
+
* 並插入在該 rule 之後,讓自己優先被套用
|
|
110
|
+
*/ if (priority === -1) {
|
|
111
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width'));
|
|
112
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') || eachSyntaxRule.priority !== -1);
|
|
113
|
+
} else {
|
|
114
|
+
matchStartIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width') && eachSyntaxRule.priority !== -1);
|
|
115
|
+
matchEndIndex = findIndex(mediaWidthStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'min-width') && eachSyntaxRule.priority !== -1);
|
|
116
|
+
}
|
|
117
|
+
if (matchStartIndex !== -1) {
|
|
118
|
+
for(let i = matchEndIndex; i >= matchStartIndex; i--){
|
|
119
|
+
const value = (this.rules[i].at.media?.find(({ name })=>name === 'max-width')).value;
|
|
120
|
+
if (value < maxWidthFeature.value) {
|
|
121
|
+
matchEndIndex = i - 1;
|
|
122
|
+
} else if (value > maxWidthFeature.value) {
|
|
123
|
+
matchStartIndex = i + 1;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
if (priority === -1) {
|
|
132
|
+
matchStartIndex = mediaStartIndex;
|
|
133
|
+
matchEndIndex = findIndex(mediaStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width') || eachSyntaxRule.priority !== -1);
|
|
134
|
+
} else {
|
|
135
|
+
matchStartIndex = findIndex(mediaStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'), (eachSyntaxRule)=>eachSyntaxRule.priority !== -1);
|
|
136
|
+
matchEndIndex = findIndex(mediaStartIndex, (eachSyntaxRule)=>eachSyntaxRule.at.media?.find(({ name })=>name === 'max-width' || name === 'min-width'));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
if (priority === -1) {
|
|
142
|
+
matchStartIndex = 0;
|
|
143
|
+
matchEndIndex = findIndex(0, (eachSyntax)=>eachSyntax.atToken || eachSyntax.priority !== -1);
|
|
144
|
+
} else {
|
|
145
|
+
matchStartIndex = findIndex(0, (eachSyntax)=>eachSyntax.atToken, (eachSyntax)=>eachSyntax.priority !== -1);
|
|
146
|
+
matchEndIndex = findIndex(0, (eachSyntax)=>eachSyntax.atToken);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (index === undefined && matchEndIndex !== undefined && matchStartIndex !== undefined) {
|
|
150
|
+
if (matchStartIndex === -1) {
|
|
151
|
+
index = matchEndIndex + 1;
|
|
152
|
+
} else {
|
|
153
|
+
if (priority === -1) {
|
|
154
|
+
for(let i = matchStartIndex; i <= matchEndIndex; i++){
|
|
155
|
+
const currentSyntaxRule = this.rules[i];
|
|
156
|
+
if (currentSyntaxRule.order >= order) {
|
|
157
|
+
index = i;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
} else {
|
|
162
|
+
for(let i = matchStartIndex; i <= matchEndIndex; i++){
|
|
163
|
+
const currentSyntaxRule = this.rules[i];
|
|
164
|
+
if (currentSyntaxRule.priority < priority) {
|
|
165
|
+
index = i;
|
|
166
|
+
break;
|
|
167
|
+
} else if (currentSyntaxRule.priority === priority) {
|
|
168
|
+
if (currentSyntaxRule.order >= order) {
|
|
169
|
+
index = i;
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
index = i + 1;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (index === undefined) {
|
|
178
|
+
index = matchEndIndex + 1;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
super.insert(syntaxRule, index);
|
|
183
|
+
this.insertVariables(syntaxRule);
|
|
184
|
+
this.insertAnimations(syntaxRule);
|
|
185
|
+
syntaxRule.definition.insert?.call(syntaxRule);
|
|
186
|
+
return index;
|
|
187
|
+
}
|
|
188
|
+
delete(key) {
|
|
189
|
+
const syntaxRule = super.delete(key);
|
|
190
|
+
if (!syntaxRule) return;
|
|
191
|
+
if (syntaxRule.variableNames) {
|
|
192
|
+
for (const eachVariableName of syntaxRule.variableNames){
|
|
193
|
+
if (!--this.css.themeLayer.usages[eachVariableName]) {
|
|
194
|
+
this.css.themeLayer.delete(eachVariableName);
|
|
195
|
+
delete this.css.themeLayer.usages[eachVariableName];
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (syntaxRule.animationNames) {
|
|
200
|
+
for (const eachKeyframeName of syntaxRule.animationNames){
|
|
201
|
+
if (!--this.css.animationsNonLayer.usages[eachKeyframeName]) {
|
|
202
|
+
this.css.animationsNonLayer.delete(eachKeyframeName);
|
|
203
|
+
delete this.css.animationsNonLayer.usages[eachKeyframeName];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
syntaxRule.definition.delete?.call(syntaxRule, syntaxRule.name);
|
|
208
|
+
return syntaxRule;
|
|
209
|
+
}
|
|
210
|
+
insertVariables(syntaxRule) {
|
|
211
|
+
if (syntaxRule.variableNames) {
|
|
212
|
+
for (const eachVariableName of syntaxRule.variableNames){
|
|
213
|
+
const variable = this.css.variables[eachVariableName];
|
|
214
|
+
if (this.css.themeLayer.rules.find(({ name })=>name === eachVariableName)) {
|
|
215
|
+
this.css.themeLayer.usages[eachVariableName]++;
|
|
216
|
+
} else {
|
|
217
|
+
const newRule = new rule.Rule(eachVariableName);
|
|
218
|
+
const addNative = (mode, _variable)=>{
|
|
219
|
+
let isDefaultMode = false;
|
|
220
|
+
let preifxCssRuleText;
|
|
221
|
+
let endCurlyBracketCount = 1;
|
|
222
|
+
if (mode) {
|
|
223
|
+
switch(this.css.config.modes?.[mode]){
|
|
224
|
+
case 'media':
|
|
225
|
+
preifxCssRuleText = `@media(prefers-color-scheme:${mode}){:root`;
|
|
226
|
+
endCurlyBracketCount++;
|
|
227
|
+
break;
|
|
228
|
+
case 'host':
|
|
229
|
+
preifxCssRuleText = `:host(.${mode})`;
|
|
230
|
+
if (!variable.value && this.css.config.defaultMode === mode) {
|
|
231
|
+
preifxCssRuleText += ',:host';
|
|
232
|
+
isDefaultMode = true;
|
|
233
|
+
}
|
|
234
|
+
break;
|
|
235
|
+
case 'class':
|
|
236
|
+
preifxCssRuleText = `.${mode}`;
|
|
237
|
+
if (!variable.value && this.css.config.defaultMode === mode) {
|
|
238
|
+
preifxCssRuleText += ',:root';
|
|
239
|
+
isDefaultMode = true;
|
|
240
|
+
}
|
|
241
|
+
break;
|
|
242
|
+
default:
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
} else {
|
|
246
|
+
preifxCssRuleText = ':root';
|
|
247
|
+
}
|
|
248
|
+
const cssRuleText = `${preifxCssRuleText}{--${eachVariableName}:${String(_variable.value)}${'}'.repeat(endCurlyBracketCount)}`;
|
|
249
|
+
if (isDefaultMode) {
|
|
250
|
+
newRule.nodes.unshift({
|
|
251
|
+
text: cssRuleText
|
|
252
|
+
});
|
|
253
|
+
} else {
|
|
254
|
+
newRule.nodes.push({
|
|
255
|
+
text: cssRuleText
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
if (variable.value) {
|
|
260
|
+
addNative('', variable);
|
|
261
|
+
}
|
|
262
|
+
if (variable.modes) {
|
|
263
|
+
for(const mode in variable.modes){
|
|
264
|
+
addNative(mode, variable.modes[mode]);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
this.css.themeLayer.insert(newRule);
|
|
268
|
+
this.css.themeLayer.usages[eachVariableName] = 1;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
insertAnimations(syntaxRule) {
|
|
274
|
+
if (syntaxRule.animationNames) {
|
|
275
|
+
for (const eachAnimationName of syntaxRule.animationNames){
|
|
276
|
+
if (this.css.animationsNonLayer.rules.find(({ name })=>name === eachAnimationName)) {
|
|
277
|
+
this.css.animationsNonLayer.usages[eachAnimationName]++;
|
|
278
|
+
} else {
|
|
279
|
+
this.css.animationsNonLayer.insert(new rule.Rule(eachAnimationName, [
|
|
280
|
+
{
|
|
281
|
+
text: `@keyframes ${eachAnimationName}{` + Object.entries(this.css.animations[eachAnimationName]).map(([key, variables])=>`${key}{${Object.entries(variables).map(([name, value])=>name + ':' + value).join(';')}}`).join('') + '}'
|
|
282
|
+
}
|
|
283
|
+
]));
|
|
284
|
+
this.css.animationsNonLayer.usages[eachAnimationName] = 1;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
module.exports = SyntaxLayer;
|