@ui0/theme 0.0.0-stage → 0.1.0
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 +113 -2
- package/dist/backdrop.module.css +1 -0
- package/dist/backdrop.scss +7 -0
- package/dist/color.inject.module.css +7 -0
- package/dist/color.module.css +3 -0
- package/dist/color.scss +84 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +53 -0
- package/dist/components/style.css +1 -0
- package/dist/components/theme-provider.keys.d.ts +4 -0
- package/dist/components/theme-provider.keys.d.ts.map +1 -0
- package/dist/components/theme-provider.module.css +1 -0
- package/dist/components/theme-provider.types.d.ts +18 -0
- package/dist/components/theme-provider.types.d.ts.map +1 -0
- package/dist/components/theme-provider.vue.d.ts +19 -0
- package/dist/config.default.d.mts +4 -0
- package/dist/config.default.d.mts.map +1 -0
- package/dist/config.default.mjs +73 -0
- package/dist/config.default.mjs.map +1 -0
- package/dist/disabled.inject.module.css +5 -0
- package/dist/disabled.module.css +1 -0
- package/dist/disabled.scss +3 -0
- package/dist/display.module.css +2 -0
- package/dist/display.scss +63 -0
- package/dist/duration.scss +17 -0
- package/dist/elevation.module.css +33 -0
- package/dist/elevation.scss +46 -0
- package/dist/generate-BPYE5ALG.mjs +1037 -0
- package/dist/generate-BPYE5ALG.mjs.map +1 -0
- package/dist/generator/cli.d.mts +1 -0
- package/dist/generator/cli.mjs +103 -0
- package/dist/generator/cli.mjs.map +1 -0
- package/dist/generator/vite.d.mts +18 -0
- package/dist/generator/vite.d.mts.map +1 -0
- package/dist/generator/vite.mjs +117 -0
- package/dist/generator/vite.mjs.map +1 -0
- package/dist/index.d.mts +339 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +909 -0
- package/dist/index.mjs.map +1 -0
- package/dist/is.scss +185 -0
- package/dist/load-config-64q6nzFy.mjs +48 -0
- package/dist/load-config-64q6nzFy.mjs.map +1 -0
- package/dist/ripple.scss +57 -0
- package/dist/round.inject.module.css +92 -0
- package/dist/round.module.css +14 -0
- package/dist/round.scss +90 -0
- package/dist/size.inject.module.css +50 -0
- package/dist/size.module.css +13 -0
- package/dist/size.scss +28 -0
- package/dist/theme.scss +16 -0
- package/dist/typography.inject.module.css +81 -0
- package/dist/typography.module.css +32 -0
- package/dist/typography.scss +21 -0
- package/dist/util.scss +78 -0
- package/dist/vars.scss +0 -0
- package/package.json +96 -4
- package/src/contracts/backdrop/backdrop.contract.ts +44 -0
- package/src/contracts/backdrop/backdrop.generator.ts +82 -0
- package/src/contracts/backdrop/backdrop.keys.ts +7 -0
- package/src/contracts/backdrop/backdrop.module.css +3 -0
- package/src/contracts/backdrop/backdrop.scss +7 -0
- package/src/contracts/backdrop/backdrop.types.ts +45 -0
- package/src/contracts/backdrop/index.ts +21 -0
- package/src/contracts/color/color.contract.spec.ts +75 -0
- package/src/contracts/color/color.contract.ts +97 -0
- package/src/contracts/color/color.generator.spec.ts +73 -0
- package/src/contracts/color/color.generator.ts +122 -0
- package/src/contracts/color/color.gradient.spec.ts +32 -0
- package/src/contracts/color/color.gradient.ts +52 -0
- package/src/contracts/color/color.inject.module.css +5 -0
- package/src/contracts/color/color.keys.ts +7 -0
- package/src/contracts/color/color.module.css +5 -0
- package/src/contracts/color/color.scss +84 -0
- package/src/contracts/color/color.serialize.spec.ts +57 -0
- package/src/contracts/color/color.serialize.ts +35 -0
- package/src/contracts/color/color.token.spec.ts +57 -0
- package/src/contracts/color/color.token.ts +89 -0
- package/src/contracts/color/color.types.ts +82 -0
- package/src/contracts/color/index.md +87 -0
- package/src/contracts/color/index.ts +25 -0
- package/src/contracts/contract.ts +115 -0
- package/src/contracts/disabled/disabled.contract.ts +32 -0
- package/src/contracts/disabled/disabled.generator.ts +32 -0
- package/src/contracts/disabled/disabled.inject.module.css +5 -0
- package/src/contracts/disabled/disabled.keys.ts +6 -0
- package/src/contracts/disabled/disabled.module.css +3 -0
- package/src/contracts/disabled/disabled.scss +3 -0
- package/src/contracts/disabled/disabled.types.ts +19 -0
- package/src/contracts/disabled/index.ts +21 -0
- package/src/contracts/display/display.contract.ts +41 -0
- package/src/contracts/display/display.generator.ts +57 -0
- package/src/contracts/display/display.instance.ts +173 -0
- package/src/contracts/display/display.keys.ts +9 -0
- package/src/contracts/display/display.module.css +4 -0
- package/src/contracts/display/display.scss +63 -0
- package/src/contracts/display/display.types.ts +75 -0
- package/src/contracts/display/index.ts +27 -0
- package/src/contracts/elevation/elevation.contract.ts +37 -0
- package/src/contracts/elevation/elevation.generator.ts +71 -0
- package/src/contracts/elevation/elevation.keys.ts +6 -0
- package/src/contracts/elevation/elevation.module.css +35 -0
- package/src/contracts/elevation/elevation.scss +46 -0
- package/src/contracts/elevation/elevation.types.ts +21 -0
- package/src/contracts/elevation/index.ts +20 -0
- package/src/contracts/generator.ts +38 -0
- package/src/contracts/index.md +48 -0
- package/src/contracts/index.ts +37 -0
- package/src/contracts/round/index.ts +21 -0
- package/src/contracts/round/round.contract.ts +75 -0
- package/src/contracts/round/round.generator.ts +33 -0
- package/src/contracts/round/round.inject.module.scss +36 -0
- package/src/contracts/round/round.keys.ts +7 -0
- package/src/contracts/round/round.module.css +16 -0
- package/src/contracts/round/round.scss +90 -0
- package/src/contracts/round/round.types.ts +44 -0
- package/src/contracts/size/index.ts +22 -0
- package/src/contracts/size/size.contract.ts +98 -0
- package/src/contracts/size/size.generator.spec.ts +101 -0
- package/src/contracts/size/size.generator.ts +51 -0
- package/src/contracts/size/size.inject.module.scss +12 -0
- package/src/contracts/size/size.keys.ts +8 -0
- package/src/contracts/size/size.module.css +15 -0
- package/src/contracts/size/size.scss +28 -0
- package/src/contracts/size/size.types.ts +63 -0
- package/src/contracts/size/units.scss +17 -0
- package/src/contracts/style/index.ts +11 -0
- package/src/contracts/style/style.generator.ts +36 -0
- package/src/contracts/style/style.key.ts +4 -0
- package/src/contracts/style/style.types.ts +16 -0
- package/src/contracts/typography/index.ts +26 -0
- package/src/contracts/typography/typography.contract.ts +52 -0
- package/src/contracts/typography/typography.generator.spec.ts +48 -0
- package/src/contracts/typography/typography.generator.ts +44 -0
- package/src/contracts/typography/typography.inject.module.css +54 -0
- package/src/contracts/typography/typography.keys.ts +12 -0
- package/src/contracts/typography/typography.module.css +36 -0
- package/src/contracts/typography/typography.scss +21 -0
- package/src/contracts/typography/typography.types.ts +90 -0
- package/src/generator/theme.default.css +657 -0
- package/src/styles/duration.scss +17 -0
- package/src/styles/index.md +18 -0
- package/src/styles/is.scss +185 -0
- package/src/styles/ripple.scss +57 -0
- package/src/styles/theme.scss +16 -0
- package/src/styles/util.scss +78 -0
- package/src/styles/vars.scss +0 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,909 @@
|
|
|
1
|
+
import { S as schemesOf, _ as parseRef, a as deepMerge, b as backdrop_module_css_default, c as contractGenerators, d as round_module_css_default, f as elevation_module_css_default, g as parseColorProp, h as color_module_css_default, i as withDefaults, l as typography_module_css_default, m as disabled_module_css_default, n as generateThemeCss, o as resolvePreset, p as display_module_css_default, r as generateThemeTypes, s as hashClassName, t as generateThemeArtifacts, u as size_module_css_default, v as buildPool, x as ensureThemeBaseStyle, y as resolvePool } from "./generate-BPYE5ALG.mjs";
|
|
2
|
+
import config from "./config.default.mjs";
|
|
3
|
+
import { RecordContainer, arrayPickNext, arrayPickPrev, getClientHeight, getClientWidth, isArray, isBrowser, isString, mergeCssModulesStyles, newFrameworkError, objectMerge, parseUnits, propsToCssModuleClassNext, toCamelCase } from "@ui0/util";
|
|
4
|
+
import { AT_SIGN } from "@ui0/shared";
|
|
5
|
+
import { getCurrentInstance, hasInjectionContext, inject, isReactive, onMounted, onUnmounted, provide, reactive, ref, toRefs, useCssModule, watch } from "vue";
|
|
6
|
+
import { ThemeProvider } from "./components/index.js";
|
|
7
|
+
// src/constants.ts
|
|
8
|
+
const THEME_SCHEMES = [
|
|
9
|
+
"dark",
|
|
10
|
+
"light",
|
|
11
|
+
"default"
|
|
12
|
+
];
|
|
13
|
+
const EMPTY_OBJ = Object.freeze({});
|
|
14
|
+
// src/contracts/backdrop/backdrop.contract.ts
|
|
15
|
+
function backdropClasses(p, s) {
|
|
16
|
+
const $ = mergeCssModulesStyles(backdrop_module_css_default, s);
|
|
17
|
+
console.log("$", $);
|
|
18
|
+
if (p.backdrop) return [$["backdrop"]];
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
function backdropDeal(instance) {
|
|
22
|
+
const props = instance.props;
|
|
23
|
+
return {
|
|
24
|
+
classes: () => instance.inject(backdropClasses(props, instance.$styles)),
|
|
25
|
+
styles() {
|
|
26
|
+
const out = {};
|
|
27
|
+
const val = props.backdrop;
|
|
28
|
+
if (val) {
|
|
29
|
+
if (isArray(val)) {} else if (isString(val)) {
|
|
30
|
+
const split = val.split(AT_SIGN);
|
|
31
|
+
if (split[1]) {
|
|
32
|
+
out["--0-backdrop-" + split[0]] = split[1];
|
|
33
|
+
out["--0-backdrop"] = `${split[0]}(var(--0-backdrop-${split[0]}))`;
|
|
34
|
+
} else out["--0-backdrop"] = `${props.backdrop}(var(--0-backdrop-${props.backdrop}))`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return instance.inject(out);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// src/contracts/backdrop/backdrop.keys.ts
|
|
42
|
+
const BackdropRefKey = Symbol("BackdropRefKey");
|
|
43
|
+
const BackdropContractKey = Symbol("BackdropContractKey");
|
|
44
|
+
// src/contracts/backdrop/index.ts
|
|
45
|
+
const BackdropPropsKeys = ["backdrop"];
|
|
46
|
+
const backdrop = {
|
|
47
|
+
name: "backdrop",
|
|
48
|
+
key: BackdropContractKey,
|
|
49
|
+
ref: BackdropRefKey,
|
|
50
|
+
deal: backdropDeal,
|
|
51
|
+
flag: 3,
|
|
52
|
+
props: BackdropPropsKeys
|
|
53
|
+
};
|
|
54
|
+
// src/contracts/color/color.gradient.ts
|
|
55
|
+
const DIRECTIONS = {
|
|
56
|
+
right: "to right",
|
|
57
|
+
left: "to left",
|
|
58
|
+
top: "to top",
|
|
59
|
+
bottom: "to bottom",
|
|
60
|
+
tr: "to top right",
|
|
61
|
+
tl: "to top left",
|
|
62
|
+
br: "to bottom right",
|
|
63
|
+
bl: "to bottom left"
|
|
64
|
+
};
|
|
65
|
+
/** compile a gradient prop value into a `linear-gradient(...)` string */
|
|
66
|
+
function gradientStyle(value) {
|
|
67
|
+
if (!isString(value) || !value.trim()) return void 0;
|
|
68
|
+
const parts = value.trim().split(/\s+/);
|
|
69
|
+
let direction = DIRECTIONS.bottom;
|
|
70
|
+
if (parts[0]?.startsWith("to-")) {
|
|
71
|
+
const css = DIRECTIONS[parts[0].slice(3)];
|
|
72
|
+
if (!css) throw new Error(`ui0 gradient: unknown direction "${parts[0]}" (expected to-right|to-left|to-top|to-bottom|to-tr|to-tl|to-br|to-bl)`);
|
|
73
|
+
direction = css;
|
|
74
|
+
parts.shift();
|
|
75
|
+
}
|
|
76
|
+
const stops = parts.join("").split("->").map((s) => parseRef(s)).filter((s) => s.ref);
|
|
77
|
+
if (stops.length < 2) throw new Error(`ui0 gradient: "${value}" needs at least two stops (ref[->ref...])`);
|
|
78
|
+
const paint = stops.map((s) => `rgb(var(--0-c-${s.ref}-v) / ${s.opacity ?? 1})`).join(", ");
|
|
79
|
+
return `linear-gradient(${direction}, ${paint})`;
|
|
80
|
+
}
|
|
81
|
+
// src/contracts/color/color.serialize.ts
|
|
82
|
+
function resolveClass(full, $) {
|
|
83
|
+
return $ && $[full] || hashClassName(full);
|
|
84
|
+
}
|
|
85
|
+
function serializeTokens(tokens, slot, $) {
|
|
86
|
+
const classes = [];
|
|
87
|
+
const styles = {};
|
|
88
|
+
const ns = slot === "c" ? "--0-c" : "--0-f";
|
|
89
|
+
for (const t of tokens) {
|
|
90
|
+
const pre = `${t.scheme ? t.scheme + "-" : ""}${t.pseudo ? t.pseudo + "-" : ""}${slot}`;
|
|
91
|
+
classes.push(resolveClass(`${pre}-${t.ref}`, $));
|
|
92
|
+
if (t.opacity !== void 0 && t.opacity < 1) {
|
|
93
|
+
const ctx = `${t.scheme === "light" ? "-l" : t.scheme === "dark" ? "-d" : ""}${t.pseudo ? `-${t.pseudo}` : ""}`;
|
|
94
|
+
styles[`${ns}-src${ctx}`] = `${t.opacity}`;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
classes,
|
|
99
|
+
styles
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
// src/contracts/color/color.contract.ts
|
|
103
|
+
function colorDeal(instance) {
|
|
104
|
+
const props = instance.props;
|
|
105
|
+
let cache;
|
|
106
|
+
const norm = (v) => isString(v) ? v : Array.isArray(v) ? v.join(" ") : "";
|
|
107
|
+
const ensure = () => {
|
|
108
|
+
const key = [
|
|
109
|
+
norm(props.color),
|
|
110
|
+
norm(props.fill),
|
|
111
|
+
norm(props.gradient),
|
|
112
|
+
norm(instance.context?.color?.value),
|
|
113
|
+
norm(instance.context?.fill?.value)
|
|
114
|
+
].join("|");
|
|
115
|
+
if (cache && cache.key === key) return cache.value;
|
|
116
|
+
const value = paint(resolveProps());
|
|
117
|
+
cache = {
|
|
118
|
+
key,
|
|
119
|
+
value
|
|
120
|
+
};
|
|
121
|
+
return value;
|
|
122
|
+
};
|
|
123
|
+
const resolveProps = () => {
|
|
124
|
+
const out = {};
|
|
125
|
+
const color = props.color;
|
|
126
|
+
const fill = props.fill;
|
|
127
|
+
if (isString(color) && color.split(" ")[0] === "inherit") {
|
|
128
|
+
const v = instance.context?.color?.value;
|
|
129
|
+
if (v) out["color"] = v;
|
|
130
|
+
} else if (color) out["color"] = color;
|
|
131
|
+
if (isString(fill) && fill.split(" ")[0] === "inherit") {
|
|
132
|
+
const v = instance.context?.fill?.value;
|
|
133
|
+
if (v) out["fill"] = v;
|
|
134
|
+
} else if (fill) out["fill"] = fill;
|
|
135
|
+
if (props.gradient) out["gradient"] = props.gradient;
|
|
136
|
+
return out;
|
|
137
|
+
};
|
|
138
|
+
const paint = (p) => {
|
|
139
|
+
const classes = [];
|
|
140
|
+
const styles = {};
|
|
141
|
+
const $ = mergeCssModulesStyles(color_module_css_default, instance.$styles);
|
|
142
|
+
if (p.color) {
|
|
143
|
+
const out = serializeTokens(parseColorProp(p.color), "c", $);
|
|
144
|
+
classes.push(...out.classes);
|
|
145
|
+
Object.assign(styles, out.styles);
|
|
146
|
+
classes.push($.colored);
|
|
147
|
+
}
|
|
148
|
+
if (p.fill) {
|
|
149
|
+
const out = serializeTokens(parseColorProp(p.fill), "f", $);
|
|
150
|
+
classes.push(...out.classes);
|
|
151
|
+
Object.assign(styles, out.styles);
|
|
152
|
+
classes.push($.filled);
|
|
153
|
+
}
|
|
154
|
+
if (p.gradient) {
|
|
155
|
+
const g = gradientStyle(p.gradient);
|
|
156
|
+
if (g) {
|
|
157
|
+
styles["--0-g-cur"] = g;
|
|
158
|
+
classes.push($.gradiented);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
classes,
|
|
163
|
+
styles
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
classes: () => props.color || props.fill || props.gradient ? instance.inject(ensure().classes) : instance.inject([]),
|
|
168
|
+
styles: () => instance.inject(ensure().styles)
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
// src/contracts/color/color.keys.ts
|
|
172
|
+
const ColorContractKey = Symbol("ColorContractKey");
|
|
173
|
+
const ColorRefKey = Symbol("ColorRefKey");
|
|
174
|
+
// src/contracts/color/index.ts
|
|
175
|
+
const ColorPropsKeys = [
|
|
176
|
+
"color",
|
|
177
|
+
"fill",
|
|
178
|
+
"gradient"
|
|
179
|
+
];
|
|
180
|
+
const color = {
|
|
181
|
+
name: "color",
|
|
182
|
+
key: ColorContractKey,
|
|
183
|
+
flag: 3,
|
|
184
|
+
ref: ColorRefKey,
|
|
185
|
+
deal: colorDeal,
|
|
186
|
+
props: ColorPropsKeys
|
|
187
|
+
};
|
|
188
|
+
// src/contracts/disabled/disabled.contract.ts
|
|
189
|
+
function disabledClasses(p, s) {
|
|
190
|
+
const $ = mergeCssModulesStyles(disabled_module_css_default, s);
|
|
191
|
+
if (p.disabled) return [$.disabled];
|
|
192
|
+
return [];
|
|
193
|
+
}
|
|
194
|
+
function disabledDeal(instance) {
|
|
195
|
+
const props = instance.props;
|
|
196
|
+
return {
|
|
197
|
+
classes: () => {
|
|
198
|
+
if (instance.context) {
|
|
199
|
+
if (props.disabled === "inherit" && instance.context.disabled) return instance.inject(disabledClasses({ disabled: instance.context.disabled.value }, instance.$styles));
|
|
200
|
+
}
|
|
201
|
+
return instance.inject(disabledClasses(props, instance.$styles));
|
|
202
|
+
},
|
|
203
|
+
styles: () => instance.inject(EMPTY_OBJ)
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
// src/contracts/disabled/disabled.keys.ts
|
|
207
|
+
const DisabledRefKey = Symbol("DisabledRefKey");
|
|
208
|
+
const DisabledContractKey = Symbol("DisabledContractKey");
|
|
209
|
+
// src/contracts/disabled/index.ts
|
|
210
|
+
const DisabledPropsKeys = ["disabled"];
|
|
211
|
+
const disabled = {
|
|
212
|
+
key: DisabledContractKey,
|
|
213
|
+
name: "disabled",
|
|
214
|
+
ref: DisabledRefKey,
|
|
215
|
+
flag: 3,
|
|
216
|
+
deal: disabledDeal,
|
|
217
|
+
props: DisabledPropsKeys
|
|
218
|
+
};
|
|
219
|
+
// src/contracts/display/display.contract.ts
|
|
220
|
+
function displayClasses(props, styles) {
|
|
221
|
+
const $ = mergeCssModulesStyles(display_module_css_default, styles);
|
|
222
|
+
const out = [];
|
|
223
|
+
if (props.display && $.displayed) out.push($.displayed);
|
|
224
|
+
return out;
|
|
225
|
+
}
|
|
226
|
+
function displayDeal(instance) {
|
|
227
|
+
const props = instance.props;
|
|
228
|
+
return {
|
|
229
|
+
classes: () => {
|
|
230
|
+
if (!props.display) return instance.inject([]);
|
|
231
|
+
if (props.display === "inherit") {
|
|
232
|
+
const ctx = instance.context;
|
|
233
|
+
if (ctx?.display) return instance.inject(displayClasses({ display: ctx.display.value }, instance.$styles));
|
|
234
|
+
}
|
|
235
|
+
return instance.inject(displayClasses(props, instance.$styles));
|
|
236
|
+
},
|
|
237
|
+
styles: () => instance.inject(EMPTY_OBJ)
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
// src/contracts/display/display.keys.ts
|
|
241
|
+
/** context key the deal resolves `inherit` against (see useThemeContract) */
|
|
242
|
+
const DisplayRefKey = Symbol("DisplayRefKey");
|
|
243
|
+
const DisplayContractKey = Symbol("DisplayContractKey");
|
|
244
|
+
const DisplayKey = Symbol("DisplayContractKey");
|
|
245
|
+
const display = {
|
|
246
|
+
key: DisplayContractKey,
|
|
247
|
+
name: "display",
|
|
248
|
+
ref: DisplayRefKey,
|
|
249
|
+
deal: displayDeal,
|
|
250
|
+
flag: 1,
|
|
251
|
+
props: []
|
|
252
|
+
};
|
|
253
|
+
// src/contracts/elevation/elevation.contract.ts
|
|
254
|
+
function elevationClasses(p, s) {
|
|
255
|
+
const { elevation } = p;
|
|
256
|
+
if (elevation === void 0) return [];
|
|
257
|
+
const $ = mergeCssModulesStyles(elevation_module_css_default, s);
|
|
258
|
+
const value = Number(elevation);
|
|
259
|
+
return Number.isNaN(value) ? [] : [$["elv" + Math.abs(value) + (value < 0 ? "n" : "")], $.elv];
|
|
260
|
+
}
|
|
261
|
+
function elevationDeal(instance) {
|
|
262
|
+
const props = instance.props;
|
|
263
|
+
return {
|
|
264
|
+
classes: () => {
|
|
265
|
+
if (instance.context) {
|
|
266
|
+
if (props.elevation === "inherit" && instance.context.elevation) return instance.inject(elevationClasses({ elevation: instance.context.elevation.value }, instance.$styles));
|
|
267
|
+
}
|
|
268
|
+
return instance.inject(elevationClasses(props, instance.$styles));
|
|
269
|
+
},
|
|
270
|
+
styles: () => instance.inject(EMPTY_OBJ)
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
// src/contracts/elevation/elevation.keys.ts
|
|
274
|
+
const ElevationRefKey = Symbol("ElevationRefKey");
|
|
275
|
+
const ElevationContractKey = Symbol("ElevationContractKey");
|
|
276
|
+
// src/contracts/elevation/index.ts
|
|
277
|
+
const ElevationPropsKeys = ["elevation"];
|
|
278
|
+
const elevation = {
|
|
279
|
+
key: ElevationContractKey,
|
|
280
|
+
name: "elevation",
|
|
281
|
+
ref: ElevationRefKey,
|
|
282
|
+
deal: elevationDeal,
|
|
283
|
+
flag: 3,
|
|
284
|
+
props: ElevationPropsKeys
|
|
285
|
+
};
|
|
286
|
+
// src/contracts/round/round.contract.ts
|
|
287
|
+
function roundDeal(instance) {
|
|
288
|
+
return {
|
|
289
|
+
classes() {
|
|
290
|
+
const { props, $styles } = instance;
|
|
291
|
+
const $ = mergeCssModulesStyles(round_module_css_default, $styles);
|
|
292
|
+
console.log("props", instance.props);
|
|
293
|
+
console.log("propsToCssModuleClassNext(props, [getRoundPropClasses($), getRoundTargetPropClasses($)], $)", propsToCssModuleClassNext(props, [getRoundPropClasses($), getRoundTargetPropClasses($)], $));
|
|
294
|
+
return propsToCssModuleClassNext(props, [getRoundPropClasses($), getRoundTargetPropClasses($)], $);
|
|
295
|
+
},
|
|
296
|
+
styles: () => instance.inject(EMPTY_OBJ)
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
function getRoundTargetPropClasses(style = round_module_css_default) {
|
|
300
|
+
return ["roundTarget", {
|
|
301
|
+
"top-left-none": style.tln,
|
|
302
|
+
"bottom-left-none": style.bln,
|
|
303
|
+
"top-right-none": style.trn,
|
|
304
|
+
"bottom-right-none": style.brn,
|
|
305
|
+
"top-none": style.tn,
|
|
306
|
+
"bottom-none": style.bn,
|
|
307
|
+
"right-none": style.rn,
|
|
308
|
+
"left-none": style.ln,
|
|
309
|
+
"bottom-left": style.bl,
|
|
310
|
+
"bottom-right": style.br,
|
|
311
|
+
"top-right": style.tr,
|
|
312
|
+
"top-left": style.tl
|
|
313
|
+
}];
|
|
314
|
+
}
|
|
315
|
+
function getRoundPropClasses(style = round_module_css_default) {
|
|
316
|
+
return ["round", {
|
|
317
|
+
true: style.rFull,
|
|
318
|
+
none: style.rNone,
|
|
319
|
+
full: style.rFull,
|
|
320
|
+
basic: style.rBasic,
|
|
321
|
+
smooth: style.rSmooth,
|
|
322
|
+
hard: style.rHard,
|
|
323
|
+
round: style.round,
|
|
324
|
+
left: [style.tl, style.bl],
|
|
325
|
+
right: [style.tr, style.br],
|
|
326
|
+
bottom: [style.br, style.bl],
|
|
327
|
+
top: [style.tl, style.tr]
|
|
328
|
+
}];
|
|
329
|
+
}
|
|
330
|
+
// src/contracts/round/round.keys.ts
|
|
331
|
+
const RoundRefKey = Symbol("RoundRefKey");
|
|
332
|
+
const RoundContractKey = Symbol("RoundContractKey");
|
|
333
|
+
// src/contracts/round/index.ts
|
|
334
|
+
const RoundPropsKeys = ["round", "round-target"];
|
|
335
|
+
const round = {
|
|
336
|
+
key: RoundContractKey,
|
|
337
|
+
name: "round",
|
|
338
|
+
ref: RoundRefKey,
|
|
339
|
+
deal: roundDeal,
|
|
340
|
+
flag: 3,
|
|
341
|
+
props: RoundPropsKeys
|
|
342
|
+
};
|
|
343
|
+
// src/contracts/size/size.types.ts
|
|
344
|
+
/** the absolute scale steps a `size` prop can pick (long and short spellings) */
|
|
345
|
+
const SizeValuesAbsolute = [
|
|
346
|
+
"xxxs",
|
|
347
|
+
"xxs",
|
|
348
|
+
"xs",
|
|
349
|
+
"s",
|
|
350
|
+
"m",
|
|
351
|
+
"l",
|
|
352
|
+
"xl",
|
|
353
|
+
"xxl",
|
|
354
|
+
"xxxl"
|
|
355
|
+
];
|
|
356
|
+
// src/contracts/size/size.contract.ts
|
|
357
|
+
function sizeClasses(props, styles) {
|
|
358
|
+
const out = [];
|
|
359
|
+
const { size, density } = props;
|
|
360
|
+
const normalizedSizing = isArray(density) ? density : [toCamelCase(density)];
|
|
361
|
+
const $ = mergeCssModulesStyles(size_module_css_default, styles);
|
|
362
|
+
if (size) {
|
|
363
|
+
out.push($.sized);
|
|
364
|
+
const cls = getSizePropClasses($)[size];
|
|
365
|
+
if (cls) out.push(cls);
|
|
366
|
+
}
|
|
367
|
+
if (normalizedSizing) normalizedSizing.forEach((d) => {
|
|
368
|
+
if ($ && $[d]) out.push($[d]);
|
|
369
|
+
});
|
|
370
|
+
return out;
|
|
371
|
+
}
|
|
372
|
+
function getSizePropClasses(styles) {
|
|
373
|
+
return {
|
|
374
|
+
"xxx-large": styles.sizeXxxl,
|
|
375
|
+
"xx-large": styles.sizeXxl,
|
|
376
|
+
"x-large": styles.sizeXl,
|
|
377
|
+
large: styles.sizeL,
|
|
378
|
+
"x-small": styles.sizeXs,
|
|
379
|
+
"xx-small": styles.sizeXxs,
|
|
380
|
+
"xxx-small": styles.sizeXxxs,
|
|
381
|
+
small: styles.sizeS,
|
|
382
|
+
medium: styles.sizeM,
|
|
383
|
+
xxxl: styles.sizeXxxl,
|
|
384
|
+
xxl: styles.sizeXxl,
|
|
385
|
+
xl: styles.sizeXl,
|
|
386
|
+
l: styles.sizeL,
|
|
387
|
+
xs: styles.sizeXs,
|
|
388
|
+
xxs: styles.sizeXxs,
|
|
389
|
+
xxxs: styles.sizeXxxs,
|
|
390
|
+
s: styles.sizeS,
|
|
391
|
+
m: styles.sizeM,
|
|
392
|
+
larger: "",
|
|
393
|
+
inherit: "",
|
|
394
|
+
smaller: "",
|
|
395
|
+
custom: styles.sizeCustom
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
function sizeDeal(instance) {
|
|
399
|
+
const props = instance.props;
|
|
400
|
+
return {
|
|
401
|
+
classes: () => {
|
|
402
|
+
const { size, density } = props;
|
|
403
|
+
if (!size && !density) return instance.inject([]);
|
|
404
|
+
if (instance.context) {
|
|
405
|
+
const out = {};
|
|
406
|
+
const ctxSize = instance.context.size;
|
|
407
|
+
if (ctxSize) {
|
|
408
|
+
if (size === "inherit") out["size"] = ctxSize.value;
|
|
409
|
+
if (size === "smaller" || size === "larger") out["size"] = (size === "smaller" ? arrayPickPrev : arrayPickNext)(SizeValuesAbsolute, ctxSize.value);
|
|
410
|
+
}
|
|
411
|
+
const ctxDensity = instance.context.density;
|
|
412
|
+
if (ctxDensity && density === "inherit") out["density"] = ctxDensity.value;
|
|
413
|
+
if (!("density" in out) && props.density) out["density"] = props.density;
|
|
414
|
+
if (!("size" in out) && props.size) out["size"] = props.size;
|
|
415
|
+
return instance.inject(sizeClasses(out, instance.$styles));
|
|
416
|
+
}
|
|
417
|
+
return instance.inject(sizeClasses(props, instance.$styles));
|
|
418
|
+
},
|
|
419
|
+
styles: () => instance.inject(EMPTY_OBJ)
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
// src/contracts/size/size.keys.ts
|
|
423
|
+
const SizeRefKey = Symbol("SizeRefKey");
|
|
424
|
+
const SizeContractKey = Symbol("SizeContractKey");
|
|
425
|
+
// src/contracts/size/index.ts
|
|
426
|
+
const SizePropsKeys = ["size", "density"];
|
|
427
|
+
const size = {
|
|
428
|
+
ref: SizeRefKey,
|
|
429
|
+
name: "size",
|
|
430
|
+
props: SizePropsKeys,
|
|
431
|
+
deal: sizeDeal,
|
|
432
|
+
flag: 3,
|
|
433
|
+
key: SizeContractKey
|
|
434
|
+
};
|
|
435
|
+
// src/contracts/style/index.ts
|
|
436
|
+
const style = {
|
|
437
|
+
key: Symbol("StyleContractKey"),
|
|
438
|
+
name: "style",
|
|
439
|
+
flag: 1
|
|
440
|
+
};
|
|
441
|
+
// src/contracts/typography/typography.contract.ts
|
|
442
|
+
function typographyClasses(props, styles) {
|
|
443
|
+
const $ = mergeCssModulesStyles(typography_module_css_default, styles);
|
|
444
|
+
const out = [];
|
|
445
|
+
if (props.typography && $[props.typography]) out.push($[props.typography]);
|
|
446
|
+
return out;
|
|
447
|
+
}
|
|
448
|
+
function typographyDeal(instance) {
|
|
449
|
+
const props = instance.props;
|
|
450
|
+
return {
|
|
451
|
+
classes: () => {
|
|
452
|
+
if (!props.typography) return instance.inject([]);
|
|
453
|
+
if (props.typography === "inherit") {
|
|
454
|
+
const ctx = instance.context;
|
|
455
|
+
if (ctx?.typography) return instance.inject(typographyClasses({ typography: ctx.typography.value }, instance.$styles));
|
|
456
|
+
}
|
|
457
|
+
return instance.inject(typographyClasses(props, instance.$styles));
|
|
458
|
+
},
|
|
459
|
+
styles: () => instance.inject(EMPTY_OBJ)
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
// src/contracts/index.ts
|
|
463
|
+
const contracts = {
|
|
464
|
+
color,
|
|
465
|
+
backdrop,
|
|
466
|
+
round,
|
|
467
|
+
elevation,
|
|
468
|
+
style,
|
|
469
|
+
disabled,
|
|
470
|
+
display,
|
|
471
|
+
typography: {
|
|
472
|
+
key: Symbol("TypographyContractKey"),
|
|
473
|
+
name: "typography",
|
|
474
|
+
ref: Symbol("TypographyRefKey"),
|
|
475
|
+
deal: typographyDeal,
|
|
476
|
+
flag: 3,
|
|
477
|
+
props: ["typography"]
|
|
478
|
+
},
|
|
479
|
+
size
|
|
480
|
+
};
|
|
481
|
+
const props = [
|
|
482
|
+
ColorPropsKeys,
|
|
483
|
+
RoundPropsKeys,
|
|
484
|
+
SizePropsKeys,
|
|
485
|
+
ElevationPropsKeys,
|
|
486
|
+
BackdropPropsKeys,
|
|
487
|
+
DisabledPropsKeys
|
|
488
|
+
].flat();
|
|
489
|
+
// src/contracts/display/display.instance.ts
|
|
490
|
+
var Display = class {
|
|
491
|
+
breakpoints;
|
|
492
|
+
_watchers;
|
|
493
|
+
_watcher;
|
|
494
|
+
_activated;
|
|
495
|
+
_listeners;
|
|
496
|
+
_width;
|
|
497
|
+
_height;
|
|
498
|
+
_resizeHandler;
|
|
499
|
+
constructor(config$1) {
|
|
500
|
+
this.breakpoints = objectMerge(config.contracts.display?.breakpoints, config$1?.breakpoints ?? {});
|
|
501
|
+
this._watchers = [];
|
|
502
|
+
this._watcher = null;
|
|
503
|
+
this._width = null;
|
|
504
|
+
this._height = null;
|
|
505
|
+
this._activated = false;
|
|
506
|
+
this._resizeHandler = () => this.update();
|
|
507
|
+
this._listeners = new RecordContainer();
|
|
508
|
+
}
|
|
509
|
+
update() {
|
|
510
|
+
if (this._width && this._height) {
|
|
511
|
+
this._width.value = getClientWidth();
|
|
512
|
+
this._height.value = getClientHeight();
|
|
513
|
+
}
|
|
514
|
+
let wasChanged = false;
|
|
515
|
+
this._watchers.forEach((watcher) => {
|
|
516
|
+
const measure = watcher.measure === "width" ? this._width : this._height;
|
|
517
|
+
const oldValue = watcher.value.value;
|
|
518
|
+
if (watcher.operation === "between") {
|
|
519
|
+
const breakpoint1 = this.getBreakpointValue(String(watcher.points[0]));
|
|
520
|
+
const breakpoint2 = this.getBreakpointValue(String(watcher.points[1]));
|
|
521
|
+
if (measure && breakpoint1 && breakpoint2) {
|
|
522
|
+
const b1 = parseUnits(String(breakpoint1)).value;
|
|
523
|
+
const b2 = parseUnits(String(breakpoint2)).value;
|
|
524
|
+
if (b1 > b2) watcher.value.value = measure.value > b2 && measure.value < b1;
|
|
525
|
+
if (b1 < b2) watcher.value.value = measure.value > b1 && measure.value < b2;
|
|
526
|
+
if (watcher.value.value !== oldValue) wasChanged = true;
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (watcher.operation === "less" || watcher.operation === "greater") {
|
|
530
|
+
const breakpoint1 = this.getBreakpointValue(String(watcher.points[0]));
|
|
531
|
+
if (breakpoint1 && measure) {
|
|
532
|
+
const b1 = parseUnits(String(breakpoint1)).value;
|
|
533
|
+
watcher.value.value = watcher.operation === "less" ? measure.value < b1 : measure.value > b1;
|
|
534
|
+
if (watcher.value.value !== oldValue) wasChanged = true;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
if (wasChanged) this._listeners.items.forEach((item) => item());
|
|
539
|
+
}
|
|
540
|
+
addUpdateListener(fn) {
|
|
541
|
+
return this._listeners.add(fn);
|
|
542
|
+
}
|
|
543
|
+
removeUpdateListener(index) {
|
|
544
|
+
this._listeners.remove(index);
|
|
545
|
+
}
|
|
546
|
+
less(point, measure = "width") {
|
|
547
|
+
const out = this.addWatcher("less", [point], measure);
|
|
548
|
+
this.activate();
|
|
549
|
+
return out;
|
|
550
|
+
}
|
|
551
|
+
between(point1, point2, measure = "width") {
|
|
552
|
+
const out = this.addWatcher("between", [point1, point2], measure);
|
|
553
|
+
this.activate();
|
|
554
|
+
this.update();
|
|
555
|
+
return out;
|
|
556
|
+
}
|
|
557
|
+
greater(point, measure = "width") {
|
|
558
|
+
const out = this.addWatcher("greater", [point], measure);
|
|
559
|
+
this.activate();
|
|
560
|
+
return out;
|
|
561
|
+
}
|
|
562
|
+
activate() {
|
|
563
|
+
if (!this._width) this._width = ref(0);
|
|
564
|
+
if (!this._height) this._height = ref(0);
|
|
565
|
+
if (isBrowser && !this._activated) window.addEventListener("resize", this._resizeHandler, { passive: true });
|
|
566
|
+
this.update();
|
|
567
|
+
this._activated = true;
|
|
568
|
+
}
|
|
569
|
+
deactivate() {
|
|
570
|
+
this._activated = false;
|
|
571
|
+
if (isBrowser) window.removeEventListener("resize", this._resizeHandler);
|
|
572
|
+
}
|
|
573
|
+
getBreakpointValue(name) {
|
|
574
|
+
return +this.breakpoints[name];
|
|
575
|
+
}
|
|
576
|
+
addWatcher(operation, points, measure = "width") {
|
|
577
|
+
let outRef = void 0;
|
|
578
|
+
this._watchers.forEach((watcher) => {
|
|
579
|
+
const isMultiValued = watcher.points.length > 1;
|
|
580
|
+
if (watcher.operation === operation) {
|
|
581
|
+
if (isMultiValued) {
|
|
582
|
+
if (watcher.points[0] === points[0] && watcher.points[1] === points[1]) {
|
|
583
|
+
console.log("setting existing ", watcher.value);
|
|
584
|
+
outRef = watcher.value;
|
|
585
|
+
}
|
|
586
|
+
} else if (watcher.points[0] === points[0]) outRef = watcher.value;
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
if (!outRef) {
|
|
590
|
+
outRef = ref(false);
|
|
591
|
+
this._watchers.push({
|
|
592
|
+
measure,
|
|
593
|
+
points,
|
|
594
|
+
operation,
|
|
595
|
+
value: outRef
|
|
596
|
+
});
|
|
597
|
+
}
|
|
598
|
+
return outRef;
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
// src/persist.ts
|
|
602
|
+
/** the storage slot holding the selection */
|
|
603
|
+
const STORAGE_KEY = "ui0:theme";
|
|
604
|
+
/**
|
|
605
|
+
* Reads the stored selection.
|
|
606
|
+
* @returns the parsed selection, or undefined when absent or unreadable
|
|
607
|
+
*/
|
|
608
|
+
function readStoredSelection() {
|
|
609
|
+
if (typeof localStorage === "undefined") return void 0;
|
|
610
|
+
try {
|
|
611
|
+
const raw = localStorage.getItem(STORAGE_KEY);
|
|
612
|
+
if (!raw) return void 0;
|
|
613
|
+
const parsed = JSON.parse(raw);
|
|
614
|
+
if (typeof parsed !== "object" || parsed === null) return void 0;
|
|
615
|
+
return parsed;
|
|
616
|
+
} catch {
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Writes the selection, swallowing storage errors.
|
|
622
|
+
* @param preset - the active preset name
|
|
623
|
+
* @param appearance - the active appearance
|
|
624
|
+
*/
|
|
625
|
+
function writeStoredSelection(preset, appearance) {
|
|
626
|
+
if (typeof localStorage === "undefined") return;
|
|
627
|
+
try {
|
|
628
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify({
|
|
629
|
+
preset,
|
|
630
|
+
appearance
|
|
631
|
+
}));
|
|
632
|
+
} catch {}
|
|
633
|
+
}
|
|
634
|
+
// src/instance.ts
|
|
635
|
+
function createThemeInstance(config, options = {}) {
|
|
636
|
+
const resolved = withDefaults(config);
|
|
637
|
+
const contracts = {};
|
|
638
|
+
const props = [];
|
|
639
|
+
const presets = { ...resolved.presets };
|
|
640
|
+
const cache = {};
|
|
641
|
+
const names = () => Object.keys(presets);
|
|
642
|
+
const stored = readStoredSelection();
|
|
643
|
+
const storedPreset = stored?.preset && stored.preset in presets ? stored.preset : void 0;
|
|
644
|
+
const storedAppearance = stored?.appearance && THEME_SCHEMES.includes(stored.appearance) ? stored.appearance : void 0;
|
|
645
|
+
const name = ref(options.theme && options.theme in presets ? options.theme : storedPreset ?? (resolved.default in presets ? resolved.default : names()[0] ?? ""));
|
|
646
|
+
const appearance = ref(options.appearance ?? storedAppearance ?? "light");
|
|
647
|
+
watch([name, appearance], ([preset, appr]) => writeStoredSelection(preset, appr), { flush: "sync" });
|
|
648
|
+
/** the resolved appearance config (base merged under the scheme) */
|
|
649
|
+
const configFor = (n, appr) => {
|
|
650
|
+
const preset = resolvePreset(presets, n, cache);
|
|
651
|
+
const scheme = appr === "default" ? schemesOf(preset).default : schemesOf(preset)[appr];
|
|
652
|
+
return scheme ? deepMerge(schemesOf(preset).default, scheme) : schemesOf(preset).default;
|
|
653
|
+
};
|
|
654
|
+
function descendants(base) {
|
|
655
|
+
const out = /* @__PURE__ */ new Set();
|
|
656
|
+
let frontier = [base];
|
|
657
|
+
while (frontier.length) {
|
|
658
|
+
const next = [];
|
|
659
|
+
for (const b of frontier) for (const n of names()) if (!out.has(n) && n !== base && presets[n]?.extends === b) {
|
|
660
|
+
out.add(n);
|
|
661
|
+
next.push(n);
|
|
662
|
+
}
|
|
663
|
+
frontier = next;
|
|
664
|
+
}
|
|
665
|
+
return [...out];
|
|
666
|
+
}
|
|
667
|
+
return {
|
|
668
|
+
contracts,
|
|
669
|
+
get preset() {
|
|
670
|
+
return name.value;
|
|
671
|
+
},
|
|
672
|
+
presets() {
|
|
673
|
+
return presets;
|
|
674
|
+
},
|
|
675
|
+
set preset(v) {
|
|
676
|
+
if (v in presets) name.value = v;
|
|
677
|
+
},
|
|
678
|
+
get appearance() {
|
|
679
|
+
return appearance.value;
|
|
680
|
+
},
|
|
681
|
+
set appearance(v) {
|
|
682
|
+
appearance.value = v;
|
|
683
|
+
},
|
|
684
|
+
toggle: () => {
|
|
685
|
+
appearance.value = appearance.value === "dark" ? "light" : "dark";
|
|
686
|
+
},
|
|
687
|
+
presetList: () => names(),
|
|
688
|
+
extends: (exact) => descendants(exact ?? name.value),
|
|
689
|
+
addPreset(n, preset) {
|
|
690
|
+
presets[n] = preset;
|
|
691
|
+
delete cache[n];
|
|
692
|
+
},
|
|
693
|
+
addContract(contract) {
|
|
694
|
+
contracts[contract.key] = contract;
|
|
695
|
+
if (contract.props && isArray(contract.props)) props.push(...contract.props);
|
|
696
|
+
},
|
|
697
|
+
removeContract(key) {
|
|
698
|
+
delete contracts[key];
|
|
699
|
+
},
|
|
700
|
+
contractList: () => Object.getOwnPropertySymbols(contracts),
|
|
701
|
+
contractProps: () => props,
|
|
702
|
+
colorList(theme, appr) {
|
|
703
|
+
const cfg = configFor(theme ?? name.value, appr ?? appearance.value);
|
|
704
|
+
const { base } = resolvePool(buildPool(cfg.color, void 0));
|
|
705
|
+
return Object.keys(base);
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
// src/keys.ts
|
|
710
|
+
const Ui0ThemeKey = Symbol("ui0-theme");
|
|
711
|
+
// src/plugin.ts
|
|
712
|
+
function createUi0Theme(config) {
|
|
713
|
+
return { install(instance) {
|
|
714
|
+
const theme = createThemeInstance(config);
|
|
715
|
+
Object.keys(contracts).forEach((c) => {
|
|
716
|
+
theme.addContract(contracts[c]);
|
|
717
|
+
});
|
|
718
|
+
const display = new Display(config.contracts.display);
|
|
719
|
+
if (typeof document !== "undefined") ensureThemeBaseStyle(document);
|
|
720
|
+
if (instance.vue) {
|
|
721
|
+
instance.vue.provide(Ui0ThemeKey, theme);
|
|
722
|
+
instance.vue.provide(DisplayKey, display);
|
|
723
|
+
}
|
|
724
|
+
return theme;
|
|
725
|
+
} };
|
|
726
|
+
}
|
|
727
|
+
// src/useTheme.ts
|
|
728
|
+
function useTheme() {
|
|
729
|
+
if (hasInjectionContext()) {
|
|
730
|
+
const provided = inject(Ui0ThemeKey, void 0);
|
|
731
|
+
if (provided) return provided;
|
|
732
|
+
}
|
|
733
|
+
const vm = getCurrentInstance();
|
|
734
|
+
if (!vm) return void 0;
|
|
735
|
+
return vm.appContext.config.globalProperties.$ui0?.theme;
|
|
736
|
+
}
|
|
737
|
+
// src/useDisplay.ts
|
|
738
|
+
function useDisplay(onUpdate) {
|
|
739
|
+
if (hasInjectionContext()) {
|
|
740
|
+
const display = inject(DisplayKey);
|
|
741
|
+
if (display) {
|
|
742
|
+
console.log("if display", display);
|
|
743
|
+
if (onUpdate) onMounted(() => {
|
|
744
|
+
const id = display.addUpdateListener(onUpdate);
|
|
745
|
+
onUnmounted(() => {
|
|
746
|
+
display.removeUpdateListener(id);
|
|
747
|
+
});
|
|
748
|
+
});
|
|
749
|
+
return display;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
throw newFrameworkError("display context not exists");
|
|
753
|
+
}
|
|
754
|
+
// src/contracts/contract.ts
|
|
755
|
+
var ThemeContractInstance = class {
|
|
756
|
+
props;
|
|
757
|
+
/**
|
|
758
|
+
* context have any provided props from styler's
|
|
759
|
+
*/
|
|
760
|
+
context;
|
|
761
|
+
$styles;
|
|
762
|
+
name;
|
|
763
|
+
classList = [];
|
|
764
|
+
styleList = {};
|
|
765
|
+
contracts;
|
|
766
|
+
constructor(name, props, styles) {
|
|
767
|
+
this.$styles = styles ?? {};
|
|
768
|
+
this.props = props ?? {};
|
|
769
|
+
this.name = name;
|
|
770
|
+
this.context = null;
|
|
771
|
+
this.contracts = {};
|
|
772
|
+
}
|
|
773
|
+
add(contract) {
|
|
774
|
+
this.contracts[contract.name] = contract;
|
|
775
|
+
}
|
|
776
|
+
prop(name) {
|
|
777
|
+
const jobs = {};
|
|
778
|
+
const instance = this;
|
|
779
|
+
for (const contract of Object.values(this.contracts)) {
|
|
780
|
+
if (isArray(name)) name.forEach((n) => {
|
|
781
|
+
if (contract.props?.includes(n)) jobs[contract.name] = contract.deal;
|
|
782
|
+
});
|
|
783
|
+
else if (isString(name)) {
|
|
784
|
+
if (contract.props?.includes(name)) jobs[contract.name] = contract;
|
|
785
|
+
}
|
|
786
|
+
contract?.props?.includes(name);
|
|
787
|
+
}
|
|
788
|
+
return {
|
|
789
|
+
styles() {
|
|
790
|
+
let out = {};
|
|
791
|
+
for (const contract of Object.values(jobs)) {
|
|
792
|
+
const deal = contract?.deal?.(instance);
|
|
793
|
+
if (deal) out = {
|
|
794
|
+
...out,
|
|
795
|
+
...deal.styles()
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
return out;
|
|
799
|
+
},
|
|
800
|
+
classes() {
|
|
801
|
+
const out = [];
|
|
802
|
+
for (const contract of Object.values(jobs)) {
|
|
803
|
+
const deal = contract?.deal?.(instance);
|
|
804
|
+
if (deal) out.push(...deal.classes());
|
|
805
|
+
}
|
|
806
|
+
return out;
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
remove(name) {
|
|
811
|
+
delete this.contracts[name];
|
|
812
|
+
}
|
|
813
|
+
setContext(p) {
|
|
814
|
+
this.context = p;
|
|
815
|
+
}
|
|
816
|
+
classes(props_, $styles = this.$styles) {
|
|
817
|
+
const props = props_ ?? this.props;
|
|
818
|
+
const out = [];
|
|
819
|
+
for (const contract of Object.values(this.contracts)) {
|
|
820
|
+
const deal = contract?.deal?.(this);
|
|
821
|
+
if (deal) out.push(...deal.classes(props, $styles));
|
|
822
|
+
}
|
|
823
|
+
return out;
|
|
824
|
+
}
|
|
825
|
+
styles(props_) {
|
|
826
|
+
const props = props_ ?? this.props;
|
|
827
|
+
let out = {};
|
|
828
|
+
for (const contract of Object.keys(this.contracts)) {
|
|
829
|
+
const deal = this.contracts[contract]?.deal?.(this);
|
|
830
|
+
if (deal) out = {
|
|
831
|
+
...out,
|
|
832
|
+
...deal.styles(props)
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
return out;
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Virtual's classes and styles injector
|
|
839
|
+
* @param data
|
|
840
|
+
* @private
|
|
841
|
+
*/
|
|
842
|
+
inject(data) {
|
|
843
|
+
if (isArray(data)) {
|
|
844
|
+
if (data.indexOf(this.classList[0]) === -1) return [...this.classList, ...data];
|
|
845
|
+
else return data;
|
|
846
|
+
} else return {
|
|
847
|
+
...this.styleList,
|
|
848
|
+
...data
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
// src/useThemeContext.ts
|
|
853
|
+
function useThemeContext(props, $styles, _allowContracts) {
|
|
854
|
+
const vm = getCurrentInstance();
|
|
855
|
+
if (hasInjectionContext()) {
|
|
856
|
+
const $style = $styles ?? useCssModule();
|
|
857
|
+
const theme = useTheme();
|
|
858
|
+
if (theme) {
|
|
859
|
+
const refs = isReactive(props) ? toRefs(props) : toRefs(reactive(props));
|
|
860
|
+
function providePropRef(name, key) {
|
|
861
|
+
const injected = inject(key, null);
|
|
862
|
+
const keys = [
|
|
863
|
+
"smaller",
|
|
864
|
+
"larger",
|
|
865
|
+
"inherit"
|
|
866
|
+
];
|
|
867
|
+
if (refs) {
|
|
868
|
+
const ref = refs[name];
|
|
869
|
+
if (ref) {
|
|
870
|
+
if (ref.value !== void 0) {
|
|
871
|
+
const v = ref.value;
|
|
872
|
+
if (isArray(v) && v.length) {
|
|
873
|
+
if (v[0] && isString(v[0]) && !keys.includes(v[0])) {
|
|
874
|
+
provide(key, ref);
|
|
875
|
+
return ref;
|
|
876
|
+
} else if (injected) {
|
|
877
|
+
provide(key, injected);
|
|
878
|
+
return injected;
|
|
879
|
+
}
|
|
880
|
+
} else if (v && isString(v) && !keys.includes(v) || typeof v === "number") {
|
|
881
|
+
provide(key, ref);
|
|
882
|
+
return ref;
|
|
883
|
+
} else if (injected) {
|
|
884
|
+
provide(key, injected);
|
|
885
|
+
return injected;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
const provider = new ThemeContractInstance("test", props, $style);
|
|
892
|
+
const ctx = {};
|
|
893
|
+
for (const c of theme.contractList()) {
|
|
894
|
+
const currentContract = theme.contracts[c];
|
|
895
|
+
const r = currentContract.ref;
|
|
896
|
+
if (r) ctx[currentContract.name] = providePropRef(currentContract.name, r);
|
|
897
|
+
provider.add(currentContract);
|
|
898
|
+
}
|
|
899
|
+
provider.setContext(ctx);
|
|
900
|
+
return [theme, provider];
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
if (!vm) throw newFrameworkError("ThemeWithContext");
|
|
904
|
+
if (!vm) return [void 0, void 0];
|
|
905
|
+
return [vm.appContext.config.globalProperties.$ui0?.theme, void 0];
|
|
906
|
+
}
|
|
907
|
+
export { props as ThemeContractPropsKeys, ThemeProvider, contractGenerators, createThemeInstance, createUi0Theme, generateThemeArtifacts, generateThemeCss, generateThemeTypes, useDisplay, useTheme, useThemeContext, withDefaults };
|
|
908
|
+
|
|
909
|
+
//# sourceMappingURL=index.mjs.map
|