@vyr/engine 0.0.32 → 0.0.34

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.
Files changed (137) hide show
  1. package/package.json +6 -3
  2. package/src/ArrayUtils.ts +63 -65
  3. package/src/AsyncTask.ts +67 -71
  4. package/src/Category.ts +69 -86
  5. package/src/Color.ts +3 -111
  6. package/src/Engine.ts +12 -24
  7. package/src/Executor.ts +109 -0
  8. package/src/Generate.ts +23 -40
  9. package/src/InputSystem.ts +106 -108
  10. package/src/Listener.ts +58 -59
  11. package/src/ObjectPool.ts +83 -84
  12. package/src/ObjectUtils.ts +97 -49
  13. package/src/Scriptable.ts +82 -0
  14. package/src/Serialization.ts +4 -6
  15. package/src/Traverser.ts +41 -39
  16. package/src/actor/Actor.ts +23 -27
  17. package/src/actor/AnimationUnitActor.ts +22 -36
  18. package/src/actor/DivActor.ts +21 -41
  19. package/src/actor/FragmentActor.ts +1 -5
  20. package/src/actor/HTMLActor.ts +81 -0
  21. package/src/actor/HTMLServiceActor.ts +49 -0
  22. package/src/actor/{HTMTransformControllerActor.ts → HTMLTransformControllerActor.ts} +178 -71
  23. package/src/actor/InputActor.ts +50 -0
  24. package/src/actor/TextActor.ts +51 -0
  25. package/src/actor/index.ts +6 -5
  26. package/src/asset/Asset.ts +23 -68
  27. package/src/asset/AssetGraph.ts +21 -28
  28. package/src/descriptor/AnimationUnit.ts +81 -0
  29. package/src/descriptor/Camera.ts +12 -0
  30. package/src/descriptor/Controller.ts +6 -0
  31. package/src/descriptor/Descriptor.ts +133 -113
  32. package/src/descriptor/Div.ts +29 -0
  33. package/src/descriptor/HTML.ts +22 -0
  34. package/src/descriptor/HTMLService.ts +42 -0
  35. package/src/descriptor/HTMLTransformController.ts +67 -0
  36. package/src/descriptor/Input.ts +29 -0
  37. package/src/descriptor/Interaction.ts +80 -0
  38. package/src/descriptor/Node.ts +98 -0
  39. package/src/descriptor/Scene.ts +110 -0
  40. package/src/descriptor/Service.ts +11 -0
  41. package/src/descriptor/Store.ts +136 -0
  42. package/src/descriptor/Text.ts +36 -0
  43. package/src/descriptor/index.ts +14 -15
  44. package/src/graphics/Collection.ts +1 -5
  45. package/src/graphics/Compilation.ts +15 -19
  46. package/src/graphics/Graphics.ts +41 -54
  47. package/src/graphics/Observer.ts +6 -14
  48. package/src/graphics/Unit.ts +3 -9
  49. package/src/graphics/VariableProxy.ts +11 -15
  50. package/src/index.ts +5 -5
  51. package/src/interpreter/AnimationUnitInterpreter.ts +7 -9
  52. package/src/interpreter/DivInterpreter.ts +10 -13
  53. package/src/interpreter/FragmentInterpreter.ts +2 -6
  54. package/src/interpreter/HTMLServiceInterpreter.ts +25 -15
  55. package/src/interpreter/HTMLTransformControllerInterpreter.ts +9 -12
  56. package/src/interpreter/InputInterpreter.ts +41 -0
  57. package/src/interpreter/Interpreter.ts +3 -4
  58. package/src/interpreter/SceneInterpreter.ts +93 -0
  59. package/src/interpreter/ServiceInterpreter.ts +8 -15
  60. package/src/interpreter/StoreInterpreter.ts +7 -0
  61. package/src/interpreter/TextInterpreter.ts +41 -0
  62. package/src/interpreter/index.ts +5 -7
  63. package/src/locale/Language.ts +1 -5
  64. package/src/locale/LanguageProvider.ts +164 -21
  65. package/src/math/Euler.ts +2 -5
  66. package/src/math/Matrix4.ts +2 -4
  67. package/src/math/Quaternion.ts +2 -4
  68. package/src/math/Vector2.ts +4 -4
  69. package/src/math/Vector3.ts +2 -4
  70. package/src/math/utils.ts +1 -5
  71. package/src/schema/AnimationUnit.ts +68 -0
  72. package/src/schema/Asset.ts +13 -0
  73. package/src/schema/Descriptor.ts +41 -0
  74. package/src/schema/HTML.ts +261 -0
  75. package/src/schema/Interaction.ts +50 -0
  76. package/src/schema/Scene.ts +138 -0
  77. package/src/schema/Store.ts +8 -0
  78. package/src/schema/index.ts +7 -0
  79. package/src/scripts/ConditionScriptable.ts +196 -0
  80. package/src/scripts/FetchScriptable.ts +51 -0
  81. package/src/scripts/FindScriptable.ts +23 -0
  82. package/src/scripts/InvokeScriptable.ts +13 -0
  83. package/src/scripts/SwitchSceneScriptable.ts +18 -0
  84. package/src/scripts/UpdateScriptable.ts +60 -0
  85. package/src/scripts/index.ts +6 -0
  86. package/src/utils/AssetProvider.ts +4 -77
  87. package/src/utils/DOM.ts +37 -0
  88. package/src/utils/HTML.ts +5 -0
  89. package/src/utils/Service.ts +40 -0
  90. package/src/utils/constants.ts +1 -5
  91. package/src/utils/http.ts +2 -21
  92. package/src/utils/index.ts +3 -1
  93. package/src/actor/HTMActor.ts +0 -169
  94. package/src/actor/HTMServiceActor.ts +0 -57
  95. package/src/actor/StyleActor.ts +0 -96
  96. package/src/descriptor/AnimationUnitDescriptor.ts +0 -65
  97. package/src/descriptor/CameraDescriptor.ts +0 -12
  98. package/src/descriptor/ControllerDescriptor.ts +0 -16
  99. package/src/descriptor/DatasetDescriptor.ts +0 -90
  100. package/src/descriptor/DivDescriptor.ts +0 -18
  101. package/src/descriptor/DynamicDescriptor.ts +0 -27
  102. package/src/descriptor/HTMLDescriptor.ts +0 -87
  103. package/src/descriptor/HTMLServiceDescriptor.ts +0 -19
  104. package/src/descriptor/HTMLTransformControllerDescriptor.ts +0 -34
  105. package/src/descriptor/NodeDescriptor.ts +0 -32
  106. package/src/descriptor/PrefabDescriptor.ts +0 -53
  107. package/src/descriptor/PrefabInstanceDescriptor.ts +0 -32
  108. package/src/descriptor/ServiceDescriptor.ts +0 -32
  109. package/src/descriptor/ServiceSchedulerDescriptor.ts +0 -32
  110. package/src/descriptor/StyleDescriptor.ts +0 -213
  111. package/src/interaction/InteractionDescriptor.ts +0 -96
  112. package/src/interaction/InteractionExecutor.ts +0 -84
  113. package/src/interaction/Scriptable.ts +0 -44
  114. package/src/interaction/index.ts +0 -3
  115. package/src/interpreter/DatasetInterpreter.ts +0 -11
  116. package/src/interpreter/DynamicInterpreter.ts +0 -207
  117. package/src/interpreter/PrefaInterpreter.ts +0 -11
  118. package/src/interpreter/PrefabInstanceInterpreter.ts +0 -12
  119. package/src/interpreter/ServiceSchedulerInterpreter.ts +0 -42
  120. package/src/interpreter/StyleInterpreter.ts +0 -66
  121. package/src/preset/execute/dataset/index.ts +0 -1
  122. package/src/preset/execute/dataset/update.ts +0 -51
  123. package/src/preset/execute/graphics/index.ts +0 -1
  124. package/src/preset/execute/graphics/invoke.ts +0 -48
  125. package/src/preset/execute/index.ts +0 -4
  126. package/src/preset/execute/net/http.ts +0 -52
  127. package/src/preset/execute/net/index.ts +0 -1
  128. package/src/preset/execute/scheduler/index.ts +0 -1
  129. package/src/preset/execute/scheduler/switch.ts +0 -46
  130. package/src/preset/index.ts +0 -7
  131. package/src/preset/interaction/graphics/index.ts +0 -1
  132. package/src/preset/interaction/graphics/invoke.ts +0 -27
  133. package/src/preset/interaction/index.ts +0 -2
  134. package/src/preset/interaction/scheduler/index.ts +0 -1
  135. package/src/preset/interaction/scheduler/switch.ts +0 -27
  136. package/src/setup/index.ts +0 -17
  137. package/src/utils/compile.ts +0 -50
@@ -1,169 +0,0 @@
1
- import { InteractionDescriptor, InteractionProperty } from "../interaction";
2
- import { Asset } from "../asset"
3
- import { Descriptor, HTMLDescriptor, HTMLStyle, StyleDescriptor } from "../descriptor"
4
- import { Graphics } from "../graphics";
5
- import { Actor } from "./Actor"
6
- import { StyleActor } from "./StyleActor"
7
-
8
- abstract class HTMLActor extends Actor {
9
- static className = 'vyr-html-wrapper'
10
- static uuidKey = 'data-vyr-uuid'
11
- static isTrigger(target: any, uuid: string): target is HTMLElement {
12
- return target.getAttribute(HTMLActor.uuidKey) === uuid
13
- }
14
- readonly uuid
15
- readonly unlisteners: Array<() => void> = []
16
- className?: string[]
17
-
18
- constructor(uuid: string) {
19
- super()
20
- this.uuid = uuid
21
- }
22
-
23
- createDOM() {
24
- const DOM = document.createElement('div')
25
- DOM.setAttribute(HTMLActor.uuidKey, this.uuid)
26
- DOM.style.width = '100%'
27
- DOM.style.height = '100%'
28
- DOM.style.position = 'relative'
29
- DOM.style.backgroundSize = '100% 100%'
30
- DOM.style.backgroundRepeat = 'no-repeat'
31
- DOM.style.backgroundPosition = '0% 0%'
32
- return DOM
33
- }
34
-
35
- getWrapperStyle(descriptor: HTMLDescriptor) {
36
- const style: HTMLStyle = {}
37
- style.pointerEvents = 'auto'
38
- style.flexGrow = descriptor.flexGrow + ''
39
- if (descriptor.visible === false) {
40
- style.display = 'none'
41
- } else {
42
- style.display = descriptor.display
43
- }
44
-
45
- const width = descriptor.width
46
- if (width < 0) {
47
- style.width = 'auto'
48
- } else {
49
- style.width = `calc(${width + descriptor.wUnit} + ${descriptor.calcWidth}px)`
50
- }
51
-
52
- const height = descriptor.height
53
- if (height < 0) {
54
- style.height = 'auto'
55
- } else {
56
- style.height = `calc(${height + descriptor.hUnit} + ${descriptor.calcHeight}px)`
57
- }
58
-
59
- style.position = descriptor.position
60
- style.transform = ''
61
- if (descriptor.translate.x !== 0) {
62
- style.transform += `translateX(${descriptor.translate.x}%) `
63
- }
64
- if (descriptor.translate.y !== 0) {
65
- style.transform += `translateY(${descriptor.translate.y}%) `
66
- }
67
-
68
- const xValue = descriptor.location.x + descriptor.xUnit
69
- if (descriptor.xAxis === 'left') {
70
- style.left = xValue
71
- style.right = ''
72
- } else {
73
- style.right = xValue
74
- style.left = ''
75
- }
76
- const yValue = descriptor.location.y + descriptor.yUnit
77
- if (descriptor.yAxis === 'top') {
78
- style.top = yValue
79
- style.bottom = ''
80
- } else {
81
- style.bottom = yValue
82
- style.top = ''
83
- }
84
-
85
- style.marginLeft = descriptor.margin.left + 'px'
86
- style.marginTop = descriptor.margin.top + 'px'
87
- style.marginRight = descriptor.margin.right + 'px'
88
- style.marginBottom = descriptor.margin.bottom + 'px'
89
-
90
- return style
91
- }
92
-
93
- getLayoutStyle(descriptor: HTMLDescriptor) {
94
- const style: HTMLStyle = {}
95
-
96
- style.display = descriptor.display
97
- style.flexWrap = descriptor.flexWrap
98
- style.flexDirection = descriptor.flexDirection
99
- style.justifyContent = descriptor.justifyContent
100
- style.alignItems = descriptor.alignItems
101
- style.alignContent = descriptor.alignContent
102
- style.opacity = descriptor.opacity + ''
103
- style.zIndex = descriptor.zIndex
104
-
105
- return style
106
- }
107
-
108
- setHTMLStyle(DOM: HTMLElement, style: HTMLStyle) {
109
- Object.assign(DOM.style, style)
110
- }
111
-
112
- getStyleClass(descriptor: HTMLDescriptor) {
113
- const styleDescriptor = Asset.get<StyleDescriptor>(descriptor.style)
114
- if (styleDescriptor === null) return []
115
- const graphics = Actor.getGraphics(this)
116
- const styleActor = graphics.getInterpreter(styleDescriptor).getActor<StyleActor>(descriptor)
117
- return styleActor.getClassName()
118
- }
119
-
120
- setStyleClass(DOM: HTMLElement, className: string[]) {
121
- this.clearStyleClass(DOM)
122
- this.className = className
123
- DOM.classList.add(...className)
124
- }
125
-
126
- clearStyleClass(DOM: HTMLElement) {
127
- if (this.className === undefined) return
128
- DOM.classList.remove(...this.className)
129
- delete this.className
130
- }
131
-
132
- bindInteraction(DOM: HTMLElement, property: InteractionProperty, trigger: Descriptor, graphics: Graphics,) {
133
- const interaction = Asset.get<InteractionDescriptor>(property.url)
134
-
135
- const listener = (e: Event) => {
136
- if (HTMLActor.isTrigger(e.target, this.uuid)) {
137
- e.stopPropagation()
138
- interaction.execute(property.inputs, graphics, trigger)
139
- }
140
- }
141
- const eid = graphics.engine.inputSystem.listen(property.type as any, listener, { target: DOM })
142
- this.unlisteners.push(() => graphics.engine.inputSystem.unlisten(eid))
143
- }
144
-
145
- cleanInteraction() {
146
- for (const unlistener of this.unlisteners) unlistener()
147
- this.unlisteners.length = 0
148
- }
149
-
150
- setHTMLInteraction(DOM: HTMLElement, trigger: Descriptor) {
151
- this.cleanInteraction()
152
- const graphics = HTMLActor.getGraphics(this)
153
- for (const interaction of trigger.interactions) {
154
- if (interaction.url) this.bindInteraction(DOM, interaction, trigger, graphics)
155
- }
156
- }
157
-
158
- abstract add(actor: Actor): void
159
-
160
- abstract remove(actor: Actor): void
161
-
162
- abstract getWrapper(): HTMLElement | null
163
-
164
- abstract update(descriptor: HTMLDescriptor): void
165
- }
166
-
167
- export {
168
- HTMLActor
169
- }
@@ -1,57 +0,0 @@
1
- import { HTMLServiceDescriptor, StyleDescriptor } from "../descriptor"
2
- import { Actor } from "./Actor"
3
- import { HTMLActor } from "./HTMActor"
4
-
5
- class HTMLServiceActor extends HTMLActor {
6
- private _wrapper: HTMLElement | null = null
7
- readonly DOM
8
-
9
- constructor(uuid: string) {
10
- super(uuid)
11
- this.DOM = this.createDOM()
12
- const wrapper = this.getWrapper()
13
- wrapper.appendChild(this.DOM)
14
- }
15
-
16
- protected createWrapper() {
17
- const wrapper = document.createElement('div')
18
- wrapper.setAttribute('class', HTMLActor.className)
19
- wrapper.setAttribute(HTMLActor.uuidKey, this.uuid)
20
- return wrapper
21
- }
22
-
23
- getWrapper() {
24
- if (this._wrapper === null) {
25
- this._wrapper = this.createWrapper()
26
- }
27
-
28
- return this._wrapper
29
- }
30
-
31
- add(actor: Actor) {
32
- if (actor instanceof HTMLActor) {
33
- const wrapper = actor.getWrapper()
34
- if (wrapper === null) return
35
- if (this.DOM.contains(wrapper)) return
36
- this.DOM.appendChild(wrapper)
37
- }
38
- }
39
-
40
- remove(actor: Actor) {
41
- if (actor instanceof HTMLActor) {
42
- const wrapper = actor.getWrapper()
43
- if (wrapper === null) return
44
- if (this.DOM.contains(wrapper)) this.DOM.removeChild(wrapper)
45
- }
46
- }
47
-
48
- update(descriptor: HTMLServiceDescriptor) {
49
- const wrapper = this.getWrapper()
50
- this.setHTMLStyle(wrapper, this.getWrapperStyle(descriptor))
51
- const styleClass = [...this.getStyleClass(descriptor)]
52
- if (descriptor.active) styleClass.push(StyleDescriptor.activeName)
53
- this.setStyleClass(this.DOM, styleClass)
54
- }
55
- }
56
-
57
- export { HTMLServiceActor }
@@ -1,96 +0,0 @@
1
- import { Asset } from "../asset"
2
- import { Actor } from "./Actor"
3
- import { StyleDescriptor } from "../descriptor"
4
- import { StyleInterpreter } from "../interpreter"
5
-
6
- interface RuleObjects extends Array<{ name: string, value: string }> { }
7
-
8
- class StyleActor extends Actor {
9
- private _styleCollection = new Map<string, RuleObjects>()
10
- private _className: string[] = []
11
-
12
- getStyleValue() {
13
- const styles: string[] = []
14
-
15
- const entries = this._styleCollection.entries()
16
- for (const [selectorText, rules] of entries) {
17
- const style: string[] = []
18
- style.push(`${selectorText}{`)
19
- if (rules.length === 0) {
20
- style.push('/* 如果需要样式,在这里添加 */')
21
- } else {
22
- for (const rule of rules) {
23
- style.push(`${rule.name}:${rule.value};`)
24
- }
25
- }
26
- style.push(`}`)
27
- styles.push(style.join('\n'))
28
- }
29
-
30
- return styles
31
- }
32
-
33
- getClassName() {
34
- return [...this._className]
35
- }
36
-
37
- updateRule(sheet: CSSStyleSheet) {
38
- let count = 0
39
- for (const rule of sheet.cssRules) {
40
- if (rule instanceof CSSStyleRule) {
41
- const styleObjects = this._styleCollection.get(rule.selectorText)
42
- if (styleObjects === undefined) continue
43
-
44
- count++
45
- rule.style.cssText = ''
46
- for (const styleObject of styleObjects) {
47
- rule.style.setProperty(styleObject.name, styleObject.value)
48
- }
49
-
50
- if (count === 2) return true
51
- }
52
- }
53
- return false
54
- }
55
-
56
- update(descriptor: StyleDescriptor, className: string) {
57
- this._className.length = 0
58
- this._styleCollection.clear()
59
-
60
- let inherit = Asset.get<StyleDescriptor>(descriptor.inherit)
61
- if (inherit) {
62
- const graphics = Actor.getGraphics(this)
63
- const interpreter = graphics.getInterpreter<StyleInterpreter>(inherit)
64
- this._className.push(interpreter.className)
65
- }
66
- this._className.push(className)
67
-
68
- const rules: RuleObjects = []
69
- for (const rule of descriptor.rules) {
70
- if (rule.inherit === true) continue
71
- const value = rule.getValue()
72
- rules.push({ name: rule.name, value })
73
- }
74
- this._styleCollection.set(`.${className}`, rules)
75
-
76
- const hover: RuleObjects = []
77
- for (const rule of descriptor.hoverRules) {
78
- if (rule.inherit === true) continue
79
- const value = rule.getValue()
80
- hover.push({ name: rule.name, value })
81
- }
82
- this._styleCollection.set(`.${className}:hover`, hover)
83
-
84
- const active: RuleObjects = []
85
- for (const rule of descriptor.activeRules) {
86
- if (rule.inherit === true) continue
87
- const value = rule.getValue()
88
- active.push({ name: rule.name, value })
89
- }
90
- this._styleCollection.set(`.${className}.${StyleDescriptor.activeName}`, active)
91
- }
92
- }
93
-
94
- export {
95
- StyleActor
96
- }
@@ -1,65 +0,0 @@
1
- import { DeserializationObject } from "../Serialization"
2
- import { Descriptor } from "./Descriptor"
3
-
4
- interface FrameData {
5
- type: string
6
- startValue: Array<string | number | boolean> | number | string
7
- endValue: Array<string | number | boolean> | number | string
8
- }
9
-
10
- interface NumberFrameData extends FrameData {
11
- type: 'number' | 'boolean'
12
- startValue: number
13
- endValue: number
14
- }
15
-
16
- interface VectorFrameData extends FrameData {
17
- type: 'vector2' | 'vector3' | 'euler'
18
- startValue: number[]
19
- endValue: number[]
20
- }
21
-
22
- interface ColorFrameData extends FrameData {
23
- type: 'color'
24
- startValue: string
25
- endValue: string
26
- }
27
-
28
- type AnimationFrameData = NumberFrameData | VectorFrameData | ColorFrameData
29
-
30
- class AnimationUnitDescriptor extends Descriptor {
31
- static type = 'AnimationUnit'
32
-
33
- play: boolean
34
- duration: number
35
- /**循环次数 */
36
- count: number
37
- /**循环模式
38
- *
39
- * - 1 顺序循环
40
- * - 2 往返循环
41
- */
42
- mode: number
43
- startTime: number
44
- path: string
45
- frameData: AnimationFrameData
46
-
47
- constructor(descriptor: Partial<DeserializationObject<AnimationUnitDescriptor>> = {}) {
48
- super(descriptor)
49
- this.play = descriptor.play ?? false
50
- this.duration = descriptor.duration ?? 0
51
- this.count = descriptor.count ?? Infinity
52
- this.mode = descriptor.mode ?? 1
53
- this.startTime = descriptor.startTime ?? 0
54
- this.path = descriptor.path ?? ''
55
- this.frameData = descriptor.frameData ? Descriptor.deepClone<AnimationFrameData>(descriptor.frameData) : { type: 'vector2', startValue: [], endValue: [] } as VectorFrameData
56
- }
57
- }
58
- Descriptor.register(AnimationUnitDescriptor)
59
-
60
- export {
61
- NumberFrameData,
62
- VectorFrameData,
63
- AnimationFrameData,
64
- AnimationUnitDescriptor
65
- }
@@ -1,12 +0,0 @@
1
- import { DeserializationObject } from "../Serialization"
2
- import { NodeDescriptor } from "./NodeDescriptor"
3
-
4
- class CameraDescriptor extends NodeDescriptor {
5
- static type = 'Camera'
6
-
7
- constructor(descriptor: Partial<DeserializationObject<CameraDescriptor>> = {}) {
8
- super(descriptor)
9
- }
10
- }
11
-
12
- export { CameraDescriptor }
@@ -1,16 +0,0 @@
1
- import { DeserializationObject } from "../Serialization"
2
- import { Descriptor } from "./Descriptor"
3
-
4
- class ControllerDescriptor extends Descriptor {
5
- static type = 'Controller'
6
-
7
- /**控制器是否响应用户的操作 */
8
- enabled: boolean
9
-
10
- constructor(descriptor: Partial<DeserializationObject<ControllerDescriptor>> = {}) {
11
- super(descriptor)
12
- this.enabled = descriptor.enabled ?? false
13
- }
14
- }
15
-
16
- export { ControllerDescriptor }
@@ -1,90 +0,0 @@
1
- import { HttpType } from "../utils/constants";
2
- import { Asset } from "../asset";
3
- import { observer } from "../graphics/Observer";
4
- import { DeserializationObject } from "../Serialization";
5
- import { Descriptor } from "./Descriptor";
6
-
7
- interface Data {
8
- [k: string]: any
9
- }
10
-
11
- interface DataConfig {
12
- mode: string
13
- key: string
14
- }
15
-
16
- interface HttpDataConfig extends DataConfig {
17
- mode: 'http',
18
- url: string
19
- type: HttpType
20
- }
21
-
22
- class DatasetDescriptor<C extends DataConfig = HttpDataConfig> extends Descriptor {
23
- static type = 'Dataset'
24
-
25
- static getData<T = Data>(dataset: string) {
26
- const descriptor = Asset.get(dataset)
27
- if (descriptor instanceof DatasetDescriptor) {
28
- return descriptor.getData() as T
29
- } else {
30
- return null
31
- }
32
- }
33
- static getCollection<T = Data>(dataset: string): T[] {
34
- const data = this.getData<T>(dataset)
35
-
36
- if (!data) return []
37
-
38
- return Array.isArray(data) ? data : [data]
39
- }
40
-
41
- private _data!: Data
42
- private _extraData: Data = {}
43
- readonly dataConfigs: C[]
44
- defaultData: Data
45
-
46
- constructor(descriptor: Partial<DeserializationObject<DatasetDescriptor>> = {}) {
47
- super(descriptor)
48
- this.dataConfigs = descriptor.dataConfigs === undefined ? [] : Descriptor.deepClone(descriptor.dataConfigs)
49
- this.defaultData = descriptor.defaultData === undefined ? {} : Descriptor.deepClone(descriptor.defaultData)
50
- this._updateData(this.defaultData)
51
- }
52
-
53
- private _updateData(data: Data) {
54
- this._data = data
55
- }
56
-
57
- getData<T extends Data | null = Data | null>() {
58
- return (this._data ?? null) as T
59
- }
60
-
61
- setData(data: Data) {
62
- this._updateData(data)
63
-
64
- observer.trigger('updateDeps', { self: this.uuid })
65
- }
66
-
67
- setExtraData(data: Data) {
68
- this._extraData = data
69
- }
70
-
71
- getExtraData<T extends Data = Data>() {
72
- return this._extraData as T
73
- }
74
-
75
- toJSON() {
76
- const { _data, _extraData, ...rest } = this;
77
- return rest;
78
- }
79
-
80
- setNeedsUpdate() { }
81
- }
82
-
83
- Descriptor.register(DatasetDescriptor)
84
-
85
- export {
86
- Data,
87
- DataConfig,
88
- HttpDataConfig,
89
- DatasetDescriptor
90
- }
@@ -1,18 +0,0 @@
1
- import { DeserializationObject } from "../Serialization"
2
- import { HTMLDescriptor } from "./HTMLDescriptor"
3
-
4
- class DivDescriptor extends HTMLDescriptor {
5
- static type = 'Div'
6
-
7
- text: string
8
- backroundIamge: string
9
-
10
- constructor(descriptor: Partial<DeserializationObject<DivDescriptor>> = {}) {
11
- super(descriptor)
12
- this.text = descriptor.text ?? ''
13
- this.backroundIamge = descriptor.backroundIamge ?? ''
14
- }
15
- }
16
- HTMLDescriptor.register(DivDescriptor)
17
-
18
- export { DivDescriptor }
@@ -1,27 +0,0 @@
1
- import { DeserializationObject } from "../Serialization"
2
- import { Descriptor } from "./Descriptor"
3
-
4
- class DynamicDescriptor extends Descriptor {
5
- static type = 'Dynamic'
6
-
7
- url: string
8
- /** 数据集配置
9
- * - 1 使用节点自身的数据集
10
- * - 2 使用父节点数据集的属性
11
- */
12
- dataConfig: number
13
- /**根节点数据集属性的路径 */
14
- dataPath: string
15
-
16
- constructor(descriptor: Partial<DeserializationObject<DynamicDescriptor>> = {}) {
17
- super(descriptor)
18
- this.url = descriptor.url ?? ''
19
- this.dataConfig = descriptor.dataConfig ?? 1
20
- this.dataPath = descriptor.dataPath ?? ''
21
- }
22
- }
23
- Descriptor.register(DynamicDescriptor)
24
-
25
- export {
26
- DynamicDescriptor
27
- }
@@ -1,87 +0,0 @@
1
- import { Vector2 } from "../math"
2
- import { DeserializationObject } from "../Serialization"
3
- import { Descriptor } from "./Descriptor"
4
- import { StyleSpacing } from "./StyleDescriptor"
5
-
6
- interface HTMLStyle {
7
- [k: string]: string
8
- }
9
-
10
- class HTMLDescriptor extends Descriptor {
11
- static type = 'HTML'
12
-
13
- visible: boolean
14
- active: boolean
15
- style: string
16
- display: string
17
- flexWrap: string
18
- flexDirection: string
19
- justifyContent: string
20
- alignItems: string
21
- alignContent: string
22
- margin: StyleSpacing
23
- /** 项目的放大比例,定义在分配多余空间时项目的放大能力,默认0(不放大) */
24
- flexGrow: number
25
- /**宽度
26
- * - -1 宽度根据内容自适应
27
- */
28
- width: number
29
- wUnit: string
30
- calcWidth: number
31
- /**高度
32
- * - -1 高度根据内容自适应
33
- */
34
- height: number
35
- hUnit: string
36
- calcHeight: number
37
-
38
- position: string
39
- location: Vector2
40
-
41
- xAxis: 'left' | 'right'
42
- xUnit: string
43
-
44
- yAxis: 'top' | 'bottom'
45
- yUnit: string
46
-
47
- translate: Vector2
48
-
49
- opacity: number
50
- zIndex: string
51
-
52
- constructor(descriptor: Partial<DeserializationObject<HTMLDescriptor>> = {}) {
53
- super(descriptor)
54
-
55
- this.visible = descriptor.visible ?? true
56
- this.active = descriptor.active ?? false
57
- this.style = descriptor.style ?? ''
58
- this.display = descriptor.display ?? 'block'
59
- this.flexWrap = descriptor.flexWrap ?? 'nowrap'
60
- this.flexDirection = descriptor.flexDirection ?? 'row'
61
- this.justifyContent = descriptor.justifyContent ?? 'flex-start'
62
- this.alignItems = descriptor.alignItems ?? 'stretch'
63
- this.alignContent = descriptor.alignContent ?? 'stretch'
64
- this.flexGrow = descriptor.flexGrow ?? 0
65
- this.margin = new StyleSpacing(descriptor.margin)
66
-
67
- this.width = descriptor.width ?? 100
68
- this.wUnit = descriptor.wUnit ?? 'px'
69
- this.calcWidth = descriptor.calcWidth ?? 0
70
- this.calcHeight = descriptor.calcHeight ?? 0
71
- this.height = descriptor.height ?? 100
72
- this.hUnit = descriptor.hUnit ?? 'px'
73
- this.position = descriptor.position ?? 'static'
74
- this.location = Vector2.create(descriptor.location)
75
- this.xAxis = descriptor.xAxis ?? 'left'
76
- this.xUnit = descriptor.xUnit ?? 'px'
77
- this.yAxis = descriptor.yAxis ?? 'top'
78
- this.yUnit = descriptor.yUnit ?? 'px'
79
-
80
- this.translate = Vector2.create(descriptor.translate)
81
-
82
- this.opacity = descriptor.opacity ?? 1
83
- this.zIndex = descriptor.zIndex ?? 'auto'
84
- }
85
- }
86
-
87
- export { HTMLStyle, HTMLDescriptor }
@@ -1,19 +0,0 @@
1
- import { DeserializationObject } from "../Serialization"
2
- import { ServiceDescriptor } from "./ServiceDescriptor"
3
-
4
- class HTMLServiceDescriptor extends ServiceDescriptor {
5
- static type = 'HTMLService'
6
-
7
- constructor(descriptor: Partial<DeserializationObject<HTMLServiceDescriptor>> = {}) {
8
- super(descriptor)
9
- this.width = descriptor.width ?? 100
10
- this.wUnit = descriptor.wUnit ?? '%'
11
- this.height = descriptor.height ?? 100
12
- this.hUnit = descriptor.hUnit ?? '%'
13
- this.position = descriptor.position ?? 'absolute'
14
- }
15
- }
16
-
17
- ServiceDescriptor.register(HTMLServiceDescriptor)
18
-
19
- export { HTMLServiceDescriptor }
@@ -1,34 +0,0 @@
1
- import { DeserializationObject } from "../Serialization"
2
- import { ControllerDescriptor } from "./ControllerDescriptor"
3
- import { ScriptableArgs } from "../interaction"
4
-
5
- interface HTMLTransformControllerChangeArgs extends ScriptableArgs<undefined, undefined, undefined> {
6
- event: {
7
- type: string
8
- target: string
9
- }
10
- }
11
-
12
- class HTMLTransformControllerDescriptor extends ControllerDescriptor {
13
- static type = 'HTMLTransformController'
14
-
15
- /**控制器的摄像机 */
16
- camera: string
17
- /**控制器的模式 */
18
- mode: string
19
- /**控制器的目标 */
20
- target: string
21
- /**控制器触发事件时执行的脚本依赖 */
22
- event: string
23
-
24
- constructor(descriptor: Partial<DeserializationObject<HTMLTransformControllerDescriptor>> = {}) {
25
- super(descriptor)
26
- this.camera = descriptor.camera ?? ''
27
- this.mode = descriptor.mode ?? ''
28
- this.target = descriptor.target ?? ''
29
- this.event = descriptor.event ?? ''
30
- }
31
- }
32
- ControllerDescriptor.register(HTMLTransformControllerDescriptor)
33
-
34
- export { HTMLTransformControllerChangeArgs, HTMLTransformControllerDescriptor }