tailwindcss 0.0.0-oxide-insiders.a7fe2fe → 0.0.0-oxide-insiders.7f555c4
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/lib/cli/build/deps.js +34 -18
- package/lib/cli/build/index.js +45 -12
- package/lib/cli/build/plugin.js +273 -90
- package/lib/cli/build/utils.js +56 -24
- package/lib/cli/build/watching.js +156 -38
- package/lib/cli/help/index.js +61 -16
- package/lib/cli/index.js +121 -62
- package/lib/cli/init/index.js +47 -23
- package/lib/cli-peer-dependencies.js +23 -13
- package/lib/cli.js +5 -1
- package/lib/corePluginList.js +7 -4
- package/lib/corePlugins.js +855 -386
- package/lib/featureFlags.js +43 -18
- package/lib/lib/cacheInvalidation.js +78 -30
- package/lib/lib/collapseAdjacentRules.js +46 -23
- package/lib/lib/collapseDuplicateDeclarations.js +70 -27
- package/lib/lib/content.js +134 -41
- package/lib/lib/defaultExtractor.js +201 -96
- package/lib/lib/detectNesting.js +38 -12
- package/lib/lib/evaluateTailwindFunctions.js +192 -103
- package/lib/lib/expandApplyAtRules.js +488 -181
- package/lib/lib/expandTailwindAtRules.js +240 -70
- package/lib/lib/findAtConfigPath.js +34 -15
- package/lib/lib/generateRules.js +775 -353
- package/lib/lib/getModuleDependencies.js +67 -29
- package/lib/lib/load-config.js +27 -17
- package/lib/lib/normalizeTailwindDirectives.js +73 -27
- package/lib/lib/offsets.js +227 -62
- package/lib/lib/partitionApplyAtRules.js +53 -29
- package/lib/lib/regex.js +50 -28
- package/lib/lib/remap-bitfield.js +86 -9
- package/lib/lib/resolveDefaultsAtRules.js +123 -53
- package/lib/lib/setupContextUtils.js +1117 -584
- package/lib/lib/setupTrackingContext.js +149 -58
- package/lib/lib/sharedState.js +71 -23
- package/lib/lib/substituteScreenAtRules.js +19 -9
- package/lib/oxide/cli/build/deps.js +46 -23
- package/lib/oxide/cli/build/index.js +44 -12
- package/lib/oxide/cli/build/plugin.js +271 -89
- package/lib/oxide/cli/build/utils.js +55 -24
- package/lib/oxide/cli/build/watching.js +153 -36
- package/lib/oxide/cli/help/index.js +60 -16
- package/lib/oxide/cli/index.js +128 -67
- package/lib/oxide/cli/init/index.js +40 -19
- package/lib/oxide/cli.js +3 -2
- package/lib/plugin.js +58 -31
- package/lib/postcss-plugins/nesting/index.js +13 -7
- package/lib/postcss-plugins/nesting/plugin.js +65 -20
- package/lib/processTailwindFeatures.js +41 -10
- package/lib/public/colors.js +25 -16
- package/lib/public/create-plugin.js +11 -6
- package/lib/public/default-config.js +12 -6
- package/lib/public/default-theme.js +12 -6
- package/lib/public/load-config.js +9 -5
- package/lib/public/resolve-config.js +10 -6
- package/lib/util/applyImportantSelector.js +28 -17
- package/lib/util/bigSign.js +9 -6
- package/lib/util/buildMediaQuery.js +19 -10
- package/lib/util/cloneDeep.js +19 -9
- package/lib/util/cloneNodes.js +29 -14
- package/lib/util/color.js +87 -47
- package/lib/util/colorNames.js +752 -0
- package/lib/util/configurePlugins.js +18 -9
- package/lib/util/createPlugin.js +17 -8
- package/lib/util/createUtilityPlugin.js +30 -16
- package/lib/util/dataTypes.js +189 -38
- package/lib/util/defaults.js +21 -9
- package/lib/util/escapeClassName.js +15 -9
- package/lib/util/escapeCommas.js +9 -6
- package/lib/util/flattenColorPalette.js +11 -7
- package/lib/util/formatVariantSelector.js +209 -60
- package/lib/util/getAllConfigs.js +44 -35
- package/lib/util/hashConfig.js +12 -8
- package/lib/util/isKeyframeRule.js +10 -7
- package/lib/util/isPlainObject.js +14 -9
- package/lib/util/isSyntacticallyValidPropertyValue.js +45 -14
- package/lib/util/log.js +20 -9
- package/lib/util/nameClass.js +31 -10
- package/lib/util/negateValue.js +28 -10
- package/lib/util/normalizeConfig.js +242 -63
- package/lib/util/normalizeScreens.js +145 -70
- package/lib/util/parseAnimationValue.js +64 -14
- package/lib/util/parseBoxShadowValue.js +63 -14
- package/lib/util/parseDependency.js +39 -13
- package/lib/util/parseGlob.js +25 -8
- package/lib/util/parseObjectStyles.js +29 -18
- package/lib/util/pluginUtils.js +196 -77
- package/lib/util/prefixSelector.js +31 -12
- package/lib/util/pseudoElements.js +116 -34
- package/lib/util/removeAlphaVariables.js +23 -8
- package/lib/util/resolveConfig.js +224 -105
- package/lib/util/resolveConfigPath.js +45 -15
- package/lib/util/responsive.js +10 -6
- package/lib/util/splitAtTopLevelOnly.js +46 -10
- package/lib/util/tap.js +11 -7
- package/lib/util/toColorValue.js +10 -7
- package/lib/util/toPath.js +28 -8
- package/lib/util/transformThemeValue.js +49 -14
- package/lib/util/validateConfig.js +25 -15
- package/lib/util/validateFormalSyntax.js +14 -6
- package/lib/util/withAlphaVariable.js +54 -30
- package/package.json +18 -22
- package/peers/index.js +57849 -43101
- package/src/lib/expandTailwindAtRules.js +1 -1
- package/src/lib/setupTrackingContext.js +1 -1
- package/src/util/color.js +1 -1
- package/src/util/colorNames.js +150 -0
- package/src/util/pseudoElements.js +4 -4
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value:
|
|
4
|
-
}), Object.defineProperty(exports, "default", {
|
|
5
|
-
enumerable: !0,
|
|
6
|
-
get: ()=>getModuleDependencies
|
|
3
|
+
value: true
|
|
7
4
|
});
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return getModuleDependencies;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
12
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
13
|
+
function _interop_require_default(obj) {
|
|
10
14
|
return obj && obj.__esModule ? obj : {
|
|
11
15
|
default: obj
|
|
12
16
|
};
|
|
@@ -15,7 +19,18 @@ let jsExtensions = [
|
|
|
15
19
|
".js",
|
|
16
20
|
".cjs",
|
|
17
21
|
".mjs"
|
|
18
|
-
]
|
|
22
|
+
];
|
|
23
|
+
// Given the current file `a.ts`, we want to make sure that when importing `b` that we resolve
|
|
24
|
+
// `b.ts` before `b.js`
|
|
25
|
+
//
|
|
26
|
+
// E.g.:
|
|
27
|
+
//
|
|
28
|
+
// a.ts
|
|
29
|
+
// b // .ts
|
|
30
|
+
// c // .ts
|
|
31
|
+
// a.js
|
|
32
|
+
// b // .js or .ts
|
|
33
|
+
let jsResolutionOrder = [
|
|
19
34
|
"",
|
|
20
35
|
".js",
|
|
21
36
|
".cjs",
|
|
@@ -25,7 +40,8 @@ let jsExtensions = [
|
|
|
25
40
|
".mts",
|
|
26
41
|
".jsx",
|
|
27
42
|
".tsx"
|
|
28
|
-
]
|
|
43
|
+
];
|
|
44
|
+
let tsResolutionOrder = [
|
|
29
45
|
"",
|
|
30
46
|
".ts",
|
|
31
47
|
".cts",
|
|
@@ -36,26 +52,48 @@ let jsExtensions = [
|
|
|
36
52
|
".mjs",
|
|
37
53
|
".jsx"
|
|
38
54
|
];
|
|
55
|
+
function resolveWithExtension(file, extensions) {
|
|
56
|
+
// Try to find `./a.ts`, `./a.ts`, ... from `./a`
|
|
57
|
+
for (let ext of extensions){
|
|
58
|
+
let full = `${file}${ext}`;
|
|
59
|
+
if (_fs.default.existsSync(full) && _fs.default.statSync(full).isFile()) {
|
|
60
|
+
return full;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// Try to find `./a/index.js` from `./a`
|
|
64
|
+
for (let ext of extensions){
|
|
65
|
+
let full = `${file}/index${ext}`;
|
|
66
|
+
if (_fs.default.existsSync(full)) {
|
|
67
|
+
return full;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function* _getModuleDependencies(filename, base, seen, ext = _path.default.extname(filename)) {
|
|
73
|
+
// Try to find the file
|
|
74
|
+
let absoluteFile = resolveWithExtension(_path.default.resolve(base, filename), jsExtensions.includes(ext) ? jsResolutionOrder : tsResolutionOrder);
|
|
75
|
+
if (absoluteFile === null) return; // File doesn't exist
|
|
76
|
+
// Prevent infinite loops when there are circular dependencies
|
|
77
|
+
if (seen.has(absoluteFile)) return; // Already seen
|
|
78
|
+
seen.add(absoluteFile);
|
|
79
|
+
// Mark the file as a dependency
|
|
80
|
+
yield absoluteFile;
|
|
81
|
+
// Resolve new base for new imports/requires
|
|
82
|
+
base = _path.default.dirname(absoluteFile);
|
|
83
|
+
ext = _path.default.extname(absoluteFile);
|
|
84
|
+
let contents = _fs.default.readFileSync(absoluteFile, "utf-8");
|
|
85
|
+
// Find imports/requires
|
|
86
|
+
for (let match of [
|
|
87
|
+
...contents.matchAll(/import[\s\S]*?['"](.{3,}?)['"]/gi),
|
|
88
|
+
...contents.matchAll(/import[\s\S]*from[\s\S]*?['"](.{3,}?)['"]/gi),
|
|
89
|
+
...contents.matchAll(/require\(['"`](.+)['"`]\)/gi)
|
|
90
|
+
]){
|
|
91
|
+
// Bail out if it's not a relative file
|
|
92
|
+
if (!match[1].startsWith(".")) continue;
|
|
93
|
+
yield* _getModuleDependencies(match[1], base, seen, ext);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
39
96
|
function getModuleDependencies(absoluteFilePath) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
for (let ext of extensions){
|
|
43
|
-
let full = `${file}${ext}`;
|
|
44
|
-
if (_fs.default.existsSync(full) && _fs.default.statSync(full).isFile()) return full;
|
|
45
|
-
}
|
|
46
|
-
for (let ext of extensions){
|
|
47
|
-
let full = `${file}/index${ext}`;
|
|
48
|
-
if (_fs.default.existsSync(full)) return full;
|
|
49
|
-
}
|
|
50
|
-
return null;
|
|
51
|
-
}(_path.default.resolve(base, filename), jsExtensions.includes(ext) ? jsResolutionOrder : tsResolutionOrder);
|
|
52
|
-
if (null === absoluteFile || seen.has(absoluteFile)) return;
|
|
53
|
-
seen.add(absoluteFile), yield absoluteFile, base = _path.default.dirname(absoluteFile), ext = _path.default.extname(absoluteFile);
|
|
54
|
-
let contents = _fs.default.readFileSync(absoluteFile, "utf-8");
|
|
55
|
-
for (let match of [
|
|
56
|
-
...contents.matchAll(/import[\s\S]*?['"](.{3,}?)['"]/gi),
|
|
57
|
-
...contents.matchAll(/import[\s\S]*from[\s\S]*?['"](.{3,}?)['"]/gi),
|
|
58
|
-
...contents.matchAll(/require\(['"`](.+)['"`]\)/gi)
|
|
59
|
-
])match[1].startsWith(".") && (yield* _getModuleDependencies(match[1], base, seen, ext));
|
|
60
|
-
}(absoluteFilePath, _path.default.dirname(absoluteFilePath), new Set()));
|
|
97
|
+
if (absoluteFilePath === null) return new Set();
|
|
98
|
+
return new Set(_getModuleDependencies(absoluteFilePath, _path.default.dirname(absoluteFilePath), new Set()));
|
|
61
99
|
}
|
package/lib/lib/load-config.js
CHANGED
|
@@ -1,32 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value:
|
|
4
|
-
}), Object.defineProperty(exports, "loadConfig", {
|
|
5
|
-
enumerable: !0,
|
|
6
|
-
get: ()=>loadConfig
|
|
3
|
+
value: true
|
|
7
4
|
});
|
|
8
|
-
|
|
5
|
+
Object.defineProperty(exports, "loadConfig", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return loadConfig;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _jiti = /*#__PURE__*/ _interop_require_default(require("jiti"));
|
|
12
|
+
const _sucrase = require("sucrase");
|
|
13
|
+
function _interop_require_default(obj) {
|
|
9
14
|
return obj && obj.__esModule ? obj : {
|
|
10
15
|
default: obj
|
|
11
16
|
};
|
|
12
|
-
}
|
|
17
|
+
}
|
|
13
18
|
let jiti = null;
|
|
19
|
+
function lazyJiti() {
|
|
20
|
+
return jiti !== null && jiti !== void 0 ? jiti : jiti = (0, _jiti.default)(__filename, {
|
|
21
|
+
interopDefault: true,
|
|
22
|
+
transform: (opts)=>{
|
|
23
|
+
return (0, _sucrase.transform)(opts.source, {
|
|
24
|
+
transforms: [
|
|
25
|
+
"typescript",
|
|
26
|
+
"imports"
|
|
27
|
+
]
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
14
32
|
function loadConfig(path) {
|
|
15
|
-
var _config_default;
|
|
16
33
|
let config = function() {
|
|
17
34
|
try {
|
|
18
35
|
return path ? require(path) : {};
|
|
19
36
|
} catch {
|
|
20
|
-
return (
|
|
21
|
-
interopDefault: !0,
|
|
22
|
-
transform: (opts)=>(0, _sucrase.transform)(opts.source, {
|
|
23
|
-
transforms: [
|
|
24
|
-
"typescript",
|
|
25
|
-
"imports"
|
|
26
|
-
]
|
|
27
|
-
})
|
|
28
|
-
}))(path);
|
|
37
|
+
return lazyJiti()(path);
|
|
29
38
|
}
|
|
30
39
|
}();
|
|
31
|
-
|
|
40
|
+
var _config_default;
|
|
41
|
+
return (_config_default = config.default) !== null && _config_default !== void 0 ? _config_default : config;
|
|
32
42
|
}
|
|
@@ -1,40 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value:
|
|
4
|
-
}), Object.defineProperty(exports, "default", {
|
|
5
|
-
enumerable: !0,
|
|
6
|
-
get: ()=>normalizeTailwindDirectives
|
|
3
|
+
value: true
|
|
7
4
|
});
|
|
8
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return normalizeTailwindDirectives;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _log = /*#__PURE__*/ _interop_require_default(require("../util/log"));
|
|
12
|
+
function _interop_require_default(obj) {
|
|
9
13
|
return obj && obj.__esModule ? obj : {
|
|
10
14
|
default: obj
|
|
11
15
|
};
|
|
12
|
-
}
|
|
16
|
+
}
|
|
13
17
|
function normalizeTailwindDirectives(root) {
|
|
14
|
-
let tailwindDirectives = new Set()
|
|
15
|
-
|
|
16
|
-
|
|
18
|
+
let tailwindDirectives = new Set();
|
|
19
|
+
let layerDirectives = new Set();
|
|
20
|
+
let applyDirectives = new Set();
|
|
21
|
+
root.walkAtRules((atRule)=>{
|
|
22
|
+
if (atRule.name === "apply") {
|
|
23
|
+
applyDirectives.add(atRule);
|
|
24
|
+
}
|
|
25
|
+
if (atRule.name === "import") {
|
|
26
|
+
if (atRule.params === '"tailwindcss/base"' || atRule.params === "'tailwindcss/base'") {
|
|
27
|
+
atRule.name = "tailwind";
|
|
28
|
+
atRule.params = "base";
|
|
29
|
+
} else if (atRule.params === '"tailwindcss/components"' || atRule.params === "'tailwindcss/components'") {
|
|
30
|
+
atRule.name = "tailwind";
|
|
31
|
+
atRule.params = "components";
|
|
32
|
+
} else if (atRule.params === '"tailwindcss/utilities"' || atRule.params === "'tailwindcss/utilities'") {
|
|
33
|
+
atRule.name = "tailwind";
|
|
34
|
+
atRule.params = "utilities";
|
|
35
|
+
} else if (atRule.params === '"tailwindcss/screens"' || atRule.params === "'tailwindcss/screens'" || atRule.params === '"tailwindcss/variants"' || atRule.params === "'tailwindcss/variants'") {
|
|
36
|
+
atRule.name = "tailwind";
|
|
37
|
+
atRule.params = "variants";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (atRule.name === "tailwind") {
|
|
41
|
+
if (atRule.params === "screens") {
|
|
42
|
+
atRule.params = "variants";
|
|
43
|
+
}
|
|
44
|
+
tailwindDirectives.add(atRule.params);
|
|
45
|
+
}
|
|
46
|
+
if ([
|
|
17
47
|
"layer",
|
|
18
48
|
"responsive",
|
|
19
49
|
"variants"
|
|
20
|
-
].includes(atRule.name)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
50
|
+
].includes(atRule.name)) {
|
|
51
|
+
if ([
|
|
52
|
+
"responsive",
|
|
53
|
+
"variants"
|
|
54
|
+
].includes(atRule.name)) {
|
|
55
|
+
_log.default.warn(`${atRule.name}-at-rule-deprecated`, [
|
|
56
|
+
`The \`@${atRule.name}\` directive has been deprecated in Tailwind CSS v3.0.`,
|
|
57
|
+
`Use \`@layer utilities\` or \`@layer components\` instead.`,
|
|
58
|
+
"https://tailwindcss.com/docs/upgrade-guide#replace-variants-with-layer"
|
|
59
|
+
]);
|
|
60
|
+
}
|
|
61
|
+
layerDirectives.add(atRule);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
if (!tailwindDirectives.has("base") || !tailwindDirectives.has("components") || !tailwindDirectives.has("utilities")) {
|
|
65
|
+
for (let rule of layerDirectives){
|
|
66
|
+
if (rule.name === "layer" && [
|
|
67
|
+
"base",
|
|
68
|
+
"components",
|
|
69
|
+
"utilities"
|
|
70
|
+
].includes(rule.params)) {
|
|
71
|
+
if (!tailwindDirectives.has(rule.params)) {
|
|
72
|
+
throw rule.error(`\`@layer ${rule.params}\` is used but no matching \`@tailwind ${rule.params}\` directive is present.`);
|
|
73
|
+
}
|
|
74
|
+
} else if (rule.name === "responsive") {
|
|
75
|
+
if (!tailwindDirectives.has("utilities")) {
|
|
76
|
+
throw rule.error("`@responsive` is used but `@tailwind utilities` is missing.");
|
|
77
|
+
}
|
|
78
|
+
} else if (rule.name === "variants") {
|
|
79
|
+
if (!tailwindDirectives.has("utilities")) {
|
|
80
|
+
throw rule.error("`@variants` is used but `@tailwind utilities` is missing.");
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
38
84
|
}
|
|
39
85
|
return {
|
|
40
86
|
tailwindDirectives,
|
package/lib/lib/offsets.js
CHANGED
|
@@ -1,34 +1,64 @@
|
|
|
1
|
+
// @ts-check
|
|
1
2
|
"use strict";
|
|
2
3
|
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value:
|
|
4
|
-
}), Object.defineProperty(exports, "Offsets", {
|
|
5
|
-
enumerable: !0,
|
|
6
|
-
get: ()=>Offsets
|
|
4
|
+
value: true
|
|
7
5
|
});
|
|
8
|
-
|
|
6
|
+
Object.defineProperty(exports, "Offsets", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return Offsets;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
const _bigSign = /*#__PURE__*/ _interop_require_default(require("../util/bigSign"));
|
|
13
|
+
const _remapbitfield = require("./remap-bitfield.js");
|
|
14
|
+
function _interop_require_default(obj) {
|
|
9
15
|
return obj && obj.__esModule ? obj : {
|
|
10
16
|
default: obj
|
|
11
17
|
};
|
|
12
|
-
}
|
|
18
|
+
}
|
|
13
19
|
class Offsets {
|
|
14
20
|
constructor(){
|
|
15
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Offsets for the next rule in a given layer
|
|
23
|
+
*
|
|
24
|
+
* @type {Record<Layer, bigint>}
|
|
25
|
+
*/ this.offsets = {
|
|
16
26
|
defaults: 0n,
|
|
17
27
|
base: 0n,
|
|
18
28
|
components: 0n,
|
|
19
29
|
utilities: 0n,
|
|
20
30
|
variants: 0n,
|
|
21
31
|
user: 0n
|
|
22
|
-
}
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Positions for a given layer
|
|
35
|
+
*
|
|
36
|
+
* @type {Record<Layer, bigint>}
|
|
37
|
+
*/ this.layerPositions = {
|
|
23
38
|
defaults: 0n,
|
|
24
39
|
base: 1n,
|
|
25
40
|
components: 2n,
|
|
26
41
|
utilities: 3n,
|
|
42
|
+
// There isn't technically a "user" layer, but we need to give it a position
|
|
43
|
+
// Because it's used for ordering user-css from @apply
|
|
27
44
|
user: 4n,
|
|
28
45
|
variants: 5n
|
|
29
|
-
}
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* The total number of functions currently registered across all variants (including arbitrary variants)
|
|
49
|
+
*
|
|
50
|
+
* @type {bigint}
|
|
51
|
+
*/ this.reservedVariantBits = 0n;
|
|
52
|
+
/**
|
|
53
|
+
* Positions for a given variant
|
|
54
|
+
*
|
|
55
|
+
* @type {Map<string, bigint>}
|
|
56
|
+
*/ this.variantOffsets = new Map();
|
|
30
57
|
}
|
|
31
|
-
|
|
58
|
+
/**
|
|
59
|
+
* @param {Layer} layer
|
|
60
|
+
* @returns {RuleOffset}
|
|
61
|
+
*/ create(layer) {
|
|
32
62
|
return {
|
|
33
63
|
layer,
|
|
34
64
|
parentLayer: layer,
|
|
@@ -39,103 +69,238 @@ class Offsets {
|
|
|
39
69
|
options: []
|
|
40
70
|
};
|
|
41
71
|
}
|
|
42
|
-
|
|
72
|
+
/**
|
|
73
|
+
* @returns {RuleOffset}
|
|
74
|
+
*/ arbitraryProperty() {
|
|
43
75
|
return {
|
|
44
76
|
...this.create("utilities"),
|
|
45
77
|
arbitrary: 1n
|
|
46
78
|
};
|
|
47
79
|
}
|
|
48
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Get the offset for a variant
|
|
82
|
+
*
|
|
83
|
+
* @param {string} variant
|
|
84
|
+
* @param {number} index
|
|
85
|
+
* @returns {RuleOffset}
|
|
86
|
+
*/ forVariant(variant, index = 0) {
|
|
49
87
|
let offset = this.variantOffsets.get(variant);
|
|
50
|
-
if (
|
|
88
|
+
if (offset === undefined) {
|
|
89
|
+
throw new Error(`Cannot find offset for unknown variant ${variant}`);
|
|
90
|
+
}
|
|
51
91
|
return {
|
|
52
92
|
...this.create("variants"),
|
|
53
93
|
variants: offset << BigInt(index)
|
|
54
94
|
};
|
|
55
95
|
}
|
|
56
|
-
|
|
57
|
-
|
|
96
|
+
/**
|
|
97
|
+
* @param {RuleOffset} rule
|
|
98
|
+
* @param {RuleOffset} variant
|
|
99
|
+
* @param {VariantOption} options
|
|
100
|
+
* @returns {RuleOffset}
|
|
101
|
+
*/ applyVariantOffset(rule, variant, options) {
|
|
102
|
+
options.variant = variant.variants;
|
|
103
|
+
return {
|
|
58
104
|
...rule,
|
|
59
105
|
layer: "variants",
|
|
60
|
-
parentLayer: "variants"
|
|
106
|
+
parentLayer: rule.layer === "variants" ? rule.parentLayer : rule.layer,
|
|
61
107
|
variants: rule.variants | variant.variants,
|
|
62
108
|
options: options.sort ? [].concat(options, rule.options) : rule.options,
|
|
109
|
+
// TODO: Technically this is wrong. We should be handling parallel index on a per variant basis.
|
|
110
|
+
// We'll take the max of all the parallel indexes for now.
|
|
111
|
+
// @ts-ignore
|
|
63
112
|
parallelIndex: max([
|
|
64
113
|
rule.parallelIndex,
|
|
65
114
|
variant.parallelIndex
|
|
66
115
|
])
|
|
67
116
|
};
|
|
68
117
|
}
|
|
69
|
-
|
|
118
|
+
/**
|
|
119
|
+
* @param {RuleOffset} offset
|
|
120
|
+
* @param {number} parallelIndex
|
|
121
|
+
* @returns {RuleOffset}
|
|
122
|
+
*/ applyParallelOffset(offset, parallelIndex) {
|
|
70
123
|
return {
|
|
71
124
|
...offset,
|
|
72
125
|
parallelIndex: BigInt(parallelIndex)
|
|
73
126
|
};
|
|
74
127
|
}
|
|
75
|
-
|
|
76
|
-
|
|
128
|
+
/**
|
|
129
|
+
* Each variant gets 1 bit per function / rule registered.
|
|
130
|
+
* This is because multiple variants can be applied to a single rule and we need to know which ones are present and which ones are not.
|
|
131
|
+
* Additionally, every unique group of variants is grouped together in the stylesheet.
|
|
132
|
+
*
|
|
133
|
+
* This grouping is order-independent. For instance, we do not differentiate between `hover:focus` and `focus:hover`.
|
|
134
|
+
*
|
|
135
|
+
* @param {string[]} variants
|
|
136
|
+
* @param {(name: string) => number} getLength
|
|
137
|
+
*/ recordVariants(variants, getLength) {
|
|
138
|
+
for (let variant of variants){
|
|
139
|
+
this.recordVariant(variant, getLength(variant));
|
|
140
|
+
}
|
|
77
141
|
}
|
|
78
|
-
|
|
79
|
-
|
|
142
|
+
/**
|
|
143
|
+
* The same as `recordVariants` but for a single arbitrary variant at runtime.
|
|
144
|
+
* @param {string} variant
|
|
145
|
+
* @param {number} fnCount
|
|
146
|
+
*
|
|
147
|
+
* @returns {RuleOffset} The highest offset for this variant
|
|
148
|
+
*/ recordVariant(variant, fnCount = 1) {
|
|
149
|
+
this.variantOffsets.set(variant, 1n << this.reservedVariantBits);
|
|
150
|
+
// Ensure space is reserved for each "function" in the parallel variant
|
|
151
|
+
// by offsetting the next variant by the number of parallel variants
|
|
152
|
+
// in the one we just added.
|
|
153
|
+
// Single functions that return parallel variants are NOT handled separately here
|
|
154
|
+
// They're offset by 1 (or the number of functions) as usual
|
|
155
|
+
// And each rule returned is tracked separately since the functions are evaluated lazily.
|
|
156
|
+
// @see `RuleOffset.parallelIndex`
|
|
157
|
+
this.reservedVariantBits += BigInt(fnCount);
|
|
158
|
+
return {
|
|
80
159
|
...this.create("variants"),
|
|
81
160
|
variants: this.variantOffsets.get(variant)
|
|
82
161
|
};
|
|
83
162
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
bOptions.variant
|
|
93
|
-
])) && void 0 !== _max ? _max : 0n, mask = ~(maxFnVariant | maxFnVariant - 1n);
|
|
94
|
-
if ((a.variants & mask) != (b.variants & mask)) continue;
|
|
95
|
-
let result = aOptions.sort({
|
|
96
|
-
value: aOptions.value,
|
|
97
|
-
modifier: aOptions.modifier
|
|
98
|
-
}, {
|
|
99
|
-
value: bOptions.value,
|
|
100
|
-
modifier: bOptions.modifier
|
|
101
|
-
});
|
|
102
|
-
if (0 !== result) return result;
|
|
163
|
+
/**
|
|
164
|
+
* @param {RuleOffset} a
|
|
165
|
+
* @param {RuleOffset} b
|
|
166
|
+
* @returns {bigint}
|
|
167
|
+
*/ compare(a, b) {
|
|
168
|
+
// Sort layers together
|
|
169
|
+
if (a.layer !== b.layer) {
|
|
170
|
+
return this.layerPositions[a.layer] - this.layerPositions[b.layer];
|
|
103
171
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
172
|
+
// When sorting the `variants` layer, we need to sort based on the parent layer as well within
|
|
173
|
+
// this variants layer.
|
|
174
|
+
if (a.parentLayer !== b.parentLayer) {
|
|
175
|
+
return this.layerPositions[a.parentLayer] - this.layerPositions[b.parentLayer];
|
|
176
|
+
}
|
|
177
|
+
// Sort based on the sorting function
|
|
178
|
+
for (let aOptions of a.options){
|
|
179
|
+
for (let bOptions of b.options){
|
|
180
|
+
if (aOptions.id !== bOptions.id) continue;
|
|
181
|
+
if (!aOptions.sort || !bOptions.sort) continue;
|
|
182
|
+
var _max;
|
|
183
|
+
let maxFnVariant = (_max = max([
|
|
184
|
+
aOptions.variant,
|
|
185
|
+
bOptions.variant
|
|
186
|
+
])) !== null && _max !== void 0 ? _max : 0n;
|
|
187
|
+
// Create a mask of 0s from bits 1..N where N represents the mask of the Nth bit
|
|
188
|
+
let mask = ~(maxFnVariant | maxFnVariant - 1n);
|
|
189
|
+
let aVariantsAfterFn = a.variants & mask;
|
|
190
|
+
let bVariantsAfterFn = b.variants & mask;
|
|
191
|
+
// If the variants the same, we _can_ sort them
|
|
192
|
+
if (aVariantsAfterFn !== bVariantsAfterFn) {
|
|
193
|
+
continue;
|
|
112
194
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
195
|
+
let result = aOptions.sort({
|
|
196
|
+
value: aOptions.value,
|
|
197
|
+
modifier: aOptions.modifier
|
|
198
|
+
}, {
|
|
199
|
+
value: bOptions.value,
|
|
200
|
+
modifier: bOptions.modifier
|
|
201
|
+
});
|
|
202
|
+
if (result !== 0) return result;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
// Sort variants in the order they were registered
|
|
206
|
+
if (a.variants !== b.variants) {
|
|
207
|
+
return a.variants - b.variants;
|
|
208
|
+
}
|
|
209
|
+
// Make sure each rule returned by a parallel variant is sorted in ascending order
|
|
210
|
+
if (a.parallelIndex !== b.parallelIndex) {
|
|
211
|
+
return a.parallelIndex - b.parallelIndex;
|
|
212
|
+
}
|
|
213
|
+
// Always sort arbitrary properties after other utilities
|
|
214
|
+
if (a.arbitrary !== b.arbitrary) {
|
|
215
|
+
return a.arbitrary - b.arbitrary;
|
|
216
|
+
}
|
|
217
|
+
// Sort utilities, components, etc… in the order they were registered
|
|
218
|
+
return a.index - b.index;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Arbitrary variants are recorded in the order they're encountered.
|
|
222
|
+
* This means that the order is not stable between environments and sets of content files.
|
|
223
|
+
*
|
|
224
|
+
* In order to make the order stable, we need to remap the arbitrary variant offsets to
|
|
225
|
+
* be in alphabetical order starting from the offset of the first arbitrary variant.
|
|
226
|
+
*/ recalculateVariantOffsets() {
|
|
227
|
+
// Sort the variants by their name
|
|
228
|
+
let variants = Array.from(this.variantOffsets.entries()).filter(([v])=>v.startsWith("[")).sort(([a], [z])=>fastCompare(a, z));
|
|
229
|
+
// Sort the list of offsets
|
|
230
|
+
// This is not necessarily a discrete range of numbers which is why
|
|
231
|
+
// we're using sort instead of creating a range from min/max
|
|
232
|
+
let newOffsets = variants.map(([, offset])=>offset).sort((a, z)=>(0, _bigSign.default)(a - z));
|
|
233
|
+
// Create a map from the old offsets to the new offsets in the new sort order
|
|
234
|
+
/** @type {[bigint, bigint][]} */ let mapping = variants.map(([, oldOffset], i)=>[
|
|
116
235
|
oldOffset,
|
|
117
236
|
newOffsets[i]
|
|
118
|
-
])
|
|
237
|
+
]);
|
|
238
|
+
// Remove any variants that will not move letting us skip
|
|
239
|
+
// remapping if everything happens to be in order
|
|
240
|
+
return mapping.filter(([a, z])=>a !== z);
|
|
119
241
|
}
|
|
120
|
-
|
|
242
|
+
/**
|
|
243
|
+
* @template T
|
|
244
|
+
* @param {[RuleOffset, T][]} list
|
|
245
|
+
* @returns {[RuleOffset, T][]}
|
|
246
|
+
*/ remapArbitraryVariantOffsets(list) {
|
|
121
247
|
let mapping = this.recalculateVariantOffsets();
|
|
122
|
-
|
|
248
|
+
// No arbitrary variants? Nothing to do.
|
|
249
|
+
// Everyhing already in order? Nothing to do.
|
|
250
|
+
if (mapping.length === 0) {
|
|
251
|
+
return list;
|
|
252
|
+
}
|
|
253
|
+
// Remap every variant offset in the list
|
|
254
|
+
return list.map((item)=>{
|
|
123
255
|
let [offset, rule] = item;
|
|
256
|
+
offset = {
|
|
257
|
+
...offset,
|
|
258
|
+
variants: (0, _remapbitfield.remapBitfield)(offset.variants, mapping)
|
|
259
|
+
};
|
|
124
260
|
return [
|
|
125
|
-
offset
|
|
126
|
-
...offset,
|
|
127
|
-
variants: (0, _remapBitfieldJs.remapBitfield)(offset.variants, mapping)
|
|
128
|
-
},
|
|
261
|
+
offset,
|
|
129
262
|
rule
|
|
130
263
|
];
|
|
131
264
|
});
|
|
132
265
|
}
|
|
133
|
-
|
|
134
|
-
|
|
266
|
+
/**
|
|
267
|
+
* @template T
|
|
268
|
+
* @param {[RuleOffset, T][]} list
|
|
269
|
+
* @returns {[RuleOffset, T][]}
|
|
270
|
+
*/ sort(list) {
|
|
271
|
+
list = this.remapArbitraryVariantOffsets(list);
|
|
272
|
+
return list.sort(([a], [b])=>(0, _bigSign.default)(this.compare(a, b)));
|
|
135
273
|
}
|
|
136
274
|
}
|
|
137
|
-
|
|
275
|
+
/**
|
|
276
|
+
*
|
|
277
|
+
* @param {bigint[]} nums
|
|
278
|
+
* @returns {bigint|null}
|
|
279
|
+
*/ function max(nums) {
|
|
138
280
|
let max = null;
|
|
139
|
-
for (
|
|
281
|
+
for (const num of nums){
|
|
282
|
+
max = max !== null && max !== void 0 ? max : num;
|
|
283
|
+
max = max > num ? max : num;
|
|
284
|
+
}
|
|
140
285
|
return max;
|
|
141
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* A fast ASCII order string comparison function.
|
|
289
|
+
*
|
|
290
|
+
* Using `.sort()` without a custom compare function is faster
|
|
291
|
+
* But you can only use that if you're sorting an array of
|
|
292
|
+
* only strings. If you're sorting strings inside objects
|
|
293
|
+
* or arrays, you need must use a custom compare function.
|
|
294
|
+
*
|
|
295
|
+
* @param {string} a
|
|
296
|
+
* @param {string} b
|
|
297
|
+
*/ function fastCompare(a, b) {
|
|
298
|
+
let aLen = a.length;
|
|
299
|
+
let bLen = b.length;
|
|
300
|
+
let minLen = aLen < bLen ? aLen : bLen;
|
|
301
|
+
for(let i = 0; i < minLen; i++){
|
|
302
|
+
let cmp = a.charCodeAt(i) - b.charCodeAt(i);
|
|
303
|
+
if (cmp !== 0) return cmp;
|
|
304
|
+
}
|
|
305
|
+
return aLen - bLen;
|
|
306
|
+
}
|