@ironflock/widget-toolbar 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget-toolbar.js","sources":["../src/tools.ts","../src/layout.ts","../src/colors.ts","../src/widget-toolbar.ts"],"sourcesContent":["/**\n * What the toolbar draws and writes, derived from the config. Everything here\n * is pure: the config belongs to the host (which shares bound rows with other\n * tiles), so nothing writes to it, and every field is checked rather than\n * trusted, because boards keep configs written by hand or for older versions.\n */\nimport type { ToolbarConfiguration } from './definition-schema.js'\n\nexport type Control = 'button' | 'switch' | 'slider' | 'choice' | 'dropdown' | 'label' | 'separator' | 'spacer'\nexport type Variant = 'filled' | 'tonal' | 'outlined' | 'text'\n\nconst CONTROLS: readonly Control[] = ['button', 'switch', 'slider', 'choice', 'dropdown', 'label', 'separator', 'spacer']\nconst VARIANTS: readonly Variant[] = ['filled', 'tonal', 'outlined', 'text']\n\n/** Tools that write a value; label, separator and spacer don't. */\nexport const isInteractive = (control: Control): boolean =>\n control === 'button' || control === 'switch' || control === 'slider' || control === 'choice' || control === 'dropdown'\n\n/** A table column as the targetColumn picker stores it. Studio adds the app's backend key. */\nexport type ColumnRef = {\n swarm_app_databackend_key: string | number\n tablename: string\n column: string\n dataType?: string\n}\n\n/** One column value, as `data-submit` carries it. Studio groups the items into one row per table. */\nexport type ValueItem = {\n swarm_app_databackend_key: string | number\n table_name: string\n column_name: string\n value: unknown\n}\n\nexport type Option = { label: string; value: string; icon?: string }\n\n/**\n * The value an operator set, held until the reported value agrees with it.\n * `expected` is what the tool's state source should report once the write\n * has landed. Without a timer (nothing reports the value) it is the state.\n */\nexport type Request = { expected: unknown; timer?: ReturnType<typeof setTimeout> }\n\n/** Where a tool's shown value comes from. */\nexport type Source = 'url' | 'data' | 'local'\n\nexport type ToolModel = {\n /** Stable per position and type; changing a tool's type starts it afresh. */\n key: string\n index: number\n control: Control\n label: string\n icon?: string\n variant: Variant\n /** The tool's own accent colour, if configured. */\n color?: string\n // Interactive tools\n source: Source\n /** The value the tool shows: reported, or held after a click. */\n state: unknown\n disabled: boolean\n confirmText?: string\n parameterKey?: string\n target?: ColumnRef\n // button\n buttonValue: string\n active: boolean\n // switch\n on: boolean\n // slider\n min: number\n max: number\n step: number\n decimals: number\n unit: string\n sliderValue: number\n // choice, dropdown\n options: Option[]\n selected: number\n}\n\n/** What one interaction writes. */\nexport type Commit = {\n /** URL parameters for `param-submit`, or undefined when the tool sets none. */\n params?: Record<string, string | undefined>\n /** Items for `data-submit`, or undefined when the tool writes no column. */\n items?: ValueItem[]\n /** What the tool's state source should report afterwards. */\n expected: unknown\n}\n\n// Written into the URL and into a column for \"on\" when nothing else is set.\nconst DEFAULT_ON = 'true'\n\nconst text = (value: unknown): string =>\n typeof value === 'string' ? value : typeof value === 'number' && Number.isFinite(value) ? String(value) : ''\n\nexport const isEmpty = (value: unknown): boolean =>\n value === undefined || value === null || (typeof value === 'string' && value.trim() === '')\n\nexport const toNumber = (value: unknown): number | undefined => {\n if (value === null || value === undefined || value === '' || typeof value === 'boolean') return undefined\n const number = typeof value === 'number' ? value : Number(String(value).trim())\n return Number.isFinite(number) ? number : undefined\n}\n\n/** A picked column, or undefined unless it names a backend, a table and a column. */\nexport function columnRef(target: unknown): ColumnRef | undefined {\n if (!target || typeof target !== 'object') return undefined\n const ref = target as Record<string, unknown>\n const key = ref.swarm_app_databackend_key\n const hasKey = (typeof key === 'number' && Number.isFinite(key)) || (typeof key === 'string' && key.trim() !== '')\n const named = (part: unknown) => typeof part === 'string' && part.trim() !== ''\n if (!hasKey || !named(ref.tablename) || !named(ref.column)) return undefined\n return {\n swarm_app_databackend_key: key as string | number,\n tablename: ref.tablename as string,\n column: ref.column as string,\n dataType: typeof ref.dataType === 'string' ? ref.dataType : undefined\n }\n}\n\nconst sameTable = (a: ColumnRef, b: ColumnRef): boolean =>\n String(a.swarm_app_databackend_key) === String(b.swarm_app_databackend_key) && a.tablename === b.tablename\n\n/**\n * A value as its column's type wants it. The editor stores constants as text,\n * so '12' or 'true' becomes a number or a boolean for those columns. What\n * does not convert is written as it is, and Studio reports the failed row.\n * (The same conversion as widget-switch's.)\n */\nexport function columnValue(value: unknown, dataType: unknown): unknown {\n if (value === undefined || value === null) return null\n if (dataType === 'boolean') {\n if (typeof value === 'boolean') return value\n if (typeof value === 'number') return value !== 0\n const t = String(value).trim().toLowerCase()\n if (t === 'true' || t === '1') return true\n if (t === 'false' || t === '0') return false\n return value\n }\n if (dataType === 'numeric' || dataType === 'bigint') {\n if (typeof value === 'boolean') return value ? 1 : 0\n if (typeof value === 'number') return value\n const t = String(value).trim()\n const n = Number(t)\n if (t === '' || !Number.isFinite(n)) return value\n // A bigint id beyond 2^53 would lose digits as a number.\n return dataType === 'bigint' && !Number.isSafeInteger(n) ? t : n\n }\n if (dataType === 'string' && (typeof value === 'boolean' || typeof value === 'number')) return String(value)\n return value\n}\n\n// Only used against a boolean, so 1 and 0 count as true and false.\nconst asBoolean = (value: unknown): boolean | undefined => {\n if (typeof value === 'boolean') return value\n const t = String(value).trim().toLowerCase()\n if (t === 'true' || t === '1') return true\n if (t === 'false' || t === '0') return false\n return undefined\n}\n\n/**\n * Whether two values mean the same, after the column's conversion on both\n * sides: true written to a numeric column comes back as 1, '5' as 5. Empty\n * values (missing, null, '') are all the same.\n */\nexport function sameValue(a: unknown, b: unknown, dataType?: unknown): boolean {\n if (isEmpty(a) || isEmpty(b)) return isEmpty(a) && isEmpty(b)\n const ca = columnValue(a, dataType)\n const cb = columnValue(b, dataType)\n if (typeof ca === 'boolean' || typeof cb === 'boolean') {\n const ba = asBoolean(ca)\n const bb = asBoolean(cb)\n if (ba !== undefined && bb !== undefined) return ba === bb\n }\n if (dataType !== 'string') {\n const na = toNumber(ca)\n const nb = toNumber(cb)\n if (na !== undefined && nb !== undefined) return na === nb\n }\n return String(ca).trim() === String(cb).trim()\n}\n\n/** The value the URL holds for a parameter, undefined while it is absent. */\nexport function paramsOf(route: unknown): URLSearchParams {\n if (typeof route !== 'string') return new URLSearchParams()\n const query = route.indexOf('?')\n return new URLSearchParams(query < 0 ? '' : route.slice(query + 1))\n}\n\ntype RawTool = Record<string, unknown>\n\nconst rawTools = (config: unknown): (RawTool | undefined)[] => {\n const tools = (config as ToolbarConfiguration | undefined)?.tools\n if (!Array.isArray(tools)) return []\n // A null slot (a stray '-' in a board template) keeps its position, so the\n // keys of the tools after it do not shift.\n return tools.map((tool) => (tool && typeof tool === 'object' ? (tool as RawTool) : undefined))\n}\n\nconst controlOf = (tool: RawTool): Control => {\n const control = tool.control\n return CONTROLS.includes(control as Control) ? (control as Control) : 'button'\n}\n\nexport const toolKey = (index: number, control: Control): string => `${index}:${control}`\n\n/** The key and the reported value of every interactive tool, for settling held requests. */\nexport type Report = { key: string; source: Source; reported: unknown; dataType?: string }\n\n/** What each interactive tool's source reports right now. */\nexport function reports(config: unknown, params: URLSearchParams): Report[] {\n return rawTools(config).flatMap((tool, index): Report[] => {\n if (!tool) return []\n const control = controlOf(tool)\n if (!isInteractive(control)) return []\n const key = toolKey(index, control)\n const parameterKey = text(tool.parameterKey).trim()\n if (parameterKey) {\n return [{ key, source: 'url', reported: params.get(parameterKey) ?? undefined }]\n }\n // A bound value that has delivered nothing yet (null) reports nothing.\n if (tool.value !== undefined && tool.value !== null) {\n return [{ key, source: 'data', reported: tool.value, dataType: columnRef(tool.targetColumn)?.dataType }]\n }\n return [{ key, source: 'local', reported: undefined }]\n })\n}\n\n/** Whether a held request can go: its source now reports what it expects, or reports at all without a timer. */\nexport function settled(report: Report, request: Request): boolean {\n if (report.source === 'local') return false\n if (request.timer === undefined) return true\n return sameValue(report.reported, request.expected, report.source === 'data' ? report.dataType : undefined)\n}\n\nconst decimalsOf = (step: number): number => {\n const [, fraction = ''] = String(step).split('.')\n return Math.min(fraction.length, 6)\n}\n\nconst options = (raw: unknown): Option[] => {\n if (!Array.isArray(raw)) return []\n const seen = new Set<string>()\n return raw.flatMap((option) => {\n if (!option || typeof option !== 'object') return []\n const o = option as Record<string, unknown>\n const value = text(o.value)\n // Two options with one value would both be \"selected\"; the first wins.\n if (seen.has(value)) return []\n seen.add(value)\n const label = text(o.label) || value\n const icon = text(o.icon).trim() || undefined\n if (!label && !icon) return []\n return [{ label, value, icon }]\n })\n}\n\n/** Shared columns that go into the same table as `target`. */\nfunction sharedFor(config: unknown, target: ColumnRef): { ref: ColumnRef; value: unknown }[] {\n const shared = (config as ToolbarConfiguration | undefined)?.sharedColumns\n if (!Array.isArray(shared)) return []\n return shared.flatMap((entry) => {\n const ref = columnRef(entry?.targetColumn)\n return ref && sameTable(ref, target) ? [{ ref, value: entry?.value }] : []\n })\n}\n\nfunction extrasOf(tool: RawTool): { ref: ColumnRef; value: unknown }[] {\n if (!Array.isArray(tool.extraColumns)) return []\n return tool.extraColumns.flatMap((extra) => {\n const ref = columnRef((extra as RawTool | null)?.targetColumn)\n return ref ? [{ ref, value: (extra as RawTool).value }] : []\n })\n}\n\nconst valueItem = (ref: ColumnRef, value: unknown): ValueItem => ({\n swarm_app_databackend_key: ref.swarm_app_databackend_key,\n table_name: ref.tablename,\n column_name: ref.column,\n value: columnValue(value, ref.dataType)\n})\n\n/**\n * The row a tool writes with `value` in its own column, or undefined while a\n * key column has no value: a row without its record's key would land nowhere.\n * The tool's own column comes last, so it wins over a shared or extra column\n * naming the same column (Studio keeps the later item).\n */\nexport function rowItems(config: unknown, tool: RawTool, value: unknown): ValueItem[] | undefined {\n const target = columnRef(tool.targetColumn)\n if (!target) return undefined\n const keys = [...sharedFor(config, target), ...extrasOf(tool)]\n if (keys.some((key) => isEmpty(key.value))) return undefined\n return [...keys.map((key) => valueItem(key.ref, key.value)), valueItem(target, value)]\n}\n\n/**\n * The tool models, in configuration order. `requests` holds what the operator\n * set; each request is either still waiting for its source (it has a timer) or\n * stands in for a source that reports nothing.\n */\nexport function toTools(config: unknown, route: unknown, requests: ReadonlyMap<string, Request>): ToolModel[] {\n const params = paramsOf(route)\n const reported = new Map(reports(config, params).map((report) => [report.key, report]))\n return rawTools(config).flatMap((tool, index) => {\n if (!tool) return []\n const control = controlOf(tool)\n const key = toolKey(index, control)\n const label = text(tool.label).trim()\n const icon = text(tool.icon).trim() || undefined\n const color = typeof tool.color === 'string' && tool.color.trim() ? tool.color.trim() : undefined\n const report = reported.get(key)\n const request = requests.get(key)\n const source: Source = report?.source ?? 'local'\n // A held request wins until its source agrees (the element drops it then).\n const state = request ? request.expected : report?.reported\n const target = columnRef(tool.targetColumn)\n const parameterKey = text(tool.parameterKey).trim() || undefined\n const dataType = source === 'data' ? target?.dataType : undefined\n\n // A tool that names a column but misses a key value is disabled, even\n // when it also sets a URL parameter: half a write is worse than none.\n const writable = target ? rowItems(config, tool, true) !== undefined : false\n const disabled = isInteractive(control) && (target ? !writable : !parameterKey)\n\n const buttonValue = text(tool.buttonValue)\n // Compared with what the switch writes for \"on\": a configured On Value,\n // else true, which a numeric column stores (and reports back) as 1.\n const onValue: unknown = text(tool.onValue).trim() || (source === 'url' ? DEFAULT_ON : true)\n\n let min = toNumber(tool.min) ?? 0\n let max = toNumber(tool.max) ?? 100\n if (!(max > min)) max = min + 100\n let step = toNumber(tool.step) ?? 1\n if (!(step > 0)) step = 1\n if (step > max - min) step = max - min\n const decimals = decimalsOf(step)\n const number = toNumber(state)\n const sliderValue = number === undefined ? min : Math.min(max, Math.max(min, number))\n\n const opts = options(tool.options)\n const selected = control === 'choice' || control === 'dropdown'\n ? opts.findIndex((option) => sameValue(state, option.value, dataType))\n : -1\n\n return [\n {\n key,\n index,\n control,\n label,\n icon,\n variant: VARIANTS.includes(tool.variant as Variant) ? (tool.variant as Variant) : 'filled',\n color,\n source,\n state,\n disabled,\n confirmText: text(tool.confirmText).trim() || undefined,\n parameterKey,\n target,\n buttonValue,\n active: control === 'button' && buttonValue.trim() !== '' && sameValue(state, buttonValue, dataType),\n on: control === 'switch' && sameValue(state, onValue, dataType),\n min,\n max,\n step,\n decimals,\n unit: text(tool.unit),\n sliderValue,\n options: opts,\n selected\n }\n ]\n })\n}\n\n/**\n * What an interaction writes. `next` is the new position: a switch's on/off,\n * a slider's number, an option's value; a button ignores it.\n */\nexport function commitFor(config: unknown, model: ToolModel, next?: unknown): Commit | undefined {\n if (!isInteractive(model.control) || model.disabled) return undefined\n const tool = rawTools(config)[model.index]\n if (!tool) return undefined\n\n // What goes into the URL (undefined removes the parameter) and into the column.\n let urlValue: string | undefined\n let column: unknown\n switch (model.control) {\n case 'button': {\n const value = model.buttonValue.trim() === '' ? undefined : model.buttonValue\n urlValue = value\n column = value ?? true\n break\n }\n case 'switch': {\n const onValue = text(tool.onValue).trim()\n const offValue = text(tool.offValue).trim()\n if (next) {\n urlValue = onValue || DEFAULT_ON\n column = onValue || true\n } else {\n urlValue = offValue || undefined\n column = offValue || false\n }\n break\n }\n case 'slider': {\n const n = toNumber(next) ?? model.sliderValue\n const value = Number(Math.min(model.max, Math.max(model.min, n)).toFixed(model.decimals))\n urlValue = String(value)\n column = value\n break\n }\n default: {\n const value = text(next)\n urlValue = value.trim() === '' ? undefined : value\n column = value.trim() === '' ? null : value\n }\n }\n\n const items = model.target ? rowItems(config, tool, column) : undefined\n if (model.target && !items) return undefined\n const params = model.parameterKey ? { [model.parameterKey]: urlValue } : undefined\n const expected = model.parameterKey ? urlValue : model.target ? columnValue(column, model.target.dataType) : column\n return { params, items, expected }\n}\n","/**\n * Which tools the bar shows, at which density, and which move into the ⋮ menu.\n * Pure: it works on sizes the element measured, so it can be tested without a\n * browser.\n *\n * Main axis: along the bar (width when horizontal, height when vertical).\n * Cross axis: across it.\n */\n\nexport type Extent = { main: number; cross: number }\n\nexport type Item = {\n kind: 'tool' | 'separator' | 'spacer'\n /** The tool drawn with its label. */\n full: Extent\n /** The tool drawn as small as it gets: icon-only buttons and choices, a shorter slider. */\n compact: Extent\n}\n\nexport type LayoutInput = {\n items: Item[]\n /** The bar's content box. */\n available: Extent\n /** Space between two items on the main axis. */\n gap: number\n /** The ⋮ button. */\n more: Extent\n /**\n * Whether the cross axis limits the tools: true for a vertical strip, where\n * a switch with its label can be wider than the strip. Each tool then gets\n * its labels where it fits across, is compact where only that fits, and\n * goes to the menu where neither does. A horizontal bar centres its tools\n * and lets the tile clip them.\n */\n checkCross: boolean\n}\n\nexport type Density = 'full' | 'compact'\n\nexport type Placement = {\n /** Indexes of the items in the bar, in order. */\n visible: number[]\n /** Indexes of the visible items drawn compact. */\n compact: number[]\n /** Indexes of the items in the menu, in order. Empty: no ⋮ button. */\n overflow: number[]\n}\n\n/**\n * Separators only between tools: none at either end, none next to another.\n * Spacers don't count as tools, and in the menu they mean nothing.\n */\nfunction tidy(items: Item[], indexes: number[], keepSpacers: boolean): number[] {\n const kept = indexes.filter((i) => keepSpacers || items[i].kind !== 'spacer')\n const result: number[] = []\n // The last tool or separator kept; spacers sit between them unseen.\n let last: 'none' | 'tool' | 'separator' = 'none'\n kept.forEach((i, n) => {\n const kind = items[i].kind\n if (kind === 'separator') {\n const toolAfter = kept.slice(n + 1).some((j) => items[j].kind === 'tool')\n if (last !== 'tool' || !toolAfter) return\n last = 'separator'\n } else if (kind === 'tool') {\n last = 'tool'\n }\n result.push(i)\n })\n return result\n}\n\nexport function place(input: LayoutInput): Placement {\n const { items, available, gap, more, checkCross } = input\n const fitsAcross = (extent: Extent) => !checkCross || extent.cross <= available.cross\n\n // A density per item, or undefined where the item fits across at neither.\n type Choice = (Density | undefined)[]\n const preferred: Choice = items.map((item) =>\n item.kind !== 'tool' || fitsAcross(item.full) ? 'full' : fitsAcross(item.compact) ? 'compact' : undefined\n )\n const allCompact: Choice = items.map((item) =>\n item.kind !== 'tool' || fitsAcross(item.compact) ? 'compact' : undefined\n )\n\n const done = (choice: Choice, visible: number[], overflow: number[]): Placement => {\n const bar = tidy(items, visible, true)\n const menu = tidy(items, overflow, false)\n // A menu of separators alone is no menu.\n const hasTools = menu.some((i) => items[i].kind === 'tool')\n return {\n visible: bar,\n compact: bar.filter((i) => items[i].kind === 'tool' && choice[i] === 'compact'),\n overflow: hasTools ? menu : []\n }\n }\n\n const length = (choice: Choice, indexes: number[]): number =>\n indexes.reduce((sum, i, n) => sum + items[i][choice[i] ?? 'compact'].main + (n > 0 ? gap : 0), 0)\n\n // Everything in the bar: with labels where possible; else compact the\n // tools that save the most first, so the labels go where they cost most\n // and the rest keep theirs.\n if (!preferred.some((density) => density === undefined)) {\n const shown = tidy(items, items.map((_, i) => i), true)\n const choice = [...preferred]\n const savings = shown\n .filter((i) => items[i].kind === 'tool' && choice[i] === 'full')\n .map((i) => ({ i, saving: items[i].full.main - items[i].compact.main }))\n .filter(({ saving }) => saving > 0)\n .sort((a, b) => b.saving - a.saving || a.i - b.i)\n let total = length(choice, shown)\n for (const { i, saving } of savings) {\n if (total <= available.main) break\n choice[i] = 'compact'\n total -= saving\n }\n if (total <= available.main) return done(choice, shown, [])\n }\n\n // The ⋮ menu: the first tools that fit, then the rest. Once one tool does\n // not fit, every tool after it goes to the menu too, so the bar keeps the\n // configured order. Tools that fit across at neither density go anyway.\n const budget = available.main - more.main - gap\n const fill = (choice: Choice) => {\n const visible: number[] = []\n const overflow: number[] = []\n let used = 0\n let full = false\n items.forEach((item, i) => {\n const density = choice[i]\n if (density === undefined) {\n overflow.push(i)\n return\n }\n const add = (visible.length > 0 ? gap : 0) + item[density].main\n if (!full && used + add <= budget) {\n visible.push(i)\n used += add\n } else {\n full = true\n overflow.push(i)\n }\n })\n return { visible, overflow }\n }\n // Keep the labels when that costs no tool, else go compact.\n const labelled = fill(preferred)\n const small = fill(allCompact)\n const count = (indexes: number[]) => indexes.filter((i) => items[i].kind === 'tool').length\n return count(labelled.visible) >= count(small.visible)\n ? done(preferred, labelled.visible, labelled.overflow)\n : done(allCompact, small.visible, small.overflow)\n}\n","/**\n * Colour helpers for the parts of the toolbar that need a real colour rather\n * than a var() chain: the opaque surface of the menu and the confirmation\n * dialog (the tile behind them is usually translucent), and the text colour\n * on an accent-coloured button. Taken from widget-filter-dropdown.\n */\n\nlet colorContext: CanvasRenderingContext2D | null | undefined\n\n// A colour as [r, g, b, alpha] in sRGB (channels 0-255), parsed by the browser\n// itself through a canvas's fillStyle, so names, hsl(), hex with alpha,\n// color-mix() and the like all work. A value the browser rejects comes back\n// fully transparent. Only the normalised string is read, never pixels: with\n// Firefox's resistFingerprinting on, getImageData() answers with random colours.\nexport const parseColor = (value: string): number[] => {\n colorContext ??= document.createElement('canvas').getContext('2d')\n if (!colorContext) return [0, 0, 0, 0]\n // Chromium hands oklch(), lab(), color() and the like back as written;\n // mixed into srgb they come back as color(srgb r g b / alpha).\n for (const candidate of [value, `color-mix(in srgb, ${value} 100%, transparent)`]) {\n // A rejected value leaves the previous fillStyle in place, so set it\n // after two different placeholders: only an accepted one reads the same.\n colorContext.fillStyle = '#000'\n colorContext.fillStyle = candidate\n const color = String(colorContext.fillStyle)\n colorContext.fillStyle = '#fff'\n colorContext.fillStyle = candidate\n if (String(colorContext.fillStyle) !== color) continue\n let match = /^#([\\da-f]{2})([\\da-f]{2})([\\da-f]{2})$/.exec(color)\n if (match) return [...match.slice(1).map((hex) => parseInt(hex, 16)), 1]\n match = /^rgba\\((\\d+), (\\d+), (\\d+), ([\\d.]+)\\)$/.exec(color)\n if (match) return match.slice(1).map(Number)\n match = /^color\\(srgb (\\S+) (\\S+) (\\S+)(?: \\/ (\\S+))?\\)$/.exec(color)\n if (match) {\n const [r, g, b] = match.slice(1, 4).map((v) => Math.min(Math.max(Number(v) || 0, 0), 1) * 255)\n return [r, g, b, Number(match[4] ?? 1) || 0]\n }\n }\n return [0, 0, 0, 0]\n}\n\nconst surfaceCache = new Map<string, string>()\n\n/**\n * Paint the given colours, bottom first, over white, as the screen composites\n * a translucent background over what is behind it, and return the opaque\n * result as #rrggbb.\n */\nexport const opaqueSurface = (layers: string[]): string => {\n const key = JSON.stringify(layers)\n const cached = surfaceCache.get(key)\n if (cached !== undefined) return cached\n\n let surface = [255, 255, 255]\n for (const layer of layers) {\n const [r, g, b, alpha] = parseColor(layer)\n surface = [r, g, b].map((channel, i) => channel * alpha + surface[i] * (1 - alpha))\n }\n const hex = '#' + surface.map((channel) => Math.round(channel).toString(16).padStart(2, '0')).join('')\n if (surfaceCache.size > 200) surfaceCache.clear()\n surfaceCache.set(key, hex)\n return hex\n}\n\n// WCAG relative luminance of an opaque #rrggbb colour (0 black, 1 white).\nconst luminance = (hex: string): number => {\n const [r, g, b] = [1, 3, 5].map((i) => {\n const channel = parseInt(hex.slice(i, i + 2), 16) / 255\n return channel <= 0.03928 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4\n })\n return 0.2126 * r + 0.7152 * g + 0.0722 * b\n}\n\n/** WCAG contrast ratio of two opaque #rrggbb colours, from 1 to 21. */\nexport const contrast = (a: string, b: string): number => {\n const [lighter, darker] = [luminance(a), luminance(b)].sort((x, y) => y - x)\n return (lighter + 0.05) / (darker + 0.05)\n}\n\n// WCAG's minimum contrast for a control against its surroundings.\nconst ACCENT_CONTRAST = 3\n\nconst isColor = (color: unknown): color is string =>\n typeof color === 'string' && color.trim() !== '' && parseColor(color)[3] > 0\n\n/**\n * The accent: a configured colour as written; otherwise the theme's first\n * palette colour when it stands out from the surface; otherwise the text\n * colour, which is picked to read on the tile.\n */\nexport const accentColor = (configured: unknown, themeColor: unknown, surface: string, textColor: string): string => {\n if (isColor(configured)) return configured.trim()\n if (isColor(themeColor) && contrast(opaqueSurface([surface, themeColor]), surface) >= ACCENT_CONTRAST)\n return themeColor\n return textColor\n}\n\n/** Black or white, whichever reads better on the accent painted over the surface. */\nexport const onColor = (accent: string, surface: string): string => {\n const painted = opaqueSurface([surface, accent])\n return contrast(painted, '#ffffff') >= contrast(painted, '#000000') ? '#ffffff' : '#000000'\n}\n","import { html, css, nothing, LitElement, PropertyValues, TemplateResult } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\nimport { repeat } from 'lit/directives/repeat.js'\nimport { live } from 'lit/directives/live.js'\nimport { styleMap } from 'lit/directives/style-map.js'\nimport '@material/web/switch/switch.js'\nimport '@material/web/icon/icon.js'\nimport type { MdSwitch } from '@material/web/switch/switch.js'\nimport type { ToolbarConfiguration } from './definition-schema.js'\nimport { commitFor, paramsOf, reports, settled, toTools, type Commit, type Request, type ToolModel } from './tools.ts'\nimport { place, type Density, type Extent, type Item, type Placement } from './layout.ts'\nimport { accentColor, onColor, opaqueSurface } from './colors.ts'\n\ntype Theme = { theme_name: string; theme_object?: any }\n\ntype Popup = { kind: 'menu' } | { kind: 'dropdown'; key: string }\n\n// How long a tool keeps the value an operator set before it shows what its\n// source reports again: a bound value gets time for the row to travel to the\n// table and back, a URL parameter only for Studio to hand over the new route\n// (nothing hands one over in the widget editor, where the tool falls back).\nconst DATA_HOLD_MS = 10000\nconst URL_HOLD_MS = 2000\n\nconst ORIENTATIONS = ['horizontal', 'vertical'] as const\nconst SIZES = ['small', 'normal', 'big'] as const\nconst SHAPES = ['round', 'rounded', 'square'] as const\nconst ALIGNMENTS = { start: 'flex-start', center: 'center', end: 'flex-end' } as const\n\nconst oneOf = <T extends string>(value: unknown, allowed: readonly T[], fallback: T): T =>\n allowed.includes(value as T) ? (value as T) : fallback\n\n// Formatted in the viewer's locale; one formatter per number of decimals.\nconst formatters = new Map<number, Intl.NumberFormat>()\nconst formatNumber = (value: number, decimals: number): string => {\n let formatter = formatters.get(decimals)\n if (!formatter) {\n formatter = new Intl.NumberFormat(undefined, {\n minimumFractionDigits: decimals,\n maximumFractionDigits: decimals\n })\n formatters.set(decimals, formatter)\n }\n return formatter.format(value)\n}\n\n/** What decides the tools' sizes: a placement measured for another signature is stale. */\nconst layoutSignature = (tools: ToolModel[], orientation: string, size: string): string =>\n JSON.stringify([\n orientation,\n size,\n tools.map((t) => [\n t.control,\n t.label,\n t.buttonValue,\n t.icon,\n t.variant,\n t.unit,\n t.min,\n t.max,\n t.decimals,\n t.options.map((o) => [o.label, o.icon])\n ])\n ])\n\n@customElement('widget-toolbar-versionplaceholder')\nexport class WidgetToolbar extends LitElement {\n /** This tile's config, with every data binding already replaced by its data. */\n @property({ type: Object }) inputData?: ToolbarConfiguration\n\n /** The board's ECharts theme. theme_object is missing on boards without a theme. */\n @property({ type: Object }) theme?: Theme\n\n /** The page path relative to the board, with its ?query. The URL parameters are read from it. */\n @property({ type: String }) route?: string\n\n @state() private placement?: { placement: Placement; signature: string }\n @state() private popup?: Popup\n @state() private confirm?: { message: string; accent: string; onAccent: string }\n @state() private dragging?: { key: string; value: number }\n @state() private requestsVersion = 0\n\n @query('.bar') private bar?: HTMLElement\n @query('.ruler') private ruler?: HTMLElement\n @query('.popup') private popupEl?: HTMLElement\n @query('dialog.confirm') private dialog?: HTMLDialogElement\n\n version: string = 'versionplaceholder'\n\n private tools: ToolModel[] = []\n private signature = ''\n private measuredSignature?: string\n // What operators set, by tool key, until the tool's source agrees.\n private requests = new Map<string, Request>()\n private confirmAction?: () => void\n\n private observer = new ResizeObserver(() => this.scheduleMeasure())\n private observed: Element[] = []\n private measureFrame = 0\n\n private popupAnchor?: HTMLElement\n private popupFrame = 0\n private popupRect = ''\n\n // Colours resolved at render (see resolveColors()).\n private surface = '#ffffff'\n private accentDefault = '#5470c6'\n\n connectedCallback(): void {\n super.connectedCallback()\n if (!this.hasUpdated) return\n // Studio moves a tile by detaching and re-attaching it in one task.\n this.observeLayout(true)\n // A modal <dialog> leaves the top layer when it is detached but keeps\n // its open attribute: close it and show it again (as widget-form does).\n // The close event this queues finds the dialog open again and is ignored.\n const dialog = this.dialog\n if (this.confirm && dialog?.open) {\n dialog.close()\n this.showDialog()\n }\n }\n\n disconnectedCallback(): void {\n super.disconnectedCallback()\n this.observer.disconnect()\n this.observed = []\n cancelAnimationFrame(this.measureFrame)\n this.measureFrame = 0\n // A menu is fleeting; it does not survive a move.\n this.closePopup()\n // Held requests with a timer would fire into a detached element.\n for (const [key, request] of this.requests) {\n if (request.timer === undefined) continue\n clearTimeout(request.timer)\n this.requests.delete(key)\n }\n // A move re-attaches within this task; anything else ends the question.\n setTimeout(() => {\n if (!this.isConnected && this.confirm) this.endConfirm(false)\n })\n }\n\n protected willUpdate(changed: PropertyValues): void {\n if (changed.has('inputData') || changed.has('route') || changed.has('requestsVersion')) {\n this.settleRequests()\n }\n this.tools = toTools(this.inputData, this.route, this.requests)\n this.signature = layoutSignature(this.tools, this.orientation, this.size)\n }\n\n protected updated(): void {\n // md-switch binds its checkbox's checked *attribute*, which a browser\n // stops honouring once the user has clicked it. Without this, a switch\n // moved by a report, a timeout, a cancelled confirmation or the URL\n // keeps its checkbox on the old position, and the next click toggles\n // from there. (widget-switch has the same fix.)\n this.shadowRoot?.querySelectorAll('md-switch').forEach((sw) => {\n const input = sw.shadowRoot?.querySelector('input')\n if (input && input.checked !== sw.selected) input.checked = sw.selected\n })\n this.observeLayout(false)\n if (this.signature !== this.measuredSignature) this.scheduleMeasure()\n }\n\n private get orientation() {\n return oneOf(this.inputData?.orientation, ORIENTATIONS, 'horizontal')\n }\n\n private get size() {\n return oneOf(this.inputData?.size, SIZES, 'normal')\n }\n\n private get shape() {\n return oneOf(this.inputData?.shape, SHAPES, 'round')\n }\n\n // ---------------------------------------------------------------- state --\n\n /** Drop the held values whose source now agrees, or whose tool is gone. */\n private settleRequests() {\n if (!this.requests.size) return\n const current = new Map(reports(this.inputData, paramsOf(this.route)).map((r) => [r.key, r]))\n for (const [key, request] of this.requests) {\n const report = current.get(key)\n if (!report || settled(report, request)) {\n clearTimeout(request.timer)\n this.requests.delete(key)\n }\n }\n }\n\n /** An operator moved a tool to `next`. Writes it, after the confirmation if one is set. */\n private interact(model: ToolModel, next?: unknown) {\n const commit = commitFor(this.inputData, model, next)\n if (!commit) {\n // Nothing to write (a key column lost its value): put the tool back.\n this.requestUpdate()\n return\n }\n if (model.confirmText) {\n this.closePopup()\n const { accent, onAccent } = this.toolColors(model)\n this.confirmAction = () => this.apply(model, commit)\n this.confirm = { message: model.confirmText, accent, onAccent }\n this.updateComplete.then(() => this.showDialog())\n return\n }\n this.apply(model, commit)\n }\n\n private apply(model: ToolModel, commit: Commit) {\n const { key } = model\n clearTimeout(this.requests.get(key)?.timer)\n this.requests.delete(key)\n // A button with nothing to report back has no state to hold.\n if (!(model.control === 'button' && model.source === 'local')) {\n const hold = model.source === 'url' ? URL_HOLD_MS : model.source === 'data' ? DATA_HOLD_MS : undefined\n const timer =\n hold === undefined\n ? undefined\n : setTimeout(() => {\n this.requests.delete(key)\n this.requestsVersion++\n }, hold)\n this.requests.set(key, { expected: commit.expected, timer })\n }\n this.requestsVersion++\n\n // Studio writes the row into the app's table, grouped per table, with\n // tsp; the stored value comes back through the tool's value binding.\n if (commit.items) {\n this.dispatchEvent(new CustomEvent('data-submit', { detail: commit.items, bubbles: false, composed: false }))\n }\n // Studio merges the parameters into the page URL (undefined removes\n // one) and hands the new route back, which is where the tool reads it.\n if (commit.params) {\n this.dispatchEvent(\n new CustomEvent('param-submit', { detail: { params: commit.params }, bubbles: true, composed: true })\n )\n }\n }\n\n // ------------------------------------------------------------ confirm --\n\n private showDialog() {\n const dialog = this.dialog\n if (!dialog || !this.isConnected || dialog.open || !this.confirm) return\n dialog.returnValue = ''\n try {\n dialog.showModal()\n } catch {\n this.endConfirm(false)\n }\n }\n\n private onDialogClose() {\n const dialog = this.dialog\n // Open again: the close of a re-show after a tile move.\n if (!dialog || dialog.open || !this.confirm) return\n this.endConfirm(dialog.returnValue === 'ok')\n }\n\n private endConfirm(ok: boolean) {\n const action = this.confirmAction\n this.confirmAction = undefined\n this.confirm = undefined\n if (this.dialog?.open) this.dialog.close()\n if (ok) action?.()\n // A cancelled switch or slider goes back to where it was.\n else this.requestUpdate()\n }\n\n // ------------------------------------------------------------- layout --\n\n /** Observe the host and every ruler slot; re-observe when the slots changed. */\n private observeLayout(force: boolean) {\n const slots = this.ruler ? [...this.ruler.children] : []\n if (!force && slots.length === this.observed.length && slots.every((s, i) => s === this.observed[i])) return\n this.observer.disconnect()\n this.observer.observe(this)\n slots.forEach((slot) => this.observer.observe(slot))\n this.observed = slots\n this.scheduleMeasure()\n }\n\n // A ResizeObserver callback that changes what it observes would loop:\n // measure in the next frame instead.\n private scheduleMeasure() {\n if (this.measureFrame || !this.isConnected) return\n this.measureFrame = requestAnimationFrame(() => {\n this.measureFrame = 0\n this.measure()\n })\n }\n\n private measure() {\n const bar = this.bar\n const ruler = this.ruler\n if (!bar || !ruler || !this.isConnected) return\n const box = bar.getBoundingClientRect()\n // A hidden page (display: none) or a collapsed tile measures 0: keep\n // what was placed, and measure again once it has a size.\n if (box.width === 0 || box.height === 0) return\n const slots = [...ruler.children]\n const tools = this.tools\n if (slots.length !== tools.length * 2 + 1) return\n\n const vertical = this.orientation === 'vertical'\n const extent = (el: Element): Extent => {\n const r = el.getBoundingClientRect()\n return vertical ? { main: r.height, cross: r.width } : { main: r.width, cross: r.height }\n }\n const items: Item[] = tools.map((tool, i) => ({\n kind: tool.control === 'separator' ? 'separator' : tool.control === 'spacer' ? 'spacer' : 'tool',\n full: extent(slots[2 * i]),\n compact: extent(slots[2 * i + 1])\n }))\n // Not laid out yet: wait for the ruler's own resize.\n if (items.some((item) => item.kind === 'tool' && item.full.main === 0)) return\n\n const style = getComputedStyle(bar)\n const px = (value: string) => parseFloat(value) || 0\n const width = box.width - px(style.paddingLeft) - px(style.paddingRight)\n const height = box.height - px(style.paddingTop) - px(style.paddingBottom)\n const placement = place({\n items,\n available: vertical ? { main: height, cross: width } : { main: width, cross: height },\n gap: px(vertical ? style.rowGap : style.columnGap),\n more: extent(slots[slots.length - 1]),\n checkCross: vertical\n })\n this.measuredSignature = this.signature\n const next = { placement, signature: this.signature }\n if (JSON.stringify(next) !== JSON.stringify(this.placement)) this.placement = next\n }\n\n // -------------------------------------------------------------- popup --\n\n private async togglePopup(popup: Popup, anchor: HTMLElement) {\n const current = this.popup\n const same =\n current?.kind === popup.kind &&\n (popup.kind === 'menu' || (current.kind === 'dropdown' && current.key === popup.key))\n if (current) this.closePopup()\n if (same) return\n this.popupAnchor = anchor\n this.popup = popup\n await this.updateComplete\n const el = this.popupEl\n if (!el || !this.isConnected || this.popup !== popup) return\n try {\n if (!el.matches(':popover-open')) el.showPopover()\n } catch {\n this.closePopup()\n return\n }\n this.popupRect = ''\n this.trackPopup()\n window.addEventListener('pointerdown', this.onOutsidePointer, true)\n window.addEventListener('keydown', this.onPopupKey, true)\n const first =\n el.querySelector<HTMLElement>('button[data-current]') ??\n el.querySelector<HTMLElement>('button:not(:disabled), input:not(:disabled), md-switch:not([disabled])')\n first?.focus({ preventScroll: true })\n }\n\n private closePopup() {\n cancelAnimationFrame(this.popupFrame)\n this.popupFrame = 0\n window.removeEventListener('pointerdown', this.onOutsidePointer, true)\n window.removeEventListener('keydown', this.onPopupKey, true)\n try {\n if (this.popupEl?.matches(':popover-open')) this.popupEl.hidePopover()\n } catch {\n // Already gone with the element.\n }\n this.popup = undefined\n this.popupAnchor = undefined\n }\n\n private onOutsidePointer = (event: Event) => {\n const path = event.composedPath()\n if ((this.popupEl && path.includes(this.popupEl)) || (this.popupAnchor && path.includes(this.popupAnchor))) return\n this.closePopup()\n }\n\n private onPopupKey = (event: KeyboardEvent) => {\n if (event.key !== 'Escape') return\n const anchor = this.popupAnchor\n this.closePopup()\n anchor?.focus({ preventScroll: true })\n }\n\n /**\n * Keep the open popup next to its trigger, frame by frame: the board\n * scrolls inside its own element, whose scroll events never reach this\n * one. A trigger that collapsed (a hidden page) or left the page (the\n * layout moved it into the menu) closes the popup.\n */\n private trackPopup = () => {\n const anchor = this.popupAnchor\n const el = this.popupEl\n if (!anchor || !el || !this.popup) return\n const rect = anchor.getBoundingClientRect()\n if (!anchor.isConnected || (rect.width === 0 && rect.height === 0)) {\n this.closePopup()\n return\n }\n const key = [rect.left, rect.top, rect.width, rect.height, innerWidth, innerHeight].join()\n if (key !== this.popupRect) {\n this.popupRect = key\n this.positionPopup(el, rect)\n }\n this.popupFrame = requestAnimationFrame(this.trackPopup)\n }\n\n private positionPopup(el: HTMLElement, anchor: DOMRect) {\n const margin = 4\n el.style.minWidth = this.popup?.kind === 'dropdown' ? `${anchor.width}px` : ''\n el.style.maxHeight = `${Math.max(0, innerHeight - 2 * margin)}px`\n const width = el.offsetWidth\n const height = el.offsetHeight\n let top = anchor.bottom + margin\n if (top + height > innerHeight - margin && anchor.top - margin - height >= margin) {\n top = anchor.top - margin - height\n }\n top = Math.min(Math.max(top, margin), Math.max(margin, innerHeight - margin - height))\n // The menu hangs from the ⋮ button's end, a dropdown list from its start.\n let left = this.popup?.kind === 'menu' ? anchor.right - width : anchor.left\n left = Math.min(Math.max(left, margin), Math.max(margin, innerWidth - margin - width))\n el.style.top = `${top}px`\n el.style.left = `${left}px`\n }\n\n // -------------------------------------------------------------- colours --\n\n /**\n * The colours that have to be real colours, resolved at render and never\n * cached across renders: the opaque surface of the menu and the dialog\n * (the tile is usually translucent), and the accent with the text colour\n * on it. Text itself uses var() chains, which follow a board style edit\n * without a render.\n */\n private resolveColors() {\n const style = getComputedStyle(this)\n const tile = style.getPropertyValue('--re-tile-background-color').trim()\n const board = style.getPropertyValue('--re-background-color').trim()\n const themeBg = String(this.theme?.theme_object?.backgroundColor ?? '')\n this.surface = opaqueSurface(board ? [board, tile || themeBg] : [themeBg, tile])\n const text =\n style.getPropertyValue('--re-text-color').trim() ||\n this.theme?.theme_object?.title?.textStyle?.color ||\n style.color ||\n '#333333'\n this.accentDefault = accentColor(\n this.inputData?.accentColor,\n this.theme?.theme_object?.color?.[0],\n this.surface,\n text\n )\n }\n\n private toolColors(tool: ToolModel) {\n const accent = accentColor(tool.color, undefined, this.surface, this.accentDefault)\n return { accent, onAccent: onColor(accent, this.surface) }\n }\n\n private toolStyle(tool: ToolModel) {\n const { accent, onAccent } = this.toolColors(tool)\n return styleMap({ '--accent': accent, '--on-accent': onAccent })\n }\n\n // -------------------------------------------------------------- render --\n\n static styles = css`\n :host {\n display: block;\n box-sizing: border-box;\n /* clip, not hidden: the ruler is taller than the tile, and a\n hidden overflow can still be scrolled (focus, scrollIntoView),\n which shifted the bar out of the tile. */\n overflow: clip;\n position: relative;\n font-family: Roboto, 'Helvetica Neue', Arial, sans-serif;\n }\n\n .root {\n height: 100%;\n width: 100%;\n color: var(--text);\n --h: 36px;\n --font: 14px;\n --icon: 20px;\n --gap: 12px;\n --pad: 6px;\n --slider: 140px;\n --slider-compact: 88px;\n --switch-scale: 0.8;\n /* Corner radius as a share of the control's height, so a shape\n holds at every size: 0.5 makes pill-shaped ends. */\n --round: 0.5;\n }\n .root[data-shape='rounded'] {\n --round: 0.2;\n }\n .root[data-shape='square'] {\n --round: 0;\n }\n .root[data-size='small'] {\n --h: 28px;\n --font: 12px;\n --icon: 18px;\n --gap: 8px;\n --pad: 4px;\n --slider: 110px;\n --slider-compact: 72px;\n --switch-scale: 0.65;\n }\n .root[data-size='big'] {\n --h: 48px;\n --font: 18px;\n --icon: 26px;\n --gap: 16px;\n --pad: 8px;\n --slider: 180px;\n --slider-compact: 110px;\n --switch-scale: 1.1;\n }\n\n .bar {\n box-sizing: border-box;\n height: 100%;\n width: 100%;\n display: flex;\n align-items: center;\n gap: var(--gap);\n padding: var(--pad) calc(var(--pad) * 2);\n overflow: clip;\n }\n .root[data-orientation='vertical'] .bar {\n flex-direction: column;\n align-items: stretch;\n padding: calc(var(--pad) * 2) var(--pad);\n }\n .bar > * {\n flex: none;\n }\n .bar > .spacer {\n flex: 1 1 0;\n }\n\n /* A copy of every tool at both densities, measured, never seen. */\n .ruler {\n position: absolute;\n top: 0;\n left: 0;\n width: max-content;\n display: flex;\n flex-direction: column;\n align-items: flex-start;\n visibility: hidden;\n pointer-events: none;\n z-index: -1;\n }\n .slot {\n display: flex;\n width: max-content;\n }\n\n md-icon {\n --md-icon-size: var(--icon);\n flex: none;\n }\n\n .text {\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n min-width: 0;\n }\n\n button {\n font: inherit;\n color: inherit;\n }\n button:focus-visible,\n input:focus-visible {\n outline: 2px solid var(--accent, currentColor);\n outline-offset: 2px;\n }\n\n /* Buttons, and the dropdown trigger and ⋮, which look like them. */\n .button {\n box-sizing: border-box;\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 0.4em;\n height: var(--h);\n min-width: var(--h);\n padding: 0 calc(var(--h) * 0.42);\n border: 1px solid transparent;\n border-radius: calc(var(--h) * var(--round));\n font-size: var(--font);\n font-weight: 500;\n line-height: 1;\n white-space: nowrap;\n cursor: pointer;\n background: transparent;\n }\n .button.icon-only {\n padding: 0;\n width: var(--h);\n }\n .button[data-variant='filled'] {\n background-color: var(--accent);\n color: var(--on-accent);\n }\n .button[data-variant='tonal'] {\n background-color: color-mix(in srgb, var(--accent) 22%, transparent);\n }\n .button[data-variant='outlined'] {\n border-color: color-mix(in srgb, currentColor 45%, transparent);\n }\n .button[data-variant='text'] {\n color: var(--accent);\n }\n .button:hover:not(:disabled),\n .segment:hover:not(:disabled),\n .menu-item:hover:not(:disabled) {\n background-image: linear-gradient(\n color-mix(in srgb, currentColor 10%, transparent),\n color-mix(in srgb, currentColor 10%, transparent)\n );\n }\n /* A button whose value is the current one, as in a mode selector. */\n .button[data-active] {\n box-shadow: inset 0 0 0 2px var(--accent);\n }\n .button[data-active]:not([data-variant='filled']) {\n background-color: color-mix(in srgb, var(--accent) 28%, transparent);\n }\n .button[data-active][data-variant='filled'] {\n box-shadow:\n inset 0 0 0 2px var(--accent),\n inset 0 0 0 4px var(--on-accent);\n }\n\n button:disabled,\n input:disabled,\n [data-disabled] {\n cursor: default;\n opacity: 0.4;\n }\n\n .tool {\n display: inline-flex;\n align-items: center;\n gap: 0.5em;\n font-size: var(--font);\n white-space: nowrap;\n min-width: 0;\n }\n /* In a strip the label takes the row, so a switch sits at its end.\n A dropdown, choice group or slider takes the rest of the row\n instead. Every basis is the content's own width, never 0: with\n flex: 1 the label and the control split the row in half, and the\n control was cut off below the width the ruler measured. Only the\n label gives way (with an ellipsis) when the row is short. */\n .root[data-orientation='vertical'] .bar > .tool > .text {\n flex: 1 1 auto;\n }\n .root[data-orientation='vertical'] .bar > .tool:is(.dropdown, .choice, .slider) > .text {\n flex: 0 1 auto;\n }\n\n md-switch {\n --md-switch-track-width: calc(52px * var(--switch-scale));\n --md-switch-track-height: calc(32px * var(--switch-scale));\n --md-switch-handle-width: calc(16px * var(--switch-scale));\n --md-switch-handle-height: calc(16px * var(--switch-scale));\n --md-switch-selected-handle-width: calc(24px * var(--switch-scale));\n --md-switch-selected-handle-height: calc(24px * var(--switch-scale));\n --md-switch-pressed-handle-width: calc(28px * var(--switch-scale));\n --md-switch-pressed-handle-height: calc(28px * var(--switch-scale));\n --md-switch-state-layer-size: calc(40px * var(--switch-scale));\n /* The button shape: the track by its height, the handle by its own size. */\n --md-switch-track-shape: calc(32px * var(--switch-scale) * var(--round));\n --md-switch-handle-shape: calc(var(--round) * 100%);\n --md-switch-selected-handle-color: var(--accent);\n --md-switch-selected-hover-handle-color: var(--accent);\n --md-switch-selected-focus-handle-color: var(--accent);\n --md-switch-selected-pressed-handle-color: var(--accent);\n --md-switch-selected-track-color: color-mix(in srgb, var(--accent) 40%, transparent);\n --md-switch-selected-hover-track-color: color-mix(in srgb, var(--accent) 50%, transparent);\n --md-switch-selected-focus-track-color: color-mix(in srgb, var(--accent) 50%, transparent);\n --md-switch-selected-pressed-track-color: color-mix(in srgb, var(--accent) 50%, transparent);\n /* OFF: Material 2.4.1 names these without \"unselected\". */\n --switch-off-track: color-mix(in srgb, var(--text) 20%, transparent);\n --md-switch-handle-color: var(--text);\n --md-switch-hover-handle-color: var(--text);\n --md-switch-focus-handle-color: var(--text);\n --md-switch-pressed-handle-color: var(--text);\n --md-switch-track-color: var(--switch-off-track);\n --md-switch-hover-track-color: var(--switch-off-track);\n --md-switch-focus-track-color: var(--switch-off-track);\n --md-switch-pressed-track-color: var(--switch-off-track);\n --md-switch-track-outline-color: var(--text);\n --md-switch-hover-track-outline-color: var(--text);\n --md-switch-focus-track-outline-color: var(--text);\n --md-switch-pressed-track-outline-color: var(--text);\n /* Material's disabled colours are its light scheme's near-black,\n which vanishes on a dark tile. */\n --md-switch-disabled-handle-color: var(--text);\n --md-switch-disabled-track-outline-color: var(--text);\n --md-switch-disabled-selected-track-color: var(--text);\n --md-switch-disabled-selected-handle-color: var(--text);\n flex: none;\n }\n\n input[type='range'] {\n accent-color: var(--accent);\n width: var(--slider);\n margin: 0;\n min-width: 0;\n cursor: pointer;\n }\n .compact input[type='range'] {\n width: var(--slider-compact);\n }\n .root[data-orientation='vertical'] .bar input[type='range'] {\n flex: 1 0 auto;\n }\n .readout {\n font-variant-numeric: tabular-nums;\n white-space: nowrap;\n }\n\n /* Several texts in one grid cell, only one visible: the cell is as\n wide as the widest, so a changing value never changes the width. */\n .stack {\n display: inline-grid;\n text-align: end;\n }\n .stack > * {\n grid-area: 1 / 1;\n }\n .stack > :not([data-current]) {\n visibility: hidden;\n }\n /* In a strip the trigger is wider than its text: the text takes the\n room, so it starts after the icon and the arrow stays at the end. */\n .trigger .stack {\n flex: 1 1 auto;\n text-align: start;\n }\n\n .segments {\n display: inline-flex;\n height: var(--h);\n box-sizing: border-box;\n border: 1px solid color-mix(in srgb, currentColor 40%, transparent);\n border-radius: calc(var(--h) * var(--round));\n overflow: hidden;\n }\n .root[data-orientation='vertical'] .bar .segments {\n flex: 1 0 auto;\n }\n .segment {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 0.35em;\n flex: 1 0 auto;\n padding: 0 0.85em;\n border: none;\n background: transparent;\n font-size: var(--font);\n cursor: pointer;\n white-space: nowrap;\n }\n .segment.icon-only {\n padding: 0 0.5em;\n }\n .segment + .segment {\n border-left: 1px solid color-mix(in srgb, currentColor 40%, transparent);\n }\n .segment[aria-checked='true'] {\n background-color: var(--accent);\n color: var(--on-accent);\n }\n\n .trigger {\n justify-content: space-between;\n padding: 0 0.3em 0 0.8em;\n }\n .root[data-orientation='vertical'] .bar .trigger {\n flex: 1 0 auto;\n }\n\n .label {\n opacity: 0.85;\n }\n\n .separator {\n align-self: center;\n width: 1px;\n height: calc(var(--h) * 0.7);\n background: color-mix(in srgb, currentColor 30%, transparent);\n }\n .root[data-orientation='vertical'] .separator {\n width: auto;\n height: 1px;\n align-self: stretch;\n }\n .spacer {\n min-width: 0;\n min-height: 0;\n }\n\n /* The menu and dropdown lists live in the top layer: the tile clips. */\n .popup {\n position: fixed;\n inset: auto;\n margin: 0;\n box-sizing: border-box;\n min-width: 180px;\n max-width: min(340px, calc(100vw - 8px));\n padding: 6px 0;\n overflow: auto;\n border: 1px solid color-mix(in srgb, var(--text) 18%, transparent);\n border-radius: 10px;\n background: var(--surface);\n color: var(--text);\n box-shadow: 0 6px 20px rgb(0 0 0 / 0.25);\n font-size: 14px;\n --h: 36px;\n --font: 14px;\n --icon: 20px;\n --switch-scale: 0.8;\n }\n .menu-item {\n box-sizing: border-box;\n display: flex;\n align-items: center;\n gap: 12px;\n width: 100%;\n min-height: 40px;\n padding: 4px 16px;\n border: none;\n background: transparent;\n text-align: start;\n font-size: 14px;\n cursor: pointer;\n }\n .menu-item .text {\n flex: 1;\n }\n .menu-item.column {\n flex-direction: column;\n align-items: stretch;\n gap: 4px;\n cursor: default;\n }\n .menu-item.column > .row {\n display: flex;\n align-items: center;\n gap: 12px;\n }\n .menu-item input[type='range'] {\n flex: 1;\n width: auto;\n }\n .menu-item[aria-checked='true'],\n .menu-item[data-active] {\n background-color: color-mix(in srgb, var(--accent) 18%, transparent);\n }\n .menu-heading {\n display: flex;\n align-items: center;\n gap: 12px;\n padding: 8px 16px 2px;\n font-size: 12px;\n opacity: 0.75;\n }\n .check {\n visibility: hidden;\n color: var(--accent);\n }\n [aria-checked='true'] > .check {\n visibility: visible;\n }\n .popup hr {\n margin: 6px 0;\n border: none;\n border-top: 1px solid color-mix(in srgb, var(--text) 18%, transparent);\n }\n\n dialog.confirm {\n box-sizing: border-box;\n max-width: min(380px, calc(100vw - 32px));\n padding: 20px 24px 16px;\n border: none;\n border-radius: 14px;\n background: var(--surface);\n color: var(--text);\n box-shadow: 0 8px 28px rgb(0 0 0 / 0.3);\n font-size: 15px;\n line-height: 1.4;\n }\n dialog.confirm::backdrop {\n background: rgb(0 0 0 / 0.32);\n }\n dialog.confirm p {\n margin: 0;\n overflow-wrap: anywhere;\n }\n dialog.confirm .actions {\n display: flex;\n justify-content: flex-end;\n gap: 8px;\n margin-top: 20px;\n --h: 36px;\n --font: 14px;\n }\n `\n\n render() {\n this.resolveColors()\n const tools = this.tools\n const orientation = this.orientation\n const vertical = orientation === 'vertical'\n const alignment = oneOf(this.inputData?.alignment, ['start', 'center', 'end'] as const, 'start')\n // Until the tools are measured for this config, show them all.\n const placement: Placement =\n this.placement && this.placement.signature === this.signature\n ? this.placement.placement\n : { visible: tools.map((_, i) => i), compact: [], overflow: [] }\n const themeText = this.theme?.theme_object?.title?.textStyle?.color\n // The host's --re-text-color wins; the theme's colour is the fallback.\n const text = `var(--re-text-color, ${typeof themeText === 'string' && themeText ? themeText : 'inherit'})`\n\n return html`\n <div\n class=\"root\"\n data-orientation=${orientation}\n data-size=${this.size}\n data-shape=${this.shape}\n style=${styleMap({ '--text': text, '--surface': this.surface })}\n >\n <div\n class=\"bar\"\n role=\"toolbar\"\n aria-orientation=${orientation}\n style=${styleMap({ justifyContent: ALIGNMENTS[alignment] })}\n >\n ${repeat(\n placement.visible.filter((i) => tools[i]),\n (i) => tools[i].key,\n (i) => this.renderTool(tools[i], placement.compact.includes(i) ? 'compact' : 'full')\n )}\n ${placement.overflow.length ? this.renderMore(vertical, this.popup?.kind === 'menu') : nothing}\n </div>\n <div class=\"ruler\" inert aria-hidden=\"true\">\n ${repeat(\n tools,\n (tool) => tool.key,\n (tool) => html`\n <div class=\"slot\">${this.renderTool(tool, 'full', true)}</div>\n <div class=\"slot\">${this.renderTool(tool, 'compact', true)}</div>\n `\n )}\n <div class=\"slot\">${this.renderMore(vertical, false)}</div>\n </div>\n <div class=\"popup\" popover=\"manual\" role=${this.popup?.kind === 'dropdown' ? 'listbox' : nothing}>\n ${this.renderPopup(placement)}\n </div>\n <dialog\n class=\"confirm\"\n @close=${this.onDialogClose}\n @cancel=${(e: Event) => {\n // Escape answers \"no\".\n e.preventDefault()\n this.endConfirm(false)\n }}\n >\n ${this.confirm\n ? html`\n <p>${this.confirm.message}</p>\n <form method=\"dialog\" class=\"actions\">\n <button class=\"button\" value=\"cancel\">Cancel</button>\n <button\n class=\"button\"\n data-variant=\"filled\"\n value=\"ok\"\n autofocus\n style=${styleMap({\n '--accent': this.confirm.accent,\n '--on-accent': this.confirm.onAccent\n })}\n >\n OK\n </button>\n </form>\n `\n : nothing}\n </dialog>\n </div>\n `\n }\n\n private renderMore(vertical: boolean, open: boolean) {\n return html`\n <button\n class=\"button icon-only more\"\n aria-label=\"More tools\"\n aria-haspopup=\"true\"\n aria-expanded=${open ? 'true' : 'false'}\n @click=${(e: Event) => this.togglePopup({ kind: 'menu' }, e.currentTarget as HTMLElement)}\n >\n <md-icon aria-hidden=\"true\">${vertical ? 'more_horiz' : 'more_vert'}</md-icon>\n </button>\n `\n }\n\n private icon(name?: string) {\n return name ? html`<md-icon aria-hidden=\"true\">${name}</md-icon>` : nothing\n }\n\n /** One tool in the bar, or with `ruler` its measured copy. */\n private renderTool(tool: ToolModel, density: Density, ruler = false): TemplateResult {\n const compact = density === 'compact'\n // Compact drops a label only where an icon stands in for it.\n const showLabel = !!tool.label && !(compact && tool.icon)\n\n switch (tool.control) {\n case 'separator':\n return html`<span class=\"separator\" role=\"separator\"></span>`\n case 'spacer':\n return html`<span class=\"spacer\"></span>`\n case 'label':\n return html`<span class=\"tool label\">${this.icon(tool.icon)}<span class=\"text\">${tool.label}</span></span>`\n case 'button': {\n const label = tool.label || tool.buttonValue\n const iconOnly = !!tool.icon && (!label || compact)\n return html`\n <button\n class=\"button ${iconOnly ? 'icon-only' : ''}\"\n data-variant=${tool.variant}\n ?data-active=${tool.active}\n aria-pressed=${tool.buttonValue.trim() ? (tool.active ? 'true' : 'false') : nothing}\n aria-label=${label || nothing}\n title=${iconOnly && label ? label : nothing}\n ?disabled=${tool.disabled}\n style=${this.toolStyle(tool)}\n @click=${ruler ? nothing : () => this.interact(tool)}\n >\n ${this.icon(tool.icon)}${iconOnly ? nothing : html`<span class=\"text\">${label}</span>`}\n </button>\n `\n }\n case 'switch':\n return html`\n <label class=\"tool switch\" ?data-disabled=${tool.disabled} style=${this.toolStyle(tool)}>\n ${this.icon(tool.icon)}${showLabel ? html`<span class=\"text\">${tool.label}</span>` : nothing}\n <md-switch\n aria-label=${tool.label || nothing}\n .selected=${live(tool.on)}\n ?disabled=${tool.disabled}\n @change=${ruler\n ? nothing\n : (e: Event) => this.interact(tool, (e.target as MdSwitch).selected)}\n ></md-switch>\n </label>\n `\n case 'slider':\n return html`\n <div\n class=\"tool slider ${compact ? 'compact' : ''}\"\n ?data-disabled=${tool.disabled}\n style=${this.toolStyle(tool)}\n >\n ${this.icon(tool.icon)}${showLabel ? html`<span class=\"text\">${tool.label}</span>` : nothing}\n ${this.renderRange(tool, ruler)}\n </div>\n `\n case 'choice':\n return html`\n <div\n class=\"tool choice\"\n role=\"radiogroup\"\n aria-label=${tool.label || nothing}\n style=${this.toolStyle(tool)}\n >\n ${tool.label && !compact ? html`<span class=\"text\">${tool.label}</span>` : nothing}\n <div class=\"segments\">\n ${tool.options.map((option, j) => {\n const iconOnly = compact && !!option.icon\n return html`\n <button\n class=\"segment ${iconOnly ? 'icon-only' : ''}\"\n role=\"radio\"\n aria-checked=${j === tool.selected ? 'true' : 'false'}\n aria-label=${option.label || nothing}\n title=${iconOnly && option.label ? option.label : nothing}\n ?disabled=${tool.disabled}\n @click=${ruler ? nothing : () => this.pick(tool, j)}\n >\n ${this.icon(option.icon)}${iconOnly ? nothing : option.label}\n </button>\n `\n })}\n </div>\n </div>\n `\n case 'dropdown': {\n const open = !ruler && this.popup?.kind === 'dropdown' && this.popup.key === tool.key\n return html`\n <div class=\"tool dropdown\" style=${this.toolStyle(tool)}>\n ${tool.label && !compact ? html`<span class=\"text\">${tool.label}</span>` : nothing}\n <button\n class=\"button trigger\"\n data-variant=\"outlined\"\n aria-haspopup=\"listbox\"\n aria-expanded=${open ? 'true' : 'false'}\n aria-label=${tool.label || nothing}\n ?disabled=${tool.disabled}\n @click=${ruler\n ? nothing\n : (e: Event) =>\n this.togglePopup({ kind: 'dropdown', key: tool.key }, e.currentTarget as HTMLElement)}\n >\n ${this.icon(tool.icon)}\n <span class=\"stack\">\n ${tool.options.map(\n (option, j) => html`<span ?data-current=${j === tool.selected}>${option.label}</span>`\n )}\n <span ?data-current=${tool.selected < 0}>–</span>\n </span>\n <md-icon aria-hidden=\"true\">arrow_drop_down</md-icon>\n </button>\n </div>\n `\n }\n }\n }\n\n /** A slider's range input and its value, in a width that never depends on the value. */\n private renderRange(tool: ToolModel, ruler: boolean) {\n const dragged = !ruler && this.dragging?.key === tool.key ? this.dragging.value : undefined\n const value = dragged ?? tool.sliderValue\n return html`\n <input\n type=\"range\"\n min=${tool.min}\n max=${tool.max}\n step=${tool.step}\n .value=${live(String(value))}\n aria-label=${tool.label || nothing}\n aria-valuetext=${`${formatNumber(value, tool.decimals)}${tool.unit ? ' ' + tool.unit : ''}`}\n ?disabled=${tool.disabled}\n @input=${ruler\n ? nothing\n : (e: Event) => {\n this.dragging = { key: tool.key, value: Number((e.target as HTMLInputElement).value) }\n }}\n @change=${ruler\n ? nothing\n : (e: Event) => {\n this.dragging = undefined\n this.interact(tool, Number((e.target as HTMLInputElement).value))\n }}\n />\n <span class=\"readout\"\n ><span class=\"stack\"\n ><span>${formatNumber(tool.min, tool.decimals)}</span\n ><span>${formatNumber(tool.max, tool.decimals)}</span\n ><span data-current>${formatNumber(value, tool.decimals)}</span></span\n >${tool.unit ? ` ${tool.unit}` : nothing}</span\n >\n `\n }\n\n private pick(tool: ToolModel, index: number) {\n // Picking what is already picked writes nothing: no duplicate row, no\n // extra step in the browser history.\n if (index === tool.selected) return\n const option = tool.options[index]\n if (option) this.interact(tool, option.value)\n }\n\n /** The open popup's content: the ⋮ menu's tools, or a dropdown's options. */\n private renderPopup(placement: Placement) {\n const popup = this.popup\n if (!popup) return nothing\n if (popup.kind === 'dropdown') {\n const tool = this.tools.find((t) => t.key === popup.key)\n if (!tool) return nothing\n return html`<div style=${this.toolStyle(tool)}>${this.renderChoices(tool, 'option')}</div>`\n }\n return placement.overflow.map((i) => (this.tools[i] ? this.renderMenuTool(this.tools[i]) : nothing))\n }\n\n private renderChoices(tool: ToolModel, role: 'option' | 'radio') {\n return tool.options.map(\n (option, j) => html`\n <button\n class=\"menu-item\"\n role=${role}\n aria-checked=${role === 'radio' ? (j === tool.selected ? 'true' : 'false') : nothing}\n aria-selected=${role === 'option' ? (j === tool.selected ? 'true' : 'false') : nothing}\n ?data-current=${j === tool.selected}\n ?disabled=${tool.disabled}\n @click=${() => {\n this.closePopup()\n this.pick(tool, j)\n }}\n >\n ${this.icon(option.icon)}<span class=\"text\">${option.label}</span>\n <md-icon\n class=\"check\"\n aria-hidden=\"true\"\n style=${j === tool.selected ? 'visibility: visible' : nothing}\n >check</md-icon\n >\n </button>\n `\n )\n }\n\n /** A tool as a row of the ⋮ menu. */\n private renderMenuTool(tool: ToolModel): TemplateResult | typeof nothing {\n const style = this.toolStyle(tool)\n switch (tool.control) {\n case 'separator':\n return html`<hr />`\n case 'spacer':\n return nothing\n case 'label':\n return html`<div class=\"menu-heading\">${this.icon(tool.icon)}${tool.label}</div>`\n case 'button': {\n const label = tool.label || tool.buttonValue\n return html`\n <button\n class=\"menu-item\"\n ?data-active=${tool.active}\n aria-pressed=${tool.buttonValue.trim() ? (tool.active ? 'true' : 'false') : nothing}\n ?disabled=${tool.disabled}\n style=${style}\n @click=${() => {\n this.closePopup()\n this.interact(tool)\n }}\n >\n ${this.icon(tool.icon)}<span class=\"text\">${label}</span>\n </button>\n `\n }\n case 'switch':\n return html`\n <label class=\"menu-item\" ?data-disabled=${tool.disabled} style=${style}>\n ${this.icon(tool.icon)}<span class=\"text\">${tool.label}</span>\n <md-switch\n aria-label=${tool.label || nothing}\n .selected=${live(tool.on)}\n ?disabled=${tool.disabled}\n @change=${(e: Event) => this.interact(tool, (e.target as MdSwitch).selected)}\n ></md-switch>\n </label>\n `\n case 'slider':\n return html`\n <div class=\"menu-item column\" ?data-disabled=${tool.disabled} style=${style}>\n <div class=\"row\">${this.icon(tool.icon)}<span class=\"text\">${tool.label}</span></div>\n <div class=\"row\">${this.renderRange(tool, false)}</div>\n </div>\n `\n case 'choice':\n case 'dropdown':\n return html`\n <div role=\"radiogroup\" aria-label=${tool.label || nothing} style=${style}>\n ${tool.label ? html`<div class=\"menu-heading\">${this.icon(tool.icon)}${tool.label}</div>` : nothing}\n ${this.renderChoices(tool, 'radio')}\n </div>\n `\n }\n }\n}\n"],"names":["CONTROLS","VARIANTS","isInteractive","control","DEFAULT_ON","text","value","isEmpty","toNumber","number","columnRef","target","ref","key","hasKey","named","part","sameTable","a","b","columnValue","dataType","t","n","asBoolean","sameValue","ca","cb","ba","bb","na","nb","paramsOf","route","query","rawTools","config","tools","tool","controlOf","toolKey","index","reports","params","parameterKey","settled","report","request","decimalsOf","step","fraction","options","raw","seen","option","o","label","icon","sharedFor","shared","entry","extrasOf","extra","valueItem","rowItems","keys","toTools","requests","reported","color","source","state","writable","disabled","buttonValue","onValue","min","max","decimals","sliderValue","opts","selected","commitFor","model","next","urlValue","column","offValue","items","expected","tidy","indexes","keepSpacers","kept","i","result","last","kind","toolAfter","j","place","input","available","gap","more","checkCross","fitsAcross","extent","preferred","item","allCompact","done","choice","visible","overflow","bar","menu","hasTools","length","sum","density","shown","_","savings","saving","total","budget","fill","used","full","add","labelled","small","count","colorContext","parseColor","candidate","match","hex","r","g","v","surfaceCache","opaqueSurface","layers","cached","surface","layer","alpha","channel","luminance","contrast","lighter","darker","x","y","ACCENT_CONTRAST","isColor","accentColor","configured","themeColor","textColor","onColor","accent","painted","DATA_HOLD_MS","URL_HOLD_MS","ORIENTATIONS","SIZES","SHAPES","ALIGNMENTS","oneOf","allowed","fallback","formatters","formatNumber","formatter","layoutSignature","orientation","size","WidgetToolbar","LitElement","event","path","anchor","el","rect","dialog","changed","sw","current","commit","onAccent","hold","timer","ok","action","force","slots","s","slot","ruler","box","vertical","style","px","width","height","placement","popup","same","top","left","tile","board","themeBg","styleMap","alignment","themeText","html","repeat","nothing","e","open","name","compact","showLabel","iconOnly","live","role","css","__decorateClass","property","customElement"],"mappings":";;;;;;;AAWA,MAAMA,KAA+B,CAAC,UAAU,UAAU,UAAU,UAAU,YAAY,SAAS,aAAa,QAAQ,GAClHC,KAA+B,CAAC,UAAU,SAAS,YAAY,MAAM,GAG9DC,IAAgB,CAACC,MAC1BA,MAAY,YAAYA,MAAY,YAAYA,MAAY,YAAYA,MAAY,YAAYA,MAAY,YA4E1GC,KAAa,QAEbC,IAAO,CAACC,MACV,OAAOA,KAAU,WAAWA,IAAQ,OAAOA,KAAU,YAAY,OAAO,SAASA,CAAK,IAAI,OAAOA,CAAK,IAAI,IAEjGC,IAAU,CAACD,MACGA,KAAU,QAAS,OAAOA,KAAU,YAAYA,EAAM,KAAA,MAAW,IAE/EE,IAAW,CAACF,MAAuC;AAC5D,MAAIA,KAAU,QAA+BA,MAAU,MAAM,OAAOA,KAAU,UAAW;AACzF,QAAMG,IAAS,OAAOH,KAAU,WAAWA,IAAQ,OAAO,OAAOA,CAAK,EAAE,MAAM;AAC9E,SAAO,OAAO,SAASG,CAAM,IAAIA,IAAS;AAC9C;AAGO,SAASC,EAAUC,GAAwC;AAC9D,MAAI,CAACA,KAAU,OAAOA,KAAW,SAAU;AAC3C,QAAMC,IAAMD,GACNE,IAAMD,EAAI,2BACVE,IAAU,OAAOD,KAAQ,YAAY,OAAO,SAASA,CAAG,KAAO,OAAOA,KAAQ,YAAYA,EAAI,WAAW,IACzGE,IAAQ,CAACC,MAAkB,OAAOA,KAAS,YAAYA,EAAK,WAAW;AAC7E,MAAI,GAACF,KAAU,CAACC,EAAMH,EAAI,SAAS,KAAK,CAACG,EAAMH,EAAI,MAAM;AACzD,WAAO;AAAA,MACH,2BAA2BC;AAAA,MAC3B,WAAWD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A;AAAM,GAXE6G,EAWQ,WAAA,SAAA,CAAA;AACAmD,EAAA;AAAA,EAAhBhK,EAAA;AAAM,GAZE6G,EAYQ,WAAA,WAAA,CAAA;AACAmD,EAAA;AAAA,EAAhBhK,EAAA;AAAM,GAbE6G,EAaQ,WAAA,YAAA,CAAA;AACAmD,EAAA;AAAA,EAAhBhK,EAAA;AAAM,GAdE6G,EAcQ,WAAA,mBAAA,CAAA;AAEMmD,EAAA;AAAA,EAAtBrM,EAAM,MAAM;AAAA,GAhBJkJ,EAgBc,WAAA,OAAA,CAAA;AACEmD,EAAA;AAAA,EAAxBrM,EAAM,QAAQ;AAAA,GAjBNkJ,EAiBgB,WAAA,SAAA,CAAA;AACAmD,EAAA;AAAA,EAAxBrM,EAAM,QAAQ;AAAA,GAlBNkJ,EAkBgB,WAAA,WAAA,CAAA;AACQmD,EAAA;AAAA,EAAhCrM,EAAM,gBAAgB;AAAA,GAnBdkJ,EAmBwB,WAAA,UAAA,CAAA;AAnBxBA,IAANmD,EAAA;AAAA,EADNE,GAAc,sBAAmC;AAAA,GACrCrD,CAAA;"}
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
- "name": "@ironflock/widget-toolbar",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@ironflock/widget-toolbar",
3
+ "description": "IronFlock board widget: a responsive toolbar of buttons, switches, sliders and choices that write table columns and set URL parameters",
4
+ "license": "MIT",
5
+ "author": "IronFlock GmbH",
6
+ "version": "1.0.1",
7
+ "engines": {
8
+ "node": ">=24.9.0",
9
+ "npm": ">=10.0.2"
10
+ },
11
+ "type": "module",
12
+ "main": "dist/widget-toolbar.js",
13
+ "files": [
14
+ "dist",
15
+ "src",
16
+ "thumbnail.png",
17
+ "thumbnail.webp"
18
+ ],
19
+ "scripts": {
20
+ "start": "vite build --watch & vite",
21
+ "build": "tsc -p . && vite build",
22
+ "watch": "vite build --watch",
23
+ "typecheck": "tsc -p .",
24
+ "test": "node --test 'test/*.test.mjs'",
25
+ "types": "cat src/definition-schema.json | json2ts --style.tabWidth=4 > src/definition-schema.d.ts"
26
+ },
27
+ "dependencies": {
28
+ "lit": "^3.3.3"
29
+ },
30
+ "peerDependencies": {
31
+ "@material/web": "^2.4.1"
32
+ },
33
+ "devDependencies": {
34
+ "@material/web": "2.4.1",
35
+ "@rollup/plugin-replace": "^6.0.2",
36
+ "json-schema-to-typescript": "^15.0.4",
37
+ "tslib": "^2.8.1",
38
+ "typescript": "^5.9.3",
39
+ "vite": "^7.3.0"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "git+https://github.com/IronFlock/widget-toolbar.git"
44
+ },
45
+ "keywords": [
46
+ "ironflock",
47
+ "widget",
48
+ "toolbar"
49
+ ],
50
+ "bugs": {
51
+ "url": "https://github.com/IronFlock/widget-toolbar/issues"
52
+ },
53
+ "homepage": "https://github.com/IronFlock/widget-toolbar#readme"
54
+ }
package/src/colors.ts ADDED
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Colour helpers for the parts of the toolbar that need a real colour rather
3
+ * than a var() chain: the opaque surface of the menu and the confirmation
4
+ * dialog (the tile behind them is usually translucent), and the text colour
5
+ * on an accent-coloured button. Taken from widget-filter-dropdown.
6
+ */
7
+
8
+ let colorContext: CanvasRenderingContext2D | null | undefined
9
+
10
+ // A colour as [r, g, b, alpha] in sRGB (channels 0-255), parsed by the browser
11
+ // itself through a canvas's fillStyle, so names, hsl(), hex with alpha,
12
+ // color-mix() and the like all work. A value the browser rejects comes back
13
+ // fully transparent. Only the normalised string is read, never pixels: with
14
+ // Firefox's resistFingerprinting on, getImageData() answers with random colours.
15
+ export const parseColor = (value: string): number[] => {
16
+ colorContext ??= document.createElement('canvas').getContext('2d')
17
+ if (!colorContext) return [0, 0, 0, 0]
18
+ // Chromium hands oklch(), lab(), color() and the like back as written;
19
+ // mixed into srgb they come back as color(srgb r g b / alpha).
20
+ for (const candidate of [value, `color-mix(in srgb, ${value} 100%, transparent)`]) {
21
+ // A rejected value leaves the previous fillStyle in place, so set it
22
+ // after two different placeholders: only an accepted one reads the same.
23
+ colorContext.fillStyle = '#000'
24
+ colorContext.fillStyle = candidate
25
+ const color = String(colorContext.fillStyle)
26
+ colorContext.fillStyle = '#fff'
27
+ colorContext.fillStyle = candidate
28
+ if (String(colorContext.fillStyle) !== color) continue
29
+ let match = /^#([\da-f]{2})([\da-f]{2})([\da-f]{2})$/.exec(color)
30
+ if (match) return [...match.slice(1).map((hex) => parseInt(hex, 16)), 1]
31
+ match = /^rgba\((\d+), (\d+), (\d+), ([\d.]+)\)$/.exec(color)
32
+ if (match) return match.slice(1).map(Number)
33
+ match = /^color\(srgb (\S+) (\S+) (\S+)(?: \/ (\S+))?\)$/.exec(color)
34
+ if (match) {
35
+ const [r, g, b] = match.slice(1, 4).map((v) => Math.min(Math.max(Number(v) || 0, 0), 1) * 255)
36
+ return [r, g, b, Number(match[4] ?? 1) || 0]
37
+ }
38
+ }
39
+ return [0, 0, 0, 0]
40
+ }
41
+
42
+ const surfaceCache = new Map<string, string>()
43
+
44
+ /**
45
+ * Paint the given colours, bottom first, over white, as the screen composites
46
+ * a translucent background over what is behind it, and return the opaque
47
+ * result as #rrggbb.
48
+ */
49
+ export const opaqueSurface = (layers: string[]): string => {
50
+ const key = JSON.stringify(layers)
51
+ const cached = surfaceCache.get(key)
52
+ if (cached !== undefined) return cached
53
+
54
+ let surface = [255, 255, 255]
55
+ for (const layer of layers) {
56
+ const [r, g, b, alpha] = parseColor(layer)
57
+ surface = [r, g, b].map((channel, i) => channel * alpha + surface[i] * (1 - alpha))
58
+ }
59
+ const hex = '#' + surface.map((channel) => Math.round(channel).toString(16).padStart(2, '0')).join('')
60
+ if (surfaceCache.size > 200) surfaceCache.clear()
61
+ surfaceCache.set(key, hex)
62
+ return hex
63
+ }
64
+
65
+ // WCAG relative luminance of an opaque #rrggbb colour (0 black, 1 white).
66
+ const luminance = (hex: string): number => {
67
+ const [r, g, b] = [1, 3, 5].map((i) => {
68
+ const channel = parseInt(hex.slice(i, i + 2), 16) / 255
69
+ return channel <= 0.03928 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4
70
+ })
71
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b
72
+ }
73
+
74
+ /** WCAG contrast ratio of two opaque #rrggbb colours, from 1 to 21. */
75
+ export const contrast = (a: string, b: string): number => {
76
+ const [lighter, darker] = [luminance(a), luminance(b)].sort((x, y) => y - x)
77
+ return (lighter + 0.05) / (darker + 0.05)
78
+ }
79
+
80
+ // WCAG's minimum contrast for a control against its surroundings.
81
+ const ACCENT_CONTRAST = 3
82
+
83
+ const isColor = (color: unknown): color is string =>
84
+ typeof color === 'string' && color.trim() !== '' && parseColor(color)[3] > 0
85
+
86
+ /**
87
+ * The accent: a configured colour as written; otherwise the theme's first
88
+ * palette colour when it stands out from the surface; otherwise the text
89
+ * colour, which is picked to read on the tile.
90
+ */
91
+ export const accentColor = (configured: unknown, themeColor: unknown, surface: string, textColor: string): string => {
92
+ if (isColor(configured)) return configured.trim()
93
+ if (isColor(themeColor) && contrast(opaqueSurface([surface, themeColor]), surface) >= ACCENT_CONTRAST)
94
+ return themeColor
95
+ return textColor
96
+ }
97
+
98
+ /** Black or white, whichever reads better on the accent painted over the surface. */
99
+ export const onColor = (accent: string, surface: string): string => {
100
+ const painted = opaqueSurface([surface, accent])
101
+ return contrast(painted, '#ffffff') >= contrast(painted, '#000000') ? '#ffffff' : '#000000'
102
+ }
@@ -0,0 +1,45 @@
1
+ {
2
+ "orientation": "horizontal",
3
+ "size": "normal",
4
+ "tools": [
5
+ {
6
+ "label": "Live",
7
+ "control": "switch",
8
+ "icon": "sensors",
9
+ "parameterKey": "live"
10
+ },
11
+ {
12
+ "control": "separator"
13
+ },
14
+ {
15
+ "label": "Period",
16
+ "control": "choice",
17
+ "parameterKey": "period",
18
+ "options": [
19
+ { "label": "Day", "value": "day" },
20
+ { "label": "Week", "value": "week" },
21
+ { "label": "Month", "value": "month" }
22
+ ]
23
+ },
24
+ {
25
+ "label": "Threshold",
26
+ "control": "slider",
27
+ "icon": "tune",
28
+ "min": 0,
29
+ "max": 100,
30
+ "step": 5,
31
+ "unit": "%",
32
+ "parameterKey": "threshold"
33
+ },
34
+ {
35
+ "control": "spacer"
36
+ },
37
+ {
38
+ "label": "Show all",
39
+ "control": "button",
40
+ "icon": "filter_alt_off",
41
+ "variant": "outlined",
42
+ "parameterKey": "period"
43
+ }
44
+ ]
45
+ }