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.
- package/LICENSE +21 -0
- package/README.md +167 -0
- package/dist/annotations/client.d.ts +4 -0
- package/dist/annotations/client.d.ts.map +1 -0
- package/dist/annotations/client.js +497 -0
- package/dist/annotations/client.js.map +1 -0
- package/dist/annotations/index.d.ts +110 -0
- package/dist/annotations/index.d.ts.map +1 -0
- package/dist/annotations/index.js +22 -0
- package/dist/annotations/index.js.map +1 -0
- package/dist/astro.d.ts +29 -0
- package/dist/astro.d.ts.map +1 -0
- package/dist/astro.js +24 -0
- package/dist/astro.js.map +1 -0
- package/dist/bun.d.ts +12 -0
- package/dist/bun.d.ts.map +1 -0
- package/dist/bun.js +67 -0
- package/dist/bun.js.map +1 -0
- package/dist/client/index.d.ts +95 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +1333 -0
- package/dist/client/index.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/loader.d.ts +15 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +17 -0
- package/dist/loader.js.map +1 -0
- package/dist/next.d.ts +17 -0
- package/dist/next.d.ts.map +1 -0
- package/dist/next.js +150 -0
- package/dist/next.js.map +1 -0
- package/dist/recommended/index.d.ts +25 -0
- package/dist/recommended/index.d.ts.map +1 -0
- package/dist/recommended/index.js +19 -0
- package/dist/recommended/index.js.map +1 -0
- package/dist/recordings/client.d.ts +4 -0
- package/dist/recordings/client.d.ts.map +1 -0
- package/dist/recordings/client.js +376 -0
- package/dist/recordings/client.js.map +1 -0
- package/dist/recordings/index.d.ts +2 -0
- package/dist/recordings/index.js +3 -0
- package/dist/screenshots/client.d.ts +23 -0
- package/dist/screenshots/client.d.ts.map +1 -0
- package/dist/screenshots/client.js +76 -0
- package/dist/screenshots/client.js.map +1 -0
- package/dist/screenshots/dom.d.ts +4 -0
- package/dist/screenshots/dom.d.ts.map +1 -0
- package/dist/screenshots/dom.js +92 -0
- package/dist/screenshots/dom.js.map +1 -0
- package/dist/screenshots/index.d.ts +2 -0
- package/dist/screenshots/index.js +98 -0
- package/dist/screenshots/index.js.map +1 -0
- package/dist/screenshots/rrweb.d.ts +9 -0
- package/dist/screenshots/rrweb.d.ts.map +1 -0
- package/dist/screenshots/rrweb.js +60 -0
- package/dist/screenshots/rrweb.js.map +1 -0
- package/dist/shared/endpoints.js +354 -0
- package/dist/shared/endpoints.js.map +1 -0
- package/dist/shared/index.d.ts +226 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index2.d.ts +98 -0
- package/dist/shared/index2.d.ts.map +1 -0
- package/dist/shared/index3.d.ts +86 -0
- package/dist/shared/index3.d.ts.map +1 -0
- package/dist/shared/index4.d.ts +184 -0
- package/dist/shared/index4.d.ts.map +1 -0
- package/dist/shared/index5.d.ts +70 -0
- package/dist/shared/index5.d.ts.map +1 -0
- package/dist/shared/integration.d.ts +20 -0
- package/dist/shared/integration.d.ts.map +1 -0
- package/dist/shared/integration.js +279 -0
- package/dist/shared/integration.js.map +1 -0
- package/dist/shared/kept.js +23 -0
- package/dist/shared/kept.js.map +1 -0
- package/dist/shared/marks.js +14 -0
- package/dist/shared/marks.js.map +1 -0
- package/dist/shared/playwright.js +105 -0
- package/dist/shared/playwright.js.map +1 -0
- package/dist/shared/recordings.js +246 -0
- package/dist/shared/recordings.js.map +1 -0
- package/dist/shared/shortcut.js +63 -0
- package/dist/shared/shortcut.js.map +1 -0
- package/dist/shared/tasks.js +521 -0
- package/dist/shared/tasks.js.map +1 -0
- package/dist/shared/waveform.js +93 -0
- package/dist/shared/waveform.js.map +1 -0
- package/dist/tailwind/client.d.ts +4 -0
- package/dist/tailwind/client.d.ts.map +1 -0
- package/dist/tailwind/client.js +613 -0
- package/dist/tailwind/client.js.map +1 -0
- package/dist/tailwind/index.d.ts +2 -0
- package/dist/tailwind/index.js +557 -0
- package/dist/tailwind/index.js.map +1 -0
- package/dist/tasks/client.d.ts +6 -0
- package/dist/tasks/client.d.ts.map +1 -0
- package/dist/tasks/client.js +642 -0
- package/dist/tasks/client.js.map +1 -0
- package/dist/tasks/index.d.ts +2 -0
- package/dist/tasks/index.js +1 -0
- package/dist/vite.d.ts +16 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +61 -0
- package/dist/vite.js.map +1 -0
- package/dist/voice/client.d.ts +4 -0
- package/dist/voice/client.d.ts.map +1 -0
- package/dist/voice/client.js +66 -0
- package/dist/voice/client.js.map +1 -0
- package/dist/voice/index.d.ts +47 -0
- package/dist/voice/index.d.ts.map +1 -0
- package/dist/voice/index.js +74 -0
- package/dist/voice/index.js.map +1 -0
- package/dist/webpack.d.ts +50 -0
- package/dist/webpack.d.ts.map +1 -0
- package/dist/webpack.js +78 -0
- package/dist/webpack.js.map +1 -0
- package/package.json +307 -7
- package/skills/deictic/SKILL.md +47 -0
- package/skills/deictic/references/install.md +96 -0
- package/skills/deictic/references/recordings.md +83 -0
- package/skills/deictic/references/tasks.md +79 -0
- package/skills/deictic/references/watch.md +43 -0
- package/skills/deictic/scripts/frame.mjs +62 -0
- package/skills/deictic/scripts/lib.mjs +211 -0
- package/skills/deictic/scripts/recording.mjs +186 -0
- package/skills/deictic/scripts/task.mjs +84 -0
- package/skills/deictic/scripts/transcribe.mjs +93 -0
- package/skills/deictic/scripts/voice.mjs +50 -0
- package/skills/deictic/scripts/watch.mjs +51 -0
- package/src/astro.ts +34 -0
- package/src/bun.ts +79 -0
- package/src/client/index.ts +846 -0
- package/src/client/lightbox.ts +256 -0
- package/src/client/style.ts +243 -0
- package/src/client/tooltip.ts +78 -0
- package/src/client/waveform.ts +98 -0
- package/src/index.ts +247 -0
- package/src/loader.ts +28 -0
- package/src/next.ts +133 -0
- package/src/plugins/annotations/client.ts +301 -0
- package/src/plugins/annotations/draw.ts +169 -0
- package/src/plugins/annotations/index.ts +105 -0
- package/src/plugins/annotations/svg.ts +61 -0
- package/src/plugins/recommended/index.ts +35 -0
- package/src/plugins/recordings/client.ts +316 -0
- package/src/plugins/recordings/index.ts +175 -0
- package/src/plugins/recordings/marks.ts +11 -0
- package/src/plugins/recordings/ours.ts +70 -0
- package/src/plugins/recordings/replay.ts +165 -0
- package/src/plugins/screenshots/client.ts +64 -0
- package/src/plugins/screenshots/dom.ts +79 -0
- package/src/plugins/screenshots/index.ts +194 -0
- package/src/plugins/screenshots/playwright.ts +119 -0
- package/src/plugins/screenshots/rrweb.ts +45 -0
- package/src/plugins/tailwind/catalog.ts +396 -0
- package/src/plugins/tailwind/client.ts +669 -0
- package/src/plugins/tailwind/index.ts +267 -0
- package/src/plugins/tasks/client.ts +622 -0
- package/src/plugins/tasks/index.ts +557 -0
- package/src/plugins/tasks/local.ts +170 -0
- package/src/plugins/voice/client.ts +58 -0
- package/src/plugins/voice/index.ts +114 -0
- package/src/shortcut.ts +83 -0
- package/src/tools/astro.ts +81 -0
- package/src/tools/editor.ts +22 -0
- package/src/tools/endpoints.ts +163 -0
- package/src/tools/history.ts +203 -0
- package/src/tools/integration.ts +108 -0
- package/src/tools/kept.ts +21 -0
- package/src/tools/locate.ts +94 -0
- package/src/tools/plugins.ts +41 -0
- package/src/tools/source.ts +72 -0
- package/src/vite.ts +81 -0
- package/src/webpack.ts +107 -0
- package/index.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","names":[],"sources":["../../src/plugins/tailwind/client.ts"],"sourcesContent":["/**\n * Tailwind's panel: the element's classes as chips, a field to add more, and Save. Every change\n * previews on the page at once, on every element from the same place in the source, keeping the\n * classes the source adds at runtime; closing without saving puts the page back.\n *\n * Where a class helper adds more on a condition (`cn('…', active && '…')`), each condition whose classes are a\n * string in the file is a state to pick, beside the element's own list: picked, its classes are the chips, and\n * they show on the clicked element whether or not the condition holds there. A dot marks the ones that do hold,\n * read from the element's classes, which is all the page says of a condition.\n *\n * What the project's Tailwind knows comes from the server half's routes. The field completes the word being\n * typed. A chip of a class Tailwind knows shows what it sets (a colour's swatch, a size's value) and opens the\n * classes of its kind to switch between, with a field for a value of one's own (`text-[13px]`). A class no file\n * 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\n * page's that goes as the panel does. The completions and a chip's kind open in boxes of their own beside the popup\n * (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.\n */\nimport { defineClientPlugin } from '#src/index.ts';\n\nimport type { Alternatives, ClassInfo, Model, Op } from './index.ts';\n\nconst STYLE = `\n.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }\n.chip { display: inline-flex; align-items: stretch; border: 1px solid var(--deictic-line); border-radius: 4px; font: 12px/20px ui-monospace, monospace; }\n.chip.open { border-color: var(--deictic-accent); }\n.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; }\n.chip button.name:hover { background: rgb(255 255 255 / 0.08); }\n.chip .x { border: 0; padding: 0 5px; color: var(--deictic-muted); }\n.chip .x:hover { color: var(--deictic-problem); }\n/* A colour over a checker, so one that's part clear shows it. */\n.swatch {\n flex: none;\n width: 10px;\n height: 10px;\n border-radius: 2px;\n box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.25);\n background: linear-gradient(var(--c), var(--c)), repeating-conic-gradient(#71717a 0 25%, #d4d4d8 0 50%) 0 0 / 6px 6px;\n}\n.hint { color: var(--deictic-muted); }\n/* Beside the popup, not in it: in its flow they'd resize it under the pointer with every word and click. */\n.editor, .suggest {\n position: fixed;\n left: 0;\n top: 0;\n z-index: 2147483647;\n box-sizing: border-box;\n border: 1px solid var(--deictic-line);\n border-radius: 6px;\n font: 13px/1.4 system-ui, sans-serif;\n color: var(--deictic-fg);\n background: var(--deictic-bg);\n box-shadow: 0 8px 24px rgb(0 0 0 / 0.45);\n}\n.editor[hidden], .suggest[hidden] { display: none; }\n.editor .top { display: flex; align-items: center; gap: 4px; padding: 2px 2px 2px 8px; font: 12px ui-monospace, monospace; color: var(--deictic-muted); }\n.editor .top button:first-of-type { margin-left: auto; }\n.editor .top .more { padding: 0 6px; font: 12px/18px system-ui, sans-serif; }\n.editor .top .more[aria-expanded='true'] { border-color: var(--deictic-accent); color: var(--deictic-fg); }\n.custom[hidden] { display: none; }\n.alts { position: relative; display: flex; flex-wrap: wrap; gap: 4px; max-height: 190px; padding: 2px 8px 8px; overflow: auto; }\n.alts button { display: inline-flex; align-items: center; gap: 5px; padding: 0 6px; font: 12px/20px ui-monospace, monospace; }\n.alts button[aria-pressed='true'] { border-color: var(--deictic-accent); color: var(--deictic-accent); }\n.alts .family { display: flex; gap: 2px; flex-basis: 100%; }\n.alts .family button { padding: 0; border: 0; border-radius: 3px; }\n.alts .family .swatch { width: 18px; height: 18px; border-radius: 3px; }\n.alts .family button[aria-pressed='true'] { outline: 2px solid var(--deictic-fg); outline-offset: 1px; }\n.custom { display: flex; gap: 6px; align-items: center; padding: 6px 8px; border-top: 1px solid var(--deictic-line); }\n.custom input[type='color'] { flex: none; width: 28px; height: 24px; padding: 1px; cursor: pointer; }\n.custom input[aria-invalid='true'] { border-color: var(--deictic-problem); }\n.suggest { max-height: 168px; overflow: auto; }\n.option { display: flex; align-items: center; gap: 6px; padding: 1px 6px; font: 12px/20px ui-monospace, monospace; cursor: pointer; }\n.option[aria-selected='true'] { background: rgb(255 255 255 / 0.1); }\n.option .hint { margin-left: auto; }\n.row { display: flex; gap: 6px; margin-top: 8px; justify-content: flex-end; align-items: center; }\n.states { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }\n.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; }\n.state[aria-pressed='true'] { border-color: var(--deictic-accent); color: var(--deictic-fg); }\n.state .dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--deictic-accent); }\n.note { margin: -2px 0 8px; font-size: 12px; color: var(--deictic-muted); }\n.note:empty { display: none; }\n.note code { color: var(--deictic-fg); }\n.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); }\n.extra { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }\n.extra .when { flex-basis: 100%; }\n.extra code { color: var(--deictic-fg); }\n/* The code's own classes: shown, not edited here, and faint while their condition doesn't hold. */\n.chip.fixed { border-style: dashed; }\n.chip.fixed .name { padding-right: 6px; }\n.chip.fixed.off { opacity: 0.45; }\n`;\n\nconst split = (list: string) => list.split(/\\s+/).filter(Boolean);\n\n/** A list of classes to edit: the element's own, or those one of the helper's arguments adds (`at`, its place). */\ninterface State {\n at?: number;\n label: string;\n saved: string[];\n draft: string[];\n}\n/** The family a shade is of: `bg-red` for `bg-red-500`. */\nconst familyOf = (name: string) => /^(.*)-\\d+(\\/[^/]*)?!?$/.exec(name)?.[1];\n\nfunction make<Tag extends keyof HTMLElementTagNameMap>(tag: Tag, className: string, text?: string): HTMLElementTagNameMap[Tag] {\n const el = document.createElement(tag);\n el.className = className;\n if (text !== undefined) el.textContent = text;\n if (el instanceof HTMLButtonElement) el.type = 'button';\n return el;\n}\n\nfunction swatch(color: string): HTMLElement {\n const el = make('span', 'swatch');\n // A custom property takes any text, and one that isn't a colour draws nothing.\n el.style.setProperty('--c', color);\n return el;\n}\n\n/** A class as it reads everywhere: its colour, its name, and what it sets where the name doesn't say. */\nfunction face(into: HTMLElement, info: ClassInfo) {\n if (info.color !== undefined) into.append(swatch(info.color));\n into.append(info.name);\n const { value } = info;\n if (info.color !== undefined || value === undefined || value.length > 18 || value.includes('var(') || info.name.endsWith(value)) return;\n into.append(make('span', 'hint', value));\n}\n\nexport default defineClientPlugin<Model, Op>({\n name: 'tailwind',\n label: 'Tailwind',\n mount(panel, context) {\n const style = document.createElement('style');\n style.textContent = STYLE;\n panel.append(style);\n\n const { model } = context;\n if (!model.editable) {\n const note = document.createElement('p');\n note.textContent = 'These classes are built at runtime, so there is no one list to edit:';\n const code = document.createElement('code');\n code.textContent = model.source;\n panel.append(note, code);\n return () => {};\n }\n\n // What the page rendered, to put back over a preview that wasn't saved.\n const originals = context.elements.map((el) => el.getAttribute('class'));\n const others = model.others ?? [];\n // The lists to edit: the element's own, then each of the helper's arguments whose classes are a string in the\n // file, by its place among them. One is shown at a time, each keeps its draft, and Save writes every one changed.\n const states: State[] = [\n { label: 'Base', saved: split(model.classes), draft: split(model.classes) },\n ...others.flatMap((other, at): State[] =>\n other.editable === true\n ? [{ at, label: other.when ?? other.source, saved: split(other.classes ?? ''), draft: split(other.classes ?? '') }]\n : [],\n ),\n ];\n const own = states[0]!;\n let current = own;\n // What the page has beyond the source's list: classes the helper's other arguments added, per element. Read\n // only for a helper, as the page may not have caught up with the source yet (just after an undo).\n const runtime = context.elements.map((el) =>\n model.others === undefined ? [] : split(el.getAttribute('class') ?? '').filter((c) => !own.saved.includes(c)),\n );\n // Which arguments' classes each element has now: all there is to see of a condition from the page. Most of\n // them will do, as a helper that merges (`twMerge`) drops the ones a later class overrides.\n const on = others.map((other) => {\n const adds = split(other.classes ?? '');\n return runtime.map((has) => adds.length > 0 && adds.filter((c) => has.includes(c)).length * 2 >= adds.length);\n });\n // And what no argument read here accounts for: left as it is through every preview.\n const told = new Set(others.flatMap((other) => split(other.classes ?? '')));\n const untold = runtime.map((has) => has.filter((c) => !told.has(c)));\n const clicked = context.elements.indexOf(context.element);\n /**\n * An element's classes with each list as `pick` has it. `forced` adds the shown state's to the clicked element\n * though its condition doesn't hold there, so there's something to see while it's edited.\n */\n const classesOf = (i: number, pick: (state: State) => string[], forced: boolean) => [\n ...pick(own),\n ...others.flatMap((other, at) => {\n const state = states.find((s) => s.at === at);\n if (on[at]![i] !== true && !(forced && state === current && i === clicked)) return [];\n return state === undefined ? split(other.classes ?? '') : pick(state);\n }),\n ...untold[i]!,\n ];\n const unsaved = () => states.some((state) => state.draft.join(' ') !== state.saved.join(' '));\n let previewed = false;\n let committed = false;\n let gone = false;\n\n // The server's answer, or nothing where it has none: the panel works without, only plainer.\n const ask = async <T>(route: string, init?: RequestInit): Promise<T | undefined> => {\n try {\n const res = await context.request(route, init);\n return res.ok ? ((await res.json()) as T) : undefined;\n } catch {\n return undefined;\n }\n };\n const naming = (classes: string[]): RequestInit => ({\n method: 'POST',\n headers: { 'content-type': 'application/json' },\n body: JSON.stringify({ classes }),\n });\n /** What Tailwind says of each class seen so far. */\n const known = new Map<string, ClassInfo>();\n /** Set once the server says it has no Tailwind to ask. */\n let plain = false;\n\n const chips = make('div', 'chips');\n const editor = make('div', 'editor');\n editor.hidden = true;\n const input = document.createElement('input');\n input.placeholder = 'Add classes, Enter to add';\n input.spellcheck = false;\n input.autocomplete = 'off';\n const list = make('div', 'suggest');\n list.setAttribute('role', 'listbox');\n list.hidden = true;\n const save = make('button', 'primary', 'Save');\n const row = make('div', 'row');\n row.append(save);\n const picks = make('div', 'states');\n const note = make('div', 'note');\n if (states.length > 1) panel.append(picks, note);\n panel.append(chips, input, row);\n // The root the panel is in, where its styles are: the overlay's, or its own where the popup is pinned in a page.\n const around = panel.getRootNode();\n const root = around instanceof ShadowRoot ? around : context.root;\n root.append(editor, list);\n\n /** The chip whose kind is open in the editor, by its place in the current.draft. */\n let editing: number | undefined;\n // Each box under what it's about (over it where there's no room under), as wide as the field, and kept there\n // every frame: the popup follows its element and can be dragged, and a chip is drawn again with every change.\n const floats: [box: HTMLElement, by: () => Element | undefined][] = [\n [editor, () => (editing === undefined ? undefined : chips.children[editing])],\n [list, () => input],\n ];\n const place = () => {\n for (const [box, by] of floats) {\n if (box.hidden !== false) continue;\n const anchor = by();\n if (anchor === undefined) continue;\n const at = anchor.getBoundingClientRect();\n const span = input.getBoundingClientRect();\n const height = box.offsetHeight;\n const below = window.innerHeight - at.bottom;\n const top = height + 12 > below && at.top > below ? at.top - height - 4 : at.bottom + 4;\n const place = `${Math.round(span.left)}px ${Math.round(top)}px`;\n if (box.style.translate !== place) box.style.translate = place;\n const width = `${Math.round(span.width)}px`;\n if (box.style.width !== width) box.style.width = width;\n }\n };\n let following = requestAnimationFrame(function follow() {\n following = requestAnimationFrame(follow);\n place();\n });\n const extras = make('div', 'extras');\n // The arguments with no list to edit here: a bare key, a call, a name from another file.\n const fixed = others.filter((other) => other.editable !== true);\n if (fixed.length > 0) panel.append(extras);\n // What the clicked element has of them now, as the page rendered it.\n const lit = new Set(runtime[clicked] ?? []);\n /** Those arguments: what each adds as chips under what it waits on, or its code where nothing says. */\n const drawExtras = () => {\n extras.replaceChildren(\n ...fixed.map((extra) => {\n const row = make('div', 'extra');\n const when = make('div', 'when');\n if (extra.when === undefined) when.append('Always');\n else when.append('When ', make('code', '', extra.when));\n row.append(when);\n // Nothing says what it adds (a call, a prop): its code is all there is to show.\n if (extra.classes === undefined) {\n when.append(', whatever ', make('code', '', extra.source), ' adds');\n return row;\n }\n for (const c of split(extra.classes)) {\n const on = lit.has(c);\n const chip = make('span', on ? 'chip fixed' : 'chip fixed off');\n chip.title = on ? 'On the element now. Change it in the code' : 'Not on the element now. Change it in the code';\n const name = make('span', 'name');\n face(name, known.get(c) ?? { name: c, known: false });\n chip.append(name);\n row.append(chip);\n }\n return row;\n }),\n );\n };\n\n // The classes the page's build had as the panel opened: any other may have no CSS there yet.\n const built = new Set([...states.flatMap((state) => state.saved), ...told]);\n let sheet: HTMLStyleElement | undefined;\n let styled = '';\n const lend = async () => {\n const fresh = [...new Set(states.flatMap((state) => state.draft))].filter((c) => !built.has(c));\n const key = fresh.join(' ');\n if (plain || key === styled) return;\n styled = key;\n const answer = fresh.length === 0 ? { css: '' } : await ask<{ css: string }>('css', naming(fresh));\n if (answer === undefined || key !== styled || gone) return;\n sheet ??= document.head.appendChild(document.createElement('style'));\n sheet.textContent = answer.css;\n };\n\n const preview = () => {\n save.disabled = !unsaved();\n context.unsaved(unsaved() ? save : undefined);\n if (!unsaved() && !previewed && current === own) return;\n context.elements.forEach((el, i) => el.setAttribute('class', classesOf(i, (state) => state.draft, true).join(' ')));\n previewed = true;\n void lend();\n };\n\n /** The lists as buttons: the element's own, and each condition, dotted where it holds on the element now. */\n const drawStates = () => {\n picks.replaceChildren(\n ...states.map((state) => {\n const pick = make('button', 'state');\n const holds = state.at !== undefined && on[state.at]![clicked] === true;\n if (holds) pick.append(make('span', 'dot'));\n pick.append(state.at === undefined || others[state.at]!.when !== undefined ? state.label : `always: ${state.label}`);\n pick.setAttribute('aria-pressed', String(state === current));\n if (state.at !== undefined) pick.title = holds ? 'On the element now' : 'Not on the element now: shown on it while you edit';\n pick.addEventListener('click', () => {\n shut(false);\n hide();\n current = state;\n drawStates();\n render();\n input.focus();\n });\n return pick;\n }),\n );\n const shared = current.at === undefined ? undefined : others[current.at]!.shared;\n note.replaceChildren(...(shared === undefined ? [] : ['From ', make('code', '', shared), ': everything that uses it changes too.']));\n };\n\n let opened = 0;\n const drawChips = () => {\n chips.replaceChildren(\n ...current.draft.map((c, i) => {\n const chip = make('span', i === editing ? 'chip open' : 'chip');\n const info = known.get(c);\n const name = make(info?.known === true ? 'button' : 'span', 'name');\n face(name, info ?? { name: c, known: false });\n if (name instanceof HTMLButtonElement) {\n name.title = `Change ${c}`;\n name.addEventListener('click', () => void (editing === i ? shut() : edit(i)));\n }\n const remove = make('button', 'x', '×');\n remove.title = `Remove ${c}`;\n remove.addEventListener('click', () => {\n shut();\n current.draft = current.draft.toSpliced(i, 1);\n render();\n });\n chip.append(name, remove);\n return chip;\n }),\n );\n };\n const describe = async () => {\n const shown = [...states.flatMap((state) => state.draft), ...told];\n const missing = [...new Set(shown)].filter((c) => !known.has(c));\n if (plain || missing.length === 0) return;\n const answer = await ask<{ available: boolean; items: ClassInfo[] }>('info', naming(missing));\n if (answer === undefined) return;\n plain = !answer.available;\n for (const item of answer.items) known.set(item.name, item);\n if (answer.items.length === 0) return;\n drawChips();\n drawExtras();\n };\n const render = () => {\n drawChips();\n preview();\n void describe();\n };\n\n const shut = (focus = true) => {\n opened++;\n if (editing === undefined) return;\n editing = undefined;\n editor.hidden = true;\n editor.removeAttribute('data-deictic-modal');\n editor.replaceChildren();\n drawChips();\n if (focus) input.focus();\n };\n // A press anywhere else in the overlay closes the editor, as it would a menu. The chips open and close it themselves.\n const onPress = (e: Event) => {\n const path = e.composedPath();\n if (!path.includes(editor) && !path.includes(chips)) shut(false);\n };\n root.addEventListener('pointerdown', onPress, true);\n /** Puts `name` where the open chip's class is. The same class twice would be one, so that's left. */\n const swap = (name: string, info: ClassInfo) => {\n if (editing === undefined || current.draft.includes(name)) return;\n known.set(name, info);\n current.draft = current.draft.with(editing, name);\n render();\n };\n const edit = async (at: number) => {\n const turn = ++opened;\n const was = current.draft[at]!;\n const found = await ask<Alternatives | null>(`alternatives?${new URLSearchParams({ class: was })}`);\n if (turn !== opened || current.draft[at] !== was || found === undefined || found === null) return;\n editing = at;\n drawChips();\n\n const top = make('div', 'top', found.label);\n const close = make('button', 'icon', '×');\n close.title = 'Close';\n close.addEventListener('click', () => shut());\n top.append(close);\n\n const alts = make('div', 'alts');\n const buttons = new Map<string, HTMLButtonElement>();\n const press = () => {\n for (const [name, button] of buttons) button.setAttribute('aria-pressed', String(name === current.draft[at]));\n };\n const choice = (item: ClassInfo, bare: boolean) => {\n const button = make('button', '');\n if (bare && item.color !== undefined) {\n button.append(swatch(item.color));\n button.title = item.name;\n } else {\n face(button, item);\n }\n button.addEventListener('click', () => {\n swap(item.name, item);\n press();\n });\n buttons.set(item.name, button);\n return button;\n };\n // A colour's shades in a row, a family under a family; whatever has no shades (`black`, `inherit`) comes first, named.\n const families = new Map<string, HTMLElement>();\n const loose: HTMLElement[] = [];\n for (const item of found.items) {\n const family = found.colors && item.color !== undefined ? familyOf(item.name) : undefined;\n if (family === undefined) {\n loose.push(choice(item, false));\n continue;\n }\n const shades = families.get(family) ?? make('div', 'family');\n families.set(family, shades);\n shades.append(choice(item, true));\n }\n alts.append(...loose, ...families.values());\n press();\n\n editor.replaceChildren(top, alts);\n const { custom } = found;\n if (custom !== undefined) {\n const form = make('form', 'custom');\n const field = document.createElement('input');\n field.placeholder = found.colors ? 'A colour of your own: #12b358' : `A value of your own${hinted(known.get(was))}`;\n field.spellcheck = false;\n field.value = custom.value?.replaceAll('_', ' ') ?? '';\n const named = (value: string) => `${custom.before}${value.trim().replace(/\\s+/g, '_')}${custom.after}`;\n if (found.colors) {\n const picker = document.createElement('input');\n picker.type = 'color';\n picker.title = 'Pick a colour';\n if (/^#[\\da-f]{6}$/i.test(field.value)) picker.value = field.value;\n // Each colour tried shows on the page as it's picked: a hex is a colour to Tailwind, with nothing to check.\n picker.addEventListener('input', () => {\n field.value = picker.value;\n field.removeAttribute('aria-invalid');\n swap(named(picker.value), { name: named(picker.value), known: true, color: picker.value, value: picker.value });\n press();\n });\n form.append(picker);\n }\n const set = make('button', '', 'Set');\n set.type = 'submit';\n field.addEventListener('input', () => field.removeAttribute('aria-invalid'));\n form.addEventListener('submit', (e) => {\n e.preventDefault();\n if (field.value.trim() === '') return;\n const name = named(field.value);\n void ask<{ items: ClassInfo[] }>('info', naming([name])).then((answer) => {\n const info = answer?.items[0];\n if (turn !== opened || editing !== at) return;\n if (info?.known !== true) {\n field.setAttribute('aria-invalid', 'true');\n field.title = `Tailwind makes nothing of ${name}`;\n return;\n }\n swap(name, info);\n // Its kind may be another now (`text-[red]` is a colour), and the list has it to show as chosen.\n void edit(at);\n });\n });\n form.append(field, set);\n // Shown on asking, or where the class already has a value of its own to show.\n let asked = custom.value !== undefined;\n const more = make('button', 'more', 'Custom');\n more.title = 'Set a value of your own';\n const show = () => {\n form.hidden = !asked;\n more.setAttribute('aria-expanded', String(asked));\n };\n show();\n more.addEventListener('click', () => {\n asked = !asked;\n show();\n if (asked) field.focus();\n });\n close.before(more);\n editor.append(form);\n }\n // Esc closes the editor, not the popup, and reaches it only from inside: so the focus goes in.\n editor.setAttribute('data-deictic-modal', '');\n editor.hidden = false;\n // Placed as it shows, not a frame later, when it would flash where it was.\n place();\n const chosen = buttons.get(current.draft[at]);\n if (chosen !== undefined) alts.scrollTop = chosen.offsetTop - alts.clientHeight / 2;\n (chosen ?? editor.querySelector('button'))?.focus();\n };\n editor.addEventListener('keydown', (e) => {\n if (e.key !== 'Escape') return;\n e.preventDefault();\n shut();\n });\n\n const commit = async () => {\n // One change each, in the history too. One the server refuses leaves the rest as they are, still to save.\n for (const state of states) {\n if (state.draft.join(' ') === state.saved.join(' ')) continue;\n const next = await context.apply({ classes: state.draft.join(' '), ...(state.at === undefined ? {} : { at: state.at }) });\n if (next.editable) state.saved = split(state.at === undefined ? next.classes : (next.others?.[state.at]?.classes ?? ''));\n state.draft = [...state.saved];\n committed = true;\n }\n previewed = false;\n shut();\n render();\n };\n\n /** What completes the word being typed, and the one Enter takes. */\n let options: ClassInfo[] = [];\n let active = 0;\n let typed = 0;\n const drawOptions = () => {\n list.hidden = options.length === 0;\n // While it's open, Esc closes it and not the popup.\n list.toggleAttribute('data-deictic-modal', options.length > 0);\n list.replaceChildren(\n ...options.map((item, i) => {\n const option = make('div', 'option');\n option.setAttribute('role', 'option');\n option.setAttribute('aria-selected', String(i === active));\n face(option, item);\n option.addEventListener('click', () => take(item));\n return option;\n }),\n );\n place();\n const shown = list.children[active];\n if (!(shown instanceof HTMLElement)) return;\n if (shown.offsetTop < list.scrollTop) list.scrollTop = shown.offsetTop;\n else if (shown.offsetTop + shown.offsetHeight > list.scrollTop + list.clientHeight)\n list.scrollTop = shown.offsetTop + shown.offsetHeight - list.clientHeight;\n };\n const hide = () => {\n typed++;\n options = [];\n drawOptions();\n };\n const suggest = async () => {\n const turn = ++typed;\n const word = /\\S*$/.exec(input.value)![0];\n if (plain || word === '') return hide();\n const answer = await ask<{ items: ClassInfo[] }>(`complete?${new URLSearchParams({ q: word })}`);\n if (turn !== typed) return;\n options = (answer?.items ?? []).filter((item) => !current.draft.includes(item.name));\n active = 0;\n drawOptions();\n };\n /** Adds what the field holds. False when it held nothing new. */\n const add = () => {\n const added = split(input.value).filter((c) => !current.draft.includes(c));\n input.value = '';\n hide();\n if (added.length === 0) return false;\n current.draft = [...current.draft, ...added];\n render();\n return true;\n };\n const take = (item: ClassInfo) => {\n input.value = input.value.replace(/\\S*$/, item.name);\n input.focus();\n // A variant is the start of a class: the rest is still to type.\n if (item.variant === true) {\n void suggest();\n return;\n }\n known.set(item.name, item);\n add();\n };\n\n input.addEventListener('input', () => void suggest());\n // A press in the list mustn't take the focus from the field, which would close the list under it.\n list.addEventListener('mousedown', (e) => e.preventDefault());\n input.addEventListener('blur', hide);\n input.addEventListener('keydown', (e) => {\n if (options.length > 0) {\n if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {\n e.preventDefault();\n active = (active + (e.key === 'ArrowDown' ? 1 : options.length - 1)) % options.length;\n drawOptions();\n return;\n }\n if (e.key === 'Enter' || e.key === 'Tab') {\n e.preventDefault();\n take(options[active]!);\n return;\n }\n if (e.key === 'Escape') {\n e.preventDefault();\n hide();\n return;\n }\n }\n if (e.key !== 'Enter') return;\n e.preventDefault();\n if (!add()) void commit().catch(() => {});\n });\n save.addEventListener('click', () => void commit().catch(() => {}));\n drawStates();\n drawExtras();\n render();\n input.focus();\n\n // A saved list reaches the page through the bundler's update, which this mustn't race.\n return () => {\n gone = true;\n sheet?.remove();\n cancelAnimationFrame(following);\n root.removeEventListener('pointerdown', onPress, true);\n editor.remove();\n list.remove();\n if (!previewed) return;\n context.elements.forEach((el, i) => {\n // As the page rendered it, or, once something's saved, as the source now has it: never the classes from before.\n const was = committed ? classesOf(i, (state) => state.saved, false).join(' ') : originals[i];\n if (was === null || was === undefined || (was === '' && originals[i] === null)) el.removeAttribute('class');\n else el.setAttribute('class', was);\n });\n };\n },\n});\n\n/** What a field for a value of one's own shows as the kind of thing to type: the class's value now. */\nfunction hinted(info: ClassInfo | undefined): string {\n const value = info?.value;\n return value === undefined || value.length > 18 || value.includes('var(') ? '' : `: ${value}`;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AAC,CAAC,KAAK,GAAG,IAAI,UAAU;IAC1F,IAAI,QAAQ,QAAQ,QAAQ,KAAA,KAAc,QAAQ,MAAM,UAAU,OAAO,MAAO,GAAG,gBAAgB,OAAO;SACrG,GAAG,aAAa,SAAS,GAAG;GACnC,CAAC;EACH;CACF;AACF,CAAC;;AAGD,SAAS,OAAO,MAAqC;CACnD,MAAM,QAAQ,MAAM;CACpB,OAAO,UAAU,KAAA,KAAa,MAAM,SAAS,MAAM,MAAM,SAAS,MAAM,IAAI,KAAK,KAAK;AACxF"}
|
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
import { Refusal, definePlugin } from "../index.js";
|
|
2
|
+
import { readFileSync, statSync } from "node:fs";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { dirname, join, resolve } from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
// src/plugins/tailwind/catalog.ts
|
|
7
|
+
/**
|
|
8
|
+
* What the project's Tailwind knows, for the panel: every class it can make (to complete what's typed), what
|
|
9
|
+
* each one sets (a colour to show, a value to hint), the classes of the same kind (to switch between), and a
|
|
10
|
+
* class's CSS (to preview one no file uses yet).
|
|
11
|
+
*
|
|
12
|
+
* All of it comes from Tailwind's own design system, loaded from the project (v4, through `@tailwindcss/node`,
|
|
13
|
+
* which every v4 integration brings), so the theme is the project's. Two classes are of a kind when they set the
|
|
14
|
+
* same properties: `text-sm` and `text-lg`, `flex` and `grid`, but not `text-sm` and `text-red-500`.
|
|
15
|
+
*/
|
|
16
|
+
/** Packages that depend on `@tailwindcss/node`, where the project doesn't itself. */
|
|
17
|
+
const VIA = [
|
|
18
|
+
"@tailwindcss/vite",
|
|
19
|
+
"@tailwindcss/postcss",
|
|
20
|
+
"@tailwindcss/cli",
|
|
21
|
+
"@tailwindcss/webpack"
|
|
22
|
+
];
|
|
23
|
+
const MOST = 400;
|
|
24
|
+
const natural = new Intl.Collator("en", { numeric: true }).compare;
|
|
25
|
+
/**
|
|
26
|
+
* The catalog of the project at `root`, from its stylesheet (`css`, from the root: the one that imports
|
|
27
|
+
* Tailwind and holds the theme), or from Tailwind's defaults without one. Read again when that file changes.
|
|
28
|
+
* Rejects where the project has no Tailwind v4.
|
|
29
|
+
*/
|
|
30
|
+
async function loadCatalog(root, css) {
|
|
31
|
+
const { __unstable__loadDesignSystem: load } = await tailwindOf(root);
|
|
32
|
+
const file = css === void 0 ? void 0 : resolve(root, css);
|
|
33
|
+
const build = async () => catalogOf(file === void 0 ? await load("@import \"tailwindcss\";", { base: root }) : await load(readFileSync(file, "utf8"), { base: dirname(file) }));
|
|
34
|
+
const stamp = () => file === void 0 ? 0 : statSync(file).mtimeMs;
|
|
35
|
+
let built = stamp();
|
|
36
|
+
let current = await build();
|
|
37
|
+
const latest = () => {
|
|
38
|
+
const now = stamp();
|
|
39
|
+
if (now !== built) {
|
|
40
|
+
built = now;
|
|
41
|
+
build().then((next) => current = next, () => {});
|
|
42
|
+
}
|
|
43
|
+
return current;
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
complete: (query, limit) => latest().complete(query, limit),
|
|
47
|
+
info: (classes) => latest().info(classes),
|
|
48
|
+
alternatives: (name) => latest().alternatives(name),
|
|
49
|
+
css: (classes) => latest().css(classes)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
async function tailwindOf(root) {
|
|
53
|
+
const from = createRequire(join(root, "package.json"));
|
|
54
|
+
const found = [() => from.resolve("@tailwindcss/node"), ...VIA.map((via) => () => createRequire(from.resolve(via)).resolve("@tailwindcss/node"))];
|
|
55
|
+
for (const find of found) {
|
|
56
|
+
let path;
|
|
57
|
+
try {
|
|
58
|
+
path = find();
|
|
59
|
+
} catch {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const module = await import(pathToFileURL(path).href);
|
|
63
|
+
if (typeof module.__unstable__loadDesignSystem === "function") return { __unstable__loadDesignSystem: module.__unstable__loadDesignSystem };
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`no Tailwind v4 in ${root}: install @tailwindcss/node there (or one of ${VIA.join(", ")})`);
|
|
66
|
+
}
|
|
67
|
+
function catalogOf(design) {
|
|
68
|
+
/** A value with the theme's variables written out, and what arithmetic is left done: `calc(var(--spacing) * 4)` is `1rem`. */
|
|
69
|
+
const resolved = (value) => {
|
|
70
|
+
let now = value;
|
|
71
|
+
for (let i = 0; i < 4; i++) {
|
|
72
|
+
const next = now.replace(/var\((--[\w-]+)\)/g, (all, name) => themed(name) ?? all);
|
|
73
|
+
if (next === now) break;
|
|
74
|
+
now = next;
|
|
75
|
+
}
|
|
76
|
+
return now.replace(/calc\(([^()]+)\)/g, (all, sum) => computed(sum) ?? all);
|
|
77
|
+
};
|
|
78
|
+
const themed = (name) => {
|
|
79
|
+
try {
|
|
80
|
+
return design.resolveThemeValue(name) ?? void 0;
|
|
81
|
+
} catch {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const entryOf = (name, css) => {
|
|
86
|
+
const set = declarations(css);
|
|
87
|
+
const kind = [...new Set(set.map(([property]) => property))].toSorted().join(",");
|
|
88
|
+
const color = set.findLast(([property, value]) => COLOR.test(property) && !NO_COLOR.test(value))?.[1];
|
|
89
|
+
const main = (set.find(([property]) => !property.startsWith("--")) ?? set[0])?.[1];
|
|
90
|
+
return {
|
|
91
|
+
name,
|
|
92
|
+
kind,
|
|
93
|
+
...color === void 0 ? {} : { color: resolved(color) },
|
|
94
|
+
...main === void 0 ? {} : { value: resolved(main) }
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
const names = design.getClassList().map(([name]) => name).toSorted(natural);
|
|
98
|
+
const modifiers = new Map(design.getClassList().map(([name, { modifiers = [] }]) => [name, modifiers]));
|
|
99
|
+
const sheets = design.candidatesToCss(names);
|
|
100
|
+
const byName = /* @__PURE__ */ new Map();
|
|
101
|
+
const kinds = /* @__PURE__ */ new Map();
|
|
102
|
+
names.forEach((name, i) => {
|
|
103
|
+
const css = sheets[i];
|
|
104
|
+
if (css === null || css === void 0) return;
|
|
105
|
+
const entry = entryOf(name, css);
|
|
106
|
+
if (entry.kind === "") return;
|
|
107
|
+
byName.set(name, entry);
|
|
108
|
+
const kind = kinds.get(entry.kind);
|
|
109
|
+
if (kind === void 0) kinds.set(entry.kind, [entry]);
|
|
110
|
+
else kind.push(entry);
|
|
111
|
+
});
|
|
112
|
+
for (const kind of kinds.values()) kind.sort(byValue(kind));
|
|
113
|
+
const variants = design.getVariants().flatMap(({ name, values, hasDash }) => [name, ...values.map((value) => `${name}${hasDash ? "-" : ""}${value}`)]).filter((name) => /^[@\w]/.test(name)).toSorted(natural);
|
|
114
|
+
/** A class Tailwind makes on asking, not in its list: one with a value in brackets, a modifier, a fraction. */
|
|
115
|
+
const made = /* @__PURE__ */ new Map();
|
|
116
|
+
const make = (body) => {
|
|
117
|
+
if (made.has(body)) return made.get(body);
|
|
118
|
+
const css = design.candidatesToCss([body])[0];
|
|
119
|
+
const entry = css === null || css === void 0 ? void 0 : entryOf(body, css);
|
|
120
|
+
made.set(body, entry?.kind === "" ? void 0 : entry);
|
|
121
|
+
return made.get(body);
|
|
122
|
+
};
|
|
123
|
+
const rootOf = (body) => {
|
|
124
|
+
for (const candidate of design.parseCandidate(body)) if (candidate.kind === "functional" && candidate.root !== void 0 && candidate.value) return candidate.root;
|
|
125
|
+
};
|
|
126
|
+
/** The entry of a class's own part (no variants, no `!`), and the kind it's of among the listed ones. */
|
|
127
|
+
const find = (body) => {
|
|
128
|
+
const listed = byName.get(body);
|
|
129
|
+
if (listed !== void 0) return {
|
|
130
|
+
entry: listed,
|
|
131
|
+
kind: listed.kind
|
|
132
|
+
};
|
|
133
|
+
const entry = make(body);
|
|
134
|
+
if (entry === void 0) return void 0;
|
|
135
|
+
if (kinds.has(entry.kind)) return {
|
|
136
|
+
entry,
|
|
137
|
+
kind: entry.kind
|
|
138
|
+
};
|
|
139
|
+
const root = rootOf(body);
|
|
140
|
+
if (root === void 0) return {
|
|
141
|
+
entry,
|
|
142
|
+
kind: entry.kind
|
|
143
|
+
};
|
|
144
|
+
const own = new Set(entry.kind.split(","));
|
|
145
|
+
let best;
|
|
146
|
+
for (const name of names) {
|
|
147
|
+
if (!name.startsWith(`${root}-`)) continue;
|
|
148
|
+
const kind = byName.get(name)?.kind;
|
|
149
|
+
if (kind === void 0 || kind === best?.kind) continue;
|
|
150
|
+
const shared = kind.split(",").filter((property) => own.has(property)).length;
|
|
151
|
+
if (shared > (best?.shared ?? 0)) best = {
|
|
152
|
+
kind,
|
|
153
|
+
shared
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
entry,
|
|
158
|
+
kind: best?.kind ?? entry.kind
|
|
159
|
+
};
|
|
160
|
+
};
|
|
161
|
+
const shown = (name, entry) => ({
|
|
162
|
+
name,
|
|
163
|
+
known: true,
|
|
164
|
+
...entry.color === void 0 ? {} : { color: entry.color },
|
|
165
|
+
...entry.value === void 0 ? {} : { value: entry.value }
|
|
166
|
+
});
|
|
167
|
+
const info = (name) => {
|
|
168
|
+
const found = find(parts(name).body);
|
|
169
|
+
return found === void 0 ? {
|
|
170
|
+
name,
|
|
171
|
+
known: false
|
|
172
|
+
} : shown(name, found.entry);
|
|
173
|
+
};
|
|
174
|
+
return {
|
|
175
|
+
complete(query, limit = 40) {
|
|
176
|
+
const { before: variantsBefore, bang, body, after } = parts(query.trim());
|
|
177
|
+
if (body === "" && variantsBefore === "") return [];
|
|
178
|
+
const before = `${variantsBefore}${bang}`;
|
|
179
|
+
const starts = [];
|
|
180
|
+
const holds = [];
|
|
181
|
+
const add = (to, name, entry) => {
|
|
182
|
+
if (to.length < limit) to.push(shown(`${before}${name}${after}`, entry));
|
|
183
|
+
};
|
|
184
|
+
const exact = byName.get(body);
|
|
185
|
+
if (exact !== void 0) add(starts, body, exact);
|
|
186
|
+
for (const name of names) {
|
|
187
|
+
if (starts.length >= limit) break;
|
|
188
|
+
if (name === body) continue;
|
|
189
|
+
const entry = byName.get(name);
|
|
190
|
+
if (entry === void 0) continue;
|
|
191
|
+
if (name.startsWith(body)) add(starts, name, entry);
|
|
192
|
+
else if (body.length > 1 && name.includes(body)) add(holds, name, entry);
|
|
193
|
+
}
|
|
194
|
+
const slash = body.lastIndexOf("/");
|
|
195
|
+
const base = slash < 0 ? void 0 : byName.get(body.slice(0, slash));
|
|
196
|
+
const modified = base === void 0 || starts.length > 0 ? [] : (modifiers.get(base.name) ?? []).filter((modifier) => modifier.startsWith(body.slice(slash + 1))).map((modifier) => shown(`${before}${base.name}/${modifier}${after}`, make(`${base.name}/${modifier}`) ?? base));
|
|
197
|
+
const ahead = after !== "" || bang !== "" || body === "" ? [] : variants.filter((name) => name.startsWith(body)).map((name) => ({
|
|
198
|
+
name: `${before}${name}:`,
|
|
199
|
+
known: true,
|
|
200
|
+
variant: true
|
|
201
|
+
}));
|
|
202
|
+
return [
|
|
203
|
+
...starts,
|
|
204
|
+
...modified,
|
|
205
|
+
...ahead,
|
|
206
|
+
...holds
|
|
207
|
+
].slice(0, limit);
|
|
208
|
+
},
|
|
209
|
+
info: (classes) => classes.map(info),
|
|
210
|
+
alternatives(name) {
|
|
211
|
+
const { before, bang, body, after } = parts(name);
|
|
212
|
+
const found = find(body);
|
|
213
|
+
if (found === void 0) return void 0;
|
|
214
|
+
const { modifier, base } = modified(body, byName);
|
|
215
|
+
const kind = kinds.get(found.kind) ?? [];
|
|
216
|
+
const properties = found.kind.split(",");
|
|
217
|
+
const root = rootOf(body);
|
|
218
|
+
const value = [...design.parseCandidate(body)].find((candidate) => candidate.value?.kind === "arbitrary")?.value?.value;
|
|
219
|
+
const items = kind.slice(0, MOST).map((entry) => shown(`${before}${bang}${entry.name}${modifier}${after}`, entry));
|
|
220
|
+
if (!kind.some((entry) => entry.name === base)) items.unshift(shown(name, found.entry));
|
|
221
|
+
return {
|
|
222
|
+
label: properties.find((property) => !property.startsWith("--")) ?? properties[0],
|
|
223
|
+
colors: kind.filter((entry) => entry.color !== void 0).length * 2 > kind.length,
|
|
224
|
+
items,
|
|
225
|
+
...root === void 0 ? {} : { custom: {
|
|
226
|
+
before: `${before}${bang}${root}-[`,
|
|
227
|
+
after: `]${modifier}${after}`,
|
|
228
|
+
...value === void 0 ? {} : { value }
|
|
229
|
+
} }
|
|
230
|
+
};
|
|
231
|
+
},
|
|
232
|
+
css(classes) {
|
|
233
|
+
const bodies = [...new Set(classes)];
|
|
234
|
+
const order = new Map(design.getClassOrder(bodies));
|
|
235
|
+
bodies.sort((a, b) => {
|
|
236
|
+
const [x, y] = [order.get(a) ?? null, order.get(b) ?? null];
|
|
237
|
+
if (x === null || y === null) return x === y ? 0 : x === null ? 1 : -1;
|
|
238
|
+
return x < y ? -1 : x > y ? 1 : 0;
|
|
239
|
+
});
|
|
240
|
+
const properties = /* @__PURE__ */ new Set();
|
|
241
|
+
const rules = design.candidatesToCss(bodies).filter((css) => css !== null && css !== void 0).map((css) => css.replace(PROPERTY, (rule) => {
|
|
242
|
+
properties.add(rule.trim());
|
|
243
|
+
return "";
|
|
244
|
+
})).join("");
|
|
245
|
+
if (rules.trim() === "") return "";
|
|
246
|
+
return `${[...properties].join("\n")}\n@layer utilities {\n${rules.replace(/var\((--[\w-]+)\)/g, (all, name) => themed(name) ?? all)}}\n`;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
const COLOR = /(^|-)color$|^fill$|^stroke$|^--tw-gradient-(from|via|to)$/;
|
|
251
|
+
const NO_COLOR = /^(inherit|none|initial|unset)$/;
|
|
252
|
+
const PROPERTY = /@property [^{]+\{[^}]*\}\n?/g;
|
|
253
|
+
/** A rule's declarations, in order, from Tailwind's CSS for one class: one a line, `@property` rules after. */
|
|
254
|
+
function declarations(css) {
|
|
255
|
+
return [...css.replace(PROPERTY, "").matchAll(/^\s+(-{0,2}[\w-]+):\s*(.+?)(?:\s*!important)?;$/gm)].map((match) => [match[1], match[2]]);
|
|
256
|
+
}
|
|
257
|
+
/** `0.25rem * 4` as `1rem`: products and quotients of numbers with one unit between them. Anything else is left. */
|
|
258
|
+
function computed(sum) {
|
|
259
|
+
const tokens = sum.trim().split(/\s+/);
|
|
260
|
+
let total = 1;
|
|
261
|
+
let unit = "";
|
|
262
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
263
|
+
const token = tokens[i];
|
|
264
|
+
if (i % 2 === 1) {
|
|
265
|
+
if (token !== "*" && token !== "/") return void 0;
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const match = /^(-?(?:\d+\.?\d*|\.\d+))(%|[a-z]+)?$/.exec(token);
|
|
269
|
+
if (match === null) return void 0;
|
|
270
|
+
const divides = tokens[i - 1] === "/";
|
|
271
|
+
if (match[2] !== void 0 && (unit !== "" || divides)) return void 0;
|
|
272
|
+
unit = match[2] ?? unit;
|
|
273
|
+
total = divides ? total / Number(match[1]) : total * Number(match[1]);
|
|
274
|
+
}
|
|
275
|
+
if (tokens.length % 2 === 0 || !Number.isFinite(total)) return void 0;
|
|
276
|
+
return `${Number(total.toFixed(4))}${unit}`;
|
|
277
|
+
}
|
|
278
|
+
/** A length as a number to order by, where the value is one: `1rem` is 16. */
|
|
279
|
+
function measure(value) {
|
|
280
|
+
const match = value === void 0 ? null : /^(-?(?:\d+\.?\d*|\.\d+))(px|rem|em|%)?$/.exec(value);
|
|
281
|
+
if (match === null) return void 0;
|
|
282
|
+
return Number(match[1]) * (match[2] === "rem" || match[2] === "em" ? 16 : 1);
|
|
283
|
+
}
|
|
284
|
+
/** A kind's order: by size where most of it has one (`text-xs` before `text-sm`), by name else, as it already is. */
|
|
285
|
+
function byValue(kind) {
|
|
286
|
+
const sizes = new Map(kind.map((entry) => [entry, measure(entry.value)]));
|
|
287
|
+
if ([...sizes.values()].filter((size) => size !== void 0).length * 10 < kind.length * 7) return () => 0;
|
|
288
|
+
return (a, b) => {
|
|
289
|
+
const [x, y] = [sizes.get(a), sizes.get(b)];
|
|
290
|
+
if (x === void 0 || y === void 0) return x === y ? 0 : x === void 0 ? 1 : -1;
|
|
291
|
+
return x - y;
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* A class as written, apart: its variants (`md:hover:`), `!` where it leads, its own part, and `!` where it
|
|
296
|
+
* trails. A `:` inside brackets or parentheses is the value's.
|
|
297
|
+
*/
|
|
298
|
+
function parts(name) {
|
|
299
|
+
let depth = 0;
|
|
300
|
+
let cut = 0;
|
|
301
|
+
for (let i = 0; i < name.length; i++) {
|
|
302
|
+
const char = name[i];
|
|
303
|
+
if (char === "[" || char === "(") depth++;
|
|
304
|
+
else if (char === "]" || char === ")") depth--;
|
|
305
|
+
else if (char === ":" && depth === 0) cut = i + 1;
|
|
306
|
+
}
|
|
307
|
+
const own = name.slice(cut);
|
|
308
|
+
const bang = own.startsWith("!") ? "!" : "";
|
|
309
|
+
const after = !bang && own.endsWith("!") ? "!" : "";
|
|
310
|
+
return {
|
|
311
|
+
before: name.slice(0, cut),
|
|
312
|
+
bang,
|
|
313
|
+
body: own.slice(bang.length, own.length - after.length),
|
|
314
|
+
after
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
/** A class's modifier (`/50`) and what it's on, where the whole isn't a class itself, as `w-1/2` is. */
|
|
318
|
+
function modified(body, listed) {
|
|
319
|
+
const slash = body.lastIndexOf("/");
|
|
320
|
+
if (listed.has(body) || slash < 0 || body.indexOf("]", slash) >= 0) return {
|
|
321
|
+
base: body,
|
|
322
|
+
modifier: ""
|
|
323
|
+
};
|
|
324
|
+
return {
|
|
325
|
+
base: body.slice(0, slash),
|
|
326
|
+
modifier: body.slice(slash)
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
// src/plugins/tailwind/index.ts
|
|
330
|
+
const HELPERS = [
|
|
331
|
+
"cn",
|
|
332
|
+
"clsx",
|
|
333
|
+
"cx",
|
|
334
|
+
"twMerge",
|
|
335
|
+
"classNames"
|
|
336
|
+
];
|
|
337
|
+
function tailwind(options = {}) {
|
|
338
|
+
const helpers = new Set(options.helpers ?? HELPERS);
|
|
339
|
+
const attribute = options.attribute ?? "className";
|
|
340
|
+
let loading;
|
|
341
|
+
const catalog = ({ root }) => loading ??= loadCatalog(root, options.css).catch((problem) => {
|
|
342
|
+
console.warn(`deictic/tailwind: no completions or class details, as ${problem instanceof Error ? problem.message : String(problem)}`);
|
|
343
|
+
});
|
|
344
|
+
const asked = async (request) => {
|
|
345
|
+
const body = await request.json().catch(() => void 0);
|
|
346
|
+
return Array.isArray(body?.classes) ? body.classes.filter((c) => typeof c === "string").slice(0, 500) : [];
|
|
347
|
+
};
|
|
348
|
+
return definePlugin({
|
|
349
|
+
name: "tailwind",
|
|
350
|
+
client: "deictic/tailwind/client",
|
|
351
|
+
shortcut: options.shortcut,
|
|
352
|
+
routes: {
|
|
353
|
+
complete: async (request, context) => {
|
|
354
|
+
const query = new URL(request.url).searchParams.get("q") ?? "";
|
|
355
|
+
return Response.json({ items: (await catalog(context))?.complete(query) ?? [] });
|
|
356
|
+
},
|
|
357
|
+
info: async (request, context) => {
|
|
358
|
+
const known = await catalog(context);
|
|
359
|
+
return Response.json({
|
|
360
|
+
available: known !== void 0,
|
|
361
|
+
items: known?.info(await asked(request)) ?? []
|
|
362
|
+
});
|
|
363
|
+
},
|
|
364
|
+
alternatives: async (request, context) => {
|
|
365
|
+
const name = new URL(request.url).searchParams.get("class") ?? "";
|
|
366
|
+
return Response.json((await catalog(context))?.alternatives(name) ?? null);
|
|
367
|
+
},
|
|
368
|
+
css: async (request, context) => Response.json({ css: (await catalog(context))?.css(await asked(request)) ?? "" })
|
|
369
|
+
},
|
|
370
|
+
read({ code, element, program }) {
|
|
371
|
+
const spot = spotOf(element, code, helpers);
|
|
372
|
+
if (spot.kind === "fixed") return {
|
|
373
|
+
editable: false,
|
|
374
|
+
source: spot.source
|
|
375
|
+
};
|
|
376
|
+
if (spot.kind === "missing") return {
|
|
377
|
+
editable: true,
|
|
378
|
+
classes: ""
|
|
379
|
+
};
|
|
380
|
+
const others = spot.others?.flatMap((argument) => extrasOf(argument, code, program)).map(({ spot: _, ...extra }) => extra);
|
|
381
|
+
return {
|
|
382
|
+
editable: true,
|
|
383
|
+
classes: code.slice(spot.start, spot.end),
|
|
384
|
+
...others === void 0 ? {} : { others }
|
|
385
|
+
};
|
|
386
|
+
},
|
|
387
|
+
apply({ file, code, element, program }, _target, { classes, at }) {
|
|
388
|
+
const list = classes.trim().split(/\s+/).filter(Boolean).join(" ");
|
|
389
|
+
const spot = spotOf(element, code, helpers);
|
|
390
|
+
if (spot.kind === "fixed") throw new Refusal("this class list is built at runtime: edit it in the editor");
|
|
391
|
+
if (at !== void 0) {
|
|
392
|
+
const place = (spot.kind === "list" ? (spot.others ?? []).flatMap((argument) => extrasOf(argument, code, program)) : [])[at]?.spot;
|
|
393
|
+
if (place === void 0) throw new Refusal("these classes aren't a string in this file any more: reload, or edit them in the editor");
|
|
394
|
+
return [{
|
|
395
|
+
start: place.start,
|
|
396
|
+
end: place.end,
|
|
397
|
+
text: quoted(list, place.quote)
|
|
398
|
+
}];
|
|
399
|
+
}
|
|
400
|
+
const name = file.endsWith(".astro") ? "class" : attribute;
|
|
401
|
+
if (spot.kind === "missing") return list === "" ? [] : [{
|
|
402
|
+
start: spot.at,
|
|
403
|
+
end: spot.at,
|
|
404
|
+
text: ` ${name}="${quoted(list, "\"")}"`
|
|
405
|
+
}];
|
|
406
|
+
return [{
|
|
407
|
+
start: spot.start,
|
|
408
|
+
end: spot.end,
|
|
409
|
+
text: quoted(list, spot.quote)
|
|
410
|
+
}];
|
|
411
|
+
},
|
|
412
|
+
describe({ classes, at }, before) {
|
|
413
|
+
if (!before.editable) return "classes";
|
|
414
|
+
if (at === void 0) return diff(before.classes, classes);
|
|
415
|
+
const other = before.others?.[at];
|
|
416
|
+
return `${diff(other?.classes ?? "", classes)}${other?.when === void 0 ? "" : ` when ${other.when}`}`;
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
function spotOf(element, code, helpers) {
|
|
421
|
+
const attr = element.attributes.find((a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && (a.name.name === "className" || a.name.name === "class"));
|
|
422
|
+
if (attr === void 0) {
|
|
423
|
+
const listed = element.attributes.find((a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" && a.name.name === "class:list");
|
|
424
|
+
return listed === void 0 ? {
|
|
425
|
+
kind: "missing",
|
|
426
|
+
at: element.name.end
|
|
427
|
+
} : {
|
|
428
|
+
kind: "fixed",
|
|
429
|
+
source: code.slice(listed.start, listed.end)
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
const { value } = attr;
|
|
433
|
+
if (value?.type === "Literal") return list(value, code);
|
|
434
|
+
if (value?.type !== "JSXExpressionContainer" || value.expression.type === "JSXEmptyExpression") return {
|
|
435
|
+
kind: "fixed",
|
|
436
|
+
source: code.slice(attr.start, attr.end)
|
|
437
|
+
};
|
|
438
|
+
const e = value.expression;
|
|
439
|
+
const whole = listIn(e, code);
|
|
440
|
+
if (whole !== void 0) return whole;
|
|
441
|
+
if (e.type === "CallExpression" && e.callee.type === "Identifier" && helpers.has(e.callee.name)) {
|
|
442
|
+
const [first, ...others] = e.arguments;
|
|
443
|
+
const head = first === void 0 || first.type === "SpreadElement" ? void 0 : listIn(first, code);
|
|
444
|
+
if (head !== void 0) return others.length === 0 ? head : {
|
|
445
|
+
...head,
|
|
446
|
+
others
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
return {
|
|
450
|
+
kind: "fixed",
|
|
451
|
+
source: code.slice(attr.start, attr.end)
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* What one of a helper's arguments adds, and when: `on && 'ring'`, `on ? 'a' : 'b'`, `{ ring: on }`, a string,
|
|
456
|
+
* or a name for one. Anything else is only its source, as nothing says what it adds.
|
|
457
|
+
*/
|
|
458
|
+
function extrasOf(argument, code, program) {
|
|
459
|
+
const source = (node) => code.slice(node.start, node.end);
|
|
460
|
+
const added = (e, when, key = false) => {
|
|
461
|
+
const found = stringOf(e, program, !key);
|
|
462
|
+
if (found === void 0) return {
|
|
463
|
+
source: source(e),
|
|
464
|
+
...when === void 0 ? {} : { when }
|
|
465
|
+
};
|
|
466
|
+
return {
|
|
467
|
+
source: source(e),
|
|
468
|
+
classes: found.value,
|
|
469
|
+
...when === void 0 ? {} : { when },
|
|
470
|
+
editable: true,
|
|
471
|
+
...found.shared === void 0 ? {} : { shared: found.shared },
|
|
472
|
+
spot: list(found.node, code)
|
|
473
|
+
};
|
|
474
|
+
};
|
|
475
|
+
const e = argument;
|
|
476
|
+
if (e.type === "SpreadElement") return [{ source: source(e) }];
|
|
477
|
+
if (e.type === "LogicalExpression" && e.operator === "&&") return [added(e.right, source(e.left))];
|
|
478
|
+
if (e.type === "ConditionalExpression") {
|
|
479
|
+
const test = source(e.test);
|
|
480
|
+
const not = e.test.type === "Identifier" ? `!${test}` : `!(${test})`;
|
|
481
|
+
return [added(e.consequent, test), added(e.alternate, not)].filter((extra) => extra.classes !== "" && !/^(undefined|null|false)$/.test(extra.source));
|
|
482
|
+
}
|
|
483
|
+
if (e.type === "ObjectExpression") return e.properties.map((property) => {
|
|
484
|
+
if (property.type !== "Property" || property.computed) return { source: source(property) };
|
|
485
|
+
const when = property.value.type === "Literal" && property.value.value === true ? {} : { when: source(property.value) };
|
|
486
|
+
if (property.key.type === "Identifier") return {
|
|
487
|
+
source: source(property),
|
|
488
|
+
classes: property.key.name,
|
|
489
|
+
...when
|
|
490
|
+
};
|
|
491
|
+
const { source: _, ...key } = added(property.key, void 0, true);
|
|
492
|
+
return key.classes === void 0 ? { source: source(property) } : {
|
|
493
|
+
source: source(property),
|
|
494
|
+
...key,
|
|
495
|
+
...when
|
|
496
|
+
};
|
|
497
|
+
});
|
|
498
|
+
return [added(e)];
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* A string the source spells out, and where: a literal, a template with nothing interpolated, or a top-level
|
|
502
|
+
* `const` of one (`shared`, its name).
|
|
503
|
+
*/
|
|
504
|
+
function stringOf(e, program, named = true) {
|
|
505
|
+
const node = e;
|
|
506
|
+
if (node.type === "Literal") return typeof node.value === "string" ? {
|
|
507
|
+
value: node.value,
|
|
508
|
+
node
|
|
509
|
+
} : void 0;
|
|
510
|
+
if (node.type === "TemplateLiteral") {
|
|
511
|
+
const value = node.expressions.length === 0 ? node.quasis[0]?.value.cooked : void 0;
|
|
512
|
+
return value === void 0 || value === null ? void 0 : {
|
|
513
|
+
value,
|
|
514
|
+
node
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
if (node.type !== "Identifier" || !named) return void 0;
|
|
518
|
+
for (const statement of program.body) {
|
|
519
|
+
const declared = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
|
|
520
|
+
if (declared?.type !== "VariableDeclaration" || declared.kind !== "const") continue;
|
|
521
|
+
for (const { id, init } of declared.declarations) {
|
|
522
|
+
if (id.type !== "Identifier" || id.name !== node.name || !init) continue;
|
|
523
|
+
const found = stringOf(init, program, false);
|
|
524
|
+
return found === void 0 ? void 0 : {
|
|
525
|
+
...found,
|
|
526
|
+
shared: node.name
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
/** A string literal or a template with nothing interpolated, as the text between its quotes. */
|
|
532
|
+
function listIn(e, code) {
|
|
533
|
+
if (e.type === "Literal" && typeof e.value === "string") return list(e, code);
|
|
534
|
+
if (e.type === "TemplateLiteral" && e.expressions.length === 0) return list(e, code);
|
|
535
|
+
}
|
|
536
|
+
const list = (node, code) => ({
|
|
537
|
+
kind: "list",
|
|
538
|
+
start: node.start + 1,
|
|
539
|
+
end: node.end - 1,
|
|
540
|
+
quote: code[node.start]
|
|
541
|
+
});
|
|
542
|
+
/** The list as it may sit between `quote`s. A JSX attribute has no escapes, so a quote of its own kind can't. */
|
|
543
|
+
function quoted(list, quote) {
|
|
544
|
+
if (quote === "`") return list.replaceAll("\\", "\\\\").replaceAll("`", "\\`").replaceAll("${", "\\${");
|
|
545
|
+
if (!list.includes(quote)) return list;
|
|
546
|
+
throw new Refusal(`a class can't hold ${quote} here: use the other quote inside arbitrary values, as in content-['…']`);
|
|
547
|
+
}
|
|
548
|
+
/** What changed between two lists: `+ring -px-2`. */
|
|
549
|
+
function diff(before, after) {
|
|
550
|
+
const was = new Set(before.split(/\s+/).filter(Boolean));
|
|
551
|
+
const now = new Set(after.split(/\s+/).filter(Boolean));
|
|
552
|
+
const parts = [...[...now].filter((c) => !was.has(c)).map((c) => `+${c}`), ...[...was].filter((c) => !now.has(c)).map((c) => `-${c}`)];
|
|
553
|
+
return parts.length > 0 ? parts.join(" ") : "reordered classes";
|
|
554
|
+
}
|
|
555
|
+
export { tailwind as default, tailwind };
|
|
556
|
+
|
|
557
|
+
//# sourceMappingURL=index.js.map
|