@superdoc-dev/esign 1.3.0 → 1.3.1
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.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +357 -359
- package/package.json +4 -5
- package/dist/PdfViewer-BLHsHKWf.es-DVVY0V9L.cjs +0 -43
- package/dist/PdfViewer-BLHsHKWf.es-JoVU99JQ.js +0 -400
- package/dist/superdoc.es-CqejOF1J.js +0 -90963
- package/dist/superdoc.es-DfpwGgyj.cjs +0 -1180
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdoc-dev/esign",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "React eSignature component for SuperDoc",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -51,10 +51,8 @@
|
|
|
51
51
|
"homepage": "https://github.com/superdoc-dev/esign#readme",
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
54
|
-
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
|
|
55
|
-
|
|
56
|
-
"dependencies": {
|
|
57
|
-
"superdoc": "^0.22.0"
|
|
54
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
55
|
+
"superdoc": "^0.29.0"
|
|
58
56
|
},
|
|
59
57
|
"devDependencies": {
|
|
60
58
|
"@commitlint/cli": "^20.1.0",
|
|
@@ -78,6 +76,7 @@
|
|
|
78
76
|
"react": "^19.2.0",
|
|
79
77
|
"react-dom": "^19.2.0",
|
|
80
78
|
"semantic-release": "^24.2.9",
|
|
79
|
+
"superdoc": "^0.29.0",
|
|
81
80
|
"typescript": "^5.9.2",
|
|
82
81
|
"typescript-eslint": "^8.44.1",
|
|
83
82
|
"vite": "^7.1.7",
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./superdoc.es-DfpwGgyj.cjs");function B(s){const{opacityDisabled:t,heightTiny:o,heightSmall:n,heightMedium:i,heightLarge:a,heightHuge:u,primaryColor:l,fontSize:r}=s;return{fontSize:r,textColor:l,sizeTiny:o,sizeSmall:n,sizeMedium:i,sizeLarge:a,sizeHuge:u,color:l,opacitySpinning:t}}const V={common:e.derived,self:B},L=e.c$1([e.c$1("@keyframes spin-rotate",`
|
|
2
|
-
from {
|
|
3
|
-
transform: rotate(0);
|
|
4
|
-
}
|
|
5
|
-
to {
|
|
6
|
-
transform: rotate(360deg);
|
|
7
|
-
}
|
|
8
|
-
`),e.cB("spin-container",`
|
|
9
|
-
position: relative;
|
|
10
|
-
`,[e.cB("spin-body",`
|
|
11
|
-
position: absolute;
|
|
12
|
-
top: 50%;
|
|
13
|
-
left: 50%;
|
|
14
|
-
transform: translateX(-50%) translateY(-50%);
|
|
15
|
-
`,[e.fadeInTransition()])]),e.cB("spin-body",`
|
|
16
|
-
display: inline-flex;
|
|
17
|
-
align-items: center;
|
|
18
|
-
justify-content: center;
|
|
19
|
-
flex-direction: column;
|
|
20
|
-
`),e.cB("spin",`
|
|
21
|
-
display: inline-flex;
|
|
22
|
-
height: var(--n-size);
|
|
23
|
-
width: var(--n-size);
|
|
24
|
-
font-size: var(--n-size);
|
|
25
|
-
color: var(--n-color);
|
|
26
|
-
`,[e.cM("rotate",`
|
|
27
|
-
animation: spin-rotate 2s linear infinite;
|
|
28
|
-
`)]),e.cB("spin-description",`
|
|
29
|
-
display: inline-block;
|
|
30
|
-
font-size: var(--n-font-size);
|
|
31
|
-
color: var(--n-text-color);
|
|
32
|
-
transition: color .3s var(--n-bezier);
|
|
33
|
-
margin-top: 8px;
|
|
34
|
-
`),e.cB("spin-content",`
|
|
35
|
-
opacity: 1;
|
|
36
|
-
transition: opacity .3s var(--n-bezier);
|
|
37
|
-
pointer-events: all;
|
|
38
|
-
`,[e.cM("spinning",`
|
|
39
|
-
user-select: none;
|
|
40
|
-
-webkit-user-select: none;
|
|
41
|
-
pointer-events: none;
|
|
42
|
-
opacity: var(--n-opacity-spinning);
|
|
43
|
-
`)])]),_={small:20,medium:18,large:16},R=Object.assign(Object.assign({},e.useTheme.props),{contentClass:String,contentStyle:[Object,String],description:String,stroke:String,size:{type:[String,Number],default:"medium"},show:{type:Boolean,default:!0},strokeWidth:Number,rotate:{type:Boolean,default:!0},spinning:{type:Boolean,validator:()=>!0,default:void 0},delay:Number}),D=e.defineComponent({name:"Spin",props:R,slots:Object,setup(s){e.process$1.env.NODE_ENV!=="production"&&e.watchEffect(()=>{s.spinning!==void 0&&e.warnOnce("spin","`spinning` is deprecated, please use `show` instead.")});const{mergedClsPrefixRef:t,inlineThemeDisabled:o}=e.useConfig(s),n=e.useTheme("Spin","-spin",L,V,s,t),i=e.computed(()=>{const{size:r}=s,{common:{cubicBezierEaseInOut:p},self:h}=n.value,{opacitySpinning:f,color:y,textColor:b}=h,m=typeof r=="number"?e.pxfy(r):h[e.createKey("size",r)];return{"--n-bezier":p,"--n-opacity-spinning":f,"--n-size":m,"--n-color":y,"--n-text-color":b}}),a=o?e.useThemeClass("spin",e.computed(()=>{const{size:r}=s;return typeof r=="number"?String(r):r[0]}),i,s):void 0,u=e.useCompitable(s,["spinning","show"]),l=e.ref(!1);return e.watchEffect(r=>{let p;if(u.value){const{delay:h}=s;if(h){p=window.setTimeout(()=>{l.value=!0},h),r(()=>{clearTimeout(p)});return}}l.value=u.value}),{mergedClsPrefix:t,active:l,mergedStrokeWidth:e.computed(()=>{const{strokeWidth:r}=s;if(r!==void 0)return r;const{size:p}=s;return _[typeof p=="number"?"medium":p]}),cssVars:o?void 0:i,themeClass:a?.themeClass,onRender:a?.onRender}},render(){var s,t;const{$slots:o,mergedClsPrefix:n,description:i}=this,a=o.icon&&this.rotate,u=(i||o.description)&&e.h("div",{class:`${n}-spin-description`},i||((s=o.description)===null||s===void 0?void 0:s.call(o))),l=o.icon?e.h("div",{class:[`${n}-spin-body`,this.themeClass]},e.h("div",{class:[`${n}-spin`,a&&`${n}-spin--rotate`],style:o.default?"":this.cssVars},o.icon()),u):e.h("div",{class:[`${n}-spin-body`,this.themeClass]},e.h(e.NBaseLoading,{clsPrefix:n,style:o.default?"":this.cssVars,stroke:this.stroke,"stroke-width":this.mergedStrokeWidth,class:`${n}-spin`}),u);return(t=this.onRender)===null||t===void 0||t.call(this),o.default?e.h("div",{class:[`${n}-spin-container`,this.themeClass],style:this.cssVars},e.h("div",{class:[`${n}-spin-content`,this.active&&`${n}-spin-content--spinning`,this.contentClass],style:this.contentStyle},o),e.h(e.Transition,{name:"fade-in-transition"},{default:()=>this.active?l:null})):l}}),M=(s,t)=>{const o=t-s;return Array.from({length:o},(n,i)=>s+i)};class z{constructor(){if(Object.getPrototypeOf(this).constructor===z)throw new Error("Abstract class should not be instanciated")}}class T extends z{constructor(t){super(),this.pdfLib=t.pdfLib,this.pdfViewer=t.pdfViewer,this.workerSrc=t.workerSrc,this.textLayerMode=t.textLayerMode??0,t.setWorker&&(this.workerSrc?this.pdfLib.GlobalWorkerOptions.workerSrc=t.workerSrc:this.pdfLib.GlobalWorkerOptions.workerSrc=N(this.pdfLib.version)),this.pdfPageViews=[]}async getDocument(t){return await this.pdfLib.getDocument(t).promise}async renderPages({documentId:t,pdfDocument:o,viewerContainer:n,emit:i=()=>{}}){try{this.pdfPageViews=[];const a=o.numPages,l=await $(o,1,a),r=[];for(const[p,h]of l.entries()){const f=document.createElement("div");f.classList.add("pdf-page"),f.dataset.pageNumber=(p+1).toString(),f.id=`${t}-page-${p+1}`,r.push(f);const{width:y,height:b}=this.getOriginalPageSize(h),m=1,C=new this.pdfViewer.EventBus,d=new this.pdfViewer.PDFPageView({container:f,id:p+1,scale:m,defaultViewport:h.getViewport({scale:m}),eventBus:C,textLayerMode:this.textLayerMode});this.pdfPageViews.push(d);const g=f.getBoundingClientRect();g.originalWidth=y,g.originalHeight=b,d.setPdfPage(h),await d.draw(),i("page-loaded",t,p,g)}n.append(...r),i("ready",t,n)}catch(a){console.error("Error loading PDF:",a)}}getOriginalPageSize(t){const o=t.getViewport({scale:1}),n=o.width,i=o.height;return{width:n,height:i}}destroy(){this.pdfPageViews.forEach(t=>t.destroy()),this.pdfPageViews=[]}}class j{static create(t){const o={pdfjs:()=>new T(t),default:()=>{throw new Error("Unsupported adapter")}};return(o[t.adapter]??o.default)()}}const O=s=>({...{adapter:"pdfjs"},...s});async function $(s,t,o){const n=M(t,o+1).map(i=>s.getPage(i));return await Promise.all(n)}function N(s){return`https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${s}/pdf.worker.min.mjs`}const E=s=>new Promise((t,o)=>{const n=new FileReader;n.onload=i=>t(i.target.result),n.onerror=o,n.readAsDataURL(s)}),W={key:0,class:"superdoc-pdf-viewer__loader"},A={__name:"PdfViewer",props:{documentData:{type:Object,required:!0},config:{type:Object,required:!0}},emits:["page-loaded","ready","selection-change","bypass-selection"],setup(s,{emit:t}){const o=t,n=s,i=e.useSuperdocStore(),{activeZoom:a}=e.storeToRefs(i),u=e.ref(null),l=e.ref(!1),r=n.documentData.id,p=n.documentData.data,h=O({pdfLib:n.config.pdfLib,pdfViewer:n.config.pdfViewer,workerSrc:n.config.workerSrc,setWorker:n.config.setWorker,textLayerMode:n.config.textLayerMode}),f=j.create(h),y=async d=>{try{const g=await E(d),S=await f.getDocument(g);await f.renderPages({documentId:r,pdfDocument:S,viewerContainer:u.value,emit:o}),l.value=!0}catch{}};function b(d){const g=window.getSelection();if(g.rangeCount===0)return null;const w=g.getRangeAt(0).getClientRects();if(w.length===0)return null;const P=w[0];let c={top:P.top,left:P.left,bottom:P.bottom,right:P.right};for(let x=1;x<w.length;x++){const v=w[x];v.width===0||v.height===0||(c.top=Math.min(c.top,v.top),c.left=Math.min(c.left,v.left),c.bottom=Math.max(c.bottom,v.bottom),c.right=Math.max(c.right,v.right))}const k=d.getBoundingClientRect();return u.value.getBoundingClientRect(),c.top=(c.top-k.top)/(a.value/100)+d.scrollTop,c.left=(c.left-k.left)/(a.value/100)+d.scrollLeft,c.bottom=(c.bottom-k.top)/(a.value/100)+d.scrollTop,c.right=(c.right-k.left)/(a.value/100)+d.scrollLeft,c}const m=d=>{const{target:g}=d;g.tagName!=="SPAN"&&o("bypass-selection",d)},C=d=>{if(window.getSelection().toString().length>0){const S=b(u.value),w=e.useSelection({selectionBounds:S,documentId:r});o("selection-change",w)}};return e.onMounted(async()=>{await y(p)}),e.onUnmounted(()=>{f.destroy()}),(d,g)=>(e.openBlock(),e.createElementBlock("div",{class:"superdoc-pdf-viewer-container",onMousedown:m,onMouseup:C},[e.createBaseVNode("div",{class:"superdoc-pdf-viewer",ref_key:"viewer",ref:u,id:"viewerId"},null,512),l.value?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",W,[e.createVNode(e.unref(D),{class:"superdoc-pdf-viewer__spin",size:"large"})]))],32))}},F=e._export_sfc(A,[["__scopeId","data-v-84719682"]]);exports.default=F;
|
|
@@ -1,400 +0,0 @@
|
|
|
1
|
-
import { _ as N, u as O, s as $, r as L, o as E, a as W, c as B, b as R, d as A, e as F, f as I, g as H, h as U, i as h, N as q, T as G, p as K, w as D, j as J, k as X, l as M, m as Y, n as T, q as V, t as Z, v as Q, x as ee, y as te, z as se, A as y, B as ne, C as j } from "./superdoc.es-CqejOF1J.js";
|
|
2
|
-
function oe(n) {
|
|
3
|
-
const {
|
|
4
|
-
opacityDisabled: e,
|
|
5
|
-
heightTiny: s,
|
|
6
|
-
heightSmall: t,
|
|
7
|
-
heightMedium: o,
|
|
8
|
-
heightLarge: r,
|
|
9
|
-
heightHuge: p,
|
|
10
|
-
primaryColor: d,
|
|
11
|
-
fontSize: i
|
|
12
|
-
} = n;
|
|
13
|
-
return {
|
|
14
|
-
fontSize: i,
|
|
15
|
-
textColor: d,
|
|
16
|
-
sizeTiny: s,
|
|
17
|
-
sizeSmall: t,
|
|
18
|
-
sizeMedium: o,
|
|
19
|
-
sizeLarge: r,
|
|
20
|
-
sizeHuge: p,
|
|
21
|
-
color: d,
|
|
22
|
-
opacitySpinning: e
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
const ie = {
|
|
26
|
-
common: Y,
|
|
27
|
-
self: oe
|
|
28
|
-
}, re = T([T("@keyframes spin-rotate", `
|
|
29
|
-
from {
|
|
30
|
-
transform: rotate(0);
|
|
31
|
-
}
|
|
32
|
-
to {
|
|
33
|
-
transform: rotate(360deg);
|
|
34
|
-
}
|
|
35
|
-
`), y("spin-container", `
|
|
36
|
-
position: relative;
|
|
37
|
-
`, [y("spin-body", `
|
|
38
|
-
position: absolute;
|
|
39
|
-
top: 50%;
|
|
40
|
-
left: 50%;
|
|
41
|
-
transform: translateX(-50%) translateY(-50%);
|
|
42
|
-
`, [ne()])]), y("spin-body", `
|
|
43
|
-
display: inline-flex;
|
|
44
|
-
align-items: center;
|
|
45
|
-
justify-content: center;
|
|
46
|
-
flex-direction: column;
|
|
47
|
-
`), y("spin", `
|
|
48
|
-
display: inline-flex;
|
|
49
|
-
height: var(--n-size);
|
|
50
|
-
width: var(--n-size);
|
|
51
|
-
font-size: var(--n-size);
|
|
52
|
-
color: var(--n-color);
|
|
53
|
-
`, [j("rotate", `
|
|
54
|
-
animation: spin-rotate 2s linear infinite;
|
|
55
|
-
`)]), y("spin-description", `
|
|
56
|
-
display: inline-block;
|
|
57
|
-
font-size: var(--n-font-size);
|
|
58
|
-
color: var(--n-text-color);
|
|
59
|
-
transition: color .3s var(--n-bezier);
|
|
60
|
-
margin-top: 8px;
|
|
61
|
-
`), y("spin-content", `
|
|
62
|
-
opacity: 1;
|
|
63
|
-
transition: opacity .3s var(--n-bezier);
|
|
64
|
-
pointer-events: all;
|
|
65
|
-
`, [j("spinning", `
|
|
66
|
-
user-select: none;
|
|
67
|
-
-webkit-user-select: none;
|
|
68
|
-
pointer-events: none;
|
|
69
|
-
opacity: var(--n-opacity-spinning);
|
|
70
|
-
`)])]), ae = {
|
|
71
|
-
small: 20,
|
|
72
|
-
medium: 18,
|
|
73
|
-
large: 16
|
|
74
|
-
}, ce = Object.assign(Object.assign({}, M.props), {
|
|
75
|
-
contentClass: String,
|
|
76
|
-
contentStyle: [Object, String],
|
|
77
|
-
description: String,
|
|
78
|
-
stroke: String,
|
|
79
|
-
size: {
|
|
80
|
-
type: [String, Number],
|
|
81
|
-
default: "medium"
|
|
82
|
-
},
|
|
83
|
-
show: {
|
|
84
|
-
type: Boolean,
|
|
85
|
-
default: !0
|
|
86
|
-
},
|
|
87
|
-
strokeWidth: Number,
|
|
88
|
-
rotate: {
|
|
89
|
-
type: Boolean,
|
|
90
|
-
default: !0
|
|
91
|
-
},
|
|
92
|
-
spinning: {
|
|
93
|
-
type: Boolean,
|
|
94
|
-
validator: () => !0,
|
|
95
|
-
default: void 0
|
|
96
|
-
},
|
|
97
|
-
delay: Number
|
|
98
|
-
}), de = U({
|
|
99
|
-
name: "Spin",
|
|
100
|
-
props: ce,
|
|
101
|
-
slots: Object,
|
|
102
|
-
setup(n) {
|
|
103
|
-
K.env.NODE_ENV !== "production" && D(() => {
|
|
104
|
-
n.spinning !== void 0 && J("spin", "`spinning` is deprecated, please use `show` instead.");
|
|
105
|
-
});
|
|
106
|
-
const {
|
|
107
|
-
mergedClsPrefixRef: e,
|
|
108
|
-
inlineThemeDisabled: s
|
|
109
|
-
} = X(n), t = M("Spin", "-spin", re, ie, n, e), o = V(() => {
|
|
110
|
-
const {
|
|
111
|
-
size: i
|
|
112
|
-
} = n, {
|
|
113
|
-
common: {
|
|
114
|
-
cubicBezierEaseInOut: l
|
|
115
|
-
},
|
|
116
|
-
self: g
|
|
117
|
-
} = t.value, {
|
|
118
|
-
opacitySpinning: u,
|
|
119
|
-
color: b,
|
|
120
|
-
textColor: S
|
|
121
|
-
} = g, m = typeof i == "number" ? Z(i) : g[Q("size", i)];
|
|
122
|
-
return {
|
|
123
|
-
"--n-bezier": l,
|
|
124
|
-
"--n-opacity-spinning": u,
|
|
125
|
-
"--n-size": m,
|
|
126
|
-
"--n-color": b,
|
|
127
|
-
"--n-text-color": S
|
|
128
|
-
};
|
|
129
|
-
}), r = s ? ee("spin", V(() => {
|
|
130
|
-
const {
|
|
131
|
-
size: i
|
|
132
|
-
} = n;
|
|
133
|
-
return typeof i == "number" ? String(i) : i[0];
|
|
134
|
-
}), o, n) : void 0, p = te(n, ["spinning", "show"]), d = L(!1);
|
|
135
|
-
return D((i) => {
|
|
136
|
-
let l;
|
|
137
|
-
if (p.value) {
|
|
138
|
-
const {
|
|
139
|
-
delay: g
|
|
140
|
-
} = n;
|
|
141
|
-
if (g) {
|
|
142
|
-
l = window.setTimeout(() => {
|
|
143
|
-
d.value = !0;
|
|
144
|
-
}, g), i(() => {
|
|
145
|
-
clearTimeout(l);
|
|
146
|
-
});
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
d.value = p.value;
|
|
151
|
-
}), {
|
|
152
|
-
mergedClsPrefix: e,
|
|
153
|
-
active: d,
|
|
154
|
-
mergedStrokeWidth: V(() => {
|
|
155
|
-
const {
|
|
156
|
-
strokeWidth: i
|
|
157
|
-
} = n;
|
|
158
|
-
if (i !== void 0) return i;
|
|
159
|
-
const {
|
|
160
|
-
size: l
|
|
161
|
-
} = n;
|
|
162
|
-
return ae[typeof l == "number" ? "medium" : l];
|
|
163
|
-
}),
|
|
164
|
-
cssVars: s ? void 0 : o,
|
|
165
|
-
themeClass: r?.themeClass,
|
|
166
|
-
onRender: r?.onRender
|
|
167
|
-
};
|
|
168
|
-
},
|
|
169
|
-
render() {
|
|
170
|
-
var n, e;
|
|
171
|
-
const {
|
|
172
|
-
$slots: s,
|
|
173
|
-
mergedClsPrefix: t,
|
|
174
|
-
description: o
|
|
175
|
-
} = this, r = s.icon && this.rotate, p = (o || s.description) && h("div", {
|
|
176
|
-
class: `${t}-spin-description`
|
|
177
|
-
}, o || ((n = s.description) === null || n === void 0 ? void 0 : n.call(s))), d = s.icon ? h("div", {
|
|
178
|
-
class: [`${t}-spin-body`, this.themeClass]
|
|
179
|
-
}, h("div", {
|
|
180
|
-
class: [`${t}-spin`, r && `${t}-spin--rotate`],
|
|
181
|
-
style: s.default ? "" : this.cssVars
|
|
182
|
-
}, s.icon()), p) : h("div", {
|
|
183
|
-
class: [`${t}-spin-body`, this.themeClass]
|
|
184
|
-
}, h(q, {
|
|
185
|
-
clsPrefix: t,
|
|
186
|
-
style: s.default ? "" : this.cssVars,
|
|
187
|
-
stroke: this.stroke,
|
|
188
|
-
"stroke-width": this.mergedStrokeWidth,
|
|
189
|
-
class: `${t}-spin`
|
|
190
|
-
}), p);
|
|
191
|
-
return (e = this.onRender) === null || e === void 0 || e.call(this), s.default ? h("div", {
|
|
192
|
-
class: [`${t}-spin-container`, this.themeClass],
|
|
193
|
-
style: this.cssVars
|
|
194
|
-
}, h("div", {
|
|
195
|
-
class: [`${t}-spin-content`, this.active && `${t}-spin-content--spinning`, this.contentClass],
|
|
196
|
-
style: this.contentStyle
|
|
197
|
-
}, s), h(G, {
|
|
198
|
-
name: "fade-in-transition"
|
|
199
|
-
}, {
|
|
200
|
-
default: () => this.active ? d : null
|
|
201
|
-
})) : d;
|
|
202
|
-
}
|
|
203
|
-
}), le = (n, e) => {
|
|
204
|
-
const s = e - n;
|
|
205
|
-
return Array.from({ length: s }, (t, o) => n + o);
|
|
206
|
-
};
|
|
207
|
-
class _ {
|
|
208
|
-
/**
|
|
209
|
-
* @throws {Error}
|
|
210
|
-
*/
|
|
211
|
-
constructor() {
|
|
212
|
-
if (Object.getPrototypeOf(this).constructor === _)
|
|
213
|
-
throw new Error("Abstract class should not be instanciated");
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
class pe extends _ {
|
|
217
|
-
/**
|
|
218
|
-
* @param {PDFJSConfig} config
|
|
219
|
-
*/
|
|
220
|
-
constructor(e) {
|
|
221
|
-
super(), this.pdfLib = e.pdfLib, this.pdfViewer = e.pdfViewer, this.workerSrc = e.workerSrc, this.textLayerMode = e.textLayerMode ?? 0, e.setWorker && (this.workerSrc ? this.pdfLib.GlobalWorkerOptions.workerSrc = e.workerSrc : this.pdfLib.GlobalWorkerOptions.workerSrc = he(this.pdfLib.version)), this.pdfPageViews = [];
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* @param {string | ArrayBuffer | Uint8Array} file
|
|
225
|
-
* @returns {Promise<PDFDocumentProxy>}
|
|
226
|
-
*/
|
|
227
|
-
async getDocument(e) {
|
|
228
|
-
return await this.pdfLib.getDocument(e).promise;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* @param {RenderPagesOptions} options
|
|
232
|
-
* @returns {Promise<void>}
|
|
233
|
-
*/
|
|
234
|
-
async renderPages({ documentId: e, pdfDocument: s, viewerContainer: t, emit: o = () => {
|
|
235
|
-
} }) {
|
|
236
|
-
try {
|
|
237
|
-
this.pdfPageViews = [];
|
|
238
|
-
const r = s.numPages, d = await ge(s, 1, r), i = [];
|
|
239
|
-
for (const [l, g] of d.entries()) {
|
|
240
|
-
const u = document.createElement("div");
|
|
241
|
-
u.classList.add("pdf-page"), u.dataset.pageNumber = (l + 1).toString(), u.id = `${e}-page-${l + 1}`, i.push(u);
|
|
242
|
-
const { width: b, height: S } = this.getOriginalPageSize(g), m = 1, x = new this.pdfViewer.EventBus(), c = new this.pdfViewer.PDFPageView({
|
|
243
|
-
container: u,
|
|
244
|
-
id: l + 1,
|
|
245
|
-
scale: m,
|
|
246
|
-
defaultViewport: g.getViewport({ scale: m }),
|
|
247
|
-
eventBus: x,
|
|
248
|
-
textLayerMode: this.textLayerMode
|
|
249
|
-
});
|
|
250
|
-
this.pdfPageViews.push(c);
|
|
251
|
-
const f = u.getBoundingClientRect();
|
|
252
|
-
f.originalWidth = b, f.originalHeight = S, c.setPdfPage(g), await c.draw(), o("page-loaded", e, l, f);
|
|
253
|
-
}
|
|
254
|
-
t.append(...i), o("ready", e, t);
|
|
255
|
-
} catch (r) {
|
|
256
|
-
console.error("Error loading PDF:", r);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* @param {PDFPageProxy} page
|
|
261
|
-
* @returns {object}
|
|
262
|
-
*/
|
|
263
|
-
getOriginalPageSize(e) {
|
|
264
|
-
const s = e.getViewport({ scale: 1 }), t = s.width, o = s.height;
|
|
265
|
-
return { width: t, height: o };
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* @return {void}
|
|
269
|
-
*/
|
|
270
|
-
destroy() {
|
|
271
|
-
this.pdfPageViews.forEach((e) => e.destroy()), this.pdfPageViews = [];
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
class ue {
|
|
275
|
-
/**
|
|
276
|
-
* @param {PDFJSConfig & {adapter: AdapterType}} config
|
|
277
|
-
* @returns {PDFAdapter}
|
|
278
|
-
* @throws {Error}
|
|
279
|
-
*/
|
|
280
|
-
static create(e) {
|
|
281
|
-
const s = {
|
|
282
|
-
pdfjs: () => new pe(e),
|
|
283
|
-
default: () => {
|
|
284
|
-
throw new Error("Unsupported adapter");
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
return (s[e.adapter] ?? s.default)();
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
const fe = (n) => ({
|
|
291
|
-
...{
|
|
292
|
-
adapter: "pdfjs"
|
|
293
|
-
},
|
|
294
|
-
...n
|
|
295
|
-
});
|
|
296
|
-
async function ge(n, e, s) {
|
|
297
|
-
const t = le(e, s + 1).map((o) => n.getPage(o));
|
|
298
|
-
return await Promise.all(t);
|
|
299
|
-
}
|
|
300
|
-
function he(n) {
|
|
301
|
-
return `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${n}/pdf.worker.min.mjs`;
|
|
302
|
-
}
|
|
303
|
-
const me = (n) => new Promise((e, s) => {
|
|
304
|
-
const t = new FileReader();
|
|
305
|
-
t.onload = (o) => e(o.target.result), t.onerror = s, t.readAsDataURL(n);
|
|
306
|
-
}), we = {
|
|
307
|
-
key: 0,
|
|
308
|
-
class: "superdoc-pdf-viewer__loader"
|
|
309
|
-
}, ve = {
|
|
310
|
-
__name: "PdfViewer",
|
|
311
|
-
props: {
|
|
312
|
-
documentData: {
|
|
313
|
-
type: Object,
|
|
314
|
-
required: !0
|
|
315
|
-
},
|
|
316
|
-
config: {
|
|
317
|
-
type: Object,
|
|
318
|
-
required: !0
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
emits: ["page-loaded", "ready", "selection-change", "bypass-selection"],
|
|
322
|
-
setup(n, { emit: e }) {
|
|
323
|
-
const s = e, t = n, o = O(), { activeZoom: r } = $(o), p = L(null), d = L(!1), i = t.documentData.id, l = t.documentData.data, g = fe({
|
|
324
|
-
pdfLib: t.config.pdfLib,
|
|
325
|
-
pdfViewer: t.config.pdfViewer,
|
|
326
|
-
workerSrc: t.config.workerSrc,
|
|
327
|
-
setWorker: t.config.setWorker,
|
|
328
|
-
textLayerMode: t.config.textLayerMode
|
|
329
|
-
}), u = ue.create(g), b = async (c) => {
|
|
330
|
-
try {
|
|
331
|
-
const f = await me(c), P = await u.getDocument(f);
|
|
332
|
-
await u.renderPages({
|
|
333
|
-
documentId: i,
|
|
334
|
-
pdfDocument: P,
|
|
335
|
-
viewerContainer: p.value,
|
|
336
|
-
emit: s
|
|
337
|
-
}), d.value = !0;
|
|
338
|
-
} catch {
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
function S(c) {
|
|
342
|
-
const f = window.getSelection();
|
|
343
|
-
if (f.rangeCount === 0)
|
|
344
|
-
return null;
|
|
345
|
-
const w = f.getRangeAt(0).getClientRects();
|
|
346
|
-
if (w.length === 0)
|
|
347
|
-
return null;
|
|
348
|
-
const k = w[0];
|
|
349
|
-
let a = {
|
|
350
|
-
top: k.top,
|
|
351
|
-
left: k.left,
|
|
352
|
-
bottom: k.bottom,
|
|
353
|
-
right: k.right
|
|
354
|
-
};
|
|
355
|
-
for (let z = 1; z < w.length; z++) {
|
|
356
|
-
const v = w[z];
|
|
357
|
-
v.width === 0 || v.height === 0 || (a.top = Math.min(a.top, v.top), a.left = Math.min(a.left, v.left), a.bottom = Math.max(a.bottom, v.bottom), a.right = Math.max(a.right, v.right));
|
|
358
|
-
}
|
|
359
|
-
const C = c.getBoundingClientRect();
|
|
360
|
-
return p.value.getBoundingClientRect(), a.top = (a.top - C.top) / (r.value / 100) + c.scrollTop, a.left = (a.left - C.left) / (r.value / 100) + c.scrollLeft, a.bottom = (a.bottom - C.top) / (r.value / 100) + c.scrollTop, a.right = (a.right - C.left) / (r.value / 100) + c.scrollLeft, a;
|
|
361
|
-
}
|
|
362
|
-
const m = (c) => {
|
|
363
|
-
const { target: f } = c;
|
|
364
|
-
f.tagName !== "SPAN" && s("bypass-selection", c);
|
|
365
|
-
}, x = (c) => {
|
|
366
|
-
if (window.getSelection().toString().length > 0) {
|
|
367
|
-
const P = S(p.value), w = se({
|
|
368
|
-
selectionBounds: P,
|
|
369
|
-
documentId: i
|
|
370
|
-
});
|
|
371
|
-
s("selection-change", w);
|
|
372
|
-
}
|
|
373
|
-
};
|
|
374
|
-
return E(async () => {
|
|
375
|
-
await b(l);
|
|
376
|
-
}), W(() => {
|
|
377
|
-
u.destroy();
|
|
378
|
-
}), (c, f) => (R(), B("div", {
|
|
379
|
-
class: "superdoc-pdf-viewer-container",
|
|
380
|
-
onMousedown: m,
|
|
381
|
-
onMouseup: x
|
|
382
|
-
}, [
|
|
383
|
-
A("div", {
|
|
384
|
-
class: "superdoc-pdf-viewer",
|
|
385
|
-
ref_key: "viewer",
|
|
386
|
-
ref: p,
|
|
387
|
-
id: "viewerId"
|
|
388
|
-
}, null, 512),
|
|
389
|
-
d.value ? F("", !0) : (R(), B("div", we, [
|
|
390
|
-
I(H(de), {
|
|
391
|
-
class: "superdoc-pdf-viewer__spin",
|
|
392
|
-
size: "large"
|
|
393
|
-
})
|
|
394
|
-
]))
|
|
395
|
-
], 32));
|
|
396
|
-
}
|
|
397
|
-
}, be = /* @__PURE__ */ N(ve, [["__scopeId", "data-v-84719682"]]);
|
|
398
|
-
export {
|
|
399
|
-
be as default
|
|
400
|
-
};
|