@link-foundation/ui-themes 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/LICENSE +24 -0
- package/README.md +121 -2
- package/package.json +52 -4
- package/src/classic/catalog.js +193 -0
- package/src/classic/effect-governor.js +199 -0
- package/src/classic/effect-quality.js +76 -0
- package/src/classic/frame-color.js +27 -0
- package/src/classic/frame-css-controls.js +65 -0
- package/src/classic/frame-css-corners.js +138 -0
- package/src/classic/frame-css-edge-geometry.js +74 -0
- package/src/classic/frame-css-edges.js +99 -0
- package/src/classic/frame-css-enums.js +65 -0
- package/src/classic/frame-css-geometry.js +133 -0
- package/src/classic/frame-css-modes.js +45 -0
- package/src/classic/frame-css-states.js +85 -0
- package/src/classic/frame-css-values.js +156 -0
- package/src/classic/frame-css.js +232 -0
- package/src/classic/frame-geometry.js +189 -0
- package/src/classic/frame-schema.js +328 -0
- package/src/classic/frame-vocabulary.js +10 -0
- package/src/classic/frames.d.ts +143 -0
- package/src/classic/frames.js +77 -0
- package/src/classic/material-visibility.js +94 -0
- package/src/classic/materials.d.ts +133 -0
- package/src/classic/materials.js +139 -0
- package/src/classic/optical-css.js +47 -0
- package/src/classic/optics.js +107 -0
- package/src/classic/refraction.js +145 -0
- package/src/fluent2/brand-aliases.js +157 -0
- package/src/fluent2/brand.js +84 -0
- package/src/fluent2/names.js +31 -0
- package/src/index.d.ts +54 -0
- package/src/index.js +79 -0
- package/src/mapping.js +135 -0
- package/src/material3/mapping.js +18 -0
- package/src/material3/mui.js +128 -0
- package/src/material3/seed.js +144 -0
- package/themes/base/theme.lino +35 -0
- package/themes/classic/README.md +90 -0
- package/themes/classic/deepcase/2025.lino +156 -0
- package/themes/classic/deepcase/classic.lino +86 -0
- package/themes/classic/deepcase/dark.lino +87 -0
- package/themes/classic/deepcase/deepcase-0.1.lino +63 -0
- package/themes/classic/deepcase/handler-windows.lino +22 -0
- package/themes/classic/deepcase/landing.lino +60 -0
- package/themes/classic/deepcase/perception.lino +88 -0
- package/themes/classic/formal-ai/chat-bubbles.lino +40 -0
- package/themes/classic/formal-ai/chat-cards.lino +40 -0
- package/themes/classic/formal-ai/chat-compact.lino +40 -0
- package/themes/classic/formal-ai/composer.lino +132 -0
- package/themes/classic/formal-ai/fa-contrast.lino +79 -0
- package/themes/classic/formal-ai/fa-flat.lino +79 -0
- package/themes/classic/formal-ai/fa-glass.lino +79 -0
- package/themes/classic/formal-ai/fa-material.lino +79 -0
- package/themes/classic/immortality/arwes.lino +59 -0
- package/themes/classic/immortality/palettes.lino +968 -0
- package/themes/classic/immortality/poseidon.lino +59 -0
- package/themes/classic/immortality/quiet.lino +59 -0
- package/themes/classic/konard/futuristic.lino +89 -0
- package/themes/classic/konard/glass.lino +89 -0
- package/themes/classic/konard/liquid.lino +89 -0
- package/themes/classic/meta-sovereign/chat-signal.lino +68 -0
- package/themes/classic/meta-sovereign/chat-t3.lino +68 -0
- package/themes/classic/meta-sovereign/chat-telegram.lino +74 -0
- package/themes/classic/meta-sovereign/chat-whatsapp.lino +68 -0
- package/themes/fluent2/LICENSE.txt +15 -0
- package/themes/fluent2/brand-aliases.lino +101 -0
- package/themes/fluent2/colors-dark.lino +1124 -0
- package/themes/fluent2/colors-high-contrast.lino +1109 -0
- package/themes/fluent2/colors.lino +1489 -0
- package/themes/fluent2/fluent-mapping.lino +120 -0
- package/themes/fluent2/motion-dark.lino +62 -0
- package/themes/fluent2/motion-high-contrast.lino +62 -0
- package/themes/fluent2/motion.lino +70 -0
- package/themes/fluent2/shadow-dark.lino +50 -0
- package/themes/fluent2/shadow-high-contrast.lino +50 -0
- package/themes/fluent2/shadow.lino +49 -0
- package/themes/fluent2/shape-dark.lino +47 -0
- package/themes/fluent2/shape-high-contrast.lino +47 -0
- package/themes/fluent2/shape.lino +46 -0
- package/themes/fluent2/spacing-dark.lino +68 -0
- package/themes/fluent2/spacing-high-contrast.lino +68 -0
- package/themes/fluent2/spacing.lino +67 -0
- package/themes/fluent2/styles.lino +511 -0
- package/themes/fluent2/templates.lino +60 -0
- package/themes/fluent2/theme.lino +31 -0
- package/themes/fluent2/type-dark.lino +83 -0
- package/themes/fluent2/type-high-contrast.lino +83 -0
- package/themes/fluent2/type.lino +82 -0
- package/themes/hig/colors.lino +54 -0
- package/themes/hig/materials.lino +7 -0
- package/themes/hig/motion.lino +13 -0
- package/themes/hig/shape.lino +5 -0
- package/themes/hig/spacing.lino +11 -0
- package/themes/hig/styles.lino +143 -0
- package/themes/hig/swiftui-mapping.lino +80 -0
- package/themes/hig/templates.lino +36 -0
- package/themes/hig/theme.lino +3 -0
- package/themes/hig/type.lino +26 -0
- package/themes/hig-ios/theme.lino +5 -0
- package/themes/hig-macos/theme.lino +5 -0
- package/themes/material3/colors.lino +320 -0
- package/themes/material3/elevation.lino +110 -0
- package/themes/material3/motion.lino +102 -0
- package/themes/material3/mui-mapping.lino +216 -0
- package/themes/material3/shape.lino +16 -0
- package/themes/material3/styles.lino +498 -0
- package/themes/material3/templates.lino +55 -0
- package/themes/material3/theme.lino +7 -0
- package/themes/material3/type.lino +336 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { values } from '@link-foundation/ui-core';
|
|
2
|
+
|
|
3
|
+
export function colorCss(text) {
|
|
4
|
+
const parts = text.split(' at ');
|
|
5
|
+
if (parts.length > 2) {
|
|
6
|
+
throw new TypeError(`Invalid frame color: ${text}`);
|
|
7
|
+
}
|
|
8
|
+
const [color, alpha] = parts;
|
|
9
|
+
let css;
|
|
10
|
+
if (
|
|
11
|
+
['currentColor', 'transparent'].includes(color) ||
|
|
12
|
+
values.typeValue(color, { type: 'color' }).value
|
|
13
|
+
) {
|
|
14
|
+
css = color;
|
|
15
|
+
} else if (/^[a-zA-Z][\w.-]*$/u.test(color)) {
|
|
16
|
+
css = `var(--color-${color.replaceAll('.', '-')}, currentColor)`;
|
|
17
|
+
} else {
|
|
18
|
+
throw new TypeError(`Invalid frame color: ${text}`);
|
|
19
|
+
}
|
|
20
|
+
if (alpha === undefined) {
|
|
21
|
+
return css;
|
|
22
|
+
}
|
|
23
|
+
if (!/^(?:100|\d{1,2}(?:\.\d+)?)%$/u.test(alpha)) {
|
|
24
|
+
throw new TypeError(`Invalid frame alpha: ${text}`);
|
|
25
|
+
}
|
|
26
|
+
return `color-mix(in srgb, ${css} ${alpha}, transparent)`;
|
|
27
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { enumRules } from './frame-css-enums.js';
|
|
2
|
+
|
|
3
|
+
export function createCssContext(frames, options) {
|
|
4
|
+
const ctx = {
|
|
5
|
+
frames,
|
|
6
|
+
...options,
|
|
7
|
+
registrations: new Map(),
|
|
8
|
+
controls: new Map(),
|
|
9
|
+
unresolvedColors: new Set(),
|
|
10
|
+
enumCss: '',
|
|
11
|
+
enumerations: [],
|
|
12
|
+
prop(level, key) {
|
|
13
|
+
return `--${ctx.prefix}-${level}-${key}`;
|
|
14
|
+
},
|
|
15
|
+
variable(level, key) {
|
|
16
|
+
return `var(${ctx.prop(level, key)})`;
|
|
17
|
+
},
|
|
18
|
+
register(name, syntax = '<length>', initial = '0px', inherits = true) {
|
|
19
|
+
ctx.registrations.set(name, { syntax, initial, inherits });
|
|
20
|
+
},
|
|
21
|
+
set(
|
|
22
|
+
level,
|
|
23
|
+
key,
|
|
24
|
+
value,
|
|
25
|
+
syntax = '<length>',
|
|
26
|
+
initial = '0px',
|
|
27
|
+
inherits = true
|
|
28
|
+
) {
|
|
29
|
+
const property = ctx.prop(level, key);
|
|
30
|
+
ctx.register(property, syntax, initial, inherits);
|
|
31
|
+
ctx.controls.set(property, { level, property, syntax, inherits });
|
|
32
|
+
return [property, String(value)];
|
|
33
|
+
},
|
|
34
|
+
color(level, key, value) {
|
|
35
|
+
const result = ctx.set(level, key, value, '<color>', 'black');
|
|
36
|
+
// currentColor depends on the drawing element. Keep its input unresolved;
|
|
37
|
+
// the non-inheriting geometry alias provides the typed final color.
|
|
38
|
+
const name = ctx.prop(level, key);
|
|
39
|
+
if (value.includes('currentColor')) {
|
|
40
|
+
ctx.unresolvedColors.add(name);
|
|
41
|
+
}
|
|
42
|
+
if (ctx.unresolvedColors.has(name)) {
|
|
43
|
+
ctx.registrations.delete(name);
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
},
|
|
47
|
+
enumeration(level, key, choices, declarations) {
|
|
48
|
+
const attribute = `data-${ctx.prefix}-${level}-${key}`;
|
|
49
|
+
ctx.controls.set(attribute, { level, attribute, choices });
|
|
50
|
+
ctx.enumerations.push({ level, key, choices, declarations });
|
|
51
|
+
},
|
|
52
|
+
renderEnums() {
|
|
53
|
+
ctx.enumCss += enumRules(ctx);
|
|
54
|
+
},
|
|
55
|
+
properties() {
|
|
56
|
+
return [...ctx.registrations]
|
|
57
|
+
.map(
|
|
58
|
+
([name, { syntax, initial, inherits }]) =>
|
|
59
|
+
`@property ${name} {\n syntax: "${syntax}";\n inherits: ${inherits};\n initial-value: ${initial};\n}\n`
|
|
60
|
+
)
|
|
61
|
+
.join('');
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
return ctx;
|
|
65
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { corners, lines } from './frame-vocabulary.js';
|
|
2
|
+
import { FRAME_CORNERS, FRAME_EDGES } from './frame-schema.js';
|
|
3
|
+
import { IDS, shapePoints } from './frame-css-geometry.js';
|
|
4
|
+
import { colorCss } from './frame-color.js';
|
|
5
|
+
|
|
6
|
+
export function cornerShape(ctx, level, id, shape) {
|
|
7
|
+
const p = (key) => ctx.prop(level, `${id}-${key}`);
|
|
8
|
+
return [
|
|
9
|
+
[p('wf'), shape === 'tall' ? 0.5 : 1],
|
|
10
|
+
[p('hf'), shape === 'wide' ? 0.5 : 1],
|
|
11
|
+
...shapePoints(shape).flatMap(([x, y], i) => [
|
|
12
|
+
[p(`x${i}`), x],
|
|
13
|
+
[p(`y${i}`), y],
|
|
14
|
+
]),
|
|
15
|
+
];
|
|
16
|
+
}
|
|
17
|
+
export function cornerLine(ctx, level, id, line) {
|
|
18
|
+
const p = (key) => ctx.prop(level, `${id}-${key}`);
|
|
19
|
+
const v = (key) => ctx.variable(level, key);
|
|
20
|
+
return [
|
|
21
|
+
[p('visible'), ['none', 'gap'].includes(line) ? 0 : 1],
|
|
22
|
+
[p('gap'), line === 'gap' ? v(`${id}-arm`) : '0px'],
|
|
23
|
+
[p('extension'), line === 'bracket' ? v(`${id}-arm`) : '0px'],
|
|
24
|
+
[
|
|
25
|
+
p('paint'),
|
|
26
|
+
v(
|
|
27
|
+
line === 'line'
|
|
28
|
+
? `${FRAME_EDGES[IDS.indexOf(id)]}-color`
|
|
29
|
+
: `${id}-color`
|
|
30
|
+
),
|
|
31
|
+
],
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
function automaticStroke(frames, level, name) {
|
|
35
|
+
const definition = frames.get(level);
|
|
36
|
+
const stroke = definition.corners[name]?.stroke;
|
|
37
|
+
if (stroke !== undefined) {
|
|
38
|
+
return stroke === 'auto';
|
|
39
|
+
}
|
|
40
|
+
return definition.extends
|
|
41
|
+
? automaticStroke(frames, definition.extends, name)
|
|
42
|
+
: true;
|
|
43
|
+
}
|
|
44
|
+
function cornerStroke(ctx, level, name, id, corner, raw) {
|
|
45
|
+
const auto =
|
|
46
|
+
raw?.stroke === undefined
|
|
47
|
+
? automaticStroke(ctx.frames, level, name)
|
|
48
|
+
: raw.stroke === 'auto';
|
|
49
|
+
if (raw && raw.stroke === undefined && !auto) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
return [
|
|
53
|
+
ctx.set(
|
|
54
|
+
level,
|
|
55
|
+
`${id}-stroke`,
|
|
56
|
+
auto
|
|
57
|
+
? ctx.variable(level, `${FRAME_EDGES[IDS.indexOf(id)]}-stroke`)
|
|
58
|
+
: `${corner.stroke}px`
|
|
59
|
+
),
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
function strokeChanged(patch, raw, adjacent) {
|
|
63
|
+
return (
|
|
64
|
+
!patch ||
|
|
65
|
+
raw?.stroke !== undefined ||
|
|
66
|
+
patch.stroke !== undefined ||
|
|
67
|
+
adjacent?.stroke !== undefined
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
function cornerPaint(ctx, level, id, corner, { patch, raw, adjacent }) {
|
|
71
|
+
const values = cornerLine(ctx, level, id, corner.line);
|
|
72
|
+
if (!patch || raw?.line !== undefined) {
|
|
73
|
+
return values;
|
|
74
|
+
}
|
|
75
|
+
return raw?.color !== undefined || adjacent?.color !== undefined
|
|
76
|
+
? [values.at(-1)]
|
|
77
|
+
: [];
|
|
78
|
+
}
|
|
79
|
+
function dimensionChanged(changed, key, value) {
|
|
80
|
+
return (
|
|
81
|
+
changed(key) || changed('size') || (changed('shape') && value === undefined)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
export function cornerValues(ctx, level, frame, id, patch) {
|
|
85
|
+
const name = FRAME_CORNERS[IDS.indexOf(id)];
|
|
86
|
+
const c = frame.corners[name];
|
|
87
|
+
const raw = patch?.corners[name];
|
|
88
|
+
const p = (key) => ctx.prop(level, `${id}-${key}`);
|
|
89
|
+
const v = (key) => ctx.variable(level, `${id}-${key}`);
|
|
90
|
+
const set = (key, value, ...type) =>
|
|
91
|
+
ctx.set(level, `${id}-${key}`, value, ...type);
|
|
92
|
+
const declarations = [];
|
|
93
|
+
const changed = (key) => !patch || raw?.[key] !== undefined;
|
|
94
|
+
for (const key of ['size', 'arm']) {
|
|
95
|
+
if (changed(key)) {
|
|
96
|
+
declarations.push(set(key, `${c[key]}px`));
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
for (const key of ['width', 'height']) {
|
|
100
|
+
if (dimensionChanged(changed, key, c[key])) {
|
|
101
|
+
declarations.push(
|
|
102
|
+
set(
|
|
103
|
+
key,
|
|
104
|
+
c[key] === undefined
|
|
105
|
+
? `calc(${v('size')} * ${v(key === 'width' ? 'wf' : 'hf')})`
|
|
106
|
+
: `${c[key]}px`
|
|
107
|
+
)
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const adjacent = patch?.edges[FRAME_EDGES[IDS.indexOf(id)]];
|
|
112
|
+
if (strokeChanged(patch, raw, adjacent)) {
|
|
113
|
+
declarations.push(...cornerStroke(ctx, level, name, id, c, raw));
|
|
114
|
+
}
|
|
115
|
+
if (changed('color')) {
|
|
116
|
+
declarations.push(ctx.color(level, `${id}-color`, colorCss(c.color)));
|
|
117
|
+
}
|
|
118
|
+
if (changed('shape')) {
|
|
119
|
+
declarations.push(...cornerShape(ctx, level, id, c.shape));
|
|
120
|
+
}
|
|
121
|
+
// Derived values are recomputed on a state host so inherited scope values
|
|
122
|
+
// cannot retain stale dimensions or paint when a state changes one input.
|
|
123
|
+
declarations.push([p('w'), v('width')], [p('h'), v('height')]);
|
|
124
|
+
declarations.push(
|
|
125
|
+
...cornerPaint(ctx, level, id, c, { patch, raw, adjacent })
|
|
126
|
+
);
|
|
127
|
+
ctx.register(p('w'));
|
|
128
|
+
ctx.register(p('h'));
|
|
129
|
+
if (!patch) {
|
|
130
|
+
ctx.enumeration(level, `${name}-shape`, corners, (shape) =>
|
|
131
|
+
cornerShape(ctx, level, id, shape)
|
|
132
|
+
);
|
|
133
|
+
ctx.enumeration(level, `${name}-line`, lines, (line) =>
|
|
134
|
+
cornerLine(ctx, level, id, line)
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
return declarations;
|
|
138
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { SIDES, rule } from './frame-css-geometry.js';
|
|
2
|
+
|
|
3
|
+
/** Paint a full-size polygon band so fractional widths receive the same
|
|
4
|
+
* antialiasing as SVG strokes, including one-pixel edges on the frame boundary. */
|
|
5
|
+
export function edgeGeometryCss(prefix) {
|
|
6
|
+
const v = (name) => `var(--${prefix}-g-${name})`;
|
|
7
|
+
const edgeCorners = [
|
|
8
|
+
['tl', 'tr'],
|
|
9
|
+
['tr', 'br'],
|
|
10
|
+
['br', 'bl'],
|
|
11
|
+
['bl', 'tl'],
|
|
12
|
+
];
|
|
13
|
+
return SIDES.map((side, i) => {
|
|
14
|
+
const [a, b] = edgeCorners[i];
|
|
15
|
+
const horizontal = i % 2 === 0;
|
|
16
|
+
const start = horizontal ? (i === 0 ? a : b) : i === 1 ? a : b;
|
|
17
|
+
const end = start === a ? b : a;
|
|
18
|
+
const axis = horizontal ? 'w' : 'h';
|
|
19
|
+
const stroke = v(`${side}-stroke`);
|
|
20
|
+
const dimension = horizontal ? '100cqw' : '100cqh';
|
|
21
|
+
const factor = `${v('fit')} * ${v('threshold')} * ${v('border')}`;
|
|
22
|
+
const corner = (id) => `calc(${v(`${id}-${axis}`)} * ${factor})`;
|
|
23
|
+
const room = `max(0px, calc((${dimension} - ${corner(start)} - ${corner(end)}) / 2))`;
|
|
24
|
+
const extent = (id) =>
|
|
25
|
+
`calc(${corner(id)} + min(${room}, calc(${v(`${id}-gap`)} * ${factor})))`;
|
|
26
|
+
const from = extent(start),
|
|
27
|
+
to = `calc(${dimension} - ${extent(end)})`;
|
|
28
|
+
const center =
|
|
29
|
+
i === 0 || i === 3 ? '0px' : horizontal ? '100cqh' : '100cqw';
|
|
30
|
+
const near = `calc(${center} - ${stroke} / 2)`,
|
|
31
|
+
far = `calc(${center} + ${stroke} / 2)`;
|
|
32
|
+
const points = [
|
|
33
|
+
[from, near],
|
|
34
|
+
[to, near],
|
|
35
|
+
[to, far],
|
|
36
|
+
[from, far],
|
|
37
|
+
].map((p) => (horizontal ? p : p.toReversed()));
|
|
38
|
+
const coordinates = [];
|
|
39
|
+
const polygon = points
|
|
40
|
+
.map((p, j) =>
|
|
41
|
+
p
|
|
42
|
+
.map((value, k) => {
|
|
43
|
+
const name = `--${prefix}-edge-${side}-${j}-${k}`;
|
|
44
|
+
coordinates.push([name, `calc(${value} + ${stroke})`]);
|
|
45
|
+
return `var(${name})`;
|
|
46
|
+
})
|
|
47
|
+
.join(' ')
|
|
48
|
+
)
|
|
49
|
+
.join(', ');
|
|
50
|
+
const offset = `calc(${from} + ${stroke})`;
|
|
51
|
+
const length = `calc(${to} - ${from})`;
|
|
52
|
+
const normalPosition = `${side} calc(${stroke} / 2)`;
|
|
53
|
+
const along = horizontal ? `left ${offset}` : `top ${offset}`;
|
|
54
|
+
return rule(`[data-frame-edge='${side}']`, [
|
|
55
|
+
['inset', `calc(${stroke} * -1)`],
|
|
56
|
+
...coordinates,
|
|
57
|
+
['clip-path', `polygon(${polygon})`],
|
|
58
|
+
['background-image', v(`${side}-image`)],
|
|
59
|
+
[
|
|
60
|
+
'background-size',
|
|
61
|
+
horizontal
|
|
62
|
+
? `100% ${v(`${side}-across`)}`
|
|
63
|
+
: `${v(`${side}-across`)} 100%`,
|
|
64
|
+
],
|
|
65
|
+
['background-repeat', horizontal ? 'repeat-x' : 'repeat-y'],
|
|
66
|
+
['background-position', `${along} ${normalPosition}`],
|
|
67
|
+
['mask-image', v(`${side}-mask`)],
|
|
68
|
+
['mask-size', horizontal ? `${length} 100%` : `100% ${length}`],
|
|
69
|
+
['mask-position', horizontal ? `${offset} 0px` : `0px ${offset}`],
|
|
70
|
+
['mask-repeat', 'no-repeat'],
|
|
71
|
+
['opacity', `calc(${v('opacity')} * ${v(`${side}-visible`)})`],
|
|
72
|
+
]);
|
|
73
|
+
}).join('');
|
|
74
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { lines } from './frame-vocabulary.js';
|
|
2
|
+
import { FRAME_STYLES } from './frame-schema.js';
|
|
3
|
+
import { colorCss } from './frame-color.js';
|
|
4
|
+
|
|
5
|
+
export function edgeStyle(ctx, level, name, style) {
|
|
6
|
+
const color = ctx.variable(level, `${name}-color`);
|
|
7
|
+
const stroke = ctx.variable(level, `${name}-stroke`);
|
|
8
|
+
const horizontal = name === 'top' || name === 'bottom';
|
|
9
|
+
const direction = horizontal ? 'to right' : 'to bottom';
|
|
10
|
+
const across = horizontal ? 'to bottom' : 'to right';
|
|
11
|
+
const dash =
|
|
12
|
+
style === 'dotted'
|
|
13
|
+
? `max(1px, ${stroke})`
|
|
14
|
+
: `max(1px, calc(${stroke} * 3))`;
|
|
15
|
+
const images = {
|
|
16
|
+
solid: `linear-gradient(${color}, ${color})`,
|
|
17
|
+
double: `linear-gradient(${across}, ${color} 0% 33.333%, transparent 33.333% 66.667%, ${color} 66.667%)`,
|
|
18
|
+
dashed: `repeating-linear-gradient(${direction}, ${color} 0px ${dash}, transparent ${dash} calc(${dash} * 2))`,
|
|
19
|
+
dotted: `repeating-linear-gradient(${direction}, ${color} 0px ${dash}, transparent ${dash} calc(${dash} * 2))`,
|
|
20
|
+
};
|
|
21
|
+
return [
|
|
22
|
+
[ctx.prop(level, `${name}-image`), images[style]],
|
|
23
|
+
[ctx.prop(level, `${name}-across`), style === 'double' ? stroke : '100%'],
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
export function edgeLine(ctx, level, name, line) {
|
|
27
|
+
const direction =
|
|
28
|
+
name === 'top' || name === 'bottom' ? 'to right' : 'to bottom';
|
|
29
|
+
const gap = ctx.variable(level, `${name}-gap`);
|
|
30
|
+
const mask =
|
|
31
|
+
line === 'bracket'
|
|
32
|
+
? `linear-gradient(${direction}, black 0px ${gap}, transparent ${gap} calc(100% - ${gap}), black calc(100% - ${gap}))`
|
|
33
|
+
: line === 'gap'
|
|
34
|
+
? `repeating-linear-gradient(${direction}, black 0px ${gap}, transparent ${gap} calc(${gap} * 2))`
|
|
35
|
+
: 'linear-gradient(black, black)';
|
|
36
|
+
return [
|
|
37
|
+
[ctx.prop(level, `${name}-visible`), line === 'none' ? 0 : 1],
|
|
38
|
+
[ctx.prop(level, `${name}-mask`), mask],
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
function autoStroke(frames, level, side) {
|
|
42
|
+
const entry = frames.get(level);
|
|
43
|
+
const stroke = entry.edges[side]?.stroke;
|
|
44
|
+
if (stroke !== undefined) {
|
|
45
|
+
return stroke === 'auto';
|
|
46
|
+
}
|
|
47
|
+
return entry.extends ? autoStroke(frames, entry.extends, side) : true;
|
|
48
|
+
}
|
|
49
|
+
function edgePaint(ctx, level, side, edge, patch, raw) {
|
|
50
|
+
const declarations = [];
|
|
51
|
+
if (
|
|
52
|
+
!patch ||
|
|
53
|
+
['style', 'color', 'stroke'].some((key) => raw?.[key] !== undefined) ||
|
|
54
|
+
patch.style !== undefined ||
|
|
55
|
+
patch.stroke !== undefined
|
|
56
|
+
) {
|
|
57
|
+
declarations.push(...edgeStyle(ctx, level, side, edge.style));
|
|
58
|
+
}
|
|
59
|
+
if (!patch || raw?.line !== undefined || raw?.gap !== undefined) {
|
|
60
|
+
declarations.push(...edgeLine(ctx, level, side, edge.line));
|
|
61
|
+
}
|
|
62
|
+
return declarations;
|
|
63
|
+
}
|
|
64
|
+
export function edgeValues(ctx, level, frame, side, patch) {
|
|
65
|
+
const edge = frame.edges[side];
|
|
66
|
+
const raw = patch?.edges[side];
|
|
67
|
+
const declarations = [];
|
|
68
|
+
const changed = (key) => !patch || raw?.[key] !== undefined;
|
|
69
|
+
const set = (key, value, ...type) =>
|
|
70
|
+
ctx.set(level, `${side}-${key}`, value, ...type);
|
|
71
|
+
if (changed('stroke') || patch?.stroke !== undefined) {
|
|
72
|
+
const auto = patch
|
|
73
|
+
? raw?.stroke === 'auto'
|
|
74
|
+
: autoStroke(ctx.frames, level, side);
|
|
75
|
+
declarations.push(
|
|
76
|
+
set('stroke', auto ? ctx.variable(level, 'stroke') : `${edge.stroke}px`)
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
if (changed('color')) {
|
|
80
|
+
declarations.push(ctx.color(level, `${side}-color`, colorCss(edge.color)));
|
|
81
|
+
}
|
|
82
|
+
if (changed('gap')) {
|
|
83
|
+
declarations.push(set('gap', `${edge.gap}px`));
|
|
84
|
+
}
|
|
85
|
+
declarations.push(...edgePaint(ctx, level, side, edge, patch, raw));
|
|
86
|
+
if (!patch && !colorCss(edge.color).includes('currentColor')) {
|
|
87
|
+
ctx.register(ctx.prop(level, `${side}-image`), '<image> | none', 'none');
|
|
88
|
+
}
|
|
89
|
+
ctx.register(ctx.prop(level, `${side}-mask`), '<image> | none', 'none');
|
|
90
|
+
if (!patch) {
|
|
91
|
+
ctx.enumeration(level, `${side}-style`, FRAME_STYLES, (style) =>
|
|
92
|
+
edgeStyle(ctx, level, side, style)
|
|
93
|
+
);
|
|
94
|
+
ctx.enumeration(level, `${side}-line`, lines, (line) =>
|
|
95
|
+
edgeLine(ctx, level, side, line)
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
return declarations;
|
|
99
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { FRAME_CORNERS, FRAME_EDGES } from './frame-schema.js';
|
|
2
|
+
import { rule } from './frame-css-geometry.js';
|
|
3
|
+
|
|
4
|
+
function inheritsChoice(definition, key) {
|
|
5
|
+
const corner = FRAME_CORNERS.find((id) => key.startsWith(`${id}-`));
|
|
6
|
+
if (corner) {
|
|
7
|
+
return (
|
|
8
|
+
definition.corners[corner]?.[key.slice(corner.length + 1)] === undefined
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
const edge = FRAME_EDGES.find((id) => key.startsWith(`${id}-`));
|
|
12
|
+
if (edge) {
|
|
13
|
+
const field = key.slice(edge.length + 1);
|
|
14
|
+
return (
|
|
15
|
+
definition.edges[edge]?.[field] === undefined &&
|
|
16
|
+
!(field === 'style' && definition.style !== undefined)
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
return definition[key] === undefined;
|
|
20
|
+
}
|
|
21
|
+
/** Rebind enum expressions on inheriting levels so their own widths/colors
|
|
22
|
+
* remain live, using expressions bound to the child level. */
|
|
23
|
+
export function enumRules(ctx) {
|
|
24
|
+
let css = '';
|
|
25
|
+
const depth = (level) => {
|
|
26
|
+
let count = 0;
|
|
27
|
+
while (ctx.frames.get(level)?.extends) {
|
|
28
|
+
level = ctx.frames.get(level).extends;
|
|
29
|
+
count++;
|
|
30
|
+
}
|
|
31
|
+
return count;
|
|
32
|
+
};
|
|
33
|
+
for (const entry of [...ctx.enumerations].sort(
|
|
34
|
+
(a, b) => depth(a.level) - depth(b.level)
|
|
35
|
+
)) {
|
|
36
|
+
const { level, key, choices, declarations } = entry;
|
|
37
|
+
const descendants = [...ctx.frames.keys()].filter((child) => {
|
|
38
|
+
if (child === level) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
while (child !== level) {
|
|
42
|
+
const definition = ctx.frames.get(child);
|
|
43
|
+
if (!definition.extends || !inheritsChoice(definition, key)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
child = definition.extends;
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
});
|
|
50
|
+
for (const choice of choices) {
|
|
51
|
+
const own = declarations(choice);
|
|
52
|
+
const inherited = descendants.flatMap((child) =>
|
|
53
|
+
own.map(([name, value]) => [
|
|
54
|
+
name.replace(ctx.prop(level, ''), ctx.prop(child, '')),
|
|
55
|
+
String(value).replaceAll(ctx.prop(level, ''), ctx.prop(child, '')),
|
|
56
|
+
])
|
|
57
|
+
);
|
|
58
|
+
css += rule(
|
|
59
|
+
`:where(${ctx.scope})[data-${ctx.prefix}-${level}-${key}='${choice}']`,
|
|
60
|
+
[...own, ...inherited]
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return css;
|
|
65
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { edgeGeometryCss } from './frame-css-edge-geometry.js';
|
|
2
|
+
|
|
3
|
+
/** Shared responsive geometry. All lengths resolve against the decoration layer,
|
|
4
|
+
* never a layout containment boundary on the host. Quadratics are sampled at
|
|
5
|
+
* sixteen equal parameter intervals (maximum deviation at 128px: 0.18px).
|
|
6
|
+
*/
|
|
7
|
+
export const POINTS = 16;
|
|
8
|
+
export const IDS = ['tl', 'tr', 'br', 'bl'];
|
|
9
|
+
export const SIDES = ['top', 'right', 'bottom', 'left'];
|
|
10
|
+
export function shapePoints(shape) {
|
|
11
|
+
return Array.from({ length: POINTS + 1 }, (_, i) => {
|
|
12
|
+
const t = i / POINTS;
|
|
13
|
+
if (shape === 'round') {
|
|
14
|
+
return [t * t, (1 - t) ** 2];
|
|
15
|
+
}
|
|
16
|
+
if (shape === 'scoop') {
|
|
17
|
+
return [2 * t - t * t, 1 - t * t];
|
|
18
|
+
}
|
|
19
|
+
if (shape === 'notch') {
|
|
20
|
+
const points = [
|
|
21
|
+
[0, 1],
|
|
22
|
+
[0.5, 1],
|
|
23
|
+
[0.5, 0.5],
|
|
24
|
+
[1, 0.5],
|
|
25
|
+
[1, 0],
|
|
26
|
+
];
|
|
27
|
+
const j = Math.min(3, Math.floor(t * 4));
|
|
28
|
+
const f = t * 4 - j;
|
|
29
|
+
return points[j].map((v, k) => v + (points[j + 1][k] - v) * f);
|
|
30
|
+
}
|
|
31
|
+
if (shape === 'square') {
|
|
32
|
+
return t <= 0.5 ? [0, 1 - 2 * t] : [2 * t - 1, 0];
|
|
33
|
+
}
|
|
34
|
+
return [t, 1 - t];
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const rule = (selector, declarations) =>
|
|
38
|
+
`${selector} {\n${declarations.map(([k, v]) => ` ${k}: ${v};`).join('\n')}\n}\n`;
|
|
39
|
+
export { rule };
|
|
40
|
+
|
|
41
|
+
export function geometryCss(prefix) {
|
|
42
|
+
const v = (name) => `var(--${prefix}-g-${name})`;
|
|
43
|
+
const prop = (name) => `--${prefix}-g-${name}`;
|
|
44
|
+
const declarations = [];
|
|
45
|
+
// Length division preserves container-unit ratios in both browser engines.
|
|
46
|
+
// Denominators stay positive, including a completely square frame.
|
|
47
|
+
const ratios = [
|
|
48
|
+
['100cqw', 'tl-w', 'tr-w'],
|
|
49
|
+
['100cqw', 'bl-w', 'br-w'],
|
|
50
|
+
['100cqh', 'tl-h', 'bl-h'],
|
|
51
|
+
['100cqh', 'tr-h', 'br-h'],
|
|
52
|
+
].map(
|
|
53
|
+
([extent, a, b]) =>
|
|
54
|
+
`calc(${extent} / max(0.000001px, calc(${v(a)} + ${v(b)})))`
|
|
55
|
+
);
|
|
56
|
+
declarations.push([prop('fit'), `min(1, ${ratios.join(', ')})`]);
|
|
57
|
+
const at = (id, i, inset = false) => {
|
|
58
|
+
const x = `calc(${v(`${id}-x${i}`)} * ${v(`${id}-${id === 'tr' || id === 'bl' ? 'h' : 'w'}`)} * ${v('fit')} * ${v('threshold')} * ${v('border')})`;
|
|
59
|
+
const y = `calc(${v(`${id}-y${i}`)} * ${v(`${id}-${id === 'tr' || id === 'bl' ? 'w' : 'h'}`)} * ${v('fit')} * ${v('threshold')} * ${v('border')})`;
|
|
60
|
+
const offset = inset ? `calc(${v(`${id}-stroke`)} / 2)` : '0px';
|
|
61
|
+
// The local axes rotate clockwise for odd corners, matching frameGeometry.
|
|
62
|
+
const local = id === 'tr' || id === 'bl' ? [y, x] : [x, y];
|
|
63
|
+
return [
|
|
64
|
+
id === 'tr' || id === 'br'
|
|
65
|
+
? `calc(100cqw - ${local[0]} - ${offset})`
|
|
66
|
+
: `calc(${local[0]} + ${offset})`,
|
|
67
|
+
id === 'br' || id === 'bl'
|
|
68
|
+
? `calc(100cqh - ${local[1]} - ${offset})`
|
|
69
|
+
: `calc(${local[1]} + ${offset})`,
|
|
70
|
+
];
|
|
71
|
+
};
|
|
72
|
+
const contour = IDS.flatMap((id) =>
|
|
73
|
+
Array.from({ length: POINTS + 1 }, (_, i) => at(id, i).join(' '))
|
|
74
|
+
);
|
|
75
|
+
let css = rule('[data-frame-paint] > *', declarations);
|
|
76
|
+
css += rule('[data-frame-material]', [
|
|
77
|
+
['clip-path', `polygon(${contour.join(', ')})`],
|
|
78
|
+
]);
|
|
79
|
+
for (const id of IDS) {
|
|
80
|
+
const points = Array.from({ length: POINTS + 1 }, (_, i) => at(id, i));
|
|
81
|
+
const extension = `calc(${v(`${id}-extension`)} * ${v('fit')} * ${v('threshold')} * ${v('border')})`;
|
|
82
|
+
const extra = (point, axis, sign) =>
|
|
83
|
+
point.map((value, j) =>
|
|
84
|
+
j === axis ? `calc(${value} + ${sign} * ${extension})` : value
|
|
85
|
+
);
|
|
86
|
+
const startAxes = [1, 0, 1, 0],
|
|
87
|
+
endAxes = [0, 1, 0, 1];
|
|
88
|
+
const index = IDS.indexOf(id);
|
|
89
|
+
const outside = [
|
|
90
|
+
extra(points[0], startAxes[index], [1, -1, -1, 1][index]),
|
|
91
|
+
...points,
|
|
92
|
+
extra(points.at(-1), endAxes[index], [1, 1, -1, -1][index]),
|
|
93
|
+
];
|
|
94
|
+
// Parallel-offset sample normals. This also handles horizontal/vertical
|
|
95
|
+
// notch segments, and keeps stroke widths independent of corner fitting.
|
|
96
|
+
const inside = outside.map((point, i) => {
|
|
97
|
+
const a = outside[Math.max(0, i - 1)];
|
|
98
|
+
const b = outside[Math.min(outside.length - 1, i + 1)];
|
|
99
|
+
const dx = `calc(${b[0]} - ${a[0]})`;
|
|
100
|
+
const dy = `calc(${b[1]} - ${a[1]})`;
|
|
101
|
+
const length = `max(0.000001px, hypot(${dx}, ${dy}))`;
|
|
102
|
+
return [
|
|
103
|
+
`calc(${point[0]} - (${dy} / ${length}) * ${v(`${id}-stroke`)} / 2)`,
|
|
104
|
+
`calc(${point[1]} + (${dx} / ${length}) * ${v(`${id}-stroke`)} / 2)`,
|
|
105
|
+
];
|
|
106
|
+
});
|
|
107
|
+
// Stroke is centered on the contour, as in the fixed-size SVG reference.
|
|
108
|
+
const outer = outside.map((p, i) =>
|
|
109
|
+
p.map((value, axis) => `calc(${value} * 2 - ${inside[i][axis]})`)
|
|
110
|
+
);
|
|
111
|
+
const pointDeclarations = [];
|
|
112
|
+
const polygon = [...outer, ...inside.reverse()].map((p, i) =>
|
|
113
|
+
p
|
|
114
|
+
.map((value, axis) => {
|
|
115
|
+
const name = `--${prefix}-point-${id}-${i}-${axis}`;
|
|
116
|
+
pointDeclarations.push([name, value]);
|
|
117
|
+
return `var(${name})`;
|
|
118
|
+
})
|
|
119
|
+
.join(' ')
|
|
120
|
+
);
|
|
121
|
+
css += rule(`[data-frame-corner='${id}']`, [
|
|
122
|
+
...pointDeclarations,
|
|
123
|
+
['clip-path', `polygon(${polygon.join(', ')})`],
|
|
124
|
+
['background', v(`${id}-paint`)],
|
|
125
|
+
[
|
|
126
|
+
'opacity',
|
|
127
|
+
`calc(${v('opacity')} * ${v(`${id}-visible`)} * ${v('border')} * min(1, calc(${v('threshold')} * 1000000)))`,
|
|
128
|
+
],
|
|
129
|
+
['z-index', v('layer')],
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
return css + edgeGeometryCss(prefix);
|
|
133
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { FRAME_EDGES } from './frame-schema.js';
|
|
2
|
+
import { IDS, rule } from './frame-css-geometry.js';
|
|
3
|
+
|
|
4
|
+
/** A level in frame mode reads its explicit parent's live frame parameters.
|
|
5
|
+
* Own mode restores its ordinary cascade; border mode collapses all extents. */
|
|
6
|
+
export function modeRules(ctx, level, declarations) {
|
|
7
|
+
const definition = ctx.frames.get(level);
|
|
8
|
+
const partKeys = declarations
|
|
9
|
+
.map(([name]) => name.slice(ctx.prop(level, '').length))
|
|
10
|
+
.filter((key) =>
|
|
11
|
+
[...IDS, ...FRAME_EDGES].some((id) => key.startsWith(`${id}-`))
|
|
12
|
+
);
|
|
13
|
+
const parent = definition.extends;
|
|
14
|
+
const inherited = parent
|
|
15
|
+
? partKeys.map((key) => {
|
|
16
|
+
const field = key.slice(key.indexOf('-') + 1);
|
|
17
|
+
const scale = [
|
|
18
|
+
'size',
|
|
19
|
+
'width',
|
|
20
|
+
'height',
|
|
21
|
+
'arm',
|
|
22
|
+
'w',
|
|
23
|
+
'h',
|
|
24
|
+
'gap',
|
|
25
|
+
'extension',
|
|
26
|
+
].includes(field);
|
|
27
|
+
const value = ctx.variable(parent, key);
|
|
28
|
+
return [
|
|
29
|
+
ctx.prop(level, key),
|
|
30
|
+
scale ? `calc(${value} * ${ctx.variable(level, 'scale')})` : value,
|
|
31
|
+
];
|
|
32
|
+
})
|
|
33
|
+
: [];
|
|
34
|
+
ctx.enumeration(level, 'mode', ['frame', 'own', 'border'], (mode) => [
|
|
35
|
+
[ctx.prop(level, 'border'), mode === 'border' ? 0 : 1],
|
|
36
|
+
...(mode === 'frame' ? inherited : []),
|
|
37
|
+
]);
|
|
38
|
+
if (definition.mode === 'frame' && parent) {
|
|
39
|
+
const attribute = `data-${ctx.prefix}-${level}-mode`;
|
|
40
|
+
ctx.enumCss += rule(
|
|
41
|
+
`:where(${ctx.scope}):not([${attribute}='own']):not([${attribute}='border'])`,
|
|
42
|
+
inherited
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|