@hatiolab/things-scene 2.7.22 → 2.7.26

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/things-scene.d.ts CHANGED
@@ -1,6 +1,13 @@
1
+ import { property } from 'lodash'
2
+
1
3
  declare module '@hatiolab/things-scene' {
2
4
  type Constructor<T = {}> = new (...args: any[]) => T
3
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[]
4
11
 
5
12
  const MODE_VIEW = 0
6
13
  const MODE_EDIT = 1
@@ -8,7 +15,8 @@ declare module '@hatiolab/things-scene' {
8
15
 
9
16
  enum SCENE_MODE {
10
17
  VIEW = 0,
11
- EDIT = 1
18
+ EDIT = 1,
19
+ SHIFT = 2
12
20
  }
13
21
 
14
22
  type FITMODE = 'both' | 'ratio' | 'width' | 'height' | 'center' | 'none'
@@ -16,8 +24,55 @@ declare module '@hatiolab/things-scene' {
16
24
  type SCALE = DIMENSION
17
25
  type TRANSLATE = DIMENSION
18
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
+ }
19
51
 
20
- type Properties = { [key: string]: any }
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
21
76
 
22
77
  type AnimationConfig = {
23
78
  duration?: number
@@ -76,9 +131,9 @@ declare module '@hatiolab/things-scene' {
76
131
  }
77
132
 
78
133
  class Model {
79
- static compile(model: Model, context: any): Component
134
+ static compile(model: Model, context?: any): Component
80
135
 
81
- type: string;
136
+ type?: string;
82
137
  [key: string]: any
83
138
  }
84
139
 
@@ -146,9 +201,11 @@ declare module '@hatiolab/things-scene' {
146
201
  class Component extends MixinEvent(Object) {
147
202
  static register(type: string, Clazz: typeof Component): void
148
203
  static memoize(base: any, property: string, needClone: boolean): void
204
+ static drawStroke(context: CanvasRenderingContext2D, style: Style): void
149
205
 
150
206
  state: Properties
151
- bounds: { top: number; left: number; width: number; height: number }
207
+ bounds: BOUNDS
208
+ textBounds: BOUNDS
152
209
  root: RootContainer
153
210
  rootModel: ModelLayer
154
211
  parent: Container
@@ -157,20 +214,42 @@ declare module '@hatiolab/things-scene' {
157
214
  hierarchy: Model
158
215
  path: Array<DIMENSION>
159
216
  anchors: Array<Anchor>
160
- data: any
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)
161
226
 
162
227
  get controls(): Array<Control> | undefined
163
228
  get hasTextProperty(): boolean
164
229
 
230
+ isRootModel(): boolean
231
+ isContainer(): boolean
232
+ isLine(): boolean
233
+ isLayer(): boolean
234
+ is3dish(): boolean
235
+
165
236
  ready(): void
166
237
  dispose(): void
167
238
  getState(prop: string): any
168
239
  setState(props: Properties | any, value?: any): void
169
240
  get(prop: string): any
241
+ contains(x: number, y: number): boolean
170
242
  set(props: Properties | string, value?: any): void
171
243
  reposition(): void
244
+ clearCache(): void
245
+
172
246
  transcoordP2S(x: number, y: number): POSITION
247
+ transcoordC2S(x: number, y: number, top?: RootContainer): POSITION
248
+
249
+ prerender(context: CanvasRenderingContext2D): void
173
250
  render(context: CanvasRenderingContext2D): void
251
+ postrender(context: CanvasRenderingContext2D): void
252
+
174
253
  executeMappings(force?: boolean): void
175
254
  invalidate(): void
176
255
  animate(config: AnimationConfig): {
@@ -195,17 +274,29 @@ declare module '@hatiolab/things-scene' {
195
274
  ondblclick(e: MouseEvent): void
196
275
  }
197
276
 
198
- class ContainerAbstract extends MoveHandle(RectPath(Component)) {}
199
- class Container extends MixinHTMLElement(ContainerAbstract) {
277
+ class ContainerAbstract extends MoveHandle(RectPath(Component)) {
200
278
  indexOf(component: Component): number
279
+ size(): number
280
+ addComponent(target: Component): void
281
+ removeComponent(target: Component): void
201
282
  insertComponentAt(target: Component, idx: number): void
202
- findById(id: string): Component
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[])
203
295
  }
204
- class RootContainer extends Container {}
205
296
 
206
297
  class Layer extends ContainerAbstract {
207
- target: HTMLElement
208
- canvas: HTMLCanvasElement
298
+ target: HTMLElement | null
299
+ canvas: HTMLCanvasElement | null
209
300
 
210
301
  getContext(): CanvasRenderingContext2D
211
302
  }
@@ -237,7 +328,20 @@ declare module '@hatiolab/things-scene' {
237
328
  * @param boundsOrOffset {object} - x, y, cx, cy, ...
238
329
  * @param onto {string} - onto
239
330
  */
240
- add({ models, boundsOrOffset, onto }: { models: object; boundsOrOffset: object; onto: string }): Component
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
241
345
 
242
346
  /**
243
347
  * scene의 컴포넌트를 복제한다.
@@ -270,7 +374,7 @@ declare module '@hatiolab/things-scene' {
270
374
  */
271
375
  variable(id: string, value: any): any
272
376
 
273
- target: HTMLElement
377
+ target: HTMLElement | null
274
378
  scale: SCALE
275
379
  translate: TRANSLATE
276
380
 
@@ -279,6 +383,8 @@ declare module '@hatiolab/things-scene' {
279
383
  readonly PPI: number
280
384
  readonly DPPX: number
281
385
 
386
+ mode: SCENE_MODE
387
+
282
388
  /**
283
389
  * Scene 모델의 단위(unit)을 감안한 기본 Scale 값을 제공한다.
284
390
  * 통산 'mm', 'cm' 단위의 Scene은 각 값에 10배를 곱한 수치로 모델링된다.(값을 10으로 나눈값이 실제 단위와 일치한다.)
@@ -302,6 +408,7 @@ declare module '@hatiolab/things-scene' {
302
408
  */
303
409
  resize(): void
304
410
 
411
+ release(): void
305
412
  dispose(): void
306
413
 
307
414
  /* Selection Based API - Modeling APIs */
@@ -348,14 +455,34 @@ declare module '@hatiolab/things-scene' {
348
455
 
349
456
  on(event: string, listener: Function, context?: any): void
350
457
  once(event: string, listener: Function, context?: any): void
351
- off(event: string, listener: Function, context?: any): void
458
+ off(event: string, listener?: Function, context?: any): void
352
459
 
353
460
  toDataURL(): string
354
461
 
355
462
  fit(type: FITMODE): void
356
463
 
357
464
  readonly fitMode: FITMODE
358
- readonly ids: string[]
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
359
486
 
360
487
  data: object
361
488