@warp-drive-mirror/experiments 0.2.7-beta.0 → 0.2.7-beta.2

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 (104) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/README.md +2 -1
  3. package/dist/data-worker.d.ts +35 -0
  4. package/dist/data-worker.d.ts.map +1 -0
  5. package/dist/data-worker.js +235 -339
  6. package/dist/data-worker.js.map +1 -0
  7. package/dist/document-storage-CwwTQ49-.d.ts +91 -0
  8. package/dist/document-storage-CwwTQ49-.d.ts.map +1 -0
  9. package/dist/document-storage-LM925Stz.js +270 -0
  10. package/dist/document-storage-LM925Stz.js.map +1 -0
  11. package/dist/document-storage.d.ts +2 -0
  12. package/dist/document-storage.js +3 -1
  13. package/dist/image-fetch.d.ts +60 -0
  14. package/dist/image-fetch.d.ts.map +1 -0
  15. package/dist/image-fetch.js +108 -79
  16. package/dist/image-fetch.js.map +1 -0
  17. package/dist/image-worker.d.ts +40 -0
  18. package/dist/image-worker.d.ts.map +1 -0
  19. package/dist/image-worker.js +95 -95
  20. package/dist/image-worker.js.map +1 -0
  21. package/dist/pagination.d.ts +2 -0
  22. package/dist/pagination.js +3 -0
  23. package/dist/storage.d.ts +354 -0
  24. package/dist/storage.d.ts.map +1 -0
  25. package/dist/storage.js +914 -0
  26. package/dist/storage.js.map +1 -0
  27. package/dist/types-CRs-Qww6.d.ts +17 -0
  28. package/dist/types-CRs-Qww6.d.ts.map +1 -0
  29. package/dist/unpkg/dev/data-worker.js +231 -338
  30. package/dist/unpkg/dev/data-worker.js.map +1 -0
  31. package/dist/unpkg/dev/document-storage-DkiEg9rY.js +268 -0
  32. package/dist/unpkg/dev/document-storage-DkiEg9rY.js.map +1 -0
  33. package/dist/unpkg/dev/document-storage.js +2 -348
  34. package/dist/unpkg/dev/image-fetch.js +104 -71
  35. package/dist/unpkg/dev/image-fetch.js.map +1 -0
  36. package/dist/unpkg/dev/image-worker.js +93 -94
  37. package/dist/unpkg/dev/image-worker.js.map +1 -0
  38. package/dist/unpkg/dev/pagination.js +3 -0
  39. package/dist/unpkg/dev/storage.js +913 -0
  40. package/dist/unpkg/dev/storage.js.map +1 -0
  41. package/dist/unpkg/dev/worker-fetch.js +112 -145
  42. package/dist/unpkg/dev/worker-fetch.js.map +1 -0
  43. package/dist/unpkg/dev-deprecated/data-worker.js +231 -338
  44. package/dist/unpkg/dev-deprecated/data-worker.js.map +1 -0
  45. package/dist/unpkg/dev-deprecated/document-storage-DkiEg9rY.js +268 -0
  46. package/dist/unpkg/dev-deprecated/document-storage-DkiEg9rY.js.map +1 -0
  47. package/dist/unpkg/dev-deprecated/document-storage.js +2 -348
  48. package/dist/unpkg/dev-deprecated/image-fetch.js +104 -71
  49. package/dist/unpkg/dev-deprecated/image-fetch.js.map +1 -0
  50. package/dist/unpkg/dev-deprecated/image-worker.js +93 -94
  51. package/dist/unpkg/dev-deprecated/image-worker.js.map +1 -0
  52. package/dist/unpkg/dev-deprecated/pagination.js +3 -0
  53. package/dist/unpkg/dev-deprecated/storage.js +913 -0
  54. package/dist/unpkg/dev-deprecated/storage.js.map +1 -0
  55. package/dist/unpkg/dev-deprecated/worker-fetch.js +112 -145
  56. package/dist/unpkg/dev-deprecated/worker-fetch.js.map +1 -0
  57. package/dist/unpkg/prod/data-worker.js +224 -324
  58. package/dist/unpkg/prod/data-worker.js.map +1 -0
  59. package/dist/unpkg/prod/document-storage-D0k_6GM9.js +262 -0
  60. package/dist/unpkg/prod/document-storage-D0k_6GM9.js.map +1 -0
  61. package/dist/unpkg/prod/document-storage.js +2 -338
  62. package/dist/unpkg/prod/image-fetch.js +101 -71
  63. package/dist/unpkg/prod/image-fetch.js.map +1 -0
  64. package/dist/unpkg/prod/image-worker.js +93 -94
  65. package/dist/unpkg/prod/image-worker.js.map +1 -0
  66. package/dist/unpkg/prod/pagination.js +3 -0
  67. package/dist/unpkg/prod/storage.js +844 -0
  68. package/dist/unpkg/prod/storage.js.map +1 -0
  69. package/dist/unpkg/prod/worker-fetch.js +109 -145
  70. package/dist/unpkg/prod/worker-fetch.js.map +1 -0
  71. package/dist/unpkg/prod-deprecated/data-worker.js +224 -324
  72. package/dist/unpkg/prod-deprecated/data-worker.js.map +1 -0
  73. package/dist/unpkg/prod-deprecated/document-storage-D0k_6GM9.js +262 -0
  74. package/dist/unpkg/prod-deprecated/document-storage-D0k_6GM9.js.map +1 -0
  75. package/dist/unpkg/prod-deprecated/document-storage.js +2 -338
  76. package/dist/unpkg/prod-deprecated/image-fetch.js +101 -71
  77. package/dist/unpkg/prod-deprecated/image-fetch.js.map +1 -0
  78. package/dist/unpkg/prod-deprecated/image-worker.js +93 -94
  79. package/dist/unpkg/prod-deprecated/image-worker.js.map +1 -0
  80. package/dist/unpkg/prod-deprecated/pagination.js +3 -0
  81. package/dist/unpkg/prod-deprecated/storage.js +844 -0
  82. package/dist/unpkg/prod-deprecated/storage.js.map +1 -0
  83. package/dist/unpkg/prod-deprecated/worker-fetch.js +109 -145
  84. package/dist/unpkg/prod-deprecated/worker-fetch.js.map +1 -0
  85. package/dist/worker-fetch.d.ts +23 -0
  86. package/dist/worker-fetch.d.ts.map +1 -0
  87. package/dist/worker-fetch.js +116 -153
  88. package/dist/worker-fetch.js.map +1 -0
  89. package/package.json +27 -23
  90. package/declarations/data-worker/cache-handler.d.ts +0 -7
  91. package/declarations/data-worker/fetch.d.ts +0 -21
  92. package/declarations/data-worker/types.d.ts +0 -31
  93. package/declarations/data-worker/utils.d.ts +0 -12
  94. package/declarations/data-worker/worker.d.ts +0 -23
  95. package/declarations/data-worker.d.ts +0 -2
  96. package/declarations/document-storage/index.d.ts +0 -90
  97. package/declarations/document-storage.d.ts +0 -1
  98. package/declarations/image-fetch.d.ts +0 -1
  99. package/declarations/image-worker/fetch.d.ts +0 -18
  100. package/declarations/image-worker/types.d.ts +0 -21
  101. package/declarations/image-worker/worker.d.ts +0 -14
  102. package/declarations/image-worker.d.ts +0 -1
  103. package/declarations/worker-fetch.d.ts +0 -1
  104. package/dist/index-CGCX7hY2.js +0 -349
@@ -1,80 +1,109 @@
1
- import { createDeferred } from '@warp-drive-mirror/core/request';
2
- import { macroCondition, getGlobalConfig } from '@embroider/macros';
1
+ import { getGlobalConfig, macroCondition } from "@embroider/macros";
2
+ import { createDeferred } from "@warp-drive-mirror/core/request";
3
3
 
4
- // @ts-expect-error untyped global
5
- const isServerEnv = typeof FastBoot !== 'undefined';
6
- class ImageFetch {
7
- constructor(worker) {
8
- this.threadId = isServerEnv ? '' : crypto.randomUUID();
9
- this.pending = new Map();
10
- this.cache = new Map();
11
- const isTesting = macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING) ? true : false;
12
- macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) ? (test => {
13
- if (!test) {
14
- throw new Error(`Expected a SharedWorker instance`);
15
- }
16
- })(isTesting || isServerEnv || worker instanceof SharedWorker) : {};
17
- this.worker = worker;
18
- if (!isServerEnv) {
19
- const fn = event => {
20
- const {
21
- type,
22
- url
23
- } = event.data;
24
- const deferred = this.cleanupRequest(url);
25
- if (!deferred) {
26
- return;
27
- }
28
- if (type === 'success-response') {
29
- deferred.resolve(url);
30
- return;
31
- }
32
- if (type === 'error-response') {
33
- deferred.reject(null);
34
- return;
35
- }
36
- };
37
- if (worker instanceof SharedWorker) {
38
- worker.port.postMessage({
39
- type: 'connect',
40
- thread: this.threadId
41
- });
42
- worker.port.onmessage = fn;
43
- } else if (worker) {
44
- this.channel = new MessageChannel();
45
- worker.postMessage({
46
- type: 'connect',
47
- thread: this.threadId
48
- }, [this.channel.port2]);
49
- this.channel.port1.onmessage = fn;
50
- }
51
- }
52
- }
53
- cleanupRequest(url) {
54
- const deferred = this.pending.get(url);
55
- this.pending.delete(url);
56
- return deferred;
57
- }
58
- _send(event) {
59
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
60
- this.worker instanceof SharedWorker ? this.worker.port.postMessage(event) : this.channel.port1.postMessage(event);
61
- }
62
- load(url) {
63
- if (isServerEnv) {
64
- return Promise.resolve(url);
65
- }
66
- const objectUrl = this.cache.get(url);
67
- if (objectUrl) {
68
- return Promise.resolve(objectUrl);
69
- }
70
- const deferred = createDeferred();
71
- this.pending.set(url, deferred);
72
- this._send({
73
- type: 'load',
74
- thread: this.threadId,
75
- url
76
- });
77
- return deferred.promise;
78
- }
79
- }
80
- export { ImageFetch };
4
+ //#region src/image-worker/fetch.ts
5
+ const isServerEnv = typeof FastBoot !== "undefined";
6
+ /**
7
+ * Main-thread client for an {@link ImageWorker}. Sends image `load`
8
+ * requests to a `Worker` or `SharedWorker` running an `ImageWorker`.
9
+ *
10
+ * In FastBoot/SSR, or when constructed with a `null` worker, `ImageFetch`
11
+ * skips worker communication entirely: {@link ImageFetch.load} resolves
12
+ * immediately with the given url.
13
+ *
14
+ * A plain `Worker` is only accepted when running in a `TESTING` build;
15
+ * production usage requires a `SharedWorker`.
16
+ *
17
+ * @public
18
+ */
19
+ var ImageFetch = class {
20
+ /**
21
+ * @param worker - the `Worker` or `SharedWorker` running an
22
+ * {@link ImageWorker}, or `null` to disable worker communication (e.g.
23
+ * in FastBoot/SSR).
24
+ */
25
+ constructor(worker) {
26
+ this.threadId = isServerEnv ? "" : crypto.randomUUID();
27
+ this.pending = /* @__PURE__ */ new Map();
28
+ this.cache = /* @__PURE__ */ new Map();
29
+ const isTesting = macroCondition(getGlobalConfig().WarpDriveMirror.env.TESTING) ? true : false;
30
+ macroCondition(getGlobalConfig().WarpDriveMirror.env.DEBUG) && ((test) => {
31
+ if (!test) throw new Error(`Expected a SharedWorker instance`);
32
+ })(isTesting || isServerEnv || worker instanceof SharedWorker);
33
+ this.worker = worker;
34
+ if (!isServerEnv) {
35
+ const fn = (event) => {
36
+ const { type, url } = event.data;
37
+ const deferred = this.cleanupRequest(url);
38
+ if (!deferred) return;
39
+ if (type === "success-response") {
40
+ const { objectUrl } = event.data;
41
+ this.cache.set(url, objectUrl);
42
+ deferred.resolve(objectUrl);
43
+ return;
44
+ }
45
+ if (type === "error-response") {
46
+ deferred.reject(null);
47
+ return;
48
+ }
49
+ };
50
+ if (worker instanceof SharedWorker) {
51
+ worker.port.postMessage({
52
+ type: "connect",
53
+ thread: this.threadId
54
+ });
55
+ worker.port.onmessage = fn;
56
+ } else if (worker) {
57
+ this.channel = new MessageChannel();
58
+ worker.postMessage({
59
+ type: "connect",
60
+ thread: this.threadId
61
+ }, [this.channel.port2]);
62
+ this.channel.port1.onmessage = fn;
63
+ }
64
+ }
65
+ }
66
+ cleanupRequest(url) {
67
+ const deferred = this.pending.get(url);
68
+ this.pending.delete(url);
69
+ return deferred;
70
+ }
71
+ _send(event) {
72
+ this.worker instanceof SharedWorker ? this.worker.port.postMessage(event) : this.channel.port1.postMessage(event);
73
+ }
74
+ /**
75
+ * Requests that the given image url be loaded by the connected
76
+ * {@link ImageWorker}, resolving with an object url for the fetched
77
+ * image's blob once the worker responds (or immediately with the
78
+ * original `url`, in SSR/FastBoot or when this instance was constructed
79
+ * with a `null` worker).
80
+ *
81
+ * The resolved object url is cached in-memory by source url on this
82
+ * instance, so subsequent calls for the same url resolve immediately
83
+ * without another round-trip to the worker.
84
+ *
85
+ * Calling `load` again for a url that is already in-flight (not yet
86
+ * cached) on this instance replaces the pending request rather than
87
+ * joining it — only the most recently issued call for a given url will
88
+ * resolve.
89
+ *
90
+ * @public
91
+ */
92
+ load(url) {
93
+ if (isServerEnv) return Promise.resolve(url);
94
+ const objectUrl = this.cache.get(url);
95
+ if (objectUrl) return Promise.resolve(objectUrl);
96
+ const deferred = createDeferred();
97
+ this.pending.set(url, deferred);
98
+ this._send({
99
+ type: "load",
100
+ thread: this.threadId,
101
+ url
102
+ });
103
+ return deferred.promise;
104
+ }
105
+ };
106
+
107
+ //#endregion
108
+ export { ImageFetch };
109
+ //# sourceMappingURL=image-fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-fetch.js","names":["createDeferred","getGlobalConfig","macroCondition","isServerEnv","FastBoot","ImageFetch","constructor","worker","threadId","crypto","randomUUID","pending","Map","cache","isTesting","WarpDrive","env","TESTING","DEBUG","test","Error","SharedWorker","fn","event","type","url","data","deferred","cleanupRequest","objectUrl","set","resolve","reject","port","postMessage","thread","onmessage","channel","MessageChannel","port2","port1","get","delete","_send","load","Promise","promise"],"sources":["../src/image-worker/fetch.ts"],"sourcesContent":["import { TESTING } from '@warp-drive-mirror/core/build-config/env';\nimport { assert } from '@warp-drive-mirror/core/build-config/macros';\nimport type { Deferred } from '@warp-drive-mirror/core/request';\nimport { createDeferred } from '@warp-drive-mirror/core/request';\n\nimport type { MainThreadEvent, RequestEventData } from './types';\n// oxlint-disable-next-line no-unused-vars\nimport type { ImageWorker } from './worker';\n\nexport interface FastBoot {\n require(moduleName: string): unknown;\n isFastBoot: boolean;\n request: Request;\n}\n\n// @ts-expect-error untyped global\nconst isServerEnv = typeof FastBoot !== 'undefined';\n\n/**\n * Main-thread client for an {@link ImageWorker}. Sends image `load`\n * requests to a `Worker` or `SharedWorker` running an `ImageWorker`.\n *\n * In FastBoot/SSR, or when constructed with a `null` worker, `ImageFetch`\n * skips worker communication entirely: {@link ImageFetch.load} resolves\n * immediately with the given url.\n *\n * A plain `Worker` is only accepted when running in a `TESTING` build;\n * production usage requires a `SharedWorker`.\n *\n * @public\n */\nexport class ImageFetch {\n declare worker: Worker | SharedWorker;\n declare threadId: string;\n declare pending: Map<string, Deferred<string>>;\n declare channel: MessageChannel;\n declare cache: Map<string, string>;\n\n /**\n * @param worker - the `Worker` or `SharedWorker` running an\n * {@link ImageWorker}, or `null` to disable worker communication (e.g.\n * in FastBoot/SSR).\n */\n constructor(worker: Worker | SharedWorker | null) {\n this.threadId = isServerEnv ? '' : crypto.randomUUID();\n this.pending = new Map();\n this.cache = new Map();\n\n const isTesting = TESTING ? true : false;\n assert(`Expected a SharedWorker instance`, isTesting || isServerEnv || worker instanceof SharedWorker);\n this.worker = worker as SharedWorker;\n\n if (!isServerEnv) {\n const fn = (event: MainThreadEvent) => {\n const { type, url } = event.data;\n const deferred = this.cleanupRequest(url);\n if (!deferred) {\n return;\n }\n\n if (type === 'success-response') {\n const { objectUrl } = event.data;\n this.cache.set(url, objectUrl);\n deferred.resolve(objectUrl);\n return;\n }\n\n if (type === 'error-response') {\n deferred.reject(null);\n return;\n }\n };\n\n if (worker instanceof SharedWorker) {\n worker.port.postMessage({ type: 'connect', thread: this.threadId });\n worker.port.onmessage = fn;\n } else if (worker) {\n this.channel = new MessageChannel();\n worker.postMessage({ type: 'connect', thread: this.threadId }, [this.channel.port2]);\n\n this.channel.port1.onmessage = fn;\n }\n }\n }\n\n cleanupRequest(url: string): Deferred<string> | undefined {\n const deferred = this.pending.get(url);\n this.pending.delete(url);\n\n return deferred;\n }\n\n _send(event: RequestEventData): void {\n // oxlint-disable-next-line no-unused-expressions\n this.worker instanceof SharedWorker ? this.worker.port.postMessage(event) : this.channel.port1.postMessage(event);\n }\n\n /**\n * Requests that the given image url be loaded by the connected\n * {@link ImageWorker}, resolving with an object url for the fetched\n * image's blob once the worker responds (or immediately with the\n * original `url`, in SSR/FastBoot or when this instance was constructed\n * with a `null` worker).\n *\n * The resolved object url is cached in-memory by source url on this\n * instance, so subsequent calls for the same url resolve immediately\n * without another round-trip to the worker.\n *\n * Calling `load` again for a url that is already in-flight (not yet\n * cached) on this instance replaces the pending request rather than\n * joining it — only the most recently issued call for a given url will\n * resolve.\n *\n * @public\n */\n load(url: string): Promise<string> {\n if (isServerEnv) {\n return Promise.resolve(url);\n }\n\n const objectUrl = this.cache.get(url);\n if (objectUrl) {\n return Promise.resolve(objectUrl);\n }\n\n const deferred = createDeferred<string>();\n this.pending.set(url, deferred);\n this._send({ type: 'load', thread: this.threadId, url });\n return deferred.promise;\n }\n}\n"],"mappings":";;;;AAgBA,MAAMG,cAAc,OAAOC,aAAa;;;;;;;;;;;;;;AAexC,IAAaC,aAAb,MAAwB;;;;;;CAYtBC,YAAYC,QAAsC;EAChD,KAAKC,WAAWL,cAAc,KAAKM,O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EAEnC,KAAKhB,kBAAkBc,eAAe,KAAKd,OAAO0B,KAAKC,YAAYX,KAAK,IAAI,KAAKc,QAAQG,MAAMN,YAAYX,KAAK;CAClH;;;;;;;;;;;;;;;;;;;CAoBAqB,KAAKnB,KAA8B;EACjC,IAAItB,aACF,OAAO0C,QAAQd,QAAQN,GAAG;EAG5B,MAAMI,YAAY,KAAKhB,MAAM4B,IAAIhB,GAAG;EACpC,IAAII,WACF,OAAOgB,QAAQd,QAAQF,SAAS;EAGlC,MAAMF,WAAW3B,eAAuB;EACxC,KAAKW,QAAQmB,IAAIL,KAAKE,QAAQ;EAC9B,KAAKgB,MAAM;GAAEnB,MAAM;GAAQW,QAAQ,KAAK3B;GAAUiB;EAAI,CAAC;EACvD,OAAOE,SAASmB;CAClB;AACF"}
@@ -0,0 +1,40 @@
1
+ //#region src/image-worker/worker.d.ts
2
+ /**
3
+ * Runs inside a `Worker` or `SharedWorker` to fetch images on behalf of
4
+ * one or more {@link ImageFetch} instances running on the main thread(s)
5
+ * that connect to it.
6
+ *
7
+ * Each connecting thread registers itself by sending a `connect` message
8
+ * along with a {@link MessagePort}. When a thread sends a `load` request
9
+ * for a url, the worker fetches the image via `fetch`, converts the
10
+ * response into a `Blob`, and creates an object url for it via
11
+ * `URL.createObjectURL`. The fetch for a given url is deduped and cached
12
+ * in-memory for the lifetime of the worker, so repeat `load` requests for
13
+ * the same url — whether from the same or a different connected thread —
14
+ * do not trigger another network request.
15
+ *
16
+ * Only intended for use inside a Worker context: constructing an
17
+ * `ImageWorker` on the main thread is a no-op.
18
+ *
19
+ * @public
20
+ */
21
+ declare class ImageWorker {
22
+ private threads;
23
+ private pendingImages;
24
+ private options;
25
+ private isSharedWorker;
26
+ private cache;
27
+ /**
28
+ * @param options.persisted - reserved for a future on-disk cache; currently unused.
29
+ */
30
+ constructor(options?: {
31
+ persisted: boolean;
32
+ });
33
+ private fetch;
34
+ private initialize;
35
+ private setupThread;
36
+ private request;
37
+ }
38
+ //#endregion
39
+ export { ImageWorker };
40
+ //# sourceMappingURL=image-worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-worker.d.ts","names":[],"sources":["../src/image-worker/worker.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;cA+Ba;UACK;UACA;UACA;UACA;UACA;;;;EAKhB,YAAY;IAAY;;UAahB;UAsBA;UA4BA;UAiBM"}
@@ -1,98 +1,98 @@
1
+ //#region src/image-worker/worker.ts
1
2
  const WorkerScope = globalThis.SharedWorkerGlobalScope;
2
3
  async function loadImage(url) {
3
- const response = await fetch(url);
4
- const fileBlob = await response.blob();
5
- return URL.createObjectURL(fileBlob);
4
+ const fileBlob = await (await fetch(url)).blob();
5
+ return URL.createObjectURL(fileBlob);
6
6
  }
7
- class ImageWorker {
8
- constructor(options) {
9
- // disable if running on main thread
10
- if (typeof window !== 'undefined') {
11
- return;
12
- }
13
- this.threads = new Map();
14
- this.pendingImages = new Map();
15
- this.cache = new Map();
16
- this.options = options || {
17
- persisted: false
18
- };
19
- this.isSharedWorker = WorkerScope && globalThis instanceof WorkerScope;
20
- this.initialize();
21
- }
22
- fetch(url) {
23
- const objectUrl = this.cache.get(url);
24
- if (objectUrl) {
25
- return Promise.resolve(objectUrl);
26
- }
27
- const pending = this.pendingImages.get(url);
28
- if (pending) {
29
- return pending;
30
- }
31
- const promise = loadImage(url);
32
- this.pendingImages.set(url, promise);
33
- return promise.finally(() => {
34
- this.pendingImages.delete(url);
35
- });
36
- }
37
- initialize() {
38
- if (this.isSharedWorker) {
39
- globalThis.onconnect = e => {
40
- const port = e.ports[0];
41
- port.onmessage = event => {
42
- const {
43
- type
44
- } = event.data;
45
- switch (type) {
46
- case 'connect':
47
- this.setupThread(event.data.thread, port);
48
- break;
49
- }
50
- };
51
- port.start();
52
- };
53
- } else {
54
- globalThis.onmessage = event => {
55
- const {
56
- type
57
- } = event.data;
58
- switch (type) {
59
- case 'connect':
60
- this.setupThread(event.data.thread, event.ports[0]);
61
- break;
62
- }
63
- };
64
- }
65
- }
66
- setupThread(thread, port) {
67
- this.threads.set(thread, port);
68
- port.onmessage = event => {
69
- if (event.type === 'close') {
70
- this.threads.delete(thread);
71
- return;
72
- }
73
- const {
74
- type
75
- } = event.data;
76
- switch (type) {
77
- case 'load':
78
- void this.request(event.data);
79
- break;
80
- }
81
- };
82
- }
83
- async request(event) {
84
- const {
85
- thread,
86
- url
87
- } = event;
88
- const objectUrl = await this.fetch(url);
89
- const port = this.threads.get(thread);
90
- port.postMessage({
91
- type: 'success-response',
92
- thread,
93
- url,
94
- objectUrl
95
- });
96
- }
97
- }
98
- export { ImageWorker };
7
+ /**
8
+ * Runs inside a `Worker` or `SharedWorker` to fetch images on behalf of
9
+ * one or more {@link ImageFetch} instances running on the main thread(s)
10
+ * that connect to it.
11
+ *
12
+ * Each connecting thread registers itself by sending a `connect` message
13
+ * along with a {@link MessagePort}. When a thread sends a `load` request
14
+ * for a url, the worker fetches the image via `fetch`, converts the
15
+ * response into a `Blob`, and creates an object url for it via
16
+ * `URL.createObjectURL`. The fetch for a given url is deduped and cached
17
+ * in-memory for the lifetime of the worker, so repeat `load` requests for
18
+ * the same url — whether from the same or a different connected thread —
19
+ * do not trigger another network request.
20
+ *
21
+ * Only intended for use inside a Worker context: constructing an
22
+ * `ImageWorker` on the main thread is a no-op.
23
+ *
24
+ * @public
25
+ */
26
+ var ImageWorker = class {
27
+ /**
28
+ * @param options.persisted - reserved for a future on-disk cache; currently unused.
29
+ */
30
+ constructor(options) {
31
+ if (typeof window !== "undefined") return;
32
+ this.threads = /* @__PURE__ */ new Map();
33
+ this.pendingImages = /* @__PURE__ */ new Map();
34
+ this.cache = /* @__PURE__ */ new Map();
35
+ this.options = options || { persisted: false };
36
+ this.isSharedWorker = WorkerScope && globalThis instanceof WorkerScope;
37
+ this.initialize();
38
+ }
39
+ fetch(url) {
40
+ const objectUrl = this.cache.get(url);
41
+ if (objectUrl) return Promise.resolve(objectUrl);
42
+ const pending = this.pendingImages.get(url);
43
+ if (pending) return pending;
44
+ const promise = loadImage(url).then((loadedObjectUrl) => {
45
+ this.cache.set(url, loadedObjectUrl);
46
+ return loadedObjectUrl;
47
+ });
48
+ this.pendingImages.set(url, promise);
49
+ return promise.finally(() => {
50
+ this.pendingImages.delete(url);
51
+ });
52
+ }
53
+ initialize() {
54
+ if (this.isSharedWorker) globalThis.onconnect = (e) => {
55
+ const port = e.ports[0];
56
+ port.onmessage = (event) => {
57
+ const { type } = event.data;
58
+ switch (type) {
59
+ case "connect": this.setupThread(event.data.thread, port);
60
+ }
61
+ };
62
+ port.start();
63
+ };
64
+ else globalThis.onmessage = (event) => {
65
+ const { type } = event.data;
66
+ switch (type) {
67
+ case "connect": this.setupThread(event.data.thread, event.ports[0]);
68
+ }
69
+ };
70
+ }
71
+ setupThread(thread, port) {
72
+ this.threads.set(thread, port);
73
+ port.onmessage = (event) => {
74
+ if (event.type === "close") {
75
+ this.threads.delete(thread);
76
+ return;
77
+ }
78
+ const { type } = event.data;
79
+ switch (type) {
80
+ case "load": this.request(event.data);
81
+ }
82
+ };
83
+ }
84
+ async request(event) {
85
+ const { thread, url } = event;
86
+ const objectUrl = await this.fetch(url);
87
+ this.threads.get(thread).postMessage({
88
+ type: "success-response",
89
+ thread,
90
+ url,
91
+ objectUrl
92
+ });
93
+ }
94
+ };
95
+
96
+ //#endregion
97
+ export { ImageWorker };
98
+ //# sourceMappingURL=image-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-worker.js","names":["WorkerScope","globalThis","SharedWorkerGlobalScope","loadImage","url","response","fetch","fileBlob","blob","URL","createObjectURL","ImageWorker","constructor","options","window","threads","Map","pendingImages","cache","persisted","isSharedWorker","initialize","objectUrl","get","Promise","resolve","pending","promise","then","loadedObjectUrl","set","finally","delete","onconnect","e","port","ports","onmessage","event","type","data","setupThread","thread","start","request","postMessage"],"sources":["../src/image-worker/worker.ts"],"sourcesContent":["// oxlint-disable-next-line no-unused-vars\nimport type { ImageFetch } from './fetch';\nimport type { RequestEventData, ThreadInitEventData, WorkerThreadEvent } from './types';\n\nconst WorkerScope = (globalThis as unknown as { SharedWorkerGlobalScope: FunctionConstructor }).SharedWorkerGlobalScope;\n\nasync function loadImage(url: string): Promise<string> {\n const response = await fetch(url);\n const fileBlob = await response.blob();\n return URL.createObjectURL(fileBlob);\n}\n\n/**\n * Runs inside a `Worker` or `SharedWorker` to fetch images on behalf of\n * one or more {@link ImageFetch} instances running on the main thread(s)\n * that connect to it.\n *\n * Each connecting thread registers itself by sending a `connect` message\n * along with a {@link MessagePort}. When a thread sends a `load` request\n * for a url, the worker fetches the image via `fetch`, converts the\n * response into a `Blob`, and creates an object url for it via\n * `URL.createObjectURL`. The fetch for a given url is deduped and cached\n * in-memory for the lifetime of the worker, so repeat `load` requests for\n * the same url — whether from the same or a different connected thread —\n * do not trigger another network request.\n *\n * Only intended for use inside a Worker context: constructing an\n * `ImageWorker` on the main thread is a no-op.\n *\n * @public\n */\nexport class ImageWorker {\n declare private threads: Map<string, MessagePort>;\n declare private pendingImages: Map<string, Promise<string>>;\n declare private options: { persisted: boolean };\n declare private isSharedWorker: boolean;\n declare private cache: Map<string, string>;\n\n /**\n * @param options.persisted - reserved for a future on-disk cache; currently unused.\n */\n constructor(options?: { persisted: boolean }) {\n // disable if running on main thread\n if (typeof window !== 'undefined') {\n return;\n }\n this.threads = new Map();\n this.pendingImages = new Map();\n this.cache = new Map();\n this.options = options || { persisted: false };\n this.isSharedWorker = WorkerScope && globalThis instanceof WorkerScope;\n this.initialize();\n }\n\n private fetch(url: string): Promise<string> {\n const objectUrl = this.cache.get(url);\n\n if (objectUrl) {\n return Promise.resolve(objectUrl);\n }\n\n const pending = this.pendingImages.get(url);\n if (pending) {\n return pending;\n }\n\n const promise = loadImage(url).then((loadedObjectUrl) => {\n this.cache.set(url, loadedObjectUrl);\n return loadedObjectUrl;\n });\n this.pendingImages.set(url, promise);\n return promise.finally(() => {\n this.pendingImages.delete(url);\n });\n }\n\n private initialize(): void {\n if (this.isSharedWorker) {\n (globalThis as unknown as { onconnect: typeof globalThis.onmessage }).onconnect = (e) => {\n const port = e.ports[0];\n port.onmessage = (event: MessageEvent<ThreadInitEventData>) => {\n const { type } = event.data;\n\n switch (type) {\n case 'connect':\n this.setupThread(event.data.thread, port);\n break;\n }\n };\n port.start();\n };\n } else {\n globalThis.onmessage = (event: MessageEvent<ThreadInitEventData>) => {\n const { type } = event.data;\n\n switch (type) {\n case 'connect':\n this.setupThread(event.data.thread, event.ports[0]);\n break;\n }\n };\n }\n }\n\n private setupThread(thread: string, port: MessagePort): void {\n this.threads.set(thread, port);\n port.onmessage = (event: WorkerThreadEvent) => {\n if (event.type === 'close') {\n this.threads.delete(thread);\n return;\n }\n\n const { type } = event.data;\n switch (type) {\n case 'load':\n void this.request(event.data);\n break;\n }\n };\n }\n\n private async request(event: RequestEventData): Promise<void> {\n const { thread, url } = event;\n\n const objectUrl = await this.fetch(url);\n const port = this.threads.get(thread)!;\n port.postMessage({ type: 'success-response', thread, url, objectUrl });\n }\n}\n"],"mappings":";AAIA,MAAMA,cAAeC,WAA2EC;AAEhG,eAAeC,UAAUC,KAA8B;CAErD,MAAMG,WAAW,OAAMF,MADAC,MAAMF,GAAG,EACD,CAACI,KAAK;CACrC,OAAOC,IAAIC,gBAAgBH,QAAQ;AACrC;;;;;;;;;;;;;;;;;;;;AAqBA,IAAaI,cAAb,MAAyB;;;;CAUvBC,YAAYC,SAAkC;EAE5C,IAAI,OAAOC,WAAW,aACpB;EAEF,KAAKC,0BAAU,IAAIC,IAAI;EACvB,KAAKC,gCAAgB,IAAID,IAAI;EAC7B,KAAKE,wBAAQ,IAAIF,IAAI;EACrB,KAAKH,UAAUA,WAAW,EAAEM,WAAW,MAAM;EAC7C,KAAKC,iBAAiBpB,eAAeC,sBAAsBD;EAC3D,KAAKqB,WAAW;CAClB;CAEQf,MAAMF,KAA8B;EAC1C,MAAMkB,YAAY,KAAKJ,MAAMK,IAAInB,GAAG;EAEpC,IAAIkB,WACF,OA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KAAKpB,QAAQQ,IAAImB,MAC9BP,CAAI,CAACU,YAAY;GAAEN,MAAM;GAAoBG;GAAQtC;GAAKkB;EAAU,CAAC;CACvE;AACF"}
@@ -0,0 +1,2 @@
1
+ import { InfinitePaginationContentFeatures, InfinitePaginationState, PageCache, PageHints, PagedPaginationContentFeatures, PagedPaginationState, PaginateArgs, PaginateMode, PaginationCache, PaginationContentFeatures, PaginationContentFeaturesFor, PaginationLink, PaginationLinks, PaginationLinksSubscription, PaginationState, PaginationStateFor, PaginationSubscription, PlaceholderPaginationLink, RealPaginationLink, RelationalPaginationLink, SharedPaginationContentFeatures, SharedPaginationState, clearPaginationCache, createPaginationLinksSubscription, createPaginationSubscription, defaultPageHints, getPaginationCache, getPaginationLinks, getPaginationState } from "@warp-drive-mirror/core/signals/-leaked";
2
+ export { type InfinitePaginationContentFeatures, type InfinitePaginationState, type PageCache, type PageHints, type PagedPaginationContentFeatures, type PagedPaginationState, type PaginateArgs, type PaginateMode, type PaginationCache, type PaginationContentFeatures, type PaginationContentFeaturesFor, type PaginationLink, type PaginationLinks, type PaginationLinksSubscription, type PaginationState, type PaginationStateFor, type PaginationSubscription, type PlaceholderPaginationLink, type RealPaginationLink, type RelationalPaginationLink, type SharedPaginationContentFeatures, type SharedPaginationState, clearPaginationCache, createPaginationLinksSubscription, createPaginationSubscription, defaultPageHints, getPaginationCache, getPaginationLinks, getPaginationState };
@@ -0,0 +1,3 @@
1
+ import { clearPaginationCache, createPaginationLinksSubscription, createPaginationSubscription, defaultPageHints, getPaginationCache, getPaginationLinks, getPaginationState } from "@warp-drive-mirror/core/signals/-leaked";
2
+
3
+ export { clearPaginationCache, createPaginationLinksSubscription, createPaginationSubscription, defaultPageHints, getPaginationCache, getPaginationLinks, getPaginationState };