@embedpdf/plugin-capture 1.0.19 → 1.0.21
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +98 -11
- package/dist/index.js.map +1 -1
- package/dist/lib/capture-plugin.d.ts +2 -1
- package/dist/lib/handlers/index.d.ts +1 -0
- package/dist/lib/handlers/marquee-capture.handler.d.ts +9 -0
- package/dist/lib/types.d.ts +10 -0
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +12 -53
- package/dist/preact/index.js.map +1 -1
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +12 -53
- package/dist/react/index.js.map +1 -1
- package/dist/shared-preact/components/marquee-capture.d.ts +1 -9
- package/dist/shared-preact/index.d.ts +1 -0
- package/dist/shared-react/components/marquee-capture.d.ts +1 -9
- package/dist/shared-react/index.d.ts +1 -0
- package/dist/vue/components/index.d.ts +1 -0
- package/dist/vue/components/marquee-capture.vue.d.ts +16 -0
- package/dist/vue/hooks/index.d.ts +1 -0
- package/dist/vue/hooks/use-capture.d.ts +3 -0
- package/dist/vue/index.cjs +2 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +3 -0
- package/dist/vue/index.js +60 -0
- package/dist/vue/index.js.map +1 -0
- package/package.json +16 -9
- package/dist/preact/interaction-manager.d.ts +0 -1
- package/dist/react/interaction-manager.d.ts +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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"],
|
|
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"],optional:["interaction-manager"],defaultConfig:{enabled:!0,scale:1,imageType:"image/png",withAnnotations:!1}};const r=class extends e.BasePlugin{constructor(a,t,i){var r;super(a,t),this.captureArea$=e.createEmitter(),this.config=i,this.renderCapability=this.registry.getPlugin("render").provides(),this.interactionManagerCapability=null==(r=this.registry.getPlugin("interaction-manager"))?void 0:r.provides(),this.interactionManagerCapability&&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())},registerMarqueeOnPage:e=>this.registerMarqueeOnPage(e)}}registerMarqueeOnPage(a){if(!this.interactionManagerCapability)return this.logger.warn("CapturePlugin","MissingDependency","Interaction manager plugin not loaded, marquee capture disabled"),()=>{};const t=this.coreState.core.document;if(!t)return this.logger.warn("CapturePlugin","DocumentNotFound","Document not found"),()=>{};const i=t.pages[a.pageIndex];if(!i)return this.logger.warn("CapturePlugin","PageNotFound",`Page ${a.pageIndex} not found`),()=>{};const r=function(a){const{pageSize:t,scale:i,minDragPx:r=5,onPreview:n,onCommit:l}=a;let o=null,u=null;return{onPointerDown:(e,a)=>{var t;o=e,u={origin:{x:e.x,y:e.y},size:{width:0,height:0}},null==n||n(u),null==(t=a.setPointerCapture)||t.call(a)},onPointerMove:a=>{if(!o)return;const i=e.clamp(a.x,0,t.width),r=e.clamp(a.y,0,t.height);u={origin:{x:Math.min(o.x,i),y:Math.min(o.y,r)},size:{width:Math.abs(i-o.x),height:Math.abs(r-o.y)}},null==n||n(u)},onPointerUp:(e,a)=>{var t;u&&Math.max(u.size.width,u.size.height)*i>r&&(null==l||l(u)),o=null,u=null,null==n||n(null),null==(t=a.releasePointerCapture)||t.call(a)},onPointerCancel:(e,a)=>{var t;o=null,u=null,null==n||n(null),null==(t=a.releasePointerCapture)||t.call(a)}}}({pageSize:i.size,scale:a.scale,onPreview:a.callback.onPreview,onCommit:e=>{var t,i;this.captureArea(a.pageIndex,e),null==(i=(t=a.callback).onCommit)||i.call(t,e)}});return this.interactionManagerCapability.registerHandlers({modeId:"marqueeCapture",handlers:r,pageIndex:a.pageIndex})}captureArea(e,t){this.disableMarqueeCapture();this.renderCapability.renderPageRect({pageIndex:e,rect:t,options:{imageType:this.config.imageType,scaleFactor:this.config.scale,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.activateDefaultMode()}toggleMarqueeCapture(){var e,a,t;"marqueeCapture"===(null==(e=this.interactionManagerCapability)?void 0:e.getActiveMode())?null==(a=this.interactionManagerCapability)||a.activateDefaultMode():null==(t=this.interactionManagerCapability)||t.activate("marqueeCapture")}};r.id="capture";let n=r;const l={manifest:i,create:(e,a)=>new n(t,e,a),reducer:()=>{},initialState:{}};exports.CAPTURE_PLUGIN_ID=t,exports.CapturePlugin=n,exports.CapturePluginPackage=l,exports.manifest=i;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 options: {\n imageType: this.config.imageType,\n scaleFactor: this.config.scale,\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?.activateDefaultMode();\n }\n\n private toggleMarqueeCapture() {\n if (this.interactionManagerCapability?.getActiveMode() === 'marqueeCapture') {\n this.interactionManagerCapability?.activateDefaultMode();\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, 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","options","scaleFactor","wait","blob","emit","ignore","activate","activateDefaultMode","_b","_c","CapturePlugin","CapturePluginPackage","create","reducer","initialState"],"mappings":"gJAGaA,EAAoB,UAEp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sC,SAAM,CAGH,oBAAAd,SACD,OAAAI,EAAArB,KAAAK,iCAA8B2B,SAAS,iBAAgB,CAGtD,qBAAAd,SACN,OAAAG,EAAArB,KAAKK,+BAA8BgB,EAAAY,qBAAoB,CAGjD,oBAAAd,aACqD,oBAAvD,OAAAE,EAAKrB,KAAAK,mCAA8B,EAAAgB,EAAAC,iBACrC,OAAAY,EAAAlC,KAAKK,+BAA8B6B,EAAAD,sBAE9B,OAAAE,EAAAnC,KAAAK,iCAA8B2B,SAAS,iBAC9C,GA9EFtC,EAAgBX,GAAK,UADhB,IAAMqD,EAAN1C,ECLA,MAAM2C,EAA0E,CACrFvD,WACAwD,OAAQ,CAACzC,EAAUC,IAAW,IAAIsC,EAAcvD,EAAmBgB,EAAUC,GAC7EyC,QAAS,OACTC,aAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/lib/manifest.ts","../src/lib/capture-plugin.ts","../src/lib/handlers/marquee-capture.handler.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'],\n optional: ['interaction-manager'],\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 { ignore, Rect } from '@embedpdf/models';\nimport {\n InteractionManagerCapability,\n InteractionManagerPlugin,\n} from '@embedpdf/plugin-interaction-manager';\nimport { RenderCapability, RenderPlugin } from '@embedpdf/plugin-render';\n\nimport {\n CaptureAreaEvent,\n CaptureCapability,\n CapturePluginConfig,\n RegisterMarqueeOnPageOptions,\n} from './types';\nimport { createMarqueeHandler } from './handlers';\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 | undefined;\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 if (this.interactionManagerCapability) {\n this.interactionManagerCapability.registerMode({\n id: 'marqueeCapture',\n scope: 'page',\n exclusive: true,\n cursor: 'crosshair',\n });\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 registerMarqueeOnPage: (opts) => this.registerMarqueeOnPage(opts),\n };\n }\n\n public registerMarqueeOnPage(opts: RegisterMarqueeOnPageOptions) {\n if (!this.interactionManagerCapability) {\n this.logger.warn(\n 'CapturePlugin',\n 'MissingDependency',\n 'Interaction manager plugin not loaded, marquee capture disabled',\n );\n return () => {};\n }\n\n const document = this.coreState.core.document;\n if (!document) {\n this.logger.warn('CapturePlugin', 'DocumentNotFound', 'Document not found');\n return () => {};\n }\n\n const page = document.pages[opts.pageIndex];\n if (!page) {\n this.logger.warn('CapturePlugin', 'PageNotFound', `Page ${opts.pageIndex} not found`);\n return () => {};\n }\n\n const handlers = createMarqueeHandler({\n pageSize: page.size,\n scale: opts.scale,\n onPreview: opts.callback.onPreview,\n onCommit: (rect) => {\n // Capture the selected area\n this.captureArea(opts.pageIndex, rect);\n opts.callback.onCommit?.(rect);\n },\n });\n\n const off = this.interactionManagerCapability.registerHandlers({\n modeId: 'marqueeCapture',\n handlers,\n pageIndex: opts.pageIndex,\n });\n\n return off;\n }\n\n private captureArea(pageIndex: number, rect: Rect) {\n this.disableMarqueeCapture();\n\n const task = this.renderCapability.renderPageRect({\n pageIndex,\n rect,\n options: {\n imageType: this.config.imageType,\n scaleFactor: this.config.scale,\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?.activateDefaultMode();\n }\n\n private toggleMarqueeCapture() {\n if (this.interactionManagerCapability?.getActiveMode() === 'marqueeCapture') {\n this.interactionManagerCapability?.activateDefaultMode();\n } else {\n this.interactionManagerCapability?.activate('marqueeCapture');\n }\n }\n}\n","import { Position, Rect, Size } from '@embedpdf/models';\nimport { clamp } from '@embedpdf/core';\nimport {\n EmbedPdfPointerEvent,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\n\nexport function createMarqueeHandler(opts: {\n pageSize: Size;\n scale: number;\n minDragPx?: number;\n onPreview?: (rect: Rect | null) => void;\n onCommit?: (rect: Rect) => void;\n}): PointerEventHandlersWithLifecycle<EmbedPdfPointerEvent> {\n const { pageSize, scale, minDragPx = 5, onPreview, onCommit } = opts;\n\n let start: Position | null = null;\n let last: Rect | null = null;\n\n return {\n onPointerDown: (pos, evt) => {\n start = pos;\n last = { origin: { x: pos.x, y: pos.y }, size: { width: 0, height: 0 } };\n onPreview?.(last);\n evt.setPointerCapture?.();\n },\n onPointerMove: (pos) => {\n if (!start) return;\n const x = clamp(pos.x, 0, pageSize.width);\n const y = clamp(pos.y, 0, pageSize.height);\n last = {\n origin: { x: Math.min(start.x, x), y: Math.min(start.y, y) },\n size: { width: Math.abs(x - start.x), height: Math.abs(y - start.y) },\n };\n onPreview?.(last);\n },\n onPointerUp: (_pos, evt) => {\n if (last) {\n const dragPx = Math.max(last.size.width, last.size.height) * scale;\n if (dragPx > minDragPx) {\n onCommit?.(last);\n }\n }\n start = null;\n last = null;\n onPreview?.(null);\n evt.releasePointerCapture?.();\n },\n onPointerCancel: (_pos, evt) => {\n start = null;\n last = null;\n onPreview?.(null);\n evt.releasePointerCapture?.();\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, 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","_a","registerMode","scope","exclusive","cursor","initialize","_","buildCapability","onCaptureArea","on","captureArea","bind","enableMarqueeCapture","disableMarqueeCapture","toggleMarqueeCapture","isMarqueeCaptureActive","getActiveMode","registerMarqueeOnPage","opts","logger","warn","document","coreState","core","page","pages","pageIndex","handlers","pageSize","minDragPx","onPreview","onCommit","start","last","onPointerDown","pos","evt","origin","x","y","size","width","height","setPointerCapture","call","onPointerMove","clamp","Math","min","abs","onPointerUp","_pos","max","releasePointerCapture","onPointerCancel","createMarqueeHandler","callback","rect","_b","registerHandlers","modeId","renderPageRect","options","scaleFactor","wait","blob","emit","ignore","activate","activateDefaultMode","_c","CapturePlugin","Cap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ClF,EAAUC,IAAW,IAAI+E,EAAchG,EAAmBgB,EAAUC,GAC7EkF,QAAS,OACTC,aAAc,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BasePlugin, createEmitter } from "@embedpdf/core";
|
|
1
|
+
import { clamp, BasePlugin, createEmitter } from "@embedpdf/core";
|
|
2
2
|
import { ignore } from "@embedpdf/models";
|
|
3
3
|
const CAPTURE_PLUGIN_ID = "capture";
|
|
4
4
|
const manifest = {
|
|
@@ -6,8 +6,8 @@ const manifest = {
|
|
|
6
6
|
name: "Capture Plugin",
|
|
7
7
|
version: "1.0.0",
|
|
8
8
|
provides: ["capture"],
|
|
9
|
-
requires: ["render"
|
|
10
|
-
optional: [],
|
|
9
|
+
requires: ["render"],
|
|
10
|
+
optional: ["interaction-manager"],
|
|
11
11
|
defaultConfig: {
|
|
12
12
|
enabled: true,
|
|
13
13
|
scale: 1,
|
|
@@ -15,19 +15,66 @@ const manifest = {
|
|
|
15
15
|
withAnnotations: false
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
|
+
function createMarqueeHandler(opts) {
|
|
19
|
+
const { pageSize, scale, minDragPx = 5, onPreview, onCommit } = opts;
|
|
20
|
+
let start = null;
|
|
21
|
+
let last = null;
|
|
22
|
+
return {
|
|
23
|
+
onPointerDown: (pos, evt) => {
|
|
24
|
+
var _a;
|
|
25
|
+
start = pos;
|
|
26
|
+
last = { origin: { x: pos.x, y: pos.y }, size: { width: 0, height: 0 } };
|
|
27
|
+
onPreview == null ? void 0 : onPreview(last);
|
|
28
|
+
(_a = evt.setPointerCapture) == null ? void 0 : _a.call(evt);
|
|
29
|
+
},
|
|
30
|
+
onPointerMove: (pos) => {
|
|
31
|
+
if (!start) return;
|
|
32
|
+
const x = clamp(pos.x, 0, pageSize.width);
|
|
33
|
+
const y = clamp(pos.y, 0, pageSize.height);
|
|
34
|
+
last = {
|
|
35
|
+
origin: { x: Math.min(start.x, x), y: Math.min(start.y, y) },
|
|
36
|
+
size: { width: Math.abs(x - start.x), height: Math.abs(y - start.y) }
|
|
37
|
+
};
|
|
38
|
+
onPreview == null ? void 0 : onPreview(last);
|
|
39
|
+
},
|
|
40
|
+
onPointerUp: (_pos, evt) => {
|
|
41
|
+
var _a;
|
|
42
|
+
if (last) {
|
|
43
|
+
const dragPx = Math.max(last.size.width, last.size.height) * scale;
|
|
44
|
+
if (dragPx > minDragPx) {
|
|
45
|
+
onCommit == null ? void 0 : onCommit(last);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
start = null;
|
|
49
|
+
last = null;
|
|
50
|
+
onPreview == null ? void 0 : onPreview(null);
|
|
51
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
52
|
+
},
|
|
53
|
+
onPointerCancel: (_pos, evt) => {
|
|
54
|
+
var _a;
|
|
55
|
+
start = null;
|
|
56
|
+
last = null;
|
|
57
|
+
onPreview == null ? void 0 : onPreview(null);
|
|
58
|
+
(_a = evt.releasePointerCapture) == null ? void 0 : _a.call(evt);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
18
62
|
const _CapturePlugin = class _CapturePlugin extends BasePlugin {
|
|
19
63
|
constructor(id, registry, config) {
|
|
64
|
+
var _a;
|
|
20
65
|
super(id, registry);
|
|
21
66
|
this.captureArea$ = createEmitter();
|
|
22
67
|
this.config = config;
|
|
23
68
|
this.renderCapability = this.registry.getPlugin("render").provides();
|
|
24
|
-
this.interactionManagerCapability = this.registry.getPlugin("interaction-manager").provides();
|
|
25
|
-
this.interactionManagerCapability
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
69
|
+
this.interactionManagerCapability = (_a = this.registry.getPlugin("interaction-manager")) == null ? void 0 : _a.provides();
|
|
70
|
+
if (this.interactionManagerCapability) {
|
|
71
|
+
this.interactionManagerCapability.registerMode({
|
|
72
|
+
id: "marqueeCapture",
|
|
73
|
+
scope: "page",
|
|
74
|
+
exclusive: true,
|
|
75
|
+
cursor: "crosshair"
|
|
76
|
+
});
|
|
77
|
+
}
|
|
31
78
|
}
|
|
32
79
|
async initialize(_) {
|
|
33
80
|
}
|
|
@@ -41,9 +88,49 @@ const _CapturePlugin = class _CapturePlugin extends BasePlugin {
|
|
|
41
88
|
isMarqueeCaptureActive: () => {
|
|
42
89
|
var _a;
|
|
43
90
|
return ((_a = this.interactionManagerCapability) == null ? void 0 : _a.getActiveMode()) === "marqueeCapture";
|
|
44
|
-
}
|
|
91
|
+
},
|
|
92
|
+
registerMarqueeOnPage: (opts) => this.registerMarqueeOnPage(opts)
|
|
45
93
|
};
|
|
46
94
|
}
|
|
95
|
+
registerMarqueeOnPage(opts) {
|
|
96
|
+
if (!this.interactionManagerCapability) {
|
|
97
|
+
this.logger.warn(
|
|
98
|
+
"CapturePlugin",
|
|
99
|
+
"MissingDependency",
|
|
100
|
+
"Interaction manager plugin not loaded, marquee capture disabled"
|
|
101
|
+
);
|
|
102
|
+
return () => {
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
const document = this.coreState.core.document;
|
|
106
|
+
if (!document) {
|
|
107
|
+
this.logger.warn("CapturePlugin", "DocumentNotFound", "Document not found");
|
|
108
|
+
return () => {
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
const page = document.pages[opts.pageIndex];
|
|
112
|
+
if (!page) {
|
|
113
|
+
this.logger.warn("CapturePlugin", "PageNotFound", `Page ${opts.pageIndex} not found`);
|
|
114
|
+
return () => {
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const handlers = createMarqueeHandler({
|
|
118
|
+
pageSize: page.size,
|
|
119
|
+
scale: opts.scale,
|
|
120
|
+
onPreview: opts.callback.onPreview,
|
|
121
|
+
onCommit: (rect) => {
|
|
122
|
+
var _a, _b;
|
|
123
|
+
this.captureArea(opts.pageIndex, rect);
|
|
124
|
+
(_b = (_a = opts.callback).onCommit) == null ? void 0 : _b.call(_a, rect);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
const off = this.interactionManagerCapability.registerHandlers({
|
|
128
|
+
modeId: "marqueeCapture",
|
|
129
|
+
handlers,
|
|
130
|
+
pageIndex: opts.pageIndex
|
|
131
|
+
});
|
|
132
|
+
return off;
|
|
133
|
+
}
|
|
47
134
|
captureArea(pageIndex, rect) {
|
|
48
135
|
this.disableMarqueeCapture();
|
|
49
136
|
const task = this.renderCapability.renderPageRect({
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 options: {\n imageType: this.config.imageType,\n scaleFactor: this.config.scale,\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?.activateDefaultMode();\n }\n\n private toggleMarqueeCapture() {\n if (this.interactionManagerCapability?.getActiveMode() === 'marqueeCapture') {\n this.interactionManagerCapability?.activateDefaultMode();\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, 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,SAAS;AAAA,QACP,WAAW,KAAK,OAAO;AAAA,QACvB,aAAa,KAAK,OAAO;AAAA,QACzB,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;;AAC9B,eAAK,iCAAL,mBAAmC;AAAA,EAAoB;AAAA,EAGjD,uBAAuB;;AAC7B,UAAI,UAAK,iCAAL,mBAAmC,qBAAoB,kBAAkB;AAC3E,iBAAK,iCAAL,mBAAmC;AAAA,IAAoB,OAClD;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,WAAW,IAAI,cAAc,mBAAmB,UAAU,MAAM;AAAA,EACnF,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAA;AAChB;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/lib/manifest.ts","../src/lib/handlers/marquee-capture.handler.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'],\n optional: ['interaction-manager'],\n defaultConfig: {\n enabled: true,\n scale: 1,\n imageType: 'image/png',\n withAnnotations: false,\n },\n};\n","import { Position, Rect, Size } from '@embedpdf/models';\nimport { clamp } from '@embedpdf/core';\nimport {\n EmbedPdfPointerEvent,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\n\nexport function createMarqueeHandler(opts: {\n pageSize: Size;\n scale: number;\n minDragPx?: number;\n onPreview?: (rect: Rect | null) => void;\n onCommit?: (rect: Rect) => void;\n}): PointerEventHandlersWithLifecycle<EmbedPdfPointerEvent> {\n const { pageSize, scale, minDragPx = 5, onPreview, onCommit } = opts;\n\n let start: Position | null = null;\n let last: Rect | null = null;\n\n return {\n onPointerDown: (pos, evt) => {\n start = pos;\n last = { origin: { x: pos.x, y: pos.y }, size: { width: 0, height: 0 } };\n onPreview?.(last);\n evt.setPointerCapture?.();\n },\n onPointerMove: (pos) => {\n if (!start) return;\n const x = clamp(pos.x, 0, pageSize.width);\n const y = clamp(pos.y, 0, pageSize.height);\n last = {\n origin: { x: Math.min(start.x, x), y: Math.min(start.y, y) },\n size: { width: Math.abs(x - start.x), height: Math.abs(y - start.y) },\n };\n onPreview?.(last);\n },\n onPointerUp: (_pos, evt) => {\n if (last) {\n const dragPx = Math.max(last.size.width, last.size.height) * scale;\n if (dragPx > minDragPx) {\n onCommit?.(last);\n }\n }\n start = null;\n last = null;\n onPreview?.(null);\n evt.releasePointerCapture?.();\n },\n onPointerCancel: (_pos, evt) => {\n start = null;\n last = null;\n onPreview?.(null);\n evt.releasePointerCapture?.();\n },\n };\n}\n","import { BasePlugin, createEmitter, PluginRegistry } from '@embedpdf/core';\nimport { ignore, Rect } from '@embedpdf/models';\nimport {\n InteractionManagerCapability,\n InteractionManagerPlugin,\n} from '@embedpdf/plugin-interaction-manager';\nimport { RenderCapability, RenderPlugin } from '@embedpdf/plugin-render';\n\nimport {\n CaptureAreaEvent,\n CaptureCapability,\n CapturePluginConfig,\n RegisterMarqueeOnPageOptions,\n} from './types';\nimport { createMarqueeHandler } from './handlers';\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 | undefined;\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 if (this.interactionManagerCapability) {\n this.interactionManagerCapability.registerMode({\n id: 'marqueeCapture',\n scope: 'page',\n exclusive: true,\n cursor: 'crosshair',\n });\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 registerMarqueeOnPage: (opts) => this.registerMarqueeOnPage(opts),\n };\n }\n\n public registerMarqueeOnPage(opts: RegisterMarqueeOnPageOptions) {\n if (!this.interactionManagerCapability) {\n this.logger.warn(\n 'CapturePlugin',\n 'MissingDependency',\n 'Interaction manager plugin not loaded, marquee capture disabled',\n );\n return () => {};\n }\n\n const document = this.coreState.core.document;\n if (!document) {\n this.logger.warn('CapturePlugin', 'DocumentNotFound', 'Document not found');\n return () => {};\n }\n\n const page = document.pages[opts.pageIndex];\n if (!page) {\n this.logger.warn('CapturePlugin', 'PageNotFound', `Page ${opts.pageIndex} not found`);\n return () => {};\n }\n\n const handlers = createMarqueeHandler({\n pageSize: page.size,\n scale: opts.scale,\n onPreview: opts.callback.onPreview,\n onCommit: (rect) => {\n // Capture the selected area\n this.captureArea(opts.pageIndex, rect);\n opts.callback.onCommit?.(rect);\n },\n });\n\n const off = this.interactionManagerCapability.registerHandlers({\n modeId: 'marqueeCapture',\n handlers,\n pageIndex: opts.pageIndex,\n });\n\n return off;\n }\n\n private captureArea(pageIndex: number, rect: Rect) {\n this.disableMarqueeCapture();\n\n const task = this.renderCapability.renderPageRect({\n pageIndex,\n rect,\n options: {\n imageType: this.config.imageType,\n scaleFactor: this.config.scale,\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?.activateDefaultMode();\n }\n\n private toggleMarqueeCapture() {\n if (this.interactionManagerCapability?.getActiveMode() === 'marqueeCapture') {\n this.interactionManagerCapability?.activateDefaultMode();\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, 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;AAA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B,eAAK,iCAAL,mBAAmC;AAAA,EAAoB;AAAA,EAGjD,uBAAuB;;AAC7B,UAAI,UAAK,iCAAL,mBAAmC,qBAAoB,kBAAkB;AAC3E,iBAAK,iCAAL,mBAAmC;AAAA,IAAoB,OAClD;AACA,iBAAA,iCAAA,mBAA8B,SAAS;AAAA,IAAgB;AAAA,EAC9D;AAEJ;AA7HE,eAAgB,KAAK;AADhB,IAAM,gBAAN;ACXA,MAAM,uBAA0E;AAAA,EACrF;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,cAAc,mBAAmB,UAAU,MAAM;AAAA,EACnF,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAA;AAChB;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BasePlugin, PluginRegistry } from '@embedpdf/core';
|
|
2
|
-
import { CaptureCapability, CapturePluginConfig } from './types';
|
|
2
|
+
import { CaptureCapability, CapturePluginConfig, RegisterMarqueeOnPageOptions } from './types';
|
|
3
3
|
export declare class CapturePlugin extends BasePlugin<CapturePluginConfig, CaptureCapability> {
|
|
4
4
|
static readonly id: "capture";
|
|
5
5
|
private captureArea$;
|
|
@@ -9,6 +9,7 @@ export declare class CapturePlugin extends BasePlugin<CapturePluginConfig, Captu
|
|
|
9
9
|
constructor(id: string, registry: PluginRegistry, config: CapturePluginConfig);
|
|
10
10
|
initialize(_: CapturePluginConfig): Promise<void>;
|
|
11
11
|
protected buildCapability(): CaptureCapability;
|
|
12
|
+
registerMarqueeOnPage(opts: RegisterMarqueeOnPageOptions): () => void;
|
|
12
13
|
private captureArea;
|
|
13
14
|
private enableMarqueeCapture;
|
|
14
15
|
private disableMarqueeCapture;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './marquee-capture.handler';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Rect, Size } from '@embedpdf/models';
|
|
2
|
+
import { EmbedPdfPointerEvent, PointerEventHandlersWithLifecycle } from '@embedpdf/plugin-interaction-manager';
|
|
3
|
+
export declare function createMarqueeHandler(opts: {
|
|
4
|
+
pageSize: Size;
|
|
5
|
+
scale: number;
|
|
6
|
+
minDragPx?: number;
|
|
7
|
+
onPreview?: (rect: Rect | null) => void;
|
|
8
|
+
onCommit?: (rect: Rect) => void;
|
|
9
|
+
}): PointerEventHandlersWithLifecycle<EmbedPdfPointerEvent>;
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -13,6 +13,15 @@ export interface CaptureAreaEvent {
|
|
|
13
13
|
scale: number;
|
|
14
14
|
withAnnotations: boolean;
|
|
15
15
|
}
|
|
16
|
+
export interface MarqueeCaptureCallback {
|
|
17
|
+
onPreview?: (rect: Rect | null) => void;
|
|
18
|
+
onCommit?: (rect: Rect) => void;
|
|
19
|
+
}
|
|
20
|
+
export interface RegisterMarqueeOnPageOptions {
|
|
21
|
+
pageIndex: number;
|
|
22
|
+
scale: number;
|
|
23
|
+
callback: MarqueeCaptureCallback;
|
|
24
|
+
}
|
|
16
25
|
export interface CaptureCapability {
|
|
17
26
|
onCaptureArea: EventHook<CaptureAreaEvent>;
|
|
18
27
|
captureArea(pageIndex: number, rect: Rect): void;
|
|
@@ -20,4 +29,5 @@ export interface CaptureCapability {
|
|
|
20
29
|
disableMarqueeCapture: () => void;
|
|
21
30
|
toggleMarqueeCapture: () => void;
|
|
22
31
|
isMarqueeCaptureActive: () => boolean;
|
|
32
|
+
registerMarqueeOnPage: (opts: RegisterMarqueeOnPageOptions) => () => void;
|
|
23
33
|
}
|
package/dist/preact/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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"),
|
|
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"),a=()=>e.useCapability(r.CapturePlugin.id);exports.MarqueeCapture=({pageIndex:e,scale:r,className:o,stroke:s="rgba(33,150,243,0.8)",fill:u="rgba(33,150,243,0.15)"})=>{const{provides:p}=a(),[l,n]=i.useState(null);return i.useEffect((()=>{if(p)return p.registerMarqueeOnPage({pageIndex:e,scale:r,callback:{onPreview:n}})}),[p,e,r]),l?t.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:l.origin.x*r,top:l.origin.y*r,width:l.size.width*r,height:l.size.height*r,border:`1px solid ${s}`,background:u,boxSizing:"border-box"},className:o}):null},exports.useCaptureCapability=a,exports.useCapturePlugin=()=>e.usePlugin(r.CapturePlugin.id),Object.keys(r).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})}));
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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, useState } from '@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 /** 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\nexport const MarqueeCapture = ({\n pageIndex,\n scale,\n className,\n stroke = 'rgba(33,150,243,0.8)',\n fill = 'rgba(33,150,243,0.15)',\n}: MarqueeCaptureProps) => {\n const { provides: capturePlugin } = useCaptureCapability();\n const [rect, setRect] = useState<Rect | null>(null);\n\n useEffect(() => {\n if (!capturePlugin) return;\n return capturePlugin.registerMarqueeOnPage({\n pageIndex,\n scale,\n callback: {\n onPreview: setRect,\n },\n });\n }, [capturePlugin, pageIndex, scale]);\n\n if (!rect) return null;\n\n return (\n <div\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","className","stroke","fill","provides","capturePlugin","rect","setRect","useState","useEffect","registerMarqueeOnPage","callback","onPreview","jsxRuntime","jsx","style","position","pointerEvents","left","origin","x","top","y","width","size","height","border","background","boxSizing","usePlugin"],"mappings":"yNAGaA,EAAuB,IAAMC,gBAA6BC,EAAAA,cAAcC,2BCcvD,EAC5BC,YACAC,QACAC,YACAC,SAAS,uBACTC,OAAO,4BAEP,MAAQC,SAAUC,GAAkBV,KAC7BW,EAAMC,GAAWC,EAAAA,SAAsB,MAa1C,OAXJC,EAAAA,WAAU,KACR,GAAKJ,EACL,OAAOA,EAAcK,sBAAsB,CACzCX,YACAC,QACAW,SAAU,CACRC,UAAWL,IAEd,GACA,CAACF,EAAeN,EAAWC,IAEzBM,EAGHO,EAAAC,IAAC,MAAA,CACCC,MAAO,CACLC,SAAU,WACVC,cAAe,OACfC,KAAMZ,EAAKa,OAAOC,EAAIpB,EACtBqB,IAAKf,EAAKa,OAAOG,EAAItB,EACrBuB,MAAOjB,EAAKkB,KAAKD,MAAQvB,EACzByB,OAAQnB,EAAKkB,KAAKC,OAASzB,EAC3B0B,OAAQ,aAAaxB,IACrByB,WAAYxB,EACZyB,UAAW,cAEb3B,cAfc,IAgBhB,0DDlD4B,IAAM4B,YAAyBhC,EAAAA,cAAcC"}
|
package/dist/preact/index.js
CHANGED
|
@@ -1,70 +1,29 @@
|
|
|
1
1
|
import { useCapability, usePlugin } from "@embedpdf/core/preact";
|
|
2
2
|
import { CapturePlugin } from "@embedpdf/plugin-capture";
|
|
3
|
+
export * from "@embedpdf/plugin-capture";
|
|
3
4
|
import { jsx } from "preact/jsx-runtime";
|
|
4
|
-
import {
|
|
5
|
-
import { usePointerHandlers } from "@embedpdf/plugin-interaction-manager/preact";
|
|
5
|
+
import { useState, useEffect } from "preact/hooks";
|
|
6
6
|
const useCaptureCapability = () => useCapability(CapturePlugin.id);
|
|
7
7
|
const useCapturePlugin = () => usePlugin(CapturePlugin.id);
|
|
8
8
|
const MarqueeCapture = ({
|
|
9
9
|
pageIndex,
|
|
10
10
|
scale,
|
|
11
|
-
pageWidth,
|
|
12
|
-
pageHeight,
|
|
13
11
|
className,
|
|
14
12
|
stroke = "rgba(33,150,243,0.8)",
|
|
15
13
|
fill = "rgba(33,150,243,0.15)"
|
|
16
14
|
}) => {
|
|
17
|
-
const { provides:
|
|
18
|
-
const { register } = usePointerHandlers({ modeId: "marqueeCapture", pageIndex });
|
|
19
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
20
|
-
const startRef = useRef(null);
|
|
15
|
+
const { provides: capturePlugin } = useCaptureCapability();
|
|
21
16
|
const [rect, setRect] = useState(null);
|
|
22
|
-
const pageWidthPDF = pageWidth / scale;
|
|
23
|
-
const pageHeightPDF = pageHeight / scale;
|
|
24
|
-
const handlers = useMemo(
|
|
25
|
-
() => ({
|
|
26
|
-
onPointerDown: (pos, evt) => {
|
|
27
|
-
var _a, _b;
|
|
28
|
-
startRef.current = pos;
|
|
29
|
-
setRect({ origin: { x: pos.x, y: pos.y }, size: { width: 0, height: 0 } });
|
|
30
|
-
(_b = (_a = evt.target) == null ? void 0 : _a.setPointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
|
|
31
|
-
},
|
|
32
|
-
onPointerMove: (pos) => {
|
|
33
|
-
if (!startRef.current) return;
|
|
34
|
-
const curX = clamp(pos.x, 0, pageWidthPDF);
|
|
35
|
-
const curY = clamp(pos.y, 0, pageHeightPDF);
|
|
36
|
-
const { x: sx, y: sy } = startRef.current;
|
|
37
|
-
const left = Math.min(sx, curX);
|
|
38
|
-
const top = Math.min(sy, curY);
|
|
39
|
-
const width = Math.abs(curX - sx);
|
|
40
|
-
const height = Math.abs(curY - sy);
|
|
41
|
-
setRect({ origin: { x: left, y: top }, size: { width, height } });
|
|
42
|
-
},
|
|
43
|
-
onPointerUp: (_, evt) => {
|
|
44
|
-
var _a, _b;
|
|
45
|
-
if (rect && capture) {
|
|
46
|
-
const dragPx = Math.max(rect.size.width, rect.size.height) * scale;
|
|
47
|
-
if (dragPx > 5) {
|
|
48
|
-
capture.captureArea(pageIndex, rect);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
startRef.current = null;
|
|
52
|
-
setRect(null);
|
|
53
|
-
(_b = (_a = evt.target) == null ? void 0 : _a.releasePointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
|
|
54
|
-
},
|
|
55
|
-
onPointerCancel: (_, evt) => {
|
|
56
|
-
var _a, _b;
|
|
57
|
-
startRef.current = null;
|
|
58
|
-
setRect(null);
|
|
59
|
-
(_b = (_a = evt.target) == null ? void 0 : _a.releasePointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
|
|
60
|
-
}
|
|
61
|
-
}),
|
|
62
|
-
[pageWidthPDF, pageWidthPDF, capture, scale, rect, pageIndex]
|
|
63
|
-
);
|
|
64
17
|
useEffect(() => {
|
|
65
|
-
if (!
|
|
66
|
-
return
|
|
67
|
-
|
|
18
|
+
if (!capturePlugin) return;
|
|
19
|
+
return capturePlugin.registerMarqueeOnPage({
|
|
20
|
+
pageIndex,
|
|
21
|
+
scale,
|
|
22
|
+
callback: {
|
|
23
|
+
onPreview: setRect
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}, [capturePlugin, pageIndex, scale]);
|
|
68
27
|
if (!rect) return null;
|
|
69
28
|
return /* @__PURE__ */ jsx(
|
|
70
29
|
"div",
|
package/dist/preact/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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,
|
|
1
|
+
{"version":3,"file":"index.js","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, useState } from '@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 /** 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\nexport const MarqueeCapture = ({\n pageIndex,\n scale,\n className,\n stroke = 'rgba(33,150,243,0.8)',\n fill = 'rgba(33,150,243,0.15)',\n}: MarqueeCaptureProps) => {\n const { provides: capturePlugin } = useCaptureCapability();\n const [rect, setRect] = useState<Rect | null>(null);\n\n useEffect(() => {\n if (!capturePlugin) return;\n return capturePlugin.registerMarqueeOnPage({\n pageIndex,\n scale,\n callback: {\n onPreview: setRect,\n },\n });\n }, [capturePlugin, pageIndex, scale]);\n\n if (!rect) return null;\n\n return (\n <div\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":[],"mappings":";;;;;AAGO,MAAM,uBAAuB,MAAM,cAA6B,cAAc,EAAE;AAChF,MAAM,mBAAmB,MAAM,UAAyB,cAAc,EAAE;ACaxE,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,OAAO;AACT,MAA2B;AACzB,QAAM,EAAE,UAAU,cAAc,IAAI,qBAAqB;AACzD,QAAM,CAAC,MAAM,OAAO,IAAI,SAAsB,IAAI;AAElD,YAAU,MAAM;AACd,QAAI,CAAC,cAAe;AACpB,WAAO,cAAc,sBAAsB;AAAA,MACzC;AAAA,MACA;AAAA,MACA,UAAU;AAAA,QACR,WAAW;AAAA,MAAA;AAAA,IACb,CACD;AAAA,EACA,GAAA,CAAC,eAAe,WAAW,KAAK,CAAC;AAEhC,MAAA,CAAC,KAAa,QAAA;AAGhB,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,UAAU;AAAA,QACV,eAAe;AAAA,QACf,MAAM,KAAK,OAAO,IAAI;AAAA,QACtB,KAAK,KAAK,OAAO,IAAI;AAAA,QACrB,OAAO,KAAK,KAAK,QAAQ;AAAA,QACzB,QAAQ,KAAK,KAAK,SAAS;AAAA,QAC3B,QAAQ,aAAa,MAAM;AAAA,QAC3B,YAAY;AAAA,QACZ,WAAW;AAAA,MACb;AAAA,MACA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
package/dist/react/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),r=require("@embedpdf/plugin-capture"),t=require("react/jsx-runtime"),i=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),r=require("@embedpdf/plugin-capture"),t=require("react/jsx-runtime"),i=require("react"),a=()=>e.useCapability(r.CapturePlugin.id);exports.MarqueeCapture=({pageIndex:e,scale:r,className:s,stroke:o="rgba(33,150,243,0.8)",fill:u="rgba(33,150,243,0.15)"})=>{const{provides:l}=a(),[n,p]=i.useState(null);return i.useEffect((()=>{if(l)return l.registerMarqueeOnPage({pageIndex:e,scale:r,callback:{onPreview:p}})}),[l,e,r]),n?t.jsx("div",{style:{position:"absolute",pointerEvents:"none",left:n.origin.x*r,top:n.origin.y*r,width:n.size.width*r,height:n.size.height*r,border:`1px solid ${o}`,background:u,boxSizing:"border-box"},className:s}):null},exports.useCaptureCapability=a,exports.useCapturePlugin=()=>e.usePlugin(r.CapturePlugin.id),Object.keys(r).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})}));
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/react/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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, useState } from '@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 /** 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\nexport const MarqueeCapture = ({\n pageIndex,\n scale,\n className,\n stroke = 'rgba(33,150,243,0.8)',\n fill = 'rgba(33,150,243,0.15)',\n}: MarqueeCaptureProps) => {\n const { provides: capturePlugin } = useCaptureCapability();\n const [rect, setRect] = useState<Rect | null>(null);\n\n useEffect(() => {\n if (!capturePlugin) return;\n return capturePlugin.registerMarqueeOnPage({\n pageIndex,\n scale,\n callback: {\n onPreview: setRect,\n },\n });\n }, [capturePlugin, pageIndex, scale]);\n\n if (!rect) return null;\n\n return (\n <div\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","className","stroke","fill","provides","capturePlugin","rect","setRect","useState","useEffect","registerMarqueeOnPage","callback","onPreview","jsxRuntime","jsx","style","position","pointerEvents","left","origin","x","top","y","width","size","height","border","background","boxSizing","usePlugin"],"mappings":"gNAGaA,EAAuB,IAAMC,gBAA6BC,EAAAA,cAAcC,2BCcvD,EAC5BC,YACAC,QACAC,YACAC,SAAS,uBACTC,OAAO,4BAEP,MAAQC,SAAUC,GAAkBV,KAC7BW,EAAMC,GAAWC,EAAAA,SAAsB,MAa1C,OAXJC,EAAAA,WAAU,KACR,GAAKJ,EACL,OAAOA,EAAcK,sBAAsB,CACzCX,YACAC,QACAW,SAAU,CACRC,UAAWL,IAEd,GACA,CAACF,EAAeN,EAAWC,IAEzBM,EAGHO,EAAAC,IAAC,MAAA,CACCC,MAAO,CACLC,SAAU,WACVC,cAAe,OACfC,KAAMZ,EAAKa,OAAOC,EAAIpB,EACtBqB,IAAKf,EAAKa,OAAOG,EAAItB,EACrBuB,MAAOjB,EAAKkB,KAAKD,MAAQvB,EACzByB,OAAQnB,EAAKkB,KAAKC,OAASzB,EAC3B0B,OAAQ,aAAaxB,IACrByB,WAAYxB,EACZyB,UAAW,cAEb3B,cAfc,IAgBhB,0DDlD4B,IAAM4B,YAAyBhC,EAAAA,cAAcC"}
|
package/dist/react/index.js
CHANGED
|
@@ -1,70 +1,29 @@
|
|
|
1
1
|
import { useCapability, usePlugin } from "@embedpdf/core/react";
|
|
2
2
|
import { CapturePlugin } from "@embedpdf/plugin-capture";
|
|
3
|
+
export * from "@embedpdf/plugin-capture";
|
|
3
4
|
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
import {
|
|
5
|
-
import { usePointerHandlers } from "@embedpdf/plugin-interaction-manager/react";
|
|
5
|
+
import { useState, useEffect } from "react";
|
|
6
6
|
const useCaptureCapability = () => useCapability(CapturePlugin.id);
|
|
7
7
|
const useCapturePlugin = () => usePlugin(CapturePlugin.id);
|
|
8
8
|
const MarqueeCapture = ({
|
|
9
9
|
pageIndex,
|
|
10
10
|
scale,
|
|
11
|
-
pageWidth,
|
|
12
|
-
pageHeight,
|
|
13
11
|
className,
|
|
14
12
|
stroke = "rgba(33,150,243,0.8)",
|
|
15
13
|
fill = "rgba(33,150,243,0.15)"
|
|
16
14
|
}) => {
|
|
17
|
-
const { provides:
|
|
18
|
-
const { register } = usePointerHandlers({ modeId: "marqueeCapture", pageIndex });
|
|
19
|
-
const clamp = (v, min, max) => Math.max(min, Math.min(max, v));
|
|
20
|
-
const startRef = useRef(null);
|
|
15
|
+
const { provides: capturePlugin } = useCaptureCapability();
|
|
21
16
|
const [rect, setRect] = useState(null);
|
|
22
|
-
const pageWidthPDF = pageWidth / scale;
|
|
23
|
-
const pageHeightPDF = pageHeight / scale;
|
|
24
|
-
const handlers = useMemo(
|
|
25
|
-
() => ({
|
|
26
|
-
onPointerDown: (pos, evt) => {
|
|
27
|
-
var _a, _b;
|
|
28
|
-
startRef.current = pos;
|
|
29
|
-
setRect({ origin: { x: pos.x, y: pos.y }, size: { width: 0, height: 0 } });
|
|
30
|
-
(_b = (_a = evt.target) == null ? void 0 : _a.setPointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
|
|
31
|
-
},
|
|
32
|
-
onPointerMove: (pos) => {
|
|
33
|
-
if (!startRef.current) return;
|
|
34
|
-
const curX = clamp(pos.x, 0, pageWidthPDF);
|
|
35
|
-
const curY = clamp(pos.y, 0, pageHeightPDF);
|
|
36
|
-
const { x: sx, y: sy } = startRef.current;
|
|
37
|
-
const left = Math.min(sx, curX);
|
|
38
|
-
const top = Math.min(sy, curY);
|
|
39
|
-
const width = Math.abs(curX - sx);
|
|
40
|
-
const height = Math.abs(curY - sy);
|
|
41
|
-
setRect({ origin: { x: left, y: top }, size: { width, height } });
|
|
42
|
-
},
|
|
43
|
-
onPointerUp: (_, evt) => {
|
|
44
|
-
var _a, _b;
|
|
45
|
-
if (rect && capture) {
|
|
46
|
-
const dragPx = Math.max(rect.size.width, rect.size.height) * scale;
|
|
47
|
-
if (dragPx > 5) {
|
|
48
|
-
capture.captureArea(pageIndex, rect);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
startRef.current = null;
|
|
52
|
-
setRect(null);
|
|
53
|
-
(_b = (_a = evt.target) == null ? void 0 : _a.releasePointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
|
|
54
|
-
},
|
|
55
|
-
onPointerCancel: (_, evt) => {
|
|
56
|
-
var _a, _b;
|
|
57
|
-
startRef.current = null;
|
|
58
|
-
setRect(null);
|
|
59
|
-
(_b = (_a = evt.target) == null ? void 0 : _a.releasePointerCapture) == null ? void 0 : _b.call(_a, evt.pointerId);
|
|
60
|
-
}
|
|
61
|
-
}),
|
|
62
|
-
[pageWidthPDF, pageWidthPDF, capture, scale, rect, pageIndex]
|
|
63
|
-
);
|
|
64
17
|
useEffect(() => {
|
|
65
|
-
if (!
|
|
66
|
-
return
|
|
67
|
-
|
|
18
|
+
if (!capturePlugin) return;
|
|
19
|
+
return capturePlugin.registerMarqueeOnPage({
|
|
20
|
+
pageIndex,
|
|
21
|
+
scale,
|
|
22
|
+
callback: {
|
|
23
|
+
onPreview: setRect
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}, [capturePlugin, pageIndex, scale]);
|
|
68
27
|
if (!rect) return null;
|
|
69
28
|
return /* @__PURE__ */ jsx(
|
|
70
29
|
"div",
|
package/dist/react/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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,
|
|
1
|
+
{"version":3,"file":"index.js","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, useState } from '@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 /** 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\nexport const MarqueeCapture = ({\n pageIndex,\n scale,\n className,\n stroke = 'rgba(33,150,243,0.8)',\n fill = 'rgba(33,150,243,0.15)',\n}: MarqueeCaptureProps) => {\n const { provides: capturePlugin } = useCaptureCapability();\n const [rect, setRect] = useState<Rect | null>(null);\n\n useEffect(() => {\n if (!capturePlugin) return;\n return capturePlugin.registerMarqueeOnPage({\n pageIndex,\n scale,\n callback: {\n onPreview: setRect,\n },\n });\n }, [capturePlugin, pageIndex, scale]);\n\n if (!rect) return null;\n\n return (\n <div\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":[],"mappings":";;;;;AAGO,MAAM,uBAAuB,MAAM,cAA6B,cAAc,EAAE;AAChF,MAAM,mBAAmB,MAAM,UAAyB,cAAc,EAAE;ACaxE,MAAM,iBAAiB,CAAC;AAAA,EAC7B;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT,OAAO;AACT,MAA2B;AACzB,QAAM,EAAE,UAAU,cAAc,IAAI,qBAAqB;AACzD,QAAM,CAAC,MAAM,OAAO,IAAI,SAAsB,IAAI;AAElD,YAAU,MAAM;AACd,QAAI,CAAC,cAAe;AACpB,WAAO,cAAc,sBAAsB;AAAA,MACzC;AAAA,MACA;AAAA,MACA,UAAU;AAAA,QACR,WAAW;AAAA,MAAA;AAAA,IACb,CACD;AAAA,EACA,GAAA,CAAC,eAAe,WAAW,KAAK,CAAC;AAEhC,MAAA,CAAC,KAAa,QAAA;AAGhB,SAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,OAAO;AAAA,QACL,UAAU;AAAA,QACV,eAAe;AAAA,QACf,MAAM,KAAK,OAAO,IAAI;AAAA,QACtB,KAAK,KAAK,OAAO,IAAI;AAAA,QACrB,OAAO,KAAK,KAAK,QAAQ;AAAA,QACzB,QAAQ,KAAK,KAAK,SAAS;AAAA,QAC3B,QAAQ,aAAa,MAAM;AAAA,QAC3B,YAAY;AAAA,QACZ,WAAW;AAAA,MACb;AAAA,MACA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
@@ -3,19 +3,11 @@ interface MarqueeCaptureProps {
|
|
|
3
3
|
pageIndex: number;
|
|
4
4
|
/** Scale of the page */
|
|
5
5
|
scale: number;
|
|
6
|
-
/** Width of the page */
|
|
7
|
-
pageWidth: number;
|
|
8
|
-
/** Height of the page */
|
|
9
|
-
pageHeight: number;
|
|
10
6
|
/** Optional CSS class applied to the marquee rectangle */
|
|
11
7
|
className?: string;
|
|
12
8
|
/** Stroke / fill colours (defaults below) */
|
|
13
9
|
stroke?: string;
|
|
14
10
|
fill?: string;
|
|
15
11
|
}
|
|
16
|
-
|
|
17
|
-
* Draws a marquee rectangle while the user drags.
|
|
18
|
-
* Hook it into the interaction-manager with modeId = 'marqueeCapture'.
|
|
19
|
-
*/
|
|
20
|
-
export declare const MarqueeCapture: ({ pageIndex, scale, pageWidth, pageHeight, className, stroke, fill, }: MarqueeCaptureProps) => import("preact").JSX.Element | null;
|
|
12
|
+
export declare const MarqueeCapture: ({ pageIndex, scale, className, stroke, fill, }: MarqueeCaptureProps) => import("preact").JSX.Element | null;
|
|
21
13
|
export {};
|
|
@@ -3,19 +3,11 @@ interface MarqueeCaptureProps {
|
|
|
3
3
|
pageIndex: number;
|
|
4
4
|
/** Scale of the page */
|
|
5
5
|
scale: number;
|
|
6
|
-
/** Width of the page */
|
|
7
|
-
pageWidth: number;
|
|
8
|
-
/** Height of the page */
|
|
9
|
-
pageHeight: number;
|
|
10
6
|
/** Optional CSS class applied to the marquee rectangle */
|
|
11
7
|
className?: string;
|
|
12
8
|
/** Stroke / fill colours (defaults below) */
|
|
13
9
|
stroke?: string;
|
|
14
10
|
fill?: string;
|
|
15
11
|
}
|
|
16
|
-
|
|
17
|
-
* Draws a marquee rectangle while the user drags.
|
|
18
|
-
* Hook it into the interaction-manager with modeId = 'marqueeCapture'.
|
|
19
|
-
*/
|
|
20
|
-
export declare const MarqueeCapture: ({ pageIndex, scale, pageWidth, pageHeight, className, stroke, fill, }: MarqueeCaptureProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
12
|
+
export declare const MarqueeCapture: ({ pageIndex, scale, className, stroke, fill, }: MarqueeCaptureProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
21
13
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as MarqueeCapture } from './marquee-capture.vue';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface MarqueeCaptureProps {
|
|
2
|
+
/** Index of the page this layer lives on */
|
|
3
|
+
pageIndex: number;
|
|
4
|
+
/** Scale of the page */
|
|
5
|
+
scale: number;
|
|
6
|
+
/** Optional CSS class applied to the marquee rectangle */
|
|
7
|
+
className?: string;
|
|
8
|
+
/** Stroke / fill colours (defaults below) */
|
|
9
|
+
stroke?: string;
|
|
10
|
+
fill?: string;
|
|
11
|
+
}
|
|
12
|
+
declare const _default: import('vue').DefineComponent<MarqueeCaptureProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<MarqueeCaptureProps> & Readonly<{}>, {
|
|
13
|
+
fill: string;
|
|
14
|
+
stroke: string;
|
|
15
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
|
|
16
|
+
export default _default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './use-capture';
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { CapturePlugin } from '../../lib/index.ts';
|
|
2
|
+
export declare const useCaptureCapability: () => import('@embedpdf/core/vue').CapabilityState<Readonly<import('../../lib/index.ts').CaptureCapability>>;
|
|
3
|
+
export declare const useCapturePlugin: () => import('@embedpdf/core/vue').PluginState<CapturePlugin>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/vue"),a=require("@embedpdf/plugin-capture"),t=require("vue"),l=()=>e.useCapability(a.CapturePlugin.id),r=t.defineComponent({__name:"marquee-capture",props:{pageIndex:{},scale:{},className:{},stroke:{default:"rgba(33,150,243,0.8)"},fill:{default:"rgba(33,150,243,0.15)"}},setup(e){const a=e,{provides:r}=l(),o=t.ref(null);let u;return t.onMounted((()=>{r.value&&(u=r.value.registerMarqueeOnPage({pageIndex:a.pageIndex,scale:a.scale,callback:{onPreview:e=>{o.value=e}}}))})),t.onUnmounted((()=>{null==u||u()})),(e,a)=>o.value?(t.openBlock(),t.createElementBlock("div",{key:0,style:t.normalizeStyle({position:"absolute",pointerEvents:"none",left:o.value.origin.x*e.scale+"px",top:o.value.origin.y*e.scale+"px",width:o.value.size.width*e.scale+"px",height:o.value.size.height*e.scale+"px",border:`1px solid ${e.stroke}`,background:e.fill,boxSizing:"border-box"}),class:t.normalizeClass(e.className)},null,6)):t.createCommentVNode("",!0)}});exports.MarqueeCapture=r,exports.useCaptureCapability=l,exports.useCapturePlugin=()=>e.usePlugin(a.CapturePlugin.id),Object.keys(a).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>a[e]})}));
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-capture.ts","../../src/vue/components/marquee-capture.vue"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { CapturePlugin } from '@embedpdf/plugin-capture';\n\nexport const useCaptureCapability = () => useCapability<CapturePlugin>(CapturePlugin.id);\nexport const useCapturePlugin = () => usePlugin<CapturePlugin>(CapturePlugin.id);\n","<template>\n <div\n v-if=\"rect\"\n :style=\"{\n position: 'absolute',\n pointerEvents: 'none',\n left: `${rect.origin.x * scale}px`,\n top: `${rect.origin.y * scale}px`,\n width: `${rect.size.width * scale}px`,\n height: `${rect.size.height * scale}px`,\n border: `1px solid ${stroke}`,\n background: fill,\n boxSizing: 'border-box',\n }\"\n :class=\"className\"\n />\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted } from 'vue';\nimport type { Rect } from '@embedpdf/models';\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 /** 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\nconst props = withDefaults(defineProps<MarqueeCaptureProps>(), {\n stroke: 'rgba(33,150,243,0.8)',\n fill: 'rgba(33,150,243,0.15)',\n});\n\nconst { provides: capturePlugin } = useCaptureCapability();\nconst rect = ref<Rect | null>(null);\n\nlet unregister: (() => void) | undefined;\n\nonMounted(() => {\n if (!capturePlugin.value) return;\n\n unregister = capturePlugin.value.registerMarqueeOnPage({\n pageIndex: props.pageIndex,\n scale: props.scale,\n callback: {\n onPreview: (newRect) => {\n rect.value = newRect;\n },\n },\n });\n});\n\nonUnmounted(() => {\n unregister?.();\n});\n</script>\n"],"names":["useCaptureCapability","useCapability","CapturePlugin","id","props","__props","provides","capturePlugin","rect","ref","unregister","onMounted","value","registerMarqueeOnPage","pageIndex","scale","callback","onPreview","newRect","onUnmounted","_createElementBlock","style","_normalizeStyle","left","origin","x","top","y","width","size","height","stroke","fill","class","className","usePlugin"],"mappings":"6KAGaA,EAAuB,IAAMC,gBAA6BC,EAAAA,cAAcC,qLCgCrF,MAAMC,EAAQC,GAKNC,SAAUC,GAAkBP,IAC9BQ,EAAOC,MAAiB,MAE1B,IAAAC,SAEJC,EAAAA,WAAU,KACHJ,EAAcK,QAENF,EAAAH,EAAcK,MAAMC,sBAAsB,CACrDC,UAAWV,EAAMU,UACjBC,MAAOX,EAAMW,MACbC,SAAU,CACRC,UAAYC,IACVV,EAAKI,MAAQM,CAAA,KAGlB,IAGHC,EAAAA,aAAY,KACG,MAAAT,GAAAA,GAAA,WA1DLF,EAAII,qBADZQ,EAAAA,mBAcE,MAAA,OAZCC,MAAKC,EAAAA,eAAA,0CAA4EC,KAAAf,EAAAI,MAAKY,OAAOC,EAAIV,EAAKA,MAArB,KAAyCW,IAAAlB,EAAAI,MAAKY,OAAOG,EAAIZ,EAAKA,MAArB,KAA2Ca,MAAApB,EAAAI,MAAKiB,KAAKD,MAAQb,EAAKA,MAAvB,KAA8Ce,OAAAtB,EAAAI,MAAKiB,KAAKC,OAASf,EAAKA,MAAxB,yBAAyDgB,EAAMA,oBAAsBC,EAAIA,8BAW5SC,uBAAOC,EAASA,qIDVW,IAAMC,YAAyBjC,EAAAA,cAAcC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useCapability, usePlugin } from "@embedpdf/core/vue";
|
|
2
|
+
import { CapturePlugin } from "@embedpdf/plugin-capture";
|
|
3
|
+
export * from "@embedpdf/plugin-capture";
|
|
4
|
+
import { defineComponent, ref, onMounted, onUnmounted, createElementBlock, createCommentVNode, openBlock, normalizeClass, normalizeStyle } from "vue";
|
|
5
|
+
const useCaptureCapability = () => useCapability(CapturePlugin.id);
|
|
6
|
+
const useCapturePlugin = () => usePlugin(CapturePlugin.id);
|
|
7
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
8
|
+
__name: "marquee-capture",
|
|
9
|
+
props: {
|
|
10
|
+
pageIndex: {},
|
|
11
|
+
scale: {},
|
|
12
|
+
className: {},
|
|
13
|
+
stroke: { default: "rgba(33,150,243,0.8)" },
|
|
14
|
+
fill: { default: "rgba(33,150,243,0.15)" }
|
|
15
|
+
},
|
|
16
|
+
setup(__props) {
|
|
17
|
+
const props = __props;
|
|
18
|
+
const { provides: capturePlugin } = useCaptureCapability();
|
|
19
|
+
const rect = ref(null);
|
|
20
|
+
let unregister;
|
|
21
|
+
onMounted(() => {
|
|
22
|
+
if (!capturePlugin.value) return;
|
|
23
|
+
unregister = capturePlugin.value.registerMarqueeOnPage({
|
|
24
|
+
pageIndex: props.pageIndex,
|
|
25
|
+
scale: props.scale,
|
|
26
|
+
callback: {
|
|
27
|
+
onPreview: (newRect) => {
|
|
28
|
+
rect.value = newRect;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
onUnmounted(() => {
|
|
34
|
+
unregister == null ? void 0 : unregister();
|
|
35
|
+
});
|
|
36
|
+
return (_ctx, _cache) => {
|
|
37
|
+
return rect.value ? (openBlock(), createElementBlock("div", {
|
|
38
|
+
key: 0,
|
|
39
|
+
style: normalizeStyle({
|
|
40
|
+
position: "absolute",
|
|
41
|
+
pointerEvents: "none",
|
|
42
|
+
left: `${rect.value.origin.x * _ctx.scale}px`,
|
|
43
|
+
top: `${rect.value.origin.y * _ctx.scale}px`,
|
|
44
|
+
width: `${rect.value.size.width * _ctx.scale}px`,
|
|
45
|
+
height: `${rect.value.size.height * _ctx.scale}px`,
|
|
46
|
+
border: `1px solid ${_ctx.stroke}`,
|
|
47
|
+
background: _ctx.fill,
|
|
48
|
+
boxSizing: "border-box"
|
|
49
|
+
}),
|
|
50
|
+
class: normalizeClass(_ctx.className)
|
|
51
|
+
}, null, 6)) : createCommentVNode("", true);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
export {
|
|
56
|
+
_sfc_main as MarqueeCapture,
|
|
57
|
+
useCaptureCapability,
|
|
58
|
+
useCapturePlugin
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-capture.ts","../../src/vue/components/marquee-capture.vue"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { CapturePlugin } from '@embedpdf/plugin-capture';\n\nexport const useCaptureCapability = () => useCapability<CapturePlugin>(CapturePlugin.id);\nexport const useCapturePlugin = () => usePlugin<CapturePlugin>(CapturePlugin.id);\n","<template>\n <div\n v-if=\"rect\"\n :style=\"{\n position: 'absolute',\n pointerEvents: 'none',\n left: `${rect.origin.x * scale}px`,\n top: `${rect.origin.y * scale}px`,\n width: `${rect.size.width * scale}px`,\n height: `${rect.size.height * scale}px`,\n border: `1px solid ${stroke}`,\n background: fill,\n boxSizing: 'border-box',\n }\"\n :class=\"className\"\n />\n</template>\n\n<script setup lang=\"ts\">\nimport { ref, onMounted, onUnmounted } from 'vue';\nimport type { Rect } from '@embedpdf/models';\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 /** 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\nconst props = withDefaults(defineProps<MarqueeCaptureProps>(), {\n stroke: 'rgba(33,150,243,0.8)',\n fill: 'rgba(33,150,243,0.15)',\n});\n\nconst { provides: capturePlugin } = useCaptureCapability();\nconst rect = ref<Rect | null>(null);\n\nlet unregister: (() => void) | undefined;\n\nonMounted(() => {\n if (!capturePlugin.value) return;\n\n unregister = capturePlugin.value.registerMarqueeOnPage({\n pageIndex: props.pageIndex,\n scale: props.scale,\n callback: {\n onPreview: (newRect) => {\n rect.value = newRect;\n },\n },\n });\n});\n\nonUnmounted(() => {\n unregister?.();\n});\n</script>\n"],"names":["_createElementBlock","_normalizeStyle","scale","stroke","fill","className"],"mappings":";;;;AAGO,MAAM,uBAAuB,MAAM,cAA6B,cAAc,EAAE;AAChF,MAAM,mBAAmB,MAAM,UAAyB,cAAc,EAAE;;;;;;;;;;;AC+B/E,UAAM,QAAQ;AAKd,UAAM,EAAE,UAAU,cAAc,IAAI,qBAAqB;AACnD,UAAA,OAAO,IAAiB,IAAI;AAE9B,QAAA;AAEJ,cAAU,MAAM;AACV,UAAA,CAAC,cAAc,MAAO;AAEb,mBAAA,cAAc,MAAM,sBAAsB;AAAA,QACrD,WAAW,MAAM;AAAA,QACjB,OAAO,MAAM;AAAA,QACb,UAAU;AAAA,UACR,WAAW,CAAC,YAAY;AACtB,iBAAK,QAAQ;AAAA,UAAA;AAAA,QACf;AAAA,MACF,CACD;AAAA,IAAA,CACF;AAED,gBAAY,MAAM;AACH;AAAA,IAAA,CACd;;aA3DS,KAAI,sBADZA,mBAcE,OAAA;AAAA;QAZC,OAAKC,eAAA;AAAA;;UAA4E,MAAA,GAAA,KAAA,MAAK,OAAO,IAAIC,KAAK,KAAA;AAAA,UAAoB,KAAA,GAAA,KAAA,MAAK,OAAO,IAAIA,KAAK,KAAA;AAAA,UAAsB,OAAA,GAAA,KAAA,MAAK,KAAK,QAAQA,KAAK,KAAA;AAAA,UAAuB,QAAA,GAAA,KAAA,MAAK,KAAK,SAASA,KAAK,KAAA;AAAA,+BAAiCC,KAAM,MAAA;AAAA,sBAAsBC,KAAI;AAAA;;QAW5S,sBAAOC,KAAS,SAAA;AAAA;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embedpdf/plugin-capture",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.21",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -20,26 +20,32 @@
|
|
|
20
20
|
"types": "./dist/react/index.d.ts",
|
|
21
21
|
"import": "./dist/react/index.js",
|
|
22
22
|
"require": "./dist/react/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./vue": {
|
|
25
|
+
"types": "./dist/vue/index.d.ts",
|
|
26
|
+
"import": "./dist/vue/index.js",
|
|
27
|
+
"require": "./dist/vue/index.cjs"
|
|
23
28
|
}
|
|
24
29
|
},
|
|
25
30
|
"dependencies": {
|
|
26
|
-
"@embedpdf/models": "1.0.
|
|
31
|
+
"@embedpdf/models": "1.0.21"
|
|
27
32
|
},
|
|
28
33
|
"devDependencies": {
|
|
29
34
|
"@types/react": "^18.2.0",
|
|
30
35
|
"typescript": "^5.0.0",
|
|
31
36
|
"@embedpdf/build": "1.0.0",
|
|
32
|
-
"@embedpdf/core": "1.0.
|
|
33
|
-
"@embedpdf/plugin-render": "1.0.
|
|
34
|
-
"@embedpdf/plugin-interaction-manager": "1.0.
|
|
37
|
+
"@embedpdf/core": "1.0.21",
|
|
38
|
+
"@embedpdf/plugin-render": "1.0.21",
|
|
39
|
+
"@embedpdf/plugin-interaction-manager": "1.0.21"
|
|
35
40
|
},
|
|
36
41
|
"peerDependencies": {
|
|
37
42
|
"react": ">=16.8.0",
|
|
38
43
|
"react-dom": ">=16.8.0",
|
|
39
44
|
"preact": "^10.26.4",
|
|
40
|
-
"
|
|
41
|
-
"@embedpdf/
|
|
42
|
-
"@embedpdf/plugin-
|
|
45
|
+
"vue": ">=3.2.0",
|
|
46
|
+
"@embedpdf/core": "1.0.21",
|
|
47
|
+
"@embedpdf/plugin-interaction-manager": "1.0.21",
|
|
48
|
+
"@embedpdf/plugin-render": "1.0.21"
|
|
43
49
|
},
|
|
44
50
|
"files": [
|
|
45
51
|
"dist",
|
|
@@ -61,7 +67,8 @@
|
|
|
61
67
|
"build:base": "vite build --mode base",
|
|
62
68
|
"build:react": "vite build --mode react",
|
|
63
69
|
"build:preact": "vite build --mode preact",
|
|
64
|
-
"build": "
|
|
70
|
+
"build:vue": "vite build --mode vue",
|
|
71
|
+
"build": "pnpm run clean && concurrently -c auto -n base,react,preact,vue \"vite build --mode base\" \"vite build --mode react\" \"vite build --mode preact\" \"vite build --mode vue\"",
|
|
65
72
|
"clean": "rimraf dist",
|
|
66
73
|
"lint": "eslint src --color",
|
|
67
74
|
"lint:fix": "eslint src --color --fix"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@embedpdf/plugin-interaction-manager/preact';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@embedpdf/plugin-interaction-manager/react';
|