boss-css 0.0.1 → 0.0.2
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,245 @@
|
|
|
1
|
+
const require_vars = require('./vars.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/use/token/runtime-only.ts
|
|
4
|
+
let currentApi = null;
|
|
5
|
+
const tokenVarsCache = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
const getTokenVars = (api) => {
|
|
7
|
+
if (!api) return null;
|
|
8
|
+
const cached = tokenVarsCache.get(api);
|
|
9
|
+
if (cached) return cached;
|
|
10
|
+
const builder = require_vars.createTokenVars({
|
|
11
|
+
prefix: api.selectorPrefix ?? "",
|
|
12
|
+
toValue: (value, property) => {
|
|
13
|
+
const resolved = api.dictionary.toValue(value, property);
|
|
14
|
+
if (typeof resolved === "number" || typeof resolved === "string") return resolved;
|
|
15
|
+
if (resolved == null) return null;
|
|
16
|
+
return String(resolved);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
tokenVarsCache.set(api, builder);
|
|
20
|
+
return builder;
|
|
21
|
+
};
|
|
22
|
+
const tokenVars = (input) => {
|
|
23
|
+
const builder = getTokenVars(currentApi);
|
|
24
|
+
return builder ? builder(input) : {};
|
|
25
|
+
};
|
|
26
|
+
const onInit = (api) => {
|
|
27
|
+
currentApi = api;
|
|
28
|
+
if (!api.tokenVars) api.tokenVars = tokenVars;
|
|
29
|
+
};
|
|
30
|
+
const create = (currentKey = "$$.token") => {
|
|
31
|
+
const baseFn = (() => currentKey);
|
|
32
|
+
return new Proxy(baseFn, { get(target, key) {
|
|
33
|
+
if (key === "IS_TOKEN_FN") return true;
|
|
34
|
+
return typeof key === "string" ? create(`${target()}.${key}`) : void 0;
|
|
35
|
+
} });
|
|
36
|
+
};
|
|
37
|
+
const tokenPaths = /* @__PURE__ */ new Set();
|
|
38
|
+
const defaultTokens = { color: {
|
|
39
|
+
black: "#000",
|
|
40
|
+
white: "#fff"
|
|
41
|
+
} };
|
|
42
|
+
const propMap = new Map([
|
|
43
|
+
["color", new Set([
|
|
44
|
+
"color",
|
|
45
|
+
"background",
|
|
46
|
+
"background-color",
|
|
47
|
+
"border-color",
|
|
48
|
+
"accent-color",
|
|
49
|
+
"caret-color",
|
|
50
|
+
"fill",
|
|
51
|
+
"outline-color",
|
|
52
|
+
"stroke",
|
|
53
|
+
"text-decoration-color",
|
|
54
|
+
"text-shadow",
|
|
55
|
+
"box-shadow",
|
|
56
|
+
"background-image",
|
|
57
|
+
"linear-gradient",
|
|
58
|
+
"radial-gradient",
|
|
59
|
+
"conic-gradient",
|
|
60
|
+
"filter"
|
|
61
|
+
])],
|
|
62
|
+
["size", new Set([
|
|
63
|
+
"width",
|
|
64
|
+
"height",
|
|
65
|
+
"min-width",
|
|
66
|
+
"min-height",
|
|
67
|
+
"max-width",
|
|
68
|
+
"max-height",
|
|
69
|
+
"inset",
|
|
70
|
+
"top",
|
|
71
|
+
"right",
|
|
72
|
+
"bottom",
|
|
73
|
+
"left",
|
|
74
|
+
"translate",
|
|
75
|
+
"flex-basis",
|
|
76
|
+
"gap",
|
|
77
|
+
"column-gap",
|
|
78
|
+
"row-gap",
|
|
79
|
+
"margin",
|
|
80
|
+
"margin-top",
|
|
81
|
+
"margin-right",
|
|
82
|
+
"margin-bottom",
|
|
83
|
+
"margin-left",
|
|
84
|
+
"padding",
|
|
85
|
+
"padding-top",
|
|
86
|
+
"padding-right",
|
|
87
|
+
"padding-bottom",
|
|
88
|
+
"padding-left",
|
|
89
|
+
"border-spacing",
|
|
90
|
+
"scroll-margin",
|
|
91
|
+
"scroll-margin-top",
|
|
92
|
+
"scroll-margin-right",
|
|
93
|
+
"scroll-margin-bottom",
|
|
94
|
+
"scroll-margin-left",
|
|
95
|
+
"scroll-padding",
|
|
96
|
+
"scroll-padding-top",
|
|
97
|
+
"scroll-padding-right",
|
|
98
|
+
"scroll-padding-bottom",
|
|
99
|
+
"scroll-padding-left",
|
|
100
|
+
"text-indent"
|
|
101
|
+
])],
|
|
102
|
+
["grid", new Set([
|
|
103
|
+
"grid-column",
|
|
104
|
+
"grid-row",
|
|
105
|
+
"grid-template-columns",
|
|
106
|
+
"grid-template-rows",
|
|
107
|
+
"grid-auto-columns",
|
|
108
|
+
"grid-auto-rows"
|
|
109
|
+
])],
|
|
110
|
+
["duration", new Set([
|
|
111
|
+
"transition-duration",
|
|
112
|
+
"transition-delay",
|
|
113
|
+
"animation-duration",
|
|
114
|
+
"animation-delay"
|
|
115
|
+
])],
|
|
116
|
+
["backgroundPosition", new Set(["background-position", "object-position"])]
|
|
117
|
+
]);
|
|
118
|
+
const mergeTokens = (base, incoming) => {
|
|
119
|
+
if (!incoming || typeof incoming !== "object") return { ...base };
|
|
120
|
+
const result = { ...base };
|
|
121
|
+
for (const [key, value] of Object.entries(incoming)) if (value && typeof value === "object" && !Array.isArray(value) && typeof result[key] === "object") result[key] = mergeTokens(result[key], value);
|
|
122
|
+
else result[key] = value;
|
|
123
|
+
return result;
|
|
124
|
+
};
|
|
125
|
+
const tokenState = /* @__PURE__ */ new WeakMap();
|
|
126
|
+
const tokenAlphaKeyPattern = /^[a-zA-Z0-9_.-]+$/;
|
|
127
|
+
const getTokenState = (api) => {
|
|
128
|
+
if (tokenState.has(api)) return tokenState.get(api);
|
|
129
|
+
const tokens = mergeTokens(defaultTokens, api.tokens);
|
|
130
|
+
const byProp = /* @__PURE__ */ new Map();
|
|
131
|
+
for (const [group, values] of Object.entries(tokens)) {
|
|
132
|
+
const propsToMap = propMap.get(group) ?? new Set([group]);
|
|
133
|
+
for (const prop of propsToMap) {
|
|
134
|
+
const dashProp = api?.camelCaseToDash ? api.camelCaseToDash(prop) : prop;
|
|
135
|
+
byProp.set(prop, values);
|
|
136
|
+
byProp.set(dashProp, values);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const state = {
|
|
140
|
+
groups: tokens,
|
|
141
|
+
byProp
|
|
142
|
+
};
|
|
143
|
+
tokenState.set(api, state);
|
|
144
|
+
return state;
|
|
145
|
+
};
|
|
146
|
+
const resolveTokenParts = (values, pathParts) => {
|
|
147
|
+
if (!pathParts.length) return values;
|
|
148
|
+
return pathParts.reduce((acc, key) => acc?.[key]?.value ?? acc?.[key], values);
|
|
149
|
+
};
|
|
150
|
+
const parseTokenAlphaValue = (value) => {
|
|
151
|
+
const slashIndex = value.lastIndexOf("/");
|
|
152
|
+
if (slashIndex <= 0 || slashIndex === value.length - 1) return null;
|
|
153
|
+
const base = value.slice(0, slashIndex);
|
|
154
|
+
const alphaRaw = value.slice(slashIndex + 1);
|
|
155
|
+
if (!tokenAlphaKeyPattern.test(base)) return null;
|
|
156
|
+
if (!/^\d{1,3}$/.test(alphaRaw)) return {
|
|
157
|
+
base,
|
|
158
|
+
alpha: null
|
|
159
|
+
};
|
|
160
|
+
const alpha = Number(alphaRaw);
|
|
161
|
+
if (!Number.isInteger(alpha) || alpha < 0 || alpha > 100) return {
|
|
162
|
+
base,
|
|
163
|
+
alpha: null
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
base,
|
|
167
|
+
alpha
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
const isTokenFunction = (value) => typeof value === "function" && Boolean(value && value.IS_TOKEN_FN);
|
|
171
|
+
const getTokenPath = (api, prop, value) => {
|
|
172
|
+
if (isTokenFunction(value)) return {
|
|
173
|
+
path: value().replace("$$.token.", ""),
|
|
174
|
+
source: "group"
|
|
175
|
+
};
|
|
176
|
+
if (typeof value === "string" && value.startsWith("$$.token.")) return {
|
|
177
|
+
path: value.replace("$$.token.", ""),
|
|
178
|
+
source: "group"
|
|
179
|
+
};
|
|
180
|
+
if (typeof value !== "string") return null;
|
|
181
|
+
const { byProp } = getTokenState(api);
|
|
182
|
+
const dashProp = api?.camelCaseToDash ? api.camelCaseToDash(prop) : prop;
|
|
183
|
+
const values = byProp.get(prop) ?? byProp.get(dashProp);
|
|
184
|
+
if (!values) return null;
|
|
185
|
+
if (typeof value === "string") {
|
|
186
|
+
const tokenAlpha = parseTokenAlphaValue(value);
|
|
187
|
+
if (tokenAlpha) {
|
|
188
|
+
if (resolveTokenParts(values, tokenAlpha.base.split(".")) === void 0) return null;
|
|
189
|
+
if (tokenAlpha.alpha === null) return null;
|
|
190
|
+
return {
|
|
191
|
+
path: `${prop}.${tokenAlpha.base}`,
|
|
192
|
+
source: "prop",
|
|
193
|
+
values,
|
|
194
|
+
alpha: tokenAlpha.alpha,
|
|
195
|
+
selectorValue: value
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (value in values) return {
|
|
200
|
+
path: `${prop}.${value}`,
|
|
201
|
+
source: "prop",
|
|
202
|
+
values
|
|
203
|
+
};
|
|
204
|
+
return null;
|
|
205
|
+
};
|
|
206
|
+
const resolveRuntimeToken = (api, prop, value) => {
|
|
207
|
+
const tokenData = getTokenPath(api, prop, value);
|
|
208
|
+
if (!tokenData) return null;
|
|
209
|
+
const { groups } = getTokenState(api);
|
|
210
|
+
let tokenValue;
|
|
211
|
+
if (tokenData.source === "group") {
|
|
212
|
+
const [group, ...rest] = tokenData.path.split(".");
|
|
213
|
+
const values = groups[group];
|
|
214
|
+
if (!values) return null;
|
|
215
|
+
tokenValue = resolveTokenParts(values, rest);
|
|
216
|
+
} else tokenValue = resolveTokenParts(tokenData.values ?? {}, tokenData.path.split(".").slice(1));
|
|
217
|
+
if (tokenValue === void 0) return null;
|
|
218
|
+
const runtimeOnly = api.runtime?.only === true;
|
|
219
|
+
const hasServerToken = tokenPaths.has(tokenData.path);
|
|
220
|
+
const tokenKey = tokenData.selectorValue ?? tokenData.path.split(".").slice(1).join(".");
|
|
221
|
+
const varValue = `var(${`--${api.selectorPrefix ?? ""}${tokenData.path.replace(/\./g, "-")}`})`;
|
|
222
|
+
const mixValue = tokenData.alpha === void 0 ? null : `color-mix(in oklab, ${hasServerToken && !runtimeOnly ? varValue : tokenValue} ${tokenData.alpha}%, transparent)`;
|
|
223
|
+
if (runtimeOnly || !hasServerToken) return {
|
|
224
|
+
value: mixValue ?? tokenValue,
|
|
225
|
+
selectorValue: tokenData.alpha === void 0 ? tokenValue : tokenKey,
|
|
226
|
+
tokenKey,
|
|
227
|
+
tokenPath: tokenData.path
|
|
228
|
+
};
|
|
229
|
+
return {
|
|
230
|
+
value: mixValue ?? varValue,
|
|
231
|
+
selectorValue: tokenKey,
|
|
232
|
+
tokenKey,
|
|
233
|
+
tokenPath: tokenData.path
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
const onBrowserObjectStart = () => {};
|
|
237
|
+
|
|
238
|
+
//#endregion
|
|
239
|
+
exports.create = create;
|
|
240
|
+
exports.onBrowserObjectStart = onBrowserObjectStart;
|
|
241
|
+
exports.onInit = onInit;
|
|
242
|
+
exports.propMap = propMap;
|
|
243
|
+
exports.resolveRuntimeToken = resolveRuntimeToken;
|
|
244
|
+
exports.tokenPaths = tokenPaths;
|
|
245
|
+
exports.tokenVars = tokenVars;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { createTokenVars } from "./vars.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/use/token/runtime-only.ts
|
|
4
|
+
let currentApi = null;
|
|
5
|
+
const tokenVarsCache = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
const getTokenVars = (api) => {
|
|
7
|
+
if (!api) return null;
|
|
8
|
+
const cached = tokenVarsCache.get(api);
|
|
9
|
+
if (cached) return cached;
|
|
10
|
+
const builder = createTokenVars({
|
|
11
|
+
prefix: api.selectorPrefix ?? "",
|
|
12
|
+
toValue: (value, property) => {
|
|
13
|
+
const resolved = api.dictionary.toValue(value, property);
|
|
14
|
+
if (typeof resolved === "number" || typeof resolved === "string") return resolved;
|
|
15
|
+
if (resolved == null) return null;
|
|
16
|
+
return String(resolved);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
tokenVarsCache.set(api, builder);
|
|
20
|
+
return builder;
|
|
21
|
+
};
|
|
22
|
+
const tokenVars = (input) => {
|
|
23
|
+
const builder = getTokenVars(currentApi);
|
|
24
|
+
return builder ? builder(input) : {};
|
|
25
|
+
};
|
|
26
|
+
const onInit = (api) => {
|
|
27
|
+
currentApi = api;
|
|
28
|
+
if (!api.tokenVars) api.tokenVars = tokenVars;
|
|
29
|
+
};
|
|
30
|
+
const create = (currentKey = "$$.token") => {
|
|
31
|
+
const baseFn = (() => currentKey);
|
|
32
|
+
return new Proxy(baseFn, { get(target, key) {
|
|
33
|
+
if (key === "IS_TOKEN_FN") return true;
|
|
34
|
+
return typeof key === "string" ? create(`${target()}.${key}`) : void 0;
|
|
35
|
+
} });
|
|
36
|
+
};
|
|
37
|
+
const tokenPaths = /* @__PURE__ */ new Set();
|
|
38
|
+
const defaultTokens = { color: {
|
|
39
|
+
black: "#000",
|
|
40
|
+
white: "#fff"
|
|
41
|
+
} };
|
|
42
|
+
const propMap = new Map([
|
|
43
|
+
["color", new Set([
|
|
44
|
+
"color",
|
|
45
|
+
"background",
|
|
46
|
+
"background-color",
|
|
47
|
+
"border-color",
|
|
48
|
+
"accent-color",
|
|
49
|
+
"caret-color",
|
|
50
|
+
"fill",
|
|
51
|
+
"outline-color",
|
|
52
|
+
"stroke",
|
|
53
|
+
"text-decoration-color",
|
|
54
|
+
"text-shadow",
|
|
55
|
+
"box-shadow",
|
|
56
|
+
"background-image",
|
|
57
|
+
"linear-gradient",
|
|
58
|
+
"radial-gradient",
|
|
59
|
+
"conic-gradient",
|
|
60
|
+
"filter"
|
|
61
|
+
])],
|
|
62
|
+
["size", new Set([
|
|
63
|
+
"width",
|
|
64
|
+
"height",
|
|
65
|
+
"min-width",
|
|
66
|
+
"min-height",
|
|
67
|
+
"max-width",
|
|
68
|
+
"max-height",
|
|
69
|
+
"inset",
|
|
70
|
+
"top",
|
|
71
|
+
"right",
|
|
72
|
+
"bottom",
|
|
73
|
+
"left",
|
|
74
|
+
"translate",
|
|
75
|
+
"flex-basis",
|
|
76
|
+
"gap",
|
|
77
|
+
"column-gap",
|
|
78
|
+
"row-gap",
|
|
79
|
+
"margin",
|
|
80
|
+
"margin-top",
|
|
81
|
+
"margin-right",
|
|
82
|
+
"margin-bottom",
|
|
83
|
+
"margin-left",
|
|
84
|
+
"padding",
|
|
85
|
+
"padding-top",
|
|
86
|
+
"padding-right",
|
|
87
|
+
"padding-bottom",
|
|
88
|
+
"padding-left",
|
|
89
|
+
"border-spacing",
|
|
90
|
+
"scroll-margin",
|
|
91
|
+
"scroll-margin-top",
|
|
92
|
+
"scroll-margin-right",
|
|
93
|
+
"scroll-margin-bottom",
|
|
94
|
+
"scroll-margin-left",
|
|
95
|
+
"scroll-padding",
|
|
96
|
+
"scroll-padding-top",
|
|
97
|
+
"scroll-padding-right",
|
|
98
|
+
"scroll-padding-bottom",
|
|
99
|
+
"scroll-padding-left",
|
|
100
|
+
"text-indent"
|
|
101
|
+
])],
|
|
102
|
+
["grid", new Set([
|
|
103
|
+
"grid-column",
|
|
104
|
+
"grid-row",
|
|
105
|
+
"grid-template-columns",
|
|
106
|
+
"grid-template-rows",
|
|
107
|
+
"grid-auto-columns",
|
|
108
|
+
"grid-auto-rows"
|
|
109
|
+
])],
|
|
110
|
+
["duration", new Set([
|
|
111
|
+
"transition-duration",
|
|
112
|
+
"transition-delay",
|
|
113
|
+
"animation-duration",
|
|
114
|
+
"animation-delay"
|
|
115
|
+
])],
|
|
116
|
+
["backgroundPosition", new Set(["background-position", "object-position"])]
|
|
117
|
+
]);
|
|
118
|
+
const mergeTokens = (base, incoming) => {
|
|
119
|
+
if (!incoming || typeof incoming !== "object") return { ...base };
|
|
120
|
+
const result = { ...base };
|
|
121
|
+
for (const [key, value] of Object.entries(incoming)) if (value && typeof value === "object" && !Array.isArray(value) && typeof result[key] === "object") result[key] = mergeTokens(result[key], value);
|
|
122
|
+
else result[key] = value;
|
|
123
|
+
return result;
|
|
124
|
+
};
|
|
125
|
+
const tokenState = /* @__PURE__ */ new WeakMap();
|
|
126
|
+
const tokenAlphaKeyPattern = /^[a-zA-Z0-9_.-]+$/;
|
|
127
|
+
const getTokenState = (api) => {
|
|
128
|
+
if (tokenState.has(api)) return tokenState.get(api);
|
|
129
|
+
const tokens = mergeTokens(defaultTokens, api.tokens);
|
|
130
|
+
const byProp = /* @__PURE__ */ new Map();
|
|
131
|
+
for (const [group, values] of Object.entries(tokens)) {
|
|
132
|
+
const propsToMap = propMap.get(group) ?? new Set([group]);
|
|
133
|
+
for (const prop of propsToMap) {
|
|
134
|
+
const dashProp = api?.camelCaseToDash ? api.camelCaseToDash(prop) : prop;
|
|
135
|
+
byProp.set(prop, values);
|
|
136
|
+
byProp.set(dashProp, values);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const state = {
|
|
140
|
+
groups: tokens,
|
|
141
|
+
byProp
|
|
142
|
+
};
|
|
143
|
+
tokenState.set(api, state);
|
|
144
|
+
return state;
|
|
145
|
+
};
|
|
146
|
+
const resolveTokenParts = (values, pathParts) => {
|
|
147
|
+
if (!pathParts.length) return values;
|
|
148
|
+
return pathParts.reduce((acc, key) => acc?.[key]?.value ?? acc?.[key], values);
|
|
149
|
+
};
|
|
150
|
+
const parseTokenAlphaValue = (value) => {
|
|
151
|
+
const slashIndex = value.lastIndexOf("/");
|
|
152
|
+
if (slashIndex <= 0 || slashIndex === value.length - 1) return null;
|
|
153
|
+
const base = value.slice(0, slashIndex);
|
|
154
|
+
const alphaRaw = value.slice(slashIndex + 1);
|
|
155
|
+
if (!tokenAlphaKeyPattern.test(base)) return null;
|
|
156
|
+
if (!/^\d{1,3}$/.test(alphaRaw)) return {
|
|
157
|
+
base,
|
|
158
|
+
alpha: null
|
|
159
|
+
};
|
|
160
|
+
const alpha = Number(alphaRaw);
|
|
161
|
+
if (!Number.isInteger(alpha) || alpha < 0 || alpha > 100) return {
|
|
162
|
+
base,
|
|
163
|
+
alpha: null
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
base,
|
|
167
|
+
alpha
|
|
168
|
+
};
|
|
169
|
+
};
|
|
170
|
+
const isTokenFunction = (value) => typeof value === "function" && Boolean(value && value.IS_TOKEN_FN);
|
|
171
|
+
const getTokenPath = (api, prop, value) => {
|
|
172
|
+
if (isTokenFunction(value)) return {
|
|
173
|
+
path: value().replace("$$.token.", ""),
|
|
174
|
+
source: "group"
|
|
175
|
+
};
|
|
176
|
+
if (typeof value === "string" && value.startsWith("$$.token.")) return {
|
|
177
|
+
path: value.replace("$$.token.", ""),
|
|
178
|
+
source: "group"
|
|
179
|
+
};
|
|
180
|
+
if (typeof value !== "string") return null;
|
|
181
|
+
const { byProp } = getTokenState(api);
|
|
182
|
+
const dashProp = api?.camelCaseToDash ? api.camelCaseToDash(prop) : prop;
|
|
183
|
+
const values = byProp.get(prop) ?? byProp.get(dashProp);
|
|
184
|
+
if (!values) return null;
|
|
185
|
+
if (typeof value === "string") {
|
|
186
|
+
const tokenAlpha = parseTokenAlphaValue(value);
|
|
187
|
+
if (tokenAlpha) {
|
|
188
|
+
if (resolveTokenParts(values, tokenAlpha.base.split(".")) === void 0) return null;
|
|
189
|
+
if (tokenAlpha.alpha === null) return null;
|
|
190
|
+
return {
|
|
191
|
+
path: `${prop}.${tokenAlpha.base}`,
|
|
192
|
+
source: "prop",
|
|
193
|
+
values,
|
|
194
|
+
alpha: tokenAlpha.alpha,
|
|
195
|
+
selectorValue: value
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (value in values) return {
|
|
200
|
+
path: `${prop}.${value}`,
|
|
201
|
+
source: "prop",
|
|
202
|
+
values
|
|
203
|
+
};
|
|
204
|
+
return null;
|
|
205
|
+
};
|
|
206
|
+
const resolveRuntimeToken = (api, prop, value) => {
|
|
207
|
+
const tokenData = getTokenPath(api, prop, value);
|
|
208
|
+
if (!tokenData) return null;
|
|
209
|
+
const { groups } = getTokenState(api);
|
|
210
|
+
let tokenValue;
|
|
211
|
+
if (tokenData.source === "group") {
|
|
212
|
+
const [group, ...rest] = tokenData.path.split(".");
|
|
213
|
+
const values = groups[group];
|
|
214
|
+
if (!values) return null;
|
|
215
|
+
tokenValue = resolveTokenParts(values, rest);
|
|
216
|
+
} else tokenValue = resolveTokenParts(tokenData.values ?? {}, tokenData.path.split(".").slice(1));
|
|
217
|
+
if (tokenValue === void 0) return null;
|
|
218
|
+
const runtimeOnly = api.runtime?.only === true;
|
|
219
|
+
const hasServerToken = tokenPaths.has(tokenData.path);
|
|
220
|
+
const tokenKey = tokenData.selectorValue ?? tokenData.path.split(".").slice(1).join(".");
|
|
221
|
+
const varValue = `var(${`--${api.selectorPrefix ?? ""}${tokenData.path.replace(/\./g, "-")}`})`;
|
|
222
|
+
const mixValue = tokenData.alpha === void 0 ? null : `color-mix(in oklab, ${hasServerToken && !runtimeOnly ? varValue : tokenValue} ${tokenData.alpha}%, transparent)`;
|
|
223
|
+
if (runtimeOnly || !hasServerToken) return {
|
|
224
|
+
value: mixValue ?? tokenValue,
|
|
225
|
+
selectorValue: tokenData.alpha === void 0 ? tokenValue : tokenKey,
|
|
226
|
+
tokenKey,
|
|
227
|
+
tokenPath: tokenData.path
|
|
228
|
+
};
|
|
229
|
+
return {
|
|
230
|
+
value: mixValue ?? varValue,
|
|
231
|
+
selectorValue: tokenKey,
|
|
232
|
+
tokenKey,
|
|
233
|
+
tokenPath: tokenData.path
|
|
234
|
+
};
|
|
235
|
+
};
|
|
236
|
+
const onBrowserObjectStart = () => {};
|
|
237
|
+
|
|
238
|
+
//#endregion
|
|
239
|
+
export { create, onBrowserObjectStart, onInit, propMap, resolveRuntimeToken, tokenPaths, tokenVars };
|