@likecoin/epubcheck-ts 0.6.1 → 0.6.2

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/index.js CHANGED
@@ -1,8 +1,23 @@
1
- import { XmlDocument, XmlElement } from 'libxml2-wasm';
2
1
  import { parse, walk } from 'css-tree';
3
2
  import { unzipSync, strFromU8, gunzipSync } from 'fflate';
4
3
 
5
- // src/content/validator.ts
4
+ // src/util/xml-engine.ts
5
+ var engine;
6
+ async function loadXmlEngine() {
7
+ engine ??= await import('libxml2-wasm');
8
+ }
9
+ function getXmlDocument() {
10
+ if (!engine) {
11
+ throw new Error("libxml2-wasm not initialized \u2014 call loadXmlEngine() first");
12
+ }
13
+ return engine.XmlDocument;
14
+ }
15
+ function getXmlElement() {
16
+ if (!engine) {
17
+ throw new Error("libxml2-wasm not initialized \u2014 call loadXmlEngine() first");
18
+ }
19
+ return engine.XmlElement;
20
+ }
6
21
 
7
22
  // src/messages/messages.ts
8
23
  var severityOverrides = /* @__PURE__ */ new Map();
@@ -5082,7 +5097,7 @@ var SKMValidator = class {
5082
5097
  const content = typeof data === "string" ? data : new TextDecoder().decode(data);
5083
5098
  let doc = null;
5084
5099
  try {
5085
- doc = XmlDocument.fromString(content);
5100
+ doc = getXmlDocument().fromString(content);
5086
5101
  } catch {
5087
5102
  pushMessage(context.messages, {
5088
5103
  id: MessageId.RSC_016,
@@ -5319,7 +5334,7 @@ var SMILValidator = class {
5319
5334
  const content = typeof data === "string" ? data : new TextDecoder().decode(data);
5320
5335
  let doc = null;
5321
5336
  try {
5322
- doc = XmlDocument.fromString(content);
5337
+ doc = getXmlDocument().fromString(content);
5323
5338
  } catch {
5324
5339
  pushMessage(context.messages, {
5325
5340
  id: MessageId.RSC_016,
@@ -6229,7 +6244,7 @@ var ContentValidator = class {
6229
6244
  const svgContent = new TextDecoder().decode(svgData);
6230
6245
  let doc;
6231
6246
  try {
6232
- doc = XmlDocument.fromString(svgContent);
6247
+ doc = getXmlDocument().fromString(svgContent);
6233
6248
  this.extractAndRegisterIDs(path, doc.root, registry);
6234
6249
  } catch (e) {
6235
6250
  pushMessage(context.messages, {
@@ -6247,7 +6262,7 @@ var ContentValidator = class {
6247
6262
  const svgContent = new TextDecoder().decode(svgData);
6248
6263
  let doc;
6249
6264
  try {
6250
- doc = XmlDocument.fromString(svgContent);
6265
+ doc = getXmlDocument().fromString(svgContent);
6251
6266
  } catch {
6252
6267
  return;
6253
6268
  }
@@ -6293,7 +6308,7 @@ var ContentValidator = class {
6293
6308
  const svgContent = new TextDecoder().decode(svgData);
6294
6309
  let doc;
6295
6310
  try {
6296
- doc = XmlDocument.fromString(svgContent);
6311
+ doc = getXmlDocument().fromString(svgContent);
6297
6312
  } catch {
6298
6313
  return;
6299
6314
  }
@@ -6643,7 +6658,7 @@ var ContentValidator = class {
6643
6658
  }
6644
6659
  let doc = null;
6645
6660
  try {
6646
- doc = XmlDocument.fromString(content);
6661
+ doc = getXmlDocument().fromString(content);
6647
6662
  } catch (error) {
6648
6663
  if (error instanceof Error) {
6649
6664
  const { message, line, column } = this.parseLibxmlError(error.message);
@@ -8728,6 +8743,7 @@ var ContentValidator = class {
8728
8743
  }
8729
8744
  return Number.parseInt(el.name.substring(1), 10);
8730
8745
  };
8746
+ const XmlElement = getXmlElement();
8731
8747
  const directElementChildren = (parent) => {
8732
8748
  const out = [];
8733
8749
  let n = parent.firstChild;
@@ -10336,11 +10352,13 @@ function toJSONReport(result) {
10336
10352
  2
10337
10353
  );
10338
10354
  }
10355
+
10356
+ // src/ncx/validator.ts
10339
10357
  var NCXValidator = class {
10340
10358
  validate(context, ncxContent, ncxPath, registry) {
10341
10359
  let doc = null;
10342
10360
  try {
10343
- doc = XmlDocument.fromString(ncxContent);
10361
+ doc = getXmlDocument().fromString(ncxContent);
10344
10362
  } catch (error) {
10345
10363
  if (error instanceof Error) {
10346
10364
  pushMessage(context.messages, {
@@ -12097,11 +12115,11 @@ var RelaxNGValidator = class extends BaseSchemaValidator {
12097
12115
  try {
12098
12116
  const libxml2 = await import('libxml2-wasm');
12099
12117
  const LibRelaxNGValidator = libxml2.RelaxNGValidator;
12100
- const { XmlDocument: XmlDocument5 } = libxml2;
12101
- const doc = XmlDocument5.fromString(xml);
12118
+ const { XmlDocument } = libxml2;
12119
+ const doc = XmlDocument.fromString(xml);
12102
12120
  try {
12103
12121
  const schemaContent = await loadSchema(schemaPath);
12104
- const schemaDoc = XmlDocument5.fromString(schemaContent);
12122
+ const schemaDoc = XmlDocument.fromString(schemaContent);
12105
12123
  try {
12106
12124
  const validator = LibRelaxNGValidator.fromDoc(schemaDoc);
12107
12125
  try {
@@ -12311,6 +12329,7 @@ var EpubCheck = class _EpubCheck {
12311
12329
  */
12312
12330
  async check(data, filename) {
12313
12331
  const startTime = performance.now();
12332
+ await loadXmlEngine();
12314
12333
  const context = {
12315
12334
  data,
12316
12335
  options: this.options,
@@ -12352,6 +12371,7 @@ var EpubCheck = class _EpubCheck {
12352
12371
  */
12353
12372
  async checkExpanded(files) {
12354
12373
  const startTime = performance.now();
12374
+ await loadXmlEngine();
12355
12375
  const context = {
12356
12376
  data: new Uint8Array(0),
12357
12377
  options: this.options,
@@ -12396,6 +12416,7 @@ var EpubCheck = class _EpubCheck {
12396
12416
  async checkSingleFile(data, filename) {
12397
12417
  const startTime = performance.now();
12398
12418
  const mode = this.options.mode;
12419
+ await loadXmlEngine();
12399
12420
  const context = {
12400
12421
  data: new Uint8Array(0),
12401
12422
  options: this.options,