@skillre/dsh-plugin-sticky-wall 0.9.1 → 0.9.3

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/lib/client.js CHANGED
@@ -229,6 +229,7 @@ window.__ModuleLoader__.load({
229
229
  "editorSaving": "\u4FDD\u5B58\u4E2D\u2026",
230
230
  "editorUnsaved": "\u672A\u4FDD\u5B58",
231
231
  "editorSaveFailed": "\u4FDD\u5B58\u5931\u8D25\uFF1A{message}",
232
+ "toolbarLabel": "\u7F16\u8F91\u5DE5\u5177\u680F",
232
233
  "toolbarStructure": "\u7ED3\u6784",
233
234
  "toolbarList": "\u5217\u8868",
234
235
  "toolbarTable": "\u8868\u683C",
@@ -335,6 +336,7 @@ window.__ModuleLoader__.load({
335
336
  "editorSaving": "Saving\u2026",
336
337
  "editorUnsaved": "Unsaved",
337
338
  "editorSaveFailed": "Save failed: {message}",
339
+ "toolbarLabel": "Formatting toolbar",
338
340
  "toolbarStructure": "Structure",
339
341
  "toolbarList": "Lists",
340
342
  "toolbarTable": "Table",
@@ -371,6 +373,369 @@ window.__ModuleLoader__.load({
371
373
  // src/client/view.tsx
372
374
  var import_react3 = require("react");
373
375
 
376
+ // src/markdown-parse.ts
377
+ var INDENT_WIDTH = 2;
378
+ var CODE_INDENT = 4;
379
+ var MAX_DEPTH = 12;
380
+ function stepBudget(lineCount) {
381
+ return Math.max(1e3, lineCount * 64);
382
+ }
383
+ var FENCE = /^(`{3,}|~{3,})\s*(.*)$/;
384
+ var HEADING = /^(#{1,6})\s+(.*)$/;
385
+ var RULE = /^(?:[-*_][ \t]*){3,}$/;
386
+ var BULLET = /^([-*+])[ \t]+(.*)$/;
387
+ var ORDERED = /^(\d{1,9})[.)][ \t]+(.*)$/;
388
+ var QUOTE = /^>[ \t]?(.*)$/;
389
+ var TABLE_DIVIDER = /^\|?[ \t]*:?-{2,}:?[ \t]*(?:\|[ \t]*:?-{2,}:?[ \t]*)*\|?[ \t]*$/;
390
+ function toLine(raw) {
391
+ let width = 0;
392
+ let index = 0;
393
+ while (index < raw.length) {
394
+ const char = raw[index];
395
+ if (char === " ") width += 1;
396
+ else if (char === " ") width += INDENT_WIDTH;
397
+ else break;
398
+ index += 1;
399
+ }
400
+ return { raw, indent: width, body: raw.slice(index) };
401
+ }
402
+ function stripColumns(raw, width) {
403
+ let consumed = 0;
404
+ let index = 0;
405
+ while (index < raw.length && consumed < width) {
406
+ const char = raw[index];
407
+ if (char === " ") {
408
+ consumed += 1;
409
+ index += 1;
410
+ } else if (char === " ") {
411
+ consumed += INDENT_WIDTH;
412
+ index += 1;
413
+ } else break;
414
+ }
415
+ return raw.slice(index);
416
+ }
417
+ function startsBlock(body) {
418
+ return FENCE.test(body) || HEADING.test(body) || RULE.test(body) || BULLET.test(body) || ORDERED.test(body) || QUOTE.test(body) || TABLE_DIVIDER.test(body);
419
+ }
420
+ function splitRow(line) {
421
+ const trimmed = line.trim().replace(/^\|/, "").replace(/\|$/, "");
422
+ return trimmed.split("|").map((cell) => cell.trim());
423
+ }
424
+ function parseAlign(divider) {
425
+ return splitRow(divider).map((cell) => {
426
+ const left = cell.startsWith(":");
427
+ const right = cell.endsWith(":");
428
+ if (left && right) return "center";
429
+ if (right) return "right";
430
+ if (left) return "left";
431
+ return null;
432
+ });
433
+ }
434
+ function tableAt(lines, at, to) {
435
+ if (at + 1 >= to) return false;
436
+ const header = lines[at];
437
+ const divider = lines[at + 1];
438
+ if (header === void 0 || divider === void 0) return false;
439
+ return header.body.includes("|") && TABLE_DIVIDER.test(divider.body);
440
+ }
441
+ function parseOne(lines, index, to, blocks, depth) {
442
+ const line = lines[index];
443
+ if (line === void 0) return index + 1;
444
+ if (depth >= MAX_DEPTH) {
445
+ const literal = [];
446
+ let cursor2 = index;
447
+ while (cursor2 < to) {
448
+ const candidate = lines[cursor2];
449
+ if (candidate === void 0) break;
450
+ literal.push(candidate.body);
451
+ cursor2 += 1;
452
+ }
453
+ const text = literal.join("\n").trim();
454
+ if (text !== "") blocks.push({ kind: "paragraph", text });
455
+ return to;
456
+ }
457
+ const fence = FENCE.exec(line.body);
458
+ if (fence !== null) {
459
+ const marker = fence[1] ?? "```";
460
+ const char = marker.charAt(0);
461
+ const info = (fence[2] ?? "").trim();
462
+ const language = info === "" ? "" : info.split(/[\s{]/)[0] ?? "";
463
+ const body2 = [];
464
+ let cursor2 = index + 1;
465
+ while (cursor2 < to) {
466
+ const candidate = lines[cursor2];
467
+ if (candidate === void 0) break;
468
+ const closing = FENCE.exec(candidate.body);
469
+ if (closing !== null) {
470
+ const closingMarker = closing[1] ?? "";
471
+ if (closingMarker.charAt(0) === char && closingMarker.length >= marker.length) break;
472
+ }
473
+ body2.push(stripColumns(candidate.raw, line.indent));
474
+ cursor2 += 1;
475
+ }
476
+ blocks.push({ kind: "code", text: body2.join("\n"), language });
477
+ return cursor2 < to ? cursor2 + 1 : to;
478
+ }
479
+ const heading = HEADING.exec(line.body);
480
+ if (heading !== null) {
481
+ const level = Math.min(6, (heading[1] ?? "#").length);
482
+ blocks.push({ kind: "heading", level, text: (heading[2] ?? "").trim() });
483
+ return index + 1;
484
+ }
485
+ if (RULE.test(line.body)) {
486
+ blocks.push({ kind: "rule" });
487
+ return index + 1;
488
+ }
489
+ if (QUOTE.test(line.body)) {
490
+ const inner = [];
491
+ let cursor2 = index;
492
+ while (cursor2 < to) {
493
+ const candidate = lines[cursor2];
494
+ if (candidate === void 0) break;
495
+ const match = QUOTE.exec(candidate.body);
496
+ if (match !== null) {
497
+ inner.push(toLine(match[1] ?? ""));
498
+ cursor2 += 1;
499
+ continue;
500
+ }
501
+ if (candidate.body === "") {
502
+ let probe = cursor2;
503
+ while (probe < to && lines[probe]?.body === "") probe += 1;
504
+ const next = lines[probe];
505
+ if (next !== void 0 && QUOTE.test(next.body)) {
506
+ for (let blank = cursor2; blank < probe; blank += 1) inner.push(toLine(""));
507
+ cursor2 = probe;
508
+ continue;
509
+ }
510
+ }
511
+ break;
512
+ }
513
+ blocks.push({ kind: "quote", children: parseRange(inner, 0, inner.length, depth + 1) });
514
+ return Math.max(cursor2, index + 1);
515
+ }
516
+ if (tableAt(lines, index, to)) {
517
+ const header = splitRow(line.body);
518
+ const divider = lines[index + 1];
519
+ const align = parseAlign(divider === void 0 ? "" : divider.body);
520
+ const rows = [];
521
+ let cursor2 = index + 2;
522
+ while (cursor2 < to) {
523
+ const candidate = lines[cursor2];
524
+ if (candidate === void 0) break;
525
+ if (candidate.body === "" || !candidate.body.includes("|")) break;
526
+ if (startsBlock(candidate.body) && !TABLE_DIVIDER.test(candidate.body)) break;
527
+ rows.push(splitRow(candidate.body));
528
+ cursor2 += 1;
529
+ }
530
+ blocks.push({ kind: "table", header, rows, align });
531
+ return cursor2;
532
+ }
533
+ const bullet = BULLET.exec(line.body);
534
+ const ordered = bullet === null ? ORDERED.exec(line.body) : null;
535
+ if (bullet !== null || ordered !== null) {
536
+ const isOrdered = ordered !== null;
537
+ const start = isOrdered ? Number(ordered[1] ?? "1") : 1;
538
+ const baseIndent = line.indent;
539
+ const items = [];
540
+ let cursor2 = index;
541
+ while (cursor2 < to) {
542
+ const candidate = lines[cursor2];
543
+ if (candidate === void 0) break;
544
+ if (candidate.indent !== baseIndent) break;
545
+ const marker = isOrdered ? ORDERED.exec(candidate.body) : BULLET.exec(candidate.body);
546
+ if (marker === null) break;
547
+ let paragraph = marker[2] ?? "";
548
+ const nested = [];
549
+ let separated = false;
550
+ let probe = cursor2 + 1;
551
+ while (probe < to) {
552
+ const next = lines[probe];
553
+ if (next === void 0) break;
554
+ if (next.body === "") {
555
+ let ahead = probe;
556
+ while (ahead < to && lines[ahead]?.body === "") ahead += 1;
557
+ const resumed = lines[ahead];
558
+ if (resumed !== void 0 && resumed.indent >= baseIndent + INDENT_WIDTH) {
559
+ for (let blank = probe; blank < ahead; blank += 1) nested.push("");
560
+ separated = true;
561
+ probe = ahead;
562
+ continue;
563
+ }
564
+ break;
565
+ }
566
+ if (next.indent < baseIndent + INDENT_WIDTH) break;
567
+ const deindented = stripColumns(next.raw, baseIndent + INDENT_WIDTH);
568
+ const deLine = toLine(deindented);
569
+ if (!separated && nested.length === 0 && !startsBlock(deLine.body)) {
570
+ paragraph = paragraph === "" ? deLine.body : `${paragraph}
571
+ ${deLine.body}`;
572
+ probe += 1;
573
+ continue;
574
+ }
575
+ nested.push(deindented);
576
+ probe += 1;
577
+ }
578
+ items.push({
579
+ text: paragraph,
580
+ children: nested.length > 0 ? parseRange(nested.map(toLine), 0, nested.length, depth + 1) : []
581
+ });
582
+ cursor2 = probe;
583
+ let skip = cursor2;
584
+ while (skip < to && lines[skip]?.body === "") skip += 1;
585
+ const sibling = lines[skip];
586
+ if (sibling !== void 0 && sibling.indent === baseIndent) {
587
+ const siblingMarker = isOrdered ? ORDERED.exec(sibling.body) : BULLET.exec(sibling.body);
588
+ if (siblingMarker !== null) {
589
+ cursor2 = skip;
590
+ continue;
591
+ }
592
+ }
593
+ break;
594
+ }
595
+ blocks.push({ kind: "list", ordered: isOrdered, start, items });
596
+ return Math.max(cursor2, index + 1);
597
+ }
598
+ const previous = index > 0 ? lines[index - 1] : void 0;
599
+ if (line.indent >= CODE_INDENT && (previous === void 0 || previous.body === "")) {
600
+ const body2 = [];
601
+ let cursor2 = index;
602
+ let lastContent = index;
603
+ while (cursor2 < to) {
604
+ const candidate = lines[cursor2];
605
+ if (candidate === void 0) break;
606
+ if (candidate.body === "") {
607
+ body2.push("");
608
+ cursor2 += 1;
609
+ continue;
610
+ }
611
+ if (candidate.indent < CODE_INDENT) break;
612
+ body2.push(stripColumns(candidate.raw, CODE_INDENT));
613
+ lastContent = cursor2;
614
+ cursor2 += 1;
615
+ }
616
+ while (body2.length > 0 && body2[body2.length - 1] === "") body2.pop();
617
+ blocks.push({ kind: "indentedCode", text: body2.join("\n") });
618
+ return lastContent + 1;
619
+ }
620
+ const body = [line.body];
621
+ let cursor = index + 1;
622
+ while (cursor < to) {
623
+ const next = lines[cursor];
624
+ if (next === void 0) break;
625
+ if (next.body === "") break;
626
+ if (startsBlock(next.body)) break;
627
+ if (tableAt(lines, cursor, to)) break;
628
+ body.push(next.body);
629
+ cursor += 1;
630
+ }
631
+ blocks.push({ kind: "paragraph", text: body.join("\n") });
632
+ return cursor;
633
+ }
634
+ function parseRange(lines, from, to, depth) {
635
+ const blocks = [];
636
+ let index = from;
637
+ const budget = stepBudget(Math.max(1, to - from));
638
+ for (let step = 0; index < to; step += 1) {
639
+ if (step > budget) break;
640
+ const line = lines[index];
641
+ if (line === void 0) break;
642
+ if (line.body === "") {
643
+ index += 1;
644
+ continue;
645
+ }
646
+ const next = parseOne(lines, index, to, blocks, depth);
647
+ index = next > index ? next : index + 1;
648
+ }
649
+ return blocks;
650
+ }
651
+ function parseBlocks(source) {
652
+ const text = typeof source === "string" ? source : "";
653
+ const lines = text.replace(/\r\n?/g, "\n").split("\n").map(toLine);
654
+ return parseRange(lines, 0, lines.length, 0);
655
+ }
656
+ function stripInlineMarkdown(text) {
657
+ let out = text;
658
+ out = out.replace(/\\([\\`*_{}[\]()#+\-.!>~|])/g, "$1");
659
+ out = out.replace(/!\[([^\]]*)\]\([^)\s]*\)/g, "$1");
660
+ out = out.replace(/\[([^\]]*)\]\([^)\s]*\)/g, "$1");
661
+ out = out.replace(/`+([^`]*)`+/g, "$1");
662
+ out = out.replace(/\*\*\*([^*]+)\*\*\*/g, "$1");
663
+ out = out.replace(/\*\*([^*]+)\*\*/g, "$1");
664
+ out = out.replace(/\*([^*]+)\*/g, "$1");
665
+ out = out.replace(/~~([^~]+)~~/g, "$1");
666
+ out = out.replace(/(^|[^A-Za-z0-9])___([^_]+)___(?![A-Za-z0-9])/g, "$1$2");
667
+ out = out.replace(/(^|[^A-Za-z0-9])__([^_]+)__(?![A-Za-z0-9])/g, "$1$2");
668
+ out = out.replace(/(^|[^A-Za-z0-9])_([^_]+)_(?![A-Za-z0-9])/g, "$1$2");
669
+ return out;
670
+ }
671
+ function flattenWhitespace(text) {
672
+ return text.replace(/\s+/g, " ").trim();
673
+ }
674
+ function truncateDigest(text, limit) {
675
+ if (text.length <= limit) return text;
676
+ let cut = limit;
677
+ const code = text.charCodeAt(cut - 1);
678
+ if (code >= 55296 && code <= 56319) cut -= 1;
679
+ return `${text.slice(0, cut).replace(/\s+$/, "")}\u2026`;
680
+ }
681
+ function firstVisibleText(block) {
682
+ switch (block.kind) {
683
+ case "rule":
684
+ return "";
685
+ case "code":
686
+ case "indentedCode":
687
+ return block.text.split("\n")[0] ?? "";
688
+ case "table":
689
+ return block.header.join(" ");
690
+ case "quote": {
691
+ for (const child of block.children) {
692
+ const text = firstVisibleText(child);
693
+ if (text !== "") return text;
694
+ }
695
+ return "";
696
+ }
697
+ case "list": {
698
+ for (const item of block.items) {
699
+ const own = item.text.replace(/^\[[ xX]\]\s*/, "");
700
+ if (own !== "") return own;
701
+ for (const child of item.children) {
702
+ const text = firstVisibleText(child);
703
+ if (text !== "") return text;
704
+ }
705
+ }
706
+ return "";
707
+ }
708
+ case "heading":
709
+ case "paragraph":
710
+ default:
711
+ return block.text;
712
+ }
713
+ }
714
+ function plainTextSummary(source, max = 90) {
715
+ const limit = Number.isFinite(max) ? Math.floor(max) : 0;
716
+ if (limit <= 0) return "";
717
+ const raw = typeof source === "string" ? source : "";
718
+ let blocks;
719
+ try {
720
+ blocks = parseBlocks(raw);
721
+ } catch {
722
+ return truncateDigest(flattenWhitespace(stripInlineMarkdown(raw)), limit);
723
+ }
724
+ for (const block of blocks) {
725
+ const candidate = firstVisibleText(block);
726
+ const digest = flattenWhitespace(stripInlineMarkdown(candidate));
727
+ if (digest !== "") return truncateDigest(digest, limit);
728
+ }
729
+ return "";
730
+ }
731
+ function safeHref(raw) {
732
+ const value = raw.trim();
733
+ if (value === "") return void 0;
734
+ if (/^(?:https?|mailto):/i.test(value)) return value;
735
+ if (/^www\./i.test(value)) return `https://${value}`;
736
+ return void 0;
737
+ }
738
+
374
739
  // src/layout.ts
375
740
  var GOLDEN_ANGLE = Math.PI * (3 - Math.sqrt(5));
376
741
  var PREVIEW_STEP = 196;
@@ -422,14 +787,7 @@ window.__ModuleLoader__.load({
422
787
  }
423
788
  function estimateHeight(note, width) {
424
789
  const columnsPerLine = columnsPerLineFor(width);
425
- let lines = 0;
426
- for (const paragraph of note.body.split("\n")) {
427
- if (paragraph.trim() === "") {
428
- lines += 0.4;
429
- continue;
430
- }
431
- lines += Math.max(1, Math.ceil(columns(paragraph.replace(/^[#>*\-+\d. ]+/u, "")) / columnsPerLine));
432
- }
790
+ let lines = bodyLines(note.body, columnsPerLine);
433
791
  if (note.title !== "") {
434
792
  const titleColumns = columnsPerLineFor(width, 0.92);
435
793
  lines += Math.max(1, Math.ceil(columns(note.title) / titleColumns));
@@ -443,6 +801,66 @@ window.__ModuleLoader__.load({
443
801
  const estimated = Math.round(58 + clamped * 19);
444
802
  return Math.min(estimated, MAX_CARD_HEIGHT[width]);
445
803
  }
804
+ function bodyLines(body, columnsPerLine) {
805
+ let lines = 0;
806
+ for (const block of parseBlocks(body)) {
807
+ lines += blockLines(block, columnsPerLine);
808
+ }
809
+ return lines;
810
+ }
811
+ function blockLines(block, columnsPerLine) {
812
+ switch (block.kind) {
813
+ case "rule":
814
+ return 1.2;
815
+ case "code":
816
+ case "indentedCode": {
817
+ const count = block.text === "" ? 1 : block.text.split("\n").length;
818
+ return count * 0.95 + 1.3;
819
+ }
820
+ case "table": {
821
+ const rows = block.rows.length + 1;
822
+ return rows * 1.25 + 0.6;
823
+ }
824
+ case "heading":
825
+ return Math.max(1, Math.ceil(columns(block.text) / columnsPerLine)) + 0.55;
826
+ case "quote":
827
+ case "paragraph":
828
+ return paragraphLines(block.kind === "quote" ? blockText(block) : block.text, columnsPerLine, 0) + (block.kind === "quote" ? 0.5 : 0.5);
829
+ case "list": {
830
+ let lines = 0.5;
831
+ for (const item of block.items) {
832
+ const marker = 2;
833
+ lines += paragraphLines(item.text, Math.max(8, columnsPerLine - marker), 0);
834
+ for (const child of item.children) lines += blockLines(child, Math.max(8, columnsPerLine - 2));
835
+ lines += 0.12;
836
+ }
837
+ return lines;
838
+ }
839
+ default:
840
+ return 1;
841
+ }
842
+ }
843
+ function blockText(block) {
844
+ const parts = [];
845
+ for (const child of block.kind === "quote" ? block.children : []) {
846
+ if (child.kind === "paragraph" || child.kind === "heading") parts.push(child.text);
847
+ else if (child.kind === "list") parts.push(child.items.map((item) => item.text).join(" "));
848
+ else if (child.kind === "code" || child.kind === "indentedCode") parts.push(child.text);
849
+ else if (child.kind === "table") parts.push(child.header.join(" "));
850
+ }
851
+ return parts.join("\n");
852
+ }
853
+ function paragraphLines(text, columnsPerLine, extra) {
854
+ let lines = extra;
855
+ for (const part of text.split("\n")) {
856
+ if (part.trim() === "") {
857
+ lines += 0.4;
858
+ continue;
859
+ }
860
+ lines += Math.max(1, Math.ceil(columns(part) / columnsPerLine));
861
+ }
862
+ return lines;
863
+ }
446
864
  function columnsPerLineFor(width, density = 1) {
447
865
  return Math.max(8, Math.floor((WIDTH_PX[width] - 26) / 7.1 * density));
448
866
  }
@@ -518,212 +936,176 @@ window.__ModuleLoader__.load({
518
936
 
519
937
  // src/client/markdown.tsx
520
938
  var import_jsx_runtime = require("react/jsx-runtime");
521
- var FENCE = /^(```|~~~)\s*([A-Za-z0-9_+-]*)\s*$/;
522
- var HEADING = /^(#{1,4})\s+(.*)$/;
523
- var RULE = /^(?:[-*_]\s*){3,}$/;
524
- var BULLET = /^[-*+]\s+(.*)$/;
525
- var ORDERED = /^\d{1,3}[.)]\s+(.*)$/;
526
- var QUOTE = /^>\s?(.*)$/;
527
- var TABLE_DIVIDER = /^\|?\s*:?-{2,}:?\s*(?:\|\s*:?-{2,}:?\s*)*\|?\s*$/;
528
- function splitRow(line) {
529
- const trimmed = line.trim().replace(/^\|/, "").replace(/\|$/, "");
530
- return trimmed.split("|").map((cell) => cell.trim());
939
+ var TASK = /^\[([ xX])\][ \t]+([\s\S]*)$/;
940
+ var ESCAPABLE = /* @__PURE__ */ new Set(["\\", "`", "*", "_", "{", "}", "[", "]", "(", ")", "#", "+", "-", ".", "!", ">", "~", "|"]);
941
+ function runLength(text, from, char) {
942
+ let length = 0;
943
+ while (text.charAt(from + length) === char) length += 1;
944
+ return length;
531
945
  }
532
- function parseBlocks(source) {
533
- const lines = source.replace(/\r\n?/g, "\n").split("\n");
534
- const blocks = [];
535
- let index = 0;
536
- while (index < lines.length) {
537
- const line = lines[index] ?? "";
538
- if (line.trim() === "") {
539
- index += 1;
540
- continue;
541
- }
542
- const fence = line.trim().match(FENCE);
543
- if (fence !== null) {
544
- const marker = fence[1] ?? "```";
545
- const language = fence[2] ?? "";
546
- const body2 = [];
547
- index += 1;
548
- while (index < lines.length && (lines[index] ?? "").trim() !== marker) {
549
- body2.push(lines[index] ?? "");
550
- index += 1;
551
- }
552
- if (index < lines.length) index += 1;
553
- blocks.push({ kind: "code", text: body2.join("\n"), language });
946
+ function isWordChar(text, at) {
947
+ const char = text.charAt(at);
948
+ if (char === "") return false;
949
+ return /[A-Za-z0-9]/.test(char);
950
+ }
951
+ function findClosing(text, from, delimiter) {
952
+ const char = delimiter.charAt(0);
953
+ const underscore = char === "_";
954
+ let index = from;
955
+ while (index < text.length) {
956
+ const found = text.indexOf(delimiter, index);
957
+ if (found === -1) return -1;
958
+ let backslashes = 0;
959
+ for (let probe = found - 1; probe >= 0 && text.charAt(probe) === "\\"; probe -= 1) backslashes += 1;
960
+ if (backslashes % 2 === 1) {
961
+ index = found + delimiter.length;
554
962
  continue;
555
963
  }
556
- const heading = line.match(HEADING);
557
- if (heading !== null) {
558
- const level = Math.min(4, (heading[1] ?? "#").length);
559
- blocks.push({ kind: "heading", level, text: (heading[2] ?? "").trim() });
560
- index += 1;
964
+ if (underscore && isWordChar(text, found + delimiter.length)) {
965
+ index = found + delimiter.length;
561
966
  continue;
562
967
  }
563
- if (RULE.test(line.trim())) {
564
- blocks.push({ kind: "rule" });
565
- index += 1;
968
+ if (runLength(text, found, char) < delimiter.length) {
969
+ index = found + 1;
566
970
  continue;
567
971
  }
568
- if (QUOTE.test(line.trim())) {
569
- const body2 = [];
570
- while (index < lines.length) {
571
- const current = lines[index] ?? "";
572
- const match = current.match(QUOTE);
573
- if (match === null) break;
574
- body2.push(match[1] ?? "");
575
- index += 1;
972
+ return found;
973
+ }
974
+ return -1;
975
+ }
976
+ function renderInline(text, keyPrefix = "i") {
977
+ const nodes = [];
978
+ let buffer = "";
979
+ let counter = 0;
980
+ let index = 0;
981
+ const nextKey = () => `${keyPrefix}-${counter++}`;
982
+ const flush = () => {
983
+ if (buffer === "") return;
984
+ const parts = buffer.split("\n");
985
+ parts.forEach((part, position) => {
986
+ if (part !== "") nodes.push(part);
987
+ if (position < parts.length - 1) nodes.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}, nextKey()));
988
+ });
989
+ buffer = "";
990
+ };
991
+ while (index < text.length) {
992
+ const char = text.charAt(index);
993
+ if (char === "\\") {
994
+ const escaped = text.charAt(index + 1);
995
+ if (ESCAPABLE.has(escaped)) {
996
+ buffer += escaped;
997
+ index += 2;
998
+ continue;
576
999
  }
577
- blocks.push({ kind: "quote", text: body2.join("\n").trim() });
578
- continue;
579
1000
  }
580
- if (line.includes("|") && TABLE_DIVIDER.test(lines[index + 1] ?? "")) {
581
- const header = splitRow(line);
582
- const rows = [];
583
- index += 2;
584
- while (index < lines.length && (lines[index] ?? "").includes("|") && (lines[index] ?? "").trim() !== "") {
585
- rows.push(splitRow(lines[index] ?? ""));
586
- index += 1;
1001
+ if (char === "`") {
1002
+ const open = runLength(text, index, "`");
1003
+ const closing = findClosing(text, index + open, "`".repeat(open));
1004
+ if (closing !== -1) {
1005
+ flush();
1006
+ const inner = text.slice(index + open, closing);
1007
+ const trimmed = inner.length > 2 && inner.startsWith(" ") && inner.endsWith(" ") ? inner.slice(1, -1) : inner;
1008
+ nodes.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { className: "skw-md-code", children: trimmed }, nextKey()));
1009
+ index = closing + open;
1010
+ continue;
587
1011
  }
588
- blocks.push({ kind: "table", header, rows });
1012
+ buffer += "`".repeat(open);
1013
+ index += open;
589
1014
  continue;
590
1015
  }
591
- if (BULLET.test(line.trim()) || ORDERED.test(line.trim())) {
592
- const ordered = ORDERED.test(line.trim());
593
- const items = [];
594
- while (index < lines.length) {
595
- const current = lines[index] ?? "";
596
- const match = current.trim().match(ordered ? ORDERED : BULLET);
597
- if (match === null) break;
598
- items.push((match[1] ?? "").trim());
599
- index += 1;
1016
+ if (char === "*" || char === "_") {
1017
+ const run = runLength(text, index, char);
1018
+ const opens = char !== "_" || !isWordChar(text, index - 1);
1019
+ if (opens && run >= 3) {
1020
+ const delimiter = char.repeat(3);
1021
+ const closing = findClosing(text, index + 3, delimiter);
1022
+ if (closing > index + 3) {
1023
+ flush();
1024
+ nodes.push(
1025
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("em", { children: renderInline(text.slice(index + 3, closing), `${keyPrefix}-se`) }) }, nextKey())
1026
+ );
1027
+ index = closing + 3;
1028
+ continue;
1029
+ }
1030
+ }
1031
+ if (opens && run >= 2) {
1032
+ const delimiter = char + char;
1033
+ const closing = findClosing(text, index + 2, delimiter);
1034
+ if (closing > index + 2) {
1035
+ flush();
1036
+ nodes.push(
1037
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: renderInline(text.slice(index + 2, closing), `${keyPrefix}-s`) }, nextKey())
1038
+ );
1039
+ index = closing + 2;
1040
+ continue;
1041
+ }
600
1042
  }
601
- blocks.push({ kind: "list", ordered, items });
1043
+ if (opens && run === 1) {
1044
+ const closing = findClosing(text, index + 1, char);
1045
+ if (closing > index + 1) {
1046
+ flush();
1047
+ nodes.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("em", { children: renderInline(text.slice(index + 1, closing), `${keyPrefix}-e`) }, nextKey()));
1048
+ index = closing + 1;
1049
+ continue;
1050
+ }
1051
+ }
1052
+ buffer += char.repeat(run);
1053
+ index += run;
602
1054
  continue;
603
1055
  }
604
- const body = [line.trim()];
605
- index += 1;
606
- while (index < lines.length) {
607
- const current = lines[index] ?? "";
608
- if (current.trim() === "") break;
609
- if (FENCE.test(current.trim()) || HEADING.test(current) || RULE.test(current.trim())) break;
610
- if (BULLET.test(current.trim()) || ORDERED.test(current.trim()) || QUOTE.test(current.trim())) break;
611
- body.push(current.trim());
612
- index += 1;
613
- }
614
- blocks.push({ kind: "paragraph", text: body.join("\n") });
615
- }
616
- return blocks;
617
- }
618
- function stripInlineMarkdown(text) {
619
- let out = text;
620
- out = out.replace(/!\[([^\]]*)\]\([^)\s]*\)/g, "$1");
621
- out = out.replace(/\[([^\]]*)\]\([^)\s]*\)/g, "$1");
622
- out = out.replace(/`+([^`]*)`+/g, "$1");
623
- out = out.replace(/\*\*\*([^*]+)\*\*\*/g, "$1");
624
- out = out.replace(/\*\*([^*]+)\*\*/g, "$1");
625
- out = out.replace(/\*([^*]+)\*/g, "$1");
626
- out = out.replace(/~~([^~]+)~~/g, "$1");
627
- out = out.replace(/(^|[^A-Za-z0-9])__([^_]+)__(?![A-Za-z0-9])/g, "$1$2");
628
- out = out.replace(/(^|[^A-Za-z0-9])_([^_]+)_(?![A-Za-z0-9])/g, "$1$2");
629
- return out;
630
- }
631
- function flattenWhitespace(text) {
632
- return text.replace(/\s+/g, " ").trim();
633
- }
634
- function truncateDigest(text, limit) {
635
- if (text.length <= limit) return text;
636
- let cut = limit;
637
- const code = text.charCodeAt(cut - 1);
638
- if (code >= 55296 && code <= 56319) cut -= 1;
639
- return `${text.slice(0, cut).replace(/\s+$/, "")}\u2026`;
640
- }
641
- function plainTextSummary(source, max = 90) {
642
- const limit = Number.isFinite(max) ? Math.floor(max) : 0;
643
- if (limit <= 0) return "";
644
- const raw = typeof source === "string" ? source : "";
645
- let blocks;
646
- try {
647
- blocks = parseBlocks(raw);
648
- } catch {
649
- return truncateDigest(flattenWhitespace(stripInlineMarkdown(raw)), limit);
650
- }
651
- for (const block of blocks) {
652
- if (block.kind === "rule") continue;
653
- let candidate;
654
- if (block.kind === "code") {
655
- candidate = block.text.split("\n")[0] ?? "";
656
- } else if (block.kind === "list") {
657
- candidate = (block.items[0] ?? "").replace(/^\[[ xX]\]\s*/, "");
658
- } else if (block.kind === "table") {
659
- candidate = block.header.join(" ");
660
- } else {
661
- candidate = block.text;
1056
+ if (char === "~" && text.startsWith("~~", index)) {
1057
+ const closing = findClosing(text, index + 2, "~~");
1058
+ if (closing > index + 2) {
1059
+ flush();
1060
+ nodes.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("s", { children: renderInline(text.slice(index + 2, closing), `${keyPrefix}-d`) }, nextKey()));
1061
+ index = closing + 2;
1062
+ continue;
1063
+ }
662
1064
  }
663
- const digest = flattenWhitespace(stripInlineMarkdown(candidate));
664
- if (digest !== "") return truncateDigest(digest, limit);
665
- }
666
- return "";
667
- }
668
- function safeHref(raw) {
669
- const value = raw.trim();
670
- if (value === "") return void 0;
671
- if (/^(?:https?|mailto):/i.test(value)) return value;
672
- if (/^www\./i.test(value)) return `https://${value}`;
673
- return void 0;
674
- }
675
- function renderInline(text, keyPrefix = "i") {
676
- const nodes = [];
677
- let rest = text;
678
- let counter = 0;
679
- const pattern = /(`[^`]+`)|(\*\*[^*]+\*\*)|(\*[^*]+\*)|(_[^_]+_)|(~~[^~]+~~)|(\[[^\]]+\]\([^)\s]+\))|((?:https?:\/\/|www\.)[^\s<>()]+)/g;
680
- let match;
681
- while ((match = pattern.exec(rest)) !== null) {
682
- if (match.index > 0) {
683
- const head = rest.slice(0, match.index);
684
- const parts = head.split("\n");
685
- parts.forEach((part, position) => {
686
- if (part !== "") nodes.push(part);
687
- if (position < parts.length - 1) nodes.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}, `${keyPrefix}-br-${counter++}`));
688
- });
1065
+ if (char === "[") {
1066
+ const match = /^\[([^\]]*)\]\(((?:[^()\s]|\([^()\s]*\))*)\)/.exec(text.slice(index));
1067
+ if (match !== null) {
1068
+ flush();
1069
+ const label = match[1] ?? "";
1070
+ const href = safeHref(match[2] ?? "");
1071
+ nodes.push(
1072
+ href === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: label }, nextKey()) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { className: "skw-md-link", href, target: "_blank", rel: "noreferrer noopener", children: renderInline(label, `${keyPrefix}-l`) }, nextKey())
1073
+ );
1074
+ index += match[0].length;
1075
+ continue;
1076
+ }
689
1077
  }
690
- const token = match[0];
691
- const key = `${keyPrefix}-${counter++}`;
692
- if (token.startsWith("`")) {
693
- nodes.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { className: "skw-md-code", children: token.slice(1, -1) }, key));
694
- } else if (token.startsWith("**")) {
695
- nodes.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: renderInline(token.slice(2, -2), `${key}s`) }, key));
696
- } else if (token.startsWith("~~")) {
697
- nodes.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("s", { children: renderInline(token.slice(2, -2), `${key}s`) }, key));
698
- } else if (token.startsWith("*")) {
699
- nodes.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("em", { children: renderInline(token.slice(1, -1), `${key}e`) }, key));
700
- } else if (token.startsWith("_")) {
701
- nodes.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("em", { children: renderInline(token.slice(1, -1), `${key}e`) }, key));
702
- } else if (token.startsWith("[")) {
703
- const split = token.match(/\[([^\]]+)\]\(([^)\s]+)\)/);
704
- const label = split?.[1] ?? token;
705
- const href = safeHref(split?.[2] ?? "");
706
- nodes.push(
707
- href === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: label }, key) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { className: "skw-md-link", href, target: "_blank", rel: "noreferrer noopener", children: renderInline(label, `${key}l`) }, key)
708
- );
709
- } else {
710
- const href = safeHref(token);
711
- nodes.push(
712
- href === void 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: token }, key) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { className: "skw-md-link", href, target: "_blank", rel: "noreferrer noopener", children: token }, key)
713
- );
1078
+ if (char === "h" || char === "w") {
1079
+ const match = /^(?:https?:\/\/|www\.)[^\s<>()]+/.exec(text.slice(index));
1080
+ if (match !== null) {
1081
+ const raw = match[0];
1082
+ const trimmed = raw.replace(/[.,;:!?]+$/, "");
1083
+ const href = safeHref(trimmed);
1084
+ if (href !== void 0) {
1085
+ flush();
1086
+ nodes.push(
1087
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { className: "skw-md-link", href, target: "_blank", rel: "noreferrer noopener", children: trimmed }, nextKey())
1088
+ );
1089
+ index += trimmed.length;
1090
+ continue;
1091
+ }
1092
+ }
714
1093
  }
715
- rest = rest.slice(match.index + token.length);
716
- pattern.lastIndex = 0;
717
- }
718
- if (rest !== "") {
719
- const parts = rest.split("\n");
720
- parts.forEach((part, position) => {
721
- if (part !== "") nodes.push(part);
722
- if (position < parts.length - 1) nodes.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}, `${keyPrefix}-br-${counter++}`));
723
- });
1094
+ buffer += char;
1095
+ index += 1;
724
1096
  }
1097
+ flush();
725
1098
  return nodes;
726
1099
  }
1100
+ function renderTask(item, key) {
1101
+ const match = TASK.exec(item);
1102
+ if (match === null) return renderInline(item, key);
1103
+ const checked = (match[1] ?? " ") !== " ";
1104
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "skw-md-task", "data-checked": checked, children: [
1105
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "skw-md-box", "aria-hidden": "true", children: checked ? "\u2713" : "" }),
1106
+ renderInline(match[2] ?? "", `${key}t`)
1107
+ ] }, key);
1108
+ }
727
1109
  function renderBlock(block, key) {
728
1110
  switch (block.kind) {
729
1111
  case "heading": {
@@ -731,41 +1113,55 @@ window.__ModuleLoader__.load({
731
1113
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tag, { className: "skw-md-heading", children: renderInline(block.text, `${key}h`) }, key);
732
1114
  }
733
1115
  case "code":
734
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "skw-md-pre", "data-language": block.language || void 0, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: block.text }) }, key);
1116
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "skw-md-pre", "data-language": block.language === "" ? void 0 : block.language, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: block.text }) }, key);
1117
+ case "indentedCode":
1118
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "skw-md-pre", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: block.text }) }, key);
735
1119
  case "quote":
736
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("blockquote", { className: "skw-md-quote", children: renderInline(block.text, `${key}q`) }, key);
1120
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("blockquote", { className: "skw-md-quote", children: block.children.map((child, position) => renderBlock(child, `${key}q${position}`)) }, key);
737
1121
  case "rule":
738
1122
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("hr", { className: "skw-md-rule" }, key);
739
- case "list":
740
- return block.ordered ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ol", { className: "skw-md-list", children: block.items.map((item, position) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: renderTask(item, `${key}-${position}`) }, `${key}-${position}`)) }, key) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { className: "skw-md-list", children: block.items.map((item, position) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: renderTask(item, `${key}-${position}`) }, `${key}-${position}`)) }, key);
1123
+ case "list": {
1124
+ const Tag = block.ordered ? "ol" : "ul";
1125
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Tag, { className: "skw-md-list", start: block.ordered && block.start !== 1 ? block.start : void 0, children: block.items.map((item, position) => {
1126
+ const itemKey = `${key}-${position}`;
1127
+ const hasChildren = item.children.length > 0;
1128
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", { children: [
1129
+ item.text === "" ? null : renderTask(item.text, `${itemKey}t`),
1130
+ hasChildren ? item.children.map((child, childIndex) => renderBlock(child, `${itemKey}c${childIndex}`)) : null
1131
+ ] }, itemKey);
1132
+ }) }, key);
1133
+ }
741
1134
  case "table":
742
1135
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", { className: "skw-md-table", children: [
743
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: block.header.map((cell, position) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { children: renderInline(cell, `${key}h${position}`) }, `${key}-h-${position}`)) }) }),
744
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { children: block.rows.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: row.map((cell, position) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { children: renderInline(cell, `${key}r${rowIndex}${position}`) }, `${key}-r-${rowIndex}-${position}`)) }, `${key}-r-${rowIndex}`)) })
1136
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: block.header.map((cell, position) => {
1137
+ const align = block.align[position] ?? null;
1138
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { style: align === null ? void 0 : { textAlign: align }, children: renderInline(cell, `${key}h${position}`) }, `${key}-h-${position}`);
1139
+ }) }) }),
1140
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { children: block.rows.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: row.map((cell, position) => {
1141
+ const align = block.align[position] ?? null;
1142
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { style: align === null ? void 0 : { textAlign: align }, children: renderInline(cell, `${key}r${rowIndex}${position}`) }, `${key}-r-${rowIndex}-${position}`);
1143
+ }) }, `${key}-r-${rowIndex}`)) })
745
1144
  ] }, key);
746
1145
  case "paragraph":
747
1146
  default:
748
1147
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "skw-md-p", children: renderInline(block.text, `${key}p`) }, key);
749
1148
  }
750
1149
  }
751
- function renderTask(item, key) {
752
- const match = item.match(/^\[( |x|X)\]\s+(.*)$/);
753
- if (match === null) return renderInline(item, key);
754
- const checked = (match[1] ?? " ") !== " ";
755
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "skw-md-task", "data-checked": checked, children: [
756
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "skw-md-box", "aria-hidden": "true", children: checked ? "\u2713" : "" }),
757
- renderInline(match[2] ?? "", `${key}t`)
758
- ] }, key);
759
- }
760
1150
  function Markdown({ source, compact = false }) {
761
- const blocks = parseBlocks(source);
1151
+ let blocks;
1152
+ try {
1153
+ blocks = parseBlocks(source);
1154
+ } catch {
1155
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "skw-md", "data-compact": compact, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "skw-md-p", children: typeof source === "string" ? source : "" }) });
1156
+ }
762
1157
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "skw-md", "data-compact": compact, children: blocks.map((block, index) => renderBlock(block, `b${index}`)) });
763
1158
  }
764
1159
 
765
1160
  // src/client/editor.tsx
766
1161
  var import_react = require("react");
767
1162
  var import_jsx_runtime2 = require("react/jsx-runtime");
768
- var INDENT = " ";
1163
+ var INDENT_WIDTH2 = 2;
1164
+ var INDENT = " ".repeat(INDENT_WIDTH2);
769
1165
  var MIN_HEIGHT_PX = 88;
770
1166
  var VIEWPORT_SHARE = 0.6;
771
1167
  function clampRange(value, start, end) {
@@ -927,38 +1323,46 @@ window.__ModuleLoader__.load({
927
1323
  \`\`\``;
928
1324
  return insertBlock(ctx, block, 4 + body.length);
929
1325
  }
930
- var TOOLBAR_LABEL = { zh: "\u7F16\u8F91\u5DE5\u5177\u680F", en: "Formatting toolbar" };
1326
+ var TOOLBAR_LABEL = {
1327
+ key: "toolbarLabel",
1328
+ zh: "\u7F16\u8F91\u5DE5\u5177\u680F",
1329
+ en: "Formatting toolbar"
1330
+ };
931
1331
  var TOOLBAR = [
932
1332
  {
933
1333
  id: "structure",
1334
+ key: "toolbarStructure",
934
1335
  zh: "\u7ED3\u6784",
935
1336
  en: "Structure",
936
1337
  actions: [
937
- { id: "h1", zh: "\u4E00\u7EA7\u6807\u9898", en: "Heading 1", glyph: "H1", run: applyHeading(1) },
938
- { id: "h2", zh: "\u4E8C\u7EA7\u6807\u9898", en: "Heading 2", glyph: "H2", run: applyHeading(2) },
939
- { id: "h3", zh: "\u4E09\u7EA7\u6807\u9898", en: "Heading 3", glyph: "H3", run: applyHeading(3) },
940
- { id: "quote", zh: "\u5F15\u7528", en: "Blockquote", glyph: "\u275D", run: applyQuote },
941
- { id: "rule", zh: "\u5206\u5272\u7EBF", en: "Divider", glyph: "\u2014", run: (ctx) => insertBlock(ctx, "---", 4) },
942
- { id: "code-block", zh: "\u4EE3\u7801\u5757", en: "Code block", glyph: "{ }", run: insertCodeBlock }
1338
+ { id: "h1", key: "mdH1", zh: "\u4E00\u7EA7\u6807\u9898", en: "Heading 1", glyph: "H1", run: applyHeading(1) },
1339
+ { id: "h2", key: "mdH2", zh: "\u4E8C\u7EA7\u6807\u9898", en: "Heading 2", glyph: "H2", run: applyHeading(2) },
1340
+ { id: "h3", key: "mdH3", zh: "\u4E09\u7EA7\u6807\u9898", en: "Heading 3", glyph: "H3", run: applyHeading(3) },
1341
+ { id: "quote", key: "mdQuote", zh: "\u5F15\u7528", en: "Blockquote", glyph: "\u275D", run: applyQuote },
1342
+ { id: "rule", key: "mdHr", zh: "\u5206\u5272\u7EBF", en: "Divider", glyph: "\u2014", run: (ctx) => insertBlock(ctx, "---", 4) },
1343
+ { id: "code-block", key: "mdCodeBlock", zh: "\u4EE3\u7801\u5757", en: "Code block", glyph: "{ }", run: insertCodeBlock }
943
1344
  ]
944
1345
  },
945
1346
  {
946
1347
  id: "lists",
1348
+ key: "toolbarList",
947
1349
  zh: "\u5217\u8868",
948
1350
  en: "Lists",
949
1351
  actions: [
950
- { id: "bullet", zh: "\u65E0\u5E8F\u5217\u8868", en: "Bullet list", glyph: "\u2022", run: applyList("bullet") },
951
- { id: "ordered", zh: "\u6709\u5E8F\u5217\u8868", en: "Numbered list", glyph: "1.", run: applyList("ordered") },
952
- { id: "todo", zh: "\u5F85\u529E", en: "Todo", glyph: "\u2611", run: applyList("todo") }
1352
+ { id: "bullet", key: "mdBullet", zh: "\u65E0\u5E8F\u5217\u8868", en: "Bullet list", glyph: "\u2022", run: applyList("bullet") },
1353
+ { id: "ordered", key: "mdOrdered", zh: "\u6709\u5E8F\u5217\u8868", en: "Numbered list", glyph: "1.", run: applyList("ordered") },
1354
+ { id: "todo", key: "mdTodo", zh: "\u5F85\u529E", en: "Todo", glyph: "\u2611", run: applyList("todo") }
953
1355
  ]
954
1356
  },
955
1357
  {
956
1358
  id: "table",
1359
+ key: "toolbarTable",
957
1360
  zh: "\u8868\u683C",
958
1361
  en: "Table",
959
1362
  actions: [
960
1363
  {
961
1364
  id: "table",
1365
+ key: "mdTable",
962
1366
  zh: "\u63D2\u5165\u8868\u683C",
963
1367
  en: "Insert table",
964
1368
  glyph: "\u25A6",
@@ -971,52 +1375,157 @@ window.__ModuleLoader__.load({
971
1375
  },
972
1376
  {
973
1377
  id: "inline",
1378
+ key: "toolbarInline",
974
1379
  zh: "\u884C\u5185",
975
1380
  en: "Inline",
976
1381
  actions: [
977
- { id: "bold", zh: "\u7C97\u4F53", en: "Bold", glyph: "B", style: "bold", run: (ctx) => wrapSelection(ctx, "**", "**") },
978
- { id: "italic", zh: "\u659C\u4F53", en: "Italic", glyph: "I", style: "italic", run: (ctx) => wrapSelection(ctx, "_", "_") },
979
- { id: "strike", zh: "\u5220\u9664\u7EBF", en: "Strikethrough", glyph: "S", style: "strike", run: (ctx) => wrapSelection(ctx, "~~", "~~") },
980
- { id: "code", zh: "\u884C\u5185\u4EE3\u7801", en: "Inline code", glyph: "<>", run: (ctx) => wrapSelection(ctx, "`", "`") },
981
- { id: "link", zh: "\u94FE\u63A5", en: "Link", glyph: "\u26D3", run: (ctx) => wrapSelection(ctx, "[", "](https://)") }
1382
+ { id: "bold", key: "mdBold", zh: "\u7C97\u4F53", en: "Bold", glyph: "B", style: "bold", run: (ctx) => wrapSelection(ctx, "**", "**") },
1383
+ { id: "italic", key: "mdItalic", zh: "\u659C\u4F53", en: "Italic", glyph: "I", style: "italic", run: (ctx) => wrapSelection(ctx, "_", "_") },
1384
+ { id: "strike", key: "mdStrike", zh: "\u5220\u9664\u7EBF", en: "Strikethrough", glyph: "S", style: "strike", run: (ctx) => wrapSelection(ctx, "~~", "~~") },
1385
+ { id: "code", key: "mdCode", zh: "\u884C\u5185\u4EE3\u7801", en: "Inline code", glyph: "<>", run: (ctx) => wrapSelection(ctx, "`", "`") },
1386
+ { id: "link", key: "mdLink", zh: "\u94FE\u63A5", en: "Link", glyph: "\u26D3", run: (ctx) => wrapSelection(ctx, "[", "](https://)") }
982
1387
  ]
983
1388
  },
984
1389
  {
985
1390
  id: "other",
1391
+ key: "toolbarOther",
986
1392
  zh: "\u5176\u4ED6",
987
1393
  en: "Other",
988
- actions: [{ id: "timestamp", zh: "\u65E5\u671F\u65F6\u95F4", en: "Date and time", glyph: "\u231A", run: insertStamp }]
1394
+ actions: [{ id: "timestamp", key: "mdTimestamp", zh: "\u65E5\u671F\u65F6\u95F4", en: "Date and time", glyph: "\u231A", run: insertStamp }]
989
1395
  }
990
1396
  ];
1397
+ var TOOLBAR_KEYS = [
1398
+ TOOLBAR_LABEL.key,
1399
+ ...TOOLBAR.flatMap((group) => [group.key, ...group.actions.map((action) => action.key)])
1400
+ ];
1401
+ function columnsOf(prefix) {
1402
+ let width = 0;
1403
+ for (const char of prefix) width += char === " " ? INDENT_WIDTH2 : 1;
1404
+ return width;
1405
+ }
991
1406
  function indentSelection(value, start, end, direction) {
992
1407
  return rewriteLines(value, start, end, (line) => {
993
- if (direction === 1) return `${INDENT}${line}`;
994
- if (line.startsWith(INDENT)) return line.slice(INDENT.length);
995
- if (line.startsWith(" ")) return line.slice(1);
996
- return line.replace(/^ {1,2}/, "");
1408
+ if (line.trim() === "") return line;
1409
+ const prefix = leadingSpace(line);
1410
+ const body = line.slice(prefix.length);
1411
+ if (direction === 1) return `${prefix}${INDENT}${body}`;
1412
+ const level = Math.floor(columnsOf(prefix) / INDENT_WIDTH2);
1413
+ return `${" ".repeat(Math.max(0, level - 1) * INDENT_WIDTH2)}${body}`;
997
1414
  });
998
1415
  }
1416
+ function fenceLines(lines) {
1417
+ const marked = lines.map(() => false);
1418
+ let open = null;
1419
+ lines.forEach((line, index) => {
1420
+ const body = line.trimStart();
1421
+ const match = FENCE_OPEN.exec(body);
1422
+ const marker = match?.[1] ?? "";
1423
+ if (open === null) {
1424
+ if (marker !== "") {
1425
+ open = { char: marker.charAt(0), length: marker.length };
1426
+ marked[index] = true;
1427
+ }
1428
+ return;
1429
+ }
1430
+ marked[index] = true;
1431
+ if (marker !== "" && marker.charAt(0) === open.char && marker.length >= open.length) open = null;
1432
+ });
1433
+ return marked;
1434
+ }
1435
+ var FENCE_OPEN = /^(`{3,}|~{3,})/;
1436
+ var TABLE_DIVIDER2 = /^\|?[ \t]*:?-{2,}:?[ \t]*(?:\|[ \t]*:?-{2,}:?[ \t]*)*\|?[ \t]*$/;
1437
+ function splitTableRow(line) {
1438
+ const trimmed = line.trim().replace(/^\|/, "").replace(/\|$/, "");
1439
+ if (trimmed.trim() === "") return [];
1440
+ return trimmed.split("|");
1441
+ }
1442
+ function tableInsertion(lines, index) {
1443
+ const isRow = (at) => (lines[at] ?? "").trimStart().includes("|");
1444
+ const isDivider = (at) => TABLE_DIVIDER2.test((lines[at] ?? "").trimStart());
1445
+ let first = index;
1446
+ while (first > 0 && isRow(first - 1)) first -= 1;
1447
+ if (!isDivider(first + 1)) return null;
1448
+ const cells = splitTableRow(lines[index] ?? "");
1449
+ if (cells.length === 0) return null;
1450
+ let last = index;
1451
+ if (index === first) {
1452
+ last = first + 1;
1453
+ while (isRow(last + 1) && !isDivider(last + 1)) last += 1;
1454
+ } else {
1455
+ while (isRow(last + 1)) last += 1;
1456
+ }
1457
+ return { at: last, columns: cells.length };
1458
+ }
1459
+ var QUOTE_PREFIX = /^(?:>[ \t]?)+/;
999
1460
  var CONTINUE_TODO = /^([ \t]*)([-*+])[ \t]+\[[ xX]\][ \t]+/;
1000
1461
  var CONTINUE_BULLET = /^([ \t]*)([-*+])[ \t]+/;
1001
1462
  var CONTINUE_ORDERED = /^([ \t]*)(\d{1,3})([.)])[ \t]+/;
1002
- function continueList(value, start, end) {
1463
+ function plainNewline(value, start, end) {
1464
+ const caret = start + 1;
1465
+ return { value: `${value.slice(0, start)}
1466
+ ${value.slice(end)}`, start: caret, end: caret };
1467
+ }
1468
+ function dropMarkerLine(value, from, to) {
1469
+ const end = to < value.length ? to + 1 : to;
1470
+ return { value: value.slice(0, from) + value.slice(end), start: from, end: from };
1471
+ }
1472
+ function continueLine(value, start, end) {
1003
1473
  const line = lineBounds(value, start);
1004
1474
  const text = value.slice(line.from, line.to);
1475
+ const lines = value.split("\n");
1476
+ const index = value.slice(0, line.from).split("\n").length - 1;
1477
+ if (fenceLines(lines)[index] === true) return plainNewline(value, start, end);
1478
+ const body = text.slice(leadingSpace(text).length);
1479
+ const quote = QUOTE_PREFIX.exec(body);
1480
+ if (quote !== null) {
1481
+ const prefix2 = leadingSpace(text);
1482
+ if (start - line.from < prefix2.length + quote[0].length) return null;
1483
+ if (body.slice(quote[0].length).trim() === "") return dropMarkerLine(value, line.from, line.to);
1484
+ const marker2 = quote[0].endsWith(" ") || quote[0].endsWith(" ") ? quote[0] : `${quote[0]} `;
1485
+ const insert = `
1486
+ ${prefix2}${marker2}`;
1487
+ const caret = start + insert.length;
1488
+ return { value: value.slice(0, start) + insert + value.slice(end), start: caret, end: caret };
1489
+ }
1005
1490
  const todo = CONTINUE_TODO.exec(text);
1006
1491
  const bullet = todo === null ? CONTINUE_BULLET.exec(text) : null;
1007
1492
  const ordered = todo === null && bullet === null ? CONTINUE_ORDERED.exec(text) : null;
1008
1493
  const marker = (todo ?? bullet ?? ordered)?.[0];
1009
- if (marker === void 0) return null;
1010
- if (start - line.from < marker.length) return null;
1011
- const body = text.slice(marker.length);
1012
- if (body.trim() === "") {
1013
- return { value: value.slice(0, line.from) + value.slice(line.to), start: line.from, end: line.from };
1014
- }
1015
- const nextMarker = todo !== null ? `${todo[1] ?? ""}${todo[2] ?? "-"} [ ] ` : bullet !== null ? `${bullet[1] ?? ""}${bullet[2] ?? "-"} ` : `${ordered?.[1] ?? ""}${Number(ordered?.[2] ?? "1") + 1}${ordered?.[3] ?? "."} `;
1016
- const insert = `
1494
+ if (marker !== void 0) {
1495
+ if (start - line.from >= marker.length) {
1496
+ const itemBody = text.slice(marker.length);
1497
+ if (itemBody.trim() === "") {
1498
+ return dropMarkerLine(value, line.from, line.to);
1499
+ }
1500
+ const nextMarker = todo !== null ? `${todo[1] ?? ""}${todo[2] ?? "-"} [ ] ` : bullet !== null ? `${bullet[1] ?? ""}${bullet[2] ?? "-"} ` : `${ordered?.[1] ?? ""}${Number(ordered?.[2] ?? "1") + 1}${ordered?.[3] ?? "."} `;
1501
+ const insert = `
1017
1502
  ${nextMarker}`;
1018
- const caret = start + insert.length;
1019
- return { value: value.slice(0, start) + insert + value.slice(end), start: caret, end: caret };
1503
+ const caret = start + insert.length;
1504
+ return { value: value.slice(0, start) + insert + value.slice(end), start: caret, end: caret };
1505
+ }
1506
+ }
1507
+ const table = tableInsertion(lines, index);
1508
+ if (table !== null) {
1509
+ if (start !== line.to) return null;
1510
+ const row = `|${" |".repeat(table.columns)}`;
1511
+ const at = lines.slice(0, table.at + 1).reduce((sum, entry) => sum + entry.length + 1, 0) - 1;
1512
+ const insert = `
1513
+ ${row}`;
1514
+ const caret = at + 3;
1515
+ return {
1516
+ value: `${value.slice(0, at)}${insert}${value.slice(at)}`,
1517
+ start: caret,
1518
+ end: caret
1519
+ };
1520
+ }
1521
+ const prefix = leadingSpace(text);
1522
+ if (prefix !== "" && text.trim() !== "" && start - line.from >= prefix.length) {
1523
+ const insert = `
1524
+ ${prefix}`;
1525
+ const caret = start + insert.length;
1526
+ return { value: value.slice(0, start) + insert + value.slice(end), start: caret, end: caret };
1527
+ }
1528
+ return null;
1020
1529
  }
1021
1530
  function MarkdownEditor(props) {
1022
1531
  const {
@@ -1031,8 +1540,18 @@ window.__ModuleLoader__.load({
1031
1540
  autoFocus = true,
1032
1541
  fill = false,
1033
1542
  disabled = false,
1034
- locale = "zh"
1543
+ locale = "zh",
1544
+ t,
1545
+ hidden = false
1035
1546
  } = props;
1547
+ const labelOf = (0, import_react.useCallback)(
1548
+ (pair) => {
1549
+ if (t === void 0) return pair[locale];
1550
+ const translated = t(pair.key);
1551
+ return translated === pair.key ? pair[locale] : translated;
1552
+ },
1553
+ [locale, t]
1554
+ );
1036
1555
  const areaRef = (0, import_react.useRef)(null);
1037
1556
  const composing = (0, import_react.useRef)(false);
1038
1557
  const justEnded = (0, import_react.useRef)(false);
@@ -1133,6 +1652,14 @@ window.__ModuleLoader__.load({
1133
1652
  const end = node.value.length;
1134
1653
  if (!composing.current) node.setSelectionRange(end, end);
1135
1654
  }, [autoFocus]);
1655
+ const wasHidden = (0, import_react.useRef)(hidden);
1656
+ (0, import_react.useLayoutEffect)(() => {
1657
+ if (wasHidden.current && !hidden) {
1658
+ const node = areaRef.current;
1659
+ if (node !== null && !composing.current) node.focus();
1660
+ }
1661
+ wasHidden.current = hidden;
1662
+ }, [hidden]);
1136
1663
  const commit = (0, import_react.useCallback)(
1137
1664
  (edit) => {
1138
1665
  if (edit === null) return;
@@ -1153,19 +1680,22 @@ window.__ModuleLoader__.load({
1153
1680
  },
1154
1681
  [maxLength, onChange, value]
1155
1682
  );
1683
+ function saveOnce(event) {
1684
+ event.preventDefault();
1685
+ event.stopPropagation();
1686
+ if (!event.repeat) onSave?.();
1687
+ }
1156
1688
  function onKeyDown(event) {
1157
1689
  if (guarded(event)) return;
1158
1690
  const node = event.currentTarget;
1159
1691
  const modifier = event.metaKey || event.ctrlKey;
1160
1692
  if (event.key !== "Tab" && event.key !== "Escape") tabEscape.current = false;
1161
1693
  if (modifier && (event.key === "s" || event.key === "S")) {
1162
- event.preventDefault();
1163
- if (!event.repeat) onSave?.();
1694
+ saveOnce(event);
1164
1695
  return;
1165
1696
  }
1166
1697
  if (modifier && event.key === "Enter") {
1167
- event.preventDefault();
1168
- if (!event.repeat) onSave?.();
1698
+ saveOnce(event);
1169
1699
  return;
1170
1700
  }
1171
1701
  if (event.key === "Escape") {
@@ -1183,7 +1713,7 @@ window.__ModuleLoader__.load({
1183
1713
  return;
1184
1714
  }
1185
1715
  if (event.key === "Enter" && !modifier && !event.shiftKey && !event.altKey) {
1186
- const continuation = continueList(value, node.selectionStart, node.selectionEnd);
1716
+ const continuation = continueLine(value, node.selectionStart, node.selectionEnd);
1187
1717
  if (continuation === null) return;
1188
1718
  event.preventDefault();
1189
1719
  commit(continuation);
@@ -1197,57 +1727,74 @@ window.__ModuleLoader__.load({
1197
1727
  if (node === null) return;
1198
1728
  commit(action.run({ value, start: node.selectionStart, end: node.selectionEnd, locale }));
1199
1729
  }
1200
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "skw-ed-root", "data-disabled": disabled ? "true" : void 0, "data-fill": fill ? "true" : void 0, children: [
1201
- toolbar && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1202
- "div",
1203
- {
1204
- className: "skw-ed-toolbar",
1205
- role: "toolbar",
1206
- "aria-label": TOOLBAR_LABEL[locale],
1207
- onMouseDown: onToolbarMouseDown,
1208
- children: TOOLBAR.map((group) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "skw-ed-group", role: "group", "aria-label": group[locale], children: group.actions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1209
- "button",
1730
+ const rootStyle = hidden ? { display: "none" } : void 0;
1731
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1732
+ "div",
1733
+ {
1734
+ className: "skw-ed-root",
1735
+ style: rootStyle,
1736
+ "data-hidden": hidden ? "true" : void 0,
1737
+ "data-disabled": disabled ? "true" : void 0,
1738
+ "data-fill": fill ? "true" : void 0,
1739
+ "aria-hidden": hidden ? "true" : void 0,
1740
+ children: [
1741
+ toolbar && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1742
+ "div",
1210
1743
  {
1211
- type: "button",
1212
- className: "skw-ed-btn",
1213
- "data-action": action.id,
1214
- "data-style": action.style,
1215
- "aria-label": action[locale],
1216
- title: action[locale],
1217
- disabled,
1218
- onClick: () => {
1219
- runAction(action);
1744
+ className: "skw-ed-toolbar",
1745
+ role: "toolbar",
1746
+ "aria-label": labelOf(TOOLBAR_LABEL),
1747
+ onMouseDown: onToolbarMouseDown,
1748
+ children: TOOLBAR.map((group) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "skw-ed-group", role: "group", "aria-label": labelOf(group), children: group.actions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1749
+ "button",
1750
+ {
1751
+ type: "button",
1752
+ className: "skw-ed-btn",
1753
+ "data-action": action.id,
1754
+ "data-style": action.style,
1755
+ "aria-label": labelOf(action),
1756
+ title: labelOf(action),
1757
+ disabled,
1758
+ onClick: () => {
1759
+ runAction(action);
1760
+ },
1761
+ children: action.glyph
1762
+ },
1763
+ action.id
1764
+ )) }, group.id))
1765
+ }
1766
+ ),
1767
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1768
+ "textarea",
1769
+ {
1770
+ ref: areaRef,
1771
+ className: "skw-ed-input",
1772
+ value,
1773
+ onChange: (event) => {
1774
+ onChange(event.target.value);
1220
1775
  },
1221
- children: action.glyph
1222
- },
1223
- action.id
1224
- )) }, group.id))
1225
- }
1226
- ),
1227
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1228
- "textarea",
1229
- {
1230
- ref: areaRef,
1231
- className: "skw-ed-input",
1232
- value,
1233
- onChange: (event) => {
1234
- onChange(event.target.value);
1235
- },
1236
- onKeyDown,
1237
- placeholder,
1238
- maxLength,
1239
- disabled,
1240
- "aria-label": label,
1241
- autoComplete: "off",
1242
- spellCheck: true
1243
- }
1244
- )
1245
- ] });
1776
+ onKeyDown,
1777
+ placeholder,
1778
+ maxLength,
1779
+ disabled,
1780
+ "aria-label": label,
1781
+ autoComplete: "off",
1782
+ spellCheck: true
1783
+ }
1784
+ )
1785
+ ]
1786
+ }
1787
+ );
1246
1788
  }
1247
1789
  var EDITOR_CSS = `
1248
1790
  .skw-ed-root { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
1249
1791
  .skw-ed-root *, .skw-ed-root *::before, .skw-ed-root *::after { box-sizing: border-box; }
1250
1792
  .skw-ed-root[data-disabled="true"] { opacity: .7; }
1793
+ /* Hidden by the composer's preview toggle. The inline style is what actually
1794
+ hides it (an author display rule beats the UA sheet's [hidden] rule, so the
1795
+ attribute alone leaves the editor laid out); this rule is the belt to that
1796
+ braces for a caller that sets the data attribute without the style. */
1797
+ .skw-ed-root[data-hidden="true"] { display: none !important; }
1251
1798
  /* Fill mode: the sheet gives the editor a box and the editor fills it, so a
1252
1799
  taller sheet means more visible text instead of more empty sheet. */
1253
1800
  .skw-ed-root[data-fill="true"] { flex: 1 1 auto; min-height: 0; }
@@ -1903,8 +2450,41 @@ window.__ModuleLoader__.load({
1903
2450
 
1904
2451
  /* Rendered Markdown.
1905
2452
  Sized in em so it follows the card's own font size at every width preset,
1906
- and kept quiet: headings are one step up, not a document outline. */
1907
- .skw-md { font-size: inherit; line-height: inherit; }
2453
+ and kept quiet: headings are one step up, not a document outline.
2454
+
2455
+ The palette is a MIDDLE LAYER declared on .skw-md itself, because that one
2456
+ element is rendered on two surfaces: inside a note card, and inside the
2457
+ composer's neutral preview pane, which is NOT a .skw-note. A note's own
2458
+ --skw-note-* variables exist only on .skw-note, so a .skw-md-* rule that read
2459
+ them directly resolved to nothing in the preview pane \u2014 and every color-mix()
2460
+ built on that empty variable was an invalid declaration there, which is why
2461
+ the preview lost its code chip, quote rail, rule and table borders. Routing
2462
+ every rule through --skw-md-* fixes that at the source.
2463
+
2464
+ The defaults are the shell's own label/brand tokens, so a .skw-md on a neutral
2465
+ surface is readable with no extra rule. A note card re-points the layer at its
2466
+ own palette below. The fallback inside each var() is the last resort for a
2467
+ .skw-md rendered outside the sheet entirely. */
2468
+ .skw-md {
2469
+ font-size: inherit; line-height: inherit;
2470
+ --skw-md-ink: var(--dsw-alias-label-primary);
2471
+ --skw-md-accent: var(--dsw-alias-brand-primary);
2472
+ --skw-md-accent-ink: var(--dsw-alias-brand-primary);
2473
+ }
2474
+ /* A note card re-points the middle layer at its own palette, so a card's
2475
+ Markdown keeps exactly the colors it had when the rules read --skw-note-*
2476
+ directly. This MUST be a descendant rule and not a line inside the twelve
2477
+ .skw-note[data-color] palette rules: a custom property declared on .skw-md
2478
+ beats an inherited value from its ancestor, so a note-level
2479
+ --skw-md-ink: var(--skw-note-ink) would be shadowed by the default above and
2480
+ change nothing. This selector's specificity is what wins.
2481
+ Dark mode needs no extra rule: the palette rules already restate --skw-note-*
2482
+ under body[data-ds-dark-theme], and this mapping inherits. */
2483
+ .skw-note .skw-md {
2484
+ --skw-md-ink: var(--skw-note-ink);
2485
+ --skw-md-accent: var(--skw-note-accent);
2486
+ --skw-md-accent-ink: var(--skw-note-accent-ink);
2487
+ }
1908
2488
  .skw-md[data-compact="true"] > *:first-child { margin-top: 0; }
1909
2489
  .skw-md[data-compact="true"] > *:last-child { margin-bottom: 0; }
1910
2490
  .skw-md .skw-md-p { margin: 0 0 .5em; }
@@ -1916,51 +2496,52 @@ window.__ModuleLoader__.load({
1916
2496
  .skw-md h5.skw-md-heading, .skw-md h6.skw-md-heading { font-size: 1em; }
1917
2497
  .skw-md .skw-md-list { margin: .35em 0 .55em; padding-left: 1.15em; }
1918
2498
  .skw-md .skw-md-list li { margin: .12em 0; }
1919
- .skw-md .skw-md-list li::marker { color: var(--skw-note-accent-ink); }
2499
+ .skw-md .skw-md-list li::marker { color: var(--skw-md-accent-ink, currentColor); }
1920
2500
  .skw-md .skw-md-pre {
1921
2501
  margin: .45em 0; padding: 7px 9px; border-radius: 7px; overflow: auto;
1922
- background: color-mix(in srgb, var(--skw-note-ink) 9%, transparent);
1923
- border: 1px solid color-mix(in srgb, var(--skw-note-ink) 14%, transparent);
2502
+ background: color-mix(in srgb, var(--skw-md-ink, currentColor) 9%, transparent);
2503
+ border: 1px solid color-mix(in srgb, var(--skw-md-ink, currentColor) 14%, transparent);
1924
2504
  font-size: .92em; line-height: 1.45; max-height: 180px;
1925
2505
  }
1926
2506
  .skw-md .skw-md-pre code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre; }
1927
2507
  .skw-md .skw-md-code {
1928
2508
  padding: .08em .34em; border-radius: 4px; font-size: .94em;
1929
2509
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
1930
- background: color-mix(in srgb, var(--skw-note-ink) 11%, transparent);
2510
+ background: color-mix(in srgb, var(--skw-md-ink, currentColor) 11%, transparent);
1931
2511
  }
1932
2512
  .skw-md .skw-md-quote {
1933
2513
  margin: .4em 0; padding: .1em 0 .1em .7em;
1934
- border-left: 2px solid var(--skw-note-accent);
1935
- color: color-mix(in srgb, var(--skw-note-ink) 82%, transparent);
2514
+ border-left: 2px solid var(--skw-md-accent, currentColor);
2515
+ color: color-mix(in srgb, var(--skw-md-ink, currentColor) 82%, transparent);
1936
2516
  }
1937
- .skw-md .skw-md-rule { margin: .6em 0; border: 0; border-top: 1px solid color-mix(in srgb, var(--skw-note-ink) 22%, transparent); }
1938
- .skw-md .skw-md-link { color: var(--skw-note-accent-ink); text-decoration: underline; text-underline-offset: 2px; }
2517
+ .skw-md .skw-md-rule { margin: .6em 0; border: 0; border-top: 1px solid color-mix(in srgb, var(--skw-md-ink, currentColor) 22%, transparent); }
2518
+ .skw-md .skw-md-link { color: var(--skw-md-accent-ink, currentColor); text-decoration: underline; text-underline-offset: 2px; }
1939
2519
  .skw-md .skw-md-link:hover { text-decoration-thickness: 2px; }
1940
2520
  .skw-md .skw-md-table { margin: .45em 0; border-collapse: collapse; width: 100%; font-size: .94em; }
1941
2521
  .skw-md .skw-md-table th, .skw-md .skw-md-table td {
1942
- padding: 3px 6px; border: 1px solid color-mix(in srgb, var(--skw-note-ink) 18%, transparent); text-align: left;
2522
+ padding: 3px 6px; border: 1px solid color-mix(in srgb, var(--skw-md-ink, currentColor) 18%, transparent); text-align: left;
1943
2523
  }
1944
- .skw-md .skw-md-table th { background: color-mix(in srgb, var(--skw-note-ink) 7%, transparent); font-weight: 600; }
2524
+ .skw-md .skw-md-table th { background: color-mix(in srgb, var(--skw-md-ink, currentColor) 7%, transparent); font-weight: 600; }
1945
2525
  .skw-md .skw-md-task { display: inline-flex; align-items: baseline; gap: 5px; }
1946
2526
  .skw-md .skw-md-box {
1947
2527
  display: inline-flex; align-items: center; justify-content: center;
1948
2528
  width: 12px; height: 12px; flex: none; border-radius: 3px; font-size: 9px; line-height: 1;
1949
- border: 1px solid color-mix(in srgb, var(--skw-note-ink) 40%, transparent);
2529
+ border: 1px solid color-mix(in srgb, var(--skw-md-ink, currentColor) 40%, transparent);
1950
2530
  }
1951
- .skw-md .skw-md-task[data-checked="true"] .skw-md-box { background: var(--skw-note-accent); border-color: transparent; color: var(--skw-note-accent-ink); }
2531
+ .skw-md .skw-md-task[data-checked="true"] .skw-md-box { background: var(--skw-md-accent, currentColor); border-color: transparent; color: var(--skw-md-accent-ink, currentColor); }
1952
2532
  .skw-md .skw-md-task[data-checked="true"] { opacity: .78; }
1953
2533
 
1954
- /* Composer preview pane: same Markdown, on a neutral sheet instead of a note. */
2534
+ /* Composer preview pane: the same Markdown on a neutral sheet instead of a note.
2535
+ It needs NO palette overrides of its own: .skw-md above already resolves the
2536
+ middle layer to the theme tokens here (there is no .skw-note ancestor to
2537
+ supply --skw-note-*), so every .skw-md-* rule renders on both surfaces from
2538
+ one definition instead of a per-surface patch list. */
1955
2539
  .skw-preview-box {
1956
2540
  min-height: 132px; max-height: 42vh; overflow: auto; padding: 9px 11px;
1957
2541
  border: 1px solid var(--dsw-alias-border-l2); border-radius: 8px;
1958
2542
  background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-primary);
1959
2543
  font-size: 13px; line-height: 20px;
1960
2544
  }
1961
- .skw-preview-box .skw-md-link { color: var(--dsw-alias-brand-primary); }
1962
- .skw-preview-box .skw-md-code { background: var(--dsw-alias-bg-layer-2); }
1963
- .skw-preview-box .skw-md-pre { background: var(--dsw-alias-bg-layer-2); border-color: var(--dsw-alias-border-l1); }
1964
2545
  .skw-preview-empty { margin: 0; color: var(--dsw-alias-label-tertiary); }
1965
2546
  .skw-sheet-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
1966
2547
  .skw-sheet-row .skw-spacer { flex: 1; }
@@ -2237,11 +2818,14 @@ window.__ModuleLoader__.load({
2237
2818
  "aria-label": t("titlePlaceholder")
2238
2819
  }
2239
2820
  ),
2240
- preview ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "skw-preview-box skw-preview-fill", children: draft.body.trim() === "" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "skw-preview-empty", children: t("bodyPlaceholder") }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Markdown, { source: draft.body }) }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2821
+ preview && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "skw-preview-box skw-preview-fill", children: draft.body.trim() === "" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "skw-preview-empty", children: t("bodyPlaceholder") }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Markdown, { source: draft.body }) }),
2822
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2241
2823
  MarkdownEditor,
2242
2824
  {
2243
2825
  value: draft.body,
2244
2826
  fill: true,
2827
+ hidden: preview,
2828
+ t,
2245
2829
  onChange: (body) => onChange({ body }),
2246
2830
  onSave: save,
2247
2831
  onEscape: requestClose,
@@ -2700,7 +3284,7 @@ window.__ModuleLoader__.load({
2700
3284
  }
2701
3285
  async function tidyWall() {
2702
3286
  const ran = await mutate(async () => {
2703
- await api.arrange(life.current.signal, { centreReserve: centreReserve() });
3287
+ await api.arrange(life.current.signal, { centreReserve: CENTRE_RESERVE });
2704
3288
  });
2705
3289
  if (!ran) return;
2706
3290
  await new Promise((resolve) => {
@@ -2808,10 +3392,7 @@ window.__ModuleLoader__.load({
2808
3392
  const viewport = viewportRefCurrent.current;
2809
3393
  if (world !== null) world.style.transform = `translate3d(${current.panX}px, ${current.panY}px, 0) scale(${current.zoom})`;
2810
3394
  const centre = centreRef.current;
2811
- if (centre !== null) {
2812
- const scale = Math.min(1, current.zoom);
2813
- centre.style.transform = `translate(-50%, -50%) scale(${scale})`;
2814
- }
3395
+ if (centre !== null) centre.style.transform = "translate(-50%, -50%)";
2815
3396
  if (viewport !== null) {
2816
3397
  viewport.style.backgroundSize = `${DOT_PITCH * current.zoom}px ${DOT_PITCH * current.zoom}px`;
2817
3398
  viewport.style.backgroundPosition = `${current.panX}px ${current.panY}px`;
@@ -2976,33 +3557,24 @@ window.__ModuleLoader__.load({
2976
3557
  const blockRect = centre === null ? null : centre.getBoundingClientRect();
2977
3558
  const fieldX = blockRect === null ? width / 2 : blockRect.left + blockRect.width / 2 - view2.left;
2978
3559
  const fieldY = blockRect === null ? height / 2 : blockRect.top + blockRect.height / 2 - view2.top;
2979
- const reserve = CENTRE_RESERVE;
2980
- const blockHalf = (zoom2) => ({
2981
- // The painted overlay is counter-scaled by `min(1, zoom)`, while its world
2982
- // footprint stays fixed; taking the larger of the two keeps the card clear
2983
- // of whichever is actually on screen.
2984
- halfW: reserve.halfWidth * Math.max(1, zoom2),
2985
- halfH: reserve.halfHeight * Math.max(1, zoom2)
2986
- });
3560
+ const measured = blockRect !== null && blockRect.width > 0 && blockRect.height > 0;
3561
+ const halfW = measured ? blockRect.width / 2 : CENTRE_RESERVE.halfWidth * camera.current.zoom;
3562
+ const halfH = measured ? blockRect.height / 2 : CENTRE_RESERVE.halfHeight * camera.current.zoom;
2987
3563
  const cardX = box.x + box.width / 2;
2988
3564
  const cardY = box.y + box.height / 2;
2989
3565
  const screenX = cardX * camera.current.zoom + camera.current.panX;
2990
3566
  const screenY = cardY * camera.current.zoom + camera.current.panY;
2991
3567
  const fitsAt = (x, y2, zoom2) => x - box.width * zoom2 / 2 >= margin && x + box.width * zoom2 / 2 <= width - margin && y2 - box.height * zoom2 / 2 >= margin && y2 + box.height * zoom2 / 2 <= usableBottom;
2992
- const hiddenAt = (x, y2, zoom2) => {
2993
- const { halfW, halfH: halfH2 } = blockHalf(zoom2);
2994
- return x - box.width * zoom2 / 2 < fieldX + halfW && x + box.width * zoom2 / 2 > fieldX - halfW && y2 - box.height * zoom2 / 2 < fieldY + halfH2 && y2 + box.height * zoom2 / 2 > fieldY - halfH2;
2995
- };
3568
+ const hiddenAt = (x, y2, zoom2) => x - box.width * zoom2 / 2 < fieldX + halfW && x + box.width * zoom2 / 2 > fieldX - halfW && y2 - box.height * zoom2 / 2 < fieldY + halfH && y2 + box.height * zoom2 / 2 > fieldY - halfH;
2996
3569
  if (fitsAt(screenX, screenY, camera.current.zoom) && !hiddenAt(screenX, screenY, camera.current.zoom)) return;
2997
3570
  const gap = 26;
2998
3571
  for (let step = 0; step <= 8; step += 1) {
2999
3572
  const zoom2 = step === 0 ? camera.current.zoom : Math.max(ZOOM_MIN, camera.current.zoom * 0.88 ** step);
3000
- const { halfW, halfH: halfH2 } = blockHalf(zoom2);
3001
3573
  const halfCardW = box.width * zoom2 / 2;
3002
3574
  const halfCardH = box.height * zoom2 / 2;
3003
3575
  const candidates = [
3004
- { x: fieldX, y: fieldY - halfH2 - gap - halfCardH },
3005
- { x: fieldX, y: fieldY + halfH2 + gap + halfCardH },
3576
+ { x: fieldX, y: fieldY - halfH - gap - halfCardH },
3577
+ { x: fieldX, y: fieldY + halfH + gap + halfCardH },
3006
3578
  { x: fieldX - halfW - gap - halfCardW, y: fieldY },
3007
3579
  { x: fieldX + halfW + gap + halfCardW, y: fieldY }
3008
3580
  ];
@@ -3024,7 +3596,6 @@ window.__ModuleLoader__.load({
3024
3596
  (width - margin * 2) / Math.max(1, box.width),
3025
3597
  (usableBottom - margin) / Math.max(1, box.height)
3026
3598
  ));
3027
- const { halfH } = blockHalf(targetZoom);
3028
3599
  const y = fieldY + halfH + gap + box.height * targetZoom / 2;
3029
3600
  glideCameraTo(targetZoom, width / 2 - cardX * targetZoom, y - cardY * targetZoom);
3030
3601
  }, [glideCameraTo]);