@vinena/knobs 0.5.0 → 0.5.2

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.
Files changed (75) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +7 -0
  3. package/dist/early.global.js +6 -6
  4. package/dist/{elementsview-6g274ptr.js → elementsview-2z4pkrdz.js} +4 -4
  5. package/dist/{elementsview-pkzp9kc6.js → elementsview-qn8qyksa.js} +4 -4
  6. package/dist/engine/browserdraw.d.ts +24 -2
  7. package/dist/engine/browserkit.d.ts +18 -1
  8. package/dist/engine/browserui.d.ts +162 -22
  9. package/dist/engine/devicon.d.ts +59 -0
  10. package/dist/engine/fit.d.ts +4 -3
  11. package/dist/engine/foldflip.d.ts +40 -0
  12. package/dist/engine/identity.d.ts +7 -4
  13. package/dist/engine/mock.d.ts +16 -0
  14. package/dist/engine/mockdata.d.ts +4 -1
  15. package/dist/engine/mockdraw.d.ts +14 -2
  16. package/dist/engine/pageshot.d.ts +5 -2
  17. package/dist/engine/safaridraw.d.ts +162 -10
  18. package/dist/engine/screen.d.ts +24 -0
  19. package/dist/engine/store.d.ts +2 -1
  20. package/dist/engine/tabicon.d.ts +43 -0
  21. package/dist/engine/toplayer.d.ts +62 -0
  22. package/dist/engine/touchpointer.d.ts +0 -21
  23. package/dist/engine/underbar.d.ts +61 -0
  24. package/dist/{framekit-g96t6nmq.js → framekit-te90cjs0.js} +2325 -1572
  25. package/dist/{framekit-3n7p79ht.js → framekit-w0v516w5.js} +2325 -1572
  26. package/dist/host.d.ts +51 -0
  27. package/dist/{index-64rd634h.js → index-30fc6php.js} +1 -1
  28. package/dist/{index-dvr4x91q.js → index-9re7sv56.js} +20 -8
  29. package/dist/{index-0casarhy.js → index-agwr37gw.js} +1 -1
  30. package/dist/{index-2d6wvs8h.js → index-dan2kpsd.js} +4 -4
  31. package/dist/{index-kzsb9drs.js → index-hv02xka3.js} +20 -8
  32. package/dist/{index-peh33xjv.js → index-pewcdh28.js} +1 -1
  33. package/dist/{index-d0cjxjsm.js → index-r72tz2vn.js} +1 -1
  34. package/dist/{index-33x9hxe3.js → index-sxe5079a.js} +605 -187
  35. package/dist/{index-5d6qzte3.js → index-trx7bxdk.js} +4 -4
  36. package/dist/{index-5baxvd3v.js → index-xjhwp5cj.js} +275 -112
  37. package/dist/index.d.ts +26 -1
  38. package/dist/index.global.js +270 -176
  39. package/dist/index.js +398 -124
  40. package/dist/instance.d.ts +23 -4
  41. package/dist/{react-pdvseef0.js → react-05jh9jv5.js} +1 -1
  42. package/dist/{react-4kbj1t4h.js → react-16spgn0h.js} +1 -1
  43. package/dist/{react-65tgdbs8.js → react-4pvp6amm.js} +1 -1
  44. package/dist/{react-qv0nykcv.js → react-ayg1bgw3.js} +602 -184
  45. package/dist/{react-xxfpfddf.js → react-exjcpxma.js} +1 -1
  46. package/dist/{react-carf84xv.js → react-fm9y8dbn.js} +275 -112
  47. package/dist/{react-mv9y20jy.js → react-sw8d8c94.js} +4 -4
  48. package/dist/{react-71a9ypex.js → react-zy1mmhgz.js} +4 -4
  49. package/dist/react.js +394 -123
  50. package/dist/{storageview-vdkbp6rt.js → storageview-r595qpt9.js} +4 -4
  51. package/dist/{storageview-j9d44f99.js → storageview-s7heg93p.js} +4 -4
  52. package/dist/types.d.ts +7 -0
  53. package/dist/ui/footer.d.ts +9 -2
  54. package/dist/ui/panel.d.ts +16 -2
  55. package/dist/ui/settings.d.ts +17 -1
  56. package/dist/version.d.ts +2 -0
  57. package/package.json +3 -2
  58. package/skills/devknobs/SKILL.md +1 -1
  59. package/dist/elementsview-jnkbhzkj.js +0 -2873
  60. package/dist/elementsview-tf4qzmtw.js +0 -2874
  61. package/dist/engine/endroom.d.ts +0 -21
  62. package/dist/framekit-095qevka.js +0 -8838
  63. package/dist/framekit-q5aad770.js +0 -8839
  64. package/dist/index-hw56t3zy.js +0 -4800
  65. package/dist/index-k015tb6c.js +0 -357
  66. package/dist/index-ke6v7919.js +0 -4801
  67. package/dist/index-qxye1j73.js +0 -528
  68. package/dist/index-z5ytnj01.js +0 -4563
  69. package/dist/index-zvze25nf.js +0 -686
  70. package/dist/react-eygws6cx.js +0 -358
  71. package/dist/react-sq9pkw4k.js +0 -687
  72. package/dist/react-vjm88w4t.js +0 -4564
  73. package/dist/react-znfrjqk8.js +0 -529
  74. package/dist/storageview-sb23henh.js +0 -2729
  75. package/dist/storageview-vf8v8q8j.js +0 -2728
@@ -1,686 +0,0 @@
1
- import {
2
- icon,
3
- radioMove
4
- } from "./index-33x9hxe3.js";
5
-
6
- // src/ui/dom.ts
7
- function el(tag, className, text) {
8
- const node = document.createElement(tag);
9
- node.className = className;
10
- if (text !== undefined)
11
- node.textContent = text;
12
- return node;
13
- }
14
- function button(className, label) {
15
- const node = document.createElement("button");
16
- node.type = "button";
17
- node.className = className;
18
- node.textContent = label;
19
- return node;
20
- }
21
- function lay(node, layout) {
22
- node.setAttribute("data-layout", layout);
23
- }
24
- function rowBox(parts) {
25
- const { main, grip, glyph } = parts;
26
- const box = el("div", "row");
27
- const line = el("div", "line");
28
- const label = el("span", "row-label", parts.title);
29
- if (glyph)
30
- main.append(glyph);
31
- main.append(label, ...parts.ends ?? []);
32
- if (grip) {
33
- grip.className = `lead ${grip.className}`;
34
- line.append(grip);
35
- }
36
- line.append(main, ...parts.after ?? []);
37
- box.append(line);
38
- return { box, label };
39
- }
40
- function rowsLabel(text) {
41
- return el("div", "rows-label", text);
42
- }
43
- function rowButton(className, glyph, label) {
44
- const node = button(`row-button ${className}`, "");
45
- node.append(glyph);
46
- node.setAttribute("aria-label", label);
47
- return node;
48
- }
49
- function field(className, placeholder, label) {
50
- const node = document.createElement("input");
51
- node.className = `field ${className}`;
52
- node.placeholder = placeholder;
53
- node.autocomplete = "off";
54
- node.spellcheck = false;
55
- node.setAttribute("aria-label", label);
56
- return node;
57
- }
58
- function numberField(placeholder, label = placeholder) {
59
- const node = field("field-num", placeholder, label);
60
- node.type = "number";
61
- node.step = "any";
62
- node.inputMode = "decimal";
63
- return node;
64
- }
65
- function mark(node, on, attribute = "aria-pressed") {
66
- node.classList.toggle("on", on);
67
- node.setAttribute(attribute, on ? "true" : "false");
68
- }
69
- function reveal(node, box) {
70
- const top = node.offsetTop;
71
- const bottom = top + node.offsetHeight;
72
- if (top < box.scrollTop)
73
- box.scrollTop = top;
74
- else if (bottom > box.scrollTop + box.clientHeight) {
75
- box.scrollTop = Math.min(top, bottom - box.clientHeight);
76
- }
77
- }
78
- function firstControl(box) {
79
- if (!box)
80
- return null;
81
- const controls = Array.from(box.querySelectorAll("button, input, textarea"));
82
- return controls.find((node) => node.tabIndex >= 0 && node.getClientRects().length > 0) ?? null;
83
- }
84
- function center(node, box) {
85
- box.scrollTop = node.offsetTop - (box.clientHeight - node.offsetHeight) / 2;
86
- }
87
-
88
- // src/ui/syntax.ts
89
- function langOf(type) {
90
- if (/[/+]json\b/i.test(type))
91
- return "json";
92
- if (/html|[/+]xml\b|\/svg/i.test(type))
93
- return "html";
94
- if (/\/css\b/i.test(type))
95
- return "css";
96
- return /(java|ecma)script/i.test(type) ? "js" : "text";
97
- }
98
- var STRING = /"(?:[^"\\\n]|\\.)*"?|'(?:[^'\\\n]|\\.)*'?/y;
99
- var BLOCK_COMMENT = /\/\*[\s\S]*?(?:\*\/|$)/y;
100
- var JSON_RULES = [
101
- [/"(?:[^"\\\n]|\\.)*"?/y, (_, rest) => /^\s*:/.test(rest) ? "key" : "str"],
102
- [/-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/y, "num"],
103
- [/\b(?:true|false|null)\b/y, "kw"]
104
- ];
105
- var KEYWORDS = "const|let|var|function|return|if|else|for|while|do|switch|case|break|continue|new|class|extends|import|export|from|default|async|await|try|catch|finally|throw|typeof|instanceof|in|of|this|null|undefined|true|false|void|delete|yield|super|static";
106
- var JS_RULES = [
107
- [/\/\/[^\n]*/y, "com"],
108
- [BLOCK_COMMENT, "com"],
109
- [STRING, "str"],
110
- [/`(?:[^`\\]|\\[\s\S])*`?/y, "str"],
111
- [/\b(?:0x[0-9a-f]+|\d[\d_]*(?:\.\d+)?(?:e[+-]?\d+)?)n?\b/iy, "num"],
112
- [new RegExp(`\\b(?:${KEYWORDS})\\b`, "y"), "kw"],
113
- [/[A-Za-z_$][\w$]*/y, ""]
114
- ];
115
- var CSS_OUT = [
116
- [BLOCK_COMMENT, "com"],
117
- [STRING, "str"],
118
- [/@[\w-]+/y, "kw"],
119
- [/[^\s{},;/"'@]+/y, "tag"]
120
- ];
121
- var CSS_IN = [
122
- [BLOCK_COMMENT, "com"],
123
- [STRING, "str"],
124
- [/[^\s{};"']{1,256}(?=\s*\{)/y, "tag"],
125
- [/--[\w-]+|[a-zA-Z-]+(?=\s*:)/y, "key"],
126
- [/#[0-9a-fA-F]{3,8}\b|-?(?:\d+\.?\d*|\.\d+)(?:%|[a-zA-Z]+)?/y, "num"],
127
- [/![a-z]+/y, "kw"],
128
- [/[\w-]+/y, ""]
129
- ];
130
- var HTML_OUT = [
131
- [/<!--[\s\S]*?(?:-->|$)/y, "com"],
132
- [/<![^>]*>?/y, "tag"],
133
- [/<\/?[\w:-]+/y, "tag"],
134
- [/[^<]+/y, ""]
135
- ];
136
- var HTML_IN = [
137
- [/\/?>/y, "tag"],
138
- [STRING, "str"],
139
- [/[^\s=>/"']+/y, "attr"]
140
- ];
141
- function push(tokens, kind, text) {
142
- const last = tokens[tokens.length - 1];
143
- if (last && last[0] === kind)
144
- last[1] += text;
145
- else
146
- tokens.push([kind, text]);
147
- }
148
- function match(text, at, rules) {
149
- for (const [pattern, kind] of rules) {
150
- pattern.lastIndex = at;
151
- const found = pattern.exec(text);
152
- if (!found || found[0] === "")
153
- continue;
154
- const piece = found[0];
155
- return [typeof kind === "function" ? kind(piece, text.slice(at + piece.length, at + piece.length + 64)) : kind, piece];
156
- }
157
- return null;
158
- }
159
- function scan(text, rules, inner, turns) {
160
- const tokens = [];
161
- let inside = false;
162
- let at = 0;
163
- while (at < text.length) {
164
- const found = match(text, at, inside && inner ? inner : rules);
165
- const [kind, piece] = found ?? ["", text.charAt(at)];
166
- push(tokens, kind, piece);
167
- if (turns)
168
- inside = turns(piece, inside);
169
- at += piece.length;
170
- }
171
- return tokens;
172
- }
173
- function tokens(text, lang) {
174
- if (lang === "json")
175
- return scan(text, JSON_RULES);
176
- if (lang === "js")
177
- return scan(text, JS_RULES);
178
- if (lang === "css") {
179
- let depth = 0;
180
- return scan(text, CSS_OUT, CSS_IN, (piece) => {
181
- if (piece === "{")
182
- depth++;
183
- else if (piece === "}")
184
- depth = Math.max(0, depth - 1);
185
- return depth > 0;
186
- });
187
- }
188
- if (lang === "html")
189
- return scan(text, HTML_OUT, HTML_IN, (piece, inside) => inside ? !/>$/.test(piece) : /^<[\w/]/.test(piece));
190
- return text === "" ? [] : [["", text]];
191
- }
192
- function tokenLines(text, lang) {
193
- const lines = [[]];
194
- for (const [kind, piece] of tokens(text, lang)) {
195
- const parts = piece.split(`
196
- `);
197
- parts.forEach((part, index) => {
198
- if (index > 0)
199
- lines.push([]);
200
- if (part !== "")
201
- lines[lines.length - 1]?.push([kind, part]);
202
- });
203
- }
204
- return lines;
205
- }
206
- function indentOf(line) {
207
- const lead = /^[ \t]*/.exec(line)?.[0] ?? "";
208
- return lead.length + (lead.split("\t").length - 1);
209
- }
210
- function jsonLeaf(value) {
211
- if (typeof value === "string")
212
- return ["str", JSON.stringify(value)];
213
- if (typeof value === "number")
214
- return ["num", String(value)];
215
- if (value === null || typeof value === "boolean")
216
- return ["kw", String(value)];
217
- return ["", String(value)];
218
- }
219
- function jsonOpens(value) {
220
- return typeof value === "object" && value !== null;
221
- }
222
- function jsonEntries(value) {
223
- return Array.isArray(value) ? value.map((each, index) => [String(index), each]) : Object.entries(value);
224
- }
225
- var PREVIEW_CHARS = 100;
226
- function inner(value) {
227
- if (Array.isArray(value))
228
- return `Array(${value.length})`;
229
- return jsonOpens(value) ? "{…}" : jsonLeaf(value)[1];
230
- }
231
- function jsonPreview(value, max = PREVIEW_CHARS) {
232
- const list = Array.isArray(value);
233
- const [open, close] = list ? ["[", "]"] : ["{", "}"];
234
- let text = "";
235
- for (const [key, each] of jsonEntries(value)) {
236
- const part = `${text === "" ? "" : ", "}${list ? "" : `${key}: `}${inner(each)}`;
237
- if (open.length + text.length + part.length + close.length > max)
238
- return `${open}${text}${text === "" ? "" : ", "}…${close}`;
239
- text += part;
240
- }
241
- return `${open}${text}${close}`;
242
- }
243
- // src/ui/radio.ts
244
- function radioGroup(track, items, pick) {
245
- const shown = () => Array.from(track.children).flatMap((node) => {
246
- const item = items.find((entry) => entry.node === node);
247
- return item && !item.node.hidden ? [item] : [];
248
- });
249
- track.addEventListener("keydown", (event) => {
250
- if (event.altKey || event.ctrlKey || event.metaKey)
251
- return;
252
- const list = shown();
253
- const at = list.findIndex((item2) => item2.node === event.target);
254
- const next = at < 0 ? null : radioMove(event.key, at, list.length);
255
- const item = next === null ? undefined : list[next];
256
- if (!item)
257
- return;
258
- event.preventDefault();
259
- item.node.focus();
260
- pick(item.value);
261
- });
262
- return (current) => {
263
- const list = shown();
264
- const known = list.some((item) => item.value === current);
265
- for (const item of items) {
266
- const on = item.value === current;
267
- mark(item.node, on, "aria-checked");
268
- item.node.tabIndex = on || !known && item === list[0] ? 0 : -1;
269
- }
270
- };
271
- }
272
- function segments(options) {
273
- const node = el("div", "seg");
274
- node.setAttribute("role", "radiogroup");
275
- node.setAttribute("aria-label", options.label);
276
- const items = options.options.map((option) => {
277
- const item = button("seg-item", option.label);
278
- item.setAttribute("role", "radio");
279
- item.addEventListener("click", () => options.onChange(option.value));
280
- node.append(item);
281
- return { node: item, value: option.value };
282
- });
283
- const set = radioGroup(node, items, options.onChange);
284
- if (options.value !== undefined)
285
- set(options.value);
286
- return { node, items, set };
287
- }
288
-
289
- // src/ui/kit.ts
290
- function filterField(options) {
291
- const node = field("filter", options.placeholder, options.label ?? options.placeholder);
292
- node.addEventListener("input", () => options.onInput(node.value));
293
- return {
294
- node,
295
- clear() {
296
- if (node.value === "")
297
- return false;
298
- node.value = "";
299
- options.onInput("");
300
- return true;
301
- }
302
- };
303
- }
304
- function toolbar(children) {
305
- const node = el("div", "toolbar");
306
- node.append(...children);
307
- return node;
308
- }
309
- function toolToggle(options) {
310
- const node = button("tool", "");
311
- node.append(icon(options.icon));
312
- node.setAttribute("aria-label", options.label);
313
- node.addEventListener("click", () => options.onPress());
314
- const set = (on) => mark(node, on);
315
- set(options.on);
316
- return { node, set };
317
- }
318
- function emptyLine(text) {
319
- return el("div", "empty", text);
320
- }
321
- function emptyAction(text, run) {
322
- const node = button("empty empty-action", text);
323
- node.addEventListener("click", () => run());
324
- return node;
325
- }
326
- var FOLD_TALL = 1200;
327
- function sectionFold(options) {
328
- const main = button("main", "");
329
- const turn = el("span", "turn");
330
- turn.append(icon("chevron-left"));
331
- const { box, label } = rowBox({ main, glyph: turn, title: options.label, ends: options.ends });
332
- if (options.glyph)
333
- main.insertBefore(options.glyph, label);
334
- const fold = el("div", "fold");
335
- const body = el("div", "fold-body");
336
- fold.append(body);
337
- box.append(fold);
338
- let open = false;
339
- let still = false;
340
- const set = (next) => {
341
- open = next;
342
- box.className = `row${next ? " open" : ""}${still ? " still" : ""}`;
343
- fold.inert = !next;
344
- main.setAttribute("aria-expanded", next ? "true" : "false");
345
- };
346
- main.addEventListener("click", () => {
347
- still = body.scrollHeight > FOLD_TALL;
348
- set(!open);
349
- options.onToggle?.(open);
350
- if (open && body.scrollHeight > FOLD_TALL) {
351
- still = true;
352
- set(true);
353
- }
354
- });
355
- set(options.open);
356
- return { node: box, main, label, body, set };
357
- }
358
- function branch(children) {
359
- const node = el("div", "branch");
360
- node.append(...children);
361
- return node;
362
- }
363
- function entryCells(main, label, options) {
364
- const columned = options.value !== undefined;
365
- label.className = `${label.className} cell-name${columned ? " columned" : ""}${options.quiet ? " quiet" : ""}`;
366
- label.title = options.name;
367
- if (options.index !== undefined)
368
- main.insertBefore(el("span", "cell-index", options.index), label);
369
- if (options.value !== undefined)
370
- main.append(el("span", "cell-value", options.value));
371
- if (options.end !== undefined && options.end !== "")
372
- main.append(el("span", "cell-end", options.end));
373
- }
374
- function entryHead(options) {
375
- const node = el("div", "cells-head");
376
- node.setAttribute("aria-hidden", "true");
377
- node.append(el("span", "cell-lead"));
378
- if (options.index !== undefined)
379
- node.append(el("span", "cell-index", options.index));
380
- node.append(el("span", `cell-name${options.value !== undefined ? " columned" : ""}`, options.name));
381
- if (options.value !== undefined)
382
- node.append(el("span", "cell-value", options.value));
383
- if (options.end !== undefined && options.end !== "")
384
- node.append(el("span", "cell-end", options.end));
385
- return node;
386
- }
387
- function entryFold(options) {
388
- const fold = sectionFold({ label: options.name, open: options.open, onToggle: options.onToggle });
389
- entryCells(fold.main, fold.label, options);
390
- return fold;
391
- }
392
- function noteLine(text) {
393
- return el("div", "note", text);
394
- }
395
- function noteButton(text, run) {
396
- const node = button("note note-button", text);
397
- node.addEventListener("click", run);
398
- return node;
399
- }
400
- function group(options) {
401
- const node = el("div", "group");
402
- node.setAttribute("role", "group");
403
- node.setAttribute("aria-label", options.label);
404
- const head = el("div", "group-head");
405
- head.append(el("span", "group-label", options.label), ...options.ends ?? []);
406
- node.append(head);
407
- return node;
408
- }
409
- function stack(children) {
410
- const node = el("div", "stack");
411
- node.append(...children);
412
- return node;
413
- }
414
- function controls(options) {
415
- const node = el("div", "chips");
416
- const buttons = options.map((option) => {
417
- const control = button("chip", option.label);
418
- control.addEventListener("click", () => option.run());
419
- node.append(control);
420
- return control;
421
- });
422
- return { node, buttons };
423
- }
424
- function textField(options) {
425
- const node = field("field-line", options.placeholder, options.label ?? options.placeholder);
426
- node.value = options.value ?? "";
427
- node.addEventListener("keydown", (event) => {
428
- if (event.key === "Enter" && !event.isComposing)
429
- options.onEnter?.();
430
- });
431
- return node;
432
- }
433
- var AREA_ROWS = 14;
434
- function textArea(options) {
435
- const node = document.createElement("textarea");
436
- node.className = "field field-area";
437
- node.value = options.value ?? "";
438
- node.placeholder = options.placeholder ?? "";
439
- node.spellcheck = false;
440
- node.setAttribute("aria-label", options.label);
441
- const fit = () => {
442
- node.rows = Math.min(Math.max(node.value.split(`
443
- `).length, 2), AREA_ROWS);
444
- };
445
- fit();
446
- node.addEventListener("input", fit);
447
- node.addEventListener("keydown", (event) => {
448
- if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
449
- event.preventDefault();
450
- options.onSave?.();
451
- }
452
- });
453
- return node;
454
- }
455
- function pairs(lines) {
456
- const node = el("dl", "pairs");
457
- const rows = lines.map(([name, value]) => {
458
- const cells = [el("dt", "pair-name", name), el("dd", "pair-value", typeof value === "string" ? value : undefined)];
459
- if (typeof value !== "string")
460
- cells[1]?.append(value);
461
- node.append(...cells);
462
- return { name, value: typeof value === "string" ? value : value.textContent ?? "", cells };
463
- });
464
- return {
465
- node,
466
- keep(match2) {
467
- let kept = 0;
468
- for (const row of rows) {
469
- const shows = match2(row.name, row.value);
470
- if (shows)
471
- kept++;
472
- for (const cell of row.cells)
473
- cell.hidden = !shows;
474
- }
475
- return kept;
476
- }
477
- };
478
- }
479
- var LONG_LINE = 80;
480
- function codeBlock(options) {
481
- const node = el("div", "code");
482
- const all = options.text.split(`
483
- `);
484
- const folded = options.lines !== undefined && all.length > options.lines;
485
- const text = el("pre", "code-text", folded ? all.slice(0, options.lines).join(`
486
- `) : options.text);
487
- node.append(text);
488
- if (folded) {
489
- const more = button("chip code-all", "show all");
490
- more.addEventListener("click", () => {
491
- text.textContent = options.text;
492
- more.remove();
493
- });
494
- node.append(more);
495
- }
496
- let wrap = null;
497
- if (all.some((line) => line.length > LONG_LINE)) {
498
- const toggle = button("chip code-wrap", "wrap");
499
- let wrapped = true;
500
- mark(toggle, wrapped);
501
- toggle.addEventListener("click", () => {
502
- wrapped = !wrapped;
503
- mark(toggle, wrapped);
504
- text.classList.toggle("nowrap", !wrapped);
505
- });
506
- wrap = toggle;
507
- }
508
- return { node, wrap };
509
- }
510
- function switchLine(options) {
511
- const node = el("div", "knob knob-switch");
512
- const control = button("switch", "");
513
- control.setAttribute("role", "switch");
514
- control.setAttribute("aria-label", options.label);
515
- let on = false;
516
- const set = (next) => {
517
- on = next;
518
- mark(control, next, "aria-checked");
519
- };
520
- control.addEventListener("click", () => {
521
- set(!on);
522
- options.onChange(on);
523
- });
524
- set(options.on);
525
- node.append(el("span", "knob-label", options.label), control);
526
- return { node, control, set };
527
- }
528
- function confirmLine(options) {
529
- const node = el("div", "ask");
530
- const answers = controls([
531
- { label: options.confirm, run: options.onConfirm },
532
- { label: "cancel", run: options.onCancel }
533
- ]);
534
- node.append(noteLine(options.text), answers.node);
535
- return { node, buttons: answers.buttons };
536
- }
537
- var tabsMade = 0;
538
- function tabBar(options) {
539
- const id = `dk-tabs-${++tabsMade}`;
540
- const node = el("div", "tabs");
541
- node.setAttribute("role", "tablist");
542
- node.setAttribute("aria-label", options.label);
543
- const panel = el("div", "tab-panel");
544
- panel.setAttribute("role", "tabpanel");
545
- panel.tabIndex = 0;
546
- panel.id = `${id}-panel`;
547
- const items = options.options.map((option, index) => {
548
- const item = button("tab", option.label);
549
- item.id = `${id}-${index}`;
550
- item.setAttribute("role", "tab");
551
- item.setAttribute("aria-controls", panel.id);
552
- item.addEventListener("click", () => options.onChange(option.value));
553
- node.append(item);
554
- return { node: item, value: option.value };
555
- });
556
- node.addEventListener("keydown", (event) => {
557
- if (event.altKey || event.ctrlKey || event.metaKey)
558
- return;
559
- if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key))
560
- return;
561
- const shown = items.filter((item2) => !item2.node.hidden);
562
- const at = shown.findIndex((item2) => item2.node === event.target);
563
- const next = at < 0 ? null : radioMove(event.key, at, shown.length);
564
- const item = next === null ? undefined : shown[next];
565
- if (!item)
566
- return;
567
- event.preventDefault();
568
- item.node.focus();
569
- options.onChange(item.value);
570
- });
571
- return {
572
- node,
573
- items,
574
- panel,
575
- set(value) {
576
- for (const item of items) {
577
- const on = item.value === value;
578
- item.node.classList.toggle("on", on);
579
- item.node.setAttribute("aria-selected", on ? "true" : "false");
580
- item.node.tabIndex = on ? 0 : -1;
581
- if (!on)
582
- continue;
583
- panel.setAttribute("aria-labelledby", item.node.id);
584
- const left = item.node.offsetLeft;
585
- const width = item.node.offsetWidth;
586
- if (typeof left !== "number" || typeof width !== "number")
587
- continue;
588
- if (left < node.scrollLeft)
589
- node.scrollLeft = left;
590
- else if (left + width > node.scrollLeft + node.clientWidth)
591
- node.scrollLeft = left + width - node.clientWidth;
592
- }
593
- }
594
- };
595
- }
596
- var sectionsMade = 0;
597
- function section(options) {
598
- const node = el("div", "sect");
599
- const top = el("div", "sect-top");
600
- const head = button("sect-head", "");
601
- const turn = el("span", "sect-turn");
602
- turn.append(icon("chevron-left", 12));
603
- head.append(turn, el("span", "sect-label", options.label));
604
- if (options.count !== undefined)
605
- head.append(el("span", "sect-count", options.count));
606
- top.append(head, ...options.ends ?? []);
607
- const body = el("div", "sect-body");
608
- body.id = `dk-sect-${++sectionsMade}`;
609
- head.setAttribute("aria-controls", body.id);
610
- node.append(top, body);
611
- let open = false;
612
- const set = (next) => {
613
- open = next;
614
- head.setAttribute("aria-expanded", next ? "true" : "false");
615
- body.hidden = !next;
616
- };
617
- head.addEventListener("click", () => {
618
- set(!open);
619
- options.onToggle?.(open);
620
- });
621
- set(options.open);
622
- return { node, head, body, set };
623
- }
624
- function actButton(label, run, pressed) {
625
- const node = button("act", label);
626
- node.addEventListener("click", run);
627
- if (pressed !== undefined)
628
- mark(node, pressed);
629
- return node;
630
- }
631
- function tokenNodes(tokens2) {
632
- return tokens2.map(([kind, text]) => kind === "" ? text : el("span", `tok-${kind}`, text));
633
- }
634
- function codeView(options) {
635
- const node = el("div", "src");
636
- const lines = tokenLines(options.text, options.lang ?? "text");
637
- const raw = options.text.split(`
638
- `);
639
- lines.forEach((tokens2, index) => {
640
- const row = el("div", "src-line");
641
- const number = el("span", "src-num", String(index + 1));
642
- number.setAttribute("aria-hidden", "true");
643
- const text = el("span", "src-text");
644
- text.append(...tokenNodes(tokens2));
645
- const hang = indentOf(raw[index] ?? "") + 2;
646
- text.style.paddingLeft = `${hang}ch`;
647
- text.style.textIndent = `-${hang}ch`;
648
- row.append(number, text);
649
- node.append(row);
650
- });
651
- return node;
652
- }
653
- function jsonItem(key, value, open) {
654
- const name = key === null ? [] : [el("span", "tok-key", key), ": "];
655
- if (!jsonOpens(value)) {
656
- const leaf = el("div", "json-leaf");
657
- leaf.append(...name, ...tokenNodes([jsonLeaf(value)]));
658
- return leaf;
659
- }
660
- const node = el("div", "json-node");
661
- const head = button("json-head", "");
662
- const turn = el("span", "sect-turn");
663
- turn.append(icon("chevron-left", 12));
664
- head.append(turn, ...name, el("span", "json-preview", jsonPreview(value)));
665
- const kids = el("div", "json-kids");
666
- node.append(head, kids);
667
- let built = false;
668
- const set = (next) => {
669
- if (next && !built) {
670
- built = true;
671
- kids.append(...jsonEntries(value).map(([each, inner2]) => jsonItem(each, inner2, false)));
672
- }
673
- head.setAttribute("aria-expanded", next ? "true" : "false");
674
- kids.hidden = !next;
675
- };
676
- head.addEventListener("click", () => set(head.getAttribute("aria-expanded") !== "true"));
677
- set(open);
678
- return node;
679
- }
680
- function jsonTree(value) {
681
- const node = el("div", "json");
682
- node.append(jsonItem(null, value, true));
683
- return node;
684
- }
685
-
686
- export { el, button, lay, rowBox, rowsLabel, rowButton, field, numberField, mark, reveal, firstControl, center, langOf, radioGroup, segments, filterField, toolbar, toolToggle, emptyLine, emptyAction, sectionFold, branch, entryHead, entryFold, noteLine, noteButton, group, stack, controls, textField, textArea, pairs, codeBlock, switchLine, confirmLine, tabBar, section, actButton, codeView, jsonTree };