@hatiolab/things-scene 3.0.0-beta.0 → 3.0.0-beta.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.
@@ -0,0 +1,388 @@
1
+ declare module '@hatiolab/things-scene' {
2
+ type Constructor<T = {}> = new (...args: any[]) => T
3
+ type Class = { new (...args: any[]): any }
4
+ type Properties = { [key: string]: any }
5
+
6
+ const MODE_VIEW = 0
7
+ const MODE_EDIT = 1
8
+ const MODE_SHIFT = 2
9
+
10
+ enum SCENE_MODE {
11
+ VIEW = 0,
12
+ EDIT = 1
13
+ }
14
+
15
+ type FITMODE = 'both' | 'ratio' | 'width' | 'height' | 'center' | 'none'
16
+ type DIMENSION = { x: number; y: number }
17
+ type SCALE = DIMENSION
18
+ type TRANSLATE = DIMENSION
19
+ type POSITION = DIMENSION
20
+
21
+ type LAYOUT = {
22
+ reflow: (container: Container) => void
23
+ capturables?: (container: Container) => boolean
24
+ drawables?: (container: Container) => boolean
25
+ isStuck?: (component: Container) => boolean
26
+ keyNavigate?: (container: Container, component: Component, e: KeyboardEvent) => Component
27
+ joinType?: boolean
28
+ }
29
+
30
+ const AbsoluteLayout: LAYOUT & { ABSOLUTE: boolean }
31
+ const TableLayout: LAYOUT
32
+ const CardLayout: LAYOUT
33
+ const HTMLAbsoluteLayout: LAYOUT
34
+ const LinearHorizontal: LAYOUT
35
+ const LinearVertical: LAYOUT
36
+
37
+ type AnimationConfig = {
38
+ duration?: number
39
+ delay?: number
40
+ step: Function
41
+ delta: 'linear' | 'quad' | 'circ' | 'back' | 'bounce' | 'elastic' | Function
42
+ ease: 'out' | 'inout'
43
+ options?: object
44
+ repeat?: boolean
45
+ }
46
+
47
+ type ControlHandler = {
48
+ ondragstart?(point: POSITION, index: number, component: Component): void
49
+ ondragmove?(point: POSITION, index: number, component: Component): void
50
+ ondragend?(point: POSITION, index: number, component: Component): void
51
+ }
52
+
53
+ interface Control extends DIMENSION {
54
+ handler: ControlHandler
55
+ }
56
+
57
+ function create({
58
+ target,
59
+ model,
60
+ style,
61
+ layers,
62
+ handlers,
63
+ mode,
64
+ refProvider,
65
+ baseUrl,
66
+ fitMode
67
+ }: {
68
+ target?: HTMLElement
69
+ model: Object
70
+ style?: any
71
+ layers?: Array<any>
72
+ handlers?: Array<any>
73
+ mode?: SCENE_MODE
74
+ refProvider?: any
75
+ baseUrl?: string | undefined
76
+ fitMode?: FITMODE
77
+ }): Scene
78
+
79
+ function error(...args: any[]): void
80
+ function warn(...args: any[]): void
81
+ function debug(...args: any[]): void
82
+
83
+ class ScriptLoader {
84
+ static load(scripts: string | Array<string>, styles?: string | Array<string>): Promise<void>
85
+ }
86
+
87
+ class Anchor {
88
+ constructor({ component, anchor, position }: { component: Component; anchor: string; position: POSITION })
89
+
90
+ position: POSITION
91
+ }
92
+
93
+ class Model {
94
+ static compile(model: Model, context?: any): Component
95
+
96
+ type: string;
97
+ [key: string]: any
98
+ }
99
+
100
+ class ApplicationContext {
101
+ readonly refProvider: any
102
+ readonly isViewMode: boolean
103
+
104
+ mode: SCENE_MODE
105
+ baseUrl: string
106
+
107
+ dispose(): void
108
+ }
109
+
110
+ /* mixins */
111
+
112
+ function RectPath<TBase extends Constructor>(Base: TBase): TBase
113
+
114
+ function ValueHolder<TBase extends Constructor>(
115
+ Base: TBase
116
+ ): {
117
+ new (...args: any[]): {
118
+ value: number
119
+ animValue: number
120
+ animOnValueChange(value: number, animFromBase: boolean, base: number): void
121
+ }
122
+ } & TBase
123
+
124
+ function DataSource<TBase extends Constructor>(
125
+ Base: TBase
126
+ ): {
127
+ new (...args: any[]): {
128
+ isDataSource(): boolean
129
+ }
130
+ } & TBase
131
+
132
+ function MoveHandle<TBase extends Constructor>(Base: TBase): TBase
133
+
134
+ function MixinHTMLElement<TBase extends Constructor>(
135
+ Base: TBase
136
+ ): {
137
+ new (...args: any[]): {
138
+ get tagName(): string
139
+ element: HTMLElement
140
+
141
+ createElement(): void
142
+ userInputEventHandler(e: Event): void
143
+ reposition(): void
144
+ disposeElement(): void
145
+ }
146
+ } & TBase
147
+
148
+ function MixinEvent<TBase extends Constructor>(
149
+ Base: TBase
150
+ ): {
151
+ new (...args: any[]): {
152
+ on(name: string, callback: Function, context?: any): void
153
+ off(name: string, callback: Function, context?: any): void
154
+ once(name: string, callback: Function, context?: any): void
155
+ trigger(name: string): void
156
+ }
157
+ } & TBase
158
+
159
+ /* components */
160
+
161
+ class Component extends MixinEvent(Object) {
162
+ static register(type: string, Clazz: typeof Component): void
163
+ static memoize(base: any, property: string, needClone: boolean): void
164
+
165
+ state: Properties
166
+ bounds: { top: number; left: number; width: number; height: number }
167
+ root: RootContainer
168
+ rootModel: ModelLayer
169
+ parent: Container
170
+ app: ApplicationContext /* application context */
171
+ model: Model
172
+ hierarchy: Model
173
+ path: Array<DIMENSION>
174
+ anchors: Array<Anchor>
175
+ get data(): any
176
+ set data(data: any)
177
+
178
+ get controls(): Array<Control> | undefined
179
+ get hasTextProperty(): boolean
180
+
181
+ ready(): void
182
+ dispose(): void
183
+ getState(prop: string): any
184
+ setState(props: Properties | any, value?: any): void
185
+ get(prop: string): any
186
+ set(props: Properties | string, value?: any): void
187
+ reposition(): void
188
+ transcoordP2S(x: number, y: number): POSITION
189
+ render(context: CanvasRenderingContext2D): void
190
+ executeMappings(force?: boolean): void
191
+ invalidate(): void
192
+ animate(config: AnimationConfig): {
193
+ start: Function /* start function */
194
+ stop: Function /* stop function */
195
+ }
196
+
197
+ onchange(after: Properties, before: Properties): void
198
+
199
+ drawImage(
200
+ context: CanvasRenderingContext2D,
201
+ image: HTMLImageElement,
202
+ left: number,
203
+ top: number,
204
+ width: number,
205
+ height: number
206
+ ): void
207
+ drawStroke(context: CanvasRenderingContext2D): void
208
+ drawFill(context: CanvasRenderingContext2D): void
209
+ drawText(context: CanvasRenderingContext2D): void
210
+
211
+ ondblclick(e: MouseEvent): void
212
+ }
213
+
214
+ class ContainerAbstract extends MoveHandle(RectPath(Component)) {}
215
+ class Container extends MixinHTMLElement(ContainerAbstract) {
216
+ indexOf(component: Component): number
217
+ insertComponentAt(target: Component, idx: number): void
218
+ findById(id: string): Component
219
+
220
+ add(components: Component[] | Component): Container
221
+ remove(components: Component[] | Component): Container
222
+
223
+ components: Component[]
224
+ }
225
+ class RootContainer extends Container {}
226
+
227
+ class Layer extends ContainerAbstract {
228
+ target: HTMLElement
229
+ canvas: HTMLCanvasElement
230
+
231
+ getContext(): CanvasRenderingContext2D
232
+ }
233
+
234
+ class ModelLayer extends Layer {
235
+ overlay: HTMLDivElement
236
+ }
237
+
238
+ class Text extends RectPath(Component) {}
239
+ class Shape extends Component {}
240
+ class Ellipse extends Shape {}
241
+ class Polygon extends Shape {}
242
+ class Donut extends Ellipse {}
243
+ class Rect extends RectPath(Shape) {}
244
+ class HTMLOverlayElement extends MixinHTMLElement(RectPath(Component)) {}
245
+
246
+ class HTMLOverlayContainer extends Container {
247
+ readonly layout: any
248
+ }
249
+
250
+ /* Scene API */
251
+
252
+ class Scene {
253
+ static readonly residents: WeakSet<Scene>
254
+
255
+ /**
256
+ * scene에 컴포넌트를 추가한다.
257
+ * @param models {object} - Component Model Object
258
+ * @param boundsOrOffset {object} - x, y, cx, cy, ...
259
+ * @param onto {string} - onto
260
+ */
261
+ add({ models, boundsOrOffset, onto }: { models: object; boundsOrOffset: object; onto: string }): Component
262
+
263
+ /**
264
+ * scene의 컴포넌트를 복제한다.
265
+ * 현재 선택되어있는 컴포넌트가 복제되므로, 컴포넌트를 복제하기 위해서는
266
+ * 먼저 복제하고자하는 컴포넌트를 선택된 상태로 만든 후에(참조. {@link select} 메쏘드) 이 메쏘드를 호출한다.
267
+ */
268
+ duplicate(): void
269
+
270
+ /**
271
+ * scene의 컴포넌트를 삭제한다.
272
+ * 현재 선택되어있는 컴포넌트가 삭제되므로, 컴포넌트를 삭제하기 위해서는
273
+ * 먼저 삭제하고자하는 컴포넌트를 선택된 상태로 만든 후에(참조. {@link select} 메쏘드) 이 메쏘드를 호출한다.
274
+ */
275
+ remove(): void
276
+
277
+ animate(config: AnimationConfig): {
278
+ start: Function /* start function */
279
+ stop: Function /* stop function */
280
+ }
281
+
282
+ /**
283
+ * scene이 그려지고 있는 컨테이너를 전체화면 모드에서 표시되도록 한다.
284
+ */
285
+ fullscreen(): void
286
+
287
+ /**
288
+ * 파라미터로 주어지는 id를 가진 컴포넌트의 data 값을 변경한다.
289
+ * @param id {string} - component id
290
+ * @param value {any} - data value
291
+ */
292
+ variable(id: string, value: any): any
293
+
294
+ target: HTMLElement
295
+ scale: SCALE
296
+ translate: TRANSLATE
297
+
298
+ readonly unit: string /* 'px' */
299
+ readonly PPM: number
300
+ readonly PPI: number
301
+ readonly DPPX: number
302
+
303
+ /**
304
+ * Scene 모델의 단위(unit)을 감안한 기본 Scale 값을 제공한다.
305
+ * 통산 'mm', 'cm' 단위의 Scene은 각 값에 10배를 곱한 수치로 모델링된다.(값을 10으로 나눈값이 실제 단위와 일치한다.)
306
+ * unitScale의 의미는 scene에 unitScale값으로 scale하면, 각 단위값이 화면과 일치한다는 의미이다.
307
+ *
308
+ * 모델링의 수치단위가 픽셀이 아니고, mm, cm, inch 등의 단위인 경우에,
309
+ * 화면에서의 크기가 실물과 유사하게 보이는 수준의 기본 스케일을 제공하는 기능이다.
310
+ * 이 값은 내부적으로는, Ruler에서 눈금을 실제 자의 눈금과 일치시키기 위해서 사용한다.
311
+ */
312
+ readonly unitScale: string
313
+
314
+ /**
315
+ * scene이 그려질 모니터 화면의 크기정보 (inch)
316
+ * 예시) 17, 20, 24, 27, 30, ...
317
+ * @type {number}
318
+ */
319
+ screen: number
320
+
321
+ /**
322
+ * 컨테이너의 크기에 맞게 크기를 조정한다.
323
+ */
324
+ resize(): void
325
+
326
+ dispose(): void
327
+
328
+ /* Selection Based API - Modeling APIs */
329
+
330
+ /**
331
+ * scene 내에서 선택된 컴포넌트의 리스트
332
+ * @type {object-array}
333
+ */
334
+ selected: Array<Component>
335
+
336
+ /**
337
+ * scene이 그리고 있는 컴포넌트 모델정보
338
+ * @type {object}
339
+ */
340
+ model: Component
341
+
342
+ /*
343
+ * root는 모델의 최상위 컨테이너인 모델레이어를 의미한다.
344
+ */
345
+ readonly root: Container
346
+
347
+ /*
348
+ * selector에 해당하는 모든 컴포넌트들을 찾는다.
349
+ * @params selector {string}
350
+ */
351
+ findAll(selector: string): Array<Component>
352
+
353
+ /*
354
+ * selector에 해당하는 첫번째 컴포넌트를 찾는다.
355
+ * @params selector {string}
356
+ */
357
+ findFirst(selector: string): Component
358
+
359
+ /*
360
+ * id를 갖는 컴포넌트를 찾는다.
361
+ * @params id {string}
362
+ */
363
+ findById(id: string): Component
364
+
365
+ /*
366
+ * scene이 그리는 모델 오브젝트를 JSON 텍스트로 리턴한다.
367
+ */
368
+ serialize(): string
369
+
370
+ on(event: string, listener: Function, context?: any): void
371
+ once(event: string, listener: Function, context?: any): void
372
+ off(event: string, listener: Function, context?: any): void
373
+
374
+ toDataURL(): string
375
+
376
+ fit(type: FITMODE): void
377
+
378
+ readonly fitMode: FITMODE
379
+ readonly ids: string[]
380
+
381
+ data: object
382
+
383
+ // @deprecated
384
+ variables: object
385
+
386
+ baseUrl: string
387
+ }
388
+ }