@embedpdf/plugin-spread 1.4.1 → 2.0.0-next.0

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 CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core");var t=(e=>(e.None="none",e.Odd="odd",e.Even="even",e))(t||{});const a="SET_SPREAD_MODE";function r(e){return{type:a,payload:e}}const s=class extends e.BasePlugin{constructor(a,s,d){super(a,s),this.spreadEmitter$=e.createBehaviorEmitter(),this.resetReady(),this.dispatch(r(d.defaultSpreadMode??t.None));s.getPlugin("loader").provides().onDocumentLoaded((e=>this.documentLoaded(e)))}async initialize(e){e.defaultSpreadMode&&this.dispatch(r(e.defaultSpreadMode))}documentLoaded(t){this.dispatchCoreAction(e.setPages(this.getSpreadPagesObjects(t.pages))),this.markReady()}getSpreadPagesObjects(e){if(!e.length)return[];switch(this.state.spreadMode){case t.None:return e.map((e=>[e]));case t.Odd:return Array.from({length:Math.ceil(e.length/2)},((t,a)=>e.slice(2*a,2*a+2)));case t.Even:return[[e[0]],...Array.from({length:Math.ceil((e.length-1)/2)},((t,a)=>e.slice(1+2*a,1+2*a+2)))];default:return e.map((e=>[e]))}}setSpreadMode(t){const a=this.state.spreadMode,s=this.coreState.core.document;if(!s)throw new Error("Document not loaded");a!==t&&(this.dispatch(r(t)),this.dispatchCoreAction(e.setPages(this.getSpreadPagesObjects(s.pages))),this.notifySpreadChange(t))}notifySpreadChange(e){this.spreadEmitter$.emit(e)}buildCapability(){return{onSpreadChange:this.spreadEmitter$.on,setSpreadMode:e=>this.setSpreadMode(e),getSpreadMode:()=>this.state.spreadMode}}async destroy(){this.spreadEmitter$.clear()}};s.id="spread";let d=s;const o="spread",i={id:o,name:"Spread Plugin",version:"1.0.0",provides:["spread"],requires:["loader"],optional:[],defaultConfig:{enabled:!0}},n={spreadMode:t.None},p={manifest:i,create:(e,t)=>new d(o,e,t),reducer:(e=n,t)=>t.type===a?{...e,spreadMode:t.payload}:e,initialState:n};exports.SPREAD_PLUGIN_ID=o,exports.SpreadMode=t,exports.SpreadPlugin=d,exports.SpreadPluginPackage=p,exports.manifest=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core");var t=(e=>(e.None="none",e.Odd="odd",e.Even="even",e))(t||{});const o="SPREAD/INIT_STATE",r="SPREAD/CLEANUP_STATE",d="SPREAD/SET_ACTIVE_DOCUMENT",n="SPREAD/SET_SPREAD_MODE",a="SPREAD/SET_PAGE_GROUPING";function s(e,t){return{type:o,payload:{documentId:e,state:t}}}function c(e){return{type:r,payload:e}}function u(e,t){return{type:n,payload:{documentId:e,spreadMode:t}}}function i(e,t){return{type:a,payload:{documentId:e,grouping:t}}}const p=class extends e.BasePlugin{constructor(o,r,d){var n;super(o,r),this.spreadEmitter$=e.createBehaviorEmitter(),this.defaultSpreadMode=d.defaultSpreadMode??t.None,this.viewport=(null==(n=r.getPlugin("viewport"))?void 0:n.provides())??null}onDocumentLoadingStarted(e){var t;const o={spreadMode:this.defaultSpreadMode};this.dispatch(s(e,o)),null==(t=this.viewport)||t.gate("spread",e),this.logger.debug("SpreadPlugin","DocumentOpened",`Initialized spread state for document: ${e}`)}onDocumentLoaded(e){var t;const o=this.coreState.core.documents[e];if(null==o?void 0:o.document){const t=this.calculatePageGrouping(e,o.document.pages.length);this.dispatch(i(e,t))}null==(t=this.viewport)||t.releaseGate("spread",e)}onDocumentClosed(e){this.dispatch(c(e)),this.logger.debug("SpreadPlugin","DocumentClosed",`Cleaned up spread state for document: ${e}`)}buildCapability(){return{setSpreadMode:e=>this.setSpreadModeForDocument(e),getSpreadMode:()=>this.getSpreadModeForDocument(),getSpreadPages:()=>this.getSpreadPages(),forDocument:e=>this.createSpreadScope(e),onSpreadChange:this.spreadEmitter$.on}}createSpreadScope(e){return{setSpreadMode:t=>this.setSpreadModeForDocument(t,e),getSpreadMode:()=>this.getSpreadModeForDocument(e),getSpreadPages:()=>this.getSpreadPages(e),onSpreadChange:t=>this.spreadEmitter$.on(o=>{o.documentId===e&&t(o.spreadMode)})}}getDocumentState(e){const t=e??this.getActiveDocumentId();return this.state.documents[t]??null}getDocumentStateOrThrow(e){const t=this.getDocumentState(e);if(!t)throw new Error(`Spread state not found for document: ${e??"active"}`);return t}setSpreadModeForDocument(e,t){const o=t??this.getActiveDocumentId(),r=this.getDocumentStateOrThrow(o),d=this.coreState.core.documents[o];if(!(null==d?void 0:d.document))throw new Error(`Document ${o} not loaded`);if(r.spreadMode!==e){this.dispatch(u(o,e));const t=this.calculatePageGrouping(o,d.document.pages.length);this.dispatch(i(o,t)),this.spreadEmitter$.emit({documentId:o,spreadMode:e})}}getSpreadModeForDocument(e){return this.getDocumentStateOrThrow(e).spreadMode}calculatePageGrouping(e,o){switch(this.getDocumentStateOrThrow(e).spreadMode){case t.None:return Array.from({length:o},(e,t)=>[t]);case t.Odd:return Array.from({length:Math.ceil(o/2)},(e,t)=>{const r=[2*t];return 2*t+1<o&&r.push(2*t+1),r});case t.Even:return[[0],...Array.from({length:Math.ceil((o-1)/2)},(e,t)=>{const r=[1+2*t];return 1+2*t+1<o&&r.push(1+2*t+1),r})];default:return Array.from({length:o},(e,t)=>[t])}}getSpreadPages(e){const t=e??this.getActiveDocumentId(),o=this.coreState.core.documents[t],r=this.getDocumentStateOrThrow(t);if(!(null==o?void 0:o.document))throw new Error(`Document ${t} not loaded`);const d=r.pageGrouping??[],n=o.document.pages;return d.map(e=>e.map(e=>n[e]).filter(Boolean))}onStoreUpdated(e,o){for(const r in o.documents){const d=e.documents[r],n=o.documents[r];(null==d?void 0:d.spreadMode)!==n.spreadMode&&this.logger.debug("SpreadPlugin","SpreadModeChanged",`Spread mode changed for document ${r}: ${(null==d?void 0:d.spreadMode)??t.None} -> ${n.spreadMode}`)}}async initialize(e){this.logger.info("SpreadPlugin","Initialize","Spread plugin initialized")}async destroy(){this.spreadEmitter$.clear(),super.destroy()}};p.id="spread";let l=p;const m="spread",g={id:m,name:"Spread Plugin",version:"1.0.0",provides:["spread"],requires:[],optional:["viewport"],defaultConfig:{enabled:!0}},S={spreadMode:t.None},h={documents:{},activeDocumentId:null},D=(e=h,t)=>{switch(t.type){case o:{const{documentId:o,state:r}=t.payload;return{...e,documents:{...e.documents,[o]:r},activeDocumentId:e.activeDocumentId??o}}case r:{const o=t.payload,{[o]:r,...d}=e.documents;return{...e,documents:d,activeDocumentId:e.activeDocumentId===o?null:e.activeDocumentId}}case d:return{...e,activeDocumentId:t.payload};case n:{const{documentId:o,spreadMode:r}=t.payload,d=e.documents[o];return d?{...e,documents:{...e.documents,[o]:{...d,spreadMode:r}}}:e}case a:{const{documentId:o,grouping:r}=t.payload,d=e.documents[o];return d?{...e,documents:{...e.documents,[o]:{...d,pageGrouping:r}}}:e}default:return e}},E={manifest:g,create:(e,t)=>new l(m,e,t),reducer:D,initialState:h};exports.CLEANUP_SPREAD_STATE=r,exports.INIT_SPREAD_STATE=o,exports.SET_ACTIVE_SPREAD_DOCUMENT=d,exports.SET_PAGE_GROUPING=a,exports.SET_SPREAD_MODE=n,exports.SPREAD_PLUGIN_ID=m,exports.SpreadMode=t,exports.SpreadPlugin=l,exports.SpreadPluginPackage=E,exports.cleanupSpreadState=c,exports.initSpreadState=s,exports.initialDocumentState=S,exports.initialState=h,exports.manifest=g,exports.setActiveSpreadDocument=function(e){return{type:d,payload:e}},exports.setPageGrouping=i,exports.setSpreadMode=u,exports.spreadReducer=D;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/lib/types.ts","../src/lib/actions.ts","../src/lib/spread-plugin.ts","../src/lib/manifest.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePluginConfig, EventHook } from '@embedpdf/core';\n\nexport interface SpreadPluginConfig extends BasePluginConfig {\n defaultSpreadMode?: SpreadMode;\n}\n\nexport enum SpreadMode {\n None = 'none',\n Odd = 'odd',\n Even = 'even',\n}\n\nexport interface SpreadCapability {\n onSpreadChange: EventHook<SpreadMode>;\n setSpreadMode(mode: SpreadMode): void;\n getSpreadMode(): SpreadMode;\n}\n\nexport interface SpreadState {\n spreadMode: SpreadMode;\n}\n","import { SpreadMode } from './types';\n\nexport const SET_SPREAD_MODE = 'SET_SPREAD_MODE';\n\nexport interface SetSpreadModeAction {\n type: typeof SET_SPREAD_MODE;\n payload: SpreadMode;\n}\n\nexport type SpreadAction = SetSpreadModeAction;\n\nexport function setSpreadMode(mode: SpreadMode): SetSpreadModeAction {\n return {\n type: SET_SPREAD_MODE,\n payload: mode,\n };\n}\n","import {\n BasePlugin,\n createBehaviorEmitter,\n createEmitter,\n PluginRegistry,\n setPages,\n} from '@embedpdf/core';\nimport { PdfDocumentObject, PdfPageObject } from '@embedpdf/models';\nimport { LoaderPlugin } from '@embedpdf/plugin-loader';\nimport { SpreadCapability, SpreadMode, SpreadPluginConfig, SpreadState } from './types';\nimport { setSpreadMode } from './actions';\nimport { SpreadAction } from './actions';\n\nexport class SpreadPlugin extends BasePlugin<\n SpreadPluginConfig,\n SpreadCapability,\n SpreadState,\n SpreadAction\n> {\n static readonly id = 'spread' as const;\n\n private readonly spreadEmitter$ = createBehaviorEmitter<SpreadMode>();\n\n constructor(id: string, registry: PluginRegistry, cfg: SpreadPluginConfig) {\n super(id, registry);\n this.resetReady();\n this.dispatch(setSpreadMode(cfg.defaultSpreadMode ?? SpreadMode.None));\n const loaderPlugin = registry.getPlugin<LoaderPlugin>('loader');\n loaderPlugin!.provides().onDocumentLoaded((document) => this.documentLoaded(document));\n }\n\n async initialize(config: SpreadPluginConfig): Promise<void> {\n if (config.defaultSpreadMode) {\n this.dispatch(setSpreadMode(config.defaultSpreadMode));\n }\n }\n\n private documentLoaded(document: PdfDocumentObject): void {\n this.dispatchCoreAction(setPages(this.getSpreadPagesObjects(document.pages)));\n this.markReady();\n }\n\n getSpreadPagesObjects(pages: PdfPageObject[]): PdfPageObject[][] {\n if (!pages.length) return [];\n\n switch (this.state.spreadMode) {\n case SpreadMode.None:\n return pages.map((page) => [page]);\n\n case SpreadMode.Odd:\n return Array.from({ length: Math.ceil(pages.length / 2) }, (_, i) =>\n pages.slice(i * 2, i * 2 + 2),\n );\n\n case SpreadMode.Even:\n return [\n [pages[0]],\n ...Array.from({ length: Math.ceil((pages.length - 1) / 2) }, (_, i) =>\n pages.slice(1 + i * 2, 1 + i * 2 + 2),\n ),\n ];\n\n default:\n return pages.map((page) => [page]);\n }\n }\n\n setSpreadMode(mode: SpreadMode): void {\n const currentMode = this.state.spreadMode;\n const document = this.coreState.core.document;\n if (!document) {\n throw new Error('Document not loaded');\n }\n if (currentMode !== mode) {\n this.dispatch(setSpreadMode(mode));\n this.dispatchCoreAction(setPages(this.getSpreadPagesObjects(document.pages)));\n this.notifySpreadChange(mode);\n }\n }\n\n private notifySpreadChange(spreadMode: SpreadMode): void {\n this.spreadEmitter$.emit(spreadMode);\n }\n\n protected buildCapability(): SpreadCapability {\n return {\n onSpreadChange: this.spreadEmitter$.on,\n setSpreadMode: (mode) => this.setSpreadMode(mode),\n getSpreadMode: () => this.state.spreadMode,\n };\n }\n\n async destroy(): Promise<void> {\n this.spreadEmitter$.clear();\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { SpreadPluginConfig } from './types';\n\nexport const SPREAD_PLUGIN_ID = 'spread';\n\nexport const manifest: PluginManifest<SpreadPluginConfig> = {\n id: SPREAD_PLUGIN_ID,\n name: 'Spread Plugin',\n version: '1.0.0',\n provides: ['spread'],\n requires: ['loader'],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { Reducer } from '@embedpdf/core';\nimport { SpreadState, SpreadMode } from './types';\nimport { SET_SPREAD_MODE, SetSpreadModeAction } from './actions';\n\nexport const initialState: SpreadState = {\n spreadMode: SpreadMode.None,\n};\n\nexport const spreadReducer: Reducer<SpreadState, SetSpreadModeAction> = (\n state = initialState,\n action,\n) => {\n switch (action.type) {\n case SET_SPREAD_MODE:\n return {\n ...state,\n spreadMode: action.payload,\n };\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { SpreadPlugin } from './spread-plugin';\nimport { manifest, SPREAD_PLUGIN_ID } from './manifest';\nimport { SpreadPluginConfig, SpreadState } from './types';\nimport { spreadReducer, initialState } from './reducer';\nimport { SpreadAction } from './actions';\n\nexport const SpreadPluginPackage: PluginPackage<\n SpreadPlugin,\n SpreadPluginConfig,\n SpreadState,\n SpreadAction\n> = {\n manifest,\n create: (registry, config) => new SpreadPlugin(SPREAD_PLUGIN_ID, registry, config),\n reducer: spreadReducer,\n initialState,\n};\n\nexport * from './spread-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["SpreadMode","SET_SPREAD_MODE","setSpreadMode","mode","type","payload","_SpreadPlugin","BasePlugin","constructor","id","registry","cfg","super","this","spreadEmitter$","createBehaviorEmitter","resetReady","dispatch","defaultSpreadMode","None","getPlugin","provides","onDocumentLoaded","document","documentLoaded","initialize","config","dispatchCoreAction","setPages","getSpreadPagesObjects","pages","markReady","length","state","spreadMode","map","page","Odd","Array","from","Math","ceil","_","i","slice","Even","currentMode","coreState","core","Error","notifySpreadChange","emit","buildCapability","onSpreadChange","on","getSpreadMode","destroy","clear","SpreadPlugin","SPREAD_PLUGIN_ID","manifest","name","version","requires","optional","defaultConfig","enabled","initialState","SpreadPluginPackage","create","reducer","action"],"mappings":"kHAMY,IAAAA,GAAAA,IACVA,EAAO,KAAA,OACPA,EAAM,IAAA,MACNA,EAAO,KAAA,OAHGA,IAAAA,GAAA,CAAA,GCJL,MAAMC,EAAkB,kBASxB,SAASC,EAAcC,GACrB,MAAA,CACLC,KAAMH,EACNI,QAASF,EAEb,CCHO,MAAMG,EAAN,cAA2BC,EAAAA,WAUhC,WAAAC,CAAYC,EAAYC,EAA0BC,GAChDC,MAAMH,EAAIC,GAHKG,KAAAC,eAAiBC,0BAIhCF,KAAK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,eAAgBxC,KAAKC,eAAewC,GACpCpD,cAAgBC,GAASU,KAAKX,cAAcC,GAC5CoD,cAAe,IAAM1C,KAAKoB,MAAMC,WAClC,CAGF,aAAMsB,GACJ3C,KAAKC,eAAe2C,OAAM,GA1E5BnD,EAAgBG,GAAK,SANhB,IAAMiD,EAANpD,ECVA,MAAMqD,EAAmB,SAEnBC,EAA+C,CAC1DnD,GAAIkD,EACJE,KAAM,gBACNC,QAAS,QACTzC,SAAU,CAAC,UACX0C,SAAU,CAAC,UACXC,SAAU,GACVC,cAAe,CACbC,SAAS,ICTAC,EAA4B,CACvCjC,WAAYlC,EAAWmB,MCEZiD,EAKT,CACFR,WACAS,OAAQ,CAAC3D,EAAUgB,IAAW,IAAIgC,EAAaC,EAAkBjD,EAAUgB,GAC3E4C,QDPsE,CACtErC,EAAQkC,EACRI,IAEQA,EAAOnE,OACRH,EACI,IACFgC,EACHC,WAAYqC,EAAOlE,SAGd4B,ECHXkC"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/lib/types.ts","../src/lib/actions.ts","../src/lib/spread-plugin.ts","../src/lib/manifest.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePluginConfig, EventHook } from '@embedpdf/core';\nimport { PdfPageObject } from '@embedpdf/models';\n\nexport interface SpreadPluginConfig extends BasePluginConfig {\n defaultSpreadMode?: SpreadMode;\n}\n\nexport enum SpreadMode {\n None = 'none',\n Odd = 'odd',\n Even = 'even',\n}\n\n// Per-document spread state\nexport interface SpreadDocumentState {\n spreadMode: SpreadMode;\n pageGrouping?: number[][]; // [[0], [1,2], [3,4], ...]\n}\n\nexport interface SpreadState {\n documents: Record<string, SpreadDocumentState>;\n activeDocumentId: string | null;\n}\n\n// Events include documentId\nexport interface SpreadChangeEvent {\n documentId: string;\n spreadMode: SpreadMode;\n}\n\n// Scoped spread capability\nexport interface SpreadScope {\n setSpreadMode(mode: SpreadMode): void;\n getSpreadMode(): SpreadMode;\n getSpreadPages(): PdfPageObject[][];\n onSpreadChange: EventHook<SpreadMode>;\n}\n\nexport interface SpreadCapability {\n // Active document operations\n setSpreadMode(mode: SpreadMode): void;\n getSpreadMode(): SpreadMode;\n getSpreadPages(documentId?: string): PdfPageObject[][];\n\n // Document-scoped operations\n forDocument(documentId: string): SpreadScope;\n\n // Events\n onSpreadChange: EventHook<SpreadChangeEvent>;\n}\n","import { Action } from '@embedpdf/core';\nimport { SpreadMode, SpreadDocumentState } from './types';\n\n// Document lifecycle\nexport const INIT_SPREAD_STATE = 'SPREAD/INIT_STATE';\nexport const CLEANUP_SPREAD_STATE = 'SPREAD/CLEANUP_STATE';\nexport const SET_ACTIVE_SPREAD_DOCUMENT = 'SPREAD/SET_ACTIVE_DOCUMENT';\n\n// Spread operations\nexport const SET_SPREAD_MODE = 'SPREAD/SET_SPREAD_MODE';\nexport const SET_PAGE_GROUPING = 'SPREAD/SET_PAGE_GROUPING';\n\n// Document lifecycle actions\nexport interface InitSpreadStateAction extends Action {\n type: typeof INIT_SPREAD_STATE;\n payload: {\n documentId: string;\n state: SpreadDocumentState;\n };\n}\n\nexport interface CleanupSpreadStateAction extends Action {\n type: typeof CLEANUP_SPREAD_STATE;\n payload: string; // documentId\n}\n\nexport interface SetActiveSpreadDocumentAction extends Action {\n type: typeof SET_ACTIVE_SPREAD_DOCUMENT;\n payload: string | null; // documentId\n}\n\nexport interface SetSpreadModeAction extends Action {\n type: typeof SET_SPREAD_MODE;\n payload: {\n documentId: string;\n spreadMode: SpreadMode;\n };\n}\n\nexport interface SetPageGroupingAction extends Action {\n type: typeof SET_PAGE_GROUPING;\n payload: {\n documentId: string;\n grouping: number[][];\n };\n}\n\nexport type SpreadAction =\n | InitSpreadStateAction\n | CleanupSpreadStateAction\n | SetActiveSpreadDocumentAction\n | SetSpreadModeAction\n | SetPageGroupingAction;\n\n// Action Creators\nexport function initSpreadState(\n documentId: string,\n state: SpreadDocumentState,\n): InitSpreadStateAction {\n return { type: INIT_SPREAD_STATE, payload: { documentId, state } };\n}\n\nexport function cleanupSpreadState(documentId: string): CleanupSpreadStateAction {\n return { type: CLEANUP_SPREAD_STATE, payload: documentId };\n}\n\nexport function setActiveSpreadDocument(documentId: string | null): SetActiveSpreadDocumentAction {\n return { type: SET_ACTIVE_SPREAD_DOCUMENT, payload: documentId };\n}\n\nexport function setSpreadMode(documentId: string, spreadMode: SpreadMode): SetSpreadModeAction {\n return { type: SET_SPREAD_MODE, payload: { documentId, spreadMode } };\n}\n\nexport function setPageGrouping(documentId: string, grouping: number[][]): SetPageGroupingAction {\n return { type: SET_PAGE_GROUPING, payload: { documentId, grouping } };\n}\n","import { BasePlugin, createBehaviorEmitter, Listener, PluginRegistry } from '@embedpdf/core';\nimport { PdfPageObject } from '@embedpdf/models';\nimport {\n SpreadCapability,\n SpreadMode,\n SpreadPluginConfig,\n SpreadState,\n SpreadScope,\n SpreadChangeEvent,\n SpreadDocumentState,\n} from './types';\nimport {\n setSpreadMode,\n initSpreadState,\n cleanupSpreadState,\n SpreadAction,\n setPageGrouping,\n} from './actions';\nimport { ViewportCapability, ViewportPlugin } from '@embedpdf/plugin-viewport';\n\nexport class SpreadPlugin extends BasePlugin<\n SpreadPluginConfig,\n SpreadCapability,\n SpreadState,\n SpreadAction\n> {\n static readonly id = 'spread' as const;\n\n private readonly spreadEmitter$ = createBehaviorEmitter<SpreadChangeEvent>();\n private readonly defaultSpreadMode: SpreadMode;\n private readonly viewport: ViewportCapability | null;\n\n constructor(id: string, registry: PluginRegistry, cfg: SpreadPluginConfig) {\n super(id, registry);\n this.defaultSpreadMode = cfg.defaultSpreadMode ?? SpreadMode.None;\n\n this.viewport = registry.getPlugin<ViewportPlugin>('viewport')?.provides() ?? null;\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Lifecycle Hooks (from BasePlugin)\n // ─────────────────────────────────────────────────────────\n\n protected override onDocumentLoadingStarted(documentId: string): void {\n // Initialize spread state for this document\n const docState: SpreadDocumentState = {\n spreadMode: this.defaultSpreadMode,\n };\n\n this.dispatch(initSpreadState(documentId, docState));\n this.viewport?.gate('spread', documentId);\n this.logger.debug(\n 'SpreadPlugin',\n 'DocumentOpened',\n `Initialized spread state for document: ${documentId}`,\n );\n }\n\n protected override onDocumentLoaded(documentId: string): void {\n // Calculate grouping indices and store in plugin state\n const coreDoc = this.coreState.core.documents[documentId];\n if (coreDoc?.document) {\n const grouping = this.calculatePageGrouping(documentId, coreDoc.document.pages.length);\n\n // Store grouping in plugin state\n this.dispatch(setPageGrouping(documentId, grouping));\n }\n this.viewport?.releaseGate('spread', documentId);\n }\n\n protected override onDocumentClosed(documentId: string): void {\n this.dispatch(cleanupSpreadState(documentId));\n\n this.logger.debug(\n 'SpreadPlugin',\n 'DocumentClosed',\n `Cleaned up spread state for document: ${documentId}`,\n );\n }\n\n // ─────────────────────────────────────────────────────────\n // Capability\n // ─────────────────────────────────────────────────────────\n\n protected buildCapability(): SpreadCapability {\n return {\n // Active document operations\n setSpreadMode: (mode: SpreadMode) => this.setSpreadModeForDocument(mode),\n getSpreadMode: () => this.getSpreadModeForDocument(),\n getSpreadPages: () => this.getSpreadPages(),\n // Document-scoped operations\n forDocument: (documentId: string) => this.createSpreadScope(documentId),\n\n // Events\n onSpreadChange: this.spreadEmitter$.on,\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Scoping\n // ─────────────────────────────────────────────────────────\n\n private createSpreadScope(documentId: string): SpreadScope {\n return {\n setSpreadMode: (mode: SpreadMode) => this.setSpreadModeForDocument(mode, documentId),\n getSpreadMode: () => this.getSpreadModeForDocument(documentId),\n getSpreadPages: () => this.getSpreadPages(documentId),\n onSpreadChange: (listener: Listener<SpreadMode>) =>\n this.spreadEmitter$.on((event) => {\n if (event.documentId === documentId) listener(event.spreadMode);\n }),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // State Helpers\n // ─────────────────────────────────────────────────────────\n private getDocumentState(documentId?: string): SpreadDocumentState | null {\n const id = documentId ?? this.getActiveDocumentId();\n return this.state.documents[id] ?? null;\n }\n\n private getDocumentStateOrThrow(documentId?: string): SpreadDocumentState {\n const state = this.getDocumentState(documentId);\n if (!state) {\n throw new Error(`Spread state not found for document: ${documentId ?? 'active'}`);\n }\n return state;\n }\n\n // ─────────────────────────────────────────────────────────\n // Core Operations\n // ─────────────────────────────────────────────────────────\n\n private setSpreadModeForDocument(mode: SpreadMode, documentId?: string): void {\n const id = documentId ?? this.getActiveDocumentId();\n const currentState = this.getDocumentStateOrThrow(id);\n const coreDoc = this.coreState.core.documents[id];\n\n if (!coreDoc?.document) {\n throw new Error(`Document ${id} not loaded`);\n }\n\n if (currentState.spreadMode !== mode) {\n // Update plugin state\n this.dispatch(setSpreadMode(id, mode));\n\n // Calculate new grouping\n const grouping = this.calculatePageGrouping(id, coreDoc.document.pages.length);\n this.dispatch(setPageGrouping(id, grouping));\n\n // Emit event\n this.spreadEmitter$.emit({\n documentId: id,\n spreadMode: mode,\n });\n }\n }\n\n private getSpreadModeForDocument(documentId?: string): SpreadMode {\n return this.getDocumentStateOrThrow(documentId).spreadMode;\n }\n\n /**\n * Calculate page grouping indices based on spread mode\n * Returns indices, not actual page objects\n */\n private calculatePageGrouping(documentId: string, pageCount: number): number[][] {\n const docState = this.getDocumentStateOrThrow(documentId);\n const spreadMode = docState.spreadMode;\n\n switch (spreadMode) {\n case SpreadMode.None:\n // [[0], [1], [2], [3], ...]\n return Array.from({ length: pageCount }, (_, i) => [i]);\n\n case SpreadMode.Odd:\n // [[0, 1], [2, 3], [4, 5], ...]\n return Array.from({ length: Math.ceil(pageCount / 2) }, (_, i) => {\n const indices = [i * 2];\n if (i * 2 + 1 < pageCount) indices.push(i * 2 + 1);\n return indices;\n });\n\n case SpreadMode.Even:\n // [[0], [1, 2], [3, 4], [5, 6], ...]\n return [\n [0],\n ...Array.from({ length: Math.ceil((pageCount - 1) / 2) }, (_, i) => {\n const indices = [1 + i * 2];\n if (1 + i * 2 + 1 < pageCount) indices.push(1 + i * 2 + 1);\n return indices;\n }),\n ];\n\n default:\n return Array.from({ length: pageCount }, (_, i) => [i]);\n }\n }\n\n /**\n * Get the actual page objects grouped according to spread mode\n * This is computed on-demand, not stored\n */\n private getSpreadPages(documentId?: string): PdfPageObject[][] {\n const id = documentId ?? this.getActiveDocumentId();\n const coreDoc = this.coreState.core.documents[id];\n const spreadState = this.getDocumentStateOrThrow(id);\n\n if (!coreDoc?.document) {\n throw new Error(`Document ${id} not loaded`);\n }\n\n const grouping = spreadState.pageGrouping ?? [];\n const pages = coreDoc.document.pages;\n\n // Map indices to actual page objects\n return grouping.map((indices) => indices.map((idx) => pages[idx]).filter(Boolean));\n }\n\n // ─────────────────────────────────────────────────────────\n // Store Update Handlers\n // ─────────────────────────────────────────────────────────\n\n override onStoreUpdated(prevState: SpreadState, newState: SpreadState): void {\n // Emit spread change events for each changed document\n for (const documentId in newState.documents) {\n const prevDoc = prevState.documents[documentId];\n const newDoc = newState.documents[documentId];\n\n if (prevDoc?.spreadMode !== newDoc.spreadMode) {\n this.logger.debug(\n 'SpreadPlugin',\n 'SpreadModeChanged',\n `Spread mode changed for document ${documentId}: ${prevDoc?.spreadMode ?? SpreadMode.None} -> ${newDoc.spreadMode}`,\n );\n }\n }\n }\n\n // ─────────────────────────────────────────────────────────\n // Lifecycle\n // ─────────────────────────────────────────────────────────\n\n async initialize(_config: SpreadPluginConfig): Promise<void> {\n this.logger.info('SpreadPlugin', 'Initialize', 'Spread plugin initialized');\n }\n\n async destroy(): Promise<void> {\n this.spreadEmitter$.clear();\n super.destroy();\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { SpreadPluginConfig } from './types';\n\nexport const SPREAD_PLUGIN_ID = 'spread';\n\nexport const manifest: PluginManifest<SpreadPluginConfig> = {\n id: SPREAD_PLUGIN_ID,\n name: 'Spread Plugin',\n version: '1.0.0',\n provides: ['spread'],\n requires: [],\n optional: ['viewport'],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { Reducer } from '@embedpdf/core';\nimport {\n SpreadAction,\n INIT_SPREAD_STATE,\n CLEANUP_SPREAD_STATE,\n SET_ACTIVE_SPREAD_DOCUMENT,\n SET_SPREAD_MODE,\n SET_PAGE_GROUPING,\n} from './actions';\nimport { SpreadState, SpreadDocumentState, SpreadMode } from './types';\n\nexport const initialDocumentState: SpreadDocumentState = {\n spreadMode: SpreadMode.None,\n};\n\nexport const initialState: SpreadState = {\n documents: {},\n activeDocumentId: null,\n};\n\nexport const spreadReducer: Reducer<SpreadState, SpreadAction> = (state = initialState, action) => {\n switch (action.type) {\n case INIT_SPREAD_STATE: {\n const { documentId, state: docState } = action.payload;\n return {\n ...state,\n documents: {\n ...state.documents,\n [documentId]: docState,\n },\n // Set as active if no active document\n activeDocumentId: state.activeDocumentId ?? documentId,\n };\n }\n\n case CLEANUP_SPREAD_STATE: {\n const documentId = action.payload;\n const { [documentId]: removed, ...remainingDocs } = state.documents;\n return {\n ...state,\n documents: remainingDocs,\n activeDocumentId: state.activeDocumentId === documentId ? null : state.activeDocumentId,\n };\n }\n\n case SET_ACTIVE_SPREAD_DOCUMENT: {\n return {\n ...state,\n activeDocumentId: action.payload,\n };\n }\n\n case SET_SPREAD_MODE: {\n const { documentId, spreadMode } = action.payload;\n const docState = state.documents[documentId];\n if (!docState) return state;\n\n return {\n ...state,\n documents: {\n ...state.documents,\n [documentId]: {\n ...docState,\n spreadMode,\n },\n },\n };\n }\n\n case SET_PAGE_GROUPING: {\n const { documentId, grouping } = action.payload;\n const docState = state.documents[documentId];\n if (!docState) return state;\n\n return {\n ...state,\n documents: {\n ...state.documents,\n [documentId]: {\n ...docState,\n pageGrouping: grouping,\n },\n },\n };\n }\n\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { SpreadPlugin } from './spread-plugin';\nimport { manifest, SPREAD_PLUGIN_ID } from './manifest';\nimport { SpreadPluginConfig, SpreadState } from './types';\nimport { spreadReducer, initialState } from './reducer';\nimport { SpreadAction } from './actions';\n\nexport const SpreadPluginPackage: PluginPackage<\n SpreadPlugin,\n SpreadPluginConfig,\n SpreadState,\n SpreadAction\n> = {\n manifest,\n create: (registry, config) => new SpreadPlugin(SPREAD_PLUGIN_ID, registry, config),\n reducer: spreadReducer,\n initialState,\n};\n\nexport * from './spread-plugin';\nexport * from './types';\nexport * from './manifest';\nexport * from './actions';\nexport * from './reducer';\n"],"names":["SpreadMode","INIT_SPREAD_STATE","CLEANUP_SPREAD_STATE","SET_ACTIVE_SPREAD_DOCUMENT","SET_SPREAD_MODE","SET_PAGE_GROUPING","initSpreadState","documentId","state","type","payload","cleanupSpreadState","setSpreadMode","spreadMode","setPageGrouping","grouping","_SpreadPlugin","BasePlugin","constructor","id","registry","cfg","super","this","spreadEmitter$","createBehaviorEmitter","defaultSpreadMode","None","viewport","_a","getPlugin","provides","onDocumentLoadingStarted","docState","dispatch","gate","logger","debug","onDocumentLoaded","coreDoc","coreState","core","documents","document","calculatePageGrouping","pages","length","releaseGate","onDocumentClosed","buildCapability","mode","setSpreadModeForDocument","getSpreadMode","getSpreadModeForDocument","getSpreadPages","forDocument","createSpreadScope","onSpreadChange","on","listener","event","getDocumentState","getActiveDocumentId","getDocumentStateOrThrow","Error","currentState","emit","pageCount","Array","from","_","i","Odd","Math","ceil","indices","push","Even","spreadState","pageGrouping","map","idx","filter","Boolean","onStoreUpdated","prevState","newState","prevDoc","newDoc","initialize","_config","info","destroy","clear","SpreadPlugin","SPREAD_PLUGIN_ID","manifest","name","version","requires","optional","defaultConfig","enabled","initialDocumentState","initialState","activeDocumentId","spreadReducer","action","removed","remainingDocs","SpreadPluginPackage","create","config","reducer"],"mappings":"kHAOO,IAAKA,GAAAA,IACVA,EAAA,KAAO,OACPA,EAAA,IAAM,MACNA,EAAA,KAAO,OAHGA,IAAAA,GAAA,CAAA,GCHL,MAAMC,EAAoB,oBACpBC,EAAuB,uBACvBC,EAA6B,6BAG7BC,EAAkB,yBAClBC,EAAoB,2BA6C1B,SAASC,EACdC,EACAC,GAEA,MAAO,CAAEC,KAAMR,EAAmBS,QAAS,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,EAEE,IACFzB,EACHkC,UAAW,IACNlC,EAAMkC,UACTnC,CAACA,GAAa,IACT0B,EACHpB,gBARgBL,CAYxB,CAEA,KAAKH,EAAmB,CACtB,MAAME,WAAEA,EAAAQ,SAAYA,GAAa4F,EAAOjG,QAClCuB,EAAWzB,EAAMkC,UAAUnC,GACjC,OAAK0B,EAEE,IACFzB,EACHkC,UAAW,IACNlC,EAAMkC,UACTnC,CAACA,GAAa,IACT0B,EACH8C,aAAchE,KAREP,CAYxB,CAEA,QACE,OAAOA,IChFAsG,EAKT,CACFd,WACAe,OAAQ,CAAC3F,EAAU4F,IAAW,IAAIlB,EAAaC,EAAkB3E,EAAU4F,GAC3EC,QAASP,EACTF,2aJkDK,SAAiCjG,GACtC,MAAO,CAAEE,KAAMN,EAA4BO,QAASH,EACtD"}
package/dist/index.js CHANGED
@@ -1,81 +1,205 @@
1
- import { BasePlugin, createBehaviorEmitter, setPages } from "@embedpdf/core";
1
+ import { BasePlugin, createBehaviorEmitter } from "@embedpdf/core";
2
2
  var SpreadMode = /* @__PURE__ */ ((SpreadMode2) => {
3
3
  SpreadMode2["None"] = "none";
4
4
  SpreadMode2["Odd"] = "odd";
5
5
  SpreadMode2["Even"] = "even";
6
6
  return SpreadMode2;
7
7
  })(SpreadMode || {});
8
- const SET_SPREAD_MODE = "SET_SPREAD_MODE";
9
- function setSpreadMode(mode) {
10
- return {
11
- type: SET_SPREAD_MODE,
12
- payload: mode
13
- };
8
+ const INIT_SPREAD_STATE = "SPREAD/INIT_STATE";
9
+ const CLEANUP_SPREAD_STATE = "SPREAD/CLEANUP_STATE";
10
+ const SET_ACTIVE_SPREAD_DOCUMENT = "SPREAD/SET_ACTIVE_DOCUMENT";
11
+ const SET_SPREAD_MODE = "SPREAD/SET_SPREAD_MODE";
12
+ const SET_PAGE_GROUPING = "SPREAD/SET_PAGE_GROUPING";
13
+ function initSpreadState(documentId, state) {
14
+ return { type: INIT_SPREAD_STATE, payload: { documentId, state } };
15
+ }
16
+ function cleanupSpreadState(documentId) {
17
+ return { type: CLEANUP_SPREAD_STATE, payload: documentId };
18
+ }
19
+ function setActiveSpreadDocument(documentId) {
20
+ return { type: SET_ACTIVE_SPREAD_DOCUMENT, payload: documentId };
21
+ }
22
+ function setSpreadMode(documentId, spreadMode) {
23
+ return { type: SET_SPREAD_MODE, payload: { documentId, spreadMode } };
24
+ }
25
+ function setPageGrouping(documentId, grouping) {
26
+ return { type: SET_PAGE_GROUPING, payload: { documentId, grouping } };
14
27
  }
15
28
  const _SpreadPlugin = class _SpreadPlugin extends BasePlugin {
16
29
  constructor(id, registry, cfg) {
30
+ var _a;
17
31
  super(id, registry);
18
32
  this.spreadEmitter$ = createBehaviorEmitter();
19
- this.resetReady();
20
- this.dispatch(setSpreadMode(cfg.defaultSpreadMode ?? SpreadMode.None));
21
- const loaderPlugin = registry.getPlugin("loader");
22
- loaderPlugin.provides().onDocumentLoaded((document) => this.documentLoaded(document));
23
- }
24
- async initialize(config) {
25
- if (config.defaultSpreadMode) {
26
- this.dispatch(setSpreadMode(config.defaultSpreadMode));
33
+ this.defaultSpreadMode = cfg.defaultSpreadMode ?? SpreadMode.None;
34
+ this.viewport = ((_a = registry.getPlugin("viewport")) == null ? void 0 : _a.provides()) ?? null;
35
+ }
36
+ // ─────────────────────────────────────────────────────────
37
+ // Document Lifecycle Hooks (from BasePlugin)
38
+ // ─────────────────────────────────────────────────────────
39
+ onDocumentLoadingStarted(documentId) {
40
+ var _a;
41
+ const docState = {
42
+ spreadMode: this.defaultSpreadMode
43
+ };
44
+ this.dispatch(initSpreadState(documentId, docState));
45
+ (_a = this.viewport) == null ? void 0 : _a.gate("spread", documentId);
46
+ this.logger.debug(
47
+ "SpreadPlugin",
48
+ "DocumentOpened",
49
+ `Initialized spread state for document: ${documentId}`
50
+ );
51
+ }
52
+ onDocumentLoaded(documentId) {
53
+ var _a;
54
+ const coreDoc = this.coreState.core.documents[documentId];
55
+ if (coreDoc == null ? void 0 : coreDoc.document) {
56
+ const grouping = this.calculatePageGrouping(documentId, coreDoc.document.pages.length);
57
+ this.dispatch(setPageGrouping(documentId, grouping));
27
58
  }
59
+ (_a = this.viewport) == null ? void 0 : _a.releaseGate("spread", documentId);
28
60
  }
29
- documentLoaded(document) {
30
- this.dispatchCoreAction(setPages(this.getSpreadPagesObjects(document.pages)));
31
- this.markReady();
61
+ onDocumentClosed(documentId) {
62
+ this.dispatch(cleanupSpreadState(documentId));
63
+ this.logger.debug(
64
+ "SpreadPlugin",
65
+ "DocumentClosed",
66
+ `Cleaned up spread state for document: ${documentId}`
67
+ );
32
68
  }
33
- getSpreadPagesObjects(pages) {
34
- if (!pages.length) return [];
35
- switch (this.state.spreadMode) {
69
+ // ─────────────────────────────────────────────────────────
70
+ // Capability
71
+ // ─────────────────────────────────────────────────────────
72
+ buildCapability() {
73
+ return {
74
+ // Active document operations
75
+ setSpreadMode: (mode) => this.setSpreadModeForDocument(mode),
76
+ getSpreadMode: () => this.getSpreadModeForDocument(),
77
+ getSpreadPages: () => this.getSpreadPages(),
78
+ // Document-scoped operations
79
+ forDocument: (documentId) => this.createSpreadScope(documentId),
80
+ // Events
81
+ onSpreadChange: this.spreadEmitter$.on
82
+ };
83
+ }
84
+ // ─────────────────────────────────────────────────────────
85
+ // Document Scoping
86
+ // ─────────────────────────────────────────────────────────
87
+ createSpreadScope(documentId) {
88
+ return {
89
+ setSpreadMode: (mode) => this.setSpreadModeForDocument(mode, documentId),
90
+ getSpreadMode: () => this.getSpreadModeForDocument(documentId),
91
+ getSpreadPages: () => this.getSpreadPages(documentId),
92
+ onSpreadChange: (listener) => this.spreadEmitter$.on((event) => {
93
+ if (event.documentId === documentId) listener(event.spreadMode);
94
+ })
95
+ };
96
+ }
97
+ // ─────────────────────────────────────────────────────────
98
+ // State Helpers
99
+ // ─────────────────────────────────────────────────────────
100
+ getDocumentState(documentId) {
101
+ const id = documentId ?? this.getActiveDocumentId();
102
+ return this.state.documents[id] ?? null;
103
+ }
104
+ getDocumentStateOrThrow(documentId) {
105
+ const state = this.getDocumentState(documentId);
106
+ if (!state) {
107
+ throw new Error(`Spread state not found for document: ${documentId ?? "active"}`);
108
+ }
109
+ return state;
110
+ }
111
+ // ─────────────────────────────────────────────────────────
112
+ // Core Operations
113
+ // ─────────────────────────────────────────────────────────
114
+ setSpreadModeForDocument(mode, documentId) {
115
+ const id = documentId ?? this.getActiveDocumentId();
116
+ const currentState = this.getDocumentStateOrThrow(id);
117
+ const coreDoc = this.coreState.core.documents[id];
118
+ if (!(coreDoc == null ? void 0 : coreDoc.document)) {
119
+ throw new Error(`Document ${id} not loaded`);
120
+ }
121
+ if (currentState.spreadMode !== mode) {
122
+ this.dispatch(setSpreadMode(id, mode));
123
+ const grouping = this.calculatePageGrouping(id, coreDoc.document.pages.length);
124
+ this.dispatch(setPageGrouping(id, grouping));
125
+ this.spreadEmitter$.emit({
126
+ documentId: id,
127
+ spreadMode: mode
128
+ });
129
+ }
130
+ }
131
+ getSpreadModeForDocument(documentId) {
132
+ return this.getDocumentStateOrThrow(documentId).spreadMode;
133
+ }
134
+ /**
135
+ * Calculate page grouping indices based on spread mode
136
+ * Returns indices, not actual page objects
137
+ */
138
+ calculatePageGrouping(documentId, pageCount) {
139
+ const docState = this.getDocumentStateOrThrow(documentId);
140
+ const spreadMode = docState.spreadMode;
141
+ switch (spreadMode) {
36
142
  case SpreadMode.None:
37
- return pages.map((page) => [page]);
143
+ return Array.from({ length: pageCount }, (_, i) => [i]);
38
144
  case SpreadMode.Odd:
39
- return Array.from(
40
- { length: Math.ceil(pages.length / 2) },
41
- (_, i) => pages.slice(i * 2, i * 2 + 2)
42
- );
145
+ return Array.from({ length: Math.ceil(pageCount / 2) }, (_, i) => {
146
+ const indices = [i * 2];
147
+ if (i * 2 + 1 < pageCount) indices.push(i * 2 + 1);
148
+ return indices;
149
+ });
43
150
  case SpreadMode.Even:
44
151
  return [
45
- [pages[0]],
46
- ...Array.from(
47
- { length: Math.ceil((pages.length - 1) / 2) },
48
- (_, i) => pages.slice(1 + i * 2, 1 + i * 2 + 2)
49
- )
152
+ [0],
153
+ ...Array.from({ length: Math.ceil((pageCount - 1) / 2) }, (_, i) => {
154
+ const indices = [1 + i * 2];
155
+ if (1 + i * 2 + 1 < pageCount) indices.push(1 + i * 2 + 1);
156
+ return indices;
157
+ })
50
158
  ];
51
159
  default:
52
- return pages.map((page) => [page]);
160
+ return Array.from({ length: pageCount }, (_, i) => [i]);
53
161
  }
54
162
  }
55
- setSpreadMode(mode) {
56
- const currentMode = this.state.spreadMode;
57
- const document = this.coreState.core.document;
58
- if (!document) {
59
- throw new Error("Document not loaded");
163
+ /**
164
+ * Get the actual page objects grouped according to spread mode
165
+ * This is computed on-demand, not stored
166
+ */
167
+ getSpreadPages(documentId) {
168
+ const id = documentId ?? this.getActiveDocumentId();
169
+ const coreDoc = this.coreState.core.documents[id];
170
+ const spreadState = this.getDocumentStateOrThrow(id);
171
+ if (!(coreDoc == null ? void 0 : coreDoc.document)) {
172
+ throw new Error(`Document ${id} not loaded`);
60
173
  }
61
- if (currentMode !== mode) {
62
- this.dispatch(setSpreadMode(mode));
63
- this.dispatchCoreAction(setPages(this.getSpreadPagesObjects(document.pages)));
64
- this.notifySpreadChange(mode);
174
+ const grouping = spreadState.pageGrouping ?? [];
175
+ const pages = coreDoc.document.pages;
176
+ return grouping.map((indices) => indices.map((idx) => pages[idx]).filter(Boolean));
177
+ }
178
+ // ─────────────────────────────────────────────────────────
179
+ // Store Update Handlers
180
+ // ─────────────────────────────────────────────────────────
181
+ onStoreUpdated(prevState, newState) {
182
+ for (const documentId in newState.documents) {
183
+ const prevDoc = prevState.documents[documentId];
184
+ const newDoc = newState.documents[documentId];
185
+ if ((prevDoc == null ? void 0 : prevDoc.spreadMode) !== newDoc.spreadMode) {
186
+ this.logger.debug(
187
+ "SpreadPlugin",
188
+ "SpreadModeChanged",
189
+ `Spread mode changed for document ${documentId}: ${(prevDoc == null ? void 0 : prevDoc.spreadMode) ?? SpreadMode.None} -> ${newDoc.spreadMode}`
190
+ );
191
+ }
65
192
  }
66
193
  }
67
- notifySpreadChange(spreadMode) {
68
- this.spreadEmitter$.emit(spreadMode);
69
- }
70
- buildCapability() {
71
- return {
72
- onSpreadChange: this.spreadEmitter$.on,
73
- setSpreadMode: (mode) => this.setSpreadMode(mode),
74
- getSpreadMode: () => this.state.spreadMode
75
- };
194
+ // ─────────────────────────────────────────────────────────
195
+ // Lifecycle
196
+ // ─────────────────────────────────────────────────────────
197
+ async initialize(_config) {
198
+ this.logger.info("SpreadPlugin", "Initialize", "Spread plugin initialized");
76
199
  }
77
200
  async destroy() {
78
201
  this.spreadEmitter$.clear();
202
+ super.destroy();
79
203
  }
80
204
  };
81
205
  _SpreadPlugin.id = "spread";
@@ -86,22 +210,78 @@ const manifest = {
86
210
  name: "Spread Plugin",
87
211
  version: "1.0.0",
88
212
  provides: ["spread"],
89
- requires: ["loader"],
90
- optional: [],
213
+ requires: [],
214
+ optional: ["viewport"],
91
215
  defaultConfig: {
92
216
  enabled: true
93
217
  }
94
218
  };
95
- const initialState = {
219
+ const initialDocumentState = {
96
220
  spreadMode: SpreadMode.None
97
221
  };
222
+ const initialState = {
223
+ documents: {},
224
+ activeDocumentId: null
225
+ };
98
226
  const spreadReducer = (state = initialState, action) => {
99
227
  switch (action.type) {
100
- case SET_SPREAD_MODE:
228
+ case INIT_SPREAD_STATE: {
229
+ const { documentId, state: docState } = action.payload;
230
+ return {
231
+ ...state,
232
+ documents: {
233
+ ...state.documents,
234
+ [documentId]: docState
235
+ },
236
+ // Set as active if no active document
237
+ activeDocumentId: state.activeDocumentId ?? documentId
238
+ };
239
+ }
240
+ case CLEANUP_SPREAD_STATE: {
241
+ const documentId = action.payload;
242
+ const { [documentId]: removed, ...remainingDocs } = state.documents;
243
+ return {
244
+ ...state,
245
+ documents: remainingDocs,
246
+ activeDocumentId: state.activeDocumentId === documentId ? null : state.activeDocumentId
247
+ };
248
+ }
249
+ case SET_ACTIVE_SPREAD_DOCUMENT: {
250
+ return {
251
+ ...state,
252
+ activeDocumentId: action.payload
253
+ };
254
+ }
255
+ case SET_SPREAD_MODE: {
256
+ const { documentId, spreadMode } = action.payload;
257
+ const docState = state.documents[documentId];
258
+ if (!docState) return state;
101
259
  return {
102
260
  ...state,
103
- spreadMode: action.payload
261
+ documents: {
262
+ ...state.documents,
263
+ [documentId]: {
264
+ ...docState,
265
+ spreadMode
266
+ }
267
+ }
104
268
  };
269
+ }
270
+ case SET_PAGE_GROUPING: {
271
+ const { documentId, grouping } = action.payload;
272
+ const docState = state.documents[documentId];
273
+ if (!docState) return state;
274
+ return {
275
+ ...state,
276
+ documents: {
277
+ ...state.documents,
278
+ [documentId]: {
279
+ ...docState,
280
+ pageGrouping: grouping
281
+ }
282
+ }
283
+ };
284
+ }
105
285
  default:
106
286
  return state;
107
287
  }
@@ -113,10 +293,23 @@ const SpreadPluginPackage = {
113
293
  initialState
114
294
  };
115
295
  export {
296
+ CLEANUP_SPREAD_STATE,
297
+ INIT_SPREAD_STATE,
298
+ SET_ACTIVE_SPREAD_DOCUMENT,
299
+ SET_PAGE_GROUPING,
300
+ SET_SPREAD_MODE,
116
301
  SPREAD_PLUGIN_ID,
117
302
  SpreadMode,
118
303
  SpreadPlugin,
119
304
  SpreadPluginPackage,
120
- manifest
305
+ cleanupSpreadState,
306
+ initSpreadState,
307
+ initialDocumentState,
308
+ initialState,
309
+ manifest,
310
+ setActiveSpreadDocument,
311
+ setPageGrouping,
312
+ setSpreadMode,
313
+ spreadReducer
121
314
  };
122
315
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/lib/types.ts","../src/lib/actions.ts","../src/lib/spread-plugin.ts","../src/lib/manifest.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePluginConfig, EventHook } from '@embedpdf/core';\n\nexport interface SpreadPluginConfig extends BasePluginConfig {\n defaultSpreadMode?: SpreadMode;\n}\n\nexport enum SpreadMode {\n None = 'none',\n Odd = 'odd',\n Even = 'even',\n}\n\nexport interface SpreadCapability {\n onSpreadChange: EventHook<SpreadMode>;\n setSpreadMode(mode: SpreadMode): void;\n getSpreadMode(): SpreadMode;\n}\n\nexport interface SpreadState {\n spreadMode: SpreadMode;\n}\n","import { SpreadMode } from './types';\n\nexport const SET_SPREAD_MODE = 'SET_SPREAD_MODE';\n\nexport interface SetSpreadModeAction {\n type: typeof SET_SPREAD_MODE;\n payload: SpreadMode;\n}\n\nexport type SpreadAction = SetSpreadModeAction;\n\nexport function setSpreadMode(mode: SpreadMode): SetSpreadModeAction {\n return {\n type: SET_SPREAD_MODE,\n payload: mode,\n };\n}\n","import {\n BasePlugin,\n createBehaviorEmitter,\n createEmitter,\n PluginRegistry,\n setPages,\n} from '@embedpdf/core';\nimport { PdfDocumentObject, PdfPageObject } from '@embedpdf/models';\nimport { LoaderPlugin } from '@embedpdf/plugin-loader';\nimport { SpreadCapability, SpreadMode, SpreadPluginConfig, SpreadState } from './types';\nimport { setSpreadMode } from './actions';\nimport { SpreadAction } from './actions';\n\nexport class SpreadPlugin extends BasePlugin<\n SpreadPluginConfig,\n SpreadCapability,\n SpreadState,\n SpreadAction\n> {\n static readonly id = 'spread' as const;\n\n private readonly spreadEmitter$ = createBehaviorEmitter<SpreadMode>();\n\n constructor(id: string, registry: PluginRegistry, cfg: SpreadPluginConfig) {\n super(id, registry);\n this.resetReady();\n this.dispatch(setSpreadMode(cfg.defaultSpreadMode ?? SpreadMode.None));\n const loaderPlugin = registry.getPlugin<LoaderPlugin>('loader');\n loaderPlugin!.provides().onDocumentLoaded((document) => this.documentLoaded(document));\n }\n\n async initialize(config: SpreadPluginConfig): Promise<void> {\n if (config.defaultSpreadMode) {\n this.dispatch(setSpreadMode(config.defaultSpreadMode));\n }\n }\n\n private documentLoaded(document: PdfDocumentObject): void {\n this.dispatchCoreAction(setPages(this.getSpreadPagesObjects(document.pages)));\n this.markReady();\n }\n\n getSpreadPagesObjects(pages: PdfPageObject[]): PdfPageObject[][] {\n if (!pages.length) return [];\n\n switch (this.state.spreadMode) {\n case SpreadMode.None:\n return pages.map((page) => [page]);\n\n case SpreadMode.Odd:\n return Array.from({ length: Math.ceil(pages.length / 2) }, (_, i) =>\n pages.slice(i * 2, i * 2 + 2),\n );\n\n case SpreadMode.Even:\n return [\n [pages[0]],\n ...Array.from({ length: Math.ceil((pages.length - 1) / 2) }, (_, i) =>\n pages.slice(1 + i * 2, 1 + i * 2 + 2),\n ),\n ];\n\n default:\n return pages.map((page) => [page]);\n }\n }\n\n setSpreadMode(mode: SpreadMode): void {\n const currentMode = this.state.spreadMode;\n const document = this.coreState.core.document;\n if (!document) {\n throw new Error('Document not loaded');\n }\n if (currentMode !== mode) {\n this.dispatch(setSpreadMode(mode));\n this.dispatchCoreAction(setPages(this.getSpreadPagesObjects(document.pages)));\n this.notifySpreadChange(mode);\n }\n }\n\n private notifySpreadChange(spreadMode: SpreadMode): void {\n this.spreadEmitter$.emit(spreadMode);\n }\n\n protected buildCapability(): SpreadCapability {\n return {\n onSpreadChange: this.spreadEmitter$.on,\n setSpreadMode: (mode) => this.setSpreadMode(mode),\n getSpreadMode: () => this.state.spreadMode,\n };\n }\n\n async destroy(): Promise<void> {\n this.spreadEmitter$.clear();\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { SpreadPluginConfig } from './types';\n\nexport const SPREAD_PLUGIN_ID = 'spread';\n\nexport const manifest: PluginManifest<SpreadPluginConfig> = {\n id: SPREAD_PLUGIN_ID,\n name: 'Spread Plugin',\n version: '1.0.0',\n provides: ['spread'],\n requires: ['loader'],\n optional: [],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { Reducer } from '@embedpdf/core';\nimport { SpreadState, SpreadMode } from './types';\nimport { SET_SPREAD_MODE, SetSpreadModeAction } from './actions';\n\nexport const initialState: SpreadState = {\n spreadMode: SpreadMode.None,\n};\n\nexport const spreadReducer: Reducer<SpreadState, SetSpreadModeAction> = (\n state = initialState,\n action,\n) => {\n switch (action.type) {\n case SET_SPREAD_MODE:\n return {\n ...state,\n spreadMode: action.payload,\n };\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { SpreadPlugin } from './spread-plugin';\nimport { manifest, SPREAD_PLUGIN_ID } from './manifest';\nimport { SpreadPluginConfig, SpreadState } from './types';\nimport { spreadReducer, initialState } from './reducer';\nimport { SpreadAction } from './actions';\n\nexport const SpreadPluginPackage: PluginPackage<\n SpreadPlugin,\n SpreadPluginConfig,\n SpreadState,\n SpreadAction\n> = {\n manifest,\n create: (registry, config) => new SpreadPlugin(SPREAD_PLUGIN_ID, registry, config),\n reducer: spreadReducer,\n initialState,\n};\n\nexport * from './spread-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["SpreadMode"],"mappings":";AAMY,IAAA,+BAAAA,gBAAL;AACLA,cAAA,MAAO,IAAA;AACPA,cAAA,KAAM,IAAA;AACNA,cAAA,MAAO,IAAA;AAHGA,SAAAA;AAAA,GAAA,cAAA,CAAA,CAAA;ACJL,MAAM,kBAAkB;AASxB,SAAS,cAAc,MAAuC;AAC5D,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,EACX;AACF;ACHO,MAAM,gBAAN,MAAM,sBAAqB,WAKhC;AAAA,EAKA,YAAY,IAAY,UAA0B,KAAyB;AACzE,UAAM,IAAI,QAAQ;AAHpB,SAAiB,iBAAiB,sBAAkC;AAIlE,SAAK,WAAW;AAChB,SAAK,SAAS,cAAc,IAAI,qBAAqB,WAAW,IAAI,CAAC;AAC/D,UAAA,eAAe,SAAS,UAAwB,QAAQ;AAChD,iBAAA,WAAW,iBAAiB,CAAC,aAAa,KAAK,eAAe,QAAQ,CAAC;AAAA,EAAA;AAAA,EAGvF,MAAM,WAAW,QAA2C;AAC1D,QAAI,OAAO,mBAAmB;AAC5B,WAAK,SAAS,cAAc,OAAO,iBAAiB,CAAC;AAAA,IAAA;AAAA,EACvD;AAAA,EAGM,eAAe,UAAmC;AAC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AAA;AAAA,EAG3B,kBAAoC;AACrC,WAAA;AAAA,MACL,gBAAgB,KAAK,eAAe;AAAA,MACpC,eAAe,CAAC,SAAS,KAAK,cAAc,IAAI;AAAA,MAChD,eAAe,MAAM,KAAK,MAAM;AAAA,IAClC;AAAA,EAAA;AAAA,EAGF,MAAM,UAAyB;AAC7B,SAAK,eAAe,MAAM;AAAA,EAAA;AAE9B;AA5EE,cAAgB,KAAK;AANhB,IAAM,eAAN;ACVA,MAAM,mBAAmB;AAEzB,MAAM,WAA+C;AAAA,EAC1D,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,SAAS;AAAA,EACT,UAAU,CAAC,QAAQ;AAAA,EACnB,UAAU,CAAC,QAAQ;AAAA,EACnB,UAAU,CAAC;AAAA,EACX,eAAe;AAAA,IACb,SAAS;AAAA,EAAA;AAEb;ACXO,MAAM,eAA4B;AAAA,EACvC,YAAY,WAAW;AACzB;AAEO,MAAM,gBAA2D,CACtE,QAAQ,cACR,WACG;AACH,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK;AACI,aAAA;AAAA,QACL,GAAG;AAAA,QACH,YAAY,OAAO;AAAA,MACrB;AAAA,IACF;AACS,aAAA;AAAA,EAAA;AAEb;ACdO,MAAM,sBAKT;AAAA,EACF;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EACjF,SAAS;AAAA,EACT;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../src/lib/types.ts","../src/lib/actions.ts","../src/lib/spread-plugin.ts","../src/lib/manifest.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePluginConfig, EventHook } from '@embedpdf/core';\nimport { PdfPageObject } from '@embedpdf/models';\n\nexport interface SpreadPluginConfig extends BasePluginConfig {\n defaultSpreadMode?: SpreadMode;\n}\n\nexport enum SpreadMode {\n None = 'none',\n Odd = 'odd',\n Even = 'even',\n}\n\n// Per-document spread state\nexport interface SpreadDocumentState {\n spreadMode: SpreadMode;\n pageGrouping?: number[][]; // [[0], [1,2], [3,4], ...]\n}\n\nexport interface SpreadState {\n documents: Record<string, SpreadDocumentState>;\n activeDocumentId: string | null;\n}\n\n// Events include documentId\nexport interface SpreadChangeEvent {\n documentId: string;\n spreadMode: SpreadMode;\n}\n\n// Scoped spread capability\nexport interface SpreadScope {\n setSpreadMode(mode: SpreadMode): void;\n getSpreadMode(): SpreadMode;\n getSpreadPages(): PdfPageObject[][];\n onSpreadChange: EventHook<SpreadMode>;\n}\n\nexport interface SpreadCapability {\n // Active document operations\n setSpreadMode(mode: SpreadMode): void;\n getSpreadMode(): SpreadMode;\n getSpreadPages(documentId?: string): PdfPageObject[][];\n\n // Document-scoped operations\n forDocument(documentId: string): SpreadScope;\n\n // Events\n onSpreadChange: EventHook<SpreadChangeEvent>;\n}\n","import { Action } from '@embedpdf/core';\nimport { SpreadMode, SpreadDocumentState } from './types';\n\n// Document lifecycle\nexport const INIT_SPREAD_STATE = 'SPREAD/INIT_STATE';\nexport const CLEANUP_SPREAD_STATE = 'SPREAD/CLEANUP_STATE';\nexport const SET_ACTIVE_SPREAD_DOCUMENT = 'SPREAD/SET_ACTIVE_DOCUMENT';\n\n// Spread operations\nexport const SET_SPREAD_MODE = 'SPREAD/SET_SPREAD_MODE';\nexport const SET_PAGE_GROUPING = 'SPREAD/SET_PAGE_GROUPING';\n\n// Document lifecycle actions\nexport interface InitSpreadStateAction extends Action {\n type: typeof INIT_SPREAD_STATE;\n payload: {\n documentId: string;\n state: SpreadDocumentState;\n };\n}\n\nexport interface CleanupSpreadStateAction extends Action {\n type: typeof CLEANUP_SPREAD_STATE;\n payload: string; // documentId\n}\n\nexport interface SetActiveSpreadDocumentAction extends Action {\n type: typeof SET_ACTIVE_SPREAD_DOCUMENT;\n payload: string | null; // documentId\n}\n\nexport interface SetSpreadModeAction extends Action {\n type: typeof SET_SPREAD_MODE;\n payload: {\n documentId: string;\n spreadMode: SpreadMode;\n };\n}\n\nexport interface SetPageGroupingAction extends Action {\n type: typeof SET_PAGE_GROUPING;\n payload: {\n documentId: string;\n grouping: number[][];\n };\n}\n\nexport type SpreadAction =\n | InitSpreadStateAction\n | CleanupSpreadStateAction\n | SetActiveSpreadDocumentAction\n | SetSpreadModeAction\n | SetPageGroupingAction;\n\n// Action Creators\nexport function initSpreadState(\n documentId: string,\n state: SpreadDocumentState,\n): InitSpreadStateAction {\n return { type: INIT_SPREAD_STATE, payload: { documentId, state } };\n}\n\nexport function cleanupSpreadState(documentId: string): CleanupSpreadStateAction {\n return { type: CLEANUP_SPREAD_STATE, payload: documentId };\n}\n\nexport function setActiveSpreadDocument(documentId: string | null): SetActiveSpreadDocumentAction {\n return { type: SET_ACTIVE_SPREAD_DOCUMENT, payload: documentId };\n}\n\nexport function setSpreadMode(documentId: string, spreadMode: SpreadMode): SetSpreadModeAction {\n return { type: SET_SPREAD_MODE, payload: { documentId, spreadMode } };\n}\n\nexport function setPageGrouping(documentId: string, grouping: number[][]): SetPageGroupingAction {\n return { type: SET_PAGE_GROUPING, payload: { documentId, grouping } };\n}\n","import { BasePlugin, createBehaviorEmitter, Listener, PluginRegistry } from '@embedpdf/core';\nimport { PdfPageObject } from '@embedpdf/models';\nimport {\n SpreadCapability,\n SpreadMode,\n SpreadPluginConfig,\n SpreadState,\n SpreadScope,\n SpreadChangeEvent,\n SpreadDocumentState,\n} from './types';\nimport {\n setSpreadMode,\n initSpreadState,\n cleanupSpreadState,\n SpreadAction,\n setPageGrouping,\n} from './actions';\nimport { ViewportCapability, ViewportPlugin } from '@embedpdf/plugin-viewport';\n\nexport class SpreadPlugin extends BasePlugin<\n SpreadPluginConfig,\n SpreadCapability,\n SpreadState,\n SpreadAction\n> {\n static readonly id = 'spread' as const;\n\n private readonly spreadEmitter$ = createBehaviorEmitter<SpreadChangeEvent>();\n private readonly defaultSpreadMode: SpreadMode;\n private readonly viewport: ViewportCapability | null;\n\n constructor(id: string, registry: PluginRegistry, cfg: SpreadPluginConfig) {\n super(id, registry);\n this.defaultSpreadMode = cfg.defaultSpreadMode ?? SpreadMode.None;\n\n this.viewport = registry.getPlugin<ViewportPlugin>('viewport')?.provides() ?? null;\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Lifecycle Hooks (from BasePlugin)\n // ─────────────────────────────────────────────────────────\n\n protected override onDocumentLoadingStarted(documentId: string): void {\n // Initialize spread state for this document\n const docState: SpreadDocumentState = {\n spreadMode: this.defaultSpreadMode,\n };\n\n this.dispatch(initSpreadState(documentId, docState));\n this.viewport?.gate('spread', documentId);\n this.logger.debug(\n 'SpreadPlugin',\n 'DocumentOpened',\n `Initialized spread state for document: ${documentId}`,\n );\n }\n\n protected override onDocumentLoaded(documentId: string): void {\n // Calculate grouping indices and store in plugin state\n const coreDoc = this.coreState.core.documents[documentId];\n if (coreDoc?.document) {\n const grouping = this.calculatePageGrouping(documentId, coreDoc.document.pages.length);\n\n // Store grouping in plugin state\n this.dispatch(setPageGrouping(documentId, grouping));\n }\n this.viewport?.releaseGate('spread', documentId);\n }\n\n protected override onDocumentClosed(documentId: string): void {\n this.dispatch(cleanupSpreadState(documentId));\n\n this.logger.debug(\n 'SpreadPlugin',\n 'DocumentClosed',\n `Cleaned up spread state for document: ${documentId}`,\n );\n }\n\n // ─────────────────────────────────────────────────────────\n // Capability\n // ─────────────────────────────────────────────────────────\n\n protected buildCapability(): SpreadCapability {\n return {\n // Active document operations\n setSpreadMode: (mode: SpreadMode) => this.setSpreadModeForDocument(mode),\n getSpreadMode: () => this.getSpreadModeForDocument(),\n getSpreadPages: () => this.getSpreadPages(),\n // Document-scoped operations\n forDocument: (documentId: string) => this.createSpreadScope(documentId),\n\n // Events\n onSpreadChange: this.spreadEmitter$.on,\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // Document Scoping\n // ─────────────────────────────────────────────────────────\n\n private createSpreadScope(documentId: string): SpreadScope {\n return {\n setSpreadMode: (mode: SpreadMode) => this.setSpreadModeForDocument(mode, documentId),\n getSpreadMode: () => this.getSpreadModeForDocument(documentId),\n getSpreadPages: () => this.getSpreadPages(documentId),\n onSpreadChange: (listener: Listener<SpreadMode>) =>\n this.spreadEmitter$.on((event) => {\n if (event.documentId === documentId) listener(event.spreadMode);\n }),\n };\n }\n\n // ─────────────────────────────────────────────────────────\n // State Helpers\n // ─────────────────────────────────────────────────────────\n private getDocumentState(documentId?: string): SpreadDocumentState | null {\n const id = documentId ?? this.getActiveDocumentId();\n return this.state.documents[id] ?? null;\n }\n\n private getDocumentStateOrThrow(documentId?: string): SpreadDocumentState {\n const state = this.getDocumentState(documentId);\n if (!state) {\n throw new Error(`Spread state not found for document: ${documentId ?? 'active'}`);\n }\n return state;\n }\n\n // ─────────────────────────────────────────────────────────\n // Core Operations\n // ─────────────────────────────────────────────────────────\n\n private setSpreadModeForDocument(mode: SpreadMode, documentId?: string): void {\n const id = documentId ?? this.getActiveDocumentId();\n const currentState = this.getDocumentStateOrThrow(id);\n const coreDoc = this.coreState.core.documents[id];\n\n if (!coreDoc?.document) {\n throw new Error(`Document ${id} not loaded`);\n }\n\n if (currentState.spreadMode !== mode) {\n // Update plugin state\n this.dispatch(setSpreadMode(id, mode));\n\n // Calculate new grouping\n const grouping = this.calculatePageGrouping(id, coreDoc.document.pages.length);\n this.dispatch(setPageGrouping(id, grouping));\n\n // Emit event\n this.spreadEmitter$.emit({\n documentId: id,\n spreadMode: mode,\n });\n }\n }\n\n private getSpreadModeForDocument(documentId?: string): SpreadMode {\n return this.getDocumentStateOrThrow(documentId).spreadMode;\n }\n\n /**\n * Calculate page grouping indices based on spread mode\n * Returns indices, not actual page objects\n */\n private calculatePageGrouping(documentId: string, pageCount: number): number[][] {\n const docState = this.getDocumentStateOrThrow(documentId);\n const spreadMode = docState.spreadMode;\n\n switch (spreadMode) {\n case SpreadMode.None:\n // [[0], [1], [2], [3], ...]\n return Array.from({ length: pageCount }, (_, i) => [i]);\n\n case SpreadMode.Odd:\n // [[0, 1], [2, 3], [4, 5], ...]\n return Array.from({ length: Math.ceil(pageCount / 2) }, (_, i) => {\n const indices = [i * 2];\n if (i * 2 + 1 < pageCount) indices.push(i * 2 + 1);\n return indices;\n });\n\n case SpreadMode.Even:\n // [[0], [1, 2], [3, 4], [5, 6], ...]\n return [\n [0],\n ...Array.from({ length: Math.ceil((pageCount - 1) / 2) }, (_, i) => {\n const indices = [1 + i * 2];\n if (1 + i * 2 + 1 < pageCount) indices.push(1 + i * 2 + 1);\n return indices;\n }),\n ];\n\n default:\n return Array.from({ length: pageCount }, (_, i) => [i]);\n }\n }\n\n /**\n * Get the actual page objects grouped according to spread mode\n * This is computed on-demand, not stored\n */\n private getSpreadPages(documentId?: string): PdfPageObject[][] {\n const id = documentId ?? this.getActiveDocumentId();\n const coreDoc = this.coreState.core.documents[id];\n const spreadState = this.getDocumentStateOrThrow(id);\n\n if (!coreDoc?.document) {\n throw new Error(`Document ${id} not loaded`);\n }\n\n const grouping = spreadState.pageGrouping ?? [];\n const pages = coreDoc.document.pages;\n\n // Map indices to actual page objects\n return grouping.map((indices) => indices.map((idx) => pages[idx]).filter(Boolean));\n }\n\n // ─────────────────────────────────────────────────────────\n // Store Update Handlers\n // ─────────────────────────────────────────────────────────\n\n override onStoreUpdated(prevState: SpreadState, newState: SpreadState): void {\n // Emit spread change events for each changed document\n for (const documentId in newState.documents) {\n const prevDoc = prevState.documents[documentId];\n const newDoc = newState.documents[documentId];\n\n if (prevDoc?.spreadMode !== newDoc.spreadMode) {\n this.logger.debug(\n 'SpreadPlugin',\n 'SpreadModeChanged',\n `Spread mode changed for document ${documentId}: ${prevDoc?.spreadMode ?? SpreadMode.None} -> ${newDoc.spreadMode}`,\n );\n }\n }\n }\n\n // ─────────────────────────────────────────────────────────\n // Lifecycle\n // ─────────────────────────────────────────────────────────\n\n async initialize(_config: SpreadPluginConfig): Promise<void> {\n this.logger.info('SpreadPlugin', 'Initialize', 'Spread plugin initialized');\n }\n\n async destroy(): Promise<void> {\n this.spreadEmitter$.clear();\n super.destroy();\n }\n}\n","import { PluginManifest } from '@embedpdf/core';\nimport { SpreadPluginConfig } from './types';\n\nexport const SPREAD_PLUGIN_ID = 'spread';\n\nexport const manifest: PluginManifest<SpreadPluginConfig> = {\n id: SPREAD_PLUGIN_ID,\n name: 'Spread Plugin',\n version: '1.0.0',\n provides: ['spread'],\n requires: [],\n optional: ['viewport'],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { Reducer } from '@embedpdf/core';\nimport {\n SpreadAction,\n INIT_SPREAD_STATE,\n CLEANUP_SPREAD_STATE,\n SET_ACTIVE_SPREAD_DOCUMENT,\n SET_SPREAD_MODE,\n SET_PAGE_GROUPING,\n} from './actions';\nimport { SpreadState, SpreadDocumentState, SpreadMode } from './types';\n\nexport const initialDocumentState: SpreadDocumentState = {\n spreadMode: SpreadMode.None,\n};\n\nexport const initialState: SpreadState = {\n documents: {},\n activeDocumentId: null,\n};\n\nexport const spreadReducer: Reducer<SpreadState, SpreadAction> = (state = initialState, action) => {\n switch (action.type) {\n case INIT_SPREAD_STATE: {\n const { documentId, state: docState } = action.payload;\n return {\n ...state,\n documents: {\n ...state.documents,\n [documentId]: docState,\n },\n // Set as active if no active document\n activeDocumentId: state.activeDocumentId ?? documentId,\n };\n }\n\n case CLEANUP_SPREAD_STATE: {\n const documentId = action.payload;\n const { [documentId]: removed, ...remainingDocs } = state.documents;\n return {\n ...state,\n documents: remainingDocs,\n activeDocumentId: state.activeDocumentId === documentId ? null : state.activeDocumentId,\n };\n }\n\n case SET_ACTIVE_SPREAD_DOCUMENT: {\n return {\n ...state,\n activeDocumentId: action.payload,\n };\n }\n\n case SET_SPREAD_MODE: {\n const { documentId, spreadMode } = action.payload;\n const docState = state.documents[documentId];\n if (!docState) return state;\n\n return {\n ...state,\n documents: {\n ...state.documents,\n [documentId]: {\n ...docState,\n spreadMode,\n },\n },\n };\n }\n\n case SET_PAGE_GROUPING: {\n const { documentId, grouping } = action.payload;\n const docState = state.documents[documentId];\n if (!docState) return state;\n\n return {\n ...state,\n documents: {\n ...state.documents,\n [documentId]: {\n ...docState,\n pageGrouping: grouping,\n },\n },\n };\n }\n\n default:\n return state;\n }\n};\n","import { PluginPackage } from '@embedpdf/core';\nimport { SpreadPlugin } from './spread-plugin';\nimport { manifest, SPREAD_PLUGIN_ID } from './manifest';\nimport { SpreadPluginConfig, SpreadState } from './types';\nimport { spreadReducer, initialState } from './reducer';\nimport { SpreadAction } from './actions';\n\nexport const SpreadPluginPackage: PluginPackage<\n SpreadPlugin,\n SpreadPluginConfig,\n SpreadState,\n SpreadAction\n> = {\n manifest,\n create: (registry, config) => new SpreadPlugin(SPREAD_PLUGIN_ID, registry, config),\n reducer: spreadReducer,\n initialState,\n};\n\nexport * from './spread-plugin';\nexport * from './types';\nexport * from './manifest';\nexport * from './actions';\nexport * from './reducer';\n"],"names":["SpreadMode"],"mappings":";AAOO,IAAK,+BAAAA,gBAAL;AACLA,cAAA,MAAA,IAAO;AACPA,cAAA,KAAA,IAAM;AACNA,cAAA,MAAA,IAAO;AAHG,SAAAA;AAAA,GAAA,cAAA,CAAA,CAAA;ACHL,MAAM,oBAAoB;AAC1B,MAAM,uBAAuB;AAC7B,MAAM,6BAA6B;AAGnC,MAAM,kBAAkB;AACxB,MAAM,oBAAoB;AA6C1B,SAAS,gBACd,YACA,OACuB;AACvB,SAAO,EAAE,MAAM,mBAAmB,SAAS,EAAE,YAAY,QAAM;AACjE;AAEO,SAAS,mBAAmB,YAA8C;AAC/E,SAAO,EAAE,MAAM,sBAAsB,SAAS,WAAA;AAChD;AAEO,SAAS,wBAAwB,YAA0D;AAChG,SAAO,EAAE,MAAM,4BAA4B,SAAS,WAAA;AACtD;AAEO,SAAS,cAAc,YAAoB,YAA6C;AAC7F,SAAO,EAAE,MAAM,iBAAiB,SAAS,EAAE,YAAY,aAAW;AACpE;AAEO,SAAS,gBAAgB,YAAoB,UAA6C;AAC/F,SAAO,EAAE,MAAM,mBAAmB,SAAS,EAAE,YAAY,WAAS;AACpE;ACxDO,MAAM,gBAAN,MAAM,sB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AAA,MACF;AAAA,IAEJ;AAAA,IAEA;AACE,aAAO;AAAA,EAAA;AAEb;AClFO,MAAM,sBAKT;AAAA,EACF;AAAA,EACA,QAAQ,CAAC,UAAU,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EACjF,SAAS;AAAA,EACT;AACF;"}
@@ -1,8 +1,42 @@
1
- import { SpreadMode } from './types';
2
- export declare const SET_SPREAD_MODE = "SET_SPREAD_MODE";
3
- export interface SetSpreadModeAction {
1
+ import { Action } from '@embedpdf/core';
2
+ import { SpreadMode, SpreadDocumentState } from './types';
3
+ export declare const INIT_SPREAD_STATE = "SPREAD/INIT_STATE";
4
+ export declare const CLEANUP_SPREAD_STATE = "SPREAD/CLEANUP_STATE";
5
+ export declare const SET_ACTIVE_SPREAD_DOCUMENT = "SPREAD/SET_ACTIVE_DOCUMENT";
6
+ export declare const SET_SPREAD_MODE = "SPREAD/SET_SPREAD_MODE";
7
+ export declare const SET_PAGE_GROUPING = "SPREAD/SET_PAGE_GROUPING";
8
+ export interface InitSpreadStateAction extends Action {
9
+ type: typeof INIT_SPREAD_STATE;
10
+ payload: {
11
+ documentId: string;
12
+ state: SpreadDocumentState;
13
+ };
14
+ }
15
+ export interface CleanupSpreadStateAction extends Action {
16
+ type: typeof CLEANUP_SPREAD_STATE;
17
+ payload: string;
18
+ }
19
+ export interface SetActiveSpreadDocumentAction extends Action {
20
+ type: typeof SET_ACTIVE_SPREAD_DOCUMENT;
21
+ payload: string | null;
22
+ }
23
+ export interface SetSpreadModeAction extends Action {
4
24
  type: typeof SET_SPREAD_MODE;
5
- payload: SpreadMode;
25
+ payload: {
26
+ documentId: string;
27
+ spreadMode: SpreadMode;
28
+ };
29
+ }
30
+ export interface SetPageGroupingAction extends Action {
31
+ type: typeof SET_PAGE_GROUPING;
32
+ payload: {
33
+ documentId: string;
34
+ grouping: number[][];
35
+ };
6
36
  }
7
- export type SpreadAction = SetSpreadModeAction;
8
- export declare function setSpreadMode(mode: SpreadMode): SetSpreadModeAction;
37
+ export type SpreadAction = InitSpreadStateAction | CleanupSpreadStateAction | SetActiveSpreadDocumentAction | SetSpreadModeAction | SetPageGroupingAction;
38
+ export declare function initSpreadState(documentId: string, state: SpreadDocumentState): InitSpreadStateAction;
39
+ export declare function cleanupSpreadState(documentId: string): CleanupSpreadStateAction;
40
+ export declare function setActiveSpreadDocument(documentId: string | null): SetActiveSpreadDocumentAction;
41
+ export declare function setSpreadMode(documentId: string, spreadMode: SpreadMode): SetSpreadModeAction;
42
+ export declare function setPageGrouping(documentId: string, grouping: number[][]): SetPageGroupingAction;
@@ -6,3 +6,5 @@ export declare const SpreadPluginPackage: PluginPackage<SpreadPlugin, SpreadPlug
6
6
  export * from './spread-plugin';
7
7
  export * from './types';
8
8
  export * from './manifest';
9
+ export * from './actions';
10
+ export * from './reducer';
@@ -1,5 +1,6 @@
1
1
  import { Reducer } from '@embedpdf/core';
2
- import { SpreadState } from './types';
3
- import { SetSpreadModeAction } from './actions';
2
+ import { SpreadAction } from './actions';
3
+ import { SpreadState, SpreadDocumentState } from './types';
4
+ export declare const initialDocumentState: SpreadDocumentState;
4
5
  export declare const initialState: SpreadState;
5
- export declare const spreadReducer: Reducer<SpreadState, SetSpreadModeAction>;
6
+ export declare const spreadReducer: Reducer<SpreadState, SpreadAction>;
@@ -1,16 +1,32 @@
1
1
  import { BasePlugin, PluginRegistry } from '@embedpdf/core';
2
- import { PdfPageObject } from '@embedpdf/models';
3
- import { SpreadCapability, SpreadMode, SpreadPluginConfig, SpreadState } from './types';
2
+ import { SpreadCapability, SpreadPluginConfig, SpreadState } from './types';
4
3
  import { SpreadAction } from './actions';
5
4
  export declare class SpreadPlugin extends BasePlugin<SpreadPluginConfig, SpreadCapability, SpreadState, SpreadAction> {
6
5
  static readonly id: "spread";
7
6
  private readonly spreadEmitter$;
7
+ private readonly defaultSpreadMode;
8
+ private readonly viewport;
8
9
  constructor(id: string, registry: PluginRegistry, cfg: SpreadPluginConfig);
9
- initialize(config: SpreadPluginConfig): Promise<void>;
10
- private documentLoaded;
11
- getSpreadPagesObjects(pages: PdfPageObject[]): PdfPageObject[][];
12
- setSpreadMode(mode: SpreadMode): void;
13
- private notifySpreadChange;
10
+ protected onDocumentLoadingStarted(documentId: string): void;
11
+ protected onDocumentLoaded(documentId: string): void;
12
+ protected onDocumentClosed(documentId: string): void;
14
13
  protected buildCapability(): SpreadCapability;
14
+ private createSpreadScope;
15
+ private getDocumentState;
16
+ private getDocumentStateOrThrow;
17
+ private setSpreadModeForDocument;
18
+ private getSpreadModeForDocument;
19
+ /**
20
+ * Calculate page grouping indices based on spread mode
21
+ * Returns indices, not actual page objects
22
+ */
23
+ private calculatePageGrouping;
24
+ /**
25
+ * Get the actual page objects grouped according to spread mode
26
+ * This is computed on-demand, not stored
27
+ */
28
+ private getSpreadPages;
29
+ onStoreUpdated(prevState: SpreadState, newState: SpreadState): void;
30
+ initialize(_config: SpreadPluginConfig): Promise<void>;
15
31
  destroy(): Promise<void>;
16
32
  }
@@ -1,4 +1,5 @@
1
1
  import { BasePluginConfig, EventHook } from '@embedpdf/core';
2
+ import { PdfPageObject } from '@embedpdf/models';
2
3
  export interface SpreadPluginConfig extends BasePluginConfig {
3
4
  defaultSpreadMode?: SpreadMode;
4
5
  }
@@ -7,11 +8,28 @@ export declare enum SpreadMode {
7
8
  Odd = "odd",
8
9
  Even = "even"
9
10
  }
10
- export interface SpreadCapability {
11
- onSpreadChange: EventHook<SpreadMode>;
12
- setSpreadMode(mode: SpreadMode): void;
13
- getSpreadMode(): SpreadMode;
11
+ export interface SpreadDocumentState {
12
+ spreadMode: SpreadMode;
13
+ pageGrouping?: number[][];
14
14
  }
15
15
  export interface SpreadState {
16
+ documents: Record<string, SpreadDocumentState>;
17
+ activeDocumentId: string | null;
18
+ }
19
+ export interface SpreadChangeEvent {
20
+ documentId: string;
16
21
  spreadMode: SpreadMode;
17
22
  }
23
+ export interface SpreadScope {
24
+ setSpreadMode(mode: SpreadMode): void;
25
+ getSpreadMode(): SpreadMode;
26
+ getSpreadPages(): PdfPageObject[][];
27
+ onSpreadChange: EventHook<SpreadMode>;
28
+ }
29
+ export interface SpreadCapability {
30
+ setSpreadMode(mode: SpreadMode): void;
31
+ getSpreadMode(): SpreadMode;
32
+ getSpreadPages(documentId?: string): PdfPageObject[][];
33
+ forDocument(documentId: string): SpreadScope;
34
+ onSpreadChange: EventHook<SpreadChangeEvent>;
35
+ }
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),r=require("@embedpdf/plugin-spread");require("preact");const t=require("preact/hooks"),p=()=>e.useCapability(r.SpreadPlugin.id);exports.useSpread=()=>{const{provides:e}=p(),[o,a]=t.useState(r.SpreadMode.None);return t.useEffect((()=>null==e?void 0:e.onSpreadChange((e=>{a(e)}))),[e]),{provides:e,spreadMode:o}},exports.useSpreadCapability=p,exports.useSpreadPlugin=()=>e.usePlugin(r.SpreadPlugin.id),Object.keys(r).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})}));
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),r=require("@embedpdf/plugin-spread");require("preact");const t=require("preact/hooks"),o=()=>e.useCapability(r.SpreadPlugin.id);exports.useSpread=e=>{const{provides:p}=o(),[u,a]=t.useState(r.initialDocumentState.spreadMode);return t.useEffect(()=>{if(!p)return;const r=p.forDocument(e);return a(r.getSpreadMode()),r.onSpreadChange(e=>{a(e)})},[p,e]),{spreadMode:u,provides:(null==p?void 0:p.forDocument(e))??null}},exports.useSpreadCapability=o,exports.useSpreadPlugin=()=>e.usePlugin(r.SpreadPlugin.id),Object.keys(r).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-spread.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SpreadMode, SpreadPlugin } from '@embedpdf/plugin-spread';\nimport { useEffect, useState } from '@framework';\n\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\nexport const useSpread = () => {\n const { provides: spreadProvider } = useSpreadCapability();\n const [spreadMode, setSpreadMode] = useState<SpreadMode>(SpreadMode.None);\n\n useEffect(() => {\n return spreadProvider?.onSpreadChange((spreadMode) => {\n setSpreadMode(spreadMode);\n });\n }, [spreadProvider]);\n\n return {\n provides: spreadProvider,\n spreadMode,\n };\n};\n"],"names":["useSpreadCapability","useCapability","SpreadPlugin","id","provides","spreadProvider","spreadMode","setSpreadMode","useState","SpreadMode","None","useEffect","onSpreadChange","usePlugin"],"mappings":"gNAKaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,sBAEzD,KACvB,MAAQC,SAAUC,GAAmBL,KAC9BM,EAAYC,GAAiBC,EAAAA,SAAqBC,EAAAA,WAAWC,MAQ7D,OANPC,EAAAA,WAAU,IACD,MAAAN,OAAA,EAAAA,EAAgBO,gBAAgBN,IACrCC,EAAcD,EAAU,KAEzB,CAACD,IAEG,CACLD,SAAUC,EACVC,aACF,wDAhB6B,IAAMO,YAAwBX,EAAAA,aAAaC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-spread.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SpreadMode, SpreadPlugin, initialDocumentState } from '@embedpdf/plugin-spread';\nimport { useEffect, useState } from '@framework';\n\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\n/**\n * Hook for spread state for a specific document\n * @param documentId Document ID\n */\nexport const useSpread = (documentId: string) => {\n const { provides } = useSpreadCapability();\n const [spreadMode, setSpreadMode] = useState<SpreadMode>(initialDocumentState.spreadMode);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n\n // Get initial state\n setSpreadMode(scope.getSpreadMode());\n\n // Subscribe to spread mode changes\n return scope.onSpreadChange((newSpreadMode) => {\n setSpreadMode(newSpreadMode);\n });\n }, [provides, documentId]);\n\n return {\n spreadMode,\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n"],"names":["useSpreadCapability","useCapability","SpreadPlugin","id","documentId","provides","spreadMode","setSpreadMode","useState","initialDocumentState","useEffect","scope","forDocument","getSpreadMode","onSpreadChange","newSpreadMode","usePlugin"],"mappings":"gNAKaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,sBAMxDC,IACxB,MAAMC,SAAEA,GAAaL,KACdM,EAAYC,GAAiBC,EAAAA,SAAqBC,EAAAA,qBAAqBH,YAgB9E,OAdAI,EAAAA,UAAU,KACR,IAAKL,EAAU,OAEf,MAAMM,EAAQN,EAASO,YAAYR,GAMnC,OAHAG,EAAcI,EAAME,iBAGbF,EAAMG,eAAgBC,IAC3BR,EAAcQ,MAEf,CAACV,EAAUD,IAEP,CACLE,aACAD,UAAU,MAAAA,OAAA,EAAAA,EAAUO,YAAYR,KAAe,6DA3BpB,IAAMY,YAAwBd,EAAAA,aAAaC"}
@@ -1,21 +1,24 @@
1
1
  import { usePlugin, useCapability } from "@embedpdf/core/preact";
2
- import { SpreadPlugin, SpreadMode } from "@embedpdf/plugin-spread";
2
+ import { SpreadPlugin, initialDocumentState } from "@embedpdf/plugin-spread";
3
3
  export * from "@embedpdf/plugin-spread";
4
4
  import "preact";
5
5
  import { useState, useEffect } from "preact/hooks";
6
6
  const useSpreadPlugin = () => usePlugin(SpreadPlugin.id);
7
7
  const useSpreadCapability = () => useCapability(SpreadPlugin.id);
8
- const useSpread = () => {
9
- const { provides: spreadProvider } = useSpreadCapability();
10
- const [spreadMode, setSpreadMode] = useState(SpreadMode.None);
8
+ const useSpread = (documentId) => {
9
+ const { provides } = useSpreadCapability();
10
+ const [spreadMode, setSpreadMode] = useState(initialDocumentState.spreadMode);
11
11
  useEffect(() => {
12
- return spreadProvider == null ? void 0 : spreadProvider.onSpreadChange((spreadMode2) => {
13
- setSpreadMode(spreadMode2);
12
+ if (!provides) return;
13
+ const scope = provides.forDocument(documentId);
14
+ setSpreadMode(scope.getSpreadMode());
15
+ return scope.onSpreadChange((newSpreadMode) => {
16
+ setSpreadMode(newSpreadMode);
14
17
  });
15
- }, [spreadProvider]);
18
+ }, [provides, documentId]);
16
19
  return {
17
- provides: spreadProvider,
18
- spreadMode
20
+ spreadMode,
21
+ provides: (provides == null ? void 0 : provides.forDocument(documentId)) ?? null
19
22
  };
20
23
  };
21
24
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-spread.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SpreadMode, SpreadPlugin } from '@embedpdf/plugin-spread';\nimport { useEffect, useState } from '@framework';\n\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\nexport const useSpread = () => {\n const { provides: spreadProvider } = useSpreadCapability();\n const [spreadMode, setSpreadMode] = useState<SpreadMode>(SpreadMode.None);\n\n useEffect(() => {\n return spreadProvider?.onSpreadChange((spreadMode) => {\n setSpreadMode(spreadMode);\n });\n }, [spreadProvider]);\n\n return {\n provides: spreadProvider,\n spreadMode,\n };\n};\n"],"names":["spreadMode"],"mappings":";;;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAE7E,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,CAAC,YAAY,aAAa,IAAI,SAAqB,WAAW,IAAI;AAExE,YAAU,MAAM;AACP,WAAA,iDAAgB,eAAe,CAACA,gBAAe;AACpD,oBAAcA,WAAU;AAAA,IAAA;AAAA,EACzB,GACA,CAAC,cAAc,CAAC;AAEZ,SAAA;AAAA,IACL,UAAU;AAAA,IACV;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-spread.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SpreadMode, SpreadPlugin, initialDocumentState } from '@embedpdf/plugin-spread';\nimport { useEffect, useState } from '@framework';\n\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\n/**\n * Hook for spread state for a specific document\n * @param documentId Document ID\n */\nexport const useSpread = (documentId: string) => {\n const { provides } = useSpreadCapability();\n const [spreadMode, setSpreadMode] = useState<SpreadMode>(initialDocumentState.spreadMode);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n\n // Get initial state\n setSpreadMode(scope.getSpreadMode());\n\n // Subscribe to spread mode changes\n return scope.onSpreadChange((newSpreadMode) => {\n setSpreadMode(newSpreadMode);\n });\n }, [provides, documentId]);\n\n return {\n spreadMode,\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n"],"names":[],"mappings":";;;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAM7E,MAAM,YAAY,CAAC,eAAuB;AAC/C,QAAM,EAAE,SAAA,IAAa,oBAAA;AACrB,QAAM,CAAC,YAAY,aAAa,IAAI,SAAqB,qBAAqB,UAAU;AAExF,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AAEf,UAAM,QAAQ,SAAS,YAAY,UAAU;AAG7C,kBAAc,MAAM,eAAe;AAGnC,WAAO,MAAM,eAAe,CAAC,kBAAkB;AAC7C,oBAAc,aAAa;AAAA,IAC7B,CAAC;AAAA,EACH,GAAG,CAAC,UAAU,UAAU,CAAC;AAEzB,SAAO;AAAA,IACL;AAAA,IACA,WAAU,qCAAU,YAAY,gBAAe;AAAA,EAAA;AAEnD;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),r=require("@embedpdf/plugin-spread"),t=require("react"),p=()=>e.useCapability(r.SpreadPlugin.id);exports.useSpread=()=>{const{provides:e}=p(),[o,a]=t.useState(r.SpreadMode.None);return t.useEffect((()=>null==e?void 0:e.onSpreadChange((e=>{a(e)}))),[e]),{provides:e,spreadMode:o}},exports.useSpreadCapability=p,exports.useSpreadPlugin=()=>e.usePlugin(r.SpreadPlugin.id),Object.keys(r).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})}));
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),r=require("@embedpdf/plugin-spread"),t=require("react"),o=()=>e.useCapability(r.SpreadPlugin.id);exports.useSpread=e=>{const{provides:p}=o(),[u,a]=t.useState(r.initialDocumentState.spreadMode);return t.useEffect(()=>{if(!p)return;const r=p.forDocument(e);return a(r.getSpreadMode()),r.onSpreadChange(e=>{a(e)})},[p,e]),{spreadMode:u,provides:(null==p?void 0:p.forDocument(e))??null}},exports.useSpreadCapability=o,exports.useSpreadPlugin=()=>e.usePlugin(r.SpreadPlugin.id),Object.keys(r).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-spread.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SpreadMode, SpreadPlugin } from '@embedpdf/plugin-spread';\nimport { useEffect, useState } from '@framework';\n\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\nexport const useSpread = () => {\n const { provides: spreadProvider } = useSpreadCapability();\n const [spreadMode, setSpreadMode] = useState<SpreadMode>(SpreadMode.None);\n\n useEffect(() => {\n return spreadProvider?.onSpreadChange((spreadMode) => {\n setSpreadMode(spreadMode);\n });\n }, [spreadProvider]);\n\n return {\n provides: spreadProvider,\n spreadMode,\n };\n};\n"],"names":["useSpreadCapability","useCapability","SpreadPlugin","id","provides","spreadProvider","spreadMode","setSpreadMode","useState","SpreadMode","None","useEffect","onSpreadChange","usePlugin"],"mappings":"gLAKaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,sBAEzD,KACvB,MAAQC,SAAUC,GAAmBL,KAC9BM,EAAYC,GAAiBC,EAAAA,SAAqBC,EAAAA,WAAWC,MAQ7D,OANPC,EAAAA,WAAU,IACD,MAAAN,OAAA,EAAAA,EAAgBO,gBAAgBN,IACrCC,EAAcD,EAAU,KAEzB,CAACD,IAEG,CACLD,SAAUC,EACVC,aACF,wDAhB6B,IAAMO,YAAwBX,EAAAA,aAAaC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-spread.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SpreadMode, SpreadPlugin, initialDocumentState } from '@embedpdf/plugin-spread';\nimport { useEffect, useState } from '@framework';\n\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\n/**\n * Hook for spread state for a specific document\n * @param documentId Document ID\n */\nexport const useSpread = (documentId: string) => {\n const { provides } = useSpreadCapability();\n const [spreadMode, setSpreadMode] = useState<SpreadMode>(initialDocumentState.spreadMode);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n\n // Get initial state\n setSpreadMode(scope.getSpreadMode());\n\n // Subscribe to spread mode changes\n return scope.onSpreadChange((newSpreadMode) => {\n setSpreadMode(newSpreadMode);\n });\n }, [provides, documentId]);\n\n return {\n spreadMode,\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n"],"names":["useSpreadCapability","useCapability","SpreadPlugin","id","documentId","provides","spreadMode","setSpreadMode","useState","initialDocumentState","useEffect","scope","forDocument","getSpreadMode","onSpreadChange","newSpreadMode","usePlugin"],"mappings":"gLAKaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,sBAMxDC,IACxB,MAAMC,SAAEA,GAAaL,KACdM,EAAYC,GAAiBC,EAAAA,SAAqBC,EAAAA,qBAAqBH,YAgB9E,OAdAI,EAAAA,UAAU,KACR,IAAKL,EAAU,OAEf,MAAMM,EAAQN,EAASO,YAAYR,GAMnC,OAHAG,EAAcI,EAAME,iBAGbF,EAAMG,eAAgBC,IAC3BR,EAAcQ,MAEf,CAACV,EAAUD,IAEP,CACLE,aACAD,UAAU,MAAAA,OAAA,EAAAA,EAAUO,YAAYR,KAAe,6DA3BpB,IAAMY,YAAwBd,EAAAA,aAAaC"}
@@ -1,20 +1,23 @@
1
1
  import { usePlugin, useCapability } from "@embedpdf/core/react";
2
- import { SpreadPlugin, SpreadMode } from "@embedpdf/plugin-spread";
2
+ import { SpreadPlugin, initialDocumentState } from "@embedpdf/plugin-spread";
3
3
  export * from "@embedpdf/plugin-spread";
4
4
  import { useState, useEffect } from "react";
5
5
  const useSpreadPlugin = () => usePlugin(SpreadPlugin.id);
6
6
  const useSpreadCapability = () => useCapability(SpreadPlugin.id);
7
- const useSpread = () => {
8
- const { provides: spreadProvider } = useSpreadCapability();
9
- const [spreadMode, setSpreadMode] = useState(SpreadMode.None);
7
+ const useSpread = (documentId) => {
8
+ const { provides } = useSpreadCapability();
9
+ const [spreadMode, setSpreadMode] = useState(initialDocumentState.spreadMode);
10
10
  useEffect(() => {
11
- return spreadProvider == null ? void 0 : spreadProvider.onSpreadChange((spreadMode2) => {
12
- setSpreadMode(spreadMode2);
11
+ if (!provides) return;
12
+ const scope = provides.forDocument(documentId);
13
+ setSpreadMode(scope.getSpreadMode());
14
+ return scope.onSpreadChange((newSpreadMode) => {
15
+ setSpreadMode(newSpreadMode);
13
16
  });
14
- }, [spreadProvider]);
17
+ }, [provides, documentId]);
15
18
  return {
16
- provides: spreadProvider,
17
- spreadMode
19
+ spreadMode,
20
+ provides: (provides == null ? void 0 : provides.forDocument(documentId)) ?? null
18
21
  };
19
22
  };
20
23
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-spread.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SpreadMode, SpreadPlugin } from '@embedpdf/plugin-spread';\nimport { useEffect, useState } from '@framework';\n\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\nexport const useSpread = () => {\n const { provides: spreadProvider } = useSpreadCapability();\n const [spreadMode, setSpreadMode] = useState<SpreadMode>(SpreadMode.None);\n\n useEffect(() => {\n return spreadProvider?.onSpreadChange((spreadMode) => {\n setSpreadMode(spreadMode);\n });\n }, [spreadProvider]);\n\n return {\n provides: spreadProvider,\n spreadMode,\n };\n};\n"],"names":["spreadMode"],"mappings":";;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAE7E,MAAM,YAAY,MAAM;AAC7B,QAAM,EAAE,UAAU,eAAe,IAAI,oBAAoB;AACzD,QAAM,CAAC,YAAY,aAAa,IAAI,SAAqB,WAAW,IAAI;AAExE,YAAU,MAAM;AACP,WAAA,iDAAgB,eAAe,CAACA,gBAAe;AACpD,oBAAcA,WAAU;AAAA,IAAA;AAAA,EACzB,GACA,CAAC,cAAc,CAAC;AAEZ,SAAA;AAAA,IACL,UAAU;AAAA,IACV;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-spread.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { SpreadMode, SpreadPlugin, initialDocumentState } from '@embedpdf/plugin-spread';\nimport { useEffect, useState } from '@framework';\n\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\n/**\n * Hook for spread state for a specific document\n * @param documentId Document ID\n */\nexport const useSpread = (documentId: string) => {\n const { provides } = useSpreadCapability();\n const [spreadMode, setSpreadMode] = useState<SpreadMode>(initialDocumentState.spreadMode);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n\n // Get initial state\n setSpreadMode(scope.getSpreadMode());\n\n // Subscribe to spread mode changes\n return scope.onSpreadChange((newSpreadMode) => {\n setSpreadMode(newSpreadMode);\n });\n }, [provides, documentId]);\n\n return {\n spreadMode,\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n"],"names":[],"mappings":";;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAM7E,MAAM,YAAY,CAAC,eAAuB;AAC/C,QAAM,EAAE,SAAA,IAAa,oBAAA;AACrB,QAAM,CAAC,YAAY,aAAa,IAAI,SAAqB,qBAAqB,UAAU;AAExF,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AAEf,UAAM,QAAQ,SAAS,YAAY,UAAU;AAG7C,kBAAc,MAAM,eAAe;AAGnC,WAAO,MAAM,eAAe,CAAC,kBAAkB;AAC7C,oBAAc,aAAa;AAAA,IAC7B,CAAC;AAAA,EACH,GAAG,CAAC,UAAU,UAAU,CAAC;AAEzB,SAAO;AAAA,IACL;AAAA,IACA,WAAU,qCAAU,YAAY,gBAAe;AAAA,EAAA;AAEnD;"}
@@ -9,7 +9,11 @@ export declare const useSpreadCapability: () => {
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
11
  };
12
- export declare const useSpread: () => {
13
- provides: Readonly<import('../../index.ts').SpreadCapability> | null;
12
+ /**
13
+ * Hook for spread state for a specific document
14
+ * @param documentId Document ID
15
+ */
16
+ export declare const useSpread: (documentId: string) => {
14
17
  spreadMode: SpreadMode;
18
+ provides: import('../../index.ts').SpreadScope | null;
15
19
  };
@@ -9,7 +9,11 @@ export declare const useSpreadCapability: () => {
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
11
  };
12
- export declare const useSpread: () => {
13
- provides: Readonly<import('../../lib/index.ts').SpreadCapability> | null;
12
+ /**
13
+ * Hook for spread state for a specific document
14
+ * @param documentId Document ID
15
+ */
16
+ export declare const useSpread: (documentId: string) => {
14
17
  spreadMode: SpreadMode;
18
+ provides: import('../../lib/index.ts').SpreadScope | null;
15
19
  };
@@ -9,7 +9,11 @@ export declare const useSpreadCapability: () => {
9
9
  isLoading: boolean;
10
10
  ready: Promise<void>;
11
11
  };
12
- export declare const useSpread: () => {
13
- provides: Readonly<import('../../lib/index.ts').SpreadCapability> | null;
12
+ /**
13
+ * Hook for spread state for a specific document
14
+ * @param documentId Document ID
15
+ */
16
+ export declare const useSpread: (documentId: string) => {
14
17
  spreadMode: SpreadMode;
18
+ provides: import('../../lib/index.ts').SpreadScope | null;
15
19
  };
@@ -1,13 +1,4 @@
1
- import { SpreadMode, SpreadPlugin } from '../../lib/index.ts';
2
- /**
3
- * Hook to get the spread plugin's capability API.
4
- * This provides methods for controlling spread mode.
5
- */
6
- export declare const useSpreadCapability: () => {
7
- provides: Readonly<import('../../lib/index.ts').SpreadCapability> | null;
8
- isLoading: boolean;
9
- ready: Promise<void>;
10
- };
1
+ import { SpreadMode, SpreadPlugin, SpreadScope } from '../../lib/index.ts';
11
2
  /**
12
3
  * Hook to get the raw spread plugin instance.
13
4
  * Useful for accessing plugin-specific properties or methods not exposed in the capability.
@@ -18,10 +9,21 @@ export declare const useSpreadPlugin: () => {
18
9
  ready: Promise<void>;
19
10
  };
20
11
  /**
21
- * Hook to manage spread mode state and listen to changes.
22
- * Returns the capability provider and reactive spread mode.
12
+ * Hook to get the spread plugin's capability API.
13
+ * This provides methods for controlling spread mode.
23
14
  */
24
- export declare const useSpread: () => {
25
- readonly provides: Readonly<import('../../lib/index.ts').SpreadCapability> | null;
26
- spreadMode: SpreadMode;
15
+ export declare const useSpreadCapability: () => {
16
+ provides: Readonly<import('../../lib/index.ts').SpreadCapability> | null;
17
+ isLoading: boolean;
18
+ ready: Promise<void>;
27
19
  };
20
+ interface UseSpreadReturn {
21
+ provides: SpreadScope | null;
22
+ spreadMode: SpreadMode;
23
+ }
24
+ /**
25
+ * Hook for spread state for a specific document
26
+ * @param getDocumentId Function that returns the document ID
27
+ */
28
+ export declare const useSpread: (getDocumentId: () => string | null) => UseSpreadReturn;
29
+ export {};
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),r=require("@embedpdf/core/svelte"),t=require("@embedpdf/plugin-spread");function o(e){const r=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const t in e)if("default"!==t){const o=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,o.get?o:{enumerable:!0,get:()=>e[t]})}return r.default=e,Object.freeze(r)}const p=o(e),d=()=>r.useCapability(t.SpreadPlugin.id);exports.useSpread=()=>{const e=d(),r=p.proxy({get provides(){return e.provides},spreadMode:t.SpreadMode.None});return p.user_effect((()=>{if(!e.provides)return;r.spreadMode=e.provides.getSpreadMode();return e.provides.onSpreadChange((e=>{r.spreadMode=e}))})),r},exports.useSpreadCapability=d,exports.useSpreadPlugin=()=>r.usePlugin(t.SpreadPlugin.id),Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),t=require("@embedpdf/core/svelte"),r=require("@embedpdf/plugin-spread");function o(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e)for(const r in e)if("default"!==r){const o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:()=>e[r]})}return t.default=e,Object.freeze(t)}const n=o(e),i=()=>t.useCapability(r.SpreadPlugin.id);exports.useSpread=e=>{const t=i();let o=n.state(n.proxy(r.initialDocumentState.spreadMode));const s=n.derived(e),d=n.derived(()=>t.provides&&n.get(s)?t.provides.forDocument(n.get(s)):null);return n.user_effect(()=>{const e=t.provides,i=n.get(s);if(!e||!i)return void n.set(o,r.initialDocumentState.spreadMode,!0);const d=e.forDocument(i);return n.set(o,d.getSpreadMode(),!0),d.onSpreadChange(e=>{n.set(o,e,!0)})}),{get provides(){return n.get(d)},get spreadMode(){return n.get(o)}}},exports.useSpreadCapability=i,exports.useSpreadPlugin=()=>t.usePlugin(r.SpreadPlugin.id),Object.keys(r).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>r[e]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-spread.svelte.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { SpreadMode, SpreadPlugin } from '@embedpdf/plugin-spread';\n\n/**\n * Hook to get the spread plugin's capability API.\n * This provides methods for controlling spread mode.\n */\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\n/**\n * Hook to get the raw spread plugin instance.\n * Useful for accessing plugin-specific properties or methods not exposed in the capability.\n */\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\n\n/**\n * Hook to manage spread mode state and listen to changes.\n * Returns the capability provider and reactive spread mode.\n */\nexport const useSpread = () => {\n const capability = useSpreadCapability();\n\n const state = $state({\n get provides() {\n return capability.provides;\n },\n spreadMode: SpreadMode.None as SpreadMode,\n });\n\n $effect(() => {\n if (!capability.provides) return;\n\n // Set initial spread mode\n state.spreadMode = capability.provides.getSpreadMode();\n\n // Subscribe to spread mode changes\n const unsubscribe = capability.provides.onSpreadChange((newSpreadMode) => {\n state.spreadMode = newSpreadMode;\n });\n\n return unsubscribe;\n });\n\n return state;\n};\n"],"names":["useSpreadCapability","useCapability","SpreadPlugin","id","capability","state","provides","spreadMode","SpreadMode","None","$","user_effect","getSpreadMode","onSpreadChange","newSpreadMode","usePlugin"],"mappings":"0dAOaA,EAA4B,IAAAC,gBAA4BC,EAAAA,aAAaC,2BAa1E,MAAAC,EAAaJ,IAEbK,WACA,YAAAC,GACK,OAAAF,EAAWE,QACpB,EACAC,WAAYC,EAAAA,WAAWC,OAiBlB,OAdPC,EAAAC,kBACO,IAAAP,EAAWE,SAAU,OAGpBD,EAAAE,WAAaH,EAAWE,SAASM,gBAOhC,OAJaR,EAAWE,SAASO,gBAAgBC,IACtDT,EAAME,WAAaO,CAAA,GAGd,IAGFT,CAAA,wDA9B4B,IAAAU,YAAwBb,EAAAA,aAAaC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-spread.svelte.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport {\n SpreadMode,\n SpreadPlugin,\n initialDocumentState,\n SpreadScope,\n} from '@embedpdf/plugin-spread';\n\n/**\n * Hook to get the raw spread plugin instance.\n * Useful for accessing plugin-specific properties or methods not exposed in the capability.\n */\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\n\n/**\n * Hook to get the spread plugin's capability API.\n * This provides methods for controlling spread mode.\n */\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseSpreadReturn {\n provides: SpreadScope | null;\n spreadMode: SpreadMode;\n}\n\n/**\n * Hook for spread state for a specific document\n * @param getDocumentId Function that returns the document ID\n */\nexport const useSpread = (getDocumentId: () => string | null): UseSpreadReturn => {\n const capability = useSpreadCapability();\n\n let spreadMode = $state<SpreadMode>(initialDocumentState.spreadMode);\n\n // Reactive documentId\n const documentId = $derived(getDocumentId());\n\n // Scoped capability for current docId\n const scopedProvides = $derived(\n capability.provides && documentId ? capability.provides.forDocument(documentId) : null,\n );\n\n $effect(() => {\n const provides = capability.provides;\n const docId = documentId;\n\n if (!provides || !docId) {\n spreadMode = initialDocumentState.spreadMode;\n return;\n }\n\n const scope = provides.forDocument(docId);\n\n // Set initial spread mode\n spreadMode = scope.getSpreadMode();\n\n // Subscribe to spread mode changes for this document\n return scope.onSpreadChange((newSpreadMode) => {\n spreadMode = newSpreadMode;\n });\n });\n\n return {\n get provides() {\n return scopedProvides;\n },\n get spreadMode() {\n return spreadMode;\n },\n };\n};\n"],"names":["useSpreadCapability","useCapability","SpreadPlugin","id","getDocumentId","capability","spreadMode","$","state","proxy","initialDocumentState","documentId","scopedProvides","derived","provides","forDocument","user_effect","docId","scope","getSpreadMode","onSpreadChange","newSpreadMode","set","usePlugin"],"mappings":"0dAkBaA,EAAA,IAA4BC,gBAA4BC,EAAAA,aAAaC,sBAYxDC,IAClB,MAAAC,EAAaL,QAEfM,EAAAC,EAAAC,MAAAD,EAAAE,MAAgCC,EAAAA,qBAAqBJ,aAGnD,MAAAK,YAAsBP,GAGtBQ,EAAAL,EAAAM,QAAA,IACJR,EAAWS,gBAAYH,GAAaN,EAAWS,SAASC,kBAAYJ,IAAc,aAGpFJ,EAAAS,uBACQF,EAAWT,EAAWS,SACtBG,QAAQN,OAETG,IAAaG,oBAChBX,EAAaI,EAAAA,qBAAqBJ,YAAA,GAI9B,MAAAY,EAAQJ,EAASC,YAAYE,GAM5B,aAHPX,EAAaY,EAAMC,iBAAA,GAGZD,EAAME,eAAgBC,IAC3Bd,EAAAe,IAAAhB,EAAae,GAAA,QAKX,YAAAP,gBACKF,EACT,EACI,cAAAN,gBACKA,EACT,0DAzDS,IAAwBiB,YAAwBrB,EAAAA,aAAaC"}
@@ -1,26 +1,35 @@
1
1
  import * as $ from "svelte/internal/client";
2
- import { useCapability, usePlugin } from "@embedpdf/core/svelte";
3
- import { SpreadPlugin, SpreadMode } from "@embedpdf/plugin-spread";
2
+ import { usePlugin, useCapability } from "@embedpdf/core/svelte";
3
+ import { SpreadPlugin, initialDocumentState } from "@embedpdf/plugin-spread";
4
4
  export * from "@embedpdf/plugin-spread";
5
- const useSpreadCapability = () => useCapability(SpreadPlugin.id);
6
5
  const useSpreadPlugin = () => usePlugin(SpreadPlugin.id);
7
- const useSpread = () => {
6
+ const useSpreadCapability = () => useCapability(SpreadPlugin.id);
7
+ const useSpread = (getDocumentId) => {
8
8
  const capability = useSpreadCapability();
9
- const state = $.proxy({
10
- get provides() {
11
- return capability.provides;
12
- },
13
- spreadMode: SpreadMode.None
14
- });
9
+ let spreadMode = $.state($.proxy(initialDocumentState.spreadMode));
10
+ const documentId = $.derived(getDocumentId);
11
+ const scopedProvides = $.derived(() => capability.provides && $.get(documentId) ? capability.provides.forDocument($.get(documentId)) : null);
15
12
  $.user_effect(() => {
16
- if (!capability.provides) return;
17
- state.spreadMode = capability.provides.getSpreadMode();
18
- const unsubscribe = capability.provides.onSpreadChange((newSpreadMode) => {
19
- state.spreadMode = newSpreadMode;
13
+ const provides = capability.provides;
14
+ const docId = $.get(documentId);
15
+ if (!provides || !docId) {
16
+ $.set(spreadMode, initialDocumentState.spreadMode, true);
17
+ return;
18
+ }
19
+ const scope = provides.forDocument(docId);
20
+ $.set(spreadMode, scope.getSpreadMode(), true);
21
+ return scope.onSpreadChange((newSpreadMode) => {
22
+ $.set(spreadMode, newSpreadMode, true);
20
23
  });
21
- return unsubscribe;
22
24
  });
23
- return state;
25
+ return {
26
+ get provides() {
27
+ return $.get(scopedProvides);
28
+ },
29
+ get spreadMode() {
30
+ return $.get(spreadMode);
31
+ }
32
+ };
24
33
  };
25
34
  export {
26
35
  useSpread,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-spread.svelte.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { SpreadMode, SpreadPlugin } from '@embedpdf/plugin-spread';\n\n/**\n * Hook to get the spread plugin's capability API.\n * This provides methods for controlling spread mode.\n */\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\n/**\n * Hook to get the raw spread plugin instance.\n * Useful for accessing plugin-specific properties or methods not exposed in the capability.\n */\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\n\n/**\n * Hook to manage spread mode state and listen to changes.\n * Returns the capability provider and reactive spread mode.\n */\nexport const useSpread = () => {\n const capability = useSpreadCapability();\n\n const state = $state({\n get provides() {\n return capability.provides;\n },\n spreadMode: SpreadMode.None as SpreadMode,\n });\n\n $effect(() => {\n if (!capability.provides) return;\n\n // Set initial spread mode\n state.spreadMode = capability.provides.getSpreadMode();\n\n // Subscribe to spread mode changes\n const unsubscribe = capability.provides.onSpreadChange((newSpreadMode) => {\n state.spreadMode = newSpreadMode;\n });\n\n return unsubscribe;\n });\n\n return state;\n};\n"],"names":[],"mappings":";;;;AAOa,MAAA,sBAA4B,MAAA,cAA4B,aAAa,EAAE;AAMvE,MAAA,kBAAwB,MAAA,UAAwB,aAAa,EAAE;AAM/D,MAAA,kBAAkB;AACvB,QAAA,aAAa,oBAAoB;QAEjC;IACA,IAAA,WAAW;AACN,aAAA,WAAW;AAAA,IACpB;AAAA,IACA,YAAY,WAAW;AAAA;AAGzB,IAAA,kBAAc;AACP,QAAA,CAAA,WAAW,SAAU;AAGpB,UAAA,aAAa,WAAW,SAAS,cAAc;UAG/C,cAAc,WAAW,SAAS,eAAA,CAAgB,kBAAkB;AACxE,YAAM,aAAa;AAAA,KACpB;WAEM;AAAA,GACR;SAEM;AACT;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-spread.svelte.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport {\n SpreadMode,\n SpreadPlugin,\n initialDocumentState,\n SpreadScope,\n} from '@embedpdf/plugin-spread';\n\n/**\n * Hook to get the raw spread plugin instance.\n * Useful for accessing plugin-specific properties or methods not exposed in the capability.\n */\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\n\n/**\n * Hook to get the spread plugin's capability API.\n * This provides methods for controlling spread mode.\n */\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseSpreadReturn {\n provides: SpreadScope | null;\n spreadMode: SpreadMode;\n}\n\n/**\n * Hook for spread state for a specific document\n * @param getDocumentId Function that returns the document ID\n */\nexport const useSpread = (getDocumentId: () => string | null): UseSpreadReturn => {\n const capability = useSpreadCapability();\n\n let spreadMode = $state<SpreadMode>(initialDocumentState.spreadMode);\n\n // Reactive documentId\n const documentId = $derived(getDocumentId());\n\n // Scoped capability for current docId\n const scopedProvides = $derived(\n capability.provides && documentId ? capability.provides.forDocument(documentId) : null,\n );\n\n $effect(() => {\n const provides = capability.provides;\n const docId = documentId;\n\n if (!provides || !docId) {\n spreadMode = initialDocumentState.spreadMode;\n return;\n }\n\n const scope = provides.forDocument(docId);\n\n // Set initial spread mode\n spreadMode = scope.getSpreadMode();\n\n // Subscribe to spread mode changes for this document\n return scope.onSpreadChange((newSpreadMode) => {\n spreadMode = newSpreadMode;\n });\n });\n\n return {\n get provides() {\n return scopedProvides;\n },\n get spreadMode() {\n return spreadMode;\n },\n };\n};\n"],"names":[],"mappings":";;;;AAYa,MAAA,kBAAA,MAAwB,UAAwB,aAAa,EAAE;AAM/D,MAAA,sBAAA,MAA4B,cAA4B,aAAa,EAAE;MAYvE,YAAA,CAAa,kBAAwD;AAC1E,QAAA,aAAa,oBAAA;MAEf,aAAA,EAAA,MAAA,EAAA,MAAgC,qBAAqB,UAAU,CAAA;AAG7D,QAAA,uBAAsB,aAAA;AAGtB,QAAA,iBAAA,EAAA,QAAA,MACJ,WAAW,kBAAY,UAAA,IAAa,WAAW,SAAS,kBAAY,UAAU,CAAA,IAAI,IAAA;AAGpF,IAAA,kBAAc;UACN,WAAW,WAAW;AACtB,UAAA,cAAQ,UAAA;SAET,YAAA,CAAa,OAAO;YACvB,YAAa,qBAAqB,YAAA,IAAA;;IAEpC;AAEM,UAAA,QAAQ,SAAS,YAAY,KAAK;UAGxC,YAAa,MAAM,cAAA,GAAA,IAAA;AAGZ,WAAA,MAAM,eAAA,CAAgB,kBAAkB;AAC7C,QAAA,IAAA,YAAa,eAAA,IAAA;AAAA,IACf,CAAC;AAAA,EACH,CAAC;;IAGK,IAAA,WAAW;mBACN,cAAA;AAAA,IACT;AAAA,IACI,IAAA,aAAa;mBACR,UAAA;AAAA,IACT;AAAA;AAEJ;"}
@@ -1,7 +1,12 @@
1
+ import { MaybeRefOrGetter } from 'vue';
1
2
  import { SpreadMode, SpreadPlugin } from '../../lib/index.ts';
2
3
  export declare const useSpreadPlugin: () => import('@embedpdf/core/vue').PluginState<SpreadPlugin>;
3
4
  export declare const useSpreadCapability: () => import('@embedpdf/core/vue').CapabilityState<Readonly<import('../../lib/index.ts').SpreadCapability>>;
4
- export declare const useSpread: () => {
5
- provides: import('vue').Ref<Readonly<import('../../lib/index.ts').SpreadCapability> | null, Readonly<import('../../lib/index.ts').SpreadCapability> | null>;
6
- spreadMode: import('vue').Ref<SpreadMode, SpreadMode>;
5
+ /**
6
+ * Hook for spread state for a specific document
7
+ * @param documentId Document ID (can be ref, computed, getter, or plain value)
8
+ */
9
+ export declare const useSpread: (documentId: MaybeRefOrGetter<string>) => {
10
+ provides: import('vue').ComputedRef<import('../../lib/index.ts').SpreadScope | null>;
11
+ spreadMode: Readonly<import('vue').Ref<SpreadMode, SpreadMode>>;
7
12
  };
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),r=require("@embedpdf/core/vue"),t=require("@embedpdf/plugin-spread"),p=()=>r.useCapability(t.SpreadPlugin.id);exports.useSpread=()=>{const{provides:r}=p(),a=e.ref(t.SpreadMode.None);return e.watch(r,((e,r,t)=>{if(e){a.value=e.getSpreadMode();t(e.onSpreadChange((e=>{a.value=e})))}}),{immediate:!0}),{provides:r,spreadMode:a}},exports.useSpreadCapability=p,exports.useSpreadPlugin=()=>r.usePlugin(t.SpreadPlugin.id),Object.keys(t).forEach((e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})}));
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),r=require("@embedpdf/core/vue"),t=require("@embedpdf/plugin-spread"),o=()=>r.useCapability(t.SpreadPlugin.id);exports.useSpread=r=>{const{provides:a}=o(),u=e.ref(t.initialDocumentState.spreadMode);e.watch([a,()=>e.toValue(r)],([e,r],o,a)=>{if(!e)return void(u.value=t.initialDocumentState.spreadMode);const d=e.forDocument(r);u.value=d.getSpreadMode();a(d.onSpreadChange(e=>{u.value=e}))},{immediate:!0});return{provides:e.computed(()=>{var t;const o=e.toValue(r);return(null==(t=a.value)?void 0:t.forDocument(o))??null}),spreadMode:e.readonly(u)}},exports.useSpreadCapability=o,exports.useSpreadPlugin=()=>r.usePlugin(t.SpreadPlugin.id),Object.keys(t).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>t[e]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-spread.ts"],"sourcesContent":["import { ref, watch } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { SpreadMode, SpreadPlugin } from '@embedpdf/plugin-spread';\n\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\nexport const useSpread = () => {\n const { provides } = useSpreadCapability();\n const spreadMode = ref<SpreadMode>(SpreadMode.None);\n\n watch(\n provides,\n (providesValue, _, onCleanup) => {\n if (providesValue) {\n // Set initial spread mode\n spreadMode.value = providesValue.getSpreadMode();\n\n // Subscribe to spread mode changes\n const unsubscribe = providesValue.onSpreadChange((newSpreadMode) => {\n spreadMode.value = newSpreadMode;\n });\n\n onCleanup(unsubscribe);\n }\n },\n { immediate: true },\n );\n\n return {\n provides,\n spreadMode,\n };\n};\n"],"names":["useSpreadCapability","useCapability","SpreadPlugin","id","provides","spreadMode","ref","SpreadMode","None","vue$1","watch","providesValue","_","onCleanup","value","getSpreadMode","onSpreadChange","newSpreadMode","immediate","usePlugin"],"mappings":"4KAKaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,sBAEzD,KACjB,MAAAC,SAAEA,GAAaJ,IACfK,EAAaC,EAAAA,IAAgBC,EAAAA,WAAWC,MAoBvC,OAlBPC,EAAAC,MACEN,GACA,CAACO,EAAeC,EAAGC,KACjB,GAAIF,EAAe,CAENN,EAAAS,MAAQH,EAAcI,gBAOjCF,EAJoBF,EAAcK,gBAAgBC,IAChDZ,EAAWS,MAAQG,CAAA,IAGA,IAGzB,CAAEC,WAAW,IAGR,CACLd,WACAC,aACF,wDA5B6B,IAAMc,YAAwBjB,EAAAA,aAAaC"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-spread.ts"],"sourcesContent":["import { ref, watch, computed, readonly, toValue, type MaybeRefOrGetter } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { SpreadMode, SpreadPlugin, initialDocumentState } from '@embedpdf/plugin-spread';\n\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\n/**\n * Hook for spread state for a specific document\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport const useSpread = (documentId: MaybeRefOrGetter<string>) => {\n const { provides } = useSpreadCapability();\n const spreadMode = ref<SpreadMode>(initialDocumentState.spreadMode);\n\n watch(\n [provides, () => toValue(documentId)],\n ([providesValue, docId], _, onCleanup) => {\n if (!providesValue) {\n spreadMode.value = initialDocumentState.spreadMode;\n return;\n }\n\n const scope = providesValue.forDocument(docId);\n\n // Set initial spread mode\n spreadMode.value = scope.getSpreadMode();\n\n // Subscribe to spread mode changes\n const unsubscribe = scope.onSpreadChange((newSpreadMode) => {\n spreadMode.value = newSpreadMode;\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n );\n\n // Return a computed ref for the scoped capability\n const scopedProvides = computed(() => {\n const docId = toValue(documentId);\n return provides.value?.forDocument(docId) ?? null;\n });\n\n return {\n provides: scopedProvides,\n spreadMode: readonly(spreadMode),\n };\n};\n"],"names":["useSpreadCapability","useCapability","SpreadPlugin","id","documentId","provides","spreadMode","ref","initialDocumentState","watch","toValue","providesValue","docId","_","onCleanup","value","scope","forDocument","getSpreadMode","onSpreadChange","newSpreadMode","immediate","computed","_a","readonly","usePlugin"],"mappings":"4KAKaA,EAAsB,IAAMC,gBAA4BC,EAAAA,aAAaC,sBAMxDC,IACxB,MAAMC,SAAEA,GAAaL,IACfM,EAAaC,EAAAA,IAAgBC,EAAAA,qBAAqBF,YAExDG,EAAAA,MACE,CAACJ,EAAU,IAAMK,UAAQN,IACzB,EAAEO,EAAeC,GAAQC,EAAGC,KAC1B,IAAKH,EAEH,YADAL,EAAWS,MAAQP,EAAAA,qBAAqBF,YAI1C,MAAMU,EAAQL,EAAcM,YAAYL,GAGxCN,EAAWS,MAAQC,EAAME,gBAOzBJ,EAJoBE,EAAMG,eAAgBC,IACxCd,EAAWS,MAAQK,MAKvB,CAAEC,WAAW,IASf,MAAO,CACLhB,SANqBiB,EAAAA,SAAS,WAC9B,MAAMV,EAAQF,EAAAA,QAAQN,GACtB,OAAO,OAAAmB,EAAAlB,EAASU,YAAT,EAAAQ,EAAgBN,YAAYL,KAAU,OAK7CN,WAAYkB,EAAAA,SAASlB,2DA1CM,IAAMmB,YAAwBvB,EAAAA,aAAaC"}
package/dist/vue/index.js CHANGED
@@ -1,28 +1,36 @@
1
- import { ref, watch } from "vue";
1
+ import { ref, watch, toValue, computed, readonly } from "vue";
2
2
  import { usePlugin, useCapability } from "@embedpdf/core/vue";
3
- import { SpreadPlugin, SpreadMode } from "@embedpdf/plugin-spread";
3
+ import { SpreadPlugin, initialDocumentState } from "@embedpdf/plugin-spread";
4
4
  export * from "@embedpdf/plugin-spread";
5
5
  const useSpreadPlugin = () => usePlugin(SpreadPlugin.id);
6
6
  const useSpreadCapability = () => useCapability(SpreadPlugin.id);
7
- const useSpread = () => {
7
+ const useSpread = (documentId) => {
8
8
  const { provides } = useSpreadCapability();
9
- const spreadMode = ref(SpreadMode.None);
9
+ const spreadMode = ref(initialDocumentState.spreadMode);
10
10
  watch(
11
- provides,
12
- (providesValue, _, onCleanup) => {
13
- if (providesValue) {
14
- spreadMode.value = providesValue.getSpreadMode();
15
- const unsubscribe = providesValue.onSpreadChange((newSpreadMode) => {
16
- spreadMode.value = newSpreadMode;
17
- });
18
- onCleanup(unsubscribe);
11
+ [provides, () => toValue(documentId)],
12
+ ([providesValue, docId], _, onCleanup) => {
13
+ if (!providesValue) {
14
+ spreadMode.value = initialDocumentState.spreadMode;
15
+ return;
19
16
  }
17
+ const scope = providesValue.forDocument(docId);
18
+ spreadMode.value = scope.getSpreadMode();
19
+ const unsubscribe = scope.onSpreadChange((newSpreadMode) => {
20
+ spreadMode.value = newSpreadMode;
21
+ });
22
+ onCleanup(unsubscribe);
20
23
  },
21
24
  { immediate: true }
22
25
  );
26
+ const scopedProvides = computed(() => {
27
+ var _a;
28
+ const docId = toValue(documentId);
29
+ return ((_a = provides.value) == null ? void 0 : _a.forDocument(docId)) ?? null;
30
+ });
23
31
  return {
24
- provides,
25
- spreadMode
32
+ provides: scopedProvides,
33
+ spreadMode: readonly(spreadMode)
26
34
  };
27
35
  };
28
36
  export {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-spread.ts"],"sourcesContent":["import { ref, watch } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { SpreadMode, SpreadPlugin } from '@embedpdf/plugin-spread';\n\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\nexport const useSpread = () => {\n const { provides } = useSpreadCapability();\n const spreadMode = ref<SpreadMode>(SpreadMode.None);\n\n watch(\n provides,\n (providesValue, _, onCleanup) => {\n if (providesValue) {\n // Set initial spread mode\n spreadMode.value = providesValue.getSpreadMode();\n\n // Subscribe to spread mode changes\n const unsubscribe = providesValue.onSpreadChange((newSpreadMode) => {\n spreadMode.value = newSpreadMode;\n });\n\n onCleanup(unsubscribe);\n }\n },\n { immediate: true },\n );\n\n return {\n provides,\n spreadMode,\n };\n};\n"],"names":[],"mappings":";;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAE7E,MAAM,YAAY,MAAM;AACvB,QAAA,EAAE,SAAS,IAAI,oBAAoB;AACnC,QAAA,aAAa,IAAgB,WAAW,IAAI;AAElD;AAAA,IACE;AAAA,IACA,CAAC,eAAe,GAAG,cAAc;AAC/B,UAAI,eAAe;AAEN,mBAAA,QAAQ,cAAc,cAAc;AAG/C,cAAM,cAAc,cAAc,eAAe,CAAC,kBAAkB;AAClE,qBAAW,QAAQ;AAAA,QAAA,CACpB;AAED,kBAAU,WAAW;AAAA,MAAA;AAAA,IAEzB;AAAA,IACA,EAAE,WAAW,KAAK;AAAA,EACpB;AAEO,SAAA;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-spread.ts"],"sourcesContent":["import { ref, watch, computed, readonly, toValue, type MaybeRefOrGetter } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { SpreadMode, SpreadPlugin, initialDocumentState } from '@embedpdf/plugin-spread';\n\nexport const useSpreadPlugin = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n\n/**\n * Hook for spread state for a specific document\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport const useSpread = (documentId: MaybeRefOrGetter<string>) => {\n const { provides } = useSpreadCapability();\n const spreadMode = ref<SpreadMode>(initialDocumentState.spreadMode);\n\n watch(\n [provides, () => toValue(documentId)],\n ([providesValue, docId], _, onCleanup) => {\n if (!providesValue) {\n spreadMode.value = initialDocumentState.spreadMode;\n return;\n }\n\n const scope = providesValue.forDocument(docId);\n\n // Set initial spread mode\n spreadMode.value = scope.getSpreadMode();\n\n // Subscribe to spread mode changes\n const unsubscribe = scope.onSpreadChange((newSpreadMode) => {\n spreadMode.value = newSpreadMode;\n });\n\n onCleanup(unsubscribe);\n },\n { immediate: true },\n );\n\n // Return a computed ref for the scoped capability\n const scopedProvides = computed(() => {\n const docId = toValue(documentId);\n return provides.value?.forDocument(docId) ?? null;\n });\n\n return {\n provides: scopedProvides,\n spreadMode: readonly(spreadMode),\n };\n};\n"],"names":[],"mappings":";;;;AAIO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AACrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAM7E,MAAM,YAAY,CAAC,eAAyC;AACjE,QAAM,EAAE,SAAA,IAAa,oBAAA;AACrB,QAAM,aAAa,IAAgB,qBAAqB,UAAU;AAElE;AAAA,IACE,CAAC,UAAU,MAAM,QAAQ,UAAU,CAAC;AAAA,IACpC,CAAC,CAAC,eAAe,KAAK,GAAG,GAAG,cAAc;AACxC,UAAI,CAAC,eAAe;AAClB,mBAAW,QAAQ,qBAAqB;AACxC;AAAA,MACF;AAEA,YAAM,QAAQ,cAAc,YAAY,KAAK;AAG7C,iBAAW,QAAQ,MAAM,cAAA;AAGzB,YAAM,cAAc,MAAM,eAAe,CAAC,kBAAkB;AAC1D,mBAAW,QAAQ;AAAA,MACrB,CAAC;AAED,gBAAU,WAAW;AAAA,IACvB;AAAA,IACA,EAAE,WAAW,KAAA;AAAA,EAAK;AAIpB,QAAM,iBAAiB,SAAS,MAAM;;AACpC,UAAM,QAAQ,QAAQ,UAAU;AAChC,aAAO,cAAS,UAAT,mBAAgB,YAAY,WAAU;AAAA,EAC/C,CAAC;AAED,SAAO;AAAA,IACL,UAAU;AAAA,IACV,YAAY,SAAS,UAAU;AAAA,EAAA;AAEnC;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-spread",
3
- "version": "1.4.1",
3
+ "version": "2.0.0-next.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",
@@ -34,14 +34,14 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@embedpdf/models": "1.4.1"
37
+ "@embedpdf/models": "2.0.0-next.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/react": "^18.2.0",
41
41
  "typescript": "^5.0.0",
42
- "@embedpdf/core": "1.4.1",
43
- "@embedpdf/build": "1.1.0",
44
- "@embedpdf/plugin-loader": "1.4.1"
42
+ "@embedpdf/plugin-viewport": "2.0.0-next.0",
43
+ "@embedpdf/core": "2.0.0-next.0",
44
+ "@embedpdf/build": "1.1.0"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "react": ">=16.8.0",
@@ -49,8 +49,7 @@
49
49
  "preact": "^10.26.4",
50
50
  "vue": ">=3.2.0",
51
51
  "svelte": ">=5 <6",
52
- "@embedpdf/core": "1.4.1",
53
- "@embedpdf/plugin-loader": "1.4.1"
52
+ "@embedpdf/core": "2.0.0-next.0"
54
53
  },
55
54
  "files": [
56
55
  "dist",