nuxt-tiff-provider 0.4.0 → 0.5.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/README.md CHANGED
@@ -35,6 +35,7 @@ export default defineNuxtConfig({
35
35
  retryRacedImages: true, // re-fetch images that raced the SW on first load
36
36
  paramPrefix: 'tp', // query-param namespace + interception marker
37
37
  ignoreNativeTiff: false, // true → transcode in Safari too, skip native passthrough
38
+ transcodeWorkers: true, // decode on page-side workers (/tiff-transcode-worker.js)
38
39
  },
39
40
  })
40
41
  ```
@@ -48,6 +49,11 @@ export default defineNuxtConfig({
48
49
  - Already run your own Service Worker? Set `autoRegister: false` and
49
50
  `importScripts('/tiff-sw.js')` inside it (see `@tiff-provider/core`).
50
51
  - Sources must be same-origin or CORS-readable (cross-origin needs CORS headers).
52
+ - Decoding runs on a pool of dedicated workers in the page
53
+ (`/tiff-transcode-worker.js`), several images at once, so the Service Worker
54
+ stays responsive and a cancelled image stops mid-decode. If the worker cannot
55
+ start (for example a CSP without `worker-src 'self'`), the SW decodes by
56
+ itself. `transcodeWorkers: false` always decodes in the SW.
51
57
  - The SW intercepts by the `tp=1` marker the provider adds, not by file extension,
52
58
  so extension-less sources (e.g. an S3 key served as TIFF via `Content-Type`)
53
59
  work too. Building a URL by hand? Add the marker with `buildTiffUrl` or `?tp=1`.
package/dist/module.d.mts CHANGED
@@ -17,6 +17,11 @@ interface ModuleOptions {
17
17
  paramPrefix: string;
18
18
  /** Transcode in the SW even where TIFF is native (Safari). Default false. */
19
19
  ignoreNativeTiff: boolean;
20
+ /**
21
+ * Decode on a pool of dedicated workers in the page instead of in the SW
22
+ * (served at /tiff-transcode-worker.js). Default true.
23
+ */
24
+ transcodeWorkers: boolean;
20
25
  }
21
26
  declare const module$1: nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
22
27
 
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "0.4.0",
7
+ "version": "0.5.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -18,7 +18,8 @@ const module$1 = defineNuxtModule({
18
18
  autoRegister: true,
19
19
  retryRacedImages: true,
20
20
  paramPrefix: "tp",
21
- ignoreNativeTiff: false
21
+ ignoreNativeTiff: false,
22
+ transcodeWorkers: true
22
23
  },
23
24
  async setup(options, nuxt) {
24
25
  const resolver = createResolver(import.meta.url);
@@ -38,24 +39,29 @@ const module$1 = defineNuxtModule({
38
39
  await installModule("@nuxt/image");
39
40
  }
40
41
  const require = createRequire(import.meta.url);
41
- let swSource;
42
- try {
43
- swSource = require.resolve("@tiff-provider/core/tiff-sw.js");
44
- } catch {
45
- throw new Error(
46
- 'nuxt-tiff-provider: could not resolve "@tiff-provider/core/tiff-sw.js". Ensure @tiff-provider/core is installed and built (run `pnpm run build:core`).'
47
- );
48
- }
42
+ const resolveArtifact = (name) => {
43
+ try {
44
+ return require.resolve(`@tiff-provider/core/${name}`);
45
+ } catch {
46
+ throw new Error(
47
+ `nuxt-tiff-provider: could not resolve "@tiff-provider/core/${name}". Ensure @tiff-provider/core is installed and built (run \`pnpm run build:core\`).`
48
+ );
49
+ }
50
+ };
51
+ const swSource = resolveArtifact("tiff-sw.js");
52
+ const workerSource = resolveArtifact("tiff-transcode-worker.js");
49
53
  const swDir = join(nuxt.options.buildDir, "cache", "tiff-sw");
50
54
  mkdirSync(swDir, { recursive: true });
51
55
  copyFileSync(swSource, join(swDir, "tiff-sw.js"));
56
+ copyFileSync(workerSource, join(swDir, "tiff-transcode-worker.js"));
52
57
  nuxt.hook("nitro:config", (nitro) => {
53
58
  nitro.publicAssets ||= [];
54
59
  nitro.publicAssets.push({ baseURL: "/", dir: swDir });
55
60
  });
56
61
  const nitroOptions = nuxt.options.nitro ??= {};
57
62
  nitroOptions.routeRules = defu(nitroOptions.routeRules, {
58
- "/tiff-sw.js": { headers: { "cache-control": "no-cache" } }
63
+ "/tiff-sw.js": { headers: { "cache-control": "no-cache" } },
64
+ "/tiff-transcode-worker.js": { headers: { "cache-control": "no-cache" } }
59
65
  });
60
66
  nuxt.options.runtimeConfig.public.tiff = defu(
61
67
  nuxt.options.runtimeConfig.public.tiff || {},
@@ -65,7 +71,8 @@ const module$1 = defineNuxtModule({
65
71
  scope: options.scope,
66
72
  retryRacedImages: options.retryRacedImages,
67
73
  paramPrefix: options.paramPrefix,
68
- ignoreNativeTiff: options.ignoreNativeTiff
74
+ ignoreNativeTiff: options.ignoreNativeTiff,
75
+ transcodeWorkers: options.transcodeWorkers
69
76
  }
70
77
  );
71
78
  if (options.autoRegister) {
@@ -9,6 +9,7 @@ export default defineNuxtPlugin(() => {
9
9
  quality: cfg.quality,
10
10
  retryRacedImages: cfg.retryRacedImages,
11
11
  paramPrefix: cfg.paramPrefix,
12
- ignoreNativeTiff: cfg.ignoreNativeTiff
12
+ ignoreNativeTiff: cfg.ignoreNativeTiff,
13
+ transcodeWorkers: cfg.transcodeWorkers
13
14
  });
14
15
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-tiff-provider",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Nuxt module: render TIFFs via @nuxt/image off the main thread in a Service Worker.",
5
5
  "keywords": [
6
6
  "nuxt",
@@ -38,7 +38,7 @@
38
38
  "@nuxt/image": "^1.11.0",
39
39
  "@nuxt/kit": "^4.0.0",
40
40
  "defu": "^6.1.0",
41
- "@tiff-provider/core": "0.4.0"
41
+ "@tiff-provider/core": "0.5.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@nuxt/module-builder": "^1.0.0",