boss-css 0.0.1 → 0.0.3
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 +1 -0
- package/dist/_virtual/rolldown_runtime.cjs +43 -0
- package/dist/_virtual/rolldown_runtime.mjs +20 -0
- package/dist/api/browser.cjs +54 -0
- package/dist/api/browser.mjs +48 -0
- package/dist/api/config.cjs +94 -0
- package/dist/api/config.mjs +91 -0
- package/dist/api/css.cjs +304 -0
- package/dist/api/css.mjs +303 -0
- package/dist/api/dictionary.cjs +218 -0
- package/dist/api/dictionary.mjs +215 -0
- package/dist/api/file/dts.cjs +21 -0
- package/dist/api/file/dts.mjs +21 -0
- package/dist/api/file/file.cjs +123 -0
- package/dist/api/file/file.mjs +120 -0
- package/dist/api/file/js.cjs +118 -0
- package/dist/api/file/js.mjs +116 -0
- package/dist/api/names.cjs +52 -0
- package/dist/api/names.mjs +46 -0
- package/dist/api/noopCss.cjs +37 -0
- package/dist/api/noopCss.mjs +36 -0
- package/dist/api/propTree.cjs +54 -0
- package/dist/api/propTree.mjs +48 -0
- package/dist/api/server.cjs +112 -0
- package/dist/api/server.mjs +106 -0
- package/dist/cli/build.cjs +1 -0
- package/dist/cli/build.mjs +3 -0
- package/dist/cli/index.cjs +30 -0
- package/dist/cli/index.mjs +29 -0
- package/dist/cli/tasks/build.cjs +24 -0
- package/dist/cli/tasks/build.mjs +23 -0
- package/dist/cli/tasks/choose.cjs +47 -0
- package/dist/cli/tasks/choose.mjs +46 -0
- package/dist/cli/tasks/compile.cjs +68 -0
- package/dist/cli/tasks/compile.mjs +67 -0
- package/dist/cli/tasks/dev.cjs +51 -0
- package/dist/cli/tasks/dev.mjs +48 -0
- package/dist/cli/tasks/init.cjs +1835 -0
- package/dist/cli/tasks/init.mjs +1831 -0
- package/dist/cli/tasks/watch.cjs +38 -0
- package/dist/cli/tasks/watch.mjs +37 -0
- package/dist/cli/templates/init.cjs +82 -0
- package/dist/cli/templates/init.mjs +78 -0
- package/dist/cli/types.cjs +13 -0
- package/dist/cli/types.mjs +13 -0
- package/dist/cli/utils.cjs +43 -0
- package/dist/cli/utils.mjs +41 -0
- package/dist/compile/classname-strategy.cjs +79 -0
- package/dist/compile/classname-strategy.mjs +77 -0
- package/dist/compile/classname.cjs +366 -0
- package/dist/compile/classname.mjs +360 -0
- package/dist/compile/index.cjs +238 -0
- package/dist/compile/index.mjs +235 -0
- package/dist/compile/jsx.cjs +803 -0
- package/dist/compile/jsx.mjs +800 -0
- package/dist/compile/prepared.cjs +88 -0
- package/dist/compile/prepared.mjs +87 -0
- package/dist/compile/runtime.cjs +33 -0
- package/dist/compile/runtime.mjs +32 -0
- package/dist/compile/transform.cjs +371 -0
- package/dist/compile/transform.mjs +369 -0
- package/dist/cx/index.cjs +93 -0
- package/dist/cx/index.mjs +85 -0
- package/dist/detect-fw/index.cjs +384 -0
- package/dist/detect-fw/index.mjs +379 -0
- package/dist/dev/client.cjs +39 -0
- package/dist/dev/client.mjs +38 -0
- package/dist/dev/plugin/browser.cjs +11 -0
- package/dist/dev/plugin/browser.mjs +9 -0
- package/dist/dev/plugin/server.cjs +86 -0
- package/dist/dev/plugin/server.mjs +78 -0
- package/dist/dev/port.cjs +46 -0
- package/dist/dev/port.mjs +43 -0
- package/dist/dev/runtime.cjs +28 -0
- package/dist/dev/runtime.mjs +29 -0
- package/dist/dev/server.cjs +808 -0
- package/dist/dev/server.mjs +805 -0
- package/dist/dev/shared.cjs +6 -0
- package/dist/dev/shared.mjs +5 -0
- package/dist/eslint-plugin/index.cjs +66 -0
- package/dist/eslint-plugin/index.mjs +66 -0
- package/dist/eslint-plugin/rules/classnames-only.cjs +68 -0
- package/dist/eslint-plugin/rules/classnames-only.mjs +68 -0
- package/dist/eslint-plugin/rules/format-classnames.cjs +137 -0
- package/dist/eslint-plugin/rules/format-classnames.mjs +136 -0
- package/dist/eslint-plugin/rules/no-unknown-classes.cjs +119 -0
- package/dist/eslint-plugin/rules/no-unknown-classes.mjs +119 -0
- package/dist/eslint-plugin/rules/prefer-classnames.cjs +69 -0
- package/dist/eslint-plugin/rules/prefer-classnames.mjs +69 -0
- package/dist/eslint-plugin/rules/prefer-token-values.cjs +197 -0
- package/dist/eslint-plugin/rules/prefer-token-values.mjs +197 -0
- package/dist/eslint-plugin/rules/props-only.cjs +115 -0
- package/dist/eslint-plugin/rules/props-only.mjs +115 -0
- package/dist/eslint-plugin/rules/redundant-cx.cjs +66 -0
- package/dist/eslint-plugin/rules/redundant-cx.mjs +66 -0
- package/dist/eslint-plugin/rules/require-prop-functions.cjs +130 -0
- package/dist/eslint-plugin/rules/require-prop-functions.mjs +130 -0
- package/dist/eslint-plugin/utils/api.cjs +30 -0
- package/dist/eslint-plugin/utils/api.mjs +29 -0
- package/dist/eslint-plugin/utils/ast.cjs +119 -0
- package/dist/eslint-plugin/utils/ast.mjs +112 -0
- package/dist/eslint-plugin/utils/boss-classes.cjs +185 -0
- package/dist/eslint-plugin/utils/boss-classes.mjs +175 -0
- package/dist/eslint-plugin/utils/defaults.cjs +99 -0
- package/dist/eslint-plugin/utils/defaults.mjs +93 -0
- package/dist/eslint-plugin/utils/format.cjs +20 -0
- package/dist/eslint-plugin/utils/format.mjs +19 -0
- package/dist/eslint-plugin/utils/order.cjs +76 -0
- package/dist/eslint-plugin/utils/order.mjs +76 -0
- package/dist/eslint-plugin/utils/property-order.cjs +449 -0
- package/dist/eslint-plugin/utils/property-order.mjs +448 -0
- package/dist/eslint-plugin/utils/static.cjs +36 -0
- package/dist/eslint-plugin/utils/static.mjs +35 -0
- package/dist/fontsource/directory.cjs +39588 -0
- package/dist/fontsource/directory.mjs +39587 -0
- package/dist/fontsource/server.cjs +291 -0
- package/dist/fontsource/server.mjs +282 -0
- package/dist/index.cjs +10 -0
- package/dist/index.mjs +6 -0
- package/dist/log/browser.cjs +28 -0
- package/dist/log/browser.mjs +28 -0
- package/dist/log/server.cjs +32 -0
- package/dist/log/server.mjs +30 -0
- package/dist/merge/index.cjs +590 -0
- package/dist/merge/index.mjs +586 -0
- package/dist/native/browser.cjs +78 -0
- package/dist/native/browser.mjs +77 -0
- package/dist/native/server.cjs +180 -0
- package/dist/native/server.mjs +176 -0
- package/dist/native/styleTypes.cjs +168 -0
- package/dist/native/styleTypes.mjs +164 -0
- package/dist/parser/classname/server.cjs +239 -0
- package/dist/parser/classname/server.mjs +232 -0
- package/dist/parser/jsx/browser.cjs +66 -0
- package/dist/parser/jsx/browser.mjs +63 -0
- package/dist/parser/jsx/extractCode.cjs +99 -0
- package/dist/parser/jsx/extractCode.mjs +98 -0
- package/dist/parser/jsx/extractPrepared.cjs +123 -0
- package/dist/parser/jsx/extractPrepared.mjs +122 -0
- package/dist/parser/jsx/extractProps.cjs +234 -0
- package/dist/parser/jsx/extractProps.mjs +232 -0
- package/dist/parser/jsx/isDOMProp.cjs +17 -0
- package/dist/parser/jsx/isDOMProp.mjs +15 -0
- package/dist/parser/jsx/native.cjs +110 -0
- package/dist/parser/jsx/native.mjs +108 -0
- package/dist/parser/jsx/runtime.cjs +4 -0
- package/dist/parser/jsx/runtime.mjs +3 -0
- package/dist/parser/jsx/server.cjs +278 -0
- package/dist/parser/jsx/server.mjs +268 -0
- package/dist/postcss/index.cjs +16 -0
- package/dist/postcss/index.mjs +16 -0
- package/dist/prop/at/runtime-only.cjs +90 -0
- package/dist/prop/at/runtime-only.mjs +88 -0
- package/dist/prop/at/server.cjs +282 -0
- package/dist/prop/at/server.mjs +268 -0
- package/dist/prop/at/shared.cjs +153 -0
- package/dist/prop/at/shared.mjs +144 -0
- package/dist/prop/bosswind/browser.cjs +18 -0
- package/dist/prop/bosswind/browser.mjs +16 -0
- package/dist/prop/bosswind/runtime-only.cjs +18 -0
- package/dist/prop/bosswind/runtime-only.mjs +16 -0
- package/dist/prop/bosswind/server.cjs +81 -0
- package/dist/prop/bosswind/server.mjs +72 -0
- package/dist/prop/bosswind/shared.cjs +861 -0
- package/dist/prop/bosswind/shared.mjs +855 -0
- package/dist/prop/bosswind/tailwind-theme.cjs +703 -0
- package/dist/prop/bosswind/tailwind-theme.mjs +702 -0
- package/dist/prop/child/runtime-only.cjs +18 -0
- package/dist/prop/child/runtime-only.mjs +15 -0
- package/dist/prop/child/server.cjs +81 -0
- package/dist/prop/child/server.mjs +72 -0
- package/dist/prop/css/getDtsTemplate.cjs +65 -0
- package/dist/prop/css/getDtsTemplate.mjs +63 -0
- package/dist/prop/css/runtime-only.cjs +14 -0
- package/dist/prop/css/runtime-only.mjs +13 -0
- package/dist/prop/css/server.cjs +99 -0
- package/dist/prop/css/server.mjs +90 -0
- package/dist/prop/pseudo/runtime-only.cjs +23 -0
- package/dist/prop/pseudo/runtime-only.mjs +21 -0
- package/dist/prop/pseudo/server.cjs +91 -0
- package/dist/prop/pseudo/server.mjs +82 -0
- package/dist/prop/pseudo/shared.cjs +61 -0
- package/dist/prop/pseudo/shared.mjs +60 -0
- package/dist/reset/server.cjs +34 -0
- package/dist/reset/server.mjs +26 -0
- package/dist/runtime/index.cjs +119 -0
- package/dist/runtime/index.mjs +118 -0
- package/dist/runtime/preact.cjs +4 -0
- package/dist/runtime/preact.mjs +3 -0
- package/dist/runtime/qwik.cjs +21 -0
- package/dist/runtime/qwik.mjs +18 -0
- package/dist/runtime/react.cjs +4 -0
- package/dist/runtime/react.mjs +3 -0
- package/dist/runtime/solid.cjs +15 -0
- package/dist/runtime/solid.mjs +14 -0
- package/dist/runtime/stencil.cjs +25 -0
- package/dist/runtime/stencil.mjs +21 -0
- package/dist/runtime/style.cjs +14 -0
- package/dist/runtime/style.mjs +13 -0
- package/dist/shared/boundaries.cjs +288 -0
- package/dist/shared/boundaries.mjs +285 -0
- package/dist/shared/customCss.cjs +212 -0
- package/dist/shared/customCss.mjs +211 -0
- package/dist/shared/debug.cjs +76 -0
- package/dist/shared/debug.mjs +74 -0
- package/dist/shared/file.cjs +21 -0
- package/dist/shared/file.mjs +19 -0
- package/dist/shared/framework.cjs +10 -0
- package/dist/shared/framework.mjs +9 -0
- package/dist/shared/json.cjs +58 -0
- package/dist/shared/json.mjs +57 -0
- package/dist/shared/types.cjs +11 -0
- package/dist/shared/types.mjs +10 -0
- package/dist/strategy/classic/runtime-only.cjs +190 -0
- package/dist/strategy/classic/runtime-only.mjs +186 -0
- package/dist/strategy/classname-first/runtime-only.cjs +138 -0
- package/dist/strategy/classname-first/runtime-only.mjs +134 -0
- package/dist/strategy/classname-first/server.cjs +139 -0
- package/dist/strategy/classname-first/server.mjs +133 -0
- package/dist/strategy/classname-only/server.cjs +43 -0
- package/dist/strategy/classname-only/server.mjs +35 -0
- package/dist/strategy/inline-first/browser.cjs +61 -0
- package/dist/strategy/inline-first/browser.mjs +58 -0
- package/dist/strategy/inline-first/runtime-only.cjs +159 -0
- package/dist/strategy/inline-first/runtime-only.mjs +155 -0
- package/dist/strategy/inline-first/server.cjs +92 -0
- package/dist/strategy/inline-first/server.mjs +83 -0
- package/dist/strategy/runtime/runtime-only.cjs +24 -0
- package/dist/strategy/runtime/runtime-only.mjs +22 -0
- package/dist/strategy/runtime/server.cjs +72 -0
- package/dist/strategy/runtime/server.mjs +63 -0
- package/dist/strategy/runtime-only/css.cjs +183 -0
- package/dist/strategy/runtime-only/css.mjs +181 -0
- package/dist/tasks/build.cjs +88 -0
- package/dist/tasks/build.mjs +84 -0
- package/dist/tasks/compile.cjs +12 -0
- package/dist/tasks/compile.mjs +12 -0
- package/dist/tasks/postcss.cjs +116 -0
- package/dist/tasks/postcss.mjs +113 -0
- package/dist/tasks/session.cjs +46 -0
- package/dist/tasks/session.mjs +42 -0
- package/dist/tasks/watch.cjs +102 -0
- package/dist/tasks/watch.mjs +99 -0
- package/dist/transform/cache.cjs +24 -0
- package/dist/transform/cache.mjs +21 -0
- package/dist/transform/processFile.cjs +26 -0
- package/dist/transform/processFile.mjs +24 -0
- package/dist/use/token/browser.cjs +65 -0
- package/dist/use/token/browser.mjs +61 -0
- package/dist/use/token/runtime-only.cjs +245 -0
- package/dist/use/token/runtime-only.mjs +239 -0
- package/dist/use/token/server.cjs +325 -0
- package/dist/use/token/server.mjs +313 -0
- package/dist/use/token/vars.cjs +47 -0
- package/dist/use/token/vars.mjs +46 -0
- package/package.json +300 -4
- package/src/api/config.d.ts +1 -0
- package/src/fontsource/types.d.ts +50 -0
- package/src/packages/document-create-element/createElement.browser.js +3 -0
- package/src/packages/document-create-element/createElement.js +7 -0
- package/src/packages/document-create-element/package.json +17 -0
- package/src/packages/is-css-prop/browser.js +13 -0
- package/src/packages/is-css-prop/index.js +13 -0
- package/src/packages/is-css-prop/package-lock.json +52 -0
- package/src/packages/is-css-prop/package.json +17 -0
- package/src/prop/css/csstype.json +4387 -0
- package/src/prop/css/package.json +3 -0
- package/src/reset/reset.css +259 -0
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let ts_deepmerge = require("ts-deepmerge");
|
|
3
|
+
|
|
4
|
+
//#region src/use/token/server.ts
|
|
5
|
+
var server_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
6
|
+
getTokens: () => getTokens,
|
|
7
|
+
name: () => name,
|
|
8
|
+
onBoot: () => onBoot,
|
|
9
|
+
onPropTree: () => onPropTree,
|
|
10
|
+
onReady: () => onReady,
|
|
11
|
+
propMap: () => propMap,
|
|
12
|
+
set: () => set
|
|
13
|
+
});
|
|
14
|
+
const name = "token";
|
|
15
|
+
const propMap = new Map([
|
|
16
|
+
["color", new Set([
|
|
17
|
+
"color",
|
|
18
|
+
"background",
|
|
19
|
+
"background-color",
|
|
20
|
+
"border-color",
|
|
21
|
+
"accent-color",
|
|
22
|
+
"caret-color",
|
|
23
|
+
"fill",
|
|
24
|
+
"outline-color",
|
|
25
|
+
"stroke",
|
|
26
|
+
"text-decoration-color",
|
|
27
|
+
"text-shadow",
|
|
28
|
+
"box-shadow",
|
|
29
|
+
"background-image",
|
|
30
|
+
"linear-gradient",
|
|
31
|
+
"radial-gradient",
|
|
32
|
+
"conic-gradient",
|
|
33
|
+
"filter"
|
|
34
|
+
])],
|
|
35
|
+
["size", new Set([
|
|
36
|
+
"width",
|
|
37
|
+
"height",
|
|
38
|
+
"min-width",
|
|
39
|
+
"min-height",
|
|
40
|
+
"max-width",
|
|
41
|
+
"max-height",
|
|
42
|
+
"inset",
|
|
43
|
+
"top",
|
|
44
|
+
"right",
|
|
45
|
+
"bottom",
|
|
46
|
+
"left",
|
|
47
|
+
"translate",
|
|
48
|
+
"flex-basis",
|
|
49
|
+
"gap",
|
|
50
|
+
"column-gap",
|
|
51
|
+
"row-gap",
|
|
52
|
+
"margin",
|
|
53
|
+
"margin-top",
|
|
54
|
+
"margin-right",
|
|
55
|
+
"margin-bottom",
|
|
56
|
+
"margin-left",
|
|
57
|
+
"padding",
|
|
58
|
+
"padding-top",
|
|
59
|
+
"padding-right",
|
|
60
|
+
"padding-bottom",
|
|
61
|
+
"padding-left",
|
|
62
|
+
"border-spacing",
|
|
63
|
+
"scroll-margin",
|
|
64
|
+
"scroll-margin-top",
|
|
65
|
+
"scroll-margin-right",
|
|
66
|
+
"scroll-margin-bottom",
|
|
67
|
+
"scroll-margin-left",
|
|
68
|
+
"scroll-padding",
|
|
69
|
+
"scroll-padding-top",
|
|
70
|
+
"scroll-padding-right",
|
|
71
|
+
"scroll-padding-bottom",
|
|
72
|
+
"scroll-padding-left",
|
|
73
|
+
"text-indent"
|
|
74
|
+
])],
|
|
75
|
+
["grid", new Set([
|
|
76
|
+
"grid-column",
|
|
77
|
+
"grid-row",
|
|
78
|
+
"grid-template-columns",
|
|
79
|
+
"grid-template-rows",
|
|
80
|
+
"grid-auto-columns",
|
|
81
|
+
"grid-auto-rows"
|
|
82
|
+
])],
|
|
83
|
+
["duration", new Set([
|
|
84
|
+
"transition-duration",
|
|
85
|
+
"transition-delay",
|
|
86
|
+
"animation-duration",
|
|
87
|
+
"animation-delay"
|
|
88
|
+
])],
|
|
89
|
+
["backgroundPosition", new Set([
|
|
90
|
+
"background-position",
|
|
91
|
+
"object-position",
|
|
92
|
+
"transform-origin"
|
|
93
|
+
])],
|
|
94
|
+
["font", new Set(["font-family"])]
|
|
95
|
+
]);
|
|
96
|
+
let originals = {};
|
|
97
|
+
const getTokens = () => originals;
|
|
98
|
+
const set = (input) => {
|
|
99
|
+
const resolvedInput = typeof input === "object" ? input : input(valueMap);
|
|
100
|
+
originals = (0, ts_deepmerge.merge)(originals, resolvedInput);
|
|
101
|
+
for (const [key, value] of Object.entries(resolvedInput)) {
|
|
102
|
+
const propsToMap = propMap.get(key) || [key];
|
|
103
|
+
for (const prop of propsToMap) valueMap.set(prop, value);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
let valueMap;
|
|
107
|
+
let hasTokens = false;
|
|
108
|
+
let hasProxyTokens = false;
|
|
109
|
+
let hasTokenOverrides = false;
|
|
110
|
+
let browserResolvedPaths;
|
|
111
|
+
let emittedAllTokens = false;
|
|
112
|
+
let runtimeIncludesTokenPaths = false;
|
|
113
|
+
let tokenCreatorVarName = "";
|
|
114
|
+
let tokenVarsVarName = "";
|
|
115
|
+
const alphaWarnings = /* @__PURE__ */ new Set();
|
|
116
|
+
const tokenAlphaKeyPattern = /^[a-zA-Z0-9_.-]+$/;
|
|
117
|
+
const parseTokenAlphaValue = (value) => {
|
|
118
|
+
const slashIndex = value.lastIndexOf("/");
|
|
119
|
+
if (slashIndex <= 0 || slashIndex === value.length - 1) return null;
|
|
120
|
+
const base = value.slice(0, slashIndex);
|
|
121
|
+
const alphaRaw = value.slice(slashIndex + 1);
|
|
122
|
+
if (!tokenAlphaKeyPattern.test(base)) return null;
|
|
123
|
+
if (!/^\d{1,3}$/.test(alphaRaw)) return {
|
|
124
|
+
base,
|
|
125
|
+
alpha: null,
|
|
126
|
+
alphaRaw
|
|
127
|
+
};
|
|
128
|
+
const alpha = Number(alphaRaw);
|
|
129
|
+
if (!Number.isInteger(alpha) || alpha < 0 || alpha > 100) return {
|
|
130
|
+
base,
|
|
131
|
+
alpha: null,
|
|
132
|
+
alphaRaw
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
base,
|
|
136
|
+
alpha,
|
|
137
|
+
alphaRaw
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
const resolveTokenParts = (values, pathParts) => {
|
|
141
|
+
if (!pathParts.length) return values;
|
|
142
|
+
return pathParts.reduce((acc, key) => acc?.[key]?.value ?? acc?.[key], values);
|
|
143
|
+
};
|
|
144
|
+
const warnAlpha = (message) => {
|
|
145
|
+
if (alphaWarnings.has(message)) return;
|
|
146
|
+
alphaWarnings.add(message);
|
|
147
|
+
console.warn(`[boss-css] ${message}`);
|
|
148
|
+
};
|
|
149
|
+
const onBoot = async (api) => {
|
|
150
|
+
hasTokens = false;
|
|
151
|
+
hasProxyTokens = false;
|
|
152
|
+
hasTokenOverrides = false;
|
|
153
|
+
browserResolvedPaths = /* @__PURE__ */ new Set();
|
|
154
|
+
emittedAllTokens = false;
|
|
155
|
+
runtimeIncludesTokenPaths = false;
|
|
156
|
+
valueMap = /* @__PURE__ */ new Map();
|
|
157
|
+
valueMap.asObject = function() {
|
|
158
|
+
return Array.from(this.entries()).reduce((acc, [key, value]) => {
|
|
159
|
+
acc[key] = value;
|
|
160
|
+
return acc;
|
|
161
|
+
}, {});
|
|
162
|
+
};
|
|
163
|
+
set({ color: {
|
|
164
|
+
black: "#000",
|
|
165
|
+
white: "#fff"
|
|
166
|
+
} });
|
|
167
|
+
if (api.tokens) set(api.tokens);
|
|
168
|
+
const shouldEmitRuntime = () => Boolean(hasTokens || hasProxyTokens || hasTokenOverrides || api.emitAllTokens);
|
|
169
|
+
const runtimeConfig = api.runtime;
|
|
170
|
+
const hasRuntimeConfig = Boolean(runtimeConfig && (runtimeConfig.only !== void 0 || runtimeConfig.strategy));
|
|
171
|
+
runtimeIncludesTokenPaths = hasRuntimeConfig;
|
|
172
|
+
const runtimeModule = hasRuntimeConfig ? "boss-css/use/token/runtime-only" : "boss-css/use/token/browser";
|
|
173
|
+
api.file.js.importAndConfig({
|
|
174
|
+
name: "onInit",
|
|
175
|
+
from: runtimeModule
|
|
176
|
+
}, shouldEmitRuntime);
|
|
177
|
+
api.file.js.importAndConfig({
|
|
178
|
+
name: "onBrowserObjectStart",
|
|
179
|
+
from: runtimeModule
|
|
180
|
+
}, shouldEmitRuntime);
|
|
181
|
+
const tokenPathsVarName = api.file.js.import({
|
|
182
|
+
name: "tokenPaths",
|
|
183
|
+
from: runtimeModule
|
|
184
|
+
}, () => browserResolvedPaths.size > 0 || Boolean(api.emitAllTokens));
|
|
185
|
+
const shouldEmitTokenProxy = () => Boolean(hasProxyTokens);
|
|
186
|
+
tokenCreatorVarName = api.file.js.import({
|
|
187
|
+
name: "create",
|
|
188
|
+
from: runtimeModule
|
|
189
|
+
}, shouldEmitTokenProxy);
|
|
190
|
+
tokenVarsVarName = api.file.js.import({
|
|
191
|
+
name: "tokenVars",
|
|
192
|
+
from: runtimeModule
|
|
193
|
+
}, () => true);
|
|
194
|
+
if (hasRuntimeConfig) api.file.js.config({
|
|
195
|
+
from: runtimeModule,
|
|
196
|
+
config: {
|
|
197
|
+
tokens: originals,
|
|
198
|
+
runtime: runtimeConfig
|
|
199
|
+
}
|
|
200
|
+
}, shouldEmitRuntime);
|
|
201
|
+
api.file.js.set("body", "token:browserResolvedPaths", () => `;${JSON.stringify(Array.from(browserResolvedPaths))}.forEach(v => ${tokenPathsVarName}.add(v))`, () => browserResolvedPaths.size > 0 || Boolean(api.emitAllTokens));
|
|
202
|
+
};
|
|
203
|
+
const onReady = async (api) => {
|
|
204
|
+
api.file.js.dts.set("body", "token:types", `type $$TokenLeaf = string | number | (string | number)[]
|
|
205
|
+
type $$TokenDefinition = ${JSON.stringify(originals, null, 4)}
|
|
206
|
+
type $$TokenOverrides<T = $$TokenDefinition> =
|
|
207
|
+
T extends any[]
|
|
208
|
+
? $$TokenLeaf
|
|
209
|
+
: T extends { value: infer V }
|
|
210
|
+
? $$TokenOverrides<V> | { [K in keyof T]?: $$TokenOverrides<T[K]> }
|
|
211
|
+
: T extends object
|
|
212
|
+
? { [K in keyof T]?: $$TokenOverrides<T[K]> }
|
|
213
|
+
: $$TokenLeaf
|
|
214
|
+
`);
|
|
215
|
+
api.file.js.dts.replace("body", "$$:FinalProps", (value) => `${value} & { tokens?: $$TokenOverrides }`);
|
|
216
|
+
api.file.js.dts.prepend("body", "jsx:proxy-custom-members", ` token: ${JSON.stringify(originals, null, 4)}\n`);
|
|
217
|
+
api.file.js.dts.prepend("body", "jsx:proxy-custom-members", ` tokenVars: (overrides: $$TokenOverrides) => Record<string, string | number>\n`);
|
|
218
|
+
const shouldEmitTokenProxy = () => hasProxyTokens;
|
|
219
|
+
api.file.js.set("foot", "token:$$.token", `$$.token = ${tokenCreatorVarName}()`, shouldEmitTokenProxy);
|
|
220
|
+
api.file.js.set("foot", "token:$$.tokenVars", `$$.tokenVars = ${tokenVarsVarName}`);
|
|
221
|
+
for (const [name, values] of valueMap) {
|
|
222
|
+
const descriptor = api.dictionary.get(name);
|
|
223
|
+
if (!values || typeof values !== "object") continue;
|
|
224
|
+
const keys = Object.keys(values);
|
|
225
|
+
if (!descriptor) continue;
|
|
226
|
+
for (const alias of descriptor.aliases) {
|
|
227
|
+
const cssDescription = api.file.js.dts.get("body").get(`css:${alias}:description`);
|
|
228
|
+
const cssDeclaration = api.file.js.dts.get("body").get(`css:${alias}:declaration`);
|
|
229
|
+
if (cssDescription) api.file.js.dts.prepend("body", `css:${alias}:description`, `**Available tokens**\n
|
|
230
|
+
${keys.map((k) => `- \`${k}\`: \`${values[k]}\``).join("\n")}
|
|
231
|
+
\n`);
|
|
232
|
+
if (cssDeclaration) {
|
|
233
|
+
const cssContent = String(cssDeclaration.content ?? "");
|
|
234
|
+
api.file.js.dts.set("body", `css:${alias}:declaration`, cssContent.replace("?: ", `?: ${keys.map((k) => `"${k}"`).join(" | ")} | `));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const onPropTree = async (api, { tree, parser }) => {
|
|
240
|
+
if (!hasTokenOverrides && tree && typeof tree === "object" && "tokens" in tree) {
|
|
241
|
+
hasTokenOverrides = true;
|
|
242
|
+
hasTokens = true;
|
|
243
|
+
}
|
|
244
|
+
if (api.emitAllTokens && !emittedAllTokens) {
|
|
245
|
+
emittedAllTokens = true;
|
|
246
|
+
hasTokens = true;
|
|
247
|
+
const addTokenVars = (prefix, value) => {
|
|
248
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
249
|
+
for (const [key, next] of Object.entries(value)) addTokenVars(prefix ? `${prefix}.${key}` : key, next);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (!prefix) return;
|
|
253
|
+
const varName = `--${api.selectorPrefix ?? ""}${prefix.replace(/\./g, "-")}`;
|
|
254
|
+
api.css.addRoot(`${varName}: ${api.dictionary.toValue(value)};`);
|
|
255
|
+
browserResolvedPaths.add(prefix);
|
|
256
|
+
};
|
|
257
|
+
for (const [group, value] of valueMap.entries()) addTokenVars(group, value);
|
|
258
|
+
}
|
|
259
|
+
api.walkPropTree(tree, (name, prop) => {
|
|
260
|
+
const descriptor = api.dictionary.get(name);
|
|
261
|
+
if (!descriptor) return;
|
|
262
|
+
const isTokenCodeString = Boolean(prop.dynamic && prop.code?.startsWith("$$.token."));
|
|
263
|
+
hasProxyTokens = hasProxyTokens || isTokenCodeString;
|
|
264
|
+
const pathString = isTokenCodeString ? prop.code?.replace("$$.token.", "") : typeof prop.value === "string" ? prop.value.startsWith("$$.token") ? prop.value.replace("$$.token.", "") : `${name}.${prop.value}` : prop.value;
|
|
265
|
+
if (typeof pathString !== "string") return;
|
|
266
|
+
const path = pathString.split(".");
|
|
267
|
+
const [tokenGroupName, ...rest] = path;
|
|
268
|
+
const { aliases } = descriptor;
|
|
269
|
+
const valuesByGroupName = valueMap.get(tokenGroupName);
|
|
270
|
+
const values = aliases.reduce((acc, alias) => {
|
|
271
|
+
return acc || valueMap.get(alias) || null;
|
|
272
|
+
}, null) || valuesByGroupName;
|
|
273
|
+
if (!values) return;
|
|
274
|
+
const rawValue = prop.value;
|
|
275
|
+
const colorTokens = valueMap.get("color");
|
|
276
|
+
const tokenAlpha = typeof rawValue === "string" && values && colorTokens && values === colorTokens ? parseTokenAlphaValue(rawValue) : null;
|
|
277
|
+
if (tokenAlpha) {
|
|
278
|
+
const baseValue = resolveTokenParts(values, tokenAlpha.base.split("."));
|
|
279
|
+
if (baseValue === void 0) {
|
|
280
|
+
warnAlpha(`Unknown token "${tokenAlpha.base}" for "${name}:${rawValue}".`);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (tokenAlpha.alpha === null) {
|
|
284
|
+
warnAlpha(`Invalid token alpha "${tokenAlpha.alphaRaw}" for "${name}:${rawValue}" (use 0-100).`);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const tokenPath = `${name}.${tokenAlpha.base}`;
|
|
288
|
+
const varName = `--${api.selectorPrefix ?? ""}${tokenPath.replace(/\./g, "-")}`;
|
|
289
|
+
const mixValue = `color-mix(in oklab, var(${varName}) ${tokenAlpha.alpha}%, transparent)`;
|
|
290
|
+
prop.dynamic = false;
|
|
291
|
+
prop.selectorValue = rawValue;
|
|
292
|
+
prop.value = mixValue;
|
|
293
|
+
hasTokens = true;
|
|
294
|
+
api.css.addRoot(`${varName}: ${api.dictionary.toValue(baseValue)};`);
|
|
295
|
+
if (parser !== "classname") browserResolvedPaths.add(tokenPath);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const tokenValue = rest.length ? resolveTokenParts(values, rest) : void 0;
|
|
299
|
+
if (tokenValue !== void 0) {
|
|
300
|
+
const varName = `--${api.selectorPrefix ?? ""}${path.join("-")}`;
|
|
301
|
+
prop.dynamic = false;
|
|
302
|
+
prop.selectorValue = parser === "classname" ? prop.value : rest.join(".");
|
|
303
|
+
prop.value = `var(${varName})`;
|
|
304
|
+
hasTokens = true;
|
|
305
|
+
api.css.addRoot(`${varName}: ${api.dictionary.toValue(tokenValue)};`);
|
|
306
|
+
const shouldTrackPath = runtimeIncludesTokenPaths || typeof prop.value === "string" && !prop.value.startsWith("$$");
|
|
307
|
+
if (parser !== "classname" && typeof pathString === "string" && shouldTrackPath) browserResolvedPaths.add(pathString);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
//#endregion
|
|
313
|
+
exports.getTokens = getTokens;
|
|
314
|
+
exports.name = name;
|
|
315
|
+
exports.onBoot = onBoot;
|
|
316
|
+
exports.onPropTree = onPropTree;
|
|
317
|
+
exports.onReady = onReady;
|
|
318
|
+
exports.propMap = propMap;
|
|
319
|
+
Object.defineProperty(exports, 'server_exports', {
|
|
320
|
+
enumerable: true,
|
|
321
|
+
get: function () {
|
|
322
|
+
return server_exports;
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
exports.set = set;
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { __exportAll } from "../../_virtual/rolldown_runtime.mjs";
|
|
2
|
+
import { merge } from "ts-deepmerge";
|
|
3
|
+
|
|
4
|
+
//#region src/use/token/server.ts
|
|
5
|
+
var server_exports = /* @__PURE__ */ __exportAll({
|
|
6
|
+
getTokens: () => getTokens,
|
|
7
|
+
name: () => name,
|
|
8
|
+
onBoot: () => onBoot,
|
|
9
|
+
onPropTree: () => onPropTree,
|
|
10
|
+
onReady: () => onReady,
|
|
11
|
+
propMap: () => propMap,
|
|
12
|
+
set: () => set
|
|
13
|
+
});
|
|
14
|
+
const name = "token";
|
|
15
|
+
const propMap = new Map([
|
|
16
|
+
["color", new Set([
|
|
17
|
+
"color",
|
|
18
|
+
"background",
|
|
19
|
+
"background-color",
|
|
20
|
+
"border-color",
|
|
21
|
+
"accent-color",
|
|
22
|
+
"caret-color",
|
|
23
|
+
"fill",
|
|
24
|
+
"outline-color",
|
|
25
|
+
"stroke",
|
|
26
|
+
"text-decoration-color",
|
|
27
|
+
"text-shadow",
|
|
28
|
+
"box-shadow",
|
|
29
|
+
"background-image",
|
|
30
|
+
"linear-gradient",
|
|
31
|
+
"radial-gradient",
|
|
32
|
+
"conic-gradient",
|
|
33
|
+
"filter"
|
|
34
|
+
])],
|
|
35
|
+
["size", new Set([
|
|
36
|
+
"width",
|
|
37
|
+
"height",
|
|
38
|
+
"min-width",
|
|
39
|
+
"min-height",
|
|
40
|
+
"max-width",
|
|
41
|
+
"max-height",
|
|
42
|
+
"inset",
|
|
43
|
+
"top",
|
|
44
|
+
"right",
|
|
45
|
+
"bottom",
|
|
46
|
+
"left",
|
|
47
|
+
"translate",
|
|
48
|
+
"flex-basis",
|
|
49
|
+
"gap",
|
|
50
|
+
"column-gap",
|
|
51
|
+
"row-gap",
|
|
52
|
+
"margin",
|
|
53
|
+
"margin-top",
|
|
54
|
+
"margin-right",
|
|
55
|
+
"margin-bottom",
|
|
56
|
+
"margin-left",
|
|
57
|
+
"padding",
|
|
58
|
+
"padding-top",
|
|
59
|
+
"padding-right",
|
|
60
|
+
"padding-bottom",
|
|
61
|
+
"padding-left",
|
|
62
|
+
"border-spacing",
|
|
63
|
+
"scroll-margin",
|
|
64
|
+
"scroll-margin-top",
|
|
65
|
+
"scroll-margin-right",
|
|
66
|
+
"scroll-margin-bottom",
|
|
67
|
+
"scroll-margin-left",
|
|
68
|
+
"scroll-padding",
|
|
69
|
+
"scroll-padding-top",
|
|
70
|
+
"scroll-padding-right",
|
|
71
|
+
"scroll-padding-bottom",
|
|
72
|
+
"scroll-padding-left",
|
|
73
|
+
"text-indent"
|
|
74
|
+
])],
|
|
75
|
+
["grid", new Set([
|
|
76
|
+
"grid-column",
|
|
77
|
+
"grid-row",
|
|
78
|
+
"grid-template-columns",
|
|
79
|
+
"grid-template-rows",
|
|
80
|
+
"grid-auto-columns",
|
|
81
|
+
"grid-auto-rows"
|
|
82
|
+
])],
|
|
83
|
+
["duration", new Set([
|
|
84
|
+
"transition-duration",
|
|
85
|
+
"transition-delay",
|
|
86
|
+
"animation-duration",
|
|
87
|
+
"animation-delay"
|
|
88
|
+
])],
|
|
89
|
+
["backgroundPosition", new Set([
|
|
90
|
+
"background-position",
|
|
91
|
+
"object-position",
|
|
92
|
+
"transform-origin"
|
|
93
|
+
])],
|
|
94
|
+
["font", new Set(["font-family"])]
|
|
95
|
+
]);
|
|
96
|
+
let originals = {};
|
|
97
|
+
const getTokens = () => originals;
|
|
98
|
+
const set = (input) => {
|
|
99
|
+
const resolvedInput = typeof input === "object" ? input : input(valueMap);
|
|
100
|
+
originals = merge(originals, resolvedInput);
|
|
101
|
+
for (const [key, value] of Object.entries(resolvedInput)) {
|
|
102
|
+
const propsToMap = propMap.get(key) || [key];
|
|
103
|
+
for (const prop of propsToMap) valueMap.set(prop, value);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
let valueMap;
|
|
107
|
+
let hasTokens = false;
|
|
108
|
+
let hasProxyTokens = false;
|
|
109
|
+
let hasTokenOverrides = false;
|
|
110
|
+
let browserResolvedPaths;
|
|
111
|
+
let emittedAllTokens = false;
|
|
112
|
+
let runtimeIncludesTokenPaths = false;
|
|
113
|
+
let tokenCreatorVarName = "";
|
|
114
|
+
let tokenVarsVarName = "";
|
|
115
|
+
const alphaWarnings = /* @__PURE__ */ new Set();
|
|
116
|
+
const tokenAlphaKeyPattern = /^[a-zA-Z0-9_.-]+$/;
|
|
117
|
+
const parseTokenAlphaValue = (value) => {
|
|
118
|
+
const slashIndex = value.lastIndexOf("/");
|
|
119
|
+
if (slashIndex <= 0 || slashIndex === value.length - 1) return null;
|
|
120
|
+
const base = value.slice(0, slashIndex);
|
|
121
|
+
const alphaRaw = value.slice(slashIndex + 1);
|
|
122
|
+
if (!tokenAlphaKeyPattern.test(base)) return null;
|
|
123
|
+
if (!/^\d{1,3}$/.test(alphaRaw)) return {
|
|
124
|
+
base,
|
|
125
|
+
alpha: null,
|
|
126
|
+
alphaRaw
|
|
127
|
+
};
|
|
128
|
+
const alpha = Number(alphaRaw);
|
|
129
|
+
if (!Number.isInteger(alpha) || alpha < 0 || alpha > 100) return {
|
|
130
|
+
base,
|
|
131
|
+
alpha: null,
|
|
132
|
+
alphaRaw
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
base,
|
|
136
|
+
alpha,
|
|
137
|
+
alphaRaw
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
const resolveTokenParts = (values, pathParts) => {
|
|
141
|
+
if (!pathParts.length) return values;
|
|
142
|
+
return pathParts.reduce((acc, key) => acc?.[key]?.value ?? acc?.[key], values);
|
|
143
|
+
};
|
|
144
|
+
const warnAlpha = (message) => {
|
|
145
|
+
if (alphaWarnings.has(message)) return;
|
|
146
|
+
alphaWarnings.add(message);
|
|
147
|
+
console.warn(`[boss-css] ${message}`);
|
|
148
|
+
};
|
|
149
|
+
const onBoot = async (api) => {
|
|
150
|
+
hasTokens = false;
|
|
151
|
+
hasProxyTokens = false;
|
|
152
|
+
hasTokenOverrides = false;
|
|
153
|
+
browserResolvedPaths = /* @__PURE__ */ new Set();
|
|
154
|
+
emittedAllTokens = false;
|
|
155
|
+
runtimeIncludesTokenPaths = false;
|
|
156
|
+
valueMap = /* @__PURE__ */ new Map();
|
|
157
|
+
valueMap.asObject = function() {
|
|
158
|
+
return Array.from(this.entries()).reduce((acc, [key, value]) => {
|
|
159
|
+
acc[key] = value;
|
|
160
|
+
return acc;
|
|
161
|
+
}, {});
|
|
162
|
+
};
|
|
163
|
+
set({ color: {
|
|
164
|
+
black: "#000",
|
|
165
|
+
white: "#fff"
|
|
166
|
+
} });
|
|
167
|
+
if (api.tokens) set(api.tokens);
|
|
168
|
+
const shouldEmitRuntime = () => Boolean(hasTokens || hasProxyTokens || hasTokenOverrides || api.emitAllTokens);
|
|
169
|
+
const runtimeConfig = api.runtime;
|
|
170
|
+
const hasRuntimeConfig = Boolean(runtimeConfig && (runtimeConfig.only !== void 0 || runtimeConfig.strategy));
|
|
171
|
+
runtimeIncludesTokenPaths = hasRuntimeConfig;
|
|
172
|
+
const runtimeModule = hasRuntimeConfig ? "boss-css/use/token/runtime-only" : "boss-css/use/token/browser";
|
|
173
|
+
api.file.js.importAndConfig({
|
|
174
|
+
name: "onInit",
|
|
175
|
+
from: runtimeModule
|
|
176
|
+
}, shouldEmitRuntime);
|
|
177
|
+
api.file.js.importAndConfig({
|
|
178
|
+
name: "onBrowserObjectStart",
|
|
179
|
+
from: runtimeModule
|
|
180
|
+
}, shouldEmitRuntime);
|
|
181
|
+
const tokenPathsVarName = api.file.js.import({
|
|
182
|
+
name: "tokenPaths",
|
|
183
|
+
from: runtimeModule
|
|
184
|
+
}, () => browserResolvedPaths.size > 0 || Boolean(api.emitAllTokens));
|
|
185
|
+
const shouldEmitTokenProxy = () => Boolean(hasProxyTokens);
|
|
186
|
+
tokenCreatorVarName = api.file.js.import({
|
|
187
|
+
name: "create",
|
|
188
|
+
from: runtimeModule
|
|
189
|
+
}, shouldEmitTokenProxy);
|
|
190
|
+
tokenVarsVarName = api.file.js.import({
|
|
191
|
+
name: "tokenVars",
|
|
192
|
+
from: runtimeModule
|
|
193
|
+
}, () => true);
|
|
194
|
+
if (hasRuntimeConfig) api.file.js.config({
|
|
195
|
+
from: runtimeModule,
|
|
196
|
+
config: {
|
|
197
|
+
tokens: originals,
|
|
198
|
+
runtime: runtimeConfig
|
|
199
|
+
}
|
|
200
|
+
}, shouldEmitRuntime);
|
|
201
|
+
api.file.js.set("body", "token:browserResolvedPaths", () => `;${JSON.stringify(Array.from(browserResolvedPaths))}.forEach(v => ${tokenPathsVarName}.add(v))`, () => browserResolvedPaths.size > 0 || Boolean(api.emitAllTokens));
|
|
202
|
+
};
|
|
203
|
+
const onReady = async (api) => {
|
|
204
|
+
api.file.js.dts.set("body", "token:types", `type $$TokenLeaf = string | number | (string | number)[]
|
|
205
|
+
type $$TokenDefinition = ${JSON.stringify(originals, null, 4)}
|
|
206
|
+
type $$TokenOverrides<T = $$TokenDefinition> =
|
|
207
|
+
T extends any[]
|
|
208
|
+
? $$TokenLeaf
|
|
209
|
+
: T extends { value: infer V }
|
|
210
|
+
? $$TokenOverrides<V> | { [K in keyof T]?: $$TokenOverrides<T[K]> }
|
|
211
|
+
: T extends object
|
|
212
|
+
? { [K in keyof T]?: $$TokenOverrides<T[K]> }
|
|
213
|
+
: $$TokenLeaf
|
|
214
|
+
`);
|
|
215
|
+
api.file.js.dts.replace("body", "$$:FinalProps", (value) => `${value} & { tokens?: $$TokenOverrides }`);
|
|
216
|
+
api.file.js.dts.prepend("body", "jsx:proxy-custom-members", ` token: ${JSON.stringify(originals, null, 4)}\n`);
|
|
217
|
+
api.file.js.dts.prepend("body", "jsx:proxy-custom-members", ` tokenVars: (overrides: $$TokenOverrides) => Record<string, string | number>\n`);
|
|
218
|
+
const shouldEmitTokenProxy = () => hasProxyTokens;
|
|
219
|
+
api.file.js.set("foot", "token:$$.token", `$$.token = ${tokenCreatorVarName}()`, shouldEmitTokenProxy);
|
|
220
|
+
api.file.js.set("foot", "token:$$.tokenVars", `$$.tokenVars = ${tokenVarsVarName}`);
|
|
221
|
+
for (const [name, values] of valueMap) {
|
|
222
|
+
const descriptor = api.dictionary.get(name);
|
|
223
|
+
if (!values || typeof values !== "object") continue;
|
|
224
|
+
const keys = Object.keys(values);
|
|
225
|
+
if (!descriptor) continue;
|
|
226
|
+
for (const alias of descriptor.aliases) {
|
|
227
|
+
const cssDescription = api.file.js.dts.get("body").get(`css:${alias}:description`);
|
|
228
|
+
const cssDeclaration = api.file.js.dts.get("body").get(`css:${alias}:declaration`);
|
|
229
|
+
if (cssDescription) api.file.js.dts.prepend("body", `css:${alias}:description`, `**Available tokens**\n
|
|
230
|
+
${keys.map((k) => `- \`${k}\`: \`${values[k]}\``).join("\n")}
|
|
231
|
+
\n`);
|
|
232
|
+
if (cssDeclaration) {
|
|
233
|
+
const cssContent = String(cssDeclaration.content ?? "");
|
|
234
|
+
api.file.js.dts.set("body", `css:${alias}:declaration`, cssContent.replace("?: ", `?: ${keys.map((k) => `"${k}"`).join(" | ")} | `));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const onPropTree = async (api, { tree, parser }) => {
|
|
240
|
+
if (!hasTokenOverrides && tree && typeof tree === "object" && "tokens" in tree) {
|
|
241
|
+
hasTokenOverrides = true;
|
|
242
|
+
hasTokens = true;
|
|
243
|
+
}
|
|
244
|
+
if (api.emitAllTokens && !emittedAllTokens) {
|
|
245
|
+
emittedAllTokens = true;
|
|
246
|
+
hasTokens = true;
|
|
247
|
+
const addTokenVars = (prefix, value) => {
|
|
248
|
+
if (value && typeof value === "object" && !Array.isArray(value)) {
|
|
249
|
+
for (const [key, next] of Object.entries(value)) addTokenVars(prefix ? `${prefix}.${key}` : key, next);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
if (!prefix) return;
|
|
253
|
+
const varName = `--${api.selectorPrefix ?? ""}${prefix.replace(/\./g, "-")}`;
|
|
254
|
+
api.css.addRoot(`${varName}: ${api.dictionary.toValue(value)};`);
|
|
255
|
+
browserResolvedPaths.add(prefix);
|
|
256
|
+
};
|
|
257
|
+
for (const [group, value] of valueMap.entries()) addTokenVars(group, value);
|
|
258
|
+
}
|
|
259
|
+
api.walkPropTree(tree, (name, prop) => {
|
|
260
|
+
const descriptor = api.dictionary.get(name);
|
|
261
|
+
if (!descriptor) return;
|
|
262
|
+
const isTokenCodeString = Boolean(prop.dynamic && prop.code?.startsWith("$$.token."));
|
|
263
|
+
hasProxyTokens = hasProxyTokens || isTokenCodeString;
|
|
264
|
+
const pathString = isTokenCodeString ? prop.code?.replace("$$.token.", "") : typeof prop.value === "string" ? prop.value.startsWith("$$.token") ? prop.value.replace("$$.token.", "") : `${name}.${prop.value}` : prop.value;
|
|
265
|
+
if (typeof pathString !== "string") return;
|
|
266
|
+
const path = pathString.split(".");
|
|
267
|
+
const [tokenGroupName, ...rest] = path;
|
|
268
|
+
const { aliases } = descriptor;
|
|
269
|
+
const valuesByGroupName = valueMap.get(tokenGroupName);
|
|
270
|
+
const values = aliases.reduce((acc, alias) => {
|
|
271
|
+
return acc || valueMap.get(alias) || null;
|
|
272
|
+
}, null) || valuesByGroupName;
|
|
273
|
+
if (!values) return;
|
|
274
|
+
const rawValue = prop.value;
|
|
275
|
+
const colorTokens = valueMap.get("color");
|
|
276
|
+
const tokenAlpha = typeof rawValue === "string" && values && colorTokens && values === colorTokens ? parseTokenAlphaValue(rawValue) : null;
|
|
277
|
+
if (tokenAlpha) {
|
|
278
|
+
const baseValue = resolveTokenParts(values, tokenAlpha.base.split("."));
|
|
279
|
+
if (baseValue === void 0) {
|
|
280
|
+
warnAlpha(`Unknown token "${tokenAlpha.base}" for "${name}:${rawValue}".`);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
if (tokenAlpha.alpha === null) {
|
|
284
|
+
warnAlpha(`Invalid token alpha "${tokenAlpha.alphaRaw}" for "${name}:${rawValue}" (use 0-100).`);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const tokenPath = `${name}.${tokenAlpha.base}`;
|
|
288
|
+
const varName = `--${api.selectorPrefix ?? ""}${tokenPath.replace(/\./g, "-")}`;
|
|
289
|
+
const mixValue = `color-mix(in oklab, var(${varName}) ${tokenAlpha.alpha}%, transparent)`;
|
|
290
|
+
prop.dynamic = false;
|
|
291
|
+
prop.selectorValue = rawValue;
|
|
292
|
+
prop.value = mixValue;
|
|
293
|
+
hasTokens = true;
|
|
294
|
+
api.css.addRoot(`${varName}: ${api.dictionary.toValue(baseValue)};`);
|
|
295
|
+
if (parser !== "classname") browserResolvedPaths.add(tokenPath);
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const tokenValue = rest.length ? resolveTokenParts(values, rest) : void 0;
|
|
299
|
+
if (tokenValue !== void 0) {
|
|
300
|
+
const varName = `--${api.selectorPrefix ?? ""}${path.join("-")}`;
|
|
301
|
+
prop.dynamic = false;
|
|
302
|
+
prop.selectorValue = parser === "classname" ? prop.value : rest.join(".");
|
|
303
|
+
prop.value = `var(${varName})`;
|
|
304
|
+
hasTokens = true;
|
|
305
|
+
api.css.addRoot(`${varName}: ${api.dictionary.toValue(tokenValue)};`);
|
|
306
|
+
const shouldTrackPath = runtimeIncludesTokenPaths || typeof prop.value === "string" && !prop.value.startsWith("$$");
|
|
307
|
+
if (parser !== "classname" && typeof pathString === "string" && shouldTrackPath) browserResolvedPaths.add(pathString);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
//#endregion
|
|
313
|
+
export { getTokens, name, onBoot, onPropTree, onReady, propMap, server_exports, set };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/use/token/vars.ts
|
|
3
|
+
const isPlainObject = (value) => {
|
|
4
|
+
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
5
|
+
};
|
|
6
|
+
const hasValueEntry = (value) => {
|
|
7
|
+
return isPlainObject(value) && Object.prototype.hasOwnProperty.call(value, "value");
|
|
8
|
+
};
|
|
9
|
+
const createTokenVars = ({ prefix = "", toValue } = {}) => {
|
|
10
|
+
const resolveValue = toValue ?? ((value) => value == null ? value : String(value));
|
|
11
|
+
return (input) => {
|
|
12
|
+
const result = {};
|
|
13
|
+
if (!input || typeof input !== "object") return result;
|
|
14
|
+
const applyVar = (path, group, value) => {
|
|
15
|
+
if (!path.length) return;
|
|
16
|
+
const name = `--${prefix}${path.join("-")}`;
|
|
17
|
+
const resolved = resolveValue(value, group ?? path[0]);
|
|
18
|
+
if (typeof resolved === "number") {
|
|
19
|
+
result[name] = resolved;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (typeof resolved === "string") {
|
|
23
|
+
result[name] = resolved;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (resolved == null) return;
|
|
27
|
+
result[name] = String(resolved);
|
|
28
|
+
};
|
|
29
|
+
const walk = (node, path, group) => {
|
|
30
|
+
if (node == null) return;
|
|
31
|
+
if (Array.isArray(node) || !isPlainObject(node)) {
|
|
32
|
+
applyVar(path, group, node);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (hasValueEntry(node)) {
|
|
36
|
+
applyVar(path, group, node.value);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
for (const [key, value] of Object.entries(node)) walk(value, [...path, key], group ?? key);
|
|
40
|
+
};
|
|
41
|
+
walk(input, [], null);
|
|
42
|
+
return result;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
exports.createTokenVars = createTokenVars;
|