@master/css 2.0.0-rc.2 → 2.0.0-rc.21
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 +5 -0
- package/dist/_virtual/_commonjsHelpers.mjs +3 -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/config/animations.cjs +113 -0
- package/dist/config/animations.mjs +111 -0
- package/dist/config/functions.cjs +352 -0
- package/dist/config/functions.mjs +350 -0
- package/dist/config/index.cjs +34 -0
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.mjs +25 -0
- package/dist/config/media-queries.cjs +7 -0
- package/dist/config/media-queries.mjs +1 -0
- package/dist/config/rules.cjs +2190 -0
- package/dist/config/rules.mjs +2184 -0
- package/dist/config/selectors.cjs +29 -0
- package/dist/config/selectors.mjs +27 -0
- package/dist/config/semantics.cjs +194 -0
- package/dist/config/semantics.mjs +192 -0
- package/dist/config/styles.cjs +2 -0
- package/dist/config/styles.mjs +1 -0
- package/dist/config/variables.cjs +116 -0
- package/dist/config/variables.d.ts +135 -168
- package/dist/config/variables.mjs +114 -0
- package/dist/constants/base-unit-regex.cjs +5 -0
- package/dist/constants/base-unit-regex.mjs +3 -0
- package/dist/constants/start-symbol.cjs +10 -0
- package/dist/constants/start-symbol.mjs +8 -0
- package/dist/core.cjs +979 -0
- package/dist/core.d.ts +16 -16
- package/dist/core.mjs +974 -0
- package/dist/functions/reorder-for-readable-classes.cjs +68 -0
- package/dist/functions/reorder-for-readable-classes.d.ts +1 -1
- package/dist/functions/reorder-for-readable-classes.mjs +66 -0
- package/dist/functions/transform-color-with-opacity.cjs +9 -0
- package/dist/functions/transform-color-with-opacity.mjs +7 -0
- package/dist/index.cjs +37 -0
- package/dist/index.d.ts +3 -6
- package/dist/index.mjs +13 -0
- package/dist/layer.cjs +23 -0
- package/dist/layer.mjs +23 -0
- package/dist/polyfills/css-escape.cjs +8 -0
- package/dist/polyfills/css-escape.mjs +2 -0
- package/dist/polyfills/css-escape2.cjs +68 -0
- package/dist/polyfills/css-escape2.mjs +64 -0
- package/dist/rule.cjs +702 -0
- package/dist/rule.d.ts +2 -2
- package/dist/rule.mjs +700 -0
- package/dist/shared/utils/css-escape.cjs +56 -0
- package/dist/shared/utils/css-escape.mjs +54 -0
- package/dist/tokens/screen-sizes.cjs +17 -0
- package/dist/tokens/screen-sizes.mjs +15 -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/utils/concat-arrays.cjs +12 -0
- package/dist/utils/concat-arrays.mjs +10 -0
- package/dist/utils/extend-config.cjs +59 -0
- package/dist/utils/extend-config.mjs +57 -0
- package/dist/utils/flatten-object.cjs +15 -0
- package/dist/utils/flatten-object.mjs +13 -0
- package/dist/utils/get-type.cjs +12 -0
- package/dist/utils/get-type.mjs +10 -0
- package/dist/utils/hex-to-rgb.cjs +30 -0
- package/dist/utils/hex-to-rgb.mjs +28 -0
- package/dist/utils/is-plain-object.cjs +15 -0
- package/dist/utils/is-plain-object.mjs +13 -0
- package/dist/utils/is-symbol.cjs +14 -0
- package/dist/utils/is-symbol.mjs +12 -0
- package/dist/utils/rgb-to-hex.cjs +7 -0
- package/dist/utils/rgb-to-hex.mjs +5 -0
- package/package.json +1 -1
- package/dist/bin/index.bundle.js +0 -36
- 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/index.bundle.js +0 -35
- package/dist/index.bundle.mjs +0 -35
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var layer = require('../layer.cjs');
|
|
4
|
+
var core = require('../core.cjs');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Sorts classes in a consistent order
|
|
8
|
+
* @param classes
|
|
9
|
+
* @param options
|
|
10
|
+
* @returns consistent classes
|
|
11
|
+
*/ function reorderForReadableClasses(classes, options) {
|
|
12
|
+
let css;
|
|
13
|
+
if (options?.css) {
|
|
14
|
+
css = options?.css;
|
|
15
|
+
} else {
|
|
16
|
+
css = new core.default(options?.config);
|
|
17
|
+
}
|
|
18
|
+
for (const eachClass of classes){
|
|
19
|
+
css.add(eachClass);
|
|
20
|
+
}
|
|
21
|
+
return css.rules// 只保留樣式語法相關的 rules, 排除 keyframes 與 variables 在外
|
|
22
|
+
.filter((eachRule)=>eachRule.layer).sort((a, b)=>{
|
|
23
|
+
if (a.layer === layer.Layer.Semantic && b.layer !== layer.Layer.Semantic) {
|
|
24
|
+
// 如果 a 是 Layer.Semantic 而 b 不是,则 a 应该排在 b 前面
|
|
25
|
+
return -1;
|
|
26
|
+
} else if (a.layer !== layer.Layer.Semantic && b.layer === layer.Layer.Semantic) {
|
|
27
|
+
// 如果 b 是 Layer.Semantic 而 a 不是,则 b 应该排在 a 前面
|
|
28
|
+
return 1;
|
|
29
|
+
} else if (a.id !== b.id) {
|
|
30
|
+
return a.className.localeCompare(b.className);
|
|
31
|
+
} else {
|
|
32
|
+
// 檢查 vendorSuffixSelectors 是否存在
|
|
33
|
+
const aHasVendorSuffix = a.vendorSuffixSelectors?.['']?.[0];
|
|
34
|
+
const bHasVendorSuffix = b.vendorSuffixSelectors?.['']?.[0];
|
|
35
|
+
// 檢查 media.token 是否存在
|
|
36
|
+
const aHasMediaToken = a.media?.token;
|
|
37
|
+
const bHasMediaToken = b.media?.token;
|
|
38
|
+
if (a.priority === -1 && b.priority === -1) {
|
|
39
|
+
// 如果 a 和 b 都有 vendorSuffixSelectors 或 media.token,則按照以下規則排序
|
|
40
|
+
if (aHasVendorSuffix && bHasVendorSuffix) {
|
|
41
|
+
return aHasVendorSuffix.localeCompare(bHasVendorSuffix);
|
|
42
|
+
}
|
|
43
|
+
// 如果 a 和 b 都有 media.token 且不包含內建已處理過排序的,則按照以下規則排序
|
|
44
|
+
if (aHasMediaToken && bHasMediaToken && !Object.keys(a.media.features || {}).length && !Object.keys(b.media.features || {}).length) {
|
|
45
|
+
return aHasMediaToken.localeCompare(bHasMediaToken);
|
|
46
|
+
}
|
|
47
|
+
if (aHasVendorSuffix && !bHasVendorSuffix) {
|
|
48
|
+
return 1;
|
|
49
|
+
} else if (!aHasVendorSuffix && bHasVendorSuffix) {
|
|
50
|
+
return -1;
|
|
51
|
+
}
|
|
52
|
+
if (aHasMediaToken && !bHasMediaToken) {
|
|
53
|
+
return 1;
|
|
54
|
+
} else if (!aHasMediaToken && bHasMediaToken) {
|
|
55
|
+
return -1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// 如果 a 和 b 的 id 相同,則按照以下規則排序
|
|
59
|
+
if (a.id === b.id && a.stateToken === b.stateToken) {
|
|
60
|
+
return a.className.localeCompare(b.className);
|
|
61
|
+
}
|
|
62
|
+
// 再按照 rule.order 本身來升序排列
|
|
63
|
+
return a.order - b.order;
|
|
64
|
+
}
|
|
65
|
+
}).map((eachRule)=>eachRule.className);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
module.exports = reorderForReadableClasses;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Layer } from '../layer.mjs';
|
|
2
|
+
import MasterCSS from '../core.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Sorts classes in a consistent order
|
|
6
|
+
* @param classes
|
|
7
|
+
* @param options
|
|
8
|
+
* @returns consistent classes
|
|
9
|
+
*/ function reorderForReadableClasses(classes, options) {
|
|
10
|
+
let css;
|
|
11
|
+
if (options?.css) {
|
|
12
|
+
css = options?.css;
|
|
13
|
+
} else {
|
|
14
|
+
css = new MasterCSS(options?.config);
|
|
15
|
+
}
|
|
16
|
+
for (const eachClass of classes){
|
|
17
|
+
css.add(eachClass);
|
|
18
|
+
}
|
|
19
|
+
return css.rules// 只保留樣式語法相關的 rules, 排除 keyframes 與 variables 在外
|
|
20
|
+
.filter((eachRule)=>eachRule.layer).sort((a, b)=>{
|
|
21
|
+
if (a.layer === Layer.Semantic && b.layer !== Layer.Semantic) {
|
|
22
|
+
// 如果 a 是 Layer.Semantic 而 b 不是,则 a 应该排在 b 前面
|
|
23
|
+
return -1;
|
|
24
|
+
} else if (a.layer !== Layer.Semantic && b.layer === Layer.Semantic) {
|
|
25
|
+
// 如果 b 是 Layer.Semantic 而 a 不是,则 b 应该排在 a 前面
|
|
26
|
+
return 1;
|
|
27
|
+
} else if (a.id !== b.id) {
|
|
28
|
+
return a.className.localeCompare(b.className);
|
|
29
|
+
} else {
|
|
30
|
+
// 檢查 vendorSuffixSelectors 是否存在
|
|
31
|
+
const aHasVendorSuffix = a.vendorSuffixSelectors?.['']?.[0];
|
|
32
|
+
const bHasVendorSuffix = b.vendorSuffixSelectors?.['']?.[0];
|
|
33
|
+
// 檢查 media.token 是否存在
|
|
34
|
+
const aHasMediaToken = a.media?.token;
|
|
35
|
+
const bHasMediaToken = b.media?.token;
|
|
36
|
+
if (a.priority === -1 && b.priority === -1) {
|
|
37
|
+
// 如果 a 和 b 都有 vendorSuffixSelectors 或 media.token,則按照以下規則排序
|
|
38
|
+
if (aHasVendorSuffix && bHasVendorSuffix) {
|
|
39
|
+
return aHasVendorSuffix.localeCompare(bHasVendorSuffix);
|
|
40
|
+
}
|
|
41
|
+
// 如果 a 和 b 都有 media.token 且不包含內建已處理過排序的,則按照以下規則排序
|
|
42
|
+
if (aHasMediaToken && bHasMediaToken && !Object.keys(a.media.features || {}).length && !Object.keys(b.media.features || {}).length) {
|
|
43
|
+
return aHasMediaToken.localeCompare(bHasMediaToken);
|
|
44
|
+
}
|
|
45
|
+
if (aHasVendorSuffix && !bHasVendorSuffix) {
|
|
46
|
+
return 1;
|
|
47
|
+
} else if (!aHasVendorSuffix && bHasVendorSuffix) {
|
|
48
|
+
return -1;
|
|
49
|
+
}
|
|
50
|
+
if (aHasMediaToken && !bHasMediaToken) {
|
|
51
|
+
return 1;
|
|
52
|
+
} else if (!aHasMediaToken && bHasMediaToken) {
|
|
53
|
+
return -1;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// 如果 a 和 b 的 id 相同,則按照以下規則排序
|
|
57
|
+
if (a.id === b.id && a.stateToken === b.stateToken) {
|
|
58
|
+
return a.className.localeCompare(b.className);
|
|
59
|
+
}
|
|
60
|
+
// 再按照 rule.order 本身來升序排列
|
|
61
|
+
return a.order - b.order;
|
|
62
|
+
}
|
|
63
|
+
}).map((eachRule)=>eachRule.className);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { reorderForReadableClasses as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function transformColorWithOpacity(color, opacityStr) {
|
|
4
|
+
let opacity = opacityStr.endsWith('%') ? parseFloat(opacityStr) / 100.0 : +opacityStr;
|
|
5
|
+
opacity = isNaN(opacity) ? 1 : Math.min(Math.max(opacity, 0), 1);
|
|
6
|
+
return color + Math.round(opacity * 255).toString(16).toUpperCase().padStart(2, '0');
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
exports.transformColorWithOpacity = transformColorWithOpacity;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
function transformColorWithOpacity(color, opacityStr) {
|
|
2
|
+
let opacity = opacityStr.endsWith('%') ? parseFloat(opacityStr) / 100.0 : +opacityStr;
|
|
3
|
+
opacity = isNaN(opacity) ? 1 : Math.min(Math.max(opacity, 0), 1);
|
|
4
|
+
return color + Math.round(opacity * 255).toString(16).toUpperCase().padStart(2, '0');
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { transformColorWithOpacity };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var index = require('./config/index.cjs');
|
|
6
|
+
var rule = require('./rule.cjs');
|
|
7
|
+
var layer = require('./layer.cjs');
|
|
8
|
+
var extend = require('@techor/extend');
|
|
9
|
+
var reorderForReadableClasses = require('./functions/reorder-for-readable-classes.cjs');
|
|
10
|
+
var core = require('./core.cjs');
|
|
11
|
+
var selectors = require('./config/selectors.cjs');
|
|
12
|
+
var semantics = require('./config/semantics.cjs');
|
|
13
|
+
var rules = require('./config/rules.cjs');
|
|
14
|
+
var functions = require('./config/functions.cjs');
|
|
15
|
+
var animations = require('./config/animations.cjs');
|
|
16
|
+
var variables = require('./config/variables.cjs');
|
|
17
|
+
var screenSizes = require('./tokens/screen-sizes.cjs');
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
exports.config = index.config;
|
|
22
|
+
exports.Rule = rule.Rule;
|
|
23
|
+
Object.defineProperty(exports, "Layer", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return layer.Layer; }
|
|
26
|
+
});
|
|
27
|
+
exports.extend = extend;
|
|
28
|
+
exports.reorderForReadableClasses = reorderForReadableClasses;
|
|
29
|
+
exports.MasterCSS = core.default;
|
|
30
|
+
exports.default = core.default;
|
|
31
|
+
exports.selectors = selectors;
|
|
32
|
+
exports.semantics = semantics;
|
|
33
|
+
exports.rules = rules.default;
|
|
34
|
+
exports.functions = functions;
|
|
35
|
+
exports.animations = animations;
|
|
36
|
+
exports.variables = variables;
|
|
37
|
+
exports.mediaQueries = screenSizes;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './config';
|
|
2
2
|
export { Rule } from './rule';
|
|
3
|
-
export type { NativeRule, MediaFeatureComponent, MediaQuery } from './rule';
|
|
4
|
-
export { CONFIG_TEXT } from './constants/config-text';
|
|
5
|
-
export { CONFIG_ESM_TEXT } from './constants/config-esm-text';
|
|
6
|
-
export { CONFIG_TS_TEXT } from './constants/config-ts-text';
|
|
7
3
|
export { Layer } from './layer';
|
|
8
4
|
export { default as extend } from '@techor/extend';
|
|
9
5
|
export { default as reorderForReadableClasses } from './functions/reorder-for-readable-classes';
|
|
10
|
-
export
|
|
6
|
+
export { default as MasterCSS, default } from './core';
|
|
7
|
+
export type { NativeRule, MediaFeatureComponent, MediaQuery } from './rule';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { config } from './config/index.mjs';
|
|
2
|
+
export { Rule } from './rule.mjs';
|
|
3
|
+
export { Layer } from './layer.mjs';
|
|
4
|
+
export { default as extend } from '@techor/extend';
|
|
5
|
+
export { default as reorderForReadableClasses } from './functions/reorder-for-readable-classes.mjs';
|
|
6
|
+
export { default as MasterCSS, default } from './core.mjs';
|
|
7
|
+
export { default as selectors } from './config/selectors.mjs';
|
|
8
|
+
export { default as semantics } from './config/semantics.mjs';
|
|
9
|
+
export { default as rules } from './config/rules.mjs';
|
|
10
|
+
export { default as functions } from './config/functions.mjs';
|
|
11
|
+
export { default as animations } from './config/animations.mjs';
|
|
12
|
+
export { default as variables } from './config/variables.mjs';
|
|
13
|
+
export { default as mediaQueries } from './tokens/screen-sizes.mjs';
|
package/dist/layer.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.Layer = void 0;
|
|
4
|
+
(function(Layer) {
|
|
5
|
+
// semantic
|
|
6
|
+
Layer[Layer["Semantic"] = -8] = "Semantic";
|
|
7
|
+
// native shorthand
|
|
8
|
+
Layer[Layer["CoreNativeShorthand"] = -7] = "CoreNativeShorthand";
|
|
9
|
+
// native shorthand
|
|
10
|
+
Layer[Layer["NativeShorthand"] = -6] = "NativeShorthand";
|
|
11
|
+
// shorthand
|
|
12
|
+
Layer[Layer["CoreShorthand"] = -5] = "CoreShorthand";
|
|
13
|
+
// shorthand
|
|
14
|
+
Layer[Layer["Shorthand"] = -4] = "Shorthand";
|
|
15
|
+
// native
|
|
16
|
+
Layer[Layer["CoreNative"] = -3] = "CoreNative";
|
|
17
|
+
// native
|
|
18
|
+
Layer[Layer["Native"] = -2] = "Native";
|
|
19
|
+
// normal
|
|
20
|
+
Layer[Layer["Core"] = -1] = "Core";
|
|
21
|
+
// normal
|
|
22
|
+
Layer[Layer["Normal"] = 0] = "Normal";
|
|
23
|
+
})(exports.Layer || (exports.Layer = {}));
|
package/dist/layer.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var Layer;
|
|
2
|
+
(function(Layer) {
|
|
3
|
+
// semantic
|
|
4
|
+
Layer[Layer["Semantic"] = -8] = "Semantic";
|
|
5
|
+
// native shorthand
|
|
6
|
+
Layer[Layer["CoreNativeShorthand"] = -7] = "CoreNativeShorthand";
|
|
7
|
+
// native shorthand
|
|
8
|
+
Layer[Layer["NativeShorthand"] = -6] = "NativeShorthand";
|
|
9
|
+
// shorthand
|
|
10
|
+
Layer[Layer["CoreShorthand"] = -5] = "CoreShorthand";
|
|
11
|
+
// shorthand
|
|
12
|
+
Layer[Layer["Shorthand"] = -4] = "Shorthand";
|
|
13
|
+
// native
|
|
14
|
+
Layer[Layer["CoreNative"] = -3] = "CoreNative";
|
|
15
|
+
// native
|
|
16
|
+
Layer[Layer["Native"] = -2] = "Native";
|
|
17
|
+
// normal
|
|
18
|
+
Layer[Layer["Core"] = -1] = "Core";
|
|
19
|
+
// normal
|
|
20
|
+
Layer[Layer["Normal"] = 0] = "Normal";
|
|
21
|
+
})(Layer || (Layer = {}));
|
|
22
|
+
|
|
23
|
+
export { Layer };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _commonjsHelpers = require('../_virtual/_commonjsHelpers.cjs');
|
|
4
|
+
|
|
5
|
+
(()=>{
|
|
6
|
+
const root = typeof _commonjsHelpers.commonjsGlobal !== 'undefined' ? _commonjsHelpers.commonjsGlobal : window;
|
|
7
|
+
if (!root.CSS && !root.CSS?.escape) {
|
|
8
|
+
// https://drafts.csswg.org/cssom/#serialize-an-identifier
|
|
9
|
+
const cssEscape = function(value) {
|
|
10
|
+
if (arguments.length == 0) {
|
|
11
|
+
throw new TypeError('`CSS.escape` requires an argument.');
|
|
12
|
+
}
|
|
13
|
+
const string = String(value);
|
|
14
|
+
const length = string.length;
|
|
15
|
+
let index = -1;
|
|
16
|
+
let result = '';
|
|
17
|
+
let codeUnit;
|
|
18
|
+
const firstCodeUnit = string.charCodeAt(0);
|
|
19
|
+
if (// If the character is the first character and is a `-` (U+002D), and
|
|
20
|
+
// there is no second character, […]
|
|
21
|
+
length == 1 && firstCodeUnit == 0x002D) {
|
|
22
|
+
return '\\' + string;
|
|
23
|
+
}
|
|
24
|
+
while(++index < length){
|
|
25
|
+
codeUnit = string.charCodeAt(index);
|
|
26
|
+
// Note: there’s no need to special-case astral symbols, surrogate
|
|
27
|
+
// pairs, or lone surrogates.
|
|
28
|
+
// If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
|
|
29
|
+
// (U+FFFD).
|
|
30
|
+
if (codeUnit == 0x0000) {
|
|
31
|
+
result += '\uFFFD';
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (// If the character is in the range [\1-\1F] (U+0001 to U+001F) or is
|
|
35
|
+
// U+007F, […]
|
|
36
|
+
codeUnit >= 0x0001 && codeUnit <= 0x001F || codeUnit == 0x007F || // If the character is the first character and is in the range [0-9]
|
|
37
|
+
// (U+0030 to U+0039), […]
|
|
38
|
+
index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039 || // If the character is the second character and is in the range [0-9]
|
|
39
|
+
// (U+0030 to U+0039) and the first character is a `-` (U+002D), […]
|
|
40
|
+
index == 1 && codeUnit >= 0x0030 && codeUnit <= 0x0039 && firstCodeUnit == 0x002D) {
|
|
41
|
+
// https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
|
|
42
|
+
result += '\\' + codeUnit.toString(16) + ' ';
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
// If the character is not handled by one of the above rules and is
|
|
46
|
+
// greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
|
|
47
|
+
// is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
|
|
48
|
+
// U+005A), or [a-z] (U+0061 to U+007A), […]
|
|
49
|
+
if (codeUnit >= 0x0080 || codeUnit == 0x002D || codeUnit == 0x005F || codeUnit >= 0x0030 && codeUnit <= 0x0039 || codeUnit >= 0x0041 && codeUnit <= 0x005A || codeUnit >= 0x0061 && codeUnit <= 0x007A) {
|
|
50
|
+
// the character itself
|
|
51
|
+
result += string.charAt(index);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
// Otherwise, the escaped character.
|
|
55
|
+
// https://drafts.csswg.org/cssom/#escape-a-character
|
|
56
|
+
result += '\\' + string.charAt(index);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
if (!root.CSS) {
|
|
61
|
+
root.CSS = {};
|
|
62
|
+
}
|
|
63
|
+
root.CSS.escape = cssEscape;
|
|
64
|
+
globalThis.CSS.escape = cssEscape;
|
|
65
|
+
}
|
|
66
|
+
})();
|
|
67
|
+
|
|
68
|
+
module.exports = undefined;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { commonjsGlobal } from '../_virtual/_commonjsHelpers.mjs';
|
|
2
|
+
|
|
3
|
+
(()=>{
|
|
4
|
+
const root = typeof commonjsGlobal !== 'undefined' ? commonjsGlobal : window;
|
|
5
|
+
if (!root.CSS && !root.CSS?.escape) {
|
|
6
|
+
// https://drafts.csswg.org/cssom/#serialize-an-identifier
|
|
7
|
+
const cssEscape = function(value) {
|
|
8
|
+
if (arguments.length == 0) {
|
|
9
|
+
throw new TypeError('`CSS.escape` requires an argument.');
|
|
10
|
+
}
|
|
11
|
+
const string = String(value);
|
|
12
|
+
const length = string.length;
|
|
13
|
+
let index = -1;
|
|
14
|
+
let result = '';
|
|
15
|
+
let codeUnit;
|
|
16
|
+
const firstCodeUnit = string.charCodeAt(0);
|
|
17
|
+
if (// If the character is the first character and is a `-` (U+002D), and
|
|
18
|
+
// there is no second character, […]
|
|
19
|
+
length == 1 && firstCodeUnit == 0x002D) {
|
|
20
|
+
return '\\' + string;
|
|
21
|
+
}
|
|
22
|
+
while(++index < length){
|
|
23
|
+
codeUnit = string.charCodeAt(index);
|
|
24
|
+
// Note: there’s no need to special-case astral symbols, surrogate
|
|
25
|
+
// pairs, or lone surrogates.
|
|
26
|
+
// If the character is NULL (U+0000), then the REPLACEMENT CHARACTER
|
|
27
|
+
// (U+FFFD).
|
|
28
|
+
if (codeUnit == 0x0000) {
|
|
29
|
+
result += '\uFFFD';
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (// If the character is in the range [\1-\1F] (U+0001 to U+001F) or is
|
|
33
|
+
// U+007F, […]
|
|
34
|
+
codeUnit >= 0x0001 && codeUnit <= 0x001F || codeUnit == 0x007F || // If the character is the first character and is in the range [0-9]
|
|
35
|
+
// (U+0030 to U+0039), […]
|
|
36
|
+
index == 0 && codeUnit >= 0x0030 && codeUnit <= 0x0039 || // If the character is the second character and is in the range [0-9]
|
|
37
|
+
// (U+0030 to U+0039) and the first character is a `-` (U+002D), […]
|
|
38
|
+
index == 1 && codeUnit >= 0x0030 && codeUnit <= 0x0039 && firstCodeUnit == 0x002D) {
|
|
39
|
+
// https://drafts.csswg.org/cssom/#escape-a-character-as-code-point
|
|
40
|
+
result += '\\' + codeUnit.toString(16) + ' ';
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
// If the character is not handled by one of the above rules and is
|
|
44
|
+
// greater than or equal to U+0080, is `-` (U+002D) or `_` (U+005F), or
|
|
45
|
+
// is in one of the ranges [0-9] (U+0030 to U+0039), [A-Z] (U+0041 to
|
|
46
|
+
// U+005A), or [a-z] (U+0061 to U+007A), […]
|
|
47
|
+
if (codeUnit >= 0x0080 || codeUnit == 0x002D || codeUnit == 0x005F || codeUnit >= 0x0030 && codeUnit <= 0x0039 || codeUnit >= 0x0041 && codeUnit <= 0x005A || codeUnit >= 0x0061 && codeUnit <= 0x007A) {
|
|
48
|
+
// the character itself
|
|
49
|
+
result += string.charAt(index);
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
// Otherwise, the escaped character.
|
|
53
|
+
// https://drafts.csswg.org/cssom/#escape-a-character
|
|
54
|
+
result += '\\' + string.charAt(index);
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
if (!root.CSS) {
|
|
59
|
+
root.CSS = {};
|
|
60
|
+
}
|
|
61
|
+
root.CSS.escape = cssEscape;
|
|
62
|
+
globalThis.CSS.escape = cssEscape;
|
|
63
|
+
}
|
|
64
|
+
})();
|