@vyr/engine 0.0.33 → 0.0.35
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/package.json +6 -3
- package/src/ArrayUtils.ts +63 -65
- package/src/AsyncTask.ts +67 -71
- package/src/Category.ts +69 -86
- package/src/Color.ts +3 -111
- package/src/Engine.ts +12 -24
- package/src/Executor.ts +109 -0
- package/src/Generate.ts +23 -40
- package/src/InputSystem.ts +106 -108
- package/src/Listener.ts +58 -59
- package/src/ObjectPool.ts +83 -84
- package/src/ObjectUtils.ts +97 -49
- package/src/Scriptable.ts +82 -0
- package/src/Serialization.ts +4 -6
- package/src/Traverser.ts +41 -39
- package/src/actor/Actor.ts +23 -27
- package/src/actor/AnimationUnitActor.ts +22 -36
- package/src/actor/DivActor.ts +21 -41
- package/src/actor/FragmentActor.ts +1 -5
- package/src/actor/HTMLActor.ts +81 -0
- package/src/actor/HTMLServiceActor.ts +49 -0
- package/src/actor/{HTMTransformControllerActor.ts → HTMLTransformControllerActor.ts} +178 -71
- package/src/actor/InputActor.ts +50 -0
- package/src/actor/TextActor.ts +51 -0
- package/src/actor/index.ts +6 -5
- package/src/asset/Asset.ts +23 -68
- package/src/asset/AssetGraph.ts +21 -28
- package/src/descriptor/AnimationUnit.ts +81 -0
- package/src/descriptor/Camera.ts +12 -0
- package/src/descriptor/Controller.ts +6 -0
- package/src/descriptor/Descriptor.ts +133 -113
- package/src/descriptor/Div.ts +29 -0
- package/src/descriptor/HTML.ts +22 -0
- package/src/descriptor/HTMLService.ts +42 -0
- package/src/descriptor/HTMLTransformController.ts +67 -0
- package/src/descriptor/Input.ts +29 -0
- package/src/descriptor/Interaction.ts +80 -0
- package/src/descriptor/Node.ts +98 -0
- package/src/descriptor/Scene.ts +110 -0
- package/src/descriptor/Service.ts +11 -0
- package/src/descriptor/Store.ts +136 -0
- package/src/descriptor/Text.ts +36 -0
- package/src/descriptor/index.ts +14 -15
- package/src/graphics/Collection.ts +1 -5
- package/src/graphics/Compilation.ts +15 -19
- package/src/graphics/Graphics.ts +41 -54
- package/src/graphics/Observer.ts +6 -14
- package/src/graphics/Unit.ts +3 -9
- package/src/graphics/VariableProxy.ts +11 -15
- package/src/index.ts +5 -5
- package/src/interpreter/AnimationUnitInterpreter.ts +7 -9
- package/src/interpreter/DivInterpreter.ts +10 -13
- package/src/interpreter/FragmentInterpreter.ts +2 -6
- package/src/interpreter/HTMLServiceInterpreter.ts +25 -15
- package/src/interpreter/HTMLTransformControllerInterpreter.ts +9 -12
- package/src/interpreter/InputInterpreter.ts +41 -0
- package/src/interpreter/Interpreter.ts +3 -4
- package/src/interpreter/SceneInterpreter.ts +93 -0
- package/src/interpreter/ServiceInterpreter.ts +8 -15
- package/src/interpreter/StoreInterpreter.ts +7 -0
- package/src/interpreter/TextInterpreter.ts +41 -0
- package/src/interpreter/index.ts +5 -7
- package/src/locale/Language.ts +1 -5
- package/src/locale/LanguageProvider.ts +164 -21
- package/src/math/Euler.ts +2 -5
- package/src/math/Matrix4.ts +2 -4
- package/src/math/Quaternion.ts +2 -4
- package/src/math/Vector2.ts +4 -4
- package/src/math/Vector3.ts +2 -4
- package/src/math/utils.ts +1 -5
- package/src/schema/AnimationUnit.ts +68 -0
- package/src/schema/Asset.ts +13 -0
- package/src/schema/Descriptor.ts +41 -0
- package/src/schema/HTML.ts +261 -0
- package/src/schema/Interaction.ts +50 -0
- package/src/schema/Scene.ts +138 -0
- package/src/schema/Store.ts +8 -0
- package/src/schema/index.ts +7 -0
- package/src/scripts/ConditionScriptable.ts +196 -0
- package/src/scripts/FetchScriptable.ts +51 -0
- package/src/scripts/FindScriptable.ts +23 -0
- package/src/scripts/InvokeScriptable.ts +13 -0
- package/src/scripts/SwitchSceneScriptable.ts +18 -0
- package/src/scripts/UpdateScriptable.ts +60 -0
- package/src/scripts/index.ts +6 -0
- package/src/utils/AssetProvider.ts +4 -77
- package/src/utils/DOM.ts +37 -0
- package/src/utils/HTML.ts +5 -0
- package/src/utils/Service.ts +40 -0
- package/src/utils/constants.ts +1 -5
- package/src/utils/http.ts +2 -21
- package/src/utils/index.ts +3 -1
- package/src/actor/HTMActor.ts +0 -169
- package/src/actor/HTMServiceActor.ts +0 -57
- package/src/actor/StyleActor.ts +0 -96
- package/src/descriptor/AnimationUnitDescriptor.ts +0 -65
- package/src/descriptor/CameraDescriptor.ts +0 -12
- package/src/descriptor/ControllerDescriptor.ts +0 -16
- package/src/descriptor/DatasetDescriptor.ts +0 -90
- package/src/descriptor/DivDescriptor.ts +0 -18
- package/src/descriptor/DynamicDescriptor.ts +0 -27
- package/src/descriptor/HTMLDescriptor.ts +0 -87
- package/src/descriptor/HTMLServiceDescriptor.ts +0 -19
- package/src/descriptor/HTMLTransformControllerDescriptor.ts +0 -34
- package/src/descriptor/NodeDescriptor.ts +0 -32
- package/src/descriptor/PrefabDescriptor.ts +0 -53
- package/src/descriptor/PrefabInstanceDescriptor.ts +0 -32
- package/src/descriptor/ServiceDescriptor.ts +0 -32
- package/src/descriptor/ServiceSchedulerDescriptor.ts +0 -32
- package/src/descriptor/StyleDescriptor.ts +0 -213
- package/src/interaction/InteractionDescriptor.ts +0 -96
- package/src/interaction/InteractionExecutor.ts +0 -84
- package/src/interaction/Scriptable.ts +0 -44
- package/src/interaction/index.ts +0 -3
- package/src/interpreter/DatasetInterpreter.ts +0 -11
- package/src/interpreter/DynamicInterpreter.ts +0 -207
- package/src/interpreter/PrefaInterpreter.ts +0 -11
- package/src/interpreter/PrefabInstanceInterpreter.ts +0 -12
- package/src/interpreter/ServiceSchedulerInterpreter.ts +0 -42
- package/src/interpreter/StyleInterpreter.ts +0 -66
- package/src/preset/execute/dataset/index.ts +0 -1
- package/src/preset/execute/dataset/update.ts +0 -51
- package/src/preset/execute/graphics/index.ts +0 -1
- package/src/preset/execute/graphics/invoke.ts +0 -48
- package/src/preset/execute/index.ts +0 -4
- package/src/preset/execute/net/http.ts +0 -52
- package/src/preset/execute/net/index.ts +0 -1
- package/src/preset/execute/scheduler/index.ts +0 -1
- package/src/preset/execute/scheduler/switch.ts +0 -46
- package/src/preset/index.ts +0 -7
- package/src/preset/interaction/graphics/index.ts +0 -1
- package/src/preset/interaction/graphics/invoke.ts +0 -27
- package/src/preset/interaction/index.ts +0 -2
- package/src/preset/interaction/scheduler/index.ts +0 -1
- package/src/preset/interaction/scheduler/switch.ts +0 -27
- package/src/setup/index.ts +0 -17
- package/src/utils/compile.ts +0 -50
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Vector2 } from "../math"
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Scriptable } from "../interaction/Scriptable"
|
|
2
|
+
import { Descriptor, HTML, HTMLTransformController } from "../descriptor"
|
|
3
|
+
import { Scriptable } from "../Scriptable"
|
|
5
4
|
import { Actor } from "./Actor"
|
|
6
|
-
import { HTMLActor } from "./
|
|
5
|
+
import { HTMLActor } from "./HTMLActor"
|
|
6
|
+
import { isHTML } from "../utils"
|
|
7
7
|
|
|
8
8
|
class HTMLTransformState {
|
|
9
9
|
isDragging = false
|
|
@@ -25,14 +25,14 @@ class HTMLTransformState {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
class HTMLTransformControllerActor extends Actor {
|
|
28
|
+
export class HTMLTransformControllerActor extends Actor {
|
|
29
29
|
state = new HTMLTransformState()
|
|
30
30
|
offset = new Vector2()
|
|
31
31
|
events: number[] = []
|
|
32
32
|
element: HTMLElement
|
|
33
33
|
circles: HTMLElement[]
|
|
34
|
-
target!:
|
|
35
|
-
descriptor!:
|
|
34
|
+
target!: HTML
|
|
35
|
+
descriptor!: HTMLTransformController
|
|
36
36
|
|
|
37
37
|
constructor() {
|
|
38
38
|
super()
|
|
@@ -98,22 +98,21 @@ class HTMLTransformControllerActor extends Actor {
|
|
|
98
98
|
circle.style.cursor = [1, 3].includes(index) ? 'nesw-resize' : 'nwse-resize'
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
this.reset()
|
|
101
|
+
transform(descriptor: HTMLTransformController) {
|
|
103
102
|
const graphics = Actor.getGraphics(this)
|
|
104
103
|
const target = graphics.variableProxy.get<Descriptor>(descriptor.target, graphics)
|
|
105
|
-
if (target
|
|
104
|
+
if (isHTML(target)) {
|
|
106
105
|
|
|
107
106
|
const targetActor = graphics.getActor<HTMLActor>(target)
|
|
108
107
|
if (targetActor === null) return
|
|
109
108
|
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
109
|
+
const DOM = targetActor.getDOM()
|
|
110
|
+
if (DOM === null) return
|
|
112
111
|
|
|
113
112
|
this.descriptor = descriptor
|
|
114
113
|
this.target = target
|
|
115
114
|
|
|
116
|
-
this.selectTargetElement(
|
|
115
|
+
this.selectTargetElement(DOM)
|
|
117
116
|
|
|
118
117
|
this.events.push(graphics.engine.inputSystem.listen('mousedown', this.handleDragStart, { target: this.element }))
|
|
119
118
|
for (const circle of this.circles) {
|
|
@@ -124,25 +123,46 @@ class HTMLTransformControllerActor extends Actor {
|
|
|
124
123
|
}
|
|
125
124
|
}
|
|
126
125
|
|
|
126
|
+
highlight(descriptor: HTMLTransformController) {
|
|
127
|
+
const graphics = Actor.getGraphics(this)
|
|
128
|
+
const target = graphics.variableProxy.get<Descriptor>(descriptor.highlight, graphics)
|
|
129
|
+
if (isHTML(target)) {
|
|
130
|
+
|
|
131
|
+
const targetActor = graphics.getActor<HTMLActor>(target)
|
|
132
|
+
if (targetActor === null) return
|
|
133
|
+
|
|
134
|
+
const DOM = targetActor.getDOM()
|
|
135
|
+
if (DOM === null) return
|
|
136
|
+
|
|
137
|
+
this.descriptor = descriptor
|
|
138
|
+
this.target = target
|
|
139
|
+
|
|
140
|
+
this.selectTargetElement(DOM)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
listen(descriptor: HTMLTransformController) {
|
|
145
|
+
this.reset()
|
|
146
|
+
if (descriptor.highlight) {
|
|
147
|
+
this.highlight(descriptor)
|
|
148
|
+
} else {
|
|
149
|
+
this.transform(descriptor)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
127
153
|
unlisten() {
|
|
128
154
|
this.reset()
|
|
129
155
|
}
|
|
130
156
|
|
|
131
|
-
update(descriptor:
|
|
157
|
+
update(descriptor: HTMLTransformController) {
|
|
132
158
|
this.listen(descriptor)
|
|
133
159
|
}
|
|
134
160
|
|
|
135
161
|
change = (type = 'change') => {
|
|
136
|
-
const scriptable =
|
|
162
|
+
const scriptable = Scriptable.use(this.descriptor.event)
|
|
137
163
|
if (scriptable === null) return
|
|
138
164
|
const graphics = Actor.getGraphics(this)
|
|
139
|
-
|
|
140
|
-
event: { type, target: this.descriptor.target },
|
|
141
|
-
trigger: this.descriptor,
|
|
142
|
-
input: undefined,
|
|
143
|
-
result: undefined,
|
|
144
|
-
}
|
|
145
|
-
scriptable.execute(graphics, _args)
|
|
165
|
+
scriptable.execute(graphics, this.descriptor.uuid, { type, target: this.descriptor.target })
|
|
146
166
|
}
|
|
147
167
|
|
|
148
168
|
reset() {
|
|
@@ -174,10 +194,18 @@ class HTMLTransformControllerActor extends Actor {
|
|
|
174
194
|
}
|
|
175
195
|
|
|
176
196
|
updateOffset(rect: DOMRect = this.state.target.initialRect) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
)
|
|
197
|
+
// 从 style 中解析 translate 值
|
|
198
|
+
const transform = this.target.htmlAttributes.style.transform || '';
|
|
199
|
+
const translateMatch = transform.match(/translate\(([^)]+)\)/);
|
|
200
|
+
if (translateMatch) {
|
|
201
|
+
const [x, y] = translateMatch[1].split(',').map(v => parseFloat(v.trim()));
|
|
202
|
+
this.offset.set(
|
|
203
|
+
rect.width * (x / 100),
|
|
204
|
+
rect.height * (y / 100)
|
|
205
|
+
);
|
|
206
|
+
} else {
|
|
207
|
+
this.offset.set(0, 0);
|
|
208
|
+
}
|
|
181
209
|
}
|
|
182
210
|
|
|
183
211
|
// 更新拖拽元素以匹配目标
|
|
@@ -202,12 +230,26 @@ class HTMLTransformControllerActor extends Actor {
|
|
|
202
230
|
|
|
203
231
|
// 设置尺寸
|
|
204
232
|
if (resize) {
|
|
205
|
-
|
|
206
|
-
|
|
233
|
+
const computedStyle = getComputedStyle(this.state.target.element);
|
|
234
|
+
const paddingLeft = parseFloat(computedStyle.paddingLeft);
|
|
235
|
+
const paddingRight = parseFloat(computedStyle.paddingRight);
|
|
236
|
+
const paddingTop = parseFloat(computedStyle.paddingTop);
|
|
237
|
+
const paddingBottom = parseFloat(computedStyle.paddingBottom);
|
|
238
|
+
const borderLeft = parseFloat(computedStyle.borderLeftWidth);
|
|
239
|
+
const borderRight = parseFloat(computedStyle.borderRightWidth);
|
|
240
|
+
const borderTop = parseFloat(computedStyle.borderTopWidth);
|
|
241
|
+
const borderBottom = parseFloat(computedStyle.borderBottomWidth);
|
|
242
|
+
|
|
243
|
+
const calcWidth = paddingLeft + paddingRight + borderLeft + borderRight;
|
|
244
|
+
const calcHeight = paddingTop + paddingBottom + borderTop + borderBottom;
|
|
245
|
+
|
|
246
|
+
this.setDimension('width', draggableRect.width - calcWidth, parentRect.width);
|
|
247
|
+
this.setDimension('height', draggableRect.height - calcHeight, parentRect.height);
|
|
207
248
|
}
|
|
208
249
|
|
|
209
250
|
// 设置位置
|
|
210
|
-
|
|
251
|
+
const position = this.target.htmlAttributes.style.position || 'static';
|
|
252
|
+
if (position === 'fixed') {
|
|
211
253
|
this.setFixedPosition(draggableRect)
|
|
212
254
|
} else {
|
|
213
255
|
this.setRelativePosition(draggableRect, parentRect);
|
|
@@ -216,62 +258,113 @@ class HTMLTransformControllerActor extends Actor {
|
|
|
216
258
|
this.target.setNeedsUpdate()
|
|
217
259
|
}
|
|
218
260
|
|
|
261
|
+
// 从 style 中获取单位
|
|
262
|
+
getUnitFromStyle = (property: string): string => {
|
|
263
|
+
const value = this.target.htmlAttributes.style[property as any] || '';
|
|
264
|
+
if (value.endsWith('%')) return '%';
|
|
265
|
+
if (value.endsWith('px')) return 'px';
|
|
266
|
+
if (value.endsWith('em')) return 'em';
|
|
267
|
+
if (value.endsWith('rem')) return 'rem';
|
|
268
|
+
return 'px';
|
|
269
|
+
}
|
|
270
|
+
|
|
219
271
|
// 设置元素尺寸
|
|
220
|
-
setDimension = (prop:
|
|
221
|
-
|
|
222
|
-
|
|
272
|
+
setDimension = (prop: 'width' | 'height', value: number, parentSize: number) => {
|
|
273
|
+
const unit = this.getUnitFromStyle(prop);
|
|
274
|
+
if (unit === '%') {
|
|
275
|
+
this.target.htmlAttributes.style[prop] = `${(value / parentSize) * 100}%`;
|
|
276
|
+
} else {
|
|
277
|
+
this.target.htmlAttributes.style[prop] = `${value}${unit}`;
|
|
278
|
+
}
|
|
223
279
|
}
|
|
224
280
|
|
|
225
281
|
// 设置固定定位
|
|
226
282
|
setFixedPosition = (rect: DOMRect) => {
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
283
|
+
const xAxis = this.target.htmlAttributes.style.left !== undefined ? 'left' : 'right';
|
|
284
|
+
const yAxis = this.target.htmlAttributes.style.top !== undefined ? 'top' : 'bottom';
|
|
285
|
+
|
|
286
|
+
const xUnit = this.getUnitFromStyle(xAxis);
|
|
287
|
+
const yUnit = this.getUnitFromStyle(yAxis);
|
|
288
|
+
|
|
289
|
+
if (xAxis === 'left') {
|
|
290
|
+
const leftPos = rect.left - this.offset.x;
|
|
291
|
+
if (xUnit === '%') {
|
|
292
|
+
this.target.htmlAttributes.style.left = `${(leftPos / window.innerWidth) * 100}%`;
|
|
293
|
+
} else {
|
|
294
|
+
this.target.htmlAttributes.style.left = `${leftPos}px`;
|
|
295
|
+
}
|
|
296
|
+
this.target.htmlAttributes.style.right = '';
|
|
231
297
|
} else {
|
|
232
|
-
const rightPos = window.innerWidth - rect.right + this.offset.x
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
298
|
+
const rightPos = window.innerWidth - rect.right + this.offset.x;
|
|
299
|
+
if (xUnit === '%') {
|
|
300
|
+
this.target.htmlAttributes.style.right = `${(rightPos / window.innerWidth) * 100}%`;
|
|
301
|
+
} else {
|
|
302
|
+
this.target.htmlAttributes.style.right = `${rightPos}px`;
|
|
303
|
+
}
|
|
304
|
+
this.target.htmlAttributes.style.left = '';
|
|
236
305
|
}
|
|
237
306
|
|
|
238
|
-
if (
|
|
239
|
-
const topPos = rect.top - this.offset.y
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
307
|
+
if (yAxis === 'top') {
|
|
308
|
+
const topPos = rect.top - this.offset.y;
|
|
309
|
+
if (yUnit === '%') {
|
|
310
|
+
this.target.htmlAttributes.style.top = `${(topPos / window.innerHeight) * 100}%`;
|
|
311
|
+
} else {
|
|
312
|
+
this.target.htmlAttributes.style.top = `${topPos}px`;
|
|
313
|
+
}
|
|
314
|
+
this.target.htmlAttributes.style.bottom = '';
|
|
243
315
|
} else {
|
|
244
|
-
const bottomPos = window.innerHeight - rect.bottom + this.offset.y
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
316
|
+
const bottomPos = window.innerHeight - rect.bottom + this.offset.y;
|
|
317
|
+
if (yUnit === '%') {
|
|
318
|
+
this.target.htmlAttributes.style.bottom = `${(bottomPos / window.innerHeight) * 100}%`;
|
|
319
|
+
} else {
|
|
320
|
+
this.target.htmlAttributes.style.bottom = `${bottomPos}px`;
|
|
321
|
+
}
|
|
322
|
+
this.target.htmlAttributes.style.top = '';
|
|
248
323
|
}
|
|
249
324
|
}
|
|
250
325
|
|
|
251
326
|
// 设置相对/绝对定位
|
|
252
327
|
setRelativePosition = (draggableRect: DOMRect, parentRect: DOMRect) => {
|
|
253
|
-
|
|
328
|
+
const xAxis = this.target.htmlAttributes.style.left !== undefined ? 'left' : 'right';
|
|
329
|
+
const yAxis = this.target.htmlAttributes.style.top !== undefined ? 'top' : 'bottom';
|
|
330
|
+
|
|
331
|
+
const xUnit = this.getUnitFromStyle(xAxis);
|
|
332
|
+
const yUnit = this.getUnitFromStyle(yAxis);
|
|
333
|
+
|
|
334
|
+
if (xAxis === 'left') {
|
|
254
335
|
const leftPos = draggableRect.left - parentRect.left - this.offset.x;
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
336
|
+
if (xUnit === '%') {
|
|
337
|
+
this.target.htmlAttributes.style.left = `${(leftPos / parentRect.width) * 100}%`;
|
|
338
|
+
} else {
|
|
339
|
+
this.target.htmlAttributes.style.left = `${leftPos}px`;
|
|
340
|
+
}
|
|
341
|
+
this.target.htmlAttributes.style.right = '';
|
|
258
342
|
} else {
|
|
259
343
|
const rightPos = parentRect.right - draggableRect.right + this.offset.x;
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
344
|
+
if (xUnit === '%') {
|
|
345
|
+
this.target.htmlAttributes.style.right = `${(rightPos / parentRect.width) * 100}%`;
|
|
346
|
+
} else {
|
|
347
|
+
this.target.htmlAttributes.style.right = `${rightPos}px`;
|
|
348
|
+
}
|
|
349
|
+
this.target.htmlAttributes.style.left = '';
|
|
263
350
|
}
|
|
264
351
|
|
|
265
|
-
if (
|
|
352
|
+
if (yAxis === 'top') {
|
|
266
353
|
const topPos = draggableRect.top - parentRect.top - this.offset.y;
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
354
|
+
if (yUnit === '%') {
|
|
355
|
+
this.target.htmlAttributes.style.top = `${(topPos / parentRect.height) * 100}%`;
|
|
356
|
+
} else {
|
|
357
|
+
this.target.htmlAttributes.style.top = `${topPos}px`;
|
|
358
|
+
}
|
|
359
|
+
this.target.htmlAttributes.style.bottom = '';
|
|
270
360
|
} else {
|
|
271
361
|
const bottomPos = parentRect.bottom - draggableRect.bottom + this.offset.y;
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
362
|
+
if (yUnit === '%') {
|
|
363
|
+
this.target.htmlAttributes.style.bottom = `${(bottomPos / parentRect.height) * 100}%`;
|
|
364
|
+
} else {
|
|
365
|
+
this.target.htmlAttributes.style.bottom = `${bottomPos}px`;
|
|
366
|
+
}
|
|
367
|
+
this.target.htmlAttributes.style.top = '';
|
|
275
368
|
}
|
|
276
369
|
}
|
|
277
370
|
|
|
@@ -279,7 +372,9 @@ class HTMLTransformControllerActor extends Actor {
|
|
|
279
372
|
handleDragStart = (e: MouseEvent) => {
|
|
280
373
|
if (this.descriptor.enabled === false) return
|
|
281
374
|
if (!this.state.target.element) return
|
|
282
|
-
|
|
375
|
+
|
|
376
|
+
const position = this.target.htmlAttributes.style.position || 'static';
|
|
377
|
+
if (position === 'static' || position === 'relative') return
|
|
283
378
|
|
|
284
379
|
if (e.target instanceof HTMLElement && e.target.classList.contains('resize-handle') === false) {
|
|
285
380
|
|
|
@@ -295,22 +390,37 @@ class HTMLTransformControllerActor extends Actor {
|
|
|
295
390
|
|
|
296
391
|
this.change('mousedown')
|
|
297
392
|
}
|
|
298
|
-
|
|
299
393
|
}
|
|
300
394
|
|
|
301
395
|
// 调整大小开始
|
|
302
396
|
handleResizeStart = (e: MouseEvent) => {
|
|
303
397
|
if (this.descriptor.enabled === false) return
|
|
304
398
|
if (!this.state.target.element) return;
|
|
305
|
-
|
|
399
|
+
|
|
400
|
+
const position = this.target.htmlAttributes.style.position || 'static';
|
|
401
|
+
if (position === 'static' || position === 'relative') return
|
|
402
|
+
|
|
306
403
|
if (e.target instanceof HTMLElement) {
|
|
307
404
|
|
|
308
405
|
this.state.isResizing = true;
|
|
309
406
|
this.state.resizeData.direction = e.target.classList[1];
|
|
310
407
|
|
|
311
408
|
const rect = this.element.getBoundingClientRect();
|
|
312
|
-
|
|
313
|
-
|
|
409
|
+
|
|
410
|
+
// 获取计算后的 padding 和 border 值
|
|
411
|
+
const computedStyle = getComputedStyle(this.state.target.element);
|
|
412
|
+
const paddingLeft = parseFloat(computedStyle.paddingLeft);
|
|
413
|
+
const paddingRight = parseFloat(computedStyle.paddingRight);
|
|
414
|
+
const paddingTop = parseFloat(computedStyle.paddingTop);
|
|
415
|
+
const paddingBottom = parseFloat(computedStyle.paddingBottom);
|
|
416
|
+
const borderLeft = parseFloat(computedStyle.borderLeftWidth);
|
|
417
|
+
const borderRight = parseFloat(computedStyle.borderRightWidth);
|
|
418
|
+
const borderTop = parseFloat(computedStyle.borderTopWidth);
|
|
419
|
+
const borderBottom = parseFloat(computedStyle.borderBottomWidth);
|
|
420
|
+
|
|
421
|
+
this.state.resizeData.calcWidth = paddingLeft + paddingRight + borderLeft + borderRight;
|
|
422
|
+
this.state.resizeData.calcHeight = paddingTop + paddingBottom + borderTop + borderBottom;
|
|
423
|
+
|
|
314
424
|
this.state.resizeData.startWidth = rect.width;
|
|
315
425
|
this.state.resizeData.startHeight = rect.height;
|
|
316
426
|
this.state.resizeData.startX = rect.left;
|
|
@@ -404,6 +514,3 @@ class HTMLTransformControllerActor extends Actor {
|
|
|
404
514
|
}
|
|
405
515
|
}
|
|
406
516
|
|
|
407
|
-
export {
|
|
408
|
-
HTMLTransformControllerActor
|
|
409
|
-
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createInputDOM } from "../utils"
|
|
2
|
+
import { Input } from "../descriptor"
|
|
3
|
+
import { Actor } from "./Actor"
|
|
4
|
+
import { HTMLActor } from "./HTMLActor"
|
|
5
|
+
|
|
6
|
+
export class InputActor extends HTMLActor {
|
|
7
|
+
private _wrapper: HTMLElement | null = null
|
|
8
|
+
|
|
9
|
+
constructor(uuid: string) {
|
|
10
|
+
super(uuid)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
protected createWrapper() {
|
|
14
|
+
const DOM = createInputDOM(this.uuid)
|
|
15
|
+
return DOM
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getDOM() {
|
|
19
|
+
if (this._wrapper === null) {
|
|
20
|
+
this._wrapper = this.createWrapper()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return this._wrapper
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
add(actor: Actor) {
|
|
27
|
+
if (actor instanceof HTMLActor) {
|
|
28
|
+
const child = actor.getDOM()
|
|
29
|
+
if (child === null) return
|
|
30
|
+
const DOM = this.getDOM()
|
|
31
|
+
if (DOM.contains(child)) return
|
|
32
|
+
DOM.appendChild(child)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
remove(actor: Actor) {
|
|
37
|
+
if (actor instanceof HTMLActor) {
|
|
38
|
+
const child = actor.getDOM()
|
|
39
|
+
if (child === null) return
|
|
40
|
+
const DOM = this.getDOM()
|
|
41
|
+
if (DOM.contains(child)) DOM.removeChild(child)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
update(descriptor: Input) {
|
|
46
|
+
const DOM = this.getDOM()
|
|
47
|
+
this.setHtmlAttributes(DOM, descriptor)
|
|
48
|
+
this.setHTMLInteraction(DOM, descriptor)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { createTextDOM } from "../utils"
|
|
2
|
+
import { Text } from "../descriptor"
|
|
3
|
+
import { Actor } from "./Actor"
|
|
4
|
+
import { HTMLActor } from "./HTMLActor"
|
|
5
|
+
|
|
6
|
+
export class TextActor extends HTMLActor {
|
|
7
|
+
private _wrapper: HTMLElement | null = null
|
|
8
|
+
|
|
9
|
+
constructor(uuid: string) {
|
|
10
|
+
super(uuid)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
protected createWrapper() {
|
|
14
|
+
const DOM = createTextDOM(this.uuid)
|
|
15
|
+
return DOM
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getDOM() {
|
|
19
|
+
if (this._wrapper === null) {
|
|
20
|
+
this._wrapper = this.createWrapper()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return this._wrapper
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
add(actor: Actor) {
|
|
27
|
+
if (actor instanceof HTMLActor) {
|
|
28
|
+
const child = actor.getDOM()
|
|
29
|
+
if (child === null) return
|
|
30
|
+
const DOM = this.getDOM()
|
|
31
|
+
if (DOM.contains(child)) return
|
|
32
|
+
DOM.appendChild(child)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
remove(actor: Actor) {
|
|
37
|
+
if (actor instanceof HTMLActor) {
|
|
38
|
+
const child = actor.getDOM()
|
|
39
|
+
if (child === null) return
|
|
40
|
+
const DOM = this.getDOM()
|
|
41
|
+
if (DOM.contains(child)) DOM.removeChild(child)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
update(descriptor: Text) {
|
|
46
|
+
const DOM = this.getDOM()
|
|
47
|
+
this.setHtmlAttributes(DOM, descriptor)
|
|
48
|
+
this.setHTMLInteraction(DOM, descriptor)
|
|
49
|
+
DOM.innerText = descriptor.content
|
|
50
|
+
}
|
|
51
|
+
}
|
package/src/actor/index.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export * from './Actor'
|
|
2
|
-
export * from './StyleActor'
|
|
3
|
-
export * from './AnimationUnitActor'
|
|
4
2
|
export * from './FragmentActor'
|
|
5
|
-
export * from './
|
|
3
|
+
export * from './AnimationUnitActor'
|
|
4
|
+
export * from './HTMLActor'
|
|
6
5
|
export * from './DivActor'
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
6
|
+
export * from './InputActor'
|
|
7
|
+
export * from './TextActor'
|
|
8
|
+
export * from './HTMLServiceActor'
|
|
9
|
+
export * from './HTMLTransformControllerActor'
|
package/src/asset/Asset.ts
CHANGED
|
@@ -1,25 +1,16 @@
|
|
|
1
1
|
import { language } from "../locale"
|
|
2
|
-
import { Category } from "../Category"
|
|
2
|
+
import { Category, Suffix } from "../Category"
|
|
3
3
|
import { AsyncTask } from "../AsyncTask"
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { compile } from "../utils/compile"
|
|
4
|
+
import { Store, Descriptor, Interaction, Scene } from "../descriptor"
|
|
5
|
+
import { DescriptorProvider, RawAsset, StaticFactory } from "../schema"
|
|
7
6
|
import { AssetGraph } from "./AssetGraph"
|
|
8
7
|
import { Engine } from "../Engine"
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
type RawAsset = HTMLImageElement | ImageBitmap | HTMLAudioElement | AudioBuffer | HTMLVideoElement | string | JsonAsset
|
|
12
|
-
type StaticFactory = (url: string, forced?: boolean) => Promise<any>
|
|
13
|
-
type DescriptorProvider = () => Promise<Descriptor>
|
|
14
|
-
type ScriptableProvider = () => Promise<{ default: typeof Scriptable<ScriptableArgs<any, any, any>> }>
|
|
15
|
-
type AssetProperty = { url: string }
|
|
16
|
-
type AssetPropertyCollection<T extends AssetProperty = AssetProperty> = T[]
|
|
17
|
-
|
|
18
|
-
const privateState = {
|
|
9
|
+
export const privateState = {
|
|
19
10
|
requestpPrefix: ['http://', 'https://'],
|
|
20
11
|
assetCache: new Map<string, RawAsset | Descriptor>(),
|
|
21
12
|
idToUrlCache: new Map<string, string>(),
|
|
22
|
-
providerCollection: new Map<string, DescriptorProvider
|
|
13
|
+
providerCollection: new Map<string, DescriptorProvider>(),
|
|
23
14
|
assetFactoryCollection: new Map<string, StaticFactory>(),
|
|
24
15
|
taskCollection: new Map<string, AsyncTask>(),
|
|
25
16
|
activeAssets: [] as string[],
|
|
@@ -28,12 +19,12 @@ const privateState = {
|
|
|
28
19
|
const name = urlClips[urlClips.length - 1]
|
|
29
20
|
if (name === undefined) return null
|
|
30
21
|
|
|
31
|
-
return
|
|
22
|
+
return Suffix.parseName(name.split('?')[0])
|
|
32
23
|
},
|
|
33
24
|
baseUrl: null as unknown as string,
|
|
34
25
|
}
|
|
35
26
|
|
|
36
|
-
class Asset {
|
|
27
|
+
export class Asset {
|
|
37
28
|
static virtual = 'virtual'
|
|
38
29
|
static get baseUrl() {
|
|
39
30
|
if (privateState.baseUrl === null) {
|
|
@@ -50,6 +41,10 @@ class Asset {
|
|
|
50
41
|
}
|
|
51
42
|
static graph = new AssetGraph()
|
|
52
43
|
|
|
44
|
+
static isStaticURL(url: string) {
|
|
45
|
+
return url.startsWith('/static:/')
|
|
46
|
+
}
|
|
47
|
+
|
|
53
48
|
static fetch(url: string, params?: any) {
|
|
54
49
|
return new Promise<Response>(async (resolve, reject) => {
|
|
55
50
|
const res = await fetch(url, params)
|
|
@@ -65,7 +60,7 @@ class Asset {
|
|
|
65
60
|
return `/${this.virtual}:/${fileName}`
|
|
66
61
|
}
|
|
67
62
|
|
|
68
|
-
static setProvider(url: string, provider: DescriptorProvider
|
|
63
|
+
static setProvider(url: string, provider: DescriptorProvider) {
|
|
69
64
|
privateState.providerCollection.set(url, provider)
|
|
70
65
|
}
|
|
71
66
|
|
|
@@ -113,7 +108,7 @@ class Asset {
|
|
|
113
108
|
if (status === null) continue
|
|
114
109
|
|
|
115
110
|
let factory = privateState.assetFactoryCollection.get(status.category)
|
|
116
|
-
if (factory === undefined) throw new Error(language.get('asset.load.
|
|
111
|
+
if (factory === undefined) throw new Error(language.get('asset.load.failed', { category: status.category }))
|
|
117
112
|
|
|
118
113
|
const task = new AsyncTask(async () => {
|
|
119
114
|
const asset = await factory(assetUrl, forced)
|
|
@@ -155,8 +150,8 @@ class Asset {
|
|
|
155
150
|
|
|
156
151
|
static get<U extends keyof SnowAssets>(url: U): SnowAssets[U]
|
|
157
152
|
static get<T extends SnowAssets[keyof SnowAssets] = SnowAssets[keyof SnowAssets]>(url: keyof SnowAssets): T
|
|
158
|
-
static get<T extends RawAsset |
|
|
159
|
-
static get<T extends RawAsset |
|
|
153
|
+
static get<T extends RawAsset | Interaction | Descriptor | null = Descriptor | null>(url: string): T
|
|
154
|
+
static get<T extends RawAsset | Interaction | Descriptor | null = Descriptor | null>(url: string) {
|
|
160
155
|
return (privateState.assetCache.get(url) ?? null) as T
|
|
161
156
|
}
|
|
162
157
|
|
|
@@ -185,21 +180,6 @@ class Asset {
|
|
|
185
180
|
privateState.activeAssets.length = 0
|
|
186
181
|
}
|
|
187
182
|
|
|
188
|
-
static async compileDataset(url: string, engine: Engine) {
|
|
189
|
-
const descriptor = this.get<ServiceSchedulerDescriptor>(url)
|
|
190
|
-
if (descriptor === null) return
|
|
191
|
-
const graphics = engine.ensureGraphics(url, descriptor)
|
|
192
|
-
const dependencide = Asset.graph.getDependencide(url)
|
|
193
|
-
|
|
194
|
-
const queue: Promise<void>[] = []
|
|
195
|
-
for (const dataset of dependencide.dataset) {
|
|
196
|
-
const trigger = Asset.get<DatasetDescriptor>(dataset)
|
|
197
|
-
compile(trigger, graphics)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
await Promise.all(queue)
|
|
201
|
-
}
|
|
202
|
-
|
|
203
183
|
static async loadAll(url: string, forced = false, record: string[] = []) {
|
|
204
184
|
await Asset.load(url, forced)
|
|
205
185
|
Asset.graph.create(url)
|
|
@@ -218,60 +198,35 @@ class Asset {
|
|
|
218
198
|
}
|
|
219
199
|
}
|
|
220
200
|
|
|
221
|
-
export
|
|
222
|
-
|
|
223
|
-
const getAssetByProvider = async (url: string) => {
|
|
201
|
+
export const getAssetByProvider = async (url: string) => {
|
|
224
202
|
const provider = privateState.providerCollection.get(url)
|
|
225
203
|
if (provider === undefined) return null
|
|
226
204
|
return await provider() as unknown as any
|
|
227
205
|
}
|
|
228
206
|
|
|
229
|
-
const factoryDescriptor = async (url: string) => {
|
|
230
|
-
const
|
|
231
|
-
if (
|
|
207
|
+
export const factoryDescriptor = async (url: string) => {
|
|
208
|
+
const provider = await getAssetByProvider(url)
|
|
209
|
+
if (provider !== null) return provider
|
|
232
210
|
const res = await Asset.fetch(Asset.joinUrl(url))
|
|
233
211
|
const text = await res.text()
|
|
234
212
|
const asset = Descriptor.create(Descriptor.deserialization(text))
|
|
235
213
|
return asset
|
|
236
214
|
}
|
|
237
|
-
Asset.register(Category.
|
|
215
|
+
Asset.register(Category.store, factoryDescriptor)
|
|
216
|
+
Asset.register(Category.interaction, factoryDescriptor)
|
|
238
217
|
Asset.register(Category.material, factoryDescriptor)
|
|
239
218
|
Asset.register(Category.geometry, factoryDescriptor)
|
|
240
219
|
Asset.register(Category.texture, factoryDescriptor)
|
|
241
|
-
Asset.register(Category.prefab, factoryDescriptor)
|
|
242
|
-
Asset.register(Category.interaction, factoryDescriptor)
|
|
243
220
|
Asset.register(Category.scene, factoryDescriptor)
|
|
244
|
-
Asset.register(Category.dataset, factoryDescriptor)
|
|
245
221
|
|
|
246
|
-
const factoryJson = async (url: string) => {
|
|
222
|
+
export const factoryJson = async (url: string) => {
|
|
247
223
|
const res = await Asset.fetch(Asset.joinUrl(url))
|
|
248
224
|
const text = await res.text()
|
|
249
225
|
return Descriptor.deserialization(text)
|
|
250
226
|
}
|
|
251
227
|
Asset.register(Category.json, factoryJson)
|
|
252
228
|
|
|
253
|
-
const
|
|
254
|
-
return new Promise(async (resolve, reject) => {
|
|
255
|
-
try {
|
|
256
|
-
const module = await getAssetByProvider(url)
|
|
257
|
-
if (module === null) return reject(language.get('asset.provider.notFound', { url }))
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Class constructor { ClassName } cannot be invoked without 'new'
|
|
261
|
-
*
|
|
262
|
-
* 将代码的编译目标(webpack、ts、vite等配置文件)调整为es6
|
|
263
|
-
*/
|
|
264
|
-
const scriptable = new module.default(url)
|
|
265
|
-
await scriptable.ready()
|
|
266
|
-
resolve(scriptable)
|
|
267
|
-
} catch (error) {
|
|
268
|
-
reject(error)
|
|
269
|
-
}
|
|
270
|
-
})
|
|
271
|
-
}
|
|
272
|
-
Asset.register(Category.ts, factoryScript)
|
|
273
|
-
|
|
274
|
-
const factoryOther = async (url: string) => {
|
|
229
|
+
export const factoryOther = async (url: string) => {
|
|
275
230
|
const res = await Asset.fetch(Asset.joinUrl(url))
|
|
276
231
|
return await res.arrayBuffer()
|
|
277
232
|
}
|