@ue-too/board-vue-adapter 0.12.2 → 0.13.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.
- package/Test.vue.d.ts +5 -0
- package/board.vue.d.ts +2 -0
- package/index.js +53 -54
- package/index.js.map +1 -1
- package/package.json +3 -3
package/Test.vue.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type __VLS_Props = {
|
|
2
|
+
test: string;
|
|
3
|
+
};
|
|
4
|
+
declare const _default: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
5
|
+
export default _default;
|
package/board.vue.d.ts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
export default _default;
|
package/index.js
CHANGED
|
@@ -1,90 +1,89 @@
|
|
|
1
|
-
import { provide as
|
|
2
|
-
import { Board as
|
|
3
|
-
const
|
|
4
|
-
function
|
|
5
|
-
|
|
1
|
+
import { provide as p, inject as f, watch as _, shallowRef as v, onMounted as c, onUnmounted as B, computed as b, defineComponent as s, ref as h, createElementBlock as i, openBlock as u } from "vue";
|
|
2
|
+
import { Board as l } from "@ue-too/board";
|
|
3
|
+
const m = Symbol("BOARD");
|
|
4
|
+
function F() {
|
|
5
|
+
p(m, new l());
|
|
6
6
|
}
|
|
7
7
|
function r() {
|
|
8
|
-
const
|
|
9
|
-
if (!
|
|
8
|
+
const n = f(m);
|
|
9
|
+
if (!n)
|
|
10
10
|
throw new Error(
|
|
11
11
|
"Board not found, are you using useBoard in a component that is not a child of a board provider?"
|
|
12
12
|
);
|
|
13
|
-
return
|
|
13
|
+
return n;
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
() =>
|
|
19
|
-
(
|
|
20
|
-
|
|
15
|
+
function S(n) {
|
|
16
|
+
const e = r();
|
|
17
|
+
_(
|
|
18
|
+
() => n,
|
|
19
|
+
(o) => {
|
|
20
|
+
e.cameraMux = o;
|
|
21
21
|
},
|
|
22
22
|
{ immediate: !0 }
|
|
23
23
|
);
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
const
|
|
27
|
-
return
|
|
28
|
-
t.value =
|
|
25
|
+
function k(n) {
|
|
26
|
+
const e = r(), o = e.camera[n], t = v(o);
|
|
27
|
+
return e.camera.on(n === "position" ? "pan" : n === "zoomLevel" ? "zoom" : "rotate", (a, d) => {
|
|
28
|
+
t.value = d[n];
|
|
29
29
|
}), t;
|
|
30
30
|
}
|
|
31
|
-
function w(
|
|
32
|
-
let
|
|
33
|
-
const
|
|
34
|
-
|
|
31
|
+
function w(n) {
|
|
32
|
+
let e = null;
|
|
33
|
+
const o = (t) => {
|
|
34
|
+
n?.(t), e = requestAnimationFrame(o);
|
|
35
35
|
};
|
|
36
36
|
c(() => {
|
|
37
|
-
|
|
38
|
-
}),
|
|
39
|
-
|
|
37
|
+
e = requestAnimationFrame(o);
|
|
38
|
+
}), B(() => {
|
|
39
|
+
e !== null && cancelAnimationFrame(e);
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
|
-
function x(
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
const a =
|
|
42
|
+
function x(n) {
|
|
43
|
+
const e = r(), o = b(() => (t) => {
|
|
44
|
+
e.step(t);
|
|
45
|
+
const a = e.context;
|
|
46
46
|
if (a == null) {
|
|
47
47
|
console.warn("Canvas context not available");
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
n?.(t, a);
|
|
51
51
|
});
|
|
52
52
|
w((t) => {
|
|
53
|
-
|
|
53
|
+
o.value(t);
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
-
const
|
|
56
|
+
const y = /* @__PURE__ */ s({
|
|
57
57
|
__name: "board",
|
|
58
|
-
setup(
|
|
59
|
-
const
|
|
58
|
+
setup(n) {
|
|
59
|
+
const e = h(null), o = new l();
|
|
60
60
|
return c(() => {
|
|
61
|
-
|
|
61
|
+
e.value ? o.attach(e.value) : o.tearDown();
|
|
62
62
|
}), x((t, a) => {
|
|
63
|
-
|
|
64
|
-
}), (t, a) => (
|
|
63
|
+
o.step(t), a.fillStyle = "red", a.fillRect(0, 0, 100, 100);
|
|
64
|
+
}), (t, a) => (u(), i("canvas", {
|
|
65
65
|
ref_key: "canvas",
|
|
66
|
-
ref:
|
|
66
|
+
ref: e
|
|
67
67
|
}, " Your browser does not support the canvas tag. ", 512));
|
|
68
68
|
}
|
|
69
|
-
}),
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
const g = /* @__PURE__ */ A(C, [["render", F]]);
|
|
69
|
+
}), M = /* @__PURE__ */ s({
|
|
70
|
+
__name: "Test",
|
|
71
|
+
props: {
|
|
72
|
+
test: {}
|
|
73
|
+
},
|
|
74
|
+
setup(n) {
|
|
75
|
+
return (e, o) => (u(), i("div", null, "Test 1"));
|
|
76
|
+
}
|
|
77
|
+
});
|
|
79
78
|
export {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
m as BOARD_SYMBOL,
|
|
80
|
+
y as Board,
|
|
81
|
+
M as Test,
|
|
82
|
+
F as provideBoard,
|
|
84
83
|
w as useAnimationFrame,
|
|
85
84
|
x as useAnimationFrameWithBoard,
|
|
86
85
|
r as useBoard,
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
k as useCameraState,
|
|
87
|
+
S as useCustomCameraMux
|
|
89
88
|
};
|
|
90
89
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/useBoard.ts","../src/board.vue","../src/Test.vue"],"sourcesContent":["import { provide, inject, watch, onMounted, onUnmounted, computed, type ShallowRef, shallowRef } from \"vue\";\nimport { Board, CameraMux, CameraState } from \"@ue-too/board\";\nimport { type Ref } from \"vue\";\n\nexport const BOARD_SYMBOL = Symbol(\"BOARD\");\n\nexport function provideBoard() {\n provide(BOARD_SYMBOL, new Board());\n}\n\nexport function useBoard() {\n const board = inject<Board>(BOARD_SYMBOL);\n if (!board) {\n throw new Error(\n \"Board not found, are you using useBoard in a component that is not a child of a board provider?\"\n );\n }\n return board;\n}\n\nexport function useCustomCameraMux(cameraMux: CameraMux) {\n const board = useBoard();\n watch(\n () => cameraMux,\n (newMux) => {\n board.cameraMux = newMux;\n },\n { immediate: true }\n );\n}\n\nexport function useCameraState<K extends keyof CameraState>(state: K): ShallowRef<CameraState[K]>{\n const board = useBoard();\n const initialState: CameraState[K] = board.camera[state];\n const stateValue = shallowRef<CameraState[K]>(initialState);\n board.camera.on(state === \"position\" ? \"pan\" : state === \"zoomLevel\" ? \"zoom\" : \"rotate\", (newState, cameraState) => {\n stateValue.value = cameraState[state];\n });\n return stateValue as ShallowRef<CameraState[K]>;\n}\n\n\n/**\n * Hook to run a callback on every animation frame.\n * \n * @param callback - Function to call on each animation frame, receives the current timestamp\n */\nexport function useAnimationFrame(callback?: (timestamp: number) => void) {\n let animationFrameId: number | null = null;\n\n const step = (timestamp: number) => {\n callback?.(timestamp);\n animationFrameId = requestAnimationFrame(step);\n };\n\n onMounted(() => {\n animationFrameId = requestAnimationFrame(step);\n });\n\n onUnmounted(() => {\n if (animationFrameId !== null) {\n cancelAnimationFrame(animationFrameId);\n }\n });\n}\n\n/**\n * Hook to run an animation loop integrated with the Board's step function.\n * \n * @param callback - Optional function to call after board.step(), receives timestamp and canvas context\n */\nexport function useAnimationFrameWithBoard(\n callback?: (timestamp: number, ctx: CanvasRenderingContext2D) => void\n) {\n const board = useBoard();\n\n // Use computed to memoize the callback function (Vue's useCallback equivalent)\n const animationCallback = computed(() => {\n return (timestamp: number) => {\n board.step(timestamp);\n const ctx = board.context;\n if (ctx == undefined) {\n console.warn(\"Canvas context not available\");\n return;\n }\n callback?.(timestamp, ctx);\n };\n });\n\n useAnimationFrame((timestamp) => {\n animationCallback.value(timestamp);\n });\n}\n","<script setup lang=\"ts\">\nimport { ref, onMounted } from \"vue\";\nimport { useAnimationFrameWithBoard, useBoard } from \"./useBoard\";\nimport { Board } from \"@ue-too/board\";\n\nconst canvas = ref<HTMLCanvasElement | null>(null);\nconst board = new Board();\n\nonMounted(() => {\n if (canvas.value) {\n board.attach(canvas.value);\n } else {\n board.tearDown();\n }\n});\n\nuseAnimationFrameWithBoard((timestamp, ctx) => {\n board.step(timestamp);\n ctx.fillStyle = \"red\";\n ctx.fillRect(0, 0, 100, 100);\n});\n</script>\n\n<template>\n <canvas ref=\"canvas\"> Your browser does not support the canvas tag. </canvas>\n</template>\n","<template>\n <div>Test</div>\n</template>\n\n<script setup lang=\"ts\">\n</script>\n"],"names":["BOARD_SYMBOL","provideBoard","provide","Board","useBoard","board","inject","useCustomCameraMux","cameraMux","watch","newMux","useCameraState","state","initialState","stateValue","shallowRef","newState","cameraState","useAnimationFrame","callback","animationFrameId","step","timestamp","onMounted","onUnmounted","useAnimationFrameWithBoard","animationCallback","computed","ctx","canvas","ref","_createElementBlock","_openBlock"],"mappings":";;AAIO,MAAMA,IAAe,OAAO,OAAO;AAEnC,SAASC,IAAe;AAC7B,EAAAC,EAAQF,GAAc,IAAIG,GAAO;AACnC;AAEO,SAASC,IAAW;AACzB,QAAMC,IAAQC,EAAcN,CAAY;AACxC,MAAI,CAACK;AACH,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAGJ,SAAOA;AACT;AAEO,SAAS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B,EAAU,MAAM;AACd,MAAIM,EAAO,QACTxB,EAAM,OAAOwB,EAAO,KAAK,IAEzBxB,EAAM,SAAA;AAAA,IAEV,CAAC,GAEDoB,EAA2B,CAACH,GAAWM,MAAQ;AAC7C,MAAAvB,EAAM,KAAKiB,CAAS,GACpBM,EAAI,YAAY,OAChBA,EAAI,SAAS,GAAG,GAAG,KAAK,GAAG;AAAA,IAC7B,CAAC,mBAICG,EAA6E,UAAA;AAAA,eAAjE;AAAA,MAAJ,KAAIF;AAAA,IAAA,GAAS,mDAA+C,GAAA;AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/useBoard.ts","../src/board.vue","../src/Test.vue"],"sourcesContent":["import { provide, inject, watch, onMounted, onUnmounted, computed, type ShallowRef, shallowRef } from \"vue\";\nimport { Board, CameraMux, CameraState } from \"@ue-too/board\";\nimport { type Ref } from \"vue\";\n\nexport const BOARD_SYMBOL = Symbol(\"BOARD\");\n\nexport function provideBoard() {\n provide(BOARD_SYMBOL, new Board());\n}\n\nexport function useBoard() {\n const board = inject<Board>(BOARD_SYMBOL);\n if (!board) {\n throw new Error(\n \"Board not found, are you using useBoard in a component that is not a child of a board provider?\"\n );\n }\n return board;\n}\n\nexport function useCustomCameraMux(cameraMux: CameraMux) {\n const board = useBoard();\n watch(\n () => cameraMux,\n (newMux) => {\n board.cameraMux = newMux;\n },\n { immediate: true }\n );\n}\n\nexport function useCameraState<K extends keyof CameraState>(state: K): ShallowRef<CameraState[K]>{\n const board = useBoard();\n const initialState: CameraState[K] = board.camera[state];\n const stateValue = shallowRef<CameraState[K]>(initialState);\n board.camera.on(state === \"position\" ? \"pan\" : state === \"zoomLevel\" ? \"zoom\" : \"rotate\", (newState, cameraState) => {\n stateValue.value = cameraState[state];\n });\n return stateValue as ShallowRef<CameraState[K]>;\n}\n\n\n/**\n * Hook to run a callback on every animation frame.\n * \n * @param callback - Function to call on each animation frame, receives the current timestamp\n */\nexport function useAnimationFrame(callback?: (timestamp: number) => void) {\n let animationFrameId: number | null = null;\n\n const step = (timestamp: number) => {\n callback?.(timestamp);\n animationFrameId = requestAnimationFrame(step);\n };\n\n onMounted(() => {\n animationFrameId = requestAnimationFrame(step);\n });\n\n onUnmounted(() => {\n if (animationFrameId !== null) {\n cancelAnimationFrame(animationFrameId);\n }\n });\n}\n\n/**\n * Hook to run an animation loop integrated with the Board's step function.\n * \n * @param callback - Optional function to call after board.step(), receives timestamp and canvas context\n */\nexport function useAnimationFrameWithBoard(\n callback?: (timestamp: number, ctx: CanvasRenderingContext2D) => void\n) {\n const board = useBoard();\n\n // Use computed to memoize the callback function (Vue's useCallback equivalent)\n const animationCallback = computed(() => {\n return (timestamp: number) => {\n board.step(timestamp);\n const ctx = board.context;\n if (ctx == undefined) {\n console.warn(\"Canvas context not available\");\n return;\n }\n callback?.(timestamp, ctx);\n };\n });\n\n useAnimationFrame((timestamp) => {\n animationCallback.value(timestamp);\n });\n}\n","<script setup lang=\"ts\">\nimport { ref, onMounted } from \"vue\";\nimport { useAnimationFrameWithBoard, useBoard } from \"./useBoard\";\nimport { Board } from \"@ue-too/board\";\n\nconst canvas = ref<HTMLCanvasElement | null>(null);\nconst board = new Board();\n\nonMounted(() => {\n if (canvas.value) {\n board.attach(canvas.value);\n } else {\n board.tearDown();\n }\n});\n\nuseAnimationFrameWithBoard((timestamp, ctx) => {\n board.step(timestamp);\n ctx.fillStyle = \"red\";\n ctx.fillRect(0, 0, 100, 100);\n});\n</script>\n\n<template>\n <canvas ref=\"canvas\"> Your browser does not support the canvas tag. </canvas>\n</template>\n","<template>\n <div>Test 1</div>\n</template>\n\n<script setup lang=\"ts\">\n defineProps<{\n test: string;\n }>();\n</script>\n"],"names":["BOARD_SYMBOL","provideBoard","provide","Board","useBoard","board","inject","useCustomCameraMux","cameraMux","watch","newMux","useCameraState","state","initialState","stateValue","shallowRef","newState","cameraState","useAnimationFrame","callback","animationFrameId","step","timestamp","onMounted","onUnmounted","useAnimationFrameWithBoard","animationCallback","computed","ctx","can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AW;AACpB,cAAQ,KAAK,8BAA8B;AAC3C;AAAA,IACF;AACA,IAAAT,IAAWG,GAAWM,CAAG;AAAA,EAC3B,CACD;AAED,EAAAV,EAAkB,CAACI,MAAc;AAC/B,IAAAI,EAAkB,MAAMJ,CAAS;AAAA,EACnC,CAAC;AACH;;;;ACvFA,UAAMO,IAASC,EAA8B,IAAI,GAC3CzB,IAAQ,IAAIF,EAAA;AAElB,WAAAoB,EAAU,MAAM;AACd,MAAIM,EAAO,QACTxB,EAAM,OAAOwB,EAAO,KAAK,IAEzBxB,EAAM,SAAA;AAAA,IAEV,CAAC,GAEDoB,EAA2B,CAACH,GAAWM,MAAQ;AAC7C,MAAAvB,EAAM,KAAKiB,CAAS,GACpBM,EAAI,YAAY,OAChBA,EAAI,SAAS,GAAG,GAAG,KAAK,GAAG;AAAA,IAC7B,CAAC,mBAICG,EAA6E,UAAA;AAAA,eAAjE;AAAA,MAAJ,KAAIF;AAAA,IAAA,GAAS,mDAA+C,GAAA;AAAA;;;;;;;sBCvBlEG,EAAA,GAAAD,EAAiB,aAAZ,QAAM;AAAA;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ue-too/board-vue-adapter",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.13.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"vue": "^3.5.25"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ue-too/board": "
|
|
29
|
+
"@ue-too/board": "^0.13.0"
|
|
30
30
|
},
|
|
31
31
|
"main": "./index.js",
|
|
32
32
|
"types": "./index.d.ts",
|
|
33
33
|
"module": "./index.js"
|
|
34
|
-
}
|
|
34
|
+
}
|