@embedpdf/plugin-spread 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 CloudPDF
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ SPREAD_PLUGIN_ID: () => SPREAD_PLUGIN_ID,
24
+ SpreadMode: () => SpreadMode,
25
+ SpreadPlugin: () => SpreadPlugin,
26
+ SpreadPluginPackage: () => SpreadPluginPackage,
27
+ manifest: () => manifest
28
+ });
29
+ module.exports = __toCommonJS(index_exports);
30
+
31
+ // src/lib/spread-plugin.ts
32
+ var import_core = require("@embedpdf/core");
33
+
34
+ // src/lib/types.ts
35
+ var SpreadMode = /* @__PURE__ */ ((SpreadMode2) => {
36
+ SpreadMode2["None"] = "none";
37
+ SpreadMode2["Odd"] = "odd";
38
+ SpreadMode2["Even"] = "even";
39
+ return SpreadMode2;
40
+ })(SpreadMode || {});
41
+
42
+ // src/lib/actions.ts
43
+ var SET_SPREAD_MODE = "SET_SPREAD_MODE";
44
+ function setSpreadMode(mode) {
45
+ return {
46
+ type: SET_SPREAD_MODE,
47
+ payload: mode
48
+ };
49
+ }
50
+
51
+ // src/lib/spread-plugin.ts
52
+ var SpreadPlugin = class extends import_core.BasePlugin {
53
+ constructor(id, registry, cfg) {
54
+ super(id, registry);
55
+ this.spreadEmitter$ = (0, import_core.createEmitter)();
56
+ this.resetReady();
57
+ this.dispatch(setSpreadMode(cfg.defaultSpreadMode ?? "none" /* None */));
58
+ const loaderPlugin = registry.getPlugin("loader");
59
+ loaderPlugin.provides().onDocumentLoaded((document) => this.documentLoaded(document));
60
+ }
61
+ async initialize(config) {
62
+ if (config.defaultSpreadMode) {
63
+ this.dispatch(setSpreadMode(config.defaultSpreadMode));
64
+ }
65
+ }
66
+ documentLoaded(document) {
67
+ this.dispatchCoreAction((0, import_core.setPages)(this.getSpreadPagesObjects(document.pages)));
68
+ this.markReady();
69
+ }
70
+ getSpreadPagesObjects(pages) {
71
+ if (!pages.length) return [];
72
+ switch (this.state.spreadMode) {
73
+ case "none" /* None */:
74
+ return pages.map((page) => [page]);
75
+ case "odd" /* Odd */:
76
+ return Array.from(
77
+ { length: Math.ceil(pages.length / 2) },
78
+ (_, i) => pages.slice(i * 2, i * 2 + 2)
79
+ );
80
+ case "even" /* Even */:
81
+ return [
82
+ [pages[0]],
83
+ ...Array.from(
84
+ { length: Math.ceil((pages.length - 1) / 2) },
85
+ (_, i) => pages.slice(1 + i * 2, 1 + i * 2 + 2)
86
+ )
87
+ ];
88
+ default:
89
+ return pages.map((page) => [page]);
90
+ }
91
+ }
92
+ setSpreadMode(mode) {
93
+ const currentMode = this.state.spreadMode;
94
+ const document = this.coreState.core.document;
95
+ if (!document) {
96
+ throw new Error("Document not loaded");
97
+ }
98
+ if (currentMode !== mode) {
99
+ this.dispatch(setSpreadMode(mode));
100
+ this.dispatchCoreAction((0, import_core.setPages)(this.getSpreadPagesObjects(document.pages)));
101
+ this.notifySpreadChange(mode);
102
+ }
103
+ }
104
+ notifySpreadChange(spreadMode) {
105
+ this.spreadEmitter$.emit(spreadMode);
106
+ }
107
+ buildCapability() {
108
+ return {
109
+ onSpreadChange: this.spreadEmitter$.on,
110
+ setSpreadMode: (mode) => this.setSpreadMode(mode),
111
+ getSpreadMode: () => this.state.spreadMode,
112
+ getSpreadPagesObjects: (pages) => this.getSpreadPagesObjects(pages)
113
+ };
114
+ }
115
+ async destroy() {
116
+ this.spreadEmitter$.clear();
117
+ }
118
+ };
119
+ SpreadPlugin.id = "spread";
120
+
121
+ // src/lib/manifest.ts
122
+ var SPREAD_PLUGIN_ID = "spread";
123
+ var manifest = {
124
+ id: SPREAD_PLUGIN_ID,
125
+ name: "Spread Plugin",
126
+ version: "1.0.0",
127
+ provides: ["spread"],
128
+ requires: ["loader"],
129
+ optional: [],
130
+ defaultConfig: {
131
+ enabled: true
132
+ }
133
+ };
134
+
135
+ // src/lib/reducer.ts
136
+ var initialState = {
137
+ spreadMode: "none" /* None */
138
+ };
139
+ var spreadReducer = (state = initialState, action) => {
140
+ switch (action.type) {
141
+ case SET_SPREAD_MODE:
142
+ return {
143
+ ...state,
144
+ spreadMode: action.payload
145
+ };
146
+ default:
147
+ return state;
148
+ }
149
+ };
150
+
151
+ // src/lib/index.ts
152
+ var SpreadPluginPackage = {
153
+ manifest,
154
+ create: (registry, _engine, config) => new SpreadPlugin(SPREAD_PLUGIN_ID, registry, config),
155
+ reducer: spreadReducer,
156
+ initialState
157
+ };
158
+ // Annotate the CommonJS export names for ESM import in node:
159
+ 0 && (module.exports = {
160
+ SPREAD_PLUGIN_ID,
161
+ SpreadMode,
162
+ SpreadPlugin,
163
+ SpreadPluginPackage,
164
+ manifest
165
+ });
166
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/lib/spread-plugin.ts","../src/lib/types.ts","../src/lib/actions.ts","../src/lib/manifest.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["export * from './lib';\n","import { BasePlugin, createEmitter, PluginRegistry, setPages } 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$ = createEmitter<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 getSpreadPagesObjects: (pages) => this.getSpreadPagesObjects(pages),\n };\n }\n\n async destroy(): Promise<void> {\n this.spreadEmitter$.clear();\n }\n}\n","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\nexport interface SpreadCapability {\n onSpreadChange: EventHook<SpreadMode>;\n setSpreadMode(mode: SpreadMode): void;\n getSpreadMode(): SpreadMode;\n getSpreadPagesObjects(pages: PdfPageObject[]): PdfPageObject[][];\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 { 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, _engine, 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"],"mappings":"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","names":["SpreadMode"]}
@@ -0,0 +1,47 @@
1
+ import { BasePluginConfig, EventHook, BasePlugin, PluginRegistry, PluginManifest, PluginPackage } from '@embedpdf/core';
2
+ import { PdfPageObject } from '@embedpdf/models';
3
+
4
+ interface SpreadPluginConfig extends BasePluginConfig {
5
+ defaultSpreadMode?: SpreadMode;
6
+ }
7
+ declare enum SpreadMode {
8
+ None = "none",
9
+ Odd = "odd",
10
+ Even = "even"
11
+ }
12
+ interface SpreadCapability {
13
+ onSpreadChange: EventHook<SpreadMode>;
14
+ setSpreadMode(mode: SpreadMode): void;
15
+ getSpreadMode(): SpreadMode;
16
+ getSpreadPagesObjects(pages: PdfPageObject[]): PdfPageObject[][];
17
+ }
18
+ interface SpreadState {
19
+ spreadMode: SpreadMode;
20
+ }
21
+
22
+ declare const SET_SPREAD_MODE = "SET_SPREAD_MODE";
23
+ interface SetSpreadModeAction {
24
+ type: typeof SET_SPREAD_MODE;
25
+ payload: SpreadMode;
26
+ }
27
+ type SpreadAction = SetSpreadModeAction;
28
+
29
+ declare class SpreadPlugin extends BasePlugin<SpreadPluginConfig, SpreadCapability, SpreadState, SpreadAction> {
30
+ static readonly id: "spread";
31
+ private readonly spreadEmitter$;
32
+ constructor(id: string, registry: PluginRegistry, cfg: SpreadPluginConfig);
33
+ initialize(config: SpreadPluginConfig): Promise<void>;
34
+ private documentLoaded;
35
+ getSpreadPagesObjects(pages: PdfPageObject[]): PdfPageObject[][];
36
+ setSpreadMode(mode: SpreadMode): void;
37
+ private notifySpreadChange;
38
+ protected buildCapability(): SpreadCapability;
39
+ destroy(): Promise<void>;
40
+ }
41
+
42
+ declare const SPREAD_PLUGIN_ID = "spread";
43
+ declare const manifest: PluginManifest<SpreadPluginConfig>;
44
+
45
+ declare const SpreadPluginPackage: PluginPackage<SpreadPlugin, SpreadPluginConfig, SpreadState, SpreadAction>;
46
+
47
+ export { SPREAD_PLUGIN_ID, type SpreadCapability, SpreadMode, SpreadPlugin, type SpreadPluginConfig, SpreadPluginPackage, type SpreadState, manifest };
@@ -0,0 +1,47 @@
1
+ import { BasePluginConfig, EventHook, BasePlugin, PluginRegistry, PluginManifest, PluginPackage } from '@embedpdf/core';
2
+ import { PdfPageObject } from '@embedpdf/models';
3
+
4
+ interface SpreadPluginConfig extends BasePluginConfig {
5
+ defaultSpreadMode?: SpreadMode;
6
+ }
7
+ declare enum SpreadMode {
8
+ None = "none",
9
+ Odd = "odd",
10
+ Even = "even"
11
+ }
12
+ interface SpreadCapability {
13
+ onSpreadChange: EventHook<SpreadMode>;
14
+ setSpreadMode(mode: SpreadMode): void;
15
+ getSpreadMode(): SpreadMode;
16
+ getSpreadPagesObjects(pages: PdfPageObject[]): PdfPageObject[][];
17
+ }
18
+ interface SpreadState {
19
+ spreadMode: SpreadMode;
20
+ }
21
+
22
+ declare const SET_SPREAD_MODE = "SET_SPREAD_MODE";
23
+ interface SetSpreadModeAction {
24
+ type: typeof SET_SPREAD_MODE;
25
+ payload: SpreadMode;
26
+ }
27
+ type SpreadAction = SetSpreadModeAction;
28
+
29
+ declare class SpreadPlugin extends BasePlugin<SpreadPluginConfig, SpreadCapability, SpreadState, SpreadAction> {
30
+ static readonly id: "spread";
31
+ private readonly spreadEmitter$;
32
+ constructor(id: string, registry: PluginRegistry, cfg: SpreadPluginConfig);
33
+ initialize(config: SpreadPluginConfig): Promise<void>;
34
+ private documentLoaded;
35
+ getSpreadPagesObjects(pages: PdfPageObject[]): PdfPageObject[][];
36
+ setSpreadMode(mode: SpreadMode): void;
37
+ private notifySpreadChange;
38
+ protected buildCapability(): SpreadCapability;
39
+ destroy(): Promise<void>;
40
+ }
41
+
42
+ declare const SPREAD_PLUGIN_ID = "spread";
43
+ declare const manifest: PluginManifest<SpreadPluginConfig>;
44
+
45
+ declare const SpreadPluginPackage: PluginPackage<SpreadPlugin, SpreadPluginConfig, SpreadState, SpreadAction>;
46
+
47
+ export { SPREAD_PLUGIN_ID, type SpreadCapability, SpreadMode, SpreadPlugin, type SpreadPluginConfig, SpreadPluginPackage, type SpreadState, manifest };
package/dist/index.js ADDED
@@ -0,0 +1,135 @@
1
+ // src/lib/spread-plugin.ts
2
+ import { BasePlugin, createEmitter, setPages } from "@embedpdf/core";
3
+
4
+ // src/lib/types.ts
5
+ var SpreadMode = /* @__PURE__ */ ((SpreadMode2) => {
6
+ SpreadMode2["None"] = "none";
7
+ SpreadMode2["Odd"] = "odd";
8
+ SpreadMode2["Even"] = "even";
9
+ return SpreadMode2;
10
+ })(SpreadMode || {});
11
+
12
+ // src/lib/actions.ts
13
+ var SET_SPREAD_MODE = "SET_SPREAD_MODE";
14
+ function setSpreadMode(mode) {
15
+ return {
16
+ type: SET_SPREAD_MODE,
17
+ payload: mode
18
+ };
19
+ }
20
+
21
+ // src/lib/spread-plugin.ts
22
+ var SpreadPlugin = class extends BasePlugin {
23
+ constructor(id, registry, cfg) {
24
+ super(id, registry);
25
+ this.spreadEmitter$ = createEmitter();
26
+ this.resetReady();
27
+ this.dispatch(setSpreadMode(cfg.defaultSpreadMode ?? "none" /* None */));
28
+ const loaderPlugin = registry.getPlugin("loader");
29
+ loaderPlugin.provides().onDocumentLoaded((document) => this.documentLoaded(document));
30
+ }
31
+ async initialize(config) {
32
+ if (config.defaultSpreadMode) {
33
+ this.dispatch(setSpreadMode(config.defaultSpreadMode));
34
+ }
35
+ }
36
+ documentLoaded(document) {
37
+ this.dispatchCoreAction(setPages(this.getSpreadPagesObjects(document.pages)));
38
+ this.markReady();
39
+ }
40
+ getSpreadPagesObjects(pages) {
41
+ if (!pages.length) return [];
42
+ switch (this.state.spreadMode) {
43
+ case "none" /* None */:
44
+ return pages.map((page) => [page]);
45
+ case "odd" /* Odd */:
46
+ return Array.from(
47
+ { length: Math.ceil(pages.length / 2) },
48
+ (_, i) => pages.slice(i * 2, i * 2 + 2)
49
+ );
50
+ case "even" /* Even */:
51
+ return [
52
+ [pages[0]],
53
+ ...Array.from(
54
+ { length: Math.ceil((pages.length - 1) / 2) },
55
+ (_, i) => pages.slice(1 + i * 2, 1 + i * 2 + 2)
56
+ )
57
+ ];
58
+ default:
59
+ return pages.map((page) => [page]);
60
+ }
61
+ }
62
+ setSpreadMode(mode) {
63
+ const currentMode = this.state.spreadMode;
64
+ const document = this.coreState.core.document;
65
+ if (!document) {
66
+ throw new Error("Document not loaded");
67
+ }
68
+ if (currentMode !== mode) {
69
+ this.dispatch(setSpreadMode(mode));
70
+ this.dispatchCoreAction(setPages(this.getSpreadPagesObjects(document.pages)));
71
+ this.notifySpreadChange(mode);
72
+ }
73
+ }
74
+ notifySpreadChange(spreadMode) {
75
+ this.spreadEmitter$.emit(spreadMode);
76
+ }
77
+ buildCapability() {
78
+ return {
79
+ onSpreadChange: this.spreadEmitter$.on,
80
+ setSpreadMode: (mode) => this.setSpreadMode(mode),
81
+ getSpreadMode: () => this.state.spreadMode,
82
+ getSpreadPagesObjects: (pages) => this.getSpreadPagesObjects(pages)
83
+ };
84
+ }
85
+ async destroy() {
86
+ this.spreadEmitter$.clear();
87
+ }
88
+ };
89
+ SpreadPlugin.id = "spread";
90
+
91
+ // src/lib/manifest.ts
92
+ var SPREAD_PLUGIN_ID = "spread";
93
+ var manifest = {
94
+ id: SPREAD_PLUGIN_ID,
95
+ name: "Spread Plugin",
96
+ version: "1.0.0",
97
+ provides: ["spread"],
98
+ requires: ["loader"],
99
+ optional: [],
100
+ defaultConfig: {
101
+ enabled: true
102
+ }
103
+ };
104
+
105
+ // src/lib/reducer.ts
106
+ var initialState = {
107
+ spreadMode: "none" /* None */
108
+ };
109
+ var spreadReducer = (state = initialState, action) => {
110
+ switch (action.type) {
111
+ case SET_SPREAD_MODE:
112
+ return {
113
+ ...state,
114
+ spreadMode: action.payload
115
+ };
116
+ default:
117
+ return state;
118
+ }
119
+ };
120
+
121
+ // src/lib/index.ts
122
+ var SpreadPluginPackage = {
123
+ manifest,
124
+ create: (registry, _engine, config) => new SpreadPlugin(SPREAD_PLUGIN_ID, registry, config),
125
+ reducer: spreadReducer,
126
+ initialState
127
+ };
128
+ export {
129
+ SPREAD_PLUGIN_ID,
130
+ SpreadMode,
131
+ SpreadPlugin,
132
+ SpreadPluginPackage,
133
+ manifest
134
+ };
135
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/lib/spread-plugin.ts","../src/lib/types.ts","../src/lib/actions.ts","../src/lib/manifest.ts","../src/lib/reducer.ts","../src/lib/index.ts"],"sourcesContent":["import { BasePlugin, createEmitter, PluginRegistry, setPages } 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$ = createEmitter<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 getSpreadPagesObjects: (pages) => this.getSpreadPagesObjects(pages),\n };\n }\n\n async destroy(): Promise<void> {\n this.spreadEmitter$.clear();\n }\n}\n","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\nexport interface SpreadCapability {\n onSpreadChange: EventHook<SpreadMode>;\n setSpreadMode(mode: SpreadMode): void;\n getSpreadMode(): SpreadMode;\n getSpreadPagesObjects(pages: PdfPageObject[]): PdfPageObject[][];\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 { 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, _engine, 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"],"mappings":"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","names":["SpreadMode"]}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/preact/index.ts
21
+ var preact_exports = {};
22
+ __export(preact_exports, {
23
+ useSpread: () => useSpread,
24
+ useSpreadCapability: () => useSpreadCapability
25
+ });
26
+ module.exports = __toCommonJS(preact_exports);
27
+
28
+ // src/preact/hooks/use-spread.ts
29
+ var import_preact = require("@embedpdf/core/preact");
30
+ var import_plugin_spread = require("@embedpdf/plugin-spread");
31
+ var useSpread = () => (0, import_preact.usePlugin)(import_plugin_spread.SpreadPlugin.id);
32
+ var useSpreadCapability = () => (0, import_preact.useCapability)(import_plugin_spread.SpreadPlugin.id);
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ useSpread,
36
+ useSpreadCapability
37
+ });
38
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/preact/index.ts","../../src/preact/hooks/use-spread.ts"],"sourcesContent":["export * from './hooks';\n","import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { SpreadPlugin } from '@embedpdf/plugin-spread';\n\nexport const useSpread = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAyC;AACzC,2BAA6B;AAEtB,IAAM,YAAY,UAAM,yBAAwB,kCAAa,EAAE;AAC/D,IAAM,sBAAsB,UAAM,6BAA4B,kCAAa,EAAE;","names":[]}
@@ -0,0 +1,15 @@
1
+ import * as _embedpdf_plugin_spread from '@embedpdf/plugin-spread';
2
+ import { SpreadPlugin } from '@embedpdf/plugin-spread';
3
+
4
+ declare const useSpread: () => {
5
+ plugin: SpreadPlugin | null;
6
+ isLoading: boolean;
7
+ ready: Promise<void>;
8
+ };
9
+ declare const useSpreadCapability: () => {
10
+ provides: Readonly<_embedpdf_plugin_spread.SpreadCapability> | null;
11
+ isLoading: boolean;
12
+ ready: Promise<void>;
13
+ };
14
+
15
+ export { useSpread, useSpreadCapability };
@@ -0,0 +1,15 @@
1
+ import * as _embedpdf_plugin_spread from '@embedpdf/plugin-spread';
2
+ import { SpreadPlugin } from '@embedpdf/plugin-spread';
3
+
4
+ declare const useSpread: () => {
5
+ plugin: SpreadPlugin | null;
6
+ isLoading: boolean;
7
+ ready: Promise<void>;
8
+ };
9
+ declare const useSpreadCapability: () => {
10
+ provides: Readonly<_embedpdf_plugin_spread.SpreadCapability> | null;
11
+ isLoading: boolean;
12
+ ready: Promise<void>;
13
+ };
14
+
15
+ export { useSpread, useSpreadCapability };
@@ -0,0 +1,10 @@
1
+ // src/preact/hooks/use-spread.ts
2
+ import { useCapability, usePlugin } from "@embedpdf/core/preact";
3
+ import { SpreadPlugin } from "@embedpdf/plugin-spread";
4
+ var useSpread = () => usePlugin(SpreadPlugin.id);
5
+ var useSpreadCapability = () => useCapability(SpreadPlugin.id);
6
+ export {
7
+ useSpread,
8
+ useSpreadCapability
9
+ };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/preact/hooks/use-spread.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/preact';\nimport { SpreadPlugin } from '@embedpdf/plugin-spread';\n\nexport const useSpread = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,oBAAoB;AAEtB,IAAM,YAAY,MAAM,UAAwB,aAAa,EAAE;AAC/D,IAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;","names":[]}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/react/index.ts
21
+ var react_exports = {};
22
+ __export(react_exports, {
23
+ useSpread: () => useSpread,
24
+ useSpreadCapability: () => useSpreadCapability
25
+ });
26
+ module.exports = __toCommonJS(react_exports);
27
+
28
+ // src/react/hooks/use-spread.ts
29
+ var import_react = require("@embedpdf/core/react");
30
+ var import_plugin_spread = require("@embedpdf/plugin-spread");
31
+ var useSpread = () => (0, import_react.usePlugin)(import_plugin_spread.SpreadPlugin.id);
32
+ var useSpreadCapability = () => (0, import_react.useCapability)(import_plugin_spread.SpreadPlugin.id);
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ useSpread,
36
+ useSpreadCapability
37
+ });
38
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/react/index.ts","../../src/react/hooks/use-spread.ts"],"sourcesContent":["export * from './hooks';\n","import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { SpreadPlugin } from '@embedpdf/plugin-spread';\n\nexport const useSpread = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAyC;AACzC,2BAA6B;AAEtB,IAAM,YAAY,UAAM,wBAAwB,kCAAa,EAAE;AAC/D,IAAM,sBAAsB,UAAM,4BAA4B,kCAAa,EAAE;","names":[]}
@@ -0,0 +1,15 @@
1
+ import * as _embedpdf_plugin_spread from '@embedpdf/plugin-spread';
2
+ import { SpreadPlugin } from '@embedpdf/plugin-spread';
3
+
4
+ declare const useSpread: () => {
5
+ plugin: SpreadPlugin | null;
6
+ isLoading: boolean;
7
+ ready: Promise<void>;
8
+ };
9
+ declare const useSpreadCapability: () => {
10
+ provides: Readonly<_embedpdf_plugin_spread.SpreadCapability> | null;
11
+ isLoading: boolean;
12
+ ready: Promise<void>;
13
+ };
14
+
15
+ export { useSpread, useSpreadCapability };
@@ -0,0 +1,15 @@
1
+ import * as _embedpdf_plugin_spread from '@embedpdf/plugin-spread';
2
+ import { SpreadPlugin } from '@embedpdf/plugin-spread';
3
+
4
+ declare const useSpread: () => {
5
+ plugin: SpreadPlugin | null;
6
+ isLoading: boolean;
7
+ ready: Promise<void>;
8
+ };
9
+ declare const useSpreadCapability: () => {
10
+ provides: Readonly<_embedpdf_plugin_spread.SpreadCapability> | null;
11
+ isLoading: boolean;
12
+ ready: Promise<void>;
13
+ };
14
+
15
+ export { useSpread, useSpreadCapability };
@@ -0,0 +1,10 @@
1
+ // src/react/hooks/use-spread.ts
2
+ import { useCapability, usePlugin } from "@embedpdf/core/react";
3
+ import { SpreadPlugin } from "@embedpdf/plugin-spread";
4
+ var useSpread = () => usePlugin(SpreadPlugin.id);
5
+ var useSpreadCapability = () => useCapability(SpreadPlugin.id);
6
+ export {
7
+ useSpread,
8
+ useSpreadCapability
9
+ };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/react/hooks/use-spread.ts"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/react';\nimport { SpreadPlugin } from '@embedpdf/plugin-spread';\n\nexport const useSpread = () => usePlugin<SpreadPlugin>(SpreadPlugin.id);\nexport const useSpreadCapability = () => useCapability<SpreadPlugin>(SpreadPlugin.id);\n"],"mappings":";AAAA,SAAS,eAAe,iBAAiB;AACzC,SAAS,oBAAoB;AAEtB,IAAM,YAAY,MAAM,UAAwB,aAAa,EAAE;AAC/D,IAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;","names":[]}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@embedpdf/plugin-spread",
3
+ "version": "1.0.0",
4
+ "type": "module",
5
+ "main": "./dist/index.cjs",
6
+ "module": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "require": "./dist/index.cjs"
13
+ },
14
+ "./preact": {
15
+ "types": "./dist/preact/index.d.ts",
16
+ "import": "./dist/preact/index.js",
17
+ "require": "./dist/preact/index.cjs"
18
+ },
19
+ "./react": {
20
+ "types": "./dist/react/index.d.ts",
21
+ "import": "./dist/react/index.js",
22
+ "require": "./dist/react/index.cjs"
23
+ }
24
+ },
25
+ "dependencies": {
26
+ "@embedpdf/models": "1.0.0",
27
+ "@embedpdf/plugin-loader": "1.0.0"
28
+ },
29
+ "devDependencies": {
30
+ "@types/react": "^18.2.0",
31
+ "tsup": "^8.0.0",
32
+ "typescript": "^5.0.0"
33
+ },
34
+ "peerDependencies": {
35
+ "react": ">=16.8.0",
36
+ "react-dom": ">=16.8.0",
37
+ "preact": "^10.26.4",
38
+ "@embedpdf/core": "1.0.0"
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "README.md"
43
+ ],
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "https://github.com/embedpdf/embed-pdf-viewer",
47
+ "directory": "packages/plugin-spread"
48
+ },
49
+ "homepage": "https://www.embedpdf.com/docs",
50
+ "bugs": {
51
+ "url": "https://github.com/embedpdf/embed-pdf-viewer/issues"
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "scripts": {
57
+ "build": "PROJECT_CWD=$(pwd) pnpm -w p:build",
58
+ "build:watch": "PROJECT_CWD=$(pwd) pnpm -w p:build:watch",
59
+ "clean": "PROJECT_CWD=$(pwd) pnpm -w p:clean",
60
+ "lint": "PROJECT_CWD=$(pwd) pnpm -w p:lint",
61
+ "lint:fix": "PROJECT_CWD=$(pwd) pnpm -w p:lint:fix",
62
+ "typecheck": "PROJECT_CWD=$(pwd) pnpm -w p:typecheck"
63
+ }
64
+ }