@motion-proto/live-tokens 0.20.0 → 0.20.1
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/dist-plugin/index.cjs +13 -3
- package/dist-plugin/index.js +13 -3
- package/package.json +1 -1
- package/src/editor/component-editor/scaffolding/ComponentFileManager.svelte +1 -7
- package/src/editor/component-editor/scaffolding/VariantGroup.svelte +4 -6
- package/src/editor/component-editor/scaffolding/linkedBlock.ts +4 -1
- package/src/editor/core/components/componentPersist.ts +1 -6
- package/src/editor/core/palettes/tokenRegistry.ts +2 -4
- package/src/editor/core/store/cssVarRef.ts +87 -0
- package/src/editor/core/store/editorStore.ts +2 -3
- package/src/editor/core/store/editorTypes.ts +5 -1
- package/src/editor/core/themes/parsers/colorOpacity.ts +41 -0
- package/src/editor/core/themes/slices/components.ts +2 -23
- package/src/editor/ui/UIPaletteSelector.svelte +7 -11
- package/src/editor/ui/UITokenSelector.svelte +7 -7
package/dist-plugin/index.cjs
CHANGED
|
@@ -52,6 +52,14 @@ function extractGlobalRootBody(source) {
|
|
|
52
52
|
return bodies.join("\n");
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
// src/editor/core/themes/parsers/colorOpacity.ts
|
|
56
|
+
var COLOR_OPACITY_RE = /^color-mix\(in srgb,\s*var\((--[a-z0-9-]+)\)\s+(\d+)%,\s*transparent\)$/i;
|
|
57
|
+
function parseColorOpacity(value) {
|
|
58
|
+
const m = value.trim().match(COLOR_OPACITY_RE);
|
|
59
|
+
if (!m) return null;
|
|
60
|
+
return { name: m[1], opacity: parseInt(m[2], 10) };
|
|
61
|
+
}
|
|
62
|
+
|
|
55
63
|
// src/editor/core/storage/files/versionedFileResourceClient.ts
|
|
56
64
|
function sanitizeFileName(name) {
|
|
57
65
|
return name.toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9\-_]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "") || "unnamed";
|
|
@@ -1013,11 +1021,13 @@ function themeFileApi(opts) {
|
|
|
1013
1021
|
}
|
|
1014
1022
|
function extractAliasDeclarations(body) {
|
|
1015
1023
|
const aliases = {};
|
|
1016
|
-
const re = /(--[a-z0-9-]+)\s*:\s*(
|
|
1024
|
+
const re = /(--[a-z0-9-]+)\s*:\s*([^;]+);/gi;
|
|
1017
1025
|
let m;
|
|
1018
1026
|
while ((m = re.exec(body)) !== null) {
|
|
1019
|
-
const
|
|
1020
|
-
|
|
1027
|
+
const value = m[2].trim();
|
|
1028
|
+
const plain = value.match(/^var\((--[a-z0-9-]+)\)$/i);
|
|
1029
|
+
if (plain) aliases[m[1]] = plain[1];
|
|
1030
|
+
else if (parseColorOpacity(value)) aliases[m[1]] = value;
|
|
1021
1031
|
}
|
|
1022
1032
|
return aliases;
|
|
1023
1033
|
}
|
package/dist-plugin/index.js
CHANGED
|
@@ -10,6 +10,14 @@ import {
|
|
|
10
10
|
import fs2 from "fs";
|
|
11
11
|
import path2 from "path";
|
|
12
12
|
|
|
13
|
+
// src/editor/core/themes/parsers/colorOpacity.ts
|
|
14
|
+
var COLOR_OPACITY_RE = /^color-mix\(in srgb,\s*var\((--[a-z0-9-]+)\)\s+(\d+)%,\s*transparent\)$/i;
|
|
15
|
+
function parseColorOpacity(value) {
|
|
16
|
+
const m = value.trim().match(COLOR_OPACITY_RE);
|
|
17
|
+
if (!m) return null;
|
|
18
|
+
return { name: m[1], opacity: parseInt(m[2], 10) };
|
|
19
|
+
}
|
|
20
|
+
|
|
13
21
|
// src/editor/core/storage/files/versionedFileResourceClient.ts
|
|
14
22
|
function sanitizeFileName(name) {
|
|
15
23
|
return name.toLowerCase().trim().replace(/\s+/g, "-").replace(/[^a-z0-9\-_]/g, "").replace(/-+/g, "-").replace(/^-|-$/g, "") || "unnamed";
|
|
@@ -753,11 +761,13 @@ function themeFileApi(opts) {
|
|
|
753
761
|
}
|
|
754
762
|
function extractAliasDeclarations(body) {
|
|
755
763
|
const aliases = {};
|
|
756
|
-
const re = /(--[a-z0-9-]+)\s*:\s*(
|
|
764
|
+
const re = /(--[a-z0-9-]+)\s*:\s*([^;]+);/gi;
|
|
757
765
|
let m;
|
|
758
766
|
while ((m = re.exec(body)) !== null) {
|
|
759
|
-
const
|
|
760
|
-
|
|
767
|
+
const value = m[2].trim();
|
|
768
|
+
const plain = value.match(/^var\((--[a-z0-9-]+)\)$/i);
|
|
769
|
+
if (plain) aliases[m[1]] = plain[1];
|
|
770
|
+
else if (parseColorOpacity(value)) aliases[m[1]] = value;
|
|
761
771
|
}
|
|
762
772
|
return aliases;
|
|
763
773
|
}
|
package/package.json
CHANGED
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
import { listManifests, saveAsManifest } from '../../core/manifests/manifestService';
|
|
27
27
|
import type { ManifestMeta } from '../../core/themes/themeTypes';
|
|
28
28
|
import { CURRENT_COMPONENT_SCHEMA_VERSION } from '../../core/themes/migrations';
|
|
29
|
-
import
|
|
29
|
+
import { refToDiskValue } from '../../core/store/cssVarRef';
|
|
30
30
|
import { safeFetch } from '../../core/storage/storage';
|
|
31
31
|
import { API_BASE } from '../../core/storage/apiBase';
|
|
32
32
|
import { flashStatus } from '../../core/flashStatus';
|
|
@@ -126,12 +126,6 @@
|
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
function refToDiskValue(ref: CssVarRef): AliasDiskValue {
|
|
130
|
-
if (ref.kind === 'token') return ref.name;
|
|
131
|
-
if (ref.kind === 'literal') return ref.value;
|
|
132
|
-
return { kind: 'gradient', value: ref.value };
|
|
133
|
-
}
|
|
134
|
-
|
|
135
129
|
function currentAliases(): Record<string, AliasDiskValue> {
|
|
136
130
|
const slice = get(editorState).components[component];
|
|
137
131
|
if (!slice) return {};
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { mutate } from '../../core/store/editorStore';
|
|
10
10
|
import { getDeclaredValue } from '../../core/palettes/tokenRegistry';
|
|
11
11
|
import type { CssVarRef } from '../../core/store/editorTypes';
|
|
12
|
+
import { cssStringToRef, refToCss } from '../../core/store/cssVarRef';
|
|
12
13
|
import { getEditorContext } from './editorContext';
|
|
13
14
|
import type { Token, TypeGroupConfig } from './types';
|
|
14
15
|
import type { Sibling } from './siblings';
|
|
@@ -112,9 +113,7 @@
|
|
|
112
113
|
instead of falling back to its own family's default. */
|
|
113
114
|
function declaredToRef(declared: string | null): CssVarRef | null {
|
|
114
115
|
if (!declared) return null;
|
|
115
|
-
|
|
116
|
-
if (m) return { kind: 'token', name: m[1] };
|
|
117
|
-
return { kind: 'literal', value: declared };
|
|
116
|
+
return cssStringToRef(declared.trim());
|
|
118
117
|
}
|
|
119
118
|
|
|
120
119
|
/** Extract a transparency percentage from a `color-mix(in srgb, var(--X) N%, transparent)`
|
|
@@ -179,9 +178,8 @@
|
|
|
179
178
|
const effectiveValue = (varName: string): string | null => {
|
|
180
179
|
const ref = slice.aliases[varName];
|
|
181
180
|
if (!ref) return getDeclaredValue(varName);
|
|
182
|
-
if (ref.kind === '
|
|
183
|
-
|
|
184
|
-
return null;
|
|
181
|
+
if (ref.kind === 'gradient') return null;
|
|
182
|
+
return refToCss(ref);
|
|
185
183
|
};
|
|
186
184
|
|
|
187
185
|
const apply = (srcVar: string, dstVar: string) => {
|
|
@@ -5,11 +5,14 @@ import {
|
|
|
5
5
|
editorState,
|
|
6
6
|
} from '../../core/store/editorStore';
|
|
7
7
|
import type { CssVarRef } from '../../core/store/editorTypes';
|
|
8
|
+
import { refToCss } from '../../core/store/cssVarRef';
|
|
8
9
|
import type { Token } from './types';
|
|
9
10
|
|
|
11
|
+
/** Stable per-ref identity key: refs that render to the same CSS share a key,
|
|
12
|
+
* so siblings with equal values bucket together regardless of ref kind. */
|
|
10
13
|
function aliasKey(ref: CssVarRef | undefined): string {
|
|
11
14
|
if (!ref) return '';
|
|
12
|
-
return ref
|
|
15
|
+
return refToCss(ref);
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
const TYPOGRAPHY_PROP_SUFFIXES = ['font-family', 'font-size', 'font-weight', 'line-height'] as const;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { get } from 'svelte/store';
|
|
2
2
|
import type { AliasDiskValue, ComponentConfig } from '../themes/themeTypes';
|
|
3
3
|
import { editorState, markComponentSaved } from '../store/editorStore';
|
|
4
|
-
import
|
|
4
|
+
import { refToDiskValue } from '../store/cssVarRef';
|
|
5
5
|
import { CURRENT_COMPONENT_SCHEMA_VERSION } from '../themes/migrations';
|
|
6
6
|
import {
|
|
7
7
|
listComponentConfigs,
|
|
@@ -24,11 +24,6 @@ export type SaveActiveComponentResult =
|
|
|
24
24
|
| { ok: true; fileName: string; displayName: string }
|
|
25
25
|
| { ok: false; reason: 'default' | 'no-state' | 'error'; error?: unknown };
|
|
26
26
|
|
|
27
|
-
function refToDiskValue(ref: CssVarRef): AliasDiskValue {
|
|
28
|
-
if (ref.kind === 'token') return ref.name;
|
|
29
|
-
if (ref.kind === 'literal') return ref.value;
|
|
30
|
-
return { kind: 'gradient', value: ref.value };
|
|
31
|
-
}
|
|
32
27
|
|
|
33
28
|
export async function saveActiveComponentConfig(
|
|
34
29
|
component: string,
|
|
@@ -23,7 +23,7 @@ import tokensCss from '../../../system/styles/tokens.css?raw';
|
|
|
23
23
|
import { editorState } from '../store/editorStore';
|
|
24
24
|
import type { EditorState } from '../store/editorTypes';
|
|
25
25
|
import { extractGlobalRootBody } from '../themes/parsers/globalRootBlock';
|
|
26
|
-
import {
|
|
26
|
+
import { refToCss } from '../store/cssVarRef';
|
|
27
27
|
|
|
28
28
|
// Re-exported for tests and downstream consumers that previously imported it
|
|
29
29
|
// from this module. The canonical implementation lives in `./parsers/globalRootBlock`
|
|
@@ -112,9 +112,7 @@ function buildOverlayRegistry(
|
|
|
112
112
|
const overrides = new Map<string, string>();
|
|
113
113
|
for (const slice of Object.values(components)) {
|
|
114
114
|
for (const [varName, ref] of Object.entries(slice.aliases)) {
|
|
115
|
-
|
|
116
|
-
else if (ref.kind === 'literal') overrides.set(varName, ref.value);
|
|
117
|
-
else overrides.set(varName, formatGradientValue(ref.value));
|
|
115
|
+
overrides.set(varName, refToCss(ref));
|
|
118
116
|
}
|
|
119
117
|
}
|
|
120
118
|
const getDeclared = (v: string): string | null =>
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single classifier + renderer for `CssVarRef`. Every place that turns a
|
|
3
|
+
* CSS value string into a ref, or a ref back into CSS, routes through here so
|
|
4
|
+
* the three ref kinds (`token`, `literal`, `gradient`) are interpreted
|
|
5
|
+
* identically across the disk loader, the live-edit path, the registry, and the
|
|
6
|
+
* component renderer.
|
|
7
|
+
*
|
|
8
|
+
* A `token` may carry an optional `opacity` (a colour below 100%). Opacity
|
|
9
|
+
* serialization is delegated to `parsers/colorOpacity`, the one place that knows
|
|
10
|
+
* the `color-mix(in srgb, var(--token) NN%, transparent)` shape.
|
|
11
|
+
*/
|
|
12
|
+
import type { CssVarRef } from './editorTypes';
|
|
13
|
+
import type { AliasDiskValue } from '../themes/themeTypes';
|
|
14
|
+
import { formatGradientValue } from '../themes/slices/gradients';
|
|
15
|
+
import { formatColorOpacity, parseColorOpacity } from '../themes/parsers/colorOpacity';
|
|
16
|
+
|
|
17
|
+
/** True when a token carries a non-trivial opacity (a colour below 100%). */
|
|
18
|
+
function hasOpacity(opacity: number | undefined): opacity is number {
|
|
19
|
+
return opacity != null && opacity < 100;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Render a ref to the CSS value string written to a custom property. */
|
|
23
|
+
export function refToCss(ref: CssVarRef): string {
|
|
24
|
+
switch (ref.kind) {
|
|
25
|
+
case 'token':
|
|
26
|
+
return hasOpacity(ref.opacity) ? formatColorOpacity(ref.name, ref.opacity) : `var(${ref.name})`;
|
|
27
|
+
case 'literal':
|
|
28
|
+
return ref.value;
|
|
29
|
+
case 'gradient':
|
|
30
|
+
return formatGradientValue(ref.value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Classify a CSS value string into a ref. Accepts a bare token name (`--x`,
|
|
36
|
+
* the disk convention), a wrapped alias (`var(--x)`, the declared-value form),
|
|
37
|
+
* a colour-opacity expression, or anything else (a raw literal). Never produces
|
|
38
|
+
* a gradient — gradients are stored as structured objects, not strings.
|
|
39
|
+
*/
|
|
40
|
+
export function cssStringToRef(value: string): CssVarRef {
|
|
41
|
+
const op = parseColorOpacity(value);
|
|
42
|
+
if (op) return { kind: 'token', name: op.name, opacity: op.opacity };
|
|
43
|
+
if (value.startsWith('--')) return { kind: 'token', name: value };
|
|
44
|
+
const wrapped = value.match(/^var\((--[a-z0-9-]+)\)$/);
|
|
45
|
+
if (wrapped) return { kind: 'token', name: wrapped[1] };
|
|
46
|
+
return { kind: 'literal', value };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Serialize a ref to its on-disk `AliasDiskValue`. Mirrors `refToCss` except a
|
|
51
|
+
* token is stored as its bare name (`--x`, not `var(--x)`) — the editor's disk
|
|
52
|
+
* convention — and a gradient is a structured object rather than a CSS string.
|
|
53
|
+
*/
|
|
54
|
+
export function refToDiskValue(ref: CssVarRef): AliasDiskValue {
|
|
55
|
+
switch (ref.kind) {
|
|
56
|
+
case 'token':
|
|
57
|
+
return hasOpacity(ref.opacity) ? formatColorOpacity(ref.name, ref.opacity) : ref.name;
|
|
58
|
+
case 'literal':
|
|
59
|
+
return ref.value;
|
|
60
|
+
case 'gradient':
|
|
61
|
+
return { kind: 'gradient', value: ref.value };
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Structural equality across all ref kinds. */
|
|
66
|
+
export function cssVarRefEqual(a: CssVarRef | undefined, b: CssVarRef | undefined): boolean {
|
|
67
|
+
if (!a || !b) return a === b;
|
|
68
|
+
if (a.kind !== b.kind) return false;
|
|
69
|
+
if (a.kind === 'token') {
|
|
70
|
+
const bt = b as { kind: 'token'; name: string; opacity?: number };
|
|
71
|
+
return a.name === bt.name && (a.opacity ?? 100) === (bt.opacity ?? 100);
|
|
72
|
+
}
|
|
73
|
+
if (a.kind === 'literal') return a.value === (b as { kind: 'literal'; value: string }).value;
|
|
74
|
+
const av = a.value;
|
|
75
|
+
const bv = (b as { kind: 'gradient'; value: typeof a.value }).value;
|
|
76
|
+
if (av.type !== bv.type || av.angle !== bv.angle || av.stops.length !== bv.stops.length) return false;
|
|
77
|
+
if ((av.aspectX ?? 1) !== (bv.aspectX ?? 1)) return false;
|
|
78
|
+
if ((av.aspectY ?? 1) !== (bv.aspectY ?? 1)) return false;
|
|
79
|
+
for (let i = 0; i < av.stops.length; i++) {
|
|
80
|
+
const sa = av.stops[i];
|
|
81
|
+
const sb = bv.stops[i];
|
|
82
|
+
if (sa.position !== sb.position || sa.color !== sb.color || (sa.opacity ?? 100) !== (sb.opacity ?? 100)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
import type { CssVarRef, EditorState, GradientAliasValue } from './editorTypes';
|
|
22
22
|
import type { AliasDiskValue, Theme } from '../themes/themeTypes';
|
|
23
23
|
import { KNOWN_COMPONENT_CONFIG_KEYS } from '../components/componentConfigKeys';
|
|
24
|
+
import { cssStringToRef } from './cssVarRef';
|
|
24
25
|
import {
|
|
25
26
|
CURRENT_THEME_SCHEMA_VERSION,
|
|
26
27
|
CURRENT_COMPONENT_SCHEMA_VERSION,
|
|
@@ -421,9 +422,7 @@ function splitAliasesAndConfig(
|
|
|
421
422
|
if (config[key] === undefined) config[key] = value;
|
|
422
423
|
continue;
|
|
423
424
|
}
|
|
424
|
-
aliases[key] = value
|
|
425
|
-
? { kind: 'token', name: value }
|
|
426
|
-
: { kind: 'literal', value };
|
|
425
|
+
aliases[key] = cssStringToRef(value);
|
|
427
426
|
}
|
|
428
427
|
return { aliases, config };
|
|
429
428
|
}
|
|
@@ -100,7 +100,11 @@ export interface GradientAliasValue {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
export type CssVarRef =
|
|
103
|
-
|
|
103
|
+
/** An alias to a design token. `opacity` is an optional integer percent set
|
|
104
|
+
* only for a colour carried below 100% (serializes to
|
|
105
|
+
* `color-mix(in srgb, var(name) opacity%, transparent)`); absent means fully
|
|
106
|
+
* opaque, which also covers every non-colour alias (radius, spacing, font). */
|
|
107
|
+
| { kind: 'token'; name: string; opacity?: number }
|
|
104
108
|
| { kind: 'literal'; value: string }
|
|
105
109
|
| { kind: 'gradient'; value: GradientAliasValue };
|
|
106
110
|
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The single source of truth for a design-token colour carried at reduced
|
|
3
|
+
* opacity. A colour token below 100% opacity serializes as:
|
|
4
|
+
*
|
|
5
|
+
* color-mix(in srgb, var(--token) NN%, transparent)
|
|
6
|
+
*
|
|
7
|
+
* 100% opacity is NOT represented here — a fully opaque colour collapses to a
|
|
8
|
+
* plain `var(--token)` alias (`CssVarRef` kind `'token'`). Everything that
|
|
9
|
+
* reads, writes, or validates this form must go through `parseColorOpacity` /
|
|
10
|
+
* `formatColorOpacity` so the canonical shape lives in exactly one place.
|
|
11
|
+
*
|
|
12
|
+
* This module is intentionally dependency-free so the dev-server vite plugin
|
|
13
|
+
* (a separate build) can import it the same way it imports `globalRootBlock`.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** `opacity` is an integer percentage in [0, 100). */
|
|
17
|
+
export interface ColorOpacity {
|
|
18
|
+
/** The design-token name, e.g. `--surface-neutral-lower`. */
|
|
19
|
+
name: string;
|
|
20
|
+
/** Integer percentage, 0–99 (100 is not an opacity colour — it's a token). */
|
|
21
|
+
opacity: number;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const COLOR_OPACITY_RE =
|
|
25
|
+
/^color-mix\(in srgb,\s*var\((--[a-z0-9-]+)\)\s+(\d+)%,\s*transparent\)$/i;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Parse a `color-mix(in srgb, var(--token) NN%, transparent)` string into its
|
|
29
|
+
* token name and integer opacity. Returns null for any other value (plain
|
|
30
|
+
* aliases, raw literals, gradients).
|
|
31
|
+
*/
|
|
32
|
+
export function parseColorOpacity(value: string): ColorOpacity | null {
|
|
33
|
+
const m = value.trim().match(COLOR_OPACITY_RE);
|
|
34
|
+
if (!m) return null;
|
|
35
|
+
return { name: m[1], opacity: parseInt(m[2], 10) };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Serialize a token + integer opacity back to the canonical color-mix string. */
|
|
39
|
+
export function formatColorOpacity(name: string, opacity: number): string {
|
|
40
|
+
return `color-mix(in srgb, var(${name}) ${opacity}%, transparent)`;
|
|
41
|
+
}
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
import { writable, derived, get, type Readable } from 'svelte/store';
|
|
33
33
|
import type { CssVarRef, EditorState } from '../../store/editorTypes';
|
|
34
34
|
import { store, mutate } from '../../store/editorCore';
|
|
35
|
-
import {
|
|
35
|
+
import { refToCss, cssVarRefEqual } from '../../store/cssVarRef';
|
|
36
36
|
import { CASCADING_COMPONENT_CONFIG_KEYS } from '../../components/componentConfigKeys';
|
|
37
37
|
|
|
38
38
|
const EMPTY_COMPONENT_BASELINE = JSON.stringify({ aliases: {}, config: {} });
|
|
@@ -45,9 +45,7 @@ export function componentsToVars(components: EditorState['components']): Record<
|
|
|
45
45
|
const out: Record<string, string> = {};
|
|
46
46
|
for (const slice of Object.values(components)) {
|
|
47
47
|
for (const [varName, ref] of Object.entries(slice.aliases)) {
|
|
48
|
-
|
|
49
|
-
else if (ref.kind === 'literal') out[varName] = ref.value;
|
|
50
|
-
else out[varName] = formatGradientValue(ref.value);
|
|
48
|
+
out[varName] = refToCss(ref);
|
|
51
49
|
}
|
|
52
50
|
for (const [key, value] of Object.entries(slice.config)) {
|
|
53
51
|
if (CASCADING_COMPONENT_CONFIG_KEYS.has(key) && typeof value === 'string') {
|
|
@@ -248,25 +246,6 @@ export function getComponentPropertySiblings(component: string, varName: string)
|
|
|
248
246
|
return siblings;
|
|
249
247
|
}
|
|
250
248
|
|
|
251
|
-
function cssVarRefEqual(a: CssVarRef | undefined, b: CssVarRef | undefined): boolean {
|
|
252
|
-
if (!a || !b) return a === b;
|
|
253
|
-
if (a.kind !== b.kind) return false;
|
|
254
|
-
if (a.kind === 'token') return a.name === (b as { kind: 'token'; name: string }).name;
|
|
255
|
-
if (a.kind === 'literal') return a.value === (b as { kind: 'literal'; value: string }).value;
|
|
256
|
-
// gradient: structural compare on type, angle, aspect axes, and stops.
|
|
257
|
-
const av = a.value;
|
|
258
|
-
const bv = (b as { kind: 'gradient'; value: typeof a.value }).value;
|
|
259
|
-
if (av.type !== bv.type || av.angle !== bv.angle || av.stops.length !== bv.stops.length) return false;
|
|
260
|
-
if ((av.aspectX ?? 1) !== (bv.aspectX ?? 1)) return false;
|
|
261
|
-
if ((av.aspectY ?? 1) !== (bv.aspectY ?? 1)) return false;
|
|
262
|
-
for (let i = 0; i < av.stops.length; i++) {
|
|
263
|
-
const sa = av.stops[i];
|
|
264
|
-
const sb = bv.stops[i];
|
|
265
|
-
if (sa.position !== sb.position || sa.color !== sb.color || (sa.opacity ?? 100) !== (sb.opacity ?? 100)) return false;
|
|
266
|
-
}
|
|
267
|
-
return true;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
249
|
/** True iff `varName` is not individually opted out, has ≥2 declared siblings,
|
|
271
250
|
* and the linked siblings agree — either all sharing the same explicit alias,
|
|
272
251
|
* or all having no override (linked at the upstream default). */
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { resolveAliasChain } from '../core/palettes/tokenRegistry';
|
|
7
7
|
import { editorState } from '../core/store/editorStore';
|
|
8
8
|
import { formatGradientStops } from '../core/themes/slices/gradients';
|
|
9
|
+
import { formatColorOpacity, parseColorOpacity } from '../core/themes/parsers/colorOpacity';
|
|
9
10
|
import type { GradientToken } from '../core/store/editorTypes';
|
|
10
11
|
import UITokenSelector from './UITokenSelector.svelte';
|
|
11
12
|
|
|
@@ -249,24 +250,19 @@
|
|
|
249
250
|
return null;
|
|
250
251
|
}
|
|
251
252
|
|
|
252
|
-
function parseOpacity(raw: string): { inner: string; opacity: number } | null {
|
|
253
|
-
const m = raw.match(/^color-mix\(in srgb,\s*(var\(--[a-z0-9-]+\))\s+(\d+)%,\s*transparent\)$/);
|
|
254
|
-
if (!m) return null;
|
|
255
|
-
return { inner: m[1], opacity: parseInt(m[2]) };
|
|
256
|
-
}
|
|
257
|
-
|
|
258
253
|
function parseStatic(raw: string): { name: 'white' | 'black'; opacity: number } | null {
|
|
259
254
|
const direct = raw.match(/^var\(--color-(white|black)\)$/);
|
|
260
255
|
if (direct) return { name: direct[1] as 'white' | 'black', opacity: 100 };
|
|
261
|
-
const
|
|
262
|
-
|
|
256
|
+
const op = parseColorOpacity(raw);
|
|
257
|
+
const m = op?.name.match(/^--color-(white|black)$/);
|
|
258
|
+
if (op && m) return { name: m[1] as 'white' | 'black', opacity: op.opacity };
|
|
263
259
|
return null;
|
|
264
260
|
}
|
|
265
261
|
|
|
266
262
|
function buildValue(varName: string): string | null {
|
|
267
263
|
if (varName === variable && opacity >= 100) return null;
|
|
268
264
|
if (opacity >= 100) return varName;
|
|
269
|
-
return
|
|
265
|
+
return formatColorOpacity(varName, opacity);
|
|
270
266
|
}
|
|
271
267
|
|
|
272
268
|
function applyOpacity() {
|
|
@@ -399,9 +395,9 @@
|
|
|
399
395
|
}
|
|
400
396
|
chosenStatic = null;
|
|
401
397
|
|
|
402
|
-
const opacityParsed =
|
|
398
|
+
const opacityParsed = parseColorOpacity(raw);
|
|
403
399
|
if (opacityParsed) {
|
|
404
|
-
const parsed = parseRef(opacityParsed.
|
|
400
|
+
const parsed = parseRef(`var(${opacityParsed.name})`);
|
|
405
401
|
if (parsed) {
|
|
406
402
|
chosenCategory = parsed.category;
|
|
407
403
|
chosenFamily = parsed.family;
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import type { Snippet } from 'svelte';
|
|
4
4
|
import { setCssVar, removeCssVar, CSS_VAR_CHANGE_EVENT } from '../core/cssVarSync';
|
|
5
5
|
import type { CssVarRef } from '../core/store/editorTypes';
|
|
6
|
+
import { cssStringToRef } from '../core/store/cssVarRef';
|
|
6
7
|
import {
|
|
7
8
|
editorState,
|
|
8
9
|
setComponentAlias,
|
|
@@ -116,14 +117,13 @@
|
|
|
116
117
|
if (component) {
|
|
117
118
|
const useLinked = isLinkedDisplay;
|
|
118
119
|
if (semanticName) {
|
|
119
|
-
//
|
|
120
|
-
// (rendered as `var(name)`);
|
|
121
|
-
// `
|
|
122
|
-
//
|
|
120
|
+
// Same classifier as the disk loader (cssStringToRef): a `--…`
|
|
121
|
+
// reference becomes a token (rendered as `var(name)`); a
|
|
122
|
+
// `color-mix(... var(--token) NN%, transparent)` becomes a colour ref;
|
|
123
|
+
// anything else (`transparent`, a materialized gradient) is a literal
|
|
124
|
+
// emitted as-is. Storing complex CSS as a token would render
|
|
123
125
|
// `var(color-mix(...))`, which is invalid and breaks the preview.
|
|
124
|
-
const ref: CssVarRef = semanticName
|
|
125
|
-
? { kind: 'token', name: semanticName }
|
|
126
|
-
: { kind: 'literal', value: semanticName };
|
|
126
|
+
const ref: CssVarRef = cssStringToRef(semanticName);
|
|
127
127
|
if (useLinked) setComponentAliasLinked(component, variable, ref);
|
|
128
128
|
else setComponentAlias(component, variable, ref);
|
|
129
129
|
} else {
|