magic-canvas-yonava 1.0.7 → 1.0.8

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.
@@ -0,0 +1,10 @@
1
+ declare const _default: import('vue').DefineComponent<{
2
+ canvasRef: (canvas: HTMLCanvasElement) => void;
3
+ cleanup: (canvas: HTMLCanvasElement) => void;
4
+ }, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<{
5
+ canvasRef: (canvas: HTMLCanvasElement) => void;
6
+ cleanup: (canvas: HTMLCanvasElement) => void;
7
+ }> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {
8
+ canvas: HTMLCanvasElement;
9
+ }, HTMLCanvasElement>;
10
+ export default _default;
@@ -0,0 +1,6 @@
1
+ import { Camera } from './camera';
2
+ import { Coordinate, DrawFns } from './types';
3
+ export type DrawPattern = (ctx: CanvasRenderingContext2D, at: Coordinate, alpha: string) => void;
4
+ export declare const useBackgroundPattern: ({ panX, panY, zoom }: Camera["state"], drawPattern: DrawFns["backgroundPattern"]) => {
5
+ draw: (ctx: CanvasRenderingContext2D) => void;
6
+ };
@@ -0,0 +1,15 @@
1
+ import { Ref } from 'vue';
2
+ export declare const useCamera: (canvas: Ref<HTMLCanvasElement | undefined>, storageKey: string) => {
3
+ transformAndClear: (ctx: CanvasRenderingContext2D) => void;
4
+ actions: {
5
+ zoomIn: (increment?: number) => void;
6
+ zoomOut: (decrement?: number) => void;
7
+ };
8
+ state: {
9
+ panX: import('@vueuse/shared').RemovableRef<number>;
10
+ panY: import('@vueuse/shared').RemovableRef<number>;
11
+ zoom: import('@vueuse/shared').RemovableRef<number>;
12
+ };
13
+ cleanup: (ref: HTMLCanvasElement) => void;
14
+ };
15
+ export type Camera = ReturnType<typeof useCamera>;
@@ -0,0 +1,23 @@
1
+ import { Ref } from 'vue';
2
+ export declare const MIN_ZOOM = 0.2;
3
+ export declare const MAX_ZOOM = 10;
4
+ export declare const ZOOM_SENSITIVITY = 0.02;
5
+ export declare const PAN_SENSITIVITY = 1;
6
+ export declare const usePanAndZoom: (canvas: Ref<HTMLCanvasElement | undefined>, storageKey: string) => {
7
+ actions: {
8
+ zoomIn: (increment?: number) => void;
9
+ zoomOut: (decrement?: number) => void;
10
+ };
11
+ state: {
12
+ panX: import('@vueuse/shared').RemovableRef<number>;
13
+ panY: import('@vueuse/shared').RemovableRef<number>;
14
+ zoom: import('@vueuse/shared').RemovableRef<number>;
15
+ };
16
+ getTransform: () => {
17
+ scaleX: number;
18
+ scaleY: number;
19
+ translateX: number;
20
+ translateY: number;
21
+ };
22
+ cleanup: (ref: HTMLCanvasElement) => void;
23
+ };
@@ -0,0 +1,17 @@
1
+ export type TransformProps = {
2
+ /** corresponds to `a` in {@link CanvasRenderingContext2D.setTransform} */
3
+ scaleX: number;
4
+ /** corresponds to `b` in {@link CanvasRenderingContext2D.setTransform} */
5
+ skewY: number;
6
+ /** corresponds to `c` in {@link CanvasRenderingContext2D.setTransform} */
7
+ skewX: number;
8
+ /** corresponds to `d` in {@link CanvasRenderingContext2D.setTransform} */
9
+ scaleY: number;
10
+ /** corresponds to `e` in {@link CanvasRenderingContext2D.setTransform} */
11
+ translateX: number;
12
+ /** corresponds to `f` in {@link CanvasRenderingContext2D.setTransform} */
13
+ translateY: number;
14
+ };
15
+ export type TransformOptions = Partial<TransformProps>;
16
+ export declare const getDevicePixelRatio: () => number;
17
+ export declare const addTransform: (ctx: CanvasRenderingContext2D, t: TransformOptions) => void;
@@ -0,0 +1,44 @@
1
+ import { Ref } from 'vue';
2
+ import { Coordinate } from '../types';
3
+ export declare const getCanvasTransform: (ctx: CanvasRenderingContext2D) => {
4
+ panX: number;
5
+ panY: number;
6
+ zoom: number;
7
+ };
8
+ /**
9
+ * the coordinates in the real world. aka the browser
10
+ */
11
+ export type ClientCoords = Pick<MouseEvent, "clientX" | "clientY">;
12
+ /**
13
+ * the coordinates in the magic canvas world
14
+ */
15
+ export type MagicCoords = Coordinate;
16
+ export type WithZoom<T> = T & {
17
+ /**
18
+ * the scale factor of the canvas
19
+ */
20
+ zoom: number;
21
+ };
22
+ /**
23
+ * magic coordinates are coordinates transformed by the pan and zoom of the camera.
24
+ *
25
+ * if the user has panned their camera 10px to the left, running this function with
26
+ * `clientCoords` set to (0, 0) will return (-10, 0, 1)
27
+ */
28
+ export declare const getMagicCoordinates: (clientCoords: ClientCoords, ctx: CanvasRenderingContext2D) => WithZoom<MagicCoords>;
29
+ /**
30
+ * client coordinates are the raw coordinates corresponding to the clients physical screen.
31
+ *
32
+ * the top left corner is (0, 0) and bottom right corner is (window.innerWidth, window.innerHeight).
33
+ */
34
+ export declare const getClientCoordinates: (magicCoords: MagicCoords, ctx: CanvasRenderingContext2D) => WithZoom<ClientCoords>;
35
+ export declare const useMagicCoordinates: (canvas: Ref<HTMLCanvasElement | undefined>) => {
36
+ coordinates: Ref<{
37
+ x: number;
38
+ y: number;
39
+ }, Coordinate | {
40
+ x: number;
41
+ y: number;
42
+ }>;
43
+ cleanup: (ref: HTMLCanvasElement) => void;
44
+ };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * a registry for all localStorage keys this application uses
3
+ */
4
+ export declare const localKeys: {
5
+ /** camera `panX` state in magic canvas - {@link Camera.state} */
6
+ readonly cameraPanX: (key: string) => `camera-pan-x-${string}`;
7
+ /** camera `panY` state in magic canvas - {@link Camera.state} */
8
+ readonly cameraPanY: (key: string) => `camera-pan-y-${string}`;
9
+ /** camera `zoom` state in magic canvas - {@link Camera.state} */
10
+ readonly cameraZoom: (key: string) => `camera-zoom-${string}`;
11
+ };
12
+ /**
13
+ * all return values of localStorage are, by default, string.
14
+ * this type allows string to be narrowed to types such as 'true' | 'false'
15
+ */
16
+ type TypeOverride = {};
17
+ type LocalObj = typeof localKeys;
18
+ /**
19
+ * @example
20
+ * type T = TypeOrReturnType<number> // number
21
+ * type TFunc = TypeOrReturnType<() => number> // number
22
+ */
23
+ type TypeOrReturnType<T> = T extends (...args: any[]) => infer U ? U : T;
24
+ type LocalKeys = TypeOrReturnType<LocalObj[keyof LocalObj]>;
25
+ type LocalType<T extends LocalKeys> = T extends keyof TypeOverride ? TypeOverride[T] : string;
26
+ /**
27
+ * perform **type safe** localStorage actions
28
+ */
29
+ export declare const local: {
30
+ get: <T extends LocalKeys>(key: T) => string | null;
31
+ set: <T extends LocalKeys, K extends LocalType<T>>(key: T, value: K) => void;
32
+ remove: <T extends LocalKeys>(key: T) => void;
33
+ clear: () => void;
34
+ };
35
+ export {};
@@ -0,0 +1,29 @@
1
+ import { Ref } from 'vue';
2
+ import { DrawPattern } from './backgroundPattern';
3
+ import { 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;
@@ -0,0 +1,2 @@
1
+ import { UseMagicCanvas } from './types';
2
+ export declare const useMagicCanvas: UseMagicCanvas;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "magic-canvas-yonava",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/vite.config.ts CHANGED
@@ -8,7 +8,7 @@ export default defineConfig({
8
8
  vue(),
9
9
  dts({
10
10
  insertTypesEntry: true,
11
- include: ["src/index.ts"],
11
+ include: ["src/**/*.ts", "src/**/*.vue"],
12
12
  }),
13
13
  ],
14
14
  build: {