xh-htmlword 1.1.8 → 1.2.0
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/README.md +11 -2
- package/dist/xh.js +25 -21
- package/dist/xh.umd.cjs +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@ import handleExportWord from "xh-htmlword";
|
|
|
13
13
|
## 页面 dom 生成后调用
|
|
14
14
|
|
|
15
15
|
```js
|
|
16
|
+
//在需要分页的地方添加 <span><br clear="all" style="page-break-before: always" /> </span> 即可分页
|
|
17
|
+
|
|
16
18
|
// dom:需要渲染的html父盒子标签 , 类型:string 例如 id/class
|
|
17
19
|
// fileName:文件名称 类型:string
|
|
18
20
|
// timeOut:设置导出图片加载 超时时间 默认值 5000 (5s)
|
|
@@ -25,8 +27,8 @@ handleExportWord({
|
|
|
25
27
|
dom: ".export-box",
|
|
26
28
|
fileName: "cs",
|
|
27
29
|
timeOut: 3000,
|
|
28
|
-
callBack: () => {
|
|
29
|
-
console.log("导出成功");
|
|
30
|
+
callBack: (res) => {
|
|
31
|
+
console.log("导出成功"); //res 文档流
|
|
30
32
|
},
|
|
31
33
|
defultImg: "",
|
|
32
34
|
className: "export-box",
|
|
@@ -195,6 +197,13 @@ handleExportWord({
|
|
|
195
197
|
<el-step title="Step 3" />
|
|
196
198
|
</el-steps>
|
|
197
199
|
</div>
|
|
200
|
+
|
|
201
|
+
<span><br clear="all" style="page-break-before: always" /> </span>
|
|
202
|
+
分页
|
|
203
|
+
|
|
204
|
+
<span><br clear="all" style="page-break-before: always" /> </span>
|
|
205
|
+
分页
|
|
206
|
+
|
|
198
207
|
</div>
|
|
199
208
|
|
|
200
209
|
<button @click="handleExport">导出</button>
|
package/dist/xh.js
CHANGED
|
@@ -10257,28 +10257,32 @@ const $C = Array.isArray, AQ = (r, e, A) => new Promise((t, n) => {
|
|
|
10257
10257
|
}) => {
|
|
10258
10258
|
const s = document.querySelector(r), g = s.cloneNode(!0);
|
|
10259
10259
|
if (o && o.length > 0 && $C(o)) {
|
|
10260
|
-
const f =
|
|
10261
|
-
|
|
10262
|
-
|
|
10260
|
+
const f = [];
|
|
10261
|
+
o.map((u) => {
|
|
10262
|
+
const U = document.querySelectorAll(u);
|
|
10263
|
+
if (U.length == 0)
|
|
10263
10264
|
throw new Error(`dom不存在:“${u}” , 请检查传入的dom标签是否正确`);
|
|
10264
|
-
|
|
10265
|
-
|
|
10266
|
-
|
|
10267
|
-
|
|
10268
|
-
|
|
10269
|
-
|
|
10270
|
-
|
|
10271
|
-
|
|
10272
|
-
|
|
10273
|
-
|
|
10274
|
-
|
|
10275
|
-
|
|
10276
|
-
|
|
10277
|
-
|
|
10278
|
-
|
|
10265
|
+
U.forEach((p, v) => {
|
|
10266
|
+
f.push(
|
|
10267
|
+
new Promise((K, k) => {
|
|
10268
|
+
YC(p, {
|
|
10269
|
+
scale: 1,
|
|
10270
|
+
width: p.offsetWidth,
|
|
10271
|
+
height: p.offsetHeight,
|
|
10272
|
+
allowTaint: !0,
|
|
10273
|
+
useCORS: !0
|
|
10274
|
+
}).then((L) => {
|
|
10275
|
+
const F = g.querySelectorAll(u)[v];
|
|
10276
|
+
F.innerHTML = "";
|
|
10277
|
+
const O = L.toDataURL("image/png", 1), D = new Image();
|
|
10278
|
+
D.onload = () => {
|
|
10279
|
+
URL.revokeObjectURL(O);
|
|
10280
|
+
}, D.src = O, F.appendChild(D), K(L);
|
|
10281
|
+
});
|
|
10282
|
+
})
|
|
10283
|
+
);
|
|
10279
10284
|
});
|
|
10280
|
-
});
|
|
10281
|
-
await Promise.all(f);
|
|
10285
|
+
}), await Promise.all(f);
|
|
10282
10286
|
}
|
|
10283
10287
|
const Q = s == null ? void 0 : s.getElementsByTagName("canvas"), c = g == null ? void 0 : g.getElementsByTagName("canvas"), h = Array.from(Q).map((f, u) => new Promise((U) => {
|
|
10284
10288
|
const p = f.toDataURL("image/png", 1), v = new Image();
|
|
@@ -10303,7 +10307,7 @@ const $C = Array.isArray, AQ = (r, e, A) => new Promise((t, n) => {
|
|
|
10303
10307
|
});
|
|
10304
10308
|
};
|
|
10305
10309
|
function eQ(r, e) {
|
|
10306
|
-
return e && [...tQ(e)].forEach((A) => {
|
|
10310
|
+
return r = r.replace(/break-before: page/g, "page-break-before: always"), e && [...tQ(e)].forEach((A) => {
|
|
10307
10311
|
if (r.includes(fi(A.selectorText))) {
|
|
10308
10312
|
let t = new RegExp(`class="${fi(A.selectorText)}"`, "g");
|
|
10309
10313
|
r = r.replace(t, `style="${A.style.cssText}"`);
|
package/dist/xh.umd.cjs
CHANGED
|
@@ -98,10 +98,10 @@ Content-Location: `+((a=i.contentLocation)==null?"":a)+`
|
|
|
98
98
|
* @vue/shared v3.4.23
|
|
99
99
|
* (c) 2018-present Yuxi (Evan) You and Vue contributors
|
|
100
100
|
* @license MIT
|
|
101
|
-
**/process.env.NODE_ENV!=="production"&&Object.freeze({}),process.env.NODE_ENV!=="production"&&Object.freeze([]);const $C=Array.isArray,AQ=(r,e,A)=>new Promise((t,n)=>{const i=new Image;i.crossOrigin="",i.src=r.src,i.onload=function(){const s=document.createElement("canvas");s.width=r.width,s.height=r.height;const g=s.getContext("2d");g==null||g.drawImage(i,0,0,r.width,r.height);const Q=i.src.substring(i.src.lastIndexOf(".")+1).toLowerCase(),c=s.toDataURL("image/"+Q,1);r.setAttribute("src",c),s.remove(),clearTimeout(a),t(c)},i.onerror=async()=>{clearTimeout(a),await o(),console.error("图片加载异常:",i.src),t("xh-htmlword: 图片加载异常")};const a=setTimeout(async()=>{await o(),console.error("图片加载超时:",i.src),t("xh-htmlword: 图片加载超时")},e),o=()=>new Promise(s=>{const g=new Image;g.crossOrigin="",g.src=A||ya,g.onload=()=>{const Q=document.createElement("canvas");Q.width=r.width,Q.height=r.height;const c=Q.getContext("2d");c==null||c.drawImage(g,0,0,r.width,r.height);const h=g.src.substring(g.src.lastIndexOf(".")+1).toLowerCase(),C=Q.toDataURL("image/"+h,1);r.setAttribute("src",C),Q.remove(),s()}})}),eQ=async({dom:r,fileName:e=nQ(),timeOut:A=5e3,callBack:t,options:n={},defultImg:i,className:a,drawCanvas:o})=>{const s=document.querySelector(r),g=s.cloneNode(!0);if(o&&o.length>0&&$C(o)){const f=o.map(u=>{const U=document.
|
|
101
|
+
**/process.env.NODE_ENV!=="production"&&Object.freeze({}),process.env.NODE_ENV!=="production"&&Object.freeze([]);const $C=Array.isArray,AQ=(r,e,A)=>new Promise((t,n)=>{const i=new Image;i.crossOrigin="",i.src=r.src,i.onload=function(){const s=document.createElement("canvas");s.width=r.width,s.height=r.height;const g=s.getContext("2d");g==null||g.drawImage(i,0,0,r.width,r.height);const Q=i.src.substring(i.src.lastIndexOf(".")+1).toLowerCase(),c=s.toDataURL("image/"+Q,1);r.setAttribute("src",c),s.remove(),clearTimeout(a),t(c)},i.onerror=async()=>{clearTimeout(a),await o(),console.error("图片加载异常:",i.src),t("xh-htmlword: 图片加载异常")};const a=setTimeout(async()=>{await o(),console.error("图片加载超时:",i.src),t("xh-htmlword: 图片加载超时")},e),o=()=>new Promise(s=>{const g=new Image;g.crossOrigin="",g.src=A||ya,g.onload=()=>{const Q=document.createElement("canvas");Q.width=r.width,Q.height=r.height;const c=Q.getContext("2d");c==null||c.drawImage(g,0,0,r.width,r.height);const h=g.src.substring(g.src.lastIndexOf(".")+1).toLowerCase(),C=Q.toDataURL("image/"+h,1);r.setAttribute("src",C),Q.remove(),s()}})}),eQ=async({dom:r,fileName:e=nQ(),timeOut:A=5e3,callBack:t,options:n={},defultImg:i,className:a,drawCanvas:o})=>{const s=document.querySelector(r),g=s.cloneNode(!0);if(o&&o.length>0&&$C(o)){const f=[];o.map(u=>{const U=document.querySelectorAll(u);if(U.length==0)throw new Error(`dom不存在:“${u}” , 请检查传入的dom标签是否正确`);U.forEach((p,v)=>{f.push(new Promise((K,k)=>{YC(p,{scale:1,width:p.offsetWidth,height:p.offsetHeight,allowTaint:!0,useCORS:!0}).then(L=>{const F=g.querySelectorAll(u)[v];F.innerHTML="";const O=L.toDataURL("image/png",1),D=new Image;D.onload=()=>{URL.revokeObjectURL(O)},D.src=O,F.appendChild(D),K(L)})}))})}),await Promise.all(f)}const Q=s==null?void 0:s.getElementsByTagName("canvas"),c=g==null?void 0:g.getElementsByTagName("canvas"),h=Array.from(Q).map((f,u)=>new Promise(U=>{const p=f.toDataURL("image/png",1),v=new Image;v.onload=()=>{URL.revokeObjectURL(p),U()},v.src=p,c[u].parentNode.insertBefore(v,c[u])})),C=g.getElementsByTagName("canvas");Array.from(C).forEach(f=>f.parentNode.removeChild(f)),Promise.all(h).then(async()=>{const f=[...g.getElementsByTagName("img")];let u=[];f.forEach(K=>{u.push(AQ(K,A,i))}),await Promise.all(u);const U=`
|
|
102
102
|
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'><head>
|
|
103
103
|
</head>
|
|
104
104
|
<body>
|
|
105
105
|
${g.outerHTML}
|
|
106
106
|
</body>
|
|
107
|
-
</html>`,p=tQ(U,a),v=Ua.asBlob(p,n);va(v,`${e}.docx`),t&&t()})};function tQ(r,e){return e&&[...rQ(e)].forEach(A=>{if(r.includes(ha(A.selectorText))){let t=new RegExp(`class="${ha(A.selectorText)}"`,"g");r=r.replace(t,`style="${A.style.cssText}"`)}}),r}function ha(r){let e=r.match(/\.(\w+)/);if(e)return e[1];console.log("没有找到匹配的部分")}function rQ(r){return[...document.styleSheets].reverse().find(({cssRules:t})=>[...t].find(n=>n.selectorText.includes(r))).cssRules}const nQ=()=>{const r=new Date,e=r.getFullYear(),A=("0"+(r.getMonth()+1)).slice(-2),t=("0"+r.getDate()).slice(-2);return`${e}${A}${t}`};return eQ});
|
|
107
|
+
</html>`,p=tQ(U,a),v=Ua.asBlob(p,n);va(v,`${e}.docx`),t&&t()})};function tQ(r,e){return r=r.replace(/break-before: page/g,"page-break-before: always"),e&&[...rQ(e)].forEach(A=>{if(r.includes(ha(A.selectorText))){let t=new RegExp(`class="${ha(A.selectorText)}"`,"g");r=r.replace(t,`style="${A.style.cssText}"`)}}),r}function ha(r){let e=r.match(/\.(\w+)/);if(e)return e[1];console.log("没有找到匹配的部分")}function rQ(r){return[...document.styleSheets].reverse().find(({cssRules:t})=>[...t].find(n=>n.selectorText.includes(r))).cssRules}const nQ=()=>{const r=new Date,e=r.getFullYear(),A=("0"+(r.getMonth()+1)).slice(-2),t=("0"+r.getDate()).slice(-2);return`${e}${A}${t}`};return eQ});
|