You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte-kit-vice/web/routes/uix/components/knob/+page.svelte

461 lines
16 KiB

<script lang="ts">
import { Knob, type KnobSize } from '$uix/eidos/components/knob';
import { compileMorfo } from '$uix/morfo';
import { knobMorfo } from '@/uix/morfo/components/knob';
import { getActiveUix } from '$active-uix';
type Tab = 'live' | 'api' | 'morfo' | 'sema' | 'recipe' | 'a11y';
type Intent = 'neutral' | 'affirm' | 'risk' | 'threat';
type TraceEntry = { event: string; family: string; intent?: string; at: number };
const uix = getActiveUix();
let tab = $state<Tab>('live');
let value = $state(40);
let min = $state(0);
let max = $state(100);
let step = $state(1);
let largeStep = $state(10);
let startAngle = $state(-135);
let endAngle = $state(135);
let disabled = $state(false);
let readonly = $state(false);
let invalid = $state(false);
let intent = $state<Intent>('neutral');
let size = $state<KnobSize>('md');
let showNeedle = $state(true);
const compiled = compileMorfo(knobMorfo);
const partsList = $derived([...compiled.parts.byKebab.values()]);
const events = $derived([...compiled.actions.byName.values()]);
const controlKeyboard = $derived(knobMorfo.parts[1].keyboard ?? []);
let stageRef = $state<HTMLElement | null>(null);
let trace = $state<TraceEntry[]>([]);
$effect(() => {
const el = stageRef;
if (!el) return;
const obs = new MutationObserver((mutations) => {
for (const m of mutations) {
if (m.attributeName !== 'data-event') continue;
const target = m.target as Element;
const ev = target.getAttribute('data-event');
if (!ev) continue;
trace = [
{
event: ev,
family: target.getAttribute('data-event-family') ?? '-',
intent: target.getAttribute('data-event-intent') ?? undefined,
at: Date.now()
},
...trace
].slice(0, 6);
}
});
obs.observe(el, { attributes: true, subtree: true, attributeFilter: ['data-event'] });
return () => obs.disconnect();
});
function fmtTime(at: number): string {
const d = new Date(at);
return `${String(d.getSeconds()).padStart(2, '0')}.${String(d.getMilliseconds()).padStart(3, '0')}`;
}
const somaSnippet = $derived(
[
"<script lang='ts'>",
" import * as Knob from '$soma/components/knob';",
` let value = $state(${value});`,
'</' + 'script>',
'',
`<Knob.Provider bind:value min={${min}} max={${max}} aria-label="Gain">`,
' <Knob.Control>',
' <Knob.Indicator />',
' </Knob.Control>',
' <Knob.ValueText />',
'</Knob.Provider>'
].join('\n')
);
const eidosSnippet = $derived(
[
"<script lang='ts'>",
" import { Knob } from '$uix/eidos/components/knob';",
` let value = $state(${value});`,
'</' + 'script>',
'',
`<Knob bind:value min={${min}} max={${max}} size="${size}" aria-label="Gain">`,
' <Knob.Control>',
' <Knob.Indicator />',
' </Knob.Control>',
' <Knob.ValueText />',
'</Knob>'
].join('\n')
);
</script>
<div data-uix-canvas-inner>
<header>
<div data-uix-eyebrow>Controls · Knob</div>
<h1 data-uix-page-title>Knob</h1>
<p data-uix-page-lede>
Rotary value control (WAI-ARIA slider pattern, radial rendering). Soma owns the radial gesture
(via <code>Gesture.rotate</code>), keyboard, value and ARIA; Eidos adds visual size.
</p>
<div data-uix-page-meta>
<span data-uix-meta-pill><span data-uix-meta-key>parts</span>{compiled.parts.order.length}</span
>
<span data-uix-meta-pill><span data-uix-meta-key>events</span>{events.length}</span>
<span data-uix-meta-pill><span data-uix-meta-key>keyboard</span>{controlKeyboard.length}</span>
<span data-uix-meta-pill><span data-uix-meta-key>gesture</span>rotate</span>
</div>
</header>
<div data-uix-stage bind:this={stageRef}>
<div data-uix-stage-area>
<Knob
bind:value
{min}
{max}
{step}
{largeStep}
{startAngle}
{endAngle}
{disabled}
{readonly}
{invalid}
{intent}
{size}
aria-label="Gain"
>
<Knob.Control>
{#if showNeedle}
<Knob.Indicator />
{/if}
<Knob.ValueText>{value}</Knob.ValueText>
</Knob.Control>
</Knob>
</div>
<div data-uix-stage-trace>
<span data-uix-stage-trace-key>trace</span>
{#if trace.length === 0}
<span>drag the dial or step with the keyboard to see sema events</span>
{:else}
{#each trace.slice(0, 3) as entry}
<span
><span data-uix-stage-trace-event>{entry.event}</span> · {entry.family}{entry.intent
? ' · ' + entry.intent
: ''}</span
>
<span style="color: var(--uix-text-faint)">{fmtTime(entry.at)}</span>
{/each}
{/if}
<span style="margin-inline-start: auto;">
<span data-uix-stage-trace-key>value</span>
{value} · {size}
</span>
</div>
</div>
<div data-uix-tabs role="tablist">
<button data-uix-tab data-active={tab === 'live'} onclick={() => (tab = 'live')}>Live</button>
<button data-uix-tab data-active={tab === 'api'} onclick={() => (tab = 'api')}>API</button>
<button data-uix-tab data-active={tab === 'morfo'} onclick={() => (tab = 'morfo')}>
<span data-uix-layer-badge="morfo">morfo</span>
<span data-uix-tab-count>{partsList.length}p · {events.length}e</span>
</button>
<button data-uix-tab data-active={tab === 'sema'} onclick={() => (tab = 'sema')}>
<span data-uix-layer-badge="sema">sema</span>
<span data-uix-tab-count>{events.length}</span>
</button>
<button data-uix-tab data-active={tab === 'recipe'} onclick={() => (tab = 'recipe')}>Recipe</button>
<button data-uix-tab data-active={tab === 'a11y'} onclick={() => (tab = 'a11y')}>A11y</button>
</div>
{#if tab === 'live'}
<section data-uix-section>
<h2 data-uix-section-title>Controls</h2>
<p data-uix-section-desc>
<span data-uix-layer-badge="soma">soma</span> owns the radial gesture + value model.
<span data-uix-layer-badge="eidos">eidos</span> owns size.
</p>
<div data-uix-subsection-head>
<span data-uix-layer-badge="soma">soma</span> props · value model
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>value <span data-uix-control-hint>{value}</span></span>
<input type="range" {min} {max} {step} bind:value />
</label>
<label data-uix-control
><span data-uix-control-label>min</span><input type="number" bind:value={min} /></label
>
<label data-uix-control
><span data-uix-control-label>max</span><input type="number" bind:value={max} /></label
>
<label data-uix-control
><span data-uix-control-label>step</span><input
type="number"
min="1"
bind:value={step}
/></label
>
<label data-uix-control
><span data-uix-control-label>largeStep</span><input
type="number"
min="1"
bind:value={largeStep}
/></label
>
<label data-uix-control
><span data-uix-control-label>startAngle</span><input
type="number"
bind:value={startAngle}
/></label
>
<label data-uix-control
><span data-uix-control-label>endAngle</span><input
type="number"
bind:value={endAngle}
/></label
>
<label data-uix-control>
<span data-uix-control-label>intent</span>
<span data-uix-chips role="radiogroup">
{#each ['neutral', 'affirm', 'risk', 'threat'] as i}
<button data-uix-chip data-active={intent === i} onclick={() => (intent = i as Intent)}
>{i}</button
>
{/each}
</span>
</label>
<label data-uix-control>
<span data-uix-control-label>disabled</span>
<span data-uix-switch
><input type="checkbox" bind:checked={disabled} /><span data-uix-switch-label
>{disabled ? 'on' : 'off'}</span
></span
>
</label>
<label data-uix-control>
<span data-uix-control-label>readonly</span>
<span data-uix-switch
><input type="checkbox" bind:checked={readonly} /><span data-uix-switch-label
>{readonly ? 'on' : 'off'}</span
></span
>
</label>
<label data-uix-control>
<span data-uix-control-label>invalid</span>
<span data-uix-switch
><input type="checkbox" bind:checked={invalid} /><span data-uix-switch-label
>{invalid ? 'on' : 'off'}</span
></span
>
</label>
<label data-uix-control>
<span data-uix-control-label>needle</span>
<span data-uix-switch
><input type="checkbox" bind:checked={showNeedle} /><span data-uix-switch-label
>{showNeedle ? 'on' : 'off'}</span
></span
>
</label>
</div>
<div data-uix-subsection-head>
<span data-uix-layer-badge="eidos">eidos</span> props · visual treatment
</div>
<div data-uix-controls>
<label data-uix-control>
<span data-uix-control-label>size</span>
<span data-uix-chips role="radiogroup">
{#each ['sm', 'md', 'lg', 'xl'] as s}
<button data-uix-chip data-active={size === s} onclick={() => (size = s as KnobSize)}
>{s}</button
>
{/each}
</span>
</label>
</div>
<div data-uix-code>
<div data-uix-code-head>
<span data-uix-layer-badge="soma">soma</span>
<span>headless · knob model</span>
<span data-uix-code-lang>svelte</span>
</div>
<pre><code>{somaSnippet}</code></pre>
</div>
<div data-uix-code style="margin-top: var(--uix-space-3);">
<div data-uix-code-head>
<span data-uix-layer-badge="eidos">eidos</span>
<span>visual · adds size</span>
<span data-uix-code-lang>svelte</span>
</div>
<pre><code>{eidosSnippet}</code></pre>
</div>
</section>
{/if}
{#if tab === 'api'}
<section data-uix-section>
<h2 data-uix-section-title>API surface</h2>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Prop</th><th>Owner</th><th>Default</th><th>Notes</th></tr></thead>
<tbody>
<tr><td class="name">value</td><td>soma</td><td class="default">min</td><td>Bindable number</td></tr>
<tr><td class="name">min / max / step</td><td>soma</td><td class="default">0 / 100 / 1</td><td>Range + snapping grid</td></tr>
<tr><td class="name">largeStep</td><td>soma</td><td class="default">10</td><td>PageUp / PageDown</td></tr>
<tr><td class="name">defaultValue</td><td>soma</td><td class="default">min</td><td>Double-click reset target</td></tr>
<tr><td class="name">startAngle / endAngle</td><td>soma</td><td class="default">-135 / 135</td><td>Sweep (deg, 0 = up, clockwise)</td></tr>
<tr><td class="name">readonly / invalid</td><td>soma</td><td class="default">false</td><td>Focusable-not-editable / aria-invalid</td></tr>
<tr><td class="name">intent</td><td>soma</td><td class="default">neutral</td><td>Evaluative load of commits</td></tr>
<tr><td class="name">formatValue</td><td>soma</td><td class="default">—</td><td>Custom aria-valuetext formatter</td></tr>
<tr><td class="name">size</td><td>eidos</td><td class="default">md</td><td>sm | md | lg | xl</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'morfo'}
<section data-uix-section>
<h2 data-uix-section-title>Morfo contract</h2>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Part</th><th>Marker</th><th>Element</th><th>Role</th><th>Optional</th></tr></thead>
<tbody>
{#each partsList as part}
<tr>
<td class="name">{part.kebab}</td>
<td><code data-uix-part-marker>[{part.marker}]</code></td>
<td class="type">&lt;{part.defaultElement}&gt;</td>
<td class="type">{part.role ?? '—'}</td>
<td class="default">{part.optional ? 'yes' : 'no'}</td>
</tr>
{/each}
</tbody>
</table>
</div>
<div data-uix-subsection-head>Keyboard <span data-uix-control-hint>(on Control)</span></div>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Key</th><th>Action</th></tr></thead>
<tbody>
{#each controlKeyboard as key}
<tr><td class="name">{key.key}</td><td>{key.action}</td></tr>
{/each}
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'sema'}
<section data-uix-section>
<h2 data-uix-section-title>
<span data-uix-layer-badge="sema">sema</span> · events + perceptual signature
</h2>
<p data-uix-section-desc>
Continuous-shape component: the gesture is modeled as start / commit boundaries
(<code>handle-pick</code> · <code>handle-drop</code> · <code>commit-set</code> ·
<code>commit-reset</code>), never per-frame emissions.
</p>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Name</th><th>Family</th><th>Verb</th><th>Sequence</th><th>Target</th><th>Play</th></tr></thead>
<tbody>
{#each events as action}
<tr>
<td class="name">{action.name}</td>
<td class="type">{action.semantic.family}</td>
<td>{action.semantic.verb ?? '—'}</td>
<td>{action.semantic.sequence ?? 'pre'}</td>
<td>{action.target}</td>
<td>
<button
data-uix-play
onclick={() => {
const target = stageRef?.querySelector(
'[data-knob-control]'
) as HTMLElement | null;
if (!target) return;
void uix.events?.emit({
name: action.name,
family: action.semantic.family,
target
});
}}>▶ play</button
>
</td>
</tr>
{/each}
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'recipe'}
<section data-uix-section>
<h2 data-uix-section-title>Eidos recipe</h2>
<p data-uix-section-desc>
Selectors live in <code>src/uix/eidos/components/knob/knob.css</code> and consume Soma
attrs plus the provider-published <code>--knob-progress</code> / <code>--knob-angle</code>
custom properties.
</p>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Selector</th><th>Owner</th><th>Purpose</th></tr></thead>
<tbody>
<tr>
<td class="name"><code>[data-knob]</code></td>
<td><span data-uix-tag data-kind="morfo">morfo</span></td>
<td>Root container (flex column, gap).</td>
</tr>
<tr>
<td class="name"><code>[data-knob-control]</code></td>
<td><span data-uix-tag data-kind="morfo">morfo</span></td>
<td>The dial: value arc via conic-gradient from <code>--knob-progress</code>.</td>
</tr>
<tr>
<td class="name"><code>[data-knob-indicator]</code></td>
<td><span data-uix-tag data-kind="morfo">morfo</span></td>
<td>Pointer rotated by <code>--knob-angle</code>.</td>
</tr>
<tr>
<td class="name"><code>[data-knob][data-dragging]</code></td>
<td><span data-uix-tag data-kind="morfo">morfo</span></td>
<td>Grabbing cursor + raised shadow during the gesture.</td>
</tr>
<tr>
<td class="name"><code>[data-knob][data-intent='risk']</code></td>
<td><span data-uix-tag data-kind="morfo">morfo</span></td>
<td>Persistent evaluative tint of the value arc.</td>
</tr>
</tbody>
</table>
</div>
</section>
{/if}
{#if tab === 'a11y'}
<section data-uix-section>
<h2 data-uix-section-title>Accessibility</h2>
<div data-uix-table-wrap>
<table data-uix-table>
<thead><tr><th>Concern</th><th>Contract</th></tr></thead>
<tbody>
<tr><td class="name">Role</td><td>Control uses <code>role="slider"</code> with a rotary roledescription.</td></tr>
<tr><td class="name">Value</td><td>Exposes min, max, now and a locale-formatted valuetext.</td></tr>
<tr><td class="name">Label</td><td><code>aria-labelledby</code> when a Label part exists, else <code>aria-label</code> (via the <code>part-absent</code> condition).</td></tr>
<tr><td class="name">Keyboard</td><td>Arrows step, PageUp/PageDown large-step, Home/End jump to bounds; double-click resets.</td></tr>
</tbody>
</table>
</div>
</section>
{/if}
</div>

Powered by TurnKey Linux.