magic-canvas-yonava 1.0.6 → 1.0.7
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/dist/index.d.ts +7 -8
- package/dist/index.es.js +3335 -0
- package/dist/index.umd.js +1 -0
- package/package.json +8 -5
- package/src/index.ts +1 -1
- package/tsconfig.json +1 -1
- package/vite.config.ts +29 -0
- package/dist/MagicCanvas.vue.d.ts +0 -9
- package/dist/MagicCanvas.vue.js +0 -36
- package/dist/backgroundPattern.d.ts +0 -6
- package/dist/backgroundPattern.js +0 -36
- package/dist/camera/index.d.ts +0 -15
- package/dist/camera/index.js +0 -20
- package/dist/camera/panZoom.d.ts +0 -23
- package/dist/camera/panZoom.js +0 -100
- package/dist/camera/utils.d.ts +0 -17
- package/dist/camera/utils.js +0 -18
- package/dist/coordinates/index.d.ts +0 -44
- package/dist/coordinates/index.js +0 -58
- package/dist/index.js +0 -11
- package/dist/localStorage.d.ts +0 -35
- package/dist/localStorage.js +0 -20
- package/dist/types.d.ts +0 -29
- package/dist/types.js +0 -1
- package/dist/useMagicCanvas.d.ts +0 -2
- package/dist/useMagicCanvas.js +0 -54
package/dist/localStorage.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* a registry for all localStorage keys this application uses
|
|
3
|
-
*/
|
|
4
|
-
export const localKeys = {
|
|
5
|
-
/** camera `panX` state in magic canvas - {@link Camera.state} */
|
|
6
|
-
cameraPanX: (key) => `camera-pan-x-${key}`,
|
|
7
|
-
/** camera `panY` state in magic canvas - {@link Camera.state} */
|
|
8
|
-
cameraPanY: (key) => `camera-pan-y-${key}`,
|
|
9
|
-
/** camera `zoom` state in magic canvas - {@link Camera.state} */
|
|
10
|
-
cameraZoom: (key) => `camera-zoom-${key}`,
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* perform **type safe** localStorage actions
|
|
14
|
-
*/
|
|
15
|
-
export const local = {
|
|
16
|
-
get: (key) => localStorage.getItem(key),
|
|
17
|
-
set: (key, value) => localStorage.setItem(key, value),
|
|
18
|
-
remove: (key) => localStorage.removeItem(key),
|
|
19
|
-
clear: localStorage.clear,
|
|
20
|
-
};
|
package/dist/types.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { Ref } from 'vue';
|
|
2
|
-
import type { DrawPattern } from './backgroundPattern';
|
|
3
|
-
import type { Camera } from './camera';
|
|
4
|
-
export type Coordinate = {
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
};
|
|
8
|
-
export type DrawContent = (ctx: CanvasRenderingContext2D) => void;
|
|
9
|
-
export type DrawFns = {
|
|
10
|
-
content: Ref<DrawContent>;
|
|
11
|
-
backgroundPattern: Ref<DrawPattern>;
|
|
12
|
-
};
|
|
13
|
-
export type MagicCanvasProps = {
|
|
14
|
-
canvas: Ref<HTMLCanvasElement | undefined>;
|
|
15
|
-
camera: Omit<Camera, 'cleanup'>;
|
|
16
|
-
cursorCoordinates: Ref<Coordinate>;
|
|
17
|
-
ref: {
|
|
18
|
-
canvasRef: (canvas: HTMLCanvasElement) => void;
|
|
19
|
-
cleanup: (canvas: HTMLCanvasElement) => void;
|
|
20
|
-
};
|
|
21
|
-
draw: DrawFns;
|
|
22
|
-
};
|
|
23
|
-
export type MagicCanvasOptions = {
|
|
24
|
-
/**
|
|
25
|
-
* a key that is used to track the camera state in localStorage
|
|
26
|
-
*/
|
|
27
|
-
storageKey?: string;
|
|
28
|
-
};
|
|
29
|
-
export type UseMagicCanvas = (options?: MagicCanvasOptions) => MagicCanvasProps;
|
package/dist/types.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/useMagicCanvas.d.ts
DELETED
package/dist/useMagicCanvas.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { useElementSize } from "@vueuse/core";
|
|
2
|
-
import { onMounted, ref, watch } from "vue";
|
|
3
|
-
import { useBackgroundPattern } from "./backgroundPattern";
|
|
4
|
-
import { useCamera } from "./camera";
|
|
5
|
-
import { getDevicePixelRatio } from "./camera/utils";
|
|
6
|
-
import { useMagicCoordinates } from "./coordinates";
|
|
7
|
-
import { getCtx } from "magic-utils-yonava";
|
|
8
|
-
const REPAINT_FPS = 60;
|
|
9
|
-
const initCanvasWidthHeight = (canvas) => {
|
|
10
|
-
if (!canvas)
|
|
11
|
-
throw new Error("Canvas not found in DOM. Check ref link.");
|
|
12
|
-
const dpr = getDevicePixelRatio();
|
|
13
|
-
const rect = canvas.getBoundingClientRect();
|
|
14
|
-
canvas.width = rect.width * dpr;
|
|
15
|
-
canvas.height = rect.height * dpr;
|
|
16
|
-
};
|
|
17
|
-
export const useMagicCanvas = (options = {}) => {
|
|
18
|
-
const canvas = ref();
|
|
19
|
-
const canvasBoxSize = useElementSize(canvas);
|
|
20
|
-
const drawContent = ref(() => { });
|
|
21
|
-
const drawBackgroundPattern = ref(() => { });
|
|
22
|
-
let repaintInterval;
|
|
23
|
-
onMounted(() => {
|
|
24
|
-
initCanvasWidthHeight(canvas.value);
|
|
25
|
-
repaintInterval = setInterval(repaintCanvas, 1000 / REPAINT_FPS);
|
|
26
|
-
});
|
|
27
|
-
watch([canvasBoxSize.width, canvasBoxSize.height], () => initCanvasWidthHeight(canvas.value));
|
|
28
|
-
const { cleanup: cleanupCamera, ...camera } = useCamera(canvas, options?.storageKey ?? "[default-storage-key]");
|
|
29
|
-
const { coordinates: cursorCoordinates, cleanup: cleanupCoords } = useMagicCoordinates(canvas);
|
|
30
|
-
const pattern = useBackgroundPattern(camera.state, drawBackgroundPattern);
|
|
31
|
-
const repaintCanvas = () => {
|
|
32
|
-
const ctx = getCtx(canvas);
|
|
33
|
-
camera.transformAndClear(ctx);
|
|
34
|
-
pattern.draw(ctx);
|
|
35
|
-
drawContent.value(ctx);
|
|
36
|
-
};
|
|
37
|
-
return {
|
|
38
|
-
canvas,
|
|
39
|
-
camera,
|
|
40
|
-
cursorCoordinates,
|
|
41
|
-
ref: {
|
|
42
|
-
canvasRef: (ref) => (canvas.value = ref),
|
|
43
|
-
cleanup: (ref) => {
|
|
44
|
-
cleanupCoords(ref);
|
|
45
|
-
cleanupCamera(ref);
|
|
46
|
-
clearInterval(repaintInterval);
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
draw: {
|
|
50
|
-
content: drawContent,
|
|
51
|
-
backgroundPattern: drawBackgroundPattern,
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
|
-
};
|