@vyr/remote 0.0.1
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 +18 -0
- package/src/Bridge.ts +133 -0
- package/src/ChangeScriptable.ts +22 -0
- package/src/Collection.ts +36 -0
- package/src/RemoteExecutor.ts +514 -0
- package/src/RemoteInvoker.ts +72 -0
- package/src/RemoteProcess.ts +87 -0
- package/src/index.ts +7 -0
- package/src/job/IJob.ts +6 -0
- package/src/job/Job.ts +16 -0
- package/src/job/asset/add.ts +23 -0
- package/src/job/asset/dragdrap.ts +24 -0
- package/src/job/asset/index.ts +6 -0
- package/src/job/asset/load.ts +20 -0
- package/src/job/asset/remove.ts +20 -0
- package/src/job/asset/unload.ts +18 -0
- package/src/job/asset/update.ts +22 -0
- package/src/job/bridge/connection.ts +18 -0
- package/src/job/bridge/disconnect.ts +29 -0
- package/src/job/bridge/index.ts +2 -0
- package/src/job/index.ts +1 -0
- package/src/job/invoke/alert.ts +20 -0
- package/src/job/invoke/animation.ts +45 -0
- package/src/job/invoke/event.ts +40 -0
- package/src/job/invoke/index.ts +8 -0
- package/src/job/invoke/orbit.ts +20 -0
- package/src/job/invoke/pick.ts +15 -0
- package/src/job/invoke/properties.ts +43 -0
- package/src/job/invoke/screenshot.ts +35 -0
- package/src/job/invoke/transform.ts +36 -0
- package/src/job/scene/add.ts +22 -0
- package/src/job/scene/dragdrap.ts +23 -0
- package/src/job/scene/index.ts +6 -0
- package/src/job/scene/load.ts +19 -0
- package/src/job/scene/remove.ts +19 -0
- package/src/job/scene/unload.ts +17 -0
- package/src/job/scene/update.ts +20 -0
- package/src/locale/Language.ts +10 -0
- package/src/locale/LanguageProvider.ts +15 -0
- package/src/locale/index.ts +2 -0
- package/src/utils/index.ts +85 -0
- package/src/utils/screenshot.ts +20 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { AnimationUnitDescriptor, Asset, Descriptor } from "@vyr/engine"
|
|
2
|
+
import { RemoteProcess } from "../RemoteProcess"
|
|
3
|
+
import { Job } from "../job"
|
|
4
|
+
|
|
5
|
+
const createControllerStyle = () => {
|
|
6
|
+
const style = document.createElement('style')
|
|
7
|
+
const css = [
|
|
8
|
+
'.vyr-html-wrapper{pointer-events: all !important;}',
|
|
9
|
+
'.vyr-html-wrapper > * {pointer-events: none !important}',
|
|
10
|
+
]
|
|
11
|
+
style.innerText = css.join('\n')
|
|
12
|
+
document.head.append(style)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const pickupObject = (process: RemoteProcess) => {
|
|
16
|
+
const executor = (event: MouseEvent) => {
|
|
17
|
+
const graphics = process.engine.getGraphics(process.scheduler)
|
|
18
|
+
const result = graphics.pickup(event)
|
|
19
|
+
if (result.length === 0) return
|
|
20
|
+
|
|
21
|
+
const select = result[0]
|
|
22
|
+
process.bridge.send(new Job.invoke.pick.Response({ descriptor: select.generatedBy || select.uuid }))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let count = 0
|
|
26
|
+
const beforePickup = (event: MouseEvent) => {
|
|
27
|
+
if (count === 0) {
|
|
28
|
+
setTimeout(() => pickup(event), 250)
|
|
29
|
+
}
|
|
30
|
+
count++
|
|
31
|
+
}
|
|
32
|
+
const pickup = (event: MouseEvent) => {
|
|
33
|
+
if (count > 1) {
|
|
34
|
+
executor(event)
|
|
35
|
+
}
|
|
36
|
+
count = 0
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
window.addEventListener('click', beforePickup)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const cleanPickupObject = (process: RemoteProcess) => {
|
|
43
|
+
let now = 0
|
|
44
|
+
const mousedown = (event: MouseEvent) => {
|
|
45
|
+
if (event.button !== 2) return
|
|
46
|
+
now = performance.now()
|
|
47
|
+
window.addEventListener('mouseup', mouseup, { once: true })
|
|
48
|
+
}
|
|
49
|
+
const mouseup = (event: MouseEvent) => {
|
|
50
|
+
if (event.button !== 2) return
|
|
51
|
+
if (performance.now() - now > 150) return
|
|
52
|
+
process.bridge.send(new Job.invoke.pick.Response({ descriptor: '' }))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
window.addEventListener('mousedown', mousedown)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const getAnimationUnit = (descriptor: Descriptor) => {
|
|
59
|
+
let max = 0
|
|
60
|
+
descriptor.traverse((sub) => {
|
|
61
|
+
if (sub instanceof AnimationUnitDescriptor) {
|
|
62
|
+
const uptime = sub.startTime + sub.duration
|
|
63
|
+
if (uptime > max) max = uptime
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
return max
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const getAnimationUnitByAsset = (url: string) => {
|
|
70
|
+
const descriptor = Asset.get<Descriptor>(url)
|
|
71
|
+
if (descriptor instanceof Descriptor) {
|
|
72
|
+
return getAnimationUnit(descriptor)
|
|
73
|
+
} else {
|
|
74
|
+
return 0
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export {
|
|
79
|
+
createControllerStyle,
|
|
80
|
+
pickupObject,
|
|
81
|
+
cleanPickupObject,
|
|
82
|
+
getAnimationUnit,
|
|
83
|
+
getAnimationUnitByAsset,
|
|
84
|
+
}
|
|
85
|
+
export * from './screenshot'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
let HTMLToImage: any = null
|
|
2
|
+
const screenshot = async (html: HTMLElement, backgroundColor = '#ffffff') => {
|
|
3
|
+
if (HTMLToImage === null) {
|
|
4
|
+
//@ts-ignore
|
|
5
|
+
HTMLToImage = await import('dom-to-image')
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const url = await HTMLToImage.default.toPng(html, {
|
|
9
|
+
bgcolor: backgroundColor,
|
|
10
|
+
width: html.clientWidth || html.scrollWidth,
|
|
11
|
+
height: html.clientHeight || html.scrollHeight,
|
|
12
|
+
quality: 1.0,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
return url
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
screenshot
|
|
20
|
+
}
|