nuxt-tiff-provider 0.3.2 → 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
@@ -34,18 +34,26 @@ export default defineNuxtConfig({
34
34
  autoRegister: true, // false → call registerTiffServiceWorker() yourself
35
35
  retryRacedImages: true, // re-fetch images that raced the SW on first load
36
36
  paramPrefix: 'tp', // query-param namespace + interception marker
37
+ ignoreNativeTiff: false, // true → transcode in Safari too, skip native passthrough
38
+ transcodeWorkers: true, // decode on page-side workers (/tiff-transcode-worker.js)
37
39
  },
38
40
  })
39
41
  ```
40
42
 
41
43
  ## Notes
42
44
 
43
- - Safari paints TIFF natively; the SW detects this and passes through.
45
+ - Safari paints TIFF natively; the SW detects this and passes through. Set
46
+ `ignoreNativeTiff: true` to transcode there too.
44
47
  - First cold visit: images requested before the SW took control are re-fetched
45
48
  automatically once it does (disable with `retryRacedImages: false`).
46
49
  - Already run your own Service Worker? Set `autoRegister: false` and
47
50
  `importScripts('/tiff-sw.js')` inside it (see `@tiff-provider/core`).
48
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.
49
57
  - The SW intercepts by the `tp=1` marker the provider adds, not by file extension,
50
58
  so extension-less sources (e.g. an S3 key served as TIFF via `Content-Type`)
51
59
  work too. Building a URL by hand? Add the marker with `buildTiffUrl` or `?tp=1`.
package/dist/module.d.mts CHANGED
@@ -15,6 +15,13 @@ interface ModuleOptions {
15
15
  retryRacedImages: boolean;
16
16
  /** Query-param namespace for modifiers and the interception marker. Default 'tp'. */
17
17
  paramPrefix: string;
18
+ /** Transcode in the SW even where TIFF is native (Safari). Default false. */
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;
18
25
  }
19
26
  declare const module$1: nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
20
27
 
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "0.3.2",
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
@@ -17,7 +17,9 @@ const module$1 = defineNuxtModule({
17
17
  scope: "/",
18
18
  autoRegister: true,
19
19
  retryRacedImages: true,
20
- paramPrefix: "tp"
20
+ paramPrefix: "tp",
21
+ ignoreNativeTiff: false,
22
+ transcodeWorkers: true
21
23
  },
22
24
  async setup(options, nuxt) {
23
25
  const resolver = createResolver(import.meta.url);
@@ -37,24 +39,29 @@ const module$1 = defineNuxtModule({
37
39
  await installModule("@nuxt/image");
38
40
  }
39
41
  const require = createRequire(import.meta.url);
40
- let swSource;
41
- try {
42
- swSource = require.resolve("@tiff-provider/core/tiff-sw.js");
43
- } catch {
44
- throw new Error(
45
- '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`).'
46
- );
47
- }
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");
48
53
  const swDir = join(nuxt.options.buildDir, "cache", "tiff-sw");
49
54
  mkdirSync(swDir, { recursive: true });
50
55
  copyFileSync(swSource, join(swDir, "tiff-sw.js"));
56
+ copyFileSync(workerSource, join(swDir, "tiff-transcode-worker.js"));
51
57
  nuxt.hook("nitro:config", (nitro) => {
52
58
  nitro.publicAssets ||= [];
53
59
  nitro.publicAssets.push({ baseURL: "/", dir: swDir });
54
60
  });
55
61
  const nitroOptions = nuxt.options.nitro ??= {};
56
62
  nitroOptions.routeRules = defu(nitroOptions.routeRules, {
57
- "/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" } }
58
65
  });
59
66
  nuxt.options.runtimeConfig.public.tiff = defu(
60
67
  nuxt.options.runtimeConfig.public.tiff || {},
@@ -63,7 +70,9 @@ const module$1 = defineNuxtModule({
63
70
  quality: options.quality,
64
71
  scope: options.scope,
65
72
  retryRacedImages: options.retryRacedImages,
66
- paramPrefix: options.paramPrefix
73
+ paramPrefix: options.paramPrefix,
74
+ ignoreNativeTiff: options.ignoreNativeTiff,
75
+ transcodeWorkers: options.transcodeWorkers
67
76
  }
68
77
  );
69
78
  if (options.autoRegister) {
@@ -8,6 +8,8 @@ export default defineNuxtPlugin(() => {
8
8
  cacheName: cfg.cacheName,
9
9
  quality: cfg.quality,
10
10
  retryRacedImages: cfg.retryRacedImages,
11
- paramPrefix: cfg.paramPrefix
11
+ paramPrefix: cfg.paramPrefix,
12
+ ignoreNativeTiff: cfg.ignoreNativeTiff,
13
+ transcodeWorkers: cfg.transcodeWorkers
12
14
  });
13
15
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-tiff-provider",
3
- "version": "0.3.2",
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.3.2"
41
+ "@tiff-provider/core": "0.5.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@nuxt/module-builder": "^1.0.0",