@d-i-t-a/reader 3.0.0-alpha.5 → 3.0.0-alpha.7
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/esm/index.js +45 -74
- package/dist/esm/index.js.map +4 -4
- package/dist/reader.js +49 -49
- package/dist/reader.js.map +4 -4
- package/dist/types/model/Link.d.ts +7 -5
- package/dist/types/model/v3/Publication.d.ts +6 -0
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -14676,7 +14676,7 @@ var require_lodash = __commonJS({
|
|
|
14676
14676
|
} else if (isPlainObject(srcValue) || isArguments(srcValue)) {
|
|
14677
14677
|
newValue = objValue;
|
|
14678
14678
|
if (isArguments(objValue)) {
|
|
14679
|
-
newValue =
|
|
14679
|
+
newValue = toPlainObject2(objValue);
|
|
14680
14680
|
} else if (!isObject(objValue) || isFunction(objValue)) {
|
|
14681
14681
|
newValue = initCloneObject(srcValue);
|
|
14682
14682
|
}
|
|
@@ -17317,7 +17317,7 @@ var require_lodash = __commonJS({
|
|
|
17317
17317
|
var isBinary = reIsBinary.test(value);
|
|
17318
17318
|
return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value;
|
|
17319
17319
|
}
|
|
17320
|
-
function
|
|
17320
|
+
function toPlainObject2(value) {
|
|
17321
17321
|
return copyObject(value, keysIn(value));
|
|
17322
17322
|
}
|
|
17323
17323
|
function toSafeInteger(value) {
|
|
@@ -18197,7 +18197,7 @@ var require_lodash = __commonJS({
|
|
|
18197
18197
|
lodash4.toPairs = toPairs;
|
|
18198
18198
|
lodash4.toPairsIn = toPairsIn;
|
|
18199
18199
|
lodash4.toPath = toPath;
|
|
18200
|
-
lodash4.toPlainObject =
|
|
18200
|
+
lodash4.toPlainObject = toPlainObject2;
|
|
18201
18201
|
lodash4.transform = transform;
|
|
18202
18202
|
lodash4.unary = unary;
|
|
18203
18203
|
lodash4.union = union;
|
|
@@ -68637,7 +68637,7 @@ var Link = class extends U {
|
|
|
68637
68637
|
// src/model/v3/Publication.ts
|
|
68638
68638
|
function toLink(link) {
|
|
68639
68639
|
if (link instanceof Link) return link;
|
|
68640
|
-
return
|
|
68640
|
+
return new Link({
|
|
68641
68641
|
href: link.href,
|
|
68642
68642
|
templated: link.templated,
|
|
68643
68643
|
type: link.type,
|
|
@@ -68663,6 +68663,27 @@ var Publication = class _Publication {
|
|
|
68663
68663
|
this.manifest = manifest;
|
|
68664
68664
|
this.manifestUrl = manifestUrl;
|
|
68665
68665
|
}
|
|
68666
|
+
/**
|
|
68667
|
+
* Create a Publication from a raw JSON object.
|
|
68668
|
+
* Handles both RWPM (camelCase) and legacy (PascalCase) key formats.
|
|
68669
|
+
* Returns null if the JSON cannot be parsed.
|
|
68670
|
+
*/
|
|
68671
|
+
static fromJSON(json, url) {
|
|
68672
|
+
const normalized = {
|
|
68673
|
+
metadata: json.metadata ?? json.Metadata ?? { title: "" },
|
|
68674
|
+
links: json.links ?? json.Links ?? [],
|
|
68675
|
+
readingOrder: json.readingOrder ?? json.spine ?? json.Spine ?? [],
|
|
68676
|
+
resources: json.resources ?? json.Resources,
|
|
68677
|
+
toc: json.toc ?? json.TOC
|
|
68678
|
+
};
|
|
68679
|
+
if (!normalized.metadata.title) {
|
|
68680
|
+
normalized.metadata.title = normalized.metadata.Title ?? "";
|
|
68681
|
+
}
|
|
68682
|
+
const manifest = Ue.deserialize(normalized);
|
|
68683
|
+
if (!manifest) return null;
|
|
68684
|
+
manifest.setSelfLink(url.href);
|
|
68685
|
+
return new _Publication(manifest, url);
|
|
68686
|
+
}
|
|
68666
68687
|
static async fromUrl(url, requestConfig) {
|
|
68667
68688
|
const response = await fetch(url.href, requestConfig);
|
|
68668
68689
|
const manifestJSON = await response.json();
|
|
@@ -76921,16 +76942,6 @@ var MediaOverlayNode = class _MediaOverlayNode {
|
|
|
76921
76942
|
}
|
|
76922
76943
|
};
|
|
76923
76944
|
|
|
76924
|
-
// src/utils/JsonUtil.ts
|
|
76925
|
-
init_polyfills();
|
|
76926
|
-
function TaJsonDeserialize(json, type) {
|
|
76927
|
-
if (type && typeof type.deserialize === "function") {
|
|
76928
|
-
const result = type.deserialize(json);
|
|
76929
|
-
if (result) return result;
|
|
76930
|
-
}
|
|
76931
|
-
return Object.assign(new type(), json);
|
|
76932
|
-
}
|
|
76933
|
-
|
|
76934
76945
|
// src/modules/mediaoverlays/MediaOverlaySettings.ts
|
|
76935
76946
|
init_polyfills();
|
|
76936
76947
|
init_HTMLUtilities();
|
|
@@ -77393,10 +77404,7 @@ var MediaOverlayModule = class {
|
|
|
77393
77404
|
import_loglevel11.default.log("## moJson" + moJson);
|
|
77394
77405
|
return;
|
|
77395
77406
|
}
|
|
77396
|
-
link.mediaOverlayNode =
|
|
77397
|
-
moJson,
|
|
77398
|
-
MediaOverlayNode
|
|
77399
|
-
);
|
|
77407
|
+
link.mediaOverlayNode = MediaOverlayNode.deserialize(moJson);
|
|
77400
77408
|
link.mediaOverlayNode.initialized = true;
|
|
77401
77409
|
const href = link.hrefDecoded || link.href;
|
|
77402
77410
|
const hrefUrlObj = new URL("https://dita.digital/" + href);
|
|
@@ -77475,10 +77483,7 @@ var MediaOverlayModule = class {
|
|
|
77475
77483
|
if (response.ok) {
|
|
77476
77484
|
const moJson = await response.json();
|
|
77477
77485
|
if (moJson) {
|
|
77478
|
-
link.mediaOverlayNode =
|
|
77479
|
-
moJson,
|
|
77480
|
-
MediaOverlayNode
|
|
77481
|
-
);
|
|
77486
|
+
link.mediaOverlayNode = MediaOverlayNode.deserialize(moJson);
|
|
77482
77487
|
link.mediaOverlayNode.initialized = true;
|
|
77483
77488
|
}
|
|
77484
77489
|
}
|
|
@@ -87512,35 +87517,18 @@ init_HTMLUtilities();
|
|
|
87512
87517
|
|
|
87513
87518
|
// src/model/Link.ts
|
|
87514
87519
|
init_polyfills();
|
|
87515
|
-
function
|
|
87516
|
-
|
|
87517
|
-
if (o instanceof Array)
|
|
87518
|
-
|
|
87519
|
-
|
|
87520
|
-
|
|
87521
|
-
|
|
87522
|
-
|
|
87523
|
-
|
|
87524
|
-
|
|
87525
|
-
newO = {};
|
|
87526
|
-
for (origKey in o) {
|
|
87527
|
-
if (o.hasOwnProperty(origKey)) {
|
|
87528
|
-
newKey = (origKey.charAt(0).toLowerCase() + origKey.slice(1) || origKey).toString();
|
|
87529
|
-
value = o[origKey];
|
|
87530
|
-
if (value instanceof Array || value !== null && value !== void 0 && value.constructor === Object) {
|
|
87531
|
-
value = convertAndCamel(value);
|
|
87532
|
-
}
|
|
87533
|
-
if (newKey === "href1") {
|
|
87534
|
-
newO["href"] = value;
|
|
87535
|
-
} else if (newKey === "typeLink") {
|
|
87536
|
-
newO["type"] = value;
|
|
87537
|
-
} else {
|
|
87538
|
-
newO[newKey] = value;
|
|
87539
|
-
}
|
|
87540
|
-
}
|
|
87541
|
-
}
|
|
87520
|
+
function toPlainObject(o) {
|
|
87521
|
+
if (o == null) return o;
|
|
87522
|
+
if (o instanceof Set) return Array.from(o);
|
|
87523
|
+
if (o.items && Array.isArray(o.items)) return o.items.map(toPlainObject);
|
|
87524
|
+
if (Array.isArray(o)) return o.map(toPlainObject);
|
|
87525
|
+
if (typeof o !== "object") return o;
|
|
87526
|
+
const result = {};
|
|
87527
|
+
for (const key in o) {
|
|
87528
|
+
if (!o.hasOwnProperty(key)) continue;
|
|
87529
|
+
result[key] = toPlainObject(o[key]);
|
|
87542
87530
|
}
|
|
87543
|
-
return
|
|
87531
|
+
return result;
|
|
87544
87532
|
}
|
|
87545
87533
|
|
|
87546
87534
|
// src/modules/highlight/LayerSettings.ts
|
|
@@ -88016,27 +88004,10 @@ var D2Reader = class _D2Reader {
|
|
|
88016
88004
|
if (pubInput instanceof Publication) {
|
|
88017
88005
|
publication = pubInput;
|
|
88018
88006
|
} else {
|
|
88019
|
-
|
|
88020
|
-
metadata: pubInput.metadata ?? pubInput.Metadata ?? { title: "" },
|
|
88021
|
-
links: pubInput.links ?? pubInput.Links ?? [],
|
|
88022
|
-
readingOrder: pubInput.readingOrder ?? pubInput.spine ?? pubInput.Spine ?? [],
|
|
88023
|
-
resources: pubInput.resources ?? pubInput.Resources,
|
|
88024
|
-
toc: pubInput.toc ?? pubInput.TOC
|
|
88025
|
-
};
|
|
88026
|
-
if (!json.metadata.title && !json.metadata.Title) {
|
|
88027
|
-
json.metadata.title = "";
|
|
88028
|
-
}
|
|
88029
|
-
if (json.metadata.Title && !json.metadata.title) {
|
|
88030
|
-
json.metadata.title = json.metadata.Title;
|
|
88031
|
-
}
|
|
88032
|
-
const manifest = Ue.deserialize(json);
|
|
88033
|
-
if (!manifest) {
|
|
88034
|
-
throw new Error("Failed to parse publication manifest from config");
|
|
88035
|
-
}
|
|
88036
|
-
manifest.setSelfLink(webPubManifestUrl.href);
|
|
88037
|
-
publication = new Publication(manifest, new URL(webPubManifestUrl));
|
|
88007
|
+
publication = Publication.fromJSON(pubInput, webPubManifestUrl);
|
|
88038
88008
|
}
|
|
88039
|
-
}
|
|
88009
|
+
}
|
|
88010
|
+
if (!publication) {
|
|
88040
88011
|
publication = await Publication.fromUrl(
|
|
88041
88012
|
webPubManifestUrl,
|
|
88042
88013
|
initialConfig.requestConfig
|
|
@@ -88260,19 +88231,19 @@ var D2Reader = class _D2Reader {
|
|
|
88260
88231
|
}
|
|
88261
88232
|
/** Table of Contents */
|
|
88262
88233
|
get tableOfContents() {
|
|
88263
|
-
return
|
|
88234
|
+
return toPlainObject(this.navigator.tableOfContents()) ?? [];
|
|
88264
88235
|
}
|
|
88265
88236
|
/** Landmarks */
|
|
88266
88237
|
get landmarks() {
|
|
88267
|
-
return
|
|
88238
|
+
return toPlainObject(this.navigator.landmarks()) ?? [];
|
|
88268
88239
|
}
|
|
88269
88240
|
/** Page List */
|
|
88270
88241
|
get pageList() {
|
|
88271
|
-
return
|
|
88242
|
+
return toPlainObject(this.navigator.pageList()) ?? [];
|
|
88272
88243
|
}
|
|
88273
88244
|
/** Reading Order or Spine */
|
|
88274
88245
|
get readingOrder() {
|
|
88275
|
-
return
|
|
88246
|
+
return toPlainObject(this.navigator.readingOrder()) ?? [];
|
|
88276
88247
|
}
|
|
88277
88248
|
/** Current Bookmarks */
|
|
88278
88249
|
get bookmarks() {
|