@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.
- package/dist/cfi/CfiHandler.d.ts +4 -1
- package/dist/index.js +22 -4
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +22 -4
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +3 -3
package/dist/cfi/CfiHandler.d.ts
CHANGED
|
@@ -3,8 +3,11 @@ export declare class CfiHandler {
|
|
|
3
3
|
parts: {}[];
|
|
4
4
|
opts: {};
|
|
5
5
|
cfi: string;
|
|
6
|
+
private static tempDocument;
|
|
7
|
+
private static tempTextArea;
|
|
6
8
|
constructor(str: string, opts: {});
|
|
7
9
|
removeIllegalOpts(parts: any[]): void;
|
|
10
|
+
private static getTextArea;
|
|
8
11
|
static generatePart(node: Element | Node, offset?: number, extra?: {}): string;
|
|
9
12
|
static generate(node: Node, offset?: number, extra?: {}): string;
|
|
10
13
|
static toParsed(cfi: any): any;
|
|
@@ -12,7 +15,7 @@ export declare class CfiHandler {
|
|
|
12
15
|
static sort(a: any): void;
|
|
13
16
|
static compare(a: any, b: any): number;
|
|
14
17
|
static compareParts(a: any, b: any): number;
|
|
15
|
-
decodeEntities(
|
|
18
|
+
decodeEntities(_: Document, str: string): string;
|
|
16
19
|
trueLength(dom: Document, str: string): number;
|
|
17
20
|
getFrom(): any;
|
|
18
21
|
getTo(): any;
|
package/dist/index.js
CHANGED
|
@@ -2850,7 +2850,7 @@ function compareSpatial(a, b) {
|
|
|
2850
2850
|
if (diff) return diff;
|
|
2851
2851
|
return (a.x || 0) - (b.x || 0);
|
|
2852
2852
|
}
|
|
2853
|
-
class
|
|
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 @@ class CfiHandler {
|
|
|
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 @@ class CfiHandler {
|
|
|
3039
3048
|
}
|
|
3040
3049
|
return 0;
|
|
3041
3050
|
}
|
|
3042
|
-
|
|
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 =
|
|
3059
|
+
const el = _CfiHandler.getTextArea();
|
|
3045
3060
|
el.innerHTML = str;
|
|
3046
3061
|
return el.value || ``;
|
|
3047
3062
|
} catch (err) {
|
|
@@ -3612,7 +3627,10 @@ class CfiHandler {
|
|
|
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(/\]/, ``))) || [];
|