@gbti/ryker 0.2.5 → 0.3.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.
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Ryker 0.2.5
2
+ * Ryker 0.3.0
3
3
  * A drop-in editing layer for authored HTML reports.
4
4
  *
5
5
  * Generated bundle. Do not edit. Sources, in load order:
@@ -7,27 +7,28 @@
7
7
  * config/config.js (157 lines)
8
8
  * security/scan.js (86 lines)
9
9
  * editor/sanitize.js (218 lines)
10
- * editor/blocks.js (596 lines)
10
+ * editor/fields.js (113 lines)
11
+ * editor/blocks.js (598 lines)
11
12
  * export/zip.js (193 lines)
12
- * export/html.js (217 lines)
13
- * export/markdown.js (297 lines)
13
+ * export/html.js (226 lines)
14
+ * export/markdown.js (338 lines)
14
15
  * export/target.js (66 lines)
15
16
  * export/packager.js (277 lines)
16
17
  * ui/theme.js (61 lines)
17
- * ui/styles.js (421 lines)
18
- * ui/shell.js (241 lines)
18
+ * ui/styles.js (486 lines)
19
+ * ui/shell.js (252 lines)
19
20
  * ui/icons.js (68 lines)
20
21
  * ui/tooltip.js (82 lines)
21
- * ui/dialog.js (138 lines)
22
- * ui/menu.js (104 lines)
22
+ * ui/dialog.js (176 lines)
23
+ * ui/menu.js (114 lines)
23
24
  * ui/about.js (80 lines)
24
25
  * export/dialog.js (213 lines)
25
26
  * editor/editable.js (600 lines)
26
- * editor/history.js (276 lines)
27
- * editor/formatbar.js (252 lines)
27
+ * editor/history.js (296 lines)
28
+ * editor/formatbar.js (264 lines)
28
29
  * editor/links.js (173 lines)
29
- * editor/pick.js (228 lines)
30
- * editor/multi.js (172 lines)
30
+ * editor/pick.js (305 lines)
31
+ * editor/multi.js (176 lines)
31
32
  * editor/table.js (345 lines)
32
33
  * editor/outline.js (289 lines)
33
34
  * editor/move.js (436 lines)
@@ -35,14 +36,15 @@
35
36
  * ui/rail.js (530 lines)
36
37
  * instructions/steps.js (592 lines)
37
38
  * instructions/moves.js (158 lines)
38
- * instructions/instructions.js (517 lines)
39
- * instructions/merge.js (405 lines)
40
- * storage/fs.js (336 lines)
41
- * storage/logger.js (433 lines)
42
- * instructions/browser.js (296 lines)
39
+ * instructions/instructions.js (546 lines)
40
+ * instructions/merge.js (432 lines)
41
+ * comments/comments.js (369 lines)
42
+ * storage/fs.js (340 lines)
43
+ * storage/logger.js (439 lines)
44
+ * instructions/browser.js (299 lines)
43
45
  * ui/pane.js (292 lines)
44
- * storage/recover.js (335 lines)
45
- * bootstrap/boot.js (546 lines)
46
+ * storage/recover.js (348 lines)
47
+ * bootstrap/boot.js (578 lines)
46
48
  *
47
49
  * Classic script by design: module scripts do not load from file:// URLs,
48
50
  * and a report handed over as a ZIP is opened from disk.
@@ -50,7 +52,7 @@
50
52
  (function () {
51
53
  'use strict';
52
54
  if (window.Ryker && window.Ryker.VERSION) return;
53
- var Ryker = { VERSION: "0.2.5", BUILD: "Ryker", SURFACE: "drop-in" };
55
+ var Ryker = { VERSION: "0.3.0", BUILD: "Ryker", SURFACE: "drop-in" };
54
56
  window.Ryker = Ryker;
55
57
 
56
58
  /* ---- utils/dom.js ---------------------------------------------- */
@@ -573,6 +575,121 @@
573
575
  })();
574
576
 
575
577
 
578
+ /* ---- editor/fields.js ------------------------------------------ */
579
+ // Text boxes the page owns, which Ryker leaves to the page.
580
+ //
581
+ // Ryker arms its own editing hosts, one per prose block, and marks each with
582
+ // ryker-editing. A page can bring editors of its own: a post composer, a mail
583
+ // body, a chat box. Those are contenteditable hosts Ryker did not arm, or form
584
+ // fields, and the page's own script holds their state (React, Draft.js,
585
+ // ProseMirror). Measured on x.com/compose/post, 2026-11-10: the composer is a
586
+ // Draft.js host inside an aria-modal dialog, and Ryker's pick gesture, finding
587
+ // no block under the pointer, reached past the dialog to an icon in the
588
+ // timeline behind it and prevented the press, so the composer could never
589
+ // take a caret or a selection. Everything here exists so that a press, a pick
590
+ // or an armed block never lands inside one of these.
591
+ Ryker.fields = (function () {
592
+ 'use strict';
593
+
594
+ var TEXT_INPUT = /^(text|search|email|url|tel|password|number|)$/;
595
+
596
+ function elementOf(node) {
597
+ if (node && node.nodeType === 3) node = node.parentElement;
598
+ return node && node.nodeType === 1 ? node : null;
599
+ }
600
+
601
+ function ours(el) { return !!(Ryker.shell && Ryker.shell.owns(el)); }
602
+
603
+ // A form control a person types into. Buttons, checkboxes and the like are
604
+ // controls too, but a press on them selects nothing Ryker could take.
605
+ function isTextControl(node) {
606
+ var el = elementOf(node);
607
+ if (!el || ours(el)) return false;
608
+ if (el.tagName === 'TEXTAREA' || el.tagName === 'SELECT') return true;
609
+ return el.tagName === 'INPUT' && TEXT_INPUT.test(String(el.getAttribute('type') || '').toLowerCase());
610
+ }
611
+
612
+ function pageHost(el) {
613
+ if (!el.hasAttribute || !el.hasAttribute('contenteditable')) return false;
614
+ if (el.classList.contains('ryker-editing')) return false;
615
+ return String(el.getAttribute('contenteditable')).toLowerCase() !== 'false';
616
+ }
617
+
618
+ /** The outermost editing host the page made, containing node, or null.
619
+ * Outermost, because an editor may nest hosts (a mention chip, a table
620
+ * cell), and the editor is the thing that owns the text. */
621
+ function editorOf(node) {
622
+ var el = elementOf(node);
623
+ if (!el || ours(el)) return null;
624
+ var found = null;
625
+ for (var n = el; n && n.nodeType === 1; n = n.parentElement) {
626
+ if (pageHost(n)) found = n;
627
+ }
628
+ return found;
629
+ }
630
+
631
+ function inField(node) { return !!editorOf(node) || isTextControl(node); }
632
+
633
+ // A dialog the page opened over its own content. A press inside one is about
634
+ // that dialog, never about the document behind it.
635
+ var LAYER = '[aria-modal="true"], dialog, [role="dialog"], [role="alertdialog"]';
636
+ function inLayer(node) {
637
+ var el = elementOf(node);
638
+ return !!(el && !ours(el) && el.closest && el.closest(LAYER));
639
+ }
640
+
641
+ // An icon inside a link or a button is the control's face, not content, so
642
+ // Ryker never picks it as an object (x.com draws every control with one).
643
+ var CONTROL = 'a, button, label, [role="button"], [role="link"], [role="menuitem"], [role="tab"]';
644
+ function inControl(node) {
645
+ var el = elementOf(node);
646
+ return !!(el && el.closest && el.closest(CONTROL));
647
+ }
648
+
649
+ var LINE = /^(block|flex|grid|list-item|table|flow-root)$/;
650
+
651
+ /** The paragraph of a page editor under node: the nearest block-level element
652
+ * inside the editor, or the editor itself when its text is not split into
653
+ * blocks (plain text with line breaks). Draft.js gives each line its own
654
+ * block element, ProseMirror and Lexical a <p>. */
655
+ function lineOf(editor, node) {
656
+ for (var el = elementOf(node); el && el !== editor && editor.contains(el); el = el.parentElement) {
657
+ var display = '';
658
+ try { display = getComputedStyle(el).display; } catch (e) {}
659
+ if (LINE.test(display) && String(el.textContent || '').trim()) return el;
660
+ }
661
+ return editor;
662
+ }
663
+
664
+ /** Ctrl+click inside a page editor: select the paragraph under the pointer
665
+ * as ordinary text, so the page's own editor holds the selection and keeps
666
+ * it in its own state. A second Ctrl+click in the same editor stretches
667
+ * the selection over both paragraphs and everything between, which is the
668
+ * most a single text selection can hold. Returns true when it selected. */
669
+ function selectLine(editor, node) {
670
+ var line = lineOf(editor, node);
671
+ if (!String(line.textContent || '').trim()) return false;
672
+ var next = document.createRange();
673
+ next.selectNodeContents(line);
674
+ var sel = window.getSelection();
675
+ var was = sel && sel.rangeCount ? sel.getRangeAt(0) : null;
676
+ if (was && !was.collapsed && editor.contains(was.commonAncestorContainer)) {
677
+ if (was.compareBoundaryPoints(Range.START_TO_START, next) < 0) next.setStart(was.startContainer, was.startOffset);
678
+ if (was.compareBoundaryPoints(Range.END_TO_END, next) > 0) next.setEnd(was.endContainer, was.endOffset);
679
+ }
680
+ try { editor.focus({ preventScroll: true }); } catch (e) {}
681
+ sel.removeAllRanges();
682
+ sel.addRange(next);
683
+ return true;
684
+ }
685
+
686
+ return {
687
+ editorOf: editorOf, isTextControl: isTextControl, inField: inField,
688
+ inLayer: inLayer, inControl: inControl, lineOf: lineOf, selectLine: selectLine
689
+ };
690
+ })();
691
+
692
+
576
693
  /* ---- editor/blocks.js ------------------------------------------ */
577
694
  // Which parts of the report are editable, and how a block is named.
578
695
  //
@@ -632,6 +749,8 @@
632
749
  // Navigation is not content. Editing the table of contents would desync it
633
750
  // from the headings it points at.
634
751
  if (node.closest('nav, footer')) return true;
752
+ // A text box the page owns keeps its own state (editor/fields.js).
753
+ if (Ryker.fields && Ryker.fields.editorOf(node)) return true;
635
754
  // A <header> is usually site chrome, but the document's own title block is
636
755
  // also a header, and that one IS content. The test is where it sits rather
637
756
  // than what it is called: a header inside <main> belongs to the document.
@@ -749,7 +868,7 @@
749
868
 
750
869
  function atomic(node) {
751
870
  return !!(node && node.matches && node.matches(ATOMIC_SELECTOR) &&
752
- root().contains(node) && !excluded(node));
871
+ root().contains(node) && !excluded(node) && !Ryker.fields.inControl(node));
753
872
  }
754
873
 
755
874
  function atomicNodes() {
@@ -1470,10 +1589,19 @@
1470
1589
  exportBody.removeAttribute('data-ryker-pushed');
1471
1590
  if (!exportBody.getAttribute('style')) exportBody.removeAttribute('style');
1472
1591
  }
1592
+ // The attribute holds the author's own style attribute, which is usually
1593
+ // absent and was therefore indistinguishable from deleting the top the
1594
+ // toolbar wrote. It is not the same thing when the author wrote one: a
1595
+ // sticky nav with an inline top:0px came back with no style attribute at
1596
+ // all, which is a byte difference and, where the stylesheet supplied no top
1597
+ // of its own, a nav that stopped sticking. Restored as the attribute rather
1598
+ // than through the CSSOM, because setting the property back re-serialises
1599
+ // it and `top:0px` returns as `top: 0px;`. Same undo as shell.releaseOffset,
1600
+ // from the same attribute, on purpose.
1473
1601
  Array.prototype.forEach.call(doc.querySelectorAll('[data-ryker-offset]'), function (n) {
1602
+ var authored = n.getAttribute('data-ryker-offset');
1474
1603
  n.removeAttribute('data-ryker-offset');
1475
- n.style.removeProperty('top');
1476
- if (!n.getAttribute('style')) n.removeAttribute('style');
1604
+ if (authored) n.setAttribute('style', authored); else n.removeAttribute('style');
1477
1605
  });
1478
1606
  // Same leak a third time, on the element the clone IS rather than one it
1479
1607
  // contains, so neither the body pass above nor the querySelectorAll below
@@ -1657,6 +1785,47 @@
1657
1785
  return out;
1658
1786
  }
1659
1787
 
1788
+ // The inverse of inlineOf, for one line of inline Markdown. It lived in
1789
+ // extension/workspace.js until Rewrite needed it in the bundle too (sow-011),
1790
+ // and it moved rather than being copied so the two cannot drift apart.
1791
+ //
1792
+ // The text is escaped before any tag is made, so whatever arrives, Markdown or
1793
+ // markup, can only ever produce the tags written below. allowUrl decides which
1794
+ // link targets become links; anything it refuses stays as literal text. The
1795
+ // default is the workspace's rule exactly: http, https, mailto and #fragments.
1796
+ var DEFAULT_URL = /^(?:https?:\/\/|mailto:|#)./;
1797
+
1798
+ function inlineHtml(value, allowUrl) {
1799
+ var allow = typeof allowUrl === 'function' ? allowUrl
1800
+ : function (url) { return DEFAULT_URL.test(url); };
1801
+ var code = [];
1802
+ // The three private-use characters below are this function's own
1803
+ // placeholders. Text that arrives already carrying them could stand one
1804
+ // in for a piece of a link target, pass the check as one string and come
1805
+ // out as another, so they are removed before anything else happens.
1806
+ value = String(value == null ? '' : value).replace(/[\uE000-\uE002]/g, '');
1807
+ var escaped = Ryker.dom.escapeHtml(value).replace(/`([^`]+)`/g, function (_, contents) {
1808
+ var token = '' + code.length + '';
1809
+ code.push('<code>' + contents + '</code>');
1810
+ return token;
1811
+ });
1812
+ escaped = escaped
1813
+ .replace(/(^|[^*])\*\*([^*\s](?:[^*]*[^*\s])?)\*\*(?!\*)/g,
1814
+ '$1<strong>$2</strong>')
1815
+ .replace(/(^|[^\w_])__([^_\s](?:[^_]*[^_\s])?)__(?![\w_])/g,
1816
+ '$1<strong>$2</strong>')
1817
+ .replace(/(^|[^*])\*([^*\s](?:[^*]*[^*\s])?)\*(?!\*)/g,
1818
+ '$1<em>$2</em>')
1819
+ .replace(/(^|[^\w_])_([^_\s](?:[^_]*[^_\s])?)_(?![\w_])/g,
1820
+ '$1<em>$2</em>')
1821
+ .replace(/\[([^\]]+)\]\(([^\s)]+)\)/g, function (whole, text, url) {
1822
+ return allow(url) ? '<a href="' + url + '">' + text + '</a>' : whole;
1823
+ });
1824
+ return escaped.replace(/(\d+)/g, function (_, index) {
1825
+ return code[Number(index)] || '';
1826
+ });
1827
+ }
1828
+
1660
1829
  function cellsOf(tr) {
1661
1830
  return Array.prototype.map.call(tr.children, function (cell) {
1662
1831
  return inlineOf(cell).replace(/\|/g, '\\|').trim();
@@ -1879,7 +2048,7 @@
1879
2048
 
1880
2049
  return {
1881
2050
  adopt: adopt, available: available, build: build,
1882
- blockOf: blockOf, inlineOf: inlineOf
2051
+ blockOf: blockOf, inlineOf: inlineOf, inlineHtml: inlineHtml
1883
2052
  };
1884
2053
  })();
1885
2054
 
@@ -2632,6 +2801,67 @@
2632
2801
  '.acts{display:flex;gap:5px;flex-wrap:wrap}',
2633
2802
 
2634
2803
  // ---- fields -----------------------------------------------------------
2804
+ // The quote inside the comment dialog. Indented behind a rule rather than
2805
+ // boxed, so it reads as the document speaking and the field below it reads
2806
+ // as the reader answering.
2807
+ '.modal blockquote.comment-quote{margin:0 0 10px;padding:6px 0 6px 12px;',
2808
+ 'border-left:2px solid var(--rk-brand-color);color:var(--rk-muted);font-style:italic;',
2809
+ 'max-height:120px;overflow:auto;white-space:pre-line}',
2810
+ // The Rewrite popup (sow-011, extension only). textarea.rk and input.rk set
2811
+ // display:block, which beats the UA's [hidden] rule, hence the first line.
2812
+ '.rewrite [hidden]{display:none!important}',
2813
+ '.rewrite-connect{max-width:560px;margin:0 auto;padding:var(--rk-s4) 0;text-align:center}',
2814
+ '.rewrite-connect .note{text-align:left}.rewrite-lead{font-size:14px;color:var(--rk-fg)}',
2815
+ '.rewrite-connect-logo svg{display:block;margin:0 auto var(--rk-s3)}',
2816
+ // A table so the list shrinks to its text and centres, yet stays a block:
2817
+ // as inline-block, the button below flowed up beside the last step.
2818
+ '.rewrite-steps{display:table;margin:0 auto var(--rk-s4);padding-left:20px;text-align:left;line-height:1.9;color:var(--rk-fg)}',
2819
+ '.rewrite-connect-action{display:flex;justify-content:center}',
2820
+ // OpenAI's approved format: the black logo and "Continue with ChatGPT".
2821
+ 'button.rk.siwc-button{padding:10px 18px;border-radius:999px;background:#fff;color:#000;',
2822
+ ' border-color:#c9ccd1;font-size:13.5px;font-weight:600;gap:9px}',
2823
+ 'button.rk.siwc-button svg{display:block}.rewrite-fine{margin-top:var(--rk-s4)!important;font-size:11.5px}',
2824
+ '.rewrite-connect-status{min-height:1.4em;margin:var(--rk-s3) 0 0!important}',
2825
+ 'a.rk-button-link{display:inline-block;margin-left:10px;padding:3px 10px;border-radius:var(--rk-r-md);',
2826
+ ' background:var(--rk-brand-color);color:#fff!important;text-decoration:none;font-weight:600}',
2827
+ '.rewrite-plan{margin-right:auto;align-self:center;font-size:11.5px}',
2828
+ '.rewrite-row{display:flex;gap:8px;align-items:center;margin:0 0 10px}.rewrite-row input.rk{flex:1;width:auto}',
2829
+ // What is rewritten comes first, then the prompt: two tabs, the selection
2830
+ // open, the article as it is sent behind the second.
2831
+ '.rewrite-tabs{display:flex;gap:2px;border-bottom:1px solid var(--rk-line);margin:0 0 10px}',
2832
+ 'button.rewrite-tab{background:none;border:0;border-bottom:2px solid transparent;margin:0 0 -1px;',
2833
+ ' padding:6px 12px;color:var(--rk-muted);font:inherit;font-size:12.5px;font-weight:600;cursor:pointer}',
2834
+ 'button.rewrite-tab[aria-selected="true"]{color:var(--rk-fg);border-bottom-color:var(--rk-brand-color)}',
2835
+ 'button.rewrite-tab:focus-visible,.rewrite-article:focus-visible{outline:2px solid var(--rk-accent);outline-offset:1px}',
2836
+ '.rewrite-selection,.rewrite-article{overflow:auto;white-space:pre-wrap;overflow-wrap:anywhere;',
2837
+ ' border:1px solid var(--rk-line);border-radius:var(--rk-r-md);background:var(--rk-bg2);color:var(--rk-fg);',
2838
+ ' padding:9px 11px;margin:0 0 12px}',
2839
+ // Square on the left, so the red rule runs straight (the owner, 2026-11-10).
2840
+ '.rewrite-selection{max-height:12em;border-left:3px solid var(--rk-brand-color);',
2841
+ ' border-radius:0 var(--rk-r-md) var(--rk-r-md) 0;font-size:13.5px;line-height:1.55}',
2842
+ '.rewrite-sel-block+.rewrite-sel-block{margin-top:.7em}.rewrite-sel-heading{font-weight:650;font-size:14.5px}',
2843
+ '.rewrite-article{position:relative;max-height:24em;font-family:var(--rk-mono);font-size:12px;line-height:1.6}',
2844
+ 'mark.rewrite-mark{background:rgba(229,56,59,.16);color:inherit;border-radius:3px}',
2845
+ '.rewrite-article-note{margin:0 0 6px!important;font-size:11.5px}',
2846
+ // The prompt, then model and count, all before anything is asked.
2847
+ 'textarea.rewrite-guidance{min-height:3.4em;margin:0 0 10px;font-size:13.5px}.rewrite-settings{gap:14px}',
2848
+ '.rewrite-settings button.rk{margin-left:auto}',
2849
+ '.rewrite-count-label{display:flex;gap:6px;align-items:center;white-space:nowrap;color:var(--rk-muted)}',
2850
+ 'select.rk{background:var(--rk-field);color:var(--rk-fg);border:1px solid var(--rk-line2);border-radius:var(--rk-r-md);padding:6px 8px;font:inherit}',
2851
+ '.rewrite-settings{flex-wrap:wrap}.rewrite-profile-note{margin:-2px 0 10px;font-size:11.5px}',
2852
+ '.rewrite-profiles{display:flex;gap:14px;min-height:20em}',
2853
+ '.rewrite-profiles-list{flex:0 0 190px;display:flex;flex-direction:column;gap:4px;padding-right:14px;border-right:1px solid var(--rk-line)}',
2854
+ '.rewrite-profiles-item{text-align:left;color:var(--rk-fg)}.rewrite-profiles-item[aria-pressed="true"]{background:var(--rk-bg2);border-color:var(--rk-line2);font-weight:600}',
2855
+ '.rewrite-profiles-new{text-align:left;border-style:dashed;margin-top:4px}',
2856
+ '.rewrite-profiles-form{flex:1;min-width:0;display:flex;flex-direction:column;gap:7px}',
2857
+ '.rewrite-profiles-heading{font-size:10.5px;font-weight:600;letter-spacing:.07em;text-transform:uppercase;color:var(--rk-muted)}',
2858
+ '.rewrite-rule-row{display:flex;gap:6px;align-items:center}.rewrite-rule-row input.rk{flex:1;width:auto;padding:6px 9px}',
2859
+ '.rewrite-profiles-hint{margin:2px 0 0;font-size:11.5px}.rewrite-profile-delete{align-self:flex-start;margin-top:auto}',
2860
+ '.rewrite-profile-stays{margin-top:auto}.rewrite-profile-fixed{font-size:13px;padding:0 0 4px}',
2861
+ '.rewrite-nav{display:flex;gap:8px;align-items:center;justify-content:center;margin:0 0 8px}',
2862
+ '.rewrite-nav button.rk{font-size:20px;line-height:1;padding:2px 14px;color:var(--rk-fg)}',
2863
+ '.rewrite-nav .of{min-width:9em;text-align:center;font-variant-numeric:tabular-nums;color:var(--rk-fg)}',
2864
+ 'textarea.rewrite-text{min-height:16em;font-size:14px;line-height:1.6}.rewrite-hint{margin:6px 0 0;font-size:11.5px}',
2635
2865
  'textarea.rk,input.rk{display:block;width:100%;background:var(--rk-field);color:var(--rk-fg);',
2636
2866
  ' border:1px solid var(--rk-line2);border-radius:var(--rk-r-md);padding:9px 11px;',
2637
2867
  ' font:inherit;font-size:12.5px;line-height:1.55;resize:vertical;',
@@ -2650,6 +2880,10 @@
2650
2880
  ' padding:var(--rk-s5) var(--rk-s5) var(--rk-s5) var(--rk-s4);overflow-y:auto}',
2651
2881
  '.modal{background:var(--rk-bg);border:1px solid var(--rk-line);border-radius:var(--rk-r-xl);',
2652
2882
  ' width:100%;max-width:460px;box-shadow:var(--rk-sh-xl);overflow:hidden}',
2883
+ // Large and centred, for a dialog that is the workspace rather than a note
2884
+ // beside the text (dialog.js, opts.size).
2885
+ '.backdrop.center{justify-content:center;padding-left:var(--rk-s5)}.modal.large{max-width:880px}',
2886
+ '.modal.large .body{max-height:76vh}',
2653
2887
  '.modal header{padding:var(--rk-s4) var(--rk-s5);border-bottom:1px solid var(--rk-line);',
2654
2888
  ' background:var(--rk-bg2)}',
2655
2889
  '.modal header h2{margin:0;font-size:13.5px;font-weight:650;letter-spacing:.005em;color:var(--rk-fg)}',
@@ -2731,6 +2965,13 @@
2731
2965
  var shifted = [];
2732
2966
  var bodyPadding = {};
2733
2967
  var owner = Ryker.dom.uid('owner');
2968
+ // A real extension install seals its root: the page underneath can then
2969
+ // neither read Ryker's interface nor press its buttons, which matters once
2970
+ // those buttons can spend a ChatGPT plan and change the person's writing
2971
+ // profiles. The worker asks for it before start(). The drop-in runs as the
2972
+ // page's own script, where there is no such line to hold, and stays open.
2973
+ var sealed = false;
2974
+ function seal() { sealed = true; }
2734
2975
 
2735
2976
  function owns(node) {
2736
2977
  if (!host || !node) return false;
@@ -2777,7 +3018,7 @@
2777
3018
  host.setAttribute('data-ryker-lock', '');
2778
3019
  document.body.appendChild(host);
2779
3020
 
2780
- shadow = host.attachShadow({ mode: 'open' });
3021
+ shadow = host.attachShadow({ mode: sealed ? 'closed' : 'open' });
2781
3022
  var style = document.createElement('style');
2782
3023
  style.textContent = Ryker.styles.shadowCss;
2783
3024
  shadow.appendChild(style);
@@ -2823,8 +3064,13 @@
2823
3064
  releaseOffset();
2824
3065
  document.documentElement.style.setProperty('--ryker-offset', px + 'px');
2825
3066
  if (!px) return;
3067
+ // The whole authored style attribute, not just the top value. Putting a
3068
+ // property back through the CSSOM re-serialises the declaration, so an
3069
+ // author's `style="top:0px"` came back as `style="top: 0px;"`. That is a
3070
+ // byte difference in an export whose one promise is byte-identity, and it
3071
+ // is invisible on screen, which is the worst way for a promise to break.
2826
3072
  stickyCandidates().forEach(function (n) {
2827
- n.setAttribute('data-ryker-offset', n.style.top || '');
3073
+ n.setAttribute('data-ryker-offset', n.getAttribute('style') || '');
2828
3074
  n.style.top = px + 'px';
2829
3075
  shifted.push(n);
2830
3076
  });
@@ -2842,9 +3088,8 @@
2842
3088
  function releaseOffset() {
2843
3089
  shifted.forEach(function (n) {
2844
3090
  var prev = n.getAttribute('data-ryker-offset');
2845
- if (prev) n.style.top = prev; else n.style.removeProperty('top');
2846
3091
  n.removeAttribute('data-ryker-offset');
2847
- if (!n.getAttribute('style')) n.removeAttribute('style');
3092
+ if (prev) n.setAttribute('style', prev); else n.removeAttribute('style');
2848
3093
  });
2849
3094
  shifted = [];
2850
3095
  restoreBodyPadding('padding-top');
@@ -2953,7 +3198,7 @@
2953
3198
  setPanelSpace: setPanelSpace, releasePanelSpace: releasePanelSpace,
2954
3199
  setEdgeSpace: setEdgeSpace, releaseEdgeSpace: releaseEdgeSpace,
2955
3200
  originalBodyPadding: originalBodyPadding,
2956
- owns: owns, owner: function () { return owner; },
3201
+ owns: owns, owner: function () { return owner; }, seal: seal,
2957
3202
  shadow: function () { return shadow; },
2958
3203
  host: function () { return host; }
2959
3204
  };
@@ -3122,10 +3367,41 @@
3122
3367
 
3123
3368
  var stack = [];
3124
3369
 
3370
+ // A page that opened a modal of its own (x.com's post composer) may pull
3371
+ // focus back into it the moment focus leaves, which is what a focus trap
3372
+ // is for, and Ryker's fields would then hand every keystroke to the page.
3373
+ // While a Ryker dialog is up, each top-level layer holding a visible page
3374
+ // modal is made inert, so a trap has nothing to pull focus back to; the
3375
+ // last dialog to close puts them back. Only those layers, and only ones
3376
+ // this made inert. A report with no modal of its own is never touched.
3377
+ var benched = [];
3378
+ var PAGE_MODAL = '[aria-modal="true"], dialog[open]';
3379
+ function shown(n) { return !!(n.getClientRects && n.getClientRects().length); }
3380
+ function bench() {
3381
+ Array.prototype.forEach.call(document.body ? document.body.children : [], function (layer) {
3382
+ if (layer.inert || Ryker.shell.owns(layer) || benched.indexOf(layer) !== -1) return;
3383
+ var modals = [layer].filter(function (n) { return n.matches(PAGE_MODAL); })
3384
+ .concat(Array.prototype.slice.call(layer.querySelectorAll(PAGE_MODAL)));
3385
+ if (!modals.some(shown)) return;
3386
+ layer.inert = true;
3387
+ benched.push(layer);
3388
+ });
3389
+ }
3390
+ function unbench() {
3391
+ benched.forEach(function (layer) { layer.inert = false; });
3392
+ benched = [];
3393
+ }
3394
+
3395
+ // opts.size 'large' centres a wide dialog instead of docking a narrow one at
3396
+ // the right. The right-hand dock is for writing about text that must stay in
3397
+ // view; a dialog that is itself the place the text is worked on (Rewrite,
3398
+ // sow-011) wants the room, and the owner asked for it large and centred.
3125
3399
  function open(opts) {
3126
3400
  var d = Ryker.dom;
3127
- var backdrop = d.el('div', { class: 'backdrop', role: 'dialog', 'aria-modal': 'true' });
3401
+ var large = opts.size === 'large';
3402
+ var backdrop = d.el('div', { class: 'backdrop' + (large ? ' center' : ''), role: 'dialog', 'aria-modal': 'true' });
3128
3403
  var body = d.el('div', { class: 'body' });
3404
+ var heading = d.el('h2', { text: opts.title || 'Ryker' });
3129
3405
 
3130
3406
  if (typeof opts.body === 'string') body.innerHTML = opts.body;
3131
3407
  else if (opts.body) body.appendChild(opts.body);
@@ -3135,6 +3411,7 @@
3135
3411
  close: function () { close(backdrop); },
3136
3412
  body: body,
3137
3413
  foot: foot,
3414
+ setTitle: function (text) { heading.textContent = text || 'Ryker'; },
3138
3415
  setBody: function (node) {
3139
3416
  body.innerHTML = '';
3140
3417
  if (typeof node === 'string') body.innerHTML = node;
@@ -3167,8 +3444,8 @@
3167
3444
  foot.appendChild(d.el('button', { class: 'rk', text: 'Close', onclick: api.close }));
3168
3445
  }
3169
3446
 
3170
- var modal = d.el('div', { class: 'modal' }, [
3171
- d.el('header', {}, [d.el('h2', { text: opts.title || 'Ryker' })]),
3447
+ var modal = d.el('div', { class: 'modal' + (large ? ' large' : '') }, [
3448
+ d.el('header', {}, [heading]),
3172
3449
  body,
3173
3450
  foot
3174
3451
  ]);
@@ -3179,8 +3456,12 @@
3179
3456
  });
3180
3457
 
3181
3458
  Ryker.shell.add(backdrop);
3182
- stack.push({ node: backdrop, api: api });
3459
+ // opts.onClose runs however the dialog goes: a button, Escape, the
3460
+ // backdrop. Rewrite needs it to stop a sign-in wait or a request that
3461
+ // would otherwise keep running against the person's plan.
3462
+ stack.push({ node: backdrop, api: api, onClose: opts.onClose });
3183
3463
 
3464
+ bench();
3184
3465
  var focusable = modal.querySelector('button.rk, input, textarea');
3185
3466
  if (focusable) focusable.focus();
3186
3467
 
@@ -3191,7 +3472,9 @@
3191
3472
  for (var i = stack.length - 1; i >= 0; i--) {
3192
3473
  if (!node || stack[i].node === node) {
3193
3474
  if (stack[i].node.parentNode) stack[i].node.parentNode.removeChild(stack[i].node);
3194
- stack.splice(i, 1);
3475
+ var gone = stack.splice(i, 1)[0];
3476
+ if (!stack.length) unbench();
3477
+ if (gone.onClose) { try { gone.onClose(); } catch (e) {} }
3195
3478
  if (!node) return;
3196
3479
  }
3197
3480
  }
@@ -3322,17 +3605,26 @@
3322
3605
  if (anchor && anchor.nodeType === 1) anchor.setAttribute('aria-expanded', 'true');
3323
3606
  setTimeout(function () {
3324
3607
  document.addEventListener('mousedown', onAway, true);
3608
+ inside('addEventListener');
3325
3609
  document.addEventListener('keydown', onKey, true);
3326
3610
  }, 0);
3327
3611
  var first = list.querySelector('.menu-item');
3328
3612
  if (first) first.focus();
3329
3613
  }
3330
3614
 
3615
+ // The same listener on Ryker's own root. From the document a sealed root
3616
+ // shows only its host, so a press inside Ryker is judged from in here.
3617
+ function inside(method) {
3618
+ var root = Ryker.shell && Ryker.shell.shadow && Ryker.shell.shadow();
3619
+ if (root) root[method]('mousedown', onAway, true);
3620
+ }
3621
+
3331
3622
  function onAway(e) {
3332
3623
  if (!open) return;
3333
3624
  // The menu lives in a shadow root, so a click inside it reports the host as
3334
3625
  // its target in the light DOM. composedPath is the only reliable test.
3335
3626
  var path = e.composedPath ? e.composedPath() : [];
3627
+ if (e.currentTarget === document && path[0] === Ryker.shell.host()) return;
3336
3628
  if (path.indexOf(open.node) !== -1 || path.indexOf(open.anchor) !== -1) return;
3337
3629
  close();
3338
3630
  }
@@ -3349,6 +3641,7 @@
3349
3641
  }
3350
3642
  open = null;
3351
3643
  document.removeEventListener('mousedown', onAway, true);
3644
+ inside('removeEventListener');
3352
3645
  document.removeEventListener('keydown', onKey, true);
3353
3646
  }
3354
3647
 
@@ -4252,7 +4545,7 @@
4252
4545
  enable: enable, disable: disable, isOn: isOn, changes: changes, isDirty: isDirty,
4253
4546
  baselineOf: baselineOf,
4254
4547
  rebase: rebase, revertAll: revertAll, revertBlock: revertBlock,
4255
- setBaseline: setBaseline, onChange: onChange, rebind: rebind, touch: emit,
4548
+ setBaseline: setBaseline, onChange: onChange, rebind: rebind, touch: emit, mark: mark,
4256
4549
  format: format, makeLink: makeLink, splitAt: splitAt,
4257
4550
  convert: convert, blockTypeOf: blockTypeOf, BLOCK_TYPES: BLOCK_TYPES
4258
4551
  };
@@ -4342,6 +4635,7 @@
4342
4635
  if (before === after) return;
4343
4636
  push({
4344
4637
  label: 'edit',
4638
+ node: node,
4345
4639
  undo: function () { node.innerHTML = before; place(node); },
4346
4640
  redo: function () { node.innerHTML = after; place(node); }
4347
4641
  });
@@ -4365,6 +4659,21 @@
4365
4659
  catch (e) { if (Ryker.log) Ryker.log('history ' + dir + ': ' + e.message); }
4366
4660
  applying = false;
4367
4661
  emit();
4662
+ // The editor's own change signal, which the toolbar, the outline and the
4663
+ // recovery draft listen to. Every other structural edit already sends it
4664
+ // (links, multi, table, move); undo and redo did not, so Save could stay
4665
+ // disabled over a redone edit until something unrelated resynced the bar,
4666
+ // and a block's edited mark outlived the undo that cleared it. Found by the
4667
+ // sow-011 suite: accept a rewrite, Ctrl+Z, Ctrl+Shift+Z, and Save was dead.
4668
+ // entry.nodes is an edit that changed several blocks as one step (a
4669
+ // rewrite of picked paragraphs), so one undo puts them all back.
4670
+ try {
4671
+ var touched = entry.nodes || (entry.node ? [entry.node] : []);
4672
+ touched.forEach(function (n) {
4673
+ if (Ryker.editable.mark) Ryker.editable.mark(n, Ryker.blocks.blockId(n));
4674
+ });
4675
+ Ryker.editable.touch();
4676
+ } catch (e) { if (Ryker.log) Ryker.log('history ' + dir + ' sync: ' + e.message); }
4368
4677
  }
4369
4678
 
4370
4679
  function undo() {
@@ -4515,6 +4824,10 @@
4515
4824
  // Ryker takes over only inside one of the document blocks it armed; doing
4516
4825
  // otherwise makes Ctrl+Z in a link/save dialog mutate the page behind it.
4517
4826
  var path = e.composedPath ? e.composedPath() : [];
4827
+ // A sealed root shows the document only its host, so the field holding
4828
+ // the caret inside Ryker is asked for by name.
4829
+ var root = Ryker.shell && Ryker.shell.shadow && Ryker.shell.shadow();
4830
+ if (root && root.activeElement) path = [root.activeElement].concat(path);
4518
4831
  for (var i = 0; i < path.length; i++) {
4519
4832
  var n = path[i];
4520
4833
  if (!n || !n.tagName) continue;
@@ -4706,9 +5019,18 @@
4706
5019
  return Ryker.multi.covered();
4707
5020
  }
4708
5021
 
5022
+ // A selection or caret in a text box the page owns (editor/fields.js). Its
5023
+ // formatting, links and rows are the page's: a Ryker edit there would change
5024
+ // the DOM behind the page's own editor state.
5025
+ function inPageField() {
5026
+ var sel = window.getSelection();
5027
+ return !!(sel && sel.rangeCount && Ryker.fields.inField(sel.getRangeAt(0).commonAncestorContainer));
5028
+ }
5029
+
4709
5030
  function update() {
4710
5031
  // Not mid-drag: the bar would flash under the moving pointer.
4711
5032
  if (Ryker.pick && Ryker.pick.isEngaged()) { hide(); return; }
5033
+ if (inPageField()) { hide(); return; }
4712
5034
  var many = spanning();
4713
5035
  var range = editableSelection();
4714
5036
  var link = (!range && !many.length && Ryker.links) ? Ryker.links.at(null) : null;
@@ -4731,7 +5053,9 @@
4731
5053
  var block = range ? currentBlock() : null;
4732
5054
  var table = Ryker.multi && block ? Ryker.multi.tableAt(block) : null;
4733
5055
  var atomic = many.length === 1 && Ryker.blocks.atomic(many[0]);
4734
- var wide = many.length > 1 || atomic;
5056
+ // Any pick, one block included: a Ctrl+clicked paragraph has no Range for
5057
+ // bold or italic to act on, so the formatting set would be dead buttons.
5058
+ var wide = many.length > 0;
4735
5059
 
4736
5060
  // Four modes. A picked run of blocks gets only Delete, a caret resting in
4737
5061
  // a link gets only the link control, a caret resting in a cell gets only
@@ -4749,7 +5073,8 @@
4749
5073
  if (show) {
4750
5074
  Ryker.tooltip.attach(killBtn,
4751
5075
  atomic ? 'Delete this whole SVG' :
4752
- (many.length > 1 ? 'Delete the ' + many.length + ' selected blocks' : 'Delete this whole table'));
5076
+ (many.length > 1 ? 'Delete the ' + many.length + ' selected blocks'
5077
+ : (many.length === 1 ? 'Delete the selected block' : 'Delete this whole table')));
4753
5078
  Ryker.tooltip.attach(gridBtn, 'Add or remove a row or column');
4754
5079
  }
4755
5080
 
@@ -5003,7 +5328,7 @@
5003
5328
  // of our own surfaces is in the way and there is no block under the pointer.
5004
5329
  function blockAt(x, y) {
5005
5330
  var el = document.elementFromPoint(x, y);
5006
- if (!el || inShell(el)) return null;
5331
+ if (!el || inShell(el) || Ryker.fields.inField(el)) return null;
5007
5332
  var b = el.closest ? el.closest(Ryker.blocks.PICK_SELECTOR) : null;
5008
5333
  if (!b || inShell(b)) return null;
5009
5334
  if (Ryker.blocks.excluded(b)) return null;
@@ -5015,9 +5340,22 @@
5015
5340
  // Dragging down the page margin resolves no element at all, and without this
5016
5341
  // the whole gesture picks nothing. The 200px clamp is load bearing: unbounded,
5017
5342
  // a pointer in the margin grabs a block from the far end of the document.
5343
+ //
5344
+ // Margin means the document's own margin. A pointer over a dialog the page
5345
+ // opened, a text box it owns, or anything outside the document root is over
5346
+ // something else, and the nearest block is behind it (x.com, 2026-11-10: a
5347
+ // press in the post composer picked an icon in the timeline underneath).
5348
+ function margin(el) {
5349
+ if (!el) return true;
5350
+ var root = Ryker.blocks.root();
5351
+ if (el === root || el.contains(root)) return true;
5352
+ return root.contains(el) && !Ryker.fields.inLayer(el) && !Ryker.fields.inField(el);
5353
+ }
5354
+
5018
5355
  function blockNear(x, y) {
5019
5356
  var hit = blockAt(x, y);
5020
5357
  if (hit) return hit;
5358
+ if (!margin(document.elementFromPoint(x, y))) return null;
5021
5359
  var rr = Ryker.blocks.root().getBoundingClientRect();
5022
5360
  if (x < rr.left - 40 || x > rr.right + 40) return null;
5023
5361
  var list = seq || Ryker.blocks.pickSequence();
@@ -5113,11 +5451,67 @@
5113
5451
  raf = window.requestAnimationFrame(step);
5114
5452
  }
5115
5453
 
5454
+ // Ctrl+click, or Cmd+click on macOS, selects the whole of a heading or a
5455
+ // paragraph (sow-011). Cmd there because Ctrl+click on a Mac is a right-click.
5456
+ // Read per press rather than once at load, so a test can stand in for a Mac.
5457
+ function mac() { return /Mac|iPhone|iPad|iPod/.test(navigator.platform || ''); }
5458
+ function wholeKeyLabel() { return mac() ? 'Cmd' : 'Ctrl'; }
5459
+ function wholeGesture(e) {
5460
+ if (e.altKey || e.shiftKey) return false;
5461
+ return mac() ? e.metaKey : e.ctrlKey;
5462
+ }
5463
+
5464
+ // A heading or a paragraph that can be picked whole: armed, not atomic, and
5465
+ // holding some text. Comment and Rewrite read the pick through the same test,
5466
+ // so the gesture and the controls agree about what counts.
5467
+ function prose(n) {
5468
+ return !!(n && n.isConnected && /^(P|H[1-6])$/.test(n.tagName) && n.isContentEditable &&
5469
+ !Ryker.blocks.atomic(n) && String(n.textContent || '').trim());
5470
+ }
5471
+
5472
+ // Ctrl+click toggles a block in and out of the pick, the bordered set a drag
5473
+ // or Shift+click makes, so one block and several look the same and a second
5474
+ // Ctrl+click adds rather than replaces (the owner, 2026-11-09; the first
5475
+ // build made an ordinary text selection, which a second click replaced).
5476
+ // Gaps are allowed. Headings and paragraphs only, per the owner; every other
5477
+ // block keeps today's behaviour.
5478
+ function toggleWhole(e) {
5479
+ var block = blockAt(e.clientX, e.clientY);
5480
+ if (!prose(block)) return false;
5481
+ e.preventDefault();
5482
+ dropNative();
5483
+ var at = picked.indexOf(block);
5484
+ if (at === -1) { paint(picked.concat([block])); origin = block; }
5485
+ else paint(picked.slice(0, at).concat(picked.slice(at + 1)));
5486
+ return true;
5487
+ }
5488
+
5489
+ // The click that follows the press. Swallowed so that Ctrl+click on a link
5490
+ // inside the block picks the block rather than opening the link.
5491
+ var swallowClick = false;
5492
+
5116
5493
  function down(e) {
5494
+ swallowClick = false;
5117
5495
  if (e.button !== 0) return;
5118
5496
  if (inShell(e.target)) return;
5119
5497
  if (!Ryker.editable.isOn()) return;
5120
5498
 
5499
+ if (wholeGesture(e) && toggleWhole(e)) { swallowClick = true; return; }
5500
+
5501
+ // A text box the page owns gets the press untouched, so it can take the
5502
+ // caret and its own selection. Ctrl+click there selects the paragraph as
5503
+ // ordinary text (editor/fields.js), the closest a page's editor can come
5504
+ // to a pick, and Rewrite reads it from the selection.
5505
+ var editor = Ryker.fields.editorOf(e.target);
5506
+ if (editor || Ryker.fields.isTextControl(e.target)) {
5507
+ clear();
5508
+ if (editor && wholeGesture(e) && Ryker.fields.selectLine(editor, e.target)) {
5509
+ e.preventDefault();
5510
+ swallowClick = true;
5511
+ }
5512
+ return;
5513
+ }
5514
+
5121
5515
  if (e.shiftKey && picked.length) {
5122
5516
  var hit = blockNear(e.clientX, e.clientY);
5123
5517
  if (hit) { e.preventDefault(); dropNative(); extend(hit); }
@@ -5127,7 +5521,9 @@
5127
5521
  clear();
5128
5522
  seq = Ryker.blocks.pickSequence();
5129
5523
  origin = blockNear(e.clientX, e.clientY);
5130
- if (Ryker.blocks.atomic(origin)) {
5524
+ // A chart is picked by pressing on it. Reached through the margin it
5525
+ // would take the press away from whatever is actually under the pointer.
5526
+ if (Ryker.blocks.atomic(origin) && origin === blockAt(e.clientX, e.clientY)) {
5131
5527
  e.preventDefault();
5132
5528
  dropNative();
5133
5529
  paint([origin]);
@@ -5173,6 +5569,12 @@
5173
5569
  document.addEventListener('mousedown', down, true);
5174
5570
  document.addEventListener('mousemove', move, true);
5175
5571
  document.addEventListener('mouseup', up, true);
5572
+ document.addEventListener('click', function (e) {
5573
+ if (!swallowClick) return;
5574
+ swallowClick = false;
5575
+ e.preventDefault();
5576
+ e.stopPropagation();
5577
+ }, true);
5176
5578
  window.addEventListener('pointercancel', up, true);
5177
5579
  document.addEventListener('keydown', function (e) {
5178
5580
  if (e.key === 'Escape' && picked.length) clear();
@@ -5191,7 +5593,7 @@
5191
5593
  rect: rect, set: set, extend: extend, clear: clear,
5192
5594
  isEngaged: function () { return engaged; },
5193
5595
  has: function (n) { return picked.indexOf(n) !== -1; },
5194
- onChange: onChange
5596
+ onChange: onChange, wholeKeyLabel: wholeKeyLabel, prose: prose
5195
5597
  };
5196
5598
  })();
5197
5599
 
@@ -5326,9 +5728,13 @@
5326
5728
  }
5327
5729
 
5328
5730
  // The selection route: what someone gets from dragging across blocks.
5731
+ // One picked block is enough since Ctrl+click picks a single paragraph or
5732
+ // heading with the same borders a drag gives several (sow-011). The pick is
5733
+ // still only ever filled by a gesture Ryker tracked, so the select-all hazard
5734
+ // recorded above stays closed.
5329
5735
  function removeSelection() {
5330
5736
  var nodes = covered();
5331
- if (nodes.length < 2 && !(nodes.length === 1 && Ryker.blocks.atomic(nodes[0]))) return false;
5737
+ if (!nodes.length) return false;
5332
5738
  return removeNodes(collapse(nodes));
5333
5739
  }
5334
5740
 
@@ -5353,9 +5759,9 @@
5353
5759
  for (var i = 0; i < path.length; i++) {
5354
5760
  if (path[i] && Ryker.shell && Ryker.shell.owns(path[i])) return;
5355
5761
  if (path[i] && path[i].tagName === 'TEXTAREA') return;
5762
+ if (path[i] && path[i].nodeType === 1 && Ryker.fields.inField(path[i])) return;
5356
5763
  }
5357
- var picked = Ryker.pick.picked();
5358
- if (picked.length < 2 && !(picked.length === 1 && Ryker.blocks.atomic(picked[0]))) return;
5764
+ if (!Ryker.pick.picked().length) return;
5359
5765
  e.preventDefault();
5360
5766
  e.stopPropagation();
5361
5767
  removeSelection();
@@ -8244,7 +8650,13 @@
8244
8650
  function onChange(fn) { listeners.push(fn); }
8245
8651
  function emit() { listeners.forEach(function (f) { try { f(); } catch (e) {} }); }
8246
8652
 
8247
- function reset() { saved = null; savedTree = null; saves = 0; saveNotes = []; emit(); }
8653
+ function reset() {
8654
+ saved = null; savedTree = null; saves = 0; saveNotes = [];
8655
+ // Comments go with them. Clear document that left notes quoting blocks the
8656
+ // document no longer contains would be worse than losing them.
8657
+ if (Ryker.comments) Ryker.comments.reset();
8658
+ emit();
8659
+ }
8248
8660
  function originalOf(id) { return pristineHtml(id); }
8249
8661
  function saveCount() { return saves; }
8250
8662
 
@@ -8441,14 +8853,21 @@
8441
8853
  // instruction set that repeats it reads as deliberate unless something says
8442
8854
  // so. Named rather than silently deduplicated, because only the author knows
8443
8855
  // which copy was meant.
8444
- function suspicious(list) {
8856
+ //
8857
+ // The numbers have to be the numbers the reader will see. build() writes the
8858
+ // moves first and the steps after them, so a step's heading is base + i + 1
8859
+ // where base is the move count. Counting from 1 here named a move as the
8860
+ // duplicate paste and never named the last insert at all, and the preamble
8861
+ // tells an agent to delete the steps it does not want by number.
8862
+ function suspicious(list, base) {
8445
8863
  var out = [];
8446
8864
  var byText = {};
8865
+ base = base || 0;
8447
8866
  list.forEach(function (e, i) {
8448
8867
  if (e.kind !== 'insert') return;
8449
8868
  var k = text(e.after);
8450
8869
  if (!k) return;
8451
- (byText[k] = byText[k] || []).push(i + 1);
8870
+ (byText[k] = byText[k] || []).push(base + i + 1);
8452
8871
  });
8453
8872
  Object.keys(byText).forEach(function (k) {
8454
8873
  var steps = byText[k];
@@ -8467,10 +8886,12 @@
8467
8886
  if (lost.length < 40) return;
8468
8887
  var echoes = [];
8469
8888
  list.forEach(function (o, j) {
8470
- if (o.kind === 'insert' && text(o.after).indexOf(lost.slice(0, 40)) !== -1) echoes.push(j + 1);
8889
+ if (o.kind === 'insert' && text(o.after).indexOf(lost.slice(0, 40)) !== -1) {
8890
+ echoes.push(base + j + 1);
8891
+ }
8471
8892
  });
8472
8893
  if (echoes.length > 1) {
8473
- out.push('Step ' + (i + 1) + ' removes a sentence that steps ' + echoes.join(', ') +
8894
+ out.push('Step ' + (base + i + 1) + ' removes a sentence that steps ' + echoes.join(', ') +
8474
8895
  ' then add back. Check the split was intended once, not ' + echoes.length + ' times.');
8475
8896
  }
8476
8897
  });
@@ -8501,6 +8922,7 @@
8501
8922
  { where: where, text: text });
8502
8923
  var mv = moves();
8503
8924
  var out = [];
8925
+ var notesCount = Ryker.comments ? Ryker.comments.count() : 0;
8504
8926
 
8505
8927
  out.push('# Document edit instructions');
8506
8928
  out.push('');
@@ -8516,6 +8938,7 @@
8516
8938
  }
8517
8939
  out.push('Edits: ' + list.length + ' change(s)' +
8518
8940
  (mv.length ? ' and ' + mv.length + ' move(s)' : '') +
8941
+ (notesCount ? ' and ' + notesCount + ' comment(s)' : '') +
8519
8942
  ' across ' + saves + ' save(s) this session');
8520
8943
  out.push('');
8521
8944
 
@@ -8534,13 +8957,24 @@
8534
8957
  });
8535
8958
  }
8536
8959
 
8960
+ var comments = Ryker.comments ? Ryker.comments.render() : [];
8961
+ if (comments.length) out.push.apply(out, comments);
8962
+
8537
8963
  if (!list.length && !mv.length) {
8538
- out.push('No edits have been made yet. Edit the document and press Save to');
8539
- out.push('build a set of instructions here.');
8964
+ // A document carrying comments and no edits used to be told nothing had
8965
+ // been done, directly underneath the comments it was showing.
8966
+ if (notesCount) {
8967
+ out.push('No edits have been made. The comments above are the whole of this');
8968
+ out.push('document: read them, and change nothing on their account unless the');
8969
+ out.push('comment asks you to.');
8970
+ } else {
8971
+ out.push('No edits have been made yet. Edit the document and press Save to');
8972
+ out.push('build a set of instructions here.');
8973
+ }
8540
8974
  return out.join('\n');
8541
8975
  }
8542
8976
 
8543
- var warnings = suspicious(list);
8977
+ var warnings = suspicious(list, mv.length);
8544
8978
  if (warnings.length) {
8545
8979
  out.push('## Check these before applying');
8546
8980
  out.push('');
@@ -8631,7 +9065,8 @@
8631
9065
  out.push('---');
8632
9066
  out.push('');
8633
9067
  out.push('End of instructions. ' + list.length + ' edit(s)' +
8634
- (mv.length ? ' and ' + mv.length + ' move(s)' : '') + '.');
9068
+ (mv.length ? ' and ' + mv.length + ' move(s)' : '') +
9069
+ (notesCount ? ' and ' + notesCount + ' comment(s)' : '') + '.');
8635
9070
  return out.join('\n');
8636
9071
  }
8637
9072
 
@@ -8641,7 +9076,7 @@
8641
9076
  sessionId: sessionId, editingSessionId: editingSessionId,
8642
9077
  recoveryChanges: recoveryChanges, recoveryMoves: recoveryMoves,
8643
9078
  saveCount: saveCount, saveNotes: notes,
8644
- onChange: onChange, where: where, suspicious: suspicious
9079
+ onChange: onChange, touch: emit, where: where, suspicious: suspicious
8645
9080
  };
8646
9081
  })();
8647
9082
 
@@ -8690,6 +9125,12 @@
8690
9125
  return [];
8691
9126
  }
8692
9127
 
9128
+ // A record written before comments existed has no field, which is the normal
9129
+ // case for the whole logged corpus and not an error.
9130
+ function commentsOf(rec) {
9131
+ return Array.isArray(rec && rec.comments) ? rec.comments : [];
9132
+ }
9133
+
8693
9134
  function norm(html) {
8694
9135
  if (html == null) return '';
8695
9136
  return String(html).replace(/\s+/g, ' ').trim();
@@ -8899,6 +9340,20 @@
8899
9340
  });
8900
9341
  });
8901
9342
 
9343
+ // Same rule as the notes: a later save from the same session supersedes an
9344
+ // earlier one, so only the winner is read. Deduped by id across groups
9345
+ // because a record carries every comment standing when it was written, and
9346
+ // two groups from one page load would otherwise repeat all of them.
9347
+ var comments = [];
9348
+ var seenComment = {};
9349
+ groups.forEach(function (g) {
9350
+ commentsOf(g.winner).forEach(function (c) {
9351
+ if (!c || !c.id || seenComment[c.id] || !String(c.body || '').trim()) return;
9352
+ seenComment[c.id] = true;
9353
+ comments.push(c);
9354
+ });
9355
+ });
9356
+
8902
9357
  var warnings = [];
8903
9358
  if (promptOnly) {
8904
9359
  warnings.push(promptOnly + ' record(s) carry only a prose prompt with no structured ' +
@@ -8961,6 +9416,7 @@
8961
9416
  cancelled: cancelled,
8962
9417
  promptOnly: promptOnly,
8963
9418
  notes: notes,
9419
+ comments: comments,
8964
9420
  accounted: accounted,
8965
9421
  refused: refused,
8966
9422
  warnings: warnings.concat(dupes),
@@ -9011,6 +9467,12 @@
9011
9467
  out.push('');
9012
9468
  });
9013
9469
  }
9470
+ // Comments recovered from the folded records, in the same words the live
9471
+ // pane uses, because an agent should not have to learn two ways of being
9472
+ // told that a section is not a set of steps.
9473
+ if (r.comments && r.comments.length && Ryker.comments) {
9474
+ out.push.apply(out, Ryker.comments.renderList(r.comments));
9475
+ }
9014
9476
  out.push('---');
9015
9477
  out.push('');
9016
9478
  r.steps.forEach(function (s, i) {
@@ -9053,6 +9515,377 @@
9053
9515
  })();
9054
9516
 
9055
9517
 
9518
+ /* ---- comments/comments.js -------------------------------------- */
9519
+ // Comments on highlighted material: notes about the document rather than
9520
+ // instructions to change it.
9521
+ //
9522
+ // Nothing here touches the page. A comment is data, and only data: the block it
9523
+ // was made in, the words that were highlighted, and what the reader said about
9524
+ // them. Marking the selection instead, by wrapping it in an element, was
9525
+ // measured and rejected. blocks.snapshot() records a block's innerHTML verbatim
9526
+ // and diffSnapshots reports any string difference as a content change, so a
9527
+ // wrapper would manufacture an edit step telling an agent to alter text that
9528
+ // nobody altered. That is precisely the outcome this feature exists to avoid,
9529
+ // and it would also have to be added by hand to three separate strip lists to
9530
+ // keep the export clean.
9531
+ //
9532
+ // Comments were specified in sections 13 to 15 of the Phase 1 specification and
9533
+ // planned as sow-004 Phase 4, on top of an append-only journal that sow-006
9534
+ // retired. This is the same feature rebuilt on what Ryker actually has.
9535
+ Ryker.comments = (function () {
9536
+ 'use strict';
9537
+
9538
+ var list = [];
9539
+ var listeners = [];
9540
+ var offered = false;
9541
+
9542
+ // Enough of either side to tell two identical sentences apart, short enough
9543
+ // that the record stays small when a draft carries a hundred of them. Nothing
9544
+ // reads these yet. They are captured because they can only be captured now:
9545
+ // section 14's relocation needs them and the material will have moved by the
9546
+ // time anyone wants it.
9547
+ var CONTEXT = 40;
9548
+
9549
+ function onChange(fn) { listeners.push(fn); }
9550
+ function emit() { listeners.forEach(function (f) { try { f(); } catch (e) {} }); }
9551
+
9552
+ function flat(value) { return String(value == null ? '' : value).replace(/\s+/g, ' ').trim(); }
9553
+
9554
+ function hostOf(range) {
9555
+ if (!range) return null;
9556
+ var node = range.commonAncestorContainer;
9557
+ if (node && node.nodeType === 3) node = node.parentElement;
9558
+ if (!node || !node.closest) return null;
9559
+ return node.closest('[contenteditable="true"]');
9560
+ }
9561
+
9562
+ /** The live selection, cloned, or null when there is nothing to comment on.
9563
+ *
9564
+ * Cloned, and cloned synchronously by the caller, because by the time a
9565
+ * dialog button runs its action the selection is gone. Measured 2026-08-25
9566
+ * on the fixture: with fifteen characters highlighted, opening a dialog with
9567
+ * a textarea in it left `String(getSelection())` as the empty string, since
9568
+ * dialog.open focuses the first field in the modal and the editing host
9569
+ * drops its selection on losing focus. The highlight is still painted on
9570
+ * screen at that moment, so reading the selection in the confirm handler is
9571
+ * the worst kind of wrong: silent, plausible, and visible only in the
9572
+ * finished document.
9573
+ *
9574
+ * A range spanning two blocks never arrives here. Measured the same day: the
9575
+ * Selection clamps such a range to the first block, and its
9576
+ * commonAncestorContainer becomes the section rather than an editable, so
9577
+ * hostOf returns null. Single block is not a limitation this chose; it is
9578
+ * what highlighting means inside a per-block contenteditable. */
9579
+ function pending() {
9580
+ var sel = window.getSelection();
9581
+ if (!sel || !sel.rangeCount) return null;
9582
+ var range = sel.getRangeAt(0);
9583
+ if (range.collapsed) return null;
9584
+ if (!hostOf(range)) return null;
9585
+ if (!flat(range.toString())) return null;
9586
+ return range.cloneRange();
9587
+ }
9588
+
9589
+ /** The picked headings and paragraphs, in document order, or null.
9590
+ *
9591
+ * Ctrl+click picks whole blocks with borders rather than highlighting text
9592
+ * (sow-011, the owner, 2026-11-09), and several can be picked, so this is
9593
+ * the second thing a comment can be about. Every picked block must be a
9594
+ * heading or paragraph with text in it, by the same test the gesture uses;
9595
+ * a drag that took in a list item or a figure offers no comment, which is
9596
+ * what it offered before picks counted at all. A pick is checked first: the
9597
+ * gesture that makes one drops the text selection, so the two never mean
9598
+ * different things at once. */
9599
+ function pendingBlocks() {
9600
+ var list = Ryker.pick ? Ryker.pick.picked() : [];
9601
+ if (!list.length) return null;
9602
+ for (var i = 0; i < list.length; i++) if (!Ryker.pick.prose(list[i])) return null;
9603
+ return list.slice().sort(function (a, b) {
9604
+ return a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
9605
+ });
9606
+ }
9607
+
9608
+ function available() { return !!pendingBlocks() || !!pending(); }
9609
+
9610
+ /** The text of a range as a reader sees it, on one line.
9611
+ *
9612
+ * Not `range.toString()`, which concatenates Text nodes and contributes
9613
+ * nothing at all for a `<br>`. A block holding `Revenue rose<br>in the second
9614
+ * half.` gave back "rosein" for a highlight the browser itself reported as
9615
+ * "rose\nin", so the record of what somebody highlighted was a word that does
9616
+ * not occur in the document. Line breaks are common inside one block: paste
9617
+ * puts one between unwrapped paragraphs, Shift+Enter makes one, and Enter in
9618
+ * a table cell makes one. The quote renders on a single "> " line, so a space
9619
+ * is what the break means here. */
9620
+ function textOfRange(range) {
9621
+ try {
9622
+ var holder = document.createElement('div');
9623
+ holder.appendChild(range.cloneContents());
9624
+ Array.prototype.forEach.call(holder.querySelectorAll('br'), function (br) {
9625
+ br.parentNode.replaceChild(document.createTextNode(' '), br);
9626
+ });
9627
+ return flat(holder.textContent);
9628
+ } catch (e) { return flat(range.toString()); }
9629
+ }
9630
+
9631
+ // The text between the block's start and the highlight, and between the
9632
+ // highlight and the block's end. Built from the block rather than the
9633
+ // document so a comment near a boundary cannot quietly capture a neighbour.
9634
+ function edge(host, range, side) {
9635
+ try {
9636
+ var r = document.createRange();
9637
+ r.selectNodeContents(host);
9638
+ if (side === 'before') r.setEnd(range.startContainer, range.startOffset);
9639
+ else r.setStart(range.endContainer, range.endOffset);
9640
+ return textOfRange(r);
9641
+ } catch (e) { return ''; }
9642
+ }
9643
+
9644
+ function capture(range) {
9645
+ var host = hostOf(range);
9646
+ if (!host) return null;
9647
+ var quote = textOfRange(range);
9648
+ if (!quote) return null;
9649
+ return {
9650
+ blockId: Ryker.blocks.blockId(host),
9651
+ quote: quote,
9652
+ prefix: edge(host, range, 'before').slice(-CONTEXT),
9653
+ suffix: edge(host, range, 'after').slice(0, CONTEXT)
9654
+ };
9655
+ }
9656
+
9657
+ /** A comment on whole picked blocks. One block is recorded exactly as a
9658
+ * highlight of all its text would be, so the record and the instructions
9659
+ * are unchanged for the common case. Several keep the first block as
9660
+ * blockId and add blocks, one { blockId, quote } each, which renderList
9661
+ * turns into one quote per block under where it sits. */
9662
+ function captureBlocks(nodes) {
9663
+ var parts = (nodes || []).map(function (n) {
9664
+ return { blockId: Ryker.blocks.blockId(n), quote: flat(n.innerText || n.textContent) };
9665
+ }).filter(function (b) { return b.blockId && b.quote; });
9666
+ if (!parts.length) return null;
9667
+ var anchor = { blockId: parts[0].blockId, prefix: '', suffix: '',
9668
+ quote: parts.map(function (b) { return b.quote; }).join('\n') };
9669
+ if (parts.length > 1) anchor.blocks = parts;
9670
+ return anchor;
9671
+ }
9672
+
9673
+ function copyBlocks(blocks) {
9674
+ if (!blocks || !blocks.length) return null;
9675
+ var out = blocks.filter(function (b) { return b && b.blockId && flat(b.quote); })
9676
+ .map(function (b) { return { blockId: String(b.blockId), quote: flat(b.quote) }; });
9677
+ return out.length > 1 ? out : null;
9678
+ }
9679
+
9680
+ function copy(c) {
9681
+ var out = { id: c.id, blockId: c.blockId, quote: c.quote, prefix: c.prefix,
9682
+ suffix: c.suffix, body: c.body, createdAt: c.createdAt };
9683
+ if (c.blocks) out.blocks = copyBlocks(c.blocks);
9684
+ return out;
9685
+ }
9686
+
9687
+ function all() { return list.map(copy); }
9688
+ function count() { return list.length; }
9689
+
9690
+ // One call reaches the pane, the toolbar count and the recovery checkpoint,
9691
+ // because all three already hang off the instruction change signal. Three
9692
+ // separate call sites here would be three things to keep in step.
9693
+ function changed() {
9694
+ emit();
9695
+ if (Ryker.instructions && Ryker.instructions.touch) Ryker.instructions.touch();
9696
+ }
9697
+
9698
+ function store(anchor, body) {
9699
+ body = String(body == null ? '' : body).trim();
9700
+ if (!anchor || !body) return null;
9701
+ var entry = {
9702
+ id: Ryker.dom.uid('comment'),
9703
+ blockId: anchor.blockId,
9704
+ quote: anchor.quote,
9705
+ prefix: anchor.prefix,
9706
+ suffix: anchor.suffix,
9707
+ body: body,
9708
+ createdAt: Ryker.dom.now()
9709
+ };
9710
+ var blocks = copyBlocks(anchor.blocks);
9711
+ if (blocks) entry.blocks = blocks;
9712
+ list.push(entry);
9713
+ changed();
9714
+ return entry;
9715
+ }
9716
+
9717
+ /** Records a comment against a range the caller captured. Separate from
9718
+ * open() so the store can be driven without a dialog, which is what a
9719
+ * restore does and what a test that is not about the dialog should do. */
9720
+ function add(range, body) {
9721
+ return store(capture(range), body);
9722
+ }
9723
+
9724
+ function remove(id) {
9725
+ for (var i = 0; i < list.length; i++) {
9726
+ if (list[i].id === id) { list.splice(i, 1); changed(); return true; }
9727
+ }
9728
+ return false;
9729
+ }
9730
+
9731
+ function reset() {
9732
+ if (!list.length) return;
9733
+ list.length = 0;
9734
+ changed();
9735
+ }
9736
+
9737
+ // Restoring a draft. Ids come back as they were so a second restore of the
9738
+ // same draft does not duplicate what is already here.
9739
+ function restore(saved) {
9740
+ if (!saved || !saved.length) return 0;
9741
+ var known = {};
9742
+ list.forEach(function (c) { known[c.id] = true; });
9743
+ var added = 0;
9744
+ saved.forEach(function (c) {
9745
+ if (!c || !c.id || known[c.id] || !flat(c.body)) return;
9746
+ var entry = {
9747
+ id: String(c.id), blockId: c.blockId ? String(c.blockId) : null,
9748
+ quote: String(c.quote || ''), prefix: String(c.prefix || ''),
9749
+ suffix: String(c.suffix || ''), body: String(c.body),
9750
+ createdAt: c.createdAt || Ryker.dom.now()
9751
+ };
9752
+ var blocks = copyBlocks(c.blocks);
9753
+ if (blocks) entry.blocks = blocks;
9754
+ list.push(entry);
9755
+ known[c.id] = true;
9756
+ added += 1;
9757
+ });
9758
+ if (added) changed();
9759
+ return added;
9760
+ }
9761
+
9762
+ function where(id) {
9763
+ try { return Ryker.instructions.where(id); } catch (e) { return null; }
9764
+ }
9765
+
9766
+ // Both the quote and the body are block quoted, the body included. A comment
9767
+ // beginning "- rewrite this" would otherwise put a bare list marker into the
9768
+ // document above the first step, and the Markdown instruction rules forbid
9769
+ // exactly that: a marker there reads as a step dictating a bullet for a list
9770
+ // the file already has, which is a change nobody asked for.
9771
+ function quote(out, text) {
9772
+ String(text).split(/\r?\n/).forEach(function (line) { out.push('> ' + line); });
9773
+ }
9774
+
9775
+ /** The section, as lines, for instructions.build() to splice in.
9776
+ *
9777
+ * It leads with what these are. An agent handed a document of imperatives
9778
+ * reads everything in it as one unless something says otherwise, and a
9779
+ * comment that gets applied as an edit is worse than no comment at all.
9780
+ *
9781
+ * Takes the list rather than reading the module's own, because merge.js
9782
+ * renders comments recovered from saved records across page loads and the
9783
+ * wording of this section must not exist in two places. */
9784
+ function renderList(items) {
9785
+ if (!items || !items.length) return [];
9786
+ var out = ['## Comments on the material', ''];
9787
+ out.push('Notes from the person who reviewed this document. Nothing in this section asks');
9788
+ out.push('for a change, and none of it is a step to apply. The quoted text records what');
9789
+ out.push('was highlighted when the note was written, so it says what the note is about');
9790
+ out.push('even after the document has moved on. It is not a string to search for.');
9791
+ out.push('');
9792
+ items.forEach(function (c) {
9793
+ var blocks = copyBlocks(c.blocks);
9794
+ if (blocks) {
9795
+ // Several picked blocks, perhaps with gaps between them, so each quote
9796
+ // says where it sits rather than one heading claiming a range.
9797
+ out.push('### On ' + blocks.length + ' blocks');
9798
+ out.push('');
9799
+ blocks.forEach(function (b) {
9800
+ out.push('Highlighted in ' + (where(b.blockId) || 'the document') + ':');
9801
+ out.push('');
9802
+ quote(out, b.quote);
9803
+ out.push('');
9804
+ });
9805
+ } else {
9806
+ out.push('### On ' + (where(c.blockId) || 'the document'));
9807
+ out.push('');
9808
+ out.push('Highlighted:');
9809
+ out.push('');
9810
+ quote(out, c.quote);
9811
+ out.push('');
9812
+ }
9813
+ out.push('Comment:');
9814
+ out.push('');
9815
+ quote(out, c.body);
9816
+ out.push('');
9817
+ });
9818
+ return out;
9819
+ }
9820
+
9821
+ function render() { return renderList(list); }
9822
+
9823
+ /** The dialog. The range is cloned before anything else happens, for the
9824
+ * reason pending() records at length. */
9825
+ function open() {
9826
+ var blocks = pendingBlocks();
9827
+ var range = blocks ? null : pending();
9828
+ var anchor = blocks ? captureBlocks(blocks) : (range && capture(range));
9829
+ if (!anchor) return false;
9830
+
9831
+ var field = Ryker.dom.el('textarea', {
9832
+ class: 'rk comment-body', rows: '5',
9833
+ 'aria-label': 'Your comment on the highlighted text',
9834
+ placeholder: 'What should the person reading this document know about the highlighted text?'
9835
+ });
9836
+ // text, never innerHTML: the quote is somebody's document and the body is
9837
+ // somebody's prose, and neither is markup Ryker should be rendering.
9838
+ var body = Ryker.dom.el('div', {}, [
9839
+ Ryker.dom.el('p', { text: 'Recorded as a note about the highlighted text. ' +
9840
+ 'It travels with the instructions and asks for no change.' }),
9841
+ Ryker.dom.el('blockquote', { class: 'comment-quote', text: anchor.quote }),
9842
+ field
9843
+ ]);
9844
+ var dialog = Ryker.dialog.open({
9845
+ title: 'Comment on the highlighted text',
9846
+ body: body,
9847
+ buttons: [
9848
+ { label: 'Cancel' },
9849
+ { label: 'Add comment', primary: true,
9850
+ action: function () { store(anchor, field.value); } }
9851
+ ]
9852
+ });
9853
+
9854
+ // Offered once there is something to add, the way the save note is. An
9855
+ // empty field makes the button a second Cancel wearing the brand colour.
9856
+ var confirm = dialog.buttons[1];
9857
+ function offer() { confirm.hidden = !field.value.trim(); }
9858
+ field.addEventListener('input', offer);
9859
+ offer();
9860
+ return true;
9861
+ }
9862
+
9863
+ // The control's enabled state follows the selection, and nothing else in
9864
+ // Ryker watches for that. Filtered to the transitions, because selectionchange
9865
+ // fires on every mouse move during a drag and each one would otherwise rebuild
9866
+ // the toolbar.
9867
+ function watch() {
9868
+ var now = available();
9869
+ if (now === offered) return;
9870
+ offered = now;
9871
+ emit();
9872
+ }
9873
+
9874
+ function bind() {
9875
+ document.addEventListener('selectionchange', watch, true);
9876
+ // A pick changes nothing the selection event sees.
9877
+ if (Ryker.pick) Ryker.pick.onChange(watch);
9878
+ }
9879
+
9880
+ return {
9881
+ bind: bind, open: open, add: add, all: all, count: count, remove: remove,
9882
+ reset: reset, restore: restore, render: render, renderList: renderList,
9883
+ available: available, pendingBlocks: pendingBlocks, captureBlocks: captureBlocks,
9884
+ pending: pending, capture: capture, onChange: onChange
9885
+ };
9886
+ })();
9887
+
9888
+
9056
9889
  /* ---- storage/fs.js --------------------------------------------- */
9057
9890
  // The one boundary around browser file access and persisted handles.
9058
9891
  //
@@ -9107,7 +9940,11 @@
9107
9940
  [
9108
9941
  ['saveNotes', 'preference:save-notes'],
9109
9942
  ['paneWidth', 'preference:pane-width'],
9110
- ['railWidth', 'preference:rail-width']
9943
+ ['railWidth', 'preference:rail-width'],
9944
+ ['rewriteCount', 'preference:rewrite-count'],
9945
+ ['rewriteModel', 'preference:rewrite-model'],
9946
+ ['rewriteProfiles', 'preference:rewrite-profiles'],
9947
+ ['rewriteProfile', 'preference:rewrite-profile']
9111
9948
  ].forEach(function (pair) {
9112
9949
  api.get(pair[1]).then(function (value) {
9113
9950
  if (value !== null && value !== undefined) {
@@ -9581,6 +10418,12 @@
9581
10418
  // Move records retain the container-crossing intent that a flat order
9582
10419
  // cannot express when a paragraph or section changes parent.
9583
10420
  moves: Ryker.instructions.recoveryMoves ? Ryker.instructions.recoveryMoves() : [],
10421
+ // Comments ride here as well as in the draft. The draft is the live
10422
+ // carrier and normally wins recovery, but it can be lost to a cleared
10423
+ // origin or a quota refusal, and the saved round is what is left. A
10424
+ // comment is the one thing in a record that exists nowhere else: an edit
10425
+ // can be re-derived from the document, and a note about it cannot.
10426
+ comments: Ryker.comments ? Ryker.comments.all() : [],
9584
10427
  // And the pairs behind it, which is the part worth training on.
9585
10428
  edits: edits.map(function (e) {
9586
10429
  return {
@@ -9847,7 +10690,10 @@
9847
10690
  if (!extensionOwned()) {
9848
10691
  return 'Records are JSON files in the folder you granted Ryker.';
9849
10692
  }
9850
- return 'Kept in this browser only. The page cannot read them and nothing is sent anywhere. ' +
10693
+ // "They", not "nothing": since Rewrite, the extension does send text to
10694
+ // ChatGPT when the person asks for variations. These records still go
10695
+ // nowhere, and the note says exactly that much.
10696
+ return 'Kept in this browser only. The page cannot read them and they are not sent anywhere. ' +
9851
10697
  'They stay until you clear them.';
9852
10698
  }
9853
10699
 
@@ -10506,11 +11352,18 @@
10506
11352
  catch (e) { return null; }
10507
11353
  }
10508
11354
 
11355
+ function notes(found) {
11356
+ return found && Array.isArray(found.comments) ? found.comments.length : 0;
11357
+ }
11358
+
10509
11359
  function fingerprint(found) {
10510
11360
  if (!found) return 'none';
10511
11361
  var count = Array.isArray(found.changes) ? found.changes.length : 0;
10512
11362
  var moves = Array.isArray(found.moves) ? found.moves.length : 0;
10513
- return found.kind + '@' + found.baselineId + '@' + found.savedAt + '@' + count + '@' + moves;
11363
+ // Comments are in the fingerprint or a draft that gained one is mistaken
11364
+ // for a draft already declined, and the offer never appears again.
11365
+ return found.kind + '@' + found.baselineId + '@' + found.savedAt + '@' + count +
11366
+ '@' + moves + '@' + notes(found);
10514
11367
  }
10515
11368
 
10516
11369
  function checkpoint() {
@@ -10521,7 +11374,8 @@
10521
11374
  // is rebased after Save, which would otherwise drop a saved move whenever
10522
11375
  // a later unsaved text edit caused the draft to win recovery selection.
10523
11376
  var moves = Ryker.instructions.recoveryMoves ? Ryker.instructions.recoveryMoves() : [];
10524
- if (!changes.length && !moves.length) {
11377
+ var comments = Ryker.comments ? Ryker.comments.all() : [];
11378
+ if (!changes.length && !moves.length && !comments.length) {
10525
11379
  // Nothing of this page's own to record. Removing here used to be
10526
11380
  // unconditional, and boot arms this timer before anyone has edited
10527
11381
  // anything: editable.enable() fires onChange, schedule() sets it, and
@@ -10540,7 +11394,7 @@
10540
11394
  sessionId: Ryker.instructions.sessionId ? Ryker.instructions.sessionId() : null,
10541
11395
  baselineId: Ryker.instructions.baselineId(),
10542
11396
  savedAt: new Date().toISOString(), changes: changes,
10543
- order: Object.keys(snapshot), moves: moves
11397
+ order: Object.keys(snapshot), moves: moves, comments: comments
10544
11398
  };
10545
11399
  return set(draftKey(), JSON.stringify(draft)).then(function (ok) {
10546
11400
  if (ok) wrote = true;
@@ -10566,7 +11420,8 @@
10566
11420
  return found && found.baselineId &&
10567
11421
  found.baselineId === Ryker.instructions.baselineId() &&
10568
11422
  Array.isArray(found.changes) &&
10569
- (found.changes.length || (Array.isArray(found.moves) && found.moves.length) ||
11423
+ (found.changes.length || notes(found) ||
11424
+ (Array.isArray(found.moves) && found.moves.length) ||
10570
11425
  (Array.isArray(found.order) && found.order.length));
10571
11426
  }
10572
11427
 
@@ -10595,7 +11450,8 @@
10595
11450
  return Ryker.logger.read(entries[i]).then(function (raw) {
10596
11451
  var found = parse(raw);
10597
11452
  if (!found || !Array.isArray(found.changes) ||
10598
- (!found.changes.length && !(Array.isArray(found.moves) && found.moves.length) &&
11453
+ (!found.changes.length && !notes(found) &&
11454
+ !(Array.isArray(found.moves) && found.moves.length) &&
10599
11455
  !(Array.isArray(found.order) && found.order.length))) {
10600
11456
  return next(i + 1);
10601
11457
  }
@@ -10665,7 +11521,8 @@
10665
11521
  applying = false;
10666
11522
  }
10667
11523
  settle(found);
10668
- if (!changes.length && !moveOut.applied) {
11524
+ var restoredNotes = Ryker.comments ? Ryker.comments.restore(found.comments) : 0;
11525
+ if (!changes.length && !moveOut.applied && !restoredNotes) {
10669
11526
  if (out.missed + moveOut.missed) {
10670
11527
  Ryker.dialog.alert('Changes could not be restored',
10671
11528
  (out.missed + moveOut.missed) +
@@ -10693,7 +11550,8 @@
10693
11550
  (moveOut.skipped.length > 1 ? 'them' : 'it') + '.'
10694
11551
  : '';
10695
11552
  Ryker.dialog.alert('Changes restored',
10696
- changes.length + ' block(s) and ' + moveOut.applied + ' move(s) were restored.' +
11553
+ changes.length + ' block(s), ' + moveOut.applied + ' move(s) and ' +
11554
+ restoredNotes + ' comment(s) were restored.' +
10697
11555
  (lost ? ' ' + lost + ' change(s) could not be placed and were skipped.' : '') +
10698
11556
  named, lost ? 'warn' : 'ok');
10699
11557
  return true;
@@ -10715,6 +11573,7 @@
10715
11573
  title: 'Restore earlier changes?',
10716
11574
  body: Ryker.dom.el('div', {}, [
10717
11575
  Ryker.dom.el('p', { text: found.changes.length + ' content change(s)' +
11576
+ (notes(found) ? ' plus ' + notes(found) + ' comment(s)' : '') +
10718
11577
  (found.moves && found.moves.length ? ' plus ' + found.moves.length + ' move(s)' :
10719
11578
  (found.order ? ' plus saved block order' : '')) + ' were found' + when + '.' }),
10720
11579
  Ryker.dom.el('p', { class: 'muted', text: 'The source matches their baseline. Nothing is applied unless you choose Restore.' })
@@ -10818,6 +11677,18 @@
10818
11677
  // No Edit toggle. Ryker exists to edit, and a mode switch that is always in
10819
11678
  // the same position is a control nobody ever needs to touch.
10820
11679
  els.save = d().el('button', { class: 'rk', text: 'Save', onclick: requestSave });
11680
+ // Beside Save, because both record something rather than change it. It keeps
11681
+ // its slot when there is no selection and disables instead of vanishing: the
11682
+ // bar is right-aligned behind a flex spacer, so a control that comes and goes
11683
+ // moves Save out from under the cursor at the moment someone reaches for it.
11684
+ els.comment = d().el('button', { class: 'rk', text: 'Comment',
11685
+ onclick: function () { Ryker.comments.open(); } });
11686
+ // Left of Comment, so Comment keeps its place beside Save (sow-011). Only in
11687
+ // the extension, and only where something can answer it.
11688
+ if (Ryker.rewrite && Ryker.rewrite.transport()) {
11689
+ els.rewrite = d().el('button', { class: 'rk', text: 'Rewrite',
11690
+ onclick: function () { Ryker.rewrite.open(); } });
11691
+ }
10821
11692
  els.pane = d().el('button', { class: 'rk count-only',
10822
11693
  onclick: function () { Ryker.pane.toggle(); } });
10823
11694
 
@@ -10853,10 +11724,12 @@
10853
11724
  Ryker.icons.brandMark(18),
10854
11725
  d().el('span', { class: 'brand', text: 'Ryker' }),
10855
11726
  d().el('span', { class: 'spacer' }),
10856
- els.note, els.more, els.pane, els.collapse, els.save
11727
+ els.note, els.more, els.pane, els.collapse, els.rewrite, els.comment, els.save
10857
11728
  ]);
10858
11729
 
10859
11730
  Ryker.tooltip.attach(els.save, 'Save the edits into the instructions (Ctrl+S)');
11731
+ Ryker.tooltip.attach(els.comment, 'Comment on the highlighted text');
11732
+ if (els.rewrite) Ryker.tooltip.attach(els.rewrite, 'Rewrite the highlighted text');
10860
11733
  Ryker.tooltip.attach(els.pane, 'Show or hide the instructions');
10861
11734
  Ryker.tooltip.attach(els.outline, 'Show or hide the outline');
10862
11735
  Ryker.tooltip.attach(els.more, 'More actions');
@@ -11113,6 +11986,20 @@
11113
11986
  els.save.disabled = !dirty;
11114
11987
  els.save.textContent = 'Save';
11115
11988
 
11989
+ if (els.comment) {
11990
+ var canComment = Ryker.comments ? Ryker.comments.available() : false;
11991
+ els.comment.disabled = !canComment;
11992
+ els.comment.setAttribute('aria-label', canComment
11993
+ ? 'Comment on the highlighted text'
11994
+ : 'Highlight text to comment on it');
11995
+ }
11996
+ if (els.rewrite) {
11997
+ var canRewrite = Ryker.rewrite.available();
11998
+ els.rewrite.disabled = !canRewrite;
11999
+ els.rewrite.setAttribute('aria-label', canRewrite ? 'Rewrite the highlighted text'
12000
+ : 'Select text, or ' + Ryker.pick.wholeKeyLabel() + '+click a heading or paragraph, to rewrite it');
12001
+ }
12002
+
11116
12003
  els.pane.textContent = '';
11117
12004
  els.pane.appendChild(d().el('span', {
11118
12005
  class: 'count' + (edits ? ' warn' : ''), text: String(edits)
@@ -11191,6 +12078,10 @@
11191
12078
  guard('multi', function () { Ryker.multi.init(); });
11192
12079
  guard('rail', function () { Ryker.rail.build(); Ryker.rail.init(); });
11193
12080
  guard('history', function () { Ryker.history.bind(); });
12081
+ guard('comments', function () {
12082
+ Ryker.comments.bind();
12083
+ Ryker.comments.onChange(sync);
12084
+ });
11194
12085
  guard('tooltip', function () { Ryker.tooltip.init(); });
11195
12086
 
11196
12087
  guard('wire', function () {