@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.
- package/dist/core/bitmap.balcan.d.ts +4 -0
- package/dist/core/bitmap.balcan.js +22 -0
- package/dist/core/core.balcan.d.ts +73 -0
- package/dist/core/core.balcan.js +136 -0
- package/dist/core/geo.balcan.d.ts +109 -0
- package/dist/core/geo.balcan.js +255 -0
- package/dist/core/math.balcan.d.ts +35 -0
- package/dist/core/math.balcan.js +90 -0
- package/dist/core/ts-matrix/Matrix.d.ts +111 -0
- package/dist/core/ts-matrix/Matrix.js +243 -0
- package/dist/core/ts-matrix/Quat.d.ts +168 -0
- package/dist/core/ts-matrix/Quat.js +435 -0
- package/dist/core/ts-matrix/Vector.d.ts +145 -0
- package/dist/core/ts-matrix/Vector.js +252 -0
- package/dist/core/ts-matrix/constants.d.ts +1 -0
- package/dist/core/ts-matrix/constants.js +1 -0
- package/dist/core/ts-matrix/ts-matrix.d.ts +3 -0
- package/dist/core/ts-matrix/ts-matrix.js +31 -0
- package/dist/core/types.balcan.d.ts +93 -0
- package/dist/core/types.balcan.js +1 -0
- package/dist/core/util.balcan.d.ts +23 -0
- package/dist/core/util.balcan.js +71 -0
- package/dist/core/viewport.balcan.d.ts +27 -0
- package/dist/core/viewport.balcan.js +60 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +3 -0
- package/dist/mixin/mixin.d.ts +7 -0
- package/dist/mixin/mixin.js +7 -0
- package/dist/mixin/mixin.type.d.ts +2 -0
- package/dist/mixin/mixin.type.js +1 -0
- package/dist/staffs/image.staff.d.ts +27 -0
- package/dist/staffs/image.staff.js +74 -0
- package/dist/staffs/index.d.ts +3 -0
- package/dist/staffs/index.js +3 -0
- package/dist/staffs/wheelZoom.staff.d.ts +21 -0
- package/dist/staffs/wheelZoom.staff.js +45 -0
- package/dist/staffs/windowResizeObserver.staff.d.ts +8 -0
- package/dist/staffs/windowResizeObserver.staff.js +17 -0
- package/dist/types/geometry.d.ts +68 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +39 -0
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
export default class Vector {
|
|
2
|
+
/** Values of the vector */
|
|
3
|
+
_values;
|
|
4
|
+
constructor(values) {
|
|
5
|
+
// Create matrix filled with 0 by default
|
|
6
|
+
this._values = new Array((values || [0]).length).fill(0);
|
|
7
|
+
if (values) {
|
|
8
|
+
this.values = values;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
get rows() {
|
|
12
|
+
return this.values.length;
|
|
13
|
+
}
|
|
14
|
+
get values() {
|
|
15
|
+
return this._values;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Set values into the vector.
|
|
19
|
+
* If the parameters vector is to wide, the values are cropped to the current vector size.
|
|
20
|
+
* It the parameters vector is to small, remaining cells will be filled with 0.
|
|
21
|
+
* @param newValues Arrays of new values.
|
|
22
|
+
*/
|
|
23
|
+
set values(newValues) {
|
|
24
|
+
const minSize = Math.min(this.values.length, newValues.length);
|
|
25
|
+
for (let i = 0; i < minSize; i++) {
|
|
26
|
+
this.values[i] = newValues[i];
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Calculates the angle in radians between vector and the receiver.
|
|
31
|
+
* @param vector The operand vector
|
|
32
|
+
* @return An angle, between 0 and +π inclusive.
|
|
33
|
+
*/
|
|
34
|
+
angleFrom(vector) {
|
|
35
|
+
if (this.rows !== vector.rows)
|
|
36
|
+
throw new Error('To calculate the angle, vectors must have the same dimension!');
|
|
37
|
+
const dot = this.dot(vector);
|
|
38
|
+
const cos = dot / (this.length() * vector.length());
|
|
39
|
+
return Math.acos(cos);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Calculates the distance between vector and the receiver.
|
|
43
|
+
* Equivalent to |receiver - vector|
|
|
44
|
+
* @param vector The operand vector
|
|
45
|
+
* @return The distance (absolute value) between the two vectors
|
|
46
|
+
*/
|
|
47
|
+
distanceFrom(vector) {
|
|
48
|
+
if (this.rows !== vector.rows)
|
|
49
|
+
throw new Error('To calculate the distance, vectors must have the same dimension!');
|
|
50
|
+
return this.subtract(vector).length();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get a matrix value, from its position
|
|
54
|
+
* @param row Matrix line, from 0 to `rows`
|
|
55
|
+
*/
|
|
56
|
+
at(row) {
|
|
57
|
+
return this.values[row];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get the position, from its matrix value
|
|
61
|
+
* @param value The value to search
|
|
62
|
+
* @return The position of the value, or -1 if not found
|
|
63
|
+
*/
|
|
64
|
+
indexOf(value) {
|
|
65
|
+
return this.values.indexOf(value);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Sets all matrix values to 0
|
|
69
|
+
*/
|
|
70
|
+
reset() {
|
|
71
|
+
this.values = this.values.fill(0);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Add an new row to the matrix, filled with 0
|
|
75
|
+
*/
|
|
76
|
+
addAValue() {
|
|
77
|
+
this.values.push(0);
|
|
78
|
+
return new Vector(this.values);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Check if two matrix are equals, value by value
|
|
82
|
+
* @param mat The matrix against to check equality
|
|
83
|
+
*/
|
|
84
|
+
equals(vec) {
|
|
85
|
+
return (this.rows === vec.rows &&
|
|
86
|
+
this.values.reduce((eql, val, i) => eql && vec.at(i) === val, true));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Negate all values of the vector (get the opposite sign)
|
|
90
|
+
* @return A new vector whose all values have the opposed sign
|
|
91
|
+
*/
|
|
92
|
+
negate() {
|
|
93
|
+
return new Vector(this.values.map((val) => -val));
|
|
94
|
+
}
|
|
95
|
+
/** Get the length of the vector */
|
|
96
|
+
length() {
|
|
97
|
+
return Math.sqrt(this.squaredLength());
|
|
98
|
+
}
|
|
99
|
+
/** Get the squared length of the vector */
|
|
100
|
+
squaredLength() {
|
|
101
|
+
return this.dot(this);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Add all vector values with the same position value of the operand vector
|
|
105
|
+
* @param vector The operand vector
|
|
106
|
+
* @throws Error if the two vectors don't have the same dimension
|
|
107
|
+
* @return a new Vector with the result values
|
|
108
|
+
*/
|
|
109
|
+
add(vector) {
|
|
110
|
+
if (this.rows !== vector.rows)
|
|
111
|
+
throw new Error("Vectors don't have the same dimension!");
|
|
112
|
+
return this.operateOnAllValues((val, i) => val + vector.at(i));
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* subtract all vector values with the same position value of the operand vector
|
|
116
|
+
* @param vector The operand vector
|
|
117
|
+
* @throws Error if the two vectors don't have the same dimension
|
|
118
|
+
* @return a new Vector with the result values
|
|
119
|
+
*/
|
|
120
|
+
subtract(vector) {
|
|
121
|
+
if (this.rows !== vector.rows)
|
|
122
|
+
throw new Error("Vectors don't have the same dimension!");
|
|
123
|
+
return this.operateOnAllValues((val, i) => val - vector.at(i));
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Multiply all vector values with the same position value of the operand vector
|
|
127
|
+
* @param vector The operand vector
|
|
128
|
+
* @throws Error if the two vectors don't have the same dimension
|
|
129
|
+
* @return a new Vector with the result values
|
|
130
|
+
*/
|
|
131
|
+
multiply(vector) {
|
|
132
|
+
if (this.rows !== vector.rows)
|
|
133
|
+
throw new Error("Vectors don't have the same dimension!");
|
|
134
|
+
return this.operateOnAllValues((val, i) => val * vector.at(i));
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Divide all vector values with the same position value of the operand vector
|
|
138
|
+
* Be aware of divisions by 0!
|
|
139
|
+
* @param vector The operand vector
|
|
140
|
+
* @throws Error if the two vectors don't have the same dimension
|
|
141
|
+
* @return a new Vector with the result values
|
|
142
|
+
*/
|
|
143
|
+
divide(vector) {
|
|
144
|
+
if (this.rows !== vector.rows)
|
|
145
|
+
throw new Error("Vectors don't have the same dimension!");
|
|
146
|
+
return this.operateOnAllValues((val, i) => {
|
|
147
|
+
if (vector.at(i) === 0)
|
|
148
|
+
return val;
|
|
149
|
+
return val / vector.at(i);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Computes the product of this vector with a matrix (vector * matrix)
|
|
154
|
+
* The vector is treated as a row vector
|
|
155
|
+
* @param matrix The matrix to multiply with
|
|
156
|
+
* @throws Error if vector.rows != matrix.rows
|
|
157
|
+
* @return A new Vector, result of the multiplication
|
|
158
|
+
*/
|
|
159
|
+
multiplyMatrix(matrix) {
|
|
160
|
+
if (this.rows !== matrix.rows)
|
|
161
|
+
throw new Error('Dimension error! The vector must have the same number of elements as the matrix rows!');
|
|
162
|
+
const resultValues = new Array(matrix.columns);
|
|
163
|
+
for (let j = 0; j < matrix.columns; j++) {
|
|
164
|
+
resultValues[j] = this.values.reduce((sum, element, index) => sum + element * matrix.at(index, j), 0);
|
|
165
|
+
}
|
|
166
|
+
return new Vector(resultValues);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Computes the maximum value of the vector
|
|
170
|
+
* @return The maximum value
|
|
171
|
+
* @throws Error if the vector is empty
|
|
172
|
+
*/
|
|
173
|
+
max() {
|
|
174
|
+
if (this.rows === 0)
|
|
175
|
+
throw new Error('Cannot get the maximum value of an empty vector!');
|
|
176
|
+
return Math.max(...this.values);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Computes the minimum value of the vector
|
|
180
|
+
* @return The minimum value
|
|
181
|
+
* @throws Error if the vector is empty
|
|
182
|
+
*/
|
|
183
|
+
min() {
|
|
184
|
+
if (this.rows === 0)
|
|
185
|
+
throw new Error('Cannot get the minimum value of an empty vector!');
|
|
186
|
+
return Math.min(...this.values);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Rounds all vector values to the nearest integer
|
|
190
|
+
* @return A new vector with the rounded values
|
|
191
|
+
* @throws Error if the vector is empty
|
|
192
|
+
*/
|
|
193
|
+
round() {
|
|
194
|
+
if (this.rows === 0)
|
|
195
|
+
throw new Error('Cannot round an empty vector!');
|
|
196
|
+
return this.operateOnAllValues((x) => Math.round(x));
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Multiply all vector values by the given number
|
|
200
|
+
* @param scale The number to multiply with the values
|
|
201
|
+
*/
|
|
202
|
+
scale(scale) {
|
|
203
|
+
return this.operateOnAllValues((val) => val * scale);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Run a function on all vector values, as a map.
|
|
207
|
+
* @param operation The mapping method
|
|
208
|
+
* @return a new Vector with the operation done on all its values
|
|
209
|
+
*/
|
|
210
|
+
operateOnAllValues(operation) {
|
|
211
|
+
return new Vector(this.values.map(operation));
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Computes the normalized vector
|
|
215
|
+
* @return The normalized vector
|
|
216
|
+
*/
|
|
217
|
+
normalize() {
|
|
218
|
+
const vectorLength = this.length();
|
|
219
|
+
return this.operateOnAllValues((val) => val / vectorLength);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Computes the dot product of vectors
|
|
223
|
+
* @param vector The operand vector
|
|
224
|
+
*/
|
|
225
|
+
dot(vector) {
|
|
226
|
+
return this.values.reduce((res, val, i) => res + val * vector.at(i), 0);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Computes the cross product of vectors
|
|
230
|
+
* @param vector The operand vector
|
|
231
|
+
*/
|
|
232
|
+
cross(vector) {
|
|
233
|
+
if (this.rows < 3 || vector.rows < 3)
|
|
234
|
+
throw new Error('Cross product is possible on 3D vectors only');
|
|
235
|
+
const crossValues = new Array(3);
|
|
236
|
+
crossValues[0] = this.at(1) * vector.at(2) - this.at(2) * vector.at(1);
|
|
237
|
+
crossValues[1] = this.at(2) * vector.at(0) - this.at(0) * vector.at(2);
|
|
238
|
+
crossValues[2] = this.at(0) * vector.at(1) - this.at(1) * vector.at(0);
|
|
239
|
+
return new Vector(crossValues);
|
|
240
|
+
}
|
|
241
|
+
mix(vector, time) {
|
|
242
|
+
return new Vector(this.values.map((val, i) => val + time * (vector.at(i) - val)));
|
|
243
|
+
}
|
|
244
|
+
static get360angle(Va, Vb) {
|
|
245
|
+
if (Va.rows !== 3 || Vb.rows !== 3)
|
|
246
|
+
throw new Error('Vectors must be in 3D!. You can add a 1 dimension if it is missing.');
|
|
247
|
+
return -Math.atan2(Vb.cross(Va).dot(new Vector([0, 0, 1]).normalize()), Va.dot(Vb));
|
|
248
|
+
}
|
|
249
|
+
toString() {
|
|
250
|
+
return `[${this.values.join(', ')}]`;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const EPSILON = 0.00001;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const EPSILON = 0.00001;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2020 Florent Catiau-Tristant
|
|
3
|
+
* Copyright (c) 2012, 2018 Matthias Ferch
|
|
4
|
+
*
|
|
5
|
+
* Project initiated by Matthias Ferch
|
|
6
|
+
* Original library: https://github.com/matthiasferch/tsm
|
|
7
|
+
*
|
|
8
|
+
* Forked and improved by Florent Catiau-Tristant
|
|
9
|
+
* Project homepage: https://github.com/kapcash/tsmatrix
|
|
10
|
+
*
|
|
11
|
+
* This software is provided 'as-is', without any express or implied
|
|
12
|
+
* warranty. In no event will the authors be held liable for any damages arising from the use of this software.
|
|
13
|
+
*
|
|
14
|
+
* Permission is granted to anyone to use this software for any purpose,
|
|
15
|
+
* including commercial applications, and to alter it and redistribute it
|
|
16
|
+
* freely, subject to the following restrictions:
|
|
17
|
+
*
|
|
18
|
+
* 1. The origin of this software must not be misrepresented; you must not
|
|
19
|
+
* claim that you wrote the original software. If you use this software
|
|
20
|
+
* in a product, an acknowledgment in the product documentation would be
|
|
21
|
+
* appreciated but is not required.
|
|
22
|
+
*
|
|
23
|
+
* 2. Altered source versions must be plainly marked as such, and must not
|
|
24
|
+
* be misrepresented as being the original software.
|
|
25
|
+
*
|
|
26
|
+
* 3. This notice may not be removed or altered from any source
|
|
27
|
+
* distribution.
|
|
28
|
+
*/
|
|
29
|
+
export { default as Matrix } from './Matrix';
|
|
30
|
+
export { default as Vector } from './Vector';
|
|
31
|
+
export { default as Quat } from './Quat';
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Director as DirectorClass } from './core.balcan';
|
|
2
|
+
export type Director = DirectorClass;
|
|
3
|
+
/**
|
|
4
|
+
* Staff Layer, Canvas 에서 작동하는 특정한 목적을 지닌 최소 로직 집합이다.
|
|
5
|
+
* 단, 비지니스 로직을 포함하지 않는 포괄적인 기능을 수행해야 한다.
|
|
6
|
+
*
|
|
7
|
+
* @template TYPE 종류를 나타내는 문자열, type 의 값을 리터럴 형식으로 고정하기 위해 쓰임
|
|
8
|
+
* @template TData 자체적으로 가지는 추가 데이터 타입, `data` 프로퍼티의 자료형으로 쓰임
|
|
9
|
+
* @template TReturnExtend 현재 타입을 TReturnExtend 만큼 확장할 수 있음
|
|
10
|
+
*/
|
|
11
|
+
export type Staff<TYPE extends string = any, TData = any, TReturnExtend extends {
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
} = {}> = {
|
|
14
|
+
/** 유닛의 종류 */
|
|
15
|
+
type: TYPE;
|
|
16
|
+
/** 서버측 자원의 uuid를 넣을 수 있음 */
|
|
17
|
+
entityId: string;
|
|
18
|
+
/** stage 에 추가되는 id값, stage 내에서 유일 해아 함 */
|
|
19
|
+
uniqueId: string;
|
|
20
|
+
/** 호출하는 측이 자유롭게 사용할 수 있는 데이터 */
|
|
21
|
+
data: TData;
|
|
22
|
+
/** 이 객체를 소유한 Director */
|
|
23
|
+
director?: Director;
|
|
24
|
+
/** 여기에 붙는 플러그인 */
|
|
25
|
+
plugins: Plugin[];
|
|
26
|
+
/** 하위에 플러그인을 추가 함 */
|
|
27
|
+
addPlugin?: (plugin: Plugin) => void;
|
|
28
|
+
/** 플러그인 제거 */
|
|
29
|
+
removePlugin?: (pluginKey: string) => void;
|
|
30
|
+
onDestroy?: () => void;
|
|
31
|
+
onBeforeRender?: () => void;
|
|
32
|
+
onRender?: () => void;
|
|
33
|
+
} & TReturnExtend;
|
|
34
|
+
/**
|
|
35
|
+
* Actor Layer, 유닛을 조합하여 특정한 목적을 수행하는 로직 집합이다.
|
|
36
|
+
* 비지니스 로직을 포함 할 수 있다.
|
|
37
|
+
*/
|
|
38
|
+
export type Actor<TYPE extends string = any, TData = any, TReturnExtend extends {
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
} = {}> = {
|
|
41
|
+
/** type literal string */
|
|
42
|
+
type: TYPE;
|
|
43
|
+
/** 서버측 자원의 uuid를 넣을 수 있음 */
|
|
44
|
+
entityId: string;
|
|
45
|
+
/** stage 에 추가되는 id값, stage 내에서 유일 해아 함 */
|
|
46
|
+
uniqueId: string;
|
|
47
|
+
/** 호출하는 측이 자유롭게 사용할 수 있는 데이터 */
|
|
48
|
+
data: TData;
|
|
49
|
+
/** 이 객체를 소유한 director, 필요한 경우에만 사용하면 됨 */
|
|
50
|
+
director?: Director;
|
|
51
|
+
plugins: Plugin[];
|
|
52
|
+
addPlugin?: (plugin: Plugin) => void;
|
|
53
|
+
removePlugin?: (pluginKey: string) => void;
|
|
54
|
+
onDestroy?: () => void;
|
|
55
|
+
onBeforeRender?: () => void;
|
|
56
|
+
onRender?: () => void;
|
|
57
|
+
onUpdate?: () => void;
|
|
58
|
+
} & TReturnExtend;
|
|
59
|
+
/**
|
|
60
|
+
* Scene Layer
|
|
61
|
+
* 각 화면의 요구사항이 구현된 로직 집합체
|
|
62
|
+
*/
|
|
63
|
+
export type Scene<TYPE extends string = any, TData = any, TReturnExtend extends {
|
|
64
|
+
[key: string]: unknown;
|
|
65
|
+
} = {}> = {
|
|
66
|
+
/** type literal string */
|
|
67
|
+
type: TYPE;
|
|
68
|
+
/** stage 에 추가되는 키값, stage 내에서 유일 해아 함 */
|
|
69
|
+
uniqueId: string;
|
|
70
|
+
/** 앱에서 자유롭게 사용할 수 있는 데이터 */
|
|
71
|
+
data: TData;
|
|
72
|
+
/** 앱이 소속되는 스테이지 객체 */
|
|
73
|
+
director: Director;
|
|
74
|
+
} & TReturnExtend;
|
|
75
|
+
/**
|
|
76
|
+
* 플러그인 정의, 실제 사용할 때는 확장해서 사용 권장
|
|
77
|
+
* @template T 플러그인이 자체적으로 가지는 추가 데이터 타입
|
|
78
|
+
*/
|
|
79
|
+
export interface Plugin<TYPE extends string = any, TData = any> {
|
|
80
|
+
type: TYPE;
|
|
81
|
+
/** 스테이지 위에 추가되는 plugin 은 다른 plugin 과 배타적인 유일값을 가져야 함 */
|
|
82
|
+
uniqueId: string;
|
|
83
|
+
data: TData;
|
|
84
|
+
onBeforeRender?: () => void;
|
|
85
|
+
onRender?: () => void;
|
|
86
|
+
onUpdate?: (newData: TData) => void;
|
|
87
|
+
}
|
|
88
|
+
export type onTransformCallback = {
|
|
89
|
+
x: number;
|
|
90
|
+
y: number;
|
|
91
|
+
scale: number;
|
|
92
|
+
rotation: number;
|
|
93
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type Konva from 'konva';
|
|
2
|
+
export declare namespace util {
|
|
3
|
+
/**
|
|
4
|
+
* Konva Shape 나 Group에 마우스가 올라갔을 때 커서 모양을 바꿔주는 이벤트를 등록한다
|
|
5
|
+
* @param shapes 등록할 Konva Shape 들
|
|
6
|
+
*/
|
|
7
|
+
function enableMouseHoverEvent(params: {
|
|
8
|
+
shapes: (Konva.Shape | Konva.Group)[];
|
|
9
|
+
cursorStyle?: string;
|
|
10
|
+
additionalHoverEvent?: (shape: Konva.Shape | Konva.Group) => void;
|
|
11
|
+
additionalLeaveEvent?: (shape: Konva.Shape | Konva.Group) => void;
|
|
12
|
+
}): void;
|
|
13
|
+
function changeMouseCursor(stage: Konva.Stage, cursorStyle: string): void;
|
|
14
|
+
/** Konva Shape 나 Group에 걸려있는 모든 이벤트를 제거한다 */
|
|
15
|
+
function disableAllEvents(...shapes: (Konva.Shape | Konva.Group)[]): void;
|
|
16
|
+
function uuid(): string;
|
|
17
|
+
function pickShape(stage: Konva.Stage): import("konva/lib/Shape").Shape<import("konva/lib/Shape").ShapeConfig> | null;
|
|
18
|
+
/** 마우스 위치에 있는 모든 shape 목록을 가져온다 */
|
|
19
|
+
function pickShapes(stage: Konva.Stage): import("konva/lib/Shape").Shape<import("konva/lib/Shape").ShapeConfig>[];
|
|
20
|
+
/** 현재 마우스포인터의 pose + position 계산 */
|
|
21
|
+
function getPointerPosePosition(stage: Konva.Stage, originPoint: BalcanGeo.Vector2 | BalcanGeo.Pose, pixelPerMeter: number): BalcanGeo.PosePosition;
|
|
22
|
+
function randomHexColorCode(): string;
|
|
23
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { geo } from './geo.balcan';
|
|
2
|
+
export var util;
|
|
3
|
+
(function (util) {
|
|
4
|
+
/**
|
|
5
|
+
* Konva Shape 나 Group에 마우스가 올라갔을 때 커서 모양을 바꿔주는 이벤트를 등록한다
|
|
6
|
+
* @param shapes 등록할 Konva Shape 들
|
|
7
|
+
*/
|
|
8
|
+
function enableMouseHoverEvent(params) {
|
|
9
|
+
params.shapes.forEach((s) => {
|
|
10
|
+
s.on('mouseover', () => {
|
|
11
|
+
s.getStage().container().style.cursor = 'pointer';
|
|
12
|
+
params.additionalHoverEvent?.(s);
|
|
13
|
+
});
|
|
14
|
+
s.on('mouseleave', () => {
|
|
15
|
+
s.getStage().container().style.cursor = 'auto';
|
|
16
|
+
params.additionalLeaveEvent?.(s);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
util.enableMouseHoverEvent = enableMouseHoverEvent;
|
|
21
|
+
function changeMouseCursor(stage, cursorStyle) {
|
|
22
|
+
stage.container().style.cursor = cursorStyle;
|
|
23
|
+
}
|
|
24
|
+
util.changeMouseCursor = changeMouseCursor;
|
|
25
|
+
/** Konva Shape 나 Group에 걸려있는 모든 이벤트를 제거한다 */
|
|
26
|
+
function disableAllEvents(...shapes) {
|
|
27
|
+
shapes.forEach((shape) => shape.off('mouseover mouseleave mouseout dragmove transform click dblclick mouseup mousedown'));
|
|
28
|
+
}
|
|
29
|
+
util.disableAllEvents = disableAllEvents;
|
|
30
|
+
function uuid() {
|
|
31
|
+
return Math.random().toString(16).slice(2);
|
|
32
|
+
}
|
|
33
|
+
util.uuid = uuid;
|
|
34
|
+
function pickShape(stage) {
|
|
35
|
+
const picked = stage.getIntersection(stage.getPointerPosition() ?? {
|
|
36
|
+
x: 0,
|
|
37
|
+
y: 0,
|
|
38
|
+
});
|
|
39
|
+
return picked;
|
|
40
|
+
}
|
|
41
|
+
util.pickShape = pickShape;
|
|
42
|
+
/** 마우스 위치에 있는 모든 shape 목록을 가져온다 */
|
|
43
|
+
function pickShapes(stage) {
|
|
44
|
+
const picked = stage.getAllIntersections(stage.getPointerPosition() ?? {
|
|
45
|
+
x: 0,
|
|
46
|
+
y: 0,
|
|
47
|
+
});
|
|
48
|
+
return picked;
|
|
49
|
+
}
|
|
50
|
+
util.pickShapes = pickShapes;
|
|
51
|
+
/** 현재 마우스포인터의 pose + position 계산 */
|
|
52
|
+
function getPointerPosePosition(stage, originPoint, pixelPerMeter) {
|
|
53
|
+
const pointer = stage.getRelativePointerPosition();
|
|
54
|
+
const position = {
|
|
55
|
+
stagex: pointer?.x ?? 0,
|
|
56
|
+
stagey: pointer?.y ?? 0,
|
|
57
|
+
degree: 0,
|
|
58
|
+
};
|
|
59
|
+
const pose = geo.transformPosition(position, originPoint, pixelPerMeter);
|
|
60
|
+
return {
|
|
61
|
+
pose,
|
|
62
|
+
position,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
util.getPointerPosePosition = getPointerPosePosition;
|
|
66
|
+
function randomHexColorCode() {
|
|
67
|
+
return ('#' +
|
|
68
|
+
('00000' + Math.floor(Math.random() * Math.pow(16, 6)).toString(16)).slice(-6));
|
|
69
|
+
}
|
|
70
|
+
util.randomHexColorCode = randomHexColorCode;
|
|
71
|
+
})(util || (util = {}));
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type Konva from 'konva';
|
|
2
|
+
import type { Director } from './types.balcan';
|
|
3
|
+
export declare namespace viewport {
|
|
4
|
+
function getViewportCenterPosition(director: Director): {
|
|
5
|
+
asAbsolutePosition(): {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
};
|
|
9
|
+
asRelativePosition(): BalcanGeo.Vector2;
|
|
10
|
+
};
|
|
11
|
+
function getRelativePosition(director: Director): {
|
|
12
|
+
/** absolute position 을 relative position 으로 변환 */
|
|
13
|
+
fromAbsolutePosition(vector: BalcanGeo.Vector2): BalcanGeo.Vector2;
|
|
14
|
+
};
|
|
15
|
+
function getAbsolutePosition(director: Director): {
|
|
16
|
+
fromRelativePosition(vector: BalcanGeo.Vector2): {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
function bringToCenter(director: Director): {
|
|
22
|
+
/** 다음 absolute vector 를 화면의 중심으로 가져온다 */
|
|
23
|
+
fromAbsolutePosition(vector: BalcanGeo.Vector2): void;
|
|
24
|
+
fromRelativePosition(vector: BalcanGeo.Vector2): void;
|
|
25
|
+
fromShape(shape: Konva.Shape | Konva.Group): void;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { geo } from './geo.balcan';
|
|
2
|
+
export var viewport;
|
|
3
|
+
(function (viewport) {
|
|
4
|
+
function getViewportCenterPosition(director) {
|
|
5
|
+
const stage = director.stage;
|
|
6
|
+
return {
|
|
7
|
+
asAbsolutePosition() {
|
|
8
|
+
return {
|
|
9
|
+
x: stage.width() / 2,
|
|
10
|
+
y: stage.height() / 2,
|
|
11
|
+
};
|
|
12
|
+
},
|
|
13
|
+
asRelativePosition() {
|
|
14
|
+
return getRelativePosition(director).fromAbsolutePosition(this.asAbsolutePosition());
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
viewport.getViewportCenterPosition = getViewportCenterPosition;
|
|
19
|
+
function getRelativePosition(director) {
|
|
20
|
+
const stage = director.stage;
|
|
21
|
+
return {
|
|
22
|
+
/** absolute position 을 relative position 으로 변환 */
|
|
23
|
+
fromAbsolutePosition(vector) {
|
|
24
|
+
const offset = geo.subtractVector(vector, stage.getAbsolutePosition());
|
|
25
|
+
return geo.divideVector(offset, director.scale);
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
viewport.getRelativePosition = getRelativePosition;
|
|
30
|
+
function getAbsolutePosition(director) {
|
|
31
|
+
const stage = director.stage;
|
|
32
|
+
return {
|
|
33
|
+
fromRelativePosition(vector) {
|
|
34
|
+
const scaledOffset = geo.multiplyVector(vector, director.scale);
|
|
35
|
+
return geo.addVector(stage.getAbsolutePosition(), scaledOffset);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
viewport.getAbsolutePosition = getAbsolutePosition;
|
|
40
|
+
function bringToCenter(director) {
|
|
41
|
+
const stage = director.stage;
|
|
42
|
+
return {
|
|
43
|
+
/** 다음 absolute vector 를 화면의 중심으로 가져온다 */
|
|
44
|
+
fromAbsolutePosition(vector) {
|
|
45
|
+
const moveVector = geo.subtractVector(getViewportCenterPosition(director).asAbsolutePosition(), vector);
|
|
46
|
+
stage.absolutePosition(geo.addVector(stage.getAbsolutePosition(), moveVector));
|
|
47
|
+
},
|
|
48
|
+
fromRelativePosition(vector) {
|
|
49
|
+
const centerRelativePosition = getViewportCenterPosition(director).asRelativePosition();
|
|
50
|
+
const moveVector = geo.subtractVector(centerRelativePosition, vector);
|
|
51
|
+
const scaledMoveVector = geo.multiplyVector(moveVector, director.scale);
|
|
52
|
+
stage.absolutePosition(geo.addVector(stage.getAbsolutePosition(), scaledMoveVector));
|
|
53
|
+
},
|
|
54
|
+
fromShape(shape) {
|
|
55
|
+
return this.fromAbsolutePosition(shape.getAbsolutePosition());
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
viewport.bringToCenter = bringToCenter;
|
|
60
|
+
})(viewport || (viewport = {}));
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference path="./types/index.d.ts" />
|
|
2
|
+
import * as balcan from './mixin/mixin';
|
|
3
|
+
import type * as BalcanTypes from './mixin/mixin.type';
|
|
4
|
+
export declare const Balcan: {
|
|
5
|
+
core: typeof balcan.core;
|
|
6
|
+
staffs: typeof balcan.staffs;
|
|
7
|
+
geo: typeof balcan.geo;
|
|
8
|
+
math: typeof balcan.math;
|
|
9
|
+
util: typeof balcan.util;
|
|
10
|
+
viewport: typeof balcan.viewport;
|
|
11
|
+
bitmap: typeof balcan.bitmap;
|
|
12
|
+
};
|
|
13
|
+
export type { BalcanTypes };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * as core from '../core/core.balcan';
|
|
2
|
+
export * as staffs from '../staffs';
|
|
3
|
+
export * from '../core/geo.balcan';
|
|
4
|
+
export * from '../core/math.balcan';
|
|
5
|
+
export * from '../core/util.balcan';
|
|
6
|
+
export * from '../core/viewport.balcan';
|
|
7
|
+
export * from '../core/bitmap.balcan';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export * as core from '../core/core.balcan';
|
|
2
|
+
export * as staffs from '../staffs';
|
|
3
|
+
export * from '../core/geo.balcan';
|
|
4
|
+
export * from '../core/math.balcan';
|
|
5
|
+
export * from '../core/util.balcan';
|
|
6
|
+
export * from '../core/viewport.balcan';
|
|
7
|
+
export * from '../core/bitmap.balcan';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import Konva from 'konva';
|
|
2
|
+
import type { Staff, onTransformCallback, Director } from '../core/types.balcan';
|
|
3
|
+
export type BalcanImageStaffReturn = {
|
|
4
|
+
translate: (x: number, y: number) => void;
|
|
5
|
+
rotate: (rad: number) => void;
|
|
6
|
+
scale(n: number): void;
|
|
7
|
+
changeImage: (newImage: CanvasImageSource) => void;
|
|
8
|
+
};
|
|
9
|
+
export type BalcanImageStaff = Staff<'image', {
|
|
10
|
+
entityId: string;
|
|
11
|
+
imageNode: Konva.Group;
|
|
12
|
+
sourceImage: CanvasImageSource;
|
|
13
|
+
renderImage: CanvasImageSource;
|
|
14
|
+
transformer?: Konva.Transformer;
|
|
15
|
+
}, BalcanImageStaffReturn>;
|
|
16
|
+
/** Image Node 유닛 */
|
|
17
|
+
export declare function useImageStaff(params: {
|
|
18
|
+
entityId: string;
|
|
19
|
+
imageSrc: string;
|
|
20
|
+
onTransform?: (params: onTransformCallback) => void;
|
|
21
|
+
}, opt: {
|
|
22
|
+
/** 체크시 드래그 가능하며 transformer 생성됨 */
|
|
23
|
+
editable?: boolean;
|
|
24
|
+
/** 회전 중심점 */
|
|
25
|
+
offset?: BalcanGeo.Vector2;
|
|
26
|
+
director: Director;
|
|
27
|
+
}): BalcanImageStaff;
|