@phnx-labs/artifacts-cli 0.9.13 → 0.10.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.
Files changed (134) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +7 -9
  3. package/dist/cli.d.ts +1 -2
  4. package/dist/cli.js +34 -190
  5. package/dist/cli.js.map +1 -1
  6. package/dist/commands/auth.d.ts +3 -1
  7. package/dist/commands/auth.js +17 -18
  8. package/dist/commands/auth.js.map +1 -1
  9. package/dist/commands/comments.js +2 -2
  10. package/dist/commands/comments.js.map +1 -1
  11. package/dist/commands/new.js +3 -3
  12. package/dist/commands/new.js.map +1 -1
  13. package/dist/commands/share.d.ts +44 -111
  14. package/dist/commands/share.js +225 -638
  15. package/dist/commands/share.js.map +1 -1
  16. package/dist/lib/collab.d.ts +3 -3
  17. package/dist/lib/collab.js +183 -13
  18. package/dist/lib/collab.js.map +1 -1
  19. package/dist/lib/components.js +0 -1
  20. package/dist/lib/components.js.map +1 -1
  21. package/dist/lib/config.d.ts +0 -17
  22. package/dist/lib/config.js.map +1 -1
  23. package/dist/lib/embedded-html.d.ts +1 -1
  24. package/dist/lib/embedded-html.js +0 -15
  25. package/dist/lib/embedded-html.js.map +1 -1
  26. package/dist/lib/freshness.d.ts +2 -6
  27. package/dist/lib/freshness.js +4 -33
  28. package/dist/lib/freshness.js.map +1 -1
  29. package/dist/lib/header-actions.d.ts +10 -37
  30. package/dist/lib/header-actions.js +19 -94
  31. package/dist/lib/header-actions.js.map +1 -1
  32. package/dist/lib/metadata-menu.d.ts +10 -33
  33. package/dist/lib/metadata-menu.js +12 -51
  34. package/dist/lib/metadata-menu.js.map +1 -1
  35. package/dist/lib/reader-anchors.d.ts +3 -3
  36. package/dist/lib/reader-anchors.js +7 -4
  37. package/dist/lib/reader-anchors.js.map +1 -1
  38. package/dist/lib/render.d.ts +2 -19
  39. package/dist/lib/render.js +37 -321
  40. package/dist/lib/render.js.map +1 -1
  41. package/dist/lib/section-collapse.d.ts +1 -2
  42. package/dist/lib/section-collapse.js +1 -2
  43. package/dist/lib/section-collapse.js.map +1 -1
  44. package/dist/lib/selection-toolbar.d.ts +9 -0
  45. package/dist/lib/selection-toolbar.js +49 -0
  46. package/dist/lib/selection-toolbar.js.map +1 -0
  47. package/dist/lib/share/backend.d.ts +8 -75
  48. package/dist/lib/share/backend.js +11 -123
  49. package/dist/lib/share/backend.js.map +1 -1
  50. package/dist/lib/share/config.d.ts +0 -79
  51. package/dist/lib/share/config.js +3 -175
  52. package/dist/lib/share/config.js.map +1 -1
  53. package/dist/lib/share/delete.d.ts +3 -14
  54. package/dist/lib/share/delete.js +8 -12
  55. package/dist/lib/share/delete.js.map +1 -1
  56. package/dist/lib/share/http-error.d.ts +12 -0
  57. package/dist/lib/share/http-error.js +32 -0
  58. package/dist/lib/share/http-error.js.map +1 -1
  59. package/dist/lib/share/media.d.ts +1 -6
  60. package/dist/lib/share/media.js +9 -17
  61. package/dist/lib/share/media.js.map +1 -1
  62. package/dist/lib/share/og.d.ts +0 -3
  63. package/dist/lib/share/og.js +2 -4
  64. package/dist/lib/share/og.js.map +1 -1
  65. package/dist/lib/share/provision.d.ts +7 -120
  66. package/dist/lib/share/provision.js +30 -290
  67. package/dist/lib/share/provision.js.map +1 -1
  68. package/dist/lib/share/publish.d.ts +10 -65
  69. package/dist/lib/share/publish.js +32 -131
  70. package/dist/lib/share/publish.js.map +1 -1
  71. package/dist/lib/share/visibility.d.ts +11 -35
  72. package/dist/lib/share/visibility.js +8 -35
  73. package/dist/lib/share/visibility.js.map +1 -1
  74. package/dist/lib/share/worker-media-template.js +1 -1
  75. package/dist/lib/share/worker-publish-template.d.ts +1 -1
  76. package/dist/lib/share/worker-publish-template.js +3 -0
  77. package/dist/lib/share/worker-publish-template.js.map +1 -1
  78. package/dist/lib/share/worker-template.d.ts +2 -14
  79. package/dist/lib/share/worker-template.js +207 -27
  80. package/dist/lib/share/worker-template.js.map +1 -1
  81. package/dist/lib/templates.d.ts +1 -2
  82. package/dist/lib/templates.js +1 -19
  83. package/dist/lib/templates.js.map +1 -1
  84. package/dist/lib/validate.js +1 -29
  85. package/dist/lib/validate.js.map +1 -1
  86. package/package.json +1 -4
  87. package/dist/commands/answers.d.ts +0 -6
  88. package/dist/commands/answers.js +0 -91
  89. package/dist/commands/answers.js.map +0 -1
  90. package/dist/commands/favorite.d.ts +0 -9
  91. package/dist/commands/favorite.js +0 -59
  92. package/dist/commands/favorite.js.map +0 -1
  93. package/dist/commands/history.d.ts +0 -4
  94. package/dist/commands/history.js +0 -29
  95. package/dist/commands/history.js.map +0 -1
  96. package/dist/commands/notes.d.ts +0 -5
  97. package/dist/commands/notes.js +0 -28
  98. package/dist/commands/notes.js.map +0 -1
  99. package/dist/lib/browser-detect.d.ts +0 -28
  100. package/dist/lib/browser-detect.js +0 -126
  101. package/dist/lib/browser-detect.js.map +0 -1
  102. package/dist/lib/favorites.d.ts +0 -73
  103. package/dist/lib/favorites.js +0 -180
  104. package/dist/lib/favorites.js.map +0 -1
  105. package/dist/lib/github.d.ts +0 -14
  106. package/dist/lib/github.js +0 -36
  107. package/dist/lib/github.js.map +0 -1
  108. package/dist/lib/highlights.d.ts +0 -11
  109. package/dist/lib/highlights.js +0 -116
  110. package/dist/lib/highlights.js.map +0 -1
  111. package/dist/lib/link-previews.d.ts +0 -67
  112. package/dist/lib/link-previews.js +0 -427
  113. package/dist/lib/link-previews.js.map +0 -1
  114. package/dist/lib/notes.d.ts +0 -22
  115. package/dist/lib/notes.js +0 -22
  116. package/dist/lib/notes.js.map +0 -1
  117. package/dist/lib/pdf.d.ts +0 -13
  118. package/dist/lib/pdf.js +0 -66
  119. package/dist/lib/pdf.js.map +0 -1
  120. package/dist/lib/revisions.d.ts +0 -102
  121. package/dist/lib/revisions.js +0 -445
  122. package/dist/lib/revisions.js.map +0 -1
  123. package/dist/lib/share/analytics.d.ts +0 -13
  124. package/dist/lib/share/analytics.js +0 -46
  125. package/dist/lib/share/analytics.js.map +0 -1
  126. package/dist/lib/share/capture.d.ts +0 -31
  127. package/dist/lib/share/capture.js +0 -175
  128. package/dist/lib/share/capture.js.map +0 -1
  129. package/dist/lib/tokens.d.ts +0 -12
  130. package/dist/lib/tokens.js +0 -28
  131. package/dist/lib/tokens.js.map +0 -1
  132. package/dist/lib/worksheet.d.ts +0 -94
  133. package/dist/lib/worksheet.js +0 -394
  134. package/dist/lib/worksheet.js.map +0 -1
@@ -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[];
@@ -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
- {"version":3,"file":"favorites.js","sourceRoot":"","sources":["../../src/lib/favorites.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,SAAS,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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"}
@@ -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>;
@@ -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
@@ -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"}
@@ -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>";
@@ -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"}
@@ -1,67 +0,0 @@
1
- /**
2
- * Link previews: at render time, every outbound pill's target is fetched once
3
- * and its title, description, site name, and social image URL are embedded in
4
- * the page as JSON. In the reader, clicking a pill opens a preview card built
5
- * from that JSON (an "Open" link on the card, or a modifier-click on the pill,
6
- * still goes to the page). The text is embedded, so the card works offline and
7
- * on a shared copy; only the optional image is loaded from the network at view
8
- * time, and it removes itself when it cannot load — the same fail-open rule
9
- * the pill favicons already follow.
10
- *
11
- * Fetches are bounded (one attempt per URL, a short timeout, a byte cap, a
12
- * small concurrency) and cached under the artifact history root, so a watch
13
- * loop re-rendering on every keystroke never re-fetches, and a failed URL is
14
- * not retried until its short failure TTL passes. Set
15
- * ARTIFACTS_NO_LINK_PREVIEWS=1 or pass --no-link-previews to skip the
16
- * network entirely.
17
- *
18
- * Only public hosts are fetched. A render can run unattended (a hook, a
19
- * watch loop) on a machine that can reach loopback and private-network
20
- * services, and the fetched text lands in a page that may be published, so
21
- * every hop — the URL itself and each redirect — must resolve to a public
22
- * address. ARTIFACTS_LINK_PREVIEWS_ALLOW_PRIVATE=1 (or the allowPrivateHosts
23
- * option) lifts that for intranet documentation and the test suite's local
24
- * origin.
25
- */
26
- export interface LinkPreview {
27
- url: string;
28
- title?: string;
29
- description?: string;
30
- site?: string;
31
- image?: string;
32
- }
33
- export declare const LINK_PREVIEWS_ID = "artifacts-link-previews";
34
- export declare function linkPreviewsEnabled(): boolean;
35
- /**
36
- * Title, description, site name, and image from a page's <head>: Open Graph
37
- * first, then Twitter cards, then the plain <title> and meta description.
38
- * Only the head is scanned; parsing stops at <body>.
39
- */
40
- export declare function parsePreviewMetadata(html: string, pageUrl: string): Omit<LinkPreview, 'url'>;
41
- /**
42
- * True only for a globally routable unicast address. Loopback, private
43
- * (RFC 1918, ULA), link-local (including the cloud metadata range),
44
- * carrier-grade NAT, unspecified, multicast, and reserved ranges are all
45
- * refused, in both IPv4 and IPv6 (mapped and NAT64 forms are unwrapped first).
46
- */
47
- export declare function isPublicAddress(address: string): boolean;
48
- /** A hostname is public when every address it resolves to is; a literal IP is checked directly. */
49
- export declare function hostIsPublic(hostname: string): Promise<boolean>;
50
- export type PreviewFetcher = (url: string, init: RequestInit) => Promise<Response>;
51
- export interface FetchPreviewOptions {
52
- fetcher?: PreviewFetcher;
53
- now?: () => number;
54
- version?: string;
55
- /** Fetch loopback and private-network hosts too (default: ARTIFACTS_LINK_PREVIEWS_ALLOW_PRIVATE=1). */
56
- allowPrivateHosts?: boolean;
57
- }
58
- /**
59
- * Previews for the given URLs, keyed by URL. Entries with neither a title nor
60
- * a description are omitted — a card with nothing on it is worse than a plain
61
- * link. Never throws: a network problem means fewer previews, not a failed render.
62
- */
63
- export declare function fetchLinkPreviews(urls: string[], options?: FetchPreviewOptions): Promise<Record<string, LinkPreview>>;
64
- /** The embedded JSON block; `<` is escaped so fetched text can never close the script. */
65
- export declare function linkPreviewsJson(previews: Record<string, LinkPreview>): string;
66
- export declare const LINK_PREVIEW_CSS: string;
67
- export declare const LINK_PREVIEW_SCRIPT = "<script>\n(() => {\n const node = document.getElementById('artifacts-link-previews');\n if (!node) return;\n let previews;\n try { previews = JSON.parse(node.textContent || '{}'); } catch { return; }\n const card = document.createElement('div');\n card.className = 'link-preview';\n card.setAttribute('role', 'dialog');\n card.setAttribute('aria-label', 'Link preview');\n card.hidden = true;\n document.body.appendChild(card);\n let current = null;\n const hide = () => { card.hidden = true; current = null; };\n const text = (className, tag, value) => {\n const el = document.createElement(tag);\n el.className = className;\n el.textContent = value;\n return el;\n };\n const show = (pill, preview) => {\n card.replaceChildren();\n const site = document.createElement('div');\n site.className = 'link-preview-site';\n const icon = pill.querySelector('.link-pill-icon, .link-pill-favicon');\n if (icon) site.appendChild(icon.cloneNode(true));\n let host = '';\n try { host = new URL(preview.url).hostname.replace(/^www\\./, ''); } catch {}\n site.appendChild(document.createTextNode(preview.site && preview.site.toLowerCase() !== host ? preview.site + ' \u00B7 ' + host : host));\n card.appendChild(site);\n if (preview.title) card.appendChild(text('link-preview-title', 'div', preview.title));\n if (preview.description) card.appendChild(text('link-preview-desc', 'p', preview.description));\n if (preview.image) {\n const img = document.createElement('img');\n img.className = 'link-preview-image';\n img.alt = '';\n img.loading = 'lazy';\n img.decoding = 'async';\n img.referrerPolicy = 'no-referrer';\n img.addEventListener('error', () => img.remove());\n img.src = preview.image;\n card.appendChild(img);\n }\n const open = document.createElement('a');\n open.className = 'link-preview-open';\n open.href = preview.url;\n open.target = '_blank';\n open.rel = 'noopener noreferrer';\n open.textContent = 'Open ' + host + ' \\u2197';\n card.appendChild(open);\n card.hidden = false;\n const rect = pill.getBoundingClientRect();\n const width = card.offsetWidth;\n const left = Math.max(12, Math.min(rect.left + window.scrollX, window.scrollX + document.documentElement.clientWidth - width - 12));\n card.style.left = left + 'px';\n card.style.top = (rect.bottom + window.scrollY + 8) + 'px';\n current = pill;\n open.focus({ preventScroll: true });\n };\n document.addEventListener('click', (event) => {\n const pill = event.target instanceof Element ? event.target.closest('a.link-pill') : null;\n if (pill) {\n if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || event.button !== 0) return;\n const preview = previews[pill.getAttribute('href') || ''];\n if (!preview) return;\n event.preventDefault();\n if (current === pill && !card.hidden) { hide(); return; }\n show(pill, preview);\n return;\n }\n if (!card.hidden && !card.contains(event.target)) hide();\n });\n document.addEventListener('keydown', (event) => {\n if (event.key === 'Escape' && !card.hidden) { hide(); if (current) current.focus(); }\n });\n window.addEventListener('resize', hide);\n})();\n</script>";