deictic 0.0.1 → 0.2.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 (176) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +167 -0
  3. package/dist/annotations/client.d.ts +4 -0
  4. package/dist/annotations/client.d.ts.map +1 -0
  5. package/dist/annotations/client.js +497 -0
  6. package/dist/annotations/client.js.map +1 -0
  7. package/dist/annotations/index.d.ts +110 -0
  8. package/dist/annotations/index.d.ts.map +1 -0
  9. package/dist/annotations/index.js +22 -0
  10. package/dist/annotations/index.js.map +1 -0
  11. package/dist/astro.d.ts +29 -0
  12. package/dist/astro.d.ts.map +1 -0
  13. package/dist/astro.js +24 -0
  14. package/dist/astro.js.map +1 -0
  15. package/dist/bun.d.ts +12 -0
  16. package/dist/bun.d.ts.map +1 -0
  17. package/dist/bun.js +67 -0
  18. package/dist/bun.js.map +1 -0
  19. package/dist/client/index.d.ts +95 -0
  20. package/dist/client/index.d.ts.map +1 -0
  21. package/dist/client/index.js +1333 -0
  22. package/dist/client/index.js.map +1 -0
  23. package/dist/index.d.ts +23 -0
  24. package/dist/index.js +10 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/loader.d.ts +15 -0
  27. package/dist/loader.d.ts.map +1 -0
  28. package/dist/loader.js +17 -0
  29. package/dist/loader.js.map +1 -0
  30. package/dist/next.d.ts +17 -0
  31. package/dist/next.d.ts.map +1 -0
  32. package/dist/next.js +150 -0
  33. package/dist/next.js.map +1 -0
  34. package/dist/recommended/index.d.ts +25 -0
  35. package/dist/recommended/index.d.ts.map +1 -0
  36. package/dist/recommended/index.js +19 -0
  37. package/dist/recommended/index.js.map +1 -0
  38. package/dist/recordings/client.d.ts +4 -0
  39. package/dist/recordings/client.d.ts.map +1 -0
  40. package/dist/recordings/client.js +376 -0
  41. package/dist/recordings/client.js.map +1 -0
  42. package/dist/recordings/index.d.ts +2 -0
  43. package/dist/recordings/index.js +3 -0
  44. package/dist/screenshots/client.d.ts +23 -0
  45. package/dist/screenshots/client.d.ts.map +1 -0
  46. package/dist/screenshots/client.js +76 -0
  47. package/dist/screenshots/client.js.map +1 -0
  48. package/dist/screenshots/dom.d.ts +4 -0
  49. package/dist/screenshots/dom.d.ts.map +1 -0
  50. package/dist/screenshots/dom.js +92 -0
  51. package/dist/screenshots/dom.js.map +1 -0
  52. package/dist/screenshots/index.d.ts +2 -0
  53. package/dist/screenshots/index.js +98 -0
  54. package/dist/screenshots/index.js.map +1 -0
  55. package/dist/screenshots/rrweb.d.ts +9 -0
  56. package/dist/screenshots/rrweb.d.ts.map +1 -0
  57. package/dist/screenshots/rrweb.js +60 -0
  58. package/dist/screenshots/rrweb.js.map +1 -0
  59. package/dist/shared/endpoints.js +354 -0
  60. package/dist/shared/endpoints.js.map +1 -0
  61. package/dist/shared/index.d.ts +226 -0
  62. package/dist/shared/index.d.ts.map +1 -0
  63. package/dist/shared/index2.d.ts +98 -0
  64. package/dist/shared/index2.d.ts.map +1 -0
  65. package/dist/shared/index3.d.ts +86 -0
  66. package/dist/shared/index3.d.ts.map +1 -0
  67. package/dist/shared/index4.d.ts +184 -0
  68. package/dist/shared/index4.d.ts.map +1 -0
  69. package/dist/shared/index5.d.ts +70 -0
  70. package/dist/shared/index5.d.ts.map +1 -0
  71. package/dist/shared/integration.d.ts +20 -0
  72. package/dist/shared/integration.d.ts.map +1 -0
  73. package/dist/shared/integration.js +279 -0
  74. package/dist/shared/integration.js.map +1 -0
  75. package/dist/shared/kept.js +23 -0
  76. package/dist/shared/kept.js.map +1 -0
  77. package/dist/shared/marks.js +14 -0
  78. package/dist/shared/marks.js.map +1 -0
  79. package/dist/shared/playwright.js +105 -0
  80. package/dist/shared/playwright.js.map +1 -0
  81. package/dist/shared/recordings.js +246 -0
  82. package/dist/shared/recordings.js.map +1 -0
  83. package/dist/shared/shortcut.js +63 -0
  84. package/dist/shared/shortcut.js.map +1 -0
  85. package/dist/shared/tasks.js +521 -0
  86. package/dist/shared/tasks.js.map +1 -0
  87. package/dist/shared/waveform.js +93 -0
  88. package/dist/shared/waveform.js.map +1 -0
  89. package/dist/tailwind/client.d.ts +4 -0
  90. package/dist/tailwind/client.d.ts.map +1 -0
  91. package/dist/tailwind/client.js +613 -0
  92. package/dist/tailwind/client.js.map +1 -0
  93. package/dist/tailwind/index.d.ts +2 -0
  94. package/dist/tailwind/index.js +557 -0
  95. package/dist/tailwind/index.js.map +1 -0
  96. package/dist/tasks/client.d.ts +6 -0
  97. package/dist/tasks/client.d.ts.map +1 -0
  98. package/dist/tasks/client.js +642 -0
  99. package/dist/tasks/client.js.map +1 -0
  100. package/dist/tasks/index.d.ts +2 -0
  101. package/dist/tasks/index.js +1 -0
  102. package/dist/vite.d.ts +16 -0
  103. package/dist/vite.d.ts.map +1 -0
  104. package/dist/vite.js +61 -0
  105. package/dist/vite.js.map +1 -0
  106. package/dist/voice/client.d.ts +4 -0
  107. package/dist/voice/client.d.ts.map +1 -0
  108. package/dist/voice/client.js +66 -0
  109. package/dist/voice/client.js.map +1 -0
  110. package/dist/voice/index.d.ts +47 -0
  111. package/dist/voice/index.d.ts.map +1 -0
  112. package/dist/voice/index.js +74 -0
  113. package/dist/voice/index.js.map +1 -0
  114. package/dist/webpack.d.ts +50 -0
  115. package/dist/webpack.d.ts.map +1 -0
  116. package/dist/webpack.js +78 -0
  117. package/dist/webpack.js.map +1 -0
  118. package/package.json +307 -7
  119. package/skills/deictic/SKILL.md +47 -0
  120. package/skills/deictic/references/install.md +96 -0
  121. package/skills/deictic/references/recordings.md +83 -0
  122. package/skills/deictic/references/tasks.md +79 -0
  123. package/skills/deictic/references/watch.md +43 -0
  124. package/skills/deictic/scripts/frame.mjs +62 -0
  125. package/skills/deictic/scripts/lib.mjs +211 -0
  126. package/skills/deictic/scripts/recording.mjs +186 -0
  127. package/skills/deictic/scripts/task.mjs +84 -0
  128. package/skills/deictic/scripts/transcribe.mjs +93 -0
  129. package/skills/deictic/scripts/voice.mjs +50 -0
  130. package/skills/deictic/scripts/watch.mjs +51 -0
  131. package/src/astro.ts +34 -0
  132. package/src/bun.ts +79 -0
  133. package/src/client/index.ts +846 -0
  134. package/src/client/lightbox.ts +256 -0
  135. package/src/client/style.ts +243 -0
  136. package/src/client/tooltip.ts +78 -0
  137. package/src/client/waveform.ts +98 -0
  138. package/src/index.ts +247 -0
  139. package/src/loader.ts +28 -0
  140. package/src/next.ts +133 -0
  141. package/src/plugins/annotations/client.ts +301 -0
  142. package/src/plugins/annotations/draw.ts +169 -0
  143. package/src/plugins/annotations/index.ts +105 -0
  144. package/src/plugins/annotations/svg.ts +61 -0
  145. package/src/plugins/recommended/index.ts +35 -0
  146. package/src/plugins/recordings/client.ts +316 -0
  147. package/src/plugins/recordings/index.ts +175 -0
  148. package/src/plugins/recordings/marks.ts +11 -0
  149. package/src/plugins/recordings/ours.ts +70 -0
  150. package/src/plugins/recordings/replay.ts +165 -0
  151. package/src/plugins/screenshots/client.ts +64 -0
  152. package/src/plugins/screenshots/dom.ts +79 -0
  153. package/src/plugins/screenshots/index.ts +194 -0
  154. package/src/plugins/screenshots/playwright.ts +119 -0
  155. package/src/plugins/screenshots/rrweb.ts +45 -0
  156. package/src/plugins/tailwind/catalog.ts +396 -0
  157. package/src/plugins/tailwind/client.ts +669 -0
  158. package/src/plugins/tailwind/index.ts +267 -0
  159. package/src/plugins/tasks/client.ts +622 -0
  160. package/src/plugins/tasks/index.ts +557 -0
  161. package/src/plugins/tasks/local.ts +170 -0
  162. package/src/plugins/voice/client.ts +58 -0
  163. package/src/plugins/voice/index.ts +114 -0
  164. package/src/shortcut.ts +83 -0
  165. package/src/tools/astro.ts +81 -0
  166. package/src/tools/editor.ts +22 -0
  167. package/src/tools/endpoints.ts +163 -0
  168. package/src/tools/history.ts +203 -0
  169. package/src/tools/integration.ts +108 -0
  170. package/src/tools/kept.ts +21 -0
  171. package/src/tools/locate.ts +94 -0
  172. package/src/tools/plugins.ts +41 -0
  173. package/src/tools/source.ts +72 -0
  174. package/src/vite.ts +81 -0
  175. package/src/webpack.ts +107 -0
  176. package/index.js +0 -1
@@ -0,0 +1,613 @@
1
+ import { defineClientPlugin } from "../index.js";
2
+ // src/plugins/tailwind/client.ts
3
+ /**
4
+ * Tailwind's panel: the element's classes as chips, a field to add more, and Save. Every change
5
+ * previews on the page at once, on every element from the same place in the source, keeping the
6
+ * classes the source adds at runtime; closing without saving puts the page back.
7
+ *
8
+ * Where a class helper adds more on a condition (`cn('…', active && '…')`), each condition whose classes are a
9
+ * string in the file is a state to pick, beside the element's own list: picked, its classes are the chips, and
10
+ * they show on the clicked element whether or not the condition holds there. A dot marks the ones that do hold,
11
+ * read from the element's classes, which is all the page says of a condition.
12
+ *
13
+ * What the project's Tailwind knows comes from the server half's routes. The field completes the word being
14
+ * typed. A chip of a class Tailwind knows shows what it sets (a colour's swatch, a size's value) and opens the
15
+ * classes of its kind to switch between, with a field for a value of one's own (`text-[13px]`). A class no file
16
+ * used before has no CSS in the page's build until it's saved, so the preview brings its own, in a style of the
17
+ * page's that goes as the panel does. The completions and a chip's kind open in boxes of their own beside the popup
18
+ * (in the overlay's root, placed each frame), so the popup keeps its size and nothing in it moves. Without Tailwind v4 the chips are plain and nothing completes.
19
+ */
20
+ const STYLE = `
21
+ .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
22
+ .chip { display: inline-flex; align-items: stretch; border: 1px solid var(--deictic-line); border-radius: 4px; font: 12px/20px ui-monospace, monospace; }
23
+ .chip.open { border-color: var(--deictic-accent); }
24
+ .chip .name { display: inline-flex; align-items: center; gap: 5px; padding: 0 2px 0 6px; border: 0; border-radius: 3px 0 0 3px; font: inherit; }
25
+ .chip button.name:hover { background: rgb(255 255 255 / 0.08); }
26
+ .chip .x { border: 0; padding: 0 5px; color: var(--deictic-muted); }
27
+ .chip .x:hover { color: var(--deictic-problem); }
28
+ /* A colour over a checker, so one that's part clear shows it. */
29
+ .swatch {
30
+ flex: none;
31
+ width: 10px;
32
+ height: 10px;
33
+ border-radius: 2px;
34
+ box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.25);
35
+ background: linear-gradient(var(--c), var(--c)), repeating-conic-gradient(#71717a 0 25%, #d4d4d8 0 50%) 0 0 / 6px 6px;
36
+ }
37
+ .hint { color: var(--deictic-muted); }
38
+ /* Beside the popup, not in it: in its flow they'd resize it under the pointer with every word and click. */
39
+ .editor, .suggest {
40
+ position: fixed;
41
+ left: 0;
42
+ top: 0;
43
+ z-index: 2147483647;
44
+ box-sizing: border-box;
45
+ border: 1px solid var(--deictic-line);
46
+ border-radius: 6px;
47
+ font: 13px/1.4 system-ui, sans-serif;
48
+ color: var(--deictic-fg);
49
+ background: var(--deictic-bg);
50
+ box-shadow: 0 8px 24px rgb(0 0 0 / 0.45);
51
+ }
52
+ .editor[hidden], .suggest[hidden] { display: none; }
53
+ .editor .top { display: flex; align-items: center; gap: 4px; padding: 2px 2px 2px 8px; font: 12px ui-monospace, monospace; color: var(--deictic-muted); }
54
+ .editor .top button:first-of-type { margin-left: auto; }
55
+ .editor .top .more { padding: 0 6px; font: 12px/18px system-ui, sans-serif; }
56
+ .editor .top .more[aria-expanded='true'] { border-color: var(--deictic-accent); color: var(--deictic-fg); }
57
+ .custom[hidden] { display: none; }
58
+ .alts { position: relative; display: flex; flex-wrap: wrap; gap: 4px; max-height: 190px; padding: 2px 8px 8px; overflow: auto; }
59
+ .alts button { display: inline-flex; align-items: center; gap: 5px; padding: 0 6px; font: 12px/20px ui-monospace, monospace; }
60
+ .alts button[aria-pressed='true'] { border-color: var(--deictic-accent); color: var(--deictic-accent); }
61
+ .alts .family { display: flex; gap: 2px; flex-basis: 100%; }
62
+ .alts .family button { padding: 0; border: 0; border-radius: 3px; }
63
+ .alts .family .swatch { width: 18px; height: 18px; border-radius: 3px; }
64
+ .alts .family button[aria-pressed='true'] { outline: 2px solid var(--deictic-fg); outline-offset: 1px; }
65
+ .custom { display: flex; gap: 6px; align-items: center; padding: 6px 8px; border-top: 1px solid var(--deictic-line); }
66
+ .custom input[type='color'] { flex: none; width: 28px; height: 24px; padding: 1px; cursor: pointer; }
67
+ .custom input[aria-invalid='true'] { border-color: var(--deictic-problem); }
68
+ .suggest { max-height: 168px; overflow: auto; }
69
+ .option { display: flex; align-items: center; gap: 6px; padding: 1px 6px; font: 12px/20px ui-monospace, monospace; cursor: pointer; }
70
+ .option[aria-selected='true'] { background: rgb(255 255 255 / 0.1); }
71
+ .option .hint { margin-left: auto; }
72
+ .row { display: flex; gap: 6px; margin-top: 8px; justify-content: flex-end; align-items: center; }
73
+ .states { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
74
+ .state { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; padding: 0 8px; border-radius: 999px; font: 12px/20px ui-monospace, monospace; color: var(--deictic-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
75
+ .state[aria-pressed='true'] { border-color: var(--deictic-accent); color: var(--deictic-fg); }
76
+ .state .dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--deictic-accent); }
77
+ .note { margin: -2px 0 8px; font-size: 12px; color: var(--deictic-muted); }
78
+ .note:empty { display: none; }
79
+ .note code { color: var(--deictic-fg); }
80
+ .extras { display: grid; gap: 6px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--deictic-line); font-size: 12px; color: var(--deictic-muted); }
81
+ .extra { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
82
+ .extra .when { flex-basis: 100%; }
83
+ .extra code { color: var(--deictic-fg); }
84
+ /* The code's own classes: shown, not edited here, and faint while their condition doesn't hold. */
85
+ .chip.fixed { border-style: dashed; }
86
+ .chip.fixed .name { padding-right: 6px; }
87
+ .chip.fixed.off { opacity: 0.45; }
88
+ `;
89
+ const split = (list) => list.split(/\s+/).filter(Boolean);
90
+ /** The family a shade is of: `bg-red` for `bg-red-500`. */
91
+ const familyOf = (name) => /^(.*)-\d+(\/[^/]*)?!?$/.exec(name)?.[1];
92
+ function make(tag, className, text) {
93
+ const el = document.createElement(tag);
94
+ el.className = className;
95
+ if (text !== void 0) el.textContent = text;
96
+ if (el instanceof HTMLButtonElement) el.type = "button";
97
+ return el;
98
+ }
99
+ function swatch(color) {
100
+ const el = make("span", "swatch");
101
+ el.style.setProperty("--c", color);
102
+ return el;
103
+ }
104
+ /** A class as it reads everywhere: its colour, its name, and what it sets where the name doesn't say. */
105
+ function face(into, info) {
106
+ if (info.color !== void 0) into.append(swatch(info.color));
107
+ into.append(info.name);
108
+ const { value } = info;
109
+ if (info.color !== void 0 || value === void 0 || value.length > 18 || value.includes("var(") || info.name.endsWith(value)) return;
110
+ into.append(make("span", "hint", value));
111
+ }
112
+ var client_default = defineClientPlugin({
113
+ name: "tailwind",
114
+ label: "Tailwind",
115
+ mount(panel, context) {
116
+ const style = document.createElement("style");
117
+ style.textContent = STYLE;
118
+ panel.append(style);
119
+ const { model } = context;
120
+ if (!model.editable) {
121
+ const note = document.createElement("p");
122
+ note.textContent = "These classes are built at runtime, so there is no one list to edit:";
123
+ const code = document.createElement("code");
124
+ code.textContent = model.source;
125
+ panel.append(note, code);
126
+ return () => {};
127
+ }
128
+ const originals = context.elements.map((el) => el.getAttribute("class"));
129
+ const others = model.others ?? [];
130
+ const states = [{
131
+ label: "Base",
132
+ saved: split(model.classes),
133
+ draft: split(model.classes)
134
+ }, ...others.flatMap((other, at) => other.editable === true ? [{
135
+ at,
136
+ label: other.when ?? other.source,
137
+ saved: split(other.classes ?? ""),
138
+ draft: split(other.classes ?? "")
139
+ }] : [])];
140
+ const own = states[0];
141
+ let current = own;
142
+ const runtime = context.elements.map((el) => model.others === void 0 ? [] : split(el.getAttribute("class") ?? "").filter((c) => !own.saved.includes(c)));
143
+ const on = others.map((other) => {
144
+ const adds = split(other.classes ?? "");
145
+ return runtime.map((has) => adds.length > 0 && adds.filter((c) => has.includes(c)).length * 2 >= adds.length);
146
+ });
147
+ const told = new Set(others.flatMap((other) => split(other.classes ?? "")));
148
+ const untold = runtime.map((has) => has.filter((c) => !told.has(c)));
149
+ const clicked = context.elements.indexOf(context.element);
150
+ /**
151
+ * An element's classes with each list as `pick` has it. `forced` adds the shown state's to the clicked element
152
+ * though its condition doesn't hold there, so there's something to see while it's edited.
153
+ */
154
+ const classesOf = (i, pick, forced) => [
155
+ ...pick(own),
156
+ ...others.flatMap((other, at) => {
157
+ const state = states.find((s) => s.at === at);
158
+ if (on[at][i] !== true && !(forced && state === current && i === clicked)) return [];
159
+ return state === void 0 ? split(other.classes ?? "") : pick(state);
160
+ }),
161
+ ...untold[i]
162
+ ];
163
+ const unsaved = () => states.some((state) => state.draft.join(" ") !== state.saved.join(" "));
164
+ let previewed = false;
165
+ let committed = false;
166
+ let gone = false;
167
+ const ask = async (route, init) => {
168
+ try {
169
+ const res = await context.request(route, init);
170
+ return res.ok ? await res.json() : void 0;
171
+ } catch {
172
+ return;
173
+ }
174
+ };
175
+ const naming = (classes) => ({
176
+ method: "POST",
177
+ headers: { "content-type": "application/json" },
178
+ body: JSON.stringify({ classes })
179
+ });
180
+ /** What Tailwind says of each class seen so far. */
181
+ const known = /* @__PURE__ */ new Map();
182
+ /** Set once the server says it has no Tailwind to ask. */
183
+ let plain = false;
184
+ const chips = make("div", "chips");
185
+ const editor = make("div", "editor");
186
+ editor.hidden = true;
187
+ const input = document.createElement("input");
188
+ input.placeholder = "Add classes, Enter to add";
189
+ input.spellcheck = false;
190
+ input.autocomplete = "off";
191
+ const list = make("div", "suggest");
192
+ list.setAttribute("role", "listbox");
193
+ list.hidden = true;
194
+ const save = make("button", "primary", "Save");
195
+ const row = make("div", "row");
196
+ row.append(save);
197
+ const picks = make("div", "states");
198
+ const note = make("div", "note");
199
+ if (states.length > 1) panel.append(picks, note);
200
+ panel.append(chips, input, row);
201
+ const around = panel.getRootNode();
202
+ const root = around instanceof ShadowRoot ? around : context.root;
203
+ root.append(editor, list);
204
+ /** The chip whose kind is open in the editor, by its place in the current.draft. */
205
+ let editing;
206
+ const floats = [[editor, () => editing === void 0 ? void 0 : chips.children[editing]], [list, () => input]];
207
+ const place = () => {
208
+ for (const [box, by] of floats) {
209
+ if (box.hidden !== false) continue;
210
+ const anchor = by();
211
+ if (anchor === void 0) continue;
212
+ const at = anchor.getBoundingClientRect();
213
+ const span = input.getBoundingClientRect();
214
+ const height = box.offsetHeight;
215
+ const below = window.innerHeight - at.bottom;
216
+ const top = height + 12 > below && at.top > below ? at.top - height - 4 : at.bottom + 4;
217
+ const place = `${Math.round(span.left)}px ${Math.round(top)}px`;
218
+ if (box.style.translate !== place) box.style.translate = place;
219
+ const width = `${Math.round(span.width)}px`;
220
+ if (box.style.width !== width) box.style.width = width;
221
+ }
222
+ };
223
+ let following = requestAnimationFrame(function follow() {
224
+ following = requestAnimationFrame(follow);
225
+ place();
226
+ });
227
+ const extras = make("div", "extras");
228
+ const fixed = others.filter((other) => other.editable !== true);
229
+ if (fixed.length > 0) panel.append(extras);
230
+ const lit = new Set(runtime[clicked] ?? []);
231
+ /** Those arguments: what each adds as chips under what it waits on, or its code where nothing says. */
232
+ const drawExtras = () => {
233
+ extras.replaceChildren(...fixed.map((extra) => {
234
+ const row = make("div", "extra");
235
+ const when = make("div", "when");
236
+ if (extra.when === void 0) when.append("Always");
237
+ else when.append("When ", make("code", "", extra.when));
238
+ row.append(when);
239
+ if (extra.classes === void 0) {
240
+ when.append(", whatever ", make("code", "", extra.source), " adds");
241
+ return row;
242
+ }
243
+ for (const c of split(extra.classes)) {
244
+ const on = lit.has(c);
245
+ const chip = make("span", on ? "chip fixed" : "chip fixed off");
246
+ chip.title = on ? "On the element now. Change it in the code" : "Not on the element now. Change it in the code";
247
+ const name = make("span", "name");
248
+ face(name, known.get(c) ?? {
249
+ name: c,
250
+ known: false
251
+ });
252
+ chip.append(name);
253
+ row.append(chip);
254
+ }
255
+ return row;
256
+ }));
257
+ };
258
+ const built = /* @__PURE__ */ new Set([...states.flatMap((state) => state.saved), ...told]);
259
+ let sheet;
260
+ let styled = "";
261
+ const lend = async () => {
262
+ const fresh = [...new Set(states.flatMap((state) => state.draft))].filter((c) => !built.has(c));
263
+ const key = fresh.join(" ");
264
+ if (plain || key === styled) return;
265
+ styled = key;
266
+ const answer = fresh.length === 0 ? { css: "" } : await ask("css", naming(fresh));
267
+ if (answer === void 0 || key !== styled || gone) return;
268
+ sheet ??= document.head.appendChild(document.createElement("style"));
269
+ sheet.textContent = answer.css;
270
+ };
271
+ const preview = () => {
272
+ save.disabled = !unsaved();
273
+ context.unsaved(unsaved() ? save : void 0);
274
+ if (!unsaved() && !previewed && current === own) return;
275
+ context.elements.forEach((el, i) => el.setAttribute("class", classesOf(i, (state) => state.draft, true).join(" ")));
276
+ previewed = true;
277
+ lend();
278
+ };
279
+ /** The lists as buttons: the element's own, and each condition, dotted where it holds on the element now. */
280
+ const drawStates = () => {
281
+ picks.replaceChildren(...states.map((state) => {
282
+ const pick = make("button", "state");
283
+ const holds = state.at !== void 0 && on[state.at][clicked] === true;
284
+ if (holds) pick.append(make("span", "dot"));
285
+ pick.append(state.at === void 0 || others[state.at].when !== void 0 ? state.label : `always: ${state.label}`);
286
+ pick.setAttribute("aria-pressed", String(state === current));
287
+ if (state.at !== void 0) pick.title = holds ? "On the element now" : "Not on the element now: shown on it while you edit";
288
+ pick.addEventListener("click", () => {
289
+ shut(false);
290
+ hide();
291
+ current = state;
292
+ drawStates();
293
+ render();
294
+ input.focus();
295
+ });
296
+ return pick;
297
+ }));
298
+ const shared = current.at === void 0 ? void 0 : others[current.at].shared;
299
+ note.replaceChildren(...shared === void 0 ? [] : [
300
+ "From ",
301
+ make("code", "", shared),
302
+ ": everything that uses it changes too."
303
+ ]);
304
+ };
305
+ let opened = 0;
306
+ const drawChips = () => {
307
+ chips.replaceChildren(...current.draft.map((c, i) => {
308
+ const chip = make("span", i === editing ? "chip open" : "chip");
309
+ const info = known.get(c);
310
+ const name = make(info?.known === true ? "button" : "span", "name");
311
+ face(name, info ?? {
312
+ name: c,
313
+ known: false
314
+ });
315
+ if (name instanceof HTMLButtonElement) {
316
+ name.title = `Change ${c}`;
317
+ name.addEventListener("click", () => void (editing === i ? shut() : edit(i)));
318
+ }
319
+ const remove = make("button", "x", "×");
320
+ remove.title = `Remove ${c}`;
321
+ remove.addEventListener("click", () => {
322
+ shut();
323
+ current.draft = current.draft.toSpliced(i, 1);
324
+ render();
325
+ });
326
+ chip.append(name, remove);
327
+ return chip;
328
+ }));
329
+ };
330
+ const describe = async () => {
331
+ const shown = [...states.flatMap((state) => state.draft), ...told];
332
+ const missing = [...new Set(shown)].filter((c) => !known.has(c));
333
+ if (plain || missing.length === 0) return;
334
+ const answer = await ask("info", naming(missing));
335
+ if (answer === void 0) return;
336
+ plain = !answer.available;
337
+ for (const item of answer.items) known.set(item.name, item);
338
+ if (answer.items.length === 0) return;
339
+ drawChips();
340
+ drawExtras();
341
+ };
342
+ const render = () => {
343
+ drawChips();
344
+ preview();
345
+ describe();
346
+ };
347
+ const shut = (focus = true) => {
348
+ opened++;
349
+ if (editing === void 0) return;
350
+ editing = void 0;
351
+ editor.hidden = true;
352
+ editor.removeAttribute("data-deictic-modal");
353
+ editor.replaceChildren();
354
+ drawChips();
355
+ if (focus) input.focus();
356
+ };
357
+ const onPress = (e) => {
358
+ const path = e.composedPath();
359
+ if (!path.includes(editor) && !path.includes(chips)) shut(false);
360
+ };
361
+ root.addEventListener("pointerdown", onPress, true);
362
+ /** Puts `name` where the open chip's class is. The same class twice would be one, so that's left. */
363
+ const swap = (name, info) => {
364
+ if (editing === void 0 || current.draft.includes(name)) return;
365
+ known.set(name, info);
366
+ current.draft = current.draft.with(editing, name);
367
+ render();
368
+ };
369
+ const edit = async (at) => {
370
+ const turn = ++opened;
371
+ const was = current.draft[at];
372
+ const found = await ask(`alternatives?${new URLSearchParams({ class: was })}`);
373
+ if (turn !== opened || current.draft[at] !== was || found === void 0 || found === null) return;
374
+ editing = at;
375
+ drawChips();
376
+ const top = make("div", "top", found.label);
377
+ const close = make("button", "icon", "×");
378
+ close.title = "Close";
379
+ close.addEventListener("click", () => shut());
380
+ top.append(close);
381
+ const alts = make("div", "alts");
382
+ const buttons = /* @__PURE__ */ new Map();
383
+ const press = () => {
384
+ for (const [name, button] of buttons) button.setAttribute("aria-pressed", String(name === current.draft[at]));
385
+ };
386
+ const choice = (item, bare) => {
387
+ const button = make("button", "");
388
+ if (bare && item.color !== void 0) {
389
+ button.append(swatch(item.color));
390
+ button.title = item.name;
391
+ } else face(button, item);
392
+ button.addEventListener("click", () => {
393
+ swap(item.name, item);
394
+ press();
395
+ });
396
+ buttons.set(item.name, button);
397
+ return button;
398
+ };
399
+ const families = /* @__PURE__ */ new Map();
400
+ const loose = [];
401
+ for (const item of found.items) {
402
+ const family = found.colors && item.color !== void 0 ? familyOf(item.name) : void 0;
403
+ if (family === void 0) {
404
+ loose.push(choice(item, false));
405
+ continue;
406
+ }
407
+ const shades = families.get(family) ?? make("div", "family");
408
+ families.set(family, shades);
409
+ shades.append(choice(item, true));
410
+ }
411
+ alts.append(...loose, ...families.values());
412
+ press();
413
+ editor.replaceChildren(top, alts);
414
+ const { custom } = found;
415
+ if (custom !== void 0) {
416
+ const form = make("form", "custom");
417
+ const field = document.createElement("input");
418
+ field.placeholder = found.colors ? "A colour of your own: #12b358" : `A value of your own${hinted(known.get(was))}`;
419
+ field.spellcheck = false;
420
+ field.value = custom.value?.replaceAll("_", " ") ?? "";
421
+ const named = (value) => `${custom.before}${value.trim().replace(/\s+/g, "_")}${custom.after}`;
422
+ if (found.colors) {
423
+ const picker = document.createElement("input");
424
+ picker.type = "color";
425
+ picker.title = "Pick a colour";
426
+ if (/^#[\da-f]{6}$/i.test(field.value)) picker.value = field.value;
427
+ picker.addEventListener("input", () => {
428
+ field.value = picker.value;
429
+ field.removeAttribute("aria-invalid");
430
+ swap(named(picker.value), {
431
+ name: named(picker.value),
432
+ known: true,
433
+ color: picker.value,
434
+ value: picker.value
435
+ });
436
+ press();
437
+ });
438
+ form.append(picker);
439
+ }
440
+ const set = make("button", "", "Set");
441
+ set.type = "submit";
442
+ field.addEventListener("input", () => field.removeAttribute("aria-invalid"));
443
+ form.addEventListener("submit", (e) => {
444
+ e.preventDefault();
445
+ if (field.value.trim() === "") return;
446
+ const name = named(field.value);
447
+ ask("info", naming([name])).then((answer) => {
448
+ const info = answer?.items[0];
449
+ if (turn !== opened || editing !== at) return;
450
+ if (info?.known !== true) {
451
+ field.setAttribute("aria-invalid", "true");
452
+ field.title = `Tailwind makes nothing of ${name}`;
453
+ return;
454
+ }
455
+ swap(name, info);
456
+ edit(at);
457
+ });
458
+ });
459
+ form.append(field, set);
460
+ let asked = custom.value !== void 0;
461
+ const more = make("button", "more", "Custom");
462
+ more.title = "Set a value of your own";
463
+ const show = () => {
464
+ form.hidden = !asked;
465
+ more.setAttribute("aria-expanded", String(asked));
466
+ };
467
+ show();
468
+ more.addEventListener("click", () => {
469
+ asked = !asked;
470
+ show();
471
+ if (asked) field.focus();
472
+ });
473
+ close.before(more);
474
+ editor.append(form);
475
+ }
476
+ editor.setAttribute("data-deictic-modal", "");
477
+ editor.hidden = false;
478
+ place();
479
+ const chosen = buttons.get(current.draft[at]);
480
+ if (chosen !== void 0) alts.scrollTop = chosen.offsetTop - alts.clientHeight / 2;
481
+ (chosen ?? editor.querySelector("button"))?.focus();
482
+ };
483
+ editor.addEventListener("keydown", (e) => {
484
+ if (e.key !== "Escape") return;
485
+ e.preventDefault();
486
+ shut();
487
+ });
488
+ const commit = async () => {
489
+ for (const state of states) {
490
+ if (state.draft.join(" ") === state.saved.join(" ")) continue;
491
+ const next = await context.apply({
492
+ classes: state.draft.join(" "),
493
+ ...state.at === void 0 ? {} : { at: state.at }
494
+ });
495
+ if (next.editable) state.saved = split(state.at === void 0 ? next.classes : next.others?.[state.at]?.classes ?? "");
496
+ state.draft = [...state.saved];
497
+ committed = true;
498
+ }
499
+ previewed = false;
500
+ shut();
501
+ render();
502
+ };
503
+ /** What completes the word being typed, and the one Enter takes. */
504
+ let options = [];
505
+ let active = 0;
506
+ let typed = 0;
507
+ const drawOptions = () => {
508
+ list.hidden = options.length === 0;
509
+ list.toggleAttribute("data-deictic-modal", options.length > 0);
510
+ list.replaceChildren(...options.map((item, i) => {
511
+ const option = make("div", "option");
512
+ option.setAttribute("role", "option");
513
+ option.setAttribute("aria-selected", String(i === active));
514
+ face(option, item);
515
+ option.addEventListener("click", () => take(item));
516
+ return option;
517
+ }));
518
+ place();
519
+ const shown = list.children[active];
520
+ if (!(shown instanceof HTMLElement)) return;
521
+ if (shown.offsetTop < list.scrollTop) list.scrollTop = shown.offsetTop;
522
+ else if (shown.offsetTop + shown.offsetHeight > list.scrollTop + list.clientHeight) list.scrollTop = shown.offsetTop + shown.offsetHeight - list.clientHeight;
523
+ };
524
+ const hide = () => {
525
+ typed++;
526
+ options = [];
527
+ drawOptions();
528
+ };
529
+ const suggest = async () => {
530
+ const turn = ++typed;
531
+ const word = /\S*$/.exec(input.value)[0];
532
+ if (plain || word === "") return hide();
533
+ const answer = await ask(`complete?${new URLSearchParams({ q: word })}`);
534
+ if (turn !== typed) return;
535
+ options = (answer?.items ?? []).filter((item) => !current.draft.includes(item.name));
536
+ active = 0;
537
+ drawOptions();
538
+ };
539
+ /** Adds what the field holds. False when it held nothing new. */
540
+ const add = () => {
541
+ const added = split(input.value).filter((c) => !current.draft.includes(c));
542
+ input.value = "";
543
+ hide();
544
+ if (added.length === 0) return false;
545
+ current.draft = [...current.draft, ...added];
546
+ render();
547
+ return true;
548
+ };
549
+ const take = (item) => {
550
+ input.value = input.value.replace(/\S*$/, item.name);
551
+ input.focus();
552
+ if (item.variant === true) {
553
+ suggest();
554
+ return;
555
+ }
556
+ known.set(item.name, item);
557
+ add();
558
+ };
559
+ input.addEventListener("input", () => void suggest());
560
+ list.addEventListener("mousedown", (e) => e.preventDefault());
561
+ input.addEventListener("blur", hide);
562
+ input.addEventListener("keydown", (e) => {
563
+ if (options.length > 0) {
564
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
565
+ e.preventDefault();
566
+ active = (active + (e.key === "ArrowDown" ? 1 : options.length - 1)) % options.length;
567
+ drawOptions();
568
+ return;
569
+ }
570
+ if (e.key === "Enter" || e.key === "Tab") {
571
+ e.preventDefault();
572
+ take(options[active]);
573
+ return;
574
+ }
575
+ if (e.key === "Escape") {
576
+ e.preventDefault();
577
+ hide();
578
+ return;
579
+ }
580
+ }
581
+ if (e.key !== "Enter") return;
582
+ e.preventDefault();
583
+ if (!add()) commit().catch(() => {});
584
+ });
585
+ save.addEventListener("click", () => void commit().catch(() => {}));
586
+ drawStates();
587
+ drawExtras();
588
+ render();
589
+ input.focus();
590
+ return () => {
591
+ gone = true;
592
+ sheet?.remove();
593
+ cancelAnimationFrame(following);
594
+ root.removeEventListener("pointerdown", onPress, true);
595
+ editor.remove();
596
+ list.remove();
597
+ if (!previewed) return;
598
+ context.elements.forEach((el, i) => {
599
+ const was = committed ? classesOf(i, (state) => state.saved, false).join(" ") : originals[i];
600
+ if (was === null || was === void 0 || was === "" && originals[i] === null) el.removeAttribute("class");
601
+ else el.setAttribute("class", was);
602
+ });
603
+ };
604
+ }
605
+ });
606
+ /** What a field for a value of one's own shows as the kind of thing to type: the class's value now. */
607
+ function hinted(info) {
608
+ const value = info?.value;
609
+ return value === void 0 || value.length > 18 || value.includes("var(") ? "" : `: ${value}`;
610
+ }
611
+ export { client_default as default };
612
+
613
+ //# sourceMappingURL=client.js.map