@phnx-labs/artifacts-cli 0.9.13 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -0
- package/README.md +7 -9
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +34 -190
- package/dist/cli.js.map +1 -1
- package/dist/commands/auth.d.ts +3 -1
- package/dist/commands/auth.js +17 -18
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/comments.js +2 -2
- package/dist/commands/comments.js.map +1 -1
- package/dist/commands/new.js +3 -3
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/share.d.ts +58 -111
- package/dist/commands/share.js +314 -638
- package/dist/commands/share.js.map +1 -1
- package/dist/lib/collab.d.ts +3 -3
- package/dist/lib/collab.js +183 -13
- package/dist/lib/collab.js.map +1 -1
- package/dist/lib/components.js +0 -1
- package/dist/lib/components.js.map +1 -1
- package/dist/lib/config.d.ts +0 -17
- package/dist/lib/config.js.map +1 -1
- package/dist/lib/embedded-html.d.ts +1 -1
- package/dist/lib/embedded-html.js +0 -15
- package/dist/lib/embedded-html.js.map +1 -1
- package/dist/lib/freshness.d.ts +2 -6
- package/dist/lib/freshness.js +4 -33
- package/dist/lib/freshness.js.map +1 -1
- package/dist/lib/header-actions.d.ts +10 -37
- package/dist/lib/header-actions.js +19 -94
- package/dist/lib/header-actions.js.map +1 -1
- package/dist/lib/metadata-menu.d.ts +10 -33
- package/dist/lib/metadata-menu.js +12 -51
- package/dist/lib/metadata-menu.js.map +1 -1
- package/dist/lib/reader-anchors.d.ts +3 -3
- package/dist/lib/reader-anchors.js +7 -4
- package/dist/lib/reader-anchors.js.map +1 -1
- package/dist/lib/render.d.ts +2 -19
- package/dist/lib/render.js +37 -321
- package/dist/lib/render.js.map +1 -1
- package/dist/lib/section-collapse.d.ts +1 -2
- package/dist/lib/section-collapse.js +1 -2
- package/dist/lib/section-collapse.js.map +1 -1
- package/dist/lib/selection-toolbar.d.ts +9 -0
- package/dist/lib/selection-toolbar.js +49 -0
- package/dist/lib/selection-toolbar.js.map +1 -0
- package/dist/lib/share/backend.d.ts +8 -75
- package/dist/lib/share/backend.js +11 -123
- package/dist/lib/share/backend.js.map +1 -1
- package/dist/lib/share/config.d.ts +0 -79
- package/dist/lib/share/config.js +3 -175
- package/dist/lib/share/config.js.map +1 -1
- package/dist/lib/share/delete.d.ts +3 -14
- package/dist/lib/share/delete.js +8 -12
- package/dist/lib/share/delete.js.map +1 -1
- package/dist/lib/share/http-error.d.ts +12 -0
- package/dist/lib/share/http-error.js +32 -0
- package/dist/lib/share/http-error.js.map +1 -1
- package/dist/lib/share/media.d.ts +1 -6
- package/dist/lib/share/media.js +9 -17
- package/dist/lib/share/media.js.map +1 -1
- package/dist/lib/share/og.d.ts +0 -3
- package/dist/lib/share/og.js +2 -4
- package/dist/lib/share/og.js.map +1 -1
- package/dist/lib/share/people.d.ts +56 -0
- package/dist/lib/share/people.js +139 -0
- package/dist/lib/share/people.js.map +1 -0
- package/dist/lib/share/provision.d.ts +7 -120
- package/dist/lib/share/provision.js +30 -290
- package/dist/lib/share/provision.js.map +1 -1
- package/dist/lib/share/publish.d.ts +21 -63
- package/dist/lib/share/publish.js +44 -131
- package/dist/lib/share/publish.js.map +1 -1
- package/dist/lib/share/visibility.d.ts +13 -36
- package/dist/lib/share/visibility.js +8 -35
- package/dist/lib/share/visibility.js.map +1 -1
- package/dist/lib/share/worker-media-template.js +1 -1
- package/dist/lib/share/worker-people-template.d.ts +1 -0
- package/dist/lib/share/worker-people-template.js +491 -0
- package/dist/lib/share/worker-people-template.js.map +1 -0
- package/dist/lib/share/worker-publish-template.d.ts +1 -1
- package/dist/lib/share/worker-publish-template.js +5 -0
- package/dist/lib/share/worker-publish-template.js.map +1 -1
- package/dist/lib/share/worker-template.d.ts +2 -14
- package/dist/lib/share/worker-template.js +303 -52
- package/dist/lib/share/worker-template.js.map +1 -1
- package/dist/lib/templates.d.ts +1 -2
- package/dist/lib/templates.js +1 -19
- package/dist/lib/templates.js.map +1 -1
- package/dist/lib/validate.js +1 -29
- package/dist/lib/validate.js.map +1 -1
- package/package.json +1 -4
- package/dist/commands/answers.d.ts +0 -6
- package/dist/commands/answers.js +0 -91
- package/dist/commands/answers.js.map +0 -1
- package/dist/commands/favorite.d.ts +0 -9
- package/dist/commands/favorite.js +0 -59
- package/dist/commands/favorite.js.map +0 -1
- package/dist/commands/history.d.ts +0 -4
- package/dist/commands/history.js +0 -29
- package/dist/commands/history.js.map +0 -1
- package/dist/commands/notes.d.ts +0 -5
- package/dist/commands/notes.js +0 -28
- package/dist/commands/notes.js.map +0 -1
- package/dist/lib/browser-detect.d.ts +0 -28
- package/dist/lib/browser-detect.js +0 -126
- package/dist/lib/browser-detect.js.map +0 -1
- package/dist/lib/favorites.d.ts +0 -73
- package/dist/lib/favorites.js +0 -180
- package/dist/lib/favorites.js.map +0 -1
- package/dist/lib/github.d.ts +0 -14
- package/dist/lib/github.js +0 -36
- package/dist/lib/github.js.map +0 -1
- package/dist/lib/highlights.d.ts +0 -11
- package/dist/lib/highlights.js +0 -116
- package/dist/lib/highlights.js.map +0 -1
- package/dist/lib/link-previews.d.ts +0 -67
- package/dist/lib/link-previews.js +0 -427
- package/dist/lib/link-previews.js.map +0 -1
- package/dist/lib/notes.d.ts +0 -22
- package/dist/lib/notes.js +0 -22
- package/dist/lib/notes.js.map +0 -1
- package/dist/lib/pdf.d.ts +0 -13
- package/dist/lib/pdf.js +0 -66
- package/dist/lib/pdf.js.map +0 -1
- package/dist/lib/revisions.d.ts +0 -102
- package/dist/lib/revisions.js +0 -445
- package/dist/lib/revisions.js.map +0 -1
- package/dist/lib/share/analytics.d.ts +0 -13
- package/dist/lib/share/analytics.js +0 -46
- package/dist/lib/share/analytics.js.map +0 -1
- package/dist/lib/share/capture.d.ts +0 -31
- package/dist/lib/share/capture.js +0 -175
- package/dist/lib/share/capture.js.map +0 -1
- package/dist/lib/tokens.d.ts +0 -12
- package/dist/lib/tokens.js +0 -28
- package/dist/lib/tokens.js.map +0 -1
- package/dist/lib/worksheet.d.ts +0 -94
- package/dist/lib/worksheet.js +0 -394
- package/dist/lib/worksheet.js.map +0 -1
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Find an installed Chromium-family browser to drive headlessly.
|
|
3
|
-
*
|
|
4
|
-
* Used by the OG cover capture (`lib/share/capture.ts`), which shells out to
|
|
5
|
-
* `--headless=new --screenshot`. This is a path table plus one Linux-specific
|
|
6
|
-
* fix-up, not a browser driver — nothing here launches or talks to a browser.
|
|
7
|
-
*/
|
|
8
|
-
export type BrowserType = 'chrome' | 'chromium' | 'brave' | 'edge' | 'comet';
|
|
9
|
-
/**
|
|
10
|
-
* On Debian/Ubuntu the canonical launchers under `/usr/bin` (`brave-browser`,
|
|
11
|
-
* `google-chrome`, `chromium`) are not the browser ELF — they are `#!/bin/bash`
|
|
12
|
-
* wrapper scripts that run the real binary as a NON-exec child while rewiring
|
|
13
|
-
* stdio. A screenshot run through the wrapper reports the wrapper's exit rather
|
|
14
|
-
* than the browser's, so follow it to the ELF it invokes: the wrapper sets
|
|
15
|
-
* `HERE="dirname(readlink -f "$0")"` and runs `"$HERE/<name>" "$@"`.
|
|
16
|
-
*
|
|
17
|
-
* Returns the original path untouched when it is already an ELF, when it is not
|
|
18
|
-
* a resolvable wrapper, or on any non-Linux platform.
|
|
19
|
-
*/
|
|
20
|
-
export declare function resolveBrowserBinary(binaryPath: string, platform?: NodeJS.Platform): string;
|
|
21
|
-
/**
|
|
22
|
-
* Walk the per-platform priority list and return the first browser actually
|
|
23
|
-
* installed on disk, or null when none are present.
|
|
24
|
-
*/
|
|
25
|
-
export declare function findFirstInstalledBrowser(platform?: NodeJS.Platform): {
|
|
26
|
-
browserType: BrowserType;
|
|
27
|
-
binary: string;
|
|
28
|
-
} | null;
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Find an installed Chromium-family browser to drive headlessly.
|
|
3
|
-
*
|
|
4
|
-
* Used by the OG cover capture (`lib/share/capture.ts`), which shells out to
|
|
5
|
-
* `--headless=new --screenshot`. This is a path table plus one Linux-specific
|
|
6
|
-
* fix-up, not a browser driver — nothing here launches or talks to a browser.
|
|
7
|
-
*/
|
|
8
|
-
import fs from 'node:fs';
|
|
9
|
-
import os from 'node:os';
|
|
10
|
-
import path from 'node:path';
|
|
11
|
-
const WIN_PROGRAMFILES = process.env.PROGRAMFILES || 'C:\\Program Files';
|
|
12
|
-
const WIN_PROGRAMFILES_X86 = process.env['PROGRAMFILES(X86)'] || 'C:\\Program Files (x86)';
|
|
13
|
-
const WIN_LOCALAPPDATA = process.env.LOCALAPPDATA || `${os.homedir()}\\AppData\\Local`;
|
|
14
|
-
const BROWSER_PATHS = {
|
|
15
|
-
darwin: {
|
|
16
|
-
chrome: [
|
|
17
|
-
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
18
|
-
'/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
|
|
19
|
-
],
|
|
20
|
-
chromium: ['/Applications/Chromium.app/Contents/MacOS/Chromium'],
|
|
21
|
-
brave: ['/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'],
|
|
22
|
-
edge: ['/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge'],
|
|
23
|
-
comet: ['/Applications/Comet.app/Contents/MacOS/Comet'],
|
|
24
|
-
},
|
|
25
|
-
linux: {
|
|
26
|
-
chrome: ['/usr/bin/google-chrome', '/usr/bin/google-chrome-stable'],
|
|
27
|
-
chromium: ['/usr/bin/chromium', '/usr/bin/chromium-browser', '/snap/bin/chromium'],
|
|
28
|
-
brave: ['/usr/bin/brave-browser', '/usr/bin/brave'],
|
|
29
|
-
edge: ['/usr/bin/microsoft-edge'],
|
|
30
|
-
},
|
|
31
|
-
win32: {
|
|
32
|
-
chrome: [
|
|
33
|
-
`${WIN_PROGRAMFILES}\\Google\\Chrome\\Application\\chrome.exe`,
|
|
34
|
-
`${WIN_PROGRAMFILES_X86}\\Google\\Chrome\\Application\\chrome.exe`,
|
|
35
|
-
`${WIN_LOCALAPPDATA}\\Google\\Chrome\\Application\\chrome.exe`,
|
|
36
|
-
],
|
|
37
|
-
chromium: [`${WIN_LOCALAPPDATA}\\Chromium\\Application\\chrome.exe`],
|
|
38
|
-
brave: [
|
|
39
|
-
`${WIN_PROGRAMFILES}\\BraveSoftware\\Brave-Browser\\Application\\brave.exe`,
|
|
40
|
-
`${WIN_PROGRAMFILES_X86}\\BraveSoftware\\Brave-Browser\\Application\\brave.exe`,
|
|
41
|
-
`${WIN_LOCALAPPDATA}\\BraveSoftware\\Brave-Browser\\Application\\brave.exe`,
|
|
42
|
-
],
|
|
43
|
-
edge: [
|
|
44
|
-
`${WIN_PROGRAMFILES}\\Microsoft\\Edge\\Application\\msedge.exe`,
|
|
45
|
-
`${WIN_PROGRAMFILES_X86}\\Microsoft\\Edge\\Application\\msedge.exe`,
|
|
46
|
-
`${WIN_LOCALAPPDATA}\\Microsoft\\Edge\\Application\\msedge.exe`,
|
|
47
|
-
],
|
|
48
|
-
comet: [
|
|
49
|
-
`${WIN_PROGRAMFILES}\\Perplexity\\Comet\\Application\\comet.exe`,
|
|
50
|
-
`${WIN_LOCALAPPDATA}\\Perplexity\\Comet\\Application\\comet.exe`,
|
|
51
|
-
],
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
const DEFAULT_BROWSER_PRIORITY = {
|
|
55
|
-
darwin: ['chrome', 'brave', 'edge', 'chromium', 'comet'],
|
|
56
|
-
linux: ['chrome', 'chromium', 'brave', 'edge'],
|
|
57
|
-
win32: ['edge', 'chrome', 'brave', 'comet'],
|
|
58
|
-
};
|
|
59
|
-
function readsAsShebangScript(binaryPath) {
|
|
60
|
-
let fd;
|
|
61
|
-
try {
|
|
62
|
-
fd = fs.openSync(binaryPath, 'r');
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
try {
|
|
68
|
-
const head = Buffer.alloc(2);
|
|
69
|
-
fs.readSync(fd, head, 0, 2, 0);
|
|
70
|
-
// ELF binaries start with 0x7f 'E'; shebang scripts with '#!'.
|
|
71
|
-
return head[0] === 0x23 && head[1] === 0x21;
|
|
72
|
-
}
|
|
73
|
-
finally {
|
|
74
|
-
fs.closeSync(fd);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* On Debian/Ubuntu the canonical launchers under `/usr/bin` (`brave-browser`,
|
|
79
|
-
* `google-chrome`, `chromium`) are not the browser ELF — they are `#!/bin/bash`
|
|
80
|
-
* wrapper scripts that run the real binary as a NON-exec child while rewiring
|
|
81
|
-
* stdio. A screenshot run through the wrapper reports the wrapper's exit rather
|
|
82
|
-
* than the browser's, so follow it to the ELF it invokes: the wrapper sets
|
|
83
|
-
* `HERE="dirname(readlink -f "$0")"` and runs `"$HERE/<name>" "$@"`.
|
|
84
|
-
*
|
|
85
|
-
* Returns the original path untouched when it is already an ELF, when it is not
|
|
86
|
-
* a resolvable wrapper, or on any non-Linux platform.
|
|
87
|
-
*/
|
|
88
|
-
export function resolveBrowserBinary(binaryPath, platform = os.platform()) {
|
|
89
|
-
if (platform !== 'linux')
|
|
90
|
-
return binaryPath;
|
|
91
|
-
if (!readsAsShebangScript(binaryPath))
|
|
92
|
-
return binaryPath;
|
|
93
|
-
let script;
|
|
94
|
-
let realScriptPath;
|
|
95
|
-
try {
|
|
96
|
-
realScriptPath = fs.realpathSync(binaryPath);
|
|
97
|
-
script = fs.readFileSync(realScriptPath, 'utf8');
|
|
98
|
-
}
|
|
99
|
-
catch {
|
|
100
|
-
return binaryPath;
|
|
101
|
-
}
|
|
102
|
-
const match = /"\$HERE\/([A-Za-z0-9._-]+)"\s+"\$@"/.exec(script);
|
|
103
|
-
if (!match)
|
|
104
|
-
return binaryPath;
|
|
105
|
-
const realBinary = path.join(path.dirname(realScriptPath), match[1]);
|
|
106
|
-
return fs.existsSync(realBinary) ? realBinary : binaryPath;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Walk the per-platform priority list and return the first browser actually
|
|
110
|
-
* installed on disk, or null when none are present.
|
|
111
|
-
*/
|
|
112
|
-
export function findFirstInstalledBrowser(platform = os.platform()) {
|
|
113
|
-
const priority = DEFAULT_BROWSER_PRIORITY[platform];
|
|
114
|
-
const platformPaths = BROWSER_PATHS[platform];
|
|
115
|
-
if (!priority || !platformPaths)
|
|
116
|
-
return null;
|
|
117
|
-
for (const browserType of priority) {
|
|
118
|
-
for (const candidate of platformPaths[browserType] ?? []) {
|
|
119
|
-
if (fs.existsSync(candidate)) {
|
|
120
|
-
return { browserType, binary: resolveBrowserBinary(candidate, platform) };
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
//# sourceMappingURL=browser-detect.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"browser-detect.js","sourceRoot":"","sources":["../../src/lib/browser-detect.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAI7B,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,mBAAmB,CAAC;AACzE,MAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,yBAAyB,CAAC;AAC3F,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,GAAG,EAAE,CAAC,OAAO,EAAE,kBAAkB,CAAC;AAEvF,MAAM,aAAa,GAA2D;IAC5E,MAAM,EAAE;QACN,MAAM,EAAE;YACN,8DAA8D;YAC9D,4EAA4E;SAC7E;QACD,QAAQ,EAAE,CAAC,oDAAoD,CAAC;QAChE,KAAK,EAAE,CA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AAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CACvC,WAA4B,EAAE,CAAC,QAAQ,EAAE;IAEzC,MAAM,QAAQ,GAAG,wBAAwB,CAAC,QAAQ,CAAC,CAAC;IACpD,MAAM,aAAa,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAI,CAAC,QAAQ,IAAI,CAAC,aAAa;QAAE,OAAO,IAAI,CAAC;IAC7C,KAAK,MAAM,WAAW,IAAI,QAAQ,EAAE,CAAC;QACnC,KAAK,MAAM,SAAS,IAAI,aAAa,CAAC,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC;YACzD,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;gBAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,oBAAoB,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC;YAC5E,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/lib/favorites.d.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Favorites and the local artifact listing.
|
|
3
|
-
*
|
|
4
|
-
* The revision store (`revisions.ts`) already knows every rendered artifact:
|
|
5
|
-
* one directory per source under {@link historyRoot}, keyed by the SHA-256 of
|
|
6
|
-
* its canonical path, with a strict-integrity `manifest.json`. Favorites ride
|
|
7
|
-
* BESIDE that store in a single `favorites.json` at the same root rather than
|
|
8
|
-
* inside each manifest — a manifest is rewritten only inside the locked
|
|
9
|
-
* serialize→render→write transaction, and a favorite toggle must never touch
|
|
10
|
-
* (or be blocked by) that pipeline.
|
|
11
|
-
*
|
|
12
|
-
* Same env override as the revision store (`ARTIFACTS_HISTORY_DIR`), so a test
|
|
13
|
-
* or a scratch HOME relocates both together. Reads are lock-free (writes are
|
|
14
|
-
* atomic renames); writes take a lock on the store root so a served page and a
|
|
15
|
-
* CLI toggle never lose each other's update.
|
|
16
|
-
*/
|
|
17
|
-
export interface FavoriteEntry {
|
|
18
|
-
/** Canonical source path, when the favorite was recorded from a path. */
|
|
19
|
-
sourcePath?: string;
|
|
20
|
-
/** Display title, when known at toggle time (the served page sends document.title). */
|
|
21
|
-
title?: string;
|
|
22
|
-
favoritedAt: string;
|
|
23
|
-
}
|
|
24
|
-
export declare function favoritesPath(): string;
|
|
25
|
-
/**
|
|
26
|
-
* Read the favorites file. Absent means "no favorites yet"; present but
|
|
27
|
-
* unparseable or wrong-shaped is fatal — never silently reset a user's marks
|
|
28
|
-
* behind a transient read glitch (same rule as the revision manifest).
|
|
29
|
-
*/
|
|
30
|
-
export declare function readFavorites(file?: string): Record<string, FavoriteEntry>;
|
|
31
|
-
/**
|
|
32
|
-
* Set, clear, or flip the favorite flag for an artifact (a source path or a
|
|
33
|
-
* bare 64-hex id). The current-state read for a flip happens INSIDE the lock
|
|
34
|
-
* on the store root — reading before acquiring it would let two concurrent
|
|
35
|
-
* toggles both compute the same next state and collapse into one.
|
|
36
|
-
* Returns the resulting state.
|
|
37
|
-
*/
|
|
38
|
-
export declare function setFavorite(sourceOrId: string, favorite: boolean | 'toggle', extra?: {
|
|
39
|
-
sourcePath?: string;
|
|
40
|
-
title?: string;
|
|
41
|
-
}): Promise<{
|
|
42
|
-
id: string;
|
|
43
|
-
favorite: boolean;
|
|
44
|
-
}>;
|
|
45
|
-
/** Flip the favorite flag (atomically, under the store lock); returns the resulting state. */
|
|
46
|
-
export declare function toggleFavorite(sourceOrId: string, extra?: {
|
|
47
|
-
sourcePath?: string;
|
|
48
|
-
title?: string;
|
|
49
|
-
}): Promise<{
|
|
50
|
-
id: string;
|
|
51
|
-
favorite: boolean;
|
|
52
|
-
}>;
|
|
53
|
-
export declare function isFavorite(sourceOrId: string): boolean;
|
|
54
|
-
/** One artifact known to the local store, for `artifacts list`. */
|
|
55
|
-
export interface ArtifactSummary {
|
|
56
|
-
id: string;
|
|
57
|
-
sourcePath: string;
|
|
58
|
-
title: string;
|
|
59
|
-
/** First revision's timestamp; empty when the artifact has no saved revisions. */
|
|
60
|
-
createdAt: string;
|
|
61
|
-
/** Latest revision's timestamp; empty when the artifact has no saved revisions. */
|
|
62
|
-
updatedAt: string;
|
|
63
|
-
revisionCount: number;
|
|
64
|
-
favorite: boolean;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Enumerate every artifact the local store knows: the union of the revision
|
|
68
|
-
* manifests and the favorites file (a favorite can outlive — or predate — a
|
|
69
|
-
* manifest). A manifest that fails to parse is SKIPPED rather than fatal: a
|
|
70
|
-
* listing must degrade gracefully, unlike the integrity gate a targeted
|
|
71
|
-
* `history` read applies. Sorted most-recently-updated first.
|
|
72
|
-
*/
|
|
73
|
-
export declare function listArtifacts(): ArtifactSummary[];
|
package/dist/lib/favorites.js
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Favorites and the local artifact listing.
|
|
3
|
-
*
|
|
4
|
-
* The revision store (`revisions.ts`) already knows every rendered artifact:
|
|
5
|
-
* one directory per source under {@link historyRoot}, keyed by the SHA-256 of
|
|
6
|
-
* its canonical path, with a strict-integrity `manifest.json`. Favorites ride
|
|
7
|
-
* BESIDE that store in a single `favorites.json` at the same root rather than
|
|
8
|
-
* inside each manifest — a manifest is rewritten only inside the locked
|
|
9
|
-
* serialize→render→write transaction, and a favorite toggle must never touch
|
|
10
|
-
* (or be blocked by) that pipeline.
|
|
11
|
-
*
|
|
12
|
-
* Same env override as the revision store (`ARTIFACTS_HISTORY_DIR`), so a test
|
|
13
|
-
* or a scratch HOME relocates both together. Reads are lock-free (writes are
|
|
14
|
-
* atomic renames); writes take a lock on the store root so a served page and a
|
|
15
|
-
* CLI toggle never lose each other's update.
|
|
16
|
-
*/
|
|
17
|
-
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync } from 'node:fs';
|
|
18
|
-
import { closeSync, fsyncSync, openSync, writeFileSync } from 'node:fs';
|
|
19
|
-
import { randomBytes } from 'node:crypto';
|
|
20
|
-
import { basename, dirname, join } from 'node:path';
|
|
21
|
-
import { lock } from 'proper-lockfile';
|
|
22
|
-
import { artifactTarget, historyRoot } from './revisions.js';
|
|
23
|
-
const FAVORITES_SCHEMA = 'artifacts.favorites.v1';
|
|
24
|
-
const FAVORITES_FILE = 'favorites.json';
|
|
25
|
-
const FILE_MODE = 0o600;
|
|
26
|
-
const ID_RE = /^[0-9a-f]{64}$/;
|
|
27
|
-
export function favoritesPath() {
|
|
28
|
-
return join(historyRoot(), FAVORITES_FILE);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Read the favorites file. Absent means "no favorites yet"; present but
|
|
32
|
-
* unparseable or wrong-shaped is fatal — never silently reset a user's marks
|
|
33
|
-
* behind a transient read glitch (same rule as the revision manifest).
|
|
34
|
-
*/
|
|
35
|
-
export function readFavorites(file = favoritesPath()) {
|
|
36
|
-
if (!existsSync(file))
|
|
37
|
-
return {};
|
|
38
|
-
let parsed;
|
|
39
|
-
try {
|
|
40
|
-
parsed = JSON.parse(readFileSync(file, 'utf8'));
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
throw new Error(`Corrupt favorites file at ${file}: ${error.message}`);
|
|
44
|
-
}
|
|
45
|
-
const v = parsed;
|
|
46
|
-
if (!v || v.schema !== FAVORITES_SCHEMA || typeof v.favorites !== 'object' || v.favorites === null) {
|
|
47
|
-
throw new Error(`Corrupt favorites file at ${file}: unexpected shape`);
|
|
48
|
-
}
|
|
49
|
-
return v.favorites;
|
|
50
|
-
}
|
|
51
|
-
function atomicWrite(target, data, mode) {
|
|
52
|
-
const tmp = join(dirname(target), `.${basename(target)}.${process.pid}.${randomBytes(6).toString('hex')}.tmp`);
|
|
53
|
-
const fd = openSync(tmp, 'wx', mode);
|
|
54
|
-
try {
|
|
55
|
-
writeFileSync(fd, data);
|
|
56
|
-
fsyncSync(fd);
|
|
57
|
-
}
|
|
58
|
-
finally {
|
|
59
|
-
closeSync(fd);
|
|
60
|
-
}
|
|
61
|
-
renameSync(tmp, target);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Set, clear, or flip the favorite flag for an artifact (a source path or a
|
|
65
|
-
* bare 64-hex id). The current-state read for a flip happens INSIDE the lock
|
|
66
|
-
* on the store root — reading before acquiring it would let two concurrent
|
|
67
|
-
* toggles both compute the same next state and collapse into one.
|
|
68
|
-
* Returns the resulting state.
|
|
69
|
-
*/
|
|
70
|
-
export async function setFavorite(sourceOrId, favorite, extra = {}) {
|
|
71
|
-
const { id, sourcePath } = artifactTarget(sourceOrId);
|
|
72
|
-
const root = historyRoot();
|
|
73
|
-
mkdirSync(root, { recursive: true, mode: 0o700 });
|
|
74
|
-
const release = await lock(root, {
|
|
75
|
-
realpath: false,
|
|
76
|
-
// A concurrent toggle (a served page and a CLI invocation racing) waits
|
|
77
|
-
// briefly instead of failing outright.
|
|
78
|
-
retries: { retries: 20, factor: 1.4, minTimeout: 25, maxTimeout: 500 },
|
|
79
|
-
});
|
|
80
|
-
try {
|
|
81
|
-
const file = favoritesPath();
|
|
82
|
-
const favorites = readFavorites(file);
|
|
83
|
-
const next = favorite === 'toggle' ? !favorites[id] : favorite;
|
|
84
|
-
if (next) {
|
|
85
|
-
const prior = favorites[id];
|
|
86
|
-
favorites[id] = {
|
|
87
|
-
sourcePath: extra.sourcePath ?? sourcePath ?? prior?.sourcePath,
|
|
88
|
-
title: extra.title ?? prior?.title,
|
|
89
|
-
favoritedAt: prior?.favoritedAt ?? new Date().toISOString(),
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
delete favorites[id];
|
|
94
|
-
}
|
|
95
|
-
atomicWrite(file, JSON.stringify({ schema: FAVORITES_SCHEMA, favorites }, null, 2) + '\n', FILE_MODE);
|
|
96
|
-
return { id, favorite: next };
|
|
97
|
-
}
|
|
98
|
-
finally {
|
|
99
|
-
await release();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/** Flip the favorite flag (atomically, under the store lock); returns the resulting state. */
|
|
103
|
-
export async function toggleFavorite(sourceOrId, extra = {}) {
|
|
104
|
-
return setFavorite(sourceOrId, 'toggle', extra);
|
|
105
|
-
}
|
|
106
|
-
export function isFavorite(sourceOrId) {
|
|
107
|
-
const { id } = artifactTarget(sourceOrId);
|
|
108
|
-
return Boolean(readFavorites()[id]);
|
|
109
|
-
}
|
|
110
|
-
/** Frontmatter `title:` of a Markdown source, when the file still exists. */
|
|
111
|
-
function sourceTitle(sourcePath) {
|
|
112
|
-
try {
|
|
113
|
-
const raw = readFileSync(sourcePath, 'utf8');
|
|
114
|
-
const frontmatter = /^---\r?\n([\s\S]*?)\r?\n---/.exec(raw);
|
|
115
|
-
const line = frontmatter && /^title:\s*(.+)$/m.exec(frontmatter[1]);
|
|
116
|
-
const title = line?.[1]?.trim().replace(/^["']|["']$/g, '').trim();
|
|
117
|
-
if (title)
|
|
118
|
-
return title;
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
// Source moved or unreadable — the basename is the fallback below.
|
|
122
|
-
}
|
|
123
|
-
return '';
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Enumerate every artifact the local store knows: the union of the revision
|
|
127
|
-
* manifests and the favorites file (a favorite can outlive — or predate — a
|
|
128
|
-
* manifest). A manifest that fails to parse is SKIPPED rather than fatal: a
|
|
129
|
-
* listing must degrade gracefully, unlike the integrity gate a targeted
|
|
130
|
-
* `history` read applies. Sorted most-recently-updated first.
|
|
131
|
-
*/
|
|
132
|
-
export function listArtifacts() {
|
|
133
|
-
const root = historyRoot();
|
|
134
|
-
const favorites = readFavorites();
|
|
135
|
-
const byId = new Map();
|
|
136
|
-
if (existsSync(root)) {
|
|
137
|
-
for (const entry of readdirSync(root, { withFileTypes: true })) {
|
|
138
|
-
if (!entry.isDirectory() || !ID_RE.test(entry.name))
|
|
139
|
-
continue;
|
|
140
|
-
const manifestFile = join(root, entry.name, 'manifest.json');
|
|
141
|
-
if (!existsSync(manifestFile))
|
|
142
|
-
continue;
|
|
143
|
-
let manifest;
|
|
144
|
-
try {
|
|
145
|
-
manifest = JSON.parse(readFileSync(manifestFile, 'utf8'));
|
|
146
|
-
}
|
|
147
|
-
catch {
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
const revisions = Array.isArray(manifest.revisions) ? manifest.revisions : [];
|
|
151
|
-
const first = revisions[0];
|
|
152
|
-
const last = revisions.at(-1);
|
|
153
|
-
const sourcePath = typeof manifest.sourcePath === 'string' ? manifest.sourcePath : '';
|
|
154
|
-
byId.set(entry.name, {
|
|
155
|
-
id: entry.name,
|
|
156
|
-
sourcePath,
|
|
157
|
-
title: favorites[entry.name]?.title || sourceTitle(sourcePath) || basename(sourcePath),
|
|
158
|
-
createdAt: first?.createdAt ?? '',
|
|
159
|
-
updatedAt: last?.createdAt ?? '',
|
|
160
|
-
revisionCount: revisions.length,
|
|
161
|
-
favorite: Boolean(favorites[entry.name]),
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
for (const [id, entry] of Object.entries(favorites)) {
|
|
166
|
-
if (byId.has(id) || !ID_RE.test(id))
|
|
167
|
-
continue;
|
|
168
|
-
byId.set(id, {
|
|
169
|
-
id,
|
|
170
|
-
sourcePath: entry.sourcePath ?? '',
|
|
171
|
-
title: entry.title || (entry.sourcePath ? basename(entry.sourcePath) : ''),
|
|
172
|
-
createdAt: '',
|
|
173
|
-
updatedAt: '',
|
|
174
|
-
revisionCount: 0,
|
|
175
|
-
favorite: true,
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
return [...byId.values()].sort((a, b) => (b.updatedAt || b.createdAt).localeCompare(a.updatedAt || a.createdAt));
|
|
179
|
-
}
|
|
180
|
-
//# sourceMappingURL=favorites.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|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ACH,CAAC;IACD,KAAK,MAAM,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QACpD,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YAAE,SAAS;QAC9C,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE;YACX,EAAE;YACF,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,EAAE;YAClC,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1E,SAAS,EAAE,EAAE;YACb,SAAS,EAAE,EAAE;YACb,aAAa,EAAE,CAAC;YAChB,QAAQ,EAAE,IAAI;SACf,CAAC,CAAC;IACL,CAAC;IACD,OAAO,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;AACnH,CAAC"}
|
package/dist/lib/github.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The publisher's GitHub username — the URL namespace a BYO (bring-your-own
|
|
3
|
-
* Cloudflare) share publishes under. The managed endpoint namespaces on the
|
|
4
|
-
* Phoenix handle instead and never calls this.
|
|
5
|
-
*/
|
|
6
|
-
/** Explicit override, so a machine with no `gh` and no git config can still publish. */
|
|
7
|
-
export declare const GITHUB_USER_ENV = "ARTIFACTS_GITHUB_USER";
|
|
8
|
-
/**
|
|
9
|
-
* Resolve the GitHub username: the explicit env override, then the signed-in
|
|
10
|
-
* `gh` account, then `git config --global github.user`. `null` when none of the
|
|
11
|
-
* three answer — the caller turns that into an actionable error rather than
|
|
12
|
-
* inventing a namespace.
|
|
13
|
-
*/
|
|
14
|
-
export declare function resolveGitHubUsername(): Promise<string | null>;
|
package/dist/lib/github.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The publisher's GitHub username — the URL namespace a BYO (bring-your-own
|
|
3
|
-
* Cloudflare) share publishes under. The managed endpoint namespaces on the
|
|
4
|
-
* Phoenix handle instead and never calls this.
|
|
5
|
-
*/
|
|
6
|
-
import { execFile } from 'node:child_process';
|
|
7
|
-
import { promisify } from 'node:util';
|
|
8
|
-
const execFileAsync = promisify(execFile);
|
|
9
|
-
/** Explicit override, so a machine with no `gh` and no git config can still publish. */
|
|
10
|
-
export const GITHUB_USER_ENV = 'ARTIFACTS_GITHUB_USER';
|
|
11
|
-
async function tryCommand(file, args) {
|
|
12
|
-
try {
|
|
13
|
-
const { stdout } = await execFileAsync(file, args, { encoding: 'utf8', timeout: 10_000 });
|
|
14
|
-
const value = stdout.trim();
|
|
15
|
-
return value || null;
|
|
16
|
-
}
|
|
17
|
-
catch {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Resolve the GitHub username: the explicit env override, then the signed-in
|
|
23
|
-
* `gh` account, then `git config --global github.user`. `null` when none of the
|
|
24
|
-
* three answer — the caller turns that into an actionable error rather than
|
|
25
|
-
* inventing a namespace.
|
|
26
|
-
*/
|
|
27
|
-
export async function resolveGitHubUsername() {
|
|
28
|
-
const fromEnv = process.env[GITHUB_USER_ENV]?.trim();
|
|
29
|
-
if (fromEnv)
|
|
30
|
-
return fromEnv;
|
|
31
|
-
const fromGh = await tryCommand('gh', ['api', 'user', '-q', '.login']);
|
|
32
|
-
if (fromGh)
|
|
33
|
-
return fromGh;
|
|
34
|
-
return tryCommand('git', ['config', '--global', 'github.user']);
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=github.js.map
|
package/dist/lib/github.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"github.js","sourceRoot":"","sources":["../../src/lib/github.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,wFAAwF;AACxF,MAAM,CAAC,MAAM,eAAe,GAAG,uBAAuB,CAAC;AAEvD,KAAK,UAAU,UAAU,CAAC,IAAY,EAAE,IAAc;IACpD,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;QAC1F,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5B,OAAO,KAAK,IAAI,IAAI,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB;IACzC,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,IAAI,EAAE,CAAC;IACrD,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC;IAC5B,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;IACvE,IAAI,MAAM;QAAE,OAAO,MAAM,CAAC;IAC1B,OAAO,UAAU,CAAC,KAAK,EAAE,CAAC,QAAQ,EAAE,UAAU,EAAE,aAAa,CAAC,CAAC,CAAC;AAClE,CAAC"}
|
package/dist/lib/highlights.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local reader review: highlight a selection, attach a private note, keep both in
|
|
3
|
-
* `localStorage` and — on a loopback dev server only — mirror them to a sidecar.
|
|
4
|
-
*
|
|
5
|
-
* Ranges come from the shared anchor runtime in `reader-anchors.ts`; this module
|
|
6
|
-
* owns the selection toolbar, the note popover, and local persistence. The
|
|
7
|
-
* toolbar is extensible (`window.__artifactsHighlights.addAction`) so a hosted
|
|
8
|
-
* surface can add its own affordance next to Highlight and Note without forking
|
|
9
|
-
* the selection handling.
|
|
10
|
-
*/
|
|
11
|
-
export declare const HIGHLIGHTS_SCRIPT = "<script>\n(() => {\n const reader = window.__artifactsReader;\n if (!reader) return;\n const root = reader.root;\n\n const storageKey = 'artifacts-highlights:' + location.origin + location.pathname + ':' + (document.title || '');\n const read = () => {\n try {\n const value = JSON.parse(localStorage.getItem(storageKey) || '[]');\n return Array.isArray(value) ? value.filter((item) => item && item.id && item.start && item.end).map((item) => ({\n quote: '', note: '', section: 'document', created_at: new Date().toISOString(), ...item,\n })) : [];\n } catch { return []; }\n };\n let highlights = read();\n let postTimer;\n const post = () => {\n if (location.protocol !== 'http:' || !['127.0.0.1', 'localhost', '::1'].includes(location.hostname)) return;\n fetch('/notes', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ schema: 'artifacts.notes.v1', notes: highlights }) }).catch(() => {});\n };\n const write = () => {\n try { localStorage.setItem(storageKey, JSON.stringify(highlights)); } catch {}\n clearTimeout(postTimer); postTimer = setTimeout(post, 600);\n };\n const render = () => {\n reader.clearMarks('mark[data-highlight-id]');\n for (const highlight of highlights) {\n reader.paint(highlight, () => {\n const mark = document.createElement('mark');\n mark.className = 'reader-highlight'; mark.dataset.highlightId = highlight.id; mark.title = 'Open note';\n return mark;\n });\n }\n };\n\n const style = document.createElement('style');\n style.textContent = '.reader-toolbar,.reader-popover{position:fixed;z-index:40;display:flex;align-items:center;gap:6px;padding:7px;border:1px solid var(--line,#ccc);border-radius:10px;background:var(--surface,#fff);color:var(--text,#111);box-shadow:0 10px 35px rgba(0,0,0,.18);font:500 12px/1.2 var(--font-mono,monospace)}.reader-toolbar[hidden],.reader-popover[hidden]{display:none}.reader-toolbar-status{padding:0 6px;color:var(--muted,#666)}.reader-toolbar button,.reader-popover button{border:1px solid var(--line,#ccc);border-radius:999px;background:var(--surface-alt,#f5f5f5);color:inherit;padding:6px 9px;font:inherit;cursor:pointer}.reader-popover{width:min(360px,calc(100vw - 24px));align-items:stretch;flex-direction:column;padding:12px}.reader-popover-quote{margin:0;color:var(--muted,#666);font-style:italic;line-height:1.45}.reader-popover textarea{width:100%;min-height:84px;resize:vertical;border:1px solid var(--line,#ccc);border-radius:7px;padding:8px;background:var(--bg,#fff);color:inherit;font:13px/1.4 var(--font-body,sans-serif)}.reader-popover-actions{display:flex;gap:6px}.reader-remove{margin-left:auto;color:var(--danger,#b91c1c)!important}';\n document.head.append(style);\n const toolbar = document.createElement('div'); toolbar.className = 'reader-toolbar'; toolbar.hidden = true;\n toolbar.innerHTML = '<span class=\"reader-toolbar-status\">Copied</span><span aria-hidden=\"true\">\u00B7</span><button type=\"button\" data-reader-action=\"highlight\">Highlight</button><span aria-hidden=\"true\">\u00B7</span><button type=\"button\" data-reader-action=\"note\">Note</button>';\n document.body.append(toolbar);\n const popover = document.createElement('div'); popover.className = 'reader-popover'; popover.hidden = true;\n popover.innerHTML = '<p class=\"reader-popover-quote\"></p><textarea aria-label=\"Note\" placeholder=\"Attach a note\u2026\"></textarea><div class=\"reader-popover-actions\"><button type=\"button\" data-reader-action=\"copy\">Copy</button><button type=\"button\" class=\"reader-remove\" data-reader-action=\"remove\">Remove</button></div>';\n document.body.append(popover);\n let pending = null; let activeId = null; let noteTimer;\n const place = (element, rect) => { element.style.left = Math.max(8, Math.min(innerWidth - element.offsetWidth - 8, rect.left)) + 'px'; element.style.top = Math.max(8, rect.bottom + 8) + 'px'; };\n const openNote = (item, rect) => {\n activeId = item.id; toolbar.hidden = true; popover.hidden = false;\n popover.querySelector('.reader-popover-quote').textContent = '\u201C' + item.quote + '\u201D'; popover.querySelector('textarea').value = item.note || '';\n place(popover, rect);\n };\n const persistPending = (open) => {\n if (!pending) return;\n const duplicate = highlights.find((item) => item.start.anchor === pending.start.anchor && item.start.offset === pending.start.offset && item.end.anchor === pending.end.anchor && item.end.offset === pending.end.offset);\n const item = duplicate || { id: Date.now().toString(36) + Math.random().toString(36).slice(2), ...pending, created_at: new Date().toISOString() };\n if (!duplicate) highlights.push(item);\n write(); toolbar.hidden = true; render();\n if (open) openNote(item, pending.rect);\n };\n\n const extras = new Map();\n window.__artifactsHighlights = {\n // Adds a button beside Highlight and Note. The handler receives the pending\n // selection record in the shared anchor vocabulary.\n addAction: (id, label, handler) => {\n extras.set(id, handler);\n const separator = document.createElement('span'); separator.setAttribute('aria-hidden', 'true'); separator.textContent = '\u00B7';\n const button = document.createElement('button'); button.type = 'button'; button.dataset.readerAction = id; button.textContent = label;\n toolbar.append(separator, button);\n },\n dismiss: () => { toolbar.hidden = true; },\n };\n\n root.addEventListener('mouseup', () => {\n const record = reader.selectionRecord(); if (!record) return;\n pending = { ...record, note: '' };\n navigator.clipboard?.writeText(record.quote).catch(() => {});\n popover.hidden = true; toolbar.hidden = false; requestAnimationFrame(() => place(toolbar, record.rect));\n });\n toolbar.addEventListener('mousedown', (event) => event.preventDefault());\n toolbar.addEventListener('click', (event) => {\n const action = event.target.closest('button')?.dataset.readerAction;\n if (action === 'highlight') persistPending(false);\n else if (action === 'note') persistPending(true);\n else if (extras.has(action)) extras.get(action)(pending);\n });\n root.addEventListener('click', (event) => {\n const mark = event.target.closest('mark[data-highlight-id]'); if (!mark || !root.contains(mark)) return;\n event.preventDefault(); event.stopPropagation();\n const item = highlights.find((value) => value.id === mark.dataset.highlightId); if (item) openNote(item, mark.getBoundingClientRect());\n });\n popover.querySelector('textarea').addEventListener('input', (event) => {\n clearTimeout(noteTimer); noteTimer = setTimeout(() => {\n const item = highlights.find((value) => value.id === activeId); if (item) { item.note = event.target.value; write(); }\n }, 600);\n });\n popover.addEventListener('click', (event) => {\n const action = event.target.closest('button')?.dataset.readerAction; const item = highlights.find((value) => value.id === activeId); if (!item) return;\n if (action === 'copy') navigator.clipboard?.writeText(item.quote).catch(() => {});\n if (action === 'remove') { highlights = highlights.filter((value) => value.id !== activeId); write(); popover.hidden = true; render(); }\n });\n render();\n})();\n</script>";
|
package/dist/lib/highlights.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local reader review: highlight a selection, attach a private note, keep both in
|
|
3
|
-
* `localStorage` and — on a loopback dev server only — mirror them to a sidecar.
|
|
4
|
-
*
|
|
5
|
-
* Ranges come from the shared anchor runtime in `reader-anchors.ts`; this module
|
|
6
|
-
* owns the selection toolbar, the note popover, and local persistence. The
|
|
7
|
-
* toolbar is extensible (`window.__artifactsHighlights.addAction`) so a hosted
|
|
8
|
-
* surface can add its own affordance next to Highlight and Note without forking
|
|
9
|
-
* the selection handling.
|
|
10
|
-
*/
|
|
11
|
-
export const HIGHLIGHTS_SCRIPT = `<script>
|
|
12
|
-
(() => {
|
|
13
|
-
const reader = window.__artifactsReader;
|
|
14
|
-
if (!reader) return;
|
|
15
|
-
const root = reader.root;
|
|
16
|
-
|
|
17
|
-
const storageKey = 'artifacts-highlights:' + location.origin + location.pathname + ':' + (document.title || '');
|
|
18
|
-
const read = () => {
|
|
19
|
-
try {
|
|
20
|
-
const value = JSON.parse(localStorage.getItem(storageKey) || '[]');
|
|
21
|
-
return Array.isArray(value) ? value.filter((item) => item && item.id && item.start && item.end).map((item) => ({
|
|
22
|
-
quote: '', note: '', section: 'document', created_at: new Date().toISOString(), ...item,
|
|
23
|
-
})) : [];
|
|
24
|
-
} catch { return []; }
|
|
25
|
-
};
|
|
26
|
-
let highlights = read();
|
|
27
|
-
let postTimer;
|
|
28
|
-
const post = () => {
|
|
29
|
-
if (location.protocol !== 'http:' || !['127.0.0.1', 'localhost', '::1'].includes(location.hostname)) return;
|
|
30
|
-
fetch('/notes', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ schema: 'artifacts.notes.v1', notes: highlights }) }).catch(() => {});
|
|
31
|
-
};
|
|
32
|
-
const write = () => {
|
|
33
|
-
try { localStorage.setItem(storageKey, JSON.stringify(highlights)); } catch {}
|
|
34
|
-
clearTimeout(postTimer); postTimer = setTimeout(post, 600);
|
|
35
|
-
};
|
|
36
|
-
const render = () => {
|
|
37
|
-
reader.clearMarks('mark[data-highlight-id]');
|
|
38
|
-
for (const highlight of highlights) {
|
|
39
|
-
reader.paint(highlight, () => {
|
|
40
|
-
const mark = document.createElement('mark');
|
|
41
|
-
mark.className = 'reader-highlight'; mark.dataset.highlightId = highlight.id; mark.title = 'Open note';
|
|
42
|
-
return mark;
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const style = document.createElement('style');
|
|
48
|
-
style.textContent = '.reader-toolbar,.reader-popover{position:fixed;z-index:40;display:flex;align-items:center;gap:6px;padding:7px;border:1px solid var(--line,#ccc);border-radius:10px;background:var(--surface,#fff);color:var(--text,#111);box-shadow:0 10px 35px rgba(0,0,0,.18);font:500 12px/1.2 var(--font-mono,monospace)}.reader-toolbar[hidden],.reader-popover[hidden]{display:none}.reader-toolbar-status{padding:0 6px;color:var(--muted,#666)}.reader-toolbar button,.reader-popover button{border:1px solid var(--line,#ccc);border-radius:999px;background:var(--surface-alt,#f5f5f5);color:inherit;padding:6px 9px;font:inherit;cursor:pointer}.reader-popover{width:min(360px,calc(100vw - 24px));align-items:stretch;flex-direction:column;padding:12px}.reader-popover-quote{margin:0;color:var(--muted,#666);font-style:italic;line-height:1.45}.reader-popover textarea{width:100%;min-height:84px;resize:vertical;border:1px solid var(--line,#ccc);border-radius:7px;padding:8px;background:var(--bg,#fff);color:inherit;font:13px/1.4 var(--font-body,sans-serif)}.reader-popover-actions{display:flex;gap:6px}.reader-remove{margin-left:auto;color:var(--danger,#b91c1c)!important}';
|
|
49
|
-
document.head.append(style);
|
|
50
|
-
const toolbar = document.createElement('div'); toolbar.className = 'reader-toolbar'; toolbar.hidden = true;
|
|
51
|
-
toolbar.innerHTML = '<span class="reader-toolbar-status">Copied</span><span aria-hidden="true">·</span><button type="button" data-reader-action="highlight">Highlight</button><span aria-hidden="true">·</span><button type="button" data-reader-action="note">Note</button>';
|
|
52
|
-
document.body.append(toolbar);
|
|
53
|
-
const popover = document.createElement('div'); popover.className = 'reader-popover'; popover.hidden = true;
|
|
54
|
-
popover.innerHTML = '<p class="reader-popover-quote"></p><textarea aria-label="Note" placeholder="Attach a note…"></textarea><div class="reader-popover-actions"><button type="button" data-reader-action="copy">Copy</button><button type="button" class="reader-remove" data-reader-action="remove">Remove</button></div>';
|
|
55
|
-
document.body.append(popover);
|
|
56
|
-
let pending = null; let activeId = null; let noteTimer;
|
|
57
|
-
const place = (element, rect) => { element.style.left = Math.max(8, Math.min(innerWidth - element.offsetWidth - 8, rect.left)) + 'px'; element.style.top = Math.max(8, rect.bottom + 8) + 'px'; };
|
|
58
|
-
const openNote = (item, rect) => {
|
|
59
|
-
activeId = item.id; toolbar.hidden = true; popover.hidden = false;
|
|
60
|
-
popover.querySelector('.reader-popover-quote').textContent = '“' + item.quote + '”'; popover.querySelector('textarea').value = item.note || '';
|
|
61
|
-
place(popover, rect);
|
|
62
|
-
};
|
|
63
|
-
const persistPending = (open) => {
|
|
64
|
-
if (!pending) return;
|
|
65
|
-
const duplicate = highlights.find((item) => item.start.anchor === pending.start.anchor && item.start.offset === pending.start.offset && item.end.anchor === pending.end.anchor && item.end.offset === pending.end.offset);
|
|
66
|
-
const item = duplicate || { id: Date.now().toString(36) + Math.random().toString(36).slice(2), ...pending, created_at: new Date().toISOString() };
|
|
67
|
-
if (!duplicate) highlights.push(item);
|
|
68
|
-
write(); toolbar.hidden = true; render();
|
|
69
|
-
if (open) openNote(item, pending.rect);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
const extras = new Map();
|
|
73
|
-
window.__artifactsHighlights = {
|
|
74
|
-
// Adds a button beside Highlight and Note. The handler receives the pending
|
|
75
|
-
// selection record in the shared anchor vocabulary.
|
|
76
|
-
addAction: (id, label, handler) => {
|
|
77
|
-
extras.set(id, handler);
|
|
78
|
-
const separator = document.createElement('span'); separator.setAttribute('aria-hidden', 'true'); separator.textContent = '·';
|
|
79
|
-
const button = document.createElement('button'); button.type = 'button'; button.dataset.readerAction = id; button.textContent = label;
|
|
80
|
-
toolbar.append(separator, button);
|
|
81
|
-
},
|
|
82
|
-
dismiss: () => { toolbar.hidden = true; },
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
root.addEventListener('mouseup', () => {
|
|
86
|
-
const record = reader.selectionRecord(); if (!record) return;
|
|
87
|
-
pending = { ...record, note: '' };
|
|
88
|
-
navigator.clipboard?.writeText(record.quote).catch(() => {});
|
|
89
|
-
popover.hidden = true; toolbar.hidden = false; requestAnimationFrame(() => place(toolbar, record.rect));
|
|
90
|
-
});
|
|
91
|
-
toolbar.addEventListener('mousedown', (event) => event.preventDefault());
|
|
92
|
-
toolbar.addEventListener('click', (event) => {
|
|
93
|
-
const action = event.target.closest('button')?.dataset.readerAction;
|
|
94
|
-
if (action === 'highlight') persistPending(false);
|
|
95
|
-
else if (action === 'note') persistPending(true);
|
|
96
|
-
else if (extras.has(action)) extras.get(action)(pending);
|
|
97
|
-
});
|
|
98
|
-
root.addEventListener('click', (event) => {
|
|
99
|
-
const mark = event.target.closest('mark[data-highlight-id]'); if (!mark || !root.contains(mark)) return;
|
|
100
|
-
event.preventDefault(); event.stopPropagation();
|
|
101
|
-
const item = highlights.find((value) => value.id === mark.dataset.highlightId); if (item) openNote(item, mark.getBoundingClientRect());
|
|
102
|
-
});
|
|
103
|
-
popover.querySelector('textarea').addEventListener('input', (event) => {
|
|
104
|
-
clearTimeout(noteTimer); noteTimer = setTimeout(() => {
|
|
105
|
-
const item = highlights.find((value) => value.id === activeId); if (item) { item.note = event.target.value; write(); }
|
|
106
|
-
}, 600);
|
|
107
|
-
});
|
|
108
|
-
popover.addEventListener('click', (event) => {
|
|
109
|
-
const action = event.target.closest('button')?.dataset.readerAction; const item = highlights.find((value) => value.id === activeId); if (!item) return;
|
|
110
|
-
if (action === 'copy') navigator.clipboard?.writeText(item.quote).catch(() => {});
|
|
111
|
-
if (action === 'remove') { highlights = highlights.filter((value) => value.id !== activeId); write(); popover.hidden = true; render(); }
|
|
112
|
-
});
|
|
113
|
-
render();
|
|
114
|
-
})();
|
|
115
|
-
</script>`;
|
|
116
|
-
//# sourceMappingURL=highlights.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"highlights.js","sourceRoot":"","sources":["../../src/lib/highlights.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAwGvB,CAAC"}
|