idiotikmethods 0.1.0 → 0.1.1

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 (2) hide show
  1. package/IdiotikMethods.js +17 -13
  2. package/package.json +2 -2
package/IdiotikMethods.js CHANGED
@@ -42,7 +42,7 @@
42
42
  {
43
43
  key: "pdfjs",
44
44
  url: "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.2.67/pdf.min.js",
45
- fallback: "https://unpkg.com/pdfjs-dist@4.2.67/build/pdf.min.js",
45
+ fallback: "https://cdn.jsdelivr.net/npm/pdfjs-dist@4.2.67/legacy/build/pdf.min.js",
46
46
  init: () => _initPdfJs(),
47
47
  },
48
48
 
@@ -108,7 +108,7 @@
108
108
  {
109
109
  key: "chartjs",
110
110
  url: "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.3/chart.umd.min.js",
111
- fallback: "https://unpkg.com/chart.js@4.4.3/dist/chart.umd.min.js",
111
+ fallback: "https://cdn.jsdelivr.net/npm/chart.js@4.4.3/dist/chart.umd.min.js",
112
112
  init: () => _register("chartjs", root.Chart),
113
113
  },
114
114
  {
@@ -452,8 +452,14 @@
452
452
 
453
453
  // set worker src (use CDN worker)
454
454
  if (pdfjsLib.GlobalWorkerOptions) {
455
- pdfjsLib.GlobalWorkerOptions.workerSrc =
456
- "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.2.67/pdf.worker.min.js";
455
+ // primary worker — cdnjs; fallback — jsDelivr legacy build
456
+ const _workerPrimary = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.2.67/pdf.worker.min.js";
457
+ const _workerFallback = "https://cdn.jsdelivr.net/npm/pdfjs-dist@4.2.67/legacy/build/pdf.worker.min.js";
458
+ pdfjsLib.GlobalWorkerOptions.workerSrc = _workerPrimary;
459
+ // if the worker 404s, swap to fallback so pdf rendering doesn't die silently
460
+ fetch(_workerPrimary, { method: "HEAD" }).catch(() => {
461
+ pdfjsLib.GlobalWorkerOptions.workerSrc = _workerFallback;
462
+ });
457
463
  }
458
464
 
459
465
  // spin up a minimal invisible container to get the trusted event pipeline live
@@ -662,15 +668,13 @@
662
668
  }
663
669
 
664
670
  function _resolveSwUrl(type) {
665
- // look for sw.js in the same directory as the current script
666
- const scripts = document.querySelectorAll("script[src]");
667
- for (const s of scripts) {
668
- if (s.src && (s.src.includes("IdiotikMethods") || s.src.includes("idiotik"))) {
669
- const base = s.src.substring(0, s.src.lastIndexOf("/") + 1);
670
- return type === "fallback" ? `${base}sw-fallback.js` : `${base}sw.js`;
671
- }
672
- }
673
- return type === "fallback" ? "/sw-fallback.js" : "/sw.js";
671
+ // SW must be same-origin always resolve relative to the page, not the script src.
672
+ // CDN-hosted scripts (unpkg, cdnjs, jsdelivr) would produce a cross-origin SW url
673
+ // which browsers hard-block with a SecurityError. page-relative is always safe.
674
+ const swFile = type === "fallback" ? "sw-fallback.js" : "sw.js";
675
+ // use the page's current directory (works for both root and subpath deployments)
676
+ const pagePath = window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/") + 1);
677
+ return pagePath + swFile;
674
678
  }
675
679
 
676
680
  function _waitForSWActive(reg) {
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "idiotikmethods",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "main": "IdiotikMethods.js",
5
5
  "files": [
6
6
  "IdiotikMethods.js",
7
7
  "sw.js"
8
8
  ],
9
9
  "license": "MIT"
10
- }
10
+ }