{"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,W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