idiotikmethods 0.1.1 → 0.1.3

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 (3) hide show
  1. package/IdiotikMethods.js +68 -35
  2. package/package.json +1 -1
  3. package/sw.js +2 -2
package/IdiotikMethods.js CHANGED
@@ -41,8 +41,9 @@
41
41
  // ── PDF / DOC ──────────────────────────────────────────────
42
42
  {
43
43
  key: "pdfjs",
44
- url: "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.2.67/pdf.min.js",
45
- fallback: "https://cdn.jsdelivr.net/npm/pdfjs-dist@4.2.67/legacy/build/pdf.min.js",
44
+ // 3.11.174 confirmed live on cdnjs — 4.x changed path structure, 404s on cdnjs
45
+ url: "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.min.js",
46
+ fallback: "https://cdn.jsdelivr.net/npm/pdfjs-dist@3.11.174/build/pdf.min.js",
46
47
  init: () => _initPdfJs(),
47
48
  },
48
49
 
@@ -89,7 +90,8 @@
89
90
  },
90
91
  {
91
92
  key: "konva",
92
- url: "https://cdnjs.cloudflare.com/ajax/libs/konva/9.3.3/konva.min.js",
93
+ // 9.3.3 not on cdnjs — jsdelivr is the reliable source for konva
94
+ url: "https://cdn.jsdelivr.net/npm/konva@9.3.3/konva.min.js",
93
95
  fallback: "https://unpkg.com/konva@9.3.3/konva.min.js",
94
96
  init: () => _register("konva", root.Konva),
95
97
  },
@@ -107,8 +109,9 @@
107
109
  },
108
110
  {
109
111
  key: "chartjs",
110
- url: "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.3/chart.umd.min.js",
111
- fallback: "https://cdn.jsdelivr.net/npm/chart.js@4.4.3/dist/chart.umd.min.js",
112
+ // v4 dropped chart.umd.min.js — correct artifact is chart.umd.js on jsdelivr
113
+ url: "https://cdn.jsdelivr.net/npm/chart.js@4.4.3/dist/chart.umd.js",
114
+ fallback: "https://unpkg.com/chart.js@4.4.3/dist/chart.umd.js",
112
115
  init: () => _register("chartjs", root.Chart),
113
116
  },
114
117
  {
@@ -347,7 +350,8 @@
347
350
  },
348
351
  {
349
352
  key: "planck",
350
- url: "https://cdnjs.cloudflare.com/ajax/libs/planck/1.0.0/planck.min.js",
353
+ // planck was never on cdnjs — jsdelivr is the only CDN that has it
354
+ url: "https://cdn.jsdelivr.net/npm/planck@1.0.0/dist/planck.min.js",
351
355
  fallback: "https://unpkg.com/planck@1.0.0/dist/planck.min.js",
352
356
  init: () => _register("planck", root.planck),
353
357
  },
@@ -361,8 +365,9 @@
361
365
  },
362
366
  {
363
367
  key: "pagejs",
364
- url: "https://cdnjs.cloudflare.com/ajax/libs/page.js/1.11.6/page.min.js",
365
- fallback: "https://unpkg.com/page@1.11.6/page.js",
368
+ // 1.11.6 not on cdnjs — unpkg primary, jsdelivr fallback
369
+ url: "https://unpkg.com/page@1.11.6/page.js",
370
+ fallback: "https://cdn.jsdelivr.net/npm/page@1.11.6/page.js",
366
371
  init: () => _register("pagejs", root.page),
367
372
  },
368
373
 
@@ -377,7 +382,8 @@
377
382
  // ── MISC POWER TOOLS ───────────────────────────────────────
378
383
  {
379
384
  key: "idb",
380
- url: "https://cdnjs.cloudflare.com/ajax/libs/idb/8.0.0/idb.min.js",
385
+ // idb was never on cdnjs — jsdelivr umd build is the right target
386
+ url: "https://cdn.jsdelivr.net/npm/idb@8.0.0/build/umd.js",
381
387
  fallback: "https://unpkg.com/idb@8.0.0/build/umd.js",
382
388
  init: () => _register("idb", root.idb),
383
389
  },
@@ -389,9 +395,12 @@
389
395
  },
390
396
  {
391
397
  key: "fingerprintjs",
392
- url: "https://cdnjs.cloudflare.com/ajax/libs/fingerprintjs2/2.1.4/fingerprint2.min.js",
393
- fallback: "https://unpkg.com/fingerprintjs2@2.1.4/dist/fingerprint2.min.js",
394
- init: () => _register("fingerprintjs", root.Fingerprint2),
398
+ // fingerprintjs2 is abandoned and unpublished — use v4 (@fingerprintjs/fingerprintjs)
399
+ // v4 is ESM-only so we use the CDN UMD build from jsdelivr
400
+ // API change: FingerprintJS.load().then(fp => fp.get()) instead of new Fingerprint2()
401
+ url: "https://cdn.jsdelivr.net/npm/@fingerprintjs/fingerprintjs@4/dist/fp.umd.min.js",
402
+ fallback: "https://unpkg.com/@fingerprintjs/fingerprintjs@4/dist/fp.umd.min.js",
403
+ init: () => _initFingerprintJS(),
395
404
  },
396
405
  {
397
406
  key: "qrcode",
@@ -401,8 +410,9 @@
401
410
  },
402
411
  {
403
412
  key: "zxing",
404
- url: "https://cdnjs.cloudflare.com/ajax/libs/zxing-js/0.21.3/index.min.js",
405
- fallback: "https://unpkg.com/@zxing/library@0.21.3/umd/index.min.js",
413
+ // zxing-js was never on cdnjs — unpkg umd build is the right target
414
+ url: "https://unpkg.com/@zxing/library@0.21.3/umd/index.min.js",
415
+ fallback: "https://cdn.jsdelivr.net/npm/@zxing/library@0.21.3/umd/index.min.js",
406
416
  init: () => _register("zxing", root.ZXing),
407
417
  },
408
418
  {
@@ -450,13 +460,11 @@
450
460
  const pdfjsLib = root.pdfjsLib || root["pdfjs-dist"] || root.pdfjsLib;
451
461
  if (!pdfjsLib) { console.warn("[IdiotikMethods] pdf.js global not found"); return; }
452
462
 
453
- // set worker src (use CDN worker)
463
+ // set worker src must match the main pdf.js version exactly
454
464
  if (pdfjsLib.GlobalWorkerOptions) {
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";
465
+ const _workerPrimary = "https://cdnjs.cloudflare.com/ajax/libs/pdf.js/3.11.174/pdf.worker.min.js";
466
+ const _workerFallback = "https://cdn.jsdelivr.net/npm/pdfjs-dist@3.11.174/build/pdf.worker.min.js";
458
467
  pdfjsLib.GlobalWorkerOptions.workerSrc = _workerPrimary;
459
- // if the worker 404s, swap to fallback so pdf rendering doesn't die silently
460
468
  fetch(_workerPrimary, { method: "HEAD" }).catch(() => {
461
469
  pdfjsLib.GlobalWorkerOptions.workerSrc = _workerFallback;
462
470
  });
@@ -500,29 +508,37 @@
500
508
 
501
509
  function _initHammer() {
502
510
  if (!root.Hammer) { console.warn("[IdiotikMethods] Hammer.js not found"); return; }
503
- // create a hidden target and register ALL recognizers so the gesture pipeline is live
511
+ const H = root.Hammer;
504
512
  const target = document.createElement("div");
505
513
  target.style.cssText = "position:fixed;width:1px;height:1px;top:-9999px;left:-9999px;touch-action:none;pointer-events:all;";
506
514
  document.body.appendChild(target);
507
515
 
508
- const mc = new root.Hammer.Manager(target, {
509
- recognizers: [
510
- [root.Hammer.Tap],
511
- [root.Hammer.DoubleTap],
512
- [root.Hammer.Press],
513
- [root.Hammer.Pan, { direction: root.Hammer.DIRECTION_ALL }],
514
- [root.Hammer.Swipe, { direction: root.Hammer.DIRECTION_ALL }],
515
- [root.Hammer.Pinch],
516
- [root.Hammer.Rotate],
517
- ],
518
- });
516
+ // avoid the array recognizer form [Hammer.Tap, opts] — when the SW wrapper IIFE
517
+ // patches hammer's source the internal Manager constructor misreads array[0] as
518
+ // the recognizer class reference and throws "a[0] is not a constructor".
519
+ // instantiate each recognizer explicitly instead — same result, no array form.
520
+ let mc;
521
+ try {
522
+ mc = new H.Manager(target);
523
+ mc.add(new H.Tap());
524
+ mc.add(new H.DoubleTap());
525
+ mc.add(new H.Press());
526
+ mc.add(new H.Pan({ direction: H.DIRECTION_ALL }));
527
+ mc.add(new H.Swipe({ direction: H.DIRECTION_ALL }));
528
+ mc.add(new H.Pinch());
529
+ mc.add(new H.Rotate());
530
+ } catch (e) {
531
+ // if Manager itself throws (e.g. stripped build), just register the global
532
+ console.warn("[IdiotikMethods] Hammer.Manager init failed, registering global only:", e.message);
533
+ _register("hammer", H);
534
+ return;
535
+ }
519
536
 
520
- // fire noop listeners so the pipeline actually activates
521
537
  ["tap", "doubletap", "press", "pan", "swipe", "pinch", "rotate"].forEach((ev) => {
522
538
  mc.on(ev, () => {});
523
539
  });
524
540
 
525
- _register("hammer", root.Hammer);
541
+ _register("hammer", H);
526
542
  _methods.hammerManager = mc;
527
543
  if (root.idiotik) {
528
544
  root.idiotik.methods = root.idiotik.methods || {};
@@ -558,6 +574,23 @@
558
574
  }
559
575
  }
560
576
 
577
+ function _initFingerprintJS() {
578
+ // v4 API — FingerprintJS.load() returns a promise, not a constructor
579
+ // expose both the agent promise and a convenience .get() wrapper
580
+ const FP = root.FingerprintJS;
581
+ if (!FP) { console.warn("[IdiotikMethods] FingerprintJS v4 global not found"); return; }
582
+ const agentPromise = FP.load();
583
+ // convenience wrapper matching common usage patterns
584
+ const fpRef = {
585
+ load: () => agentPromise,
586
+ get: () => agentPromise.then((agent) => agent.get()),
587
+ _agent: agentPromise,
588
+ };
589
+ // kick off a background get so the pipeline is warm
590
+ agentPromise.then((agent) => agent.get()).catch(() => {});
591
+ _register("fingerprintjs", fpRef);
592
+ }
593
+
561
594
  // ----------------------------------------------------------------
562
595
  // SCRIPT LOADER — load as classic <script> (no type=module)
563
596
  // so everything lands on the shared window. with cdnjs/unpkg fallback.
@@ -725,7 +758,7 @@
725
758
  "Papa", "XLSX", "marked", "DOMPurify", "Fuse", "lunr",
726
759
  "CryptoJS", "forge", "videojs", "RecordRTC", "Matter", "planck",
727
760
  "Navigo", "page", "Comlink", "idb", "localforage",
728
- "Fingerprint2", "QRCode", "ZXing", "Tesseract", "ml5", "tf",
761
+ "FingerprintJS", "QRCode", "ZXing", "Tesseract", "ml5", "tf",
729
762
  ];
730
763
 
731
764
  // map from global key → methods key
@@ -734,7 +767,7 @@
734
767
  Chart: "chartjs", Tone: "tone", Howl: "howler", WaveSurfer: "wavesurfer",
735
768
  io: "socketio", _: "lodash", math: "mathjs", R: "ramda",
736
769
  jQuery: "jquery", $: "jquery", Swal: "sweetalert2", Papa: "papaparse",
737
- ZXing: "zxing", Fingerprint2: "fingerprintjs", tf: "tensorflow",
770
+ ZXing: "zxing", FingerprintJS: "fingerprintjs", tf: "tensorflow",
738
771
  };
739
772
 
740
773
  WATCH_KEYS.forEach((key) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "idiotikmethods",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "main": "IdiotikMethods.js",
5
5
  "files": [
6
6
  "IdiotikMethods.js",
package/sw.js CHANGED
@@ -163,7 +163,7 @@ async function _interceptCdnRequest(request, url) {
163
163
  // ── PRIMARY: response rewrite ────────────────────────────────
164
164
  try {
165
165
  const realResponse = await fetch(request.url, {
166
- cache: "force-cache",
166
+ cache: "no-cache",
167
167
  credentials: "omit",
168
168
  });
169
169
 
@@ -205,7 +205,7 @@ async function _interceptCdnRequest(request, url) {
205
205
 
206
206
  async function _blobFallbackStrategy(request, url, libKey) {
207
207
  const realResponse = await fetch(request.url, {
208
- cache: "force-cache",
208
+ cache: "no-cache",
209
209
  credentials: "omit",
210
210
  });
211
211