@embedpdf/plugin-rotate 1.0.18 → 1.0.20

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 t=require("@embedpdf/core"),e="rotate",o={id:e,name:"Rotate Plugin",version:"1.0.0",provides:["rotate"],requires:["loader"],optional:["spread"],defaultConfig:{enabled:!0}};const a=class extends t.BasePlugin{constructor(e,o,a){super(e,o),this.rotate$=t.createBehaviorEmitter(),this.resetReady();const r=a.defaultRotation??this.coreState.core.rotation;this.setRotation(r),this.markReady()}async initialize(t){}setRotation(e){if(!this.coreState.core.pages)throw new Error("Pages not loaded");this.dispatchCoreAction(t.setRotation(e))}rotateForward(){const t=(this.coreState.core.rotation+1)%4;this.setRotation(t)}rotateBackward(){const t=(this.coreState.core.rotation+3)%4;this.setRotation(t)}buildCapability(){return{onRotateChange:this.rotate$.on,setRotation:t=>this.setRotation(t),getRotation:()=>this.coreState.core.rotation,rotateForward:()=>this.rotateForward(),rotateBackward:()=>this.rotateBackward(),getMatrix:({w:t=0,h:e=0,asString:o=!0}={})=>function(t,e,o,a=!0){let r=1,i=0,s=0,n=1,c=0,d=0;switch(t){case 1:r=0,i=1,s=-1,n=0,c=o;break;case 2:r=-1,i=0,s=0,n=-1,c=e,d=o;break;case 3:r=0,i=-1,s=1,n=0,d=e}return a?`matrix(${r},${i},${s},${n},${c},${d})`:[r,i,s,n,c,d]}(this.coreState.core.rotation,t,e,o)}}async destroy(){this.rotate$.clear(),super.destroy()}};a.id="rotate";let r=a;const i={manifest:o,create:(t,o,a)=>new r(e,t,a),reducer:()=>{},initialState:{}};exports.ROTATE_PLUGIN_ID=e,exports.RotatePlugin=r,exports.RotatePluginPackage=i,exports.manifest=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@embedpdf/core"),e="rotate",o={id:e,name:"Rotate Plugin",version:"1.0.0",provides:["rotate"],requires:["loader"],optional:["spread"],defaultConfig:{enabled:!0}};const a=class extends t.BasePlugin{constructor(e,o,a){super(e,o),this.rotate$=t.createBehaviorEmitter(),this.resetReady();const r=a.defaultRotation??this.coreState.core.rotation;this.setRotation(r),this.markReady()}async initialize(t){}setRotation(e){if(!this.coreState.core.pages)throw new Error("Pages not loaded");this.dispatchCoreAction(t.setRotation(e))}rotateForward(){const t=(this.coreState.core.rotation+1)%4;this.setRotation(t)}rotateBackward(){const t=(this.coreState.core.rotation+3)%4;this.setRotation(t)}buildCapability(){return{onRotateChange:this.rotate$.on,setRotation:t=>this.setRotation(t),getRotation:()=>this.coreState.core.rotation,rotateForward:()=>this.rotateForward(),rotateBackward:()=>this.rotateBackward(),getMatrix:({w:t=0,h:e=0,asString:o=!0}={})=>function(t,e,o,a=!0){let r=1,i=0,s=0,n=1,c=0,d=0;switch(t){case 1:r=0,i=1,s=-1,n=0,c=o;break;case 2:r=-1,i=0,s=0,n=-1,c=e,d=o;break;case 3:r=0,i=-1,s=1,n=0,d=e}return a?`matrix(${r},${i},${s},${n},${c},${d})`:[r,i,s,n,c,d]}(this.coreState.core.rotation,t,e,o)}}async destroy(){this.rotate$.clear(),super.destroy()}};a.id="rotate";let r=a;const i={manifest:o,create:(t,o)=>new r(e,t,o),reducer:()=>{},initialState:{}};exports.ROTATE_PLUGIN_ID=e,exports.RotatePlugin=r,exports.RotatePluginPackage=i,exports.manifest=o;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/lib/manifest.ts","../src/lib/rotate-plugin.ts","../src/lib/utils.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { RotatePluginConfig } from './types';\n\nexport const ROTATE_PLUGIN_ID = 'rotate';\n\nexport const manifest: PluginManifest<RotatePluginConfig> = {\n id: ROTATE_PLUGIN_ID,\n name: 'Rotate Plugin',\n version: '1.0.0',\n provides: ['rotate'],\n requires: ['loader'],\n optional: ['spread'],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { BasePlugin, createBehaviorEmitter, PluginRegistry, setRotation } from '@embedpdf/core';\nimport { Rotation } from '@embedpdf/models';\nimport { RotateCapability, RotatePluginConfig } from './types';\nimport { rotationMatrix } from './utils';\n\nfunction getNextRotation(current: Rotation): Rotation {\n return ((current + 1) % 4) as Rotation;\n}\n\nfunction getPreviousRotation(current: Rotation): Rotation {\n return ((current + 3) % 4) as Rotation; // +3 is equivalent to -1 in modulo 4\n}\n\nexport class RotatePlugin extends BasePlugin<RotatePluginConfig, RotateCapability> {\n static readonly id = 'rotate' as const;\n private readonly rotate$ = createBehaviorEmitter<Rotation>();\n\n constructor(id: string, registry: PluginRegistry, cfg: RotatePluginConfig) {\n super(id, registry);\n this.resetReady();\n const rotation = cfg.defaultRotation ?? this.coreState.core.rotation;\n this.setRotation(rotation);\n this.markReady();\n }\n\n async initialize(_config: RotatePluginConfig): Promise<void> {}\n\n private setRotation(rotation: Rotation): void {\n const pages = this.coreState.core.pages;\n if (!pages) {\n throw new Error('Pages not loaded');\n }\n\n this.dispatchCoreAction(setRotation(rotation));\n }\n\n private rotateForward(): void {\n const rotation = getNextRotation(this.coreState.core.rotation);\n this.setRotation(rotation);\n }\n\n private rotateBackward(): void {\n const rotation = getPreviousRotation(this.coreState.core.rotation);\n this.setRotation(rotation);\n }\n\n protected buildCapability(): RotateCapability {\n return {\n onRotateChange: this.rotate$.on,\n setRotation: (rotation) => this.setRotation(rotation),\n getRotation: () => this.coreState.core.rotation,\n rotateForward: () => this.rotateForward(),\n rotateBackward: () => this.rotateBackward(),\n getMatrix: ({ w = 0, h = 0, asString = true } = {}) =>\n rotationMatrix(this.coreState.core.rotation, w, h, asString),\n };\n }\n\n async destroy(): Promise<void> {\n this.rotate$.clear();\n super.destroy();\n }\n}\n","import { Rotation } from '@embedpdf/models';\n\n/**\n * Returns the 6-tuple you can drop straight into\n * `matrix(a,b,c,d,e,f)` or a ready-made CSS string.\n * Rotation is clockwise, origin = top-left (0 0).\n *\n * ── Note on e,f ───────────────────────────────\n * For 0°/180° no translation is needed.\n * For 90°/270° you may want to pass the page\n * height / width so the page stays in positive\n * coordinates. Keep them 0 and handle layout\n * elsewhere if that’s what you do today.\n */\nexport function rotationMatrix(\n rotation: Rotation,\n w: number,\n h: number,\n asString = true,\n): [number, number, number, number, number, number] | string {\n let a = 1,\n b = 0,\n c = 0,\n d = 1,\n e = 0,\n f = 0;\n\n switch (rotation) {\n case 1: // 90°\n a = 0;\n b = 1;\n c = -1;\n d = 0;\n e = h;\n break;\n case 2: // 180°\n a = -1;\n b = 0;\n c = 0;\n d = -1;\n e = w;\n f = h;\n break;\n case 3: // 270°\n a = 0;\n b = -1;\n c = 1;\n d = 0;\n f = w;\n break;\n }\n return asString ? `matrix(${a},${b},${c},${d},${e},${f})` : [a, b, c, d, e, f];\n}\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, ROTATE_PLUGIN_ID } from './manifest';\nimport { RotatePluginConfig } from './types';\nimport { RotatePlugin } from './rotate-plugin';\n\nexport const RotatePluginPackage: PluginPackage<RotatePlugin, RotatePluginConfig> = {\n manifest,\n create: (registry, _engine, config) => new RotatePlugin(ROTATE_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './rotate-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["ROTATE_PLUGIN_ID","manifest","id","name","version","provides","requires","optional","defaultConfig","enabled","_RotatePlugin","BasePlugin","constructor","registry","cfg","super","this","rotate$","createBehaviorEmitter","resetReady","rotation","defaultRotation","coreState","core","setRotation","markReady","initialize","_config","pages","Error","dispatchCoreAction","rotateForward","rotateBackward","buildCapability","onRotateChange","on","getRotation","getMatrix","w","h","asString","a","b","c","d","e","f","rotationMatrix","destroy","clear","RotatePlugin","RotatePluginPackage","create","_engine","config","reducer","initialState"],"mappings":"kHAGaA,EAAmB,SAEnBC,EA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CE,GAAA,EACAC,EAAA,EACAC,EAAA,EACAC,GAAA,EACAC,EAAAP,EACAQ,EAAAP,EACJ,MACF,KAAK,EACCE,EAAA,EACAC,GAAA,EACAC,EAAA,EACAC,EAAA,EACAE,EAAAR,EAGD,OAAAE,EAAW,UAAUC,KAAKC,KAAKC,KAAKC,KAAKC,KAAKC,KAAO,CAACL,EAAGC,EAAGC,EAAGC,EAAGC,EAAGC,EAC9E,CDEQC,CAAe/B,KAAKM,UAAUC,KAAKH,SAAUkB,EAAGC,EAAGC,GACvD,CAGF,aAAMQ,GACJhC,KAAKC,QAAQgC,QACblC,MAAMiC,SAAQ,GA9ChBtC,EAAgBR,GAAK,SADhB,IAAMgD,EAANxC,EERA,MAAMyC,EAAuE,CAClFlD,WACAmD,OAAQ,CAACvC,EAAUwC,EAASC,IAAW,IAAIJ,EAAalD,EAAkBa,EAAUyC,GACpFC,QAAS,OACTC,aAAc,CAAA"}
1
+ {"version":3,"file":"index.cjs","sources":["../src/lib/manifest.ts","../src/lib/rotate-plugin.ts","../src/lib/utils.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { RotatePluginConfig } from './types';\n\nexport const ROTATE_PLUGIN_ID = 'rotate';\n\nexport const manifest: PluginManifest<RotatePluginConfig> = {\n id: ROTATE_PLUGIN_ID,\n name: 'Rotate Plugin',\n version: '1.0.0',\n provides: ['rotate'],\n requires: ['loader'],\n optional: ['spread'],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { BasePlugin, createBehaviorEmitter, PluginRegistry, setRotation } from '@embedpdf/core';\nimport { Rotation } from '@embedpdf/models';\nimport { RotateCapability, RotatePluginConfig } from './types';\nimport { rotationMatrix } from './utils';\n\nfunction getNextRotation(current: Rotation): Rotation {\n return ((current + 1) % 4) as Rotation;\n}\n\nfunction getPreviousRotation(current: Rotation): Rotation {\n return ((current + 3) % 4) as Rotation; // +3 is equivalent to -1 in modulo 4\n}\n\nexport class RotatePlugin extends BasePlugin<RotatePluginConfig, RotateCapability> {\n static readonly id = 'rotate' as const;\n private readonly rotate$ = createBehaviorEmitter<Rotation>();\n\n constructor(id: string, registry: PluginRegistry, cfg: RotatePluginConfig) {\n super(id, registry);\n this.resetReady();\n const rotation = cfg.defaultRotation ?? this.coreState.core.rotation;\n this.setRotation(rotation);\n this.markReady();\n }\n\n async initialize(_config: RotatePluginConfig): Promise<void> {}\n\n private setRotation(rotation: Rotation): void {\n const pages = this.coreState.core.pages;\n if (!pages) {\n throw new Error('Pages not loaded');\n }\n\n this.dispatchCoreAction(setRotation(rotation));\n }\n\n private rotateForward(): void {\n const rotation = getNextRotation(this.coreState.core.rotation);\n this.setRotation(rotation);\n }\n\n private rotateBackward(): void {\n const rotation = getPreviousRotation(this.coreState.core.rotation);\n this.setRotation(rotation);\n }\n\n protected buildCapability(): RotateCapability {\n return {\n onRotateChange: this.rotate$.on,\n setRotation: (rotation) => this.setRotation(rotation),\n getRotation: () => this.coreState.core.rotation,\n rotateForward: () => this.rotateForward(),\n rotateBackward: () => this.rotateBackward(),\n getMatrix: ({ w = 0, h = 0, asString = true } = {}) =>\n rotationMatrix(this.coreState.core.rotation, w, h, asString),\n };\n }\n\n async destroy(): Promise<void> {\n this.rotate$.clear();\n super.destroy();\n }\n}\n","import { Rotation } from '@embedpdf/models';\n\n/**\n * Returns the 6-tuple you can drop straight into\n * `matrix(a,b,c,d,e,f)` or a ready-made CSS string.\n * Rotation is clockwise, origin = top-left (0 0).\n *\n * ── Note on e,f ───────────────────────────────\n * For 0°/180° no translation is needed.\n * For 90°/270° you may want to pass the page\n * height / width so the page stays in positive\n * coordinates. Keep them 0 and handle layout\n * elsewhere if that’s what you do today.\n */\nexport function rotationMatrix(\n rotation: Rotation,\n w: number,\n h: number,\n asString = true,\n): [number, number, number, number, number, number] | string {\n let a = 1,\n b = 0,\n c = 0,\n d = 1,\n e = 0,\n f = 0;\n\n switch (rotation) {\n case 1: // 90°\n a = 0;\n b = 1;\n c = -1;\n d = 0;\n e = h;\n break;\n case 2: // 180°\n a = -1;\n b = 0;\n c = 0;\n d = -1;\n e = w;\n f = h;\n break;\n case 3: // 270°\n a = 0;\n b = -1;\n c = 1;\n d = 0;\n f = w;\n break;\n }\n return asString ? `matrix(${a},${b},${c},${d},${e},${f})` : [a, b, c, d, e, f];\n}\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, ROTATE_PLUGIN_ID } from './manifest';\nimport { RotatePluginConfig } from './types';\nimport { RotatePlugin } from './rotate-plugin';\n\nexport const RotatePluginPackage: PluginPackage<RotatePlugin, RotatePluginConfig> = {\n manifest,\n create: (registry, config) => new RotatePlugin(ROTATE_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './rotate-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":["ROTATE_PLUGIN_ID","manifest","id","name","version","provides","requires","optional","defaultConfig","enabled","_RotatePlugin","BasePlugin","constructor","registry","cfg","super","this","rotate$","createBehaviorEmitter","resetReady","rotation","defaultRotation","coreState","core","setRotation","markReady","initialize","_config","pages","Error","dispatchCoreAction","rotateForward","rotateBackward","buildCapability","onRotateChange","on","getRotation","getMatrix","w","h","asString","a","b","c","d","e","f","rotationMatrix","destroy","clear","RotatePlugin","RotatePluginPackage","create","config","reducer","initialState"],"mappings":"kHAGaA,EAAmB,SAEnBC,EAA+C,CAC1DC,GAAIF,EACJG,KAAM,gBACNC,QAAS,QACTC,SAAU,CAAC,UACXC,SAAU,CAAC,UACXC,SAAU,CAAC,UACXC,cAAe,CACbC,SAAS,ICAN,MAAMC,EAAN,cAA2BC,EAAAA,WAIhC,WAAAC,CAAYV,EAAYW,EAA0BC,GAChDC,MAAMb,EAAIW,GAHKG,KAAAC,QAAUC,0BAIzBF,KAAKG,aACL,MAAMC,EAAWN,EAAIO,iBAAmBL,KAAKM,UAAUC,KAAKH,SAC5DJ,KAAKQ,YAAYJ,GACjBJ,KAAKS,WAAU,CAGjB,gBAAMC,CAAWC,GAA4C,CAErD,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ChBtC,EAAgBR,GAAK,SADhB,IAAMgD,EAANxC,EERA,MAAMyC,EAAuE,CAClFlD,WACAmD,OAAQ,CAACvC,EAAUwC,IAAW,IAAIH,EAAalD,EAAkBa,EAAUwC,GAC3EC,QAAS,OACTC,aAAc,CAAA"}
package/dist/index.js CHANGED
@@ -90,7 +90,7 @@ _RotatePlugin.id = "rotate";
90
90
  let RotatePlugin = _RotatePlugin;
91
91
  const RotatePluginPackage = {
92
92
  manifest,
93
- create: (registry, _engine, config) => new RotatePlugin(ROTATE_PLUGIN_ID, registry, config),
93
+ create: (registry, config) => new RotatePlugin(ROTATE_PLUGIN_ID, registry, config),
94
94
  reducer: () => {
95
95
  },
96
96
  initialState: {}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/lib/manifest.ts","../src/lib/utils.ts","../src/lib/rotate-plugin.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { RotatePluginConfig } from './types';\n\nexport const ROTATE_PLUGIN_ID = 'rotate';\n\nexport const manifest: PluginManifest<RotatePluginConfig> = {\n id: ROTATE_PLUGIN_ID,\n name: 'Rotate Plugin',\n version: '1.0.0',\n provides: ['rotate'],\n requires: ['loader'],\n optional: ['spread'],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { Rotation } from '@embedpdf/models';\n\n/**\n * Returns the 6-tuple you can drop straight into\n * `matrix(a,b,c,d,e,f)` or a ready-made CSS string.\n * Rotation is clockwise, origin = top-left (0 0).\n *\n * ── Note on e,f ───────────────────────────────\n * For 0°/180° no translation is needed.\n * For 90°/270° you may want to pass the page\n * height / width so the page stays in positive\n * coordinates. Keep them 0 and handle layout\n * elsewhere if that’s what you do today.\n */\nexport function rotationMatrix(\n rotation: Rotation,\n w: number,\n h: number,\n asString = true,\n): [number, number, number, number, number, number] | string {\n let a = 1,\n b = 0,\n c = 0,\n d = 1,\n e = 0,\n f = 0;\n\n switch (rotation) {\n case 1: // 90°\n a = 0;\n b = 1;\n c = -1;\n d = 0;\n e = h;\n break;\n case 2: // 180°\n a = -1;\n b = 0;\n c = 0;\n d = -1;\n e = w;\n f = h;\n break;\n case 3: // 270°\n a = 0;\n b = -1;\n c = 1;\n d = 0;\n f = w;\n break;\n }\n return asString ? `matrix(${a},${b},${c},${d},${e},${f})` : [a, b, c, d, e, f];\n}\n","import { BasePlugin, createBehaviorEmitter, PluginRegistry, setRotation } from '@embedpdf/core';\nimport { Rotation } from '@embedpdf/models';\nimport { RotateCapability, RotatePluginConfig } from './types';\nimport { rotationMatrix } from './utils';\n\nfunction getNextRotation(current: Rotation): Rotation {\n return ((current + 1) % 4) as Rotation;\n}\n\nfunction getPreviousRotation(current: Rotation): Rotation {\n return ((current + 3) % 4) as Rotation; // +3 is equivalent to -1 in modulo 4\n}\n\nexport class RotatePlugin extends BasePlugin<RotatePluginConfig, RotateCapability> {\n static readonly id = 'rotate' as const;\n private readonly rotate$ = createBehaviorEmitter<Rotation>();\n\n constructor(id: string, registry: PluginRegistry, cfg: RotatePluginConfig) {\n super(id, registry);\n this.resetReady();\n const rotation = cfg.defaultRotation ?? this.coreState.core.rotation;\n this.setRotation(rotation);\n this.markReady();\n }\n\n async initialize(_config: RotatePluginConfig): Promise<void> {}\n\n private setRotation(rotation: Rotation): void {\n const pages = this.coreState.core.pages;\n if (!pages) {\n throw new Error('Pages not loaded');\n }\n\n this.dispatchCoreAction(setRotation(rotation));\n }\n\n private rotateForward(): void {\n const rotation = getNextRotation(this.coreState.core.rotation);\n this.setRotation(rotation);\n }\n\n private rotateBackward(): void {\n const rotation = getPreviousRotation(this.coreState.core.rotation);\n this.setRotation(rotation);\n }\n\n protected buildCapability(): RotateCapability {\n return {\n onRotateChange: this.rotate$.on,\n setRotation: (rotation) => this.setRotation(rotation),\n getRotation: () => this.coreState.core.rotation,\n rotateForward: () => this.rotateForward(),\n rotateBackward: () => this.rotateBackward(),\n getMatrix: ({ w = 0, h = 0, asString = true } = {}) =>\n rotationMatrix(this.coreState.core.rotation, w, h, asString),\n };\n }\n\n async destroy(): Promise<void> {\n this.rotate$.clear();\n super.destroy();\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, ROTATE_PLUGIN_ID } from './manifest';\nimport { RotatePluginConfig } from './types';\nimport { RotatePlugin } from './rotate-plugin';\n\nexport const RotatePluginPackage: PluginPackage<RotatePlugin, RotatePluginConfig> = {\n manifest,\n create: (registry, _engine, config) => new RotatePlugin(ROTATE_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './rotate-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":[],"mappings":";AAGO,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,QAAQ;AAAA,EACnB,eAAe;AAAA,IACb,SAAS;AAAA,EAAA;AAEb;ACDO,SAAS,eACd,UACA,GACA,GACA,WAAW,MACgD;AACvD,MAAA,IAAI,GACN,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI;AAEN,UAAQ,UAAU;AAAA,IAChB,KAAK;AACC,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACJ;AAAA,IACF,KAAK;AACC,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACJ;AAAA,IACF,KAAK;AACC,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACJ;AAAA,EAAA;AAEG,SAAA,WAAW,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAC/E;AC/CA,SAAS,gBAAgB,SAA6B;AACpD,UAAS,UAAU,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;AACnB,UAAM,QAAQ;AAAA,EAAA;AAElB;AAhDE,cAAgB,KAAK;AADhB,IAAM,eAAN;ACRA,MAAM,sBAAuE;AAAA,EAClF;AAAA,EACA,QAAQ,CAAC,UAAU,SAAS,WAAW,IAAI,aAAa,kBAAkB,UAAU,MAAM;AAAA,EAC1F,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,cAAc,CAAA;AAChB;"}
1
+ {"version":3,"file":"index.js","sources":["../src/lib/manifest.ts","../src/lib/utils.ts","../src/lib/rotate-plugin.ts","../src/lib/index.ts"],"sourcesContent":["import { PluginManifest } from '@embedpdf/core';\nimport { RotatePluginConfig } from './types';\n\nexport const ROTATE_PLUGIN_ID = 'rotate';\n\nexport const manifest: PluginManifest<RotatePluginConfig> = {\n id: ROTATE_PLUGIN_ID,\n name: 'Rotate Plugin',\n version: '1.0.0',\n provides: ['rotate'],\n requires: ['loader'],\n optional: ['spread'],\n defaultConfig: {\n enabled: true,\n },\n};\n","import { Rotation } from '@embedpdf/models';\n\n/**\n * Returns the 6-tuple you can drop straight into\n * `matrix(a,b,c,d,e,f)` or a ready-made CSS string.\n * Rotation is clockwise, origin = top-left (0 0).\n *\n * ── Note on e,f ───────────────────────────────\n * For 0°/180° no translation is needed.\n * For 90°/270° you may want to pass the page\n * height / width so the page stays in positive\n * coordinates. Keep them 0 and handle layout\n * elsewhere if that’s what you do today.\n */\nexport function rotationMatrix(\n rotation: Rotation,\n w: number,\n h: number,\n asString = true,\n): [number, number, number, number, number, number] | string {\n let a = 1,\n b = 0,\n c = 0,\n d = 1,\n e = 0,\n f = 0;\n\n switch (rotation) {\n case 1: // 90°\n a = 0;\n b = 1;\n c = -1;\n d = 0;\n e = h;\n break;\n case 2: // 180°\n a = -1;\n b = 0;\n c = 0;\n d = -1;\n e = w;\n f = h;\n break;\n case 3: // 270°\n a = 0;\n b = -1;\n c = 1;\n d = 0;\n f = w;\n break;\n }\n return asString ? `matrix(${a},${b},${c},${d},${e},${f})` : [a, b, c, d, e, f];\n}\n","import { BasePlugin, createBehaviorEmitter, PluginRegistry, setRotation } from '@embedpdf/core';\nimport { Rotation } from '@embedpdf/models';\nimport { RotateCapability, RotatePluginConfig } from './types';\nimport { rotationMatrix } from './utils';\n\nfunction getNextRotation(current: Rotation): Rotation {\n return ((current + 1) % 4) as Rotation;\n}\n\nfunction getPreviousRotation(current: Rotation): Rotation {\n return ((current + 3) % 4) as Rotation; // +3 is equivalent to -1 in modulo 4\n}\n\nexport class RotatePlugin extends BasePlugin<RotatePluginConfig, RotateCapability> {\n static readonly id = 'rotate' as const;\n private readonly rotate$ = createBehaviorEmitter<Rotation>();\n\n constructor(id: string, registry: PluginRegistry, cfg: RotatePluginConfig) {\n super(id, registry);\n this.resetReady();\n const rotation = cfg.defaultRotation ?? this.coreState.core.rotation;\n this.setRotation(rotation);\n this.markReady();\n }\n\n async initialize(_config: RotatePluginConfig): Promise<void> {}\n\n private setRotation(rotation: Rotation): void {\n const pages = this.coreState.core.pages;\n if (!pages) {\n throw new Error('Pages not loaded');\n }\n\n this.dispatchCoreAction(setRotation(rotation));\n }\n\n private rotateForward(): void {\n const rotation = getNextRotation(this.coreState.core.rotation);\n this.setRotation(rotation);\n }\n\n private rotateBackward(): void {\n const rotation = getPreviousRotation(this.coreState.core.rotation);\n this.setRotation(rotation);\n }\n\n protected buildCapability(): RotateCapability {\n return {\n onRotateChange: this.rotate$.on,\n setRotation: (rotation) => this.setRotation(rotation),\n getRotation: () => this.coreState.core.rotation,\n rotateForward: () => this.rotateForward(),\n rotateBackward: () => this.rotateBackward(),\n getMatrix: ({ w = 0, h = 0, asString = true } = {}) =>\n rotationMatrix(this.coreState.core.rotation, w, h, asString),\n };\n }\n\n async destroy(): Promise<void> {\n this.rotate$.clear();\n super.destroy();\n }\n}\n","import { PluginPackage } from '@embedpdf/core';\nimport { manifest, ROTATE_PLUGIN_ID } from './manifest';\nimport { RotatePluginConfig } from './types';\nimport { RotatePlugin } from './rotate-plugin';\n\nexport const RotatePluginPackage: PluginPackage<RotatePlugin, RotatePluginConfig> = {\n manifest,\n create: (registry, config) => new RotatePlugin(ROTATE_PLUGIN_ID, registry, config),\n reducer: () => {},\n initialState: {},\n};\n\nexport * from './rotate-plugin';\nexport * from './types';\nexport * from './manifest';\n"],"names":[],"mappings":";AAGO,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,QAAQ;AAAA,EACnB,eAAe;AAAA,IACb,SAAS;AAAA,EAAA;AAEb;ACDO,SAAS,eACd,UACA,GACA,GACA,WAAW,MACgD;AACvD,MAAA,IAAI,GACN,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI;AAEN,UAAQ,UAAU;AAAA,IAChB,KAAK;AACC,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACJ;AAAA,IACF,KAAK;AACC,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACJ;AAAA,IACF,KAAK;AACC,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACJ;AAAA,EAAA;AAEG,SAAA,WAAW,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAC/E;AC/CA,SAAS,gBAAgB,SAA6B;AACpD,UAAS,UAAU,KAAK;AAC1B;AAEA,SAAS,oBAAoB,SAA6B;AACxD,UAAS,UAAU,KAAK;AAC1B;AAEO,MAAM,gBAAN,MAAM,sBAAqB,WAAiD;AAAA,EAIjF,YAAY,IAAY,UAA0B,KAAyB;AACzE,UAAM,IAAI,QAAQ;AAHpB,SAAiB,UAAU,sBAAgC;AAIzD,SAAK,WAA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B,cAAc,CAAA;AAChB;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-rotate",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -28,20 +28,20 @@
28
28
  }
29
29
  },
30
30
  "dependencies": {
31
- "@embedpdf/models": "1.0.18"
31
+ "@embedpdf/models": "1.0.20"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/react": "^18.2.0",
35
35
  "typescript": "^5.0.0",
36
36
  "@embedpdf/build": "1.0.0",
37
- "@embedpdf/core": "1.0.18"
37
+ "@embedpdf/core": "1.0.20"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "preact": "^10.26.4",
41
41
  "react": ">=16.8.0",
42
42
  "react-dom": ">=16.8.0",
43
43
  "vue": ">=3.2.0",
44
- "@embedpdf/core": "1.0.18"
44
+ "@embedpdf/core": "1.0.20"
45
45
  },
46
46
  "files": [
47
47
  "dist",