@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,85 @@
|
|
|
1
|
+
import { FRAME_STATES, resolveFrame } from './frame-schema.js';
|
|
2
|
+
import { frameValues } from './frame-css-values.js';
|
|
3
|
+
import { rule } from './frame-css-geometry.js';
|
|
4
|
+
|
|
5
|
+
const disabled = ":is(:disabled, [disabled], [aria-disabled='true'])";
|
|
6
|
+
const selectors = {
|
|
7
|
+
hover: `:hover:not(${disabled})`,
|
|
8
|
+
active: ':active',
|
|
9
|
+
selected:
|
|
10
|
+
":is([aria-selected='true'], [aria-pressed='true'], [aria-current='page'])",
|
|
11
|
+
focus: ':focus-visible',
|
|
12
|
+
disabled,
|
|
13
|
+
};
|
|
14
|
+
function patchesFor(ctx, level, state) {
|
|
15
|
+
const patches = [];
|
|
16
|
+
let entry = ctx.frames.get(level);
|
|
17
|
+
while (entry) {
|
|
18
|
+
if (entry.states[state]) {
|
|
19
|
+
patches.unshift(entry.states[state]);
|
|
20
|
+
}
|
|
21
|
+
entry = ctx.frames.get(entry.extends);
|
|
22
|
+
}
|
|
23
|
+
return patches;
|
|
24
|
+
}
|
|
25
|
+
function geometryPatch(patch) {
|
|
26
|
+
return {
|
|
27
|
+
corners: patch.corners,
|
|
28
|
+
edges: patch.edges,
|
|
29
|
+
...Object.fromEntries(
|
|
30
|
+
['stroke', 'style', 'mode']
|
|
31
|
+
.filter((key) => patch[key] !== undefined)
|
|
32
|
+
.map((key) => [key, patch[key]])
|
|
33
|
+
),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function hasGeometry(patch) {
|
|
37
|
+
return (
|
|
38
|
+
Object.keys(patch.corners).length > 0 ||
|
|
39
|
+
Object.keys(patch.edges).length > 0 ||
|
|
40
|
+
['stroke', 'style', 'mode'].some((key) => patch[key] !== undefined)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
/** Compound geometry selectors preserve independent state overrides: changing
|
|
44
|
+
* a color while pressed must keep a double edge selected by hover. There are
|
|
45
|
+
* at most five states, so this expansion is bounded to 26 compound subsets. */
|
|
46
|
+
export function stateCss(ctx, level, hosts) {
|
|
47
|
+
const patches = new Map(
|
|
48
|
+
FRAME_STATES.map((state) => [state, patchesFor(ctx, level, state)])
|
|
49
|
+
);
|
|
50
|
+
const suffix = (state) =>
|
|
51
|
+
state === 'selected' && ctx.selected
|
|
52
|
+
? `:is(${ctx.selected.join(', ')})`
|
|
53
|
+
: selectors[state];
|
|
54
|
+
const render = (states, inputs) => {
|
|
55
|
+
const selector = hosts
|
|
56
|
+
.map(
|
|
57
|
+
(host) =>
|
|
58
|
+
host + states.map((state) => `:where(${suffix(state)})`).join('')
|
|
59
|
+
)
|
|
60
|
+
.join(', ');
|
|
61
|
+
const resolved = resolveFrame(ctx.frames, level, states);
|
|
62
|
+
return inputs
|
|
63
|
+
.map((patch) => rule(selector, frameValues(ctx, level, resolved, patch)))
|
|
64
|
+
.join('');
|
|
65
|
+
};
|
|
66
|
+
let css = FRAME_STATES.map((state) =>
|
|
67
|
+
render([state], patches.get(state))
|
|
68
|
+
).join('');
|
|
69
|
+
const geometryStates = FRAME_STATES.filter((state) =>
|
|
70
|
+
patches.get(state).some(hasGeometry)
|
|
71
|
+
);
|
|
72
|
+
const combinations = [[]];
|
|
73
|
+
for (const state of geometryStates) {
|
|
74
|
+
combinations.push(...combinations.map((previous) => [...previous, state]));
|
|
75
|
+
}
|
|
76
|
+
for (const states of combinations
|
|
77
|
+
.filter((items) => items.length > 1)
|
|
78
|
+
.sort((a, b) => a.length - b.length)) {
|
|
79
|
+
css += render(
|
|
80
|
+
states,
|
|
81
|
+
states.flatMap((state) => patches.get(state).map(geometryPatch))
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return css;
|
|
85
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { modeRules } from './frame-css-modes.js';
|
|
2
|
+
import {
|
|
3
|
+
FRAME_CORNERS,
|
|
4
|
+
FRAME_EDGES,
|
|
5
|
+
FRAME_STYLES,
|
|
6
|
+
resolveFrame,
|
|
7
|
+
} from './frame-schema.js';
|
|
8
|
+
import { IDS } from './frame-css-geometry.js';
|
|
9
|
+
import { cornerValues } from './frame-css-corners.js';
|
|
10
|
+
import { edgeValues, edgeStyle } from './frame-css-edges.js';
|
|
11
|
+
|
|
12
|
+
function inheritedCorner(definition, frame, id, field) {
|
|
13
|
+
const name = FRAME_CORNERS[IDS.indexOf(id)];
|
|
14
|
+
const raw = definition.corners[name] ?? {};
|
|
15
|
+
const explicit = raw[field] !== undefined && raw[field] !== 'auto';
|
|
16
|
+
if (['size', 'arm'].includes(field)) {
|
|
17
|
+
return [!explicit, true];
|
|
18
|
+
}
|
|
19
|
+
if (['width', 'height'].includes(field)) {
|
|
20
|
+
return [!explicit && frame.corners[name][field] !== undefined, true];
|
|
21
|
+
}
|
|
22
|
+
if (['wf', 'hf'].includes(field) || /^[xy]\d+$/u.test(field)) {
|
|
23
|
+
return [raw.shape === undefined, false];
|
|
24
|
+
}
|
|
25
|
+
if (['stroke', 'color'].includes(field)) {
|
|
26
|
+
return [raw[field] === undefined, false];
|
|
27
|
+
}
|
|
28
|
+
if (field === 'visible') {
|
|
29
|
+
return [raw.line === undefined, false];
|
|
30
|
+
}
|
|
31
|
+
return [false, false];
|
|
32
|
+
}
|
|
33
|
+
function inheritedEdge(definition, side, field) {
|
|
34
|
+
if (['image', 'mask', 'across'].includes(field)) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
const raw = definition.edges[side] ?? {};
|
|
38
|
+
const dependency =
|
|
39
|
+
{ visible: 'line', mask: 'line', image: 'style' }[field] ?? field;
|
|
40
|
+
return (
|
|
41
|
+
raw[dependency] === undefined &&
|
|
42
|
+
!(field === 'image' && definition.style !== undefined) &&
|
|
43
|
+
!(field === 'stroke' && definition.stroke !== undefined)
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
export function inheritValues(ctx, level, frame, declarations) {
|
|
47
|
+
const definition = ctx.frames.get(level);
|
|
48
|
+
if (!definition.extends) {
|
|
49
|
+
return declarations;
|
|
50
|
+
}
|
|
51
|
+
return declarations.map(([name, value]) => {
|
|
52
|
+
const key = name.slice(ctx.prop(level, '').length);
|
|
53
|
+
const corner = IDS.find((id) => key.startsWith(`${id}-`));
|
|
54
|
+
const edge = FRAME_EDGES.find((id) => key.startsWith(`${id}-`));
|
|
55
|
+
let inherit,
|
|
56
|
+
scaled = false;
|
|
57
|
+
if (corner) {
|
|
58
|
+
[inherit, scaled] = inheritedCorner(
|
|
59
|
+
definition,
|
|
60
|
+
frame,
|
|
61
|
+
corner,
|
|
62
|
+
key.slice(corner.length + 1)
|
|
63
|
+
);
|
|
64
|
+
} else if (edge) {
|
|
65
|
+
inherit = inheritedEdge(definition, edge, key.slice(edge.length + 1));
|
|
66
|
+
} else {
|
|
67
|
+
inherit =
|
|
68
|
+
definition[key] === undefined &&
|
|
69
|
+
!['threshold', 'border', 'scale'].includes(key);
|
|
70
|
+
}
|
|
71
|
+
const parent = ctx.variable(definition.extends, key);
|
|
72
|
+
return [
|
|
73
|
+
name,
|
|
74
|
+
inherit
|
|
75
|
+
? scaled
|
|
76
|
+
? `calc(${parent} * ${ctx.variable(level, 'scale')})`
|
|
77
|
+
: parent
|
|
78
|
+
: value,
|
|
79
|
+
];
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function levelValues(ctx, level, frame, patch) {
|
|
83
|
+
const declarations = [];
|
|
84
|
+
const changed = (key) => !patch || patch[key] !== undefined;
|
|
85
|
+
if (changed('stroke')) {
|
|
86
|
+
declarations.push(
|
|
87
|
+
ctx.set(
|
|
88
|
+
level,
|
|
89
|
+
'stroke',
|
|
90
|
+
`${frame.stroke === 'auto' ? 1 : frame.stroke}px`
|
|
91
|
+
)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
if (changed('opacity')) {
|
|
95
|
+
declarations.push(
|
|
96
|
+
ctx.set(level, 'opacity', frame.opacity, '<number>', '1')
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
if (changed('layer')) {
|
|
100
|
+
declarations.push(
|
|
101
|
+
ctx.set(level, 'layer', frame.layer === 'above' ? 2 : 0, '<number>', '2')
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
if (changed('mode')) {
|
|
105
|
+
declarations.push([
|
|
106
|
+
ctx.prop(level, 'border'),
|
|
107
|
+
frame.mode === 'border' ? 0 : 1,
|
|
108
|
+
]);
|
|
109
|
+
}
|
|
110
|
+
if (!patch) {
|
|
111
|
+
declarations.push(
|
|
112
|
+
ctx.set(level, 'threshold', 1, '<number>', '1'),
|
|
113
|
+
ctx.set(
|
|
114
|
+
level,
|
|
115
|
+
'scale',
|
|
116
|
+
ctx.frames.get(level).scale ?? 1,
|
|
117
|
+
'<number>',
|
|
118
|
+
'1',
|
|
119
|
+
false
|
|
120
|
+
),
|
|
121
|
+
ctx.set(level, 'fitScale', frame.fitScale, '<number>', '0.5')
|
|
122
|
+
);
|
|
123
|
+
for (const key of ['min-width', 'max-width', 'min-height', 'max-height']) {
|
|
124
|
+
declarations.push(
|
|
125
|
+
ctx.set(level, key, frame[key], '<number>', '0', false)
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
ctx.enumeration(level, 'layer', ['above', 'below'], (layer) => [
|
|
129
|
+
[ctx.prop(level, 'layer'), layer === 'above' ? 2 : 0],
|
|
130
|
+
]);
|
|
131
|
+
ctx.enumeration(level, 'style', FRAME_STYLES, (style) =>
|
|
132
|
+
FRAME_EDGES.flatMap((side) => edgeStyle(ctx, level, side, style))
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return declarations;
|
|
136
|
+
}
|
|
137
|
+
export function frameValues(ctx, level, frame, patch = null) {
|
|
138
|
+
if (!patch && ctx.frames.get(level).mode === 'frame') {
|
|
139
|
+
const ownFrames = new Map(ctx.frames);
|
|
140
|
+
ownFrames.set(level, { ...ctx.frames.get(level), mode: 'own' });
|
|
141
|
+
frame = resolveFrame(ownFrames, level);
|
|
142
|
+
}
|
|
143
|
+
const declarations = [
|
|
144
|
+
...levelValues(ctx, level, frame, patch),
|
|
145
|
+
...IDS.flatMap((id) => cornerValues(ctx, level, frame, id, patch)),
|
|
146
|
+
...FRAME_EDGES.flatMap((side) =>
|
|
147
|
+
edgeValues(ctx, level, frame, side, patch)
|
|
148
|
+
),
|
|
149
|
+
];
|
|
150
|
+
if (patch) {
|
|
151
|
+
return declarations;
|
|
152
|
+
}
|
|
153
|
+
const inherited = inheritValues(ctx, level, frame, declarations);
|
|
154
|
+
modeRules(ctx, level, inherited);
|
|
155
|
+
return inherited;
|
|
156
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { FRAME_EDGES, FRAME_LEVELS, resolveFrame } from './frame-schema.js';
|
|
2
|
+
import { geometryCss, POINTS, IDS, rule } from './frame-css-geometry.js';
|
|
3
|
+
import { createCssContext } from './frame-css-controls.js';
|
|
4
|
+
import { frameValues } from './frame-css-values.js';
|
|
5
|
+
import { stateCss } from './frame-css-states.js';
|
|
6
|
+
|
|
7
|
+
const validSelector = (s) =>
|
|
8
|
+
typeof s === 'string' && s.length > 0 && !/[{};]/u.test(s);
|
|
9
|
+
function validateOptions({
|
|
10
|
+
prefix,
|
|
11
|
+
scope,
|
|
12
|
+
boundaryAttribute,
|
|
13
|
+
levels,
|
|
14
|
+
selected,
|
|
15
|
+
}) {
|
|
16
|
+
if (!/^[a-zA-Z][\w-]*$/u.test(prefix) || !validSelector(scope)) {
|
|
17
|
+
throw new TypeError('Invalid frame scope or prefix');
|
|
18
|
+
}
|
|
19
|
+
if (boundaryAttribute && !/^data-[\w-]+$/u.test(boundaryAttribute)) {
|
|
20
|
+
throw new TypeError('Invalid frame boundary attribute');
|
|
21
|
+
}
|
|
22
|
+
for (const [level, selectors] of Object.entries(levels)) {
|
|
23
|
+
if (
|
|
24
|
+
!FRAME_LEVELS.includes(level) ||
|
|
25
|
+
!Array.isArray(selectors) ||
|
|
26
|
+
!selectors.length ||
|
|
27
|
+
!selectors.every(validSelector)
|
|
28
|
+
) {
|
|
29
|
+
throw new TypeError(`Invalid frame selectors: ${level}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (
|
|
33
|
+
selected &&
|
|
34
|
+
(!Array.isArray(selected) ||
|
|
35
|
+
!selected.length ||
|
|
36
|
+
!selected.every(validSelector))
|
|
37
|
+
) {
|
|
38
|
+
throw new TypeError('Invalid selected selectors');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** Static decoration markup, inserted before content in a transparent host.
|
|
42
|
+
* The separate size containers preserve intrinsic host layout and stacking. */
|
|
43
|
+
export function frameLayers() {
|
|
44
|
+
const material =
|
|
45
|
+
'<span data-frame-paint data-frame-surface aria-hidden="true"><span data-frame-material></span></span>';
|
|
46
|
+
const corners = IDS.map(
|
|
47
|
+
(id) => `<span data-frame-corner="${id}"></span>`
|
|
48
|
+
).join('');
|
|
49
|
+
const edges = FRAME_EDGES.map(
|
|
50
|
+
(id) => `<span data-frame-edge="${id}"></span>`
|
|
51
|
+
).join('');
|
|
52
|
+
return `${material}<span data-frame-paint data-frame-strokes aria-hidden="true">${corners}${edges}</span>`;
|
|
53
|
+
}
|
|
54
|
+
function baseCss(prefix) {
|
|
55
|
+
return (
|
|
56
|
+
rule('[data-frame-paint]', [
|
|
57
|
+
['position', 'absolute'],
|
|
58
|
+
['inset', '0'],
|
|
59
|
+
['container-type', 'size'],
|
|
60
|
+
['pointer-events', 'none'],
|
|
61
|
+
]) +
|
|
62
|
+
rule('[data-frame-surface]', [['z-index', '-1']]) +
|
|
63
|
+
rule('[data-frame-strokes]', [
|
|
64
|
+
['z-index', `var(--${prefix}-stacking, 2)`],
|
|
65
|
+
]) +
|
|
66
|
+
rule('[data-frame-paint] > *', [
|
|
67
|
+
['position', 'absolute'],
|
|
68
|
+
['inset', '0'],
|
|
69
|
+
['pointer-events', 'none'],
|
|
70
|
+
]) +
|
|
71
|
+
rule('[data-frame-material]', [
|
|
72
|
+
['background', 'var(--frame-material, transparent)'],
|
|
73
|
+
]) +
|
|
74
|
+
rule(':where([data-frame-paint] ~ :not([data-frame-paint]))', [
|
|
75
|
+
['position', 'relative'],
|
|
76
|
+
['z-index', '1'],
|
|
77
|
+
]) +
|
|
78
|
+
geometryCss(prefix)
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
function geometryAliases(ctx, level) {
|
|
82
|
+
const keys = ['opacity', 'layer', 'threshold', 'border'];
|
|
83
|
+
for (const id of IDS) {
|
|
84
|
+
keys.push(
|
|
85
|
+
...[
|
|
86
|
+
'w',
|
|
87
|
+
'h',
|
|
88
|
+
'stroke',
|
|
89
|
+
'color',
|
|
90
|
+
'visible',
|
|
91
|
+
'gap',
|
|
92
|
+
'extension',
|
|
93
|
+
'paint',
|
|
94
|
+
].map((key) => `${id}-${key}`)
|
|
95
|
+
);
|
|
96
|
+
for (let i = 0; i <= POINTS; i++) {
|
|
97
|
+
keys.push(`${id}-x${i}`, `${id}-y${i}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
for (const side of FRAME_EDGES) {
|
|
101
|
+
keys.push(
|
|
102
|
+
...['stroke', 'color', 'visible', 'image', 'mask', 'across'].map(
|
|
103
|
+
(key) => `${side}-${key}`
|
|
104
|
+
)
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return keys.map((key) => {
|
|
108
|
+
const name = `--${ctx.prefix}-g-${key}`;
|
|
109
|
+
const inherited = ctx.registrations.get(ctx.prop(level, key));
|
|
110
|
+
const numeric =
|
|
111
|
+
['opacity', 'layer', 'threshold', 'border'].includes(key) ||
|
|
112
|
+
/-(?:visible|[xy]\d+)$/u.test(key);
|
|
113
|
+
const color = /-(?:paint|color)$/u.test(key);
|
|
114
|
+
const image = /-(?:image|mask)$/u.test(key);
|
|
115
|
+
const syntax =
|
|
116
|
+
inherited?.syntax ??
|
|
117
|
+
(image
|
|
118
|
+
? '<image> | none'
|
|
119
|
+
: color
|
|
120
|
+
? '<color>'
|
|
121
|
+
: numeric
|
|
122
|
+
? '<number>'
|
|
123
|
+
: '<length>');
|
|
124
|
+
const initial =
|
|
125
|
+
inherited?.initial ??
|
|
126
|
+
(image ? 'none' : color ? 'black' : numeric ? '0' : '0px');
|
|
127
|
+
if (!key.endsWith('-image') && !key.endsWith('-across')) {
|
|
128
|
+
ctx.register(name, syntax, initial, false);
|
|
129
|
+
}
|
|
130
|
+
return [name, ctx.variable(level, key)];
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function levelCss(ctx, level, selectors) {
|
|
134
|
+
const hosts = selectors.map((s) => `:where(${s})`);
|
|
135
|
+
const paint = (suffix = '') =>
|
|
136
|
+
hosts.map((s) => `${s}${suffix} > [data-frame-paint] > *`).join(', ');
|
|
137
|
+
let css = rule(hosts.join(', '), [
|
|
138
|
+
['position', 'relative'],
|
|
139
|
+
['isolation', 'isolate'],
|
|
140
|
+
[`--${ctx.prefix}-stacking`, ctx.variable(level, 'layer')],
|
|
141
|
+
]);
|
|
142
|
+
css += rule(paint(), geometryAliases(ctx, level));
|
|
143
|
+
css += stateCss(ctx, level, hosts);
|
|
144
|
+
return {
|
|
145
|
+
css,
|
|
146
|
+
fit: rule(paint(`[data-${ctx.prefix}-fit='outside']`), [
|
|
147
|
+
[`--${ctx.prefix}-g-threshold`, ctx.variable(level, 'fitScale')],
|
|
148
|
+
]),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function nestedCss(ctx, levels) {
|
|
152
|
+
if (!levels.panel || !ctx.frames.has('block')) {
|
|
153
|
+
return { css: '', fit: '' };
|
|
154
|
+
}
|
|
155
|
+
const panel = `:is(${levels.panel.join(', ')})`;
|
|
156
|
+
const chunk = levelCss(ctx, 'block', [
|
|
157
|
+
`:scope ${panel} ${panel}`,
|
|
158
|
+
`:scope${panel} ${panel}`,
|
|
159
|
+
]);
|
|
160
|
+
const boundary = ctx.boundaryAttribute ? `[${ctx.boundaryAttribute}]` : null;
|
|
161
|
+
const wrap = (rules) =>
|
|
162
|
+
!boundary
|
|
163
|
+
? `@scope (${ctx.scope}) {\n${rules}}\n`
|
|
164
|
+
: `@scope (${ctx.scope}) to (${boundary}) {\n${rules}}\n@scope (${boundary}) to (${boundary}) {\n${rules}}\n`;
|
|
165
|
+
return { css: wrap(chunk.css), fit: wrap(chunk.fit) };
|
|
166
|
+
}
|
|
167
|
+
/** Deterministic build-time CSS. Load properties, base, levels, fit in order.
|
|
168
|
+
* @param {Map<string, import('./frames.js').FrameDefinition>} frames
|
|
169
|
+
* @param {import('./frames.js').FramesCssOptions} [options]
|
|
170
|
+
*/
|
|
171
|
+
export function framesCss(frames, options = {}) {
|
|
172
|
+
const config = {
|
|
173
|
+
prefix: 'frame',
|
|
174
|
+
scope: ':root',
|
|
175
|
+
...options,
|
|
176
|
+
levels:
|
|
177
|
+
options.levels ??
|
|
178
|
+
Object.fromEntries(
|
|
179
|
+
[...frames.keys()].map((id) => [id, [`[data-frame='${id}']`]])
|
|
180
|
+
),
|
|
181
|
+
};
|
|
182
|
+
validateOptions(config);
|
|
183
|
+
const ctx = createCssContext(frames, config);
|
|
184
|
+
const levels = {};
|
|
185
|
+
let fit = '';
|
|
186
|
+
for (const level of frames.keys()) {
|
|
187
|
+
const frame = resolveFrame(frames, level);
|
|
188
|
+
levels[level] = rule(
|
|
189
|
+
`:where(${ctx.scope})`,
|
|
190
|
+
frameValues(ctx, level, frame)
|
|
191
|
+
);
|
|
192
|
+
if (config.levels[level]) {
|
|
193
|
+
const chunk = levelCss(ctx, level, config.levels[level]);
|
|
194
|
+
levels[level] += chunk.css;
|
|
195
|
+
fit += chunk.fit;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const nested = nestedCss(ctx, config.levels);
|
|
199
|
+
ctx.renderEnums();
|
|
200
|
+
ctx.register(`--${ctx.prefix}-g-fit`, '<number>', '1', false);
|
|
201
|
+
for (const id of IDS) {
|
|
202
|
+
for (let i = 0; i < (POINTS + 3) * 2; i++) {
|
|
203
|
+
for (const axis of [0, 1]) {
|
|
204
|
+
ctx.register(
|
|
205
|
+
`--${ctx.prefix}-point-${id}-${i}-${axis}`,
|
|
206
|
+
'<length>',
|
|
207
|
+
'0px',
|
|
208
|
+
false
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
for (const side of FRAME_EDGES) {
|
|
214
|
+
for (let i = 0; i < 4; i++) {
|
|
215
|
+
for (const axis of [0, 1]) {
|
|
216
|
+
ctx.register(
|
|
217
|
+
`--${ctx.prefix}-edge-${side}-${i}-${axis}`,
|
|
218
|
+
'<length>',
|
|
219
|
+
'0px',
|
|
220
|
+
false
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
properties: ctx.properties(),
|
|
227
|
+
base: baseCss(ctx.prefix) + ctx.enumCss + nested.css,
|
|
228
|
+
levels,
|
|
229
|
+
fit: fit + nested.fit,
|
|
230
|
+
controls: [...ctx.controls.values()],
|
|
231
|
+
};
|
|
232
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { FRAME_CORNERS, FRAME_EDGES } from './frame-schema.js';
|
|
2
|
+
import { colorCss } from './frame-color.js';
|
|
3
|
+
|
|
4
|
+
const esc = (s) =>
|
|
5
|
+
String(s)
|
|
6
|
+
.replaceAll('&', '&')
|
|
7
|
+
.replaceAll('"', '"')
|
|
8
|
+
.replaceAll('<', '<')
|
|
9
|
+
.replaceAll('>', '>');
|
|
10
|
+
|
|
11
|
+
function sizedCorners(frame) {
|
|
12
|
+
return FRAME_CORNERS.map((id) => {
|
|
13
|
+
const c = frame.corners[id];
|
|
14
|
+
return {
|
|
15
|
+
...c,
|
|
16
|
+
width:
|
|
17
|
+
frame.mode === 'border'
|
|
18
|
+
? 0
|
|
19
|
+
: (c.width ?? c.size * (c.shape === 'tall' ? 0.5 : 1)),
|
|
20
|
+
height:
|
|
21
|
+
frame.mode === 'border'
|
|
22
|
+
? 0
|
|
23
|
+
: (c.height ?? c.size * (c.shape === 'wide' ? 0.5 : 1)),
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A transparent contour plus separate stroke paths. Apply clipPath to a material
|
|
30
|
+
* layer and place borderSvg above it; neither layer paints an opaque cutout.
|
|
31
|
+
*/
|
|
32
|
+
export function frameGeometry(frame, width, height) {
|
|
33
|
+
if (![width, height].every((n) => Number.isFinite(n) && n > 0)) {
|
|
34
|
+
throw new RangeError('Frame dimensions must be positive finite pixels');
|
|
35
|
+
}
|
|
36
|
+
const cs = sizedCorners(frame);
|
|
37
|
+
const scale = Math.min(
|
|
38
|
+
1,
|
|
39
|
+
width / Math.max(cs[0].width + cs[1].width, Number.EPSILON),
|
|
40
|
+
width / Math.max(cs[2].width + cs[3].width, Number.EPSILON),
|
|
41
|
+
height / Math.max(cs[0].height + cs[3].height, Number.EPSILON),
|
|
42
|
+
height / Math.max(cs[1].height + cs[2].height, Number.EPSILON)
|
|
43
|
+
);
|
|
44
|
+
for (const c of cs) {
|
|
45
|
+
c.width *= scale;
|
|
46
|
+
c.height *= scale;
|
|
47
|
+
}
|
|
48
|
+
// Each corner is described in local coordinates from (0,h) to (w,0).
|
|
49
|
+
const transforms = [
|
|
50
|
+
(x, y) => [x, y],
|
|
51
|
+
(x, y) => [width - y, x],
|
|
52
|
+
(x, y) => [width - x, height - y],
|
|
53
|
+
(x, y) => [y, height - x],
|
|
54
|
+
];
|
|
55
|
+
const starts = [],
|
|
56
|
+
ends = [],
|
|
57
|
+
curves = [];
|
|
58
|
+
for (let i = 0; i < 4; i++) {
|
|
59
|
+
const c = cs[i];
|
|
60
|
+
const w = i % 2 ? c.height : c.width;
|
|
61
|
+
const h = i % 2 ? c.width : c.height;
|
|
62
|
+
const at = (x, y) => transforms[i](x, y).join(' ');
|
|
63
|
+
starts.push(at(0, h));
|
|
64
|
+
ends.push(at(w, 0));
|
|
65
|
+
const end = ends[i];
|
|
66
|
+
curves.push(
|
|
67
|
+
c.shape === 'square'
|
|
68
|
+
? `L ${at(0, 0)} L ${end}`
|
|
69
|
+
: c.shape === 'round'
|
|
70
|
+
? `Q ${at(0, 0)} ${end}`
|
|
71
|
+
: c.shape === 'scoop'
|
|
72
|
+
? `Q ${at(w, h)} ${end}`
|
|
73
|
+
: c.shape === 'notch'
|
|
74
|
+
? `L ${at(w / 2, h)} L ${at(w / 2, h / 2)} L ${at(w, h / 2)} L ${end}`
|
|
75
|
+
: `L ${end}`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
let path = `M ${starts[0]} ${curves[0]}`;
|
|
79
|
+
for (let i = 1; i < 4; i++) {
|
|
80
|
+
path += ` L ${starts[i]} ${curves[i]}`;
|
|
81
|
+
}
|
|
82
|
+
path += ' Z';
|
|
83
|
+
const strokes = frameStrokes(
|
|
84
|
+
frame,
|
|
85
|
+
cs,
|
|
86
|
+
{ starts, ends, curves, transforms },
|
|
87
|
+
scale
|
|
88
|
+
);
|
|
89
|
+
return {
|
|
90
|
+
path,
|
|
91
|
+
clipPath: `path("${path}")`,
|
|
92
|
+
corners: Object.fromEntries(FRAME_CORNERS.map((id, i) => [id, cs[i]])),
|
|
93
|
+
borderSvg: `<svg xmlns="http://www.w3.org/2000/svg" style="overflow:visible" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}" aria-hidden="true"><g opacity="${frame.opacity ?? 1}">${strokes}</g></svg>`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function frameStrokes(frame, cs, { starts, ends, curves, transforms }, scale) {
|
|
98
|
+
const stroke = (d, c, extra = '') =>
|
|
99
|
+
`<path d="${esc(d)}" fill="none" stroke="${esc(colorCss(c.color))}" stroke-width="${c.stroke}" ${extra}/>`;
|
|
100
|
+
const strokes = cs
|
|
101
|
+
.map((c, i) => {
|
|
102
|
+
if (['none', 'gap'].includes(c.line) || frame.mode === 'border') {
|
|
103
|
+
return '';
|
|
104
|
+
}
|
|
105
|
+
const paint =
|
|
106
|
+
c.line === 'line'
|
|
107
|
+
? { ...c, color: frame.edges[FRAME_EDGES[i]].color }
|
|
108
|
+
: c;
|
|
109
|
+
let d = `M ${starts[i]} ${curves[i]}`;
|
|
110
|
+
if (c.line === 'bracket') {
|
|
111
|
+
const w = i % 2 ? c.height : c.width,
|
|
112
|
+
h = i % 2 ? c.width : c.height;
|
|
113
|
+
d = `M ${transforms[i](0, h + c.arm * scale).join(' ')} L ${starts[i]} ${curves[i]} L ${transforms[i](w + c.arm * scale, 0).join(' ')}`;
|
|
114
|
+
}
|
|
115
|
+
return stroke(d, paint);
|
|
116
|
+
})
|
|
117
|
+
.join('');
|
|
118
|
+
return strokes + edgeStrokes(frame, cs, starts, ends, scale, stroke);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function edgeStrokes(frame, cs, starts, ends, scale, stroke) {
|
|
122
|
+
let strokes = '';
|
|
123
|
+
for (let i = 0; i < 4; i++) {
|
|
124
|
+
const edge = frame.edges[FRAME_EDGES[i]];
|
|
125
|
+
if (edge.line === 'none') {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const next = (i + 1) % 4;
|
|
129
|
+
let a = ends[i].split(' ').map(Number),
|
|
130
|
+
b = starts[next].split(' ').map(Number);
|
|
131
|
+
const fullLength = Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
132
|
+
if (fullLength > 0 && frame.mode !== 'border') {
|
|
133
|
+
const direction = a.map((value, j) => (b[j] - value) / fullLength);
|
|
134
|
+
const gapA =
|
|
135
|
+
cs[i].line === 'gap' ? Math.min(cs[i].arm * scale, fullLength / 2) : 0;
|
|
136
|
+
const gapB =
|
|
137
|
+
cs[next].line === 'gap'
|
|
138
|
+
? Math.min(cs[next].arm * scale, fullLength / 2)
|
|
139
|
+
: 0;
|
|
140
|
+
a = a.map((value, j) => value + direction[j] * gapA);
|
|
141
|
+
b = b.map((value, j) => value - direction[j] * gapB);
|
|
142
|
+
}
|
|
143
|
+
const style = edge.style ?? 'solid';
|
|
144
|
+
const paint = (d, value, extra = '') => {
|
|
145
|
+
if (style !== 'double') {
|
|
146
|
+
return stroke(d, value, extra);
|
|
147
|
+
}
|
|
148
|
+
const offset = edge.stroke / 3;
|
|
149
|
+
const shift = (sign) =>
|
|
150
|
+
i % 2 ? `${sign * offset} 0` : `0 ${sign * offset}`;
|
|
151
|
+
return [-1, 1]
|
|
152
|
+
.map((sign) =>
|
|
153
|
+
stroke(
|
|
154
|
+
d,
|
|
155
|
+
{ ...value, stroke: edge.stroke / 3 },
|
|
156
|
+
`transform="translate(${shift(sign)})"`
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
.join('');
|
|
160
|
+
};
|
|
161
|
+
const dash =
|
|
162
|
+
style === 'dotted'
|
|
163
|
+
? Math.max(1, edge.stroke)
|
|
164
|
+
: Math.max(1, edge.stroke * 3);
|
|
165
|
+
const pattern = ['dotted', 'dashed'].includes(style)
|
|
166
|
+
? `stroke-dasharray="${dash} ${dash}"`
|
|
167
|
+
: '';
|
|
168
|
+
const segment = (from, to) => `M ${from.join(' ')} L ${to.join(' ')}`;
|
|
169
|
+
const length = Math.hypot(b[0] - a[0], b[1] - a[1]);
|
|
170
|
+
if (edge.line === 'bracket' && length > 0) {
|
|
171
|
+
const f = Math.min(edge.gap, length / 2) / length;
|
|
172
|
+
const interpolate = (t) => a.map((v, j) => v + (b[j] - v) * t);
|
|
173
|
+
strokes += paint(
|
|
174
|
+
`${segment(a, interpolate(f))} ${segment(interpolate(1 - f), b)}`,
|
|
175
|
+
edge,
|
|
176
|
+
pattern
|
|
177
|
+
);
|
|
178
|
+
} else {
|
|
179
|
+
strokes += paint(
|
|
180
|
+
segment(a, b),
|
|
181
|
+
edge,
|
|
182
|
+
edge.line === 'gap'
|
|
183
|
+
? `stroke-dasharray="${edge.gap} ${edge.gap}"`
|
|
184
|
+
: pattern
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return strokes;
|
|
189
|
+
}
|