annotepage-client 2.29.0 → 2.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -62,7 +62,7 @@ the site.
62
62
  | `data-project` | the project id, 22 characters. The project is then **confidential**: the key is asked for once per browser. Without either attribute the tool does nothing |
63
63
  | `data-setup` | opens the setup screen, which creates the project and shows the key once. Remove it afterwards |
64
64
  | `data-mode` | `encrypted` (default) or `plain` |
65
- | `data-path` | path prefix: which pages belong to the project. `/fr/` does not annotate `/en/` |
65
+ | `data-path` | path prefix: which pages belong to the project. `/fr/` does not annotate `/en/`. One tool runs per page: several projects on one site means each page loads only its own tag |
66
66
  | `data-domains` | origins of the project, separated by commas |
67
67
  | `data-version` | the version really being served, as the site names it |
68
68
  | `data-environment` | the name of the environment, written into the note as it stands |
package/dist/HASHES.txt CHANGED
@@ -1,3 +1,4 @@
1
+ 2.30.0 sha384-/pIpSIUKGK7sU+9ZGx0iUTxEY56cWBp5WzJf1XrE+bbNmq1/YQCL0rwiVbgV4z8W 315659 bytes
1
2
  2.29.0 sha384-2N0B7fBqiLD7kE1Jg6ObeS+5JTqFZZWud4icxW2z4qn8qPr3F8CI02LNj429GId9 276739 bytes
2
3
  2.28.0 sha384-aiEeBEhxLgIP0cyZB6FNFRVqATgROwtxEtAmOU3amaBhO06B5IE13Hms8U+dORXp 269981 bytes
3
4
  2.27.0 sha384-aftW4rcvAamPZXxmbvollL8hu9of9Nd17h5XeQY1tjbUf2FEg3a+eAGAw0PQcQ0q 269794 bytes
@@ -1,7 +1,7 @@
1
1
  /* ============================================================================
2
2
  annotepage -- the annotation layer, browser side.
3
3
 
4
- Package version : 2.29.0
4
+ Package version : 2.30.0
5
5
  Format version : 2 (see FORMAT.md)
6
6
  Licence : MIT
7
7
 
@@ -16,7 +16,7 @@
16
16
  /* Injected by the build: they come from package.json and from
17
17
  src/styles.css, so that no value is written in two places and can
18
18
  therefore diverge. */
19
- const TOOL_VERSION = "2.29.0";
19
+ const TOOL_VERSION = "2.30.0";
20
20
  const FORMAT = 2;
21
21
  const STYLES = "/* ============================================================================\n styles.css -- THE STYLES OF THE TOOL, AND OF NO OTHER ELEMENT.\n\n This sheet is INLINED into the served file by the build, then put into the\n tool's shadow root -- as a constructed sheet when the browser can do it, in\n a <style> otherwise. It was loaded by a <link> in the original tool; the\n move to a CDN under SRI brought it inside the file, so that there is only\n one digest to keep up to date. The containment itself has not changed, and\n is still twofold:\n\n - from the tool towards the site: no rule from here can reach an element\n of the host site, the browser sees to that. That is what makes the\n claim \"the layer touches nothing\" checkable rather than promised;\n - from the site towards the tool: no rule of the site can reach an\n element here. A redesign of the site's stylesheet therefore cannot\n distort the tool, nor the other way round.\n\n The \"ap-\" prefix on every class is the third safeguard: the day somebody\n loads these styles WITHOUT a shadow root -- by mistake, or to debug --\n nothing would answer a selector of the site.\n\n NO RULE TARGETS html, body, * OR ANY SELECTOR OF THE SITE. That is the one\n absolute prohibition of this file.\n\n COLOURS: the tool has its OWN palette, defined on the shadow root. It\n reads neither the site's variables nor its theme attribute: it has no\n reason to know how the site names its colours, and it must stay readable\n on a light site as on a dark one. The switch follows the system\n preference, the only information the tool has without asking anyone.\n ============================================================================ */\n\n\n:host {\n --ap-bg: #ffffff;\n --ap-bg-soft: #f4f6f8;\n --ap-bg-raised: #e9edf2;\n --ap-text: #1a1d21;\n --ap-text-soft: #5b6570;\n --ap-border: #d5dbe2;\n --ap-accent: #2f6fed;\n --ap-accent-dark: #1d55c8;\n --ap-accent-text: #ffffff;\n --ap-accent-veil: rgba(47, 111, 237, 0.14);\n --ap-alert-bg: #fdeceb;\n --ap-alert-border: #e3a9a4;\n --ap-alert-text: #8a1f16;\n /* THE TWO STATES A REMARK CAN BE IN ONCE IT IS ANSWERED, as tokens rather\n than as literals. They were literals, written once inside the card's\n state mark -- which meant the dark theme drew them at the LIGHT theme's\n ink: measured, 2.42:1 for \"resolved\" and 2.02:1 against the veil they\n sit on, where WCAG 1.4.3 asks 4.5. Below they are 4.68 and 5.23 in the\n light theme, 6.43 and 6.64 in the dark one, on the same composite.\n\n `pending` is the state that must never be mistaken for done: resolved,\n but not deployed -- the defect is still on the reader's screen. `fill`\n is the same colour asked to carry --ap-accent-text on top of it, for the\n badge on the page: 5.93:1 in light, 10.14:1 in dark. */\n --ap-done-ink: #0f7a52;\n --ap-done-veil: rgba(16, 185, 129, 0.14);\n --ap-pending-ink: #8a5a00;\n --ap-pending-veil: rgba(245, 158, 11, 0.16);\n --ap-pending-fill: #8a5a00;\n --ap-shadow: 0 6px 24px rgba(16, 24, 40, 0.18);\n --ap-radius: 10px;\n --ap-font: system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\",\n Arial, sans-serif;\n}\n\n@media (prefers-color-scheme: dark) {\n :host {\n --ap-bg: #1d2126;\n --ap-bg-soft: #262b32;\n --ap-bg-raised: #323942;\n --ap-text: #e9ecf0;\n --ap-text-soft: #a4adb8;\n --ap-border: #3a424c;\n --ap-accent: #6d9bff;\n --ap-accent-dark: #8fb4ff;\n --ap-accent-text: #10151c;\n --ap-accent-veil: rgba(109, 155, 255, 0.18);\n --ap-alert-bg: #3a1f1c;\n --ap-alert-border: #7c3a33;\n --ap-alert-text: #ffb9b1;\n --ap-done-ink: #56d3a0;\n --ap-done-veil: rgba(16, 185, 129, 0.18);\n --ap-pending-ink: #f0b757;\n --ap-pending-veil: rgba(245, 158, 11, 0.16);\n --ap-pending-fill: #f0b757;\n --ap-shadow: 0 6px 24px rgba(0, 0, 0, 0.55);\n }\n}\n\n/* ----------------------------------------------------------------------------\n The layer.\n\n It covers the viewport and receives NO click: that is what lets the page\n behave exactly as usual as long as the tool is not in annotation mode.\n Each widget re-enables clicks for itself alone.\n ---------------------------------------------------------------------------- */\n\n.ap-layer {\n position: absolute;\n inset: 0;\n pointer-events: none;\n font-family: var(--ap-font);\n font-size: 14px;\n line-height: 1.45;\n color: var(--ap-text);\n text-align: left;\n -webkit-font-smoothing: antialiased;\n}\n\n.ap-layer button,\n.ap-layer input,\n.ap-layer textarea {\n font-family: inherit;\n font-size: inherit;\n line-height: inherit;\n color: inherit;\n margin: 0;\n box-sizing: border-box;\n}\n\n/* ----------------------------------------------------------------------------\n The button: the only thing visible when the tool is at rest.\n ---------------------------------------------------------------------------- */\n\n.ap-button {\n position: fixed;\n right: 16px;\n bottom: 16px;\n display: inline-flex;\n align-items: center;\n gap: 8px;\n padding: 9px 14px;\n border: 1px solid var(--ap-border);\n border-radius: 999px;\n background: var(--ap-bg);\n color: var(--ap-text);\n box-shadow: var(--ap-shadow);\n cursor: pointer;\n pointer-events: auto;\n opacity: 0.92;\n transition: opacity 0.15s ease, transform 0.15s ease;\n}\n\n.ap-button:hover,\n.ap-button:focus-visible {\n opacity: 1;\n transform: translateY(-1px);\n}\n\n.ap-button:focus-visible {\n outline: 2px solid var(--ap-accent);\n outline-offset: 2px;\n}\n\n.ap-button[aria-pressed=\"true\"] {\n background: var(--ap-accent);\n border-color: var(--ap-accent);\n color: var(--ap-accent-text);\n opacity: 1;\n}\n\n.ap-button-dot {\n display: inline-block;\n width: 8px;\n height: 8px;\n border-radius: 50%;\n background: var(--ap-accent);\n flex: none;\n}\n\n.ap-button[aria-pressed=\"true\"] .ap-button-dot {\n background: var(--ap-accent-text);\n}\n\n.ap-button-count {\n padding: 1px 7px;\n border-radius: 999px;\n background: var(--ap-bg-raised);\n color: var(--ap-text-soft);\n font-size: 12px;\n}\n\n.ap-button[aria-pressed=\"true\"] .ap-button-count {\n background: rgba(255, 255, 255, 0.22);\n color: var(--ap-accent-text);\n}\n\n/* ----------------------------------------------------------------------------\n The pointing highlight.\n\n It is DRAWN HERE, from the coordinates of the element being pointed at.\n Nothing is put on the element itself: no class, no attribute, no style. So\n the site cannot move by a single pixel because of the pointing.\n ---------------------------------------------------------------------------- */\n\n.ap-highlight {\n position: fixed;\n border: 2px solid var(--ap-accent);\n border-radius: 3px;\n background: var(--ap-accent-veil);\n pointer-events: none;\n display: none;\n}\n\n.ap-highlight-label {\n position: fixed;\n max-width: 320px;\n padding: 4px 8px;\n border-radius: 6px;\n background: var(--ap-accent);\n color: var(--ap-accent-text);\n font-size: 12px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n pointer-events: none;\n display: none;\n box-shadow: var(--ap-shadow);\n}\n\n/* ----------------------------------------------------------------------------\n The markers: \"there are already notes here\".\n ---------------------------------------------------------------------------- */\n\n.ap-marker {\n position: fixed;\n min-width: 22px;\n height: 22px;\n padding: 0 6px;\n border: 2px solid var(--ap-bg);\n border-radius: 999px;\n background: var(--ap-accent);\n color: var(--ap-accent-text);\n font-size: 12px;\n font-weight: 700;\n line-height: 18px;\n text-align: center;\n cursor: pointer;\n pointer-events: auto;\n box-shadow: var(--ap-shadow);\n}\n\n/* THE STATE, IN THE BADGE ITSELF. The rule above is the OPEN state -- work to\n do -- and it stays the tool's accent, because that is what a badge on a page\n has always meant here. The other two are read against it:\n\n pending filled amber. Resolved, not deployed: the defect is still on the\n screen the reader is looking at, and it is the one state worth\n catching an eye that was not looking for it.\n done hollow, in the soft ink. History: there, countable, and not\n asking for anything.\n\n THE COLOUR IS NEVER ALONE. The count is written in the badge and the state\n is spelled out in its accessible name -- a badge that said \"still to fix\"\n by hue only would say nothing at all to a good part of its readers. */\n.ap-marker-pending {\n background: var(--ap-pending-fill);\n}\n.ap-marker-done {\n background: var(--ap-bg-soft);\n color: var(--ap-text-soft);\n font-weight: 600;\n /* The 2px border is the halo against the page and cannot be spent on the\n outline, so the outline is drawn inside. */\n box-shadow: var(--ap-shadow), inset 0 0 0 1px var(--ap-border);\n}\n\n.ap-marker:focus-visible {\n outline: 2px solid var(--ap-accent-dark);\n outline-offset: 2px;\n}\n\n/* ----------------------------------------------------------------------------\n The panel.\n ---------------------------------------------------------------------------- */\n\n.ap-panel {\n position: fixed;\n top: 12px;\n right: 12px;\n bottom: 72px;\n width: 360px;\n max-width: calc(100vw - 24px);\n display: none;\n flex-direction: column;\n border: 1px solid var(--ap-border);\n border-radius: var(--ap-radius);\n background: var(--ap-bg);\n box-shadow: var(--ap-shadow);\n pointer-events: auto;\n overflow: hidden;\n}\n\n.ap-panel.ap-open {\n display: flex;\n}\n\n/* The other side. Two positions, right and left, and no third one: in\n annotation mode the layer takes every click, so every pixel of panel is a\n pixel of page that can no longer be pointed at. A floating panel would\n only move that loss around.\n\n \"bottom\" IS NOT REDECLARED, on purpose: the panel keeps the same 72 px of\n clearance above the floating button either way, and that clearance is the\n same on both sides because the button moves WITH it.\n\n AND THE BUTTON MOVES WITH IT, which was decided the other way first. The\n argument for leaving it was that it is the tool's only visible trace at\n rest, so an anchor that moved would stop being one. The owner's answer,\n and it is the better one: \"move left\" is asked of the TOOL, not of half of\n it. A panel on one edge and the control that opens it on the other makes\n the eye cross the whole window for one gesture, and somebody who set the\n side set it for the tool.\n\n TWO THINGS THIS RULE DEPENDS ON, both fragile:\n - it is written with ONE class, so it weighs exactly what \".ap-panel\"\n weighs;\n - it is written BEFORE the narrow block below.\n Reverse either and it wins under 560 px, where the panel is a bottom band\n spanning the width -- and a panel pinned to the left there is the full-\n height panel whose defect at 375 px is described in that block. */\n.ap-left {\n right: auto;\n left: 12px;\n}\n/* The button follows, and it is put on the LAYER and not on the panel: the\n button is not inside the panel, so the side has to be readable from a\n common ancestor. Same offset mirrored, same bottom -- only the edge\n changes. */\n.ap-layer.ap-left-side .ap-button {\n right: auto;\n left: 16px;\n}\n\n.ap-panel-header {\n display: flex;\n align-items: baseline;\n gap: 8px;\n padding: 12px 14px;\n border-bottom: 1px solid var(--ap-border);\n background: var(--ap-bg-soft);\n}\n\n.ap-panel-title {\n font-size: 15px;\n font-weight: 600;\n flex: 1 1 auto;\n}\n\n/* -- what the whole project holds ---------------------------------------\n THE FIRST LINE OF THE FOOTER, on its own row. The footer is a flex row of\n short things -- a name, two buttons -- so this takes the whole width and the\n rest wraps under it. No ground and no border of its own: it is IN the footer,\n not beside it. */\n/* The retention line, when there is one. `:empty` rather than a class the\n script has to add and remove: the element is always there, and CSS decides\n whether it takes any room -- so a server that deletes nothing costs the\n panel exactly nothing. */\n.ap-panel-keeps { margin-top: 6px; color: var(--ap-text-soft); }\n.ap-panel-keeps:empty { display: none; }\n\n.ap-panel-footer { flex-wrap: wrap; }\n\n/* WHO YOU ARE SIGNING AS, ON A LINE OF ITS OWN. `flex-basis: 100%` is the same\n device the block above uses, and for the same reason: the footer is one\n wrapping row and everything in it was being strung end to end. */\n.ap-foot-who {\n flex-basis: 100%;\n display: flex; align-items: baseline; gap: 8px;\n}\n\n/* -- the list of remarks -------------------------------------------------\n A ROW, AND EVERY ROW IS A BUTTON. Not a card with a link in it: the whole\n line is the target, which is what a list of things to open should be, and it\n is reachable with a keyboard for free.\n\n THE EXCERPT TAKES THE ROOM AND FOLDS TO ONE LINE. What a remark is about can\n be a paragraph; what a list can show is a line. The author keeps a fixed\n place at the end so the eye can run down it. */\n.ap-row {\n display: flex; align-items: baseline; gap: 8px;\n width: 100%; margin: 0 0 4px; padding: 8px 10px;\n border: 1px solid var(--ap-border); border-radius: 8px;\n background: var(--ap-bg); color: var(--ap-text);\n font: inherit; text-align: left; cursor: pointer;\n transition: border-color .15s ease, background-color .15s ease;\n}\n.ap-row:hover { background: var(--ap-bg-soft); border-color: var(--ap-accent); }\n.ap-row:focus-visible { outline: 2px solid var(--ap-accent); outline-offset: 2px; }\n.ap-row-about {\n flex: 1; min-width: 0;\n overflow: hidden; text-overflow: ellipsis; white-space: nowrap;\n}\n.ap-row-who { flex: none; font-size: 12px; color: var(--ap-text-soft); }\n/* THE STATE, AS A DOT. Three of them, and the middle one is the one that must\n not read as done: resolved but not deployed is a defect still on screen. The\n accessible name spells all three out -- a colour is not a fact for\n everybody. */\n.ap-row-dot {\n flex: none; width: 8px; height: 8px; border-radius: 999px;\n background: var(--ap-accent); align-self: center;\n}\n.ap-row-pending .ap-row-dot { background: var(--ap-text-soft); }\n.ap-row-done .ap-row-dot { background: transparent; border: 1px solid var(--ap-border); }\n.ap-row-done .ap-row-about { color: var(--ap-text-soft); }\n@media (prefers-reduced-motion: reduce) { .ap-row { transition: none; } }\n\n/* -- a window that is not the panel --------------------------------------\n IT FLOATS OVER THE PAGE, and that is the point: the panel is a band down one\n edge, and what goes in here is not about the page beside it. Fixed rather\n than absolute -- the reader scrolls the page under it, and a window that\n scrolled away with the article would have to be chased.\n\n ABOVE THE PANEL AND BELOW NOTHING. It is opened from the panel's footer, so\n it must cover it; the tool's own layer already sits above the site.\n\n WIDTH: it is read, not filled in. 26rem is a paragraph, and min() keeps it\n inside a phone without a media query. */\n.ap-pop {\n position: fixed; z-index: 3;\n /* THE LAYER IS `pointer-events: none` so the site underneath keeps working,\n and every piece that must be reachable turns it back on. Without this\n line the window is a picture: no click on its buttons, and no drag on its\n bar -- which is exactly how it behaved when first measured. */\n pointer-events: auto;\n width: min(26rem, calc(100vw - 24px));\n max-height: calc(100vh - 24px);\n display: flex; flex-direction: column;\n border: 1px solid var(--ap-border); border-radius: 12px;\n background: var(--ap-bg); color: var(--ap-text);\n box-shadow: 0 18px 48px rgba(0, 0, 0, .22);\n overflow: hidden;\n}\n/* THE HANDLE. `touch-action: none` is what makes a finger drag the window\n instead of scrolling the page under it -- without it the browser claims the\n gesture before the first pointermove arrives. */\n.ap-pop-bar {\n display: flex; align-items: center; gap: 8px;\n padding: 8px 12px;\n border-bottom: 1px solid var(--ap-border);\n background: var(--ap-bg-soft);\n cursor: grab; touch-action: none; user-select: none;\n}\n.ap-pop-moving .ap-pop-bar { cursor: grabbing; }\n.ap-pop-title { flex: 1; font-size: 13px; font-weight: 650; }\n/* `min-height: 0` is what makes the scroll happen INSIDE the window rather\n than the window growing past its own height: a flex item does not shrink\n below its content without it, and the end of a long remark would be behind\n the bottom edge with nothing to scroll. */\n.ap-pop-body { flex: 1 1 auto; min-height: 0; padding: 12px; overflow: auto; }\n/* The one line that says why the page stayed where it was. Drawn as the panel\n draws its own help text, not as an alert: nothing has gone wrong. */\n.ap-why {\n margin: 0 0 10px; padding: 8px 10px;\n border-radius: 8px; background: var(--ap-bg-soft);\n color: var(--ap-text-soft); font-size: 12.5px;\n}\n/* THE CORNER, AND IT IS DRAWN RATHER THAN LEFT TO THE BROWSER. `resize: both`\n would have done this in one line and does nothing under a finger on iOS; the\n window is moved with pointer events for exactly that reason, and it is\n resized with them too. Two hairlines, the shape everybody already reads as a\n grip, in the same ink as the borders around it. */\n.ap-pop-grip {\n position: absolute; right: 0; bottom: 0;\n width: 18px; height: 18px;\n cursor: nwse-resize; touch-action: none;\n background:\n linear-gradient(135deg, transparent 42%, var(--ap-border) 42%,\n var(--ap-border) 54%, transparent 54%),\n linear-gradient(135deg, transparent 66%, var(--ap-border) 66%,\n var(--ap-border) 78%, transparent 78%);\n}\n.ap-pop-sizing { user-select: none; }\n.ap-pop-sizing .ap-pop-grip { cursor: nwse-resize; }\n/* Inside a window, the block is the window: no second frame around it. */\n.ap-pop-body .ap-config { margin: 0; padding: 0; border: 0; background: none; }\n.ap-pop-body .ap-forget { margin: 0; }\n.ap-pop-body .ap-panel-stats { margin: 0; }\n.ap-pop-body .ap-stats { margin: 0; }\n/* A WINDOW HAS ROOM, SO THE FILE GETS IT. In the panel this field was two or\n four lines because the column had nothing to spare; here it can show the\n whole thing without being scrolled. */\n.ap-pop-body .ap-code { min-height: 9.5em; }\n\n/* -- the file the assistant needs ---------------------------------------\n Drawn like the other block the panel opens in its body -- a title, a\n sentence, the thing itself, two buttons -- so nothing here is a new shape to\n learn. The last line is the warning, and it is a line and not a dialog: the\n reviewer asked for this file. */\n.ap-config {\n margin: 10px 0 0; padding: 12px;\n border: 1px solid var(--ap-border); border-radius: 10px;\n background: var(--ap-bg-soft);\n}\n/* The warning is a line at the tool's own soft ink, not in an alert colour:\n the reviewer asked for this file, they are not being warned off it. There is\n no --ap-warn token and this does not invent one. */\n.ap-config .ap-warn { margin-top: 10px; }\n.ap-panel-stats {\n flex-basis: 100%;\n display: flex; flex-wrap: wrap; gap: 4px 18px;\n margin-bottom: 4px;\n}\n.ap-stat { display: inline-flex; align-items: baseline; gap: 5px; }\n/* The row says what it counts, once, and the three figures follow it. Without\n it, \"3 / 2 / 1\" beside a panel about one page reads as being about that\n page. */\n.ap-stat-label {\n flex-basis: 100%; margin-bottom: 2px;\n font-size: 11px; font-weight: 650; letter-spacing: .02em;\n text-transform: uppercase; color: var(--ap-text-soft);\n}\n.ap-stat-n { font-size: 15px; font-weight: 650; color: var(--ap-text); }\n.ap-stat-w { font-size: 12px; color: var(--ap-text-soft); }\n/* TWO BLOCKS, THIS SITE THEN THE WHOLE SERVER, and the second is absent on\n nearly every server. Each block is a label, the figures it holds, and -- when\n age takes anything here -- a second row for what it took. */\n.ap-stats { display: flex; flex-direction: column; gap: 16px; }\n.ap-stats-block { display: flex; flex-direction: column; gap: 4px; }\n.ap-stats .ap-panel-stats { margin-bottom: 0; }\n/* WHAT WAS REMOVED READS AS A FOOTNOTE TO THE ROW ABOVE, not as a second set of\n figures competing with it: same shapes, one step quieter, and indented under\n the count it belongs to. */\n.ap-stat-gone { padding-left: 10px; border-left: 2px solid var(--ap-border); }\n.ap-stat-gone .ap-stat-n { font-size: 13px; font-weight: 600; color: var(--ap-text-soft); }\n.ap-stat-since {\n font-size: 11px; font-weight: 650; letter-spacing: .02em;\n text-transform: uppercase; color: var(--ap-text-soft); align-self: baseline;\n}\n/* The date of the last sweep is context for the figures beside it, not another\n figure: soft ink, smaller, and it wraps under them rather than stretching\n the row. */\n.ap-stat-when { font-size: 12px; color: var(--ap-text-soft); align-self: baseline; }\n.ap-panel-instructions {\n padding: 10px 14px;\n border-bottom: 1px solid var(--ap-border);\n color: var(--ap-text-soft);\n font-size: 13px;\n}\n\n.ap-panel-body {\n flex: 1 1 auto;\n overflow-y: auto;\n overscroll-behavior: contain;\n padding: 4px 14px 14px;\n}\n\n.ap-panel-footer {\n padding: 8px 14px;\n border-top: 1px solid var(--ap-border);\n background: var(--ap-bg-soft);\n color: var(--ap-text-soft);\n font-size: 12px;\n display: flex;\n align-items: center;\n gap: 8px;\n}\n\n.ap-section-title {\n margin: 14px 0 6px;\n color: var(--ap-text-soft);\n font-size: 12px;\n font-weight: 600;\n text-transform: uppercase;\n letter-spacing: 0.04em;\n}\n\n.ap-section-help {\n margin: 0 0 8px;\n color: var(--ap-text-soft);\n font-size: 12px;\n}\n\n.ap-empty {\n margin: 16px 0;\n color: var(--ap-text-soft);\n}\n\n/* ----------------------------------------------------------------------------\n THE MODE BADGE: one word, drawn in both modes, at the top of every draw.\n\n It replaced a paragraph that only the public mode ever drew. Two things\n were wrong with that: secure mode said nothing, so the panel never told a\n reviewer which of the two they were in; and a paragraph pinned to the top\n for ever is skipped after the second reading, while a single word is not.\n\n IT IS NOT A BUTTON AND MUST NOT LOOK LIKE ONE. No shadow, no pressed\n state, cursor stays default: there is nothing to press. What it does have\n is a focus ring, because it takes focus -- the description below has to be\n reachable without a pointer, and that is the only reason it is focusable.\n ---------------------------------------------------------------------------- */\n\n.ap-mode {\n /* The frame the description is positioned against. It spans the width of\n the panel body, so a description pinned to its two edges cannot spill\n sideways out of a body that scrolls -- and a scrolling body clips both\n axes, not just the one it scrolls. */\n position: relative;\n margin: 4px 0 10px;\n}\n\n.ap-mode-chip {\n display: inline-block;\n padding: 2px 9px 3px;\n border: 1px solid var(--ap-border);\n border-radius: 999px;\n background: var(--ap-bg-soft);\n color: var(--ap-text-soft);\n font-size: 11px;\n font-weight: 600;\n letter-spacing: 0.05em;\n text-transform: uppercase;\n cursor: default;\n}\n\n/* The public badge is the one that carries a consequence, so it is the one\n that is coloured -- in the tool's own accent, not in the alert colours: a\n public key is a choice somebody made on purpose, not an incident. Secure\n keeps the quiet frame: it is the case where nothing is being said. */\n/* The same ring as every other focusable thing in the panel. It is the only\n visual proof, for somebody arriving by Tab, that this word is where their\n focus went. */\n.ap-mode-chip:focus-visible {\n outline: 2px solid var(--ap-accent);\n outline-offset: 2px;\n}\n\n/* Plain wears the same coat as public, and for the same reason: both are a\n choice somebody made on purpose, and both carry a consequence for whoever\n is about to write. Neither is an incident, so neither takes an alert\n colour. They cannot both be true at once. */\n.ap-mode-public .ap-mode-chip,\n.ap-mode-plain .ap-mode-chip {\n border-color: var(--ap-accent);\n background: var(--ap-accent-veil);\n color: var(--ap-accent-dark);\n}\n\n/* The description. Hidden by DEFAULT and shown on demand, and hidden in a way\n that leaves it readable to a screen reader: it is the badge's\n aria-describedby target, and an accessible description is computed from the\n referenced element whether or not it is painted. It is taken out of the\n layout entirely (absolute) so that showing it moves not one pixel of the\n list underneath -- a tooltip that pushes the notes down is a tooltip that\n makes people lose their place. */\n.ap-mode-tip {\n position: absolute;\n z-index: 2;\n top: calc(100% + 6px);\n left: 0;\n right: 0;\n padding: 8px 10px;\n border: 1px solid var(--ap-border);\n border-radius: var(--ap-radius);\n background: var(--ap-bg-raised);\n color: var(--ap-text);\n box-shadow: var(--ap-shadow);\n font-size: 12px;\n font-weight: 400;\n letter-spacing: normal;\n text-transform: none;\n line-height: 1.45;\n opacity: 0;\n visibility: hidden;\n transform: translateY(-3px);\n transition: opacity 0.12s ease, transform 0.12s ease, visibility 0s linear 0.12s;\n pointer-events: none;\n}\n\n/* BOTH, and the keyboard one is not the afterthought: :focus-visible is what\n makes the sentence reachable by somebody who never touches a pointer. */\n.ap-mode-chip:hover ~ .ap-mode-tip,\n.ap-mode-chip:focus-visible ~ .ap-mode-tip {\n opacity: 1;\n visibility: visible;\n transform: none;\n transition: opacity 0.12s ease, transform 0.12s ease, visibility 0s;\n}\n\n@media (prefers-reduced-motion: reduce) {\n .ap-mode-tip {\n transform: none;\n transition: none;\n }\n .ap-mode-chip:hover ~ .ap-mode-tip,\n .ap-mode-chip:focus-visible ~ .ap-mode-tip {\n transition: none;\n }\n}\n\n/* The \"a newer client exists\" line and the \"this server speaks another\n format\" line are the same object on screen: a standing statement about what\n one is looking at, above the notes and above the failures. One rule, so\n they cannot drift apart -- and the second one joins it rather than\n inventing a colour, precisely because a protocol disagreement is a fact\n about the project, not an incident.\n\n Deliberately NOT the alert colours: neither is a failure, and an alarm that\n never goes away stops being read. */\n.ap-upgrade,\n.ap-format {\n margin: 0 0 10px;\n padding: 8px 10px;\n border: 1px solid var(--ap-border);\n border-radius: var(--ap-radius);\n background: var(--ap-bg-soft);\n color: var(--ap-text-soft);\n font-size: 12px;\n line-height: 1.45;\n}\n\n/* ----------------------------------------------------------------------------\n A note, and its replies.\n ---------------------------------------------------------------------------- */\n\n.ap-note {\n margin: 8px 0;\n padding: 10px 12px;\n border: 1px solid var(--ap-border);\n border-radius: var(--ap-radius);\n background: var(--ap-bg);\n}\n\n.ap-note.ap-orphan {\n background: var(--ap-bg-soft);\n}\n\n\n.ap-note-header {\n display: flex;\n align-items: baseline;\n gap: 8px;\n flex-wrap: wrap;\n}\n\n.ap-note-author {\n font-weight: 600;\n}\n\n.ap-note-date {\n color: var(--ap-text-soft);\n font-size: 12px;\n}\n\n.ap-note-target {\n margin: 4px 0 0;\n color: var(--ap-text-soft);\n font-size: 12px;\n font-style: italic;\n overflow-wrap: anywhere;\n}\n\n.ap-note-text {\n margin: 6px 0 0;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n}\n\n.ap-note-actions {\n margin-top: 8px;\n display: flex;\n gap: 8px;\n flex-wrap: wrap;\n}\n\n.ap-replies {\n margin: 8px 0 0;\n padding-left: 10px;\n border-left: 2px solid var(--ap-border);\n}\n\n.ap-reply {\n margin: 8px 0 0;\n}\n\n/* ----------------------------------------------------------------------------\n The form, anchored near the element pointed at.\n ---------------------------------------------------------------------------- */\n\n.ap-form {\n position: fixed;\n width: 340px;\n max-width: calc(100vw - 24px);\n display: none;\n flex-direction: column;\n gap: 8px;\n padding: 14px;\n border: 1px solid var(--ap-border);\n border-radius: var(--ap-radius);\n background: var(--ap-bg);\n box-shadow: var(--ap-shadow);\n pointer-events: auto;\n}\n\n.ap-form.ap-open {\n display: flex;\n}\n\n.ap-form-title {\n font-size: 15px;\n font-weight: 600;\n}\n\n.ap-form-target {\n color: var(--ap-text-soft);\n font-size: 12px;\n font-style: italic;\n overflow-wrap: anywhere;\n}\n\n.ap-label {\n display: block;\n margin-bottom: 3px;\n font-size: 12px;\n font-weight: 600;\n color: var(--ap-text-soft);\n}\n\n.ap-help {\n margin: 3px 0 0;\n font-size: 12px;\n color: var(--ap-text-soft);\n}\n\n.ap-field,\n.ap-area {\n width: 100%;\n padding: 8px 10px;\n border: 1px solid var(--ap-border);\n border-radius: 8px;\n background: var(--ap-bg-soft);\n color: var(--ap-text);\n}\n\n.ap-field:focus,\n.ap-area:focus {\n outline: 2px solid var(--ap-accent);\n outline-offset: 1px;\n}\n\n.ap-area {\n min-height: 92px;\n resize: vertical;\n}\n\n.ap-actions {\n display: flex;\n align-items: center;\n gap: 8px;\n flex-wrap: wrap;\n}\n\n.ap-counter {\n margin-left: auto;\n font-size: 12px;\n color: var(--ap-text-soft);\n}\n\n/* ----------------------------------------------------------------------------\n Buttons.\n ---------------------------------------------------------------------------- */\n\n.ap-primary,\n.ap-secondary,\n.ap-link {\n border-radius: 8px;\n cursor: pointer;\n pointer-events: auto;\n}\n\n.ap-primary {\n padding: 8px 14px;\n border: 1px solid var(--ap-accent);\n background: var(--ap-accent);\n color: var(--ap-accent-text);\n font-weight: 600;\n}\n\n.ap-primary:hover {\n background: var(--ap-accent-dark);\n border-color: var(--ap-accent-dark);\n}\n\n.ap-secondary {\n padding: 8px 14px;\n border: 1px solid var(--ap-border);\n background: var(--ap-bg);\n color: var(--ap-text);\n}\n\n.ap-secondary:hover {\n background: var(--ap-bg-raised);\n}\n\n.ap-link {\n padding: 2px 4px;\n border: 0;\n background: none;\n color: var(--ap-accent);\n text-decoration: underline;\n font-size: 13px;\n}\n\n.ap-primary:disabled,\n.ap-secondary:disabled,\n.ap-link:disabled {\n opacity: 0.6;\n cursor: default;\n}\n\n.ap-primary:focus-visible,\n.ap-secondary:focus-visible,\n.ap-link:focus-visible {\n outline: 2px solid var(--ap-accent);\n outline-offset: 2px;\n}\n\n/* ----------------------------------------------------------------------------\n The failures.\n\n They are RED, at the top of the block concerned, and carry the message the\n server returned as it stands: that is how a non-technical team learns that\n its remark is not saved, instead of believing it is.\n ---------------------------------------------------------------------------- */\n\n.ap-error {\n margin: 8px 0;\n padding: 10px 12px;\n border: 1px solid var(--ap-alert-border);\n border-radius: var(--ap-radius);\n background: var(--ap-alert-bg);\n color: var(--ap-alert-text);\n}\n\n.ap-error-title {\n font-weight: 700;\n margin-bottom: 4px;\n}\n\n.ap-error-detail {\n margin: 6px 0 0;\n white-space: pre-wrap;\n overflow-wrap: anywhere;\n font-size: 13px;\n}\n\n.ap-error .ap-link {\n color: var(--ap-alert-text);\n}\n\n/* ----------------------------------------------------------------------------\n Narrow: the panel takes the full width, and so does the form.\n ---------------------------------------------------------------------------- */\n\n/* ----------------------------------------------------------------------------\n Narrow.\n\n DEFECT OBSERVED at 375 px wide: a panel taking the full height covers the\n whole page, and no element can be pointed at any more -- every click lands\n on the panel. So it becomes a bottom band, which leaves the top half of\n the viewport free; one scrolls the page there to bring the wanted element\n into view. The form, for its part, hides the panel while typing (see\n notes.js): on a screen that size, writing and reading the list at the same\n time does not hold.\n ---------------------------------------------------------------------------- */\n\n/* On a narrow screen the panel becomes a bottom band and the form takes the\n full width.\n\n THE WIDTH CEILING IS KEPT, and it comes from a measured defect: \"left: 8;\n right: 8\" sizes the element against its CONTAINING BLOCK, which the host\n site's horizontal overflow can make wider than the visible window.\n Measured, in mobile emulation at 390 px: the site overflows to 407 px\n (with the tool and without it), and the panel came out 391 px wide\n starting at 8, that is 9 px off screen. \"100vw\" is the window, not the\n containing block: the ceiling therefore does nothing when the site does\n not overflow, and pulls the width back when it does. */\n@media (max-width: 560px) {\n .ap-panel {\n top: auto;\n right: 8px;\n left: 8px;\n bottom: 66px;\n height: 52vh;\n width: auto;\n max-width: calc(100vw - 16px);\n }\n\n /* A band spanning the width has no side, so the choice is inert here and\n the button says so by not being there. Offering a control that visibly\n does nothing is worse than offering none. The stored side is untouched:\n it is waiting for the wide screen it was chosen on. */\n .ap-side-toggle {\n display: none;\n }\n\n .ap-form {\n left: 8px;\n right: 8px;\n width: auto;\n max-width: calc(100vw - 16px);\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .ap-button {\n transition: none;\n }\n}\n\n/* The failure shows without opening the panel: the button's dot changes\n colour. A team that does not click must be able to see that something is\n wrong. */\n.ap-button.ap-failed .ap-button-dot {\n background: var(--ap-alert-text);\n}\n\n.ap-button.ap-failed {\n border-color: var(--ap-alert-border);\n}\n\n/* Signature reminder, in the note form.\n The name was shown at the foot of the panel only: invisible at the moment\n one writes. A user reported not knowing which name they were writing\n under. */\n.ap-form-signature {\n display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;\n margin: 0 0 .6rem; font-size: .85rem; opacity: .8;\n}\n\n/* Resolution state, said on the card.\n Two cases NOT to be confused: resolved and online, resolved but not\n deployed yet. The second keeps the defect on the reviewer's screen; hiding\n it or announcing it as fixed would cost them their trust in the tool. */\n.ap-state-mark {\n display: inline-block; margin: 0 0 .5rem;\n padding: .15rem .55rem; border-radius: 4px;\n font-size: .75rem; font-weight: 600; letter-spacing: .02em;\n}\n.ap-note.ap-resolved { opacity: .72; }\n.ap-note.ap-resolved .ap-state-mark {\n color: var(--ap-done-ink); background: var(--ap-done-veil);\n}\n.ap-note.ap-resolved-pending .ap-state-mark {\n color: var(--ap-pending-ink); background: var(--ap-pending-veil);\n}\n/* The \"it is fixed\" / \"reopen\" block, opened under the card. Same shape as\n the reply block: it is the same gesture, one answers a remark. */\n.ap-resolve,\n.ap-reply-form {\n margin-top: .6rem;\n padding-top: .6rem;\n border-top: 1px solid var(--ap-border);\n}\n\n/* The question asked before the key is dropped, at the foot of the list.\n Framed like the resolution block -- it is the same shape of gesture, one\n answers before something changes -- and set apart from the notes above it,\n because it is not about a note. */\n.ap-forget {\n margin-top: 1rem;\n padding-top: .6rem;\n border-top: 1px solid var(--ap-border);\n}\n\n.ap-forget .ap-actions {\n margin-top: .5rem;\n}\n\n.ap-history-toggle {\n display: block; width: 100%; margin: 1rem 0 .25rem;\n padding: .5rem .75rem; border: 1px dashed currentColor; border-radius: 6px;\n background: none; color: inherit; font: inherit; opacity: .7; cursor: pointer;\n}\n.ap-history-toggle:hover { opacity: 1; }\n\n\n/* ----------------------------------------------------------------------------\n Setup and pasting the salt.\n\n These are the only screens where something is copied by hand. Everything\n there is SELECTABLE and monospaced: a 43-character salt copied wrong\n cannot be recovered, and nothing helps less than a font that confuses I, l\n and 1.\n ---------------------------------------------------------------------------- */\n\n.ap-panel-wide {\n width: 560px;\n}\n\n.ap-copy {\n display: flex;\n align-items: flex-start;\n gap: 8px;\n margin: 0 0 12px;\n}\n\n.ap-code {\n flex: 1 1 auto;\n width: 100%;\n padding: 8px 10px;\n border: 1px solid var(--ap-border);\n border-radius: 8px;\n background: var(--ap-bg-soft);\n color: var(--ap-text);\n font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, \"Liberation Mono\",\n monospace;\n font-size: 12.5px;\n line-height: 1.5;\n resize: vertical;\n white-space: pre;\n overflow-x: auto;\n}\n\n.ap-code:focus-visible {\n outline: 2px solid var(--ap-accent);\n outline-offset: 1px;\n}\n\n@media (max-width: 560px) {\n .ap-panel-wide {\n width: auto;\n }\n\n .ap-copy {\n flex-direction: column;\n }\n}\n";
22
22
 
@@ -75,6 +75,67 @@
75
75
  rather than resolved (FORMAT.md section 1.5).
76
76
  neither we stay out, and we say so once in the console. */
77
77
 
78
+ /* ONE TOOL PER PAGE, HOWEVER MANY TIMES THIS FILE RUNS.
79
+
80
+ A tag inside <body> is executed again by every router that swaps the body
81
+ and re-activates its scripts -- Turbo, htmx's hx-boost, Livewire's
82
+ wire:navigate, Astro's ClientRouter -- and a template can carry the tag
83
+ twice. Each execution used to build a tool of its own: two pills, two sets
84
+ of listeners on one page, one remark sent twice.
85
+
86
+ So the copy that boots first takes a slot ON THE DOCUMENT (85-pages), and
87
+ keeps it for the life of the document. Any later copy finds it (below, once
88
+ the tag and the object have been read, and before a single setting is
89
+ judged) and does not start. Which of two things it says depends on what it
90
+ carries:
91
+
92
+ THE SAME CONFIGURATION -- same src, same settings on the tag, same
93
+ object. That is a router executing the tag again, at every click, and it
94
+ stands down in silence: a line per navigation would bury the console. It
95
+ asks the running copy to look at the page again instead, since a
96
+ re-executed tag is the plainest sign there is that the body just changed.
97
+
98
+ ANOTHER CONFIGURATION -- another project, key, prefix, server or file. It
99
+ stands down too, and says so ONCE for the document, however many
100
+ different configurations follow it. One tool
101
+ runs per page BY RULE: two projects on one site are two tags on two sets
102
+ of pages, never two tags on one. The rule was nearly the other one --
103
+ every configuration boots, each holds its own slot -- and it was set
104
+ aside because two tools on a page share one body, one click, one history
105
+ wrapper, and a reviewer who cannot tell which pill files where. What
106
+ cannot be allowed is the silence: a second tag that quietly never starts
107
+ is a project somebody believes is running.
108
+
109
+ AN IDENTITY THIS COPY CANNOT READ -- a running copy that predates
110
+ identities, or one that writes them another way -- is neither. Nothing
111
+ can be said about it that is true, so nothing is said: a false "another
112
+ configuration" is exactly what a CDN serving a newer release in the
113
+ middle of a visit would print, on a page carrying one tag.
114
+
115
+ NO TAKEOVER, EVEN WHEN THE OWNER IS OUT OF ITS data-path. Handing the
116
+ document to whichever copy's prefix matches would make "which tool is on
117
+ this page" depend on the order of navigations, and the owner coming back
118
+ into its prefix would have to take it back. The first copy owns the
119
+ document; the only release is the upgrade hand-over (80-upgrade).
120
+
121
+ WHY THE DOCUMENT AND A REGISTERED SYMBOL. The document is what "one per
122
+ page" means, and it outlives a body swap. Symbol.for gives two copies of
123
+ this file -- two versions, from two addresses -- the same key without it
124
+ being a name a site's script can overwrite by accident: window.Annotepage
125
+ was the obvious place, and a page is allowed to assign that object whole
126
+ (15-labels).
127
+
128
+ THE CONTRACT BETWEEN COPIES IS
129
+ { copy: { version, identity, recheck }, handedOver: [identity],
130
+ refused: [identity] }
131
+ and it is read by versions that do not exist yet. Adding to it is free;
132
+ renaming a member breaks the copy that ships next to an older one.
133
+ `refused` is non-empty once the warning has been said for the document --
134
+ that is the whole of "once" -- and it keeps at most REFUSED_KEPT entries:
135
+ a trace for whoever inspects the slot, not a list that grows at every
136
+ navigation. */
137
+ const INSTANCE_SLOT = Symbol.for('annotepage');
138
+
78
139
  /* THE SETTINGS, AND THE WHOLE LIST OF THEM. `data-` plus the name on a tag,
79
140
  the name alone in the object. Documented in the client's README, and
80
141
  client/tools/check.mjs refuses a list that has drifted from it.
@@ -129,12 +190,50 @@
129
190
  const SCRIPT_SRC = script ? script.src : '';
130
191
 
131
192
  const declaredConfig = window.annotepageConfig;
132
- const HAS_CONFIG = declaredConfig !== undefined && declaredConfig !== null;
133
- if (HAS_CONFIG && (typeof declaredConfig !== 'object' || Array.isArray(declaredConfig))) {
134
- refuse('tag.config_shape', null,
135
- 'window.annotepageConfig is not an object, so nothing could be read from '
136
- + 'it. It is written { server: "...", project: "..." }.');
137
- }
193
+
194
+ /* -- Is this document already somebody's? ---------------------------------
195
+ Read HERE: after the two sources are in hand, and before anything below can
196
+ write to the console about them. A refused configuration executed again by
197
+ a router must not repeat its warning at every click either.
198
+
199
+ WHAT A CONFIGURATION IS, for this comparison: the file, every setting the
200
+ tag carries, and the object. Read before adoption -- the adopted form is
201
+ only known after the judging this has to come before -- but NOT as
202
+ written: two spellings of one declaration are one configuration, or a
203
+ router executing the tag again is told it brought a second tool. So the
204
+ object's keys are ordered, a value is trimmed, a list of origins is
205
+ trimmed and ordered item by item, and `setup: false` is the absence it
206
+ means (see WHICH SOURCE WINS).
207
+
208
+ THE FILE IS ITS ADDRESS WITHOUT THE QUERY STRING. A query on a script's
209
+ address is how a CMS defeats caches -- WordPress writes ?ver=, often with
210
+ the time in it -- so it changes at every deploy, or at every request, and
211
+ never names another project. Ignoring it can only ever merge two tags
212
+ whose settings are already identical, and running one tool for those is
213
+ the rule anyway. The path stays: another file is another configuration.
214
+
215
+ NOT PART OF IT, EITHER:
216
+ an attribute that is not a setting -- annotepage.com toggles
217
+ data-annotepage-on on its live tag -- or a page flipping its own
218
+ switch would be told it carries two tools;
219
+ data-version, which is a label for the notes and not a project. A body
220
+ swapped after a deploy brings build-2 in the same tag. That tag stands
221
+ down like any re-executed one, and THE RUNNING COPY KEEPS THE VERSION
222
+ IT READ AT BOOT until the page is reloaded: notes written meanwhile
223
+ are filed under the build the document was loaded with.
224
+
225
+ AND IT NEVER THROWS. The object is the page's, and it may hold anything: a
226
+ BigInt that JSON.stringify refuses, an object with no prototype that
227
+ String() cannot convert, a getter that throws, a loop. Each of those gets
228
+ a text of its own, so that two such objects are still told apart. */
229
+ const data = (script && script.dataset) || {};
230
+
231
+ /* Identities this copy writes start with this. One that does not was written
232
+ by a copy that predates it or reads configurations another way. */
233
+ const IDENTITY_FORMAT = 'annotepage/identity/1';
234
+ const readableIdentity = (value) =>
235
+ typeof value === 'string' && value.indexOf('["' + IDENTITY_FORMAT + '",') === 0;
236
+ const REFUSED_KEPT = 8;
138
237
 
139
238
  const isTextList = (value) => {
140
239
  if (!Array.isArray(value)) return false;
@@ -144,10 +243,142 @@
144
243
  return true;
145
244
  };
146
245
 
246
+ /* Any value, as text. `seen` is the path from the top, so a loop is named
247
+ rather than followed; the depth is bounded for an object nobody writes by
248
+ hand. */
249
+ const textOfValue = (value, seen) => {
250
+ const kind = typeof value;
251
+ if (kind === 'string') return JSON.stringify(value);
252
+ if (kind === 'bigint') return String(value) + 'n';
253
+ if (kind === 'number' || kind === 'boolean' || kind === 'undefined' || value === null) {
254
+ return String(value);
255
+ }
256
+ if (kind !== 'object') return '<' + kind + '>';
257
+ if (seen.indexOf(value) !== -1) return '<loop>';
258
+ if (seen.length >= 8) return '<deep>';
259
+ seen.push(value);
260
+ let text;
261
+ try {
262
+ const parts = [];
263
+ if (Array.isArray(value)) {
264
+ for (let i = 0; i < value.length; i += 1) parts.push(memberText(value, i, seen));
265
+ text = '[' + parts.join(',') + ']';
266
+ } else {
267
+ const names = Object.keys(value).sort();
268
+ for (let i = 0; i < names.length; i += 1) {
269
+ parts.push(JSON.stringify(names[i]) + ':' + memberText(value, names[i], seen));
270
+ }
271
+ text = '{' + parts.join(',') + '}';
272
+ }
273
+ } catch (e) {
274
+ text = '<unreadable>';
275
+ }
276
+ seen.pop();
277
+ return text;
278
+ };
279
+ function memberText(object, name, seen) {
280
+ try {
281
+ return textOfValue(object[name], seen);
282
+ } catch (e) {
283
+ return '<throws>';
284
+ }
285
+ }
286
+
287
+ /* One setting, as the comparison sees it. null is "not declared". */
288
+ const settingText = (name, value) => {
289
+ if (name === 'setup') return value ? 'yes' : null;
290
+ if (name === 'domains' && (typeof value === 'string' || isTextList(value))) {
291
+ const items = typeof value === 'string' ? value.split(',') : value;
292
+ return JSON.stringify(items.map((d) => d.trim()).filter(Boolean).sort());
293
+ }
294
+ if (typeof value === 'string') return JSON.stringify(value.trim());
295
+ return textOfValue(value, []);
296
+ };
297
+
298
+ const objectText = (object) => {
299
+ if (object === undefined) return null;
300
+ if (object === null || typeof object !== 'object' || Array.isArray(object)) {
301
+ return textOfValue(object, []);
302
+ }
303
+ try {
304
+ const parts = [];
305
+ const names = Object.keys(object).sort();
306
+ for (let i = 0; i < names.length; i += 1) {
307
+ const name = names[i];
308
+ if (name === 'version') continue;
309
+ let text;
310
+ try {
311
+ text = SETTINGS.indexOf(name) === -1
312
+ ? textOfValue(object[name], [object]) : settingText(name, object[name]);
313
+ } catch (e) {
314
+ text = '<throws>';
315
+ }
316
+ if (text !== null) parts.push(JSON.stringify(name) + ':' + text);
317
+ }
318
+ return '{' + parts.join(',') + '}';
319
+ } catch (e) {
320
+ return '<unreadable>';
321
+ }
322
+ };
323
+
324
+ const COPY_IDENTITY = JSON.stringify([IDENTITY_FORMAT,
325
+ SCRIPT_SRC.replace(/[?#].*$/, ''),
326
+ SETTINGS.filter((name) => name !== 'version').map((name) => (declaredIn(data, name)
327
+ ? settingText(name, name === 'setup' ? true : String(data[name])) : null)),
328
+ objectText(declaredConfig)]);
329
+
330
+ const slotFound = document[INSTANCE_SLOT];
331
+ const handedOverHere = (slotFound && Array.isArray(slotFound.handedOver)) ? slotFound.handedOver : [];
332
+ if (slotFound && (slotFound.copy || handedOverHere.indexOf(COPY_IDENTITY) !== -1)) {
333
+ const holder = slotFound.copy;
334
+ /* A COPY THAT HANDED OVER is still this configuration: the newer version
335
+ carries its settings under another address (80-upgrade). The old tag
336
+ executed again by a router is the same declaration, and neither a
337
+ warning nor a second hand-over is owed for it. */
338
+ const same = handedOverHere.indexOf(COPY_IDENTITY) !== -1
339
+ || !!(holder && holder.identity === COPY_IDENTITY);
340
+ /* UNKNOWN IS NOT DIFFERENT: a holder with no identity this copy can read,
341
+ or a hand-over recorded in another format -- this tag may be the very
342
+ one that copy was loaded by. */
343
+ const unknown = !same && (!holder || !readableIdentity(holder.identity)
344
+ || handedOverHere.some((identity) => !readableIdentity(identity)));
345
+ if (!same && !unknown) {
346
+ if (!Array.isArray(slotFound.refused)) slotFound.refused = [];
347
+ const refused = slotFound.refused;
348
+ // ONCE FOR THE DOCUMENT, not once per configuration: a template
349
+ // cycling through several would otherwise print a line per kind.
350
+ if (!refused.length) {
351
+ complain('this page already runs annotepage with another configuration, '
352
+ + 'and one tool runs per page: this one ('
353
+ + (SCRIPT_SRC || 'window.annotepageConfig') + ') was not started, '
354
+ + 'and any further one on this page stands down without another line. '
355
+ + 'Several projects on one site means each page loads only its own '
356
+ + 'tag. See https://annotepage.com/questions.html#one-per-page');
357
+ }
358
+ if (refused.indexOf(COPY_IDENTITY) === -1 && refused.length < REFUSED_KEPT) {
359
+ refused.push(COPY_IDENTITY);
360
+ }
361
+ }
362
+ /* IN A try, because this runs inside whatever executed the tag -- a
363
+ router, in the middle of its navigation -- and a fault of the running
364
+ copy thrown from here would surface there, uncaught, at every click.
365
+ The next sign of navigation asks again. */
366
+ try {
367
+ if (holder) holder.recheck();
368
+ } catch (e) { /* the running copy's fault, not the page's */ }
369
+ return;
370
+ }
371
+
372
+ const HAS_CONFIG = declaredConfig !== undefined && declaredConfig !== null;
373
+ if (HAS_CONFIG && (typeof declaredConfig !== 'object' || Array.isArray(declaredConfig))) {
374
+ refuse('tag.config_shape', null,
375
+ 'window.annotepageConfig is not an object, so nothing could be read from '
376
+ + 'it. It is written { server: "...", project: "..." }.');
377
+ }
378
+
147
379
  /* What each source declares, as text, and whether it declares it AT ALL -- an
148
380
  empty data-key is not the same fact as no data-key (see THE KEY below). */
149
381
  const fromTag = {};
150
- const data = (script && script.dataset) || {};
151
382
  for (let i = 0; i < SETTINGS.length; i += 1) {
152
383
  const name = SETTINGS[i];
153
384
  if (declaredIn(data, name)) fromTag[name] = String(data[name]).trim();
@@ -1336,6 +1567,22 @@
1336
1567
  let keys = null; // { id, encryptionKey, indexKey }
1337
1568
  let PAGE_INDEX = ''; // blind index of the current page
1338
1569
 
1570
+ /* WHICH PAGE THAT INDEX BELONGS TO. Read once at boot, it was the only
1571
+ answer for the life of the document -- and a router that changes the path
1572
+ without a reload kept the first page's notes on every later one. It is now
1573
+ written wherever the index is computed, and compared against the address at
1574
+ every sign of navigation (85-pages). */
1575
+ let PAGE_PATH = '';
1576
+ /* True while this copy stands down because the current path is outside the
1577
+ declared prefix. A full load would simply have stayed silent; a copy that
1578
+ outlives its first page has to remember WHY it is silent, because only this
1579
+ reason goes away when the path changes. */
1580
+ let outOfScope = false;
1581
+ /* The number of the boot under way. Raised by every start() and by leaving
1582
+ the declared prefix, so that an answer landing for an earlier boot can tell
1583
+ it no longer belongs to the page (bootIsStale, 85-pages). */
1584
+ let bootRun = 0;
1585
+
1339
1586
  const inTool = (n) => !!(host && n && (n === host || host.contains(n)));
1340
1587
 
1341
1588
  /* -- The browser's memory ------------------------------------------------
@@ -2128,6 +2375,8 @@
2128
2375
  'pointer-events: none !important;' +
2129
2376
  'z-index: 2147483000 !important;';
2130
2377
  document.body.appendChild(host);
2378
+ // And kept there: a router that swaps the body takes it along (85-pages).
2379
+ watchHost();
2131
2380
  root = host.attachShadow({ mode: 'open' });
2132
2381
 
2133
2382
  /* The stylesheet is PUT HERE, in a <style>, and not loaded by a <link>
@@ -4010,10 +4259,11 @@
4010
4259
  // We stand down for this page load. Nothing is remembered: on the
4011
4260
  // next reload the screen comes back, because the problem itself has
4012
4261
  // not been dealt with.
4013
- if (host) host.remove();
4014
- host = null;
4015
- root = null;
4016
- ui = null;
4262
+ //
4263
+ // withdraw() and not the three lines it replaces: the host is now
4264
+ // also WATCHED (85-pages), and a list of what to take down written in
4265
+ // two places is the list that drifts.
4266
+ withdraw();
4017
4267
  });
4018
4268
  header.appendChild(close);
4019
4269
  const body = create('div', 'ap-panel-body');
@@ -4441,6 +4691,11 @@
4441
4691
  // usually nothing to remove -- which is the whole point of checking
4442
4692
  // before the work rather than after it.
4443
4693
  withdraw();
4694
+ /* AND THE DOCUMENT IS GIVEN BACK, or the newer copy would find it held
4695
+ and stand down (00-preamble), leaving the page with no tool at all. It
4696
+ is the one release there is, and it records this copy's configuration,
4697
+ so that the old tag executed again stays silent (85-pages). */
4698
+ releaseDocument(document, thisCopy);
4444
4699
 
4445
4700
  const fresh = document.createElement('script');
4446
4701
  const attributes = script.attributes;
@@ -4451,7 +4706,12 @@
4451
4706
  fresh.src = url;
4452
4707
  fresh.addEventListener('error', () => {
4453
4708
  handingOver = false;
4454
- onFailure();
4709
+ /* Taken back only if still free. While the new version was being
4710
+ fetched, a tag with another configuration may have booted and taken
4711
+ the document: two tools on one page is what the slot exists to
4712
+ prevent, so this one stays down. The old tag executed again cannot
4713
+ be that copy: it stands down on the record releaseDocument left. */
4714
+ if (claimDocument(document, thisCopy)) onFailure();
4455
4715
  });
4456
4716
  (document.head || document.documentElement).appendChild(fresh);
4457
4717
  return true;
@@ -4531,6 +4791,422 @@
4531
4791
  const labelsFileFor = (declared, src, language) =>
4532
4792
  declared || shippedLabelsUrl(src, language);
4533
4793
 
4794
+ /* ==== 85-pages.js ==== */
4795
+
4796
+ /* -- 19 ter. The page changes, the document does not --------------------
4797
+ Everything in this client was written for one page per document: the path
4798
+ was read at boot, the host element was appended to the body once, and
4799
+ nothing looked again. Two families of sites break that, in two different
4800
+ ways, and both are common enough to be the default of whole frameworks:
4801
+
4802
+ THE ADDRESS CHANGES, THE BODY STAYS -- Next.js, Nuxt, Vue Router,
4803
+ SvelteKit, Inertia. history.pushState, replaceState, the back button. The
4804
+ tool stayed, with the first page's notes, on every page after it.
4805
+
4806
+ THE BODY IS REPLACED -- Turbo, Astro's ClientRouter, htmx's hx-boost,
4807
+ Livewire's wire:navigate. The host element went away with the old body,
4808
+ and a tag sitting inside the body was executed again and built a second
4809
+ tool.
4810
+
4811
+ WHAT COUNTS AS ANOTHER PAGE IS THE PATH, AND ONLY THE PATH: it is what the
4812
+ page index is computed from (20-crypto), so it is the only change that can
4813
+ move a note. A body swapped under the same address is the same page -- the
4814
+ anchoring already degrades an element that is gone into an orphan, and
4815
+ takes it back when it returns (50-anchors). A query string or a fragment
4816
+ that changes is the same page too, for the same reason.
4817
+
4818
+ NOTHING HERE TOUCHES THE DERIVATION. pagePath() and indexOfPath() are
4819
+ called exactly as the boot calls them; what changed is how often. */
4820
+
4821
+ /* -- The slot on the document -------------------------------------------
4822
+ Declared in 00-preamble, which is the first reader of it: a second copy has
4823
+ to find it before doing anything at all. Written here, by the copy that
4824
+ stays. Everything below takes the document and the window as parameters so
4825
+ that client/tools/check.mjs can hand it plain objects. */
4826
+
4827
+ const slotOf = (doc) => {
4828
+ if (!doc[INSTANCE_SLOT]) doc[INSTANCE_SLOT] = { copy: null, listening: false };
4829
+ return doc[INSTANCE_SLOT];
4830
+ };
4831
+
4832
+ /** Takes the document for `copy`. False when another copy already holds it. */
4833
+ const claimDocument = (doc, copy) => {
4834
+ const slot = slotOf(doc);
4835
+ if (slot.copy && slot.copy !== copy) return false;
4836
+ slot.copy = copy;
4837
+ return true;
4838
+ };
4839
+
4840
+ /* Given back ONLY by a copy handing over to a newer version (80-upgrade). A
4841
+ copy that went silent keeps the slot, and that is deliberate: silent is
4842
+ still this document's answer, and a re-executed tag that booted again would
4843
+ ask the same server the same question at every navigation. So does a copy
4844
+ standing down outside its data-path: see NO TAKEOVER in 00-preamble.
4845
+
4846
+ AND WHAT IT WAS CONFIGURED WITH IS REMEMBERED. The newer version arrives
4847
+ under another address, so the old tag executed again by a router no longer
4848
+ matches the copy holding the document. Without this record it would read
4849
+ as another configuration: warned about as a second tool, or -- during the
4850
+ fetch, with nobody holding the slot -- booting and handing over a second
4851
+ time. */
4852
+ const releaseDocument = (doc, copy) => {
4853
+ const slot = slotOf(doc);
4854
+ if (slot.copy !== copy) return;
4855
+ slot.copy = null;
4856
+ if (!slot.handedOver) slot.handedOver = [];
4857
+ slot.handedOver.push(copy.identity);
4858
+ };
4859
+
4860
+ /**
4861
+ * Hears every change of address, ONCE PER DOCUMENT, and forwards it to
4862
+ * whichever copy holds the slot at that moment.
4863
+ *
4864
+ * ONCE, because a copy that hands over to a newer version cannot take a
4865
+ * wrapper back off history -- the site may have wrapped it again since -- and
4866
+ * the newer copy wrapping on top would announce every navigation twice. The
4867
+ * listeners installed here never belong to a copy: they read the slot when
4868
+ * they fire.
4869
+ *
4870
+ * THE NAVIGATION API WHERE THERE IS ONE. `currententrychange` fires for
4871
+ * pushState, replaceState and a traversal alike, and it costs the site
4872
+ * nothing. history is only wrapped where that API is missing, since wrapping
4873
+ * a method of somebody else's page is the more intrusive of the two. popstate
4874
+ * is heard in both cases: it is free, and the path comparison makes a second
4875
+ * announcement of the same change a no-op.
4876
+ *
4877
+ * @returns {boolean} whether this call installed anything
4878
+ */
4879
+ const listenForPages = (win, doc) => {
4880
+ const slot = slotOf(doc);
4881
+ if (slot.listening) return false;
4882
+ slot.listening = true;
4883
+
4884
+ const tell = () => {
4885
+ if (slot.copy) slot.copy.recheck();
4886
+ };
4887
+
4888
+ win.addEventListener('popstate', tell);
4889
+
4890
+ const nav = win.navigation;
4891
+ if (nav && typeof nav.addEventListener === 'function') {
4892
+ nav.addEventListener('currententrychange', tell);
4893
+ return true;
4894
+ }
4895
+
4896
+ /* A LIMIT, SAID HERE BECAUSE THIS IS WHERE IT COMES FROM. A router that
4897
+ kept its own reference to history.pushState before this tag loaded --
4898
+ `const push = history.pushState.bind(history)` at module load is a
4899
+ common way to write one -- calls that reference and never the wrapper
4900
+ below. Its navigations are not heard through history: only through
4901
+ popstate, a re-executed tag, a swapped body, or the Navigation API where
4902
+ the browser has it. Nothing a script loaded later can do reaches a
4903
+ reference taken earlier, and loading first is not this tag's to
4904
+ decide. */
4905
+ const history = win.history;
4906
+ ['pushState', 'replaceState'].forEach((name) => {
4907
+ const original = history && history[name];
4908
+ if (typeof original !== 'function') return;
4909
+ const wrapper = function () {
4910
+ // The site's call first, untouched, and its exception with it: a
4911
+ // refused URL is the site's to hear about, and a navigation that
4912
+ // did not happen is not one to follow.
4913
+ const result = original.apply(this, arguments);
4914
+ /* THE ONE try IN THIS SECTION, AND IT IS NOT A HABIT. This line
4915
+ runs INSIDE the site's own call to pushState, in its router, in
4916
+ the middle of its render. Anything thrown here would break the
4917
+ site's navigation -- which is the one failure this tool may
4918
+ never cause. A listener that throws only reaches the console;
4919
+ this does not have that luxury. */
4920
+ try {
4921
+ tell();
4922
+ } catch (e) {
4923
+ /* The page moved on without us: the next sign of navigation
4924
+ compares the path again. */
4925
+ }
4926
+ return result;
4927
+ };
4928
+ /* A HISTORY THE SITE FROZE. Object.freeze(History.prototype) -- a
4929
+ hardening script does it -- makes this assignment throw, since the
4930
+ bundle is strict, and it threw before the boot had started: the
4931
+ tool never appeared, on a page that had done nothing wrong. It is
4932
+ not worked around with defineProperty on the instance either: a
4933
+ site that froze its history has said it is not to be wrapped. This
4934
+ copy boots without hearing pushState, and hears the rest. */
4935
+ try {
4936
+ history[name] = wrapper;
4937
+ } catch (e) {
4938
+ /* Refused: the site's history stays exactly as the site froze it. */
4939
+ }
4940
+ });
4941
+ return true;
4942
+ };
4943
+
4944
+ /**
4945
+ * WHAT A CHANGE OF ADDRESS ASKS OF THIS COPY -- the whole decision, with no
4946
+ * DOM in it, so it is checked rather than described.
4947
+ *
4948
+ * none nothing to do: same path, or a copy that must not move
4949
+ * note out of scope and already standing down there: remember the path
4950
+ * leave the path left the declared prefix: take everything down
4951
+ * enter the path came back into it: boot, as a full load of it would
4952
+ * follow another page for a running tool: its index, its notes
4953
+ * wait another page, but the tool is not in its normal shape -- a boot
4954
+ * under way, a key being asked for, a silence. Nothing is recorded,
4955
+ * so the boot looks again when it lands (proceed, 90-boot).
4956
+ *
4957
+ * `frozen` is a configuration that was refused, or a copy that has handed
4958
+ * over: neither depends on the page, and neither may act on one.
4959
+ */
4960
+ const pageStep = (s) => {
4961
+ if (s.frozen) return 'none';
4962
+ if (s.path === s.known) return 'none';
4963
+ if (!s.inScope) return s.outOfScope ? 'note' : 'leave';
4964
+ if (s.outOfScope) return 'enter';
4965
+ return s.running ? 'follow' : 'wait';
4966
+ };
4967
+
4968
+ /**
4969
+ * WHETHER AN ANSWER STILL BELONGS TO THE BOOT THAT ASKED FOR IT.
4970
+ *
4971
+ * A boot is a derivation, a request and a label file, and the reader can
4972
+ * leave the declared prefix and come back into it before it lands. Coming
4973
+ * back starts a second boot (pageStep: enter) while the first is still on
4974
+ * the network, and the first one's list, applied, is page A's notes opened
4975
+ * with page B's index: every one of them "unreadable". So each boot carries
4976
+ * the number it was started under (`run`, against bootRun in 30-state) and
4977
+ * the index it asked with, and an answer that lands under another of either
4978
+ * is dropped whole. `index` undefined is a step taken before there is one.
4979
+ */
4980
+ const bootIsStale = (s) => s.run !== s.current
4981
+ || (s.index !== undefined && s.index !== s.pageIndex);
4982
+
4983
+ /* -- What the running copy does about it --------------------------------- */
4984
+
4985
+ /** Everything that belongs to ONE page and to no other. The key, the project
4986
+ totals and the side of the panel are not in it: they belong to the
4987
+ project and to the browser, and a navigation changes neither. */
4988
+ const forgetPage = () => {
4989
+ notes = [];
4990
+ anchored = [];
4991
+ orphans = [];
4992
+ historyOpen = false;
4993
+ currentFailure = null;
4994
+ skipped = { newer: 0, unreadable: 0, unknown: 0 };
4995
+ };
4996
+
4997
+ /**
4998
+ * Another page, and the tool is running: the notes of this one, from now.
4999
+ *
5000
+ * THE PANEL STAYS OPEN IF IT WAS. In annotation mode every click on the page
5001
+ * is captured, so a navigation that happens then is the back button or the
5002
+ * site's own doing -- and a reviewer who pressed Back while reading the list
5003
+ * wants the list of where they landed, not to have the tool closed on them.
5004
+ *
5005
+ * WHAT DOES NOT SURVIVE is whatever was aimed at the page that left: the
5006
+ * window of a remark, the form half written, the outline. The element they
5007
+ * point at is gone, and a remark sent from that form now would be filed under
5008
+ * the NEW page's index -- a note on the wrong page, which is worse than a
5009
+ * note not written.
5010
+ *
5011
+ * THE OLD NOTES GO BEFORE THE NEW ONES ARRIVE. The panel is redrawn empty at
5012
+ * once, and PAGE_INDEX is cleared until the new one is computed: a reload
5013
+ * started in that gap (entering the mode, a reply landing) asks for nothing
5014
+ * rather than for the page that left, and one already in flight is discarded
5015
+ * when it lands (reload, 90-boot).
5016
+ */
5017
+ const changePage = () => {
5018
+ const path = PAGE_PATH;
5019
+ const derived = keys;
5020
+ closePop();
5021
+ closeForm();
5022
+ hideHighlight();
5023
+ hovered = null;
5024
+ forgetPage();
5025
+ PAGE_INDEX = '';
5026
+ redraw();
5027
+ return indexOfPath(derived.indexKey, path).then((index) => {
5028
+ // Moved again meanwhile, or the key was forgotten or replaced: the
5029
+ // later change owns the page now.
5030
+ if (path !== PAGE_PATH || keys !== derived) return null;
5031
+ PAGE_INDEX = index;
5032
+ return reload();
5033
+ });
5034
+ };
5035
+
5036
+ /** Out of the declared prefix: exactly what a full load of that page shows,
5037
+ which is nothing. The key stays: coming back must not ask for it. */
5038
+ const stepAside = () => {
5039
+ // A boot still on the network belongs to the page that left (bootIsStale).
5040
+ bootRun += 1;
5041
+ withdraw();
5042
+ forgetPage();
5043
+ PAGE_INDEX = '';
5044
+ outOfScope = true;
5045
+ };
5046
+
5047
+ /** Compares the address with the page this copy is on, and acts. */
5048
+ const followPage = () => {
5049
+ const path = pagePath();
5050
+ const step = pageStep({
5051
+ frozen: !!CONFIG_FAILURE || handingOver,
5052
+ path: path,
5053
+ known: PAGE_PATH,
5054
+ inScope: inScope(),
5055
+ outOfScope: outOfScope,
5056
+ running: !!(keys && ui)
5057
+ });
5058
+ if (step === 'none' || step === 'wait') return step;
5059
+ PAGE_PATH = path;
5060
+ if (step === 'leave') stepAside();
5061
+ else if (step === 'enter') start();
5062
+ else if (step === 'follow') changePage();
5063
+ return step;
5064
+ };
5065
+
5066
+ /* -- The host element, kept in the document ------------------------------
5067
+ The host is a child of <body>, and a body that is replaced -- or emptied and
5068
+ refilled -- takes it along. It is PUT BACK rather than moved somewhere a
5069
+ swap cannot reach: its shadow root, its stylesheet and its listeners are
5070
+ all intact on the detached element, so reattaching it is the whole repair,
5071
+ and the one element the site receives stays where it always was.
5072
+
5073
+ WATCHED ON TWO NODES, NEITHER OF THEM IN DEPTH. <html>'s children, which is
5074
+ where a body is swapped whole; the body's own children, which is where one
5075
+ is emptied. childList without subtree: the callback runs for a change at
5076
+ those two levels and for nothing else the page does, however busy. */
5077
+
5078
+ let hostWatch = null;
5079
+ let watchedBody = null;
5080
+
5081
+ /* HOW OFTEN THE HOST IS PUT BACK, AND WHEN THAT STOPS.
5082
+
5083
+ A site can remove, on purpose, every child of <body> it does not know --
5084
+ a MutationObserver of its own, a "clean the DOM" script. Each removal is a
5085
+ mutation this copy answers by putting the host back, and each putting back
5086
+ is a mutation the site answers by removing it. Both callbacks are
5087
+ microtasks: the browser never gets to paint or to take a click again, and
5088
+ the page is frozen. Unbounded, this repair is the one failure the tool may
5089
+ never cause.
5090
+
5091
+ So what is COUNTED is the ping-pong itself: a host found removed less than
5092
+ CONTESTED_WITHIN milliseconds after it was put back. REATTACH_LIMIT of
5093
+ those IN A ROW is somebody removing the element on purpose, and the tool
5094
+ then stops, takes everything it holds down with it, and says so once: an
5095
+ element that vanishes with nothing said is the failure nobody finds.
5096
+
5097
+ NOT A NUMBER OF SWAPS PER WINDOW, which is what this was, and it switched
5098
+ the tool off on a site doing nothing wrong. Turbo visiting a page it has
5099
+ cached swaps the body twice -- the preview, then the response -- so five
5100
+ quick pagination clicks, or ten presses on Back, spent a budget of ten in
5101
+ two seconds. Those two swaps can land within a few milliseconds of each
5102
+ other, but the next navigation waits for a person: any removal later than
5103
+ CONTESTED_WITHIN starts the count again. A loop that removes the element
5104
+ more slowly than that is not refused, and does not need to be: the browser
5105
+ paints and takes clicks between two of its rounds. */
5106
+ const REATTACH_LIMIT = 10;
5107
+ const CONTESTED_WITHIN = 100;
5108
+ const reattached = { at: -Infinity, contested: 0 };
5109
+ let reattachRefusalSaid = false;
5110
+
5111
+ /** Records one putting back at `now` in `record`. False when REATTACH_LIMIT
5112
+ removals in a row each came within CONTESTED_WITHIN of the putting back
5113
+ before it. */
5114
+ const reattachAllowed = (record, now) => {
5115
+ record.contested = now - record.at < CONTESTED_WITHIN ? record.contested + 1 : 0;
5116
+ if (record.contested >= REATTACH_LIMIT) return false;
5117
+ record.at = now;
5118
+ return true;
5119
+ };
5120
+
5121
+ const watchFrame = () => {
5122
+ hostWatch.disconnect();
5123
+ watchedBody = document.body;
5124
+ hostWatch.observe(document.documentElement, { childList: true });
5125
+ if (watchedBody) hostWatch.observe(watchedBody, { childList: true });
5126
+ };
5127
+
5128
+ /* A mutation is a sign the page may have changed: the same question a
5129
+ re-executed tag or a history change asks, answered in the same place. */
5130
+ const watchHost = () => {
5131
+ if (hostWatch || typeof MutationObserver !== 'function') return;
5132
+ hostWatch = new MutationObserver(() => recheck());
5133
+ watchFrame();
5134
+ };
5135
+
5136
+ const unwatchHost = () => {
5137
+ if (hostWatch) hostWatch.disconnect();
5138
+ hostWatch = null;
5139
+ watchedBody = null;
5140
+ };
5141
+
5142
+ const keepHostAttached = () => {
5143
+ const body = document.body;
5144
+ if (!body) return;
5145
+ const swapped = !!hostWatch && watchedBody !== body;
5146
+ if (swapped) {
5147
+ watchFrame();
5148
+ /* ANNOTATION MODE WATCHES THE BODY IN DEPTH (enterMode), and the one
5149
+ it watches has just left the document: it would never raise
5150
+ domDirty again. It moves to the body that is there, and the
5151
+ anchoring is redone once, since every element it held is gone. */
5152
+ if (observer) {
5153
+ observer.disconnect();
5154
+ observer.observe(body, { childList: true, subtree: true });
5155
+ domDirty = true;
5156
+ }
5157
+ }
5158
+ if (!host) return;
5159
+ const detached = !host.isConnected;
5160
+ if (!detached && !swapped) return;
5161
+
5162
+ /* COPIES OF THE HOST THAT ARE NOT THE HOST. Turbo keeps a snapshot of
5163
+ every page it leaves as body.cloneNode(true), and htmx keeps its history
5164
+ as the body's markup: both put back, on Back, a body carrying an
5165
+ <annotepage-notes> with the inline style and without the shadow root --
5166
+ a full-screen element with nothing in it. Removed, because it is ours;
5167
+ and only when it has no shadow root, because one that has is a tool,
5168
+ and not this copy's to remove. */
5169
+ const found = document.querySelectorAll('annotepage-notes');
5170
+ for (let i = 0; i < found.length; i += 1) {
5171
+ if (found[i] !== host && !found[i].shadowRoot) found[i].remove();
5172
+ }
5173
+ if (!detached) return;
5174
+ if (!reattachAllowed(reattached, Date.now())) {
5175
+ /* THE BOOT UNDER WAY ENDS HERE TOO. The ping-pong runs in microtasks,
5176
+ so it can spend the budget while a label file is still on the
5177
+ network -- and that boot, landing, would build its interface into
5178
+ the shadow root withdraw() has just dropped: a TypeError in the
5179
+ site's error tracker. Raising the run makes every later turn of
5180
+ it a stale one (bootIsStale), which is how stepAside stops a boot
5181
+ as well. */
5182
+ bootRun += 1;
5183
+ withdraw();
5184
+ if (!reattachRefusalSaid) {
5185
+ reattachRefusalSaid = true;
5186
+ complain('something on this page removes the element this client draws in '
5187
+ + '(<annotepage-notes>) each time it is put back. It was put back '
5188
+ + REATTACH_LIMIT + ' times in a row, each removed again within '
5189
+ + CONTESTED_WITHIN + ' ms, and the tool has stopped rather than freeze '
5190
+ + 'the page. Whatever removes unknown children of <body> has to leave '
5191
+ + 'that element alone.');
5192
+ }
5193
+ return;
5194
+ }
5195
+ body.appendChild(host);
5196
+ };
5197
+
5198
+ /**
5199
+ * THE ONE ANSWER to every sign that the page may have changed: a history
5200
+ * entry, a traversal, a body swapped, a tag executed again. Each of them asks
5201
+ * both questions, since none of them says which one it is about: Turbo swaps
5202
+ * the body AND pushes a history entry, and a re-executed tag says nothing at
5203
+ * all about which.
5204
+ */
5205
+ function recheck() {
5206
+ keepHostAttached();
5207
+ followPage();
5208
+ }
5209
+
4534
5210
  /* ==== 90-boot.js ==== */
4535
5211
 
4536
5212
  /* -- 20. Reading the notes ----------------------------------------------- */
@@ -4542,8 +5218,18 @@
4542
5218
  drawMarkers();
4543
5219
  };
4544
5220
 
4545
- const reload = () =>
4546
- call('list').then((r) => {
5221
+ /* A LIST BELONGS TO THE PAGE IT WAS ASKED FOR. The tool now outlives its
5222
+ first page (85-pages), so an answer can land after the reader has moved on:
5223
+ a slow list, or a reply sent just before Back. Applied, it would put the
5224
+ notes of the page that left on the page that came -- the very defect being
5225
+ fixed -- so the index is remembered at the question and compared at the
5226
+ answer, twice, since decrypting takes a turn of its own. No index at all is
5227
+ the gap while the next one is computed: nothing is asked then. */
5228
+ const reload = () => {
5229
+ const index = PAGE_INDEX;
5230
+ if (!index) return Promise.resolve(null);
5231
+ return call('list').then((r) => {
5232
+ if (index !== PAGE_INDEX) return null;
4547
5233
  if (!r.ok) {
4548
5234
  // The tool is already in place: we no longer keep quiet. The
4549
5235
  // notes already on screen stay, with the warning that they may
@@ -4559,12 +5245,14 @@
4559
5245
  expired = readExpired(r.data);
4560
5246
  serverWide = readServerTotals(r.data);
4561
5247
  return readList(r.data).then((read) => {
5248
+ if (index !== PAGE_INDEX) return null;
4562
5249
  notes = read;
4563
5250
  currentFailure = null;
4564
5251
  redraw();
4565
5252
  return null;
4566
5253
  });
4567
5254
  });
5255
+ };
4568
5256
 
4569
5257
  /* -- 21. Startup ----------------------------------------------------------
4570
5258
  The order matters: we ask the API BEFORE touching the DOM. If it does not
@@ -4633,15 +5321,28 @@
4633
5321
  const withdraw = () => {
4634
5322
  if (ui && mode) leaveMode();
4635
5323
  if (host) host.remove();
5324
+ // The watch that puts the host back (85-pages) goes with it, or the next
5325
+ // body swap would find nothing to restore and keep observing for ever.
5326
+ unwatchHost();
4636
5327
  host = null;
4637
5328
  root = null;
4638
5329
  ui = null;
4639
5330
  };
4640
5331
 
4641
- /** A blocking screen: the host exists from now on, the labels come first. */
5332
+ /** The one reading of bootIsStale (85-pages) this file makes, against the
5333
+ boot and the page as they are now. */
5334
+ const staleBoot = (run, index) => bootIsStale({
5335
+ run: run, current: bootRun, index: index, pageIndex: PAGE_INDEX });
5336
+
5337
+ /** A blocking screen: the host exists from now on, the labels come first.
5338
+ A screen whose labels land after the reader left the prefix is not opened:
5339
+ stepAside has already taken its host down. */
4642
5340
  const showScreen = (open) => {
5341
+ const run = bootRun;
4643
5342
  buildHost();
4644
- loadLabels().then(open);
5343
+ loadLabels().then(() => {
5344
+ if (!staleBoot(run)) open();
5345
+ });
4645
5346
  };
4646
5347
 
4647
5348
  /**
@@ -4668,12 +5369,20 @@
4668
5369
  keyText = text;
4669
5370
  keys = derived;
4670
5371
 
4671
- return indexOfPath(keys.indexKey, pagePath())
4672
- .then((index) => {
4673
- PAGE_INDEX = index;
4674
- return call('list');
4675
- })
4676
- .then((first) => {
5372
+ /* The path is read HERE and not at the top of start(): a key pasted on
5373
+ the key screen can arrive several pages after the boot began. */
5374
+ PAGE_PATH = pagePath();
5375
+ const run = bootRun;
5376
+ return indexOfPath(keys.indexKey, PAGE_PATH).then((index) => {
5377
+ if (staleBoot(run)) return null;
5378
+ PAGE_INDEX = index;
5379
+ return call('list').then((first) => {
5380
+ /* The reader left the declared prefix while this boot was on the
5381
+ network -- and may already be back in it, under a boot of its
5382
+ own (bootIsStale, 85-pages). Either way this answer is about a
5383
+ page that left, and nothing is done with it: not shown, and not
5384
+ a silence that would withdraw the newer boot's tool. */
5385
+ if (staleBoot(run, index)) return null;
4677
5386
  if (!first.ok && !speaksAtStartup(first)) {
4678
5387
  // Complete silence: no node, no pixel, no message. If a key
4679
5388
  // screen was open, it goes away with the rest.
@@ -4706,11 +5415,12 @@
4706
5415
  it comes from, and replacing ourselves from a CDN would undo
4707
5416
  that choice behind their back. */
4708
5417
  const cdn = newer ? cdnServing(SCRIPT_SRC) : null;
4709
- if (cdn && handOverTo(cdn, newer, () => { proceed(first); })) return null;
5418
+ if (cdn && handOverTo(cdn, newer, () => { proceed(first, run, index); })) return null;
4710
5419
  if (newer) upgradeAvailable = newer;
4711
5420
 
4712
- return proceed(first);
5421
+ return proceed(first, run, index);
4713
5422
  });
5423
+ });
4714
5424
  }
4715
5425
 
4716
5426
  /**
@@ -4741,24 +5451,25 @@
4741
5451
  keyText = '';
4742
5452
  keys = null;
4743
5453
  PAGE_INDEX = '';
4744
- notes = [];
4745
- anchored = [];
4746
- orphans = [];
4747
- historyOpen = false;
4748
- currentFailure = null;
4749
- skipped = { newer: 0, unreadable: 0, unknown: 0 };
5454
+ // The page's own state, from the one list of it (85-pages): a navigation
5455
+ // drops the same things, and two copies of that list would drift.
5456
+ forgetPage();
4750
5457
 
4751
5458
  // And the tool is back where it was before the key was pasted: the
4752
5459
  // screen that asks for it. openSaltScreen clears the layer it replaces.
4753
5460
  openSaltScreen();
4754
5461
  };
4755
5462
 
4756
- /** Everything the tool does once it has decided to stay. */
4757
- function proceed(first) {
5463
+ /** Everything the tool does once it has decided to stay -- for the boot
5464
+ numbered `run`, which asked with `index`. Checked at every turn it takes:
5465
+ it is also called late, when a hand-over fails (80-upgrade). */
5466
+ function proceed(first, run, index) {
5467
+ if (staleBoot(run, index)) return Promise.resolve(null);
4758
5468
  // From here on the tool EXISTS, and will no longer keep quiet
4759
5469
  // about its failures.
4760
5470
  buildHost();
4761
5471
  return loadLabels().then(() => {
5472
+ if (staleBoot(run, index)) return null;
4762
5473
  clearLayer();
4763
5474
  buildUi();
4764
5475
  if (first.ok) {
@@ -4767,6 +5478,7 @@
4767
5478
  expired = readExpired(first.data);
4768
5479
  serverWide = readServerTotals(first.data);
4769
5480
  return readList(first.data).then((read) => {
5481
+ if (staleBoot(run, index)) return null;
4770
5482
  notes = read;
4771
5483
  redraw();
4772
5484
  return null;
@@ -4775,10 +5487,23 @@
4775
5487
  currentFailure = failureFrom(first, 'error.title_read');
4776
5488
  redraw();
4777
5489
  return null;
5490
+ }).then(() => {
5491
+ if (staleBoot(run, index)) return null;
5492
+ /* THE ADDRESS MAY HAVE MOVED DURING THE BOOT: a derivation, a request
5493
+ and a label file is long enough for a router to push a page. The
5494
+ signs that arrived meanwhile were told to wait (pageStep), so this
5495
+ is where they are answered -- and on a page that did not move it
5496
+ compares two equal strings. */
5497
+ followPage();
5498
+ return null;
4778
5499
  });
4779
5500
  }
4780
5501
 
4781
5502
  const start = () => {
5503
+ // A boot of its own: whatever an earlier one still has on the network is
5504
+ // dropped when it lands (bootIsStale, 85-pages).
5505
+ bootRun += 1;
5506
+ const run = bootRun;
4782
5507
  author = readAuthor();
4783
5508
  // Read ONCE, here, and never again: the side is asked of the storage at
4784
5509
  // startup like the name, not at every draw.
@@ -4801,7 +5526,12 @@
4801
5526
 
4802
5527
  // Outside the project's scope: silence. So the declaration can live in a
4803
5528
  // template shared by the whole site.
4804
- if (!inScope()) return;
5529
+ //
5530
+ // And the reason is REMEMBERED: it is the only silence that a later
5531
+ // navigation can lift (85-pages).
5532
+ PAGE_PATH = pagePath();
5533
+ outOfScope = !inScope();
5534
+ if (outOfScope) return;
4805
5535
 
4806
5536
  if (!CRYPTO) {
4807
5537
  // Without a secure context nothing is possible -- but if somebody
@@ -4828,6 +5558,7 @@
4828
5558
  }
4829
5559
 
4830
5560
  derive(keyBytes).then((derived) => {
5561
+ if (staleBoot(run)) return null;
4831
5562
  /* Both attributes on one tag: they have to AGREE, and the id is
4832
5563
  the one thing the key can check itself against (FORMAT.md
4833
5564
  1.2). Disagreement is refused exactly as a wrongly pasted key
@@ -4845,7 +5576,7 @@
4845
5576
  }, () => {
4846
5577
  // derive() only fails when WebCrypto itself does, which is what
4847
5578
  // that screen is about.
4848
- showScreen(openContextScreen);
5579
+ if (!staleBoot(run)) showScreen(openContextScreen);
4849
5580
  });
4850
5581
  return;
4851
5582
  }
@@ -4863,6 +5594,7 @@
4863
5594
  }
4864
5595
 
4865
5596
  derive(bytes).then((derived) => {
5597
+ if (staleBoot(run)) return null;
4866
5598
  if (derived.id !== PROJECT) {
4867
5599
  // The key stored under this key does not derive this id: the
4868
5600
  // tag has changed project, or the storage was tampered with. We
@@ -4872,10 +5604,24 @@
4872
5604
  }
4873
5605
  return startWithSalt(text, derived);
4874
5606
  }, () => {
4875
- showScreen(openSaltScreen);
5607
+ if (!staleBoot(run)) showScreen(openSaltScreen);
4876
5608
  });
4877
5609
  };
4878
5610
 
5611
+ /* THIS COPY, AS OTHER COPIES SEE IT. The shape is a contract with versions
5612
+ that do not exist yet: see 00-preamble. The claim cannot fail here -- a copy
5613
+ that found the document held has already returned from the preamble, and
5614
+ nothing between the two is asynchronous. `identity` is what a later copy
5615
+ compares its own configuration with, to know whether it is this one
5616
+ executed again or a second tool it must refuse. */
5617
+ const thisCopy = { version: TOOL_VERSION, identity: COPY_IDENTITY, recheck: recheck };
5618
+ claimDocument(document, thisCopy);
5619
+
5620
+ /* Listening starts before the boot and whatever the boot decides: a page
5621
+ outside the declared prefix is exactly the one that needs to hear the next
5622
+ navigation. */
5623
+ listenForPages(window, document);
5624
+
4879
5625
  if (document.body) {
4880
5626
  start();
4881
5627
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "annotepage-client",
3
- "version": "2.29.0",
3
+ "version": "2.30.0",
4
4
  "description": "The annotepage annotation layer: click an element of a page, leave a remark on it, it is encrypted in the browser.",
5
5
  "license": "MIT",
6
6
  "repository": {