@threadlabs/looma 0.44.2 → 0.44.4
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/components/shared/icons.js +1 -0
- package/components/ui-badge/ui-badge.html +7 -6
- package/components/ui-button/ui-button.html +47 -2
- package/components/ui-card/ui-card.html +6 -6
- package/components/ui-color-picker/ui-color-picker.html +12 -5
- package/components/ui-color-picker/ui-color-picker.js +20 -6
- package/components/ui-dialog/ui-dialog.html +5 -6
- package/components/ui-icon/ui-icon.html +1 -0
- package/components/ui-icon-button/ui-icon-button.html +59 -4
- package/components/ui-menu/ui-menu.html +5 -6
- package/components/ui-number-input/ui-number-input.html +7 -0
- package/components/ui-popover/ui-popover.html +5 -6
- package/components/ui-slider/ui-slider.html +6 -0
- package/components/ui-tooltip/ui-tooltip.html +8 -5
- package/components/ui-tree-item/ui-tree-item.html +7 -1
- package/dist/index.js +1 -1
- package/docs/README.md +8 -4
- package/docs/catalog.json +469 -3704
- package/docs/customizer-render.mjs +55 -36
- package/docs/customizer.js +48 -33
- package/docs/fonts.mjs +28 -0
- package/docs/theme.mjs +39 -14
- package/editor/file-uploads.d.ts +3 -1
- package/editor/icons.d.ts +1 -0
- package/editor/index.js +2 -1
- package/package.json +1 -1
- package/styles/ui-badge.css +11 -10
- package/styles/ui-button.css +47 -2
- package/styles/ui-card.css +4 -4
- package/styles/ui-color-picker.css +105 -2
- package/styles/ui-dialog.css +10 -12
- package/styles/ui-icon-button.css +59 -4
- package/styles/ui-menu.css +5 -6
- package/styles/ui-number-input.css +6 -0
- package/styles/ui-popover.css +5 -6
- package/styles/ui-slider.css +3 -0
- package/styles/ui-tooltip.css +8 -5
- package/styles/ui-tree-item.css +12 -2
- package/theme-system.css +28 -16
- package/tokens.css +7 -0
- package/vanilla/UiColorPicker.d.ts +1 -0
- package/vanilla/UiColorPicker.js +32 -28
- package/vanilla/UiIcon.js +1 -1
- package/vanilla/UiNumberInput.d.ts +1 -0
- package/vanilla/UiNumberInput.js +53 -43
- package/vanilla/UiSlider.d.ts +1 -0
- package/vanilla/UiSlider.js +65 -57
- package/vanilla/UiTreeItem.js +1 -1
- package/vue/UiBadge.vue +7 -9
- package/vue/UiButton.vue +56 -2
- package/vue/UiCard.vue +13 -5
- package/vue/UiColorPicker.d.ts +6 -0
- package/vue/UiColorPicker.vue +156 -6
- package/vue/UiDialog.vue +22 -12
- package/vue/UiIcon.vue +1 -0
- package/vue/UiIconButton.vue +62 -4
- package/vue/UiMenu.vue +11 -6
- package/vue/UiNumberInput.d.ts +6 -0
- package/vue/UiNumberInput.vue +47 -1
- package/vue/UiPopover.vue +11 -6
- package/vue/UiSlider.d.ts +6 -0
- package/vue/UiSlider.vue +37 -1
- package/vue/UiTooltip.vue +11 -5
- package/vue/UiTreeItem.vue +19 -3
- package/vue/chunks/UiBadge.js +1 -1
- package/vue/chunks/UiButton.js +1 -1
- package/vue/chunks/UiCard.js +2 -2
- package/vue/chunks/UiColorPicker.js +60 -11
- package/vue/chunks/UiDialog.js +1 -1
- package/vue/chunks/UiIcon.js +5 -1
- package/vue/chunks/UiIconButton.js +1 -1
- package/vue/chunks/UiMenu.js +1 -1
- package/vue/chunks/UiNumberInput.js +31 -2
- package/vue/chunks/UiPopover.js +1 -1
- package/vue/chunks/UiSlider.js +33 -2
- package/vue/chunks/UiTooltip.js +1 -1
- package/vue/chunks/UiTreeItem.js +3 -3
- package/vue/chunks/compact.js +1 -1
- package/vue/components.css +457 -84
- package/vue/editor/index.js +109 -57
- package/docs/examples/ui-editor-footnote-editor/examples/01-note.behavior.js +0 -9
- package/docs/examples/ui-editor-mention-menu/examples/00-preview.behavior.js +0 -1
- package/docs/examples/ui-editor-slash-menu/examples/00-preview.behavior.js +0 -81
- package/docs/examples/ui-editor-table-overlay/examples/00-preview.behavior.js +0 -24
|
@@ -16,39 +16,39 @@ export function customizerResource(site, input = defaultRecipe()) {
|
|
|
16
16
|
const example = examples.find(item => item.tag === tag && (!suffix || item.id.endsWith(suffix))) ?? examples.find(item => item.tag === tag);
|
|
17
17
|
return example ? `<looma-example-card ${previewOnly ? 'preview-only' : ''} ${cardFields.filter(key => key !== 'id').map(key => `${key.replace(/[A-Z]/g, letter => '-' + letter.toLowerCase())}="${escape(String(example[key]))}"`).join(' ')} identity="${escape(example.id)}">${previewMarkup(site.catalog.components.flatMap(component => component.examples).find(item => item.id === example.id), `customizer-${specimen++}-${exampleKey(example.id)}`, site.base, example.category === 'layout')}</looma-example-card>` : '';
|
|
18
18
|
};
|
|
19
|
+
const help = (id, label, description, inline = false) => `<span${inline ? ' class="inline-help"' : ' slot="labelAction"'}><ui-icon-button id="help-${id}" size="sm" label="About ${escape(label)}"><ui-icon name="help"></ui-icon></ui-icon-button><ui-tooltip for="help-${id}" trigger="click">${escape(description)}</ui-tooltip></span>`;
|
|
20
|
+
const shortLabels = { 'body-font':'Font', 'display-font':'Heading font', 'label-size':'Field labels', 'secondary-action':'Secondary', 'tertiary-action':'Tertiary', 'selection-accent':'Selection', 'focus-accent':'Focus', 'link-accent':'Links', 'neutral-source':'Source', 'neutral-strength':'Strength', 'neutral-border-contrast':'Border contrast', 'success-source':'Success', 'danger-source':'Error', 'warning-source':'Warning', 'info-source':'Info', 'status-chroma':'Status chroma', 'control-roominess':'Roominess', 'surface-separation':'Rim width', 'corner-roundness':'Roundness' };
|
|
21
|
+
const setting = (field, control, id = `theme-${field.id}`) => `<div class="setting${field.type.includes('colour') ? ' color-setting' : field.type === 'easing' ? ' curve-setting' : ''}"><ui-form-field><label slot="label" for="${id}">${escape(shortLabels[field.id] ?? field.label)}</label>${['action','canvas','surface','text','secondary-action','tertiary-action'].includes(field.id) ? '' : help(field.id, field.label, field.description)}${control}</ui-form-field></div>`;
|
|
19
22
|
const renderField = field => {
|
|
20
23
|
const value = recipe.values[field.id];
|
|
21
24
|
if (field.id === 'label-size') {
|
|
22
25
|
const inherited = value === 'inherit', size = inherited ? recipe.values['text-size'] : value;
|
|
23
|
-
return
|
|
26
|
+
return setting(field, `<ui-stack gap="xs"><ui-select id="theme-label-source" size="sm" data-label-size-source value="${inherited ? 'inherit' : 'custom'}"><option value="inherit">Follow body</option><option value="custom">Set a separate size</option></ui-select><ui-number-input compact id="theme-label-size" size="sm" data-label-size-value label="Independent field label size" value="${escape(size)}" unit="${size.match(/[a-z]+$/i)?.[0] ?? 'px'}" min="0.1" step="1"${inherited ? ' hidden' : ''}></ui-number-input></ui-stack>`, 'theme-label-source');
|
|
24
27
|
}
|
|
25
28
|
if (field.type === 'optional-colour') {
|
|
26
|
-
|
|
27
|
-
const fallback = recipe.values.action;
|
|
28
|
-
return `<ui-form-field><label slot="label" for="theme-${field.id}-source">${escape(field.label)}</label><span slot="help">${escape(field.description)}</span><ui-stack gap="xs"><ui-select id="theme-${field.id}-source" size="sm" data-color-source="${field.id}" value="${custom ? 'custom' : 'default'}"><option value="default">Not used</option><option value="custom">Choose a color</option></ui-select><ui-color-picker id="theme-${field.id}" data-token="${field.id}" data-optional-color="${field.id}" value="${escape(custom ? value : fallback)}" label="${escape(field.label)} colour picker"${custom ? '' : ' hidden'}></ui-color-picker></ui-stack></ui-form-field>`;
|
|
29
|
+
return setting(field, `<ui-color-picker id="theme-${field.id}" size="sm" clearable data-token="${field.id}" data-optional-color="${field.id}" value="${escape(value === field.defaultValue ? '' : value)}" label="${escape(field.label)} colour picker"></ui-color-picker>`);
|
|
29
30
|
}
|
|
30
31
|
const editor = valueEditor(field, value, { remPixels: parseFloat(recipe.values['text-size']) });
|
|
31
|
-
const common = `size="sm" data-token="${field.id}" label="${escape(field.label)}"`;
|
|
32
|
+
const common = `size="sm" aria-label="${escape(field.label)}" data-token="${field.id}" label="${escape(field.label)}"`;
|
|
32
33
|
let control;
|
|
33
34
|
if (field.type === 'font') {
|
|
34
35
|
const selected = field.id === 'display-font' && value === recipe.values['body-font'] ? 'inherit' : recipe.fonts?.[field.id] ?? (value === systemFont ? 'system' : 'custom');
|
|
35
|
-
control = `<ui-combobox id="theme-${field.id}" data-font-picker="${field.id}" label="${escape(field.label)}" value="${escape(selected)}" placeholder="Search Google Fonts…" disclosure>${field.id === 'display-font' ? '<option value="inherit">
|
|
36
|
+
control = `<ui-combobox id="theme-${field.id}" size="sm" data-font-picker="${field.id}" label-visibility="sr-only" label="${escape(field.label)}" value="${escape(selected)}" placeholder="Search Google Fonts…" disclosure><template slot="option"><span class="font-option" from:data-font-preview="$option.value">{$option.label}</span></template>${field.id === 'display-font' ? '<option value="inherit">Follow body</option>' : ''}<option value="system">System font</option><option value="custom" disabled>${escape(value.split(',')[0].replaceAll('"', '').trim())}</option>${Object.values(googleFonts).map(font => `<option value="${escape(font.family)}">${escape(font.family)}</option>`).join('')}</ui-combobox><ui-text variant="caption" data-font-status="${field.id}" role="status" hidden></ui-text>`;
|
|
36
37
|
} else if (field.type === 'choice') {
|
|
37
38
|
control = `<ui-select id="theme-${field.id}" ${common} value="${escape(value)}">${Object.entries(field.choices).map(([id,label]) => `<option value="${id}">${escape(label)}</option>`).join('')}</ui-select>`;
|
|
38
39
|
} else if (field.type === 'easing') {
|
|
39
40
|
control = `<ui-input id="theme-${field.id}" size="sm" data-token="${field.id}" aria-label="${escape(field.label)}" value="${escape(value)}"></ui-input><div data-curve-for="${field.id}"${editor.kind === 'text' ? ' hidden' : ''}><ui-curve-editor ${common} data-editor-kind="curve" value="${escape(value)}"></ui-curve-editor></div>`;
|
|
40
41
|
} else if (editor.kind === 'number' || editor.kind === 'slider') {
|
|
41
42
|
const tag = editor.kind === 'slider' ? 'ui-slider' : 'ui-number-input';
|
|
42
|
-
const numeric = `<${tag} id="theme-${field.id}" ${common} data-editor-kind="${editor.kind}" value="${escape(editor.value)}" unit="${editor.unit}" min="${editor.min}" max="${editor.max}" step="${editor.step}"></${tag}>`;
|
|
43
|
+
const numeric = `<${tag} compact id="theme-${field.id}" ${common} data-editor-kind="${editor.kind}" value="${escape(editor.value)}" unit="${editor.unit}" min="${editor.min}" max="${editor.max}" step="${editor.step}"></${tag}>`;
|
|
43
44
|
control = editor.units ? `<ui-cluster wrap="nowrap" gap="xs">${numeric}<ui-select size="sm" style="--ui-select-inline-size: auto" data-unit-for="${field.id}" aria-label="${escape(field.label)} unit" value="${editor.unit}">${[...new Set([...editor.units, editor.unit])].map(unit => `<option value="${unit}">${unit}</option>`).join('')}</ui-select></ui-cluster>` : numeric;
|
|
44
45
|
} else {
|
|
45
|
-
control = field.type === 'colour' ? `<ui-color-picker id="theme-${field.id}" data-token="${field.id}" value="${escape(value)}" label="${escape(field.label)} colour picker"></ui-color-picker>` : `<ui-input id="theme-${field.id}" ${common} value="${escape(value)}"></ui-input>`;
|
|
46
|
+
control = field.type === 'colour' ? `<ui-color-picker id="theme-${field.id}" data-token="${field.id}" value="${escape(value)}" size="sm" label="${escape(field.label)} colour picker"></ui-color-picker>` : `<ui-input id="theme-${field.id}" ${common} value="${escape(value)}"></ui-input>`;
|
|
46
47
|
}
|
|
47
|
-
|
|
48
|
-
return `<ui-form-field><label slot="label" for="theme-${field.id}">${escape(field.label)}</label><span slot="help">${escape(field.description)}</span>${control}</ui-form-field>`;
|
|
48
|
+
return setting(field, control);
|
|
49
49
|
};
|
|
50
50
|
const swatches = tokens => `<span class="palette-swatches" aria-hidden="true">${['--ui-accent','--ui-neutral-surface','--ui-surface','--ui-text'].map(token => `<span style="background:${escape(tokens ? tokens[token] : `var(${token})`)}"></span>`).join('')}</span>`;
|
|
51
|
-
const choice = (attributes, label, value, options, content = '') => `<ui-combobox ${attributes} data-choice label="${escape(label)}" value="${escape(value)}" disclosure open-on-focus>${options}${content}</ui-combobox>`;
|
|
51
|
+
const choice = (attributes, label, value, options, content = '') => `<ui-combobox ${attributes} size="sm" data-choice label="${escape(label)}" value="${escape(value)}" disclosure open-on-focus>${options}${content}</ui-combobox>`;
|
|
52
52
|
const renderPreset = (family, location) => {
|
|
53
53
|
const presets = { material: materialPresets, palette: themePalettes, status: statusPresets }[family];
|
|
54
54
|
const state = refinementState(recipe, family), label = { material: 'Material preset', palette: 'Palette preset', status: 'Status color relationship' }[family];
|
|
@@ -67,40 +67,35 @@ export function customizerResource(site, input = defaultRecipe()) {
|
|
|
67
67
|
].map(([id,label,description]) => `<ui-button variant="card" tone="neutral" data-action="palette-relationship" data-relationship="${id}" aria-pressed="${recipe.values['palette-relationship'] === id}"><ui-stack gap="xs"><ui-text variant="label">${label}</ui-text><span class="palette-range" data-relationship-preview="${id}" aria-hidden="true"><span class="palette-canvas"></span><span class="palette-content"></span><span class="palette-action"></span></span><ui-text variant="caption">${description}</ui-text></ui-stack><span slot="action" data-relationship-selected="${id}"${recipe.values['palette-relationship'] === id ? '' : ' hidden'}><ui-icon name="check"></ui-icon></span></ui-button>`).join('')}</ui-stack>`;
|
|
68
68
|
const sizePreview = `<ui-stack gap="l"><ui-text size="md">Compare the same actions and fields at each size. Rhythm separates these groups and opens the lines of text; spacing adjusts the room between controls.</ui-text><ui-stack gap="xl" data-size-groups>${['sm','md','lg'].map((size,index) => `<ui-stack gap="s" data-size-sample="${size}"><ui-text weight="medium" size="md">${['Small','Medium','Large'][index]}<span data-size-readout></span></ui-text><ui-cluster data-size-actions><ui-button size="${size}" variant="solid" tone="accent">Create</ui-button><ui-button size="${size}" variant="outline" tone="accent">Save</ui-button><ui-button size="${size}" variant="outline" tone="neutral">Archive</ui-button></ui-cluster><ui-cluster><ui-input size="${size}" style="--ui-input-inline-size: 10ch" aria-label="${size} size sample" value="Frodo"></ui-input><ui-color-picker size="${size}" label="${size} swatch sample"></ui-color-picker></ui-cluster></ui-stack>`).join('')}</ui-stack><ui-card><ui-stack gap="s"><ui-text weight="medium" size="md">Grouped content</ui-text><ui-text size="md">Frodo plans the journey. Sam brings lunch. A longer paragraph makes the line rhythm visible alongside the space between groups.</ui-text></ui-stack></ui-card><div class="spacing-samples" data-spacing-samples role="img" aria-label="Spacing progression"><span></span><span></span><span></span><span></span></div></ui-stack>`;
|
|
69
69
|
const fieldsFor = ids => ids.map(id => renderField(themeFields.find(field => field.id === id))).join('');
|
|
70
|
-
const viewTitles = { material: 'Material & light', palette: 'Palette', typography: 'Typography', layout: 'Size & spacing', motion: 'Motion',
|
|
71
|
-
const refinement = (family, content) => `<section id="${family}" data-refinement-view="${family}" hidden tabindex="-1" aria-label="${viewTitles[family]} editor"><ui-stack gap="l"><ui-
|
|
72
|
-
const editor = (family, preview, controls) => refinement(family, `<div class="refinement-layout"><div class="editor-preview" data-editor-preview="${family}">${preview}</div
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
const
|
|
70
|
+
const viewTitles = { material: 'Material & light', palette: 'Palette', typography: 'Typography', layout: 'Size & spacing', motion: 'Motion', export: 'Export & save', components: 'Component library' };
|
|
71
|
+
const refinement = (family, content) => `<section id="${family}" data-refinement-view="${family}" hidden tabindex="-1" aria-label="${viewTitles[family]} editor"><ui-stack gap="l"><ui-text variant="heading" as="h2">${viewTitles[family]}</ui-text>${content}</ui-stack></section>`;
|
|
72
|
+
const editor = (family, preview, controls) => refinement(family, `<div class="refinement-layout"><div class="controls-panel"><ui-card padding="sm"><div class="settings-grid">${controls}</div></ui-card></div><div class="editor-preview" data-editor-preview="${family}">${preview}</div></div>`);
|
|
73
|
+
const customFontStacks = `<div class="settings-section"><ui-disclosure summary="Custom font stacks"><div class="settings-grid">${['body-font','display-font'].map(id=>`<ui-form-field><label slot="label" for="theme-${id}-custom">${id === 'body-font' ? 'Font' : 'Heading font'} stack</label><ui-input id="theme-${id}-custom" size="sm" data-token="${id}" value="${escape(recipe.values[id])}" aria-label="${id === 'body-font' ? 'Font' : 'Heading font'} stack"></ui-input></ui-form-field>`).join('')}</div></ui-disclosure></div>`;
|
|
74
|
+
const typographyView = editor('typography', `<ui-card><ui-stack><ui-text variant="heading" as="h2">There and back again.</ui-text><ui-text>Frodo plans the journey. Sam brings lunch. Clear notes keep the Fellowship moving.</ui-text><ui-form-field><label slot="label" for="type-sample-name">Memo title</label><ui-input id="type-sample-name" value="There and back again"></ui-input><span slot="help">Shown above your notes.</span></ui-form-field><ui-text variant="caption">Notes by Sméagol · Updated today</ui-text></ui-stack></ui-card>`, `<div class="settings-section"><div class="settings-grid">${fieldsFor(['body-font','display-font'])}</div></div>${fieldsFor(['text-size','label-size','text-weight'])}${customFontStacks}`);
|
|
75
|
+
const layoutView = editor('layout', `<ui-stack>${sizePreview}</ui-stack>`, `${fieldsFor(['control-roominess','rhythm','spacing','corner-roundness'])}${fieldsFor(['scale-contrast','space-curve','line-weight'])}`);
|
|
76
|
+
const motionView = editor('motion', `<ui-stack><ui-card><ui-stack><ui-text variant="eyebrow">Motion study</ui-text><div class="motion-track"><span data-motion-object aria-hidden="true"></span></div><ui-cluster><ui-button data-action="replay-motion"><ui-icon name="play"></ui-icon>Replay motion</ui-button><ui-text variant="caption" data-motion-readout></ui-text></ui-cluster><ui-text variant="caption" data-motion-preference></ui-text></ui-stack></ui-card></ui-stack>`, `${fieldsFor(['response-time'])}<div class="settings-section"><ui-disclosure summary="Shape the curve"><ui-stack>${fieldsFor(['response-curve'])}</ui-stack></ui-disclosure></div><div class="settings-section"><ui-cluster gap="xs"><ui-text weight="medium">Motion preview</ui-text>${help('motion-preview','motion preview','Replay shows the shared curve. The popover demonstrates it in a real component. System reduced-motion preferences are respected.',true)}</ui-cluster></div><div class="settings-section"><ui-disclosure summary="Try a popover">${documentationCard('ui-popover', null, true)}</ui-disclosure></div>`);
|
|
76
77
|
const materialSurfaces = `<ui-grid columns="2" min="sm"><ui-card variant="elevated" data-material-standard><ui-stack gap="s"><ui-text weight="medium" size="md">Everyday surface</ui-text><ui-text variant="caption">A restrained lift for ordinary content.</ui-text><ui-button variant="outline" tone="neutral">Read memo</ui-button></ui-stack></ui-card><ui-card variant="elevated" treatment="expressive" data-material-expressive><ui-stack gap="s"><ui-text weight="medium" size="md">Expressive surface</ui-text><ui-text variant="caption">Finish, edge light, glow and the decorative rim.</ui-text><ui-button variant="solid" tone="accent">Join briefing</ui-button></ui-stack></ui-card></ui-grid><ui-cluster><ui-button id="material-popover-trigger" variant="outline" tone="accent">Open popover</ui-button><ui-popover for="material-popover-trigger"><ui-stack gap="s"><ui-text size="md">Floating material</ui-text><ui-text variant="caption">Adjust glass, separation and translucency with this open.</ui-text></ui-stack></ui-popover><ui-button id="material-dialog-trigger" variant="outline" tone="neutral">Open dialog</ui-button><ui-dialog id="material-preview-dialog" for="material-dialog-trigger" label="Surface and light"><ui-text size="md">Compare the backdrop, content plane and frame as the material changes.</ui-text><ui-button slot="actions" variant="solid" commandfor="material-preview-dialog" command="close">Done</ui-button></ui-dialog></ui-cluster>`;
|
|
77
|
-
const materialSample = `<ui-card treatment="expressive"><ui-stack gap="m"><ui-text variant="heading" as="h3">Fellowship briefing</ui-text><ui-text>
|
|
78
|
+
const materialSample = `<ui-card treatment="expressive"><ui-stack gap="m"><ui-text variant="heading" as="h3">Fellowship briefing</ui-text><ui-text>Content stays readable while the rim reveals the scene.</ui-text><ui-input label="Office search" placeholder="Search the Fellowship office"></ui-input><ui-action-bar><ui-button slot="secondary" preset="standard">Keep draft</ui-button><ui-button slot="primary" preset="primary">Send briefing</ui-button></ui-action-bar></ui-stack></ui-card>`;
|
|
78
79
|
const lightEditor = `<ui-light-editor data-light-editor x="${recipe.values['light-x']}" y="${recipe.values['light-y']}" label="Theme light position"><ui-stack gap="s"><ui-text variant="heading">Move the light</ui-text><ui-button preset="primary">Material response</ui-button></ui-stack></ui-light-editor>`;
|
|
79
|
-
const materialView = editor('material', `<ui-stack>${materialSample}${materialSurfaces}</ui-stack>`, `<ui-cluster>${renderPreset('material', 'refinement')}<ui-button data-action="restore-material"
|
|
80
|
+
const materialView = editor('material', `<ui-stack>${materialSample}${materialSurfaces}</ui-stack>`, `<div class="settings-section"><ui-cluster align="end">${renderPreset('material', 'refinement')}<ui-button size="sm" data-action="restore-material" aria-label="Reset material">Reset</ui-button></ui-cluster></div>${fieldsFor(['finish','translucency','glassiness'])}<div class="settings-section"><ui-cluster gap="xs"><ui-text weight="medium">Lighting</ui-text><ui-icon-button id="help-lighting" size="sm" label="About lighting"><ui-icon name="help"></ui-icon></ui-icon-button><ui-tooltip for="help-lighting" trigger="click"><span data-material-dependencies></span></ui-tooltip></ui-cluster></div><ui-stack gap="s" data-glass-hint hidden><ui-text variant="caption">No transmission to blur.</ui-text><ui-button size="sm" data-action="use-glass">Use frosted glass</ui-button></ui-stack><div class="settings-section">${lightEditor}<div class="settings-grid">${fieldsFor(['light-color','light-spread','light-strength','edge-light','glow','outer-depth','inner-depth','surface-separation'])}</div></div><div class="settings-section"><ui-disclosure summary="Try floating surfaces"><ui-stack>${documentationCard('ui-card','/04-expressive-surface')}${documentationCard('ui-tooltip')}${documentationCard('ui-popover')}${documentationCard('ui-dialog')}</ui-stack></ui-disclosure></div>`);
|
|
80
81
|
const statusControls = ['success','danger','warning','info'].map(role => fieldsFor([role + '-source'])).join('');
|
|
81
|
-
const paletteView = refinement('palette', `<ui-cluster>${renderPreset('palette', 'refinement')}<ui-button data-action="restore-palette"
|
|
82
|
+
const paletteView = refinement('palette', `<div class="refinement-layout"><div class="controls-panel"><ui-card padding="sm"><ui-stack gap="s"><ui-cluster align="end">${renderPreset('palette', 'refinement')}<ui-button size="sm" data-action="restore-palette" aria-label="Reset palette">Reset</ui-button></ui-cluster><ui-cluster gap="xs"><ui-text weight="medium">Base colors</ui-text>${help('base-colors','base colors',['action','canvas','surface','text'].map(id => { const f=themeFields.find(field=>field.id===id); return f.label+': '+f.description; }).join(' '),true)}</ui-cluster><div class="color-row" data-base-colors>${fieldsFor(['action','canvas','surface','text'])}</div><ui-cluster gap="xs"><ui-text weight="medium">Supporting accents</ui-text>${help('supporting-colors','supporting accents','Optional second and third accents. Choose None inside a picker to leave it unset. Components use these only when that accent is chosen.',true)}</ui-cluster><div class="color-row" data-supporting-colors>${fieldsFor(['secondary-action','tertiary-action'])}</div><ui-text weight="medium">Use colors for</ui-text><div class="settings-grid">${fieldsFor(['selection-accent','focus-accent','link-accent'])}</div><ui-text weight="medium">Neutrals & borders</ui-text><div class="settings-grid">${fieldsFor(['neutral-source','neutral-strength','neutral-border-contrast'])}</div><ui-text weight="medium">Status colors</ui-text><ui-cluster>${renderPreset('status', 'refinement')}<ui-button size="sm" data-action="restore-status" aria-label="Reset status colors">Reset</ui-button></ui-cluster><div class="settings-grid">${statusControls}${fieldsFor(['status-chroma'])}</div><ui-disclosure summary="Color character"><div class="settings-grid">${fieldsFor(['warmth','color-intensity'])}</div>${paletteRelationships}</ui-disclosure></ui-stack></ui-card></div><div class="palette-preview"><ui-stack>${paletteDetails}</ui-stack></div></div>`);
|
|
82
83
|
const options = site.catalog.groups.map(group => `<optgroup label="${escape(group.label)}">${examples.filter(example => example.category === group.id).map(example => `<option value="${escape(example.id)}" data-description="${escape(example.category + ' · ' + example.tag)}" data-example="${escape(JSON.stringify(example))}" data-search="${escape(`${example.title} ${example.tag} ${example.description} ${example.exampleTitle}`.toLocaleLowerCase())}">${escape(example.title)} · ${escape(example.exampleTitle)}</option>`).join('')}</optgroup>`).join('');
|
|
83
|
-
const links = ['ui-action-bar','ui-stack','ui-grid','ui-cluster','ui-form-field','ui-input','ui-select','ui-color-picker','ui-button','ui-disclosure','ui-textarea','ui-number-input','ui-slider','ui-curve-editor','ui-card','ui-text','ui-light-editor','ui-combobox','ui-checkbox','ui-badge','ui-icon','ui-callout','ui-popover','ui-dialog','ui-list','ui-list-item'].map(tag => `<link rel="component" href="@threadlabs/looma/components/${tag}/${tag}.html">`).join('\n');
|
|
84
|
+
const links = ['ui-menu','ui-menu-item','ui-tooltip','ui-icon-button','ui-action-bar','ui-stack','ui-grid','ui-cluster','ui-form-field','ui-input','ui-select','ui-color-picker','ui-button','ui-disclosure','ui-textarea','ui-number-input','ui-slider','ui-curve-editor','ui-card','ui-text','ui-light-editor','ui-combobox','ui-checkbox','ui-badge','ui-icon','ui-callout','ui-popover','ui-dialog','ui-list','ui-list-item'].map(tag => `<link rel="component" href="@threadlabs/looma/components/${tag}/${tag}.html">`).join('\n');
|
|
84
85
|
return `${links}\n${exampleResources(site.catalog.components.flatMap(component => component.examples), site.catalog)}\n<link rel="component" href="./card.html">\n<link rel="component" href="./preview-choice.html">\n<template component="looma-customizer" module="./customizer.js"><defs>
|
|
85
86
|
<state name="previews" type="list" value="${escape(JSON.stringify(initial))}"><prop type="object">${cardFields.map(name => `<prop name="${name}" required type="${name === 'resizable' ? 'boolean' : 'string'}"></prop>`).join('')}</prop></state>
|
|
86
87
|
<state name="cards" type="list" value="${escape(JSON.stringify(initial))}"><prop type="object">${cardFields.map(name => `<prop name="${name}" required type="${name === 'resizable' ? 'boolean' : 'string'}"></prop>`).join('')}</prop></state>
|
|
87
88
|
</defs>
|
|
88
89
|
<div data-looma-customizer data-recipe="${escape(JSON.stringify(recipe))}" data-base="${escape(site.base)}" data-mode="${site.config.local ? 'local' : 'public'}" data-revision="${escape(site.config.revision ?? '')}">
|
|
89
90
|
<ui-stack gap="l">
|
|
90
|
-
<ui-
|
|
91
|
-
<ui-stack gap="xs"><ui-text variant="eyebrow">Theme changes</ui-text><ui-cluster><ui-button size="sm" data-action="undo" disabled>Undo</ui-button><ui-button size="sm" data-action="redo" disabled>Redo</ui-button><ui-button size="sm" data-action="reset" title="Restore this theme’s starting values">Reset</ui-button></ui-cluster></ui-stack>
|
|
91
|
+
<div class="summary-panel" data-customizer-summary><ui-card padding="sm"><div class="summary-toolbar"><div class="summary-theme">${choice('id="theme-start" data-preset label-visibility="sr-only"', 'Starting point', startingPointFor(recipe), `<option value="custom" disabled>Your theme</option>${Object.entries(startingPointLabels).map(([id,label]) => `<option value="${id}">${label}</option>`).join('')}`)}</div><nav aria-label="Theme controls" class="summary-sections">${[['palette','Palette'],['material','Material'],['typography','Type'],['layout','Size'],['motion','Motion']].map(([id,label]) => `<div class="summary-choice"><ui-button variant="ghost" tone="neutral" size="sm" data-action="refine-${id}" aria-label="${label}"><ui-stack gap="xs"><span class="summary-heading">${id === 'palette' ? swatches() : ''}<span>${label}</span></span><span data-summary="${id}" class="summary-value"></span></ui-stack></ui-button></div>`).join('')}</nav><div class="summary-actions"><ui-cluster gap="xs" wrap="nowrap"><ui-icon-button id="theme-undo" size="sm" data-action="undo" label="Undo" disabled><ui-icon name="undo"></ui-icon></ui-icon-button><ui-tooltip for="theme-undo">Undo</ui-tooltip><ui-icon-button id="theme-redo" size="sm" data-action="redo" label="Redo" disabled><ui-icon name="redo"></ui-icon></ui-icon-button><ui-tooltip for="theme-redo">Redo</ui-tooltip><ui-button size="sm" data-action="reset">Reset</ui-button><ui-icon-button id="theme-tools" size="sm" label="Theme tools"><ui-icon name="ellipsis"></ui-icon></ui-icon-button><ui-menu for="theme-tools" label="Theme tools"><ui-menu-item data-action="back">Overview</ui-menu-item><ui-menu-item data-action="refine-components">Components</ui-menu-item><ui-menu-item data-action="refine-export">Export & save</ui-menu-item></ui-menu></ui-cluster></div><span class="summary-active-value" data-active-summary></span><span class="summary-status" role="status" aria-live="polite" data-message></span></div></ui-card></div>
|
|
92
92
|
${materialView}${paletteView}${typographyView}${layoutView}${motionView}
|
|
93
|
-
${refinement('themes', `<ui-stack>${choice('id="theme-start" data-preset', 'Starting point', startingPointFor(recipe), `<option value="custom" disabled>Your theme</option>${Object.entries(startingPointLabels).map(([id,label]) => `<option value="${id}">${label}</option>`).join('')}`)}<ui-text variant="caption">A starting theme coordinates color, typography, space, material, and motion. Refine any of them from the overview.</ui-text>${documentationCard('ui-cluster', '/99-theme-sampler', true)}</ui-stack>`)}
|
|
94
93
|
${refinement('export', `<ui-stack><ui-cluster><ui-button data-action="css" variant="solid">Download CSS</ui-button><ui-button data-action="recipe">Download recipe</ui-button><ui-button data-action="import">Import recipe</ui-button></ui-cluster>
|
|
95
94
|
<input type="file" accept="application/json,.json" hidden data-recipe-file>
|
|
96
95
|
<ui-button data-action="save" variant="solid" hidden>Save to repository</ui-button>
|
|
97
96
|
<ui-disclosure summary="Use your theme"><ui-text>Every export includes light and dark. Leave data-theme off the page to follow system preference, or set it to light or dark on the page or a section. <a href="${escape(site.base)}design-system/">Installation and mode guidance</a></ui-text></ui-disclosure>
|
|
98
97
|
<ui-disclosure summary="Theme CSS"><ui-textarea data-css readonly rows="12" aria-label="Generated theme CSS" value="${escape(themeCSS(recipe))}"></ui-textarea></ui-disclosure></ui-stack>`)}
|
|
99
98
|
<div class="customizer-layout" data-customizer-overview>
|
|
100
|
-
<aside aria-label="Theme controls"><ui-stack gap="s"><ui-button variant="card" data-action="refine-themes"><ui-stack gap="xs"><ui-text variant="eyebrow">Starting theme</ui-text><ui-text variant="heading" data-theme-summary></ui-text></ui-stack></ui-button>
|
|
101
|
-
<ui-list>${[['palette','Palette','Colors for light & dark'],['material','Material & light','Surface character'],['typography','Typography','Fonts & readable type'],['layout','Size & spacing','Proportions & breathing room'],['motion','Motion','Pace & response']].map(([id,label,description]) => `<ui-list-item wrap>${id === 'palette' ? `<span slot="leading">${swatches()}</span>` : ''}<a href="#${id}" data-action="refine-${id}">${label}</a><span slot="description" data-summary="${id}">${description}</span><ui-icon slot="trailing" name="chevron-right"></ui-icon></ui-list-item>`).join('')}</ui-list>
|
|
102
|
-
<ui-cluster><ui-button data-action="refine-components">Browse components</ui-button><ui-button data-action="refine-export">Export & save</ui-button></ui-cluster>
|
|
103
|
-
</ui-stack></aside>
|
|
104
99
|
<section data-theme-sampler><ui-stack gap="xs"><ui-text variant="heading" as="h2">Theme sampler</ui-text>${documentationCard('ui-cluster', '/99-theme-sampler', true)}</ui-stack></section>
|
|
105
100
|
<noscript>Enable JavaScript to edit the theme. The component reference and example previews remain available.</noscript>
|
|
106
101
|
</div>${refinement('components', ` <section class="examples"><ui-stack><ui-form-field><label slot="label" for="example-query">Search components</label><ui-input id="example-query" type="search" data-example-query placeholder="Name, tag or purpose"></ui-input></ui-form-field><ui-text variant="caption" role="status" aria-live="polite" data-example-count></ui-text><ui-disclosure summary="Add an example"><ui-stack><ui-combobox id="example-choice" data-add-example label="Choose a component example" placeholder="Search buttons, fields, dialogs…" disclosure clearable>${options}</ui-combobox><ui-button data-action="add" disabled>Add to preview</ui-button></ui-stack></ui-disclosure>
|
|
@@ -108,15 +103,39 @@ export function customizerResource(site, input = defaultRecipe()) {
|
|
|
108
103
|
<ui-button data-action="more-examples">Show more components</ui-button></ui-stack></section>
|
|
109
104
|
`)}</ui-stack></div>
|
|
110
105
|
<style>
|
|
111
|
-
:host { background-color: var(--ui-surface);
|
|
106
|
+
:host { background-color: var(--ui-surface); }
|
|
107
|
+
.summary-panel { container-type: inline-size; position: sticky; inset-block-start: var(--_editor-chrome-height, 4.25rem); z-index: 3; }
|
|
108
|
+
.font-option { font-family: var(--_font-preview-family, inherit); font-weight: 400; }
|
|
109
|
+
.summary-theme { inline-size: 8rem; max-inline-size: 100%; min-inline-size: 0; }
|
|
110
|
+
.summary-toolbar { display: grid !important; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center !important; gap: var(--ui-space-2) !important; }
|
|
111
|
+
.summary-sections { display: flex !important; flex-wrap: wrap !important; gap: var(--ui-space-1) !important; }
|
|
112
|
+
.summary-heading { display: flex !important; align-items: center !important; gap: var(--ui-space-2) !important; }
|
|
113
|
+
.summary-active-value { display: none; grid-column: 1 / -1; color: var(--ui-text-secondary); font-size: var(--ui-font-size-sm); }
|
|
114
|
+
.curve-setting { grid-column: 1 / -1; }
|
|
115
|
+
.summary-status { grid-column: 1 / -1; font-size: var(--ui-font-size-md); color: var(--ui-text-secondary); }
|
|
116
|
+
.summary-status:empty { display: none; }
|
|
117
|
+
.summary-choice { flex: 0 1 auto; min-inline-size: 0; }
|
|
118
|
+
.summary-value { display: block; max-inline-size: 11rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--ui-font-size-sm); color: var(--ui-text-secondary); }
|
|
119
|
+
.controls-panel { grid-column: 2; grid-row: 1; min-inline-size: 0; }
|
|
120
|
+
.refinement-layout > .editor-preview, .refinement-layout > .palette-preview { grid-column: 1; grid-row: 1; }
|
|
121
|
+
@container (max-width: 16rem) { .summary-toolbar { grid-template-columns: minmax(0, 1fr); } .summary-actions { grid-column: 1 !important; grid-row: 2 !important; } .summary-sections { grid-row: 3 !important; } }
|
|
122
|
+
.settings-grid { display: grid !important; grid-template-columns: repeat(auto-fit, minmax(min(100%, 9rem), 1fr)); gap: var(--ui-space-3) !important; align-items: start !important; }
|
|
123
|
+
.settings-section { grid-column: 1 / -1; }
|
|
124
|
+
.setting { min-inline-size: 0; }
|
|
125
|
+
[data-base-colors] { display: grid !important; grid-template-columns: repeat(auto-fit, minmax(min(100%, 4.25rem), max-content)); }
|
|
126
|
+
[data-base-colors] .color-setting { inline-size: auto; }
|
|
127
|
+
.color-row { display: flex !important; flex-wrap: wrap !important; gap: var(--ui-space-4) !important; }
|
|
128
|
+
.color-setting { inline-size: 5.25rem; }
|
|
129
|
+
[data-editor-preview="material"] { padding: var(--ui-space-4) !important; background-color: var(--ui-surface); background-image: repeating-linear-gradient(0deg, transparent 0 15px, color-mix(in srgb, var(--ui-text) 24%, transparent) 14px 16px), repeating-linear-gradient(90deg, transparent 0 15px, color-mix(in srgb, var(--ui-text) 24%, transparent) 14px 16px); }
|
|
130
|
+
@media (max-width: 40rem) { .summary-toolbar { grid-template-columns: minmax(0, 1fr) auto; } .summary-sections { grid-column: 1 / -1; grid-row: 2; flex-wrap: wrap !important; } .summary-actions { grid-column: 2; grid-row: 1; } .summary-value, .summary-heading .palette-swatches { display: none; } .summary-choice { flex: 0 1 auto; } .summary-active-value { display: block; } .summary-status { font-size: var(--ui-font-size-sm); } }
|
|
131
|
+
|
|
112
132
|
[data-customizer-overview][hidden], [data-refinement-view][hidden] { display: none !important; }
|
|
113
|
-
.customizer-layout { display: grid !important; grid-template-columns: minmax(
|
|
114
|
-
aside { grid-row: 1 / span 2; position: sticky; inset-block-start: calc(var(--_editor-chrome-height, 4.25rem) + var(--ui-space-2)); max-block-size: calc(100dvh - var(--_editor-chrome-height, 4.25rem) - var(--ui-space-4)); overflow: auto; padding: max(var(--ui-space-2), calc(var(--ui-focus-width) * 2)) !important; scroll-padding: max(var(--ui-space-2), calc(var(--ui-focus-width) * 2)); }
|
|
133
|
+
.customizer-layout { display: grid !important; grid-template-columns: minmax(0, 1fr); gap: var(--ui-space-6) !important; align-items: start !important; }
|
|
134
|
+
aside { grid-row: 1 / span 2; position: sticky; inset-block-start: calc(var(--_editor-chrome-height, 4.25rem) + var(--_customizer-summary-height, 8rem) + var(--ui-space-2)); max-block-size: calc(100dvh - var(--_editor-chrome-height, 4.25rem) - var(--ui-space-4)); overflow: auto; padding: max(var(--ui-space-2), calc(var(--ui-focus-width) * 2)) !important; scroll-padding: max(var(--ui-space-2), calc(var(--ui-focus-width) * 2)); }
|
|
115
135
|
.examples { min-inline-size: 0; }
|
|
116
|
-
.refinement-layout { display: grid !important; grid-template-columns: minmax(0, 1.
|
|
117
|
-
[data-refinement-view] { scroll-margin-block-start: calc(var(--_editor-chrome-height, 4.25rem) + var(--ui-space-2)); }
|
|
118
|
-
.palette-preview, .editor-preview { position: sticky; inset-block-start: calc(var(--_editor-chrome-height, 4.25rem) + var(--ui-space-2)); max-block-size: calc(100dvh - var(--_editor-chrome-height, 4.25rem) - var(--ui-space-4)); overflow: auto; padding: max(var(--ui-space-2), calc(var(--ui-focus-width) * 2)) !important; }
|
|
119
|
-
[data-editor-preview="material"] { background: transparent; }
|
|
136
|
+
.refinement-layout { display: grid !important; grid-template-columns: minmax(0, 1.15fr) minmax(20rem, 0.85fr); gap: var(--ui-space-6) !important; align-items: start !important; }
|
|
137
|
+
[data-refinement-view] { scroll-margin-block-start: calc(var(--_editor-chrome-height, 4.25rem) + var(--_customizer-summary-height, 8rem) + var(--ui-space-2)); }
|
|
138
|
+
.palette-preview, .editor-preview { position: sticky; inset-block-start: calc(var(--_editor-chrome-height, 4.25rem) + var(--_customizer-summary-height, 8rem) + var(--ui-space-2)); max-block-size: calc(100dvh - var(--_editor-chrome-height, 4.25rem) - var(--ui-space-4)); overflow: auto; padding: max(var(--ui-space-2), calc(var(--ui-focus-width) * 2)) !important; }
|
|
120
139
|
.spacing-samples { display: flex !important; align-items: center !important; gap: 0 !important; padding-block: var(--ui-space-3) !important; }
|
|
121
140
|
.spacing-samples > span { display: block !important; block-size: var(--ui-space-1); inline-size: var(--ui-space-1); border-radius: 50%; background: var(--ui-accent); }
|
|
122
141
|
.spacing-samples > span:nth-child(2) { margin-inline-start: var(--ui-space-2) !important; }
|
|
@@ -132,7 +151,7 @@ export function customizerResource(site, input = defaultRecipe()) {
|
|
|
132
151
|
.palette-action { background: var(--_palette-action, var(--ui-accent)); }
|
|
133
152
|
.motion-track { overflow: clip; display: flex; align-items: center; block-size: 5rem; padding: var(--ui-space-3); border-radius: var(--ui-radius-md); background: var(--ui-surface-muted); }
|
|
134
153
|
[data-motion-object] { display: block; inline-size: 2rem; block-size: 2rem; border-radius: var(--ui-radius-sm); background: var(--ui-accent-solid); box-shadow: var(--ui-action-shadow); }
|
|
135
|
-
@media (max-width: 64rem) { .customizer-layout, .refinement-layout { grid-template-columns: minmax(0, 1fr); } aside { grid-row: auto; order: 1; position: static; max-block-size: none; } .palette-preview, .editor-preview { position: sticky; inset-block-start: calc(var(--_editor-chrome-height, 4.25rem) + var(--ui-space-2)); z-index: 1; background: var(--ui-surface); max-block-size: none; overflow: visible; padding: 0 !important; } .editor-preview { position: static; } [data-theme-sampler] { order: 2; } .examples { order: 3; } }
|
|
154
|
+
@media (max-width: 64rem) { .controls-panel, .refinement-layout > .editor-preview, .refinement-layout > .palette-preview { grid-column: 1; grid-row: auto; } [data-base-colors] { gap: var(--ui-space-2) !important; } [data-base-colors] .color-setting { inline-size: auto; } .customizer-layout, .refinement-layout { grid-template-columns: minmax(0, 1fr); } aside { grid-row: auto; order: 1; position: static; max-block-size: none; } .palette-preview, .editor-preview { position: sticky; inset-block-start: calc(var(--_editor-chrome-height, 4.25rem) + var(--_customizer-summary-height, 8rem) + var(--ui-space-2)); z-index: 1; background: var(--ui-surface); max-block-size: none; overflow: visible; padding: 0 !important; } .editor-preview { position: static; } [data-theme-sampler] { order: 2; } .examples { order: 3; } }
|
|
136
155
|
@media (max-width: 64rem) { .palette-preview[data-page-flow], .editor-preview[data-page-flow] { position: static; } }
|
|
137
156
|
</style></template>`;
|
|
138
157
|
}
|
package/docs/customizer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { googleFontStack, systemFont, loadGoogleFonts } from './fonts.mjs';
|
|
1
|
+
import { googleFontStack, systemFont, loadGoogleFonts, loadGoogleFontPreview, googleFonts } from './fonts.mjs';
|
|
2
2
|
import { documentationTheme, themeEvent } from './theme-session.mjs';
|
|
3
3
|
import { componentRegistry } from '@nextwebwg/html-next/runtime';
|
|
4
|
-
import { startingPoints, startingPointFor,
|
|
4
|
+
import { startingPoints, startingPointFor, themeCSS, validateRecipe, themeFields, themePalettes, materialPresets, statusPresets, applyRefinement, refinementState, deriveTheme } from './theme.mjs';
|
|
5
5
|
|
|
6
6
|
import { valueEditor, editorValue, convertValueUnit } from './value-editors.mjs';
|
|
7
7
|
|
|
@@ -34,11 +34,10 @@ export function connect(host) {
|
|
|
34
34
|
const unitContext = () => ({ remPixels: parseFloat(view.getComputedStyle(document.documentElement).fontSize) });
|
|
35
35
|
const editorFor = (field, value) => valueEditor(field, value, { remPixels: parseFloat(recipe.values['text-size']) });
|
|
36
36
|
let boundsBase, lastLabelSize;
|
|
37
|
-
const optionalColors = new Map();
|
|
38
37
|
const updateControl = (element, value) => {
|
|
39
38
|
if (element.matches('[data-choice]')) element.dataset.selectedValue = value;
|
|
40
39
|
const field = fields.get(element.dataset.token);
|
|
41
|
-
if (field?.type === 'optional-colour' && value === field.defaultValue)
|
|
40
|
+
if (field?.type === 'optional-colour' && value === field.defaultValue) value = '';
|
|
42
41
|
if (!field || !element.dataset.editorKind) { componentRegistry.update(element, { value }); return; }
|
|
43
42
|
const editor = editorFor(field, value);
|
|
44
43
|
if (element.dataset.editorKind === 'curve') {
|
|
@@ -70,6 +69,7 @@ export function connect(host) {
|
|
|
70
69
|
const previews = [...root.querySelectorAll('[data-editor-preview], .palette-preview')];
|
|
71
70
|
let layoutFrame = 0;
|
|
72
71
|
const updatePreviewLayout = () => {
|
|
72
|
+
root.style.setProperty('--_customizer-summary-height', `${root.querySelector('[data-customizer-summary]').getBoundingClientRect().height}px`);
|
|
73
73
|
const chrome = header?.getBoundingClientRect().height ?? 0;
|
|
74
74
|
root.style.setProperty('--_editor-chrome-height', `${chrome}px`);
|
|
75
75
|
for (const preview of previews) preview.toggleAttribute('data-page-flow', preview.offsetHeight > (view.innerHeight - chrome) / 2);
|
|
@@ -93,13 +93,6 @@ export function connect(host) {
|
|
|
93
93
|
};
|
|
94
94
|
const paint = () => {
|
|
95
95
|
const values = recipe.values;
|
|
96
|
-
for (const field of themeFields.filter(field => field.type === 'optional-colour')) {
|
|
97
|
-
const value = values[field.id], custom = value !== field.defaultValue;
|
|
98
|
-
if (custom) optionalColors.set(field.id, value);
|
|
99
|
-
const picker = root.querySelector(`[data-optional-color="${field.id}"]`);
|
|
100
|
-
picker.hidden = !custom;
|
|
101
|
-
componentRegistry.update(root.querySelector(`[data-color-source="${field.id}"]`), { value: custom ? 'custom' : 'default' });
|
|
102
|
-
}
|
|
103
96
|
for (const sample of root.querySelectorAll('[data-extra-accent]')) sample.hidden = values[sample.dataset.extraAccent] === 'none';
|
|
104
97
|
for (const readout of root.querySelectorAll('[data-palette-roles]')) {
|
|
105
98
|
const { tokens } = deriveTheme(recipe, { mode: readout.dataset.paletteRoles });
|
|
@@ -112,14 +105,14 @@ export function connect(host) {
|
|
|
112
105
|
const labelValue = followsBody ? lastLabelSize ?? values['text-size'] : values['label-size'];
|
|
113
106
|
componentRegistry.update(labelSize, { value: labelValue, unit: labelValue.match(/[a-z]+$/i)?.[0] ?? 'px' });
|
|
114
107
|
componentRegistry.update(root.querySelector('[data-label-size-source]'), { value: followsBody ? 'inherit' : 'custom' });
|
|
115
|
-
root.querySelector('[data-theme-summary]').textContent = startingPointLabels[recipe.origin ?? startingPointFor(recipe)] ?? 'Your theme';
|
|
116
108
|
const summaries = {
|
|
117
|
-
palette: `${themePalettes[refinementState(recipe, 'palette').id]?.label ?? 'Custom colors'} ·
|
|
118
|
-
material: `${
|
|
109
|
+
palette: `${themePalettes[refinementState(recipe, 'palette').id]?.label ?? 'Custom colors'}${refinementState(recipe, 'palette').customized ? ' · customized' : ''}`,
|
|
110
|
+
material: `${Math.round(Number(values.finish) * 100)}% finish · ${Math.round(Number(values.translucency) * 100)}% transparent`,
|
|
119
111
|
typography: `${recipe.fonts?.['body-font'] ?? values['body-font'].split(',')[0]} · ${values['text-size']}`,
|
|
120
112
|
layout: `${Number(values.rhythm) * Number(values.spacing) < .95 ? 'Compact' : Number(values.rhythm) * Number(values.spacing) > 1.2 ? 'Relaxed' : 'Comfortable'} · ${parseFloat(values['corner-roundness']) === 0 ? 'Square' : 'Rounded'} corners`,
|
|
121
113
|
motion: `${values['response-time']} · ${values['response-curve'].startsWith('cubic-bezier') ? 'Custom curve' : values['response-curve']}`,
|
|
122
114
|
};
|
|
115
|
+
root.querySelector('[data-active-summary]').textContent = summaries[view.location.hash.slice(1)] ?? Object.values(summaries).slice(0,2).join(' · ');
|
|
123
116
|
for (const [family, text] of Object.entries(summaries)) root.querySelector(`[data-summary="${family}"]`).textContent = text;
|
|
124
117
|
root.querySelector('[data-motion-readout]').textContent = `${values['response-time']} feedback · ${parseFloat(convertValueUnit(values['response-time'], 'ms', unitContext())) * 3}ms travel`;
|
|
125
118
|
componentRegistry.update(root.querySelector('[data-action="replay-motion"]'), { disabled: motionPreference.matches });
|
|
@@ -257,7 +250,7 @@ export function connect(host) {
|
|
|
257
250
|
if (!control) return;
|
|
258
251
|
const field = fields.get(control.dataset.token);
|
|
259
252
|
const raw = event.detail?.value ?? control.value;
|
|
260
|
-
const value = control.dataset.editorKind ? editorValue(field, raw) : String(raw);
|
|
253
|
+
const value = field.type === 'optional-colour' && raw === '' ? field.defaultValue : control.dataset.editorKind ? editorValue(field, raw) : String(raw);
|
|
261
254
|
const next = refinedRecipe({ ...recipe.values, [control.dataset.token]: value });
|
|
262
255
|
try {
|
|
263
256
|
preview(next); changed = JSON.stringify(recipe) !== JSON.stringify(saved);
|
|
@@ -280,11 +273,12 @@ export function connect(host) {
|
|
|
280
273
|
if (section) refinementTrigger = root.querySelector(`[data-action="refine-${family}"]`);
|
|
281
274
|
for (const element of root.querySelectorAll('[data-refinement-view]')) element.hidden = element !== section;
|
|
282
275
|
overview.hidden = Boolean(section);
|
|
276
|
+
for (const button of root.querySelectorAll('[data-customizer-summary] [data-action^="refine-"]')) button.setAttribute('aria-pressed', String(button.dataset.action === `refine-${family}`));
|
|
283
277
|
motionAnimation?.cancel();
|
|
284
278
|
if (family === 'motion') motionSignature = undefined;
|
|
285
279
|
paint();
|
|
286
280
|
if (section) { section.focus(); section.scrollIntoView({ block: 'start' }); }
|
|
287
|
-
else { refinementTrigger?.focus({ preventScroll: true }); view.scrollTo({ top: overviewScroll, behavior: 'instant' }); }
|
|
281
|
+
else { (['refine-components','refine-export'].includes(refinementTrigger?.dataset.action) ? root.querySelector('#theme-tools') : refinementTrigger)?.focus({ preventScroll: true }); view.scrollTo({ top: overviewScroll, behavior: 'instant' }); }
|
|
288
282
|
};
|
|
289
283
|
const navigate = family => {
|
|
290
284
|
flush();
|
|
@@ -302,9 +296,10 @@ export function connect(host) {
|
|
|
302
296
|
case 'replay-motion': replayMotion(); break;
|
|
303
297
|
case 'undo': case 'redo':
|
|
304
298
|
theme?.[button.dataset.action](); show(theme?.recipe ?? recipe, false); sayApplied('Previous theme decision restored.'); break;
|
|
305
|
-
case 'refine-material': case 'refine-palette': case 'refine-typography': case 'refine-layout': case 'refine-motion': case 'refine-
|
|
299
|
+
case 'refine-material': case 'refine-palette': case 'refine-typography': case 'refine-layout': case 'refine-motion': case 'refine-export': case 'refine-components': {
|
|
306
300
|
const family = button.dataset.action.slice(7);
|
|
307
|
-
refinementTrigger = button;
|
|
301
|
+
refinementTrigger = button;
|
|
302
|
+
if (!root.querySelector('[data-customizer-overview]').hidden) overviewScroll = view.scrollY;
|
|
308
303
|
navigate(family);
|
|
309
304
|
break;
|
|
310
305
|
}
|
|
@@ -362,16 +357,9 @@ export function connect(host) {
|
|
|
362
357
|
const change = async event => {
|
|
363
358
|
const value = event.detail?.value ?? event.target.value;
|
|
364
359
|
if (event.target.matches('[data-light-editor], [data-label-size-value]') || event.target.closest?.('[data-token]')) {
|
|
365
|
-
input(event); flush(); sayApplied('
|
|
360
|
+
input(event); flush(); sayApplied('Saved in this browser.'); return;
|
|
366
361
|
}
|
|
367
362
|
flush();
|
|
368
|
-
if (event.target.matches('[data-color-source]')) {
|
|
369
|
-
const field = fields.get(event.target.dataset.colorSource);
|
|
370
|
-
const fallback = recipe.values.action;
|
|
371
|
-
show(refinedRecipe({ ...recipe.values, [field.id]: value === 'default' ? field.defaultValue : optionalColors.get(field.id) ?? fallback }));
|
|
372
|
-
sayApplied(`${field.label} updated and remembered in this browser.`);
|
|
373
|
-
return;
|
|
374
|
-
}
|
|
375
363
|
if (event.target.matches('[data-label-size-source]')) {
|
|
376
364
|
show(refinedRecipe({ ...recipe.values, 'label-size': value === 'inherit' ? 'inherit' : lastLabelSize ?? recipe.values['text-size'] }));
|
|
377
365
|
sayApplied('Field label size updated and remembered in this browser.');
|
|
@@ -392,9 +380,9 @@ export function connect(host) {
|
|
|
392
380
|
show(applyRefinement(recipe, family, value));
|
|
393
381
|
sayApplied(`${{ material: 'Material', palette: 'Coordinated palette', status: 'Status color relationship' }[family]} preset applied and remembered in both modes.`);
|
|
394
382
|
}
|
|
395
|
-
if (event.target.matches('[data-preset]')) { show({ ...structuredClone(startingPoints[value]), origin: value }); sayApplied('
|
|
383
|
+
if (event.target.matches('[data-preset]')) { show({ ...structuredClone(startingPoints[value]), origin: value }); sayApplied('Saved in this browser.'); }
|
|
396
384
|
if (event.target === file && file.files[0]) {
|
|
397
|
-
try { show(JSON.parse(await file.files[0].text())); sayApplied('Recipe applied
|
|
385
|
+
try { show(JSON.parse(await file.files[0].text())); sayApplied('Recipe applied. Saved in this browser.'); }
|
|
398
386
|
catch (error) { say(error.message, true); }
|
|
399
387
|
file.value = '';
|
|
400
388
|
}
|
|
@@ -433,14 +421,14 @@ export function connect(host) {
|
|
|
433
421
|
const next = { ...refinedRecipe({ ...recipe.values, [id]: value }), fonts };
|
|
434
422
|
if (id === 'display-font' && family === 'inherit' && fonts['body-font']) next.fonts['display-font'] = fonts['body-font'];
|
|
435
423
|
const status = root.querySelector(`[data-font-status="${id}"]`), request = ++fontRequest;
|
|
436
|
-
show(next); status.textContent = family === 'inherit' ? 'Headings use the main font.' : family === 'system' ? 'Using your operating system’s native font.' : `Loading ${family} from Google Fonts…`;
|
|
424
|
+
show(next); status.hidden = false; status.textContent = family === 'inherit' ? 'Headings use the main font.' : family === 'system' ? 'Using your operating system’s native font.' : `Loading ${family} from Google Fonts…`;
|
|
437
425
|
try {
|
|
438
426
|
await loadGoogleFonts(document, fonts);
|
|
439
427
|
if (alive && request === fontRequest) for (const [field, selected] of Object.entries(fonts)) {
|
|
440
|
-
root.querySelector(`[data-font-status="${field}"]`).textContent = `${selected} loaded
|
|
428
|
+
const target = root.querySelector(`[data-font-status="${field}"]`); target.hidden = false; target.textContent = `${selected} loaded.`;
|
|
441
429
|
}
|
|
442
430
|
} catch (error) {
|
|
443
|
-
if (alive && request === fontRequest) for (const field of Object.keys(fonts)) root.querySelector(`[data-font-status="${field}"]`).textContent
|
|
431
|
+
if (alive && request === fontRequest) for (const field of Object.keys(fonts)) { const target=root.querySelector(`[data-font-status="${field}"]`); target.hidden=false; target.textContent=error.message; }
|
|
444
432
|
}
|
|
445
433
|
};
|
|
446
434
|
const selectExample = event => {
|
|
@@ -449,8 +437,35 @@ export function connect(host) {
|
|
|
449
437
|
filterExamples();
|
|
450
438
|
};
|
|
451
439
|
const motionPreferenceChanged = () => { motionAnimation?.cancel(); paint(); };
|
|
440
|
+
// Observe visible option names only; preview faces never replace selected full fonts.
|
|
441
|
+
const fontOptions = new Map();
|
|
442
|
+
const fontObserver = new view.IntersectionObserver(entries => {
|
|
443
|
+
for (const { target, isIntersecting } of entries) {
|
|
444
|
+
if (!isIntersecting) continue;
|
|
445
|
+
fontObserver.unobserve(target);
|
|
446
|
+
const family = fontOptions.get(target);
|
|
447
|
+
loadGoogleFontPreview(document, family).then(alias => {
|
|
448
|
+
if (alive && root.contains(target) && fontOptions.get(target) === family)
|
|
449
|
+
target.style.setProperty('--_font-preview-family', `"${alias}", ${googleFonts[family].category}`);
|
|
450
|
+
}).catch(() => {}); // A failed decorative preview keeps the readable inherited font.
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
const observeFontOptions = () => {
|
|
454
|
+
for (const [node] of fontOptions) if (!root.contains(node)) { fontObserver.unobserve(node); fontOptions.delete(node); }
|
|
455
|
+
for (const node of root.querySelectorAll('[data-font-preview]')) {
|
|
456
|
+
const family = node.dataset.fontPreview;
|
|
457
|
+
if (fontOptions.get(node) === family) continue;
|
|
458
|
+
fontObserver.unobserve(node); node.style.removeProperty('--_font-preview-family');
|
|
459
|
+
fontOptions.delete(node);
|
|
460
|
+
if (Object.hasOwn(googleFonts, family)) { fontOptions.set(node, family); fontObserver.observe(node); }
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
const fontMutations = new view.MutationObserver(observeFontOptions);
|
|
464
|
+
for (const picker of root.querySelectorAll('[data-font-picker]'))
|
|
465
|
+
fontMutations.observe(picker, { childList: true, subtree: true, attributes: true, attributeFilter: ['data-font-preview'] });
|
|
466
|
+
observeFontOptions();
|
|
452
467
|
const previewObserver = new view.ResizeObserver(schedulePreviewLayout);
|
|
453
|
-
for (const element of [...previews, ...(header ? [header] : [])]) previewObserver.observe(element);
|
|
468
|
+
for (const element of [root.querySelector('[data-customizer-summary]'), ...previews, ...(header ? [header] : [])]) previewObserver.observe(element);
|
|
454
469
|
view.addEventListener('resize', schedulePreviewLayout);
|
|
455
470
|
motionPreference.addEventListener('change', motionPreferenceChanged);
|
|
456
471
|
root.addEventListener('toggle', updateSizes, true);
|
|
@@ -481,5 +496,5 @@ export function connect(host) {
|
|
|
481
496
|
root.querySelector('[data-action="save"]').hidden = false;
|
|
482
497
|
}).catch(error => { if (alive && error.name !== 'AbortError') say(error.message, true); });
|
|
483
498
|
}
|
|
484
|
-
return () => { previewObserver.disconnect(); if (layoutFrame) view.cancelAnimationFrame(layoutFrame); view.removeEventListener('resize', schedulePreviewLayout); motionPreference.removeEventListener('change', motionPreferenceChanged); root.removeEventListener('toggle', updateSizes, true); motionAnimation?.cancel(); flush(); root.removeEventListener('cancel', cancel); root.removeEventListener('keydown', keyboard); alive = false; abort.abort(); root.removeEventListener('looma-example-remove', remove); root.removeEventListener('input', input); root.removeEventListener('value-change', choose); root.removeEventListener('value-change', selectExample); root.removeEventListener('value-change', selectFont); root.removeEventListener('blur', blur, true); root.removeEventListener('change', change); root.removeEventListener('click', click); view.removeEventListener('beforeunload', flush); view.removeEventListener('popstate', renderView); view.removeEventListener('hashchange', renderView); view.removeEventListener(themeEvent, synchronize); };
|
|
499
|
+
return () => { fontMutations.disconnect(); fontObserver.disconnect(); fontOptions.clear(); previewObserver.disconnect(); if (layoutFrame) view.cancelAnimationFrame(layoutFrame); view.removeEventListener('resize', schedulePreviewLayout); motionPreference.removeEventListener('change', motionPreferenceChanged); root.removeEventListener('toggle', updateSizes, true); motionAnimation?.cancel(); flush(); root.removeEventListener('cancel', cancel); root.removeEventListener('keydown', keyboard); alive = false; abort.abort(); root.removeEventListener('looma-example-remove', remove); root.removeEventListener('input', input); root.removeEventListener('value-change', choose); root.removeEventListener('value-change', selectExample); root.removeEventListener('value-change', selectFont); root.removeEventListener('blur', blur, true); root.removeEventListener('change', change); root.removeEventListener('click', click); view.removeEventListener('beforeunload', flush); view.removeEventListener('popstate', renderView); view.removeEventListener('hashchange', renderView); view.removeEventListener(themeEvent, synchronize); };
|
|
485
500
|
}
|
package/docs/fonts.mjs
CHANGED
|
@@ -43,3 +43,31 @@ export async function loadGoogleFonts(document, fonts) {
|
|
|
43
43
|
if (!faces.length) throw new Error(`${family} is unavailable; the fallback is currently displayed.`);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
+
|
|
47
|
+
/** Request only a font name's glyphs; selected fonts use the unrestricted stylesheet above. */
|
|
48
|
+
export function googleFontPreviewURL(family) {
|
|
49
|
+
if (!Object.hasOwn(googleFonts, family)) throw new Error('Choose a supported Google font.');
|
|
50
|
+
return 'https://fonts.googleapis.com/css2?family=' + encodeURIComponent(family).replaceAll('%20', '+') + ':wght@400&display=swap&text=' + encodeURIComponent(family);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const previewLoads = new WeakMap();
|
|
54
|
+
/** Isolate subset faces under aliases so document typography always uses full selected fonts. */
|
|
55
|
+
export function loadGoogleFontPreview(document, family) {
|
|
56
|
+
let loads = previewLoads.get(document);
|
|
57
|
+
if (!loads) { loads = new Map(); previewLoads.set(document, loads); }
|
|
58
|
+
if (!loads.has(family)) {
|
|
59
|
+
const loaded = (async () => {
|
|
60
|
+
const response = await document.defaultView.fetch(googleFontPreviewURL(family));
|
|
61
|
+
if (!response.ok) throw new Error('Font preview unavailable.');
|
|
62
|
+
const source = (await response.text()).match(/src\s*:\s*([^;]+);/)?.[1];
|
|
63
|
+
if (!source) throw new Error('Font preview unavailable.');
|
|
64
|
+
const alias = `Looma Font Preview ${family}`;
|
|
65
|
+
const face = new document.defaultView.FontFace(alias, source, { weight: '400', style: 'normal', display: 'swap' });
|
|
66
|
+
await face.load(); document.fonts.add(face);
|
|
67
|
+
return alias;
|
|
68
|
+
})();
|
|
69
|
+
loads.set(family, loaded);
|
|
70
|
+
loaded.catch(() => { if (loads.get(family) === loaded) loads.delete(family); });
|
|
71
|
+
}
|
|
72
|
+
return loads.get(family);
|
|
73
|
+
}
|