@embedpdf/plugin-rotate 1.5.0 → 2.0.0-next.1

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/vue"),t=require("@embedpdf/plugin-rotate"),r=require("vue"),o=()=>e.usePlugin(t.RotatePlugin.id),a=()=>e.useCapability(t.RotatePlugin.id),i=r.defineComponent({__name:"rotate",props:{pageSize:{}},setup(e){const t=e,{plugin:a}=o(),i=r.computed((()=>a.value?a.value.getMatrixAsString({w:t.pageSize.width,h:t.pageSize.height}):"matrix(1, 0, 0, 1, 0, 0)"));return(e,t)=>(r.openBlock(),r.createElementBlock("div",{style:r.normalizeStyle({position:"absolute",transformOrigin:"0 0",transform:i.value})},[r.renderSlot(e.$slots,"default")],4))}});exports.Rotate=i,exports.useRotate=()=>{const{provides:e}=a(),t=r.ref(0);return r.watchEffect((r=>{if(!e.value)return;r(e.value.onRotateChange((e=>{t.value=e})))})),{rotation:t,provides:e}},exports.useRotateCapability=a,exports.useRotatePlugin=o,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 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]})});
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 { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { RotatePlugin } from '@embedpdf/plugin-rotate';\nimport { ref, watchEffect } from 'vue';\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.\n */\nexport const useRotate = () => {\n const { provides } = useRotateCapability();\n const rotation = ref<Rotation>(0);\n\n watchEffect((onCleanup) => {\n if (!provides.value) return;\n\n const unsubscribe = provides.value.onRotateChange((newRotation) => {\n rotation.value = newRotation;\n });\n onCleanup(unsubscribe);\n });\n\n return {\n rotation,\n provides,\n };\n};\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport type { Size } from '@embedpdf/models';\nimport { useRotatePlugin } from '../hooks';\n\ninterface Props {\n pageSize: Size;\n}\n\nconst props = defineProps<Props>();\n\nconst { plugin: rotate } = useRotatePlugin();\n\nconst transformMatrix = computed(() => {\n // If the capability is not yet available, return an identity matrix.\n if (!rotate.value) {\n return 'matrix(1, 0, 0, 1, 0, 0)';\n }\n\n // Get the CSS transform matrix string from the capability.\n return rotate.value.getMatrixAsString({\n w: props.pageSize.width,\n h: props.pageSize.height,\n });\n});\n</script>\n\n<template>\n <div\n :style=\"{\n position: 'absolute',\n transformOrigin: '0 0',\n transform: transformMatrix,\n }\"\n >\n <slot />\n </div>\n</template>\n"],"names":["useRotatePlugin","usePlugin","RotatePlugin","id","useRotateCapability","useCapability","props","__props","plugin","rotate","transformMatrix","computed","value","getMatrixAsString","w","pageSize","width","h","height","_createElementBlock","createElementBlock","style","_normalizeStyle","_renderSlot","_ctx","$slots","provides","rotation","ref","vue$1","watchEffect","onCleanup","onRotateChange","newRotation"],"mappings":"4KAQaA,EAAkB,IAAMC,YAAwBC,EAAAA,aAAaC,IAM7DC,EAAsB,IAAMC,gBAA4BH,EAAAA,aAAaC,sECLlF,MAAMG,EAAQC,GAENC,OAAQC,GAAWT,IAErBU,EAAkBC,EAAAA,UAAS,IAE1BF,EAAOG,MAKLH,EAAOG,MAAMC,kBAAkB,CACpCC,EAAGR,EAAMS,SAASC,MAClBC,EAAGX,EAAMS,SAASG,SANX,yDAYTC,EAAAC,mBAQM,MAAA,CAPHC,MAAKC,EAAAA,eAAA,qDAA+EZ,EAAeE,UAMpGW,aAAQC,EAAAC,OAAA,sDDhBa,KACjB,MAAAC,SAAEA,GAAatB,IACfuB,EAAWC,MAAc,GAWxB,OATPC,EAAAC,aAAaC,IACP,IAACL,EAASd,MAAO,OAKrBmB,EAHoBL,EAASd,MAAMoB,gBAAgBC,IACjDN,EAASf,MAAQqB,CAAA,IAEE,IAGhB,CACLN,WACAD,WACF"}
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,EAAs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AAQ7B,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"}
package/dist/vue/index.js CHANGED
@@ -1,51 +1,91 @@
1
- import { usePlugin, useCapability } from "@embedpdf/core/vue";
2
- import { RotatePlugin } from "@embedpdf/plugin-rotate";
1
+ import { ref, watch, toValue, computed, readonly, defineComponent, createElementBlock, createCommentVNode, openBlock, mergeProps, renderSlot } from "vue";
2
+ import { usePlugin, useCapability, useDocumentState } from "@embedpdf/core/vue";
3
+ import { RotatePlugin, initialDocumentState } from "@embedpdf/plugin-rotate";
3
4
  export * from "@embedpdf/plugin-rotate";
4
- import { ref, watchEffect, defineComponent, computed, createElementBlock, openBlock, normalizeStyle, renderSlot } from "vue";
5
5
  const useRotatePlugin = () => usePlugin(RotatePlugin.id);
6
6
  const useRotateCapability = () => useCapability(RotatePlugin.id);
7
- const useRotate = () => {
7
+ const useRotate = (documentId) => {
8
8
  const { provides } = useRotateCapability();
9
- const rotation = ref(0);
10
- watchEffect((onCleanup) => {
11
- if (!provides.value) return;
12
- const unsubscribe = provides.value.onRotateChange((newRotation) => {
13
- rotation.value = newRotation;
14
- });
15
- onCleanup(unsubscribe);
9
+ const rotation = ref(initialDocumentState.rotation);
10
+ watch(
11
+ [provides, () => toValue(documentId)],
12
+ ([providesValue, docId], _, onCleanup) => {
13
+ if (!providesValue) {
14
+ rotation.value = initialDocumentState.rotation;
15
+ return;
16
+ }
17
+ const scope = providesValue.forDocument(docId);
18
+ rotation.value = scope.getRotation();
19
+ const unsubscribe = scope.onRotateChange((newRotation) => {
20
+ rotation.value = newRotation;
21
+ });
22
+ onCleanup(unsubscribe);
23
+ },
24
+ { immediate: true }
25
+ );
26
+ const scopedProvides = computed(() => {
27
+ var _a;
28
+ const docId = toValue(documentId);
29
+ return ((_a = provides.value) == null ? void 0 : _a.forDocument(docId)) ?? null;
16
30
  });
17
31
  return {
18
- rotation,
19
- provides
32
+ rotation: readonly(rotation),
33
+ provides: scopedProvides
20
34
  };
21
35
  };
22
36
  const _sfc_main = /* @__PURE__ */ defineComponent({
23
37
  __name: "rotate",
24
38
  props: {
25
- pageSize: {}
39
+ documentId: {},
40
+ pageIndex: {},
41
+ rotation: {},
42
+ scale: {}
26
43
  },
27
44
  setup(__props) {
28
45
  const props = __props;
29
- const { plugin: rotate } = useRotatePlugin();
30
- const transformMatrix = computed(() => {
31
- if (!rotate.value) {
32
- return "matrix(1, 0, 0, 1, 0, 0)";
33
- }
34
- return rotate.value.getMatrixAsString({
35
- w: props.pageSize.width,
36
- h: props.pageSize.height
46
+ const { plugin: rotatePlugin } = useRotatePlugin();
47
+ const documentState = useDocumentState(() => props.documentId);
48
+ const page = computed(() => {
49
+ var _a, _b, _c;
50
+ return (_c = (_b = (_a = documentState.value) == null ? void 0 : _a.document) == null ? void 0 : _b.pages) == null ? void 0 : _c[props.pageIndex];
51
+ });
52
+ const width = computed(() => {
53
+ var _a, _b;
54
+ return ((_b = (_a = page.value) == null ? void 0 : _a.size) == null ? void 0 : _b.width) ?? 0;
55
+ });
56
+ const height = computed(() => {
57
+ var _a, _b;
58
+ return ((_b = (_a = page.value) == null ? void 0 : _a.size) == null ? void 0 : _b.height) ?? 0;
59
+ });
60
+ const rotation = computed(() => {
61
+ var _a;
62
+ if (props.rotation !== void 0) return props.rotation;
63
+ return ((_a = documentState.value) == null ? void 0 : _a.rotation) ?? 0;
64
+ });
65
+ const scale = computed(() => {
66
+ var _a;
67
+ if (props.scale !== void 0) return props.scale;
68
+ return ((_a = documentState.value) == null ? void 0 : _a.scale) ?? 1;
69
+ });
70
+ const matrix = computed(() => {
71
+ if (!rotatePlugin.value) return "matrix(1, 0, 0, 1, 0, 0)";
72
+ return rotatePlugin.value.getMatrixAsString({
73
+ width: width.value * scale.value,
74
+ height: height.value * scale.value,
75
+ rotation: rotation.value
37
76
  });
38
77
  });
39
78
  return (_ctx, _cache) => {
40
- return openBlock(), createElementBlock("div", {
41
- style: normalizeStyle({
79
+ return page.value ? (openBlock(), createElementBlock("div", mergeProps({
80
+ key: 0,
81
+ style: {
42
82
  position: "absolute",
43
83
  transformOrigin: "0 0",
44
- transform: transformMatrix.value
45
- })
46
- }, [
84
+ transform: matrix.value
85
+ }
86
+ }, _ctx.$attrs), [
47
87
  renderSlot(_ctx.$slots, "default")
48
- ], 4);
88
+ ], 16)) : createCommentVNode("", true);
49
89
  };
50
90
  }
51
91
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/vue/hooks/use-rotate.ts","../../src/vue/components/rotate.vue"],"sourcesContent":["import { useCapability, usePlugin } from '@embedpdf/core/vue';\nimport { RotatePlugin } from '@embedpdf/plugin-rotate';\nimport { ref, watchEffect } from 'vue';\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.\n */\nexport const useRotate = () => {\n const { provides } = useRotateCapability();\n const rotation = ref<Rotation>(0);\n\n watchEffect((onCleanup) => {\n if (!provides.value) return;\n\n const unsubscribe = provides.value.onRotateChange((newRotation) => {\n rotation.value = newRotation;\n });\n onCleanup(unsubscribe);\n });\n\n return {\n rotation,\n provides,\n };\n};\n","<script setup lang=\"ts\">\nimport { computed } from 'vue';\nimport type { Size } from '@embedpdf/models';\nimport { useRotatePlugin } from '../hooks';\n\ninterface Props {\n pageSize: Size;\n}\n\nconst props = defineProps<Props>();\n\nconst { plugin: rotate } = useRotatePlugin();\n\nconst transformMatrix = computed(() => {\n // If the capability is not yet available, return an identity matrix.\n if (!rotate.value) {\n return 'matrix(1, 0, 0, 1, 0, 0)';\n }\n\n // Get the CSS transform matrix string from the capability.\n return rotate.value.getMatrixAsString({\n w: props.pageSize.width,\n h: props.pageSize.height,\n });\n});\n</script>\n\n<template>\n <div\n :style=\"{\n position: 'absolute',\n transformOrigin: '0 0',\n transform: transformMatrix,\n }\"\n >\n <slot />\n </div>\n</template>\n"],"names":["_createElementBlock","_normalizeStyle","_renderSlot"],"mappings":";;;;AAQO,MAAM,kBAAkB,MAAM,UAAwB,aAAa,EAAE;AAMrE,MAAM,sBAAsB,MAAM,cAA4B,aAAa,EAAE;AAK7E,MAAM,YAAY,MAAM;AACvB,QAAA,EAAE,SAAS,IAAI,oBAAoB;AACnC,QAAA,WAAW,IAAc,CAAC;AAEhC,cAAY,CAAC,cAAc;AACrB,QAAA,CAAC,SAAS,MAAO;AAErB,UAAM,cAAc,SAAS,MAAM,eAAe,CAAC,gBAAgB;AACjE,eAAS,QAAQ;AAAA,IAAA,CAClB;AACD,cAAU,WAAW;AAAA,EAAA,CACtB;AAEM,SAAA;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;;;;;;;AC3BA,UAAM,QAAQ;AAEd,UAAM,EAAE,QAAQ,OAAO,IAAI,gBAAgB;AAErC,UAAA,kBAAkB,SAAS,MAAM;AAEjC,UAAA,CAAC,OAAO,OAAO;AACV,eAAA;AAAA,MAAA;AAIF,aAAA,OAAO,MAAM,kBAAkB;AAAA,QACpC,GAAG,MAAM,SAAS;AAAA,QAClB,GAAG,MAAM,SAAS;AAAA,MAAA,CACnB;AAAA,IAAA,CACF;;0BAICA,mBAQM,OAAA;AAAA,QAPH,OAAKC,eAAA;AAAA;;qBAA+E,gBAAe;AAAA;;QAMpGC,WAAQ,KAAA,QAAA,SAAA;AAAA;;;;"}
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,EAAE;AAM7E,MAAM,YAAY,CAAC,eAAyC;AACjE,QAAM,EAAE,SAAA,IAAa,oBAAA;AACrB,QAAM,WAAW,IAAc,qBAAqB,QAAQ;AAE5D;AAAA,IACE,CAAC,UAAU,MAAM,QAAQ,UAAU,CAAC;AAAA,IACpC,CAAC,CAAC,eAAe,KAAK,GAAG,GAAG,cAAc;AACxC,UAAI,CAAC,eAAe;AAClB,iBAAS,QAAQ,qBAAqB;AACtC;AAAA,MACF;AAEA,YAAM,QAAQ,cAAc,YAAY,KAAK;AAG7C,eAAS,QAAQ,MAAM,YAAA;AAGvB,YAAM,cAAc,MAAM,eAAe,CAAC,gBAAg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A,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": "1.5.0",
3
+ "version": "2.0.0-next.1",
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": "1.5.0"
37
+ "@embedpdf/models": "2.0.0-next.1"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/react": "^18.2.0",
41
41
  "typescript": "^5.0.0",
42
42
  "@embedpdf/build": "1.1.0",
43
- "@embedpdf/core": "1.5.0"
43
+ "@embedpdf/core": "2.0.0-next.1"
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": "1.5.0"
51
+ "@embedpdf/core": "2.0.0-next.1"
52
52
  },
53
53
  "files": [
54
54
  "dist",