webview-preview 1.1.2 → 1.2.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.
@@ -0,0 +1,52 @@
1
+ import { pageDom } from "#src/page/annotate/dom.mjs";
2
+ import { ICONS } from "#src/page/annotate/icons.mjs";
3
+ import { pageKeys } from "#src/page/annotate/keys.mjs";
4
+ import { MARKUP } from "#src/page/annotate/markup.mjs";
5
+ import { annotatePanel } from "#src/page/annotate/panel.mjs";
6
+ import { pageReact } from "#src/page/annotate/react.mjs";
7
+ import { pageSelectors } from "#src/page/annotate/selector.mjs";
8
+ import { STYLES } from "#src/page/annotate/styles.mjs";
9
+ import { pageVue } from "#src/page/annotate/vue.mjs";
10
+
11
+ export { formatAnnotation } from "#src/page/annotate/format.mjs";
12
+
13
+ export const ANNOTATE_KEY = "__webviewPreviewAnnotate";
14
+ export const ANNOTATE_POLL_MS = 250;
15
+ export const ANNOTATE_CLEANUP = `window.${ANNOTATE_KEY}?.cleanup?.()`;
16
+
17
+ export const annotateStart = (name, keys = null, privateSelectors = [], keepOpen = false) => `(${annotatePanel})(${JSON.stringify({ key: ANNOTATE_KEY, name, markup: MARKUP, styles: STYLES, icons: ICONS, keepOpen })}, {
18
+ keys: (${pageKeys})(${JSON.stringify(keys)}),
19
+ selectors: (${pageSelectors})(${JSON.stringify(privateSelectors)}),
20
+ react: (${pageReact})(),
21
+ vue: (${pageVue})(),
22
+ dom: (${pageDom})()
23
+ })`;
24
+
25
+ export const ANNOTATE_CHECK = `(() => {
26
+ const state = window.${ANNOTATE_KEY};
27
+ if (!state) return "missing";
28
+ if (state.status === "open") {
29
+ const draft = state.version !== state.sentVersion ? (state.sentVersion = state.version, state.draft()) : null;
30
+ const captures = state.captures.splice(0);
31
+ if (captures.length) state.capturing = captures;
32
+ const url = location.href !== state.sentUrl ? (state.sentUrl = location.href) : null;
33
+ return draft || captures.length || url ? JSON.stringify({ status: "open", draft, captures, url }) : null;
34
+ }
35
+ return JSON.stringify({ status: state.status, result: state.result, keys: state.keys });
36
+ })()`;
37
+
38
+ export const annotateRestore = draft => `window.${ANNOTATE_KEY}Draft = ${JSON.stringify(draft)};`;
39
+
40
+ export const annotateStep = (name, keys, privateSelectors = [], keepOpen = false) => ({
41
+ kind: "annotate",
42
+ value: name,
43
+ start: annotateStart(name, keys, privateSelectors, keepOpen),
44
+ resume: `window.${ANNOTATE_KEY}?.resume?.()`,
45
+ check: ANNOTATE_CHECK,
46
+ hide: `window.${ANNOTATE_KEY}?.setHidden?.(true)`,
47
+ show: `window.${ANNOTATE_KEY}?.setHidden?.(false)`,
48
+ cleanup: ANNOTATE_CLEANUP,
49
+ dispose: `window.${ANNOTATE_KEY}?.dispose?.()`,
50
+ restoreKey: `${ANNOTATE_KEY}Draft`,
51
+ pollMs: ANNOTATE_POLL_MS
52
+ });
@@ -0,0 +1,33 @@
1
+ export function pageKeys(saved) {
2
+ const DEFAULT_KEYS = { pick: "p", notes: "n", freeze: "f", toggle: "t", parent: "ArrowUp", child: "ArrowDown", done: "Control+Enter" }
3
+ const KEY_ACTIONS = [
4
+ ["pick", "Pick elements"],
5
+ ["notes", "Show / hide notes"],
6
+ ["freeze", "Freeze"],
7
+ ["toggle", "Show / hide tools"],
8
+ ["parent", "Outline the parent"],
9
+ ["child", "Back to the child"],
10
+ ["done", "Done (Send with --keep-open)"]
11
+ ];
12
+ const bindings = { ...DEFAULT_KEYS, ...(saved ?? {}) }
13
+
14
+ const KEY_NAMES = { Control: "Ctrl", ArrowUp: "↑", ArrowDown: "↓", ArrowLeft: "←", ArrowRight: "→", " ": "Space" }
15
+ const showKey = combo => combo.split("+").map(part => KEY_NAMES[part] ?? (part.length === 1 ? part.toUpperCase() : part)).join("+");
16
+ const comboOf = event => {
17
+ if (["Control", "Alt", "Shift", "Meta"].includes(event.key)) return null;
18
+ const parts = [];
19
+ if (event.ctrlKey) parts.push("Control");
20
+ if (event.altKey) parts.push("Alt");
21
+ const code = event.code ?? "";
22
+ const key = /^Key[A-Z]$/.test(code) ? code.slice(3).toLowerCase()
23
+ : /^Digit\d$/.test(code) ? code.slice(5)
24
+ : event.key.length === 1 ? event.key.toLowerCase() : event.key;
25
+ if (event.shiftKey && key.length > 1) parts.push("Shift");
26
+ if (event.metaKey) parts.push("Meta");
27
+ parts.push(key);
28
+ return parts.join("+");
29
+ }
30
+
31
+ const actionFor = combo => Object.keys(bindings).find(action => bindings[action] === combo) ?? null;
32
+ return { DEFAULT_KEYS, KEY_ACTIONS, bindings, showKey, comboOf, actionFor }
33
+ }
@@ -0,0 +1,38 @@
1
+ import { ICONS } from "#src/page/annotate/icons.mjs";
2
+
3
+ export const MARKUP = `
4
+ <div class="layer">
5
+ <div class="masks"></div>
6
+ <div class="picks"></div>
7
+ <div class="outline"><div class="outline-label"></div></div>
8
+ </div>
9
+ <div class="dock" role="toolbar" aria-label="webview-preview annotate">
10
+ <div class="card toolbar">
11
+ <div class="grip" aria-hidden="true">${ICONS.grip}</div>
12
+ <button type="button" class="tool toggle" data-action="toggle"></button>
13
+ <div class="collapse"><div><div class="tools">
14
+ <button type="button" class="tool pick" data-action="pick" data-tip="Pick elements">${ICONS.pick}</button>
15
+ <button type="button" class="tool notes-button" data-action="notes" data-tip="Notes">${ICONS.notes}<span class="badge"></span></button>
16
+ <button type="button" class="tool freeze" data-action="freeze" data-tip="Freeze">${ICONS.freeze}<span class="badge freeze-badge"></span></button>
17
+ <button type="button" class="tool keys" data-tip="Key bindings">${ICONS.keys}</button>
18
+ <div class="divider"></div>
19
+ <button type="button" class="tool accent send" data-action="done" data-tip="Send the notes — the window stays open" hidden>${ICONS.send}</button>
20
+ <button type="button" class="tool accent done" data-action="done" data-tip="Done">${ICONS.done}</button>
21
+ <button type="button" class="tool cancel" data-tip="Cancel">${ICONS.cancel}</button>
22
+ </div></div></div>
23
+ </div>
24
+ <div class="card sheet notes-sheet" hidden>
25
+ <div class="sheet-head"><b>Notes</b><span class="run-name"></span></div>
26
+ <p class="privacy"></p>
27
+ <ol class="notes"></ol>
28
+ <label>General note<textarea class="general" rows="2" placeholder="About the whole screen"></textarea></label>
29
+ <p class="hint"></p>
30
+ </div>
31
+ <div class="card sheet keys-sheet" hidden>
32
+ <div class="sheet-head"><b>Key bindings</b><span>click, then press a key</span></div>
33
+ <div class="rows"></div>
34
+ <div class="actions"><button type="button" class="button reset-keys">Reset</button></div>
35
+ </div>
36
+ </div>
37
+ <div class="tip"></div>
38
+ `;