@prose-reader/core 1.135.0 → 1.136.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.
@@ -2850,7 +2850,7 @@
2850
2850
  if (diff) return diff;
2851
2851
  return (a.x || 0) - (b.x || 0);
2852
2852
  }
2853
- class CfiHandler {
2853
+ const _CfiHandler = class _CfiHandler {
2854
2854
  constructor(str, opts) {
2855
2855
  this.isRange = false;
2856
2856
  this.opts = Object.assign(
@@ -2943,6 +2943,15 @@
2943
2943
  }
2944
2944
  }
2945
2945
  }
2946
+ static getTextArea() {
2947
+ if (!_CfiHandler.tempTextArea) {
2948
+ if (!_CfiHandler.tempDocument) {
2949
+ _CfiHandler.tempDocument = document.implementation.createHTMLDocument();
2950
+ }
2951
+ _CfiHandler.tempTextArea = _CfiHandler.tempDocument.createElement("textarea");
2952
+ }
2953
+ return _CfiHandler.tempTextArea;
2954
+ }
2946
2955
  static generatePart(node, offset, extra) {
2947
2956
  let cfi = ``;
2948
2957
  let o;
@@ -3039,9 +3048,15 @@
3039
3048
  }
3040
3049
  return 0;
3041
3050
  }
3042
- decodeEntities(dom, str) {
3051
+ /**
3052
+ * Could be even faster by checking if there would be some potentially
3053
+ * problematic characters creating unwanted resources trigger.
3054
+ * @see https://github.com/fread-ink/epub-cfi-resolver/issues/25
3055
+ * @todo check if we really need to do this anyway.
3056
+ */
3057
+ decodeEntities(_, str) {
3043
3058
  try {
3044
- const el = dom.createElement(`textarea`);
3059
+ const el = _CfiHandler.getTextArea();
3045
3060
  el.innerHTML = str;
3046
3061
  return el.value || ``;
3047
3062
  } catch (err) {
@@ -3612,7 +3627,10 @@
3612
3627
  resolve(doc, opts) {
3613
3628
  return this.resolveLast(doc, opts);
3614
3629
  }
3615
- }
3630
+ };
3631
+ _CfiHandler.tempDocument = null;
3632
+ _CfiHandler.tempTextArea = null;
3633
+ let CfiHandler = _CfiHandler;
3616
3634
  const parseCfi = (cfi) => {
3617
3635
  var _a, _b;
3618
3636
  const [itemIndex] = ((_a = cfi.match(/\|(\[prose\~anchor[^\]]*\])+/gi)) == null ? void 0 : _a.map((s) => s.replace(/\|\[prose\~anchor\~/, ``).replace(/\]/, ``))) || [];