@coding01/docsjs 0.1.3 → 0.1.6

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.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { D as DocsWordEditorChangeDetail, a as DocsWordEditorElementApi, b as DocsWordEditorErrorDetail, c as DocsWordEditorReadyDetail } from './types-DF14w1ol.cjs';
1
+ export { D as DocsWordEditorChangeDetail, a as DocsWordEditorElementApi, b as DocsWordEditorErrorDetail, c as DocsWordEditorReadyDetail, d as DocxParseFeatureCounts, e as DocxParseReport, p as parseDocxToHtmlSnapshot, f as parseDocxToHtmlSnapshotWithReport } from './types-VvdwVF0_.cjs';
2
2
 
3
3
  declare class DocsWordElement extends HTMLElement {
4
4
  private rootRef;
@@ -48,6 +48,9 @@ interface SemanticStats {
48
48
  imageCount: number;
49
49
  anchorImageCount: number;
50
50
  wrappedImageCount: number;
51
+ ommlCount: number;
52
+ chartCount: number;
53
+ smartArtCount: number;
51
54
  listParagraphCount: number;
52
55
  commentRefCount: number;
53
56
  revisionInsCount: number;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { D as DocsWordEditorChangeDetail, a as DocsWordEditorElementApi, b as DocsWordEditorErrorDetail, c as DocsWordEditorReadyDetail } from './types-DF14w1ol.js';
1
+ export { D as DocsWordEditorChangeDetail, a as DocsWordEditorElementApi, b as DocsWordEditorErrorDetail, c as DocsWordEditorReadyDetail, d as DocxParseFeatureCounts, e as DocxParseReport, p as parseDocxToHtmlSnapshot, f as parseDocxToHtmlSnapshotWithReport } from './types-VvdwVF0_.js';
2
2
 
3
3
  declare class DocsWordElement extends HTMLElement {
4
4
  private rootRef;
@@ -48,6 +48,9 @@ interface SemanticStats {
48
48
  imageCount: number;
49
49
  anchorImageCount: number;
50
50
  wrappedImageCount: number;
51
+ ommlCount: number;
52
+ chartCount: number;
53
+ smartArtCount: number;
51
54
  listParagraphCount: number;
52
55
  commentRefCount: number;
53
56
  revisionInsCount: number;
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import {
2
2
  DocsWordElement,
3
- defineDocsWordElement
4
- } from "./chunk-PRPDJOB7.js";
3
+ defineDocsWordElement,
4
+ parseDocxToHtmlSnapshot,
5
+ parseDocxToHtmlSnapshotWithReport
6
+ } from "./chunk-632UOG2B.js";
5
7
 
6
8
  // src/lib/semanticStats.ts
7
9
  function countElements(root, selector) {
@@ -25,6 +27,9 @@ function collectSemanticStatsFromDocument(doc) {
25
27
  imageCount: countElements(doc, "img"),
26
28
  anchorImageCount: countElements(doc, 'img[data-word-anchor="1"]'),
27
29
  wrappedImageCount: countElements(doc, "img[data-word-wrap]"),
30
+ ommlCount: countElements(doc, "[data-word-omml]"),
31
+ chartCount: countElements(doc, "[data-word-chart]"),
32
+ smartArtCount: countElements(doc, "[data-word-smartart]"),
28
33
  listParagraphCount,
29
34
  commentRefCount: countElements(doc, "[data-word-comment-ref]"),
30
35
  revisionInsCount: countElements(doc, '[data-word-revision="ins"]'),
@@ -55,7 +60,7 @@ function clamp01(v) {
55
60
  }
56
61
  function calculateFidelityScore(expected, actual) {
57
62
  const structure = clamp01(
58
- (ratioScore(actual.paragraphCount, expected.paragraphCount) + ratioScore(actual.headingCount, expected.headingCount) + ratioScore(actual.tableCount, expected.tableCount) + ratioScore(actual.tableCellCount, expected.tableCellCount) + ratioScore(actual.imageCount, expected.imageCount) + ratioScore(actual.listParagraphCount, expected.listParagraphCount)) / 6
63
+ (ratioScore(actual.paragraphCount, expected.paragraphCount) + ratioScore(actual.headingCount, expected.headingCount) + ratioScore(actual.tableCount, expected.tableCount) + ratioScore(actual.tableCellCount, expected.tableCellCount) + ratioScore(actual.imageCount, expected.imageCount) + ratioScore(actual.ommlCount, expected.ommlCount) + ratioScore(actual.chartCount, expected.chartCount) + ratioScore(actual.smartArtCount, expected.smartArtCount) + ratioScore(actual.listParagraphCount, expected.listParagraphCount)) / 9
59
64
  );
60
65
  const styleProxy = clamp01(ratioScore(actual.textCharCount, expected.textCharCount));
61
66
  const pagination = clamp01(ratioScore(actual.pageSpacerCount, expected.pageSpacerCount));
@@ -67,6 +72,8 @@ export {
67
72
  calculateFidelityScore,
68
73
  collectSemanticStatsFromDocument,
69
74
  collectSemanticStatsFromHtml,
70
- defineDocsWordElement
75
+ defineDocsWordElement,
76
+ parseDocxToHtmlSnapshot,
77
+ parseDocxToHtmlSnapshotWithReport
71
78
  };
72
79
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/lib/semanticStats.ts","../src/lib/fidelityScore.ts"],"sourcesContent":["export interface SemanticStats {\n paragraphCount: number;\n headingCount: number;\n tableCount: number;\n tableCellCount: number;\n imageCount: number;\n anchorImageCount: number;\n wrappedImageCount: number;\n listParagraphCount: number;\n commentRefCount: number;\n revisionInsCount: number;\n revisionDelCount: number;\n pageBreakCount: number;\n pageSpacerCount: number;\n textCharCount: number;\n}\n\nfunction countElements(root: ParentNode, selector: string): number {\n return root.querySelectorAll(selector).length;\n}\n\nfunction isListLikeParagraph(p: Element): boolean {\n if (p.hasAttribute(\"data-word-list\")) return true;\n if (p.querySelector(\"span.__word-list-marker\")) return true;\n const style = (p.getAttribute(\"style\") ?? \"\").toLowerCase();\n return style.includes(\"mso-list\");\n}\n\nexport function collectSemanticStatsFromDocument(doc: Document): SemanticStats {\n const paragraphs = Array.from(doc.querySelectorAll(\"p\"));\n const listParagraphCount = paragraphs.filter((p) => isListLikeParagraph(p)).length;\n const textCharCount = (doc.body.textContent ?? \"\").replace(/\\s+/g, \"\").length;\n\n return {\n paragraphCount: paragraphs.length,\n headingCount: countElements(doc, \"h1,h2,h3,h4,h5,h6\"),\n tableCount: countElements(doc, \"table\"),\n tableCellCount: countElements(doc, \"td,th\"),\n imageCount: countElements(doc, \"img\"),\n anchorImageCount: countElements(doc, 'img[data-word-anchor=\"1\"]'),\n wrappedImageCount: countElements(doc, \"img[data-word-wrap]\"),\n listParagraphCount,\n commentRefCount: countElements(doc, \"[data-word-comment-ref]\"),\n revisionInsCount: countElements(doc, '[data-word-revision=\"ins\"]'),\n revisionDelCount: countElements(doc, '[data-word-revision=\"del\"]'),\n pageBreakCount: countElements(doc, \"[data-word-page-break='1']\"),\n pageSpacerCount: countElements(doc, \"[data-word-page-spacer='1']\"),\n textCharCount\n };\n}\n\nexport function collectSemanticStatsFromHtml(rawHtml: string): SemanticStats {\n const parser = new DOMParser();\n const doc = parser.parseFromString(rawHtml, \"text/html\");\n return collectSemanticStatsFromDocument(doc);\n}\n","import type { SemanticStats } from \"./semanticStats\";\n\nexport interface FidelityScore {\n structure: number;\n styleProxy: number;\n pagination: number;\n overall: number;\n}\n\nfunction ratioScore(actual: number, expected: number): number {\n if (expected <= 0 && actual <= 0) return 1;\n if (expected <= 0 || actual < 0) return 0;\n const delta = Math.abs(actual - expected);\n const penalty = delta / expected;\n return Math.max(0, 1 - penalty);\n}\n\nfunction clamp01(v: number): number {\n if (v < 0) return 0;\n if (v > 1) return 1;\n return v;\n}\n\nexport function calculateFidelityScore(expected: SemanticStats, actual: SemanticStats): FidelityScore {\n const structure = clamp01(\n (\n ratioScore(actual.paragraphCount, expected.paragraphCount) +\n ratioScore(actual.headingCount, expected.headingCount) +\n ratioScore(actual.tableCount, expected.tableCount) +\n ratioScore(actual.tableCellCount, expected.tableCellCount) +\n ratioScore(actual.imageCount, expected.imageCount) +\n ratioScore(actual.listParagraphCount, expected.listParagraphCount)\n ) / 6\n );\n\n const styleProxy = clamp01(ratioScore(actual.textCharCount, expected.textCharCount));\n const pagination = clamp01(ratioScore(actual.pageSpacerCount, expected.pageSpacerCount));\n const overall = clamp01(structure * 0.6 + styleProxy * 0.25 + pagination * 0.15);\n\n return { structure, styleProxy, pagination, overall };\n}\n"],"mappings":";;;;;;AAiBA,SAAS,cAAc,MAAkB,UAA0B;AACjE,SAAO,KAAK,iBAAiB,QAAQ,EAAE;AACzC;AAEA,SAAS,oBAAoB,GAAq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Q;AACxC,QAAM,UAAU,QAAQ;AACxB,SAAO,KAAK,IAAI,GAAG,IAAI,OAAO;AAChC;AAEA,SAAS,QAAQ,GAAmB;AAClC,MAAI,IAAI,EAAG,QAAO;AAClB,MAAI,IAAI,EAAG,QAAO;AAClB,SAAO;AACT;AAEO,SAAS,uBAAuB,UAAyB,QAAsC;AACpG,QAAM,YAAY;AAAA,KAEd,WAAW,OAAO,gBAAgB,SAAS,cAAc,IACzD,WAAW,OAAO,cAAc,SAAS,YAAY,IACrD,WAAW,OAAO,YAAY,SAAS,UAAU,IACjD,WAAW,OAAO,gBAAgB,SAAS,cAAc,IACzD,WAAW,OAAO,YAAY,SAAS,UAAU,IACjD,WAAW,OAAO,oBAAoB,SAAS,kBAAkB,KAC/D;AAAA,EACN;AAEA,QAAM,aAAa,QAAQ,WAAW,OAAO,eAAe,SAAS,aAAa,CAAC;AACnF,QAAM,aAAa,QAAQ,WAAW,OAAO,iBAAiB,SAAS,eAAe,CAAC;AACvF,QAAM,UAAU,QAAQ,YAAY,MAAM,aAAa,OAAO,aAAa,IAAI;AAE/E,SAAO,EAAE,WAAW,YAAY,YAAY,QAAQ;AACtD;","names":[]}
1
+ {"version":3,"sources":["../src/lib/semanticStats.ts","../src/lib/fidelityScore.ts"],"sourcesContent":["export interface SemanticStats {\n paragraphCount: number;\n headingCount: number;\n tableCount: number;\n tableCellCount: number;\n imageCount: number;\n anchorImageCount: number;\n wrappedImageCount: number;\n ommlCount: number;\n chartCount: number;\n smartArtCount: number;\n listParagraphCount: number;\n commentRefCount: number;\n revisionInsCount: number;\n revisionDelCount: number;\n pageBreakCount: number;\n pageSpacerCount: number;\n textCharCount: number;\n}\n\nfunction countElements(root: ParentNode, selector: string): number {\n return root.querySelectorAll(selector).length;\n}\n\nfunction isListLikeParagraph(p: Element): boolean {\n if (p.hasAttribute(\"data-word-list\")) return true;\n if (p.querySelector(\"span.__word-list-marker\")) return true;\n const style = (p.getAttribute(\"style\") ?? \"\").toLowerCase();\n return style.includes(\"mso-list\");\n}\n\nexport function collectSemanticStatsFromDocument(doc: Document): SemanticStats {\n const paragraphs = Array.from(doc.querySelectorAll(\"p\"));\n const listParagraphCount = paragraphs.filter((p) => isListLikeParagraph(p)).length;\n const textCharCount = (doc.body.textContent ?? \"\").replace(/\\s+/g, \"\").length;\n\n return {\n paragraphCount: paragraphs.length,\n headingCount: countElements(doc, \"h1,h2,h3,h4,h5,h6\"),\n tableCount: countElements(doc, \"table\"),\n tableCellCount: countElements(doc, \"td,th\"),\n imageCount: countElements(doc, \"img\"),\n anchorImageCount: countElements(doc, 'img[data-word-anchor=\"1\"]'),\n wrappedImageCount: countElements(doc, \"img[data-word-wrap]\"),\n ommlCount: countElements(doc, \"[data-word-omml]\"),\n chartCount: countElements(doc, \"[data-word-chart]\"),\n smartArtCount: countElements(doc, \"[data-word-smartart]\"),\n listParagraphCount,\n commentRefCount: countElements(doc, \"[data-word-comment-ref]\"),\n revisionInsCount: countElements(doc, '[data-word-revision=\"ins\"]'),\n revisionDelCount: countElements(doc, '[data-word-revision=\"del\"]'),\n pageBreakCount: countElements(doc, \"[data-word-page-break='1']\"),\n pageSpacerCount: countElements(doc, \"[data-word-page-spacer='1']\"),\n textCharCount\n };\n}\n\nexport function collectSemanticStatsFromHtml(rawHtml: string): SemanticStats {\n const parser = new DOMParser();\n const doc = parser.parseFromString(rawHtml, \"text/html\");\n return collectSemanticStatsFromDocument(doc);\n}\n","import type { SemanticStats } from \"./semanticStats\";\n\nexport interface FidelityScore {\n structure: number;\n styleProxy: number;\n pagination: number;\n overall: number;\n}\n\nfunction ratioScore(actual: number, expected: number): number {\n if (expected <= 0 && actual <= 0) return 1;\n if (expected <= 0 || actual < 0) return 0;\n const delta = Math.abs(actual - expected);\n const penalty = delta / expected;\n return Math.max(0, 1 - penalty);\n}\n\nfunction clamp01(v: number): number {\n if (v < 0) return 0;\n if (v > 1) return 1;\n return v;\n}\n\nexport function calculateFidelityScore(expected: SemanticStats, actual: SemanticStats): FidelityScore {\n const structure = clamp01(\n (\n ratioScore(actual.paragraphCount, expected.paragraphCount) +\n ratioScore(actual.headingCount, expected.headingCount) +\n ratioScore(actual.tableCount, expected.tableCount) +\n ratioScore(actual.tableCellCount, expected.tableCellCount) +\n ratioScore(actual.imageCount, expected.imageCount) +\n ratioScore(actual.ommlCount, expected.ommlCount) +\n ratioScore(actual.chartCount, expected.chartCount) +\n ratioScore(actual.smartArtCount, expected.smartArtCount) +\n ratioScore(actual.listParagraphCount, expected.listParagraphCount)\n ) / 9\n );\n\n const styleProxy = clamp01(ratioScore(actual.textCharCount, expected.textCharCount));\n const pagination = clamp01(ratioScore(actual.pageSpacerCount, expected.pageSpacerCount));\n const overall = clamp01(structure * 0.6 + styleProxy * 0.25 + pagination * 0.15);\n\n return { structure, styleProxy, pagination, overall };\n}\n"],"mappings":";;;;;;;;AAoBA,SAAS,cAAc,MAAkB,UAA0B;AACjE,SAAO,KAAK,iBAAiB,QAAQ,EAAE;AACzC;AAEA,SAAS,oBAAoB,GAAqB;AAChD,MAAI,EAAE,aAAa,gBAAgB,EAAG,QAAO;AAC7C,MAAI,EAAE,cAAc,yBAAyB,EAAG,QAAO;AACvD,QAAM,SAAS,EAAE,aAAa,OAAO,KAAK,IAAI,YAAY;AAC1D,SAAO,MAAM,SAAS,UAAU;AAClC;AAEO,SAAS,iCAAiC,KAA8B;AAC7E,QAAM,aAAa,MAAM,KAAK,IAAI,iBAAiB,GAAG,CAAC;AACvD,QAAM,qBAAqB,WAAW,OAAO,CAAC,MAAM,oBAAoB,CAAC,CAAC,EAAE;AAC5E,QAAM,iBAAiB,IAAI,KAAK,eAAe,IAAI,QAAQ,QAAQ,EAAE,EAAE;AAEvE,SAAO;AAAA,IACL,gBAAgB,WAAW;AAAA,IAC3B,cAAc,cAAc,KAAK,mBAAmB;AAAA,IACpD,YAAY,cAAc,KAAK,OAAO;AAAA,IACtC,gBAAgB,cAAc,KAAK,OAAO;AAAA,IAC1C,YAAY,cAAc,KAAK,KAAK;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