@povio/ui 5.0.0-rc.6 → 5.0.0-rc.7

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.
@@ -0,0 +1,163 @@
1
+ //#region src/configurator/inspector/token-classes.ts
2
+ /** Tailwind breakpoints from the Atlas base theme, in rem. */
3
+ const breakpoints = {
4
+ sm: 23.75,
5
+ md: 37.5,
6
+ lg: 80,
7
+ xl: 105
8
+ };
9
+ /** Utility prefix → the slots it sets, its specificity, and the theme namespace its value lives in. */
10
+ const utilities = [
11
+ [
12
+ "p",
13
+ [
14
+ "padding.top",
15
+ "padding.right",
16
+ "padding.bottom",
17
+ "padding.left"
18
+ ],
19
+ 0,
20
+ "spacing"
21
+ ],
22
+ [
23
+ "px",
24
+ ["padding.left", "padding.right"],
25
+ 1,
26
+ "spacing"
27
+ ],
28
+ [
29
+ "py",
30
+ ["padding.top", "padding.bottom"],
31
+ 1,
32
+ "spacing"
33
+ ],
34
+ [
35
+ "pt",
36
+ ["padding.top"],
37
+ 2,
38
+ "spacing"
39
+ ],
40
+ [
41
+ "pr",
42
+ ["padding.right"],
43
+ 2,
44
+ "spacing"
45
+ ],
46
+ [
47
+ "pe",
48
+ ["padding.right"],
49
+ 2,
50
+ "spacing"
51
+ ],
52
+ [
53
+ "pb",
54
+ ["padding.bottom"],
55
+ 2,
56
+ "spacing"
57
+ ],
58
+ [
59
+ "pl",
60
+ ["padding.left"],
61
+ 2,
62
+ "spacing"
63
+ ],
64
+ [
65
+ "ps",
66
+ ["padding.left"],
67
+ 2,
68
+ "spacing"
69
+ ],
70
+ [
71
+ "gap",
72
+ ["gap.row", "gap.column"],
73
+ 0,
74
+ "spacing"
75
+ ],
76
+ [
77
+ "gap-x",
78
+ ["gap.column"],
79
+ 1,
80
+ "spacing"
81
+ ],
82
+ [
83
+ "gap-y",
84
+ ["gap.row"],
85
+ 1,
86
+ "spacing"
87
+ ],
88
+ [
89
+ "rounded",
90
+ ["radius"],
91
+ 0,
92
+ "radius"
93
+ ]
94
+ ];
95
+ /** Splits `md:hover:px-4` into its variants and utility, ignoring colons inside `[...]` / `(...)`. */
96
+ function splitVariants(className) {
97
+ const parts = [];
98
+ let depth = 0;
99
+ let current = "";
100
+ for (const char of className) {
101
+ if (char === "[" || char === "(") depth++;
102
+ if (char === "]" || char === ")") depth--;
103
+ if (char === ":" && depth === 0) {
104
+ parts.push(current);
105
+ current = "";
106
+ } else current += char;
107
+ }
108
+ return {
109
+ variants: parts,
110
+ utility: current
111
+ };
112
+ }
113
+ /** Breakpoint weight when every variant is an active breakpoint; `undefined` for state variants or inactive breakpoints. */
114
+ function variantWeight(variants, viewportWidth, rootFontSize) {
115
+ let weight = 0;
116
+ for (const variant of variants) {
117
+ const max = variant.startsWith("max-");
118
+ const size = breakpoints[max ? variant.slice(4) : variant];
119
+ if (size === void 0) return void 0;
120
+ if (!(max ? viewportWidth < size * rootFontSize : viewportWidth >= size * rootFontSize)) return void 0;
121
+ weight = Math.max(weight, size);
122
+ }
123
+ return weight;
124
+ }
125
+ function tokenFor(value, namespace, isKnown) {
126
+ const referenced = value.match(/^\[.*?var\((--[\w-]+)/)?.[1] ?? value.match(/^\((--[\w-]+)\)$/)?.[1];
127
+ if (referenced) return isKnown(referenced) ? referenced : void 0;
128
+ const name = `--${namespace}-${value}`;
129
+ return isKnown(name) ? name : void 0;
130
+ }
131
+ /**
132
+ * Resolves which theme tokens drive an element's padding, gap and radius from its rendered Tailwind classes.
133
+ * Only tokens accepted by `isKnown` are returned, so every result can be opened in the editor.
134
+ */
135
+ function inspectTokens(className, isKnown, viewportWidth = Infinity, rootFontSize = 16) {
136
+ const winners = /* @__PURE__ */ new Map();
137
+ for (const raw of className.split(/\s+/).filter(Boolean)) {
138
+ const { variants, utility } = splitVariants(raw);
139
+ const weight = variantWeight(variants, viewportWidth, rootFontSize);
140
+ if (weight === void 0) continue;
141
+ const clean = utility.replace(/^!|!$/g, "");
142
+ for (const [prefix, slots, specificity, namespace] of utilities) {
143
+ if (!clean.startsWith(`${prefix}-`)) continue;
144
+ const token = tokenFor(clean.slice(prefix.length + 1), namespace, isKnown);
145
+ if (!token) continue;
146
+ const rank = weight * 10 + specificity;
147
+ for (const slot of slots) if ((winners.get(slot)?.rank ?? -1) <= rank) winners.set(slot, {
148
+ token,
149
+ rank
150
+ });
151
+ }
152
+ }
153
+ const result = {
154
+ padding: {},
155
+ gap: {}
156
+ };
157
+ for (const [slot, { token }] of winners) if (slot === "radius") result.radius = token;
158
+ else if (slot.startsWith("gap.")) result.gap[slot.slice(4)] = token;
159
+ else result.padding[slot.slice(8)] = token;
160
+ return result;
161
+ }
162
+ //#endregion
163
+ export { splitVariants as n, inspectTokens as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/ui",
3
- "version": "5.0.0-rc.6",
3
+ "version": "5.0.0-rc.7",
4
4
  "type": "module",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -62,7 +62,7 @@ The plugin uses Vite's development middleware and HTML hooks and is enabled only
62
62
 
63
63
  `parseThemeCss` reads the flat declaration blocks used by Atlas themes (`:root`, `.dark`, and `@theme` / `@theme static`). It excludes `@theme inline` declarations because their compiled literal values cannot be changed at runtime. It is not a general CSS parser. Supply `{ light, dark, theme }` maps directly for other theme structures. Use CSS variables in utilities you want to tune at runtime. Breakpoints, generated class names, and literal values compiled from `@theme inline` require rebuilding CSS; adjust their underlying variables instead. Edits are application-wide within the current document; mount only one configuration provider per document.
64
64
 
65
- The live preview lists every Povio UI component (`gallery/demos.tsx`). Click one to focus it, then hover to see the padding, gaps and radius that come from theme tokens; clicking a band opens that exact token in the editor. The inspector reads the rendered Tailwind classes (`inspector/token-classes.ts`), so it follows `UIOverrides` and responsive variants, and only offers tokens present in the supplied defaults. Dialog, popover, tooltip and dropdown demos are static replicas built from the components' own class definitions, because an open react-aria modal or popover would take focus away from the configurator.
65
+ Live Preview includes a docked inspector with independent scrolling. In **Inspect** mode, hover any element to see its computed styles and box model, click to pin it, and click the selected element again to unpin. **Interact** mode lets preview controls respond normally and lets gallery cards open their focused demos. The neutral box model shows per-side spacing and borders, corner radii, content dimensions, and row/column measurements inside the gutters of one gap sketch. Default and empty properties are omitted; recognized utility tokens link to the editor only when they match the computed value. Pinning retains selection while local component state and theme changes refresh the displayed values. Hover or focus a number in the box model to highlight its padding, margin, border, radius, content dimension or gap directly on the preview. Dialog, popover, tooltip and dropdown gallery demos use the components' class definitions to avoid taking focus away from the configurator.
66
66
 
67
67
  The **Advanced → Variants & overrides** sub-tab exposes the library's CVA slots by component. It resolves declarative app overrides before showing base classes, variant classes, default values, and compound-rule classes. Edits store a serializable snapshot of the effective slot using `overrideCva`; untouched slots and function mappers retain the inherited app configuration. Function-based CVA overrides are read-only. Reset slot restores the inherited definition. Apply, Cancel, Reset all, and host persistence cover CVA edits as well as tokens.
68
68