@hatiolab/things-scene 2.7.14 → 2.7.18

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,13 +1,29 @@
1
1
  declare module '@hatiolab/things-scene' {
2
- export const MODE_VIEW = 0
3
- export const MODE_EDIT = 1
4
- export const MODE_SHIFT = 2
2
+ type Constructor<T = {}> = new (...args: any[]) => T
3
+
4
+ const MODE_VIEW = 0
5
+ const MODE_EDIT = 1
6
+ const MODE_SHIFT = 2
5
7
 
6
8
  type FITMODE = 'both' | 'ratio' | 'width' | 'height' | 'center' | 'none'
7
- type SCALE = { x: number; y: number }
8
- type TRANSLATE = { x: number; y: number }
9
+ type DIMENSION = { x: number; y: number }
10
+ type SCALE = DIMENSION
11
+ type TRANSLATE = DIMENSION
12
+ type POSITION = DIMENSION
13
+
14
+ type Properties = { [key: string]: any }
15
+
16
+ type ControlHandler = {
17
+ ondragstart?(point: POSITION, index: number, component: Component): void
18
+ ondragmove?(point: POSITION, index: number, component: Component): void
19
+ ondragend?(point: POSITION, index: number, component: Component): void
20
+ }
9
21
 
10
- export function create({
22
+ interface Control extends DIMENSION {
23
+ handler: ControlHandler
24
+ }
25
+
26
+ function create({
11
27
  target,
12
28
  model,
13
29
  style,
@@ -23,17 +39,173 @@ declare module '@hatiolab/things-scene' {
23
39
  style?: any
24
40
  layers?: Array<any>
25
41
  handlers?: Array<any>
26
- mode?: 0 | 1
42
+ mode?: SCENE_MODE
27
43
  refProvider?: any
28
44
  baseUrl?: string | undefined
29
45
  fitMode?: FITMODE
30
46
  }): Scene
31
47
 
32
- export class Component {}
33
- export class Container {}
48
+ function error(...args: any[]): void
49
+ function warn(...args: any[]): void
50
+ function debug(...args: any[]): void
51
+
52
+ class ScriptLoader {
53
+ static load(scripts: string | Array<string>, styles?: string | Array<string>): Promise<void>
54
+ }
55
+
56
+ class Anchor {
57
+ constructor({ component, anchor, position }: { component: Component; anchor: string; position: POSITION })
58
+
59
+ position: POSITION
60
+ }
61
+
62
+ class Model {
63
+ static compile(model: Model, context: any): Component
64
+
65
+ type: string;
66
+ [key: string]: any
67
+ }
68
+
69
+ class ApplicationContext {
70
+ readonly refProvider: any
71
+ readonly isViewMode: boolean
72
+
73
+ mode: SCENE_MODE
74
+ baseUrl: string
75
+
76
+ dispose(): void
77
+ }
78
+
79
+ /* mixins */
80
+
81
+ function RectPath<TBase extends Constructor>(Base: TBase): TBase
82
+
83
+ function ValueHolder<TBase extends Constructor>(
84
+ Base: TBase
85
+ ): {
86
+ new (...args: any[]): {
87
+ value: number
88
+ animValue: number
89
+ animOnValueChange(value: number, animFromBase: boolean, base: number): void
90
+ }
91
+ } & TBase
92
+
93
+ function DataSource<TBase extends Constructor>(
94
+ Base: TBase
95
+ ): {
96
+ new (...args: any[]): {
97
+ isDataSource(): boolean
98
+ }
99
+ } & TBase
100
+
101
+ function MoveHandle<TBase extends Constructor>(Base: TBase): TBase
102
+
103
+ function MixinHTMLElement<TBase extends Constructor>(
104
+ Base: TBase
105
+ ): {
106
+ new (...args: any[]): {
107
+ get tagName(): string
108
+ element: HTMLElement
109
+
110
+ createElement(): void
111
+ userInputEventHandler(e: Event): void
112
+ reposition(): void
113
+ disposeElement(): void
114
+ }
115
+ } & TBase
116
+
117
+ function MixinEvent<TBase extends Constructor>(
118
+ Base: TBase
119
+ ): {
120
+ new (...args: any[]): {
121
+ on(name: string, callback: Function, context?: any): void
122
+ off(name: string, callback: Function, context?: any): void
123
+ once(name: string, callback: Function, context?: any): void
124
+ trigger(name: string): void
125
+ }
126
+ } & TBase
127
+
128
+ /* components */
129
+
130
+ class Component extends MixinEvent(Object) {
131
+ static register(type: string, Clazz: typeof Component): void
132
+
133
+ state: Properties
134
+ bounds: { top: number; left: number; width: number; height: number }
135
+ root: RootContainer
136
+ rootModel: ModelLayer
137
+ parent: Container
138
+ app: ApplicationContext /* application context */
139
+ model: Model
140
+ hierarchy: Model
141
+ path: Array<DIMENSION>
142
+ anchors: Array<Anchor>
143
+ data: any
144
+
145
+ get controls(): Array<Control> | undefined
146
+ get hasTextProperty(): boolean
147
+
148
+ ready(): void
149
+ dispose(): void
150
+ getState(prop: string): any
151
+ setState(props: Properties | any, value?: any): void
152
+ get(prop: string): any
153
+ set(props: Properties | string, value?: any): void
154
+ reposition(): void
155
+ transcoordP2S(x: number, y: number): POSITION
156
+ render(context: CanvasRenderingContext2D): void
157
+ executeMappings(force?: boolean): void
158
+
159
+ onchange(after: Properties, before: Properties): void
160
+
161
+ drawImage(
162
+ context: CanvasRenderingContext2D,
163
+ image: HTMLImageElement,
164
+ left: number,
165
+ top: number,
166
+ width: number,
167
+ height: number
168
+ ): void
169
+ drawStroke(context: CanvasRenderingContext2D): void
170
+ drawFill(context: CanvasRenderingContext2D): void
171
+ drawText(context: CanvasRenderingContext2D): void
172
+
173
+ ondblclick(e: MouseEvent): void
174
+ }
175
+
176
+ class ContainerAbstract extends MoveHandle(RectPath(Component)) {}
177
+ class Container extends MixinHTMLElement(ContainerAbstract) {
178
+ indexOf(component: Component): number
179
+ insertComponentAt(target: Component, idx: number): void
180
+ findById(id: string): Component
181
+ }
182
+ class RootContainer extends Container {}
183
+
184
+ class Layer extends ContainerAbstract {
185
+ target: HTMLElement
186
+ canvas: HTMLCanvasElement
187
+
188
+ getContext(): CanvasRenderingContext2D
189
+ invalidate(): void
190
+ }
191
+
192
+ class ModelLayer extends Layer {
193
+ overlay: HTMLDivElement
194
+ }
195
+
196
+ class Shape extends Component {}
197
+ class Ellipse extends Shape {}
198
+ class Rect extends RectPath(Shape) {}
199
+ class HTMLOverlayElement extends MixinHTMLElement(RectPath(Component)) {}
200
+
201
+ class HTMLOverlayContainer extends Container {
202
+ readonly layout: any
203
+ }
204
+
205
+ /* Scene API */
34
206
 
35
- export class Scene {
36
- static get residents(): WeakSet<Scene>
207
+ class Scene {
208
+ static readonly residents: WeakSet<Scene>
37
209
 
38
210
  /**
39
211
  * scene에 컴포넌트를 추가한다.
@@ -166,9 +338,9 @@ declare module '@hatiolab/things-scene' {
166
338
  */
167
339
  serialize(): string
168
340
 
169
- on(event: string, listener: Function, context: any): void
170
- once(event: string, listener: Function, context: any): void
171
- off(event: string, listener: Function, context: any): void
341
+ on(event: string, listener: Function, context?: any): void
342
+ once(event: string, listener: Function, context?: any): void
343
+ off(event: string, listener: Function, context?: any): void
172
344
 
173
345
  toDataURL(): string
174
346