@embedpdf/plugin-rotate 2.4.0 → 2.5.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.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/preact"),t=require("@embedpdf/plugin-rotate");require("preact");const o=require("preact/hooks"),r=require("preact/jsx-runtime"),i=()=>e.usePlugin(t.RotatePlugin.id),n=()=>e.useCapability(t.RotatePlugin.id);exports.Rotate=function({children:t,documentId:o,pageIndex:n,rotation:u,scale:l,style:a,...s}){var d,c,p,g;const{plugin:v}=i(),f=e.useDocumentState(o),m=null==(c=null==(d=null==f?void 0:f.document)?void 0:d.pages)?void 0:c[n],h=(null==(p=null==m?void 0:m.size)?void 0:p.width)??0,x=(null==(g=null==m?void 0:m.size)?void 0:g.height)??0,b=u??(null==f?void 0:f.rotation)??0,y=l??(null==f?void 0:f.scale)??1,R=(null==v?void 0:v.getMatrixAsString({width:h*y,height:x*y,rotation:b}))??"matrix(1, 0, 0, 1, 0, 0)";return m?r.jsx("div",{...s,style:{position:"absolute",transformOrigin:"0 0",transform:R,...a},children:t}):null},exports.useRotate=e=>{const{provides:r}=n(),[i,u]=o.useState(t.initialDocumentState.rotation);return o.useEffect(()=>{if(!r)return;const t=r.forDocument(e);return u(t.getRotation()),t.onRotateChange(e=>{u(e)})},[r,e]),{rotation:i,provides:(null==r?void 0:r.forDocument(e))??null}},exports.useRotateCapability=n,exports.useRotatePlugin=i,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 t=require("@embedpdf/core/preact"),e=require("@embedpdf/plugin-rotate");require("preact");const o=require("preact/hooks"),i=require("preact/jsx-runtime"),r=()=>t.usePlugin(e.RotatePlugin.id),n=()=>t.useCapability(e.RotatePlugin.id);exports.Rotate=function({children:e,documentId:o,pageIndex:n,rotation:l,scale:u,style:a,...s}){var d,c,p,g;const{plugin:v}=r(),f=t.useDocumentState(o),m=null==(c=null==(d=null==f?void 0:f.document)?void 0:d.pages)?void 0:c[n],h=(null==(p=null==m?void 0:m.size)?void 0:p.width)??0,x=(null==(g=null==m?void 0:m.size)?void 0:g.height)??0,b=(null==m?void 0:m.rotation)??0,y=(null==f?void 0:f.rotation)??0,R=void 0!==l?l:(b+y)%4,P=u??(null==f?void 0:f.scale)??1,j=(null==v?void 0:v.getMatrixAsString({width:h*P,height:x*P,rotation:R}))??"matrix(1, 0, 0, 1, 0, 0)";return m?i.jsx("div",{...s,style:{position:"absolute",transformOrigin:"0 0",transform:j,...a},children:e}):null},exports.useRotate=t=>{const{provides:i}=n(),[r,l]=o.useState(e.initialDocumentState.rotation);return o.useEffect(()=>{if(!i)return;const e=i.forDocument(t);return l(e.getRotation()),e.onRotateChange(t=>{l(t)})},[i,t]),{rotation:r,provides:(null==i?void 0:i.forDocument(t))??null}},exports.useRotateCapability=n,exports.useRotatePlugin=r,Object.keys(e).forEach(t=>{"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:()=>e[t]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-rotate.ts","../../src/shared/components/rotate.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\nimport { initialDocumentState, RotatePlugin } from '@embedpdf/plugin-rotate';\nimport { useEffect, useState } from '@framework';\n\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook for rotation state for a specific document\n * @param documentId Document ID\n */\nexport const useRotate = (documentId: string) => {\n const { provides } = useRotateCapability();\n const [rotation, setRotation] = useState<Rotation>(initialDocumentState.rotation);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n\n // Get initial state\n setRotation(scope.getRotation());\n\n // Subscribe to rotation changes\n return scope.onRotateChange((newRotation) => {\n setRotation(newRotation);\n });\n }, [provides, documentId]);\n\n return {\n rotation,\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n","import { ReactNode, HTMLAttributes, CSSProperties } from '@framework';\nimport { useDocumentState } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\n\nimport { useRotatePlugin } from '../hooks';\n\ntype RotateProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n children: ReactNode;\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n style?: CSSProperties;\n};\n\nexport function Rotate({\n children,\n documentId,\n pageIndex,\n rotation: rotationOverride,\n scale: scaleOverride,\n style,\n ...props\n}: RotateProps) {\n const { plugin: rotatePlugin } = useRotatePlugin();\n const documentState = useDocumentState(documentId);\n\n const page = documentState?.document?.pages?.[pageIndex];\n const width = page?.size?.width ?? 0;\n const height = page?.size?.height ?? 0;\n const rotation = rotationOverride ?? documentState?.rotation ?? 0;\n const scale = scaleOverride ?? documentState?.scale ?? 1;\n\n const matrix =\n rotatePlugin?.getMatrixAsString({\n width: width * scale,\n height: height * scale,\n rotation: rotation,\n }) ?? 'matrix(1, 0, 0, 1, 0, 0)';\n\n if (!page) return null;\n\n return (\n <div\n {...props}\n style={{\n position: 'absolute',\n transformOrigin: '0 0',\n transform: matrix,\n ...style,\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":["useRotatePlugin","usePlugin","RotatePlugin","id","useRotateCapability","useCapability","children","documentId","pageIndex","rotation","rotationOverride","scale","scaleOverride","style","props","plugin","rotatePlugin","documentState","useDocumentState","page","_b","_a","document","pages","width","_c","size","height","_d","matrix","getMatrixAsString","jsx","position","transformOrigin","transform","provides","setRotation","useState","initialDocumentState","useEffect","scope","forDocument","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
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-rotate.ts","../../src/shared/components/rotate.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\nimport { initialDocumentState, RotatePlugin } from '@embedpdf/plugin-rotate';\nimport { useEffect, useState } from '@framework';\n\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook for rotation state for a specific document\n * @param documentId Document ID\n */\nexport const useRotate = (documentId: string) => {\n const { provides } = useRotateCapability();\n const [rotation, setRotation] = useState<Rotation>(initialDocumentState.rotation);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n\n // Get initial state\n setRotation(scope.getRotation());\n\n // Subscribe to rotation changes\n return scope.onRotateChange((newRotation) => {\n setRotation(newRotation);\n });\n }, [provides, documentId]);\n\n return {\n rotation,\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n","import { ReactNode, HTMLAttributes, CSSProperties } from '@framework';\nimport { useDocumentState } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\n\nimport { useRotatePlugin } from '../hooks';\n\ntype RotateProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n children: ReactNode;\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n style?: CSSProperties;\n};\n\nexport function Rotate({\n children,\n documentId,\n pageIndex,\n rotation: rotationOverride,\n scale: scaleOverride,\n style,\n ...props\n}: RotateProps) {\n const { plugin: rotatePlugin } = useRotatePlugin();\n const documentState = useDocumentState(documentId);\n\n const page = documentState?.document?.pages?.[pageIndex];\n const width = page?.size?.width ?? 0;\n const height = page?.size?.height ?? 0;\n // If override is provided, use it directly (consistent with other layer components)\n // Otherwise, combine page intrinsic rotation with document rotation\n const pageRotation = page?.rotation ?? 0;\n const docRotation = documentState?.rotation ?? 0;\n const rotation =\n rotationOverride !== undefined ? rotationOverride : (pageRotation + docRotation) % 4;\n const scale = scaleOverride ?? documentState?.scale ?? 1;\n\n const matrix =\n rotatePlugin?.getMatrixAsString({\n width: width * scale,\n height: height * scale,\n rotation: rotation,\n }) ?? 'matrix(1, 0, 0, 1, 0, 0)';\n\n if (!page) return null;\n\n return (\n <div\n {...props}\n style={{\n position: 'absolute',\n transformOrigin: '0 0',\n transform: matrix,\n ...style,\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":["useRotatePlugin","usePlugin","RotatePlugin","id","useRotateCapability","useCapability","children","documentId","pageIndex","rotation","rotationOverride","scale","scaleOverride","style","props","plugin","rotatePlugin","documentState","useDocumentState","page","_b","_a","document","pages","width","_c","size","height","_d","pageRotation","docRotation","matrix","getMatrixAsString","jsx","position","transformOrigin","transform","provides","setRotation","useState","initialDocumentState","useEffect","scope","forDocument","getRotation","onRotateChange","newRotation"],"mappings":"gPAKaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,mBCS3E,UAAgBG,SACrBA,EAAAC,WACAA,EAAAC,UACAA,EACAC,SAAUC,EACVC,MAAOC,EAAAC,MACPA,KACGC,gBAEH,MAAQC,OAAQC,GAAiBhB,IAC3BiB,EAAgBC,EAAAA,iBAAiBX,GAEjCY,EAAO,OAAAC,EAAA,OAAAC,EAAA,MAAAJ,OAAA,EAAAA,EAAeK,eAAf,EAAAD,EAAyBE,YAAzB,EAAAH,EAAiCZ,GACxCgB,GAAQ,OAAAC,EAAA,MAAAN,OAAA,EAAAA,EAAMO,WAAN,EAAAD,EAAYD,QAAS,EAC7BG,GAAS,OAAAC,EAAA,MAAAT,OAAA,EAAAA,EAAMO,WAAN,EAAAE,EAAYD,SAAU,EAG/BE,SAAeV,WAAMV,WAAY,EACjCqB,SAAcb,WAAeR,WAAY,EACzCA,OACiB,IAArBC,EAAiCA,GAAoBmB,EAAeC,GAAe,EAC/EnB,EAAQC,IAAiB,MAAAK,OAAA,EAAAA,EAAeN,QAAS,EAEjDoB,SACJf,WAAcgB,kBAAkB,CAC9BR,MAAOA,EAAQb,EACfgB,OAAQA,EAAShB,EACjBF,eACI,2BAER,OAAKU,EAGHc,EAAAA,IAAC,MAAA,IACKnB,EACJD,MAAO,CACLqB,SAAU,WACVC,gBAAiB,MACjBC,UAAWL,KACRlB,GAGJP,aAZa,IAepB,oBDhD0BC,IACxB,MAAM8B,SAAEA,GAAajC,KACdK,EAAU6B,GAAeC,EAAAA,SAAmBC,EAAAA,qBAAqB/B,UAgBxE,OAdAgC,EAAAA,UAAU,KACR,IAAKJ,EAAU,OAEf,MAAMK,EAAQL,EAASM,YAAYpC,GAMnC,OAHA+B,EAAYI,EAAME,eAGXF,EAAMG,eAAgBC,IAC3BR,EAAYQ,MAEb,CAACT,EAAU9B,IAEP,CACLE,WACA4B,UAAU,MAAAA,OAAA,EAAAA,EAAUM,YAAYpC,KAAe"}
@@ -37,7 +37,9 @@ function Rotate({
37
37
  const page = (_b = (_a = documentState == null ? void 0 : documentState.document) == null ? void 0 : _a.pages) == null ? void 0 : _b[pageIndex];
38
38
  const width = ((_c = page == null ? void 0 : page.size) == null ? void 0 : _c.width) ?? 0;
39
39
  const height = ((_d = page == null ? void 0 : page.size) == null ? void 0 : _d.height) ?? 0;
40
- const rotation = rotationOverride ?? (documentState == null ? void 0 : documentState.rotation) ?? 0;
40
+ const pageRotation = (page == null ? void 0 : page.rotation) ?? 0;
41
+ const docRotation = (documentState == null ? void 0 : documentState.rotation) ?? 0;
42
+ const rotation = rotationOverride !== void 0 ? rotationOverride : (pageRotation + docRotation) % 4;
41
43
  const scale = scaleOverride ?? (documentState == null ? void 0 : documentState.scale) ?? 1;
42
44
  const matrix = (rotatePlugin == null ? void 0 : rotatePlugin.getMatrixAsString({
43
45
  width: width * scale,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-rotate.ts","../../src/shared/components/rotate.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\nimport { initialDocumentState, RotatePlugin } from '@embedpdf/plugin-rotate';\nimport { useEffect, useState } from '@framework';\n\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook for rotation state for a specific document\n * @param documentId Document ID\n */\nexport const useRotate = (documentId: string) => {\n const { provides } = useRotateCapability();\n const [rotation, setRotation] = useState<Rotation>(initialDocumentState.rotation);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n\n // Get initial state\n setRotation(scope.getRotation());\n\n // Subscribe to rotation changes\n return scope.onRotateChange((newRotation) => {\n setRotation(newRotation);\n });\n }, [provides, documentId]);\n\n return {\n rotation,\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n","import { ReactNode, HTMLAttributes, CSSProperties } from '@framework';\nimport { useDocumentState } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\n\nimport { useRotatePlugin } from '../hooks';\n\ntype RotateProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n children: ReactNode;\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n style?: CSSProperties;\n};\n\nexport function Rotate({\n children,\n documentId,\n pageIndex,\n rotation: rotationOverride,\n scale: scaleOverride,\n style,\n ...props\n}: RotateProps) {\n const { plugin: rotatePlugin } = useRotatePlugin();\n const documentState = useDocumentState(documentId);\n\n const page = documentState?.document?.pages?.[pageIndex];\n const width = page?.size?.width ?? 0;\n const height = page?.size?.height ?? 0;\n const rotation = rotationOverride ?? documentState?.rotation ?? 0;\n const scale = scaleOverride ?? documentState?.scale ?? 1;\n\n const matrix =\n rotatePlugin?.getMatrixAsString({\n width: width * scale,\n height: height * scale,\n rotation: rotation,\n }) ?? 'matrix(1, 0, 0, 1, 0, 0)';\n\n if (!page) return null;\n\n return (\n <div\n {...props}\n style={{\n position: 'absolute',\n transformOrigin: '0 0',\n transform: matrix,\n ...style,\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;AAKO,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,UAAU,WAAW,IAAI,SAAmB,qBAAqB,QAAQ;AAEhF,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AAEf,UAAM,QAAQ,SAAS,YAAY,UAAU;AAG7C,gBAAY,MAAM,aAAa;AAG/B,WAAO,MAAM,eAAe,CAAC,gBAAgB;AAC3C,kBAAY,WAAW;AAAA,IACzB,CAAC;AAAA,EACH,GAAG,CAAC,UAAU,UAAU,CAAC;AAEzB,SAAO;AAAA,IACL;AAAA,IACA,WAAU,qCAAU,YAAY,gBAAe;AAAA,EAAA;AAEnD;ACnBO,SAAS,OAAO;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP;AAAA,EACA,GAAG;AACL,GAAgB;;AACd,QAAM,EAAE,QAAQ,aAAA,IAAiB,gBAAA;AACjC,QAAM,gBAAgB,iBAAiB,UAAU;AAEjD,QAAM,QAAO,0DAAe,aAAf,mBAAyB,UAAzB,mBAAiC;AAC9C,QAAM,UAAQ,kCAAM,SAAN,mBAAY,UAAS;AACnC,QAAM,WAAS,kCAAM,SAAN,mBAAY,WAAU;AACrC,QAAM,WAAW,qBAAoB,+CAAe,aAAY;AAChE,QAAM,QAAQ,kBAAiB,+CAAe,UAAS;AAEvD,QAAM,UACJ,6CAAc,kBAAkB;AAAA,IAC9B,OAAO,QAAQ;AAAA,IACf,QAAQ,SAAS;AAAA,IACjB;AAAA,EAAA,OACI;AAER,MAAI,CAAC,KAAM,QAAO;AAElB,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,OAAO;AAAA,QACL,UAAU;AAAA,QACV,iBAAiB;AAAA,QACjB,WAAW;AAAA,QACX,GAAG;AAAA,MAAA;AAAA,MAGJ;AAAA,IAAA;AAAA,EAAA;AAGP;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-rotate.ts","../../src/shared/components/rotate.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\nimport { initialDocumentState, RotatePlugin } from '@embedpdf/plugin-rotate';\nimport { useEffect, useState } from '@framework';\n\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook for rotation state for a specific document\n * @param documentId Document ID\n */\nexport const useRotate = (documentId: string) => {\n const { provides } = useRotateCapability();\n const [rotation, setRotation] = useState<Rotation>(initialDocumentState.rotation);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n\n // Get initial state\n setRotation(scope.getRotation());\n\n // Subscribe to rotation changes\n return scope.onRotateChange((newRotation) => {\n setRotation(newRotation);\n });\n }, [provides, documentId]);\n\n return {\n rotation,\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n","import { ReactNode, HTMLAttributes, CSSProperties } from '@framework';\nimport { useDocumentState } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\n\nimport { useRotatePlugin } from '../hooks';\n\ntype RotateProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n children: ReactNode;\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n style?: CSSProperties;\n};\n\nexport function Rotate({\n children,\n documentId,\n pageIndex,\n rotation: rotationOverride,\n scale: scaleOverride,\n style,\n ...props\n}: RotateProps) {\n const { plugin: rotatePlugin } = useRotatePlugin();\n const documentState = useDocumentState(documentId);\n\n const page = documentState?.document?.pages?.[pageIndex];\n const width = page?.size?.width ?? 0;\n const height = page?.size?.height ?? 0;\n // If override is provided, use it directly (consistent with other layer components)\n // Otherwise, combine page intrinsic rotation with document rotation\n const pageRotation = page?.rotation ?? 0;\n const docRotation = documentState?.rotation ?? 0;\n const rotation =\n rotationOverride !== undefined ? rotationOverride : (pageRotation + docRotation) % 4;\n const scale = scaleOverride ?? documentState?.scale ?? 1;\n\n const matrix =\n rotatePlugin?.getMatrixAsString({\n width: width * scale,\n height: height * scale,\n rotation: rotation,\n }) ?? 'matrix(1, 0, 0, 1, 0, 0)';\n\n if (!page) return null;\n\n return (\n <div\n {...props}\n style={{\n position: 'absolute',\n transformOrigin: '0 0',\n transform: matrix,\n ...style,\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;;AAKO,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,UAAU,WAAW,IAAI,SAAmB,qBAAqB,QAAQ;AAEhF,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AAEf,UAAM,QAAQ,SAAS,YAAY,UAAU;AAG7C,gBAAY,MAAM,aAAa;AAG/B,WAAO,MAAM,eAAe,CAAC,gBAAgB;AAC3C,kBAAY,WAAW;AAAA,IACzB,CAAC;AAAA,EACH,GAAG,CAAC,UAAU,UAAU,CAAC;AAEzB,SAAO;AAAA,IACL;AAAA,IACA,WAAU,qCAAU,YAAY,gBAAe;AAAA,EAAA;AAEnD;ACnBO,SAAS,OAAO;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP;AAAA,EACA,GAAG;AACL,GAAgB;;AACd,QAAM,EAAE,QAAQ,aAAA,IAAiB,gBAAA;AACjC,QAAM,gBAAgB,iBAAiB,UAAU;AAEjD,QAAM,QAAO,0DAAe,aAAf,mBAAyB,UAAzB,mBAAiC;AAC9C,QAAM,UAAQ,kCAAM,SAAN,mBAAY,UAAS;AACnC,QAAM,WAAS,kCAAM,SAAN,mBAAY,WAAU;AAGrC,QAAM,gBAAe,6BAAM,aAAY;AACvC,QAAM,eAAc,+CAAe,aAAY;AAC/C,QAAM,WACJ,qBAAqB,SAAY,oBAAoB,eAAe,eAAe;AACrF,QAAM,QAAQ,kBAAiB,+CAAe,UAAS;AAEvD,QAAM,UACJ,6CAAc,kBAAkB;AAAA,IAC9B,OAAO,QAAQ;AAAA,IACf,QAAQ,SAAS;AAAA,IACjB;AAAA,EAAA,OACI;AAER,MAAI,CAAC,KAAM,QAAO;AAElB,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,OAAO;AAAA,QACL,UAAU;AAAA,QACV,iBAAiB;AAAA,QACjB,WAAW;AAAA,QACX,GAAG;AAAA,MAAA;AAAA,MAGJ;AAAA,IAAA;AAAA,EAAA;AAGP;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@embedpdf/core/react"),t=require("@embedpdf/plugin-rotate"),o=require("react"),i=require("react/jsx-runtime"),r=()=>e.usePlugin(t.RotatePlugin.id),n=()=>e.useCapability(t.RotatePlugin.id);exports.Rotate=function({children:t,documentId:o,pageIndex:n,rotation:l,scale:u,style:a,...s}){var d,c,p,g;const{plugin:v}=r(),f=e.useDocumentState(o),m=null==(c=null==(d=null==f?void 0:f.document)?void 0:d.pages)?void 0:c[n],x=(null==(p=null==m?void 0:m.size)?void 0:p.width)??0,b=(null==(g=null==m?void 0:m.size)?void 0:g.height)??0,h=l??(null==f?void 0:f.rotation)??0,y=u??(null==f?void 0:f.scale)??1,R=(null==v?void 0:v.getMatrixAsString({width:x*y,height:b*y,rotation:h}))??"matrix(1, 0, 0, 1, 0, 0)";return m?i.jsx("div",{...s,style:{position:"absolute",transformOrigin:"0 0",transform:R,...a},children:t}):null},exports.useRotate=e=>{const{provides:i}=n(),[r,l]=o.useState(t.initialDocumentState.rotation);return o.useEffect(()=>{if(!i)return;const t=i.forDocument(e);return l(t.getRotation()),t.onRotateChange(e=>{l(e)})},[i,e]),{rotation:r,provides:(null==i?void 0:i.forDocument(e))??null}},exports.useRotateCapability=n,exports.useRotatePlugin=r,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 t=require("@embedpdf/core/react"),e=require("@embedpdf/plugin-rotate"),o=require("react"),i=require("react/jsx-runtime"),r=()=>t.usePlugin(e.RotatePlugin.id),n=()=>t.useCapability(e.RotatePlugin.id);exports.Rotate=function({children:e,documentId:o,pageIndex:n,rotation:l,scale:u,style:a,...s}){var d,c,p,g;const{plugin:v}=r(),f=t.useDocumentState(o),m=null==(c=null==(d=null==f?void 0:f.document)?void 0:d.pages)?void 0:c[n],x=(null==(p=null==m?void 0:m.size)?void 0:p.width)??0,b=(null==(g=null==m?void 0:m.size)?void 0:g.height)??0,h=(null==m?void 0:m.rotation)??0,y=(null==f?void 0:f.rotation)??0,R=void 0!==l?l:(h+y)%4,P=u??(null==f?void 0:f.scale)??1,j=(null==v?void 0:v.getMatrixAsString({width:x*P,height:b*P,rotation:R}))??"matrix(1, 0, 0, 1, 0, 0)";return m?i.jsx("div",{...s,style:{position:"absolute",transformOrigin:"0 0",transform:j,...a},children:e}):null},exports.useRotate=t=>{const{provides:i}=n(),[r,l]=o.useState(e.initialDocumentState.rotation);return o.useEffect(()=>{if(!i)return;const e=i.forDocument(t);return l(e.getRotation()),e.onRotateChange(t=>{l(t)})},[i,t]),{rotation:r,provides:(null==i?void 0:i.forDocument(t))??null}},exports.useRotateCapability=n,exports.useRotatePlugin=r,Object.keys(e).forEach(t=>{"default"===t||Object.prototype.hasOwnProperty.call(exports,t)||Object.defineProperty(exports,t,{enumerable:!0,get:()=>e[t]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-rotate.ts","../../src/shared/components/rotate.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\nimport { initialDocumentState, RotatePlugin } from '@embedpdf/plugin-rotate';\nimport { useEffect, useState } from '@framework';\n\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook for rotation state for a specific document\n * @param documentId Document ID\n */\nexport const useRotate = (documentId: string) => {\n const { provides } = useRotateCapability();\n const [rotation, setRotation] = useState<Rotation>(initialDocumentState.rotation);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n\n // Get initial state\n setRotation(scope.getRotation());\n\n // Subscribe to rotation changes\n return scope.onRotateChange((newRotation) => {\n setRotation(newRotation);\n });\n }, [provides, documentId]);\n\n return {\n rotation,\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n","import { ReactNode, HTMLAttributes, CSSProperties } from '@framework';\nimport { useDocumentState } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\n\nimport { useRotatePlugin } from '../hooks';\n\ntype RotateProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n children: ReactNode;\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n style?: CSSProperties;\n};\n\nexport function Rotate({\n children,\n documentId,\n pageIndex,\n rotation: rotationOverride,\n scale: scaleOverride,\n style,\n ...props\n}: RotateProps) {\n const { plugin: rotatePlugin } = useRotatePlugin();\n const documentState = useDocumentState(documentId);\n\n const page = documentState?.document?.pages?.[pageIndex];\n const width = page?.size?.width ?? 0;\n const height = page?.size?.height ?? 0;\n const rotation = rotationOverride ?? documentState?.rotation ?? 0;\n const scale = scaleOverride ?? documentState?.scale ?? 1;\n\n const matrix =\n rotatePlugin?.getMatrixAsString({\n width: width * scale,\n height: height * scale,\n rotation: rotation,\n }) ?? 'matrix(1, 0, 0, 1, 0, 0)';\n\n if (!page) return null;\n\n return (\n <div\n {...props}\n style={{\n position: 'absolute',\n transformOrigin: '0 0',\n transform: matrix,\n ...style,\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":["useRotatePlugin","usePlugin","RotatePlugin","id","useRotateCapability","useCapability","children","documentId","pageIndex","rotation","rotationOverride","scale","scaleOverride","style","props","plugin","rotatePlugin","documentState","useDocumentState","page","_b","_a","document","pages","width","_c","size","height","_d","matrix","getMatrixAsString","jsx","position","transformOrigin","transform","provides","setRotation","useState","initialDocumentState","useEffect","scope","forDocument","getRotation","onRotateChange","newRotation"],"mappings":"+MAKaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,mBCS3E,UAAgBG,SACrBA,EAAAC,WACAA,EAAAC,UACAA,EACAC,SAAUC,EACVC,MAAOC,EAAAC,MACPA,KACGC,gBAEH,MAAQC,OAAQC,GAAiBhB,IAC3BiB,EAAgBC,EAAAA,iBAAiBX,GAEjCY,EAAO,OAAAC,EAAA,OAAAC,EAAA,MAAAJ,OAAA,EAAAA,EAAeK,eAAf,EAAAD,EAAyBE,YAAzB,EAAAH,EAAiCZ,GACxCgB,GAAQ,OAAAC,EAAA,MAAAN,OAAA,EAAAA,EAAMO,WAAN,EAAAD,EAAYD,QAAS,EAC7BG,GAAS,OAAAC,EAAA,MAAAT,OAAA,EAAAA,EAAMO,WAAN,EAAAE,EAAYD,SAAU,EAC/BlB,EAAWC,IAAoB,MAAAO,OAAA,EAAAA,EAAeR,WAAY,EAC1DE,EAAQC,IAAiB,MAAAK,OAAA,EAAAA,EAAeN,QAAS,EAEjDkB,SACJb,WAAcc,kBAAkB,CAC9BN,MAAOA,EAAQb,EACfgB,OAAQA,EAAShB,EACjBF,eACI,2BAER,OAAKU,EAGHY,EAAAA,IAAC,MAAA,IACKjB,EACJD,MAAO,CACLmB,SAAU,WACVC,gBAAiB,MACjBC,UAAWL,KACRhB,GAGJP,aAZa,IAepB,oBD3C0BC,IACxB,MAAM4B,SAAEA,GAAa/B,KACdK,EAAU2B,GAAeC,EAAAA,SAAmBC,EAAAA,qBAAqB7B,UAgBxE,OAdA8B,EAAAA,UAAU,KACR,IAAKJ,EAAU,OAEf,MAAMK,EAAQL,EAASM,YAAYlC,GAMnC,OAHA6B,EAAYI,EAAME,eAGXF,EAAMG,eAAgBC,IAC3BR,EAAYQ,MAEb,CAACT,EAAU5B,IAEP,CACLE,WACA0B,UAAU,MAAAA,OAAA,EAAAA,EAAUM,YAAYlC,KAAe"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/shared/hooks/use-rotate.ts","../../src/shared/components/rotate.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\nimport { initialDocumentState, RotatePlugin } from '@embedpdf/plugin-rotate';\nimport { useEffect, useState } from '@framework';\n\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook for rotation state for a specific document\n * @param documentId Document ID\n */\nexport const useRotate = (documentId: string) => {\n const { provides } = useRotateCapability();\n const [rotation, setRotation] = useState<Rotation>(initialDocumentState.rotation);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n\n // Get initial state\n setRotation(scope.getRotation());\n\n // Subscribe to rotation changes\n return scope.onRotateChange((newRotation) => {\n setRotation(newRotation);\n });\n }, [provides, documentId]);\n\n return {\n rotation,\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n","import { ReactNode, HTMLAttributes, CSSProperties } from '@framework';\nimport { useDocumentState } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\n\nimport { useRotatePlugin } from '../hooks';\n\ntype RotateProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n children: ReactNode;\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n style?: CSSProperties;\n};\n\nexport function Rotate({\n children,\n documentId,\n pageIndex,\n rotation: rotationOverride,\n scale: scaleOverride,\n style,\n ...props\n}: RotateProps) {\n const { plugin: rotatePlugin } = useRotatePlugin();\n const documentState = useDocumentState(documentId);\n\n const page = documentState?.document?.pages?.[pageIndex];\n const width = page?.size?.width ?? 0;\n const height = page?.size?.height ?? 0;\n // If override is provided, use it directly (consistent with other layer components)\n // Otherwise, combine page intrinsic rotation with document rotation\n const pageRotation = page?.rotation ?? 0;\n const docRotation = documentState?.rotation ?? 0;\n const rotation =\n rotationOverride !== undefined ? rotationOverride : (pageRotation + docRotation) % 4;\n const scale = scaleOverride ?? documentState?.scale ?? 1;\n\n const matrix =\n rotatePlugin?.getMatrixAsString({\n width: width * scale,\n height: height * scale,\n rotation: rotation,\n }) ?? 'matrix(1, 0, 0, 1, 0, 0)';\n\n if (!page) return null;\n\n return (\n <div\n {...props}\n style={{\n position: 'absolute',\n transformOrigin: '0 0',\n transform: matrix,\n ...style,\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":["useRotatePlugin","usePlugin","RotatePlugin","id","useRotateCapability","useCapability","children","documentId","pageIndex","rotation","rotationOverride","scale","scaleOverride","style","props","plugin","rotatePlugin","documentState","useDocumentState","page","_b","_a","document","pages","width","_c","size","height","_d","pageRotation","docRotation","matrix","getMatrixAsString","jsx","position","transformOrigin","transform","provides","setRotation","useState","initialDocumentState","useEffect","scope","forDocument","getRotation","onRotateChange","newRotation"],"mappings":"+MAKaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAC7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,mBCS3E,UAAgBG,SACrBA,EAAAC,WACAA,EAAAC,UACAA,EACAC,SAAUC,EACVC,MAAOC,EAAAC,MACPA,KACGC,gBAEH,MAAQC,OAAQC,GAAiBhB,IAC3BiB,EAAgBC,EAAAA,iBAAiBX,GAEjCY,EAAO,OAAAC,EAAA,OAAAC,EAAA,MAAAJ,OAAA,EAAAA,EAAeK,eAAf,EAAAD,EAAyBE,YAAzB,EAAAH,EAAiCZ,GACxCgB,GAAQ,OAAAC,EAAA,MAAAN,OAAA,EAAAA,EAAMO,WAAN,EAAAD,EAAYD,QAAS,EAC7BG,GAAS,OAAAC,EAAA,MAAAT,OAAA,EAAAA,EAAMO,WAAN,EAAAE,EAAYD,SAAU,EAG/BE,SAAeV,WAAMV,WAAY,EACjCqB,SAAcb,WAAeR,WAAY,EACzCA,OACiB,IAArBC,EAAiCA,GAAoBmB,EAAeC,GAAe,EAC/EnB,EAAQC,IAAiB,MAAAK,OAAA,EAAAA,EAAeN,QAAS,EAEjDoB,SACJf,WAAcgB,kBAAkB,CAC9BR,MAAOA,EAAQb,EACfgB,OAAQA,EAAShB,EACjBF,eACI,2BAER,OAAKU,EAGHc,EAAAA,IAAC,MAAA,IACKnB,EACJD,MAAO,CACLqB,SAAU,WACVC,gBAAiB,MACjBC,UAAWL,KACRlB,GAGJP,aAZa,IAepB,oBDhD0BC,IACxB,MAAM8B,SAAEA,GAAajC,KACdK,EAAU6B,GAAeC,EAAAA,SAAmBC,EAAAA,qBAAqB/B,UAgBxE,OAdAgC,EAAAA,UAAU,KACR,IAAKJ,EAAU,OAEf,MAAMK,EAAQL,EAASM,YAAYpC,GAMnC,OAHA+B,EAAYI,EAAME,eAGXF,EAAMG,eAAgBC,IAC3BR,EAAYQ,MAEb,CAACT,EAAU9B,IAEP,CACLE,WACA4B,UAAU,MAAAA,OAAA,EAAAA,EAAUM,YAAYpC,KAAe"}
@@ -36,7 +36,9 @@ function Rotate({
36
36
  const page = (_b = (_a = documentState == null ? void 0 : documentState.document) == null ? void 0 : _a.pages) == null ? void 0 : _b[pageIndex];
37
37
  const width = ((_c = page == null ? void 0 : page.size) == null ? void 0 : _c.width) ?? 0;
38
38
  const height = ((_d = page == null ? void 0 : page.size) == null ? void 0 : _d.height) ?? 0;
39
- const rotation = rotationOverride ?? (documentState == null ? void 0 : documentState.rotation) ?? 0;
39
+ const pageRotation = (page == null ? void 0 : page.rotation) ?? 0;
40
+ const docRotation = (documentState == null ? void 0 : documentState.rotation) ?? 0;
41
+ const rotation = rotationOverride !== void 0 ? rotationOverride : (pageRotation + docRotation) % 4;
40
42
  const scale = scaleOverride ?? (documentState == null ? void 0 : documentState.scale) ?? 1;
41
43
  const matrix = (rotatePlugin == null ? void 0 : rotatePlugin.getMatrixAsString({
42
44
  width: width * scale,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-rotate.ts","../../src/shared/components/rotate.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\nimport { initialDocumentState, RotatePlugin } from '@embedpdf/plugin-rotate';\nimport { useEffect, useState } from '@framework';\n\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook for rotation state for a specific document\n * @param documentId Document ID\n */\nexport const useRotate = (documentId: string) => {\n const { provides } = useRotateCapability();\n const [rotation, setRotation] = useState<Rotation>(initialDocumentState.rotation);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n\n // Get initial state\n setRotation(scope.getRotation());\n\n // Subscribe to rotation changes\n return scope.onRotateChange((newRotation) => {\n setRotation(newRotation);\n });\n }, [provides, documentId]);\n\n return {\n rotation,\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n","import { ReactNode, HTMLAttributes, CSSProperties } from '@framework';\nimport { useDocumentState } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\n\nimport { useRotatePlugin } from '../hooks';\n\ntype RotateProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n children: ReactNode;\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n style?: CSSProperties;\n};\n\nexport function Rotate({\n children,\n documentId,\n pageIndex,\n rotation: rotationOverride,\n scale: scaleOverride,\n style,\n ...props\n}: RotateProps) {\n const { plugin: rotatePlugin } = useRotatePlugin();\n const documentState = useDocumentState(documentId);\n\n const page = documentState?.document?.pages?.[pageIndex];\n const width = page?.size?.width ?? 0;\n const height = page?.size?.height ?? 0;\n const rotation = rotationOverride ?? documentState?.rotation ?? 0;\n const scale = scaleOverride ?? documentState?.scale ?? 1;\n\n const matrix =\n rotatePlugin?.getMatrixAsString({\n width: width * scale,\n height: height * scale,\n rotation: rotation,\n }) ?? 'matrix(1, 0, 0, 1, 0, 0)';\n\n if (!page) return null;\n\n return (\n <div\n {...props}\n style={{\n position: 'absolute',\n transformOrigin: '0 0',\n transform: matrix,\n ...style,\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;AAKO,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,UAAU,WAAW,IAAI,SAAmB,qBAAqB,QAAQ;AAEhF,YAAU,MAAM;AACd,QAAI,CAAC,SAAU;AAEf,UAAM,QAAQ,SAAS,YAAY,UAAU;AAG7C,gBAAY,MAAM,aAAa;AAG/B,WAAO,MAAM,eAAe,CAAC,gBAAgB;AAC3C,kBAAY,WAAW;AAAA,IACzB,CAAC;AAAA,EACH,GAAG,CAAC,UAAU,UAAU,CAAC;AAEzB,SAAO;AAAA,IACL;AAAA,IACA,WAAU,qCAAU,YAAY,gBAAe;AAAA,EAAA;AAEnD;ACnBO,SAAS,OAAO;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,EACV,OAAO;AAAA,EACP;AAAA,EACA,GAAG;AACL,GAAgB;;AACd,QAAM,EAAE,QAAQ,aAAA,IAAiB,gBAAA;AACjC,QAAM,gBAAgB,iBAAiB,UAAU;AAEjD,QAAM,QAAO,0DAAe,aAAf,mBAAyB,UAAzB,mBAAiC;AAC9C,QAAM,UAAQ,kCAAM,SAAN,mBAAY,UAAS;AACnC,QAAM,WAAS,kCAAM,SAAN,mBAAY,WAAU;AACrC,QAAM,WAAW,qBAAoB,+CAAe,aAAY;AAChE,QAAM,QAAQ,kBAAiB,+CAAe,UAAS;AAEvD,QAAM,UACJ,6CAAc,kBAAkB;AAAA,IAC9B,OAAO,QAAQ;AAAA,IACf,QAAQ,SAAS;AAAA,IACjB;AAAA,EAAA,OACI;AAER,MAAI,CAAC,KAAM,QAAO;AAElB,SACE;AAAA,IAAC;AAAA,IAAA;AAAA,MACE,GAAG;AAAA,MACJ,OAAO;AAAA,QACL,UAAU;AAAA,QACV,iBAAiB;AAAA,QACjB,WAAW;AAAA,QACX,GAAG;AAAA,MAAA;AAAA,MAGJ;AAAA,IAAA;AAAA,EAAA;AAGP;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/shared/hooks/use-rotate.ts","../../src/shared/components/rotate.tsx"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\nimport { initialDocumentState, RotatePlugin } from '@embedpdf/plugin-rotate';\nimport { useEffect, useState } from '@framework';\n\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook for rotation state for a specific document\n * @param documentId Document ID\n */\nexport const useRotate = (documentId: string) => {\n const { provides } = useRotateCapability();\n const [rotation, setRotation] = useState<Rotation>(initialDocumentState.rotation);\n\n useEffect(() => {\n if (!provides) return;\n\n const scope = provides.forDocument(documentId);\n\n // Get initial state\n setRotation(scope.getRotation());\n\n // Subscribe to rotation changes\n return scope.onRotateChange((newRotation) => {\n setRotation(newRotation);\n });\n }, [provides, documentId]);\n\n return {\n rotation,\n provides: provides?.forDocument(documentId) ?? null,\n };\n};\n","import { ReactNode, HTMLAttributes, CSSProperties } from '@framework';\nimport { useDocumentState } from '@embedpdf/core/@framework';\nimport { Rotation } from '@embedpdf/models';\n\nimport { useRotatePlugin } from '../hooks';\n\ntype RotateProps = Omit<HTMLAttributes<HTMLDivElement>, 'style'> & {\n children: ReactNode;\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n style?: CSSProperties;\n};\n\nexport function Rotate({\n children,\n documentId,\n pageIndex,\n rotation: rotationOverride,\n scale: scaleOverride,\n style,\n ...props\n}: RotateProps) {\n const { plugin: rotatePlugin } = useRotatePlugin();\n const documentState = useDocumentState(documentId);\n\n const page = documentState?.document?.pages?.[pageIndex];\n const width = page?.size?.width ?? 0;\n const height = page?.size?.height ?? 0;\n // If override is provided, use it directly (consistent with other layer components)\n // Otherwise, combine page intrinsic rotation with document rotation\n const pageRotation = page?.rotation ?? 0;\n const docRotation = documentState?.rotation ?? 0;\n const rotation =\n rotationOverride !== undefined ? rotationOverride : (pageRotation + docRotation) % 4;\n const scale = scaleOverride ?? documentState?.scale ?? 1;\n\n const matrix =\n rotatePlugin?.getMatrixAsString({\n width: width * scale,\n height: height * scale,\n rotation: rotation,\n }) ?? 'matrix(1, 0, 0, 1, 0, 0)';\n\n if (!page) return null;\n\n return (\n <div\n {...props}\n style={{\n position: 'absolute',\n transformOrigin: '0 0',\n transform: matrix,\n ...style,\n }}\n >\n {children}\n </div>\n );\n}\n"],"names":[],"mappings":";;;;;AAKO,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,U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Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("svelte/internal/client"),t=require("@embedpdf/core/svelte"),r=require("@embedpdf/plugin-rotate");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)}require("svelte/internal/disclose-version");const n=o(e),i=()=>t.usePlugin(r.RotatePlugin.id),l=()=>t.useCapability(r.RotatePlugin.id);var s=n.from_html("<div><!></div>");exports.Rotate=function(e,r){n.push(r,!0);let o=n.rest_props(r,["$$slots","$$events","$$legacy","documentId","pageIndex","rotation","scale","children","class","style"]);const l=i(),a=t.useDocumentState(()=>r.documentId),u=n.derived(()=>{var e,t,o;return null==(o=null==(t=null==(e=a.current)?void 0:e.document)?void 0:t.pages)?void 0:o[r.pageIndex]}),d=n.derived(()=>{var e,t;return(null==(t=null==(e=n.get(u))?void 0:e.size)?void 0:t.width)??0}),c=n.derived(()=>{var e,t;return(null==(t=null==(e=n.get(u))?void 0:e.size)?void 0:t.height)??0}),p=n.derived(()=>{var e;return void 0!==r.rotation?r.rotation:(null==(e=a.current)?void 0:e.rotation)??0}),g=n.derived(()=>{var e;return void 0!==r.scale?r.scale:(null==(e=a.current)?void 0:e.scale)??1}),v=n.derived(()=>l.plugin?l.plugin.getMatrixAsString({width:n.get(d)*n.get(g),height:n.get(c)*n.get(g),rotation:n.get(p)}):"matrix(1, 0, 0, 1, 0, 0)");var f=n.comment(),m=n.first_child(f),b=e=>{var t=s();n.attribute_effect(t,()=>({class:r.class,style:r.style,...o,[n.STYLE]:{position:"absolute","transform-origin":"0 0",transform:n.get(v)}}));var i=n.child(t);n.snippet(i,()=>r.children??n.noop),n.reset(t),n.append(e,t)};n.if(m,e=>{n.get(u)&&e(b)}),n.append(e,f),n.pop()},exports.useRotate=e=>{const t=l();let o=n.state(n.proxy(r.initialDocumentState.rotation));const i=n.derived(e),s=n.derived(()=>t.provides&&n.get(i)?t.provides.forDocument(n.get(i)):null);return n.user_effect(()=>{const e=t.provides,l=n.get(i);if(!e||!l)return void n.set(o,r.initialDocumentState.rotation,!0);const s=e.forDocument(l);return n.set(o,s.getRotation(),!0),s.onRotateChange(e=>{n.set(o,e,!0)})}),{get provides(){return n.get(s)},get rotation(){return n.get(o)}}},exports.useRotateCapability=l,exports.useRotatePlugin=i,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("svelte/internal/client"),t=require("@embedpdf/core/svelte"),r=require("@embedpdf/plugin-rotate");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)}require("svelte/internal/disclose-version");const i=o(e),n=()=>t.usePlugin(r.RotatePlugin.id),l=()=>t.useCapability(r.RotatePlugin.id);var a=i.from_html("<div><!></div>");exports.Rotate=function(e,r){i.push(r,!0);let o=i.rest_props(r,["$$slots","$$events","$$legacy","documentId","pageIndex","rotation","scale","children","class","style"]);const l=n(),s=t.useDocumentState(()=>r.documentId),d=i.derived(()=>{var e,t,o;return null==(o=null==(t=null==(e=s.current)?void 0:e.document)?void 0:t.pages)?void 0:o[r.pageIndex]}),u=i.derived(()=>{var e,t;return(null==(t=null==(e=i.get(d))?void 0:e.size)?void 0:t.width)??0}),c=i.derived(()=>{var e,t;return(null==(t=null==(e=i.get(d))?void 0:e.size)?void 0:t.height)??0}),v=i.derived(()=>{var e;return(null==(e=i.get(d))?void 0:e.rotation)??0}),g=i.derived(()=>{var e;return(null==(e=s.current)?void 0:e.rotation)??0}),p=i.derived(()=>void 0!==r.rotation?r.rotation:(i.get(v)+i.get(g))%4),f=i.derived(()=>{var e;return void 0!==r.scale?r.scale:(null==(e=s.current)?void 0:e.scale)??1}),m=i.derived(()=>l.plugin?l.plugin.getMatrixAsString({width:i.get(u)*i.get(f),height:i.get(c)*i.get(f),rotation:i.get(p)}):"matrix(1, 0, 0, 1, 0, 0)");var b=i.comment(),y=i.first_child(b),h=e=>{var t=a();i.attribute_effect(t,()=>({class:r.class,style:r.style,...o,[i.STYLE]:{position:"absolute","transform-origin":"0 0",transform:i.get(m)}}));var n=i.child(t);i.snippet(n,()=>r.children??i.noop),i.reset(t),i.append(e,t)};i.if(y,e=>{i.get(d)&&e(h)}),i.append(e,b),i.pop()},exports.useRotate=e=>{const t=l();let o=i.state(i.proxy(r.initialDocumentState.rotation));const n=i.derived(e),a=i.derived(()=>t.provides&&i.get(n)?t.provides.forDocument(i.get(n)):null);return i.user_effect(()=>{const e=t.provides,l=i.get(n);if(!e||!l)return void i.set(o,r.initialDocumentState.rotation,!0);const a=e.forDocument(l);return i.set(o,a.getRotation(),!0),a.onRotateChange(e=>{i.set(o,e,!0)})}),{get provides(){return i.get(a)},get rotation(){return i.get(o)}}},exports.useRotateCapability=l,exports.useRotatePlugin=n,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-rotate.svelte.ts","../../src/svelte/components/Rotate.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { Rotation } from '@embedpdf/models';\nimport { RotatePlugin, initialDocumentState, RotateScope } from '@embedpdf/plugin-rotate';\n\n/**\n * Hook to get the raw rotate plugin instance.\n */\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook to get the rotate plugin's capability API.\n * This provides methods for rotating the document.\n */\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseRotateReturn {\n provides: RotateScope | null;\n rotation: Rotation;\n}\n\n/**\n * Hook that provides reactive rotation state and methods for a specific document.\n * @param getDocumentId Function that returns the document ID\n */\nexport const useRotate = (getDocumentId: () => string | null): UseRotateReturn => {\n const capability = useRotateCapability();\n\n let rotation = $state<Rotation>(initialDocumentState.rotation);\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 rotation = initialDocumentState.rotation;\n return;\n }\n\n const scope = provides.forDocument(docId);\n\n // Get initial state\n rotation = scope.getRotation();\n\n // Subscribe to rotation changes for this document\n return scope.onRotateChange((newRotation) => {\n rotation = newRotation;\n });\n });\n\n return {\n get provides() {\n return scopedProvides;\n },\n get rotation() {\n return rotation;\n },\n };\n};\n","<script lang=\"ts\">\n import type { Rotation } from '@embedpdf/models';\n import type { Snippet } from 'svelte';\n import type { HTMLAttributes } from 'svelte/elements';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import { useRotatePlugin } from '../hooks';\n\n type RotateProps = HTMLAttributes<HTMLDivElement> & {\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n children?: Snippet;\n class?: string;\n style?: string;\n };\n\n let {\n documentId,\n pageIndex,\n rotation: rotationOverride,\n scale: scaleOverride,\n children,\n class: propsClass,\n style: propsStyle,\n ...restProps\n }: RotateProps = $props();\n\n const rotatePlugin = useRotatePlugin();\n const documentState = useDocumentState(() => documentId);\n\n const page = $derived(documentState.current?.document?.pages?.[pageIndex]);\n const width = $derived(page?.size?.width ?? 0);\n const height = $derived(page?.size?.height ?? 0);\n\n const rotation = $derived(\n rotationOverride !== undefined ? rotationOverride : (documentState.current?.rotation ?? 0),\n );\n\n const scale = $derived(\n scaleOverride !== undefined ? scaleOverride : (documentState.current?.scale ?? 1),\n );\n\n const matrix = $derived(\n rotatePlugin.plugin\n ? rotatePlugin.plugin.getMatrixAsString({\n width: width * scale,\n height: height * scale,\n rotation: rotation,\n })\n : 'matrix(1, 0, 0, 1, 0, 0)',\n );\n</script>\n\n{#if page}\n <div\n class={propsClass}\n style:position=\"absolute\"\n style:transform-origin=\"0 0\"\n style:transform={matrix}\n style={propsStyle}\n {...restProps}\n >\n {@render children?.()}\n </div>\n{/if}\n"],"names":["useRotatePlugin","usePlugin","RotatePlugin","id","useRotateCapability","useCapability","restProps","$","rest_props","$$props","rotatePlugin","documentState","useDocumentState","documentId","page","_c","_b","_a","current","document","pages","pageIndex","width","size","height","rotation","scale","derived","matrix","plugin","getMatrixAsString","get","div","root_1","consequent","getDocumentId","capability","state","proxy","initialDocumentState","scopedProvides","provides","forDocument","user_effect","docId","scope","getRotation","onRotateChange","newRotation","set"],"mappings":"sgBAOaA,EAAA,IAAwBC,YAAwBC,EAAAA,aAAaC,IAM7DC,EAAA,IAA4BC,gBAA4BH,EAAAA,aAAaC,sFCY3EG,EAAQC,EAAAC,WAAAC,EAAA,0GAGP,MAAAC,EAAeV,IACfW,EAAgBC,EAAAA,iBAAgB,IAAAH,EAAAI,YAEhCC,2BAAgB,OAAA,OAAAC,EAAA,OAAAC,EAAA,OAAAC,EAAAN,EAAcO,cAAd,EAAAD,EAAuBE,eAAvB,EAAAH,EAAiCI,gBAAKX,EAAAY,aACtDC,wDAAiBR,aAAMS,eAAMD,QAAS,IACtCE,wDAAkBV,aAAMS,eAAMC,SAAU,IAExCC,mCACiB,2BAAgC,OAAAR,EAAAN,EAAcO,kBAASO,WAAY,IAGpFC,EAAKnB,EAAAoB,QAAA,WAAA,YACS,IADTlB,EAAAiB,MACkBjB,EAAAiB,OAAoB,OAAAT,EAAAN,EAAcO,kBAASQ,QAAS,IAG3EE,EAAMrB,EAAAoB,QAAA,IACVjB,EAAamB,OACTnB,EAAamB,OAAOC,kBAAiB,CACnCR,MAAKf,EAAAwB,IAAET,GAAKf,EAAAwB,IAAGL,GACfF,OAAMjB,EAAAwB,IAAEP,GAAMjB,EAAAwB,IAAGL,GACjBD,eAAUA,KAEZ,2EAKLO,EAAEC,uBAAFD,EAAE,KAAA,gCAMG1B,0EAFasB,qBAJlBI,+CAAAA,cAAAA,qBADElB,MAAIoB,0BAFD,oBD3BkBC,IAClB,MAAAC,EAAahC,IAEf,IAAAqB,EAAWlB,EAAA8B,MAAA9B,EAAA+B,MAAiBC,EAAAA,qBAAqBd,WAG/C,MAAAZ,YAAsBsB,GAGtBK,EAAAjC,EAAAoB,QAAA,IACJS,EAAWK,gBAAY5B,GAAauB,EAAWK,SAASC,kBAAY7B,IAAc,aAGpFN,EAAAoC,uBACQF,EAAWL,EAAWK,SACtBG,QAAQ/B,OAET4B,IAAaG,oBAChBnB,EAAWc,EAAAA,qBAAqBd,UAAA,GAI5B,MAAAoB,EAAQJ,EAASC,YAAYE,GAM5B,aAHPnB,EAAWoB,EAAMC,eAAA,GAGVD,EAAME,eAAgBC,IAC3BzC,EAAA0C,IAAAxB,EAAWuB,GAAA,QAKT,YAAAP,gBACKD,EACT,EACI,YAAAf,gBACKA,EACT"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/svelte/hooks/use-rotate.svelte.ts","../../src/svelte/components/Rotate.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { Rotation } from '@embedpdf/models';\nimport { RotatePlugin, initialDocumentState, RotateScope } from '@embedpdf/plugin-rotate';\n\n/**\n * Hook to get the raw rotate plugin instance.\n */\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook to get the rotate plugin's capability API.\n * This provides methods for rotating the document.\n */\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseRotateReturn {\n provides: RotateScope | null;\n rotation: Rotation;\n}\n\n/**\n * Hook that provides reactive rotation state and methods for a specific document.\n * @param getDocumentId Function that returns the document ID\n */\nexport const useRotate = (getDocumentId: () => string | null): UseRotateReturn => {\n const capability = useRotateCapability();\n\n let rotation = $state<Rotation>(initialDocumentState.rotation);\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 rotation = initialDocumentState.rotation;\n return;\n }\n\n const scope = provides.forDocument(docId);\n\n // Get initial state\n rotation = scope.getRotation();\n\n // Subscribe to rotation changes for this document\n return scope.onRotateChange((newRotation) => {\n rotation = newRotation;\n });\n });\n\n return {\n get provides() {\n return scopedProvides;\n },\n get rotation() {\n return rotation;\n },\n };\n};\n","<script lang=\"ts\">\n import type { Rotation } from '@embedpdf/models';\n import type { Snippet } from 'svelte';\n import type { HTMLAttributes } from 'svelte/elements';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import { useRotatePlugin } from '../hooks';\n\n type RotateProps = HTMLAttributes<HTMLDivElement> & {\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n children?: Snippet;\n class?: string;\n style?: string;\n };\n\n let {\n documentId,\n pageIndex,\n rotation: rotationOverride,\n scale: scaleOverride,\n children,\n class: propsClass,\n style: propsStyle,\n ...restProps\n }: RotateProps = $props();\n\n const rotatePlugin = useRotatePlugin();\n const documentState = useDocumentState(() => documentId);\n\n const page = $derived(documentState.current?.document?.pages?.[pageIndex]);\n const width = $derived(page?.size?.width ?? 0);\n const height = $derived(page?.size?.height ?? 0);\n\n // If override is provided, use it directly (consistent with other layer components)\n // Otherwise, combine page intrinsic rotation with document rotation\n const pageRotation = $derived(page?.rotation ?? 0);\n const docRotation = $derived(documentState.current?.rotation ?? 0);\n const rotation = $derived(\n rotationOverride !== undefined ? rotationOverride : (pageRotation + docRotation) % 4,\n );\n\n const scale = $derived(\n scaleOverride !== undefined ? scaleOverride : (documentState.current?.scale ?? 1),\n );\n\n const matrix = $derived(\n rotatePlugin.plugin\n ? rotatePlugin.plugin.getMatrixAsString({\n width: width * scale,\n height: height * scale,\n rotation: rotation,\n })\n : 'matrix(1, 0, 0, 1, 0, 0)',\n );\n</script>\n\n{#if page}\n <div\n class={propsClass}\n style:position=\"absolute\"\n style:transform-origin=\"0 0\"\n style:transform={matrix}\n style={propsStyle}\n {...restProps}\n >\n {@render children?.()}\n </div>\n{/if}\n"],"names":["useRotatePlugin","usePlugin","RotatePlugin","id","useRotateCapability","useCapability","restProps","$","rest_props","$$props","rotatePlugin","documentState","useDocumentState","documentId","page","_c","_b","_a","current","document","pages","pageIndex","width","size","height","pageRotation","derived","get","rotation","docRotation","scale","matrix","plugin","getMatrixAsString","div","root_1","consequent","getDocumentId","capability","state","proxy","initialDocumentState","scopedProvides","provides","forDocument","user_effect","docId","scope","getRotation","onRotateChange","newRotation","set"],"mappings":"sgBAOaA,EAAA,IAAwBC,YAAwBC,EAAAA,aAAaC,IAM7DC,EAAA,IAA4BC,gBAA4BH,EAAAA,aAAaC,sFCY3EG,EAAQC,EAAAC,WAAAC,EAAA,0GAGP,MAAAC,EAAeV,IACfW,EAAgBC,EAAAA,iBAAgB,IAAAH,EAAAI,YAEhCC,2BAAgB,OAAA,OAAAC,EAAA,OAAAC,EAAA,OAAAC,EAAAN,EAAcO,cAAd,EAAAD,EAAuBE,eAAvB,EAAAH,EAAiCI,gBAAKX,EAAAY,aACtDC,wDAAiBR,aAAMS,eAAMD,QAAS,IACtCE,wDAAkBV,aAAMS,eAAMC,SAAU,IAIxCC,EAAYlB,EAAAmB,QAAA,WAAAnB,OAAAA,OAAAA,EAAAA,EAAAoB,IAAYb,SAAZP,EAAAA,EAAkBqB,WAAY,IAC1CC,uBAAuB,OAAA,OAAAZ,EAAAN,EAAcO,kBAASU,WAAY,IAC1DA,qBACiB,iCAAgCH,GAAYlB,EAAAoB,IAAGE,IAAe,GAG/EC,EAAKvB,EAAAmB,QAAA,WAAA,YACS,IADTjB,EAAAqB,MACkBrB,EAAAqB,OAAoB,OAAAb,EAAAN,EAAcO,kBAASY,QAAS,IAG3EC,EAAMxB,EAAAmB,QAAA,IACVhB,EAAasB,OACTtB,EAAasB,OAAOC,kBAAiB,CACnCX,MAAKf,EAAAoB,IAAEL,GAAKf,EAAAoB,IAAGG,GACfN,OAAMjB,EAAAoB,IAAEH,GAAMjB,EAAAoB,IAAGG,GACjBF,eAAUA,KAEZ,2EAKLM,EAAEC,uBAAFD,EAAE,KAAA,gCAMG5B,0EAFayB,qBAJlBG,+CAAAA,cAAAA,qBADEpB,MAAIsB,0BAFD,oBD/BkBC,IAClB,MAAAC,EAAalC,IAEf,IAAAwB,EAAWrB,EAAAgC,MAAAhC,EAAAiC,MAAiBC,EAAAA,qBAAqBb,WAG/C,MAAAf,YAAsBwB,GAGtBK,EAAAnC,EAAAmB,QAAA,IACJY,EAAWK,gBAAY9B,GAAayB,EAAWK,SAASC,kBAAY/B,IAAc,aAGpFN,EAAAsC,uBACQF,EAAWL,EAAWK,SACtBG,QAAQjC,OAET8B,IAAaG,oBAChBlB,EAAWa,EAAAA,qBAAqBb,UAAA,GAI5B,MAAAmB,EAAQJ,EAASC,YAAYE,GAM5B,aAHPlB,EAAWmB,EAAMC,eAAA,GAGVD,EAAME,eAAgBC,IAC3B3C,EAAA4C,IAAAvB,EAAWsB,GAAA,QAKT,YAAAP,gBACKD,EACT,EACI,YAAAd,gBACKA,EACT"}
@@ -61,10 +61,15 @@ function Rotate($$anchor, $$props) {
61
61
  var _a, _b;
62
62
  return ((_b = (_a = $.get(page)) == null ? void 0 : _a.size) == null ? void 0 : _b.height) ?? 0;
63
63
  });
64
- const rotation = $.derived(() => {
64
+ const pageRotation = $.derived(() => {
65
65
  var _a;
66
- return $$props.rotation !== void 0 ? $$props.rotation : ((_a = documentState.current) == null ? void 0 : _a.rotation) ?? 0;
66
+ return ((_a = $.get(page)) == null ? void 0 : _a.rotation) ?? 0;
67
67
  });
68
+ const docRotation = $.derived(() => {
69
+ var _a;
70
+ return ((_a = documentState.current) == null ? void 0 : _a.rotation) ?? 0;
71
+ });
72
+ const rotation = $.derived(() => $$props.rotation !== void 0 ? $$props.rotation : ($.get(pageRotation) + $.get(docRotation)) % 4);
68
73
  const scale = $.derived(() => {
69
74
  var _a;
70
75
  return $$props.scale !== void 0 ? $$props.scale : ((_a = documentState.current) == null ? void 0 : _a.scale) ?? 1;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-rotate.svelte.ts","../../src/svelte/components/Rotate.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { Rotation } from '@embedpdf/models';\nimport { RotatePlugin, initialDocumentState, RotateScope } from '@embedpdf/plugin-rotate';\n\n/**\n * Hook to get the raw rotate plugin instance.\n */\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook to get the rotate plugin's capability API.\n * This provides methods for rotating the document.\n */\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseRotateReturn {\n provides: RotateScope | null;\n rotation: Rotation;\n}\n\n/**\n * Hook that provides reactive rotation state and methods for a specific document.\n * @param getDocumentId Function that returns the document ID\n */\nexport const useRotate = (getDocumentId: () => string | null): UseRotateReturn => {\n const capability = useRotateCapability();\n\n let rotation = $state<Rotation>(initialDocumentState.rotation);\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 rotation = initialDocumentState.rotation;\n return;\n }\n\n const scope = provides.forDocument(docId);\n\n // Get initial state\n rotation = scope.getRotation();\n\n // Subscribe to rotation changes for this document\n return scope.onRotateChange((newRotation) => {\n rotation = newRotation;\n });\n });\n\n return {\n get provides() {\n return scopedProvides;\n },\n get rotation() {\n return rotation;\n },\n };\n};\n","<script lang=\"ts\">\n import type { Rotation } from '@embedpdf/models';\n import type { Snippet } from 'svelte';\n import type { HTMLAttributes } from 'svelte/elements';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import { useRotatePlugin } from '../hooks';\n\n type RotateProps = HTMLAttributes<HTMLDivElement> & {\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n children?: Snippet;\n class?: string;\n style?: string;\n };\n\n let {\n documentId,\n pageIndex,\n rotation: rotationOverride,\n scale: scaleOverride,\n children,\n class: propsClass,\n style: propsStyle,\n ...restProps\n }: RotateProps = $props();\n\n const rotatePlugin = useRotatePlugin();\n const documentState = useDocumentState(() => documentId);\n\n const page = $derived(documentState.current?.document?.pages?.[pageIndex]);\n const width = $derived(page?.size?.width ?? 0);\n const height = $derived(page?.size?.height ?? 0);\n\n const rotation = $derived(\n rotationOverride !== undefined ? rotationOverride : (documentState.current?.rotation ?? 0),\n );\n\n const scale = $derived(\n scaleOverride !== undefined ? scaleOverride : (documentState.current?.scale ?? 1),\n );\n\n const matrix = $derived(\n rotatePlugin.plugin\n ? rotatePlugin.plugin.getMatrixAsString({\n width: width * scale,\n height: height * scale,\n rotation: rotation,\n })\n : 'matrix(1, 0, 0, 1, 0, 0)',\n );\n</script>\n\n{#if page}\n <div\n class={propsClass}\n style:position=\"absolute\"\n style:transform-origin=\"0 0\"\n style:transform={matrix}\n style={propsStyle}\n {...restProps}\n >\n {@render children?.()}\n </div>\n{/if}\n"],"names":[],"mappings":";;;;;AAOa,MAAA,kBAAA,MAAwB,UAAwB,aAAa,EAAE;AAM/D,MAAA,sBAAA,MAA4B,cAA4B,aAAa,EAAE;MAYvE,YAAA,CAAa,kBAAwD;AAC1E,QAAA,aAAa,oBAAA;AAEf,MAAA,WAAW,EAAA,MAAA,EAAA,MAA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AAM,EAAA,IAAE,MAAM,IAAA,EAAA,IAAG,KAAK;AAAA,IACtB,gBAAU,QAAQ;AAAA,OAEpB,0BAA0B;;;;;UAK/B,MAAE,OAAA;yBAAF,KAAE,OAAA;AAAA;;WAMG;AAAA;;;2BAFa,MAAM;AAAA;;2BAJxB,GAAE;;cAAF,GAAE;0BAAF,GAAE;AAAA;;gBADA,IAAI,EAAA,UAAA,UAAA;AAAA;;;;AAFD;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/svelte/hooks/use-rotate.svelte.ts","../../src/svelte/components/Rotate.svelte"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/svelte';\nimport { Rotation } from '@embedpdf/models';\nimport { RotatePlugin, initialDocumentState, RotateScope } from '@embedpdf/plugin-rotate';\n\n/**\n * Hook to get the raw rotate plugin instance.\n */\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook to get the rotate plugin's capability API.\n * This provides methods for rotating the document.\n */\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n// Define the return type explicitly to maintain type safety\ninterface UseRotateReturn {\n provides: RotateScope | null;\n rotation: Rotation;\n}\n\n/**\n * Hook that provides reactive rotation state and methods for a specific document.\n * @param getDocumentId Function that returns the document ID\n */\nexport const useRotate = (getDocumentId: () => string | null): UseRotateReturn => {\n const capability = useRotateCapability();\n\n let rotation = $state<Rotation>(initialDocumentState.rotation);\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 rotation = initialDocumentState.rotation;\n return;\n }\n\n const scope = provides.forDocument(docId);\n\n // Get initial state\n rotation = scope.getRotation();\n\n // Subscribe to rotation changes for this document\n return scope.onRotateChange((newRotation) => {\n rotation = newRotation;\n });\n });\n\n return {\n get provides() {\n return scopedProvides;\n },\n get rotation() {\n return rotation;\n },\n };\n};\n","<script lang=\"ts\">\n import type { Rotation } from '@embedpdf/models';\n import type { Snippet } from 'svelte';\n import type { HTMLAttributes } from 'svelte/elements';\n import { useDocumentState } from '@embedpdf/core/svelte';\n import { useRotatePlugin } from '../hooks';\n\n type RotateProps = HTMLAttributes<HTMLDivElement> & {\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n children?: Snippet;\n class?: string;\n style?: string;\n };\n\n let {\n documentId,\n pageIndex,\n rotation: rotationOverride,\n scale: scaleOverride,\n children,\n class: propsClass,\n style: propsStyle,\n ...restProps\n }: RotateProps = $props();\n\n const rotatePlugin = useRotatePlugin();\n const documentState = useDocumentState(() => documentId);\n\n const page = $derived(documentState.current?.document?.pages?.[pageIndex]);\n const width = $derived(page?.size?.width ?? 0);\n const height = $derived(page?.size?.height ?? 0);\n\n // If override is provided, use it directly (consistent with other layer components)\n // Otherwise, combine page intrinsic rotation with document rotation\n const pageRotation = $derived(page?.rotation ?? 0);\n const docRotation = $derived(documentState.current?.rotation ?? 0);\n const rotation = $derived(\n rotationOverride !== undefined ? rotationOverride : (pageRotation + docRotation) % 4,\n );\n\n const scale = $derived(\n scaleOverride !== undefined ? scaleOverride : (documentState.current?.scale ?? 1),\n );\n\n const matrix = $derived(\n rotatePlugin.plugin\n ? rotatePlugin.plugin.getMatrixAsString({\n width: width * scale,\n height: height * scale,\n rotation: rotation,\n })\n : 'matrix(1, 0, 0, 1, 0, 0)',\n );\n</script>\n\n{#if page}\n <div\n class={propsClass}\n style:position=\"absolute\"\n style:transform-origin=\"0 0\"\n style:transform={matrix}\n style={propsStyle}\n {...restProps}\n >\n {@render children?.()}\n </div>\n{/if}\n"],"names":[],"mappings":";;;;;AAOa,MAAA,kBAAA,MAAwB,UAAwB,aAAa,EAAE;AAM/D,MAAA,sBAAA,MAA4B,cAA4B,aAAa,EAAE;MAYvE,YAAA,CAAa,kBAAwD;AAC1E,QAAA,a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AAAA,mBAAA,UACS,SAAS,QAAA,UAAoB,mBAAc,YAAd,mBAAuB,UAAS;AAAA,GAAC;QAG5E,SAAM,EAAA,QAAA,MACV,aAAa,SACT,aAAa,OAAO,kBAAiB;AAAA,IACnC,OAAK,EAAA,IAAE,KAAK,IAAA,EAAA,IAAG,KAAK;AAAA,IACpB,QAAM,EAAA,IAAE,MAAM,IAAA,EAAA,IAAG,KAAK;AAAA,IACtB,gBAAU,QAAQ;AAAA,OAEpB,0BAA0B;;;;;UAK/B,MAAE,OAAA;yBAAF,KAAE,OAAA;AAAA;;WAMG;AAAA;;;2BAFa,MAAM;AAAA;;2BAJxB,GAAE;;cAAF,GAAE;0BAAF,GAAE;AAAA;;gBADA,IAAI,EAAA,UAAA,UAAA;AAAA;;;;AAFD;"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("@embedpdf/core/vue"),o=require("@embedpdf/plugin-rotate"),a=()=>t.usePlugin(o.RotatePlugin.id),r=()=>t.useCapability(o.RotatePlugin.id),u=e.defineComponent({__name:"rotate",props:{documentId:{},pageIndex:{},rotation:{},scale:{}},setup(o){const r=o,{plugin:u}=a(),n=t.useDocumentState(()=>r.documentId),l=e.computed(()=>{var e,t,o;return null==(o=null==(t=null==(e=n.value)?void 0:e.document)?void 0:t.pages)?void 0:o[r.pageIndex]}),i=e.computed(()=>{var e,t;return(null==(t=null==(e=l.value)?void 0:e.size)?void 0:t.width)??0}),d=e.computed(()=>{var e,t;return(null==(t=null==(e=l.value)?void 0:e.size)?void 0:t.height)??0}),s=e.computed(()=>{var e;return void 0!==r.rotation?r.rotation:(null==(e=n.value)?void 0:e.rotation)??0}),v=e.computed(()=>{var e;return void 0!==r.scale?r.scale:(null==(e=n.value)?void 0:e.scale)??1}),c=e.computed(()=>u.value?u.value.getMatrixAsString({width:i.value*v.value,height:d.value*v.value,rotation:s.value}):"matrix(1, 0, 0, 1, 0, 0)");return(t,o)=>l.value?(e.openBlock(),e.createElementBlock("div",e.mergeProps({key:0,style:{position:"absolute",transformOrigin:"0 0",transform:c.value}},t.$attrs),[e.renderSlot(t.$slots,"default")],16)):e.createCommentVNode("",!0)}});exports.Rotate=u,exports.useRotate=t=>{const{provides:a}=r(),u=e.ref(o.initialDocumentState.rotation);e.watch([a,()=>e.toValue(t)],([e,t],a,r)=>{if(!e)return void(u.value=o.initialDocumentState.rotation);const n=e.forDocument(t);u.value=n.getRotation();r(n.onRotateChange(e=>{u.value=e}))},{immediate:!0});const n=e.computed(()=>{var o;const r=e.toValue(t);return(null==(o=a.value)?void 0:o.forDocument(r))??null});return{rotation:e.readonly(u),provides:n}},exports.useRotateCapability=r,exports.useRotatePlugin=a,Object.keys(o).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>o[e]})});
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),t=require("@embedpdf/core/vue"),o=require("@embedpdf/plugin-rotate"),r=()=>t.usePlugin(o.RotatePlugin.id),u=()=>t.useCapability(o.RotatePlugin.id),a=e.defineComponent({__name:"rotate",props:{documentId:{},pageIndex:{},rotation:{},scale:{}},setup(o){const u=o,{plugin:a}=r(),n=t.useDocumentState(()=>u.documentId),l=e.computed(()=>{var e,t,o;return null==(o=null==(t=null==(e=n.value)?void 0:e.document)?void 0:t.pages)?void 0:o[u.pageIndex]}),i=e.computed(()=>{var e,t;return(null==(t=null==(e=l.value)?void 0:e.size)?void 0:t.width)??0}),d=e.computed(()=>{var e,t;return(null==(t=null==(e=l.value)?void 0:e.size)?void 0:t.height)??0}),v=e.computed(()=>{var e;return(null==(e=l.value)?void 0:e.rotation)??0}),s=e.computed(()=>{var e;if(void 0!==u.rotation)return u.rotation;const t=(null==(e=n.value)?void 0:e.rotation)??0;return(v.value+t)%4}),c=e.computed(()=>{var e;return void 0!==u.scale?u.scale:(null==(e=n.value)?void 0:e.scale)??1}),p=e.computed(()=>a.value?a.value.getMatrixAsString({width:i.value*c.value,height:d.value*c.value,rotation:s.value}):"matrix(1, 0, 0, 1, 0, 0)");return(t,o)=>l.value?(e.openBlock(),e.createElementBlock("div",e.mergeProps({key:0,style:{position:"absolute",transformOrigin:"0 0",transform:p.value}},t.$attrs),[e.renderSlot(t.$slots,"default")],16)):e.createCommentVNode("",!0)}});exports.Rotate=a,exports.useRotate=t=>{const{provides:r}=u(),a=e.ref(o.initialDocumentState.rotation);e.watch([r,()=>e.toValue(t)],([e,t],r,u)=>{if(!e)return void(a.value=o.initialDocumentState.rotation);const n=e.forDocument(t);a.value=n.getRotation();u(n.onRotateChange(e=>{a.value=e}))},{immediate:!0});const n=e.computed(()=>{var o;const u=e.toValue(t);return(null==(o=r.value)?void 0:o.forDocument(u))??null});return{rotation:e.readonly(a),provides:n}},exports.useRotateCapability=u,exports.useRotatePlugin=r,Object.keys(o).forEach(e=>{"default"===e||Object.prototype.hasOwnProperty.call(exports,e)||Object.defineProperty(exports,e,{enumerable:!0,get:()=>o[e]})});
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-rotate.ts","../../src/vue/components/rotate.vue"],"sourcesContent":["import { ref, watch, readonly, computed, toValue, type MaybeRefOrGetter } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { RotatePlugin, initialDocumentState } from '@embedpdf/plugin-rotate';\nimport { Rotation } from '@embedpdf/models';\n\n/**\n * Hook to get the raw rotate plugin instance.\n */\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook to get the rotate plugin's capability API.\n * This provides methods for rotating the document.\n */\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook that provides reactive rotation state and methods for a specific document.\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport const useRotate = (documentId: MaybeRefOrGetter<string>) => {\n const { provides } = useRotateCapability();\n const rotation = ref<Rotation>(initialDocumentState.rotation);\n\n watch(\n [provides, () => toValue(documentId)],\n ([providesValue, docId], _, onCleanup) => {\n if (!providesValue) {\n rotation.value = initialDocumentState.rotation;\n return;\n }\n\n const scope = providesValue.forDocument(docId);\n\n // Get initial state\n rotation.value = scope.getRotation();\n\n // Subscribe to rotation changes\n const unsubscribe = scope.onRotateChange((newRotation) => {\n rotation.value = newRotation;\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 rotation: readonly(rotation),\n provides: scopedProvides,\n };\n};\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport { useDocumentState } from '@embedpdf/core/vue';\nimport { Rotation } from '@embedpdf/models';\nimport { useRotatePlugin } from '../hooks';\n\ninterface RotateProps {\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n}\n\nconst props = defineProps<RotateProps>();\n\nconst { plugin: rotatePlugin } = useRotatePlugin();\nconst documentState = useDocumentState(() => props.documentId);\n\nconst page = computed(() => documentState.value?.document?.pages?.[props.pageIndex]);\nconst width = computed(() => page.value?.size?.width ?? 0);\nconst height = computed(() => page.value?.size?.height ?? 0);\n\nconst rotation = computed(() => {\n if (props.rotation !== undefined) return props.rotation;\n return documentState.value?.rotation ?? 0;\n});\n\nconst scale = computed(() => {\n if (props.scale !== undefined) return props.scale;\n return documentState.value?.scale ?? 1;\n});\n\nconst matrix = computed(() => {\n if (!rotatePlugin.value) return 'matrix(1, 0, 0, 1, 0, 0)';\n\n return rotatePlugin.value.getMatrixAsString({\n width: width.value * scale.value,\n height: height.value * scale.value,\n rotation: rotation.value,\n });\n});\n</script>\n\n<template>\n <div\n v-if=\"page\"\n :style=\"{\n position: 'absolute',\n transformOrigin: '0 0',\n transform: matrix,\n }\"\n v-bind=\"$attrs\"\n >\n <slot />\n </div>\n</template>\n"],"names":["useRotatePlugin","usePlugin","RotatePlugin","id","useRotateCapability","useCapability","props","__props","plugin","rotatePlugin","documentState","useDocumentState","documentId","page","computed","_c","_b","_a","value","document","pages","pageIndex","width","size","height","rotation","scale","matrix","getMatrixAsString","_openBlock","_createElementBlock","_mergeProps","style","$attrs","_renderSlot","_ctx","$slots","provides","ref","initialDocumentState","watch","toValue","providesValue","docId","_","onCleanup","scope","forDocument","getRotation","onRotateChange","newRotation","immediate","scopedProvides","readonly"],"mappings":"4KAQaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAM7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,0GCDlF,MAAMG,EAAQC,GAENC,OAAQC,GAAiBT,IAC3BU,EAAgBC,EAAAA,iBAAiB,IAAML,EAAMM,YAE7CC,EAAOC,WAAS,eAAM,OAAA,OAAAC,EAAA,OAAAC,EAAA,OAAAC,EAAAP,EAAcQ,YAAd,EAAAD,EAAqBE,eAArB,EAAAH,EAA+BI,gBAAQd,EAAMe,aACnEC,EAAQR,EAAAA,SAAS,aAAM,OAAA,OAAAE,EAAA,OAAAC,EAAAJ,EAAKK,YAAL,EAAAD,EAAYM,WAAZ,EAAAP,EAAkBM,QAAS,IAClDE,EAASV,EAAAA,SAAS,aAAM,OAAA,OAAAE,EAAA,OAAAC,EAAAJ,EAAKK,YAAL,EAAAD,EAAYM,WAAZ,EAAAP,EAAkBQ,SAAU,IAEpDC,EAAWX,EAAAA,SAAS,WACxB,YAAuB,IAAnBR,EAAMmB,SAA+BnB,EAAMmB,UACxC,OAAAR,EAAAP,EAAcQ,YAAd,EAAAD,EAAqBQ,WAAY,IAGpCC,EAAQZ,EAAAA,SAAS,WACrB,YAAoB,IAAhBR,EAAMoB,MAA4BpB,EAAMoB,OACrC,OAAAT,EAAAP,EAAcQ,YAAd,EAAAD,EAAqBS,QAAS,IAGjCC,EAASb,EAAAA,SAAS,IACjBL,EAAaS,MAEXT,EAAaS,MAAMU,kBAAkB,CAC1CN,MAAOA,EAAMJ,MAAQQ,EAAMR,MAC3BM,OAAQA,EAAON,MAAQQ,EAAMR,MAC7BO,SAAUA,EAASP,QALW,yCAYxBL,EAAAK,OADRW,EAAAA,YAAAC,EAAAA,mBAUM,MAVNC,aAUM,OARHC,MAAK,qDAA+EL,EAAAT,QAK7Ee,EAAAA,QAAM,CAEdC,aAAQC,EAAAC,OAAA,mFDjCcxB,IACxB,MAAMyB,SAAEA,GAAajC,IACfqB,EAAWa,EAAAA,IAAcC,EAAAA,qBAAqBd,UAEpDe,EAAAA,MACE,CAACH,EAAU,IAAMI,UAAQ7B,IACzB,EAAE8B,EAAeC,GAAQC,EAAGC,KAC1B,IAAKH,EAEH,YADAjB,EAASP,MAAQqB,EAAAA,qBAAqBd,UAIxC,MAAMqB,EAAQJ,EAAcK,YAAYJ,GAGxClB,EAASP,MAAQ4B,EAAME,cAOvBH,EAJoBC,EAAMG,eAAgBC,IACxCzB,EAASP,MAAQgC,MAKrB,CAAEC,WAAW,IAIf,MAAMC,EAAiBtC,EAAAA,SAAS,WAC9B,MAAM6B,EAAQF,EAAAA,QAAQ7B,GACtB,OAAO,OAAAK,EAAAoB,EAASnB,YAAT,EAAAD,EAAgB8B,YAAYJ,KAAU,OAG/C,MAAO,CACLlB,SAAU4B,EAAAA,SAAS5B,GACnBY,SAAUe"}
1
+ {"version":3,"file":"index.cjs","sources":["../../src/vue/hooks/use-rotate.ts","../../src/vue/components/rotate.vue"],"sourcesContent":["import { ref, watch, readonly, computed, toValue, type MaybeRefOrGetter } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { RotatePlugin, initialDocumentState } from '@embedpdf/plugin-rotate';\nimport { Rotation } from '@embedpdf/models';\n\n/**\n * Hook to get the raw rotate plugin instance.\n */\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook to get the rotate plugin's capability API.\n * This provides methods for rotating the document.\n */\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook that provides reactive rotation state and methods for a specific document.\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport const useRotate = (documentId: MaybeRefOrGetter<string>) => {\n const { provides } = useRotateCapability();\n const rotation = ref<Rotation>(initialDocumentState.rotation);\n\n watch(\n [provides, () => toValue(documentId)],\n ([providesValue, docId], _, onCleanup) => {\n if (!providesValue) {\n rotation.value = initialDocumentState.rotation;\n return;\n }\n\n const scope = providesValue.forDocument(docId);\n\n // Get initial state\n rotation.value = scope.getRotation();\n\n // Subscribe to rotation changes\n const unsubscribe = scope.onRotateChange((newRotation) => {\n rotation.value = newRotation;\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 rotation: readonly(rotation),\n provides: scopedProvides,\n };\n};\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport { useDocumentState } from '@embedpdf/core/vue';\nimport { Rotation } from '@embedpdf/models';\nimport { useRotatePlugin } from '../hooks';\n\ninterface RotateProps {\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n}\n\nconst props = defineProps<RotateProps>();\n\nconst { plugin: rotatePlugin } = useRotatePlugin();\nconst documentState = useDocumentState(() => props.documentId);\n\nconst page = computed(() => documentState.value?.document?.pages?.[props.pageIndex]);\nconst width = computed(() => page.value?.size?.width ?? 0);\nconst height = computed(() => page.value?.size?.height ?? 0);\n\n// If override is provided, use it directly (consistent with other layer components)\n// Otherwise, combine page intrinsic rotation with document rotation\nconst pageRotation = computed(() => page.value?.rotation ?? 0);\nconst rotation = computed(() => {\n if (props.rotation !== undefined) return props.rotation;\n const docRotation = documentState.value?.rotation ?? 0;\n return (pageRotation.value + docRotation) % 4;\n});\n\nconst scale = computed(() => {\n if (props.scale !== undefined) return props.scale;\n return documentState.value?.scale ?? 1;\n});\n\nconst matrix = computed(() => {\n if (!rotatePlugin.value) return 'matrix(1, 0, 0, 1, 0, 0)';\n\n return rotatePlugin.value.getMatrixAsString({\n width: width.value * scale.value,\n height: height.value * scale.value,\n rotation: rotation.value,\n });\n});\n</script>\n\n<template>\n <div\n v-if=\"page\"\n :style=\"{\n position: 'absolute',\n transformOrigin: '0 0',\n transform: matrix,\n }\"\n v-bind=\"$attrs\"\n >\n <slot />\n </div>\n</template>\n"],"names":["useRotatePlugin","usePlugin","RotatePlugin","id","useRotateCapability","useCapability","props","__props","plugin","rotatePlugin","documentState","useDocumentState","documentId","page","computed","_c","_b","_a","value","document","pages","pageIndex","width","size","height","pageRotation","rotation","docRotation","scale","matrix","getMatrixAsString","_openBlock","_createElementBlock","_mergeProps","style","$attrs","_renderSlot","_ctx","$slots","provides","ref","initialDocumentState","watch","toValue","providesValue","docId","_","onCleanup","scope","forDocument","getRotation","onRotateChange","newRotation","immediate","scopedProvides","readonly"],"mappings":"4KAQaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAM7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,0GCDlF,MAAMG,EAAQC,GAENC,OAAQC,GAAiBT,IAC3BU,EAAgBC,EAAAA,iBAAiB,IAAML,EAAMM,YAE7CC,EAAOC,WAAS,eAAM,OAAA,OAAAC,EAAA,OAAAC,EAAA,OAAAC,EAAAP,EAAcQ,YAAd,EAAAD,EAAqBE,eAArB,EAAAH,EAA+BI,gBAAQd,EAAMe,aACnEC,EAAQR,EAAAA,SAAS,aAAM,OAAA,OAAAE,EAAA,OAAAC,EAAAJ,EAAKK,YAAL,EAAAD,EAAYM,WAAZ,EAAAP,EAAkBM,QAAS,IAClDE,EAASV,EAAAA,SAAS,aAAM,OAAA,OAAAE,EAAA,OAAAC,EAAAJ,EAAKK,YAAL,EAAAD,EAAYM,WAAZ,EAAAP,EAAkBQ,SAAU,IAIpDC,EAAeX,EAAAA,SAAS,WAA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,SAAU6B,EAAAA,SAAS7B,GACnBa,SAAUe"}
package/dist/vue/index.js CHANGED
@@ -57,10 +57,15 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
57
57
  var _a, _b;
58
58
  return ((_b = (_a = page.value) == null ? void 0 : _a.size) == null ? void 0 : _b.height) ?? 0;
59
59
  });
60
+ const pageRotation = computed(() => {
61
+ var _a;
62
+ return ((_a = page.value) == null ? void 0 : _a.rotation) ?? 0;
63
+ });
60
64
  const rotation = computed(() => {
61
65
  var _a;
62
66
  if (props.rotation !== void 0) return props.rotation;
63
- return ((_a = documentState.value) == null ? void 0 : _a.rotation) ?? 0;
67
+ const docRotation = ((_a = documentState.value) == null ? void 0 : _a.rotation) ?? 0;
68
+ return (pageRotation.value + docRotation) % 4;
64
69
  });
65
70
  const scale = computed(() => {
66
71
  var _a;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-rotate.ts","../../src/vue/components/rotate.vue"],"sourcesContent":["import { ref, watch, readonly, computed, toValue, type MaybeRefOrGetter } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { RotatePlugin, initialDocumentState } from '@embedpdf/plugin-rotate';\nimport { Rotation } from '@embedpdf/models';\n\n/**\n * Hook to get the raw rotate plugin instance.\n */\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook to get the rotate plugin's capability API.\n * This provides methods for rotating the document.\n */\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook that provides reactive rotation state and methods for a specific document.\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport const useRotate = (documentId: MaybeRefOrGetter<string>) => {\n const { provides } = useRotateCapability();\n const rotation = ref<Rotation>(initialDocumentState.rotation);\n\n watch(\n [provides, () => toValue(documentId)],\n ([providesValue, docId], _, onCleanup) => {\n if (!providesValue) {\n rotation.value = initialDocumentState.rotation;\n return;\n }\n\n const scope = providesValue.forDocument(docId);\n\n // Get initial state\n rotation.value = scope.getRotation();\n\n // Subscribe to rotation changes\n const unsubscribe = scope.onRotateChange((newRotation) => {\n rotation.value = newRotation;\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 rotation: readonly(rotation),\n provides: scopedProvides,\n };\n};\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport { useDocumentState } from '@embedpdf/core/vue';\nimport { Rotation } from '@embedpdf/models';\nimport { useRotatePlugin } from '../hooks';\n\ninterface RotateProps {\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n}\n\nconst props = defineProps<RotateProps>();\n\nconst { plugin: rotatePlugin } = useRotatePlugin();\nconst documentState = useDocumentState(() => props.documentId);\n\nconst page = computed(() => documentState.value?.document?.pages?.[props.pageIndex]);\nconst width = computed(() => page.value?.size?.width ?? 0);\nconst height = computed(() => page.value?.size?.height ?? 0);\n\nconst rotation = computed(() => {\n if (props.rotation !== undefined) return props.rotation;\n return documentState.value?.rotation ?? 0;\n});\n\nconst scale = computed(() => {\n if (props.scale !== undefined) return props.scale;\n return documentState.value?.scale ?? 1;\n});\n\nconst matrix = computed(() => {\n if (!rotatePlugin.value) return 'matrix(1, 0, 0, 1, 0, 0)';\n\n return rotatePlugin.value.getMatrixAsString({\n width: width.value * scale.value,\n height: height.value * scale.value,\n rotation: rotation.value,\n });\n});\n</script>\n\n<template>\n <div\n v-if=\"page\"\n :style=\"{\n position: 'absolute',\n transformOrigin: '0 0',\n transform: matrix,\n }\"\n v-bind=\"$attrs\"\n >\n <slot />\n </div>\n</template>\n"],"names":["_openBlock","_createElementBlock","_mergeProps","$attrs","_renderSlot"],"mappings":";;;;AAQO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AAMrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAA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BAAc,UAAd,mBAAqB,aAAY;AAAA,IAC1C,CAAC;AAED,UAAM,QAAQ,SAAS,MAAM;;AAC3B,UAAI,MAAM,UAAU,OAAW,QAAO,MAAM;AAC5C,eAAO,mBAAc,UAAd,mBAAqB,UAAS;AAAA,IACvC,CAAC;AAED,UAAM,SAAS,SAAS,MAAM;AAC5B,UAAI,CAAC,aAAa,MAAO,QAAO;AAEhC,aAAO,aAAa,MAAM,kBAAkB;AAAA,QAC1C,OAAO,MAAM,QAAQ,MAAM;AAAA,QAC3B,QAAQ,OAAO,QAAQ,MAAM;AAAA,QAC7B,UAAU,SAAS;AAAA,MAAA,CACpB;AAAA,IACH,CAAC;;aAKS,KAAA,SADRA,UAAA,GAAAC,mBAUM,OAVNC,WAUM;AAAA;QARH,OAAK;AAAA;;qBAA+E,OAAA;AAAA,QAAA;AAAA,SAK7EC,KAAAA,MAAM,GAAA;AAAA,QAEdC,WAAQ,KAAA,QAAA,SAAA;AAAA,MAAA;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-rotate.ts","../../src/vue/components/rotate.vue"],"sourcesContent":["import { ref, watch, readonly, computed, toValue, type MaybeRefOrGetter } from 'vue';\nimport { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { RotatePlugin, initialDocumentState } from '@embedpdf/plugin-rotate';\nimport { Rotation } from '@embedpdf/models';\n\n/**\n * Hook to get the raw rotate plugin instance.\n */\nexport const useRotatePlugin = () => usePlugin<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook to get the rotate plugin's capability API.\n * This provides methods for rotating the document.\n */\nexport const useRotateCapability = () => useCapability<RotatePlugin>(RotatePlugin.id);\n\n/**\n * Hook that provides reactive rotation state and methods for a specific document.\n * @param documentId Document ID (can be ref, computed, getter, or plain value)\n */\nexport const useRotate = (documentId: MaybeRefOrGetter<string>) => {\n const { provides } = useRotateCapability();\n const rotation = ref<Rotation>(initialDocumentState.rotation);\n\n watch(\n [provides, () => toValue(documentId)],\n ([providesValue, docId], _, onCleanup) => {\n if (!providesValue) {\n rotation.value = initialDocumentState.rotation;\n return;\n }\n\n const scope = providesValue.forDocument(docId);\n\n // Get initial state\n rotation.value = scope.getRotation();\n\n // Subscribe to rotation changes\n const unsubscribe = scope.onRotateChange((newRotation) => {\n rotation.value = newRotation;\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 rotation: readonly(rotation),\n provides: scopedProvides,\n };\n};\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport { useDocumentState } from '@embedpdf/core/vue';\nimport { Rotation } from '@embedpdf/models';\nimport { useRotatePlugin } from '../hooks';\n\ninterface RotateProps {\n documentId: string;\n pageIndex: number;\n rotation?: Rotation;\n scale?: number;\n}\n\nconst props = defineProps<RotateProps>();\n\nconst { plugin: rotatePlugin } = useRotatePlugin();\nconst documentState = useDocumentState(() => props.documentId);\n\nconst page = computed(() => documentState.value?.document?.pages?.[props.pageIndex]);\nconst width = computed(() => page.value?.size?.width ?? 0);\nconst height = computed(() => page.value?.size?.height ?? 0);\n\n// If override is provided, use it directly (consistent with other layer components)\n// Otherwise, combine page intrinsic rotation with document rotation\nconst pageRotation = computed(() => page.value?.rotation ?? 0);\nconst rotation = computed(() => {\n if (props.rotation !== undefined) return props.rotation;\n const docRotation = documentState.value?.rotation ?? 0;\n return (pageRotation.value + docRotation) % 4;\n});\n\nconst scale = computed(() => {\n if (props.scale !== undefined) return props.scale;\n return documentState.value?.scale ?? 1;\n});\n\nconst matrix = computed(() => {\n if (!rotatePlugin.value) return 'matrix(1, 0, 0, 1, 0, 0)';\n\n return rotatePlugin.value.getMatrixAsString({\n width: width.value * scale.value,\n height: height.value * scale.value,\n rotation: rotation.value,\n });\n});\n</script>\n\n<template>\n <div\n v-if=\"page\"\n :style=\"{\n position: 'absolute',\n transformOrigin: '0 0',\n trans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AAkB,UAAS;AAAA,KAAC;AACzD,UAAM,SAAS,SAAS,MAAA;;AAAM,+BAAK,UAAL,mBAAY,SAAZ,mBAAkB,WAAU;AAAA,KAAC;AAI3D,UAAM,eAAe,SAAS,MAAA;;AAAM,yBAAK,UAAL,mBAAY,aAAY;AAAA,KAAC;AAC7D,UAAM,WAAW,SAAS,MAAM;;AAC9B,UAAI,MAAM,aAAa,OAAW,QAAO,MAAM;AAC/C,YAAM,gBAAc,mBAAc,UAAd,mBAAqB,aAAY;AACrD,cAAQ,aAAa,QAAQ,eAAe;AAAA,IAC9C,CAAC;AAED,UAAM,QAAQ,SAAS,MAAM;;AAC3B,UAAI,MAAM,UAAU,OAAW,QAAO,MAAM;AAC5C,eAAO,mBAAc,UAAd,mBAAqB,UAAS;AAAA,IACvC,CAAC;AAED,UAAM,SAAS,SAAS,MAAM;AAC5B,UAAI,CAAC,aAAa,MAAO,QAAO;AAEhC,aAAO,aAAa,MAAM,kBAAkB;AAAA,QAC1C,OAAO,MAAM,QAAQ,MAAM;AAAA,QAC3B,QAAQ,OAAO,QAAQ,MAAM;AAAA,QAC7B,UAAU,SAAS;AAAA,MAAA,CACpB;AAAA,IACH,CAAC;;aAKS,KAAA,SADRA,UAAA,GAAAC,mBAUM,OAVNC,WAUM;AAAA;QARH,OAAK;AAAA;;qBAA+E,OAAA;AAAA,QAAA;AAAA,SAK7EC,KAAAA,MAAM,GAAA;AAAA,QAEdC,WAAQ,KAAA,QAAA,SAAA;AAAA,MAAA;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embedpdf/plugin-rotate",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",
@@ -34,13 +34,13 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@embedpdf/models": "2.4.0"
37
+ "@embedpdf/models": "2.5.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/react": "^18.2.0",
41
41
  "typescript": "^5.0.0",
42
- "@embedpdf/core": "2.4.0",
43
- "@embedpdf/build": "1.1.0"
42
+ "@embedpdf/build": "1.1.0",
43
+ "@embedpdf/core": "2.5.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "preact": "^10.26.4",
@@ -48,7 +48,7 @@
48
48
  "react-dom": ">=16.8.0",
49
49
  "vue": ">=3.2.0",
50
50
  "svelte": ">=5 <6",
51
- "@embedpdf/core": "2.4.0"
51
+ "@embedpdf/core": "2.5.0"
52
52
  },
53
53
  "files": [
54
54
  "dist",