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