@embedpdf/plugin-selection 1.5.0 → 2.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +449 -169
- package/dist/index.js.map +1 -1
- package/dist/lib/actions.d.ts +61 -24
- package/dist/lib/reducer.d.ts +2 -1
- package/dist/lib/selection-plugin.d.ts +27 -6
- package/dist/lib/selectors.d.ts +7 -7
- package/dist/lib/types.d.ts +68 -9
- package/dist/preact/index.cjs +1 -1
- package/dist/preact/index.cjs.map +1 -1
- package/dist/preact/index.js +88 -34
- package/dist/preact/index.js.map +1 -1
- package/dist/preact/utils.d.ts +1 -0
- package/dist/react/index.cjs +1 -1
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +88 -34
- package/dist/react/index.js.map +1 -1
- package/dist/react/utils.d.ts +1 -0
- package/dist/shared/components/selection-layer.d.ts +7 -2
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/types.d.ts +7 -0
- package/dist/shared-preact/components/selection-layer.d.ts +7 -2
- package/dist/shared-preact/index.d.ts +1 -0
- package/dist/shared-preact/types.d.ts +7 -0
- package/dist/shared-react/components/selection-layer.d.ts +7 -2
- package/dist/shared-react/index.d.ts +1 -0
- package/dist/shared-react/types.d.ts +7 -0
- package/dist/svelte/components/SelectionLayer.svelte.d.ts +13 -2
- package/dist/svelte/index.cjs +1 -1
- package/dist/svelte/index.cjs.map +1 -1
- package/dist/svelte/index.d.ts +1 -0
- package/dist/svelte/index.js +161 -34
- package/dist/svelte/index.js.map +1 -1
- package/dist/svelte/types.d.ts +7 -0
- package/dist/vue/components/copy-to-clipboard.vue.d.ts +2 -1
- package/dist/vue/components/selection-layer.vue.d.ts +27 -3
- package/dist/vue/index.cjs +1 -1
- package/dist/vue/index.cjs.map +1 -1
- package/dist/vue/index.d.ts +1 -0
- package/dist/vue/index.js +137 -43
- package/dist/vue/index.js.map +1 -1
- package/dist/vue/types.d.ts +7 -0
- package/package.json +9 -8
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/models"),i="selection",n={id:i,name:"Selection Plugin",version:"1.0.0",provides:["selection"],requires:["interaction-manager"],optional:[],defaultConfig:{enabled:!0}},s="CACHE_PAGE_GEOMETRY",o="SET_SELECTION",r="START_SELECTION",a="END_SELECTION",c="CLEAR_SELECTION",h="SET_RECTS",l="SET_SLICES",g="RESET";function d(e,t){return e.rects[t]??[]}function u(e,i){return t.boundingRect(d(e,i))}function p(e,t){for(const i of e.runs){if(!(t.y>=i.rect.y&&t.y<=i.rect.y+i.rect.height&&t.x>=i.rect.x&&t.x<=i.rect.x+i.rect.width))continue;const e=i.glyphs.findIndex((e=>t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height));if(-1!==e)return i.charStart+e}return-1}function y(e,t,i){if(!e||!t)return null;if(i<e.start.page||i>e.end.page)return null;const n=i===e.start.page?e.start.index:0,s=t.runs[t.runs.length-1],o=s.charStart+s.glyphs.length-1;return{from:n,to:i===e.end.page?e.end.index:o}}function f(e,t,i,n=!0){const s=[];for(const o of e.runs){const e=o.charStart,n=e+o.glyphs.length-1;if(n<t||e>i)continue;const r=Math.max(t,e)-e,a=Math.min(i,n)-e;let c=1/0,h=-1/0,l=1/0,g=-1/0,d=0;for(let t=r;t<=a;t++){const e=o.glyphs[t];2!==e.flags&&(c=Math.min(c,e.x),h=Math.max(h,e.x+e.width),l=Math.min(l,e.y),g=Math.max(g,e.y+e.height),d++)}c!==1/0&&d>0&&s.push({rect:{origin:{x:c,y:l},size:{width:h-c,height:g-l}},charCount:d})}return n?E(s):s.map((e=>e.rect))}function x(e,t){const i=Math.min(e.origin.x,t.origin.x),n=Math.min(e.origin.y,t.origin.y);return{origin:{x:i,y:n},size:{width:Math.max(e.origin.x+e.size.width,t.origin.x+t.size.width)-i,height:Math.max(e.origin.y+e.size.height,t.origin.y+t.size.height)-n}}}function m(e,t){const i=Math.max(e.origin.x,t.origin.x),n=Math.max(e.origin.y,t.origin.y),s=Math.min(e.origin.x+e.size.width,t.origin.x+t.size.width),o=Math.min(e.origin.y+e.size.height,t.origin.y+t.size.height);return{origin:{x:i,y:n},size:{width:Math.max(0,s-i),height:Math.max(0,o-n)}}}function S(e){return e.size.width<=0||e.size.height<=0}function C(e,t){if(S(e)||S(t))return 0;const i=x(e,t);if(i.size.height===e.size.height||i.size.height===t.size.height)return 1;return m(e,t).size.height/i.size.height}function b(e,t){const i=e.rect,n=t.rect;if(C(i,n)<.8)return!1;const s=1*i.size.width/e.charCount,o=1*n.size.width/t.charCount,r=i.origin.x-s,a=i.origin.x+i.size.width+s,c=n.origin.x-o;return r<n.origin.x+n.size.width+o&&a>c}function E(e){const t=[];let i=null,n=null;for(const s of e)i&&n?b(i,s)?n=x(n,s.rect):(t.push(n),n=s.rect):n=s.rect,i=s;return n&&!S(n)&&t.push(n),t}const M=class extends e.BasePlugin{constructor(i,n){var s;super(i,n),this.enabledModes=new Set(["pointerMode"]),this.selecting=!1,this.pageCallbacks=new Map,this.selChange$=e.createBehaviorEmitter(),this.textRetrieved$=e.createBehaviorEmitter(),this.copyToClipboard$=e.createEmitter(),this.beginSelection$=e.createEmitter(),this.endSelection$=e.createEmitter(),this.interactionManagerCapability=null==(s=this.registry.getPlugin("interaction-manager"))?void 0:s.provides(),this.coreStore.onAction(e.SET_DOCUMENT,(e=>{this.dispatch({type:g}),this.notifyAllPages()})),this.coreStore.onAction(e.REFRESH_PAGES,(e=>{const i=e.payload.map((e=>this.getNewPageGeometryAndCache(e)));t.Task.all(i).wait((()=>{e.payload.forEach((e=>{this.notifyPage(e)}))}),t.ignore)}))}async initialize(){}async destroy(){this.selChange$.clear()}buildCapability(){return{getFormattedSelection:()=>function(e){const t=[],i=Object.keys(e.rects).map(Number);for(const n of i){const i=e.rects[n]||[];if(0===i.length)continue;const s=u(e,n);s&&t.push({pageIndex:n,rect:s,segmentRects:i})}return t}(this.state),getFormattedSelectionForPage:e=>function(e,t){const i=e.rects[t]||[];if(0===i.length)return null;const n=u(e,t);return n?{pageIndex:t,rect:n,segmentRects:i}:null}(this.state,e),getHighlightRectsForPage:e=>d(this.state,e),getHighlightRects:()=>this.state.rects,getBoundingRectForPage:e=>u(this.state,e),getBoundingRects:()=>function(e){const i=[],n=e.rects;for(const s in n){const e=Number(s),o=t.boundingRect(n[e]);o&&i.push({page:e,rect:o})}return i}(this.state),onCopyToClipboard:this.copyToClipboard$.on,onSelectionChange:this.selChange$.on,onTextRetrieved:this.textRetrieved$.on,onBeginSelection:this.beginSelection$.on,onEndSelection:this.endSelection$.on,clear:()=>this.clearSelection(),getSelectedText:()=>this.getSelectedText(),copyToClipboard:()=>this.copyToClipboard(),enableForMode:e=>this.enabledModes.add(e),isEnabledForMode:e=>this.enabledModes.has(e),getState:()=>this.state}}registerSelectionOnPage(e){if(!this.interactionManagerCapability)return this.logger.warn("SelectionPlugin","MissingDependency","Interaction manager plugin not loaded, text selection disabled"),()=>{};const{pageIndex:i,onRectsChange:n}=e;this.pageCallbacks.set(i,n);const s=this.getOrLoadGeometry(i);n({rects:d(this.state,i),boundingRect:u(this.state,i)});const o={onPointerDown:(e,t,n)=>{if(!this.enabledModes.has(n))return;this.clearSelection();const s=this.state.geometry[i];if(s){const t=p(s,e);-1!==t&&this.beginSelection(i,t)}},onPointerMove:(e,t,n)=>{var s,o;if(!this.enabledModes.has(n))return;const r=this.state.geometry[i];if(r){const t=p(r,e);-1!==t?null==(s=this.interactionManagerCapability)||s.setCursor("selection-text","text",10):null==(o=this.interactionManagerCapability)||o.removeCursor("selection-text"),this.selecting&&-1!==t&&this.updateSelection(i,t)}},onPointerUp:(e,t,i)=>{this.enabledModes.has(i)&&this.endSelection()},onHandlerActiveEnd:e=>{this.enabledModes.has(e)&&this.clearSelection()}},r=this.interactionManagerCapability.registerAlways({scope:{type:"page",pageIndex:i},handlers:o});return()=>{r(),this.pageCallbacks.delete(i),s.abort({code:t.PdfErrorCode.Cancelled,message:"Cleanup"})}}notifyPage(e){var t;const i=this.pageCallbacks.get(e);if(i){i("pointerMode"===(null==(t=this.interactionManagerCapability)?void 0:t.getActiveMode())?{rects:d(this.state,e),boundingRect:u(this.state,e)}:{rects:[],boundingRect:null})}}notifyAllPages(){this.pageCallbacks.forEach(((e,t)=>{this.notifyPage(t)}))}getNewPageGeometryAndCache(e){if(!this.coreState.core.document)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Doc Not Found"});const i=this.coreState.core.document.pages.find((t=>t.index===e)),n=this.engine.getPageGeometry(this.coreState.core.document,i);return n.wait((t=>{this.dispatch(((e,t)=>({type:s,payload:{page:e,geo:t}}))(e,t))}),t.ignore),n}getOrLoadGeometry(e){const i=this.state.geometry[e];return i?t.PdfTaskHelper.resolve(i):this.getNewPageGeometryAndCache(e)}beginSelection(e,t){this.selecting=!0,this.anchor={page:e,index:t},this.dispatch({type:r}),this.beginSelection$.emit({page:e,index:t})}endSelection(){this.selecting=!1,this.anchor=void 0,this.dispatch({type:a}),this.endSelection$.emit()}clearSelection(){this.selecting=!1,this.anchor=void 0,this.dispatch({type:c}),this.selChange$.emit(null),this.notifyAllPages()}updateSelection(e,t){if(!this.selecting||!this.anchor)return;const i=this.anchor,n=e>i.page||e===i.page&&t>=i.index,s={start:n?i:{page:e,index:t},end:n?{page:e,index:t}:i};this.dispatch({type:o,payload:s}),this.updateRectsAndSlices(s),this.selChange$.emit(s);for(let o=s.start.page;o<=s.end.page;o++)this.notifyPage(o)}updateRectsAndSlices(e){const t={},i={};for(let n=e.start.page;n<=e.end.page;n++){const s=this.state.geometry[n],o=y(e,s,n);o&&(t[n]=f(s,o.from,o.to),i[n]={start:o.from,count:o.to-o.from+1})}this.dispatch((e=>({type:h,payload:e}))(t)),this.dispatch({type:l,payload:i})}getSelectedText(){if(!this.coreState.core.document||!this.state.selection)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Doc Not Found or No Selection"});const e=this.state.selection,i=[];for(let t=e.start.page;t<=e.end.page;t++){const e=this.state.slices[t];e&&i.push({pageIndex:t,charIndex:e.start,charCount:e.count})}if(0===i.length)return t.PdfTaskHelper.resolve([]);const n=this.engine.getTextSlices(this.coreState.core.document,i);return n.wait((e=>{this.textRetrieved$.emit(e)}),t.ignore),n}copyToClipboard(){this.getSelectedText().wait((e=>{this.copyToClipboard$.emit(e.join("\n"))}),t.ignore)}};M.id="selection";let P=M;const T={geometry:{},rects:{},slices:{},selection:null,active:!1,selecting:!1},w={manifest:n,create:e=>new P(i,e),reducer:(e=T,t)=>{switch(t.type){case s:{const{page:i,geo:n}=t.payload;return{...e,geometry:{...e.geometry,[i]:n}}}case o:return{...e,selection:t.payload,active:!0};case r:return{...e,selecting:!0,selection:null,rects:{}};case a:return{...e,selecting:!1};case c:return{...e,selecting:!1,selection:null,rects:{},active:!1};case h:return{...e,rects:t.payload};case l:return{...e,slices:t.payload};case g:return T;default:return e}},initialState:T};exports.SELECTION_PLUGIN_ID=i,exports.SelectionPlugin=P,exports.SelectionPluginPackage=w,exports.getVerticalOverlap=C,exports.glyphAt=p,exports.manifest=n,exports.mergeAdjacentRects=E,exports.rectIntersect=m,exports.rectIsEmpty=S,exports.rectUnion=x,exports.rectsWithinSlice=f,exports.shouldMergeHorizontalRects=b,exports.sliceBounds=y;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core"),t=require("@embedpdf/models"),i="selection",n={id:i,name:"Selection Plugin",version:"1.0.0",provides:["selection"],requires:["interaction-manager"],optional:["viewport","scroll"],defaultConfig:{enabled:!0,menuHeight:40}},o="SELECTION/INIT_STATE",s="SELECTION/CLEANUP_STATE",c="SELECTION/CACHE_PAGE_GEOMETRY",r="SELECTION/SET_SELECTION",a="SELECTION/START_SELECTION",l="SELECTION/END_SELECTION",d="SELECTION/CLEAR_SELECTION",h="SELECTION/SET_RECTS",g="SELECTION/SET_SLICES",u={geometry:{},rects:{},slices:{},selection:null,active:!1,selecting:!1},p={documents:{}},m=(e,t,i)=>({...e,documents:{...e.documents,[t]:i}});function S(e,t){return e.rects[t]??[]}function y(e,i){return t.boundingRect(S(e,i))}function f(e){const i=[],n=e.rects;for(const o in n){const e=Number(o),s=t.boundingRect(n[e]);s&&i.push({page:e,rect:s})}return i}function x(e,t){const i=e.rects[t]||[];if(0===i.length)return null;const n=y(e,t);return n?{pageIndex:t,rect:n,segmentRects:i}:null}function C(e){const t=[],i=Object.keys(e.rects).map(Number);for(const n of i){const i=e.rects[n]||[];if(0===i.length)continue;const o=y(e,n);o&&t.push({pageIndex:n,rect:o,segmentRects:i})}return t}function b(e,t){for(const i of e.runs){if(!(t.y>=i.rect.y&&t.y<=i.rect.y+i.rect.height&&t.x>=i.rect.x&&t.x<=i.rect.x+i.rect.width))continue;const e=i.glyphs.findIndex(e=>t.x>=e.x&&t.x<=e.x+e.width&&t.y>=e.y&&t.y<=e.y+e.height);if(-1!==e)return i.charStart+e}return-1}function P(e,t,i){if(!e||!t)return null;if(i<e.start.page||i>e.end.page)return null;const n=i===e.start.page?e.start.index:0,o=t.runs[t.runs.length-1],s=o.charStart+o.glyphs.length-1;return{from:n,to:i===e.end.page?e.end.index:s}}function E(e,t,i,n=!0){const o=[];for(const s of e.runs){const e=s.charStart,n=e+s.glyphs.length-1;if(n<t||e>i)continue;const c=Math.max(t,e)-e,r=Math.min(i,n)-e;let a=1/0,l=-1/0,d=1/0,h=-1/0,g=0;for(let t=c;t<=r;t++){const e=s.glyphs[t];2!==e.flags&&(a=Math.min(a,e.x),l=Math.max(l,e.x+e.width),d=Math.min(d,e.y),h=Math.max(h,e.y+e.height),g++)}a!==1/0&&g>0&&o.push({rect:{origin:{x:a,y:d},size:{width:l-a,height:h-d}},charCount:g})}return n?$(o):o.map(e=>e.rect)}function T(e,t){const i=Math.min(e.origin.x,t.origin.x),n=Math.min(e.origin.y,t.origin.y);return{origin:{x:i,y:n},size:{width:Math.max(e.origin.x+e.size.width,t.origin.x+t.size.width)-i,height:Math.max(e.origin.y+e.size.height,t.origin.y+t.size.height)-n}}}function I(e,t){const i=Math.max(e.origin.x,t.origin.x),n=Math.max(e.origin.y,t.origin.y),o=Math.min(e.origin.x+e.size.width,t.origin.x+t.size.width),s=Math.min(e.origin.y+e.size.height,t.origin.y+t.size.height);return{origin:{x:i,y:n},size:{width:Math.max(0,o-i),height:Math.max(0,s-n)}}}function v(e){return e.size.width<=0||e.size.height<=0}function M(e,t){if(v(e)||v(t))return 0;const i=T(e,t);if(i.size.height===e.size.height||i.size.height===t.size.height)return 1;return I(e,t).size.height/i.size.height}function w(e,t){const i=e.rect,n=t.rect;if(M(i,n)<.8)return!1;const o=1*i.size.width/e.charCount,s=1*n.size.width/t.charCount,c=i.origin.x-o,r=i.origin.x+i.size.width+o,a=n.origin.x-s;return c<n.origin.x+n.size.width+s&&r>a}function $(e){const t=[];let i=null,n=null;for(const o of e)i&&n?w(i,o)?n=T(n,o.rect):(t.push(n),n=o.rect):n=o.rect,i=o;return n&&!v(n)&&t.push(n),t}const D=class extends e.BasePlugin{constructor(i,n,o){var s,c,r;super(i,n),this.enabledModesPerDoc=new Map,this.selecting=new Map,this.anchor=new Map,this.pageCallbacks=new Map,this.menuPlacement$=e.createScopedEmitter((e,t)=>({documentId:e,placement:t})),this.selChange$=e.createScopedEmitter((e,t)=>({documentId:e,selection:t})),this.textRetrieved$=e.createScopedEmitter((e,t)=>({documentId:e,text:t})),this.copyToClipboard$=e.createScopedEmitter((e,t)=>({documentId:e,text:t}),{cache:!1}),this.beginSelection$=e.createScopedEmitter((e,t)=>({documentId:e,page:t.page,index:t.index}),{cache:!1}),this.endSelection$=e.createScopedEmitter(e=>({documentId:e}),{cache:!1}),this.viewportCapability=null,this.scrollCapability=null,this.menuHeight=o.menuHeight??40;const a=n.getPlugin("interaction-manager");if(!a)throw new Error("SelectionPlugin: InteractionManagerPlugin is required.");this.interactionManagerCapability=a.provides(),this.viewportCapability=(null==(s=n.getPlugin("viewport"))?void 0:s.provides())??null,this.scrollCapability=(null==(c=n.getPlugin("scroll"))?void 0:c.provides())??null,this.coreStore.onAction(e.REFRESH_PAGES,e=>{const{documentId:i,pageIndexes:n}=e.payload,o=n.map(e=>this.getNewPageGeometryAndCache(i,e));t.Task.all(o).wait(()=>{n.forEach(e=>{this.notifyPage(i,e)})},t.ignore)}),null==(r=this.viewportCapability)||r.onViewportChange(e=>{this.recalculateMenuPlacement(e.documentId)},{mode:"throttle",wait:100})}onDocumentLoadingStarted(e){this.dispatch(((e,t)=>({type:o,payload:{documentId:e,state:t}}))(e,u)),this.enabledModesPerDoc.set(e,new Set(["pointerMode"])),this.pageCallbacks.set(e,new Map),this.selecting.set(e,!1),this.anchor.set(e,void 0)}onDocumentClosed(e){this.dispatch((e=>({type:s,payload:e}))(e)),this.enabledModesPerDoc.delete(e),this.pageCallbacks.delete(e),this.selecting.delete(e),this.anchor.delete(e),this.selChange$.clearScope(e),this.textRetrieved$.clearScope(e),this.copyToClipboard$.clearScope(e),this.beginSelection$.clearScope(e),this.endSelection$.clearScope(e),this.menuPlacement$.clearScope(e)}async initialize(){}async destroy(){this.selChange$.clear(),this.textRetrieved$.clear(),this.copyToClipboard$.clear(),this.beginSelection$.clear(),this.endSelection$.clear(),this.menuPlacement$.clear(),super.destroy()}buildCapability(){const e=e=>e??this.getActiveDocumentId();return{getFormattedSelection:t=>C(this.getDocumentState(e(t))),getFormattedSelectionForPage:(t,i)=>x(this.getDocumentState(e(i)),t),getHighlightRectsForPage:(t,i)=>S(this.getDocumentState(e(i)),t),getHighlightRects:t=>this.getDocumentState(e(t)).rects,getBoundingRectForPage:(t,i)=>y(this.getDocumentState(e(i)),t),getBoundingRects:t=>f(this.getDocumentState(e(t))),getSelectedText:t=>this.getSelectedText(e(t)),clear:t=>this.clearSelection(e(t)),copyToClipboard:t=>this.copyToClipboard(e(t)),getState:t=>this.getDocumentState(e(t)),enableForMode:(t,i)=>{var n;return null==(n=this.enabledModesPerDoc.get(e(i)))?void 0:n.add(t)},isEnabledForMode:(t,i)=>{var n;return(null==(n=this.enabledModesPerDoc.get(e(i)))?void 0:n.has(t))??!1},forDocument:this.createSelectionScope.bind(this),onCopyToClipboard:this.copyToClipboard$.onGlobal,onSelectionChange:this.selChange$.onGlobal,onTextRetrieved:this.textRetrieved$.onGlobal,onBeginSelection:this.beginSelection$.onGlobal,onEndSelection:this.endSelection$.onGlobal}}createSelectionScope(e){return{getFormattedSelection:()=>C(this.getDocumentState(e)),getFormattedSelectionForPage:t=>x(this.getDocumentState(e),t),getHighlightRectsForPage:t=>S(this.getDocumentState(e),t),getHighlightRects:()=>this.getDocumentState(e).rects,getBoundingRectForPage:t=>y(this.getDocumentState(e),t),getBoundingRects:()=>f(this.getDocumentState(e)),getSelectedText:()=>this.getSelectedText(e),clear:()=>this.clearSelection(e),copyToClipboard:()=>this.copyToClipboard(e),getState:()=>this.getDocumentState(e),onSelectionChange:this.selChange$.forScope(e),onTextRetrieved:this.textRetrieved$.forScope(e),onCopyToClipboard:this.copyToClipboard$.forScope(e),onBeginSelection:this.beginSelection$.forScope(e),onEndSelection:this.endSelection$.forScope(e)}}getDocumentState(e){const t=this.state.documents[e];if(!t)throw new Error(`Selection state not found for document: ${e}`);return t}onMenuPlacement(e,t){return this.menuPlacement$.forScope(e)(t)}registerSelectionOnPage(e){var i;const{documentId:n,pageIndex:o,onRectsChange:s}=e,c=this.state.documents[n];if(!c)return this.logger.warn("SelectionPlugin","RegisterFailed",`Cannot register selection on page ${o} for document ${n}: document state not initialized.`),()=>{};null==(i=this.pageCallbacks.get(n))||i.set(o,s);const r=this.getOrLoadGeometry(n,o),a=this.interactionManagerCapability.forDocument(n),l=this.enabledModesPerDoc.get(n);s({rects:S(c,o),boundingRect:y(c,o)});const d={onPointerDown:(e,t,i)=>{if(!(null==l?void 0:l.has(i)))return;this.clearSelection(n);const s=this.getDocumentState(n).geometry[o];if(s){const t=b(s,e);-1!==t&&this.beginSelection(n,o,t)}},onPointerMove:(e,t,i)=>{if(!(null==l?void 0:l.has(i)))return;const s=this.getDocumentState(n).geometry[o];if(s){const t=b(s,e);-1!==t?a.setCursor("selection-text","text",10):a.removeCursor("selection-text"),this.selecting.get(n)&&-1!==t&&this.updateSelection(n,o,t)}},onPointerUp:(e,t,i)=>{(null==l?void 0:l.has(i))&&this.endSelection(n)},onHandlerActiveEnd:e=>{(null==l?void 0:l.has(e))&&this.clearSelection(n)}},h=this.interactionManagerCapability.registerAlways({scope:{type:"page",documentId:n,pageIndex:o},handlers:d});return()=>{var e;h(),null==(e=this.pageCallbacks.get(n))||e.delete(o),r.abort({code:t.PdfErrorCode.Cancelled,message:"Cleanup"})}}getPlacementMetrics(e,t,i,n){var o;const s=null==(o=this.scrollCapability)?void 0:o.forDocument(e),c=null==s?void 0:s.getRectPositionForPage(t,i);if(!c)return null;const r=c.origin.y-n.scrollTop,a=c.origin.y+c.size.height-n.scrollTop;return{pageIndex:t,rect:i,spaceAbove:r,spaceBelow:n.clientHeight-a,isBottomVisible:a>0&&a<=n.clientHeight,isTopVisible:r>=0&&r<n.clientHeight}}recalculateMenuPlacement(e){const t=this.state.documents[e];if(!t)return;if(t.selecting||null===t.selection)return void this.menuPlacement$.emit(e,null);const i=f(t);if(0===i.length)return void this.menuPlacement$.emit(e,null);const n=i[i.length-1];if(!this.viewportCapability||!this.scrollCapability)return void this.menuPlacement$.emit(e,{pageIndex:n.page,rect:n.rect,spaceAbove:0,spaceBelow:1/0,suggestTop:!1,isVisible:!0});const o=this.viewportCapability.forDocument(e).getMetrics(),s=i[0],c=this.getPlacementMetrics(e,n.page,n.rect,o),r=this.getPlacementMetrics(e,s.page,s.rect,o);c&&c.isBottomVisible&&c.spaceBelow>this.menuHeight?this.menuPlacement$.emit(e,{...c,suggestTop:!1,isVisible:!0}):r&&r.isTopVisible?this.menuPlacement$.emit(e,{...r,suggestTop:!0,isVisible:!0}):c&&c.isBottomVisible?this.menuPlacement$.emit(e,{...c,suggestTop:!1,isVisible:!0}):this.menuPlacement$.emit(e,null)}notifyPage(e,t){var i;const n=null==(i=this.pageCallbacks.get(e))?void 0:i.get(t);if(n){const i=this.getDocumentState(e);n("pointerMode"===this.interactionManagerCapability.forDocument(e).getActiveMode()?{rects:S(i,t),boundingRect:y(i,t)}:{rects:[],boundingRect:null})}}notifyAllPages(e){var t;null==(t=this.pageCallbacks.get(e))||t.forEach((t,i)=>{this.notifyPage(e,i)})}getNewPageGeometryAndCache(e,i){const n=this.getCoreDocument(e);if(!n||!n.document)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Doc Not Found"});const o=n.document.pages.find(e=>e.index===i),s=this.engine.getPageGeometry(n.document,o);return s.wait(t=>{this.dispatch(((e,t,i)=>({type:c,payload:{documentId:e,page:t,geo:i}}))(e,i,t))},t.ignore),s}getOrLoadGeometry(e,i){const n=this.getDocumentState(e).geometry[i];return n?t.PdfTaskHelper.resolve(n):this.getNewPageGeometryAndCache(e,i)}beginSelection(e,t,i){this.selecting.set(e,!0),this.anchor.set(e,{page:t,index:i}),this.dispatch((e=>({type:a,payload:{documentId:e}}))(e)),this.beginSelection$.emit(e,{page:t,index:i}),this.recalculateMenuPlacement(e)}endSelection(e){this.selecting.set(e,!1),this.anchor.set(e,void 0),this.dispatch((e=>({type:l,payload:{documentId:e}}))(e)),this.endSelection$.emit(e),this.recalculateMenuPlacement(e)}clearSelection(e){this.selecting.set(e,!1),this.anchor.set(e,void 0),this.dispatch((e=>({type:d,payload:{documentId:e}}))(e)),this.selChange$.emit(e,null),this.menuPlacement$.emit(e,null),this.notifyAllPages(e)}updateSelection(e,t,i){if(!this.selecting.get(e)||!this.anchor.get(e))return;const n=this.anchor.get(e),o=t>n.page||t===n.page&&i>=n.index,s={start:o?n:{page:t,index:i},end:o?{page:t,index:i}:n};this.dispatch(((e,t)=>({type:r,payload:{documentId:e,selection:t}}))(e,s)),this.updateRectsAndSlices(e,s),this.selChange$.emit(e,s);for(let c=s.start.page;c<=s.end.page;c++)this.notifyPage(e,c)}updateRectsAndSlices(e,t){const i=this.getDocumentState(e),n={},o={};for(let s=t.start.page;s<=t.end.page;s++){const e=i.geometry[s],c=P(t,e,s);c&&(n[s]=E(e,c.from,c.to),o[s]={start:c.from,count:c.to-c.from+1})}this.dispatch(((e,t)=>({type:h,payload:{documentId:e,rects:t}}))(e,n)),this.dispatch(((e,t)=>({type:g,payload:{documentId:e,slices:t}}))(e,o))}getSelectedText(e){const i=this.getCoreDocument(e),n=this.getDocumentState(e);if(!(null==i?void 0:i.document)||!n.selection)return t.PdfTaskHelper.reject({code:t.PdfErrorCode.NotFound,message:"Doc Not Found or No Selection"});const o=n.selection,s=[];for(let t=o.start.page;t<=o.end.page;t++){const e=n.slices[t];e&&s.push({pageIndex:t,charIndex:e.start,charCount:e.count})}if(0===s.length)return t.PdfTaskHelper.resolve([]);const c=this.engine.getTextSlices(i.document,s);return c.wait(t=>{this.textRetrieved$.emit(e,t)},t.ignore),c}copyToClipboard(e){this.getSelectedText(e).wait(t=>{this.copyToClipboard$.emit(e,t.join("\n"))},t.ignore)}};D.id="selection";let R=D;const N={manifest:n,create:(e,t)=>new R(i,e,t),reducer:(e=p,t)=>{switch(t.type){case o:{const{documentId:i,state:n}=t.payload;return m(e,i,n)}case s:{const i=t.payload,{[i]:n,...o}=e.documents;return{...e,documents:o}}case c:{const{documentId:i,page:n,geo:o}=t.payload,s=e.documents[i];return s?m(e,i,{...s,geometry:{...s.geometry,[n]:o}}):e}case r:{const{documentId:i,selection:n}=t.payload,o=e.documents[i];return o?m(e,i,{...o,selection:n,active:!0}):e}case a:{const{documentId:i}=t.payload,n=e.documents[i];return n?m(e,i,{...n,selecting:!0,selection:null,rects:{}}):e}case l:{const{documentId:i}=t.payload,n=e.documents[i];return n?m(e,i,{...n,selecting:!1}):e}case d:{const{documentId:i}=t.payload,n=e.documents[i];return n?m(e,i,{...n,selecting:!1,selection:null,rects:{},active:!1}):e}case h:{const{documentId:i,rects:n}=t.payload,o=e.documents[i];return o?m(e,i,{...o,rects:n}):e}case g:{const{documentId:i,slices:n}=t.payload,o=e.documents[i];return o?m(e,i,{...o,slices:n}):e}case"SELECTION/RESET":{const{documentId:i}=t.payload;return e.documents[i]?m(e,i,u):e}default:return e}},initialState:p};exports.SELECTION_PLUGIN_ID=i,exports.SelectionPlugin=R,exports.SelectionPluginPackage=N,exports.getVerticalOverlap=M,exports.glyphAt=b,exports.manifest=n,exports.mergeAdjacentRects=$,exports.rectIntersect=I,exports.rectIsEmpty=v,exports.rectUnion=T,exports.rectsWithinSlice=E,exports.shouldMergeHorizontalRects=w,exports.sliceBounds=P;
|
|
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/actions.ts","../src/lib/selectors.ts","../src/lib/utils.ts","../src/lib/selection-plugin.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { SelectionPluginConfig } from './types';\n\nexport const SELECTION_PLUGIN_ID = 'selection';\n\nexport const manifest: PluginManifest<SelectionPluginConfig> = {\n id: SELECTION_PLUGIN_ID,\n name: 'Selection Plugin',\n version: '1.0.0',\n provides: ['selection'],\n requires: ['interaction-manager'],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { Action } from '@embedpdf/core';\nimport { PdfPageGeometry, Rect } from '@embedpdf/models';\nimport { SelectionRangeX } from './types';\n\nexport const CACHE_PAGE_GEOMETRY = 'CACHE_PAGE_GEOMETRY';\nexport const SET_SELECTION = 'SET_SELECTION';\nexport const START_SELECTION = 'START_SELECTION';\nexport const END_SELECTION = 'END_SELECTION';\nexport const CLEAR_SELECTION = 'CLEAR_SELECTION';\nexport const SET_RECTS = 'SET_RECTS';\nexport const SET_SLICES = 'SET_SLICES';\nexport const RESET = 'RESET';\n\nexport interface CachePageGeometryAction extends Action {\n type: typeof CACHE_PAGE_GEOMETRY;\n payload: { page: number; geo: PdfPageGeometry };\n}\nexport interface SetSelectionAction extends Action {\n type: typeof SET_SELECTION;\n payload: SelectionRangeX | null;\n}\n\nexport interface StartSelectionAction extends Action {\n type: typeof START_SELECTION;\n}\n\nexport interface EndSelectionAction extends Action {\n type: typeof END_SELECTION;\n}\n\nexport interface ClearSelectionAction extends Action {\n type: typeof CLEAR_SELECTION;\n}\n\nexport interface SetRectsAction extends Action {\n type: typeof SET_RECTS;\n payload: Record<number, Rect[]>;\n}\n\nexport interface SetSlicesAction extends Action {\n type: typeof SET_SLICES;\n payload: Record<number, { start: number; count: number }>;\n}\n\nexport interface ResetAction extends Action {\n type: typeof RESET;\n}\n\nexport type SelectionAction =\n | CachePageGeometryAction\n | SetSelectionAction\n | StartSelectionAction\n | EndSelectionAction\n | ClearSelectionAction\n | SetRectsAction\n | SetSlicesAction\n | ResetAction;\n\nexport const cachePageGeometry = (page: number, geo: PdfPageGeometry): CachePageGeometryAction => ({\n type: CACHE_PAGE_GEOMETRY,\n payload: { page, geo },\n});\n\nexport const setSelection = (sel: SelectionRangeX): SetSelectionAction => ({\n type: SET_SELECTION,\n payload: sel,\n});\n\nexport const startSelection = (): StartSelectionAction => ({ type: START_SELECTION });\n\nexport const endSelection = (): EndSelectionAction => ({ type: END_SELECTION });\n\nexport const clearSelection = (): ClearSelectionAction => ({ type: CLEAR_SELECTION });\n\nexport const setRects = (allRects: Record<number, Rect[]>): SetRectsAction => ({\n type: SET_RECTS,\n payload: allRects,\n});\n\nexport const setSlices = (\n slices: Record<number, { start: number; count: number }>,\n): SetSlicesAction => ({ type: SET_SLICES, payload: slices });\n\nexport const reset = (): ResetAction => ({ type: RESET });\n","import { Rect, boundingRect } from '@embedpdf/models';\nimport { FormattedSelection, SelectionState } from './types';\n\nexport function selectRectsForPage(state: SelectionState, page: number) {\n return state.rects[page] ?? [];\n}\n\nexport function selectBoundingRectForPage(state: SelectionState, page: number) {\n return boundingRect(selectRectsForPage(state, page));\n}\n\nexport function selectRectsAndBoundingRectForPage(state: SelectionState, page: number) {\n return {\n rects: selectRectsForPage(state, page),\n boundingRect: selectBoundingRectForPage(state, page),\n };\n}\n\nexport function selectBoundingRectsForAllPages(state: SelectionState) {\n const out: { page: number; rect: Rect }[] = [];\n const rectMap = state.rects;\n\n for (const key in rectMap) {\n const page = Number(key);\n const bRect = boundingRect(rectMap[page]);\n if (bRect) out.push({ page, rect: bRect });\n }\n return out;\n}\n\nexport function getFormattedSelectionForPage(\n state: SelectionState,\n page: number,\n): FormattedSelection | null {\n const segmentRects = state.rects[page] || [];\n if (segmentRects.length === 0) return null;\n const boundingRect = selectBoundingRectForPage(state, page);\n if (!boundingRect) return null;\n return { pageIndex: page, rect: boundingRect, segmentRects };\n}\n\nexport function getFormattedSelection(state: SelectionState) {\n const result: FormattedSelection[] = [];\n\n // Get all pages that have rects\n const pages = Object.keys(state.rects).map(Number);\n\n for (const pageIndex of pages) {\n const segmentRects = state.rects[pageIndex] || [];\n\n if (segmentRects.length === 0) continue;\n\n // Calculate bounding rect for this page\n const boundingRect = selectBoundingRectForPage(state, pageIndex);\n\n if (boundingRect) {\n result.push({\n pageIndex,\n rect: boundingRect,\n segmentRects,\n });\n }\n }\n\n return result;\n}\n","import { PdfPageGeometry, Position, Rect } from '@embedpdf/models';\nimport { SelectionRangeX } from './types';\n\n/**\n * Hit-test helper using runs\n * @param geo - page geometry\n * @param pt - point\n * @returns glyph index\n */\nexport function glyphAt(geo: PdfPageGeometry, pt: Position) {\n for (const run of geo.runs) {\n const inRun =\n pt.y >= run.rect.y &&\n pt.y <= run.rect.y + run.rect.height &&\n pt.x >= run.rect.x &&\n pt.x <= run.rect.x + run.rect.width;\n\n if (!inRun) continue;\n\n // Simply check if the point is within any glyph's bounding box\n const rel = run.glyphs.findIndex(\n (g) => pt.x >= g.x && pt.x <= g.x + g.width && pt.y >= g.y && pt.y <= g.y + g.height,\n );\n\n if (rel !== -1) {\n return run.charStart + rel;\n }\n }\n return -1;\n}\n\n/**\n * Helper: min/max glyph indices on `page` for current sel\n * @param sel - selection range\n * @param geo - page geometry\n * @param page - page index\n * @returns { from: number; to: number } | null\n */\nexport function sliceBounds(\n sel: SelectionRangeX | null,\n geo: PdfPageGeometry | undefined,\n page: number,\n): { from: number; to: number } | null {\n if (!sel || !geo) return null;\n if (page < sel.start.page || page > sel.end.page) return null;\n\n const from = page === sel.start.page ? sel.start.index : 0;\n\n const lastRun = geo.runs[geo.runs.length - 1];\n const lastCharOnPage = lastRun.charStart + lastRun.glyphs.length - 1;\n\n const to = page === sel.end.page ? sel.end.index : lastCharOnPage;\n\n return { from, to };\n}\n\n/**\n * Helper: build rects for a slice of the page\n * @param geo - page geometry\n * @param from - from index\n * @param to - to index\n * @param merge - whether to merge adjacent rects (default: true)\n * @returns rects\n */\nexport function rectsWithinSlice(\n geo: PdfPageGeometry,\n from: number,\n to: number,\n merge: boolean = true,\n): Rect[] {\n const textRuns: TextRunInfo[] = [];\n\n for (const run of geo.runs) {\n const runStart = run.charStart;\n const runEnd = runStart + run.glyphs.length - 1;\n if (runEnd < from || runStart > to) continue;\n\n const sIdx = Math.max(from, runStart) - runStart;\n const eIdx = Math.min(to, runEnd) - runStart;\n\n let minX = Infinity,\n maxX = -Infinity;\n let minY = Infinity,\n maxY = -Infinity;\n let charCount = 0;\n\n for (let i = sIdx; i <= eIdx; i++) {\n const g = run.glyphs[i];\n if (g.flags === 2) continue; // empty glyph\n\n minX = Math.min(minX, g.x);\n maxX = Math.max(maxX, g.x + g.width);\n minY = Math.min(minY, g.y);\n maxY = Math.max(maxY, g.y + g.height);\n charCount++;\n }\n\n if (minX !== Infinity && charCount > 0) {\n textRuns.push({\n rect: {\n origin: { x: minX, y: minY },\n size: { width: maxX - minX, height: maxY - minY },\n },\n charCount,\n });\n }\n }\n\n // If merge is false, just return the individual rects\n if (!merge) {\n return textRuns.map((run) => run.rect);\n }\n\n // Otherwise merge adjacent rects\n return mergeAdjacentRects(textRuns);\n}\n\n/**\n * ============================================================================\n * Rectangle Merging Algorithm\n * ============================================================================\n *\n * The following code is adapted from Chromium's PDF text selection implementation.\n *\n * Copyright 2010 The Chromium Authors\n * Use of this source code is governed by a BSD-style license that can be\n * found in the LICENSE file: https://source.chromium.org/chromium/chromium/src/+/main:LICENSE\n *\n * Original source:\n * https://source.chromium.org/chromium/chromium/src/+/main:pdf/pdfium/pdfium_range.cc\n *\n * Adapted for TypeScript and this project's Rect/geometry types.\n */\n\n/**\n * Text run info for rect merging (similar to Chromium's ScreenRectTextRunInfo)\n */\nexport interface TextRunInfo {\n rect: Rect;\n charCount: number;\n}\n\n/**\n * Helper functions for Rect operations\n */\nexport function rectUnion(rect1: Rect, rect2: Rect): Rect {\n const left = Math.min(rect1.origin.x, rect2.origin.x);\n const top = Math.min(rect1.origin.y, rect2.origin.y);\n const right = Math.max(rect1.origin.x + rect1.size.width, rect2.origin.x + rect2.size.width);\n const bottom = Math.max(rect1.origin.y + rect1.size.height, rect2.origin.y + rect2.size.height);\n\n return {\n origin: { x: left, y: top },\n size: { width: right - left, height: bottom - top },\n };\n}\n\nexport function rectIntersect(rect1: Rect, rect2: Rect): Rect {\n const left = Math.max(rect1.origin.x, rect2.origin.x);\n const top = Math.max(rect1.origin.y, rect2.origin.y);\n const right = Math.min(rect1.origin.x + rect1.size.width, rect2.origin.x + rect2.size.width);\n const bottom = Math.min(rect1.origin.y + rect1.size.height, rect2.origin.y + rect2.size.height);\n\n const width = Math.max(0, right - left);\n const height = Math.max(0, bottom - top);\n\n return {\n origin: { x: left, y: top },\n size: { width, height },\n };\n}\n\nexport function rectIsEmpty(rect: Rect): boolean {\n return rect.size.width <= 0 || rect.size.height <= 0;\n}\n\n/**\n * Returns a ratio between [0, 1] representing vertical overlap\n */\nexport function getVerticalOverlap(rect1: Rect, rect2: Rect): number {\n if (rectIsEmpty(rect1) || rectIsEmpty(rect2)) return 0;\n\n const unionRect = rectUnion(rect1, rect2);\n\n if (unionRect.size.height === rect1.size.height || unionRect.size.height === rect2.size.height) {\n return 1.0;\n }\n\n const intersectRect = rectIntersect(rect1, rect2);\n return intersectRect.size.height / unionRect.size.height;\n}\n\n/**\n * Returns true if there is sufficient horizontal and vertical overlap\n */\nexport function shouldMergeHorizontalRects(textRun1: TextRunInfo, textRun2: TextRunInfo): boolean {\n const VERTICAL_OVERLAP_THRESHOLD = 0.8;\n const rect1 = textRun1.rect;\n const rect2 = textRun2.rect;\n\n if (getVerticalOverlap(rect1, rect2) < VERTICAL_OVERLAP_THRESHOLD) {\n return false;\n }\n\n const HORIZONTAL_WIDTH_FACTOR = 1.0;\n const averageWidth1 = (HORIZONTAL_WIDTH_FACTOR * rect1.size.width) / textRun1.charCount;\n const averageWidth2 = (HORIZONTAL_WIDTH_FACTOR * rect2.size.width) / textRun2.charCount;\n\n const rect1Left = rect1.origin.x - averageWidth1;\n const rect1Right = rect1.origin.x + rect1.size.width + averageWidth1;\n const rect2Left = rect2.origin.x - averageWidth2;\n const rect2Right = rect2.origin.x + rect2.size.width + averageWidth2;\n\n return rect1Left < rect2Right && rect1Right > rect2Left;\n}\n\n/**\n * Merge adjacent rectangles based on proximity and overlap (similar to Chromium's algorithm)\n */\nexport function mergeAdjacentRects(textRuns: TextRunInfo[]): Rect[] {\n const results: Rect[] = [];\n let previousTextRun: TextRunInfo | null = null;\n let currentRect: Rect | null = null;\n\n for (const textRun of textRuns) {\n if (previousTextRun && currentRect) {\n if (shouldMergeHorizontalRects(previousTextRun, textRun)) {\n currentRect = rectUnion(currentRect, textRun.rect);\n } else {\n results.push(currentRect);\n currentRect = textRun.rect;\n }\n } else {\n currentRect = textRun.rect;\n }\n previousTextRun = textRun;\n }\n\n if (currentRect && !rectIsEmpty(currentRect)) {\n results.push(currentRect);\n }\n\n return results;\n}\n","import {\n BasePlugin,\n PluginRegistry,\n REFRESH_PAGES,\n SET_DOCUMENT,\n createBehaviorEmitter,\n createEmitter,\n} from '@embedpdf/core';\nimport {\n PdfPageGeometry,\n Rect,\n PdfTask,\n PdfTaskHelper,\n PdfErrorCode,\n ignore,\n PageTextSlice,\n Task,\n Position,\n} from '@embedpdf/models';\nimport {\n InteractionManagerCapability,\n InteractionManagerPlugin,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\n\nimport {\n cachePageGeometry,\n setSelection,\n SelectionAction,\n endSelection,\n startSelection,\n clearSelection,\n reset,\n setRects,\n setSlices,\n} from './actions';\nimport * as selector from './selectors';\nimport {\n SelectionCapability,\n SelectionPluginConfig,\n SelectionRangeX,\n SelectionState,\n RegisterSelectionOnPageOptions,\n SelectionRectsCallback,\n} from './types';\nimport { sliceBounds, rectsWithinSlice, glyphAt } from './utils';\n\nexport class SelectionPlugin extends BasePlugin<\n SelectionPluginConfig,\n SelectionCapability,\n SelectionState,\n SelectionAction\n> {\n static readonly id = 'selection' as const;\n\n /** Modes that should trigger text-selection logic */\n private enabledModes = new Set<string>(['pointerMode']);\n\n /* interactive state */\n private selecting = false;\n private anchor?: { page: number; index: number };\n\n /** Page callbacks for rect updates */\n private pageCallbacks = new Map<number, (data: SelectionRectsCallback) => void>();\n\n private readonly selChange$ = createBehaviorEmitter<SelectionState['selection']>();\n private readonly textRetrieved$ = createBehaviorEmitter<string[]>();\n private readonly copyToClipboard$ = createEmitter<string>();\n private readonly beginSelection$ = createEmitter<{ page: number; index: number }>();\n private readonly endSelection$ = createEmitter<void>();\n\n private interactionManagerCapability: InteractionManagerCapability | undefined;\n\n constructor(id: string, registry: PluginRegistry) {\n super(id, registry);\n\n this.interactionManagerCapability = this.registry\n .getPlugin<InteractionManagerPlugin>('interaction-manager')\n ?.provides();\n\n this.coreStore.onAction(SET_DOCUMENT, (_action) => {\n this.dispatch(reset());\n this.notifyAllPages();\n });\n\n this.coreStore.onAction(REFRESH_PAGES, (action) => {\n const tasks = action.payload.map((pageIdx) => this.getNewPageGeometryAndCache(pageIdx));\n Task.all(tasks).wait(() => {\n // Notify affected pages about geometry updates\n action.payload.forEach((pageIdx) => {\n this.notifyPage(pageIdx);\n });\n }, ignore);\n });\n }\n\n /* ── life-cycle ────────────────────────────────────────── */\n async initialize() {}\n async destroy() {\n this.selChange$.clear();\n }\n\n /* ── capability exposed to UI / other plugins ─────────── */\n buildCapability(): SelectionCapability {\n return {\n getFormattedSelection: () => selector.getFormattedSelection(this.state),\n getFormattedSelectionForPage: (p) => selector.getFormattedSelectionForPage(this.state, p),\n getHighlightRectsForPage: (p) => selector.selectRectsForPage(this.state, p),\n getHighlightRects: () => this.state.rects,\n getBoundingRectForPage: (p) => selector.selectBoundingRectForPage(this.state, p),\n getBoundingRects: () => selector.selectBoundingRectsForAllPages(this.state),\n onCopyToClipboard: this.copyToClipboard$.on,\n onSelectionChange: this.selChange$.on,\n onTextRetrieved: this.textRetrieved$.on,\n onBeginSelection: this.beginSelection$.on,\n onEndSelection: this.endSelection$.on,\n clear: () => this.clearSelection(),\n getSelectedText: () => this.getSelectedText(),\n copyToClipboard: () => this.copyToClipboard(),\n enableForMode: (id: string) => this.enabledModes.add(id),\n isEnabledForMode: (id: string) => this.enabledModes.has(id),\n getState: () => this.state,\n };\n }\n\n public registerSelectionOnPage(opts: RegisterSelectionOnPageOptions) {\n if (!this.interactionManagerCapability) {\n this.logger.warn(\n 'SelectionPlugin',\n 'MissingDependency',\n 'Interaction manager plugin not loaded, text selection disabled',\n );\n return () => {};\n }\n\n const { pageIndex, onRectsChange } = opts;\n\n // Track this callback for the page\n this.pageCallbacks.set(pageIndex, onRectsChange);\n\n const geoTask = this.getOrLoadGeometry(pageIndex);\n\n // Send initial state\n onRectsChange({\n rects: selector.selectRectsForPage(this.state, pageIndex),\n boundingRect: selector.selectBoundingRectForPage(this.state, pageIndex),\n });\n\n const handlers: PointerEventHandlersWithLifecycle<PointerEvent> = {\n onPointerDown: (point: Position, _evt, modeId) => {\n if (!this.enabledModes.has(modeId)) return;\n\n // Clear the selection\n this.clearSelection();\n\n // Get geometry from cache (or load if needed)\n const cached = this.state.geometry[pageIndex];\n if (cached) {\n const g = glyphAt(cached, point);\n if (g !== -1) {\n this.beginSelection(pageIndex, g);\n }\n }\n },\n onPointerMove: (point: Position, _evt, modeId) => {\n if (!this.enabledModes.has(modeId)) return;\n\n // Get cached geometry (should be instant if already loaded)\n const cached = this.state.geometry[pageIndex];\n if (cached) {\n const g = glyphAt(cached, point);\n\n // Update cursor\n if (g !== -1) {\n this.interactionManagerCapability?.setCursor('selection-text', 'text', 10);\n } else {\n this.interactionManagerCapability?.removeCursor('selection-text');\n }\n\n // Update selection if we're selecting\n if (this.selecting && g !== -1) {\n this.updateSelection(pageIndex, g);\n }\n }\n },\n onPointerUp: (_point: Position, _evt, modeId) => {\n if (!this.enabledModes.has(modeId)) return;\n this.endSelection();\n },\n onHandlerActiveEnd: (modeId) => {\n if (!this.enabledModes.has(modeId)) return;\n this.clearSelection();\n },\n };\n\n // Register the handlers with interaction manager\n const unregisterHandlers = this.interactionManagerCapability.registerAlways({\n scope: { type: 'page', pageIndex },\n handlers,\n });\n\n // Return cleanup function\n return () => {\n unregisterHandlers();\n this.pageCallbacks.delete(pageIndex);\n geoTask.abort({ code: PdfErrorCode.Cancelled, message: 'Cleanup' });\n };\n }\n\n private notifyPage(pageIndex: number) {\n const callback = this.pageCallbacks.get(pageIndex);\n if (callback) {\n const mode = this.interactionManagerCapability?.getActiveMode();\n if (mode === 'pointerMode') {\n callback({\n rects: selector.selectRectsForPage(this.state, pageIndex),\n boundingRect: selector.selectBoundingRectForPage(this.state, pageIndex),\n });\n } else {\n callback({ rects: [], boundingRect: null });\n }\n }\n }\n\n private notifyAllPages() {\n this.pageCallbacks.forEach((_, pageIndex) => {\n this.notifyPage(pageIndex);\n });\n }\n\n private getNewPageGeometryAndCache(pageIdx: number): PdfTask<PdfPageGeometry> {\n if (!this.coreState.core.document)\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Doc Not Found' });\n const page = this.coreState.core.document.pages.find((p) => p.index === pageIdx)!;\n const task = this.engine.getPageGeometry(this.coreState.core.document, page);\n task.wait((geo) => {\n this.dispatch(cachePageGeometry(pageIdx, geo));\n }, ignore);\n return task;\n }\n\n /* ── geometry cache ───────────────────────────────────── */\n private getOrLoadGeometry(pageIdx: number): PdfTask<PdfPageGeometry> {\n const cached = this.state.geometry[pageIdx];\n if (cached) return PdfTaskHelper.resolve(cached);\n\n return this.getNewPageGeometryAndCache(pageIdx);\n }\n\n /* ── selection state updates ───────────────────────────── */\n private beginSelection(page: number, index: number) {\n this.selecting = true;\n this.anchor = { page, index };\n this.dispatch(startSelection());\n this.beginSelection$.emit({ page, index });\n }\n\n private endSelection() {\n this.selecting = false;\n this.anchor = undefined;\n this.dispatch(endSelection());\n this.endSelection$.emit();\n }\n\n private clearSelection() {\n this.selecting = false;\n this.anchor = undefined;\n this.dispatch(clearSelection());\n this.selChange$.emit(null);\n this.notifyAllPages();\n }\n\n private updateSelection(page: number, index: number) {\n if (!this.selecting || !this.anchor) return;\n\n const a = this.anchor;\n const forward = page > a.page || (page === a.page && index >= a.index);\n\n const start = forward ? a : { page, index };\n const end = forward ? { page, index } : a;\n\n const range = { start, end };\n this.dispatch(setSelection(range));\n this.updateRectsAndSlices(range);\n this.selChange$.emit(range);\n\n // Notify affected pages\n for (let p = range.start.page; p <= range.end.page; p++) {\n this.notifyPage(p);\n }\n }\n\n private updateRectsAndSlices(range: SelectionRangeX) {\n const allRects: Record<number, Rect[]> = {};\n const allSlices: Record<number, { start: number; count: number }> = {};\n\n for (let p = range.start.page; p <= range.end.page; p++) {\n const geo = this.state.geometry[p];\n const sb = sliceBounds(range, geo, p);\n if (!sb) continue;\n\n allRects[p] = rectsWithinSlice(geo!, sb.from, sb.to);\n allSlices[p] = { start: sb.from, count: sb.to - sb.from + 1 };\n }\n\n this.dispatch(setRects(allRects));\n this.dispatch(setSlices(allSlices));\n }\n\n private getSelectedText(): PdfTask<string[]> {\n if (!this.coreState.core.document || !this.state.selection) {\n return PdfTaskHelper.reject({\n code: PdfErrorCode.NotFound,\n message: 'Doc Not Found or No Selection',\n });\n }\n\n const sel = this.state.selection;\n const req: PageTextSlice[] = [];\n\n for (let p = sel.start.page; p <= sel.end.page; p++) {\n const s = this.state.slices[p];\n if (s) req.push({ pageIndex: p, charIndex: s.start, charCount: s.count });\n }\n\n if (req.length === 0) return PdfTaskHelper.resolve([] as string[]);\n\n const task = this.engine.getTextSlices(this.coreState.core.document, req);\n\n // Emit the text when it's retrieved\n task.wait((text) => {\n this.textRetrieved$.emit(text);\n }, ignore);\n\n return task;\n }\n\n private copyToClipboard() {\n const text = this.getSelectedText();\n text.wait((text) => {\n this.copyToClipboard$.emit(text.join('\\n'));\n }, ignore);\n }\n}\n","import { SelectionState } from './types';\nimport {\n SelectionAction,\n CACHE_PAGE_GEOMETRY,\n SET_SELECTION,\n START_SELECTION,\n END_SELECTION,\n CLEAR_SELECTION,\n RESET,\n SET_SLICES,\n SET_RECTS,\n} from './actions';\n\nexport const initialState: SelectionState = {\n geometry: {},\n rects: {},\n slices: {},\n selection: null,\n active: false,\n selecting: false,\n};\n\nexport const selectionReducer = (state = initialState, action: SelectionAction): SelectionState => {\n switch (action.type) {\n case CACHE_PAGE_GEOMETRY: {\n const { page, geo } = action.payload;\n return { ...state, geometry: { ...state.geometry, [page]: geo } };\n }\n case SET_SELECTION:\n return { ...state, selection: action.payload, active: true };\n case START_SELECTION:\n return { ...state, selecting: true, selection: null, rects: {} };\n case END_SELECTION:\n return { ...state, selecting: false };\n case CLEAR_SELECTION:\n return { ...state, selecting: false, selection: null, rects: {}, active: false };\n case SET_RECTS:\n return { ...state, rects: action.payload };\n case SET_SLICES:\n return { ...state, slices: action.payload };\n case RESET:\n return initialState;\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, SELECTION_PLUGIN_ID } from './manifest';\nimport { SelectionPluginConfig, SelectionState } from './types';\n\nimport { SelectionPlugin } from './selection-plugin';\nimport { SelectionAction } from './actions';\nimport { selectionReducer, initialState } from './reducer';\n\nexport const SelectionPluginPackage: PluginPackage<\n SelectionPlugin,\n SelectionPluginConfig,\n SelectionState,\n SelectionAction\n> = {\n manifest,\n create: (registry) => new SelectionPlugin(SELECTION_PLUGIN_ID, registry),\n reducer: selectionReducer,\n initialState,\n};\n\nexport * from './selection-plugin';\nexport * from './types';\nexport * from './manifest';\nexport * from './utils';\n"],"names":["SELECTION_PLUGIN_ID","manifest","id","name","version","provides","requires","optional","defaultConfig","enabled","CACHE_PAGE_GEOMETRY","SET_SELECTION","START_SELECTION","END_SELECTION","CLEAR_SELECTION","SET_RECTS","SET_SLICES","RESET","selectRectsForPage","state","page","rects","selectBoundingRectForPage","boundingRect","glyphAt","geo","pt","run","runs","y","rect","height","x","width","rel","glyphs","findIndex","g","charStart","sliceBounds","sel","start","end","from","index","lastRun","length","lastCharOnPage","to","rectsWithinSlice","merge","textRuns","runStart","runEnd","sIdx","Math","max","eIdx","min","minX","Infinity","maxX","minY","maxY","charCount","i","flags","push","origin","size","mergeAdjacentRects","map","rectUnion","rect1","rect2","left","top","rectIntersect","right","bottom","rectIsEmpty","getVerticalOverlap","unionRect","shouldMergeHorizontalRects","textRun1","textRun2","averageWidth1","averageWidth2","rect1Left","rect1Right","rect2Left","results","previousTextRun","currentRect","textRun","_SelectionPlugin","BasePlugin","constructor","registry","super","this","enabledModes","Set","selecting","pageCallbacks","Map","selChange$","createBehaviorEmitter","textRetrieved$","copyToClipboard$","createEmitter","beginSelection$","endSelection$","interactionManagerCapability","_a","getPlugin","coreStore","onAction","SET_DOCUMENT","_action","dispatch","type","notifyAllPages","REFRESH_PAGES","action","tasks","payload","pageIdx","getNewPageGeometryAndCache","Task","all","wait","forEach","notifyPage","ignore","initialize","destroy","clear","buildCapability","getFormattedSelection","result","pages","Object","keys","Number","pageIndex","segmentRects","selector.getFormattedSelection","getFormattedSelectionForPage","p","selector.getFormattedSelectionForPage","getHighlightRectsForPage","selector.selectRectsForPage","getHighlightRects","getBoundingRectForPage","selector.selectBoundingRectForPage","getBoundingRects","out","rectMap","key","bRect","selector.selectBoundingRectsForAllPages","onCopyToClipboard","on","onSelectionChange","onTextRetrieved","onBeginSelection","onEndSelection","clearSelection","getSelectedText","copyToClipboard","enableForMode","add","isEnabledForMode","has","getState","registerSelectionOnPage","opts","logger","warn","onRectsChange","set","geoTask","getOrLoadGeometry","handlers","onPointerDown","point","_evt","modeId","cached","geometry","beginSelection","onPointerMove","setCursor","_b","removeCursor","updateSelection","onPointerUp","_point","endSelection","onHandlerActiveEnd","unregisterHandlers","registerAlways","scope","delete","abort","code","PdfErrorCode","Cancelled","message","callback","get","getActiveMode","_","coreState","core","document","PdfTaskHelper","reject","NotFound","find","task","engine","getPageGeometry","cachePageGeometry","resolve","anchor","emit","a","forward","range","updateRectsAndSlices","allRects","allSlices","sb","count","setRects","selection","req","s","slices","charIndex","getTextSlices","text","join","SelectionPlugin","initialState","active","SelectionPluginPackage","create","reducer"],"mappings":"gJAGaA,EAAsB,YAEtBC,EAAkD,CAC7DC,GAAIF,EACJG,KAAM,mBACNC,QAAS,QACTC,SAAU,CAAC,aACXC,SAAU,CAAC,uBACXC,SAAU,GACVC,cAAe,CACbC,SAAS,ICTAC,EAAsB,sBACtBC,EAAgB,gBAChBC,EAAkB,kBAClBC,EAAgB,gBAChBC,EAAkB,kBAClBC,EAAY,YACZC,EAAa,aACbC,EAAQ,QCRL,SAAAC,EAAmBC,EAAuBC,GACxD,OAAOD,EAAME,MAAMD,IAAS,EAC9B,CAEgB,SAAAE,EAA0BH,EAAuBC,GAC/D,OAAOG,eAAaL,EAAmBC,EAAOC,GAChD,CCAgB,SAAAI,EAAQC,EAAsBC,GACjC,IAAA,MAAAC,KAAOF,EAAIG,KAAM,CAO1B,KALEF,EAAGG,GAAKF,EAAIG,KAAKD,GACjBH,EAAGG,GAAKF,EAAIG,KAAKD,EAAIF,EAAIG,KAAKC,QAC9BL,EAAGM,GAAKL,EAAI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,kBACbtC,MAAMgH,IACT/I,KAAKS,iBAAiBsH,KAAKgB,EAAKC,KAAK,MAAK,GACzC9G,SAAM,GAhSXvC,EAAgB7F,GAAK,YANhB,IAAMmP,EAANtJ,EClCA,MAAMuJ,EAA+B,CAC1CxD,SAAU,CAAC,EACXzK,MAAO,CAAC,EACR2N,OAAQ,CAAC,EACTH,UAAW,KACXU,QAAQ,EACRhJ,WAAW,GCXAiJ,EAKT,CACFvP,WACAwP,OAASvJ,GAAa,IAAImJ,EAAgBrP,EAAqBkG,GAC/DwJ,QDM8B,CAACvO,EAAQmO,EAAc1H,KACrD,OAAQA,EAAOH,MACb,KAAK/G,EAAqB,CACxB,MAAMU,KAAEA,EAAAK,IAAMA,GAAQmG,EAAOE,QAC7B,MAAO,IAAK3G,EAAO2K,SAAU,IAAK3K,EAAM2K,SAAU1K,CAACA,GAAOK,GAAM,CAElE,KAAKd,EACH,MAAO,IAAKQ,EAAO0N,UAAWjH,EAAOE,QAASyH,QAAQ,GACxD,KAAK3O,EACI,MAAA,IAAKO,EAAOoF,WAAW,EAAMsI,UAAW,KAAMxN,MAAO,IAC9D,KAAKR,EACH,MAAO,IAAKM,EAAOoF,WAAW,GAChC,KAAKzF,EACI,MAAA,IAAKK,EAAOoF,WAAW,EAAOsI,UAAW,KAAMxN,MAAO,CAAA,EAAIkO,QAAQ,GAC3E,KAAKxO,EACH,MAAO,IAAKI,EAAOE,MAAOuG,EAAOE,SACnC,KAAK9G,EACH,MAAO,IAAKG,EAAO6N,OAAQpH,EAAOE,SACpC,KAAK7G,EACI,OAAAqO,EACT,QACS,OAAAnO,EAAA,EC1BXmO"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/lib/manifest.ts","../src/lib/actions.ts","../src/lib/reducer.ts","../src/lib/selectors.ts","../src/lib/utils.ts","../src/lib/selection-plugin.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { SelectionPluginConfig } from './types';\n\nexport const SELECTION_PLUGIN_ID = 'selection';\n\nexport const manifest: PluginManifest<SelectionPluginConfig> = {\n id: SELECTION_PLUGIN_ID,\n name: 'Selection Plugin',\n version: '1.0.0',\n provides: ['selection'],\n requires: ['interaction-manager'],\n optional: ['viewport', 'scroll'],\n defaultConfig: {\n enabled: true,\n menuHeight: 40,\n },\n};\n","import { Action } from '@embedpdf/core';\nimport { PdfPageGeometry, Rect } from '@embedpdf/models';\nimport { SelectionDocumentState, SelectionRangeX } from './types';\n\nexport const INIT_SELECTION_STATE = 'SELECTION/INIT_STATE';\nexport const CLEANUP_SELECTION_STATE = 'SELECTION/CLEANUP_STATE';\nexport const CACHE_PAGE_GEOMETRY = 'SELECTION/CACHE_PAGE_GEOMETRY';\nexport const SET_SELECTION = 'SELECTION/SET_SELECTION';\nexport const START_SELECTION = 'SELECTION/START_SELECTION';\nexport const END_SELECTION = 'SELECTION/END_SELECTION';\nexport const CLEAR_SELECTION = 'SELECTION/CLEAR_SELECTION';\nexport const SET_RECTS = 'SELECTION/SET_RECTS';\nexport const SET_SLICES = 'SELECTION/SET_SLICES';\nexport const RESET = 'SELECTION/RESET'; // This might be obsolete, but we'll keep it for now\n\nexport interface InitSelectionStateAction extends Action {\n type: typeof INIT_SELECTION_STATE;\n payload: {\n documentId: string;\n state: SelectionDocumentState;\n };\n}\n\nexport interface CleanupSelectionStateAction extends Action {\n type: typeof CLEANUP_SELECTION_STATE;\n payload: string; // documentId\n}\n\nexport interface CachePageGeometryAction extends Action {\n type: typeof CACHE_PAGE_GEOMETRY;\n payload: { documentId: string; page: number; geo: PdfPageGeometry };\n}\nexport interface SetSelectionAction extends Action {\n type: typeof SET_SELECTION;\n payload: { documentId: string; selection: SelectionRangeX | null };\n}\n\nexport interface StartSelectionAction extends Action {\n type: typeof START_SELECTION;\n payload: { documentId: string };\n}\n\nexport interface EndSelectionAction extends Action {\n type: typeof END_SELECTION;\n payload: { documentId: string };\n}\n\nexport interface ClearSelectionAction extends Action {\n type: typeof CLEAR_SELECTION;\n payload: { documentId: string };\n}\n\nexport interface SetRectsAction extends Action {\n type: typeof SET_RECTS;\n payload: { documentId: string; rects: Record<number, Rect[]> };\n}\n\nexport interface SetSlicesAction extends Action {\n type: typeof SET_SLICES;\n payload: { documentId: string; slices: Record<number, { start: number; count: number }> };\n}\n\nexport interface ResetAction extends Action {\n type: typeof RESET;\n payload: { documentId: string };\n}\n\nexport type SelectionAction =\n | InitSelectionStateAction\n | CleanupSelectionStateAction\n | CachePageGeometryAction\n | SetSelectionAction\n | StartSelectionAction\n | EndSelectionAction\n | ClearSelectionAction\n | SetRectsAction\n | SetSlicesAction\n | ResetAction;\n\nexport const initSelectionState = (\n documentId: string,\n state: SelectionDocumentState,\n): InitSelectionStateAction => ({\n type: INIT_SELECTION_STATE,\n payload: { documentId, state },\n});\n\nexport const cleanupSelectionState = (documentId: string): CleanupSelectionStateAction => ({\n type: CLEANUP_SELECTION_STATE,\n payload: documentId,\n});\n\nexport const cachePageGeometry = (\n documentId: string,\n page: number,\n geo: PdfPageGeometry,\n): CachePageGeometryAction => ({\n type: CACHE_PAGE_GEOMETRY,\n payload: { documentId, page, geo },\n});\n\nexport const setSelection = (\n documentId: string,\n sel: SelectionRangeX | null,\n): SetSelectionAction => ({\n type: SET_SELECTION,\n payload: { documentId, selection: sel },\n});\n\nexport const startSelection = (documentId: string): StartSelectionAction => ({\n type: START_SELECTION,\n payload: { documentId },\n});\n\nexport const endSelection = (documentId: string): EndSelectionAction => ({\n type: END_SELECTION,\n payload: { documentId },\n});\n\nexport const clearSelection = (documentId: string): ClearSelectionAction => ({\n type: CLEAR_SELECTION,\n payload: { documentId },\n});\n\nexport const setRects = (documentId: string, allRects: Record<number, Rect[]>): SetRectsAction => ({\n type: SET_RECTS,\n payload: { documentId, rects: allRects },\n});\n\nexport const setSlices = (\n documentId: string,\n slices: Record<number, { start: number; count: number }>,\n): SetSlicesAction => ({ type: SET_SLICES, payload: { documentId, slices } });\n\nexport const reset = (documentId: string): ResetAction => ({\n type: RESET,\n payload: { documentId },\n});\n","import { SelectionDocumentState, SelectionState } from './types';\nimport {\n SelectionAction,\n CACHE_PAGE_GEOMETRY,\n SET_SELECTION,\n START_SELECTION,\n END_SELECTION,\n CLEAR_SELECTION,\n RESET,\n SET_SLICES,\n SET_RECTS,\n INIT_SELECTION_STATE,\n CLEANUP_SELECTION_STATE,\n} from './actions';\n\nexport const initialSelectionDocumentState: SelectionDocumentState = {\n geometry: {},\n rects: {},\n slices: {},\n selection: null,\n active: false,\n selecting: false,\n};\n\nexport const initialState: SelectionState = {\n documents: {},\n};\n\nconst updateDocState = (\n state: SelectionState,\n documentId: string,\n newDocState: SelectionDocumentState,\n): SelectionState => ({\n ...state,\n documents: {\n ...state.documents,\n [documentId]: newDocState,\n },\n});\n\nexport const selectionReducer = (state = initialState, action: SelectionAction): SelectionState => {\n switch (action.type) {\n case INIT_SELECTION_STATE: {\n const { documentId, state: docState } = action.payload;\n return updateDocState(state, documentId, docState);\n }\n\n case CLEANUP_SELECTION_STATE: {\n const documentId = action.payload;\n const { [documentId]: removed, ...remaining } = state.documents;\n return {\n ...state,\n documents: remaining,\n };\n }\n\n case CACHE_PAGE_GEOMETRY: {\n const { documentId, page, geo } = action.payload;\n const docState = state.documents[documentId];\n if (!docState) return state;\n return updateDocState(state, documentId, {\n ...docState,\n geometry: { ...docState.geometry, [page]: geo },\n });\n }\n\n case SET_SELECTION: {\n const { documentId, selection } = action.payload;\n const docState = state.documents[documentId];\n if (!docState) return state;\n return updateDocState(state, documentId, {\n ...docState,\n selection,\n active: true,\n });\n }\n\n case START_SELECTION: {\n const { documentId } = action.payload;\n const docState = state.documents[documentId];\n if (!docState) return state;\n return updateDocState(state, documentId, {\n ...docState,\n selecting: true,\n selection: null,\n rects: {},\n });\n }\n\n case END_SELECTION: {\n const { documentId } = action.payload;\n const docState = state.documents[documentId];\n if (!docState) return state;\n return updateDocState(state, documentId, { ...docState, selecting: false });\n }\n\n case CLEAR_SELECTION: {\n const { documentId } = action.payload;\n const docState = state.documents[documentId];\n if (!docState) return state;\n return updateDocState(state, documentId, {\n ...docState,\n selecting: false,\n selection: null,\n rects: {},\n active: false,\n });\n }\n\n case SET_RECTS: {\n const { documentId, rects } = action.payload;\n const docState = state.documents[documentId];\n if (!docState) return state;\n return updateDocState(state, documentId, { ...docState, rects });\n }\n\n case SET_SLICES: {\n const { documentId, slices } = action.payload;\n const docState = state.documents[documentId];\n if (!docState) return state;\n return updateDocState(state, documentId, { ...docState, slices });\n }\n\n case RESET: {\n const { documentId } = action.payload;\n const docState = state.documents[documentId];\n if (!docState) return state;\n return updateDocState(state, documentId, initialSelectionDocumentState);\n }\n\n default:\n return state;\n }\n};\n","import { Rect, boundingRect } from '@embedpdf/models';\nimport { FormattedSelection, SelectionDocumentState } from './types';\n\nexport function selectRectsForPage(state: SelectionDocumentState, page: number) {\n return state.rects[page] ?? [];\n}\n\nexport function selectBoundingRectForPage(state: SelectionDocumentState, page: number) {\n return boundingRect(selectRectsForPage(state, page));\n}\n\nexport function selectRectsAndBoundingRectForPage(state: SelectionDocumentState, page: number) {\n return {\n rects: selectRectsForPage(state, page),\n boundingRect: selectBoundingRectForPage(state, page),\n };\n}\n\nexport function selectBoundingRectsForAllPages(state: SelectionDocumentState) {\n const out: { page: number; rect: Rect }[] = [];\n const rectMap = state.rects;\n\n for (const key in rectMap) {\n const page = Number(key);\n const bRect = boundingRect(rectMap[page]);\n if (bRect) out.push({ page, rect: bRect });\n }\n return out;\n}\n\nexport function getFormattedSelectionForPage(\n state: SelectionDocumentState,\n page: number,\n): FormattedSelection | null {\n const segmentRects = state.rects[page] || [];\n if (segmentRects.length === 0) return null;\n const boundingRect = selectBoundingRectForPage(state, page);\n if (!boundingRect) return null;\n return { pageIndex: page, rect: boundingRect, segmentRects };\n}\n\nexport function getFormattedSelection(state: SelectionDocumentState) {\n const result: FormattedSelection[] = [];\n\n // Get all pages that have rects\n const pages = Object.keys(state.rects).map(Number);\n\n for (const pageIndex of pages) {\n const segmentRects = state.rects[pageIndex] || [];\n\n if (segmentRects.length === 0) continue;\n\n // Calculate bounding rect for this page\n const boundingRect = selectBoundingRectForPage(state, pageIndex);\n\n if (boundingRect) {\n result.push({\n pageIndex,\n rect: boundingRect,\n segmentRects,\n });\n }\n }\n\n return result;\n}\n","import { PdfPageGeometry, Position, Rect } from '@embedpdf/models';\nimport { SelectionRangeX } from './types';\n\n/**\n * Hit-test helper using runs\n * @param geo - page geometry\n * @param pt - point\n * @returns glyph index\n */\nexport function glyphAt(geo: PdfPageGeometry, pt: Position) {\n for (const run of geo.runs) {\n const inRun =\n pt.y >= run.rect.y &&\n pt.y <= run.rect.y + run.rect.height &&\n pt.x >= run.rect.x &&\n pt.x <= run.rect.x + run.rect.width;\n\n if (!inRun) continue;\n\n // Simply check if the point is within any glyph's bounding box\n const rel = run.glyphs.findIndex(\n (g) => pt.x >= g.x && pt.x <= g.x + g.width && pt.y >= g.y && pt.y <= g.y + g.height,\n );\n\n if (rel !== -1) {\n return run.charStart + rel;\n }\n }\n return -1;\n}\n\n/**\n * Helper: min/max glyph indices on `page` for current sel\n * @param sel - selection range\n * @param geo - page geometry\n * @param page - page index\n * @returns { from: number; to: number } | null\n */\nexport function sliceBounds(\n sel: SelectionRangeX | null,\n geo: PdfPageGeometry | undefined,\n page: number,\n): { from: number; to: number } | null {\n if (!sel || !geo) return null;\n if (page < sel.start.page || page > sel.end.page) return null;\n\n const from = page === sel.start.page ? sel.start.index : 0;\n\n const lastRun = geo.runs[geo.runs.length - 1];\n const lastCharOnPage = lastRun.charStart + lastRun.glyphs.length - 1;\n\n const to = page === sel.end.page ? sel.end.index : lastCharOnPage;\n\n return { from, to };\n}\n\n/**\n * Helper: build rects for a slice of the page\n * @param geo - page geometry\n * @param from - from index\n * @param to - to index\n * @param merge - whether to merge adjacent rects (default: true)\n * @returns rects\n */\nexport function rectsWithinSlice(\n geo: PdfPageGeometry,\n from: number,\n to: number,\n merge: boolean = true,\n): Rect[] {\n const textRuns: TextRunInfo[] = [];\n\n for (const run of geo.runs) {\n const runStart = run.charStart;\n const runEnd = runStart + run.glyphs.length - 1;\n if (runEnd < from || runStart > to) continue;\n\n const sIdx = Math.max(from, runStart) - runStart;\n const eIdx = Math.min(to, runEnd) - runStart;\n\n let minX = Infinity,\n maxX = -Infinity;\n let minY = Infinity,\n maxY = -Infinity;\n let charCount = 0;\n\n for (let i = sIdx; i <= eIdx; i++) {\n const g = run.glyphs[i];\n if (g.flags === 2) continue; // empty glyph\n\n minX = Math.min(minX, g.x);\n maxX = Math.max(maxX, g.x + g.width);\n minY = Math.min(minY, g.y);\n maxY = Math.max(maxY, g.y + g.height);\n charCount++;\n }\n\n if (minX !== Infinity && charCount > 0) {\n textRuns.push({\n rect: {\n origin: { x: minX, y: minY },\n size: { width: maxX - minX, height: maxY - minY },\n },\n charCount,\n });\n }\n }\n\n // If merge is false, just return the individual rects\n if (!merge) {\n return textRuns.map((run) => run.rect);\n }\n\n // Otherwise merge adjacent rects\n return mergeAdjacentRects(textRuns);\n}\n\n/**\n * ============================================================================\n * Rectangle Merging Algorithm\n * ============================================================================\n *\n * The following code is adapted from Chromium's PDF text selection implementation.\n *\n * Copyright 2010 The Chromium Authors\n * Use of this source code is governed by a BSD-style license that can be\n * found in the LICENSE file: https://source.chromium.org/chromium/chromium/src/+/main:LICENSE\n *\n * Original source:\n * https://source.chromium.org/chromium/chromium/src/+/main:pdf/pdfium/pdfium_range.cc\n *\n * Adapted for TypeScript and this project's Rect/geometry types.\n */\n\n/**\n * Text run info for rect merging (similar to Chromium's ScreenRectTextRunInfo)\n */\nexport interface TextRunInfo {\n rect: Rect;\n charCount: number;\n}\n\n/**\n * Helper functions for Rect operations\n */\nexport function rectUnion(rect1: Rect, rect2: Rect): Rect {\n const left = Math.min(rect1.origin.x, rect2.origin.x);\n const top = Math.min(rect1.origin.y, rect2.origin.y);\n const right = Math.max(rect1.origin.x + rect1.size.width, rect2.origin.x + rect2.size.width);\n const bottom = Math.max(rect1.origin.y + rect1.size.height, rect2.origin.y + rect2.size.height);\n\n return {\n origin: { x: left, y: top },\n size: { width: right - left, height: bottom - top },\n };\n}\n\nexport function rectIntersect(rect1: Rect, rect2: Rect): Rect {\n const left = Math.max(rect1.origin.x, rect2.origin.x);\n const top = Math.max(rect1.origin.y, rect2.origin.y);\n const right = Math.min(rect1.origin.x + rect1.size.width, rect2.origin.x + rect2.size.width);\n const bottom = Math.min(rect1.origin.y + rect1.size.height, rect2.origin.y + rect2.size.height);\n\n const width = Math.max(0, right - left);\n const height = Math.max(0, bottom - top);\n\n return {\n origin: { x: left, y: top },\n size: { width, height },\n };\n}\n\nexport function rectIsEmpty(rect: Rect): boolean {\n return rect.size.width <= 0 || rect.size.height <= 0;\n}\n\n/**\n * Returns a ratio between [0, 1] representing vertical overlap\n */\nexport function getVerticalOverlap(rect1: Rect, rect2: Rect): number {\n if (rectIsEmpty(rect1) || rectIsEmpty(rect2)) return 0;\n\n const unionRect = rectUnion(rect1, rect2);\n\n if (unionRect.size.height === rect1.size.height || unionRect.size.height === rect2.size.height) {\n return 1.0;\n }\n\n const intersectRect = rectIntersect(rect1, rect2);\n return intersectRect.size.height / unionRect.size.height;\n}\n\n/**\n * Returns true if there is sufficient horizontal and vertical overlap\n */\nexport function shouldMergeHorizontalRects(textRun1: TextRunInfo, textRun2: TextRunInfo): boolean {\n const VERTICAL_OVERLAP_THRESHOLD = 0.8;\n const rect1 = textRun1.rect;\n const rect2 = textRun2.rect;\n\n if (getVerticalOverlap(rect1, rect2) < VERTICAL_OVERLAP_THRESHOLD) {\n return false;\n }\n\n const HORIZONTAL_WIDTH_FACTOR = 1.0;\n const averageWidth1 = (HORIZONTAL_WIDTH_FACTOR * rect1.size.width) / textRun1.charCount;\n const averageWidth2 = (HORIZONTAL_WIDTH_FACTOR * rect2.size.width) / textRun2.charCount;\n\n const rect1Left = rect1.origin.x - averageWidth1;\n const rect1Right = rect1.origin.x + rect1.size.width + averageWidth1;\n const rect2Left = rect2.origin.x - averageWidth2;\n const rect2Right = rect2.origin.x + rect2.size.width + averageWidth2;\n\n return rect1Left < rect2Right && rect1Right > rect2Left;\n}\n\n/**\n * Merge adjacent rectangles based on proximity and overlap (similar to Chromium's algorithm)\n */\nexport function mergeAdjacentRects(textRuns: TextRunInfo[]): Rect[] {\n const results: Rect[] = [];\n let previousTextRun: TextRunInfo | null = null;\n let currentRect: Rect | null = null;\n\n for (const textRun of textRuns) {\n if (previousTextRun && currentRect) {\n if (shouldMergeHorizontalRects(previousTextRun, textRun)) {\n currentRect = rectUnion(currentRect, textRun.rect);\n } else {\n results.push(currentRect);\n currentRect = textRun.rect;\n }\n } else {\n currentRect = textRun.rect;\n }\n previousTextRun = textRun;\n }\n\n if (currentRect && !rectIsEmpty(currentRect)) {\n results.push(currentRect);\n }\n\n return results;\n}\n","import {\n BasePlugin,\n Listener,\n PluginRegistry,\n REFRESH_PAGES,\n createScopedEmitter,\n} from '@embedpdf/core';\nimport {\n PdfPageGeometry,\n Rect,\n PdfTask,\n PdfTaskHelper,\n PdfErrorCode,\n ignore,\n PageTextSlice,\n Task,\n Position,\n} from '@embedpdf/models';\nimport {\n InteractionManagerCapability,\n InteractionManagerPlugin,\n PointerEventHandlersWithLifecycle,\n} from '@embedpdf/plugin-interaction-manager';\nimport { ViewportCapability, ViewportMetrics, ViewportPlugin } from '@embedpdf/plugin-viewport';\nimport { ScrollCapability, ScrollPlugin } from '@embedpdf/plugin-scroll';\n\nimport {\n cachePageGeometry,\n setSelection,\n SelectionAction,\n endSelection,\n startSelection,\n clearSelection,\n setRects,\n setSlices,\n initSelectionState,\n cleanupSelectionState,\n} from './actions';\nimport { initialSelectionDocumentState } from './reducer';\nimport * as selector from './selectors';\nimport {\n SelectionCapability,\n SelectionPluginConfig,\n SelectionRangeX,\n SelectionState,\n RegisterSelectionOnPageOptions,\n SelectionRectsCallback,\n SelectionScope,\n SelectionChangeEvent,\n TextRetrievedEvent,\n CopyToClipboardEvent,\n BeginSelectionEvent,\n EndSelectionEvent,\n SelectionDocumentState,\n SelectionMenuPlacement,\n SelectionMenuPlacementEvent,\n} from './types';\nimport { sliceBounds, rectsWithinSlice, glyphAt } from './utils';\n\nexport class SelectionPlugin extends BasePlugin<\n SelectionPluginConfig,\n SelectionCapability,\n SelectionState,\n SelectionAction\n> {\n static readonly id = 'selection' as const;\n\n /** Modes that should trigger text-selection logic, per document */\n private enabledModesPerDoc = new Map<string, Set<string>>();\n\n /* interactive state, per document */\n private selecting = new Map<string, boolean>();\n private anchor = new Map<string, { page: number; index: number } | undefined>();\n\n /** Page callbacks for rect updates, per document */\n private pageCallbacks = new Map<string, Map<number, (data: SelectionRectsCallback) => void>>();\n\n private readonly menuPlacement$ = createScopedEmitter<\n SelectionMenuPlacement | null,\n SelectionMenuPlacementEvent,\n string\n >((documentId, placement) => ({ documentId, placement }));\n private readonly selChange$ = createScopedEmitter<\n SelectionRangeX | null,\n SelectionChangeEvent,\n string\n >((documentId, selection) => ({ documentId, selection }));\n private readonly textRetrieved$ = createScopedEmitter<string[], TextRetrievedEvent, string>(\n (documentId, text) => ({ documentId, text }),\n );\n private readonly copyToClipboard$ = createScopedEmitter<string, CopyToClipboardEvent, string>(\n (documentId, text) => ({ documentId, text }),\n { cache: false },\n );\n private readonly beginSelection$ = createScopedEmitter<\n { page: number; index: number },\n BeginSelectionEvent,\n string\n >((documentId, data) => ({ documentId, page: data.page, index: data.index }), { cache: false });\n private readonly endSelection$ = createScopedEmitter<void, EndSelectionEvent, string>(\n (documentId) => ({ documentId }),\n { cache: false },\n );\n\n private interactionManagerCapability: InteractionManagerCapability;\n private viewportCapability: ViewportCapability | null = null;\n private scrollCapability: ScrollCapability | null = null;\n\n private readonly menuHeight: number;\n\n constructor(id: string, registry: PluginRegistry, config: SelectionPluginConfig) {\n super(id, registry);\n this.menuHeight = config.menuHeight ?? 40;\n\n const imPlugin = registry.getPlugin<InteractionManagerPlugin>('interaction-manager');\n if (!imPlugin) {\n throw new Error('SelectionPlugin: InteractionManagerPlugin is required.');\n }\n this.interactionManagerCapability = imPlugin.provides();\n this.viewportCapability = registry.getPlugin<ViewportPlugin>('viewport')?.provides() ?? null;\n this.scrollCapability = registry.getPlugin<ScrollPlugin>('scroll')?.provides() ?? null;\n\n this.coreStore.onAction(REFRESH_PAGES, (action) => {\n const { documentId, pageIndexes } = action.payload;\n const tasks = pageIndexes.map((pageIndex) =>\n this.getNewPageGeometryAndCache(documentId, pageIndex),\n );\n Task.all(tasks).wait(() => {\n // Notify affected pages about geometry updates\n pageIndexes.forEach((pageIndex) => {\n this.notifyPage(documentId, pageIndex);\n });\n }, ignore);\n });\n\n this.viewportCapability?.onViewportChange(\n (event) => {\n this.recalculateMenuPlacement(event.documentId);\n },\n { mode: 'throttle', wait: 100 },\n );\n }\n\n /* ── life-cycle ────────────────────────────────────────── */\n protected override onDocumentLoadingStarted(documentId: string): void {\n this.dispatch(initSelectionState(documentId, initialSelectionDocumentState));\n this.enabledModesPerDoc.set(documentId, new Set<string>(['pointerMode']));\n this.pageCallbacks.set(documentId, new Map());\n this.selecting.set(documentId, false);\n this.anchor.set(documentId, undefined);\n }\n\n protected override onDocumentClosed(documentId: string): void {\n this.dispatch(cleanupSelectionState(documentId));\n this.enabledModesPerDoc.delete(documentId);\n this.pageCallbacks.delete(documentId);\n this.selecting.delete(documentId);\n this.anchor.delete(documentId);\n this.selChange$.clearScope(documentId);\n this.textRetrieved$.clearScope(documentId);\n this.copyToClipboard$.clearScope(documentId);\n this.beginSelection$.clearScope(documentId);\n this.endSelection$.clearScope(documentId);\n this.menuPlacement$.clearScope(documentId);\n }\n\n async initialize() {}\n async destroy() {\n this.selChange$.clear();\n this.textRetrieved$.clear();\n this.copyToClipboard$.clear();\n this.beginSelection$.clear();\n this.endSelection$.clear();\n this.menuPlacement$.clear();\n super.destroy();\n }\n\n /* ── capability exposed to UI / other plugins ─────────── */\n buildCapability(): SelectionCapability {\n const getDocId = (documentId?: string) => documentId ?? this.getActiveDocumentId();\n\n return {\n // Active document operations\n getFormattedSelection: (docId) =>\n selector.getFormattedSelection(this.getDocumentState(getDocId(docId))),\n getFormattedSelectionForPage: (p, docId) =>\n selector.getFormattedSelectionForPage(this.getDocumentState(getDocId(docId)), p),\n getHighlightRectsForPage: (p, docId) =>\n selector.selectRectsForPage(this.getDocumentState(getDocId(docId)), p),\n getHighlightRects: (docId) => this.getDocumentState(getDocId(docId)).rects,\n getBoundingRectForPage: (p, docId) =>\n selector.selectBoundingRectForPage(this.getDocumentState(getDocId(docId)), p),\n getBoundingRects: (docId) =>\n selector.selectBoundingRectsForAllPages(this.getDocumentState(getDocId(docId))),\n getSelectedText: (docId) => this.getSelectedText(getDocId(docId)),\n clear: (docId) => this.clearSelection(getDocId(docId)),\n copyToClipboard: (docId) => this.copyToClipboard(getDocId(docId)),\n getState: (docId) => this.getDocumentState(getDocId(docId)),\n enableForMode: (modeId, docId) => this.enabledModesPerDoc.get(getDocId(docId))?.add(modeId),\n isEnabledForMode: (modeId, docId) =>\n this.enabledModesPerDoc.get(getDocId(docId))?.has(modeId) ?? false,\n\n // Document-scoped operations\n forDocument: this.createSelectionScope.bind(this),\n\n // Global events\n onCopyToClipboard: this.copyToClipboard$.onGlobal,\n onSelectionChange: this.selChange$.onGlobal,\n onTextRetrieved: this.textRetrieved$.onGlobal,\n onBeginSelection: this.beginSelection$.onGlobal,\n onEndSelection: this.endSelection$.onGlobal,\n };\n }\n\n private createSelectionScope(documentId: string): SelectionScope {\n return {\n getFormattedSelection: () =>\n selector.getFormattedSelection(this.getDocumentState(documentId)),\n getFormattedSelectionForPage: (p) =>\n selector.getFormattedSelectionForPage(this.getDocumentState(documentId), p),\n getHighlightRectsForPage: (p) =>\n selector.selectRectsForPage(this.getDocumentState(documentId), p),\n getHighlightRects: () => this.getDocumentState(documentId).rects,\n getBoundingRectForPage: (p) =>\n selector.selectBoundingRectForPage(this.getDocumentState(documentId), p),\n getBoundingRects: () =>\n selector.selectBoundingRectsForAllPages(this.getDocumentState(documentId)),\n getSelectedText: () => this.getSelectedText(documentId),\n clear: () => this.clearSelection(documentId),\n copyToClipboard: () => this.copyToClipboard(documentId),\n getState: () => this.getDocumentState(documentId),\n onSelectionChange: this.selChange$.forScope(documentId),\n onTextRetrieved: this.textRetrieved$.forScope(documentId),\n onCopyToClipboard: this.copyToClipboard$.forScope(documentId),\n onBeginSelection: this.beginSelection$.forScope(documentId),\n onEndSelection: this.endSelection$.forScope(documentId),\n };\n }\n\n private getDocumentState(documentId: string): SelectionDocumentState {\n const state = this.state.documents[documentId];\n if (!state) {\n throw new Error(`Selection state not found for document: ${documentId}`);\n }\n return state;\n }\n\n /**\n * Subscribe to menu placement changes for a specific document\n * @param documentId - The document ID to subscribe to\n * @param listener - Callback function that receives placement updates\n * @returns Unsubscribe function\n */\n public onMenuPlacement(\n documentId: string,\n listener: (placement: SelectionMenuPlacement | null) => void,\n ) {\n return this.menuPlacement$.forScope(documentId)(listener);\n }\n\n public registerSelectionOnPage(opts: RegisterSelectionOnPageOptions) {\n const { documentId, pageIndex, onRectsChange } = opts;\n const docState = this.state.documents[documentId];\n\n if (!docState) {\n this.logger.warn(\n 'SelectionPlugin',\n 'RegisterFailed',\n `Cannot register selection on page ${pageIndex} for document ${documentId}: document state not initialized.`,\n );\n return () => {};\n }\n\n // Track this callback for the page\n this.pageCallbacks.get(documentId)?.set(pageIndex, onRectsChange);\n\n const geoTask = this.getOrLoadGeometry(documentId, pageIndex);\n const interactionScope = this.interactionManagerCapability.forDocument(documentId);\n const enabledModes = this.enabledModesPerDoc.get(documentId);\n\n // Send initial state\n onRectsChange({\n rects: selector.selectRectsForPage(docState, pageIndex),\n boundingRect: selector.selectBoundingRectForPage(docState, pageIndex),\n });\n\n const handlers: PointerEventHandlersWithLifecycle<PointerEvent> = {\n onPointerDown: (point: Position, _evt, modeId) => {\n if (!enabledModes?.has(modeId)) return;\n\n // Clear the selection\n this.clearSelection(documentId);\n\n // Get geometry from cache (or load if needed)\n const cached = this.getDocumentState(documentId).geometry[pageIndex];\n if (cached) {\n const g = glyphAt(cached, point);\n if (g !== -1) {\n this.beginSelection(documentId, pageIndex, g);\n }\n }\n },\n onPointerMove: (point: Position, _evt, modeId) => {\n if (!enabledModes?.has(modeId)) return;\n\n // Get cached geometry (should be instant if already loaded)\n const cached = this.getDocumentState(documentId).geometry[pageIndex];\n if (cached) {\n const g = glyphAt(cached, point);\n\n // Update cursor\n if (g !== -1) {\n interactionScope.setCursor('selection-text', 'text', 10);\n } else {\n interactionScope.removeCursor('selection-text');\n }\n\n // Update selection if we're selecting\n if (this.selecting.get(documentId) && g !== -1) {\n this.updateSelection(documentId, pageIndex, g);\n }\n }\n },\n onPointerUp: (_point: Position, _evt, modeId) => {\n if (!enabledModes?.has(modeId)) return;\n this.endSelection(documentId);\n },\n onHandlerActiveEnd: (modeId) => {\n if (!enabledModes?.has(modeId)) return;\n this.clearSelection(documentId);\n },\n };\n\n // Register the handlers with interaction manager for all enabled modes\n // This assumes `registerAlways` is a method that runs handlers for *any* mode,\n // and the handler itself checks the `modeId`.\n // If `registerAlways` is not available, this would need to register\n // for each mode in `enabledModes` separately.\n const unregisterHandlers = this.interactionManagerCapability.registerAlways({\n scope: { type: 'page', documentId, pageIndex },\n handlers,\n });\n\n // Return cleanup function\n return () => {\n unregisterHandlers();\n this.pageCallbacks.get(documentId)?.delete(pageIndex);\n geoTask.abort({ code: PdfErrorCode.Cancelled, message: 'Cleanup' });\n };\n }\n\n /**\n * Helper to calculate viewport relative metrics for a page rect.\n * Returns null if the rect cannot be converted to viewport space.\n */\n private getPlacementMetrics(\n documentId: string,\n pageIndex: number,\n rect: Rect,\n vpMetrics: ViewportMetrics,\n ) {\n // 1. Convert Page Coordinate -> Viewport Coordinate\n // We use the scroll capability to handle rotation, scale, and scroll offset automatically\n const scrollScope = this.scrollCapability?.forDocument(documentId);\n const viewportRect = scrollScope?.getRectPositionForPage(pageIndex, rect);\n\n if (!viewportRect) return null;\n\n // 2. Calculate relative positions\n const rectTopInView = viewportRect.origin.y - vpMetrics.scrollTop;\n const rectBottomInView = viewportRect.origin.y + viewportRect.size.height - vpMetrics.scrollTop;\n\n return {\n pageIndex,\n rect, // Original Page Rect\n spaceAbove: rectTopInView,\n spaceBelow: vpMetrics.clientHeight - rectBottomInView,\n isBottomVisible: rectBottomInView > 0 && rectBottomInView <= vpMetrics.clientHeight,\n isTopVisible: rectTopInView >= 0 && rectTopInView < vpMetrics.clientHeight,\n };\n }\n\n private recalculateMenuPlacement(documentId: string) {\n const docState = this.state.documents[documentId];\n if (!docState) return;\n\n // Only show menu when not actively selecting\n if (docState.selecting || docState.selection === null) {\n this.menuPlacement$.emit(documentId, null);\n return;\n }\n\n // 1. Get Bounding Rects for all pages involved in selection.\n // These are implicitly sorted by pageIndex because updateRectsAndSlices\n // populates the map in ascending page order.\n const bounds = selector.selectBoundingRectsForAllPages(docState);\n\n if (bounds.length === 0) {\n this.menuPlacement$.emit(documentId, null);\n return;\n }\n\n const tail = bounds[bounds.length - 1];\n\n // Fallback: If viewport/scroll plugins are missing, always default to bottom of the last rect\n if (!this.viewportCapability || !this.scrollCapability) {\n this.menuPlacement$.emit(documentId, {\n pageIndex: tail.page,\n rect: tail.rect,\n spaceAbove: 0,\n spaceBelow: Infinity, // Pretend we have infinite space below to prevent auto-flipping\n suggestTop: false,\n isVisible: true, // Assume visible\n });\n return;\n }\n\n // Use document-scoped viewport to get metrics for this specific document\n const viewportScope = this.viewportCapability.forDocument(documentId);\n const vpMetrics = viewportScope.getMetrics();\n\n // 2. Calculate metrics for Head (Start) and Tail (End)\n const head = bounds[0];\n\n const tailMetrics = this.getPlacementMetrics(documentId, tail.page, tail.rect, vpMetrics);\n const headMetrics = this.getPlacementMetrics(documentId, head.page, head.rect, vpMetrics);\n\n // 3. Apply Heuristic Logic\n\n // Priority A: Bottom of Tail (Standard selection end)\n // If the bottom of the selection is visible and we have space below.\n if (tailMetrics) {\n if (tailMetrics.isBottomVisible && tailMetrics.spaceBelow > this.menuHeight) {\n this.menuPlacement$.emit(documentId, {\n ...tailMetrics,\n suggestTop: false,\n isVisible: true,\n });\n return;\n }\n }\n\n // Priority B: Top of Head (Selection start, if user scrolled up)\n // If the top of the start selection is visible, put the menu there.\n if (headMetrics) {\n if (headMetrics.isTopVisible) {\n this.menuPlacement$.emit(documentId, {\n ...headMetrics,\n suggestTop: true,\n isVisible: true,\n });\n return;\n }\n }\n\n // Priority C: Fallback to Tail Bottom if visible (even if tight space)\n // It's better to stick to the cursor end than jump to the top if space is tight.\n if (tailMetrics && tailMetrics.isBottomVisible) {\n this.menuPlacement$.emit(documentId, {\n ...tailMetrics,\n suggestTop: false,\n isVisible: true,\n });\n return;\n }\n\n // If completely off screen\n this.menuPlacement$.emit(documentId, null);\n }\n\n private notifyPage(documentId: string, pageIndex: number) {\n const callback = this.pageCallbacks.get(documentId)?.get(pageIndex);\n if (callback) {\n const docState = this.getDocumentState(documentId);\n const mode = this.interactionManagerCapability.forDocument(documentId).getActiveMode();\n if (mode === 'pointerMode') {\n callback({\n rects: selector.selectRectsForPage(docState, pageIndex),\n boundingRect: selector.selectBoundingRectForPage(docState, pageIndex),\n });\n } else {\n callback({ rects: [], boundingRect: null });\n }\n }\n }\n\n private notifyAllPages(documentId: string) {\n this.pageCallbacks.get(documentId)?.forEach((_, pageIndex) => {\n this.notifyPage(documentId, pageIndex);\n });\n }\n\n private getNewPageGeometryAndCache(\n documentId: string,\n pageIdx: number,\n ): PdfTask<PdfPageGeometry> {\n const coreDoc = this.getCoreDocument(documentId);\n if (!coreDoc || !coreDoc.document)\n return PdfTaskHelper.reject({ code: PdfErrorCode.NotFound, message: 'Doc Not Found' });\n\n const page = coreDoc.document.pages.find((p) => p.index === pageIdx)!;\n const task = this.engine.getPageGeometry(coreDoc.document, page);\n task.wait((geo) => {\n this.dispatch(cachePageGeometry(documentId, pageIdx, geo));\n }, ignore);\n return task;\n }\n\n /* ── geometry cache ───────────────────────────────────── */\n private getOrLoadGeometry(documentId: string, pageIdx: number): PdfTask<PdfPageGeometry> {\n const cached = this.getDocumentState(documentId).geometry[pageIdx];\n if (cached) return PdfTaskHelper.resolve(cached);\n\n return this.getNewPageGeometryAndCache(documentId, pageIdx);\n }\n\n /* ── selection state updates ───────────────────────────── */\n private beginSelection(documentId: string, page: number, index: number) {\n this.selecting.set(documentId, true);\n this.anchor.set(documentId, { page, index });\n this.dispatch(startSelection(documentId));\n this.beginSelection$.emit(documentId, { page, index });\n this.recalculateMenuPlacement(documentId);\n }\n\n private endSelection(documentId: string) {\n this.selecting.set(documentId, false);\n this.anchor.set(documentId, undefined);\n this.dispatch(endSelection(documentId));\n this.endSelection$.emit(documentId);\n this.recalculateMenuPlacement(documentId);\n }\n\n private clearSelection(documentId: string) {\n this.selecting.set(documentId, false);\n this.anchor.set(documentId, undefined);\n this.dispatch(clearSelection(documentId));\n this.selChange$.emit(documentId, null);\n this.menuPlacement$.emit(documentId, null);\n this.notifyAllPages(documentId);\n }\n\n private updateSelection(documentId: string, page: number, index: number) {\n if (!this.selecting.get(documentId) || !this.anchor.get(documentId)) return;\n\n const a = this.anchor.get(documentId)!;\n const forward = page > a.page || (page === a.page && index >= a.index);\n\n const start = forward ? a : { page, index };\n const end = forward ? { page, index } : a;\n\n const range = { start, end };\n this.dispatch(setSelection(documentId, range));\n this.updateRectsAndSlices(documentId, range);\n this.selChange$.emit(documentId, range);\n\n // Notify affected pages\n for (let p = range.start.page; p <= range.end.page; p++) {\n this.notifyPage(documentId, p);\n }\n }\n\n private updateRectsAndSlices(documentId: string, range: SelectionRangeX) {\n const docState = this.getDocumentState(documentId);\n const allRects: Record<number, Rect[]> = {};\n const allSlices: Record<number, { start: number; count: number }> = {};\n\n for (let p = range.start.page; p <= range.end.page; p++) {\n const geo = docState.geometry[p];\n const sb = sliceBounds(range, geo, p);\n if (!sb) continue;\n\n allRects[p] = rectsWithinSlice(geo!, sb.from, sb.to);\n allSlices[p] = { start: sb.from, count: sb.to - sb.from + 1 };\n }\n\n this.dispatch(setRects(documentId, allRects));\n this.dispatch(setSlices(documentId, allSlices));\n }\n\n private getSelectedText(documentId: string): PdfTask<string[]> {\n const coreDoc = this.getCoreDocument(documentId);\n const docState = this.getDocumentState(documentId);\n\n if (!coreDoc?.document || !docState.selection) {\n return PdfTaskHelper.reject({\n code: PdfErrorCode.NotFound,\n message: 'Doc Not Found or No Selection',\n });\n }\n\n const sel = docState.selection;\n const req: PageTextSlice[] = [];\n\n for (let p = sel.start.page; p <= sel.end.page; p++) {\n const s = docState.slices[p];\n if (s) req.push({ pageIndex: p, charIndex: s.start, charCount: s.count });\n }\n\n if (req.length === 0) return PdfTaskHelper.resolve([] as string[]);\n\n const task = this.engine.getTextSlices(coreDoc.document, req);\n\n // Emit the text when it's retrieved\n task.wait((text) => {\n this.textRetrieved$.emit(documentId, text);\n }, ignore);\n\n return task;\n }\n\n private copyToClipboard(documentId: string) {\n const text = this.getSelectedText(documentId);\n text.wait((text) => {\n this.copyToClipboard$.emit(documentId, text.join('\\n'));\n }, ignore);\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, SELECTION_PLUGIN_ID } from './manifest';\nimport { SelectionPluginConfig, SelectionState } from './types';\n\nimport { SelectionPlugin } from './selection-plugin';\nimport { SelectionAction } from './actions';\nimport { selectionReducer, initialState } from './reducer';\n\nexport const SelectionPluginPackage: PluginPackage<\n SelectionPlugin,\n SelectionPluginConfig,\n SelectionState,\n SelectionAction\n> = {\n manifest,\n create: (registry, config) => new SelectionPlugin(SELECTION_PLUGIN_ID, registry, config),\n reducer: selectionReducer,\n initialState,\n};\n\nexport * from './selection-plugin';\nexport * from './types';\nexport * from './manifest';\nexport * from './utils';\n"],"names":["SELECTION_PLUGIN_ID","manifest","id","name","version","provides","requires","optional","defaultConfig","enabled","menuHeight","INIT_SELECTION_STATE","CLEANUP_SELECTION_STATE","CACHE_PAGE_GEOMETRY","SET_SELECTION","START_SELECTION","END_SELECTION","CLEAR_SELECTION","SET_RECTS","SET_SLICES","initialSelectionDocumentState","geometry","rects","slices","selection","active","selecting","initialState","documents","updateDocState","state","documentId","newDocState","selectRectsForPage","page","selectBoundingRectForPage","boundingRect","selectBoundingRectsForAllPages","out","rectMap","key","Number","bRect","push","rect","getFormattedSelectionForPage","segmentRects","length","pageIndex","getFormattedSelection","result","pages","Object","keys","map","glyphAt","geo","pt","run","runs","y","height","x","width","rel","glyphs","findIndex","g","charStart","sliceBounds","sel","start","end","from","index","lastRun","lastCharOnPage","to","rectsWithinSlice","merge","textRuns","runStart","runEnd","sIdx","Math","max","eIdx","min","minX","Infinity","maxX","minY","maxY","charCount","i","flags","origin","size","mergeAdjacentRects","rectUnion","rect1","rect2","left","top","rectIntersect","right","bottom","rectIsEmpty","getVerticalOverlap","unionRect","shouldMergeHorizontalRects","textRun1","textRun2","averageWidth1","averageWidth2","rect1Left","rect1Right","rect2Left","results","previousTextRun","currentRect","textRun","_SelectionPlugin","BasePlugin","constructor","registry","config","super","this","enabledModesPerDoc","Map","anchor","pageCallbacks","menuPlacement$","createScopedEmitter","placement","selChange$","textRetrieved$","text","copyToClipboard$","cache","beginSelection$","data","endSelection$","viewportCapability","scrollCapability","imPlugin","getPlugin","Error","interactionManagerCapability","_a","_b","coreStore","onAction","REFRESH_PAGES","action","pageIndexes","payload","tasks","getNewPageGeometryAndCache","Task","all","wait","forEach","notifyPage","ignore","_c","onViewportChange","event","recalculateMenuPlacement","mode","onDocumentLoadingStarted","dispatch","type","initSelectionState","set","Set","onDocumentClosed","cleanupSelectionState","delete","clearScope","initialize","destroy","clear","buildCapability","getDocId","getActiveDocumentId","docId","selector.getFormattedSelection","getDocumentState","p","selector.getFormattedSelectionForPage","getHighlightRectsForPage","selector.selectRectsForPage","getHighlightRects","getBoundingRectForPage","selector.selectBoundingRectForPage","getBoundingRects","selector.selectBoundingRectsForAllPages","getSelectedText","clearSelection","copyToClipboard","getState","enableForMode","modeId","get","add","isEnabledForMode","has","forDocument","createSelectionScope","bind","onCopyToClipboard","onGlobal","onSelectionChange","onTextRetrieved","onBeginSelection","onEndSelection","forScope","onMenuPlacement","listener","registerSelectionOnPage","opts","onRectsChange","docState","logger","warn","geoTask","getOrLoadGeometry","interactionScope","enabledModes","handlers","onPointerDown","point","_evt","cached","beginSelection","onPointerMove","setCursor","removeCursor","updateSelection","onPointerUp","_point","endSelection","onHandlerActiveEnd","unregisterHandlers","registerAlways","scope","abort","code","PdfErrorCode","Cancelled","message","getPlacementMetrics","vpMetrics","scrollScope","viewportRect","getRectPositionForPage","rectTopInView","scrollTop","rectBottomInView","spaceAbove","spaceBelow","clientHeight","isBottomVisible","isTopVisible","emit","bounds","tail","suggestTop","isVisible","getMetrics","head","tailMetrics","headMetrics","callback","getActiveMode","notifyAllPages","_","pageIdx","coreDoc","getCoreDocument","document","PdfTaskHelper","reject","NotFound","find","task","engine","getPageGeometry","cachePageGeometry","resolve","startSelection","a","forward","range","setSelection","updateRectsAndSlices","allRects","allSlices","sb","count","setRects","setSlices","req","s","charIndex","getTextSlices","join","SelectionPlugin","SelectionPluginPackage","create","reducer","removed","remaining"],"mappings":"gJAGaA,EAAsB,YAEtBC,EAAkD,CAC7DC,GAAIF,EACJG,KAAM,mBACNC,QAAS,QACTC,SAAU,CAAC,aACXC,SAAU,CAAC,uBACXC,SAAU,CAAC,WAAY,UACvBC,cAAe,CACbC,SAAS,EACTC,WAAY,KCVHC,EAAuB,uBACvBC,EAA0B,0BAC1BC,EAAsB,gCACtBC,EAAgB,0BAChBC,EAAkB,4BAClBC,EAAgB,0BAChBC,EAAkB,4BAClBC,EAAY,sBACZC,EAAa,uBCGbC,EAAwD,CACnEC,SAAU,CAAA,EACVC,MAAO,CAAA,EACPC,OAAQ,CAAA,EACRC,UAAW,KACXC,QAAQ,EACRC,WAAW,GAGAC,EAA+B,CAC1CC,UAAW,CAAA,GAGPC,EAAiB,CACrBC,EACAC,EACAC,KAAA,IAEGF,EACHF,UAAW,IACNE,EAAMF,UACTG,CAACA,GAAaC,KCjCX,SAASC,EAAmBH,EAA+BI,GAChE,OAAOJ,EAAMR,MAAMY,IAAS,EAC9B,CAEO,SA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