@coding01/docsjs 0.1.6 → 0.1.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/index.d.ts CHANGED
@@ -1,5 +1,3 @@
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
-
3
1
  declare class DocsWordElement extends HTMLElement {
4
2
  private rootRef;
5
3
  private toolbar;
@@ -70,4 +68,47 @@ interface FidelityScore {
70
68
  }
71
69
  declare function calculateFidelityScore(expected: SemanticStats, actual: SemanticStats): FidelityScore;
72
70
 
73
- export { DocsWordElement, type FidelityScore, type SemanticStats, calculateFidelityScore, collectSemanticStatsFromDocument, collectSemanticStatsFromHtml, defineDocsWordElement };
71
+ interface DocxParseFeatureCounts {
72
+ hyperlinkCount: number;
73
+ anchorImageCount: number;
74
+ chartCount: number;
75
+ smartArtCount: number;
76
+ ommlCount: number;
77
+ tableCount: number;
78
+ footnoteRefCount: number;
79
+ endnoteRefCount: number;
80
+ commentRefCount: number;
81
+ revisionCount: number;
82
+ pageBreakCount: number;
83
+ }
84
+ interface DocxParseReport {
85
+ elapsedMs: number;
86
+ features: DocxParseFeatureCounts;
87
+ }
88
+ declare function parseDocxToHtmlSnapshotWithReport(file: File): Promise<{
89
+ htmlSnapshot: string;
90
+ report: DocxParseReport;
91
+ }>;
92
+ declare function parseDocxToHtmlSnapshot(file: File): Promise<string>;
93
+
94
+ interface DocsWordEditorChangeDetail {
95
+ htmlSnapshot: string;
96
+ source: "paste" | "upload" | "api" | "clear";
97
+ fileName?: string;
98
+ parseReport?: DocxParseReport;
99
+ }
100
+ interface DocsWordEditorErrorDetail {
101
+ message: string;
102
+ }
103
+ interface DocsWordEditorReadyDetail {
104
+ version: string;
105
+ }
106
+ interface DocsWordEditorElementApi extends HTMLElement {
107
+ loadDocx(file: File): Promise<void>;
108
+ loadHtml(rawHtml: string): void;
109
+ loadClipboard(): Promise<void>;
110
+ clear(): void;
111
+ getSnapshot(): string;
112
+ }
113
+
114
+ export { type DocsWordEditorChangeDetail, type DocsWordEditorElementApi, type DocsWordEditorErrorDetail, type DocsWordEditorReadyDetail, DocsWordElement, type DocxParseFeatureCounts, type DocxParseReport, type FidelityScore, type SemanticStats, calculateFidelityScore, collectSemanticStatsFromDocument, collectSemanticStatsFromHtml, defineDocsWordElement, parseDocxToHtmlSnapshot, parseDocxToHtmlSnapshotWithReport };
package/dist/index.js CHANGED
@@ -1,79 +1,60 @@
1
- import {
2
- DocsWordElement,
3
- defineDocsWordElement,
4
- parseDocxToHtmlSnapshot,
5
- parseDocxToHtmlSnapshotWithReport
6
- } from "./chunk-632UOG2B.js";
7
-
8
- // src/lib/semanticStats.ts
9
- function countElements(root, selector) {
10
- return root.querySelectorAll(selector).length;
11
- }
12
- function isListLikeParagraph(p) {
13
- if (p.hasAttribute("data-word-list")) return true;
14
- if (p.querySelector("span.__word-list-marker")) return true;
15
- const style = (p.getAttribute("style") ?? "").toLowerCase();
16
- return style.includes("mso-list");
17
- }
18
- function collectSemanticStatsFromDocument(doc) {
19
- const paragraphs = Array.from(doc.querySelectorAll("p"));
20
- const listParagraphCount = paragraphs.filter((p) => isListLikeParagraph(p)).length;
21
- const textCharCount = (doc.body.textContent ?? "").replace(/\s+/g, "").length;
22
- return {
23
- paragraphCount: paragraphs.length,
24
- headingCount: countElements(doc, "h1,h2,h3,h4,h5,h6"),
25
- tableCount: countElements(doc, "table"),
26
- tableCellCount: countElements(doc, "td,th"),
27
- imageCount: countElements(doc, "img"),
28
- anchorImageCount: countElements(doc, 'img[data-word-anchor="1"]'),
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]"),
33
- listParagraphCount,
34
- commentRefCount: countElements(doc, "[data-word-comment-ref]"),
35
- revisionInsCount: countElements(doc, '[data-word-revision="ins"]'),
36
- revisionDelCount: countElements(doc, '[data-word-revision="del"]'),
37
- pageBreakCount: countElements(doc, "[data-word-page-break='1']"),
38
- pageSpacerCount: countElements(doc, "[data-word-page-spacer='1']"),
39
- textCharCount
40
- };
41
- }
42
- function collectSemanticStatsFromHtml(rawHtml) {
43
- const parser = new DOMParser();
44
- const doc = parser.parseFromString(rawHtml, "text/html");
45
- return collectSemanticStatsFromDocument(doc);
46
- }
47
-
48
- // src/lib/fidelityScore.ts
49
- function ratioScore(actual, expected) {
50
- if (expected <= 0 && actual <= 0) return 1;
51
- if (expected <= 0 || actual < 0) return 0;
52
- const delta = Math.abs(actual - expected);
53
- const penalty = delta / expected;
54
- return Math.max(0, 1 - penalty);
55
- }
56
- function clamp01(v) {
57
- if (v < 0) return 0;
58
- if (v > 1) return 1;
59
- return v;
60
- }
61
- function calculateFidelityScore(expected, actual) {
62
- const structure = clamp01(
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
64
- );
65
- const styleProxy = clamp01(ratioScore(actual.textCharCount, expected.textCharCount));
66
- const pagination = clamp01(ratioScore(actual.pageSpacerCount, expected.pageSpacerCount));
67
- const overall = clamp01(structure * 0.6 + styleProxy * 0.25 + pagination * 0.15);
68
- return { structure, styleProxy, pagination, overall };
69
- }
70
- export {
71
- DocsWordElement,
72
- calculateFidelityScore,
73
- collectSemanticStatsFromDocument,
74
- collectSemanticStatsFromHtml,
75
- defineDocsWordElement,
76
- parseDocxToHtmlSnapshot,
77
- parseDocxToHtmlSnapshotWithReport
78
- };
79
- //# sourceMappingURL=index.js.map
1
+ var St='<!DOCTYPE html><html><head><meta charset="utf-8"/>',Ft="</head><body></body></html>";function nt(e){return e.trim()?/<html[\s>]/i.test(e)?e:`${St}${Ft}`.replace("<body></body>",`<body>${e}</body>`):`${St}${Ft}`}import Zt from"jszip";function Yt(){return{hyperlinkCount:0,anchorImageCount:0,chartCount:0,smartArtCount:0,ommlCount:0,tableCount:0,footnoteRefCount:0,endnoteRefCount:0,commentRefCount:0,revisionCount:0,pageBreakCount:0}}function W(e){return e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;")}function lt(e){return new DOMParser().parseFromString(e,"application/xml")}function Nt(e){return Array.from(e.children??[])}function O(e,t){let n=[],r=Nt(e).reverse();for(;r.length>0;){let o=r.pop();o.localName===t&&n.push(o);let i=o.children;for(let l=i.length-1;l>=0;l-=1)r.push(i[l])}return n}function L(e,t){let n=Nt(e).reverse();for(;n.length>0;){let r=n.pop();if(r.localName===t)return r;let o=r.children;for(let i=o.length-1;i>=0;i-=1)n.push(o[i])}return null}function x(e,t){return Array.from(e.children).filter(n=>n.localName===t)}function c(e,t){return e?e.getAttribute(t):null}function at(e){return e*96/914400}function ct(e){return e*96/1440}function Qt(e){let t=O(e,"extent").find(s=>{let u=s.parentElement;return u?.localName==="inline"||u?.localName==="anchor"})??null;if(!t)return{widthPx:null,heightPx:null};let n=c(t,"cx"),r=c(t,"cy"),o=n?Number.parseInt(n,10):Number.NaN,i=r?Number.parseInt(r,10):Number.NaN,l=Number.isFinite(o)&&o>0?at(o):null,a=Number.isFinite(i)&&i>0?at(i):null;return{widthPx:l,heightPx:a}}function te(e){let t=[];if(e.widthPx!==null&&t.push(`width="${Math.round(e.widthPx)}"`),e.heightPx!==null&&t.push(`height="${Math.round(e.heightPx)}"`),e.widthPx!==null||e.heightPx!==null){let n=["max-width:100%"];e.widthPx!==null&&n.push(`width:${e.widthPx.toFixed(2)}px`),e.heightPx!==null&&n.push(`height:${e.heightPx.toFixed(2)}px`),t.push(`style="${n.join(";")}"`)}return t.length>0?` ${t.join(" ")}`:""}function ee(e){let t=null,n=null,r=x(e,"positionH")[0]??null,o=x(e,"positionV")[0]??null,i=r?x(r,"posOffset")[0]??null:null,l=o?x(o,"posOffset")[0]??null:null,a=i?.textContent?.trim()??"",s=l?.textContent?.trim()??"",u=a?Number.parseFloat(a):Number.NaN,f=s?Number.parseFloat(s):Number.NaN;return Number.isFinite(u)&&(t=at(u)),Number.isFinite(f)&&(n=at(f)),{leftPx:t,topPx:n}}function ne(e){return x(e,"wrapSquare")[0]?"square":x(e,"wrapTight")[0]?"tight":x(e,"wrapTopAndBottom")[0]?"topAndBottom":x(e,"wrapNone")[0]?"none":null}function re(e){let t=x(e,"anchor")[0]??null;if(!t)return null;let n=x(t,"positionH")[0]??null,r=x(t,"positionV")[0]??null,o=c(n,"relativeFrom"),i=c(r,"relativeFrom"),l=f=>{let d=c(t,f),h=d?Number.parseInt(d,10):Number.NaN;return Number.isFinite(h)&&h>=0?at(h):null},a=c(t,"relativeHeight"),s=a?Number.parseInt(a,10):Number.NaN,u=(f,d)=>{let h=(c(t,f)??"").toLowerCase();return h==="1"||h==="true"||h==="on"?!0:h==="0"||h==="false"||h==="off"?!1:d};return{position:ee(t),wrapMode:ne(t),distTPx:l("distT"),distBPx:l("distB"),distLPx:l("distL"),distRPx:l("distR"),relativeFromH:o,relativeFromV:i,behindDoc:u("behindDoc",!1),allowOverlap:u("allowOverlap",!0),layoutInCell:u("layoutInCell",!0),relativeHeight:Number.isFinite(s)?s:null}}function oe(e,t){if(!t)return e;let{position:n,wrapMode:r}=t;if(n.leftPx===null&&n.topPx===null)return e;let o=["position:absolute",n.leftPx!==null?`left:${n.leftPx.toFixed(2)}px`:"",n.topPx!==null?`top:${n.topPx.toFixed(2)}px`:"",`z-index:${t.behindDoc?0:t.relativeHeight??3}`,t.distTPx!==null?`margin-top:${t.distTPx.toFixed(2)}px`:"",t.distBPx!==null?`margin-bottom:${t.distBPx.toFixed(2)}px`:"",t.distLPx!==null?`margin-left:${t.distLPx.toFixed(2)}px`:"",t.distRPx!==null?`margin-right:${t.distRPx.toFixed(2)}px`:""].filter(l=>l.length>0);r==="topAndBottom"&&o.push("display:block","clear:both");let i=['data-word-anchor="1"',r?`data-word-wrap="${r}"`:"",t.relativeFromH?`data-word-anchor-relh="${W(t.relativeFromH)}"`:"",t.relativeFromV?`data-word-anchor-relv="${W(t.relativeFromV)}"`:"",t.behindDoc?'data-word-anchor-behind="1"':'data-word-anchor-behind="0"',t.allowOverlap?'data-word-anchor-overlap="1"':'data-word-anchor-overlap="0"',t.layoutInCell?'data-word-anchor-layout-cell="1"':'data-word-anchor-layout-cell="0"'].filter(l=>l.length>0).join(" ");return e.includes("style=")?e.replace(/style="([^"]*)"/,(l,a)=>`style="${[a,...o].filter(u=>u.length>0).join(";")}" ${i}`):`${e} style="${o.join(";")}" ${i}`}function ie(e){if(!e)return{};let t=lt(e),n=O(t,"Relationship"),r={};for(let o of n){let i=c(o,"Id"),l=c(o,"Target");!i||!l||(r[i]=l)}return r}function le(e){let t=e.toLowerCase();return t==="png"?"image/png":t==="jpg"||t==="jpeg"?"image/jpeg":t==="gif"?"image/gif":t==="webp"?"image/webp":t==="bmp"?"image/bmp":t==="svg"?"image/svg+xml":"application/octet-stream"}function Lt(e){let t=e.replace(/\\/g,"/").replace(/^\/+/,"");return t.startsWith("word/")?t:t.startsWith("../")?`word/${t.replace(/^(\.\.\/)+/,"")}`:`word/${t}`}function ae(e,t,n){if(n&&n.trim())return`#${encodeURIComponent(n.trim())}`;if(!t)return null;let r=e[t];if(!r)return null;let o=r.trim();if(!o)return null;let i=o.toLowerCase();return i.startsWith("http://")||i.startsWith("https://")||i.startsWith("mailto:")||i.startsWith("tel:")||o.startsWith("#")?o:`#${encodeURIComponent(o)}`}async function se(e,t,n){let r=t[n];if(!r)return null;let o=Lt(r),i=e.file(o);if(!i)return null;let l=await i.async("base64"),a=o.split(".").pop()??"bin";return`data:${le(a)};base64,${l}`}async function $t(e,t,n){let r=t[n];if(!r)return null;let o=Lt(r),i=e.file(o);return i?i.async("string"):null}function ue(e){let t=["barChart","lineChart","pieChart","areaChart","scatterChart","radarChart","doughnutChart"];for(let n of t)if(L(e,n))return n.replace(/Chart$/,"");return"unknown"}function ce(e){let t=lt(e),n=O(t,"t").map(l=>(l.textContent??"").trim()).find(l=>l.length>0)??"Chart",r=O(t,"ser").length,o=O(t,"pt").length,i=ue(t);return{title:n,type:i,seriesCount:r,pointCount:o}}function pe(e){let t=lt(e);return O(t,"t").map(n=>(n.textContent??"").trim()).filter(n=>n.length>0).slice(0,12)}function Z(e){if(e.localName==="t")return e.textContent??"";if(e.localName==="f"){let t=L(e,"num"),n=L(e,"den");return`(${t?Z(t):"?"})/(${n?Z(n):"?"})`}if(e.localName==="sSup"){let t=L(e,"e"),n=L(e,"sup");return`${t?Z(t):""}^(${n?Z(n):""})`}if(e.localName==="sSub"){let t=L(e,"e"),n=L(e,"sub");return`${t?Z(t):""}_(${n?Z(n):""})`}if(e.localName==="rad"){let t=L(e,"e");return`sqrt(${t?Z(t):""})`}return Array.from(e.children).map(t=>Z(t)).join("")}function me(e){if(!e)return"";let t=[];L(e,"b")&&t.push("font-weight:700"),L(e,"i")&&t.push("font-style:italic"),L(e,"u")&&t.push("text-decoration:underline"),L(e,"strike")&&t.push("text-decoration:line-through");let n=L(e,"color"),r=c(n,"w:val")??c(n,"val");r&&r.toLowerCase()!=="auto"&&t.push(`color:#${r}`);let o=L(e,"highlight");(c(o,"w:val")??c(o,"val")??"").toLowerCase()==="yellow"&&t.push("background-color:#fff200");let l=L(e,"vertAlign"),a=(c(l,"w:val")??c(l,"val")??"").toLowerCase();return a==="superscript"&&t.push("vertical-align:super;font-size:0.83em"),a==="subscript"&&t.push("vertical-align:sub;font-size:0.83em"),t.join(";")}function de(e){let t=L(e,"pPr"),n=t?L(t,"pStyle"):null,r=(c(n,"w:val")??c(n,"val")??"").toLowerCase();return r.includes("heading1")||r==="1"||r==="heading 1"?"h1":r.includes("heading2")||r==="2"||r==="heading 2"?"h2":r.includes("heading3")||r==="3"||r==="heading 3"?"h3":"p"}function ge(e){let t=L(e,"pPr"),n=t?L(t,"jc"):null,r=(c(n,"w:val")??c(n,"val")??"").toLowerCase();return r==="center"||r==="right"||r==="left"?`text-align:${r};`:""}function Ht(e){return e===null?"":` data-word-p-index="${e}"`}function Tt(e){return O(e,"p").map(n=>Et(n)).join("<br/>").trim()}function At(e,t,n){if(!e)return{};let r=lt(e),o={},i=O(r,t);for(let l of i){let a=c(l,"w:id")??c(l,"id");if(!a)continue;if(n.requirePositiveNumericId){let u=Number.parseInt(a,10);if(!Number.isFinite(u)||u<=0)continue}let s=Tt(l);s&&(o[a]=s)}return o}function fe(e){return At(e,"footnote",{requirePositiveNumericId:!0})}function he(e){if(!e)return{};let t=lt(e),n={},r=O(t,"comment");for(let o of r){let i=c(o,"w:id")??c(o,"id");if(!i)continue;let l=Tt(o);l&&(n[i]={author:c(o,"w:author")??c(o,"author"),date:c(o,"w:date")??c(o,"date"),text:l})}return n}function be(e){return At(e,"endnote",{requirePositiveNumericId:!0})}function xe(e,t){let n=[...new Set(e)].filter(o=>t[o]);return n.length===0?"":`<section data-word-footnotes="1"><hr/><ol>${n.map(o=>`<li id="word-footnote-${o}" data-word-footnote-id="${o}">${t[o]}</li>`).join("")}</ol></section>`}function ye(e,t){let n=[...new Set(e)].filter(o=>t[o]);return n.length===0?"":`<section data-word-comments="1"><hr/><ol>${n.map(o=>{let i=t[o],l=[i.author??"",i.date??""].filter(s=>s.length>0).join(" \xB7 "),a=l?`<div data-word-comment-meta="1">${W(l)}</div>`:"";return`<li id="word-comment-${o}" data-word-comment-id="${o}">${a}<div>${i.text}</div></li>`}).join("")}</ol></section>`}function we(e,t){let n=[...new Set(e)].filter(o=>t[o]);return n.length===0?"":`<section data-word-endnotes="1"><hr/><ol>${n.map(o=>`<li id="word-endnote-${o}" data-word-endnote-id="${o}">${t[o]}</li>`).join("")}</ol></section>`}function Rt(e){let t={text:"",delText:"",lineBreakCount:0,pageBreakCount:0},n=[e];for(;n.length>0;){let r=n.pop(),o=r.localName;o==="t"?t.text+=r.textContent??"":o==="delText"?t.delText+=r.textContent??"":o==="br"&&((c(r,"w:type")??c(r,"type")??"").toLowerCase()==="page"?t.pageBreakCount+=1:t.lineBreakCount+=1);let i=r.children;for(let l=i.length-1;l>=0;l-=1)n.push(i[l])}return t}async function Pe(e,t,n,r,o,i,l,a,s,u,f){let d=de(r),h=ge(r),y=Ht(o);if(!(L(r,"r")!==null||L(r,"oMath")!==null||L(r,"oMathPara")!==null))return`<${d}${y}${h?` style="${h}"`:""}><br/></${d}>`;function H(m,T){return{type:T,id:c(m,"w:id")??c(m,"id"),author:c(m,"w:author")??c(m,"author"),date:c(m,"w:date")??c(m,"date")}}function S(m,T){if(T)return T;let w=m;for(;w;){if(w.localName==="ins")return H(w,"ins");if(w.localName==="del")return H(w,"del");if(w.localName==="p")break;w=w.parentElement}return null}function P(m){let T=[`data-word-revision="${m.type}"`];return m.id&&T.push(`data-word-revision-id="${W(m.id)}"`),m.author&&T.push(`data-word-revision-author="${W(m.author)}"`),m.date&&T.push(`data-word-revision-date="${W(m.date)}"`),T.join(" ")}async function $(m,T){let w=[],v=x(m,"rPr")[0]??null,A=me(v),D=x(m,"footnoteReference")[0]??null,I=c(D,"w:id")??c(D,"id");if(I&&i[I])return n.features.footnoteRefCount+=1,l.push(I),w.push(`<sup data-word-footnote-ref="${I}"><a href="#word-footnote-${I}">[${I}]</a></sup>`),w;let Y=x(m,"endnoteReference")[0]??null,U=c(Y,"w:id")??c(Y,"id");if(U&&a[U])return n.features.endnoteRefCount+=1,s.push(U),w.push(`<sup data-word-endnote-ref="${U}"><a href="#word-endnote-${U}">[${U}]</a></sup>`),w;let st=x(m,"commentReference")[0]??null,Q=c(st,"w:id")??c(st,"id");if(Q&&u[Q])return n.features.commentRefCount+=1,f.push(Q),w.push(`<sup data-word-comment-ref="${Q}"><a href="#word-comment-${Q}">[c${Q}]</a></sup>`),w;let tt=x(m,"drawing")[0]??null;if(tt){let z=L(tt,"blip"),B=c(z,"r:embed")??c(z,"embed");if(B){let et=await se(e,t,B);if(et){let q=Qt(tt),bt=te(q),vt=re(tt),Kt=oe(bt,vt);return vt&&(n.features.anchorImageCount+=1),w.push(`<img src="${et}" alt="word-image"${Kt}/>`),w}}let ot=L(tt,"chart"),ut=c(ot,"r:id")??c(ot,"id");if(ut){let et=await $t(e,t,ut);if(et){let q=ce(et);return n.features.chartCount+=1,w.push(`<figure data-word-chart="1" data-word-chart-type="${q.type}" data-word-chart-series="${q.seriesCount}" data-word-chart-points="${q.pointCount}"><figcaption>${W(q.title)}</figcaption><div>Chart(${W(q.type)}): series=${q.seriesCount}, points=${q.pointCount}</div></figure>`),w}}let Pt=L(tt,"relIds"),Ct=c(Pt,"r:dm")??c(Pt,"dm");if(Ct){let et=await $t(e,t,Ct),q=et?pe(et):[];n.features.smartArtCount+=1;let bt=q.length>0?`: ${W(q.join(" / "))}`:"";return w.push(`<figure data-word-smartart="1" data-word-smartart-items="${q.length}"><figcaption>SmartArt fallback${bt}</figcaption></figure>`),w}}let rt=Rt(m),it=`${W(rt.text||rt.delText)}${"<br/>".repeat(rt.lineBreakCount)}`;if(it){let z=S(m,T);if(A){let B=`<span style="${A}">${it}</span>`;if(z){n.features.revisionCount+=1;let ot=z.type==="ins"?"ins":"del";w.push(`<${ot} ${P(z)}>${B}</${ot}>`)}else w.push(B)}else if(z){n.features.revisionCount+=1;let B=z.type==="ins"?"ins":"del";w.push(`<${B} ${P(z)}>${it}</${B}>`)}else w.push(it)}for(let z=0;z<rt.pageBreakCount;z+=1)n.features.pageBreakCount+=1,w.push('<span data-word-page-break="1" style="display:block;break-before:page"></span>');return w}async function F(m,T){if(m.localName==="commentRangeStart"){let v=c(m,"w:id")??c(m,"id");return v?[`<span data-word-comment-range-start="${v}"></span>`]:[]}if(m.localName==="commentRangeEnd"){let v=c(m,"w:id")??c(m,"id");return v?[`<span data-word-comment-range-end="${v}"></span>`]:[]}if(m.localName==="r")return $(m,T);if(m.localName==="hyperlink"){let v=c(m,"r:id")??c(m,"id"),A=c(m,"w:anchor")??c(m,"anchor"),D=ae(t,v,A),I=[];for(let U of Array.from(m.children))I.push(...await F(U,T));let Y=I.join("")||W(m.textContent??"");return D?(n.features.hyperlinkCount+=1,[`<a data-word-hyperlink="1" href="${W(D)}" rel="noreferrer noopener" target="_blank">${Y}</a>`]):Y?[Y]:[]}if(m.localName==="oMath"||m.localName==="oMathPara"){let v=Z(m).trim();return v?(n.features.ommlCount+=1,[`<span data-word-omml="1">${W(v)}</span>`]):[]}if(m.localName==="ins"||m.localName==="del"){let v=H(m,m.localName==="ins"?"ins":"del"),A=[];for(let D of Array.from(m.children))A.push(...await F(D,v));return A}let w=[];for(let v of Array.from(m.children))w.push(...await F(v,T));return w}let N=[],E=O(r,"lastRenderedPageBreak").length;for(let m=0;m<E;m+=1)n.features.pageBreakCount+=1,N.push('<span data-word-page-break="1" style="display:block;break-before:page"></span>');for(let m of Array.from(r.children))N.push(...await F(m,null));let R=N.join("")||"<br/>";return`<${d}${y}${h?` style="${h}"`:""}>${R}</${d}>`}function Ce(e){let t=Rt(e),n=t.lineBreakCount+t.pageBreakCount;return`${W(t.text||t.delText)}${"<br/>".repeat(n)}`}function Et(e){return O(e,"r").map(r=>Ce(r)).join("")||"<br/>"}function ve(e){let t=x(e,"tcPr")[0]??null,n=t?x(t,"gridSpan")[0]??null:null,r=c(n,"w:val")??c(n,"val"),o=r?Number.parseInt(r,10):Number.NaN;return Number.isFinite(o)&&o>0?o:1}function Se(e){let t=x(e,"tcPr")[0]??null,n=t?x(t,"vMerge")[0]??null:null;return n?(c(n,"w:val")??c(n,"val")??"continue").toLowerCase()==="restart"?"restart":"continue":"none"}function Fe(e){let t=x(e,"tblGrid")[0]??null;return t?x(t,"gridCol").map(n=>{let r=c(n,"w:w")??c(n,"w"),o=r?Number.parseInt(r,10):Number.NaN;return Number.isFinite(o)&&o>0?ct(o):0}).filter(n=>n>0):[]}function $e(e){return e/6}function G(e){if(!e)return null;let t=(c(e,"w:val")??c(e,"val")??"").toLowerCase();if(!t||t==="nil"||t==="none")return"none";let n=(c(e,"w:color")??c(e,"color")??"222222").replace(/^#/,""),r=c(e,"w:sz")??c(e,"sz"),o=r?Number.parseInt(r,10):Number.NaN,i=Number.isFinite(o)&&o>0?$e(o):1,l=t==="single"?"solid":t;return`${i.toFixed(2)}px ${l} #${n}`}function Ne(e){let t=x(e,"tblPr")[0]??null,n=t?x(t,"tblBorders")[0]??null:null,r=t?x(t,"tblLayout")[0]??null:null,o=t?x(t,"tblCellSpacing")[0]??null:null,i=(c(o,"w:type")??c(o,"type")??"dxa").toLowerCase(),l=c(o,"w:w")??c(o,"w"),a=l?Number.parseFloat(l):Number.NaN,s=i==="dxa"&&Number.isFinite(a)&&a>0?ct(a):0,u=s>0?"separate":"collapse",f=(c(r,"w:type")??c(r,"type")??"").toLowerCase()==="autofit"?"auto":"fixed",d=G(n?x(n,"top")[0]??null:null),h=G(n?x(n,"bottom")[0]??null:null),y=G(n?x(n,"left")[0]??null:null),C=G(n?x(n,"right")[0]??null:null),H=G(n?x(n,"insideH")[0]??null:null),S=G(n?x(n,"insideV")[0]??null:null);return{tableLayout:f,borderCollapse:u,borderSpacingPx:s,borderCss:d??C??h??y??"1px solid #222",insideHCss:H,insideVCss:S}}function Le(e,t){let n=x(e,"tblPr")[0]??null,r=n?x(n,"tblW")[0]??null:null,o=(c(r,"w:type")??c(r,"type")??"").toLowerCase(),i=c(r,"w:w")??c(r,"w"),l=i?Number.parseFloat(i):Number.NaN;if(o==="dxa"&&Number.isFinite(l)&&l>0)return`width:${ct(l).toFixed(2)}px`;if(o==="pct"&&Number.isFinite(l)&&l>0)return`width:${(l/50).toFixed(2)}%`;let a=t.reduce((s,u)=>s+u,0);return a>0?`width:${a.toFixed(2)}px;max-width:100%`:"width:100%"}function He(e,t,n,r){let o=x(e,"tcPr")[0]??null,i=o?x(o,"tcW")[0]??null:null,l=(c(i,"w:type")??c(i,"type")??"").toLowerCase(),a=c(i,"w:w")??c(i,"w"),s=a?Number.parseFloat(a):Number.NaN;if(l==="dxa"&&Number.isFinite(s)&&s>0)return`width:${ct(s).toFixed(2)}px`;if(l==="pct"&&Number.isFinite(s)&&s>0)return`width:${(s/50).toFixed(2)}%`;let u=r.slice(t,t+n).reduce((f,d)=>f+d,0);return u>0?`width:${u.toFixed(2)}px`:""}function Te(e,t){let n=x(e,"tcPr")[0]??null,r=n?x(n,"tcBorders")[0]??null:null;if(!r)return`border:${t.insideHCss??t.insideVCss??t.borderCss}`;let o=G(x(r,"top")[0]??null)??t.insideHCss??t.borderCss,i=G(x(r,"right")[0]??null)??t.insideVCss??t.borderCss,l=G(x(r,"bottom")[0]??null)??t.insideHCss??t.borderCss,a=G(x(r,"left")[0]??null)??t.insideVCss??t.borderCss;return`border-top:${o};border-right:${i};border-bottom:${l};border-left:${a}`}function Ae(e,t,n){let r=[];for(let i of Array.from(e.children))if(i.localName!=="tcPr"){if(i.localName==="p"){let l=t.get(i)??null;r.push(`<p${Ht(l)}>${Et(i)}</p>`);continue}if(i.localName==="tbl"){r.push(Dt(i,t,n));continue}}if(r.length>0)return r.join("");let o=O(e,"t").map(i=>i.textContent??"").join("").trim();return W(o)||"<br/>"}function Dt(e,t,n){n.features.tableCount+=1;let r=x(e,"tr"),o=Fe(e),i=Ne(e),l=new Map,a=[],s=1,f=r.map((y,C)=>{let H=x(y,"tc"),S=new Set,P=[],$=0;for(let F of H){let N=ve(F),E=Se(F);if(E==="continue"){let v=Array.from(new Set(l.values())).filter(D=>!S.has(D)).sort((D,I)=>D.startCol-I.startCol),A=v.find(D=>D.startCol>=$)??v[0]??null;A&&(A.rowSpan+=1,S.add(A),$=A.startCol+A.colSpan);continue}for(;l.has($);)$+=1;let R=Ae(F,t,n),m=[],T=He(F,$,N,o),w=Te(F,i);if(E==="restart"){let v={id:`m${s}`,startCol:$,colSpan:N,rowSpan:1,startedRow:C};s+=1,a.push(v);for(let A=0;A<N;A+=1)l.set($+A,v);m.push(`data-word-merge-id="${v.id}"`)}N>1&&m.push(`colspan="${N}"`),P.push(`<td${m.length>0?` ${m.join(" ")}`:""} style="${w};vertical-align:top;${T}">${R}</td>`),$+=N}for(let F of Array.from(new Set(l.values())))if(F.startedRow<C&&!S.has(F))for(let N=0;N<F.colSpan;N+=1)l.delete(F.startCol+N);return`<tr>${P.join("")}</tr>`}).join("");for(let y of a){let C=`data-word-merge-id="${y.id}"`,H=y.rowSpan>1?`rowspan="${y.rowSpan}"`:"";f=f.replace(C,H).replace(/\s{2,}/g," ")}let d=Le(e,o),h=i.borderSpacingPx>0?`border-spacing:${i.borderSpacingPx.toFixed(2)}px;`:"";return`<table style="border-collapse:${i.borderCollapse};${h}table-layout:${i.tableLayout};${d};border:${i.borderCss};">${f}</table>`}async function pt(e){let t=Date.now(),n={features:Yt()},r=e.arrayBuffer,o=r?await r.call(e):await new Response(e).arrayBuffer(),i=await Zt.loadAsync(o),l=await i.file("word/document.xml")?.async("string");if(!l)throw new Error("DOCX missing document.xml");let a=await i.file("word/_rels/document.xml.rels")?.async("string"),s=await i.file("word/footnotes.xml")?.async("string"),u=await i.file("word/endnotes.xml")?.async("string"),f=await i.file("word/comments.xml")?.async("string"),d=ie(a??null),h=fe(s??null),y=be(u??null),C=he(f??null),H=[],S=[],P=[],$=lt(l),F=L($,"body");if(!F)throw new Error("DOCX missing body");let N=new Map;O($,"p").forEach((R,m)=>{N.set(R,m)});let E=[];for(let R of Array.from(F.children))if(R.localName!=="sectPr"){if(R.localName==="p"){let m=N.get(R)??null;E.push(await Pe(i,d,n,R,m,h,H,y,S,C,P));continue}if(R.localName==="tbl"){E.push(Dt(R,N,n));continue}}return E.push(xe(H,h)),E.push(we(S,y)),E.push(ye(P,C)),{htmlSnapshot:nt(E.join(`
2
+ `)),report:{elapsedMs:Date.now()-t,features:n.features}}}async function Re(e){return(await pt(e)).htmlSnapshot}function Ee(e){return e.replaceAll("&","&amp;").replaceAll('"',"&quot;")}async function Mt(e){let t=await new Response(e).arrayBuffer(),n=new Uint8Array(t),r="";for(let l of n)r+=String.fromCharCode(l);let o=btoa(r);return`data:${e.type||"application/octet-stream"};base64,${o}`}function De(e){let t=e.trim().toLowerCase();return t.startsWith("file:")||t.startsWith("blob:")||t.startsWith("cid:")||t.startsWith("mhtml:")||t.startsWith("ms-appx:")||t.startsWith("ms-appdata:")}async function kt(e,t){if(!e.trim()||t.length===0)return e;let r=new DOMParser().parseFromString(e,"text/html"),o=Array.from(r.querySelectorAll("img")),i=await Promise.all(t.map(a=>Mt(a))),l=0;for(let a of o){let s=a.getAttribute("src")??"";De(s)&&l<i.length&&(a.setAttribute("src",i[l]),l+=1)}return r.body.innerHTML}async function It(e){return e.length===0?"":(await Promise.all(e.map(n=>Mt(n)))).map(n=>`<p><img src="${Ee(n)}" alt="clipboard-image" /></p>`).join(`
3
+ `)}async function Bt(e){let t=e.getData("text/html")||"",n=e.getData("text/plain")||"",r=Array.from(e.items).filter(l=>l.kind==="file"&&l.type.startsWith("image/")).map(l=>l.getAsFile()).filter(l=>l!==null),o=await kt(t,r);return{html:o.trim()?o:await It(r),text:n,imageFiles:r}}async function Wt(e){let t="",n="",r=[];for(let l of e){l.types.includes("text/html")&&!t&&(t=await(await l.getType("text/html")).text()),l.types.includes("text/plain")&&!n&&(n=await(await l.getType("text/plain")).text());for(let a of l.types){if(!a.startsWith("image/"))continue;let s=await l.getType(a),u=`clipboard-${Date.now()}-${r.length}.${a.split("/")[1]??"bin"}`;r.push(new File([s],u,{type:a}))}}let o=await kt(t,r);return{html:o.trim()?o:await It(r),text:n,imageFiles:r}}function Me(e){let t=new Map;for(let n of e.split(";")){let[r,...o]=n.split(":"),i=r?.trim().toLowerCase(),l=o.join(":").trim();!i||!l||t.set(i,l)}return t}function ke(e){return Array.from(e.entries()).map(([t,n])=>`${t}: ${n}`).join("; ")}function Ie(e){let t=[["mso-ansi-font-size","font-size"],["mso-bidi-font-size","font-size"],["mso-hansi-font-size","font-size"],["mso-margin-top-alt","margin-top"],["mso-margin-bottom-alt","margin-bottom"],["mso-margin-left-alt","margin-left"],["mso-margin-right-alt","margin-right"],["mso-line-height-alt","line-height"]];for(let[r,o]of t){let i=e.get(r);i&&(e.has(o)||e.set(o,i))}let n=e.get("mso-foreground");n&&!e.has("color")&&e.set("color",n),e.get("mso-table-lspace")&&!e.has("margin-left")&&e.set("margin-left","0"),e.get("mso-table-rspace")&&!e.has("margin-right")&&e.set("margin-right","0")}function Be(e,t){let n=(e.getAttribute("class")??"").toLowerCase(),r=t.get("mso-list")??"";if(!(n.includes("msolist")||r.length>0))return;t.has("text-indent")||t.set("text-indent","0");let i=t.get("margin-left");i&&!t.has("padding-left")&&t.set("padding-left",i)}function We(e,t){let n=e.tagName.toLowerCase();n==="table"&&(t.has("border-collapse")||t.set("border-collapse","collapse"),t.has("border-spacing")||t.set("border-spacing","0")),(n==="td"||n==="th")&&!t.has("vertical-align")&&t.set("vertical-align","top"),n==="p"&&!t.has("min-height")&&t.set("min-height","1em")}function Ve(e){let t=Array.from(e.querySelectorAll("p"));for(let n of t){let r=(n.textContent??"").replace(/\u00a0/g," ").trim();!(n.querySelector("img,table,svg,canvas,br")!==null)&&r.length===0&&(n.innerHTML="<br/>")}}function ze(e,t){let n=e.body;if(n&&(t?.forceBodyFontFamily&&(n.style.fontFamily=t.forceBodyFontFamily),t?.forceHeadingFontFamily)){let r=Array.from(e.querySelectorAll("h1,h2,h3,h4,h5,h6"));for(let o of r)o.style.fontFamily=t.forceHeadingFontFamily}}function Vt(e,t){let n=Array.from(e.querySelectorAll("[style], p, table, td, th, li, div, span"));for(let r of n){let o=r,i=o.getAttribute("style")??"",l=Me(i);Ie(l),Be(o,l),We(o,l),l.size>0&&o.setAttribute("style",ke(l))}Ve(e),ze(e,t)}import je from"jszip";var M={bodyFontPx:14.6667,bodyLineHeightRatio:1.158333,bodyLineHeightPx:null,bodyLineHeightRule:"auto",paragraphAfterPx:10.67,contentWidthPx:553.73,pageHeightPx:1122.53,pageMarginTopPx:96,pageMarginBottomPx:96,titleFontPx:32,titleColor:"#0F4761",titleAlign:"center",bodyFontFamily:'"Times New Roman", "Noto Serif SC", serif',titleFontFamily:'DengXian, "Noto Sans SC", "Microsoft YaHei", sans-serif',discoveredFonts:[],tableCellPaddingTopPx:0,tableCellPaddingLeftPx:7.2,tableCellPaddingBottomPx:0,tableCellPaddingRightPx:7.2,paragraphProfiles:[],trailingDateText:null,trailingDateAlignedRight:!1,trailingDateParagraphIndex:null,trailingEmptyParagraphCountBeforeDate:0};function zt(e="snapshot"){return{sourceFileName:e,...M,paragraphProfiles:[]}}function k(e){return e/15}function p(e,t){return e?e.getAttribute(t):null}function b(e,t){let n=p(e,t);if(!n)return null;let r=Number.parseFloat(n);return Number.isFinite(r)?r:null}function K(e,t){return Array.from(e.querySelectorAll("*")).find(r=>r.localName===t)??null}function g(e,t){return Array.from(e.querySelectorAll("*")).filter(r=>r.localName===t)}function mt(e){return new DOMParser().parseFromString(e,"application/xml")}function qe(e){let t=K(e,"sectPr");if(!t)return{contentWidthPx:null,pageHeightPx:null,marginTopPx:null,marginBottomPx:null};let n=g(t,"pgSz")[0]??null,r=g(t,"pgMar")[0]??null,o=b(n,"w:w")??b(n,"w")??null,i=b(n,"w:h")??b(n,"h")??null,l=b(r,"w:left")??b(r,"left")??0,a=b(r,"w:right")??b(r,"right")??0,s=b(r,"w:top")??b(r,"top")??null,u=b(r,"w:bottom")??b(r,"bottom")??null;return{contentWidthPx:o===null?null:k(o-l-a),pageHeightPx:i===null?null:k(i),marginTopPx:s===null?null:k(s),marginBottomPx:u===null?null:k(u)}}function Oe(e){let t=g(e,"p");for(let n of t){let r=g(n,"pPr")[0]??null;if(!r)continue;let o=g(r,"pStyle")[0]??null,i=p(o,"w:val")??p(o,"val")??"";if(!(i==="1"||i.toLowerCase().includes("heading")))continue;let a=g(r,"jc")[0]??null,s=(p(a,"w:val")??p(a,"val")??"").toLowerCase();return s==="center"?"center":s==="right"?"right":"left"}return null}function dt(e){return g(e,"t").map(n=>n.textContent??"").join("").trim()}function jt(e){let t=g(e,"pPr")[0]??null,n=t?g(t,"jc")[0]??null:null,r=(p(n,"w:val")??p(n,"val")??"").toLowerCase();return r==="center"?"center":r==="right"?"right":"left"}function _e(e){let t=g(e,"p");if(t.length===0)return{trailingDateText:null,trailingDateAlignedRight:!1,trailingDateParagraphIndex:null,trailingEmptyParagraphCountBeforeDate:0};let n=-1;for(let s=t.length-1;s>=0;s-=1)if(dt(t[s]).length>0){n=s;break}if(n<0)return{trailingDateText:null,trailingDateAlignedRight:!1,trailingDateParagraphIndex:null,trailingEmptyParagraphCountBeforeDate:0};let r=t[n],o=dt(r),i=/\d{4}\s*年\s*\d+\s*月\s*\d+\s*日/.test(o),l=jt(r),a=0;for(let s=n-1;s>=0;s-=1){if(dt(t[s]).length===0){a+=1;continue}break}return{trailingDateText:i?o:null,trailingDateAlignedRight:i&&l==="right",trailingDateParagraphIndex:i?n:null,trailingEmptyParagraphCountBeforeDate:i?a:0}}function J(e){if(!e)return null;let t=Number.parseInt(e,10);return Number.isFinite(t)?t:null}function Xe(e){let t=new Map;if(!e)return t;let n=new Map,r=g(e,"abstractNum");for(let i of r){let l=J(p(i,"w:abstractNumId")??p(i,"abstractNumId"));if(l===null)continue;let a=g(i,"lvl"),s=new Map;for(let u of a){let f=J(p(u,"w:ilvl")??p(u,"ilvl"));if(f===null)continue;let d=g(u,"numFmt")[0]??null,h=g(u,"lvlText")[0]??null;s.set(f,{numFmt:p(d,"w:val")??p(d,"val")??null,lvlText:p(h,"w:val")??p(h,"val")??null,startAt:J(p(g(u,"start")[0]??null,"w:val")??p(g(u,"start")[0]??null,"val"))??1})}n.set(l,s)}let o=g(e,"num");for(let i of o){let l=J(p(i,"w:numId")??p(i,"numId"));if(l===null)continue;let a=g(i,"abstractNumId")[0]??null,s=J(p(a,"w:val")??p(a,"val"));if(s===null)continue;let u=n.get(s);if(!u)continue;for(let[d,h]of u.entries())t.set(`${l}:${d}`,{...h});let f=g(i,"lvlOverride");for(let d of f){let h=J(p(d,"w:ilvl")??p(d,"ilvl"));if(h===null)continue;let y=`${l}:${h}`,C=t.get(y)??{numFmt:null,lvlText:null,startAt:1},H=J(p(g(d,"startOverride")[0]??null,"w:val")??p(g(d,"startOverride")[0]??null,"val")),S=g(d,"lvl")[0]??null,P=S?g(S,"numFmt")[0]??null:null,$=S?g(S,"lvlText")[0]??null:null,F=J(p(g(S??d,"start")[0]??null,"w:val")??p(g(S??d,"start")[0]??null,"val"));t.set(y,{numFmt:p(P,"w:val")??p(P,"val")??C.numFmt,lvlText:p($,"w:val")??p($,"val")??C.lvlText,startAt:H??F??C.startAt})}}return t}function Ue(e,t){return g(e,"p").map((r,o)=>{let i=dt(r),l=g(r,"pPr")[0]??null,a=l?g(l,"spacing")[0]??null:null,s=l?g(l,"ind")[0]??null:null,u=l?g(l,"numPr")[0]??null:null,f=u?g(u,"ilvl")[0]??null:null,d=u?g(u,"numId")[0]??null:null,h=J(p(f,"w:val")??p(f,"val")),y=J(p(d,"w:val")??p(d,"val")),C=y!==null&&h!==null?t.get(`${y}:${h}`):void 0,H=l?g(l,"keepNext")[0]??null:null,S=l?g(l,"keepLines")[0]??null:null,P=l?g(l,"pageBreakBefore")[0]??null:null,$=g(r,"lastRenderedPageBreak")[0]??null,F=l?g(l,"sectPr")[0]??null:null,N=b(a,"w:before")??b(a,"before")??null,E=b(a,"w:after")??b(a,"after")??null,R=b(a,"w:line")??b(a,"line")??null,m=(p(a,"w:lineRule")??p(a,"lineRule")??"auto").toLowerCase(),T=R===null?null:m==="exact"?"exact":m==="atleast"?"atLeast":"auto",w=b(s,"w:left")??b(s,"left")??null,v=b(s,"w:right")??b(s,"right")??null,A=b(s,"w:firstLine")??b(s,"firstLine")??null,D=b(s,"w:hanging")??b(s,"hanging")??null,I=Je(r);return{index:o,text:i,isEmpty:i.length===0,align:jt(r),beforePx:N===null?null:k(N),afterPx:E===null?null:k(E),lineHeightRatio:R===null||T!=="auto"?null:R/240,lineHeightPx:R===null||T==="auto"?null:k(R),lineHeightRule:T,indentLeftPx:w===null?null:k(w),indentRightPx:v===null?null:k(v),firstLinePx:A===null?null:k(A),hangingPx:D===null?null:k(D),listNumId:y,listLevel:h,listFormat:C?.numFmt??null,listTextPattern:C?.lvlText??null,listStartAt:C?.startAt??1,keepNext:H!==null&&(p(H,"w:val")??p(H,"val")??"1")!=="0",keepLines:S!==null&&(p(S,"w:val")??p(S,"val")??"1")!=="0",pageBreakBefore:$!==null||P!==null&&(p(P,"w:val")??p(P,"val")??"1")!=="0",sectionBreakBefore:F!==null,runs:I}})}function Ge(e){let t=g(e,"style").filter(u=>(p(u,"w:type")??p(u,"type")??"").toLowerCase()==="table"),n=t.find(u=>(p(u,"w:styleId")??p(u,"styleId")??"").toLowerCase()==="a1")??t[0]??null;if(!n)return{topPx:null,leftPx:null,bottomPx:null,rightPx:null};let r=g(n,"tblPr")[0]??null,o=r?g(r,"tblCellMar")[0]??null:null,i=o?g(o,"top")[0]??null:null,l=o?g(o,"left")[0]??null:null,a=o?g(o,"bottom")[0]??null:null,s=o?g(o,"right")[0]??null:null;return{topPx:(()=>{let u=b(i,"w:w")??b(i,"w")??null;return u===null?null:k(u)})(),leftPx:(()=>{let u=b(l,"w:w")??b(l,"w")??null;return u===null?null:k(u)})(),bottomPx:(()=>{let u=b(a,"w:w")??b(a,"w")??null;return u===null?null:k(u)})(),rightPx:(()=>{let u=b(s,"w:w")??b(s,"w")??null;return u===null?null:k(u)})()}}function Je(e){return g(e,"r").map(n=>{let r=g(n,"rPr")[0]??null,o=g(n,"t"),i=g(n,"br"),l=o.map(ut=>ut.textContent??"").join("");if(i.length>0&&(l+=`
4
+ `.repeat(i.length)),!l)return null;let a=r?g(r,"sz")[0]??null:null,s=b(a,"w:val")??b(a,"val")??null,u=s===null?null:s/2*(96/72),f=r?g(r,"color")[0]??null:null,d=p(f,"w:val")??p(f,"val")??null,h=d&&d.toLowerCase()!=="auto"?`#${d}`:null,y=r?g(r,"highlight")[0]??null:null,C=(p(y,"w:val")??p(y,"val")??"").toLowerCase(),S=C&&C!=="none"?{yellow:"#fff59d",green:"#b9f6ca",cyan:"#b2ebf2",magenta:"#f8bbd0",blue:"#bbdefb",red:"#ffcdd2",darkyellow:"#fbc02d",darkgreen:"#66bb6a",darkblue:"#64b5f6",darkred:"#e57373",darkcyan:"#4dd0e1",darkmagenta:"#ba68c8",gray:"#e0e0e0",lightgray:"#f5f5f5"}[C]??null:null,P=r?g(r,"shd")[0]??null:null,$=(p(P,"w:fill")??p(P,"fill")??"").toLowerCase(),F=$&&$!=="auto"?`#${$}`:null,N=r?g(r,"spacing")[0]??null:null,E=b(N,"w:val")??b(N,"val")??null,R=E===null?null:E/20*(96/72),m=r?g(r,"b")[0]??null:null,T=r?g(r,"i")[0]??null:null,w=r?g(r,"u")[0]??null:null,v=r?g(r,"strike")[0]??null:null,A=r?g(r,"shadow")[0]??null:null,D=r?g(r,"vertAlign")[0]??null:null,I=m!==null&&(p(m,"w:val")??p(m,"val")??"1")!=="0",Y=T!==null&&(p(T,"w:val")??p(T,"val")??"1")!=="0",U=(p(w,"w:val")??p(w,"val")??"").toLowerCase(),st=w!==null&&U!=="none",Q=v!==null&&(p(v,"w:val")??p(v,"val")??"1")!=="0",tt=A!==null&&(p(A,"w:val")??p(A,"val")??"1")!=="0",rt=(p(D,"w:val")??p(D,"val")??"").toLowerCase(),it=rt==="superscript",z=rt==="subscript",B=r?g(r,"rFonts")[0]??null:null,ot=p(B,"w:eastAsia")??p(B,"eastAsia")??p(B,"w:ascii")??p(B,"ascii")??p(B,"w:hAnsi")??p(B,"hAnsi")??null;return{text:l,fontSizePx:u,color:h,highlightColor:S,shadingColor:F,charSpacingPx:R,shadow:tt,bold:I,italic:Y,underline:st,strike:Q,superscript:it,subscript:z,fontFamily:ot}}).filter(n=>n!==null)}function Ke(e){let t=K(e,"docDefaults");if(!t)return{bodyFontPx:null,bodyLineHeightRatio:null,bodyLineHeightPx:null,bodyLineHeightRule:"auto",paragraphAfterPx:null};let n=K(t,"rPrDefault"),r=n?K(n,"sz"):null,o=b(r,"w:val")??b(r,"val")??null,i=o===null?null:o/2*(96/72),l=K(t,"pPrDefault"),a=l?K(l,"spacing"):null,s=b(a,"w:line")??b(a,"line")??null,u=(p(a,"w:lineRule")??p(a,"lineRule")??"auto").toLowerCase(),f=u==="exact"?"exact":u==="atleast"?"atLeast":"auto",d=s===null||f!=="auto"?null:s/240,h=s===null||f==="auto"?null:k(s),y=b(a,"w:after")??b(a,"after")??null,C=y===null?null:k(y);return{bodyFontPx:i,bodyLineHeightRatio:d,bodyLineHeightPx:h,bodyLineHeightRule:f,paragraphAfterPx:C}}function Ze(e){let n=g(e,"style").find(f=>{let d=(p(f,"w:styleId")??p(f,"styleId")??"").toLowerCase(),h=K(f,"name"),y=(p(h,"w:val")??p(h,"val")??"").toLowerCase();return d==="1"||y==="heading 1"||y==="\u6807\u9898 1"});if(!n)return{titleFontPx:null,titleColor:null};let r=K(n,"rPr"),o=r?K(r,"sz"):null,i=b(o,"w:val")??b(o,"val")??null,l=i===null?null:i/2*(96/72),a=r?K(r,"color"):null,s=p(a,"w:val")??p(a,"val")??null,u=s?`#${s}`:null;return{titleFontPx:l,titleColor:u}}function Ye(e){if(!e)return[];let n=g(e,"font").map(r=>p(r,"w:name")??p(r,"name")??"").map(r=>r.trim()).filter(r=>r.length>0);return[...new Set(n)]}function gt(e,t){return e.some(n=>t.some(r=>n.toLowerCase().includes(r.toLowerCase())))}function Qe(e){return gt(e,["times new roman"])?'"Times New Roman", "Noto Serif SC", serif':gt(e,["dengxian","\u7B49\u7EBF","yahei","hei","song"])?'DengXian, "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif':M.bodyFontFamily}function tn(e){return gt(e,["dengxian","\u7B49\u7EBF"])?'DengXian, "Noto Sans SC", "Microsoft YaHei", sans-serif':gt(e,["times new roman"])?'"Times New Roman", "Noto Serif SC", serif':M.titleFontFamily}async function qt(e){let t=e.arrayBuffer,n=t?await t.call(e):await new Response(e).arrayBuffer(),r=await je.loadAsync(n),o=await r.file("word/document.xml")?.async("string"),i=await r.file("word/styles.xml")?.async("string"),l=await r.file("word/fontTable.xml")?.async("string"),a=await r.file("word/numbering.xml")?.async("string");if(!o||!i)throw new Error("DOCX missing document.xml or styles.xml");let s=mt(o),u=mt(i),f=l?mt(l):null,d=a?mt(a):null,h=Xe(d),y=Ke(u),C=Ze(u),H=Ge(u),S=qe(s),P=Oe(s),$=_e(s),F=Ye(f),N=Qe(F),E=tn(F),R=Ue(s,h);return{sourceFileName:e.name,bodyFontPx:y.bodyFontPx??M.bodyFontPx,bodyLineHeightRatio:y.bodyLineHeightRatio??M.bodyLineHeightRatio,bodyLineHeightPx:y.bodyLineHeightPx??M.bodyLineHeightPx,bodyLineHeightRule:y.bodyLineHeightRule??M.bodyLineHeightRule,paragraphAfterPx:y.paragraphAfterPx??M.paragraphAfterPx,contentWidthPx:S.contentWidthPx??M.contentWidthPx,pageHeightPx:S.pageHeightPx??M.pageHeightPx,pageMarginTopPx:S.marginTopPx??M.pageMarginTopPx,pageMarginBottomPx:S.marginBottomPx??M.pageMarginBottomPx,titleFontPx:C.titleFontPx??M.titleFontPx,titleColor:C.titleColor??M.titleColor,titleAlign:P??M.titleAlign,bodyFontFamily:N,titleFontFamily:E,discoveredFonts:F,tableCellPaddingTopPx:H.topPx??M.tableCellPaddingTopPx,tableCellPaddingLeftPx:H.leftPx??M.tableCellPaddingLeftPx,tableCellPaddingBottomPx:H.bottomPx??M.tableCellPaddingBottomPx,tableCellPaddingRightPx:H.rightPx??M.tableCellPaddingRightPx,paragraphProfiles:R,trailingDateText:$.trailingDateText,trailingDateAlignedRight:$.trailingDateAlignedRight,trailingDateParagraphIndex:$.trailingDateParagraphIndex,trailingEmptyParagraphCountBeforeDate:$.trailingEmptyParagraphCountBeforeDate}}function V(e,t,n){e.style.setProperty(t,n,"important")}function en(e){return e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;")}function nn(e){let t=[];e.fontSizePx!==null&&t.push(`font-size:${e.fontSizePx.toFixed(2)}px`),e.color&&t.push(`color:${e.color}`),e.highlightColor&&t.push(`background-color:${e.highlightColor}`),e.shadingColor&&t.push(`background-color:${e.shadingColor}`),e.charSpacingPx!==null&&t.push(`letter-spacing:${e.charSpacingPx.toFixed(2)}px`),e.shadow&&t.push("text-shadow:0.5px 0.5px 0 rgba(0,0,0,0.28)"),e.bold&&t.push("font-weight:700"),e.italic&&t.push("font-style:italic");let n=[];return e.underline&&n.push("underline"),e.strike&&n.push("line-through"),n.length>0&&t.push(`text-decoration:${n.join(" ")}`),e.superscript&&t.push("vertical-align:super"),e.subscript&&t.push("vertical-align:sub"),(e.superscript||e.subscript)&&t.push("font-size:0.83em"),e.fontFamily&&t.push(`font-family:${e.fontFamily}`),t.join(";")}function rn(e){return e.map(t=>{let n=nn(t),o=t.text.split(`
5
+ `).map(i=>en(i)).join("<br/>");return n?`<span style="${n}">${o}</span>`:o}).join("")}function Ot(e){let t="abcdefghijklmnopqrstuvwxyz";if(e<=0)return"a";let n=e,r="";for(;n>0;)n-=1,r=t[n%26]+r,n=Math.floor(n/26);return r}function _t(e){if(e<=0)return"I";let t=[[1e3,"M"],[900,"CM"],[500,"D"],[400,"CD"],[100,"C"],[90,"XC"],[50,"L"],[40,"XL"],[10,"X"],[9,"IX"],[5,"V"],[4,"IV"],[1,"I"]],n=e,r="";for(let[o,i]of t)for(;n>=o;)r+=i,n-=o;return r}function xt(e,t){switch((e??"").toLowerCase()){case"decimal":return`${t}.`;case"lowerletter":return`${Ot(t)}.`;case"upperletter":return`${Ot(t).toUpperCase()}.`;case"lowerroman":return`${_t(t).toLowerCase()}.`;case"upperroman":return`${_t(t)}.`;default:return"\u2022"}}function on(e,t,n,r){if(!e||e.trim().length===0)return xt(r,n[t]??1);let i=e.replace(/%(\d+)/g,(l,a)=>{let s=Number.parseInt(a,10);if(!Number.isFinite(s)||s<=0)return"";let u=s-1,f=n[u]??0;return f<=0?"":u===t?xt(r,f).replace(/\.$/,""):String(f)}).trim();return i||xt(r,n[t]??1)}function Xt(e,t){let n=e.getElementById(t);return n||(n=e.createElement("style"),n.id=t,e.head.appendChild(n)),n}function ln(e,t){let n=Xt(e,"__word_style_profile__"),r=t.contentWidthPx.toFixed(2),o=t.pageMarginTopPx.toFixed(2),i=t.pageMarginBottomPx.toFixed(2),l=t.pageHeightPx.toFixed(2),a=t.bodyLineHeightRule==="auto"||t.bodyLineHeightPx===null?t.bodyLineHeightRatio.toFixed(6):`${t.bodyLineHeightPx.toFixed(2)}px`;n.textContent=`
6
+ @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;700&family=Noto+Serif+SC:wght@400;700&display=swap');
7
+ html, body { box-sizing: border-box; }
8
+ body {
9
+ min-height: ${l}px !important;
10
+ width: ${r}px !important;
11
+ max-width: calc(100% - 24px) !important;
12
+ margin-left: auto !important;
13
+ margin-right: auto !important;
14
+ padding-top: ${o}px !important;
15
+ padding-bottom: ${i}px !important;
16
+ padding-left: 0 !important;
17
+ padding-right: 0 !important;
18
+ font-family: ${t.bodyFontFamily} !important;
19
+ }
20
+ p {
21
+ font-size: ${t.bodyFontPx.toFixed(4)}px !important;
22
+ line-height: ${a} !important;
23
+ margin-bottom: ${t.paragraphAfterPx.toFixed(2)}px !important;
24
+ }
25
+ table { border-collapse: collapse !important; border-spacing: 0 !important; }
26
+ td, th {
27
+ padding-top: ${t.tableCellPaddingTopPx.toFixed(2)}px !important;
28
+ padding-left: ${t.tableCellPaddingLeftPx.toFixed(2)}px !important;
29
+ padding-bottom: ${t.tableCellPaddingBottomPx.toFixed(2)}px !important;
30
+ padding-right: ${t.tableCellPaddingRightPx.toFixed(2)}px !important;
31
+ vertical-align: top !important;
32
+ }
33
+ h1 {
34
+ font-size: ${t.titleFontPx.toFixed(2)}px !important;
35
+ color: ${t.titleColor} !important;
36
+ text-align: ${t.titleAlign} !important;
37
+ font-family: ${t.titleFontFamily} !important;
38
+ }
39
+ `}function an(e,t){let n=e.body,r=t.contentWidthPx.toFixed(2),o=t.pageMarginTopPx.toFixed(2),i=t.pageMarginBottomPx.toFixed(2),l=t.pageHeightPx.toFixed(2);V(n,"box-sizing","border-box"),V(n,"min-height",`${l}px`),V(n,"width",`${r}px`),V(n,"max-width",`${r}px`),V(n,"margin-left","auto"),V(n,"margin-right","auto"),V(n,"padding-top",`${o}px`),V(n,"padding-bottom",`${i}px`),V(n,"padding-left","0"),V(n,"padding-right","0"),V(n,"font-family",t.bodyFontFamily);for(let a of Array.from(n.children)){if(!(a instanceof HTMLElement))continue;let s=a.tagName.toLowerCase();s==="script"||s==="style"||(V(a,"box-sizing","border-box"),V(a,"max-width","100%"))}for(let a of Array.from(e.body.querySelectorAll("img")))a instanceof HTMLElement&&(V(a,"max-width","100%"),V(a,"height","auto"))}function Ut(e){for(let t of e)(t.textContent??"").trim().length>0||t.querySelector("img,table,svg,canvas")!==null?t.removeAttribute("data-word-empty"):(t.setAttribute("data-word-empty","1"),t.innerHTML.trim().length===0&&(t.innerHTML="<br/>"))}function sn(e,t){for(let n=t+1;n<e.length;n+=1){let r=e[n],o=(r.textContent??"").trim().length>0,i=r.querySelector("img,table,svg,canvas")!==null;if(o||i)return!0}return!1}function un(e,t){let n=Array.from(e.body.querySelectorAll("p"));n.forEach(a=>{a.classList.remove("__word-date-anchor"),a.querySelectorAll("span.__word-list-marker").forEach(s=>s.remove())});let r=t.paragraphProfiles.map((a,s)=>{let u=e.body.querySelector(`[data-word-p-index="${a.index}"]`)??null,f=n[s]??null;return{profile:a,node:u??f}});if(t.trailingDateAlignedRight&&t.trailingDateText){let a=null;t.trailingDateParagraphIndex!==null&&t.trailingDateParagraphIndex>=0?a=e.body.querySelector(`[data-word-p-index="${t.trailingDateParagraphIndex}"]`)??n[t.trailingDateParagraphIndex]??null:a=n.slice().reverse().find(f=>{let d=(f.textContent??"").replace(/\s+/g,""),h=t.trailingDateText?.replace(/\s+/g,"")??"";return h.length>0&&d.includes(h)})??null;let s=a?n.indexOf(a):-1,u=s>=0?sn(n,s):!1;if(a&&!u){let f=0,d=a.previousElementSibling;for(;d&&d.tagName.toLowerCase()==="p"&&(d.textContent??"").trim().length===0;)f+=1,d=d.previousElementSibling;let h=Math.max(0,t.trailingEmptyParagraphCountBeforeDate-f);for(let y=0;y<h;y+=1){let C=e.createElement("p");C.innerHTML="<br/>",a.parentElement?.insertBefore(C,a)}}}let o=Array.from(e.body.querySelectorAll("p")),i=new Map,l=[];for(let a of r){let s=a.node,u=a.profile;if(s){if(l.push(s),s.removeAttribute("data-word-list"),s.style.textAlign=u.align,u.beforePx!==null&&(s.style.marginTop=`${u.beforePx.toFixed(2)}px`),u.afterPx!==null&&(s.style.marginBottom=`${u.afterPx.toFixed(2)}px`),u.lineHeightRule==="auto"&&u.lineHeightRatio!==null?s.style.lineHeight=u.lineHeightRatio.toFixed(6):(u.lineHeightRule==="exact"||u.lineHeightRule==="atLeast")&&u.lineHeightPx!==null&&(s.style.lineHeight=`${u.lineHeightPx.toFixed(2)}px`),u.indentLeftPx!==null&&(s.style.marginLeft=`${u.indentLeftPx.toFixed(2)}px`),u.indentRightPx!==null&&(s.style.marginRight=`${u.indentRightPx.toFixed(2)}px`),u.firstLinePx!==null&&(s.style.textIndent=`${u.firstLinePx.toFixed(2)}px`),u.hangingPx!==null&&(s.style.textIndent=`${(-u.hangingPx).toFixed(2)}px`),u.runs.length>0&&s.querySelector("img,table,svg,canvas")===null){let f=(s.textContent??"").replace(/\s+/g,""),d=u.runs.map(h=>h.text).join("").replace(/\s+/g,"");d.length>0&&f===d&&(s.innerHTML=rn(u.runs))}if(u.listNumId!==null&&u.listLevel!==null){s.setAttribute("data-word-list","1"),u.sectionBreakBefore&&i.set(u.listNumId,[]);let f=Math.max(0,u.listLevel),d=i.get(u.listNumId)??[],y=(d[f]??u.listStartAt-1)+1;d[f]=y;for(let P=f+1;P<d.length;P+=1)d[P]=0;i.set(u.listNumId,d);let C=on(u.listTextPattern,f,d,u.listFormat);if(!(s.textContent??"").replace(/\s+/g," ").trim().startsWith(C)){let P=e.createElement("span");P.className="__word-list-marker",P.setAttribute("data-word-list-marker","1"),P.textContent=`${C} `,P.style.display="inline-block",P.style.minWidth="1.8em",P.style.marginLeft=f>0?`${f*1.2}em`:"0",P.style.color="inherit",P.style.fontWeight="inherit",s.prepend(P)}}}}return Ut(o),l}function wt(e){let t=e.getBoundingClientRect();if(t.height>0)return t.height;let n=Number.parseFloat(getComputedStyle(e).lineHeight||"0");return Number.isFinite(n)&&n>0?n:16}function yt(e,t,n){if(n<=.5)return;let r=e.createElement("div");r.dataset.wordPageSpacer="1",r.style.height=`${n.toFixed(2)}px`,r.style.width="100%",r.style.pointerEvents="none",r.style.userSelect="none",t.parentElement?.insertBefore(r,t)}function cn(e){e.querySelectorAll("[data-word-page-spacer='1']").forEach(t=>t.remove())}function pn(e,t,n,r){let o=wt(e[t]);if(!n.keepNext)return o;let i=e[t+1];if(!i)return o;let l=wt(i),a=o+l;return a>r?o:a}function mn(e,t,n){cn(e);let r=Math.max(120,t.pageHeightPx-t.pageMarginTopPx-t.pageMarginBottomPx),o=Math.min(t.paragraphProfiles.length,n.length),i=0;for(let l=0;l<o;l+=1){let a=n[l],s=t.paragraphProfiles[l],u=wt(a);s.pageBreakBefore&&i>0&&(yt(e,a,r-i),i=0);let d=pn(n,l,s,r);(s.keepLines||s.keepNext)&&i>0&&i+d>r&&(yt(e,a,r-i),i=0),i>0&&i+u>r&&(yt(e,a,r-i),i=0),i+=u,i>=r&&(i=i%r)}}function dn(e,t){let n=Xt(e,"__word_view_options__");n.textContent=`
40
+ p[data-word-empty="1"]::before { content: "\\00a0"; }
41
+ ${t?`
42
+ p::after {
43
+ content: "\u21B5";
44
+ color: #66aef9;
45
+ font-size: 0.85em;
46
+ margin-left: 3px;
47
+ }
48
+ br::after {
49
+ content: "\u21B5";
50
+ color: #66aef9;
51
+ }
52
+ `:""}
53
+ `}function Gt({doc:e,styleProfile:t,showFormattingMarks:n}){let r=t??zt("__default_a4__");Vt(e,{forceBodyFontFamily:r.bodyFontFamily,forceHeadingFontFamily:r.titleFontFamily});let o=Array.from(e.body.querySelectorAll("p"));Ut(o),ln(e,r),an(e,r),t&&(o=un(e,t),mn(e,t,o)),dn(e,n)}var gn="0.1.5",_={zh:{readClipboard:"\u4ECE\u7CFB\u7EDF\u526A\u8D34\u677F\u8BFB\u53D6",uploadWord:"\u4E0A\u4F20 Word",clear:"\u6E05\u7A7A",pastePlaceholder:"\u5728\u6B64\u5904\u7C98\u8D34 Word/WPS/Google Docs \u5185\u5BB9\uFF08Ctrl/Cmd+V\uFF09",waitImport:"\u7B49\u5F85\u5185\u5BB9\u5BFC\u5165",loadedHtml:"\u5DF2\u52A0\u8F7D HTML \u5FEB\u7167",cleared:"\u6587\u6863\u5DF2\u6E05\u7A7A",loadedWord:e=>`\u5DF2\u52A0\u8F7D Word \u6587\u4EF6: ${e}`,importedClipboard:"\u5DF2\u5BFC\u5165\u526A\u8D34\u677F\u5185\u5BB9",noContent:"\u672A\u68C0\u6D4B\u5230\u53EF\u5BFC\u5165\u5185\u5BB9",noClipboardRead:"\u5F53\u524D\u6D4F\u89C8\u5668\u4E0D\u652F\u6301 clipboard.read",parseFailed:"Word \u89E3\u6790\u5931\u8D25",clipboardReadFailed:"\u8BFB\u53D6\u526A\u8D34\u677F\u5931\u8D25",errorPrefix:"\u9519\u8BEF: "},en:{readClipboard:"Read clipboard",uploadWord:"Upload Word",clear:"Clear",pastePlaceholder:"Paste Word/WPS/Google Docs content here (Ctrl/Cmd+V)",waitImport:"Waiting for input",loadedHtml:"HTML snapshot loaded",cleared:"Document cleared",loadedWord:e=>`Word file loaded: ${e}`,importedClipboard:"Clipboard content imported",noContent:"No importable content detected",noClipboardRead:"navigator.clipboard.read is not supported in this browser",parseFailed:"Word parse failed",clipboardReadFailed:"Failed to read clipboard",errorPrefix:"Error: "}},fn=`
54
+ :host{display:block;border:1px solid #d8deea;border-radius:12px;background:#fff;overflow:hidden;font-family:ui-sans-serif,system-ui,-apple-system,Segoe UI,Roboto}
55
+ .toolbar{display:flex;gap:8px;flex-wrap:wrap;padding:10px;border-bottom:1px solid #e8edf6;background:#f8faff}
56
+ button{border:1px solid #c8d2eb;background:#fff;border-radius:9px;padding:6px 10px;cursor:pointer}
57
+ .paste{width:100%;min-height:40px;border:1px dashed #95acef;border-radius:10px;background:#edf3ff;padding:8px 10px;box-sizing:border-box;resize:vertical}
58
+ .hint{display:block;padding:0 10px 10px;color:#4b5c82;font-size:12px}
59
+ iframe{width:100%;min-height:760px;border:0}
60
+ `,ft=class extends HTMLElement{rootRef;toolbar;btnRead;btnUpload;btnClear;frame;pasteArea;fileInput;hint;htmlSnapshot;styleProfile=null;frameHeight=0;locale="zh";constructor(){super(),this.rootRef=this.attachShadow({mode:"open"}),this.locale=this.parseLocale(this.getAttribute("lang")),this.htmlSnapshot=nt("<p><br/></p>");let t=document.createElement("style");t.textContent=fn,this.toolbar=document.createElement("div"),this.toolbar.className="toolbar",this.btnRead=document.createElement("button"),this.btnRead.onclick=()=>{this.loadClipboard()},this.btnUpload=document.createElement("button"),this.btnUpload.onclick=()=>this.fileInput.click(),this.btnClear=document.createElement("button"),this.btnClear.onclick=()=>this.clear(),this.fileInput=document.createElement("input"),this.fileInput.type="file",this.fileInput.accept=".docx",this.fileInput.style.display="none",this.fileInput.onchange=()=>{this.onUpload()},this.toolbar.append(this.btnRead,this.btnUpload,this.btnClear,this.fileInput),this.pasteArea=document.createElement("textarea"),this.pasteArea.className="paste",this.pasteArea.placeholder="",this.pasteArea.onpaste=n=>{n.preventDefault(),this.applyFromClipboardData(n.clipboardData)},this.hint=document.createElement("span"),this.hint.className="hint",this.hint.textContent="",this.frame=document.createElement("iframe"),this.frame.sandbox.add("allow-same-origin","allow-scripts"),this.frame.onload=()=>this.onFrameLoad(),this.rootRef.append(t,this.toolbar,this.pasteArea,this.hint,this.frame),this.syncLocaleText(),this.syncToolbarVisibility()}static get observedAttributes(){return["lang","show-toolbar"]}attributeChangedCallback(t,n,r){if(t==="lang"){this.locale=this.parseLocale(r),this.syncLocaleText();return}t==="show-toolbar"&&this.syncToolbarVisibility()}connectedCallback(){this.renderSnapshot(),this.dispatchEvent(new CustomEvent("docsjs-ready",{detail:{version:gn}}))}setSnapshot(t){this.loadHtml(t)}loadHtml(t){this.styleProfile=null,this.htmlSnapshot=nt(t),this.renderSnapshot(),this.setHint(_[this.locale].loadedHtml),this.emitChange("api")}getSnapshot(){return this.htmlSnapshot}clear(){this.styleProfile=null,this.htmlSnapshot=nt("<p><br/></p>"),this.renderSnapshot(),this.setHint(_[this.locale].cleared),this.emitChange("clear")}async loadDocx(t){await this.applyDocx(t)}async onUpload(){let t=this.fileInput.files?.[0];t&&(await this.applyDocx(t),this.fileInput.value="")}async applyDocx(t){try{let[n,r]=await Promise.all([pt(t),qt(t)]);this.styleProfile=r,this.htmlSnapshot=n.htmlSnapshot,this.renderSnapshot(),this.setHint(_[this.locale].loadedWord(r.sourceFileName)),this.emitChange("upload",r.sourceFileName,n.report)}catch(n){this.emitError(n instanceof Error?n.message:_[this.locale].parseFailed)}}async loadClipboard(){if(!navigator.clipboard?.read){this.emitError(_[this.locale].noClipboardRead);return}try{let t=await navigator.clipboard.read(),n=await Wt(t);this.applyPayload(n.html,n.text)}catch(t){this.emitError(t instanceof Error?t.message:_[this.locale].clipboardReadFailed)}}async applyFromClipboardData(t){if(!t)return;let n=await Bt(t);this.applyPayload(n.html,n.text)}applyPayload(t,n){if(this.styleProfile=null,t.trim())this.htmlSnapshot=nt(t);else if(n.trim())this.htmlSnapshot=nt(`<p>${n.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;")}</p>`);else{this.setHint(_[this.locale].noContent);return}this.renderSnapshot(),this.setHint(_[this.locale].importedClipboard),this.emitChange("paste")}onFrameLoad(){let t=this.frame.contentDocument;t&&(Gt({doc:t,styleProfile:this.styleProfile,showFormattingMarks:!1}),this.syncHeight(),window.setTimeout(()=>this.syncHeight(),120))}syncHeight(){let t=this.frame.contentDocument;if(!t)return;let r=Math.max(760,t.body.scrollHeight,t.documentElement.scrollHeight)+24;Math.abs(r-this.frameHeight)<2||(this.frameHeight=r,this.frame.style.height=`${r}px`)}renderSnapshot(){this.frame.srcdoc=this.htmlSnapshot}emitChange(t,n,r){this.dispatchEvent(new CustomEvent("docsjs-change",{detail:{htmlSnapshot:this.htmlSnapshot,source:t,fileName:n,parseReport:r}}))}emitError(t){this.dispatchEvent(new CustomEvent("docsjs-error",{detail:{message:t}})),this.setHint(`${_[this.locale].errorPrefix}${t}`)}setHint(t){this.hint.textContent=t}parseLocale(t){return t?.toLowerCase()==="en"?"en":"zh"}syncToolbarVisibility(){let t=this.getAttribute("show-toolbar"),n=t===null||t===""||t==="1"||t.toLowerCase()==="true";this.toolbar.style.display=n?"flex":"none"}syncLocaleText(){let t=_[this.locale];this.btnRead.textContent=t.readClipboard,this.btnUpload.textContent=t.uploadWord,this.btnClear.textContent=t.clear,this.pasteArea.placeholder=t.pastePlaceholder,(!this.hint.textContent||this.hint.textContent===_.en.waitImport||this.hint.textContent===_.zh.waitImport)&&(this.hint.textContent=t.waitImport)}};function hn(){customElements.get("docs-word-editor")||customElements.define("docs-word-editor",ft)}function j(e,t){return e.querySelectorAll(t).length}function bn(e){return e.hasAttribute("data-word-list")||e.querySelector("span.__word-list-marker")?!0:(e.getAttribute("style")??"").toLowerCase().includes("mso-list")}function Jt(e){let t=Array.from(e.querySelectorAll("p")),n=t.filter(o=>bn(o)).length,r=(e.body.textContent??"").replace(/\s+/g,"").length;return{paragraphCount:t.length,headingCount:j(e,"h1,h2,h3,h4,h5,h6"),tableCount:j(e,"table"),tableCellCount:j(e,"td,th"),imageCount:j(e,"img"),anchorImageCount:j(e,'img[data-word-anchor="1"]'),wrappedImageCount:j(e,"img[data-word-wrap]"),ommlCount:j(e,"[data-word-omml]"),chartCount:j(e,"[data-word-chart]"),smartArtCount:j(e,"[data-word-smartart]"),listParagraphCount:n,commentRefCount:j(e,"[data-word-comment-ref]"),revisionInsCount:j(e,'[data-word-revision="ins"]'),revisionDelCount:j(e,'[data-word-revision="del"]'),pageBreakCount:j(e,"[data-word-page-break='1']"),pageSpacerCount:j(e,"[data-word-page-spacer='1']"),textCharCount:r}}function xn(e){let n=new DOMParser().parseFromString(e,"text/html");return Jt(n)}function X(e,t){if(t<=0&&e<=0)return 1;if(t<=0||e<0)return 0;let r=Math.abs(e-t)/t;return Math.max(0,1-r)}function ht(e){return e<0?0:e>1?1:e}function yn(e,t){let n=ht((X(t.paragraphCount,e.paragraphCount)+X(t.headingCount,e.headingCount)+X(t.tableCount,e.tableCount)+X(t.tableCellCount,e.tableCellCount)+X(t.imageCount,e.imageCount)+X(t.ommlCount,e.ommlCount)+X(t.chartCount,e.chartCount)+X(t.smartArtCount,e.smartArtCount)+X(t.listParagraphCount,e.listParagraphCount))/9),r=ht(X(t.textCharCount,e.textCharCount)),o=ht(X(t.pageSpacerCount,e.pageSpacerCount)),i=ht(n*.6+r*.25+o*.15);return{structure:n,styleProxy:r,pagination:o,overall:i}}export{ft as DocsWordElement,yn as calculateFidelityScore,Jt as collectSemanticStatsFromDocument,xn as collectSemanticStatsFromHtml,hn as defineDocsWordElement,Re as parseDocxToHtmlSnapshot,pt as parseDocxToHtmlSnapshotWithReport};