@readium/shared 2.1.4 → 2.2.0-alpha.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@readium/shared",
3
- "version": "2.1.4",
3
+ "version": "2.2.0-alpha.1",
4
4
  "type": "module",
5
5
  "description": "Shared models to be used across other Readium projects and implementations in Typescript",
6
6
  "author": "readium",
@@ -44,14 +44,6 @@
44
44
  "engines": {
45
45
  "node": ">=18"
46
46
  },
47
- "scripts": {
48
- "dev": "vite",
49
- "build": "tsc && vite build",
50
- "test": "jest",
51
- "size": "size-limit",
52
- "check-locales": "node scripts/check-locales.mjs",
53
- "update-locales": "pnpm remove @edrlab/thorium-locales && pnpm add @edrlab/thorium-locales@github:edrlab/thorium-locales && pnpm check-locales"
54
- },
55
47
  "size-limit": [
56
48
  {
57
49
  "path": "dist/index.js",
@@ -70,10 +62,20 @@
70
62
  "babel-jest": "^30.2.0",
71
63
  "css-selector-generator": "^3.8.0",
72
64
  "jest": "^30.2.0",
65
+ "rimraf": "^6.1.2",
73
66
  "size-limit": "^12.0.0",
74
67
  "ts-jest": "^29.4.6",
75
68
  "tslib": "^2.8.1",
76
69
  "typescript": "^5.9.3",
77
70
  "vite": "^7.3.1"
71
+ },
72
+ "scripts": {
73
+ "dev": "vite",
74
+ "clean": "rimraf types dist",
75
+ "build": "pnpm clean && tsc && vite build",
76
+ "test": "jest",
77
+ "size": "size-limit",
78
+ "check-locales": "node scripts/check-locales.mjs",
79
+ "update-locales": "pnpm remove @edrlab/thorium-locales && pnpm add @edrlab/thorium-locales@github:edrlab/thorium-locales && pnpm check-locales"
78
80
  }
79
- }
81
+ }
@@ -108,7 +108,7 @@ export class HttpResource implements Resource {
108
108
  return await resp.text();
109
109
  }
110
110
 
111
- async readAsXML(): Promise<XMLDocument> {
111
+ async readAsXML(): Promise<Document> {
112
112
  const resp = await this.client(this.url);
113
113
  if (!resp.ok)
114
114
  throw new Error(
@@ -116,7 +116,7 @@ export class HttpResource implements Resource {
116
116
  ); // TODO
117
117
  return new DOMParser().parseFromString(
118
118
  await resp.text(),
119
- 'application/xml'
119
+ this._link.mediaType.isHTML ? (this._link.mediaType.string as 'application/xhtml+xml' | 'text/html') : 'text/xml'
120
120
  );
121
121
  }
122
122
  }
@@ -27,11 +27,11 @@ export abstract class Resource {
27
27
  return JSON.parse(str);
28
28
  });
29
29
  }
30
- readAsXML(): Promise<XMLDocument | undefined> {
31
- return this.readAsString().then(str => {
30
+ readAsXML(): Promise<Document | undefined> {
31
+ return this.link().then(l => this.readAsString().then(str => {
32
32
  if (str === undefined) return str;
33
- return new DOMParser().parseFromString(str, 'text/xml');
34
- });
33
+ return new DOMParser().parseFromString(str, l.mediaType.isHTML ? (l.mediaType.string as 'application/xhtml+xml' | 'text/html') : 'text/xml');
34
+ }));
35
35
  }
36
36
  abstract close(): void;
37
37
  }
@@ -53,6 +53,13 @@ declare module '../Locator' {
53
53
  * https://www.w3.org/TR/media-frags/
54
54
  */
55
55
  space(): [number, number, number, number] | undefined;
56
+
57
+ /**
58
+ * Text fragments, used by browsers to jump to/highlight text.
59
+ *
60
+ * https://developer.mozilla.org/en-US/docs/Web/URI/Fragment/Text_fragments
61
+ */
62
+ text(): string | undefined;
56
63
  }
57
64
  }
58
65
 
@@ -126,4 +133,11 @@ LocatorLocations.prototype.space = function(): [number, number, number, number]
126
133
  if(xywh.length !== 4) return; // Must have four parts
127
134
  if(xywh.some(isNaN)) return; // All parts must be numbers
128
135
  return xywh as [number, number, number, number];
136
+ }
137
+
138
+ LocatorLocations.prototype.text = function(): string | undefined {
139
+ const fp = this.fragmentParameters();
140
+ console.log(fp);
141
+ // :~:
142
+ return undefined;
129
143
  }
@@ -24,5 +24,5 @@ export declare class HttpResource implements Resource {
24
24
  length(): Promise<number>;
25
25
  readAsJSON(): Promise<unknown>;
26
26
  readAsString(): Promise<string>;
27
- readAsXML(): Promise<XMLDocument>;
27
+ readAsXML(): Promise<Document>;
28
28
  }
@@ -10,6 +10,6 @@ export declare abstract class Resource {
10
10
  abstract read(range?: NumberRange): Promise<Uint8Array | undefined>;
11
11
  readAsString(): Promise<string | undefined>;
12
12
  readAsJSON(): Promise<unknown | undefined>;
13
- readAsXML(): Promise<XMLDocument | undefined>;
13
+ readAsXML(): Promise<Document | undefined>;
14
14
  abstract close(): void;
15
15
  }
@@ -41,5 +41,11 @@ declare module '../Locator' {
41
41
  * https://www.w3.org/TR/media-frags/
42
42
  */
43
43
  space(): [number, number, number, number] | undefined;
44
+ /**
45
+ * Text fragments, used by browsers to jump to/highlight text.
46
+ *
47
+ * https://developer.mozilla.org/en-US/docs/Web/URI/Fragment/Text_fragments
48
+ */
49
+ text(): string | undefined;
44
50
  }
45
51
  }