annotepage-client 2.34.0 → 2.36.0-rc.1
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 +1 -0
- package/dist/HASHES.txt +6 -1
- package/dist/annotepage-frame.js +2371 -0
- package/dist/annotepage.js +1003 -491
- package/package.json +1 -1
|
@@ -0,0 +1,2371 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
annotepage -- the annotation layer, browser side.
|
|
3
|
+
|
|
4
|
+
Package version : 2.36.0-rc.1
|
|
5
|
+
Format version : 2 (see FORMAT.md)
|
|
6
|
+
Licence : MIT
|
|
7
|
+
|
|
8
|
+
GENERATED FILE -- do not edit it by hand. The sources are in src/, and
|
|
9
|
+
"npm run build" remakes this file. A fix made here would be lost at the
|
|
10
|
+
next build, and the published SRI digest would no longer match anything.
|
|
11
|
+
============================================================================ */
|
|
12
|
+
|
|
13
|
+
(function () {
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
/* Injected by the build: they come from package.json and from
|
|
17
|
+
src/styles.css, so that no value is written in two places and can
|
|
18
|
+
therefore diverge. */
|
|
19
|
+
const TOOL_VERSION = "2.36.0-rc.1";
|
|
20
|
+
const FORMAT = 2;
|
|
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 zones a remark can be written in (data-zone), while annotation mode is on.\n\n DISCREET ON PURPOSE: a dashed line and no fill. The page under review is\n what the reviewer is reading, and a veil over every open area would tint\n the very colours they may be writing about. Drawn from coordinates, like\n the highlight: nothing is put on the site's element.\n ---------------------------------------------------------------------------- */\n\n.ap-zone {\n position: fixed;\n border: 1px dashed var(--ap-accent);\n border-radius: 4px;\n opacity: 0.6;\n pointer-events: none;\n box-sizing: border-box;\n}\n\n.ap-zone-notice {\n position: fixed;\n max-width: 280px;\n padding: 6px 10px;\n border: 1px solid var(--ap-border);\n border-radius: 6px;\n background: var(--ap-bg);\n color: var(--ap-text);\n font-size: 13px;\n box-shadow: var(--ap-shadow);\n pointer-events: none;\n display: none;\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/* ----------------------------------------------------------------------------\n DOCKED (the `container` option): the panel FILLS the element the host page\n handed over, and there is no floating button -- the page opens and closes the\n tool. One class, added only when `container` is set (buildUi), so none of the\n floating layout above is touched without it.\n\n Two classes of specificity, so it wins over the edge-card rules and over the\n narrow-screen bottom band below: inside a container, the container's own box\n is what decides the size, not the viewport. The markers, the highlight and\n the pointing stay viewport-fixed and are untouched here -- only the panel\n moves from a floating card to a fill.\n ---------------------------------------------------------------------------- */\n.ap-docked .ap-button { display: none; }\n.ap-docked .ap-side-toggle { display: none; }\n.ap-docked .ap-panel {\n position: absolute;\n inset: 0;\n width: auto;\n max-width: none;\n border: 0;\n border-radius: 0;\n box-shadow: none;\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/* UP TO THREE BLOCKS: this site, the server, every server. Each is a label and\n the figures it holds, and the figures are the same size in all three. */\n.ap-stats { display: flex; flex-direction: column; gap: 14px; }\n.ap-stats-block { display: flex; flex-direction: column; gap: 4px; }\n.ap-stats .ap-panel-stats { margin-bottom: 0; }\n/* What follows a label on its line -- \"updated daily\" -- is about the label,\n not part of it: lower case, lighter, after a dot. */\n.ap-stat-aside { font-weight: 400; letter-spacing: 0; text-transform: none; }\n.ap-stat-aside::before { content: \"\\00b7\"; margin: 0 6px; }\n/* THE LAST BLOCK IS NOT THIS SERVER'S. A soft ground sets it apart from the\n two above it, which are; nothing about it is larger. */\n.ap-stats-world {\n margin: 0 -8px; padding: 8px;\n background: var(--ap-bg-soft); border-radius: 8px;\n}\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/* THE NEW-REMARK FORM, SHOWN IN THE PANEL. Only in frame mode: the clicked\n element is in another document, so the form cannot float over it (decision\n A, FRAME-DESIGN). It is then a child of the panel and fills it, over the\n list, with the panel's own surface -- the panel is a positioning context\n (fixed when floating, absolute when docked), so inset:0 means \"fill it\".\n This class is never added in the ordinary tool, so none of the floating\n rules above move. */\n.ap-form-in-panel {\n position: absolute;\n inset: 0;\n width: auto;\n max-width: none;\n border: 0;\n border-radius: 0;\n box-shadow: none;\n overflow: auto;\n z-index: 2;\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
|
+
|
|
23
|
+
/* ==== 05-hands-preamble.js ==== */
|
|
24
|
+
|
|
25
|
+
/* ============================================================================
|
|
26
|
+
05-hands-preamble.js -- THE HANDS' PREAMBLE (frame build only).
|
|
27
|
+
|
|
28
|
+
This file is in annotepage-frame.js and NOWHERE else: the full tool has
|
|
29
|
+
00-preamble, which reads a tag, adopts a project, derives keys and decides a
|
|
30
|
+
role. The hands have none of that to do. Loaded inside a sealed iframe
|
|
31
|
+
(sandbox allow-scripts, no allow-same-origin), they cannot reach a network,
|
|
32
|
+
a store or the host; they only touch the page they are in, on the head's word.
|
|
33
|
+
|
|
34
|
+
So this is 00-preamble reduced to the handful of names the page-touching half
|
|
35
|
+
and the shared shell mention. ROLE is fixed to 'hands'; there is no container
|
|
36
|
+
(that is a host-page idea); and the host-page robustness that keeps the host
|
|
37
|
+
attached across a framework's body swap (watchHost, 85-pages) is the head's,
|
|
38
|
+
not wired here. Everything else a note needs -- the server, the key, the
|
|
39
|
+
decryption, the panel -- is the head's, in the host page.
|
|
40
|
+
============================================================================ */
|
|
41
|
+
|
|
42
|
+
const ROLE = 'hands';
|
|
43
|
+
|
|
44
|
+
/* No container inside the iframe: the overlay fills this document's viewport,
|
|
45
|
+
as the floating tool always has. buildHost (57-shell) reads these at build
|
|
46
|
+
time of the host, so they are values, not lazy. */
|
|
47
|
+
const CONTAINER_EL = null;
|
|
48
|
+
const CONTAINER_SELECTOR = '';
|
|
49
|
+
|
|
50
|
+
/* Which setting named a zone: never asked here in a way that reaches this (the
|
|
51
|
+
hands' zoneSource and judgeZone take their 'hands' branch), but the names
|
|
52
|
+
must exist so the non-hands branches are not free variables. The zone the
|
|
53
|
+
hands actually use is the one the head sends with pick:on (handsZone). */
|
|
54
|
+
const script = null;
|
|
55
|
+
const ZONE_DECLARED = false;
|
|
56
|
+
const ZONE_SELECTOR = '';
|
|
57
|
+
|
|
58
|
+
/* THE SAME CAPS THE FULL TOOL USES (00-preamble), and they must be the same:
|
|
59
|
+
the hands compute a note's anchor -- cssPath, fingerprintOf, excerptOf
|
|
60
|
+
(50-anchors) -- and send it to the head to store. A different cap here would
|
|
61
|
+
file a remark the full tool anchors one way and the frame tool another. */
|
|
62
|
+
const MAX_SELECTOR = 500;
|
|
63
|
+
const MAX_FINGERPRINT = 255;
|
|
64
|
+
const MAX_EXCERPT = 160;
|
|
65
|
+
|
|
66
|
+
/* The hands speak to the console of the document they are in -- the iframe's.
|
|
67
|
+
It is prefixed so that a line read in the browser's console is clearly the
|
|
68
|
+
frame half talking, not the head. */
|
|
69
|
+
const complain = (line) => {
|
|
70
|
+
try {
|
|
71
|
+
if (window.console && typeof console.warn === 'function') {
|
|
72
|
+
console.warn('annotepage (frame): ' + line);
|
|
73
|
+
}
|
|
74
|
+
} catch (e) {
|
|
75
|
+
/* A console that throws is not a reason to fall over. */
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/* Keeping the host attached across a body swap is the head's robustness
|
|
80
|
+
(85-pages). A page shown for annotation in an iframe is content, not an app
|
|
81
|
+
swapping its own body; if that is ever wanted here, it is wired then. Stubbed
|
|
82
|
+
so buildHost can call it unconditionally. */
|
|
83
|
+
const watchHost = () => {};
|
|
84
|
+
const unwatchHost = () => {};
|
|
85
|
+
|
|
86
|
+
/* ==== 10-utils.js ==== */
|
|
87
|
+
|
|
88
|
+
/* -- 1. Labels ----------------------------------------------------------
|
|
89
|
+
No text meant for the screen is written anywhere but in 15-labels. See
|
|
90
|
+
the header of that file for the two ways of replacing them. */
|
|
91
|
+
|
|
92
|
+
const ns = (window.Annotepage = window.Annotepage || {});
|
|
93
|
+
|
|
94
|
+
/* The package version, put where a console can read it. It is the only fact
|
|
95
|
+
the tool publishes about itself: when a team says "it stopped working
|
|
96
|
+
this morning", the first question is which one is running. */
|
|
97
|
+
ns.version = TOOL_VERSION;
|
|
98
|
+
ns.format = FORMAT;
|
|
99
|
+
|
|
100
|
+
const T = (key, values) => {
|
|
101
|
+
const local = ns.labels || {};
|
|
102
|
+
const defaults = ns.defaultLabels || {};
|
|
103
|
+
// A missing label falls back on the default set; failing that, on the
|
|
104
|
+
// key -- which should never reach the screen, but beats a hole.
|
|
105
|
+
let text = local[key];
|
|
106
|
+
if (typeof text !== 'string') text = defaults[key];
|
|
107
|
+
if (typeof text !== 'string') text = key;
|
|
108
|
+
if (!values) return text;
|
|
109
|
+
return text.replace(/\{([a-z]+)\}/g, (raw, name) =>
|
|
110
|
+
Object.prototype.hasOwnProperty.call(values, name) ? String(values[name]) : raw
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** "0 notes", "1 note", "n notes" -- the plural is a label. */
|
|
115
|
+
const readableCount = (n, zero, one, many) =>
|
|
116
|
+
n === 0 ? T(zero) : n === 1 ? T(one) : T(many, { n: n });
|
|
117
|
+
|
|
118
|
+
/* -- 2. Small utilities -------------------------------------------------- */
|
|
119
|
+
|
|
120
|
+
const create = (tag, cls, text) => {
|
|
121
|
+
const e = document.createElement(tag);
|
|
122
|
+
if (cls) e.className = cls;
|
|
123
|
+
// textContent everywhere, innerHTML nowhere: the text of a note is typed
|
|
124
|
+
// by a human and must never be interpreted as markup, whatever it
|
|
125
|
+
// contains. This rule has no exception in this package, not even for the
|
|
126
|
+
// setup screen.
|
|
127
|
+
if (text !== undefined && text !== null) e.textContent = text;
|
|
128
|
+
return e;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const empty = (e) => {
|
|
132
|
+
while (e.firstChild) e.removeChild(e.firstChild);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const normalize = (t) => String(t == null ? '' : t).replace(/\s+/g, ' ').trim();
|
|
136
|
+
|
|
137
|
+
const clip = (t, max) => (t.length > max ? t.slice(0, max) : t);
|
|
138
|
+
|
|
139
|
+
/* -- 3. Bytes, text, base64url ------------------------------------------
|
|
140
|
+
base64url WITHOUT padding: it is the only form in the format (FORMAT.md
|
|
141
|
+
sections 1.1 and 3.3). It goes through a query string, a urlencoded body
|
|
142
|
+
and an SQL column without escaping, and it can be copied by hand without a
|
|
143
|
+
trailing "=" getting lost in an email. */
|
|
144
|
+
|
|
145
|
+
const utf8Encoder = new TextEncoder();
|
|
146
|
+
const utf8Decoder = new TextDecoder();
|
|
147
|
+
|
|
148
|
+
const utf8 = (t) => utf8Encoder.encode(String(t));
|
|
149
|
+
const fromUtf8 = (bytes) => utf8Decoder.decode(bytes);
|
|
150
|
+
|
|
151
|
+
const b64url = (source) => {
|
|
152
|
+
const u = new Uint8Array(source);
|
|
153
|
+
let raw = '';
|
|
154
|
+
// In chunks: String.fromCharCode.apply on an array of 24000 bytes blows
|
|
155
|
+
// the call stack in some browsers.
|
|
156
|
+
for (let i = 0; i < u.length; i += 4096) {
|
|
157
|
+
raw += String.fromCharCode.apply(null, u.subarray(i, i + 4096));
|
|
158
|
+
}
|
|
159
|
+
return btoa(raw).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Returns a Uint8Array, or null if the string is not base64url.
|
|
164
|
+
*
|
|
165
|
+
* Returning null rather than throwing: the caller is always in the middle of
|
|
166
|
+
* reading a line that came off the network, and an unreadable line gets
|
|
167
|
+
* counted, it does not stop the others from being read.
|
|
168
|
+
*/
|
|
169
|
+
const fromB64url = (text) => {
|
|
170
|
+
const t = String(text).replace(/-/g, '+').replace(/_/g, '/');
|
|
171
|
+
if (!/^[A-Za-z0-9+/]*$/.test(t)) return null;
|
|
172
|
+
let raw = '';
|
|
173
|
+
try {
|
|
174
|
+
raw = atob(t + '==='.slice((t.length + 3) % 4));
|
|
175
|
+
} catch (e) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const u = new Uint8Array(raw.length);
|
|
179
|
+
for (let i = 0; i < raw.length; i += 1) u[i] = raw.charCodeAt(i);
|
|
180
|
+
return u;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
/* -- 4. Versions ---------------------------------------------------------
|
|
184
|
+
Is the fix for a note ALREADY ONLINE?
|
|
185
|
+
We compare the three leading numbers of the version (1.0.69-rc.abc1234):
|
|
186
|
+
they grow with every build. A note resolved in a version more recent than
|
|
187
|
+
the one being served is fixed but not deployed yet, and that has to be
|
|
188
|
+
said -- otherwise we hide it while the defect is still there.
|
|
189
|
+
Unreadable or missing version: the fix is taken as NOT deployed, because
|
|
190
|
+
showing one note too many costs less than hiding one that still counts. */
|
|
191
|
+
|
|
192
|
+
const versionNumbers = (v) => {
|
|
193
|
+
const m = /^(\d+)\.(\d+)\.(\d+)/.exec(String(v || ''));
|
|
194
|
+
return m ? [+m[1], +m[2], +m[3]] : null;
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const alreadyDeployed = (fixVersion) => {
|
|
198
|
+
const a = versionNumbers(fixVersion);
|
|
199
|
+
const b = versionNumbers(SITE_VERSION);
|
|
200
|
+
if (!a || !b) return false;
|
|
201
|
+
for (let i = 0; i < 3; i += 1) {
|
|
202
|
+
if (b[i] !== a[i]) return b[i] > a[i];
|
|
203
|
+
}
|
|
204
|
+
return true;
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* THE LANGUAGE THE DOCUMENT DECLARES, or '' -- the lang attribute of <html>.
|
|
209
|
+
*
|
|
210
|
+
* Read in ONE place because two things now depend on it: the dates below, and
|
|
211
|
+
* which set of labels the panel speaks (80-upgrade, 90-boot). Read twice it
|
|
212
|
+
* would be two answers to the same question the day one of them started
|
|
213
|
+
* lowercasing, or stopped trimming.
|
|
214
|
+
*
|
|
215
|
+
* The BROWSER's language is deliberately not consulted anywhere: the page is
|
|
216
|
+
* the same document for everybody looking at it, and the browser is not.
|
|
217
|
+
*/
|
|
218
|
+
const pageLanguage = () =>
|
|
219
|
+
(document.documentElement.getAttribute('lang') || '').trim();
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* A count, with its thousands apart: 6204 is read digit by digit, 6,204 at a
|
|
223
|
+
* glance. Written the way the DOCUMENT's language writes it, like the dates
|
|
224
|
+
* below, and the plain digits where that language is not one the browser knows.
|
|
225
|
+
*/
|
|
226
|
+
const readableNumber = (n) => {
|
|
227
|
+
try {
|
|
228
|
+
return Number(n).toLocaleString(pageLanguage() || 'en');
|
|
229
|
+
} catch (e) {
|
|
230
|
+
return String(n);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* ISO date from the server -> THE READER'S LOCAL TIME.
|
|
236
|
+
*
|
|
237
|
+
* The server writes in UTC with an explicit offset; the conversion happens
|
|
238
|
+
* here, once, and nobody has to wonder which time zone they are looking at.
|
|
239
|
+
*
|
|
240
|
+
* The language is THE DOCUMENT'S: on a French page read from an English
|
|
241
|
+
* browser, "20 aout 2026" is more accurate than "Aug 20, 2026". Without one,
|
|
242
|
+
* the browser's own formatting is what is left.
|
|
243
|
+
*/
|
|
244
|
+
const readableDate = (iso) => {
|
|
245
|
+
const d = new Date(iso);
|
|
246
|
+
if (isNaN(d.getTime())) return T('date.unknown');
|
|
247
|
+
const language = pageLanguage();
|
|
248
|
+
try {
|
|
249
|
+
return d.toLocaleString(language || undefined,
|
|
250
|
+
{ dateStyle: 'medium', timeStyle: 'short' });
|
|
251
|
+
} catch (e) {
|
|
252
|
+
try {
|
|
253
|
+
return d.toLocaleString();
|
|
254
|
+
} catch (e2) {
|
|
255
|
+
return iso;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
/* ==== 15-labels.js ==== */
|
|
261
|
+
|
|
262
|
+
/* -- 5. EVERY TEXT THE TOOL PUTS ON SCREEN -------------------------------
|
|
263
|
+
|
|
264
|
+
English is the default language, and this is the only place it is
|
|
265
|
+
written: no other file in this package contains a sentence meant for the
|
|
266
|
+
screen. Translating the tool, or simply changing a word that does not suit
|
|
267
|
+
a team, therefore never means touching the code.
|
|
268
|
+
|
|
269
|
+
THREE WAYS TO REPLACE A LABEL, in order of priority:
|
|
270
|
+
|
|
271
|
+
1. an object defined BEFORE the client is loaded:
|
|
272
|
+
|
|
273
|
+
<script>
|
|
274
|
+
window.Annotepage = { labels: {
|
|
275
|
+
'button.open': 'Annoter la page'
|
|
276
|
+
} };
|
|
277
|
+
</script>
|
|
278
|
+
<script src="https://.../annotepage.js" ... defer></script>
|
|
279
|
+
|
|
280
|
+
2. a neighbouring file, DECLARED on the tag:
|
|
281
|
+
|
|
282
|
+
<script src="https://.../annotepage.js"
|
|
283
|
+
data-labels="/local-labels.js" defer></script>
|
|
284
|
+
|
|
285
|
+
That file writes, like this one, into window.Annotepage: it sets
|
|
286
|
+
"labels" (its own texts) and not "defaultLabels". It is resolved
|
|
287
|
+
against the DOCUMENT, not against the CDN: a translation belongs to
|
|
288
|
+
the site under review.
|
|
289
|
+
|
|
290
|
+
3. NOTHING AT ALL, on a page that says what language it is in:
|
|
291
|
+
|
|
292
|
+
<html lang="fr">
|
|
293
|
+
|
|
294
|
+
A set this package SHIPS -- French is the only one so far -- is then
|
|
295
|
+
loaded from beside this very file, and the panel is French without
|
|
296
|
+
anybody declaring anything. A language the package does not ship
|
|
297
|
+
stays English and fetches nothing. The two above still win: a site
|
|
298
|
+
that has said what its panel says is not overruled by its own lang
|
|
299
|
+
attribute (80-upgrade holds the rule, 90-boot applies it).
|
|
300
|
+
|
|
301
|
+
The PAGE's language, never the BROWSER's. Two people in front of one
|
|
302
|
+
screen are looking at one document, so it says one thing to both of
|
|
303
|
+
them; their browsers do not, and a panel that differed between the
|
|
304
|
+
reviewer and the colleague leaning over their shoulder would leave
|
|
305
|
+
neither able to tell the other what to click.
|
|
306
|
+
|
|
307
|
+
A full French set ships in labels/fr.json, as a worked example, and in
|
|
308
|
+
labels/fr.js, which is that file ready to be loaded.
|
|
309
|
+
|
|
310
|
+
Why a local file is DECLARED and not looked for: going to see "whether it
|
|
311
|
+
is there" means a request that usually answers 404 -- and the browser logs
|
|
312
|
+
that failure itself, in the console of EVERY page. The set in 3 is not a
|
|
313
|
+
guess for the same reason -- it is asked for only where this package's own
|
|
314
|
+
layout says it exists, beside this file on the CDN serving it.
|
|
315
|
+
|
|
316
|
+
A MISSING LABEL FALLS BACK ON ENGLISH. A partial translation is therefore
|
|
317
|
+
usable as it is.
|
|
318
|
+
|
|
319
|
+
SHAPE: a FLAT object. The keys are dotted so they read, not so they nest --
|
|
320
|
+
"button.open" is a string, not a path.
|
|
321
|
+
|
|
322
|
+
{ ... } in a value is a placeholder replaced at display time ({n}, {max},
|
|
323
|
+
{name}, {excerpt}, {code}). An unknown placeholder is left as it is. */
|
|
324
|
+
|
|
325
|
+
ns.defaultLabels = {
|
|
326
|
+
|
|
327
|
+
/* -- The button, the tool's only trace when it is at rest ---------- */
|
|
328
|
+
'button.open': 'Annotate this page',
|
|
329
|
+
'button.close': 'Done',
|
|
330
|
+
'button.help': 'Write and read the remarks on this page',
|
|
331
|
+
'button.notes_zero': '',
|
|
332
|
+
'button.notes_one': '1 note',
|
|
333
|
+
'button.notes_n': '{n} notes',
|
|
334
|
+
/* TWO NUMBERS, BECAUSE ONE OF THEM WAS THE WRONG ONE. The count said how
|
|
335
|
+
many notes the page carries, which on a page reviewed for a month is a
|
|
336
|
+
number nobody acts on -- and it kept growing as remarks were fixed. What
|
|
337
|
+
somebody opening the panel wants to know is how much is still in front
|
|
338
|
+
of them. The total stays beside it: it is the difference between "two
|
|
339
|
+
left" and "two, and nobody has looked yet". */
|
|
340
|
+
'button.notes_of': '{open} of {total}',
|
|
341
|
+
'button.help_counts': '{open} still to fix, {total} in all on this page',
|
|
342
|
+
|
|
343
|
+
/* -- The panel ----------------------------------------------------- */
|
|
344
|
+
'panel.title': 'Review notes',
|
|
345
|
+
'panel.close': 'Close',
|
|
346
|
+
/* The panel has two positions and the button says where it is GOING, not
|
|
347
|
+
where it is: a label that named the current side would read as a
|
|
348
|
+
statement and be pressed by nobody. */
|
|
349
|
+
'panel.move_left': 'Move left',
|
|
350
|
+
'panel.move_right': 'Move right',
|
|
351
|
+
'panel.instructions': 'Click an element of the page to write a remark about it.',
|
|
352
|
+
/* SAID ONLY WHERE IT IS TRUE. Everywhere else this tool deletes nothing,
|
|
353
|
+
and a line promising that on every server would be noise; here it is the
|
|
354
|
+
one fact somebody about to write a remark has a right to know, because
|
|
355
|
+
their remark has a date on it. */
|
|
356
|
+
'panel.keeps':
|
|
357
|
+
'This server keeps a thread for {n} days after its last message, then '
|
|
358
|
+
+ 'removes it. Nobody chooses which.',
|
|
359
|
+
'panel.escape': 'Press Escape to stop.',
|
|
360
|
+
/* -- The zone the site opened to remarks (data-zone) -----------------
|
|
361
|
+
Said where the reviewer acts: the instruction names the frames, and a
|
|
362
|
+
click outside them says why nothing opened. Two refusals, because they
|
|
363
|
+
are not the same news -- one sends the reader to a frame on screen, the
|
|
364
|
+
other has no frame to send them to, and saying "the outlined areas"
|
|
365
|
+
over a page with none would be a sentence nobody can obey. */
|
|
366
|
+
'panel.instructions_zone':
|
|
367
|
+
'Click an element inside the outlined areas to write a remark about it.',
|
|
368
|
+
'zone.outside': 'Remarks go in the outlined areas of this page.',
|
|
369
|
+
'zone.none': 'No part of this page is open to remarks.',
|
|
370
|
+
'panel.empty': 'Nobody has written a note on this page yet.',
|
|
371
|
+
'panel.section_page': 'On this page',
|
|
372
|
+
/* -- The list, and what opens from it --------------------------------
|
|
373
|
+
THE PANEL IS A LIST NOW, AND A REMARK IS A WINDOW. Full cards down a
|
|
374
|
+
350px band meant three of them filled it and the fourth was below the
|
|
375
|
+
fold; what a reviewer wants from that column is which remarks exist and
|
|
376
|
+
where they point, and then one of them at a time.
|
|
377
|
+
|
|
378
|
+
The row says what the remark is ABOUT, because that is how somebody
|
|
379
|
+
finds the one they mean -- not by its author and not by its date. */
|
|
380
|
+
'list.open': 'Open this remark',
|
|
381
|
+
'list.state_open': 'Still to fix',
|
|
382
|
+
'list.state_pending': 'Resolved, waiting to be deployed',
|
|
383
|
+
'list.state_done': 'Resolved and online',
|
|
384
|
+
'list.untitled': 'A remark',
|
|
385
|
+
/* -- What the whole project holds ------------------------------------
|
|
386
|
+
ONE ROW, ALWAYS, UNDER THE HEADER. A count is a glance, not a section:
|
|
387
|
+
it was a fold behind a fourth link in a 350px header, and both that link
|
|
388
|
+
and the title broke onto two lines.
|
|
389
|
+
|
|
390
|
+
"Across the site" and not "in this project": the reviewer knows the site
|
|
391
|
+
they are looking at; the word project belongs to whoever installed it. */
|
|
392
|
+
/* THE WINDOW HOLDS TWO SCOPES NOW -- this site, and the whole server --
|
|
393
|
+
so its name can no longer be one of them. "Across the site" headed a
|
|
394
|
+
block about the server underneath it, which is the kind of small lie
|
|
395
|
+
that makes a reader stop trusting the figures. */
|
|
396
|
+
'panel.stats_label': 'The figures',
|
|
397
|
+
|
|
398
|
+
/* -- The configuration the assistant needs ---------------------------
|
|
399
|
+
THE TOOL ALREADY HOLDS ALL OF IT: the address it talks to, and the key
|
|
400
|
+
it reads with. Writing that file by hand meant copying two values out of
|
|
401
|
+
a page and a tag into a text editor, and the site had to print both of
|
|
402
|
+
them in a figure to explain how. It hands the file over instead.
|
|
403
|
+
|
|
404
|
+
"for your assistant" and not "MCP configuration": the reviewer clicking
|
|
405
|
+
this is not the person who installed the MCP -- they are the one being
|
|
406
|
+
asked for the file. */
|
|
407
|
+
'config.show': 'File for your assistant',
|
|
408
|
+
'config.title': 'The file your assistant needs',
|
|
409
|
+
'config.where': 'On the machine where the assistant runs, save it as:',
|
|
410
|
+
'config.path': '~/.config/annotepage/annotepage.json',
|
|
411
|
+
'config.download': 'Download it',
|
|
412
|
+
'config.file': 'annotepage.json',
|
|
413
|
+
/* WHAT THE ASSISTANT SIGNS ITS REPLIES WITH, and the file is refused the
|
|
414
|
+
right to write without it -- `annotepage projects` says so in as many
|
|
415
|
+
words: "writing refused, for want of a name". Not the reviewer's name:
|
|
416
|
+
the replies in the thread come from the assistant, and a thread where
|
|
417
|
+
both voices carry one name is a thread nobody can read. */
|
|
418
|
+
'config.author': 'Assistant',
|
|
419
|
+
'config.warn': 'It carries your key. Anyone holding this file can read '
|
|
420
|
+
+ 'these notes and write them.',
|
|
421
|
+
'panel.stats_written': 'notes written',
|
|
422
|
+
'panel.stats_servers': 'servers',
|
|
423
|
+
'panel.stats_open': 'still open',
|
|
424
|
+
'panel.stats_pages': 'pages',
|
|
425
|
+
'panel.stats_sites': 'sites',
|
|
426
|
+
/* THE SINGULAR OF EACH, looked up when the figure is 1. A translation
|
|
427
|
+
that writes none of these falls back on the plural above, in English,
|
|
428
|
+
like every other missing label. */
|
|
429
|
+
'panel.stats_written_one': 'note written',
|
|
430
|
+
'panel.stats_servers_one': 'server',
|
|
431
|
+
'panel.stats_open_one': 'still open',
|
|
432
|
+
'panel.stats_pages_one': 'page',
|
|
433
|
+
'panel.stats_sites_one': 'site',
|
|
434
|
+
'panel.stats_here_label': 'On this site',
|
|
435
|
+
/* THE WHOLE SERVER, on the servers that publish it -- most do not, and
|
|
436
|
+
then this line is never drawn. "This server" and not "the API": the
|
|
437
|
+
reviewer is being told about the machine holding their notes. */
|
|
438
|
+
'panel.stats_server_label': 'On this whole server',
|
|
439
|
+
/* EVERY SERVER TOGETHER, where this one takes part in the statistics. The
|
|
440
|
+
second label follows the first on the same line, quieter: the figures
|
|
441
|
+
came with the server's last daily report and are as old as it is. */
|
|
442
|
+
'panel.stats_world_label': 'On all annotepage servers',
|
|
443
|
+
'panel.stats_daily': 'updated daily',
|
|
444
|
+
'panel.refresh': 'Refresh',
|
|
445
|
+
|
|
446
|
+
/* -- Notes whose element cannot be found any more ------------------- */
|
|
447
|
+
'orphans.title': 'Notes whose element has changed',
|
|
448
|
+
'orphans.help':
|
|
449
|
+
'These remarks were about an element that no longer exists in the same '
|
|
450
|
+
+ 'form. They are kept as they are.',
|
|
451
|
+
|
|
452
|
+
/* -- A note -------------------------------------------------------- */
|
|
453
|
+
'note.about': 'About: {excerpt}',
|
|
454
|
+
'note.no_element': 'About the whole page',
|
|
455
|
+
'note.element_lost': 'Element not found on the current page',
|
|
456
|
+
/* WHY THE PAGE DID NOT MOVE, said in the window that just opened. Two
|
|
457
|
+
cases, and they are not the same news: one the reader can undo in a
|
|
458
|
+
click, the other nobody can. */
|
|
459
|
+
'list.not_shown':
|
|
460
|
+
'The page did not move: what this remark is about is on it, but hidden '
|
|
461
|
+
+ 'by a setting further up.',
|
|
462
|
+
'list.not_here':
|
|
463
|
+
'The page did not move: what this remark is about is not on it any '
|
|
464
|
+
+ 'more. The remark is kept as it was written.',
|
|
465
|
+
'note.show': 'Show on the page',
|
|
466
|
+
'note.reply': 'Reply',
|
|
467
|
+
'note.reply_placeholder': 'Your reply',
|
|
468
|
+
'note.reply_send': 'Send the reply',
|
|
469
|
+
'note.cancel': 'Cancel',
|
|
470
|
+
'note.mark_resolved': 'Mark resolved',
|
|
471
|
+
'note.reopen': 'Reopen this remark',
|
|
472
|
+
|
|
473
|
+
/* -- Marking a remark resolved, and taking that mark back ----------- */
|
|
474
|
+
'resolution.help':
|
|
475
|
+
'The remark moves to the history once the fix is online. It is never '
|
|
476
|
+
+ 'deleted: it can be reopened.',
|
|
477
|
+
'resolution.confirm': 'It is fixed',
|
|
478
|
+
'reopening.help':
|
|
479
|
+
'The remark comes back into the list, with its replies. Do this if the '
|
|
480
|
+
+ 'fix turns out to be incomplete.',
|
|
481
|
+
'reopening.confirm': 'Reopen',
|
|
482
|
+
|
|
483
|
+
/* -- The form ------------------------------------------------------ */
|
|
484
|
+
'form.title': 'Your remark',
|
|
485
|
+
'form.about': 'About: {excerpt}',
|
|
486
|
+
'form.about_no_text': 'About the element you have just pointed at',
|
|
487
|
+
'form.name': 'Your name',
|
|
488
|
+
'form.name_help': 'It will appear next to your remarks, and be remembered for next time.',
|
|
489
|
+
'form.name_placeholder': 'First name, or first and last name',
|
|
490
|
+
'form.text_placeholder': 'What you noticed',
|
|
491
|
+
'form.send': 'Send',
|
|
492
|
+
'form.sending': 'Sending...',
|
|
493
|
+
'form.cancel': 'Cancel',
|
|
494
|
+
'form.name_missing': 'Give your name before sending.',
|
|
495
|
+
'form.text_missing': 'Write your remark before sending.',
|
|
496
|
+
'form.too_long': 'Your remark is {n} characters long; the limit is {max}.',
|
|
497
|
+
'form.remaining': '{n} characters left',
|
|
498
|
+
|
|
499
|
+
/* -- The reviewer's name ------------------------------------------- */
|
|
500
|
+
'author.known': 'You are writing as {name}.',
|
|
501
|
+
'author.change': 'Change',
|
|
502
|
+
'history.show': 'See the history ({n} resolved)',
|
|
503
|
+
'history.hide': 'Hide the history',
|
|
504
|
+
'history.help': 'Remarks that are resolved, and whose fix is online. '
|
|
505
|
+
+ 'They stay here: a correction believed done can turn out to be incomplete.',
|
|
506
|
+
'note.resolved': 'Resolved on {date} by {by}',
|
|
507
|
+
'note.resolved_pending': 'Resolved, waiting to be deployed',
|
|
508
|
+
'note.resolved_version': 'Fix shipped in version {version}',
|
|
509
|
+
'setup.localhost': 'You are on a local machine, so three of the values above '
|
|
510
|
+
+ 'need care. The origins line names an origin every developer shares -- '
|
|
511
|
+
+ 'never put it in a relay configuration others use. The tag points at '
|
|
512
|
+
+ 'this host, which will not exist once the site moves. And a note '
|
|
513
|
+
+ 'written here lands on any page with the same path, staging and '
|
|
514
|
+
+ 'production included: the index is the path alone.',
|
|
515
|
+
|
|
516
|
+
/* -- Failures. They are shown, they are never kept quiet ----------- */
|
|
517
|
+
'error.title': 'Your remark has NOT been saved',
|
|
518
|
+
'error.title_read': 'The notes could not be read back',
|
|
519
|
+
'error.title_resolution': 'The state of the remark has NOT been changed',
|
|
520
|
+
'error.network':
|
|
521
|
+
'The server did not answer. Your text is kept above: try again in a '
|
|
522
|
+
+ 'moment.',
|
|
523
|
+
'error.unexpected':
|
|
524
|
+
'The server answered something unexpected. Your text is kept above; '
|
|
525
|
+
+ 'tell whoever looks after the site.',
|
|
526
|
+
|
|
527
|
+
/* A FLAT refusal: a 4xx code with no readable message, almost always a
|
|
528
|
+
firewall's HTML page. It gets its own sentence because "something
|
|
529
|
+
unexpected" helped nobody: the refusal is plain, it has a code, and
|
|
530
|
+
there is a move that often gets around it -- rephrasing. */
|
|
531
|
+
'error.refused':
|
|
532
|
+
'The server REFUSED the request (code {code}) without saying why. '
|
|
533
|
+
+ 'That is almost always a firewall in front of the site, which took '
|
|
534
|
+
+ 'the text for an attack. Your text is kept above: rephrase it -- no '
|
|
535
|
+
+ '< > tags, no quotes, no fragment of code or web address -- then try '
|
|
536
|
+
+ 'again. If the refusal persists, tell whoever looks after the site: '
|
|
537
|
+
+ 'it is a firewall rule to adjust, not a broken tool.',
|
|
538
|
+
'error.refused_size':
|
|
539
|
+
'The server refused the request because it is too long (code {code}). '
|
|
540
|
+
+ 'Your text is kept above: shorten it, or split it into two remarks.',
|
|
541
|
+
'error.refused_rate':
|
|
542
|
+
'The server refused the request because it received too many in too '
|
|
543
|
+
+ 'little time (code {code}). Your text is kept above: wait a minute '
|
|
544
|
+
+ 'and try again.',
|
|
545
|
+
'error.server_failure':
|
|
546
|
+
'The server failed (code {code}). It is not your text: it is kept '
|
|
547
|
+
+ 'above. Try again in a moment, then tell whoever looks after the '
|
|
548
|
+
+ 'site.',
|
|
549
|
+
'error.encryption':
|
|
550
|
+
'Encryption failed in this browser: nothing was sent. Your text is '
|
|
551
|
+
+ 'kept above. Reload the page and try again; if it happens again, '
|
|
552
|
+
+ 'tell whoever looks after the site.',
|
|
553
|
+
'error.partial_read': 'What is shown may be incomplete.',
|
|
554
|
+
'error.hide': 'Hide',
|
|
555
|
+
|
|
556
|
+
/* -- The notes we cannot read, and do not hide --------------------- */
|
|
557
|
+
'read.newer_one':
|
|
558
|
+
'1 note was written by a more recent version of annotepage and could '
|
|
559
|
+
+ 'not be read.',
|
|
560
|
+
'read.newer_n':
|
|
561
|
+
'{n} notes were written by a more recent version of annotepage and '
|
|
562
|
+
+ 'could not be read.',
|
|
563
|
+
'read.unreadable_one':
|
|
564
|
+
'1 note could not be decrypted. The key in this browser may not be '
|
|
565
|
+
+ 'the one it was written with.',
|
|
566
|
+
'read.unreadable_n':
|
|
567
|
+
'{n} notes could not be decrypted. The key in this browser may not be '
|
|
568
|
+
+ 'the one they were written with.',
|
|
569
|
+
'read.unknown_one':
|
|
570
|
+
'1 note is written in a mode this tool does not know, and was not '
|
|
571
|
+
+ 'read.',
|
|
572
|
+
'read.unknown_n':
|
|
573
|
+
'{n} notes are written in a mode this tool does not know, and were not '
|
|
574
|
+
+ 'read.',
|
|
575
|
+
'read.title_partial': 'Some notes could not be read',
|
|
576
|
+
|
|
577
|
+
/* -- The markers put on the elements already annotated ------------- */
|
|
578
|
+
'marker.one': '1 note here',
|
|
579
|
+
'marker.n': '{n} notes here',
|
|
580
|
+
/* The badge is a button now: it opens the window on everything written
|
|
581
|
+
about that element. Said in the accessible name, because the colour and
|
|
582
|
+
the count say it to the eye alone. */
|
|
583
|
+
'marker.open': 'Open what is written here',
|
|
584
|
+
|
|
585
|
+
/* -- The key: the only secret, and it cannot be recovered ---------- */
|
|
586
|
+
'key.title': 'The key of this project is needed',
|
|
587
|
+
'key.help':
|
|
588
|
+
'The notes of this project are encrypted in your browser. Without the '
|
|
589
|
+
+ 'project key, this browser can neither read them nor write any. Ask '
|
|
590
|
+
+ 'whoever installed the tool for it, and paste it below. It will be '
|
|
591
|
+
+ 'remembered by this browser, for this site.',
|
|
592
|
+
'key.label': 'The project key (43 characters)',
|
|
593
|
+
'key.confirm': 'Use this key',
|
|
594
|
+
'key.empty': 'Paste the key before confirming.',
|
|
595
|
+
'key.shape':
|
|
596
|
+
'This is not a key: 43 characters are expected, from A-Z a-z 0-9 - _, '
|
|
597
|
+
+ 'with no space and no decorative dash. Copy it in one block.',
|
|
598
|
+
'key.wrong':
|
|
599
|
+
'This key is not the one for this project. Nothing was sent, nothing '
|
|
600
|
+
+ 'was decrypted. Check that you are pasting the key of the right '
|
|
601
|
+
+ 'project.',
|
|
602
|
+
'key.origin_changed':
|
|
603
|
+
'This key is remembered per browser AND per domain. The day staging '
|
|
604
|
+
+ 'becomes production, it has to be pasted once more on the new domain '
|
|
605
|
+
+ '-- the notes themselves do not move.',
|
|
606
|
+
'key.not_kept':
|
|
607
|
+
'This browser refuses to remember the key (private browsing, or '
|
|
608
|
+
+ 'storage blocked). The tool works for this page, but the key will '
|
|
609
|
+
+ 'have to be pasted again on the next load.',
|
|
610
|
+
'key.replace': 'Paste another key',
|
|
611
|
+
'key.forget': 'Forget the key on this browser',
|
|
612
|
+
/* Asked BEFORE, because the gesture cannot be taken back from here --
|
|
613
|
+
and it says what is really lost, which is the convenience and not the
|
|
614
|
+
notes. Announcing "your notes will be lost" would be a lie that stops
|
|
615
|
+
somebody from cleaning up a shared machine; saying nothing at all
|
|
616
|
+
would strand whoever no longer has the key anywhere else. */
|
|
617
|
+
'key.forget_confirm':
|
|
618
|
+
'This browser will stop keeping the key of this project: the tool '
|
|
619
|
+
+ 'will ask for it again here, and on every page of this site. The '
|
|
620
|
+
+ 'notes are not touched -- they stay on the server, encrypted, and '
|
|
621
|
+
+ 'they come back as soon as the key is pasted again. Make sure you '
|
|
622
|
+
+ 'can still get hold of the key before confirming: nobody, not even '
|
|
623
|
+
+ 'the server, can hand it back.',
|
|
624
|
+
|
|
625
|
+
/* -- WHICH OF THE TWO MODES THIS PROJECT RUNS IN ------------------
|
|
626
|
+
One word, drawn in BOTH modes, where the notes are and at every draw.
|
|
627
|
+
It replaces a paragraph that only the public mode ever showed: a
|
|
628
|
+
reviewer in secure mode had no way of telling which of the two they
|
|
629
|
+
were in, and a mention that appears in one case only is read as an
|
|
630
|
+
alarm rather than as a state.
|
|
631
|
+
|
|
632
|
+
The two words are the site's own: "Public" and "Secure", not a third
|
|
633
|
+
vocabulary invented here.
|
|
634
|
+
|
|
635
|
+
ENCRYPTION IS NOT ON THE BADGE. It holds in both modes, always, so
|
|
636
|
+
repeating it on screen at every draw says nothing that distinguishes
|
|
637
|
+
anything -- it belongs to the sentence one asks for, below.
|
|
638
|
+
|
|
639
|
+
Those sentences are the whole explanation, and they are reachable by
|
|
640
|
+
pointer AND by keyboard: the badge is not a button, it is focusable
|
|
641
|
+
so that the description can be asked for without a mouse. */
|
|
642
|
+
'mode.public': 'Public',
|
|
643
|
+
'mode.secure': 'Secure',
|
|
644
|
+
/* THE THIRD WORD, AND IT IS THE ONLY ONE THAT CONTRADICTS THE OTHER TWO.
|
|
645
|
+
Both of those say "end-to-end encrypted" in their sentence, which is
|
|
646
|
+
true of both -- and false where the site declared `plain`, where the
|
|
647
|
+
server stores what was typed. The badge used to read the key and say
|
|
648
|
+
encrypted anyway. */
|
|
649
|
+
'mode.plain': 'Readable',
|
|
650
|
+
/* The write half is the one nobody expects, so AND write them carries
|
|
651
|
+
the sentence. It ended on "the key gives both -- this format has no
|
|
652
|
+
reader-only role", which restated the clause before it and then
|
|
653
|
+
explained a design decision to somebody who cannot act on it. Cut. */
|
|
654
|
+
'mode.public_detail':
|
|
655
|
+
'End-to-end encrypted, and the key is in this page: anyone who can '
|
|
656
|
+
+ 'open the page can read these notes AND write them.',
|
|
657
|
+
/* The mirror answer, which had never been written down anywhere: what
|
|
658
|
+
the other mode actually costs the server. */
|
|
659
|
+
'mode.secure_detail':
|
|
660
|
+
'End-to-end encrypted, and the key is not in this page: each browser '
|
|
661
|
+
+ 'pastes it once, and the server never receives it.',
|
|
662
|
+
/* What it costs, said to the person about to write, and whose decision it
|
|
663
|
+
was. Not an alarm: plain mode is a legitimate choice on a server behind
|
|
664
|
+
the same door as the site under review -- it is just not the promise the
|
|
665
|
+
other two make. */
|
|
666
|
+
'mode.plain_detail':
|
|
667
|
+
'Not encrypted: this site chose plain mode, so the server stores these '
|
|
668
|
+
+ 'remarks as they are written and whoever administers it can read them.',
|
|
669
|
+
|
|
670
|
+
/* -- A newer client exists, and this copy is not going to fetch it -
|
|
671
|
+
Shown ONLY when the file is served by the site itself: a copy served
|
|
672
|
+
by a CDN replaces itself instead of talking about it (80-upgrade).
|
|
673
|
+
So the sentence has to say what was NOT done, and whose call it is. */
|
|
674
|
+
'upgrade.available':
|
|
675
|
+
'A more recent annotepage client exists: {version}. This page is '
|
|
676
|
+
+ 'running {current}, served by the site itself -- nothing was fetched '
|
|
677
|
+
+ 'to replace it, and when to update the file is the owner\'s call.',
|
|
678
|
+
|
|
679
|
+
/* -- The server and this client do not speak the same protocol -----
|
|
680
|
+
Two numbers in every sentence, never the word "incompatible" on its
|
|
681
|
+
own: "incompatible" sends somebody hunting through three components,
|
|
682
|
+
two numbers say in one line which end is behind and therefore what to
|
|
683
|
+
update. The two directions do not say the same thing because they do
|
|
684
|
+
not cost the same thing -- ahead of us, writing is refused; behind us,
|
|
685
|
+
everything still works. */
|
|
686
|
+
'format.server_newer':
|
|
687
|
+
'This server speaks annotepage format {server}; this client speaks '
|
|
688
|
+
+ 'format {ours}. Writing is refused from this page while that is '
|
|
689
|
+
+ 'true: a remark sealed at format {ours} would be stored in an '
|
|
690
|
+
+ 'envelope this server cannot read back, and nothing is ever deleted '
|
|
691
|
+
+ 'in this tool. The notes are still shown, and what cannot be read is '
|
|
692
|
+
+ 'counted below. To fix it, update the annotepage client file this '
|
|
693
|
+
+ 'page loads to a version that speaks format {server} -- that is the '
|
|
694
|
+
+ 'call of whoever looks after the site.',
|
|
695
|
+
'format.server_older':
|
|
696
|
+
'This server speaks annotepage format {server}; this client speaks '
|
|
697
|
+
+ 'format {ours}. Nothing is blocked: notes of format {server} are '
|
|
698
|
+
+ 'read here, and remarks can still be written. It is the SERVER that '
|
|
699
|
+
+ 'is behind -- tell whoever looks after it to update it to format '
|
|
700
|
+
+ '{ours}.',
|
|
701
|
+
'format.write_refused':
|
|
702
|
+
'Nothing was sent, and nothing was lost: your text is kept above. '
|
|
703
|
+
+ 'This server speaks annotepage format {server}, this client speaks '
|
|
704
|
+
+ 'format {ours}, so a remark written from here would be stored in an '
|
|
705
|
+
+ 'envelope the server cannot read back -- and nothing is ever deleted '
|
|
706
|
+
+ 'in this tool. The annotepage client file loaded by this page has to '
|
|
707
|
+
+ 'be updated to format {server} first. Until then, write the remark '
|
|
708
|
+
+ 'somewhere else: it will not arrive from this page.',
|
|
709
|
+
|
|
710
|
+
/* -- A tag that cannot be used as it stands ------------------------
|
|
711
|
+
Somebody put that tag there on purpose, so we speak instead of staying
|
|
712
|
+
silent -- and we refuse exactly as a wrong pasted key is refused
|
|
713
|
+
today: nothing sent, nothing decrypted. */
|
|
714
|
+
'tag.title': 'This annotepage tag cannot be used',
|
|
715
|
+
'tag.key_shape':
|
|
716
|
+
'The data-key attribute of the tag on this page is not a key: 43 '
|
|
717
|
+
+ 'characters are expected, from A-Z a-z 0-9 - _, with no space and no '
|
|
718
|
+
+ 'decorative dash. Nothing was sent and nothing was decrypted. '
|
|
719
|
+
+ 'Whoever installed the tool has to copy the key again, in one block.',
|
|
720
|
+
'tag.key_mismatch':
|
|
721
|
+
'The tag on this page carries a key and a project id that do not go '
|
|
722
|
+
+ 'together: the key does not derive that id. Nothing was sent and '
|
|
723
|
+
+ 'nothing was decrypted, and the tool does not guess which of the two '
|
|
724
|
+
+ 'is right. A public tag needs the key alone -- the id is derived '
|
|
725
|
+
+ 'from it -- so remove data-project, or correct whichever of the two '
|
|
726
|
+
+ 'is wrong.',
|
|
727
|
+
|
|
728
|
+
/* -- A configuration that cannot be used, wherever it was written --
|
|
729
|
+
The settings can also be declared in window.annotepageConfig, for the
|
|
730
|
+
pages where a tag cannot carry them -- concatenated scripts, a module,
|
|
731
|
+
an asset pipeline (00-preamble). These say what is wrong with one,
|
|
732
|
+
and they never name a tag: whoever reads them may not have one. */
|
|
733
|
+
'tag.title_config': 'This annotepage configuration cannot be used',
|
|
734
|
+
'tag.two_sources':
|
|
735
|
+
'This page declares annotepage twice -- on the tag and in '
|
|
736
|
+
+ 'window.annotepageConfig -- and the two disagree about "{name}". '
|
|
737
|
+
+ 'Nothing was sent and nothing was decrypted, and the tool does not '
|
|
738
|
+
+ 'pick a winner: whichever it took, somebody would have configured '
|
|
739
|
+
+ 'the tool and never known it was ignored. Correct one of the two, or '
|
|
740
|
+
+ 'remove it.',
|
|
741
|
+
'tag.config_no_server':
|
|
742
|
+
'The annotepage configuration on this page (window.annotepageConfig) '
|
|
743
|
+
+ 'names no server address, and there is no tag to deduce one from. '
|
|
744
|
+
+ 'Nothing was sent: an address guessed wrong would send the remarks '
|
|
745
|
+
+ 'nowhere at all. Add server: "https://.../api.php" to it.',
|
|
746
|
+
'tag.config_setting':
|
|
747
|
+
'The annotepage configuration on this page (window.annotepageConfig) '
|
|
748
|
+
+ 'carries "{name}", which is not a setting of this tool. Nothing was '
|
|
749
|
+
+ 'read from it -- a setting whose name is wrong is a setting nobody '
|
|
750
|
+
+ 'set. The names are the ones written on the tag, without data-.',
|
|
751
|
+
'tag.config_value':
|
|
752
|
+
'The setting "{name}" of the annotepage configuration on this page '
|
|
753
|
+
+ '(window.annotepageConfig) has to be written as text, between '
|
|
754
|
+
+ 'quotes. Nothing was read from it.',
|
|
755
|
+
'tag.config_shape':
|
|
756
|
+
'window.annotepageConfig on this page is not an object. It is written '
|
|
757
|
+
+ 'window.annotepageConfig = { server: "...", key: "..." }, before the '
|
|
758
|
+
+ 'client is loaded. Nothing was read from it.',
|
|
759
|
+
/* The page a document declares for itself (data-page). Said for both
|
|
760
|
+
sources, like the five above: the reader may hold either. */
|
|
761
|
+
'tag.page_shape':
|
|
762
|
+
'This document declares which page it is (data-page on the tag, or '
|
|
763
|
+
+ 'page in window.annotepageConfig), and what it declares is not a '
|
|
764
|
+
+ 'page path. It is written like the path of an address -- '
|
|
765
|
+
+ '/reviews/budget.html -- with a single leading slash, no space, no '
|
|
766
|
+
+ '".." and 300 characters at most. Nothing was sent and nothing was '
|
|
767
|
+
+ 'decrypted: a page named wrongly is a page whose remarks nobody '
|
|
768
|
+
+ 'else would find.',
|
|
769
|
+
'tag.page_outside_path':
|
|
770
|
+
'This document declares which page it is (data-page) and a path '
|
|
771
|
+
+ 'prefix (data-path), and the page is outside the prefix: the tool '
|
|
772
|
+
+ 'would never start here. Nothing was sent. Correct one of the two, '
|
|
773
|
+
+ 'or remove the prefix -- a document that names its own page does '
|
|
774
|
+
+ 'not need one.',
|
|
775
|
+
|
|
776
|
+
/* -- Setup --------------------------------------------------------- */
|
|
777
|
+
'setup.title': 'Install annotepage on this site',
|
|
778
|
+
'setup.generate': 'Generate a key and create the project',
|
|
779
|
+
'setup.warning_title': 'Read this before continuing',
|
|
780
|
+
'setup.warning':
|
|
781
|
+
'The key below is the ONLY secret of the project, and nobody else has '
|
|
782
|
+
+ 'it: not the server, not the author of the tool, nobody you can ask. '
|
|
783
|
+
+ 'KEY LOST = NOTES LOST, for good, with no recovery. Put it away now, '
|
|
784
|
+
+ 'where your team keeps its passwords, before continuing.',
|
|
785
|
+
'setup.key': 'The project key -- keep it',
|
|
786
|
+
'setup.project': 'The project id -- public, it goes into the page',
|
|
787
|
+
'setup.tag': 'The tag to paste at the end of <body>, on the pages to annotate',
|
|
788
|
+
'setup.config': 'The configuration to declare before the client is loaded, '
|
|
789
|
+
+ 'on the pages to annotate',
|
|
790
|
+
'setup.server': 'To declare in the server configuration',
|
|
791
|
+
'setup.copy': 'Copy',
|
|
792
|
+
'setup.copied': 'Copied',
|
|
793
|
+
'setup.copy_failed': 'Select the text and copy it by hand.',
|
|
794
|
+
'setup.continue': 'I have put the key away, continue',
|
|
795
|
+
'setup.done':
|
|
796
|
+
'The key is remembered by this browser. Paste the tag above into the '
|
|
797
|
+
+ 'pages, declare the project on the server, then reload this page: the '
|
|
798
|
+
+ 'tool takes over.',
|
|
799
|
+
'setup.no_server':
|
|
800
|
+
'No server address is declared on the tag (data-server), and the client '
|
|
801
|
+
+ 'does not come from the site: it cannot guess where to write. Add '
|
|
802
|
+
+ 'data-server to the tag.',
|
|
803
|
+
'setup.plain_mode':
|
|
804
|
+
'This project is declared in PLAIN mode: the server will read the '
|
|
805
|
+
+ 'remarks, the names and the paths. That mode is only acceptable if '
|
|
806
|
+
+ 'the server is the site itself, behind the same access restriction. A '
|
|
807
|
+
+ 'relay will refuse it.',
|
|
808
|
+
|
|
809
|
+
/* -- The secure context, without which nothing is possible --------- */
|
|
810
|
+
'context.title': 'annotepage cannot work on this page',
|
|
811
|
+
'context.help':
|
|
812
|
+
'Encrypting the notes and grouping them by page rest on WebCrypto, '
|
|
813
|
+
+ 'which the browser only provides in a secure context: https, or '
|
|
814
|
+
+ 'localhost. This page is not one. Nothing can be written or read '
|
|
815
|
+
+ 'back here while it is served this way.',
|
|
816
|
+
|
|
817
|
+
/* -- Odds and ends ------------------------------------------------- */
|
|
818
|
+
'date.unknown': 'unknown date'
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
/* ==== 30-state.js ==== */
|
|
822
|
+
|
|
823
|
+
/* -- 7. State, browser memory, scope ------------------------------------- */
|
|
824
|
+
|
|
825
|
+
let host = null; // the single element added to the site
|
|
826
|
+
let root = null; // its shadow root
|
|
827
|
+
let dockEl = null; // the element the panel is drawn INSIDE (container
|
|
828
|
+
// option), or null when the tool floats as it always
|
|
829
|
+
// has. Set at buildHost, read where the host is put
|
|
830
|
+
// back after a navigation (85-pages)
|
|
831
|
+
let ui = null; // the interface elements, once built
|
|
832
|
+
let mode = false; // is annotation mode on?
|
|
833
|
+
let notes = []; // the page's notes, as the server states them
|
|
834
|
+
let anchored = []; // { element, notes[] } : the notes found again
|
|
835
|
+
let orphans = []; // notes whose element was not found
|
|
836
|
+
let historyOpen = false; // resolved AND deployed notes are folded away
|
|
837
|
+
let totals = null; // { notes, open, pages } for the WHOLE project, or
|
|
838
|
+
// null: a server older than 2.5.0 does not send it,
|
|
839
|
+
// and the panel simply does not show the line
|
|
840
|
+
let retention = 0; // days a thread is kept after its last message, 0
|
|
841
|
+
// when nothing expires. A server older than 2.7.0
|
|
842
|
+
// sends nothing, which reads as 0 -- the promise
|
|
843
|
+
// it made before this key existed
|
|
844
|
+
let expired = null; // { notes, pages, last_sweep } : what retention has
|
|
845
|
+
// already taken from this project. null on a server
|
|
846
|
+
// that does not count, which is not the same thing
|
|
847
|
+
// as a project it has never taken anything from
|
|
848
|
+
let serverWide = null; // { projects, notes, pages } for the WHOLE server,
|
|
849
|
+
// and only where its operator published them.
|
|
850
|
+
// Absent everywhere else, on purpose
|
|
851
|
+
let world = null; // { servers|null, sites|null, notes } for EVERY annotepage
|
|
852
|
+
// server together, as this one was last told.
|
|
853
|
+
// null where the server takes no part in the
|
|
854
|
+
// statistics, or has not reported yet
|
|
855
|
+
let target = null; // element being annotated
|
|
856
|
+
let hovered = null; // element under the pointer
|
|
857
|
+
let currentFailure = null; // { title, detail } shown in the panel
|
|
858
|
+
let author = ''; // read at startup: see 90-boot
|
|
859
|
+
let side = 'right'; // which edge the panel sits on: see readSide
|
|
860
|
+
let timer = null;
|
|
861
|
+
let rafPending = false;
|
|
862
|
+
|
|
863
|
+
/* The page is somebody else's, and it moves. `observer` watches it WHILE
|
|
864
|
+
annotation mode is on -- never outside it -- and its only job is to raise
|
|
865
|
+
`domDirty`. The work itself belongs to the animation frame in
|
|
866
|
+
refreshPositions: a page that mutates in a loop would otherwise pay for a
|
|
867
|
+
full re-anchoring on every single mutation. */
|
|
868
|
+
let observer = null;
|
|
869
|
+
let domDirty = false;
|
|
870
|
+
|
|
871
|
+
/* What we did NOT manage to read at the last load. We count it so we can say
|
|
872
|
+
it: a note skipped in silence is a remark that disappears. */
|
|
873
|
+
let skipped = { newer: 0, unreadable: 0, unknown: 0 };
|
|
874
|
+
|
|
875
|
+
/* The key of this project, and everything derived from it. "keys" stays
|
|
876
|
+
null as long as the key is unknown: no request, no decryption goes out
|
|
877
|
+
before then. */
|
|
878
|
+
let keyText = '';
|
|
879
|
+
let keys = null; // { id, encryptionKey, indexKey }
|
|
880
|
+
let PAGE_INDEX = ''; // blind index of the current page
|
|
881
|
+
|
|
882
|
+
/* WHICH PAGE THAT INDEX BELONGS TO. Read once at boot, it was the only
|
|
883
|
+
answer for the life of the document -- and a router that changes the path
|
|
884
|
+
without a reload kept the first page's notes on every later one. It is now
|
|
885
|
+
written wherever the index is computed, and compared against the address at
|
|
886
|
+
every sign of navigation (85-pages). */
|
|
887
|
+
let PAGE_PATH = '';
|
|
888
|
+
/* True while this copy stands down because the current path is outside the
|
|
889
|
+
declared prefix. A full load would simply have stayed silent; a copy that
|
|
890
|
+
outlives its first page has to remember WHY it is silent, because only this
|
|
891
|
+
reason goes away when the path changes. */
|
|
892
|
+
let outOfScope = false;
|
|
893
|
+
/* The number of the boot under way. Raised by every start() and by leaving
|
|
894
|
+
the declared prefix, so that an answer landing for an earlier boot can tell
|
|
895
|
+
it no longer belongs to the page (bootIsStale, 85-pages). */
|
|
896
|
+
let bootRun = 0;
|
|
897
|
+
|
|
898
|
+
const inTool = (n) => !!(host && n && (n === host || host.contains(n)));
|
|
899
|
+
|
|
900
|
+
/* -- The browser's memory ------------------------------------------------
|
|
901
|
+
The try/catch blocks wrap ONLY the storage access, because that is the
|
|
902
|
+
only thing here that is allowed to fail: private browsing, or storage
|
|
903
|
+
refused by a browser policy. Widening them would turn a programming
|
|
904
|
+
mistake into a silent failure, and therefore into one nobody can find. */
|
|
905
|
+
|
|
906
|
+
// A per-browser convenience, not an identity: nobody is authenticated, and
|
|
907
|
+
// the name is there to know who to talk to, not to prove who one is.
|
|
908
|
+
const AUTHOR_KEY = 'annotepage/author';
|
|
909
|
+
|
|
910
|
+
/* The side the panel sits on. GLOBAL, exactly like the name above and
|
|
911
|
+
deliberately NOT under the project id: which edge a panel should sit on is
|
|
912
|
+
a fact about the screen and the hand in front of it, not about the project
|
|
913
|
+
being reviewed. Asking again on the next project would be asking the same
|
|
914
|
+
person the same question twice.
|
|
915
|
+
|
|
916
|
+
Two values and no third one. Annotation mode makes the layer take every
|
|
917
|
+
click, so every pixel of panel is a pixel of page that can no longer be
|
|
918
|
+
pointed at -- a panel that could sit anywhere would only move that loss
|
|
919
|
+
around, and would have to be moved back. */
|
|
920
|
+
const SIDE_KEY = 'annotepage/side';
|
|
921
|
+
|
|
922
|
+
function readSide() {
|
|
923
|
+
try {
|
|
924
|
+
return window.localStorage.getItem(SIDE_KEY) === 'left' ? 'left' : 'right';
|
|
925
|
+
} catch (e) {
|
|
926
|
+
// Without storage the panel starts on the right every visit: the
|
|
927
|
+
// choice still works, it is just not remembered.
|
|
928
|
+
return 'right';
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
function writeSide(value) {
|
|
933
|
+
side = value === 'left' ? 'left' : 'right';
|
|
934
|
+
try {
|
|
935
|
+
window.localStorage.setItem(SIDE_KEY, side);
|
|
936
|
+
} catch (e) {
|
|
937
|
+
// No consequence: only the memory of the side is lost.
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
/* The key is stored UNDER THE PROJECT ID. That naming is not cosmetic: two
|
|
942
|
+
projects reviewed from the same browser must not overwrite each other.
|
|
943
|
+
|
|
944
|
+
An unpleasant consequence, to be stated: localStorage is PER ORIGIN. The
|
|
945
|
+
day staging becomes production, every reviewer has to paste the key once
|
|
946
|
+
more on the new domain. The notes themselves do not move -- and that is
|
|
947
|
+
exactly what the rule "the domain is not in the key" buys. */
|
|
948
|
+
const keyKey = (project) => 'annotepage/key/' + project;
|
|
949
|
+
|
|
950
|
+
const readSalt = (project) => {
|
|
951
|
+
try {
|
|
952
|
+
return String(window.localStorage.getItem(keyKey(project)) || '').trim();
|
|
953
|
+
} catch (e) {
|
|
954
|
+
// Without storage the key will be asked for on every visit: that is
|
|
955
|
+
// less comfortable, it is not a failure.
|
|
956
|
+
return '';
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
|
|
960
|
+
const writeSalt = (project, text) => {
|
|
961
|
+
try {
|
|
962
|
+
window.localStorage.setItem(keyKey(project), text);
|
|
963
|
+
return true;
|
|
964
|
+
} catch (e) {
|
|
965
|
+
// We return false so the screen can SAY it: a key that is not kept
|
|
966
|
+
// will have to be pasted again on every page, and it is better to
|
|
967
|
+
// know that straight away than on the third time.
|
|
968
|
+
return false;
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
|
|
972
|
+
const forgetSalt = (project) => {
|
|
973
|
+
try {
|
|
974
|
+
window.localStorage.removeItem(keyKey(project));
|
|
975
|
+
} catch (e) {
|
|
976
|
+
// Nothing to do: there was no storage in the first place.
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
|
|
980
|
+
function readAuthor() {
|
|
981
|
+
let raw = '';
|
|
982
|
+
try {
|
|
983
|
+
raw = window.localStorage.getItem(AUTHOR_KEY) || '';
|
|
984
|
+
} catch (e) {
|
|
985
|
+
return '';
|
|
986
|
+
}
|
|
987
|
+
return normalize(raw);
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
function writeAuthor(value) {
|
|
991
|
+
author = value;
|
|
992
|
+
// A DECLARED author (AUTHOR_FIXED, 00-preamble) is the host's to set, not
|
|
993
|
+
// the browser's to remember: it is kept in memory for the session -- which
|
|
994
|
+
// the line above does -- and never written to the shared author key, where
|
|
995
|
+
// it would bleed onto every other project reviewed from this browser. This
|
|
996
|
+
// is also the "keep in memory even when storage throws" the option asks
|
|
997
|
+
// for: the value is held whatever the storage does, with nothing said.
|
|
998
|
+
if (AUTHOR_FIXED) return;
|
|
999
|
+
try {
|
|
1000
|
+
window.localStorage.setItem(AUTHOR_KEY, value);
|
|
1001
|
+
} catch (e) {
|
|
1002
|
+
// No consequence: only the memory of the name is lost.
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
/* -- The scope -----------------------------------------------------------
|
|
1007
|
+
Two checks, and neither is a security measure. They keep a tag left in a
|
|
1008
|
+
shared template from collecting notes where the project does not go, and
|
|
1009
|
+
keep a client from talking to a server that is going to say no. The real
|
|
1010
|
+
boundary is the server's domain lock (FORMAT.md section 6.2), which is
|
|
1011
|
+
itself only an anti-abuse measure. */
|
|
1012
|
+
|
|
1013
|
+
const inScope = () => {
|
|
1014
|
+
if (DOMAINS.length && DOMAINS.indexOf(location.origin) === -1) return false;
|
|
1015
|
+
if (PATH_PREFIX && pagePath().indexOf(PATH_PREFIX) !== 0) return false;
|
|
1016
|
+
return true;
|
|
1017
|
+
};
|
|
1018
|
+
|
|
1019
|
+
/* -- The zone ------------------------------------------------------------
|
|
1020
|
+
Where on the page a remark can be WRITTEN (data-zone). Reading is never
|
|
1021
|
+
restricted: a note anchored outside the zone is still listed and badged,
|
|
1022
|
+
because a remark written before the zone was declared is still a remark.
|
|
1023
|
+
|
|
1024
|
+
Everything below takes what it judges as parameters -- the element, the
|
|
1025
|
+
selector, the browser's own verdict on a selector -- so that
|
|
1026
|
+
client/tools/check.mjs runs it against plain objects. */
|
|
1027
|
+
|
|
1028
|
+
/**
|
|
1029
|
+
* The items of a selector list, split on the commas that separate them.
|
|
1030
|
+
*
|
|
1031
|
+
* NOT text.split(','): a comma inside :is(a, b), inside [title="a,b"] or
|
|
1032
|
+
* after a backslash belongs to one item. What an item is still left to the
|
|
1033
|
+
* browser -- this only has to find where one ends, so that the console can
|
|
1034
|
+
* name the item that is wrong instead of repeating a whole list back.
|
|
1035
|
+
*/
|
|
1036
|
+
const selectorItems = (text) => {
|
|
1037
|
+
const items = [];
|
|
1038
|
+
let depth = 0;
|
|
1039
|
+
let quote = '';
|
|
1040
|
+
let from = 0;
|
|
1041
|
+
for (let i = 0; i < text.length; i += 1) {
|
|
1042
|
+
const c = text[i];
|
|
1043
|
+
if (c === '\\') {
|
|
1044
|
+
i += 1;
|
|
1045
|
+
} else if (quote) {
|
|
1046
|
+
if (c === quote) quote = '';
|
|
1047
|
+
} else if (c === '"' || c === '\'') {
|
|
1048
|
+
quote = c;
|
|
1049
|
+
} else if (c === '(' || c === '[') {
|
|
1050
|
+
depth += 1;
|
|
1051
|
+
} else if ((c === ')' || c === ']') && depth > 0) {
|
|
1052
|
+
depth -= 1;
|
|
1053
|
+
} else if (c === ',' && depth === 0) {
|
|
1054
|
+
items.push(text.slice(from, i).trim());
|
|
1055
|
+
from = i + 1;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
items.push(text.slice(from).trim());
|
|
1059
|
+
return items;
|
|
1060
|
+
};
|
|
1061
|
+
|
|
1062
|
+
/**
|
|
1063
|
+
* The declared zone, judged once: { declared, valid, selector, broken }.
|
|
1064
|
+
*
|
|
1065
|
+
* `compiles` is the browser asked about one selector. It is the only judge
|
|
1066
|
+
* of CSS here -- a second grammar written in this file would be a second one
|
|
1067
|
+
* to keep in step with every browser.
|
|
1068
|
+
*
|
|
1069
|
+
* AN EMPTY ITEM IS BROKEN TOO: ".a," and ", .b" are refused by every browser,
|
|
1070
|
+
* and so is an empty attribute. `broken` is what the console line names.
|
|
1071
|
+
*
|
|
1072
|
+
* AND INVALID NEVER MEANS "EVERYWHERE". A selector that does not parse
|
|
1073
|
+
* restricts to nothing at all: falling back on the whole page would open
|
|
1074
|
+
* every part the site meant to close, with nothing on screen to say so.
|
|
1075
|
+
*/
|
|
1076
|
+
const zoneFrom = (declared, text, compiles) => {
|
|
1077
|
+
if (!declared) return { declared: false, valid: true, selector: '', broken: '' };
|
|
1078
|
+
const selector = String(text).trim();
|
|
1079
|
+
const items = selectorItems(selector);
|
|
1080
|
+
for (let i = 0; i < items.length; i += 1) {
|
|
1081
|
+
if (items[i] === '' || !compiles(items[i])) {
|
|
1082
|
+
return { declared: true, valid: false, selector: selector, broken: items[i] };
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
/* The whole list as well: the items passing one by one is what the
|
|
1086
|
+
split believes, and the list is what will actually be matched. */
|
|
1087
|
+
if (!compiles(selector)) return { declared: true, valid: false, selector: selector, broken: selector };
|
|
1088
|
+
return { declared: true, valid: true, selector: selector, broken: '' };
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
/** The zone element holding `el` -- `el` itself when it matches -- or null.
|
|
1092
|
+
Walked by hand rather than with closest(), so that the walk is the code
|
|
1093
|
+
under test and not a stand-in for it. */
|
|
1094
|
+
const zoneHolding = (el, selector) => {
|
|
1095
|
+
for (let n = el; n && n.nodeType === 1; n = n.parentElement) {
|
|
1096
|
+
if (n.matches(selector)) return n;
|
|
1097
|
+
}
|
|
1098
|
+
return null;
|
|
1099
|
+
};
|
|
1100
|
+
|
|
1101
|
+
/** 'anywhere' (no zone declared), 'inside', 'outside', or 'nowhere' (a
|
|
1102
|
+
selector that is not one). Asked at every pick, never cached: the zone
|
|
1103
|
+
may have been rendered, or replaced, since the last one. */
|
|
1104
|
+
const pickVerdict = (zone, el) => {
|
|
1105
|
+
if (!zone.declared) return 'anywhere';
|
|
1106
|
+
if (!zone.valid) return 'nowhere';
|
|
1107
|
+
return zoneHolding(el, zone.selector) ? 'inside' : 'outside';
|
|
1108
|
+
};
|
|
1109
|
+
|
|
1110
|
+
/** Of the elements matching the zone, those no other match contains. A
|
|
1111
|
+
nested zone adds no room to write, and outlining it too would draw a
|
|
1112
|
+
frame inside a frame for every paragraph of `.article, .article p`. */
|
|
1113
|
+
const outermostZones = (elements, selector) => {
|
|
1114
|
+
const outer = [];
|
|
1115
|
+
for (let i = 0; i < elements.length; i += 1) {
|
|
1116
|
+
if (!zoneHolding(elements[i].parentElement, selector)) outer.push(elements[i]);
|
|
1117
|
+
}
|
|
1118
|
+
return outer;
|
|
1119
|
+
};
|
|
1120
|
+
|
|
1121
|
+
/* ==== 50-anchors.js ==== */
|
|
1122
|
+
|
|
1123
|
+
/* -- 11. The three anchors of an element ---------------------------------
|
|
1124
|
+
None is reliable on its own: a path breaks at the first inserted block, a
|
|
1125
|
+
fingerprint of classes breaks when the styling is redone, a text excerpt
|
|
1126
|
+
breaks at the editorial pass. Together they make it possible to DEGRADE --
|
|
1127
|
+
to flag the note as orphaned -- instead of losing it. */
|
|
1128
|
+
|
|
1129
|
+
const cssPath = (el) => {
|
|
1130
|
+
const parts = [];
|
|
1131
|
+
let n = el;
|
|
1132
|
+
while (n && n.nodeType === 1 && n !== document.body && n !== document.documentElement) {
|
|
1133
|
+
const tag = n.localName;
|
|
1134
|
+
let rank = 1;
|
|
1135
|
+
let s = n.previousElementSibling;
|
|
1136
|
+
while (s) {
|
|
1137
|
+
if (s.localName === tag) rank += 1;
|
|
1138
|
+
s = s.previousElementSibling;
|
|
1139
|
+
}
|
|
1140
|
+
parts.unshift(tag + ':nth-of-type(' + rank + ')');
|
|
1141
|
+
n = n.parentElement;
|
|
1142
|
+
}
|
|
1143
|
+
// Too long for the column: we drop the leading segments. The path becomes
|
|
1144
|
+
// relative and may designate several elements -- which is exactly why the
|
|
1145
|
+
// fingerprint and the excerpt exist.
|
|
1146
|
+
let path = parts.join(' > ');
|
|
1147
|
+
while (path.length > MAX_SELECTOR && parts.length > 1) {
|
|
1148
|
+
parts.shift();
|
|
1149
|
+
path = parts.join(' > ');
|
|
1150
|
+
}
|
|
1151
|
+
return clip(path, MAX_SELECTOR);
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
const fingerprintOf = (el) => {
|
|
1155
|
+
if (!el || el.nodeType !== 1) return '';
|
|
1156
|
+
let e = el.localName;
|
|
1157
|
+
if (el.id) e += '#' + el.id;
|
|
1158
|
+
const classes = (el.getAttribute('class') || '').split(/\s+/).filter(Boolean);
|
|
1159
|
+
for (let i = 0; i < classes.length && i < 4; i += 1) e += '.' + classes[i];
|
|
1160
|
+
return clip(e, MAX_FINGERPRINT);
|
|
1161
|
+
};
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* The text by which a human recognises the element. It is what shows in the
|
|
1165
|
+
* panel: "About: Contact us". Never the path, never the fingerprint -- those
|
|
1166
|
+
* are anchors for machines.
|
|
1167
|
+
*/
|
|
1168
|
+
const excerptOf = (el) => {
|
|
1169
|
+
if (!el || el.nodeType !== 1) return '';
|
|
1170
|
+
let t = normalize(el.textContent);
|
|
1171
|
+
if (!t) {
|
|
1172
|
+
t = normalize(
|
|
1173
|
+
el.getAttribute('alt') ||
|
|
1174
|
+
el.getAttribute('aria-label') ||
|
|
1175
|
+
el.getAttribute('placeholder') ||
|
|
1176
|
+
el.getAttribute('title') ||
|
|
1177
|
+
(el.localName === 'input' ? el.value : '') ||
|
|
1178
|
+
''
|
|
1179
|
+
);
|
|
1180
|
+
}
|
|
1181
|
+
return clip(t, MAX_EXCERPT);
|
|
1182
|
+
};
|
|
1183
|
+
|
|
1184
|
+
/* -- 12. Finding the element of a note ----------------------------------- */
|
|
1185
|
+
|
|
1186
|
+
const score = (el, note) => {
|
|
1187
|
+
let s = 0;
|
|
1188
|
+
if (note.fingerprint && fingerprintOf(el) === note.fingerprint) s += 2;
|
|
1189
|
+
if (note.excerpt) {
|
|
1190
|
+
const t = excerptOf(el);
|
|
1191
|
+
if (t === note.excerpt) s += 2;
|
|
1192
|
+
else if (t && note.excerpt.length >= 12 && t.indexOf(note.excerpt.slice(0, 24)) === 0) s += 1;
|
|
1193
|
+
}
|
|
1194
|
+
return s;
|
|
1195
|
+
};
|
|
1196
|
+
|
|
1197
|
+
/**
|
|
1198
|
+
* Three attempts, from the most precise to the widest. If none returns an
|
|
1199
|
+
* element that resembles it enough, the note becomes ORPHANED: it stays
|
|
1200
|
+
* readable in the panel, with its date and its author, instead of vanishing
|
|
1201
|
+
* without anyone knowing.
|
|
1202
|
+
*/
|
|
1203
|
+
const findElement = (note) => {
|
|
1204
|
+
if (!note.selector && !note.fingerprint && !note.excerpt) return null;
|
|
1205
|
+
|
|
1206
|
+
// 1. The path, confirmed by at least one of the two other anchors.
|
|
1207
|
+
if (note.selector) {
|
|
1208
|
+
let el = null;
|
|
1209
|
+
try {
|
|
1210
|
+
el = document.body.querySelector(note.selector);
|
|
1211
|
+
} catch (e) {
|
|
1212
|
+
el = null; // path gone invalid: this is not a failure
|
|
1213
|
+
}
|
|
1214
|
+
if (el && !inTool(el)) {
|
|
1215
|
+
if (!note.fingerprint && !note.excerpt) return el;
|
|
1216
|
+
if (score(el, note) >= 1) return el;
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
1219
|
+
|
|
1220
|
+
// 2. The fingerprint: same tag, same classes, same id.
|
|
1221
|
+
if (note.fingerprint) {
|
|
1222
|
+
const tag = note.fingerprint.split(/[#.]/)[0];
|
|
1223
|
+
let candidates = [];
|
|
1224
|
+
try {
|
|
1225
|
+
candidates = Array.prototype.slice.call(document.body.querySelectorAll(tag));
|
|
1226
|
+
} catch (e) {
|
|
1227
|
+
candidates = [];
|
|
1228
|
+
}
|
|
1229
|
+
let best = null;
|
|
1230
|
+
let bestScore = 0;
|
|
1231
|
+
for (let i = 0; i < candidates.length; i += 1) {
|
|
1232
|
+
const c = candidates[i];
|
|
1233
|
+
if (inTool(c)) continue;
|
|
1234
|
+
const s = score(c, note);
|
|
1235
|
+
if (s > bestScore) {
|
|
1236
|
+
best = c;
|
|
1237
|
+
bestScore = s;
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
if (best && bestScore >= 2) return best;
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
// 3. The text alone, if it is long enough not to designate just
|
|
1244
|
+
// anything. It is the anchor that best survives a restyling.
|
|
1245
|
+
if (note.excerpt && note.excerpt.length >= 12) {
|
|
1246
|
+
const all = document.body.querySelectorAll('*');
|
|
1247
|
+
for (let i = 0; i < all.length; i += 1) {
|
|
1248
|
+
const c = all[i];
|
|
1249
|
+
if (inTool(c)) continue;
|
|
1250
|
+
if (excerptOf(c) === note.excerpt) return c;
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
return null;
|
|
1255
|
+
};
|
|
1256
|
+
|
|
1257
|
+
/** Splits the server's notes between elements found again and orphans. */
|
|
1258
|
+
const anchor = () => {
|
|
1259
|
+
anchored = [];
|
|
1260
|
+
orphans = [];
|
|
1261
|
+
for (let i = 0; i < notes.length; i += 1) {
|
|
1262
|
+
const note = notes[i];
|
|
1263
|
+
const el = findElement(note);
|
|
1264
|
+
if (!el) {
|
|
1265
|
+
orphans.push(note);
|
|
1266
|
+
continue;
|
|
1267
|
+
}
|
|
1268
|
+
let group = null;
|
|
1269
|
+
for (let j = 0; j < anchored.length; j += 1) {
|
|
1270
|
+
if (anchored[j].element === el) group = anchored[j];
|
|
1271
|
+
}
|
|
1272
|
+
if (!group) {
|
|
1273
|
+
group = { element: el, notes: [] };
|
|
1274
|
+
anchored.push(group);
|
|
1275
|
+
}
|
|
1276
|
+
group.notes.push(note);
|
|
1277
|
+
}
|
|
1278
|
+
};
|
|
1279
|
+
|
|
1280
|
+
/* -- 12 bis. When the page redraws itself under the tool -------------------
|
|
1281
|
+
`anchor()` resolves the elements ONCE. A page that replaces a piece of its
|
|
1282
|
+
own DOM -- a click that re-renders a block, a framework that swaps a node
|
|
1283
|
+
for an equivalent one -- leaves us holding a node that is no longer in the
|
|
1284
|
+
document: it measures 0x0, and the badge does not move, it VANISHES.
|
|
1285
|
+
|
|
1286
|
+
The two functions below are what lets refreshPositions notice and repair
|
|
1287
|
+
that, without the panel paying for it. */
|
|
1288
|
+
|
|
1289
|
+
/** True as soon as one remembered element has left the document. This is the
|
|
1290
|
+
safety net, and it is deliberately independent of the MutationObserver:
|
|
1291
|
+
an observer can be missing, disconnected, or blind to a change made
|
|
1292
|
+
before it was hooked up -- a detached node cannot hide. */
|
|
1293
|
+
const anchorsStale = () => {
|
|
1294
|
+
for (let i = 0; i < anchored.length; i += 1) {
|
|
1295
|
+
if (!document.contains(anchored[i].element)) return true;
|
|
1296
|
+
}
|
|
1297
|
+
return false;
|
|
1298
|
+
};
|
|
1299
|
+
|
|
1300
|
+
/**
|
|
1301
|
+
* What the PANEL would show of the current anchoring, as a string.
|
|
1302
|
+
*
|
|
1303
|
+
* The panel is rebuilt from scratch by drawPanel(), which costs the reader
|
|
1304
|
+
* their scroll position, their focus, and any reply half typed. So it is
|
|
1305
|
+
* only ever redrawn when this string changes -- that is, when a note has
|
|
1306
|
+
* actually moved between "anchored" and "orphaned", or when the groups no
|
|
1307
|
+
* longer hold the same notes. An element swapped for an equivalent one
|
|
1308
|
+
* changes NOTHING here, and rightly: only the markers have to be redrawn.
|
|
1309
|
+
*
|
|
1310
|
+
* Note identifiers are used, never the elements: two different nodes
|
|
1311
|
+
* carrying the same notes are the same thing as far as the panel goes.
|
|
1312
|
+
*/
|
|
1313
|
+
const anchorSignature = () => {
|
|
1314
|
+
const parts = [];
|
|
1315
|
+
for (let i = 0; i < anchored.length; i += 1) {
|
|
1316
|
+
const ids = [];
|
|
1317
|
+
for (let j = 0; j < anchored[i].notes.length; j += 1) {
|
|
1318
|
+
ids.push(anchored[i].notes[j].id);
|
|
1319
|
+
}
|
|
1320
|
+
parts.push(ids.join(','));
|
|
1321
|
+
}
|
|
1322
|
+
const lost = [];
|
|
1323
|
+
for (let i = 0; i < orphans.length; i += 1) lost.push(orphans[i].id);
|
|
1324
|
+
return parts.join('|') + '/' + lost.join(',');
|
|
1325
|
+
};
|
|
1326
|
+
|
|
1327
|
+
/* ==== 55-bridge.js ==== */
|
|
1328
|
+
|
|
1329
|
+
/* -- 9 bis. The bridge between the hands and the head --------------------
|
|
1330
|
+
|
|
1331
|
+
The tool is one program in two halves (see ROLE, 00-preamble): the HANDS,
|
|
1332
|
+
which touch the page -- the pointing, the numbers, the highlight, the
|
|
1333
|
+
scrolling, and the anchoring that needs the DOM -- and the HEAD, which holds
|
|
1334
|
+
the panel, the keys, the server and the notes. In the ordinary tool ('full')
|
|
1335
|
+
both halves are THIS scope and call each other directly; the bridge below is
|
|
1336
|
+
never used.
|
|
1337
|
+
|
|
1338
|
+
In frame mode they are in two documents: the head in the host page, the hands
|
|
1339
|
+
inside a sealed iframe (sandbox allow-scripts, WITHOUT allow-same-origin).
|
|
1340
|
+
They share no scope, no storage and no DOM, so they speak only by
|
|
1341
|
+
postMessage, and this file is the whole of what crosses between them.
|
|
1342
|
+
|
|
1343
|
+
TWO RULES, both because the sealed iframe has a `null` origin -- there is no
|
|
1344
|
+
origin to name, so the origin is never used as a key:
|
|
1345
|
+
- a message is ours only if it carries our NAMESPACE;
|
|
1346
|
+
- it is from the other half only if its SOURCE WINDOW is the one we are
|
|
1347
|
+
paired with -- the iframe's contentWindow for the head, window.parent for
|
|
1348
|
+
the hands.
|
|
1349
|
+
Nothing structural is trusted from a message beyond a string `type` and a
|
|
1350
|
+
plain-data `data`; neither side ever runs what the other sends. */
|
|
1351
|
+
|
|
1352
|
+
const BRIDGE_NS = 'annotepage/bridge/1';
|
|
1353
|
+
|
|
1354
|
+
const bridgeHandlers = {};
|
|
1355
|
+
const onBridge = (type, fn) => { bridgeHandlers[type] = fn; };
|
|
1356
|
+
|
|
1357
|
+
let bridgePeer = null; // the window on the other side, once known
|
|
1358
|
+
let bridgeStarted = false;
|
|
1359
|
+
|
|
1360
|
+
/* The head knows its peer from the start -- the iframe's contentWindow. The
|
|
1361
|
+
hands learn theirs from the first message they receive, which is the
|
|
1362
|
+
parent. Either way it is a WINDOW, compared by identity, not by origin. */
|
|
1363
|
+
const bridgeConnect = (peer) => { bridgePeer = peer || null; };
|
|
1364
|
+
|
|
1365
|
+
const bridgeSend = (type, data) => {
|
|
1366
|
+
if (!bridgePeer) return;
|
|
1367
|
+
try {
|
|
1368
|
+
bridgePeer.postMessage(
|
|
1369
|
+
{ ns: BRIDGE_NS, type: type, data: data === undefined ? null : data },
|
|
1370
|
+
'*');
|
|
1371
|
+
} catch (e) {
|
|
1372
|
+
/* The other window is gone -- the iframe was removed, or the parent
|
|
1373
|
+
navigated away. There is nothing to say to it and nothing to do. */
|
|
1374
|
+
}
|
|
1375
|
+
};
|
|
1376
|
+
|
|
1377
|
+
/* `expectedPeer` is the only window a side will listen to: the iframe for the
|
|
1378
|
+
head, left null for the hands (which accept their parent as it first
|
|
1379
|
+
speaks, then pin to it). */
|
|
1380
|
+
const bridgeStart = (expectedPeer) => {
|
|
1381
|
+
if (bridgeStarted) return;
|
|
1382
|
+
bridgeStarted = true;
|
|
1383
|
+
window.addEventListener('message', (event) => {
|
|
1384
|
+
const msg = event.data;
|
|
1385
|
+
if (!msg || typeof msg !== 'object' || msg.ns !== BRIDGE_NS) return;
|
|
1386
|
+
if (expectedPeer && event.source !== expectedPeer) return;
|
|
1387
|
+
if (!bridgePeer) bridgePeer = event.source;
|
|
1388
|
+
else if (event.source !== bridgePeer) return;
|
|
1389
|
+
const fn = bridgeHandlers[msg.type];
|
|
1390
|
+
if (fn) fn(msg.data, event);
|
|
1391
|
+
});
|
|
1392
|
+
};
|
|
1393
|
+
|
|
1394
|
+
/* ==== 57-shell.js ==== */
|
|
1395
|
+
|
|
1396
|
+
/* ============================================================================
|
|
1397
|
+
57-shell.js -- THE SHELL BOTH HALVES BUILD.
|
|
1398
|
+
|
|
1399
|
+
The host element, its shadow root and the one layer inside it, plus the
|
|
1400
|
+
container controller. Shared because BOTH roles build a host-and-layer: the
|
|
1401
|
+
head builds the panel into it, the hands build the page overlay into it, and
|
|
1402
|
+
buildUi (role-gated, see its own note) decides which. In 'hands' the head
|
|
1403
|
+
branches of buildUi are never reached, so the head-only names they mention
|
|
1404
|
+
(toggleMode, applySide, ...) are never evaluated there.
|
|
1405
|
+
============================================================================ */
|
|
1406
|
+
|
|
1407
|
+
/* -- 13. Building the interface -------------------------------------------
|
|
1408
|
+
Everything below lives in the shadow root. The host site sees none of it,
|
|
1409
|
+
and is seen by none of it. */
|
|
1410
|
+
|
|
1411
|
+
/**
|
|
1412
|
+
* The host element and its shadow root, and NOTHING ELSE.
|
|
1413
|
+
*
|
|
1414
|
+
* It is created before the labels are loaded -- a shadow root is needed to
|
|
1415
|
+
* load them into -- but it shows nothing: the interface itself is only built
|
|
1416
|
+
* once the texts are available.
|
|
1417
|
+
*/
|
|
1418
|
+
/* The first element matching a selector, or null -- and null, not a throw, for
|
|
1419
|
+
a selector the browser cannot parse. The container option takes a selector
|
|
1420
|
+
from the host page, and a mistake in it must not take the whole tool down. */
|
|
1421
|
+
const firstMatch = (selector) => {
|
|
1422
|
+
try {
|
|
1423
|
+
return document.querySelector(selector);
|
|
1424
|
+
} catch (e) {
|
|
1425
|
+
return null;
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
|
|
1429
|
+
const buildHost = () => {
|
|
1430
|
+
// IDEMPOTENT, and this is not a stylistic precaution: the key-pasting
|
|
1431
|
+
// screen built the host BEFORE the normal startup asked for it in turn.
|
|
1432
|
+
// Without this guard, the site received TWO elements, one of them empty
|
|
1433
|
+
// and orphaned -- the promise "one single element added" fell over at the
|
|
1434
|
+
// first pasted key.
|
|
1435
|
+
if (host) return;
|
|
1436
|
+
host = document.createElement('annotepage-notes');
|
|
1437
|
+
|
|
1438
|
+
/* WHERE THE TOOL IS DRAWN. By default it floats: the host is a full-screen,
|
|
1439
|
+
click-through layer pinned to the viewport, exactly as it has always
|
|
1440
|
+
been. With the `container` option it is DOCKED instead -- the host fills
|
|
1441
|
+
the element the host page handed over, the panel fills the host, and
|
|
1442
|
+
there is no floating button (the page opens and closes it, see buildUi).
|
|
1443
|
+
A container asked for but not found on the page is said once and the tool
|
|
1444
|
+
floats: a tool that draws nothing, silently, is the failure nobody finds. */
|
|
1445
|
+
dockEl = CONTAINER_EL
|
|
1446
|
+
|| (CONTAINER_SELECTOR ? firstMatch(CONTAINER_SELECTOR) : null);
|
|
1447
|
+
if (!dockEl && (CONTAINER_EL || CONTAINER_SELECTOR)) {
|
|
1448
|
+
complain('the container "' + (CONTAINER_SELECTOR || '[element]') + '" was not '
|
|
1449
|
+
+ 'found on the page; the tool falls back to its floating button.');
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1452
|
+
// These properties are set INLINE and with !important, on our own
|
|
1453
|
+
// element: a site rule aiming at "body > div" must not be able to move
|
|
1454
|
+
// the layer. "all: initial" also cuts off any inheritance from the site
|
|
1455
|
+
// into the tool.
|
|
1456
|
+
if (dockEl) {
|
|
1457
|
+
/* DOCKED: the host fills the element it was given and takes part in its
|
|
1458
|
+
layout (position: relative, so the panel's absolute fill is measured
|
|
1459
|
+
against it). Still click-through at the host -- only the panel inside
|
|
1460
|
+
takes clicks -- and the markers and highlight stay viewport-fixed, so
|
|
1461
|
+
pointing at the page works exactly as when floating. */
|
|
1462
|
+
host.style.cssText =
|
|
1463
|
+
'all: initial !important;' +
|
|
1464
|
+
'position: relative !important;' +
|
|
1465
|
+
'display: block !important;' +
|
|
1466
|
+
'width: 100% !important; height: 100% !important;' +
|
|
1467
|
+
'margin: 0 !important; padding: 0 !important; border: 0 !important;' +
|
|
1468
|
+
'pointer-events: none !important;' +
|
|
1469
|
+
'z-index: 2147483000 !important;';
|
|
1470
|
+
dockEl.appendChild(host);
|
|
1471
|
+
} else {
|
|
1472
|
+
host.style.cssText =
|
|
1473
|
+
'all: initial !important;' +
|
|
1474
|
+
'position: fixed !important;' +
|
|
1475
|
+
'top: 0 !important; left: 0 !important;' +
|
|
1476
|
+
'right: 0 !important; bottom: 0 !important;' +
|
|
1477
|
+
'width: auto !important; height: auto !important;' +
|
|
1478
|
+
'margin: 0 !important; padding: 0 !important; border: 0 !important;' +
|
|
1479
|
+
'pointer-events: none !important;' +
|
|
1480
|
+
'z-index: 2147483000 !important;';
|
|
1481
|
+
document.body.appendChild(host);
|
|
1482
|
+
}
|
|
1483
|
+
// And kept there: a router that swaps the body takes it along (85-pages).
|
|
1484
|
+
watchHost();
|
|
1485
|
+
root = host.attachShadow({ mode: 'open' });
|
|
1486
|
+
|
|
1487
|
+
/* The stylesheet is PUT HERE, in a <style>, and not loaded by a <link>
|
|
1488
|
+
as in the original tool.
|
|
1489
|
+
|
|
1490
|
+
Reason: the client goes to a CDN under SRI. A second request to a
|
|
1491
|
+
neighbouring file would mean a second digest to keep up to date, and
|
|
1492
|
+
nobody keeps two digests in agreement for long. One file, one digest,
|
|
1493
|
+
one thing to check.
|
|
1494
|
+
|
|
1495
|
+
Pleasant side effect: the sheet is there before the first pixel. The
|
|
1496
|
+
hiding and then showing of the host element, which existed so as not
|
|
1497
|
+
to show the tool unstyled for a fraction of a second, no longer has
|
|
1498
|
+
any reason to be and is gone.
|
|
1499
|
+
|
|
1500
|
+
The price, to be stated: the sheet weighs in the served file, and the
|
|
1501
|
+
styling can no longer be replaced by changing a neighbouring file -- it
|
|
1502
|
+
has to be rebuilt. */
|
|
1503
|
+
/* Two routes, and the first is not vanity: a strict content security
|
|
1504
|
+
policy (style-src without 'unsafe-inline') BLOCKS a <style> element,
|
|
1505
|
+
and the tool would show up unstyled -- which looks like a broken page.
|
|
1506
|
+
A CONSTRUCTED sheet, on the other hand, is not an inline sheet in the
|
|
1507
|
+
policy's sense, and goes through. We keep <style> for the browsers
|
|
1508
|
+
that do not construct sheets. */
|
|
1509
|
+
let placed = false;
|
|
1510
|
+
try {
|
|
1511
|
+
if (root.adoptedStyleSheets && typeof CSSStyleSheet === 'function') {
|
|
1512
|
+
const sheet = new CSSStyleSheet();
|
|
1513
|
+
sheet.replaceSync(STYLES);
|
|
1514
|
+
root.adoptedStyleSheets = [sheet];
|
|
1515
|
+
placed = true;
|
|
1516
|
+
}
|
|
1517
|
+
} catch (e) {
|
|
1518
|
+
placed = false;
|
|
1519
|
+
}
|
|
1520
|
+
if (!placed) {
|
|
1521
|
+
const style = document.createElement('style');
|
|
1522
|
+
style.textContent = STYLES;
|
|
1523
|
+
root.appendChild(style);
|
|
1524
|
+
}
|
|
1525
|
+
};
|
|
1526
|
+
|
|
1527
|
+
/** The interface. Built AFTER the labels: no fallback text to put in. */
|
|
1528
|
+
/* THE ONE LAYER, BUILT FOR THIS ROLE. In 'full' every branch is taken and the
|
|
1529
|
+
layer holds everything, exactly as the tool always has -- same elements, same
|
|
1530
|
+
order, so the floating stylesheet and the pixels are untouched. In 'head' the
|
|
1531
|
+
page-overlay pieces are skipped: the highlight, the numbers and the zone
|
|
1532
|
+
frames are drawn by the hands, in the iframe's own layer. In 'hands' it is the
|
|
1533
|
+
other way round: no button, no panel, no form -- only the overlay. The append
|
|
1534
|
+
ORDER is kept identical to the original for the full tool, so nothing about it
|
|
1535
|
+
can move a pixel. */
|
|
1536
|
+
const buildUi = () => {
|
|
1537
|
+
const layer = create('div', 'ap-layer');
|
|
1538
|
+
// DOCKED (container option): the panel fills the host and there is no
|
|
1539
|
+
// floating button. One class carries both, so the floating stylesheet is
|
|
1540
|
+
// untouched -- without `container`, this class is never added.
|
|
1541
|
+
if (dockEl) layer.classList.add('ap-docked');
|
|
1542
|
+
root.appendChild(layer);
|
|
1543
|
+
|
|
1544
|
+
let button = null, buttonText = null, buttonCount = null;
|
|
1545
|
+
let zones = null, zoneNotice = null, highlight = null, label = null, markers = null;
|
|
1546
|
+
let panel = null, sideToggle = null, body = null, keeps = null, footer = null, form = null;
|
|
1547
|
+
|
|
1548
|
+
/* -- the button (head) -- */
|
|
1549
|
+
if (ROLE !== 'hands') {
|
|
1550
|
+
button = create('button', 'ap-button');
|
|
1551
|
+
button.type = 'button';
|
|
1552
|
+
button.setAttribute('aria-pressed', 'false');
|
|
1553
|
+
button.title = T('button.help');
|
|
1554
|
+
const dot = create('span', 'ap-button-dot');
|
|
1555
|
+
buttonText = create('span', null, T('button.open'));
|
|
1556
|
+
buttonCount = create('span', 'ap-button-count');
|
|
1557
|
+
button.appendChild(dot);
|
|
1558
|
+
button.appendChild(buttonText);
|
|
1559
|
+
button.appendChild(buttonCount);
|
|
1560
|
+
button.addEventListener('click', () => toggleMode());
|
|
1561
|
+
layer.appendChild(button);
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
/* -- the page overlay (hands): zones, pointing highlight, markers --
|
|
1565
|
+
The zones come before the highlight, so that the outline of the element
|
|
1566
|
+
being pointed at is drawn over the frame of the zone that holds it. */
|
|
1567
|
+
if (ROLE !== 'head') {
|
|
1568
|
+
zones = create('div', 'ap-zones');
|
|
1569
|
+
layer.appendChild(zones);
|
|
1570
|
+
zoneNotice = create('div', 'ap-zone-notice');
|
|
1571
|
+
zoneNotice.setAttribute('role', 'status');
|
|
1572
|
+
|
|
1573
|
+
highlight = create('div', 'ap-highlight');
|
|
1574
|
+
label = create('div', 'ap-highlight-label');
|
|
1575
|
+
layer.appendChild(highlight);
|
|
1576
|
+
layer.appendChild(label);
|
|
1577
|
+
layer.appendChild(zoneNotice);
|
|
1578
|
+
|
|
1579
|
+
markers = create('div', 'ap-markers');
|
|
1580
|
+
layer.appendChild(markers);
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
/* -- the panel and the new-remark form (head) -- */
|
|
1584
|
+
if (ROLE !== 'hands') {
|
|
1585
|
+
panel = create('aside', 'ap-panel');
|
|
1586
|
+
panel.setAttribute('role', 'complementary');
|
|
1587
|
+
const header = create('div', 'ap-panel-header');
|
|
1588
|
+
const title = create('span', 'ap-panel-title', T('panel.title'));
|
|
1589
|
+
const close = create('button', 'ap-link', T('panel.close'));
|
|
1590
|
+
close.type = 'button';
|
|
1591
|
+
close.addEventListener('click', () => leaveMode());
|
|
1592
|
+
/* A REAL BUTTON, in the header, beside Close -- not a draggable title
|
|
1593
|
+
bar. A title bar reads as a title and not as a handle; without
|
|
1594
|
+
snapping, a dragged panel ends up crooked; and under a finger the drag
|
|
1595
|
+
fights the page's own scrolling. Being a button, it is reachable from
|
|
1596
|
+
the keyboard for free, which is why there is no shortcut for this:
|
|
1597
|
+
onKey is a capturing document listener and would fire while somebody
|
|
1598
|
+
is typing their remark in the textarea.
|
|
1599
|
+
|
|
1600
|
+
FLOATING ONLY. Docked (the `container` option), the panel fills the
|
|
1601
|
+
element the host handed over: there is no side for it to sit on, no
|
|
1602
|
+
floating button to follow it, and the move-left/right toggle means
|
|
1603
|
+
nothing. So it is not built at all when docked -- the stylesheet
|
|
1604
|
+
already hides it there (.ap-docked .ap-side-toggle), and applySide
|
|
1605
|
+
steps over a sideToggle that is not there. Without `container` this
|
|
1606
|
+
header is exactly what it always was: title, toggle, close. */
|
|
1607
|
+
header.appendChild(title);
|
|
1608
|
+
if (!dockEl) {
|
|
1609
|
+
sideToggle = create('button', 'ap-link ap-side-toggle');
|
|
1610
|
+
sideToggle.type = 'button';
|
|
1611
|
+
sideToggle.addEventListener('click', () => moveSide());
|
|
1612
|
+
header.appendChild(sideToggle);
|
|
1613
|
+
}
|
|
1614
|
+
header.appendChild(close);
|
|
1615
|
+
const instructions = create('div', 'ap-panel-instructions');
|
|
1616
|
+
/* With a zone, the sentence says where to click: frames on the page with
|
|
1617
|
+
nothing explaining them read as the site's own decoration. And the zone
|
|
1618
|
+
is judged HERE, once the tool exists on this page, so that a selector
|
|
1619
|
+
that does not parse is said in the console at load -- not on the day a
|
|
1620
|
+
reviewer first tries to click. */
|
|
1621
|
+
instructions.appendChild(create('div', null,
|
|
1622
|
+
T(judgeZone().declared ? 'panel.instructions_zone' : 'panel.instructions')));
|
|
1623
|
+
instructions.appendChild(create('div', null, T('panel.escape')));
|
|
1624
|
+
/* HOW LONG THIS SERVER KEEPS A THREAD, AND ONLY WHERE IT KEEPS ONE FOR A
|
|
1625
|
+
WHILE. "Nothing is ever deleted" is what this tool promises and what it
|
|
1626
|
+
does everywhere except on a server whose operator set an age -- and
|
|
1627
|
+
somebody about to write a remark is entitled to know their remark has a
|
|
1628
|
+
date on it. It goes here, at the top of the panel, read once when the
|
|
1629
|
+
panel opens: under the form it would be repeated at every remark, and
|
|
1630
|
+
behind a button it would be findable rather than said.
|
|
1631
|
+
|
|
1632
|
+
The element is created and left EMPTY when nothing expires, so the
|
|
1633
|
+
panel's own layout is identical on the servers that keep everything --
|
|
1634
|
+
which is all but one of them. */
|
|
1635
|
+
keeps = create('div', 'ap-panel-keeps');
|
|
1636
|
+
instructions.appendChild(keeps);
|
|
1637
|
+
body = create('div', 'ap-panel-body');
|
|
1638
|
+
footer = create('div', 'ap-panel-footer');
|
|
1639
|
+
panel.appendChild(header);
|
|
1640
|
+
panel.appendChild(instructions);
|
|
1641
|
+
panel.appendChild(body);
|
|
1642
|
+
panel.appendChild(footer);
|
|
1643
|
+
layer.appendChild(panel);
|
|
1644
|
+
|
|
1645
|
+
form = create('div', 'ap-form');
|
|
1646
|
+
// In head/frame mode the new-remark form lives IN the panel (decision
|
|
1647
|
+
// A), where it can fill it; in full mode it floats over the page, as a
|
|
1648
|
+
// layer child. 'full' keeps the layer, so nothing moves.
|
|
1649
|
+
(ROLE === 'head' ? panel : layer).appendChild(form);
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
ui = {
|
|
1653
|
+
layer: layer,
|
|
1654
|
+
button: button,
|
|
1655
|
+
buttonText: buttonText,
|
|
1656
|
+
buttonCount: buttonCount,
|
|
1657
|
+
highlight: highlight,
|
|
1658
|
+
label: label,
|
|
1659
|
+
markers: markers,
|
|
1660
|
+
panel: panel,
|
|
1661
|
+
sideToggle: sideToggle,
|
|
1662
|
+
body: body,
|
|
1663
|
+
keeps: keeps,
|
|
1664
|
+
footer: footer,
|
|
1665
|
+
form: form,
|
|
1666
|
+
zones: zones,
|
|
1667
|
+
zoneNotice: zoneNotice
|
|
1668
|
+
};
|
|
1669
|
+
|
|
1670
|
+
if (ROLE !== 'hands') applySide();
|
|
1671
|
+
if (dockEl) publishController();
|
|
1672
|
+
};
|
|
1673
|
+
|
|
1674
|
+
/* THE HOST PAGE'S HANDLE ON A DOCKED TOOL. With no floating button, the page is
|
|
1675
|
+
what opens and closes annotation mode, so the tool hands it a small controller
|
|
1676
|
+
ON THE CONTAINER ELEMENT and raises a `ready` event on it. The event may be
|
|
1677
|
+
missed by a listener attached too late; the handle is a property as well, so
|
|
1678
|
+
the page can either wait for the event or read `el.annotepage` when it likes.
|
|
1679
|
+
|
|
1680
|
+
const box = document.querySelector('#remarks');
|
|
1681
|
+
const wire = () => myButton.onclick = () => box.annotepage.toggle();
|
|
1682
|
+
box.annotepage ? wire() : box.addEventListener('annotepage:ready', wire);
|
|
1683
|
+
|
|
1684
|
+
Nothing here reaches into the page; the page reaches into nothing of ours. */
|
|
1685
|
+
const publishController = () => {
|
|
1686
|
+
if (!dockEl) return;
|
|
1687
|
+
const controller = {
|
|
1688
|
+
open: () => { if (!mode) enterMode(); },
|
|
1689
|
+
close: () => { if (mode) leaveMode(); },
|
|
1690
|
+
toggle: () => toggleMode(),
|
|
1691
|
+
get isOpen() { return mode; }
|
|
1692
|
+
};
|
|
1693
|
+
try {
|
|
1694
|
+
dockEl.annotepage = controller;
|
|
1695
|
+
} catch (e) {
|
|
1696
|
+
// A frozen or exotic element we cannot write a property on: the event
|
|
1697
|
+
// below still fires, and the page can keep its own reference from it.
|
|
1698
|
+
}
|
|
1699
|
+
try {
|
|
1700
|
+
dockEl.dispatchEvent(new CustomEvent('annotepage:ready', {
|
|
1701
|
+
detail: { annotepage: controller }
|
|
1702
|
+
}));
|
|
1703
|
+
} catch (e) {
|
|
1704
|
+
// CustomEvent absent (it is everywhere the tool runs) or dispatch
|
|
1705
|
+
// refused: the property above remains the way in.
|
|
1706
|
+
}
|
|
1707
|
+
};
|
|
1708
|
+
|
|
1709
|
+
/* ==== 58-hands.js ==== */
|
|
1710
|
+
|
|
1711
|
+
/* ============================================================================
|
|
1712
|
+
58-hands.js -- THE HANDS: everything that touches the annotated page.
|
|
1713
|
+
|
|
1714
|
+
The pointing highlight, the numbered markers, the zone outlines, the document
|
|
1715
|
+
pointer and key listeners, the scrolling, and the anchoring that needs a live
|
|
1716
|
+
DOM. This is the half that, in frame mode, runs INSIDE the sealed iframe
|
|
1717
|
+
(annotepage-frame.js is built from this file and the few it leans on); in the
|
|
1718
|
+
ordinary tool it is this same scope as the head, and the two call each other
|
|
1719
|
+
directly.
|
|
1720
|
+
|
|
1721
|
+
The head half -- the panel, the keys, the server, the notes -- is 60-ui.js.
|
|
1722
|
+
What crosses between them when they are in two documents is the bridge,
|
|
1723
|
+
55-bridge.js, and nothing else.
|
|
1724
|
+
============================================================================ */
|
|
1725
|
+
|
|
1726
|
+
/* -- Hands-side plumbing (used only when the hands run apart, ROLE 'hands') --
|
|
1727
|
+
In 'full' and 'head' these are inert: handsZone is never read (judgeZone takes
|
|
1728
|
+
the preamble's zone), and the helpers below take their non-hands branch, which
|
|
1729
|
+
calls the head's own local functions exactly as before. */
|
|
1730
|
+
|
|
1731
|
+
let handsZone = null; // the zone the head sent with pick:on: { declared, selector }
|
|
1732
|
+
|
|
1733
|
+
/* The state of a group's badge. In 'hands' the group's notes are the ITEMS the
|
|
1734
|
+
head sent, each already carrying the state the head computed (noteState needs
|
|
1735
|
+
the site version, which is the head's); in 'full' they are the real notes and
|
|
1736
|
+
the head's groupState decides. */
|
|
1737
|
+
const markerGroupState = (list) => {
|
|
1738
|
+
if (ROLE !== 'hands') return groupState(list);
|
|
1739
|
+
let seen = 'done';
|
|
1740
|
+
for (let i = 0; i < list.length; i += 1) {
|
|
1741
|
+
const one = list[i].state || 'open';
|
|
1742
|
+
if (one === 'open') return 'open';
|
|
1743
|
+
if (one === 'pending') seen = 'pending';
|
|
1744
|
+
}
|
|
1745
|
+
return seen;
|
|
1746
|
+
};
|
|
1747
|
+
|
|
1748
|
+
/* A marker was tapped. In 'full' the head is right here and opens the window; in
|
|
1749
|
+
'hands' the window is in the host page, so the ids go over the bridge and the
|
|
1750
|
+
head opens it there. */
|
|
1751
|
+
const tapGroup = (group) => {
|
|
1752
|
+
if (ROLE !== 'hands') return showGroup(group);
|
|
1753
|
+
const ids = [];
|
|
1754
|
+
for (let i = 0; i < group.notes.length; i += 1) ids.push(group.notes[i].id);
|
|
1755
|
+
bridgeSend('tapped', { ids: ids });
|
|
1756
|
+
};
|
|
1757
|
+
|
|
1758
|
+
/* WHICH NOTES ARE ORPHANED, reported to the head so its panel can show them in
|
|
1759
|
+
the "not found on this page" section. Only the ids cross -- the head already
|
|
1760
|
+
holds the notes themselves (see FRAME-DESIGN, data model). */
|
|
1761
|
+
const reportAnchored = () => {
|
|
1762
|
+
const ids = [];
|
|
1763
|
+
for (let i = 0; i < orphans.length; i += 1) ids.push(orphans[i].id);
|
|
1764
|
+
bridgeSend('anchored', { orphanIds: ids });
|
|
1765
|
+
};
|
|
1766
|
+
|
|
1767
|
+
/* -- The pointing highlight ---------------------------------------------- */
|
|
1768
|
+
|
|
1769
|
+
const place = (el, rect, margin) => {
|
|
1770
|
+
const m = margin || 0;
|
|
1771
|
+
el.style.left = Math.max(0, rect.left - m) + 'px';
|
|
1772
|
+
el.style.top = Math.max(0, rect.top - m) + 'px';
|
|
1773
|
+
el.style.width = Math.max(0, rect.width + m * 2) + 'px';
|
|
1774
|
+
el.style.height = Math.max(0, rect.height + m * 2) + 'px';
|
|
1775
|
+
};
|
|
1776
|
+
|
|
1777
|
+
const showHighlight = (el) => {
|
|
1778
|
+
if (!el) return hideHighlight();
|
|
1779
|
+
const r = el.getBoundingClientRect();
|
|
1780
|
+
if (r.width === 0 && r.height === 0) return hideHighlight();
|
|
1781
|
+
place(ui.highlight, r, 1);
|
|
1782
|
+
ui.highlight.style.display = 'block';
|
|
1783
|
+
|
|
1784
|
+
const text = excerptOf(el);
|
|
1785
|
+
ui.label.textContent = text || T('form.about_no_text');
|
|
1786
|
+
ui.label.style.display = 'block';
|
|
1787
|
+
const top = r.top > 26 ? r.top - 24 : Math.min(window.innerHeight - 24, r.bottom + 4);
|
|
1788
|
+
ui.label.style.left = Math.max(4, Math.min(r.left, window.innerWidth - 330)) + 'px';
|
|
1789
|
+
ui.label.style.top = top + 'px';
|
|
1790
|
+
};
|
|
1791
|
+
|
|
1792
|
+
const hideHighlight = () => {
|
|
1793
|
+
if (!ui) return;
|
|
1794
|
+
ui.highlight.style.display = 'none';
|
|
1795
|
+
ui.label.style.display = 'none';
|
|
1796
|
+
};
|
|
1797
|
+
|
|
1798
|
+
/* -- The markers, the reposition loop, and the zone on the page --------- */
|
|
1799
|
+
|
|
1800
|
+
/** One badge per annotated element. It only appears in annotation mode:
|
|
1801
|
+
outside that mode, the page is exactly the site's.
|
|
1802
|
+
|
|
1803
|
+
IT CARRIES A COUNT AND A COLOUR, and both are read at a glance without
|
|
1804
|
+
opening anything: how many remarks sit on this element, and whether any of
|
|
1805
|
+
them is still waiting. Blue is work to do, amber is fixed but not yet
|
|
1806
|
+
deployed -- the defect is still on screen -- and a hollow badge is history.
|
|
1807
|
+
The colour is never the only carrier: the count is written in it and the
|
|
1808
|
+
state is spelled out in the badge's accessible name.
|
|
1809
|
+
|
|
1810
|
+
AND CLICKING IT OPENS THE WINDOW. It used to bring the matching row forward
|
|
1811
|
+
in the panel, which answers "where is it in the list" -- a question nobody
|
|
1812
|
+
asks while pointing at the element itself. What they want is the remark,
|
|
1813
|
+
and the window is where a remark is read. */
|
|
1814
|
+
/* WHERE A BADGE SITS, given the element's rectangle and the viewport size. The
|
|
1815
|
+
value returned is the badge's TOP-LEFT corner, in viewport pixels.
|
|
1816
|
+
|
|
1817
|
+
NORMALLY 8px up and to the left of the element's own top-left corner, kept on
|
|
1818
|
+
screen -- the exact position the tool has always drawn, so every page that
|
|
1819
|
+
already has badges keeps them to the pixel. It leans a little over the
|
|
1820
|
+
corner, in the element's margin, which reads as "this element".
|
|
1821
|
+
|
|
1822
|
+
THE EDGES ARE WHERE THAT BROKE. An element flush to the LEFT edge has r.left
|
|
1823
|
+
near 0, so r.left - 8 is negative; the old Math.max(2, ...) then drove the
|
|
1824
|
+
badge to x=2, flat onto the element's first glyphs -- "1exte". The TOP edge
|
|
1825
|
+
had the same fault downward. So when a margin has no room, the badge is
|
|
1826
|
+
lifted CLEAR of the text into the margin that does: hard against the left, it
|
|
1827
|
+
sits just ABOVE the element (its bottom meeting the element's top); hard
|
|
1828
|
+
against the top, just to its LEFT. The common, non-edge case is untouched.
|
|
1829
|
+
|
|
1830
|
+
A badge is about 28px (min-width/height 22px plus its 2px halo, .ap-marker),
|
|
1831
|
+
and 28 is already the reach the on-screen clamp below assumes (vw/vh - 30,
|
|
1832
|
+
two px shy of the edge). Lifting by it clears a 26px badge with room over --
|
|
1833
|
+
WHERE THERE IS ROOM. Against one edge and within ~28px of the other (a corner,
|
|
1834
|
+
in effect), there is nowhere that clears the text; the badge then lifts as far
|
|
1835
|
+
as the near edge allows, which is never lower than the old clamp and so never
|
|
1836
|
+
over more of the glyphs than before. Only the floating, open-margin case is
|
|
1837
|
+
promised to clear entirely -- which is the case the fix was reported for. */
|
|
1838
|
+
const badgePosition = (r, vw, vh) => {
|
|
1839
|
+
const BADGE = 28;
|
|
1840
|
+
const left = Math.min(r.left - 8, vw - 30);
|
|
1841
|
+
const top = Math.min(r.top - 8, vh - 30);
|
|
1842
|
+
const leftTight = left < 2; // the left margin has no room: would clamp on
|
|
1843
|
+
const topTight = top < 2; // the top margin has no room: would clamp on
|
|
1844
|
+
if (leftTight && !topTight) {
|
|
1845
|
+
// Lift into the margin above: the badge's bottom meets the element's
|
|
1846
|
+
// top when there is room, and as near it as the top edge allows when
|
|
1847
|
+
// the element is also close to the top -- never below the old position.
|
|
1848
|
+
return { left: 2, top: Math.max(2, Math.min(r.top - BADGE, vh - 30)) };
|
|
1849
|
+
}
|
|
1850
|
+
if (topTight && !leftTight) {
|
|
1851
|
+
// The same, into the margin to the left: its right meets the element's
|
|
1852
|
+
// left where there is room, and as near as the left edge allows.
|
|
1853
|
+
return { left: Math.max(2, Math.min(r.left - BADGE, vw - 30)), top: 2 };
|
|
1854
|
+
}
|
|
1855
|
+
/* Non-edge -- the overwhelming case -- is byte-for-byte the old result; and
|
|
1856
|
+
the degenerate top-left corner, where no margin has room at all, falls
|
|
1857
|
+
back on it too, there being nowhere clear to lift to. */
|
|
1858
|
+
return { left: Math.max(2, left), top: Math.max(2, top) };
|
|
1859
|
+
};
|
|
1860
|
+
|
|
1861
|
+
const drawMarkers = () => {
|
|
1862
|
+
// The zones move with the page exactly when the badges do.
|
|
1863
|
+
drawZones();
|
|
1864
|
+
empty(ui.markers);
|
|
1865
|
+
if (!mode) return;
|
|
1866
|
+
for (let i = 0; i < anchored.length; i += 1) {
|
|
1867
|
+
const group = anchored[i];
|
|
1868
|
+
const r = group.element.getBoundingClientRect();
|
|
1869
|
+
if (r.width === 0 && r.height === 0) continue;
|
|
1870
|
+
if (r.bottom < 0 || r.top > window.innerHeight) continue;
|
|
1871
|
+
const n = group.notes.length;
|
|
1872
|
+
const state = markerGroupState(group.notes);
|
|
1873
|
+
const badge = create('button', 'ap-marker ap-marker-' + state, String(n));
|
|
1874
|
+
badge.type = 'button';
|
|
1875
|
+
const what = n === 1 ? T('marker.one') : T('marker.n', { n: n });
|
|
1876
|
+
const how = T(state === 'open' ? 'list.state_open'
|
|
1877
|
+
: (state === 'pending' ? 'list.state_pending' : 'list.state_done'));
|
|
1878
|
+
badge.title = what + ' \u2014 ' + how;
|
|
1879
|
+
badge.setAttribute('aria-label', T('marker.open') + ' \u2014 ' + what
|
|
1880
|
+
+ ' \u2014 ' + how);
|
|
1881
|
+
const at = badgePosition(r, window.innerWidth, window.innerHeight);
|
|
1882
|
+
badge.style.left = at.left + 'px';
|
|
1883
|
+
badge.style.top = at.top + 'px';
|
|
1884
|
+
badge.addEventListener('click', ((g) => () => tapGroup(g))(group));
|
|
1885
|
+
ui.markers.appendChild(badge);
|
|
1886
|
+
}
|
|
1887
|
+
};
|
|
1888
|
+
|
|
1889
|
+
/**
|
|
1890
|
+
* Redoes the anchoring when -- and only when -- the page has moved under us.
|
|
1891
|
+
*
|
|
1892
|
+
* Two triggers, on purpose. `domDirty` is raised by the MutationObserver,
|
|
1893
|
+
* which sees everything including a swap that leaves the badge in exactly the
|
|
1894
|
+
* same place; `anchorsStale()` sees a detached node even when no observer is
|
|
1895
|
+
* running. Either one alone would have a blind spot.
|
|
1896
|
+
*
|
|
1897
|
+
* THE PANEL IS ONLY REDRAWN IF THE RESULT CHANGED. drawPanel() rebuilds the
|
|
1898
|
+
* list from nothing: called at every tick it would wipe the reader's scroll
|
|
1899
|
+
* position, the focus, and any reply being typed. The signature says whether
|
|
1900
|
+
* a note actually changed side; the markers, cheap and stateless, are redrawn
|
|
1901
|
+
* by the caller in any case.
|
|
1902
|
+
*/
|
|
1903
|
+
const reanchor = () => {
|
|
1904
|
+
if (!domDirty && !anchorsStale()) return;
|
|
1905
|
+
domDirty = false;
|
|
1906
|
+
const before = anchorSignature();
|
|
1907
|
+
anchor();
|
|
1908
|
+
/* A note can also come BACK from the orphan list here: the page had not
|
|
1909
|
+
finished rendering when we first looked, and now it has. That is a real
|
|
1910
|
+
change, and it is worth the redraw. In 'hands' the panel is in the host
|
|
1911
|
+
page, so the change is reported and the head redraws it. */
|
|
1912
|
+
if (anchorSignature() !== before) {
|
|
1913
|
+
if (ROLE === 'hands') reportAnchored();
|
|
1914
|
+
else drawPanel();
|
|
1915
|
+
}
|
|
1916
|
+
};
|
|
1917
|
+
|
|
1918
|
+
const refreshPositions = () => {
|
|
1919
|
+
if (rafPending) return;
|
|
1920
|
+
rafPending = true;
|
|
1921
|
+
window.requestAnimationFrame(() => {
|
|
1922
|
+
rafPending = false;
|
|
1923
|
+
if (!mode) return;
|
|
1924
|
+
// BEFORE drawing: the markers must be measured on the elements that
|
|
1925
|
+
// are in the document now, not on the ones that were.
|
|
1926
|
+
reanchor();
|
|
1927
|
+
drawMarkers();
|
|
1928
|
+
/* A zone the page has since taken away puts the aim out. Without a
|
|
1929
|
+
zone pickable() is always true, and this is the line it replaced. */
|
|
1930
|
+
if (hovered && document.contains(hovered)) {
|
|
1931
|
+
if (pickable(hovered)) showHighlight(hovered);
|
|
1932
|
+
else hideHighlight();
|
|
1933
|
+
}
|
|
1934
|
+
// The new-remark form floats over its element only when it is in this
|
|
1935
|
+
// same document (full mode). In 'hands' the form is in the host panel.
|
|
1936
|
+
if (ROLE !== 'hands' && target && document.contains(target)) positionForm(target);
|
|
1937
|
+
});
|
|
1938
|
+
};
|
|
1939
|
+
|
|
1940
|
+
/* -- 14 bis. The zone, on the page ----------------------------------------
|
|
1941
|
+
The pure half -- what a selector is, which element holds which -- is in
|
|
1942
|
+
30-state. This half asks the document, and it asks AT EVERY PICK AND EVERY
|
|
1943
|
+
FRAME: a framework renders the zone after the boot, replaces it at a
|
|
1944
|
+
client-side navigation (85-pages), or never renders it on some pages. A
|
|
1945
|
+
list of zone elements kept from the boot would be a list of detached nodes
|
|
1946
|
+
by the second page. */
|
|
1947
|
+
|
|
1948
|
+
/* The browser's own parser, asked about one selector. A fragment and not the
|
|
1949
|
+
document: nothing is searched, and nothing the page holds can make the
|
|
1950
|
+
answer slow. */
|
|
1951
|
+
const selectorCompiles = (selector) => {
|
|
1952
|
+
try {
|
|
1953
|
+
document.createDocumentFragment().querySelector(selector);
|
|
1954
|
+
return true;
|
|
1955
|
+
} catch (e) {
|
|
1956
|
+
return false;
|
|
1957
|
+
}
|
|
1958
|
+
};
|
|
1959
|
+
|
|
1960
|
+
/* Which setting to name in the console: the reader has one or the other. In
|
|
1961
|
+
'hands' the zone was set on the host page and sent over, so the console line
|
|
1962
|
+
(shown in the host page's console, where the head runs) names it as such. */
|
|
1963
|
+
const zoneSource = () => (ROLE === 'hands' ? 'the host page\'s zone'
|
|
1964
|
+
: (script ? 'data-zone' : 'zone in window.annotepageConfig'));
|
|
1965
|
+
|
|
1966
|
+
let zoneJudged = null;
|
|
1967
|
+
let zoneMissingSaid = false;
|
|
1968
|
+
let zoneNoticeTimer = null;
|
|
1969
|
+
|
|
1970
|
+
/* Judged ONCE: a selector that does not parse will not start parsing, and the
|
|
1971
|
+
line that says so is said once for the copy. */
|
|
1972
|
+
const judgeZone = () => {
|
|
1973
|
+
if (zoneJudged) return zoneJudged;
|
|
1974
|
+
// In 'hands' the zone is whatever the head sent with pick:on; in 'full'/'head'
|
|
1975
|
+
// it is this page's own data-zone (00-preamble). The ternary keeps the
|
|
1976
|
+
// preamble names out of the hands build, where they do not exist.
|
|
1977
|
+
const declared = ROLE === 'hands' ? !!(handsZone && handsZone.declared) : ZONE_DECLARED;
|
|
1978
|
+
const selector = ROLE === 'hands' ? (handsZone ? handsZone.selector : '') : ZONE_SELECTOR;
|
|
1979
|
+
zoneJudged = zoneFrom(declared, selector, selectorCompiles);
|
|
1980
|
+
if (zoneJudged.declared && !zoneJudged.valid) {
|
|
1981
|
+
complain('the zone ' + JSON.stringify(zoneJudged.selector) + ' (' + zoneSource()
|
|
1982
|
+
+ ') is not a valid CSS selector list: ' + JSON.stringify(zoneJudged.broken)
|
|
1983
|
+
+ ' does not parse. No remark can be written on this page until it is '
|
|
1984
|
+
+ 'corrected; the notes already written are still shown.');
|
|
1985
|
+
}
|
|
1986
|
+
return zoneJudged;
|
|
1987
|
+
};
|
|
1988
|
+
|
|
1989
|
+
const pickable = (el) => {
|
|
1990
|
+
const verdict = pickVerdict(judgeZone(), el);
|
|
1991
|
+
return verdict === 'anywhere' || verdict === 'inside';
|
|
1992
|
+
};
|
|
1993
|
+
|
|
1994
|
+
/* The zone elements on the page NOW, and ours excluded: `*` or `body > *`
|
|
1995
|
+
would otherwise match the host, and frame the whole viewport. */
|
|
1996
|
+
const zoneElements = () => {
|
|
1997
|
+
const zone = judgeZone();
|
|
1998
|
+
if (!zone.declared || !zone.valid) return [];
|
|
1999
|
+
const found = document.querySelectorAll(zone.selector);
|
|
2000
|
+
const kept = [];
|
|
2001
|
+
for (let i = 0; i < found.length; i += 1) {
|
|
2002
|
+
if (!inTool(found[i])) kept.push(found[i]);
|
|
2003
|
+
}
|
|
2004
|
+
return kept;
|
|
2005
|
+
};
|
|
2006
|
+
|
|
2007
|
+
/* A selector that parses and matches nothing is said too, once for the copy:
|
|
2008
|
+
it is the typo (.artcle) that otherwise looks like a tool refusing every
|
|
2009
|
+
click for no reason. Asked when the mode opens and when a pick is refused,
|
|
2010
|
+
never at every frame, so a zone rendered a moment later is not reported
|
|
2011
|
+
missing at the moment it arrives. */
|
|
2012
|
+
const zoneMissing = () => {
|
|
2013
|
+
const zone = judgeZone();
|
|
2014
|
+
if (!zone.declared || !zone.valid || zoneElements().length) return false;
|
|
2015
|
+
if (!zoneMissingSaid) {
|
|
2016
|
+
zoneMissingSaid = true;
|
|
2017
|
+
complain('the zone ' + JSON.stringify(zone.selector) + ' (' + zoneSource()
|
|
2018
|
+
+ ') matches nothing on this page, so no remark can be written here. '
|
|
2019
|
+
+ 'The notes already written are still shown.');
|
|
2020
|
+
}
|
|
2021
|
+
return true;
|
|
2022
|
+
};
|
|
2023
|
+
|
|
2024
|
+
/* CAPPED, because a selector is the site's to write and `p` matches hundreds:
|
|
2025
|
+
a frame per paragraph, redrawn at every frame of a scroll, is the tool
|
|
2026
|
+
making the page slow in order to decorate it. Document order puts an
|
|
2027
|
+
ancestor before what it contains, so the frames dropped are the last ones
|
|
2028
|
+
down the page -- and picking inside them still works. */
|
|
2029
|
+
const ZONES_DRAWN = 64;
|
|
2030
|
+
|
|
2031
|
+
const drawZones = () => {
|
|
2032
|
+
empty(ui.zones);
|
|
2033
|
+
if (!mode) return;
|
|
2034
|
+
const zone = judgeZone();
|
|
2035
|
+
if (!zone.declared || !zone.valid) return;
|
|
2036
|
+
const outer = outermostZones(zoneElements(), zone.selector);
|
|
2037
|
+
for (let i = 0, drawn = 0; i < outer.length && drawn < ZONES_DRAWN; i += 1) {
|
|
2038
|
+
const r = outer[i].getBoundingClientRect();
|
|
2039
|
+
if (r.width === 0 && r.height === 0) continue;
|
|
2040
|
+
if (r.bottom < 0 || r.top > window.innerHeight) continue;
|
|
2041
|
+
const frame = create('div', 'ap-zone');
|
|
2042
|
+
place(frame, r, 4);
|
|
2043
|
+
ui.zones.appendChild(frame);
|
|
2044
|
+
drawn += 1;
|
|
2045
|
+
}
|
|
2046
|
+
};
|
|
2047
|
+
|
|
2048
|
+
/* WHY NOTHING OPENED, next to the hand that clicked. A click outside the zone
|
|
2049
|
+
that did nothing at all would be read as a broken tool; a form refused in
|
|
2050
|
+
the panel, a whole band away, would not be read at all. It goes by itself:
|
|
2051
|
+
it answers one click, and the next click is the reader's. */
|
|
2052
|
+
const sayOutsideZone = (event, label) => {
|
|
2053
|
+
const notice = ui.zoneNotice;
|
|
2054
|
+
notice.textContent = T(label);
|
|
2055
|
+
notice.style.display = 'block';
|
|
2056
|
+
const x = typeof event.clientX === 'number' ? event.clientX : window.innerWidth / 2;
|
|
2057
|
+
const y = typeof event.clientY === 'number' ? event.clientY : window.innerHeight / 2;
|
|
2058
|
+
notice.style.left = Math.max(8, Math.min(x + 12, window.innerWidth - notice.offsetWidth - 8)) + 'px';
|
|
2059
|
+
notice.style.top = Math.max(8, Math.min(y + 16, window.innerHeight - notice.offsetHeight - 8)) + 'px';
|
|
2060
|
+
if (zoneNoticeTimer) window.clearTimeout(zoneNoticeTimer);
|
|
2061
|
+
zoneNoticeTimer = window.setTimeout(hideZoneNotice, 2600);
|
|
2062
|
+
};
|
|
2063
|
+
|
|
2064
|
+
const hideZoneNotice = () => {
|
|
2065
|
+
if (zoneNoticeTimer) window.clearTimeout(zoneNoticeTimer);
|
|
2066
|
+
zoneNoticeTimer = null;
|
|
2067
|
+
if (ui) ui.zoneNotice.style.display = 'none';
|
|
2068
|
+
};
|
|
2069
|
+
|
|
2070
|
+
/* -- Showing an element (scroll into view) ------------------------------ */
|
|
2071
|
+
|
|
2072
|
+
const showElement = (note) => {
|
|
2073
|
+
let el = null;
|
|
2074
|
+
for (let i = 0; i < anchored.length; i += 1) {
|
|
2075
|
+
if (anchored[i].notes.indexOf(note) !== -1) el = anchored[i].element;
|
|
2076
|
+
}
|
|
2077
|
+
if (!el || !document.contains(el)) return 'gone';
|
|
2078
|
+
const r = el.getBoundingClientRect();
|
|
2079
|
+
if (r.width === 0 && r.height === 0) return 'hidden';
|
|
2080
|
+
// scrollIntoView moves the viewpoint, never the document: no node, no
|
|
2081
|
+
// style of the site is touched.
|
|
2082
|
+
el.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
|
2083
|
+
window.setTimeout(() => {
|
|
2084
|
+
showHighlight(el);
|
|
2085
|
+
window.setTimeout(hideHighlight, 1400);
|
|
2086
|
+
}, 350);
|
|
2087
|
+
return 'scrolled';
|
|
2088
|
+
};
|
|
2089
|
+
|
|
2090
|
+
/* -- 17. Annotation mode ------------------------------------------------- */
|
|
2091
|
+
|
|
2092
|
+
/* NOTHING IS AIMED AT WHILE A WINDOW IS OPEN. Reading a remark with the
|
|
2093
|
+
pointer resting anywhere over the page meant the outline kept jumping from
|
|
2094
|
+
paragraph to paragraph behind the window, and the label with it -- the tool
|
|
2095
|
+
proposing the next thing to annotate to somebody who is busy reading the
|
|
2096
|
+
last one. Reported as exactly that: it is distracting.
|
|
2097
|
+
|
|
2098
|
+
The aim is FROZEN, not merely hidden: `hovered` is left where it was, so
|
|
2099
|
+
closing the window puts the reader back on the element they had, rather than
|
|
2100
|
+
on whatever happens to be under a pointer that has not moved. */
|
|
2101
|
+
|
|
2102
|
+
const onHover = (event) => {
|
|
2103
|
+
/* The aim is frozen while a window is open -- a head decision. In 'hands'
|
|
2104
|
+
the window is the head's, in another document, and this page does not
|
|
2105
|
+
know it is open; it keeps its aim (a documented divergence, FRAME-DESIGN
|
|
2106
|
+
hard problem 1). The guard applies only where the pop is this scope's. */
|
|
2107
|
+
if (ROLE !== 'hands' && pop) return;
|
|
2108
|
+
/* AND NOT WHILE A REMARK IS BEING WRITTEN, for the same reason and on the
|
|
2109
|
+
same report: the outline and its label kept moving from paragraph to
|
|
2110
|
+
paragraph behind the form, so the tool was proposing the next thing to
|
|
2111
|
+
annotate to somebody in the middle of annotating this one. The element
|
|
2112
|
+
being written about stays outlined until the form closes -- which is
|
|
2113
|
+
what a reader looking away from their own sentence needs to find.
|
|
2114
|
+
|
|
2115
|
+
In 'hands' there is no form in this document (it is in the host panel):
|
|
2116
|
+
ui.form is absent, and the guard simply does not apply here. */
|
|
2117
|
+
if (ui.form && ui.form.classList.contains('ap-open')) return;
|
|
2118
|
+
const el = event.target;
|
|
2119
|
+
if (!el || el.nodeType !== 1 || inTool(el)) return;
|
|
2120
|
+
if (el === document.body || el === document.documentElement) return;
|
|
2121
|
+
/* Outside the zone the aim goes out: an outline there offers a remark
|
|
2122
|
+
the click is going to refuse. */
|
|
2123
|
+
if (!pickable(el)) {
|
|
2124
|
+
hovered = null;
|
|
2125
|
+
hideHighlight();
|
|
2126
|
+
return;
|
|
2127
|
+
}
|
|
2128
|
+
hovered = el;
|
|
2129
|
+
showHighlight(el);
|
|
2130
|
+
};
|
|
2131
|
+
|
|
2132
|
+
const onClick = (event) => {
|
|
2133
|
+
const el = event.target;
|
|
2134
|
+
// A click on the tool itself: we let the event go down into the shadow
|
|
2135
|
+
// root, where our own buttons are waiting for it.
|
|
2136
|
+
if (inTool(el)) return;
|
|
2137
|
+
// Everything else is captured: in annotation mode one points, one does
|
|
2138
|
+
// not navigate. That is what keeps a click on a link from carrying the
|
|
2139
|
+
// person away at the moment they meant to comment on it.
|
|
2140
|
+
event.preventDefault();
|
|
2141
|
+
event.stopPropagation();
|
|
2142
|
+
if (event.type !== 'click') return;
|
|
2143
|
+
|
|
2144
|
+
/* THE POP/FORM DECISION IS THE HEAD'S. In 'full' the head is this same
|
|
2145
|
+
scope, so the two rules below run right here. In 'hands' the window and
|
|
2146
|
+
the form are in the host panel, which this sealed document cannot see; so
|
|
2147
|
+
the hands do not decide -- they report the pick, and the head closes an
|
|
2148
|
+
open window, keeps a half-written form, or opens a new one (FRAME-DESIGN,
|
|
2149
|
+
hard problem 1). */
|
|
2150
|
+
if (ROLE !== 'hands') {
|
|
2151
|
+
/* A CLICK OUTSIDE THE WINDOW CLOSES IT, rather than opening a form on
|
|
2152
|
+
whatever was clicked. Same reason as the frozen aim, and the same
|
|
2153
|
+
rule Escape follows: the window is the thing on top, so a click not
|
|
2154
|
+
in it dismisses it -- one gesture, and the page is not annotated by
|
|
2155
|
+
the gesture that puts the remark away. The next click aims and opens
|
|
2156
|
+
a form as usual: nothing is trapped. */
|
|
2157
|
+
if (pop) {
|
|
2158
|
+
/* The click says where the pointer is, which the frozen aim does
|
|
2159
|
+
not know: taking it here means the outline comes back UNDER THE
|
|
2160
|
+
HAND rather than on the element it was left on three scrolls
|
|
2161
|
+
ago. */
|
|
2162
|
+
if (el && el.nodeType === 1 && el !== document.body
|
|
2163
|
+
&& el !== document.documentElement) hovered = pickable(el) ? el : null;
|
|
2164
|
+
closePop();
|
|
2165
|
+
return;
|
|
2166
|
+
}
|
|
2167
|
+
/* AND A CLICK ELSEWHERE DOES NOT THROW A REMARK AWAY. openForm()
|
|
2168
|
+
rebuilds the form from nothing, so aiming at another element while
|
|
2169
|
+
something was written DISCARDED it -- silently, on a click the reader
|
|
2170
|
+
may not have meant. Nothing typed: aiming again costs nothing.
|
|
2171
|
+
Something typed: the form stays. Escape and Cancel are the two ways
|
|
2172
|
+
out, and both are on screen. */
|
|
2173
|
+
if (ui.form.classList.contains('ap-open')) {
|
|
2174
|
+
const written = ui.form.querySelector('.ap-area');
|
|
2175
|
+
if (written && written.value.trim() !== '') return;
|
|
2176
|
+
}
|
|
2177
|
+
}
|
|
2178
|
+
if (!el || el.nodeType !== 1) return;
|
|
2179
|
+
if (el === document.body || el === document.documentElement) return;
|
|
2180
|
+
/* OUTSIDE THE ZONE, NOTHING IS CREATED, and a form already open stays as
|
|
2181
|
+
it is: it is about an element inside. The click was still captured
|
|
2182
|
+
above, so a link out there does not carry the reader away either. */
|
|
2183
|
+
if (!pickable(el)) {
|
|
2184
|
+
const nowhere = pickVerdict(judgeZone(), el) === 'nowhere' || zoneMissing();
|
|
2185
|
+
sayOutsideZone(event, nowhere ? 'zone.none' : 'zone.outside');
|
|
2186
|
+
return;
|
|
2187
|
+
}
|
|
2188
|
+
hideZoneNotice();
|
|
2189
|
+
if (ROLE === 'hands') {
|
|
2190
|
+
/* The element lives in this sealed document; the head cannot reach it,
|
|
2191
|
+
so the hands send its anchor -- the very fields openForm would have
|
|
2192
|
+
computed on save (cssPath/fingerprintOf/excerptOf). The hands also
|
|
2193
|
+
keep the local aim on it, for the context the reader needs while the
|
|
2194
|
+
form is in the other document. */
|
|
2195
|
+
hovered = el;
|
|
2196
|
+
showHighlight(el);
|
|
2197
|
+
bridgeSend('picked', {
|
|
2198
|
+
selector: cssPath(el),
|
|
2199
|
+
fingerprint: fingerprintOf(el),
|
|
2200
|
+
excerpt: excerptOf(el)
|
|
2201
|
+
});
|
|
2202
|
+
return;
|
|
2203
|
+
}
|
|
2204
|
+
openForm(el);
|
|
2205
|
+
};
|
|
2206
|
+
|
|
2207
|
+
const onKey = (event) => {
|
|
2208
|
+
if (event.key !== 'Escape') return;
|
|
2209
|
+
/* In 'hands' the window, the form and the mode are all the head's: Escape
|
|
2210
|
+
pressed over the sealed page is relayed, and the head runs exactly the
|
|
2211
|
+
cascade below in its own scope. */
|
|
2212
|
+
if (ROLE === 'hands') {
|
|
2213
|
+
bridgeSend('escape');
|
|
2214
|
+
return;
|
|
2215
|
+
}
|
|
2216
|
+
/* The window first: it is the thing on top, and Escape closes what is on
|
|
2217
|
+
top. Leaving annotation mode from under an open window would take the
|
|
2218
|
+
page away and leave the window floating over it. */
|
|
2219
|
+
if (pop) {
|
|
2220
|
+
closePop();
|
|
2221
|
+
return;
|
|
2222
|
+
}
|
|
2223
|
+
if (ui.form.classList.contains('ap-open')) {
|
|
2224
|
+
closeForm();
|
|
2225
|
+
return;
|
|
2226
|
+
}
|
|
2227
|
+
leaveMode();
|
|
2228
|
+
};
|
|
2229
|
+
|
|
2230
|
+
/* THE HANDS ENTER THE MODE: the listeners, the observer and the first draw --
|
|
2231
|
+
the half of the old enterMode that touches the page. In 'full' the head's
|
|
2232
|
+
enterMode calls this straight after raising the panel; in 'hands' the
|
|
2233
|
+
`pick:on` handler calls it when the head says so. It never touches the button
|
|
2234
|
+
or the panel, and it never asks the server: those are the head's.
|
|
2235
|
+
|
|
2236
|
+
THE PAGE REDRAWS ITSELF, AND THE BADGES MUST NOT DIE OF IT. A click on the
|
|
2237
|
+
site's own button can replace a whole block: the node we remembered is then
|
|
2238
|
+
detached, it measures 0x0, and the badge simply stops being drawn. The
|
|
2239
|
+
observer's callback raises a flag AND NOTHING ELSE; all the work happens in
|
|
2240
|
+
the animation frame of refreshPositions, at most once per frame, so a page
|
|
2241
|
+
that mutates in a loop does not pay a full re-anchoring per mutation record.
|
|
2242
|
+
It is observed on document.body, childList and subtree, and never crosses
|
|
2243
|
+
into the shadow root -- the tool cannot see, or answer, its own drawing. */
|
|
2244
|
+
const handsEnter = () => {
|
|
2245
|
+
mode = true;
|
|
2246
|
+
document.addEventListener('pointerover', onHover, true);
|
|
2247
|
+
document.addEventListener('pointerdown', onClick, true);
|
|
2248
|
+
document.addEventListener('click', onClick, true);
|
|
2249
|
+
document.addEventListener('auxclick', onClick, true);
|
|
2250
|
+
document.addEventListener('keydown', onKey, true);
|
|
2251
|
+
window.addEventListener('scroll', refreshPositions, true);
|
|
2252
|
+
window.addEventListener('resize', refreshPositions);
|
|
2253
|
+
// A carousel, a dropdown menu, an image loaded late move the elements
|
|
2254
|
+
// without emitting either scroll or resize.
|
|
2255
|
+
timer = window.setInterval(refreshPositions, 500);
|
|
2256
|
+
|
|
2257
|
+
if (typeof MutationObserver === 'function') {
|
|
2258
|
+
observer = new MutationObserver(() => {
|
|
2259
|
+
domDirty = true;
|
|
2260
|
+
});
|
|
2261
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
2262
|
+
}
|
|
2263
|
+
domDirty = false;
|
|
2264
|
+
zoneMissing();
|
|
2265
|
+
|
|
2266
|
+
// The markers for what we ALREADY know, straight away; in 'full' the server
|
|
2267
|
+
// is asked next (the head's reload) and corrects anything new, and in
|
|
2268
|
+
// 'hands' the head sends the list over the bridge. Waiting for either to
|
|
2269
|
+
// show what is already on screen would suggest an empty page.
|
|
2270
|
+
drawMarkers();
|
|
2271
|
+
};
|
|
2272
|
+
|
|
2273
|
+
/* THE HANDS LEAVE THE MODE: the exact undoing of handsEnter, and nothing of the
|
|
2274
|
+
head's. */
|
|
2275
|
+
const handsLeave = () => {
|
|
2276
|
+
mode = false;
|
|
2277
|
+
hideHighlight();
|
|
2278
|
+
hovered = null;
|
|
2279
|
+
if (ui.markers) empty(ui.markers);
|
|
2280
|
+
if (ui.zones) empty(ui.zones);
|
|
2281
|
+
hideZoneNotice();
|
|
2282
|
+
|
|
2283
|
+
document.removeEventListener('pointerover', onHover, true);
|
|
2284
|
+
document.removeEventListener('pointerdown', onClick, true);
|
|
2285
|
+
document.removeEventListener('click', onClick, true);
|
|
2286
|
+
document.removeEventListener('auxclick', onClick, true);
|
|
2287
|
+
document.removeEventListener('keydown', onKey, true);
|
|
2288
|
+
window.removeEventListener('scroll', refreshPositions, true);
|
|
2289
|
+
window.removeEventListener('resize', refreshPositions);
|
|
2290
|
+
// Outside annotation mode the tool watches nothing: the site is the
|
|
2291
|
+
// site's again, and it pays nothing for us.
|
|
2292
|
+
if (observer) {
|
|
2293
|
+
observer.disconnect();
|
|
2294
|
+
observer = null;
|
|
2295
|
+
}
|
|
2296
|
+
domDirty = false;
|
|
2297
|
+
if (timer) {
|
|
2298
|
+
window.clearInterval(timer);
|
|
2299
|
+
timer = null;
|
|
2300
|
+
}
|
|
2301
|
+
};
|
|
2302
|
+
|
|
2303
|
+
/* ==== 59-hands-boot.js ==== */
|
|
2304
|
+
|
|
2305
|
+
/* ============================================================================
|
|
2306
|
+
59-hands-boot.js -- THE HANDS' BOOT (frame build only).
|
|
2307
|
+
|
|
2308
|
+
Loaded inside the sandboxed iframe. It builds the overlay in this document,
|
|
2309
|
+
opens the one bridge to the parent (the head), and tells the head it is here.
|
|
2310
|
+
It asks no server and reads no key: a sealed iframe can do neither, and it is
|
|
2311
|
+
the head, in the host page, that holds them.
|
|
2312
|
+
============================================================================ */
|
|
2313
|
+
|
|
2314
|
+
/* What the head can ask of the hands. Registered once; dormant until the head
|
|
2315
|
+
speaks. Each handler is a page operation the hands already know how to do --
|
|
2316
|
+
the same functions the full tool calls locally. */
|
|
2317
|
+
const wireHands = () => {
|
|
2318
|
+
/* Turn pointing ON, with the zone the host page declared (the hands have no
|
|
2319
|
+
config of their own; the zone travels with the command). The judged zone
|
|
2320
|
+
is reset so it is re-read against what just arrived. */
|
|
2321
|
+
onBridge('pick:on', (zone) => {
|
|
2322
|
+
handsZone = zone || null;
|
|
2323
|
+
zoneJudged = null;
|
|
2324
|
+
zoneMissingSaid = false;
|
|
2325
|
+
handsEnter();
|
|
2326
|
+
});
|
|
2327
|
+
|
|
2328
|
+
onBridge('pick:off', () => handsLeave());
|
|
2329
|
+
|
|
2330
|
+
/* The note dataset: the hands hold it as their `notes`, anchor it to the
|
|
2331
|
+
live page, draw the badges, and report which ones they could not place so
|
|
2332
|
+
the head's panel can list them (reportAnchored). */
|
|
2333
|
+
onBridge('markers', (data) => {
|
|
2334
|
+
notes = (data && data.items) || [];
|
|
2335
|
+
anchor();
|
|
2336
|
+
drawMarkers();
|
|
2337
|
+
reportAnchored();
|
|
2338
|
+
});
|
|
2339
|
+
|
|
2340
|
+
/* Scroll an element into view and flash it -- the panel row's "find on page"
|
|
2341
|
+
in the full tool, here driven from the head. */
|
|
2342
|
+
onBridge('show', (data) => {
|
|
2343
|
+
const id = data && data.id;
|
|
2344
|
+
let found = null;
|
|
2345
|
+
for (let i = 0; i < notes.length; i += 1) {
|
|
2346
|
+
if (notes[i].id === id) found = notes[i];
|
|
2347
|
+
}
|
|
2348
|
+
if (found) showElement(found);
|
|
2349
|
+
});
|
|
2350
|
+
};
|
|
2351
|
+
|
|
2352
|
+
const bootHands = () => {
|
|
2353
|
+
buildHost();
|
|
2354
|
+
buildUi();
|
|
2355
|
+
wireHands();
|
|
2356
|
+
/* The parent is the only window that can reach a sealed iframe; the hands
|
|
2357
|
+
pin to it (bridgeConnect) and also accept it as it first speaks
|
|
2358
|
+
(bridgeStart with no expected peer, 55-bridge). */
|
|
2359
|
+
bridgeConnect(window.parent === window ? null : window.parent);
|
|
2360
|
+
bridgeStart();
|
|
2361
|
+
/* We are up. A reload of the iframe runs this again; the head's `ready`
|
|
2362
|
+
handler catches the new hands up with pick:on + the markers. */
|
|
2363
|
+
bridgeSend('ready');
|
|
2364
|
+
};
|
|
2365
|
+
|
|
2366
|
+
if (document.body) {
|
|
2367
|
+
bootHands();
|
|
2368
|
+
} else {
|
|
2369
|
+
document.addEventListener('DOMContentLoaded', bootHands);
|
|
2370
|
+
}
|
|
2371
|
+
}());
|