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