@hatiolab/things-scene 3.0.0-beta.0 → 3.0.0-beta.4

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