@pagepocket/lib 0.12.0 → 0.14.5

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 (34) hide show
  1. package/dist/core/pagepocket.d.ts +17 -0
  2. package/dist/core/pagepocket.js +25 -1
  3. package/dist/hackers/index.js +3 -1
  4. package/dist/hackers/replay-dom-rewrite/script-part-1.d.ts +1 -1
  5. package/dist/hackers/replay-dom-rewrite/script-part-1.js +40 -51
  6. package/dist/hackers/replay-dom-rewrite/script-part-2.d.ts +1 -1
  7. package/dist/hackers/replay-dom-rewrite/script-part-2.js +74 -44
  8. package/dist/hackers/replay-fetch.js +4 -0
  9. package/dist/hackers/replay-websocket.js +50 -8
  10. package/dist/hackers/replay-worker.d.ts +18 -0
  11. package/dist/hackers/replay-worker.js +242 -0
  12. package/dist/index.d.ts +1 -0
  13. package/dist/replay/match-api.js +103 -3
  14. package/dist/replay/templates/loader-template.d.ts +15 -0
  15. package/dist/replay/templates/loader-template.js +164 -0
  16. package/dist/replay/templates/match-api-source.d.ts +1 -1
  17. package/dist/replay/templates/match-api-source.js +86 -4
  18. package/dist/replay/templates/replay-script-template.part-2.js +24 -1
  19. package/dist/resource-filter.js +29 -3
  20. package/dist/snapshot-builder/build-snapshot.js +33 -3
  21. package/dist/units/apply-replace-elements-to-file-tree.d.ts +7 -0
  22. package/dist/units/apply-replace-elements-to-file-tree.js +63 -0
  23. package/dist/units/contracts-bridge.d.ts +9 -1
  24. package/dist/units/file-tree-unit.d.ts +28 -0
  25. package/dist/units/file-tree-unit.js +53 -0
  26. package/dist/units/index.d.ts +3 -0
  27. package/dist/units/index.js +2 -0
  28. package/dist/units/internal/runtime.d.ts +5 -2
  29. package/dist/units/internal/runtime.js +14 -0
  30. package/dist/units/runner.d.ts +3 -1
  31. package/dist/units/runner.js +72 -2
  32. package/dist/units/snapshot-unit.d.ts +31 -0
  33. package/dist/units/snapshot-unit.js +58 -0
  34. package/package.json +4 -4
@@ -0,0 +1,58 @@
1
+ import { applyReplaceElementsToFileTree } from "./apply-replace-elements-to-file-tree.js";
2
+ import { FileTreeUnit } from "./file-tree-unit.js";
3
+ /**
4
+ * Base class for units that produce the primary snapshot FileTree.
5
+ *
6
+ * `run()` delegates to `build()` and automatically:
7
+ * - Injects `snapshotType` into the returned patch.
8
+ * - Compiles all plugin-contributed element-replacement rules
9
+ * (`rt.elements.compile()`) and applies them to every HTML file
10
+ * in the returned FileTree. Subclasses never need to call
11
+ * `rt.elements.compile()` themselves.
12
+ *
13
+ * Subclasses implement `id`, `snapshotType`, and `build()`.
14
+ *
15
+ * ```ts
16
+ * export class MySnapshotUnit extends SnapshotUnit {
17
+ * readonly id = "mySnapshot";
18
+ * readonly snapshotType = "my-type";
19
+ *
20
+ * async build(ctx, rt) {
21
+ * return { files: buildFiles(), html: ctx.value.html };
22
+ * }
23
+ * }
24
+ * ```
25
+ */
26
+ export class SnapshotUnit extends FileTreeUnit {
27
+ async run(ctx, rt) {
28
+ const patch = await this.build(ctx, rt);
29
+ if (!patch) {
30
+ return;
31
+ }
32
+ const files = patch.files;
33
+ const replaceElements = await rt.elements.compile();
34
+ if (files && replaceElements.length > 0) {
35
+ const entryUrl = resolveEntryUrl(rt);
36
+ const updatedFiles = await applyReplaceElementsToFileTree({
37
+ files,
38
+ replaceElements,
39
+ entryUrl
40
+ });
41
+ return { ...patch, files: updatedFiles, snapshotType: this.snapshotType };
42
+ }
43
+ return { ...patch, snapshotType: this.snapshotType };
44
+ }
45
+ }
46
+ const resolveEntryUrl = (rt) => {
47
+ const entry = rt.entry;
48
+ if (entry.kind === "url") {
49
+ return entry.url;
50
+ }
51
+ if (entry.kind === "html-string" || entry.kind === "document") {
52
+ return entry.url ?? entry.baseUrl;
53
+ }
54
+ if (entry.kind === "puppeteer-page" || entry.kind === "cdp-tab") {
55
+ return entry.url ?? "";
56
+ }
57
+ return "";
58
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagepocket/lib",
3
- "version": "0.12.0",
3
+ "version": "0.14.5",
4
4
  "description": "Library for rewriting HTML snapshots and inlining local resources.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -20,9 +20,9 @@
20
20
  "dependencies": {
21
21
  "cheerio": "^1.0.0-rc.12",
22
22
  "domhandler": "^5.0.3",
23
- "@pagepocket/contracts": "0.12.0",
24
- "@pagepocket/uni-fs": "0.12.0",
25
- "@pagepocket/shared": "0.12.0"
23
+ "@pagepocket/contracts": "0.14.5",
24
+ "@pagepocket/uni-fs": "0.14.5",
25
+ "@pagepocket/shared": "0.14.5"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@playwright/test": "^1.50.1",