@embedpdf/plugin-capture 1.0.11 → 1.0.13
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.cjs +2 -129
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -46
- package/dist/index.js +21 -19
- package/dist/index.js.map +1 -1
- package/dist/lib/capture-plugin.d.ts +16 -0
- package/dist/lib/index.d.ts +7 -0
- package/dist/lib/manifest.d.ts +4 -0
- package/dist/lib/types.d.ts +23 -0
- package/dist/preact/adapter.d.ts +1 -0
- package/dist/preact/core.d.ts +1 -0
- package/dist/preact/index.cjs +2 -121
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.d.ts +1 -37
- package/dist/preact/index.js +12 -12
- package/dist/preact/index.js.map +1 -1
- package/dist/preact/interaction-manager.d.ts +1 -0
- package/dist/react/adapter.d.ts +1 -0
- package/dist/react/core.d.ts +1 -0
- package/dist/react/index.cjs +2 -121
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.ts +1 -37
- package/dist/react/index.js +12 -12
- package/dist/react/index.js.map +1 -1
- package/dist/react/interaction-manager.d.ts +1 -0
- package/dist/shared-preact/components/index.d.ts +1 -0
- package/dist/shared-preact/components/marquee-capture.d.ts +21 -0
- package/dist/shared-preact/hooks/index.d.ts +1 -0
- package/dist/shared-preact/hooks/use-capture.d.ts +11 -0
- package/dist/shared-preact/index.d.ts +2 -0
- package/dist/shared-react/components/index.d.ts +1 -0
- package/dist/shared-react/components/marquee-capture.d.ts +21 -0
- package/dist/shared-react/hooks/index.d.ts +1 -0
- package/dist/shared-react/hooks/use-capture.d.ts +11 -0
- package/dist/shared-react/index.d.ts +2 -0
- package/package.json +16 -14
- package/dist/index.d.cts +0 -46
- package/dist/preact/index.d.cts +0 -37
- package/dist/react/index.d.cts +0 -37
package/dist/index.cjs
CHANGED
|
@@ -1,129 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
CAPTURE_PLUGIN_ID: () => CAPTURE_PLUGIN_ID,
|
|
24
|
-
CapturePlugin: () => CapturePlugin,
|
|
25
|
-
CapturePluginPackage: () => CapturePluginPackage,
|
|
26
|
-
manifest: () => manifest
|
|
27
|
-
});
|
|
28
|
-
module.exports = __toCommonJS(index_exports);
|
|
29
|
-
|
|
30
|
-
// src/lib/manifest.ts
|
|
31
|
-
var CAPTURE_PLUGIN_ID = "capture";
|
|
32
|
-
var manifest = {
|
|
33
|
-
id: CAPTURE_PLUGIN_ID,
|
|
34
|
-
name: "Capture Plugin",
|
|
35
|
-
version: "1.0.0",
|
|
36
|
-
provides: ["capture"],
|
|
37
|
-
requires: ["render", "interaction-manager"],
|
|
38
|
-
optional: [],
|
|
39
|
-
defaultConfig: {
|
|
40
|
-
enabled: true,
|
|
41
|
-
scale: 1,
|
|
42
|
-
imageType: "image/png",
|
|
43
|
-
withAnnotations: false
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
// src/lib/capture-plugin.ts
|
|
48
|
-
var import_core = require("@embedpdf/core");
|
|
49
|
-
var import_models = require("@embedpdf/models");
|
|
50
|
-
var CapturePlugin = class extends import_core.BasePlugin {
|
|
51
|
-
constructor(id, registry, config) {
|
|
52
|
-
super(id, registry);
|
|
53
|
-
this.captureArea$ = (0, import_core.createEmitter)();
|
|
54
|
-
this.config = config;
|
|
55
|
-
this.renderCapability = this.registry.getPlugin("render").provides();
|
|
56
|
-
this.interactionManagerCapability = this.registry.getPlugin("interaction-manager").provides();
|
|
57
|
-
this.interactionManagerCapability.registerMode({
|
|
58
|
-
id: "marqueeCapture",
|
|
59
|
-
scope: "page",
|
|
60
|
-
exclusive: true,
|
|
61
|
-
cursor: "crosshair"
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
async initialize(_) {
|
|
65
|
-
}
|
|
66
|
-
buildCapability() {
|
|
67
|
-
return {
|
|
68
|
-
onCaptureArea: this.captureArea$.on,
|
|
69
|
-
captureArea: this.captureArea.bind(this),
|
|
70
|
-
enableMarqueeCapture: this.enableMarqueeCapture.bind(this),
|
|
71
|
-
disableMarqueeCapture: this.disableMarqueeCapture.bind(this),
|
|
72
|
-
toggleMarqueeCapture: this.toggleMarqueeCapture.bind(this),
|
|
73
|
-
isMarqueeCaptureActive: () => this.interactionManagerCapability?.getActiveMode() === "marqueeCapture"
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
captureArea(pageIndex, rect) {
|
|
77
|
-
this.disableMarqueeCapture();
|
|
78
|
-
const task = this.renderCapability.renderPageRect({
|
|
79
|
-
pageIndex,
|
|
80
|
-
rect,
|
|
81
|
-
imageType: this.config.imageType,
|
|
82
|
-
scaleFactor: this.config.scale,
|
|
83
|
-
options: {
|
|
84
|
-
withAnnotations: this.config.withAnnotations || false
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
task.wait((blob) => {
|
|
88
|
-
this.captureArea$.emit({
|
|
89
|
-
pageIndex,
|
|
90
|
-
rect,
|
|
91
|
-
blob,
|
|
92
|
-
imageType: this.config.imageType || "image/png",
|
|
93
|
-
scale: this.config.scale || 1,
|
|
94
|
-
withAnnotations: this.config.withAnnotations || false
|
|
95
|
-
});
|
|
96
|
-
}, import_models.ignore);
|
|
97
|
-
}
|
|
98
|
-
enableMarqueeCapture() {
|
|
99
|
-
this.interactionManagerCapability?.activate("marqueeCapture");
|
|
100
|
-
}
|
|
101
|
-
disableMarqueeCapture() {
|
|
102
|
-
this.interactionManagerCapability?.activate("default");
|
|
103
|
-
}
|
|
104
|
-
toggleMarqueeCapture() {
|
|
105
|
-
if (this.interactionManagerCapability?.getActiveMode() === "marqueeCapture") {
|
|
106
|
-
this.interactionManagerCapability?.activate("default");
|
|
107
|
-
} else {
|
|
108
|
-
this.interactionManagerCapability?.activate("marqueeCapture");
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
CapturePlugin.id = "capture";
|
|
113
|
-
|
|
114
|
-
// src/lib/index.ts
|
|
115
|
-
var CapturePluginPackage = {
|
|
116
|
-
manifest,
|
|
117
|
-
create: (registry, _engine, config) => new CapturePlugin(CAPTURE_PLUGIN_ID, registry, config),
|
|
118
|
-
reducer: () => {
|
|
119
|
-
},
|
|
120
|
-
initialState: {}
|
|
121
|
-
};
|
|
122
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
-
0 && (module.exports = {
|
|
124
|
-
CAPTURE_PLUGIN_ID,
|
|
125
|
-
CapturePlugin,
|
|
126
|
-
CapturePluginPackage,
|
|
127
|
-
manifest
|
|
128
|
-
});
|
|
129
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),a=require("@embedpdf/models"),t="capture",i={id:t,name:"Capture Plugin",version:"1.0.0",provides:["capture"],requires:["render","interaction-manager"],optional:[],defaultConfig:{enabled:!0,scale:1,imageType:"image/png",withAnnotations:!1}},r=class extends e.BasePlugin{constructor(a,t,i){super(a,t),this.captureArea$=e.createEmitter(),this.config=i,this.renderCapability=this.registry.getPlugin("render").provides(),this.interactionManagerCapability=this.registry.getPlugin("interaction-manager").provides(),this.interactionManagerCapability.registerMode({id:"marqueeCapture",scope:"page",exclusive:!0,cursor:"crosshair"})}async initialize(e){}buildCapability(){return{onCaptureArea:this.captureArea$.on,captureArea:this.captureArea.bind(this),enableMarqueeCapture:this.enableMarqueeCapture.bind(this),disableMarqueeCapture:this.disableMarqueeCapture.bind(this),toggleMarqueeCapture:this.toggleMarqueeCapture.bind(this),isMarqueeCaptureActive:()=>{var e;return"marqueeCapture"===(null==(e=this.interactionManagerCapability)?void 0:e.getActiveMode())}}}captureArea(e,t){this.disableMarqueeCapture();this.renderCapability.renderPageRect({pageIndex:e,rect:t,imageType:this.config.imageType,scaleFactor:this.config.scale,options:{withAnnotations:this.config.withAnnotations||!1}}).wait((a=>{this.captureArea$.emit({pageIndex:e,rect:t,blob:a,imageType:this.config.imageType||"image/png",scale:this.config.scale||1,withAnnotations:this.config.withAnnotations||!1})}),a.ignore)}enableMarqueeCapture(){var e;null==(e=this.interactionManagerCapability)||e.activate("marqueeCapture")}disableMarqueeCapture(){var e;null==(e=this.interactionManagerCapability)||e.activate("default")}toggleMarqueeCapture(){var e,a,t;"marqueeCapture"===(null==(e=this.interactionManagerCapability)?void 0:e.getActiveMode())?null==(a=this.interactionManagerCapability)||a.activate("default"):null==(t=this.interactionManagerCapability)||t.activate("marqueeCapture")}};r.id="capture";let n=r;const s={manifest:i,create:(e,a,i)=>new n(t,e,i),reducer:()=>{},initialState:{}};exports.CAPTURE_PLUGIN_ID=t,exports.CapturePlugin=n,exports.CapturePluginPackage=s,exports.manifest=i;
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/lib/manifest.ts","../src/lib/capture-plugin.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { CapturePluginConfig } from './types';\n\nexport const CAPTURE_PLUGIN_ID = 'capture';\n\nexport const manifest: PluginManifest<CapturePluginConfig> = {\n id: CAPTURE_PLUGIN_ID,\n name: 'Capture Plugin',\n version: '1.0.0',\n provides: ['capture'],\n requires: ['render', 'interaction-manager'],\n optional: [],\n defaultConfig: {\n enabled: true,\n scale: 1,\n imageType: 'image/png',\n withAnnotations: false,\n },\n};\n","import { BasePlugin, createEmitter, PluginRegistry } from '@embedpdf/core';\nimport {\n InteractionManagerCapability,\n InteractionManagerPlugin,\n} from '@embedpdf/plugin-interaction-manager';\nimport { RenderCapability, RenderPlugin } from '@embedpdf/plugin-render';\n\nimport { CaptureAreaEvent, CaptureCapability, CapturePluginConfig } from './types';\nimport { ignore, Rect } from '@embedpdf/models';\n\nexport class CapturePlugin extends BasePlugin<CapturePluginConfig, CaptureCapability> {\n static readonly id = 'capture' as const;\n\n private captureArea$ = createEmitter<CaptureAreaEvent>();\n\n private renderCapability: RenderCapability;\n private interactionManagerCapability: InteractionManagerCapability;\n private config: CapturePluginConfig;\n\n constructor(id: string, registry: PluginRegistry, config: CapturePluginConfig) {\n super(id, registry);\n\n this.config = config;\n\n this.renderCapability = this.registry.getPlugin<RenderPlugin>('render')!.provides();\n this.interactionManagerCapability = this.registry\n .getPlugin<InteractionManagerPlugin>('interaction-manager')!\n .provides();\n\n this.interactionManagerCapability.registerMode({\n id: 'marqueeCapture',\n scope: 'page',\n exclusive: true,\n cursor: 'crosshair',\n });\n }\n\n async initialize(_: CapturePluginConfig): Promise<void> {}\n\n protected buildCapability(): CaptureCapability {\n return {\n onCaptureArea: this.captureArea$.on,\n captureArea: this.captureArea.bind(this),\n enableMarqueeCapture: this.enableMarqueeCapture.bind(this),\n disableMarqueeCapture: this.disableMarqueeCapture.bind(this),\n toggleMarqueeCapture: this.toggleMarqueeCapture.bind(this),\n isMarqueeCaptureActive: () =>\n this.interactionManagerCapability?.getActiveMode() === 'marqueeCapture',\n };\n }\n\n private captureArea(pageIndex: number, rect: Rect) {\n this.disableMarqueeCapture();\n\n const task = this.renderCapability.renderPageRect({\n pageIndex,\n rect,\n imageType: this.config.imageType,\n scaleFactor: this.config.scale,\n options: {\n withAnnotations: this.config.withAnnotations || false,\n },\n });\n\n task.wait((blob) => {\n this.captureArea$.emit({\n pageIndex,\n rect,\n blob,\n imageType: this.config.imageType || 'image/png',\n scale: this.config.scale || 1,\n withAnnotations: this.config.withAnnotations || false,\n });\n }, ignore);\n }\n\n private enableMarqueeCapture() {\n this.interactionManagerCapability?.activate('marqueeCapture');\n }\n\n private disableMarqueeCapture() {\n this.interactionManagerCapability?.activate('default');\n }\n\n private toggleMarqueeCapture() {\n if (this.interactionManagerCapability?.getActiveMode() === 'marqueeCapture') {\n this.interactionManagerCapability?.activate('default');\n } else {\n this.interactionManagerCapability?.activate('marqueeCapture');\n }\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, CAPTURE_PLUGIN_ID } from './manifest';\nimport { CapturePluginConfig } from './types';\nimport { CapturePlugin } from './capture-plugin';\n\nexport const CapturePluginPackage: PluginPackage<CapturePlugin, CapturePluginConfig> = {\n manifest,\n create: (registry, _engine, config) => new CapturePlugin(CAPTURE_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './capture-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["CAPTURE_PLUGIN_ID","manifest","id","name","version","provides","requires","optional","defaultConfig","enabled","scale","imageType","withAnnotations","_CapturePlugin","BasePlugin","constructor","registry","config","super","this","captureArea$","createEmitter","renderCapability","getPlugin","interactionManagerCapability","registerMode","scope","exclusive","cursor","initialize","_","buildCapability","onCaptureArea","on","captureArea","bind","enableMarqueeCapture","disableMarqueeCapture","toggleMarqueeCapture","isMarqueeCaptureActive","_a","getActiveMode","pageIndex","rect","renderPageRect","scaleFactor","options","wait","blob","emit","ignore","activate","_b","_c","CapturePlugin","CapturePluginPackage","create","_engine","reducer","initialState"],"mappings":"gJAGaA,EAAoB,UAEpBC,EAAgD,CAC3DC,GAAIF,EACJG,KAAM,iBACNC,QAAS,QACTC,SAAU,CAAC,WACXC,SAAU,CAAC,SAAU,uBACrBC,SAAU,GACVC,cAAe,CACbC,SAAS,EACTC,MAAO,EACPC,UAAW,YACXC,iBAAiB,ICNRC,EAAN,cAA4BC,EAAAA,WASjC,WAAAC,CAAYb,EAAYc,EAA0BC,GAChDC,MAAMhB,EAAIc,GAPJG,KAAAC,aAAeC,kBASrBF,KAAKF,OAASA,EAEdE,KAAKG,iBAAmBH,KAAKH,SAASO,UAAwB,UAAWlB,WACzEc,KAAKK,6BAA+BL,KAAKH,SACtCO,UAAoC,uBACpClB,WAEHc,KAAKK,6BAA6BC,aAAa,CAC7CvB,GAAI,iBACJwB,MAAO,OACPC,WAAW,EACXC,OAAQ,aACT,CAGH,gBAAMC,CAAWC,GAAuC,CAE9C,eAAAC,GACD,MAAA,CACLC,cAAeb,KAAKC,aAAaa,GACjCC,YAAaf,KAAKe,YAAYC,KAAKhB,MACnCiB,qBAAsBjB,KAAKiB,qBAAqBD,KAAKhB,MACrDkB,sBAAuBlB,KAAKkB,sBAAsBF,KAAKhB,MACvDmB,qBAAsBnB,KAAKmB,qBAAqBH,KAAKhB,MACrDoB,uBAAwB,WACjB,MAAkD,oBAAvD,OAAKC,EAAArB,KAAAK,uCAA8BiB,gBAAoB,EAC3D,CAGM,WAAAP,CAAYQ,EAAmBC,GACrCxB,KAAKkB,wBAEQlB,KAAKG,iBAAiBsB,eAAe,CAChDF,YACAC,OACAhC,UAAWQ,KAAKF,OAAON,UACvBkC,YAAa1B,KAAKF,OAAOP,MACzBoC,QAAS,CACPlC,gBAAiBO,KAAKF,OAAOL,kBAAmB,KAI/CmC,MAAMC,IACT7B,KAAKC,aAAa6B,KAAK,CACrBP,YACAC,OACAK,OACArC,UAAWQ,KAAKF,OAAON,WAAa,YACpCD,MAAOS,KAAKF,OAAOP,OAAS,EAC5BE,gBAAiBO,KAAKF,OAAOL,kBAAmB,GACjD,GACAsC,SAAM,CAGH,oBAAAd,SACD,OAAAI,EAAArB,KAAAK,iCAA8B2B,SAAS,iBAAgB,CAGtD,qBAAAd,SACD,OAAAG,EAAArB,KAAAK,iCAA8B2B,SAAS,UAAS,CAG/C,oBAAAb,aACqD,oBAAvD,OAAAE,EAAKrB,KAAAK,mCAA8B,EAAAgB,EAAAC,iBAChC,OAAAW,EAAAjC,KAAAK,iCAA8B2B,SAAS,WAEvC,OAAAE,EAAAlC,KAAAK,iCAA8B2B,SAAS,iBAC9C,GA9EFtC,EAAgBX,GAAK,UADhB,IAAMoD,EAANzC,ECLA,MAAM0C,EAA0E,CACrFtD,WACAuD,OAAQ,CAACxC,EAAUyC,EAASxC,IAAW,IAAIqC,EAActD,EAAmBgB,EAAUC,GACtFyC,QAAS,OACTC,aAAc,CAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,46 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { ImageConversionTypes, Rect } from '@embedpdf/models';
|
|
3
|
-
|
|
4
|
-
interface CapturePluginConfig extends BasePluginConfig {
|
|
5
|
-
scale?: number;
|
|
6
|
-
imageType?: ImageConversionTypes;
|
|
7
|
-
withAnnotations?: boolean;
|
|
8
|
-
}
|
|
9
|
-
interface CaptureAreaEvent {
|
|
10
|
-
pageIndex: number;
|
|
11
|
-
rect: Rect;
|
|
12
|
-
blob: Blob;
|
|
13
|
-
imageType: ImageConversionTypes;
|
|
14
|
-
scale: number;
|
|
15
|
-
withAnnotations: boolean;
|
|
16
|
-
}
|
|
17
|
-
interface CaptureCapability {
|
|
18
|
-
onCaptureArea: EventHook<CaptureAreaEvent>;
|
|
19
|
-
captureArea(pageIndex: number, rect: Rect): void;
|
|
20
|
-
enableMarqueeCapture: () => void;
|
|
21
|
-
disableMarqueeCapture: () => void;
|
|
22
|
-
toggleMarqueeCapture: () => void;
|
|
23
|
-
isMarqueeCaptureActive: () => boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
declare class CapturePlugin extends BasePlugin<CapturePluginConfig, CaptureCapability> {
|
|
27
|
-
static readonly id: "capture";
|
|
28
|
-
private captureArea$;
|
|
29
|
-
private renderCapability;
|
|
30
|
-
private interactionManagerCapability;
|
|
31
|
-
private config;
|
|
32
|
-
constructor(id: string, registry: PluginRegistry, config: CapturePluginConfig);
|
|
33
|
-
initialize(_: CapturePluginConfig): Promise<void>;
|
|
34
|
-
protected buildCapability(): CaptureCapability;
|
|
35
|
-
private captureArea;
|
|
36
|
-
private enableMarqueeCapture;
|
|
37
|
-
private disableMarqueeCapture;
|
|
38
|
-
private toggleMarqueeCapture;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
declare const CAPTURE_PLUGIN_ID = "capture";
|
|
42
|
-
declare const manifest: PluginManifest<CapturePluginConfig>;
|
|
43
|
-
|
|
44
|
-
declare const CapturePluginPackage: PluginPackage<CapturePlugin, CapturePluginConfig>;
|
|
45
|
-
|
|
46
|
-
export { CAPTURE_PLUGIN_ID, type CaptureAreaEvent, type CaptureCapability, CapturePlugin, type CapturePluginConfig, CapturePluginPackage, manifest };
|
|
1
|
+
export * from './lib';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { BasePlugin, createEmitter } from "@embedpdf/core";
|
|
2
|
+
import { ignore } from "@embedpdf/models";
|
|
3
|
+
const CAPTURE_PLUGIN_ID = "capture";
|
|
4
|
+
const manifest = {
|
|
4
5
|
id: CAPTURE_PLUGIN_ID,
|
|
5
6
|
name: "Capture Plugin",
|
|
6
7
|
version: "1.0.0",
|
|
@@ -14,11 +15,7 @@ var manifest = {
|
|
|
14
15
|
withAnnotations: false
|
|
15
16
|
}
|
|
16
17
|
};
|
|
17
|
-
|
|
18
|
-
// src/lib/capture-plugin.ts
|
|
19
|
-
import { BasePlugin, createEmitter } from "@embedpdf/core";
|
|
20
|
-
import { ignore } from "@embedpdf/models";
|
|
21
|
-
var CapturePlugin = class extends BasePlugin {
|
|
18
|
+
const _CapturePlugin = class _CapturePlugin extends BasePlugin {
|
|
22
19
|
constructor(id, registry, config) {
|
|
23
20
|
super(id, registry);
|
|
24
21
|
this.captureArea$ = createEmitter();
|
|
@@ -41,7 +38,10 @@ var CapturePlugin = class extends BasePlugin {
|
|
|
41
38
|
enableMarqueeCapture: this.enableMarqueeCapture.bind(this),
|
|
42
39
|
disableMarqueeCapture: this.disableMarqueeCapture.bind(this),
|
|
43
40
|
toggleMarqueeCapture: this.toggleMarqueeCapture.bind(this),
|
|
44
|
-
isMarqueeCaptureActive: () =>
|
|
41
|
+
isMarqueeCaptureActive: () => {
|
|
42
|
+
var _a;
|
|
43
|
+
return ((_a = this.interactionManagerCapability) == null ? void 0 : _a.getActiveMode()) === "marqueeCapture";
|
|
44
|
+
}
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
captureArea(pageIndex, rect) {
|
|
@@ -67,23 +67,25 @@ var CapturePlugin = class extends BasePlugin {
|
|
|
67
67
|
}, ignore);
|
|
68
68
|
}
|
|
69
69
|
enableMarqueeCapture() {
|
|
70
|
-
|
|
70
|
+
var _a;
|
|
71
|
+
(_a = this.interactionManagerCapability) == null ? void 0 : _a.activate("marqueeCapture");
|
|
71
72
|
}
|
|
72
73
|
disableMarqueeCapture() {
|
|
73
|
-
|
|
74
|
+
var _a;
|
|
75
|
+
(_a = this.interactionManagerCapability) == null ? void 0 : _a.activate("default");
|
|
74
76
|
}
|
|
75
77
|
toggleMarqueeCapture() {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
var _a, _b, _c;
|
|
79
|
+
if (((_a = this.interactionManagerCapability) == null ? void 0 : _a.getActiveMode()) === "marqueeCapture") {
|
|
80
|
+
(_b = this.interactionManagerCapability) == null ? void 0 : _b.activate("default");
|
|
78
81
|
} else {
|
|
79
|
-
this.interactionManagerCapability
|
|
82
|
+
(_c = this.interactionManagerCapability) == null ? void 0 : _c.activate("marqueeCapture");
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
var CapturePluginPackage = {
|
|
86
|
+
_CapturePlugin.id = "capture";
|
|
87
|
+
let CapturePlugin = _CapturePlugin;
|
|
88
|
+
const CapturePluginPackage = {
|
|
87
89
|
manifest,
|
|
88
90
|
create: (registry, _engine, config) => new CapturePlugin(CAPTURE_PLUGIN_ID, registry, config),
|
|
89
91
|
reducer: () => {
|
|
@@ -96,4 +98,4 @@ export {
|
|
|
96
98
|
CapturePluginPackage,
|
|
97
99
|
manifest
|
|
98
100
|
};
|
|
99
|
-
//# sourceMappingURL=index.js.map
|
|
101
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/lib/manifest.ts","../src/lib/capture-plugin.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { CapturePluginConfig } from './types';\n\nexport const CAPTURE_PLUGIN_ID = 'capture';\n\nexport const manifest: PluginManifest<CapturePluginConfig> = {\n id: CAPTURE_PLUGIN_ID,\n name: 'Capture Plugin',\n version: '1.0.0',\n provides: ['capture'],\n requires: ['render', 'interaction-manager'],\n optional: [],\n defaultConfig: {\n enabled: true,\n scale: 1,\n imageType: 'image/png',\n withAnnotations: false,\n },\n};\n","import { BasePlugin, createEmitter, PluginRegistry } from '@embedpdf/core';\nimport {\n InteractionManagerCapability,\n InteractionManagerPlugin,\n} from '@embedpdf/plugin-interaction-manager';\nimport { RenderCapability, RenderPlugin } from '@embedpdf/plugin-render';\n\nimport { CaptureAreaEvent, CaptureCapability, CapturePluginConfig } from './types';\nimport { ignore, Rect } from '@embedpdf/models';\n\nexport class CapturePlugin extends BasePlugin<CapturePluginConfig, CaptureCapability> {\n static readonly id = 'capture' as const;\n\n private captureArea$ = createEmitter<CaptureAreaEvent>();\n\n private renderCapability: RenderCapability;\n private interactionManagerCapability: InteractionManagerCapability;\n private config: CapturePluginConfig;\n\n constructor(id: string, registry: PluginRegistry, config: CapturePluginConfig) {\n super(id, registry);\n\n this.config = config;\n\n this.renderCapability = this.registry.getPlugin<RenderPlugin>('render')!.provides();\n this.interactionManagerCapability = this.registry\n .getPlugin<InteractionManagerPlugin>('interaction-manager')!\n .provides();\n\n this.interactionManagerCapability.registerMode({\n id: 'marqueeCapture',\n scope: 'page',\n exclusive: true,\n cursor: 'crosshair',\n });\n }\n\n async initialize(_: CapturePluginConfig): Promise<void> {}\n\n protected buildCapability(): CaptureCapability {\n return {\n onCaptureArea: this.captureArea$.on,\n captureArea: this.captureArea.bind(this),\n enableMarqueeCapture: this.enableMarqueeCapture.bind(this),\n disableMarqueeCapture: this.disableMarqueeCapture.bind(this),\n toggleMarqueeCapture: this.toggleMarqueeCapture.bind(this),\n isMarqueeCaptureActive: () =>\n this.interactionManagerCapability?.getActiveMode() === 'marqueeCapture',\n };\n }\n\n private captureArea(pageIndex: number, rect: Rect) {\n this.disableMarqueeCapture();\n\n const task = this.renderCapability.renderPageRect({\n pageIndex,\n rect,\n imageType: this.config.imageType,\n scaleFactor: this.config.scale,\n options: {\n withAnnotations: this.config.withAnnotations || false,\n },\n });\n\n task.wait((blob) => {\n this.captureArea$.emit({\n pageIndex,\n rect,\n blob,\n imageType: this.config.imageType || 'image/png',\n scale: this.config.scale || 1,\n withAnnotations: this.config.withAnnotations || false,\n });\n }, ignore);\n }\n\n private enableMarqueeCapture() {\n this.interactionManagerCapability?.activate('marqueeCapture');\n }\n\n private disableMarqueeCapture() {\n this.interactionManagerCapability?.activate('default');\n }\n\n private toggleMarqueeCapture() {\n if (this.interactionManagerCapability?.getActiveMode() === 'marqueeCapture') {\n this.interactionManagerCapability?.activate('default');\n } else {\n this.interactionManagerCapability?.activate('marqueeCapture');\n }\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, CAPTURE_PLUGIN_ID } from './manifest';\nimport { CapturePluginConfig } from './types';\nimport { CapturePlugin } from './capture-plugin';\n\nexport const CapturePluginPackage: PluginPackage<CapturePlugin, CapturePluginConfig> = {\n manifest,\n create: (registry, _engine, config) => new CapturePlugin(CAPTURE_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './capture-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/lib/manifest.ts","../src/lib/capture-plugin.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { CapturePluginConfig } from './types';\n\nexport const CAPTURE_PLUGIN_ID = 'capture';\n\nexport const manifest: PluginManifest<CapturePluginConfig> = {\n id: CAPTURE_PLUGIN_ID,\n name: 'Capture Plugin',\n version: '1.0.0',\n provides: ['capture'],\n requires: ['render', 'interaction-manager'],\n optional: [],\n defaultConfig: {\n enabled: true,\n scale: 1,\n imageType: 'image/png',\n withAnnotations: false,\n },\n};\n","import { BasePlugin, createEmitter, PluginRegistry } from '@embedpdf/core';\nimport {\n InteractionManagerCapability,\n InteractionManagerPlugin,\n} from '@embedpdf/plugin-interaction-manager';\nimport { RenderCapability, RenderPlugin } from '@embedpdf/plugin-render';\n\nimport { CaptureAreaEvent, CaptureCapability, CapturePluginConfig } from './types';\nimport { ignore, Rect } from '@embedpdf/models';\n\nexport class CapturePlugin extends BasePlugin<CapturePluginConfig, CaptureCapability> {\n static readonly id = 'capture' as const;\n\n private captureArea$ = createEmitter<CaptureAreaEvent>();\n\n private renderCapability: RenderCapability;\n private interactionManagerCapability: InteractionManagerCapability;\n private config: CapturePluginConfig;\n\n constructor(id: string, registry: PluginRegistry, config: CapturePluginConfig) {\n super(id, registry);\n\n this.config = config;\n\n this.renderCapability = this.registry.getPlugin<RenderPlugin>('render')!.provides();\n this.interactionManagerCapability = this.registry\n .getPlugin<InteractionManagerPlugin>('interaction-manager')!\n .provides();\n\n this.interactionManagerCapability.registerMode({\n id: 'marqueeCapture',\n scope: 'page',\n exclusive: true,\n cursor: 'crosshair',\n });\n }\n\n async initialize(_: CapturePluginConfig): Promise<void> {}\n\n protected buildCapability(): CaptureCapability {\n return {\n onCaptureArea: this.captureArea$.on,\n captureArea: this.captureArea.bind(this),\n enableMarqueeCapture: this.enableMarqueeCapture.bind(this),\n disableMarqueeCapture: this.disableMarqueeCapture.bind(this),\n toggleMarqueeCapture: this.toggleMarqueeCapture.bind(this),\n isMarqueeCaptureActive: () =>\n this.interactionManagerCapability?.getActiveMode() === 'marqueeCapture',\n };\n }\n\n private captureArea(pageIndex: number, rect: Rect) {\n this.disableMarqueeCapture();\n\n const task = this.renderCapability.renderPageRect({\n pageIndex,\n rect,\n imageType: this.config.imageType,\n scaleFactor: this.config.scale,\n options: {\n withAnnotations: this.config.withAnnotations || false,\n },\n });\n\n task.wait((blob) => {\n this.captureArea$.emit({\n pageIndex,\n rect,\n blob,\n imageType: this.config.imageType || 'image/png',\n scale: this.config.scale || 1,\n withAnnotations: this.config.withAnnotations || false,\n });\n }, ignore);\n }\n\n private enableMarqueeCapture() {\n this.interactionManagerCapability?.activate('marqueeCapture');\n }\n\n private disableMarqueeCapture() {\n this.interactionManagerCapability?.activate('default');\n }\n\n private toggleMarqueeCapture() {\n if (this.interactionManagerCapability?.getActiveMode() === 'marqueeCapture') {\n this.interactionManagerCapability?.activate('default');\n } else {\n this.interactionManagerCapability?.activate('marqueeCapture');\n }\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, CAPTURE_PLUGIN_ID } from './manifest';\nimport { CapturePluginConfig } from './types';\nimport { CapturePlugin } from './capture-plugin';\n\nexport const CapturePluginPackage: PluginPackage<CapturePlugin, CapturePluginConfig> = {\n manifest,\n create: (registry, _engine, config) => new CapturePlugin(CAPTURE_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './capture-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":[],"mappings":";;AAGO,MAAM,oBAAoB;AAE1B,MAAM,WAAgD;AAAA,EAC3D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,SAAS;AAAA,EACpB,UAAU,CAAC,UAAU,qBAAqB;AAAA,EAC1C,UAAU,CAAC;AAAA,EACX,eAAe;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,WAAW;AAAA,IACX,iBAAiB;AAAA,EAAA;AAErB;ACRO,MAAM,iBAAN,MAAM,uBAAsB,WAAmD;AAAA,EASpF,YAAY,IAAY,UAA0B,QAA6B;AAC7E,UAAM,IAAI,QAAQ;AAPpB,SAAQ,eAAe,cAAgC;AASrD,SAAK,SAAS;AAEd,SAAK,mBAAmB,KAAK,SAAS,UAAwB,QAAQ,EAAG,SAAS;AAClF,SAAK,+BAA+B,KAAK,SACtC,UAAoC,qBAAqB,EACzD,SAAS;AAEZ,SAAK,6BAA6B,aAAa;AAAA,MAC7C,IAAI;AAAA,MACJ,OAAO;AAAA,MACP,WAAW;AAAA,MACX,QAAQ;AAAA,IAAA,CACT;AAAA,EAAA;AAAA,EAGH,MAAM,WAAW,GAAuC;AAAA,EAAA;AAAA,EAE9C,kBAAqC;AACtC,WAAA;AAAA,MACL,eAAe,KAAK,aAAa;AAAA,MACjC,aAAa,KAAK,YAAY,KAAK,IAAI;AAAA,MACvC,sBAAsB,KAAK,qBAAqB,KAAK,IAAI;AAAA,MACzD,uBAAuB,KAAK,sBAAsB,KAAK,IAAI;AAAA,MAC3D,sBAAsB,KAAK,qBAAqB,KAAK,IAAI;AAAA,MACzD,wBAAwB,MACtB;;AAAA,2BAAK,iCAAL,mBAAmC,qBAAoB;AAAA;AAAA,IAC3D;AAAA,EAAA;AAAA,EAGM,YAAY,WAAmB,MAAY;AACjD,SAAK,sBAAsB;AAErB,UAAA,OAAO,KAAK,iBAAiB,eAAe;AAAA,MAChD;AAAA,MACA;AAAA,MACA,WAAW,KAAK,OAAO;AAAA,MACvB,aAAa,KAAK,OAAO;AAAA,MACzB,SAAS;AAAA,QACP,iBAAiB,KAAK,OAAO,mBAAmB;AAAA,MAAA;AAAA,IAClD,CACD;AAEI,SAAA,KAAK,CAAC,SAAS;AAClB,WAAK,aAAa,KAAK;AAAA,QACrB;AAAA,QACA;AAAA,QACA;AAAA,QACA,WAAW,KAAK,OAAO,aAAa;AAAA,QACpC,OAAO,KAAK,OAAO,SAAS;AAAA,QAC5B,iBAAiB,KAAK,OAAO,mBAAmB;AAAA,MAAA,CACjD;AAAA,OACA,MAAM;AAAA,EAAA;AAAA,EAGH,uBAAuB;;AACxB,eAAA,iCAAA,mBAA8B,SAAS;AAAA,EAAgB;AAAA,EAGtD,wBAAwB;;AACzB,eAAA,iCAAA,mBAA8B,SAAS;AAAA,EAAS;AAAA,EAG/C,uBAAuB;;AAC7B,UAAI,UAAK,iCAAL,mBAAmC,qBAAoB,kBAAkB;AACtE,iBAAA,iCAAA,mBAA8B,SAAS;AAAA,IAAS,OAChD;AACA,iBAAA,iCAAA,mBAA8B,SAAS;AAAA,IAAgB;AAAA,EAC9D;AAEJ;AAhFE,eAAgB,KAAK;AADhB,IAAM,gBAAN;ACLA,MAAM,uBAA0E;AAAA,EACrF;AAAA,EACA,QAAQ,CAAC,UAAU,SAAS,WAAW,IAAI,cAAc,mBAAmB,UAAU,MAAM;AAAA,EAC5F,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAA;AAChB;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { BasePlugin, PluginRegistry } from '@embedpdf/core';
|
|
2
|
+
import { CaptureCapability, CapturePluginConfig } from './types';
|
|
3
|
+
export declare class CapturePlugin extends BasePlugin<CapturePluginConfig, CaptureCapability> {
|
|
4
|
+
static readonly id: "capture";
|
|
5
|
+
private captureArea$;
|
|
6
|
+
private renderCapability;
|
|
7
|
+
private interactionManagerCapability;
|
|
8
|
+
private config;
|
|
9
|
+
constructor(id: string, registry: PluginRegistry, config: CapturePluginConfig);
|
|
10
|
+
initialize(_: CapturePluginConfig): Promise<void>;
|
|
11
|
+
protected buildCapability(): CaptureCapability;
|
|
12
|
+
private captureArea;
|
|
13
|
+
private enableMarqueeCapture;
|
|
14
|
+
private disableMarqueeCapture;
|
|
15
|
+
private toggleMarqueeCapture;
|
|
16
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PluginPackage } from '@embedpdf/core';
|
|
2
|
+
import { CapturePluginConfig } from './types';
|
|
3
|
+
import { CapturePlugin } from './capture-plugin';
|
|
4
|
+
export declare const CapturePluginPackage: PluginPackage<CapturePlugin, CapturePluginConfig>;
|
|
5
|
+
export * from './capture-plugin';
|
|
6
|
+
export * from './types';
|
|
7
|
+
export * from './manifest';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BasePluginConfig, EventHook } from '@embedpdf/core';
|
|
2
|
+
import { ImageConversionTypes, Rect } from '@embedpdf/models';
|
|
3
|
+
export interface CapturePluginConfig extends BasePluginConfig {
|
|
4
|
+
scale?: number;
|
|
5
|
+
imageType?: ImageConversionTypes;
|
|
6
|
+
withAnnotations?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface CaptureAreaEvent {
|
|
9
|
+
pageIndex: number;
|
|
10
|
+
rect: Rect;
|
|
11
|
+
blob: Blob;
|
|
12
|
+
imageType: ImageConversionTypes;
|
|
13
|
+
scale: number;
|
|
14
|
+
withAnnotations: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface CaptureCapability {
|
|
17
|
+
onCaptureArea: EventHook<CaptureAreaEvent>;
|
|
18
|
+
captureArea(pageIndex: number, rect: Rect): void;
|
|
19
|
+
enableMarqueeCapture: () => void;
|
|
20
|
+
disableMarqueeCapture: () => void;
|
|
21
|
+
toggleMarqueeCapture: () => void;
|
|
22
|
+
isMarqueeCaptureActive: () => boolean;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useEffect, useRef, useState, useMemo } from 'preact/hooks';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@embedpdf/core/preact';
|
package/dist/preact/index.cjs
CHANGED
|
@@ -1,121 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/preact/index.ts
|
|
21
|
-
var preact_exports = {};
|
|
22
|
-
__export(preact_exports, {
|
|
23
|
-
MarqueeCapture: () => MarqueeCapture,
|
|
24
|
-
useCaptureCapability: () => useCaptureCapability,
|
|
25
|
-
useCapturePlugin: () => useCapturePlugin
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(preact_exports);
|
|
28
|
-
|
|
29
|
-
// src/preact/hooks/use-capture.ts
|
|
30
|
-
var import_preact = require("@embedpdf/core/preact");
|
|
31
|
-
var import_plugin_capture = require("@embedpdf/plugin-capture");
|
|
32
|
-
var useCaptureCapability = () => (0, import_preact.useCapability)(import_plugin_capture.CapturePlugin.id);
|
|
33
|
-
var useCapturePlugin = () => (0, import_preact.usePlugin)(import_plugin_capture.CapturePlugin.id);
|
|
34
|
-
|
|
35
|
-
// src/preact/components/marquee-capture.tsx
|
|
36
|
-
var import_hooks = require("preact/hooks");
|
|
37
|
-
var import_preact2 = require("@embedpdf/plugin-interaction-manager/preact");
|
|
38
|
-
var import_jsx_runtime = require("preact/jsx-runtime");
|
|
39
|
-
var MarqueeCapture = ({
|
|
40
|
-
pageIndex,
|
|
41
|
-
scale,
|
|
42
|
-
pageWidth,
|
|
43
|
-
pageHeight,
|
|
44
|
-
className,
|
|
45
|
-
stroke = "rgba(33,150,243,0.8)",
|
|
46
|
-
fill = "rgba(33,150,243,0.15)"
|
|
47
|
-
}) => {
|
|
48
|
-
const { provides: capture } = useCaptureCapability();
|
|
49
|
-
const { register } = (0, import_preact2.usePointerHandlers)({ modeId: "marqueeCapture", pageIndex });
|
|
50
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
51
|
-
const startRef = (0, import_hooks.useRef)(null);
|
|
52
|
-
const [rect, setRect] = (0, import_hooks.useState)(null);
|
|
53
|
-
const pageWidthPDF = pageWidth / scale;
|
|
54
|
-
const pageHeightPDF = pageHeight / scale;
|
|
55
|
-
const handlers = (0, import_hooks.useMemo)(
|
|
56
|
-
() => ({
|
|
57
|
-
onPointerDown: (pos, evt) => {
|
|
58
|
-
startRef.current = pos;
|
|
59
|
-
setRect({ origin: { x: pos.x, y: pos.y }, size: { width: 0, height: 0 } });
|
|
60
|
-
evt.target?.setPointerCapture?.(evt.pointerId);
|
|
61
|
-
},
|
|
62
|
-
onPointerMove: (pos) => {
|
|
63
|
-
if (!startRef.current) return;
|
|
64
|
-
const curX = clamp(pos.x, 0, pageWidthPDF);
|
|
65
|
-
const curY = clamp(pos.y, 0, pageHeightPDF);
|
|
66
|
-
const { x: sx, y: sy } = startRef.current;
|
|
67
|
-
const left = Math.min(sx, curX);
|
|
68
|
-
const top = Math.min(sy, curY);
|
|
69
|
-
const width = Math.abs(curX - sx);
|
|
70
|
-
const height = Math.abs(curY - sy);
|
|
71
|
-
setRect({ origin: { x: left, y: top }, size: { width, height } });
|
|
72
|
-
},
|
|
73
|
-
onPointerUp: (_, evt) => {
|
|
74
|
-
if (rect && capture) {
|
|
75
|
-
const dragPx = Math.max(rect.size.width, rect.size.height) * scale;
|
|
76
|
-
if (dragPx > 5) {
|
|
77
|
-
capture.captureArea(pageIndex, rect);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
startRef.current = null;
|
|
81
|
-
setRect(null);
|
|
82
|
-
evt.target?.releasePointerCapture?.(evt.pointerId);
|
|
83
|
-
},
|
|
84
|
-
onPointerCancel: (_, evt) => {
|
|
85
|
-
startRef.current = null;
|
|
86
|
-
setRect(null);
|
|
87
|
-
evt.target?.releasePointerCapture?.(evt.pointerId);
|
|
88
|
-
}
|
|
89
|
-
}),
|
|
90
|
-
[pageWidthPDF, pageWidthPDF, capture, scale, rect, pageIndex]
|
|
91
|
-
);
|
|
92
|
-
(0, import_hooks.useEffect)(() => {
|
|
93
|
-
if (!register) return;
|
|
94
|
-
return register(handlers);
|
|
95
|
-
}, [register, handlers]);
|
|
96
|
-
if (!rect) return null;
|
|
97
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
98
|
-
"div",
|
|
99
|
-
{
|
|
100
|
-
style: {
|
|
101
|
-
position: "absolute",
|
|
102
|
-
pointerEvents: "none",
|
|
103
|
-
left: rect.origin.x * scale,
|
|
104
|
-
top: rect.origin.y * scale,
|
|
105
|
-
width: rect.size.width * scale,
|
|
106
|
-
height: rect.size.height * scale,
|
|
107
|
-
border: `1px solid ${stroke}`,
|
|
108
|
-
background: fill,
|
|
109
|
-
boxSizing: "border-box"
|
|
110
|
-
},
|
|
111
|
-
className
|
|
112
|
-
}
|
|
113
|
-
);
|
|
114
|
-
};
|
|
115
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
116
|
-
0 && (module.exports = {
|
|
117
|
-
MarqueeCapture,
|
|
118
|
-
useCaptureCapability,
|
|
119
|
-
useCapturePlugin
|
|
120
|
-
});
|
|
121
|
-
//# sourceMappingURL=index.cjs.map
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),r=require("@embedpdf/plugin-capture"),t=require("preact/jsx-runtime"),i=require("preact/hooks"),n=require("@embedpdf/plugin-interaction-manager/preact"),a=()=>e.useCapability(r.CapturePlugin.id);exports.MarqueeCapture=({pageIndex:e,scale:r,pageWidth:u,pageHeight:l,className:o,stroke:s="rgba(33,150,243,0.8)",fill:p="rgba(33,150,243,0.15)"})=>{const{provides:d}=a(),{register:g}=n.usePointerHandlers({modeId:"marqueeCapture",pageIndex:e}),c=(e,r,t)=>Math.max(r,Math.min(t,e)),h=i.useRef(null),[x,b]=i.useState(null),m=u/r,P=l/r,f=i.useMemo((()=>({onPointerDown:(e,r)=>{var t,i;h.current=e,b({origin:{x:e.x,y:e.y},size:{width:0,height:0}}),null==(i=null==(t=r.target)?void 0:t.setPointerCapture)||i.call(t,r.pointerId)},onPointerMove:e=>{if(!h.current)return;const r=c(e.x,0,m),t=c(e.y,0,P),{x:i,y:n}=h.current,a=Math.min(i,r),u=Math.min(n,t),l=Math.abs(r-i),o=Math.abs(t-n);b({origin:{x:a,y:u},size:{width:l,height:o}})},onPointerUp:(t,i)=>{var n,a;if(x&&d){Math.max(x.size.width,x.size.height)*r>5&&d.captureArea(e,x)}h.current=null,b(null),null==(a=null==(n=i.target)?void 0:n.releasePointerCapture)||a.call(n,i.pointerId)},onPointerCancel:(e,r)=>{var t,i;h.current=null,b(null),null==(i=null==(t=r.target)?void 0:t.releasePointerCapture)||i.call(t,r.pointerId)}})),[m,m,d,r,x,e]);return i.useEffect((()=>{if(g)return g(f)}),[g,f]),x?t.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:x.origin.x*r,top:x.origin.y*r,width:x.size.width*r,height:x.size.height*r,border:`1px solid ${s}`,background:p,boxSizing:"border-box"},className:o}):null},exports.useCaptureCapability=a,exports.useCapturePlugin=()=>e.usePlugin(r.CapturePlugin.id);
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-capture.ts","../../src/shared/components/marquee-capture.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { CapturePlugin } from '@embedpdf/plugin-capture';\n\nexport const useCaptureCapability = () => useCapability<CapturePlugin>(CapturePlugin.id);\nexport const useCapturePlugin = () => usePlugin<CapturePlugin>(CapturePlugin.id);\n","import { useEffect, useMemo, useRef, useState } from '@framework';\nimport type { PointerEventHandlers } from '@embedpdf/plugin-interaction-manager';\nimport { usePointerHandlers } from '@embedpdf/plugin-interaction-manager/@framework';\nimport { Rect } from '@embedpdf/models';\n\nimport { useCaptureCapability } from '../hooks/use-capture';\n\ninterface MarqueeCaptureProps {\n /** Index of the page this layer lives on */\n pageIndex: number;\n /** Scale of the page */\n scale: number;\n /** Width of the page */\n pageWidth: number;\n /** Height of the page */\n pageHeight: number;\n /** Optional CSS class applied to the marquee rectangle */\n className?: string;\n /** Stroke / fill colours (defaults below) */\n stroke?: string;\n fill?: string;\n}\n\n/**\n * Draws a marquee rectangle while the user drags.\n * Hook it into the interaction-manager with modeId = 'marqueeCapture'.\n */\nexport const MarqueeCapture = ({\n pageIndex,\n scale,\n pageWidth,\n pageHeight,\n className,\n stroke = 'rgba(33,150,243,0.8)',\n fill = 'rgba(33,150,243,0.15)',\n}: MarqueeCaptureProps) => {\n /* ------------------------------------------------------------------ */\n /* capture capability */\n /* ------------------------------------------------------------------ */\n const { provides: capture } = useCaptureCapability();\n\n /* ------------------------------------------------------------------ */\n /* integration with interaction-manager */\n /* ------------------------------------------------------------------ */\n const { register } = usePointerHandlers({ modeId: 'marqueeCapture', pageIndex });\n\n /* ------------------------------------------------------------------ */\n /* helpers */\n /* ------------------------------------------------------------------ */\n const clamp = (v: number, min: number, max: number) => Math.max(min, Math.min(max, v));\n\n /* ------------------------------------------------------------------ */\n /* local state – start / current drag position */\n /* ------------------------------------------------------------------ */\n const startRef = useRef<{ x: number; y: number } | null>(null);\n const [rect, setRect] = useState<Rect | null>(null);\n\n /* page size in **PDF-space** (unscaled) ----------------------------- */\n const pageWidthPDF = pageWidth / scale;\n const pageHeightPDF = pageHeight / scale;\n\n /* ------------------------------------------------------------------ */\n /* pointer handlers */\n /* ------------------------------------------------------------------ */\n const handlers = useMemo<PointerEventHandlers<PointerEvent>>(\n () => ({\n onPointerDown: (pos, evt) => {\n startRef.current = pos;\n setRect({ origin: { x: pos.x, y: pos.y }, size: { width: 0, height: 0 } });\n (evt.target as HTMLElement)?.setPointerCapture?.(evt.pointerId);\n },\n onPointerMove: (pos) => {\n if (!startRef.current) return;\n /* clamp current position to the page bounds */\n const curX = clamp(pos.x, 0, pageWidthPDF);\n const curY = clamp(pos.y, 0, pageHeightPDF);\n\n const { x: sx, y: sy } = startRef.current;\n const left = Math.min(sx, curX);\n const top = Math.min(sy, curY);\n const width = Math.abs(curX - sx);\n const height = Math.abs(curY - sy);\n\n setRect({ origin: { x: left, y: top }, size: { width, height } });\n },\n onPointerUp: (_, evt) => {\n if (rect && capture) {\n const dragPx = Math.max(rect.size.width, rect.size.height) * scale;\n if (dragPx > 5) {\n // real drag → zoom to it\n capture.captureArea(pageIndex, rect);\n }\n }\n\n startRef.current = null;\n setRect(null);\n (evt.target as HTMLElement)?.releasePointerCapture?.(evt.pointerId);\n },\n onPointerCancel: (_, evt) => {\n startRef.current = null;\n setRect(null);\n (evt.target as HTMLElement)?.releasePointerCapture?.(evt.pointerId);\n },\n }),\n [pageWidthPDF, pageWidthPDF, capture, scale, rect, pageIndex],\n );\n\n /* register with the interaction-manager */\n useEffect(() => {\n if (!register) return;\n return register(handlers);\n }, [register, handlers]);\n\n /* ------------------------------------------------------------------ */\n /* render */\n /* ------------------------------------------------------------------ */\n if (!rect) return null; // nothing to draw\n\n return (\n <div\n /* Each page wrapper is position:relative, so absolute is fine */\n style={{\n position: 'absolute',\n pointerEvents: 'none',\n left: rect.origin.x * scale,\n top: rect.origin.y * scale,\n width: rect.size.width * scale,\n height: rect.size.height * scale,\n border: `1px solid ${stroke}`,\n background: fill,\n boxSizing: 'border-box',\n }}\n className={className}\n />\n );\n};\n"],"names":["useCaptureCapability","useCapability","CapturePlugin","id","pageIndex","scale","pageWidth","pageHeight","className","stroke","fill","provides","capture","register","usePointerHandlers","modeId","clamp","v","min","max","Math","startRef","useRef","rect","setRect","useState","pageWidthPDF","pageHeightPDF","handlers","useMemo","onPointerDown","pos","evt","current","origin","x","y","size","width","height","_b","_a","target","setPointerCapture","call","pointerId","onPointerMove","curX","curY","sx","sy","left","top","abs","onPointerUp","_","captureArea","releasePointerCapture","onPointerCancel","useEffect","jsxRuntime","jsx","style","position","pointerEvents","border","background","boxSizing","usePlugin"],"mappings":"kRAGaA,EAAuB,IAAMC,gBAA6BC,EAAAA,cAAcC,2BCwBvD,EAC5BC,YACAC,QACAC,YACAC,aACAC,YACAC,SAAS,uBACTC,OAAO,4BAKP,MAAQC,SAAUC,GAAYZ,KAKxBa,SAAEA,GAAaC,EAAAA,mBAAmB,CAAEC,OAAQ,iBAAkBX,cAK9DY,EAAQ,CAACC,EAAWC,EAAaC,IAAgBC,KAAKD,IAAID,EAAKE,KAAKF,IAAIC,EAAKF,IAK7EI,EAAWC,SAAwC,OAClDC,EAAMC,GAAWC,EAAAA,SAAsB,MAGxCC,EAAepB,EAAYD,EAC3BsB,EAAgBpB,EAAaF,EAK7BuB,EAAWC,EAAAA,SACf,KAAO,CACLC,cAAe,CAACC,EAAKC,aACnBX,EAASY,QAAUF,EACnBP,EAAQ,CAAEU,OAAQ,CAAEC,EAAGJ,EAAII,EAAGC,EAAGL,EAAIK,GAAKC,KAAM,CAAEC,MAAO,EAAGC,OAAQ,KACnE,OAAAC,EAAA,OAAAC,EAAAT,EAAIU,aAAJ,EAAAD,EAA4BE,oBAA5BH,EAAAI,KAAAH,EAAgDT,EAAIa,UAAA,EAEvDC,cAAgBf,IACV,IAACV,EAASY,QAAS,OAEvB,MAAMc,EAAO/B,EAAMe,EAAII,EAAG,EAAGT,GACvBsB,EAAOhC,EAAMe,EAAIK,EAAG,EAAGT,IAErBQ,EAAGc,EAAIb,EAAGc,GAAO7B,EAASY,QAC5BkB,EAAO/B,KAAKF,IAAI+B,EAAIF,GACpBK,EAAMhC,KAAKF,IAAIgC,EAAIF,GACnBV,EAAQlB,KAAKiC,IAAIN,EAAOE,GACxBV,EAASnB,KAAKiC,IAAIL,EAAOE,GAE/B1B,EAAQ,CAAEU,OAAQ,CAAEC,EAAGgB,EAAMf,EAAGgB,GAAOf,KAAM,CAAEC,QAAOC,WAAU,EAElEe,YAAa,CAACC,EAAGvB,aACf,GAAIT,GAAQX,EAAS,CACJQ,KAAKD,IAAII,EAAKc,KAAKC,MAAOf,EAAKc,KAAKE,QAAUlC,EAChD,GAEHO,EAAA4C,YAAYpD,EAAWmB,EACjC,CAGFF,EAASY,QAAU,KACnBT,EAAQ,MACP,OAAAgB,EAAA,OAAAC,EAAAT,EAAIU,aAAJ,EAAAD,EAA4BgB,wBAA5BjB,EAAAI,KAAAH,EAAoDT,EAAIa,UAAA,EAE3Da,gBAAiB,CAACH,EAAGvB,aACnBX,EAASY,QAAU,KACnBT,EAAQ,MACP,OAAAgB,EAAA,OAAAC,EAAAT,EAAIU,aAAJ,EAAAD,EAA4BgB,wBAA5BjB,EAAAI,KAAAH,EAAoDT,EAAIa,UAAA,KAG7D,CAACnB,EAAcA,EAAcd,EAASP,EAAOkB,EAAMnB,IAYjD,OARJuD,EAAAA,WAAU,KACR,GAAK9C,EACL,OAAOA,EAASe,EAAQ,GACvB,CAACf,EAAUe,IAKTL,EAGHqC,EAAAC,IAAC,MAAA,CAECC,MAAO,CACLC,SAAU,WACVC,cAAe,OACfb,KAAM5B,EAAKW,OAAOC,EAAI9B,EACtB+C,IAAK7B,EAAKW,OAAOE,EAAI/B,EACrBiC,MAAOf,EAAKc,KAAKC,MAAQjC,EACzBkC,OAAQhB,EAAKc,KAAKE,OAASlC,EAC3B4D,OAAQ,aAAaxD,IACrByD,WAAYxD,EACZyD,UAAW,cAEb3D,cAhBc,IAiBhB,0DDjI4B,IAAM4D,YAAyBlE,EAAAA,cAAcC"}
|
package/dist/preact/index.d.ts
CHANGED
|
@@ -1,37 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { CapturePlugin } from '@embedpdf/plugin-capture';
|
|
3
|
-
import * as preact from 'preact';
|
|
4
|
-
|
|
5
|
-
declare const useCaptureCapability: () => {
|
|
6
|
-
provides: Readonly<_embedpdf_plugin_capture.CaptureCapability> | null;
|
|
7
|
-
isLoading: boolean;
|
|
8
|
-
ready: Promise<void>;
|
|
9
|
-
};
|
|
10
|
-
declare const useCapturePlugin: () => {
|
|
11
|
-
plugin: CapturePlugin | null;
|
|
12
|
-
isLoading: boolean;
|
|
13
|
-
ready: Promise<void>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
interface MarqueeCaptureProps {
|
|
17
|
-
/** Index of the page this layer lives on */
|
|
18
|
-
pageIndex: number;
|
|
19
|
-
/** Scale of the page */
|
|
20
|
-
scale: number;
|
|
21
|
-
/** Width of the page */
|
|
22
|
-
pageWidth: number;
|
|
23
|
-
/** Height of the page */
|
|
24
|
-
pageHeight: number;
|
|
25
|
-
/** Optional CSS class applied to the marquee rectangle */
|
|
26
|
-
className?: string;
|
|
27
|
-
/** Stroke / fill colours (defaults below) */
|
|
28
|
-
stroke?: string;
|
|
29
|
-
fill?: string;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Draws a marquee rectangle while the user drags.
|
|
33
|
-
* Hook it into the interaction-manager with modeId = 'marqueeCapture'.
|
|
34
|
-
*/
|
|
35
|
-
declare const MarqueeCapture: ({ pageIndex, scale, pageWidth, pageHeight, className, stroke, fill, }: MarqueeCaptureProps) => preact.JSX.Element | null;
|
|
36
|
-
|
|
37
|
-
export { MarqueeCapture, useCaptureCapability, useCapturePlugin };
|
|
1
|
+
export * from '../shared-preact';
|