@component-hook/pdf-canvas 1.2.2-alpha.2 → 1.2.2-alpha.3
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/react/pdf-canvas.es.js +61 -59
- package/dist/react/pdf-canvas.umd.js +38 -38
- package/dist/vue/pdf-canvas.es.js +235 -233
- package/dist/vue/pdf-canvas.umd.js +45 -45
- package/package.json +1 -1
|
@@ -22230,18 +22230,26 @@ Y.setLayerDimensions;
|
|
|
22230
22230
|
Y.shadow;
|
|
22231
22231
|
Y.stopEvent;
|
|
22232
22232
|
var Vg = Y.version;
|
|
22233
|
+
function Wg(a) {
|
|
22234
|
+
return new Worker(
|
|
22235
|
+
"" + new URL("assets/pdfjs.worker-DawqtvLM.js", import.meta.url).href,
|
|
22236
|
+
{
|
|
22237
|
+
name: a?.name
|
|
22238
|
+
}
|
|
22239
|
+
);
|
|
22240
|
+
}
|
|
22233
22241
|
let Ja = null;
|
|
22234
|
-
function
|
|
22242
|
+
function Xg() {
|
|
22235
22243
|
const a = document.createElement("div");
|
|
22236
22244
|
a.style.width = "1in", document.body.append(a);
|
|
22237
22245
|
const t = a.offsetWidth;
|
|
22238
22246
|
return a.remove(), t;
|
|
22239
22247
|
}
|
|
22240
|
-
function
|
|
22241
|
-
const a = Ja ??
|
|
22248
|
+
function Ug() {
|
|
22249
|
+
const a = Ja ?? Xg();
|
|
22242
22250
|
return Ja = a, a / 72;
|
|
22243
22251
|
}
|
|
22244
|
-
function
|
|
22252
|
+
function Yg(a, t = 500) {
|
|
22245
22253
|
if (typeof a != "function") throw new TypeError("The first argument is not a function.");
|
|
22246
22254
|
let e = null;
|
|
22247
22255
|
return function(...s) {
|
|
@@ -22250,15 +22258,15 @@ function Ug(a, t = 500) {
|
|
|
22250
22258
|
}, t);
|
|
22251
22259
|
};
|
|
22252
22260
|
}
|
|
22253
|
-
function
|
|
22261
|
+
function $g(a) {
|
|
22254
22262
|
return new Promise((t, e) => {
|
|
22255
22263
|
const s = new FileReader();
|
|
22256
22264
|
s.addEventListener("load", () => t(s.result)), s.addEventListener("error", e), s.readAsDataURL(a);
|
|
22257
22265
|
});
|
|
22258
22266
|
}
|
|
22259
22267
|
Yl() || (zg.workerSrc = `https://cdnjs.cloudflare.com/ajax/libs/pdf.js/${Vg}/pdf.worker.min.mjs`);
|
|
22260
|
-
async function
|
|
22261
|
-
const t = "data:application/pdf;base64,", e = await
|
|
22268
|
+
async function qg(a) {
|
|
22269
|
+
const t = "data:application/pdf;base64,", e = await $g(a);
|
|
22262
22270
|
if (typeof e == "string")
|
|
22263
22271
|
return globalThis.atob(e.slice(t.length));
|
|
22264
22272
|
}
|
|
@@ -22269,24 +22277,18 @@ function Yl() {
|
|
|
22269
22277
|
return !1;
|
|
22270
22278
|
}
|
|
22271
22279
|
}
|
|
22272
|
-
async function
|
|
22273
|
-
const n =
|
|
22280
|
+
async function Kg({ page: a, PDFBase64: t, scale: e, password: s }, i) {
|
|
22281
|
+
const n = Ug() / window.devicePixelRatio;
|
|
22274
22282
|
if (Yl()) {
|
|
22275
|
-
const r = new
|
|
22276
|
-
/* @vite-ignore */
|
|
22277
|
-
"" + new URL("assets/pdfjs.worker-DawqtvLM.js", import.meta.url).href,
|
|
22278
|
-
import.meta.url
|
|
22279
|
-
), { type: "module" });
|
|
22283
|
+
const r = new Wg();
|
|
22280
22284
|
return r.postMessage({ data: t, password: s, id: i, page: a, units: n, scale: e }), await new Promise((h) => {
|
|
22281
22285
|
r.addEventListener("message", ({ data: l }) => {
|
|
22282
|
-
if (l.status === "success")
|
|
22286
|
+
if (l.status === "success")
|
|
22283
22287
|
if (l.bitmap) {
|
|
22284
22288
|
const c = document.createElement("canvas"), u = c.getContext("bitmaprenderer");
|
|
22285
22289
|
c.width = l.width, c.height = l.height, u?.transferFromImageBitmap(l.bitmap), h({ pages: l.pages, canvas: c });
|
|
22286
22290
|
} else
|
|
22287
22291
|
h({ pages: l.pages, canvas: null });
|
|
22288
|
-
r.terminate();
|
|
22289
|
-
}
|
|
22290
22292
|
});
|
|
22291
22293
|
});
|
|
22292
22294
|
} else {
|
|
@@ -22301,11 +22303,11 @@ async function qg({ page: a, PDFBase64: t, scale: e, password: s }, i) {
|
|
|
22301
22303
|
}
|
|
22302
22304
|
}
|
|
22303
22305
|
const jt = /* @__PURE__ */ new Map();
|
|
22304
|
-
function
|
|
22306
|
+
function Jg(a) {
|
|
22305
22307
|
const t = new Pr(a);
|
|
22306
22308
|
return jt.set(a, t), t;
|
|
22307
22309
|
}
|
|
22308
|
-
function
|
|
22310
|
+
function Zg(a, t) {
|
|
22309
22311
|
const e = Date.now();
|
|
22310
22312
|
return {
|
|
22311
22313
|
PDFId: `${a.name}-${e}`,
|
|
@@ -22314,19 +22316,19 @@ function Jg(a, t) {
|
|
|
22314
22316
|
PDFBase64: t
|
|
22315
22317
|
};
|
|
22316
22318
|
}
|
|
22317
|
-
async function
|
|
22319
|
+
async function Qg({ src: a }, t, e) {
|
|
22318
22320
|
if (!a || !e) return null;
|
|
22319
22321
|
const { objects: s, options: i } = await kd(a), n = s.filter((o) => o !== null), r = Xu.groupSVGElements(n, i);
|
|
22320
22322
|
return n.forEach((o) => {
|
|
22321
22323
|
o.stroke = e;
|
|
22322
22324
|
}), r.hoverCursor = "pointer", r.stroke = `${e}-${t}`, r;
|
|
22323
22325
|
}
|
|
22324
|
-
function
|
|
22326
|
+
function tp(a, t) {
|
|
22325
22327
|
if (!jt.get(a)) return;
|
|
22326
|
-
const s = 1 / 3, i =
|
|
22328
|
+
const s = 1 / 3, i = ap(t, s);
|
|
22327
22329
|
ql(a, i, s);
|
|
22328
22330
|
}
|
|
22329
|
-
async function
|
|
22331
|
+
async function ep(a, t) {
|
|
22330
22332
|
const e = await Bd(a), s = Date.now(), n = {
|
|
22331
22333
|
PDFId: `${a.name}${s}`,
|
|
22332
22334
|
name: a.name.replace(/.png|.jpg|.jpeg/, ""),
|
|
@@ -22344,30 +22346,30 @@ function ql(a, t, e) {
|
|
|
22344
22346
|
const s = jt.get(a);
|
|
22345
22347
|
s && (s.setWidth(t.width * e), s.setHeight(t.height * e), s.backgroundImage = t, s.renderAll());
|
|
22346
22348
|
}
|
|
22347
|
-
function
|
|
22349
|
+
function sp(a, t) {
|
|
22348
22350
|
if (!t) return;
|
|
22349
22351
|
const { oCoords: e } = a;
|
|
22350
22352
|
if (!e) return;
|
|
22351
22353
|
const { x: s, y: i } = e.tl.touchCorner.tl, { height: n, width: r, scaleY: o, scaleX: h } = t;
|
|
22352
22354
|
t.top = i - n * o / 2, t.left = s - r * h / 2, t.setCoords();
|
|
22353
22355
|
}
|
|
22354
|
-
function
|
|
22355
|
-
!e || !a || (e.scale(1 / t),
|
|
22356
|
+
function ip(a, t, e) {
|
|
22357
|
+
!e || !a || (e.scale(1 / t), sp(a, e));
|
|
22356
22358
|
}
|
|
22357
|
-
function
|
|
22359
|
+
function np(a, t) {
|
|
22358
22360
|
if (!a) return;
|
|
22359
22361
|
const e = a._cornerSize || 6;
|
|
22360
22362
|
a.borderScaleFactor = 1 / t, a.cornerSize = e * (1 / t), a.touchCornerSize = e * 4 * (1 / t), a.setCoords();
|
|
22361
22363
|
}
|
|
22362
|
-
function
|
|
22364
|
+
function rp(a) {
|
|
22363
22365
|
const t = jt.get(a);
|
|
22364
22366
|
t && (t.discardActiveObject(), t.renderAll());
|
|
22365
22367
|
}
|
|
22366
|
-
function
|
|
22368
|
+
function op(a) {
|
|
22367
22369
|
const t = jt.get(a);
|
|
22368
22370
|
t && (t.clear(), jt.delete(a));
|
|
22369
22371
|
}
|
|
22370
|
-
function
|
|
22372
|
+
function ap(a, t) {
|
|
22371
22373
|
return new Pt(a, { scaleX: t, scaleY: t });
|
|
22372
22374
|
}
|
|
22373
22375
|
function zr(a, t) {
|
|
@@ -22375,27 +22377,27 @@ function zr(a, t) {
|
|
|
22375
22377
|
const { left: e, top: s, scaleX: i, scaleY: n, width: r, height: o } = a, h = t.x * r * i, l = t.y * o * n;
|
|
22376
22378
|
a.set({ left: e - h, top: s - l });
|
|
22377
22379
|
}
|
|
22378
|
-
function
|
|
22380
|
+
function hp(a, t, e) {
|
|
22379
22381
|
const s = a.type;
|
|
22380
22382
|
return {
|
|
22381
|
-
"application/pdf":
|
|
22383
|
+
"application/pdf": lp,
|
|
22382
22384
|
"image/png": Za,
|
|
22383
22385
|
"image/jpeg": Za
|
|
22384
22386
|
}[s]?.(a, t, e) ?? Promise.reject(new Error(`Unsupported ${s} file type.`));
|
|
22385
22387
|
}
|
|
22386
|
-
async function
|
|
22387
|
-
const s = await
|
|
22388
|
+
async function lp(a, t, e) {
|
|
22389
|
+
const s = await qg(a);
|
|
22388
22390
|
if (!s) return;
|
|
22389
|
-
const i =
|
|
22391
|
+
const i = Zg(a, s), n = await Kl({ page: 1, PDFBase64: s, scale: 0.8, password: t }, e);
|
|
22390
22392
|
return { ...i, pages: n };
|
|
22391
22393
|
}
|
|
22392
22394
|
function Kl(a, t) {
|
|
22393
|
-
return
|
|
22395
|
+
return Kg(a, t).then(({ canvas: e, pages: s }) => (e && t && tp(t, e), s));
|
|
22394
22396
|
}
|
|
22395
22397
|
async function Za(a, t, e) {
|
|
22396
|
-
return await
|
|
22398
|
+
return await ep(a, e);
|
|
22397
22399
|
}
|
|
22398
|
-
function
|
|
22400
|
+
function cp(a, t) {
|
|
22399
22401
|
const e = jt.get(a);
|
|
22400
22402
|
if (!e) return;
|
|
22401
22403
|
const s = e.getActiveObject();
|
|
@@ -22403,7 +22405,7 @@ function lp(a, t) {
|
|
|
22403
22405
|
i.set(t);
|
|
22404
22406
|
}) : s.set(t), e.renderAll());
|
|
22405
22407
|
}
|
|
22406
|
-
async function
|
|
22408
|
+
async function up(a, t) {
|
|
22407
22409
|
const e = jt.get(a);
|
|
22408
22410
|
if (!e) return;
|
|
22409
22411
|
const s = e?.getActiveObject();
|
|
@@ -22413,7 +22415,7 @@ async function cp(a, t) {
|
|
|
22413
22415
|
e.add(n), t(e, n);
|
|
22414
22416
|
}) : (e.add(i), t(e, i)), zr(i, { x: -0.1, y: -0.1 }), e.setActiveObject(i);
|
|
22415
22417
|
}
|
|
22416
|
-
function
|
|
22418
|
+
function dp(a) {
|
|
22417
22419
|
const t = jt.get(a);
|
|
22418
22420
|
if (!t) return;
|
|
22419
22421
|
const e = t.getActiveObject();
|
|
@@ -22421,7 +22423,7 @@ function up(a) {
|
|
|
22421
22423
|
t.remove(s);
|
|
22422
22424
|
}), t.discardActiveObject()) : t.remove(e));
|
|
22423
22425
|
}
|
|
22424
|
-
function
|
|
22426
|
+
function fp(a) {
|
|
22425
22427
|
const {
|
|
22426
22428
|
id: t = "",
|
|
22427
22429
|
selectionOptions: e,
|
|
@@ -22433,7 +22435,7 @@ function dp(a) {
|
|
|
22433
22435
|
} = a || {}, h = ws(null), l = ws(null), c = ws(1), u = ws({ ...hc });
|
|
22434
22436
|
function d() {
|
|
22435
22437
|
if (!t || jt.has(t)) return;
|
|
22436
|
-
const O =
|
|
22438
|
+
const O = Jg(t);
|
|
22437
22439
|
return O.on("selection:created", (D) => {
|
|
22438
22440
|
if (r?.(D), D.selected.length <= 1) return;
|
|
22439
22441
|
const z = O.getActiveObject();
|
|
@@ -22443,7 +22445,7 @@ function dp(a) {
|
|
|
22443
22445
|
}), s && O.on("mouse:down", s), i && O.on("mouse:move", i), n && O.on("mouse:up", n), O;
|
|
22444
22446
|
}
|
|
22445
22447
|
function f(O, D) {
|
|
22446
|
-
return
|
|
22448
|
+
return hp(O, D, t);
|
|
22447
22449
|
}
|
|
22448
22450
|
function g(O) {
|
|
22449
22451
|
return Kl(O, t);
|
|
@@ -22476,7 +22478,7 @@ function dp(a) {
|
|
|
22476
22478
|
uuid: M = Date.now()
|
|
22477
22479
|
}) {
|
|
22478
22480
|
if (O.getActiveObjects().length > 1 || h.current?.stroke === `${z}-${M}`) return;
|
|
22479
|
-
const W = await
|
|
22481
|
+
const W = await Qg(u.current, M, z);
|
|
22480
22482
|
T(O), h.current = W, l.current = D, _(O, D, M), S(c.current, !0), W && O.add(W);
|
|
22481
22483
|
}
|
|
22482
22484
|
function _(O, D, z) {
|
|
@@ -22495,7 +22497,7 @@ function dp(a) {
|
|
|
22495
22497
|
}
|
|
22496
22498
|
function S(O, D = !1) {
|
|
22497
22499
|
const z = jt.get(t);
|
|
22498
|
-
c.current = O, z && (
|
|
22500
|
+
c.current = O, z && (np(l.current, O), ip(l.current, O, h.current), !D && z.renderAll());
|
|
22499
22501
|
}
|
|
22500
22502
|
function A(O) {
|
|
22501
22503
|
if (!O) return;
|
|
@@ -22507,19 +22509,19 @@ function dp(a) {
|
|
|
22507
22509
|
l.current = null, h.current && (O.remove(h.current), h.current = null);
|
|
22508
22510
|
}
|
|
22509
22511
|
function k() {
|
|
22510
|
-
|
|
22512
|
+
rp(t);
|
|
22511
22513
|
}
|
|
22512
22514
|
function P() {
|
|
22513
|
-
|
|
22515
|
+
op(t);
|
|
22514
22516
|
}
|
|
22515
22517
|
function j(O) {
|
|
22516
|
-
|
|
22518
|
+
cp(t, O);
|
|
22517
22519
|
}
|
|
22518
22520
|
function F() {
|
|
22519
|
-
return
|
|
22521
|
+
return up(t, v);
|
|
22520
22522
|
}
|
|
22521
22523
|
function I() {
|
|
22522
|
-
|
|
22524
|
+
dp(t);
|
|
22523
22525
|
}
|
|
22524
22526
|
return {
|
|
22525
22527
|
createCanvas: d,
|
|
@@ -22537,14 +22539,14 @@ function dp(a) {
|
|
|
22537
22539
|
deleteActiveFabric: I
|
|
22538
22540
|
};
|
|
22539
22541
|
}
|
|
22540
|
-
function
|
|
22541
|
-
const t = ws(0), e =
|
|
22542
|
+
function gp(a) {
|
|
22543
|
+
const t = ws(0), e = Yg(() => {
|
|
22542
22544
|
t.current !== window.innerWidth && (t.current = window.innerWidth, a());
|
|
22543
22545
|
});
|
|
22544
22546
|
Js(() => (window.addEventListener("resize", e), () => window.removeEventListener("resize", e)), []);
|
|
22545
22547
|
}
|
|
22546
|
-
const
|
|
22547
|
-
function
|
|
22548
|
+
const vp = Ql(pp);
|
|
22549
|
+
function pp({
|
|
22548
22550
|
file: a,
|
|
22549
22551
|
page: t = 1,
|
|
22550
22552
|
canvasId: e = "PDF-canvas",
|
|
@@ -22580,7 +22582,7 @@ function gp({
|
|
|
22580
22582
|
setCloseSvgOptions: ot,
|
|
22581
22583
|
copyActiveFabric: lt,
|
|
22582
22584
|
deleteActiveFabric: E
|
|
22583
|
-
} =
|
|
22585
|
+
} = fp({
|
|
22584
22586
|
id: T,
|
|
22585
22587
|
selectionOptions: P,
|
|
22586
22588
|
pointerDown: b,
|
|
@@ -22589,7 +22591,7 @@ function gp({
|
|
|
22589
22591
|
selectionCreated: y,
|
|
22590
22592
|
selectionCleared: _
|
|
22591
22593
|
});
|
|
22592
|
-
|
|
22594
|
+
gp(st);
|
|
22593
22595
|
async function H() {
|
|
22594
22596
|
globalThis.requestAnimationFrame(async () => {
|
|
22595
22597
|
if (j(), a.PDFBase64.startsWith("data:image") || a.canvas) {
|
|
@@ -22654,7 +22656,7 @@ function gp({
|
|
|
22654
22656
|
);
|
|
22655
22657
|
}
|
|
22656
22658
|
export {
|
|
22657
|
-
|
|
22658
|
-
|
|
22659
|
-
|
|
22659
|
+
vp as default,
|
|
22660
|
+
hp as loadFile,
|
|
22661
|
+
fp as useFabric
|
|
22660
22662
|
};
|