yuhwa 1.0.2 → 1.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 (51) hide show
  1. package/README.md +13 -12
  2. package/client.d.ts +9 -1
  3. package/dist/astro.d.ts +2 -2
  4. package/dist/astro.js +8 -1
  5. package/dist/browser.d.ts +11 -5
  6. package/dist/browser.js +27 -7
  7. package/dist/cli.js +612 -49
  8. package/dist/editor/assets/index-BphHLTvA.js +689 -0
  9. package/dist/editor/assets/lsp.worker-sZtzIA6-.js +30 -0
  10. package/dist/editor/index.html +5 -4
  11. package/dist/figure-CA2hy0xh.d.ts +48 -0
  12. package/dist/{index-Dl845tUQ.d.ts → index-CnnoZYl0.d.ts} +76 -7
  13. package/dist/index.d.ts +2 -2
  14. package/dist/index.js +1 -1
  15. package/dist/ironmark.d.ts +4 -2
  16. package/dist/ironmark.js +18 -7
  17. package/dist/llms.txt +26 -17
  18. package/dist/lsp-browser.d.ts +2 -2
  19. package/dist/lsp-browser.js +1 -1
  20. package/dist/lsp-node.js +208 -212
  21. package/dist/lsp-server.d.ts +1 -1
  22. package/dist/lsp-server.js +1 -1
  23. package/dist/lsp.d.ts +44 -2
  24. package/dist/lsp.js +1 -1
  25. package/dist/markdown-it.d.ts +2 -1
  26. package/dist/markdown-it.js +7 -6
  27. package/dist/node-Bzn2uKXZ.js +224 -0
  28. package/dist/remark.d.ts +2 -1
  29. package/dist/remark.js +16 -5
  30. package/dist/{server-DJC_fQMe.d.ts → server--jHjJjOS.d.ts} +2 -2
  31. package/dist/{server-DmQuHQrG.js → server-Dxo7OG8K.js} +19 -2
  32. package/dist/{service-BYS9Qfkq.js → service-B1fpOg_L.js} +348 -44
  33. package/dist/{service-ClZ8clSQ.d.ts → service-Brvpt7Do.d.ts} +3 -1
  34. package/dist/{shared-qo_r6RUN.js → shared-Ddw88O9D.js} +3069 -742
  35. package/dist/{src-wk7tBpWs.js → src-DkQj7aIV.js} +2842 -744
  36. package/dist/style.css +14 -0
  37. package/dist/vite.d.ts +1 -1
  38. package/dist/vite.js +19 -12
  39. package/dist/vuepress.d.ts +3 -1
  40. package/dist/vuepress.js +7 -2
  41. package/dist/yuhwa.iife.js +91 -75
  42. package/dist/zoom-CCSUbX1X.d.ts +49 -0
  43. package/dist/zoom-QeqB6QlH.js +275 -0
  44. package/dist/zoom-script-CVdAzMhX.js +51 -0
  45. package/dist/zoom.d.ts +35 -0
  46. package/dist/zoom.js +19 -0
  47. package/package.json +10 -2
  48. package/dist/editor/assets/index-BQLsumas.js +0 -587
  49. package/dist/editor/assets/lsp.worker-RlPj9blG.js +0 -26
  50. package/dist/figure-BZHIKnxv.d.ts +0 -27
  51. package/dist/node-Bneu5eJV.js +0 -108
package/dist/lsp-node.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire } from "node:module";
3
+ import { A as PLACEMENT_PROPS, B as themeNames, C as COLORS, D as NODE_PROPS, E as GROUP_PROPS, F as spanKey, I as THEME_KEYS, M as SPAN_KEYS, O as NUMBERS, P as parseSpanStyle, R as TONES, S as BOOLS, T as ENUMS, V as table, a as onTypeEdits, b as parse, d as optionKind, g as blockBraces, h as SETTING_VALUES, i as format, j as SHAPES, k as PANEL_PROPS, m as PANELS, n as applyChange, o as tidy, p as KNOWN_SETTINGS, r as diffEdits, s as diskResolve, t as VERSION, v as joinPath, w as EDGE_PROPS, x as serializeProps, y as lex } from "./shared-Ddw88O9D.js";
3
4
  import { fileURLToPath, pathToFileURL } from "node:url";
4
- import { C as PANEL_PROPS, D as TONES, O as themeNames, S as NUMBERS, T as THEME_KEYS, _ as BOOLS, b as GROUP_PROPS, c as KNOWN_SETTINGS, d as blockBraces, g as serializeProps, h as parse, i as isMermaid, l as PANELS, m as lex, p as joinPath, s as diskResolve, t as VERSION, u as SETTING_VALUES, v as EDGE_PROPS, w as SHAPES, x as NODE_PROPS, y as ENUMS } from "./shared-qo_r6RUN.js";
5
5
  // \0rolldown/runtime.js
6
6
  var __defProp = Object.defineProperty;
7
7
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -10667,182 +10667,20 @@ var require_main = /* @__PURE__ */ __commonJSMin(((exports, module, this$1) => {
10667
10667
  };
10668
10668
  }
10669
10669
  }));
10670
- // src/lsp/format.ts
10671
- /**
10672
- * Formatting and text edits, without a parser of their own beyond `lex`.
10673
- *
10674
- * The formatter only touches whitespace: it re-indents blocks by two spaces,
10675
- * trims line ends, keeps one blank line between statements and ends the file
10676
- * with a newline. Panel and node bodies (`timeline t { … }`, `card { … }`)
10677
- * belong to their plugin and may give indentation meaning, so they are moved
10678
- * as a whole and keep their inner indentation. Lines of a `def` body are moved
10679
- * the same way, since they may hold such bodies.
10680
- */
10681
- var import_api = require_api();
10682
- var import_main = require_main();
10683
- const lead = (l) => l.match(/^\s*/)[0].length;
10684
- const leadTabs = (l) => l.match(/^[ \t]*/)[0].length;
10685
- /** line ranges `[open, close]` whose inner lines are kept as they are */
10686
- function verbatimBlocks(text, lines) {
10687
- const d = parse(text);
10688
- const out = [];
10689
- const add = (r) => {
10690
- if (r && r[1] > r[0] && /\{\s*(\/\/.*)?$/.test(lines[r[0]] ?? "") && lines[r[1]]?.trim() === "}") out.push(r);
10691
- };
10692
- for (const p of d.panels) add(p.lines);
10693
- for (const n of d.nodes.values()) add(n.bodyLines);
10694
- return out;
10695
- }
10696
- /** Format yuhwa source. Returns the new text; whitespace is all that changes. */
10697
- function format(text) {
10698
- if (isMermaid(text)) return text;
10699
- const eol = text.includes("\r\n") ? "\r\n" : "\n";
10700
- const lines = text.split(/\r?\n/);
10701
- const verbatim = /* @__PURE__ */ new Map();
10702
- for (const [s, e] of verbatimBlocks(text, lines)) for (let i = s + 1; i < e; i++) verbatim.set(i, s);
10703
- const stack = [];
10704
- const parent = [];
10705
- const closes = [];
10706
- const code = [];
10707
- for (let i = 0; i < lines.length; i++) {
10708
- if (verbatim.has(i)) {
10709
- parent.push(void 0);
10710
- closes.push(false);
10711
- code.push(false);
10712
- continue;
10713
- }
10714
- const toks = lex(lines[i]).tokens;
10715
- const first = toks[0];
10716
- const close = first?.kind === "punct" && first.value === "}";
10717
- closes.push(close);
10718
- parent.push(stack[stack.length - 1]);
10719
- code.push(toks.length > 0);
10720
- for (const b of blockBraces(toks)) if (b === "{") stack.push({
10721
- open: i,
10722
- def: /^\s*(export\s+)?def\b/.test(lines[i]) || !!stack[stack.length - 1]?.def
10723
- });
10724
- else stack.pop();
10725
- }
10726
- const level = [];
10727
- const stacks = /* @__PURE__ */ new Map();
10728
- lines.forEach((l, i) => {
10729
- level.push(0);
10730
- const closed = closes[i] && parent[i];
10731
- if (closed) stacks.delete(parent[closed.open]?.open ?? -1);
10732
- if (verbatim.has(i) || !l.trim() || closes[i] || parent[i]?.def) return;
10733
- const k = parent[i]?.open ?? -1;
10734
- const st = stacks.get(k) ?? [];
10735
- stacks.set(k, st);
10736
- const w = lead(l);
10737
- if (!code[i]) {
10738
- level[i] = Math.max(0, st.filter((x) => x <= w).length - 1);
10739
- return;
10740
- }
10741
- while (st.length && st[st.length - 1] > w) st.pop();
10742
- if (!st.length || st[st.length - 1] < w) st.push(w);
10743
- level[i] = st.length - 1;
10744
- });
10745
- const indentOf = [];
10746
- const out = [];
10747
- const cuts = /* @__PURE__ */ new Map();
10748
- const cutOf = (open, from) => {
10749
- let c = cuts.get(open);
10750
- if (c === void 0) {
10751
- c = 1e400;
10752
- for (let j = from; verbatim.get(j) === open; j++) if (lines[j].trim()) c = Math.min(c, leadTabs(lines[j]));
10753
- cuts.set(open, c = Number.isFinite(c) ? c : 0);
10754
- }
10755
- return c;
10756
- };
10757
- const defCut = /* @__PURE__ */ new Map();
10758
- for (let i = 0; i < lines.length; i++) {
10759
- const raw = lines[i].replace(/\s+$/, "");
10760
- const open = verbatim.get(i);
10761
- if (open !== void 0) {
10762
- const base = (indentOf[open] ?? 0) + 2;
10763
- indentOf.push(base);
10764
- out.push(raw ? " ".repeat(base) + raw.slice(cutOf(open, i)) : "");
10765
- continue;
10766
- }
10767
- const p = parent[i];
10768
- const base = p ? indentOf[p.open] + (closes[i] ? 0 : 2) : 0;
10769
- let width = base;
10770
- if (raw && !closes[i]) {
10771
- if (p?.def) {
10772
- let c = defCut.get(p.open);
10773
- if (c === void 0) {
10774
- c = 1e400;
10775
- for (let j = i; j < lines.length; j++) if (parent[j] === p && lines[j].trim() && !closes[j]) c = Math.min(c, lead(lines[j]));
10776
- defCut.set(p.open, c = Number.isFinite(c) ? c : 0);
10777
- }
10778
- width = base + Math.max(0, lead(raw) - c);
10779
- } else width = base + level[i] * 2;
10780
- }
10781
- indentOf.push(width);
10782
- out.push(raw ? " ".repeat(width) + raw.trimStart() : "");
10783
- }
10784
- const kept = [];
10785
- for (const [i, l] of out.entries()) {
10786
- const blank = !l;
10787
- const inBody = verbatim.has(i);
10788
- if (blank && !inBody && (!kept.length || kept[kept.length - 1] === "")) continue;
10789
- kept.push(l);
10790
- }
10791
- while (kept.length && kept[kept.length - 1] === "") kept.pop();
10792
- return kept.length ? kept.join(eol) + eol : "";
10793
- }
10794
- /** One edit that turns `a` into `b`, covering only what differs. */
10795
- function diffEdits(a, b) {
10796
- if (a === b) return [];
10797
- let p = 0;
10798
- while (p < a.length && p < b.length && a[p] === b[p]) p++;
10799
- let q = 0;
10800
- while (q < a.length - p && q < b.length - p && a[a.length - 1 - q] === b[b.length - 1 - q]) q++;
10801
- return [{
10802
- range: {
10803
- start: positionAt(a, p),
10804
- end: positionAt(a, a.length - q)
10805
- },
10806
- newText: b.slice(p, b.length - q)
10807
- }];
10808
- }
10809
- /** LSP position of an offset. */
10810
- function positionAt(text, offset) {
10811
- const before = text.slice(0, offset).split("\n");
10812
- return {
10813
- line: before.length - 1,
10814
- character: before[before.length - 1].length
10815
- };
10816
- }
10817
- /** Offset of an LSP position (UTF-16 code units, as JS strings count). */
10818
- function offsetAt(text, p) {
10819
- let off = 0;
10820
- for (let line = 0; line < p.line; line++) {
10821
- const nl = text.indexOf("\n", off);
10822
- if (nl < 0) return text.length;
10823
- off = nl + 1;
10824
- }
10825
- const end = text.indexOf("\n", off);
10826
- const lineEnd = end < 0 ? text.length : end;
10827
- return Math.min(off + Math.max(0, p.character), lineEnd);
10828
- }
10829
- /** Apply one `didChange` content change: a range edit, or the whole text when it has no range. */
10830
- function applyChange(text, change) {
10831
- if (!change.range) return change.text;
10832
- const a = offsetAt(text, change.range.start);
10833
- const b = Math.max(a, offsetAt(text, change.range.end));
10834
- return text.slice(0, a) + change.text + text.slice(b);
10835
- }
10836
10670
  // src/lsp/service.ts
10837
10671
  /**
10838
10672
  * The yuhwa language service: plain functions from source text (and a
10839
10673
  * position) to LSP results. It does no I/O and knows no transport, so the same
10840
10674
  * code runs in a Node language server, in a Web Worker or straight in a page.
10841
10675
  */
10676
+ var import_api = require_api();
10677
+ var import_main = require_main();
10842
10678
  const SEVERITY = {
10843
10679
  error: 1,
10844
10680
  warning: 2
10845
10681
  };
10682
+ const HINT = 4;
10683
+ const UNNECESSARY = 1;
10846
10684
  const ITEM = {
10847
10685
  Function: 3,
10848
10686
  Variable: 6,
@@ -10872,15 +10710,6 @@ const HEAD_KEYWORDS = /* @__PURE__ */ new Set([
10872
10710
  ]);
10873
10711
  /** `tone` is the old name of `color`: still read, never offered */
10874
10712
  const DEPRECATED_PROPS = /* @__PURE__ */ new Set(["tone"]);
10875
- const COLOR_PROPS = /* @__PURE__ */ new Set([
10876
- "fill",
10877
- "stroke",
10878
- "color",
10879
- "text",
10880
- "sub-color",
10881
- "label-color",
10882
- "label-bg"
10883
- ]);
10884
10713
  const SIDES = [
10885
10714
  "top",
10886
10715
  "right",
@@ -10888,13 +10717,13 @@ const SIDES = [
10888
10717
  "left",
10889
10718
  "auto"
10890
10719
  ];
10891
- const ARROWS = {
10720
+ const ARROWS = table({
10892
10721
  "-": "solid line",
10893
10722
  "--": "dashed line",
10894
10723
  "..": "dotted line",
10895
10724
  "=": "thick line",
10896
10725
  "==": "thick line"
10897
- };
10726
+ });
10898
10727
  const ALL_PROPS = [.../* @__PURE__ */ new Set([
10899
10728
  ...NODE_PROPS,
10900
10729
  ...EDGE_PROPS,
@@ -10924,6 +10753,9 @@ const NAME_TYPE = {
10924
10753
  panel: "type",
10925
10754
  class: "class"
10926
10755
  };
10756
+ /** props whose value is the id of the node placed against */
10757
+ const PLACEMENT = new Set(PLACEMENT_PROPS.filter((p) => p !== "rank"));
10758
+ const PLACED = new RegExp(`(?:^\\[|[,;])\\s*(${[...PLACEMENT].join("|")})\\s*:\\s*([\\p{L}_][\\p{L}\\p{N}_-]*)(?=\\s*(?:[,;\\]]|$))`, "gu");
10927
10759
  const LAYOUT_WORDS = /* @__PURE__ */ new Set([
10928
10760
  "at",
10929
10761
  "size",
@@ -10947,6 +10779,8 @@ const range = (line, start, end) => ({
10947
10779
  end: pos(line, end)
10948
10780
  });
10949
10781
  const keyOf = (t) => t.kind === "class" ? "." + t.value : t.value;
10782
+ /** a statement's tokens without a leading `export` */
10783
+ const unexported = (t) => t[0]?.value === "export" && t[0].kind === "ident" && t.length > 1 ? t.slice(1) : t;
10950
10784
  const isKeywordHead = (t) => t[0].kind === "ident" && (HEAD_KEYWORDS.has(t[0].value) || PANELS.has(t[0].value) && t[t.length - 1].value === "{") && !!t[1] && t[1].kind !== "arrow" && t[1].value !== ":" && t[1].value !== ",";
10951
10785
  function settingValues(key, d) {
10952
10786
  if (key === "theme") return themeNames(d?.themes);
@@ -10967,26 +10801,97 @@ function inThemeBlock(a, line) {
10967
10801
  return t[t[0]?.value === "export" ? 1 : 0]?.value === "theme";
10968
10802
  }
10969
10803
  function propValues(key, panel, d) {
10970
- const opts = panel ? PANELS.get(panel)?.options?.[key] : void 0;
10971
- if (opts) return opts;
10804
+ const opt = panel ? PANELS.get(panel)?.options?.[key] : void 0;
10805
+ if (opt !== void 0) {
10806
+ const o = optionKind(opt);
10807
+ switch (o.kind) {
10808
+ case "select": return [...o.values];
10809
+ case "flag": return ["true", "false"];
10810
+ case "color": return TONES;
10811
+ case "number":
10812
+ case "text": return [];
10813
+ default: return o;
10814
+ }
10815
+ }
10972
10816
  if (panel && key === "frame") return ["false"];
10973
10817
  if (panel && key === "theme") return themeNames(d?.themes);
10974
10818
  if (panel && key === "border") return ["none", ...TONES];
10975
- if (panel && (key === "background" || key === "fill" || key === "stroke")) return TONES;
10976
10819
  if (ENUMS[key]) return ENUMS[key];
10977
10820
  if (BOOLS.includes(key)) return ["true", "false"];
10978
- if (COLOR_PROPS.has(key)) return TONES;
10821
+ if (COLORS.includes(key)) return TONES;
10979
10822
  return [];
10980
10823
  }
10981
- function propInfo(key) {
10824
+ /** The open span spec (`{size: 18, red`) the cursor is typing, if any. */
10825
+ function openSpan(before) {
10826
+ const m = before.match(/\{([^{}|"\n]*)$/);
10827
+ return m && /^[\w\s,:#.()%-]*$/.test(m[1]) ? m[1] : void 0;
10828
+ }
10829
+ /** The span spec (`{…|`) whose keys cover column `ch`, with its offset. */
10830
+ function spanAt(line, ch) {
10831
+ for (const m of line.matchAll(/\{([^{}|\n]+?)[ ]?\|/g)) {
10832
+ const at = m.index + 1;
10833
+ if (ch >= at && ch <= at + m[1].length && parseSpanStyle(m[1])) return {
10834
+ spec: m[1],
10835
+ at
10836
+ };
10837
+ }
10838
+ }
10839
+ function propInfo(key, panel) {
10840
+ const opt = panel ? PANELS.get(panel)?.options?.[key] : void 0;
10841
+ if (opt !== void 0) {
10842
+ const o = optionKind(opt);
10843
+ if (o.kind === "select") return `one of: ${o.values.join(", ")}`;
10844
+ if (o.kind === "flag") return "true or false";
10845
+ if (o.kind === "number") return "a number";
10846
+ if (o.kind === "color") return "a palette name or any CSS colour (#hex, rgb(), hsl())";
10847
+ return "text";
10848
+ }
10849
+ if (panel && key === "frame") return "`false` drops the box";
10850
+ if (panel && key === "theme") return "a theme name";
10851
+ if (panel && key === "border") return "`none`, a palette name or any CSS colour";
10982
10852
  const values = propValues(key);
10983
10853
  if (BOOLS.includes(key)) return "true or false";
10984
10854
  if (NUMBERS.includes(key)) return "a number";
10985
10855
  if (ENUMS[key]) return `one of: ${values.join(", ")}`;
10986
10856
  if (DEPRECATED_PROPS.has(key)) return "old name of `color`";
10987
- if (COLOR_PROPS.has(key)) return "a palette name or any CSS colour (#hex, rgb(), hsl())";
10857
+ if (COLORS.includes(key)) return "a palette name or any CSS colour (#hex, rgb(), hsl())";
10988
10858
  return "text";
10989
10859
  }
10860
+ /**
10861
+ * The declaration that `line` is indented under, whose props its `key: value`
10862
+ * lines set (as `parse` does), or -1.
10863
+ */
10864
+ function declAbove(a, line) {
10865
+ const indent = (l) => a.lines[l].match(/^\s*/)[0].length;
10866
+ for (let l = line - 1; l >= 0; l--) {
10867
+ const t = a.toks[l];
10868
+ if (!t.length || t[0].kind === "ident" && t[1]?.value === ":") continue;
10869
+ return t[0].value !== "}" && indent(l) < indent(line) ? l : -1;
10870
+ }
10871
+ return -1;
10872
+ }
10873
+ /** Props an indented line under the declaration on `line` can set. */
10874
+ function declProps(a, line) {
10875
+ const t = unexported(a.toks[line]);
10876
+ if (t[0].kind === "class") return ALL_PROPS;
10877
+ if (t[0].value === "group") return GROUP_PROPS;
10878
+ return t.some((x) => x.kind === "arrow") ? EDGE_PROPS : NODE_PROPS;
10879
+ }
10880
+ /**
10881
+ * Where a name quoted in a diagnostic sits on its line: a whole word, so `shap`
10882
+ * is not found inside `shape`, and with `props` the one inside `[...]`, so the
10883
+ * value in `red [shape: red]` wins over the node id.
10884
+ */
10885
+ function findQuoted(code, q, props) {
10886
+ const re = new RegExp(`(?<![\\w-])${q.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}(?![\\w-])`, "g");
10887
+ let first = -1;
10888
+ for (const m of code.matchAll(re)) {
10889
+ const depth = [...code.slice(0, m.index)].reduce((n, c) => n + (c === "[" ? 1 : c === "]" ? -1 : 0), 0);
10890
+ if (props && depth > 0) return m.index;
10891
+ if (first < 0) first = m.index;
10892
+ }
10893
+ return first >= 0 ? first : code.indexOf(q);
10894
+ }
10990
10895
  /** relative import path from one file to another */
10991
10896
  function relPath(from, to) {
10992
10897
  const a = (from ?? "").split("/").slice(0, -1);
@@ -11014,7 +10919,7 @@ var YuhwaService = class {
11014
10919
  file,
11015
10920
  resolve: this.opts.resolve
11016
10921
  });
11017
- const lines = text.split("\n");
10922
+ const lines = text.split(/\r?\n/);
11018
10923
  const opaque = lines.map(() => false);
11019
10924
  const body = (r) => {
11020
10925
  if (r) for (let i = r[0] + 1; i < r[1]; i++) opaque[i] = true;
@@ -11067,12 +10972,26 @@ var YuhwaService = class {
11067
10972
  else if (x.kind === "punct" && x.value === ":" && arrow) ids = false;
11068
10973
  if (x.kind === "class") add(li, x);
11069
10974
  else if (ids && known(x) && !(k === 0 && skipHead)) add(li, x);
10975
+ else if (x.kind === "props") {
10976
+ const bare = lines[li].slice(x.start, x.end).replace(/(["'])(?:\\.|(?!\1).)*\1?/g, (q) => " ".repeat(q.length));
10977
+ for (const m of bare.matchAll(PLACED)) {
10978
+ const start = x.start + m.index + m[0].length - m[2].length;
10979
+ if (kinds.get(m[2]) === "node") occ.push({
10980
+ key: m[2],
10981
+ line: li,
10982
+ start,
10983
+ end: start + m[2].length
10984
+ });
10985
+ }
10986
+ }
11070
10987
  }
10988
+ if (PLACEMENT.has(head) && t[1]?.value === ":" && known(t[2]) && t.length === 3) add(li, t[2]);
11071
10989
  }
11072
10990
  const decl = /* @__PURE__ */ new Map();
10991
+ const first = /* @__PURE__ */ new Map();
10992
+ for (const x of occ) if (!first.has(`${x.line}\0${x.key}`)) first.set(`${x.line}\0${x.key}`, x);
11073
10993
  const declare = (key, line) => {
11074
- if (line === void 0) return;
11075
- const o = occ.find((x) => x.key === key && x.line === line);
10994
+ const o = line === void 0 ? void 0 : first.get(`${line}\0${key}`);
11076
10995
  if (o) decl.set(key, o);
11077
10996
  };
11078
10997
  for (const n of diagram.nodes.values()) declare(n.id, declLine(n));
@@ -11104,15 +11023,25 @@ var YuhwaService = class {
11104
11023
  }
11105
11024
  diagnostics(text, file) {
11106
11025
  const a = this.analyze(text, file);
11107
- return a.diagram.diagnostics.map((d) => {
11108
- const li = Math.min(Math.max(d.line - 1, 0), a.lines.length - 1);
11109
- return {
11110
- range: this.narrow(a, li, d.message),
11026
+ const at = (line) => Math.min(Math.max(line - 1, 0), a.lines.length - 1);
11027
+ const found = a.diagram.diagnostics.map((d) => ({
11028
+ range: this.narrow(a, at(d.line), d.message),
11029
+ message: d.message,
11030
+ severity: SEVERITY[d.severity],
11031
+ source: "yuhwa"
11032
+ }));
11033
+ for (const d of tidy(text, a.diagram, a.toks)) {
11034
+ const li = at(d.line);
11035
+ const l = a.lines[li];
11036
+ found.push({
11037
+ range: range(li, l.length - l.trimStart().length, l.trimEnd().length),
11111
11038
  message: d.message,
11112
- severity: SEVERITY[d.severity],
11113
- source: "yuhwa"
11114
- };
11115
- });
11039
+ severity: HINT,
11040
+ source: "yuhwa lint",
11041
+ ...d.code?.startsWith("unused-") ? { tags: [UNNECESSARY] } : {}
11042
+ });
11043
+ }
11044
+ return found;
11116
11045
  }
11117
11046
  /** Messages name only a line; point at the quoted word they complain about when it is there. */
11118
11047
  narrow(a, li, message) {
@@ -11120,14 +11049,14 @@ var YuhwaService = class {
11120
11049
  const { codeEnd } = lex(line);
11121
11050
  const start = Math.max(0, line.search(/\S/));
11122
11051
  const end = Math.max(start, line.slice(0, codeEnd).trimEnd().length);
11123
- const quoted = /^\S+\.yuhwa:\d+:/i.test(message) ? void 0 : message.match(/"([^"\n]+)"/)?.[1];
11124
- const at = quoted ? line.indexOf(quoted) : -1;
11125
- return at >= 0 && at < codeEnd ? range(li, at, at + quoted.length) : range(li, start, end);
11052
+ const quoted = /^\S+\.(yu|yuhwa):\d+:/i.test(message) ? void 0 : message.match(/"([^"\n]+)"/)?.[1];
11053
+ const at = quoted ? findQuoted(line.slice(0, codeEnd), quoted, /prop|unknown|expects|did you mean/i.test(message)) : -1;
11054
+ return at >= 0 ? range(li, at, at + quoted.length) : range(li, start, end);
11126
11055
  }
11127
11056
  /** Quick fixes: apply a diagnostic's `did you mean "…"` suggestion. */
11128
11057
  fixes(text, diagnostics) {
11129
11058
  const out = [];
11130
- const lines = text.split("\n");
11059
+ const lines = text.split(/\r?\n/);
11131
11060
  for (const d of diagnostics) {
11132
11061
  const m = (typeof d.message === "string" ? d.message : d.message.value).match(/"([^"\n]+)".*\(did you mean "([^"\n]+)"\?\)/);
11133
11062
  if (!m) continue;
@@ -11165,8 +11094,22 @@ var YuhwaService = class {
11165
11094
  const values = (vs) => vs.map((v) => item(v, ITEM.Value));
11166
11095
  const themeKeyItems = () => Object.entries(THEME_KEYS).map(([k, { info }]) => item(k, ITEM.Property, info, `${k}: `));
11167
11096
  const nodes = () => [...d.nodes.values()].map((n) => item(n.id, ITEM.Variable, n.label !== n.id ? n.label : void 0));
11168
- if (a.opaque[p.line]) return [];
11097
+ const ends = () => [...nodes(), ...d.panels.map((x) => item(x.id, ITEM.Module, x.kind))];
11169
11098
  const toks = lex(line).tokens;
11099
+ const spec = openSpan(before);
11100
+ const brace = before.length - (spec?.length ?? 0) - 1;
11101
+ const inString = toks.some((t) => t.kind === "string" && t.start < brace && brace < t.end);
11102
+ if (spec !== void 0 && (inString || a.opaque[p.line])) {
11103
+ const seg = spec.split(",").pop();
11104
+ const colon = seg.indexOf(":");
11105
+ if (colon >= 0) {
11106
+ const key = seg.slice(0, colon).trim().toLowerCase();
11107
+ const k = spanKey(key);
11108
+ return values(k ? SPAN_KEYS[k].values : []);
11109
+ }
11110
+ return Object.entries(SPAN_KEYS).map(([k, { info, flag }]) => item(k, ITEM.Property, info, flag ? k : `${k}: `));
11111
+ }
11112
+ if (a.opaque[p.line]) return [];
11170
11113
  const tok = toks.find((t) => t.start < p.character && p.character < t.end);
11171
11114
  const open = toks.find((t) => (t.kind === "props" || t.kind === "string") && t.start < p.character && p.character === t.end && t.end === line.length);
11172
11115
  const inside = tok ?? (open && !/["'\]]$/.test(line.slice(open.start + 1)) ? open : void 0);
@@ -11193,14 +11136,15 @@ var YuhwaService = class {
11193
11136
  }
11194
11137
  if (kind === "theme") return themeKeyItems();
11195
11138
  const keys = kind === "edge" ? EDGE_PROPS : kind === "group" ? GROUP_PROPS : kind === "class" ? ALL_PROPS : kind.startsWith("panel:") ? [...Object.keys(PANELS.get(kind.slice(6))?.options ?? {}), ...PANEL_PROPS] : NODE_PROPS;
11196
- return [...new Set(keys)].filter((k) => !DEPRECATED_PROPS.has(k)).map((k) => item(k, ITEM.Property, propInfo(k), `${k}: `));
11139
+ const panel = kind.startsWith("panel:") ? kind.slice(6) : void 0;
11140
+ return [...new Set(keys)].filter((k) => !DEPRECATED_PROPS.has(k)).map((k) => item(k, ITEM.Property, propInfo(k, panel), `${k}: `));
11197
11141
  }
11198
11142
  if (inside) return [];
11199
11143
  if (/(^|[\s,:])\.$/.test(before.slice(0, wordStart))) return Object.entries(d.classes).map(([c, props]) => item(c, ITEM.Class, serializeProps(props) || void 0));
11200
11144
  const kv = before.match(/^(\s*)(?:export\s+)?([\w-]+)\s*:\s*[\p{L}\p{N}_-]*$/u);
11201
11145
  if (kv && !toks.some((t) => t.kind === "arrow")) {
11202
11146
  const key = kv[2].toLowerCase();
11203
- if (!kv[1] && a.depth[p.line] === 0) return values(settingValues(key, d));
11147
+ if (a.depth[p.line] === 0 && declAbove(a, p.line) < 0) return values(settingValues(key, d));
11204
11148
  if (inThemeBlock(a, p.line)) return values(themeValues(key, d));
11205
11149
  return values(propValues(key, void 0, d));
11206
11150
  }
@@ -11208,8 +11152,7 @@ var YuhwaService = class {
11208
11152
  const lineStart = !before.slice(0, wordStart).trim();
11209
11153
  if (p.line > ls && p.line < le) {
11210
11154
  if (lineStart) return [
11211
- ...nodes(),
11212
- ...d.panels.map((x) => item(x.id, ITEM.Module, x.kind)),
11155
+ ...ends(),
11213
11156
  ...[...new Set(d.edges.map((e) => e.key))].map((k) => item(k, ITEM.Variable, "edge")),
11214
11157
  item("rank", ITEM.Keyword)
11215
11158
  ];
@@ -11226,8 +11169,11 @@ var YuhwaService = class {
11226
11169
  }
11227
11170
  if (lineStart && inThemeBlock(a, p.line)) return themeKeyItems();
11228
11171
  if (lineStart) {
11229
- const out = nodes();
11230
- if (a.depth[p.line] === 0) {
11172
+ const out = ends();
11173
+ const decl = a.depth[p.line] === 0 ? declAbove(a, p.line) : -1;
11174
+ if (decl >= 0) {
11175
+ for (const k of new Set(declProps(a, decl))) if (!DEPRECATED_PROPS.has(k)) out.push(item(k, ITEM.Property, propInfo(k), `${k}: `));
11176
+ } else if (a.depth[p.line] === 0) {
11231
11177
  out.push(...[...KNOWN_SETTINGS].map((k) => item(k, ITEM.Property, "setting", `${k}: `)));
11232
11178
  for (const k of HEAD_KEYWORDS) out.push(item(k, ITEM.Keyword));
11233
11179
  for (const [k, kind] of PANELS) out.push(item(k, ITEM.Module, kind.syntax ?? "panel"));
@@ -11242,10 +11188,11 @@ var YuhwaService = class {
11242
11188
  else if (t.kind === "punct" && t.value === ":" && arrow) return [];
11243
11189
  }
11244
11190
  if (toks[0]?.value === "def" || toks[0]?.value === "import") return [];
11245
- return nodes();
11191
+ return ends();
11246
11192
  }
11247
11193
  /** what a `[...]` block on this line styles */
11248
11194
  statementKind(toks, props) {
11195
+ toks = unexported(toks);
11249
11196
  const head = toks[0];
11250
11197
  if (head.kind === "class") return "class";
11251
11198
  if (head.value === "group") return "group";
@@ -11295,6 +11242,16 @@ var YuhwaService = class {
11295
11242
  }
11296
11243
  return md(`**class** \`${name}\` is not defined`, o);
11297
11244
  }
11245
+ const span = spanAt(a.lines[p.line] ?? "", p.character);
11246
+ if (span) {
11247
+ const st = parseSpanStyle(span.spec);
11248
+ const parts = Object.entries(st).map(([k, v]) => `${k}: ${v}`);
11249
+ const keys = Object.entries(SPAN_KEYS).map(([k, { info }]) => `- \`${k}\`: ${info}`).join("\n");
11250
+ return md(`**style span** \`${parts.join(", ")}\`\n\nstyles the text after \`|\`. Keys:\n\n${keys}`, {
11251
+ start: span.at,
11252
+ end: span.at + span.spec.length
11253
+ });
11254
+ }
11298
11255
  const t = this.tokAt(a, p);
11299
11256
  if (!t) return null;
11300
11257
  if (t.kind === "class") return md(`**class** \`.${t.value}\` is not defined`, t);
@@ -11305,7 +11262,7 @@ var YuhwaService = class {
11305
11262
  return md(`**edge** \`${t.value}\`: ${ARROWS[m[2]]}, ${heads}`, t);
11306
11263
  }
11307
11264
  const toks = a.toks[p.line];
11308
- if (t === toks[0] && t.kind === "ident" && toks[1]?.value === ":" && a.depth[p.line] === 0) {
11265
+ if (t === toks[0] && t.kind === "ident" && toks[1]?.value === ":" && a.depth[p.line] === 0 && declAbove(a, p.line) < 0) {
11309
11266
  const key = t.value.toLowerCase();
11310
11267
  if (!KNOWN_SETTINGS.has(key)) return null;
11311
11268
  const vs = settingValues(key, a.diagram);
@@ -11321,7 +11278,10 @@ var YuhwaService = class {
11321
11278
  if (p.character < at || p.character > at + part.length) continue;
11322
11279
  const key = part.split(":")[0].trim().toLowerCase();
11323
11280
  const start = at + part.indexOf(part.trim());
11324
- return key && ALL_PROPS.includes(key) ? md(`**prop** \`${key}\`: ${propInfo(key)}`, {
11281
+ const kind = this.statementKind(toks, t);
11282
+ const panel = kind.startsWith("panel:") ? kind.slice(6) : void 0;
11283
+ const known = panel ? key in (PANELS.get(panel)?.options ?? {}) || PANEL_PROPS.includes(key) : ALL_PROPS.includes(key);
11284
+ return key && known ? md(`**prop** \`${key}\`: ${propInfo(key, panel)}`, {
11325
11285
  start,
11326
11286
  end: start + key.length
11327
11287
  }) : null;
@@ -11491,6 +11451,7 @@ var YuhwaService = class {
11491
11451
  const name = isClass && !newName.startsWith(".") ? "." + newName : newName;
11492
11452
  const t = lex(name).tokens;
11493
11453
  if (t.length !== 1 || t[0].end !== name.length || t[0].kind !== (isClass ? "class" : "ident") || name[0] === "$") return { error: `"${newName}" is not a valid ${isClass ? "class name" : "id"}` };
11454
+ if (HEAD_KEYWORDS.has(name) || PANELS.has(name)) return { error: `"${name}" is a keyword` };
11494
11455
  if (name !== o.key && a.kinds.has(name)) return { error: `"${name}" already exists` };
11495
11456
  return a.occ.filter((x) => x.key === o.key).map((x) => ({
11496
11457
  range: range(x.line, x.start, x.end),
@@ -11574,6 +11535,10 @@ var YuhwaService = class {
11574
11535
  format(text) {
11575
11536
  return diffEdits(text, format(text));
11576
11537
  }
11538
+ /** Re-indent after a newline or `}` was typed at `pos`. */
11539
+ onType(text, pos, ch) {
11540
+ return onTypeEdits(text, pos, ch);
11541
+ }
11577
11542
  folding(text, file) {
11578
11543
  const a = this.analyze(text, file);
11579
11544
  const out = a.blocks.filter(([s, e]) => e - 1 > s).map(([s, e]) => ({
@@ -11607,6 +11572,7 @@ var YuhwaService = class {
11607
11572
  * pushed (`publishDiagnostics`) to the rest, never both.
11608
11573
  */
11609
11574
  const REQUEST_FAILED = -32803;
11575
+ const DEBOUNCE_MS = 150;
11610
11576
  const defaultToPath = (uri) => {
11611
11577
  try {
11612
11578
  return decodeURIComponent(new URL(uri).pathname);
@@ -11628,7 +11594,9 @@ function startServer(connection, opts = {}) {
11628
11594
  const text = (uri) => docs.get(toPath(uri)) ?? "";
11629
11595
  let pull = false;
11630
11596
  let refresh = false;
11631
- const validate = () => {
11597
+ let watch = false;
11598
+ const publish = () => {
11599
+ timer = void 0;
11632
11600
  if (pull) {
11633
11601
  if (refresh) connection.languages.diagnostics.refresh().catch(() => {});
11634
11602
  return;
@@ -11638,6 +11606,11 @@ function startServer(connection, opts = {}) {
11638
11606
  diagnostics: service.diagnostics(src, path)
11639
11607
  });
11640
11608
  };
11609
+ let timer;
11610
+ const validate = () => {
11611
+ if (timer !== void 0) clearTimeout(timer);
11612
+ timer = setTimeout(publish, DEBOUNCE_MS);
11613
+ };
11641
11614
  const changed = (uri, src) => {
11642
11615
  const path = toPath(uri);
11643
11616
  if (src === void 0) {
@@ -11657,6 +11630,7 @@ function startServer(connection, opts = {}) {
11657
11630
  connection.onInitialize(({ capabilities: c }) => {
11658
11631
  pull = !!c.textDocument?.diagnostic;
11659
11632
  refresh = !!c.workspace?.diagnostics?.refreshSupport;
11633
+ watch = !!c.workspace?.didChangeWatchedFiles?.dynamicRegistration;
11660
11634
  return {
11661
11635
  capabilities: {
11662
11636
  positionEncoding: "utf-16",
@@ -11687,6 +11661,10 @@ function startServer(connection, opts = {}) {
11687
11661
  },
11688
11662
  codeActionProvider: { codeActionKinds: ["quickfix"] },
11689
11663
  documentFormattingProvider: true,
11664
+ documentOnTypeFormattingProvider: {
11665
+ firstTriggerCharacter: "\n",
11666
+ moreTriggerCharacter: ["}"]
11667
+ },
11690
11668
  ...pull && { diagnosticProvider: {
11691
11669
  interFileDependencies: true,
11692
11670
  workspaceDiagnostics: false
@@ -11695,6 +11673,9 @@ function startServer(connection, opts = {}) {
11695
11673
  serverInfo: { name: "yuhwa-lsp" }
11696
11674
  };
11697
11675
  });
11676
+ connection.onInitialized(() => {
11677
+ if (watch) connection.client.register(import_api.DidChangeWatchedFilesNotification.type, { watchers: [{ globPattern: "**/*.{yu,yuhwa}" }] }).catch(() => {});
11678
+ });
11698
11679
  connection.onDidOpenTextDocument((p) => changed(p.textDocument.uri, p.textDocument.text));
11699
11680
  connection.onDidChangeTextDocument((p) => {
11700
11681
  if (!p.contentChanges.length) return;
@@ -11711,6 +11692,7 @@ function startServer(connection, opts = {}) {
11711
11692
  items: service.diagnostics(text(p.textDocument.uri), toPath(p.textDocument.uri))
11712
11693
  }));
11713
11694
  connection.onDocumentFormatting((p) => service.format(text(p.textDocument.uri)));
11695
+ connection.onDocumentOnTypeFormatting((p) => service.onType(text(p.textDocument.uri), p.position, p.ch));
11714
11696
  connection.onCompletion((p) => service.completion(text(p.textDocument.uri), p.position, toPath(p.textDocument.uri)));
11715
11697
  connection.onHover((p) => service.hover(text(p.textDocument.uri), p.position, toPath(p.textDocument.uri)));
11716
11698
  connection.onDefinition((p) => {
@@ -11748,6 +11730,20 @@ function startServer(connection, opts = {}) {
11748
11730
  connection.listen();
11749
11731
  return service;
11750
11732
  }
11733
+ // src/lsp/uri.ts
11734
+ /**
11735
+ * Path of a `file:` URI with forward slashes on every platform (`C:/w/a.yu` on
11736
+ * Windows), so import paths, which always use `/`, join and compare with it.
11737
+ */
11738
+ function uriToPath(uri, windows = process.platform === "win32") {
11739
+ if (!uri.startsWith("file:")) return uri;
11740
+ const path = fileURLToPath(uri, { windows });
11741
+ return windows ? path.replace(/\\/g, "/") : path;
11742
+ }
11743
+ /** The `file:` URI of a path from `uriToPath`. */
11744
+ function pathToUri(path, windows = process.platform === "win32") {
11745
+ return pathToFileURL(path, { windows }).href;
11746
+ }
11751
11747
  // src/lsp/node.ts
11752
11748
  /**
11753
11749
  * `yuhwa-lsp`: the language server for editors. The transport comes from the
@@ -11775,7 +11771,7 @@ Usage: yuhwa-lsp [--stdio | --node-ipc | --socket=<port> | --pipe=<name>]
11775
11771
  if (!args.some((a) => /^--(stdio|node-ipc|socket|pipe)(=|$)/.test(a))) process.argv.push("--stdio");
11776
11772
  startServer((0, import_main.createConnection)(import_main.ProposedFeatures.all), {
11777
11773
  readFile: diskResolve,
11778
- toPath: (uri) => uri.startsWith("file:") ? fileURLToPath(uri) : uri,
11779
- toUri: (p) => pathToFileURL(p).href
11774
+ toPath: (uri) => uriToPath(uri),
11775
+ toUri: (p) => pathToUri(p)
11780
11776
  });
11781
11777
  export {};
@@ -6,5 +6,5 @@
6
6
  * Diagnostics are pulled (`textDocument/diagnostic`) by clients that can, and
7
7
  * pushed (`publishDiagnostics`) to the rest, never both.
8
8
  */
9
- import { n as startServer, t as ServerOptions } from "./server-DJC_fQMe.js";
9
+ import { n as startServer, t as ServerOptions } from "./server--jHjJjOS.js";
10
10
  export { ServerOptions, startServer };
@@ -1 +1 @@
1
- export { t as startServer } from "./server-DmQuHQrG.js";
1
+ export { t as startServer } from "./server-Dxo7OG8K.js";