@rocon/balcan 0.0.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.
Files changed (41) hide show
  1. package/dist/core/bitmap.balcan.d.ts +4 -0
  2. package/dist/core/bitmap.balcan.js +22 -0
  3. package/dist/core/core.balcan.d.ts +73 -0
  4. package/dist/core/core.balcan.js +136 -0
  5. package/dist/core/geo.balcan.d.ts +109 -0
  6. package/dist/core/geo.balcan.js +255 -0
  7. package/dist/core/math.balcan.d.ts +35 -0
  8. package/dist/core/math.balcan.js +90 -0
  9. package/dist/core/ts-matrix/Matrix.d.ts +111 -0
  10. package/dist/core/ts-matrix/Matrix.js +243 -0
  11. package/dist/core/ts-matrix/Quat.d.ts +168 -0
  12. package/dist/core/ts-matrix/Quat.js +435 -0
  13. package/dist/core/ts-matrix/Vector.d.ts +145 -0
  14. package/dist/core/ts-matrix/Vector.js +252 -0
  15. package/dist/core/ts-matrix/constants.d.ts +1 -0
  16. package/dist/core/ts-matrix/constants.js +1 -0
  17. package/dist/core/ts-matrix/ts-matrix.d.ts +3 -0
  18. package/dist/core/ts-matrix/ts-matrix.js +31 -0
  19. package/dist/core/types.balcan.d.ts +93 -0
  20. package/dist/core/types.balcan.js +1 -0
  21. package/dist/core/util.balcan.d.ts +23 -0
  22. package/dist/core/util.balcan.js +71 -0
  23. package/dist/core/viewport.balcan.d.ts +27 -0
  24. package/dist/core/viewport.balcan.js +60 -0
  25. package/dist/index.d.ts +13 -0
  26. package/dist/index.js +3 -0
  27. package/dist/mixin/mixin.d.ts +7 -0
  28. package/dist/mixin/mixin.js +7 -0
  29. package/dist/mixin/mixin.type.d.ts +2 -0
  30. package/dist/mixin/mixin.type.js +1 -0
  31. package/dist/staffs/image.staff.d.ts +27 -0
  32. package/dist/staffs/image.staff.js +74 -0
  33. package/dist/staffs/index.d.ts +3 -0
  34. package/dist/staffs/index.js +3 -0
  35. package/dist/staffs/wheelZoom.staff.d.ts +21 -0
  36. package/dist/staffs/wheelZoom.staff.js +45 -0
  37. package/dist/staffs/windowResizeObserver.staff.d.ts +8 -0
  38. package/dist/staffs/windowResizeObserver.staff.js +17 -0
  39. package/dist/types/geometry.d.ts +68 -0
  40. package/dist/types/index.d.ts +1 -0
  41. package/package.json +39 -0
@@ -0,0 +1,74 @@
1
+ import Konva from 'konva';
2
+ /** Image Node 유닛 */
3
+ export function useImageStaff(params, opt) {
4
+ const sourceImage = new Image();
5
+ let renderImage = new Image();
6
+ let transformer;
7
+ sourceImage.src = params.imageSrc;
8
+ renderImage.src = params.imageSrc;
9
+ const offset = { x: opt.offset?.x ?? 0, y: opt.offset?.y ?? 0 };
10
+ const imageNode = new Konva.Image({
11
+ image: renderImage,
12
+ });
13
+ const shapeGroup = new Konva.Group({
14
+ draggable: opt.editable,
15
+ offsetX: offset.x,
16
+ offsetY: offset.y,
17
+ });
18
+ shapeGroup.add(imageNode);
19
+ const me = {
20
+ type: 'image',
21
+ entityId: params.entityId,
22
+ uniqueId: 'image-' + params.entityId,
23
+ plugins: [],
24
+ data: {
25
+ entityId: params.entityId,
26
+ imageNode: shapeGroup,
27
+ sourceImage,
28
+ renderImage,
29
+ },
30
+ addPlugin: (plugin) => me.plugins.push(plugin),
31
+ removePlugin: (pluginKey) => {
32
+ me.plugins = me.plugins.filter((p) => p.uniqueId !== pluginKey);
33
+ },
34
+ changeImage,
35
+ translate: (x, y) => {
36
+ shapeGroup.x(x);
37
+ shapeGroup.y(y);
38
+ },
39
+ rotate: (deg) => shapeGroup.rotation(deg),
40
+ scale: (n) => shapeGroup.scale({ x: n, y: n }),
41
+ onDestroy: () => {
42
+ shapeGroup.destroy();
43
+ },
44
+ };
45
+ if (opt.editable) {
46
+ const tr = makeTransformer();
47
+ me.data.transformer = tr;
48
+ }
49
+ opt.director.addStaff(me);
50
+ me.data.imageNode = shapeGroup;
51
+ return me;
52
+ ///////////////////////////////////////////////
53
+ /** 렌더링 되는 이미지를 교체할 수 있음 */
54
+ function changeImage(newImage) {
55
+ renderImage = newImage;
56
+ imageNode.image(renderImage);
57
+ }
58
+ function makeTransformer() {
59
+ transformer = new Konva.Transformer({
60
+ nodes: [shapeGroup],
61
+ keepRatio: true,
62
+ flipEnabled: false,
63
+ enabledAnchors: [],
64
+ });
65
+ transformer.on('transform', () => {
66
+ const scale = shapeGroup.scaleX();
67
+ const rotation = shapeGroup.rotation();
68
+ const x = shapeGroup.x();
69
+ const y = shapeGroup.y();
70
+ params.onTransform?.({ x, y, scale, rotation });
71
+ });
72
+ return transformer;
73
+ }
74
+ }
@@ -0,0 +1,3 @@
1
+ export * from './wheelZoom.staff';
2
+ export * from './image.staff';
3
+ export * from './windowResizeObserver.staff';
@@ -0,0 +1,3 @@
1
+ export * from './wheelZoom.staff';
2
+ export * from './image.staff';
3
+ export * from './windowResizeObserver.staff';
@@ -0,0 +1,21 @@
1
+ import type { Director } from '../core/types.balcan';
2
+ export type BalcanZoomStaff = ReturnType<typeof useWheelZoomStaff>;
3
+ /** 마우스 휠로 줌 인/아웃을 조작할 수 있는 Staff */
4
+ export declare function useWheelZoomStaff(opt: {
5
+ uuid: string;
6
+ director: Director;
7
+ minScale?: number;
8
+ maxScale?: number;
9
+ }): {
10
+ type: "zoom";
11
+ entityId: string;
12
+ uniqueId: string;
13
+ data: any;
14
+ director?: Director;
15
+ plugins: import("../core/types.balcan").Plugin[];
16
+ addPlugin?: (plugin: import("../core/types.balcan").Plugin) => void;
17
+ removePlugin?: (pluginKey: string) => void;
18
+ onDestroy?: () => void;
19
+ onBeforeRender?: () => void;
20
+ onRender?: () => void;
21
+ };
@@ -0,0 +1,45 @@
1
+ /** 마우스 휠로 줌 인/아웃을 조작할 수 있는 Staff */
2
+ export function useWheelZoomStaff(opt) {
3
+ const { director, minScale = 0.2, maxScale = 3 } = opt ?? {};
4
+ const $staff = {
5
+ type: 'zoom',
6
+ uniqueId: opt.uuid,
7
+ director,
8
+ entityId: opt.uuid ?? '',
9
+ plugins: [],
10
+ data: {},
11
+ onDestroy() {
12
+ director.stage.off('wheel');
13
+ },
14
+ };
15
+ director.stage.on('wheel', (e) => {
16
+ e.evt.preventDefault();
17
+ const exponentedScale = Math.min(30, Math.E ** (director.scale / 2));
18
+ const delta = -e.evt.deltaY * 0.0002 * exponentedScale;
19
+ const addedScale = director.scale + delta;
20
+ _setScale(addedScale, true);
21
+ });
22
+ /** 현재 마우스 포인터 위치를 기준으로 줌 인/아웃을 설정합니다 */
23
+ function _setScale(newScale, withPointer = false) {
24
+ const stage = director.stage;
25
+ const sanitizedScale = Math.min(maxScale, Math.max(minScale, newScale));
26
+ if (withPointer) {
27
+ const pointer = withPointer
28
+ ? (stage.getPointerPosition() ?? { x: 0, y: 0 })
29
+ : { x: 0, y: 0 };
30
+ const mousePointTo = {
31
+ x: (pointer.x - stage.x()) / director.scale,
32
+ y: (pointer.y - stage.y()) / director.scale,
33
+ };
34
+ const newPosition = {
35
+ x: pointer.x - mousePointTo.x * sanitizedScale,
36
+ y: pointer.y - mousePointTo.y * sanitizedScale,
37
+ };
38
+ stage.position(newPosition);
39
+ }
40
+ const scale = sanitizedScale;
41
+ director.scale = scale;
42
+ }
43
+ director.addStaff($staff);
44
+ return $staff;
45
+ }
@@ -0,0 +1,8 @@
1
+ import type { Staff, Director } from '../core/types.balcan';
2
+ export type BalcanResizeObserverStaff = Staff<'resizeobserver'>;
3
+ /** */
4
+ export declare function useWindowResizeObserverStaff(opt: {
5
+ uuid?: string;
6
+ director: Director;
7
+ onResizeFunction?: () => void;
8
+ }): BalcanResizeObserverStaff;
@@ -0,0 +1,17 @@
1
+ /** */
2
+ export function useWindowResizeObserverStaff(opt) {
3
+ window.addEventListener('resize', () => {
4
+ opt.onResizeFunction?.();
5
+ });
6
+ opt.onResizeFunction?.();
7
+ const me = {
8
+ type: 'resizeobserver',
9
+ director: opt.director,
10
+ entityId: opt.uuid ?? '',
11
+ uniqueId: 'resizeobserver' + (opt.uuid ? `-${opt.uuid}` : ''),
12
+ plugins: [],
13
+ data: {},
14
+ };
15
+ opt.director.addStaff(me);
16
+ return me;
17
+ }
@@ -0,0 +1,68 @@
1
+ declare namespace BalcanGeo {
2
+ type Vector2 = {
3
+ x: number;
4
+ y: number;
5
+ };
6
+
7
+ /**
8
+ * 서버에 저장되는 형태의 현실 좌표계 상의 위치정보
9
+ * 수학좌표게를 따르므로 y축은 위로 갈 수록 증가
10
+ * 거리는 미터 단위
11
+ **/
12
+ type Pose = {
13
+ x: number;
14
+ y: number;
15
+ theta: number;
16
+ };
17
+
18
+ /**
19
+ * 렌더링을 위한 화면 좌표계 상의 위치정보
20
+ * 화면좌표계를 따르므로 y축은 아래로 갈 수록 증가
21
+ * 거리는 픽셀 단위
22
+ **/
23
+ type Position = {
24
+ stagex: number;
25
+ stagey: number;
26
+ degree: number;
27
+ };
28
+
29
+ type PoseDegree = Pose & {
30
+ degree: number;
31
+ };
32
+
33
+ type PosePosition = {
34
+ position: Position;
35
+ pose: Pose;
36
+ };
37
+
38
+ /** pose + position + 회전을반영한position 을 실시간 반영할 수 있는 프록시 객체 */
39
+ type PoseProxy = PosePosition & {
40
+ positionRender: Position;
41
+ };
42
+
43
+ /** 실좌표계의 사격형 넓이 */
44
+ type AreaMeter = {
45
+ width: number;
46
+ height: number;
47
+ };
48
+
49
+ /** 실좌표계의 사격형 넓이와 중심점 위치를 표현 */
50
+ type PoseArea = Pose & AreaMeter;
51
+
52
+ /** 사각형의 넓이와 회전값만을 표현 (위치는 없음) */
53
+ type PoseDegreeArea = PoseDegree & AreaMeter;
54
+
55
+ /** 픽셀 단위계의 사격형 넓이 */
56
+ type AreaPixel = {
57
+ widthPx: number;
58
+ heightPx: number;
59
+ scaleX: number;
60
+ scaleY: number;
61
+ };
62
+
63
+ /** 실좌표계와 픽셀좌표계 간 사각형 넓이 단위를 자동으로 변환해 주는 프록시 객체 */
64
+ type AreaProxy = {
65
+ area: AreaMeter;
66
+ areaPixel: AreaPixel;
67
+ };
68
+ }
@@ -0,0 +1 @@
1
+ /// <reference path="./geometry.d.ts" />
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@rocon/balcan",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "scripts": {
6
+ "dev": "tsc -p tsconfig.json --watch --noEmit",
7
+ "build": "tsc -p tsconfig.build.json && node scripts/postbuild.mjs"
8
+ },
9
+ "author": "",
10
+ "license": "ISC",
11
+ "dependencies": {
12
+ "lodash": "^4.17.21"
13
+ },
14
+ "devDependencies": {
15
+ "@eslint/js": "^9.26.0",
16
+ "@rocon/balcan": "file:./balcan",
17
+ "@rocon/balcan.monday": "file:./monday",
18
+ "@types/lodash": "^4.17.16",
19
+ "@types/node": "^20.5.9",
20
+ "@typescript-eslint/parser": "^8.30.1",
21
+ "eslint": "^9.26.0",
22
+ "eslint-config-prettier": "^10.1.5",
23
+ "eslint-import-resolver-typescript": "^4.3.2",
24
+ "eslint-plugin-import": "^2.31.0",
25
+ "eslint-plugin-prettier": "^5.4.0",
26
+ "globals": "^16.1.0",
27
+ "prettier": "^3.3.3",
28
+ "typescript": "~5.8.3",
29
+ "typescript-eslint": "^8.32.1"
30
+ },
31
+ "peerDependencies": {
32
+ "konva": "^9.3.22"
33
+ },
34
+ "main": "dist/index.js",
35
+ "types": "dist/index.d.ts",
36
+ "files": [
37
+ "dist"
38
+ ]
39
+ }