@vinena/knobs 0.5.3 → 0.6.0

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 (94) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +7 -6
  3. package/dist/context-amfyasb5.js +23 -0
  4. package/dist/context-svtr7vwt.js +22 -0
  5. package/dist/early.global.js +5 -5
  6. package/dist/edit/css.d.ts +59 -0
  7. package/dist/edit/html.d.ts +91 -0
  8. package/dist/edit/keep.d.ts +175 -0
  9. package/dist/edit/log.d.ts +107 -0
  10. package/dist/edit/replay.d.ts +28 -0
  11. package/dist/edit/risk.d.ts +33 -0
  12. package/dist/edit/rule.d.ts +31 -0
  13. package/dist/edit/source.d.ts +12 -0
  14. package/dist/edit/text.d.ts +66 -0
  15. package/dist/elementsview-fyc06wjt.js +3702 -0
  16. package/dist/elementsview-k6zvvcne.js +3701 -0
  17. package/dist/engine/dock.d.ts +3 -4
  18. package/dist/engine/frame.d.ts +1 -1
  19. package/dist/engine/style.d.ts +15 -0
  20. package/dist/{framekit-cjz0e4y8.js → framekit-622h6w1f.js} +54 -47
  21. package/dist/{framekit-yk1jxjv7.js → framekit-yx612r28.js} +54 -47
  22. package/dist/index-0zp9py56.js +859 -0
  23. package/dist/{index-prjpx67p.js → index-1mstjadm.js} +126 -2167
  24. package/dist/{index-begsqdm0.js → index-4a4x1bt2.js} +1 -1
  25. package/dist/index-58jdczmj.js +44 -0
  26. package/dist/index-5tv6sr74.js +23 -0
  27. package/dist/index-6bc2ztfd.js +688 -0
  28. package/dist/index-7cb4x1vj.js +1885 -0
  29. package/dist/index-a974q3aa.js +34 -0
  30. package/dist/{index-q73py563.js → index-aymfvd8s.js} +1 -1
  31. package/dist/{index-zt3rheck.js → index-aynkv7qk.js} +11 -8
  32. package/dist/{index-p57fdttx.js → index-dzm8ywq0.js} +492 -2365
  33. package/dist/{index-9jhatmky.js → index-f60yax1j.js} +13 -8
  34. package/dist/index-f67wctn3.js +1858 -0
  35. package/dist/{index-vgfn2n1h.js → index-ftjdt358.js} +8 -171
  36. package/dist/{index-j1h13ahg.js → index-gm51cthv.js} +2 -45
  37. package/dist/index-kfdzsyyw.js +1859 -0
  38. package/dist/index-t4kssacm.js +208 -0
  39. package/dist/index-v0ht9q0g.js +1518 -0
  40. package/dist/{index-6wbgqkdz.js → index-x59vz1xx.js} +247 -905
  41. package/dist/index-xh39jtkq.js +32 -0
  42. package/dist/index-yb7fc59g.js +718 -0
  43. package/dist/index-zd6adby9.js +496 -0
  44. package/dist/index.d.ts +62 -0
  45. package/dist/index.global.js +410 -152
  46. package/dist/index.js +504 -482
  47. package/dist/react-0wepdf60.js +1519 -0
  48. package/dist/{react-gefkdkdz.js → react-1gqwa2yw.js} +1 -1
  49. package/dist/{index-sn2y6j09.js → react-3mfz1x2a.js} +126 -2167
  50. package/dist/react-4rbjw9af.js +33 -0
  51. package/dist/react-5rq7bnsy.js +210 -0
  52. package/dist/react-6bz05qk1.js +860 -0
  53. package/dist/{react-qgz9afa2.js → react-6fnxxs30.js} +8 -171
  54. package/dist/react-6q2cw2ya.js +689 -0
  55. package/dist/{react-7vjfsh40.js → react-6t4dbdzn.js} +11 -8
  56. package/dist/react-88es9b5q.js +719 -0
  57. package/dist/react-97b5b8j4.js +46 -0
  58. package/dist/{react-mmq2zya3.js → react-bxzn8vq5.js} +1 -1
  59. package/dist/{react-3rhdj2k1.js → react-cs62p9qh.js} +62 -720
  60. package/dist/react-ethftdxp.js +497 -0
  61. package/dist/react-fp73vhyd.js +36 -0
  62. package/dist/{react-qfpg79hs.js → react-me102s1a.js} +2 -45
  63. package/dist/react-t2qnewz2.js +24 -0
  64. package/dist/react-ttj8f9qp.js +1886 -0
  65. package/dist/{react-806qmkyz.js → react-v8497a41.js} +13 -8
  66. package/dist/{react-6tss0r9f.js → react-wqn4sx0n.js} +265 -2137
  67. package/dist/react.js +500 -482
  68. package/dist/replay-j18rw92k.js +258 -0
  69. package/dist/replay-vtg0vqj2.js +257 -0
  70. package/dist/{storageview-7cv0vpdm.js → storageview-6xj7zb63.js} +11 -7
  71. package/dist/{storageview-dyhpgt8f.js → storageview-pzn8yaad.js} +11 -7
  72. package/dist/styles/force.d.ts +66 -0
  73. package/dist/ui/bindings.d.ts +31 -5
  74. package/dist/ui/changes.d.ts +49 -0
  75. package/dist/ui/cssauto.d.ts +119 -0
  76. package/dist/ui/cssedit.d.ts +80 -0
  77. package/dist/ui/domedit.d.ts +99 -0
  78. package/dist/ui/domtree.d.ts +26 -1
  79. package/dist/ui/elementsview.d.ts +19 -2
  80. package/dist/ui/htmledit.d.ts +62 -0
  81. package/dist/ui/inspector.d.ts +6 -1
  82. package/dist/ui/keys.d.ts +12 -8
  83. package/dist/ui/pane.d.ts +0 -2
  84. package/dist/ui/panel.d.ts +3 -0
  85. package/dist/ui/prefs.d.ts +30 -10
  86. package/dist/ui/settings.d.ts +2 -0
  87. package/dist/ui/size.d.ts +14 -22
  88. package/dist/ui/stylesview.d.ts +30 -1
  89. package/package.json +1 -1
  90. package/skills/devknobs/SKILL.md +95 -0
  91. package/dist/elementsview-1wsxcdtj.js +0 -2874
  92. package/dist/elementsview-3kv34jfx.js +0 -2873
  93. package/dist/index-78r0f8pw.js +0 -27
  94. package/dist/react-adky72h9.js +0 -29
@@ -0,0 +1,718 @@
1
+ import {
2
+ DOCK_WIDTH,
3
+ PAGE_MIN
4
+ } from "./index-58jdczmj.js";
5
+ import {
6
+ resolveNesting,
7
+ splitList
8
+ } from "./index-0zp9py56.js";
9
+ import {
10
+ flatParent,
11
+ isNewRuleSheet,
12
+ isShadowRoot,
13
+ scopeOf
14
+ } from "./index-zd6adby9.js";
15
+ import {
16
+ isDevknobs
17
+ } from "./index-6bc2ztfd.js";
18
+ import {
19
+ addStyle,
20
+ ensureStyle,
21
+ fresh,
22
+ isOwnSheet,
23
+ newer,
24
+ removeStyle,
25
+ stamped,
26
+ versionOf,
27
+ webStorage
28
+ } from "./index-dzm8ywq0.js";
29
+
30
+ // src/styles/force.ts
31
+ var FORCED_STATES = ["hover", "focus", "focus-visible", "active", "focus-within"];
32
+ var FORCE_ATTRIBUTE = "data-devknobs-force";
33
+ var SHEET = "force";
34
+ var UP = {
35
+ hover: "hover",
36
+ active: "active",
37
+ focus: "focus-within",
38
+ "focus-visible": "focus-within",
39
+ "focus-within": "focus-within"
40
+ };
41
+ var ALSO = {
42
+ hover: [],
43
+ active: [],
44
+ focus: ["focus-within"],
45
+ "focus-visible": ["focus", "focus-within"],
46
+ "focus-within": []
47
+ };
48
+ function isState(name) {
49
+ return FORCED_STATES.some((state) => state === name);
50
+ }
51
+ var current = null;
52
+ var written = new Map;
53
+ function stringEnd(text, at) {
54
+ const quote = text[at];
55
+ let i = at + 1;
56
+ while (i < text.length && text[i] !== quote)
57
+ i += text[i] === "\\" ? 2 : 1;
58
+ return i + 1;
59
+ }
60
+ function attributeEnd(text, at) {
61
+ let i = at + 1;
62
+ while (i < text.length && text[i] !== "]") {
63
+ if (text[i] === "\\")
64
+ i += 2;
65
+ else if (text[i] === '"' || text[i] === "'")
66
+ i = stringEnd(text, i);
67
+ else
68
+ i++;
69
+ }
70
+ return i + 1;
71
+ }
72
+ function rewrite(selector) {
73
+ const states = new Set;
74
+ let text = "";
75
+ let i = 0;
76
+ while (i < selector.length) {
77
+ const char = selector[i] ?? "";
78
+ let end = i + 1;
79
+ if (char === "\\")
80
+ end = i + 2;
81
+ else if (char === '"' || char === "'")
82
+ end = stringEnd(selector, i);
83
+ else if (char === "[")
84
+ end = attributeEnd(selector, i);
85
+ else if (char === ":" && selector[i + 1] === ":")
86
+ end = i + 2;
87
+ else if (char === ":") {
88
+ const name = /^[\w-]*/.exec(selector.slice(i + 1))?.[0] ?? "";
89
+ end = i + 1 + name.length;
90
+ const lower = name.toLowerCase();
91
+ if (isState(lower) && selector[end] !== "(") {
92
+ states.add(lower);
93
+ text += `:is(:${lower}, [${FORCE_ATTRIBUTE}~="${lower}"])`;
94
+ i = end;
95
+ continue;
96
+ }
97
+ }
98
+ text += selector.slice(i, end);
99
+ i = end;
100
+ }
101
+ return { text, states };
102
+ }
103
+ function forcedSelector(selector) {
104
+ let known = written.get(selector);
105
+ if (known === undefined) {
106
+ known = rewrite(selector).text;
107
+ written.set(selector, known);
108
+ }
109
+ return known;
110
+ }
111
+ function forcing() {
112
+ return current !== null;
113
+ }
114
+ function forcedState() {
115
+ return current ? { element: current.element, states: [...current.states] } : null;
116
+ }
117
+ function isKind(rule, kind) {
118
+ return rule.constructor.name === kind;
119
+ }
120
+ function standalone(selector, parent) {
121
+ if (parent === null)
122
+ return selector;
123
+ return splitList(selector).map((part) => resolveNesting(part, parent)).join(", ");
124
+ }
125
+ function copies(rules, parent, wanted, whole = false) {
126
+ const out = [];
127
+ const wrap = (head, inner) => {
128
+ if (inner.length > 0)
129
+ out.push(`${head} { ${inner.join(" ")} }`);
130
+ };
131
+ const copy = (selector, body) => {
132
+ if (body.trim() === "")
133
+ return;
134
+ const kept = splitList(selector).map(rewrite).filter(({ states }) => whole || [...states].some((state) => wanted.has(state))).map(({ text }) => text);
135
+ if (kept.length > 0)
136
+ out.push(`${kept.join(", ")} { ${body} }`);
137
+ };
138
+ for (let i = 0;i < rules.length; i++) {
139
+ const rule = rules[i];
140
+ if (!rule)
141
+ continue;
142
+ try {
143
+ if (isKind(rule, "CSSStyleRule")) {
144
+ const selector = standalone(rule.selectorText, parent);
145
+ copy(selector, rule.style.cssText);
146
+ if (rule.cssRules?.length)
147
+ out.push(...copies(rule.cssRules, selector, wanted, whole));
148
+ } else if (isKind(rule, "CSSNestedDeclarations")) {
149
+ if (parent !== null)
150
+ copy(resolveNesting("&", parent), rule.style.cssText);
151
+ } else if (isKind(rule, "CSSMediaRule")) {
152
+ wrap(`@media ${rule.media.mediaText}`, copies(rule.cssRules, parent, wanted, whole));
153
+ } else if (isKind(rule, "CSSSupportsRule")) {
154
+ wrap(`@supports ${rule.conditionText}`, copies(rule.cssRules, parent, wanted, whole));
155
+ } else if (isKind(rule, "CSSContainerRule")) {
156
+ wrap(`@container ${rule.conditionText}`, copies(rule.cssRules, parent, wanted, whole));
157
+ } else if (isKind(rule, "CSSLayerBlockRule")) {
158
+ if (rule.name)
159
+ wrap(`@layer ${rule.name}`, copies(rule.cssRules, parent, wanted, whole));
160
+ } else if (isKind(rule, "CSSScopeRule")) {
161
+ const start = parent === null ? rule.start : rule.start ? resolveNesting(rule.start, parent) : parent;
162
+ const end = parent !== null && rule.end ? resolveNesting(rule.end, parent) : rule.end;
163
+ const limits = start ? ` (${start})${end ? ` to (${end})` : ""}` : "";
164
+ const stated = [start, end].some((one) => one !== null && [...rewrite(one).states].some((state) => wanted.has(state)));
165
+ wrap(`@scope${limits ? rewrite(limits).text : ""}`, copies(rule.cssRules, null, wanted, whole || stated));
166
+ } else if (isKind(rule, "CSSImportRule")) {
167
+ if (rule.styleSheet)
168
+ out.push(...sheetCopies(rule.styleSheet, wanted, rule));
169
+ }
170
+ } catch {}
171
+ }
172
+ return out;
173
+ }
174
+ function sheetCopies(sheet, wanted, imported) {
175
+ let rules;
176
+ try {
177
+ rules = sheet.cssRules;
178
+ } catch {
179
+ return [];
180
+ }
181
+ let inner = copies(rules, null, wanted);
182
+ if (inner.length === 0)
183
+ return [];
184
+ const media = (imported ? imported.media.mediaText : sheet.media.mediaText) ?? "";
185
+ if (media)
186
+ inner = [`@media ${media} { ${inner.join(" ")} }`];
187
+ if (imported?.supportsText)
188
+ inner = [`@supports ${imported.supportsText} { ${inner.join(" ")} }`];
189
+ if (imported && imported.layerName != null)
190
+ inner = [`${imported.layerName ? `@layer ${imported.layerName}` : "@layer"} { ${inner.join(" ")} }`];
191
+ return inner;
192
+ }
193
+ function mirrorText(scope, wanted) {
194
+ const sheets = [...Array.from(scope.styleSheets), ...scope.adoptedStyleSheets ?? []];
195
+ const out = [];
196
+ for (const sheet of sheets) {
197
+ try {
198
+ if (sheet.disabled)
199
+ continue;
200
+ const owner = sheet.ownerNode;
201
+ const own = isOwnSheet(sheet) || owner !== null && "hasAttribute" in owner && isDevknobs(owner);
202
+ if (own && !isNewRuleSheet(sheet))
203
+ continue;
204
+ out.push(...sheetCopies(sheet, wanted));
205
+ } catch {}
206
+ }
207
+ return out.join(`
208
+ `);
209
+ }
210
+ function marks(element, states) {
211
+ const own = new Set(states);
212
+ for (const state of states)
213
+ for (const also of ALSO[state])
214
+ own.add(also);
215
+ const result = new Map([[element, FORCED_STATES.filter((state) => own.has(state))]]);
216
+ const up = new Set(states.map((state) => UP[state]));
217
+ const brought = FORCED_STATES.filter((state) => up.has(state));
218
+ for (let at = flatParent(element);at; at = flatParent(at))
219
+ result.set(at, brought);
220
+ return result;
221
+ }
222
+ function sheetFor(forced, scope) {
223
+ let style = forced.sheets.get(scope);
224
+ if (!style) {
225
+ style = isShadowRoot(scope) ? addStyle(scope, "") : ensureStyle(SHEET, scope);
226
+ forced.sheets.set(scope, style);
227
+ }
228
+ return style;
229
+ }
230
+ function syncForced() {
231
+ const forced = current;
232
+ if (!forced)
233
+ return;
234
+ const wanted = new Set;
235
+ const scopes = new Set;
236
+ for (const { element } of forced.marked) {
237
+ for (const state of (element.getAttribute(FORCE_ATTRIBUTE) ?? "").split(" "))
238
+ if (isState(state))
239
+ wanted.add(state);
240
+ scopes.add(scopeOf(element));
241
+ if (element.shadowRoot)
242
+ scopes.add(element.shadowRoot);
243
+ }
244
+ for (const scope of scopes) {
245
+ const text = mirrorText(scope, wanted);
246
+ const style = sheetFor(forced, scope);
247
+ if (style.textContent !== text)
248
+ style.textContent = text;
249
+ }
250
+ }
251
+ function clearForced() {
252
+ const forced = current;
253
+ if (!forced)
254
+ return;
255
+ current = null;
256
+ written.clear();
257
+ for (const { element, before } of forced.marked) {
258
+ try {
259
+ if (before === null)
260
+ element.removeAttribute(FORCE_ATTRIBUTE);
261
+ else
262
+ element.setAttribute(FORCE_ATTRIBUTE, before);
263
+ } catch {}
264
+ }
265
+ for (const [scope, style] of forced.sheets) {
266
+ try {
267
+ if (isShadowRoot(scope))
268
+ style.remove();
269
+ else
270
+ removeStyle(SHEET, scope);
271
+ } catch {}
272
+ }
273
+ }
274
+ function forceState(element, states) {
275
+ const names = new Set(states.map((state) => state.trim().replace(/^:/, "").toLowerCase()));
276
+ const chosen = FORCED_STATES.filter((state) => names.has(state));
277
+ clearForced();
278
+ if (!element || chosen.length === 0 || isDevknobs(element))
279
+ return [];
280
+ const forced = { element, states: chosen, marked: [], sheets: new Map };
281
+ for (const [one, own] of marks(element, chosen)) {
282
+ if (own.length === 0)
283
+ continue;
284
+ forced.marked.push({ element: one, before: one.getAttribute(FORCE_ATTRIBUTE) });
285
+ one.setAttribute(FORCE_ATTRIBUTE, own.join(" "));
286
+ }
287
+ current = forced;
288
+ syncForced();
289
+ return [...chosen];
290
+ }
291
+ var FORCING = { state: forcedState, set: forceState, clear: clearForced, sync: syncForced, on: forcing };
292
+
293
+ // src/ui/place.ts
294
+ var DRAG_SLOP = 4;
295
+ var FLING_SPAN = 150;
296
+ var FLING_STRETCH = 40;
297
+ var FLING_LEAST = 8;
298
+ var FLING = 0.5;
299
+ var FLING_LEAN = 1.5;
300
+ var FLING_TRAVEL = 16;
301
+ var GLIDE = 220;
302
+ var GLIDE_MAX = 440;
303
+ var GLIDE_SPEED = 6;
304
+ var PANEL_GAP = 8;
305
+ var SNAP = 24;
306
+ function dragTarget(shift, open) {
307
+ return open && !shift ? "panel" : "handle";
308
+ }
309
+ function otherSide(side) {
310
+ return side === "right" ? "left" : "right";
311
+ }
312
+ function between(value, min, max) {
313
+ return Math.min(Math.max(value, min), Math.max(min, max));
314
+ }
315
+ function snap(value, min, max) {
316
+ const end = Math.max(min, max);
317
+ const at = between(value, min, end);
318
+ if (at - min <= SNAP && at - min <= end - at)
319
+ return min;
320
+ return end - at <= SNAP ? end : at;
321
+ }
322
+ function edgeOf(value, min, max, had) {
323
+ const top = Math.abs(value - min) < 0.5;
324
+ const bottom = Math.abs(value - max) < 0.5;
325
+ if (top && bottom)
326
+ return had === "none" ? "top" : had;
327
+ return top ? "top" : bottom ? "bottom" : "none";
328
+ }
329
+ function settle(place, room, anchor = "edge") {
330
+ const last = room.view - PANEL_GAP - room.panel;
331
+ const pull = anchor === "top" ? between : snap;
332
+ const top = pull(anchor === "top" || place.edge === "none" ? place.top : place.edge === "top" ? PANEL_GAP : last, PANEL_GAP, last);
333
+ const low = top + room.panel - room.handle;
334
+ const y = pull(place.tab === "top" ? top : place.tab === "bottom" ? low : place.y, top, low);
335
+ return {
336
+ y,
337
+ top,
338
+ edge: edgeOf(top, PANEL_GAP, last, place.edge),
339
+ tab: edgeOf(y, top, low, place.tab)
340
+ };
341
+ }
342
+ function cornerAt(y, top, room) {
343
+ return edgeOf(y, top, top + room.panel - room.handle, "none");
344
+ }
345
+ function dragTo(target, open, to, from, room) {
346
+ const offset = from.y - from.top;
347
+ if (target === "panel") {
348
+ const top = snap(to, PANEL_GAP, room.view - PANEL_GAP - room.panel);
349
+ return settle({ y: top + offset, top, edge: "none", tab: "none" }, room);
350
+ }
351
+ if (open)
352
+ return settle({ ...from, y: to, tab: "none" }, room);
353
+ const y = snap(to, PANEL_GAP, room.view - PANEL_GAP - room.handle);
354
+ return settle({ y, top: y - offset, edge: "none", tab: "none" }, room);
355
+ }
356
+ function dragDocked(to, from, room) {
357
+ const y = snap(to, PANEL_GAP, room.view - PANEL_GAP - room.handle);
358
+ return { y, top: y - (from.y - from.top), edge: "none", tab: from.tab };
359
+ }
360
+ function dockedHandle(y, room) {
361
+ return between(y, PANEL_GAP, room.view - PANEL_GAP - room.handle);
362
+ }
363
+ function speedOf(from, to) {
364
+ const time = to.t - from.t;
365
+ return { x: (to.x - from.x) / time, y: (to.y - from.y) / time };
366
+ }
367
+ function velocity(samples, at) {
368
+ const recent = samples.filter((sample) => sample.t >= at - FLING_SPAN && sample.t <= at);
369
+ let fastest = { x: 0, y: 0 };
370
+ let read = false;
371
+ for (const [index, end] of recent.entries()) {
372
+ let start;
373
+ for (const sample of recent.slice(0, index)) {
374
+ if (end.t - sample.t >= FLING_STRETCH)
375
+ start = sample;
376
+ }
377
+ if (!start)
378
+ continue;
379
+ const speed = speedOf(start, end);
380
+ if (!read || Math.hypot(speed.x, speed.y) > Math.hypot(fastest.x, fastest.y))
381
+ fastest = speed;
382
+ read = true;
383
+ }
384
+ const first = recent[0];
385
+ const last = recent[recent.length - 1];
386
+ if (!read && first && last && last.t - first.t >= FLING_LEAST)
387
+ return speedOf(first, last);
388
+ return fastest;
389
+ }
390
+ function glideTime(distance) {
391
+ return between(distance / GLIDE_SPEED, GLIDE, GLIDE_MAX);
392
+ }
393
+ function landSide(side, x, width, vx, vy) {
394
+ const other = otherSide(side);
395
+ const toward = side === "right" ? -vx : vx;
396
+ const across = Math.abs(vx) >= FLING && Math.abs(vx) > FLING_LEAN * Math.abs(vy);
397
+ const past = side === "right" ? x < width / 2 : x > width / 2;
398
+ if (across && toward > 0)
399
+ return other;
400
+ if (across && toward < 0)
401
+ return side;
402
+ return past ? other : side;
403
+ }
404
+ function translateOf(value) {
405
+ const [x = 0, y = 0] = value === "none" ? [] : value.split(" ").map((part) => parseFloat(part));
406
+ return { x: Number.isFinite(x) ? x : 0, y: Number.isFinite(y) ? y : 0 };
407
+ }
408
+
409
+ // src/ui/size.ts
410
+ var PANEL_WIDTH = DOCK_WIDTH;
411
+ var WIDTH_MIN = 240;
412
+ var WIDTH_MAX = 720;
413
+ var PAGE_ROOM = 96;
414
+ function pageRoom(docked) {
415
+ return docked ? PAGE_MIN : PAGE_ROOM;
416
+ }
417
+ var WIDTH_STEP = 16;
418
+ var HANDLE_REACH = 21;
419
+ function widthLimits(view, page = PAGE_ROOM) {
420
+ return { min: WIDTH_MIN, max: Math.max(WIDTH_MIN, Math.min(WIDTH_MAX, view - page)) };
421
+ }
422
+ function widthIn(wanted, view, page = PAGE_ROOM) {
423
+ const { min, max } = widthLimits(view, page);
424
+ return Math.round(between(wanted, min, max));
425
+ }
426
+ function dragWidth(from, travel, side) {
427
+ return from + (side === "right" ? -travel : travel);
428
+ }
429
+ function keyWidth(key, width, limits, side) {
430
+ if (key === "Home")
431
+ return limits.min;
432
+ if (key === "End")
433
+ return limits.max;
434
+ if (key !== "ArrowLeft" && key !== "ArrowRight")
435
+ return null;
436
+ const wider = key === "ArrowLeft" === (side === "right");
437
+ return between(width + (wider ? WIDTH_STEP : -WIDTH_STEP), limits.min, limits.max);
438
+ }
439
+ function widthGlides(cue) {
440
+ return !cue.first && !cue.dragging && !cue.resizing;
441
+ }
442
+ function createSizer(context) {
443
+ const { host, wrap, panel, prefs } = context;
444
+ const strip = document.createElement("div");
445
+ strip.className = "sizer";
446
+ strip.tabIndex = 0;
447
+ strip.setAttribute("role", "separator");
448
+ strip.setAttribute("aria-orientation", "vertical");
449
+ strip.setAttribute("aria-label", "panel width");
450
+ let shown = null;
451
+ let held = null;
452
+ function viewWidth() {
453
+ return document.documentElement.clientWidth || window.innerWidth;
454
+ }
455
+ function put(width) {
456
+ wrap.style.setProperty("--panel-width", `${width}px`);
457
+ }
458
+ function apply(draw, resizing) {
459
+ const view = viewWidth();
460
+ const page = pageRoom(context.place().docked);
461
+ const next = widthIn(held ? held.width : prefs.get().width, view, page);
462
+ const from = shown;
463
+ const limits = widthLimits(view, page);
464
+ strip.setAttribute("aria-valuemin", String(limits.min));
465
+ strip.setAttribute("aria-valuemax", String(limits.max));
466
+ if (next === from || from !== null && !context.place().open) {
467
+ draw?.();
468
+ return;
469
+ }
470
+ strip.setAttribute("aria-valuenow", String(next));
471
+ const glide = widthGlides({ first: from === null, dragging: held !== null, resizing });
472
+ shown = next;
473
+ context.wide(next);
474
+ host.style.width = `${HANDLE_REACH + next}px`;
475
+ panel.style.transitionProperty = "none";
476
+ put(next);
477
+ draw?.();
478
+ if (glide && from !== null)
479
+ put(from);
480
+ panel.getBoundingClientRect();
481
+ panel.style.transitionProperty = "";
482
+ put(next);
483
+ if (from !== null)
484
+ context.sized(glide);
485
+ }
486
+ function end(keep) {
487
+ if (!held)
488
+ return;
489
+ const { pointer, width, moved } = held;
490
+ held = null;
491
+ delete wrap.dataset.sizing;
492
+ if (strip.hasPointerCapture(pointer))
493
+ strip.releasePointerCapture(pointer);
494
+ if (keep && moved)
495
+ prefs.setWidth(width);
496
+ else
497
+ apply(undefined, false);
498
+ }
499
+ strip.addEventListener("pointerdown", (event) => {
500
+ if (event.button !== 0 || held || shown === null)
501
+ return;
502
+ held = {
503
+ pointer: event.pointerId,
504
+ from: shown,
505
+ x: event.clientX,
506
+ width: shown,
507
+ moved: false
508
+ };
509
+ wrap.dataset.sizing = "true";
510
+ strip.setPointerCapture(event.pointerId);
511
+ });
512
+ strip.addEventListener("pointermove", (event) => {
513
+ if (!held || event.pointerId !== held.pointer)
514
+ return;
515
+ const { side, docked } = context.place();
516
+ const wanted = dragWidth(held.from, event.clientX - held.x, side);
517
+ const width = widthIn(wanted, viewWidth(), pageRoom(docked));
518
+ if (width === held.width)
519
+ return;
520
+ held.width = width;
521
+ held.moved = true;
522
+ apply(undefined, false);
523
+ });
524
+ strip.addEventListener("pointerup", (event) => {
525
+ if (event.pointerId === held?.pointer)
526
+ end(true);
527
+ });
528
+ strip.addEventListener("pointercancel", (event) => {
529
+ if (event.pointerId === held?.pointer)
530
+ end(false);
531
+ });
532
+ strip.addEventListener("lostpointercapture", (event) => {
533
+ if (event.pointerId === held?.pointer)
534
+ end(false);
535
+ });
536
+ strip.addEventListener("dblclick", () => prefs.setWidth(PANEL_WIDTH));
537
+ strip.addEventListener("keydown", (event) => {
538
+ if (shown === null || event.altKey || event.ctrlKey || event.metaKey)
539
+ return;
540
+ const { side, docked } = context.place();
541
+ const limits = widthLimits(viewWidth(), pageRoom(docked));
542
+ const next = keyWidth(event.key, shown, limits, side);
543
+ if (next === null)
544
+ return;
545
+ event.preventDefault();
546
+ prefs.setWidth(next);
547
+ });
548
+ return {
549
+ strip,
550
+ size: (draw) => apply(draw, false),
551
+ fit: () => apply(undefined, true),
552
+ cancel: () => end(false)
553
+ };
554
+ }
555
+
556
+ // src/ui/prefs.ts
557
+ var PREFS_KEY = "devknobs:prefs";
558
+ var PREFS_VERSION = 6;
559
+ var STYLES_MODE = "simple";
560
+ var STYLES_BOX = true;
561
+ var CHANGES_DIFF = false;
562
+ var HTML_HEIGHT = 200;
563
+ var HTML_MIN = 64;
564
+ function readPrefs(json) {
565
+ let value = null;
566
+ try {
567
+ value = json ? JSON.parse(json) : null;
568
+ } catch {
569
+ return {};
570
+ }
571
+ if (typeof value !== "object" || value === null || Array.isArray(value))
572
+ return {};
573
+ if (newer(value, PREFS_VERSION))
574
+ return {};
575
+ const prefs = {};
576
+ const handle = Reflect.get(value, "handle");
577
+ if (typeof handle === "boolean")
578
+ prefs.handle = handle;
579
+ const width = Reflect.get(value, versionOf(value) < 6 ? "listWidth" : "width");
580
+ if (typeof width === "number" && Number.isFinite(width) && width > 0)
581
+ prefs.width = width;
582
+ const mode = Reflect.get(value, "stylesMode");
583
+ if (mode === "simple" || mode === "advanced")
584
+ prefs.stylesMode = mode;
585
+ const box = Reflect.get(value, "stylesBox");
586
+ if (typeof box === "boolean")
587
+ prefs.stylesBox = box;
588
+ const diff = Reflect.get(value, "changesDiff");
589
+ if (typeof diff === "boolean")
590
+ prefs.changesDiff = diff;
591
+ const height = Reflect.get(value, "htmlHeight");
592
+ if (typeof height === "number" && Number.isFinite(height) && height > 0)
593
+ prefs.htmlHeight = Math.max(HTML_MIN, height);
594
+ const full = Reflect.get(value, "htmlFull");
595
+ if (typeof full === "boolean")
596
+ prefs.htmlFull = full;
597
+ return prefs;
598
+ }
599
+ function resolvePrefs(base, stored) {
600
+ return { ...base, ...stored };
601
+ }
602
+ function loadPrefs() {
603
+ try {
604
+ return readPrefs(webStorage("local")?.getItem(PREFS_KEY));
605
+ } catch {
606
+ return {};
607
+ }
608
+ }
609
+ function keepPrefs(prefs) {
610
+ try {
611
+ if (Object.keys(prefs).length === 0)
612
+ webStorage("local")?.removeItem(PREFS_KEY);
613
+ else
614
+ webStorage("local")?.setItem(PREFS_KEY, JSON.stringify(stamped(prefs, PREFS_VERSION)));
615
+ } catch {}
616
+ }
617
+ function createPrefs(options = {}) {
618
+ const base = {
619
+ handle: options.handle !== false,
620
+ width: PANEL_WIDTH,
621
+ stylesMode: STYLES_MODE,
622
+ stylesBox: STYLES_BOX,
623
+ changesDiff: CHANGES_DIFF,
624
+ htmlHeight: HTML_HEIGHT,
625
+ htmlFull: false
626
+ };
627
+ let stored = loadPrefs();
628
+ let prefs = resolvePrefs(base, stored);
629
+ const listeners = new Set;
630
+ function changed() {
631
+ prefs = resolvePrefs(base, stored);
632
+ for (const listener of Array.from(listeners))
633
+ listener();
634
+ }
635
+ function keep(next) {
636
+ stored = next;
637
+ keepPrefs(stored);
638
+ changed();
639
+ }
640
+ function onStorage(event) {
641
+ if (event.key !== PREFS_KEY && event.key !== null)
642
+ return;
643
+ if (fresh())
644
+ return;
645
+ stored = loadPrefs();
646
+ changed();
647
+ }
648
+ if (typeof window !== "undefined")
649
+ window.addEventListener("storage", onStorage);
650
+ return {
651
+ get: () => prefs,
652
+ setHandle(on) {
653
+ const next = { ...stored };
654
+ if (on === base.handle)
655
+ delete next.handle;
656
+ else
657
+ next.handle = on;
658
+ keep(next);
659
+ },
660
+ setWidth(px) {
661
+ const next = { ...stored };
662
+ if (px === base.width)
663
+ delete next.width;
664
+ else
665
+ next.width = px;
666
+ keep(next);
667
+ },
668
+ setStylesMode(mode) {
669
+ const next = { ...stored };
670
+ if (mode === base.stylesMode)
671
+ delete next.stylesMode;
672
+ else
673
+ next.stylesMode = mode;
674
+ keep(next);
675
+ },
676
+ setStylesBox(open) {
677
+ const next = { ...stored };
678
+ if (open === base.stylesBox)
679
+ delete next.stylesBox;
680
+ else
681
+ next.stylesBox = open;
682
+ keep(next);
683
+ },
684
+ setChangesDiff(open) {
685
+ const next = { ...stored };
686
+ if (open === base.changesDiff)
687
+ delete next.changesDiff;
688
+ else
689
+ next.changesDiff = open;
690
+ keep(next);
691
+ },
692
+ setHtmlSize({ height, full }) {
693
+ const next = { ...stored };
694
+ if (height === base.htmlHeight)
695
+ delete next.htmlHeight;
696
+ else
697
+ next.htmlHeight = height;
698
+ if (full === base.htmlFull)
699
+ delete next.htmlFull;
700
+ else
701
+ next.htmlFull = full;
702
+ keep(next);
703
+ },
704
+ subscribe(listener) {
705
+ listeners.add(listener);
706
+ return () => {
707
+ listeners.delete(listener);
708
+ };
709
+ },
710
+ destroy() {
711
+ listeners.clear();
712
+ if (typeof window !== "undefined")
713
+ window.removeEventListener("storage", onStorage);
714
+ }
715
+ };
716
+ }
717
+
718
+ export { FORCED_STATES, forcedSelector, forcing, clearForced, forceState, FORCING, DRAG_SLOP, FLING_SPAN, FLING_TRAVEL, GLIDE, dragTarget, otherSide, between, settle, cornerAt, dragTo, dragDocked, dockedHandle, velocity, glideTime, landSide, translateOf, createSizer, HTML_MIN, createPrefs };