@lcars-gui/federation 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 aarondnas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,59 @@
1
- # Temporary Holding Version
1
+ # @lcars-gui/federation
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ LCARS UI components in the style of the Federation – for React and plain HTML/CSS/JS.
4
+
5
+ **[▶ Live demo & docs](https://aarondnas.github.io/lcars-gui/#federation)**
6
+
7
+ ![Federation](https://raw.githubusercontent.com/aarondnas/lcars-gui/main/docs/federation.gif)
8
+
9
+ ## Installation
10
+
11
+ ```sh
12
+ npm install @lcars-gui/federation
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```tsx
18
+ // React
19
+ import "@lcars-gui/federation/ui.css";
20
+ import { Frame, Button, LcarsRoot, SoundProvider } from "@lcars-gui/federation/react";
21
+
22
+ <SoundProvider>
23
+ <LcarsRoot theme="tng">
24
+ <Frame title="Bridge" topLabel="47-1138" sidebar={<Button shape="rect" align="bottom-right">Tactical</Button>}>
25
+ …
26
+ </Frame>
27
+ </LcarsRoot>
28
+ </SoundProvider>
29
+ ```
30
+
31
+ ```html
32
+ <!-- Plain HTML/JS, no bundler -->
33
+ <link rel="stylesheet" href="https://unpkg.com/@lcars-gui/federation/dist/ui.css">
34
+ <button class="lcar-btn-std" data-color="2" data-shape="rect">Warp</button>
35
+
36
+ <script src="https://unpkg.com/@lcars-gui/federation/dist/index.global.js"></script>
37
+ <script>const ui = LcarsFederation.initLcars({ sound: true });</script>
38
+ ```
39
+
40
+ `initLcars()` makes toggles, tabs, keypads, data cascades and interface sounds in static markup interactive.
41
+
42
+ ## Themes & alert
43
+
44
+ `data-theme` (or `<LcarsRoot theme>`) switches the color palette; `data-alert="red" | "yellow"` recolors everything
45
+ below and makes the bars pulse.
46
+
47
+ | Theme | Style | Extras |
48
+ |----------|----------------------------|-------------------------------------------|
49
+ | `tng` | Enterprise-D (default) | `@lcars-gui/federation/themes/tng.css` |
50
+ | `ds9` | Deep Space Nine station | `@lcars-gui/federation/themes/ds9.css` |
51
+ | `picard` | 25th century | `@lcars-gui/federation/themes/picard.css` |
52
+
53
+ ## Font
54
+
55
+ The package bundles [Antonio](https://github.com/googlefonts/antonioFont) (SIL Open Font License 1.1, see `dist/fonts/Antonio/OFL.txt`).
56
+
57
+ ## License
58
+
59
+ MIT. Star Trek and LCARS are trademarks of CBS Studios / Paramount; this is an unofficial fan project.
@@ -0,0 +1,93 @@
1
+ Copyright 2013 The Antonio Project Authors (https://github.com/googlefonts/antonioFont)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,165 @@
1
+ import { InitBehaviorsOptions, LcarsController } from '@lcars-gui/core';
2
+ export { LcarsController, LcarsSound, LcarsSoundKind, createLcarsSound, pressedChangeEvent } from '@lcars-gui/core';
3
+
4
+ type LcarsColor = 1 | 2 | 3 | 4 | 5 | 6 | 7;
5
+ type LcarsLength = "xs" | "s" | "m" | "l" | "xl";
6
+ /** Sets data-color only when a color is given (otherwise the CSS default applies). */
7
+ declare function colorAttribute(color?: LcarsColor): {
8
+ "data-color": string;
9
+ } | {
10
+ "data-color"?: undefined;
11
+ };
12
+
13
+ type ButtonColor = LcarsColor;
14
+ type ButtonSize = "xs" | "s" | "m" | "l" | "xl";
15
+ type ButtonLength = LcarsLength;
16
+ type ButtonShape = "capsule" | "rect" | "cap-left" | "cap-right";
17
+ type ButtonAlign = "center" | "bottom-right";
18
+ /**
19
+ * Platform-neutral button props (without events/children,
20
+ * those come from the respective renderer).
21
+ */
22
+ interface ButtonProps {
23
+ color?: ButtonColor;
24
+ size?: ButtonSize;
25
+ length?: ButtonLength;
26
+ shape?: ButtonShape;
27
+ align?: ButtonAlign;
28
+ disabled?: boolean;
29
+ }
30
+ /**
31
+ * Default values, the single source of truth
32
+ * (used by all renderers).
33
+ */
34
+ declare const defaultButtonProps: Required<Omit<ButtonProps, "length">>;
35
+ /** CSS class from ui.css */
36
+ declare const buttonClassName = "lcar-btn-std";
37
+ /**
38
+ * Merges and normalizes props
39
+ * before the renderers use them.
40
+ */
41
+ declare function normalizeButtonProps<T extends ButtonProps>(props: T): {
42
+ color: ButtonColor;
43
+ size: ButtonSize;
44
+ shape: ButtonShape;
45
+ align: ButtonAlign;
46
+ disabled: boolean;
47
+ } & T;
48
+ /**
49
+ * Returns the data attributes the CSS reacts to.
50
+ */
51
+ declare function buttonDataAttributes(props: ButtonProps): {
52
+ "data-align"?: string | undefined;
53
+ "data-shape"?: "rect" | "cap-left" | "cap-right" | undefined;
54
+ "data-length"?: LcarsLength | undefined;
55
+ "data-color": string;
56
+ "data-size": "xs" | "s" | "m" | "l" | "xl";
57
+ };
58
+
59
+ type ElbowCorner = "tl" | "tr" | "bl" | "br";
60
+ type BarCap = "left" | "right" | "both";
61
+ interface ElbowProps {
62
+ corner?: ElbowCorner;
63
+ color?: LcarsColor;
64
+ }
65
+ interface BarProps {
66
+ color?: LcarsColor;
67
+ cap?: BarCap;
68
+ length?: LcarsLength;
69
+ }
70
+ interface BlockProps {
71
+ color?: LcarsColor;
72
+ fill?: boolean;
73
+ }
74
+ /** CSS classes from ui.css */
75
+ declare const frameClassNames: {
76
+ readonly elbow: "lcar-elbow";
77
+ readonly bar: "lcar-bar";
78
+ readonly block: "lcar-block";
79
+ readonly title: "lcar-title";
80
+ readonly stack: "lcar-stack";
81
+ readonly frame: "lcar-frame";
82
+ readonly frameTop: "lcar-frame-top";
83
+ readonly frameBottom: "lcar-frame-bottom";
84
+ readonly frameContent: "lcar-frame-content";
85
+ readonly frameHeader: "lcar-frame-header";
86
+ };
87
+ declare function elbowDataAttributes({ corner, color }: ElbowProps): {
88
+ "data-color": string;
89
+ "data-corner": ElbowCorner;
90
+ } | {
91
+ "data-color"?: undefined;
92
+ "data-corner": ElbowCorner;
93
+ };
94
+ declare function barDataAttributes({ color, cap, length }: BarProps): {
95
+ "data-length"?: LcarsLength | undefined;
96
+ "data-cap"?: BarCap | undefined;
97
+ "data-color": string;
98
+ } | {
99
+ "data-length"?: LcarsLength | undefined;
100
+ "data-cap"?: BarCap | undefined;
101
+ "data-color"?: undefined;
102
+ };
103
+ declare function blockDataAttributes({ color, fill }: BlockProps): {
104
+ "data-fill"?: string | undefined;
105
+ "data-color": string;
106
+ } | {
107
+ "data-fill"?: string | undefined;
108
+ "data-color"?: undefined;
109
+ };
110
+
111
+ type LcarsTheme = "tng" | "ds9" | "picard";
112
+ type AlertLevel = "red" | "yellow";
113
+ type StatusKind = "ok" | "warn" | "error" | "off";
114
+ type Orientation = "horizontal" | "vertical";
115
+ /** CSS classes from ui.css */
116
+ declare const displayClassNames: {
117
+ readonly cascade: "lcar-cascade";
118
+ readonly cascadeCol: "lcar-cascade-col";
119
+ readonly readout: "lcar-readout";
120
+ readonly number: "lcar-number";
121
+ readonly divider: "lcar-divider";
122
+ readonly grid: "lcar-grid";
123
+ readonly level: "lcar-level";
124
+ readonly gauge: "lcar-gauge";
125
+ readonly sensor: "lcar-sensor";
126
+ readonly blip: "lcar-blip";
127
+ readonly scan: "lcar-scan";
128
+ readonly status: "lcar-status";
129
+ readonly alert: "lcar-alert";
130
+ readonly alertTitle: "lcar-alert-title";
131
+ readonly alertText: "lcar-alert-text";
132
+ };
133
+ declare const controlClassNames: {
134
+ readonly tabs: "lcar-tabs";
135
+ readonly tablist: "lcar-tablist";
136
+ readonly tab: "lcar-tab";
137
+ readonly tabpanel: "lcar-tabpanel";
138
+ readonly field: "lcar-field";
139
+ readonly fieldLabel: "lcar-field-label";
140
+ readonly input: "lcar-input";
141
+ readonly range: "lcar-range";
142
+ readonly keypad: "lcar-keypad";
143
+ readonly keypadDisplay: "lcar-keypad-display";
144
+ };
145
+ /**
146
+ * Random but reproducible number columns for the data cascade
147
+ * (same seed → same numbers, important for server rendering).
148
+ */
149
+ declare function cascadeNumbers(columns: number, rows: number, seed?: number): string[][];
150
+ /** Which segments of a level bar are lit. */
151
+ declare function levelSegments(value: number, segments?: number, max?: number): boolean[];
152
+ /** Converts a value to 0–100 % (for the gauge). */
153
+ declare function toPercent(value: number, max?: number): number;
154
+
155
+ type InitLcarsOptions = InitBehaviorsOptions;
156
+ /**
157
+ * Makes static LCARS markup interactive.
158
+ * The returned controller plays sounds and removes the listeners again.
159
+ */
160
+ declare function initLcars(options?: InitLcarsOptions): LcarsController;
161
+ /** Fills empty data cascades (data-columns / data-rows / data-seed) with numbers. */
162
+ declare function fillCascades(root?: Document | HTMLElement): void;
163
+
164
+ export { barDataAttributes, blockDataAttributes, buttonClassName, buttonDataAttributes, cascadeNumbers, colorAttribute, controlClassNames, defaultButtonProps, displayClassNames, elbowDataAttributes, fillCascades, frameClassNames, initLcars, levelSegments, normalizeButtonProps, toPercent };
165
+ export type { AlertLevel, BarCap, BarProps, BlockProps, ButtonAlign, ButtonColor, ButtonLength, ButtonProps, ButtonShape, ButtonSize, ElbowCorner, ElbowProps, InitLcarsOptions, LcarsColor, LcarsLength, LcarsTheme, Orientation, StatusKind };
@@ -0,0 +1,292 @@
1
+ "use strict";
2
+ var LcarsFederation = (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var src_exports = {};
23
+ __export(src_exports, {
24
+ barDataAttributes: () => barDataAttributes,
25
+ blockDataAttributes: () => blockDataAttributes,
26
+ buttonClassName: () => buttonClassName,
27
+ buttonDataAttributes: () => buttonDataAttributes,
28
+ cascadeNumbers: () => cascadeNumbers,
29
+ colorAttribute: () => colorAttribute,
30
+ controlClassNames: () => controlClassNames,
31
+ createLcarsSound: () => createLcarsSound,
32
+ defaultButtonProps: () => defaultButtonProps,
33
+ displayClassNames: () => displayClassNames,
34
+ elbowDataAttributes: () => elbowDataAttributes,
35
+ fillCascades: () => fillCascades,
36
+ frameClassNames: () => frameClassNames,
37
+ initLcars: () => initLcars,
38
+ levelSegments: () => levelSegments,
39
+ normalizeButtonProps: () => normalizeButtonProps,
40
+ pressedChangeEvent: () => pressedChangeEvent,
41
+ toPercent: () => toPercent
42
+ });
43
+
44
+ // src/shared.ts
45
+ function colorAttribute(color) {
46
+ return color ? { "data-color": String(color) } : {};
47
+ }
48
+
49
+ // src/button.ts
50
+ var defaultButtonProps = {
51
+ color: 1,
52
+ size: "m",
53
+ shape: "capsule",
54
+ align: "center",
55
+ disabled: false
56
+ };
57
+ var buttonClassName = "lcar-btn-std";
58
+ function normalizeButtonProps(props) {
59
+ return {
60
+ ...defaultButtonProps,
61
+ ...props
62
+ };
63
+ }
64
+ function buttonDataAttributes(props) {
65
+ const { color, size, length, shape, align } = normalizeButtonProps(props);
66
+ return {
67
+ "data-color": String(color),
68
+ "data-size": size,
69
+ ...length && { "data-length": length },
70
+ ...shape !== "capsule" && { "data-shape": shape },
71
+ ...align === "bottom-right" && { "data-align": "br" }
72
+ };
73
+ }
74
+
75
+ // src/frame.ts
76
+ var frameClassNames = {
77
+ elbow: "lcar-elbow",
78
+ bar: "lcar-bar",
79
+ block: "lcar-block",
80
+ title: "lcar-title",
81
+ stack: "lcar-stack",
82
+ frame: "lcar-frame",
83
+ frameTop: "lcar-frame-top",
84
+ frameBottom: "lcar-frame-bottom",
85
+ frameContent: "lcar-frame-content",
86
+ frameHeader: "lcar-frame-header"
87
+ };
88
+ function elbowDataAttributes({ corner = "tl", color }) {
89
+ return { "data-corner": corner, ...colorAttribute(color) };
90
+ }
91
+ function barDataAttributes({ color, cap, length }) {
92
+ return {
93
+ ...colorAttribute(color),
94
+ ...cap && { "data-cap": cap },
95
+ ...length && { "data-length": length }
96
+ };
97
+ }
98
+ function blockDataAttributes({ color, fill }) {
99
+ return {
100
+ ...colorAttribute(color),
101
+ ...fill && { "data-fill": "" }
102
+ };
103
+ }
104
+
105
+ // ../core/dist/index.js
106
+ var defaultPatterns = {
107
+ beep: [[1320, 70]],
108
+ confirm: [[880, 70], [1320, 110]],
109
+ deny: [[440, 110], [330, 180]],
110
+ alert: [[620, 220], [880, 220], [620, 220], [880, 220]]
111
+ };
112
+ function createLcarsSound(volume = 0.12, { patterns = defaultPatterns, wave = "sine" } = {}) {
113
+ let ctx;
114
+ return {
115
+ play(kind = "beep") {
116
+ if (typeof AudioContext === "undefined") return;
117
+ ctx ?? (ctx = new AudioContext());
118
+ let t = ctx.currentTime;
119
+ for (const [freq, ms] of patterns[kind]) {
120
+ const osc = ctx.createOscillator();
121
+ const gain = ctx.createGain();
122
+ const end = t + ms / 1e3;
123
+ osc.type = wave;
124
+ osc.frequency.value = freq;
125
+ gain.gain.setValueAtTime(volume, t);
126
+ gain.gain.exponentialRampToValueAtTime(1e-4, end);
127
+ osc.connect(gain).connect(ctx.destination);
128
+ osc.start(t);
129
+ osc.stop(end);
130
+ t = end + 0.02;
131
+ }
132
+ }
133
+ };
134
+ }
135
+ var pressedChangeEvent = "lcar:pressedchange";
136
+ function initBehaviors(selectors, { root = document, sound = false, volume, onKeypadSubmit } = {}, soundOptions) {
137
+ const player = createLcarsSound(volume, soundOptions);
138
+ let soundOn = sound;
139
+ const play = (kind) => soundOn && player.play(kind);
140
+ const onClick = (e) => {
141
+ const target = e.target;
142
+ const control = target.closest(selectors.control);
143
+ if (control && control.dataset.sound !== "none") play(control.dataset.sound || "beep");
144
+ const toggle = target.closest("[aria-pressed]");
145
+ if (toggle) {
146
+ const pressed = toggle.getAttribute("aria-pressed") !== "true";
147
+ toggle.setAttribute("aria-pressed", String(pressed));
148
+ toggle.dispatchEvent(new CustomEvent(pressedChangeEvent, { bubbles: true, detail: { pressed } }));
149
+ }
150
+ const tab = target.closest('[role="tab"]');
151
+ if (tab) selectTab(tab);
152
+ const key = target.closest(`${selectors.keypad} ${selectors.keypadKey}`);
153
+ if (key) pressKey(key.closest(selectors.keypad), key.textContent.trim());
154
+ };
155
+ const onKeyDown = (e) => {
156
+ const { key, target } = e;
157
+ const step = key === "ArrowRight" ? 1 : key === "ArrowLeft" ? -1 : 0;
158
+ const tab = target.closest('[role="tab"]');
159
+ if (!step || !tab) return;
160
+ const list = tabsOf(tab);
161
+ const next = list[(list.indexOf(tab) + step + list.length) % list.length];
162
+ selectTab(next);
163
+ play("beep");
164
+ next.focus();
165
+ };
166
+ const codes = /* @__PURE__ */ new WeakMap();
167
+ const pressKey = (pad, key) => {
168
+ const display = pad.querySelector(selectors.keypadDisplay);
169
+ const length = Number(pad.dataset.length) || 6;
170
+ let code = codes.get(pad) ?? "";
171
+ const show = (text, state) => {
172
+ if (!display) return;
173
+ display.textContent = text || "\u2013".repeat(length);
174
+ if (state) display.dataset.state = state;
175
+ else delete display.dataset.state;
176
+ };
177
+ if (key === "ENT") {
178
+ const accepted = onKeypadSubmit ? onKeypadSubmit(code, pad) : code === pad.dataset.code;
179
+ codes.set(pad, "");
180
+ if (accepted === void 0) return play("confirm");
181
+ play(accepted ? "confirm" : "deny");
182
+ return show(accepted ? "OK" : "Denied", accepted ? "ok" : "error");
183
+ }
184
+ if (key === "CLR") code = "";
185
+ else if (code.length < length) code += key;
186
+ codes.set(pad, code);
187
+ show(pad.dataset.mask === void 0 ? code : "\u2022".repeat(code.length));
188
+ };
189
+ root.addEventListener("click", onClick);
190
+ root.addEventListener("keydown", onKeyDown);
191
+ return {
192
+ play: (kind) => player.play(kind),
193
+ setSound: (enabled) => soundOn = enabled,
194
+ destroy() {
195
+ root.removeEventListener("click", onClick);
196
+ root.removeEventListener("keydown", onKeyDown);
197
+ }
198
+ };
199
+ }
200
+ function tabsOf(tab) {
201
+ return [...tab.closest('[role="tablist"]')?.querySelectorAll('[role="tab"]') ?? []];
202
+ }
203
+ function selectTab(tab) {
204
+ for (const t of tabsOf(tab)) {
205
+ const on = t === tab;
206
+ t.setAttribute("aria-selected", String(on));
207
+ t.tabIndex = on ? 0 : -1;
208
+ const panel = document.getElementById(t.getAttribute("aria-controls") ?? "");
209
+ if (panel) panel.hidden = !on;
210
+ }
211
+ }
212
+ function seededRandom(seed = 47) {
213
+ let state = seed >>> 0;
214
+ return () => {
215
+ state = state + 1831565813 >>> 0;
216
+ let t = state;
217
+ t = Math.imul(t ^ t >>> 15, t | 1);
218
+ t ^= t + Math.imul(t ^ t >>> 7, t | 61);
219
+ return ((t ^ t >>> 14) >>> 0) / 4294967296;
220
+ };
221
+ }
222
+
223
+ // src/display.ts
224
+ var displayClassNames = {
225
+ cascade: "lcar-cascade",
226
+ cascadeCol: "lcar-cascade-col",
227
+ readout: "lcar-readout",
228
+ number: "lcar-number",
229
+ divider: "lcar-divider",
230
+ grid: "lcar-grid",
231
+ level: "lcar-level",
232
+ gauge: "lcar-gauge",
233
+ sensor: "lcar-sensor",
234
+ blip: "lcar-blip",
235
+ scan: "lcar-scan",
236
+ status: "lcar-status",
237
+ alert: "lcar-alert",
238
+ alertTitle: "lcar-alert-title",
239
+ alertText: "lcar-alert-text"
240
+ };
241
+ var controlClassNames = {
242
+ tabs: "lcar-tabs",
243
+ tablist: "lcar-tablist",
244
+ tab: "lcar-tab",
245
+ tabpanel: "lcar-tabpanel",
246
+ field: "lcar-field",
247
+ fieldLabel: "lcar-field-label",
248
+ input: "lcar-input",
249
+ range: "lcar-range",
250
+ keypad: "lcar-keypad",
251
+ keypadDisplay: "lcar-keypad-display"
252
+ };
253
+ function cascadeNumbers(columns, rows, seed = 47) {
254
+ const random = seededRandom(seed);
255
+ return Array.from({ length: columns }, (_, col) => {
256
+ const digits = 2 + col * 3 % 5;
257
+ return Array.from(
258
+ { length: rows },
259
+ () => String(Math.floor(random() * 10 ** digits)).padStart(digits, "0")
260
+ );
261
+ });
262
+ }
263
+ function levelSegments(value, segments = 10, max = 100) {
264
+ const lit = Math.round(Math.min(Math.max(value, 0), max) / max * segments);
265
+ return Array.from({ length: segments }, (_, i) => i < lit);
266
+ }
267
+ function toPercent(value, max = 100) {
268
+ return Math.min(Math.max(value / max * 100, 0), 100);
269
+ }
270
+
271
+ // src/behaviors.ts
272
+ function initLcars(options = {}) {
273
+ fillCascades(options.root);
274
+ return initBehaviors(
275
+ {
276
+ control: `.${buttonClassName}, .${controlClassNames.tab}`,
277
+ keypad: `.${controlClassNames.keypad}`,
278
+ keypadKey: `.${buttonClassName}`,
279
+ keypadDisplay: `.${controlClassNames.keypadDisplay}`
280
+ },
281
+ options
282
+ );
283
+ }
284
+ function fillCascades(root = document) {
285
+ root.querySelectorAll(`.${displayClassNames.cascade}[data-columns]`).forEach((el, k) => {
286
+ const { columns, rows = "6", seed } = el.dataset;
287
+ const data = cascadeNumbers(Number(columns), Number(rows), seed ? Number(seed) : 47 + k);
288
+ el.innerHTML = data.map((col, c) => `<div class="${displayClassNames.cascadeCol}">${col.map((n, r) => `<span style="--i:${r * 2 + c}">${n}</span>`).join("")}</div>`).join("");
289
+ });
290
+ }
291
+ return __toCommonJS(src_exports);
292
+ })();