yuhwa 1.0.2 → 1.1.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 +602 -44
  8. package/dist/editor/assets/index-BGtCSg84.js +689 -0
  9. package/dist/editor/assets/lsp.worker-DUpBJRU2.js +26 -0
  10. package/dist/editor/index.html +5 -4
  11. package/dist/figure-db587hh6.d.ts +48 -0
  12. package/dist/{index-Dl845tUQ.d.ts → index-CAO4FUcz.d.ts} +48 -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 +12 -8
  18. package/dist/lsp-browser.d.ts +2 -2
  19. package/dist/lsp-browser.js +1 -1
  20. package/dist/lsp-node.js +40 -182
  21. package/dist/lsp-server.d.ts +1 -1
  22. package/dist/lsp-server.js +1 -1
  23. package/dist/lsp.d.ts +1 -1
  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-DPojgovD.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-BSHSx8uo.d.ts} +2 -2
  31. package/dist/{server-DmQuHQrG.js → server-CT_mbBNZ.js} +1 -1
  32. package/dist/{service-BYS9Qfkq.js → service-CNM6Z-RH.js} +81 -16
  33. package/dist/{service-ClZ8clSQ.d.ts → service-DquYYTVG.d.ts} +1 -1
  34. package/dist/{shared-qo_r6RUN.js → shared-B2rP00uA.js} +2292 -429
  35. package/dist/{src-wk7tBpWs.js → src-hrqH-a8K.js} +2094 -407
  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 +90 -65
  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
@@ -1,4 +1,4 @@
1
- import { B as KNOWN_SETTINGS, G as joinPath, H as SETTING_VALUES, J as parse, K as lex, Ot as themeNames, U as blockBraces, V as PANELS, X as serializeProps, _ as isMermaid, at as NUMBERS, bt as TONES, ct as SHAPES, et as BOOLS, it as NODE_PROPS, nt as ENUMS, ot as PANEL_PROPS, rt as GROUP_PROPS, tt as EDGE_PROPS, vt as THEME_KEYS } from "./src-wk7tBpWs.js";
1
+ import { At as themeNames, G as blockBraces, H as KNOWN_SETTINGS, I as optionKind, J as lex, Q as serializeProps, St as TONES, U as PANELS, W as SETTING_VALUES, X as parse, _ as isMermaid, at as GROUP_PROPS, bt as THEME_KEYS, ct as PANEL_PROPS, it as ENUMS, nt as BOOLS, ot as NODE_PROPS, q as joinPath, rt as EDGE_PROPS, st as NUMBERS, ut as SHAPES } from "./src-hrqH-a8K.js";
2
2
  // src/lsp/format.ts
3
3
  /**
4
4
  * Formatting and text edits, without a parser of their own beyond `lex`.
@@ -163,6 +163,49 @@ function applyChange(text, change) {
163
163
  const b = Math.max(a, offsetAt(text, change.range.end));
164
164
  return text.slice(0, a) + change.text + text.slice(b);
165
165
  }
166
+ // src/core/tidy.ts
167
+ /**
168
+ * Hygiene rules for `yuhwa lint`. The diagram renders fine without fixing
169
+ * these, so `check` stays quiet about them: unused classes, variables and
170
+ * components, and edges written twice. A file that draws nothing is a library
171
+ * for importers, so its definitions count as used.
172
+ */
173
+ /** `toks`: per-line tokens the caller already has; an empty line entry is lexed here */
174
+ function tidy(source, d, toks) {
175
+ const out = [];
176
+ const warn = (code, line, message) => out.push({
177
+ line: line + 1,
178
+ message,
179
+ severity: "warning",
180
+ code
181
+ });
182
+ const library = !d.nodes.size && !d.edges.length && !d.panels.length;
183
+ const exported = new Set(d.exports ?? []);
184
+ const used = d.used ?? /* @__PURE__ */ new Set();
185
+ if (!library) {
186
+ const classes = Object.entries(d.classLines ?? {});
187
+ const applied = new Set(classes.length ? source.split(/\r?\n/).flatMap((l, li) => (toks?.[li]?.length ? toks[li] : lex(l).tokens).filter((t, i) => i && t.kind === "class").map((t) => t.value)) : []);
188
+ for (const [c, line] of classes) if (!exported.has("." + c) && !applied.has(c)) warn("unused-class", line, `Class .${c} is never used: apply it (node .${c}) or remove it`);
189
+ for (const [v, line] of Object.entries(d.varLines ?? {})) if (!exported.has("$" + v) && !used.has("$" + v)) warn("unused-variable", line, `Variable $${v} is never used: use it ($${v}) or remove it`);
190
+ for (const [f, line] of Object.entries(d.defLines ?? {})) if (!exported.has(f) && !used.has(f)) warn("unused-component", line, `Component ${f}() is never called: call it or remove it`);
191
+ }
192
+ const seen = /* @__PURE__ */ new Map();
193
+ for (const e of d.edges) {
194
+ if (!e.ref || e.ref.generated) continue;
195
+ const key = [
196
+ e.from,
197
+ e.to,
198
+ e.label ?? "",
199
+ e.line,
200
+ e.startHead,
201
+ e.endHead
202
+ ].join("\0");
203
+ const first = seen.get(key);
204
+ if (first === void 0) seen.set(key, e.ref.line);
205
+ else if (first !== e.ref.line) warn("duplicate-edge", e.ref.line, `Edge ${e.from} -> ${e.to} is already drawn on line ${first + 1}: remove one`);
206
+ }
207
+ return out;
208
+ }
166
209
  // src/lsp/service.ts
167
210
  /**
168
211
  * The yuhwa language service: plain functions from source text (and a
@@ -173,6 +216,8 @@ const SEVERITY = {
173
216
  error: 1,
174
217
  warning: 2
175
218
  };
219
+ const HINT = 4;
220
+ const UNNECESSARY = 1;
176
221
  const ITEM = {
177
222
  Function: 3,
178
223
  Variable: 6,
@@ -297,8 +342,18 @@ function inThemeBlock(a, line) {
297
342
  return t[t[0]?.value === "export" ? 1 : 0]?.value === "theme";
298
343
  }
299
344
  function propValues(key, panel, d) {
300
- const opts = panel ? PANELS.get(panel)?.options?.[key] : void 0;
301
- if (opts) return opts;
345
+ const opt = panel ? PANELS.get(panel)?.options?.[key] : void 0;
346
+ if (opt !== void 0) {
347
+ const o = optionKind(opt);
348
+ switch (o.kind) {
349
+ case "select": return [...o.values];
350
+ case "flag": return ["true", "false"];
351
+ case "color": return TONES;
352
+ case "number":
353
+ case "text": return [];
354
+ default: return o;
355
+ }
356
+ }
302
357
  if (panel && key === "frame") return ["false"];
303
358
  if (panel && key === "theme") return themeNames(d?.themes);
304
359
  if (panel && key === "border") return ["none", ...TONES];
@@ -434,15 +489,25 @@ var YuhwaService = class {
434
489
  }
435
490
  diagnostics(text, file) {
436
491
  const a = this.analyze(text, file);
437
- return a.diagram.diagnostics.map((d) => {
438
- const li = Math.min(Math.max(d.line - 1, 0), a.lines.length - 1);
439
- return {
440
- range: this.narrow(a, li, d.message),
492
+ const at = (line) => Math.min(Math.max(line - 1, 0), a.lines.length - 1);
493
+ const found = a.diagram.diagnostics.map((d) => ({
494
+ range: this.narrow(a, at(d.line), d.message),
495
+ message: d.message,
496
+ severity: SEVERITY[d.severity],
497
+ source: "yuhwa"
498
+ }));
499
+ for (const d of tidy(text, a.diagram, a.toks)) {
500
+ const li = at(d.line);
501
+ const l = a.lines[li];
502
+ found.push({
503
+ range: range(li, l.length - l.trimStart().length, l.trimEnd().length),
441
504
  message: d.message,
442
- severity: SEVERITY[d.severity],
443
- source: "yuhwa"
444
- };
445
- });
505
+ severity: HINT,
506
+ source: "yuhwa lint",
507
+ ...d.code?.startsWith("unused-") ? { tags: [UNNECESSARY] } : {}
508
+ });
509
+ }
510
+ return found;
446
511
  }
447
512
  /** Messages name only a line; point at the quoted word they complain about when it is there. */
448
513
  narrow(a, li, message) {
@@ -450,7 +515,7 @@ var YuhwaService = class {
450
515
  const { codeEnd } = lex(line);
451
516
  const start = Math.max(0, line.search(/\S/));
452
517
  const end = Math.max(start, line.slice(0, codeEnd).trimEnd().length);
453
- const quoted = /^\S+\.yuhwa:\d+:/i.test(message) ? void 0 : message.match(/"([^"\n]+)"/)?.[1];
518
+ const quoted = /^\S+\.(yu|yuhwa):\d+:/i.test(message) ? void 0 : message.match(/"([^"\n]+)"/)?.[1];
454
519
  const at = quoted ? line.indexOf(quoted) : -1;
455
520
  return at >= 0 && at < codeEnd ? range(li, at, at + quoted.length) : range(li, start, end);
456
521
  }
@@ -495,6 +560,7 @@ var YuhwaService = class {
495
560
  const values = (vs) => vs.map((v) => item(v, ITEM.Value));
496
561
  const themeKeyItems = () => Object.entries(THEME_KEYS).map(([k, { info }]) => item(k, ITEM.Property, info, `${k}: `));
497
562
  const nodes = () => [...d.nodes.values()].map((n) => item(n.id, ITEM.Variable, n.label !== n.id ? n.label : void 0));
563
+ const ends = () => [...nodes(), ...d.panels.map((x) => item(x.id, ITEM.Module, x.kind))];
498
564
  if (a.opaque[p.line]) return [];
499
565
  const toks = lex(line).tokens;
500
566
  const tok = toks.find((t) => t.start < p.character && p.character < t.end);
@@ -538,8 +604,7 @@ var YuhwaService = class {
538
604
  const lineStart = !before.slice(0, wordStart).trim();
539
605
  if (p.line > ls && p.line < le) {
540
606
  if (lineStart) return [
541
- ...nodes(),
542
- ...d.panels.map((x) => item(x.id, ITEM.Module, x.kind)),
607
+ ...ends(),
543
608
  ...[...new Set(d.edges.map((e) => e.key))].map((k) => item(k, ITEM.Variable, "edge")),
544
609
  item("rank", ITEM.Keyword)
545
610
  ];
@@ -556,7 +621,7 @@ var YuhwaService = class {
556
621
  }
557
622
  if (lineStart && inThemeBlock(a, p.line)) return themeKeyItems();
558
623
  if (lineStart) {
559
- const out = nodes();
624
+ const out = ends();
560
625
  if (a.depth[p.line] === 0) {
561
626
  out.push(...[...KNOWN_SETTINGS].map((k) => item(k, ITEM.Property, "setting", `${k}: `)));
562
627
  for (const k of HEAD_KEYWORDS) out.push(item(k, ITEM.Keyword));
@@ -572,7 +637,7 @@ var YuhwaService = class {
572
637
  else if (t.kind === "punct" && t.value === ":" && arrow) return [];
573
638
  }
574
639
  if (toks[0]?.value === "def" || toks[0]?.value === "import") return [];
575
- return nodes();
640
+ return ends();
576
641
  }
577
642
  /** what a `[...]` block on this line styles */
578
643
  statementKind(toks, props) {
@@ -2,7 +2,7 @@ import { A as Hover, C as DocumentHighlight, D as FoldingRange, H as Position, K
2
2
  interface ServiceOptions {
3
3
  /** Source of an imported file by its resolved path, as for `parse`; undefined when missing. */
4
4
  resolve?: (path: string) => string | undefined;
5
- /** Paths of the `.yuhwa` files an import may name, for completing import paths. */
5
+ /** Paths of the `.yu` files an import may name, for completing import paths. */
6
6
  files?: () => string[];
7
7
  }
8
8
  /** Where a definition lives: `file` is set when it is another file than the one asked about. */