@realsee/vreo 1.0.0-alpha.9 → 1.1.0-dev.0

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 (132) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/README.md +46 -36
  3. package/lib/PlayController/index.js +1 -1
  4. package/lib/Player/Controller.d.ts +3 -2
  5. package/lib/Player/Controller.js +31 -14
  6. package/lib/Player/index.js +27 -16
  7. package/lib/Player/modules/VideoAgent/VideoAgentMesh.d.ts +2 -2
  8. package/lib/Player/modules/VideoAgent/VideoAgentMesh.js +7 -12
  9. package/lib/Player/modules/VideoAgent/index.js +1 -1
  10. package/lib/Player/modules/Wave/index.js +160 -25
  11. package/lib/Player/modules/keyframes/BgMusic/index.js +52 -40
  12. package/lib/Player/modules/keyframes/PanoTag/index.js +1 -0
  13. package/lib/fivePlugins/CameraMovementPlugin/index.js +3 -2
  14. package/lib/shared-utils/Audio.d.ts +14 -0
  15. package/lib/shared-utils/Audio.js +158 -0
  16. package/lib/shared-utils/{AduioLike.d.ts → AudioLike.d.ts} +0 -0
  17. package/lib/shared-utils/{AduioLike.js → AudioLike.js} +4 -6
  18. package/lib/shared-utils/animationFrame/tween.d.ts +3 -58
  19. package/lib/shared-utils/animationFrame/tween.js +3 -9
  20. package/lib/typings/VreoUnit.d.ts +8 -5
  21. package/package.json +8 -6
  22. package/stylesheets/default.css +7 -2
  23. package/docs/.nojekyll +0 -1
  24. package/docs/assets/custom.css +0 -78
  25. package/docs/assets/highlight.css +0 -127
  26. package/docs/assets/icons.css +0 -1043
  27. package/docs/assets/icons.png +0 -0
  28. package/docs/assets/icons@2x.png +0 -0
  29. package/docs/assets/main.js +0 -52
  30. package/docs/assets/search.js +0 -1
  31. package/docs/assets/style.css +0 -1414
  32. package/docs/assets/widgets.png +0 -0
  33. package/docs/assets/widgets@2x.png +0 -0
  34. package/docs/classes/Player.AudioLike.html +0 -52
  35. package/docs/classes/Player.Controller.html +0 -54
  36. package/docs/classes/Player.Player-1.html +0 -50
  37. package/docs/classes/Player.VideoAgentMesh.html +0 -142
  38. package/docs/classes/Player.VideoAgentScene.html +0 -1
  39. package/docs/demo/assets/AppReact.6ca5d1d2.js +0 -1
  40. package/docs/demo/assets/default.5a762ce2.js +0 -3988
  41. package/docs/demo/assets/default.bc4c715d.css +0 -1
  42. package/docs/demo/assets/dynamic.efc5200d.js +0 -1
  43. package/docs/demo/assets/examples.80a27156.js +0 -25
  44. package/docs/demo/assets/examples.dac4a6fe.css +0 -1
  45. package/docs/demo/assets/index.9331038f.css +0 -1
  46. package/docs/demo/assets/index.ca7c5881.js +0 -1
  47. package/docs/demo/assets/main.c164d1d2.js +0 -1
  48. package/docs/demo/assets/react.2ee8565f.css +0 -1
  49. package/docs/demo/assets/react.a4774aef.js +0 -25
  50. package/docs/demo/assets/znRoyv06SZQeqA7m.0057e8ae.js +0 -1
  51. package/docs/demo/examples.html +0 -17
  52. package/docs/demo/index-react-dynamic.html +0 -20
  53. package/docs/demo/index-react.html +0 -20
  54. package/docs/demo/index.html +0 -19
  55. package/docs/enums/Player.InfoPanelStyleEnum.html +0 -1
  56. package/docs/enums/Player.InfoPanelTypeEnum.html +0 -3
  57. package/docs/enums/Player.PanoEffectEnum.html +0 -5
  58. package/docs/enums/Player.PanoTagEnum.html +0 -3
  59. package/docs/enums/Player.PanoTagStyleEnum.html +0 -7
  60. package/docs/enums/Player.VreoKeyframeEnum.html +0 -25
  61. package/docs/enums/fivePlugins.CameraMovementEffect.html +0 -1
  62. package/docs/enums/fivePlugins.Rotation.html +0 -1
  63. package/docs/index.html +0 -245
  64. package/docs/interfaces/Player.CustomVreoKeyframeProps.html +0 -1
  65. package/docs/interfaces/Player.PlayerConfigs.html +0 -7
  66. package/docs/interfaces/Player.Vertex.html +0 -3
  67. package/docs/interfaces/Player.VideoAgentMeshOptions.html +0 -8
  68. package/docs/interfaces/Player.VreoKeyframe.html +0 -3
  69. package/docs/interfaces/Player.VreoUnit.html +0 -3
  70. package/docs/interfaces/Player.VreoVideo.html +0 -3
  71. package/docs/interfaces/fivePlugins.CSS3DRenderPluginExportType.html +0 -4
  72. package/docs/interfaces/fivePlugins.CameraMovementOptsCallback.html +0 -1
  73. package/docs/interfaces/fivePlugins.CameraMovementPluginExportType.html +0 -7
  74. package/docs/interfaces/fivePlugins.CameraMovementPluginParameterType.html +0 -1
  75. package/docs/interfaces/fivePlugins.ModelTVVideoPluginData.html +0 -1
  76. package/docs/interfaces/fivePlugins.ModelTVVideoPluginExportType.html +0 -1
  77. package/docs/interfaces/fivePlugins.ModelTVVideoPluginParameterType.html +0 -1
  78. package/docs/interfaces/fivePlugins.Vector3Position.html +0 -3
  79. package/docs/interfaces/react.VreoActionCallbacks.html +0 -23
  80. package/docs/interfaces/react.VreoProviderProps.html +0 -1
  81. package/docs/modules/Player.html +0 -37
  82. package/docs/modules/custom.html +0 -3
  83. package/docs/modules/fivePlugins.html +0 -6
  84. package/docs/modules/react.html +0 -1
  85. package/docs/modules.html +0 -1
  86. package/resources/PlayController/createHTMLAudioElement.ts +0 -53
  87. package/resources/PlayController/index.ts +0 -154
  88. package/resources/Player/App.tsx +0 -66
  89. package/resources/Player/Controller.ts +0 -294
  90. package/resources/Player/custom/SpatialScenePanel/index.tsx +0 -264
  91. package/resources/Player/hooks.ts +0 -26
  92. package/resources/Player/index.tsx +0 -227
  93. package/resources/Player/modules/Drawer/index.tsx +0 -40
  94. package/resources/Player/modules/PopUp/index.tsx +0 -26
  95. package/resources/Player/modules/ResizeObserver/index.tsx +0 -23
  96. package/resources/Player/modules/VideoAgent/VideoAgentMesh.ts +0 -302
  97. package/resources/Player/modules/VideoAgent/VideoAgentScene.ts +0 -56
  98. package/resources/Player/modules/VideoAgent/index.tsx +0 -53
  99. package/resources/Player/modules/Wave/index.tsx +0 -18
  100. package/resources/Player/modules/keyframes/BgMusic/index.tsx +0 -66
  101. package/resources/Player/modules/keyframes/CameraMovement/index.tsx +0 -37
  102. package/resources/Player/modules/keyframes/InfoPanel/index.tsx +0 -165
  103. package/resources/Player/modules/keyframes/ModelVideo/index.tsx +0 -77
  104. package/resources/Player/modules/keyframes/PanoEffect/index.tsx +0 -99
  105. package/resources/Player/modules/keyframes/PanoEffect/lineAnime.ts +0 -31
  106. package/resources/Player/modules/keyframes/PanoTag/index.tsx +0 -82
  107. package/resources/Player/modules/keyframes/PanoTextLabel/index.tsx +0 -117
  108. package/resources/Player/modules/keyframes/Prompter/index.tsx +0 -56
  109. package/resources/Player/modules/keyframes/UpdateVRPanorama/index.tsx +0 -99
  110. package/resources/Player/modules/keyframes/VideoEffect/index.tsx +0 -115
  111. package/resources/Player/typings.ts +0 -49
  112. package/resources/fivePlugins/CSS3DRenderPlugin/centerPoint.ts +0 -5
  113. package/resources/fivePlugins/CSS3DRenderPlugin/createResizeObserver.ts +0 -17
  114. package/resources/fivePlugins/CSS3DRenderPlugin/evenNumber.ts +0 -4
  115. package/resources/fivePlugins/CSS3DRenderPlugin/index.ts +0 -254
  116. package/resources/fivePlugins/CSS3DRenderPlugin/transformPositionToVector3.ts +0 -5
  117. package/resources/fivePlugins/CameraMovementPlugin/index.ts +0 -226
  118. package/resources/fivePlugins/CameraMovementPlugin/typings.ts +0 -59
  119. package/resources/fivePlugins/ModelTVVideoPlugin/index.ts +0 -278
  120. package/resources/index.ts +0 -1
  121. package/resources/react/index.tsx +0 -121
  122. package/resources/shared-utils/AduioLike.ts +0 -109
  123. package/resources/shared-utils/Preloader.ts +0 -35
  124. package/resources/shared-utils/addResizeListener.ts +0 -46
  125. package/resources/shared-utils/animationFrame/BetterTween.ts +0 -33
  126. package/resources/shared-utils/animationFrame/index.ts +0 -48
  127. package/resources/shared-utils/animationFrame/tween.ts +0 -51
  128. package/resources/shared-utils/createTransMatrix.ts +0 -12
  129. package/resources/shared-utils/getFileExpandedName.ts +0 -6
  130. package/resources/shared-utils/getMediaInfo.ts +0 -52
  131. package/resources/shared-utils/setElementDataset.ts +0 -18
  132. package/resources/typings/VreoUnit.ts +0 -314
@@ -1,109 +0,0 @@
1
- import { Subscribe } from '@realsee/five'
2
- import { requestAnimationFrameInterval } from './animationFrame'
3
-
4
- /**
5
- * 模拟 `<Audio>` 事件。
6
- */
7
- export type AudioLikeEvent = {
8
- // 播放
9
- play: () => void
10
- // 语音状态 播放 -> 暂停
11
- pause: () => void
12
- // 语音时间刷新
13
- timeupdate: () => void
14
- // 播放
15
- ended: () => void
16
- }
17
-
18
-
19
- /**
20
- * 模拟 `<Audio>` 功能:没有音频,但执行逻辑跟 `<Audio>` 相似。
21
- */
22
- export class AudioLike extends Subscribe<AudioLikeEvent> {
23
- private $timestamp: number | null = null
24
- private $currentTime = 0
25
- private $duration = 0
26
- private stopInterval?: () => void
27
- muted = false
28
- src = ''
29
-
30
- setAttribute(name: string, value: string) {
31
- // nothing todo
32
- }
33
-
34
- constructor({ duration }: { duration?: number } = {}) {
35
- super()
36
- if (duration) {
37
- this.$duration = duration
38
- }
39
- }
40
-
41
- play() {
42
- if (this.$currentTime === this.$duration) {
43
- this.$currentTime = 0
44
- }
45
- if (this.$timestamp === null) {
46
- this.$timestamp = performance.now() - this.$currentTime
47
- }
48
- this.stopInterval = requestAnimationFrameInterval(() => this.requestAnimationFrameLoop())
49
- this.emit('play')
50
- }
51
-
52
- pause() {
53
- if (this.stopInterval) {
54
- this.stopInterval()
55
- this.emit('pause')
56
- this.stopInterval = undefined
57
- }
58
- this.$timestamp = null
59
- }
60
-
61
- requestAnimationFrameLoop() {
62
- if (this.$timestamp === null) return
63
- const now = performance.now()
64
- this.$currentTime = now - this.$timestamp
65
- this.emit('timeupdate')
66
- if (this.$currentTime >= this.$duration - 10) {
67
- this.$currentTime = this.$duration
68
- this.pause()
69
- this.emit('ended')
70
- }
71
- }
72
-
73
- get currentTime() {
74
- return this.$currentTime / 1000
75
- }
76
-
77
- set currentTime(time: number) {
78
- this.$currentTime = time
79
- }
80
-
81
- get duration() {
82
- return this.$duration
83
- }
84
-
85
- set duration(duration: number) {
86
- this.pause()
87
- this.$duration = duration
88
- this.$timestamp = null
89
- this.$currentTime = 0
90
- }
91
-
92
- get ended() {
93
- return this.$currentTime === this.$duration
94
- }
95
-
96
- get paused() {
97
- return !this.stopInterval
98
- }
99
-
100
- addEventListener(evtName: keyof AudioLikeEvent, callback: () => void, useCapture = false) {
101
- this.on(evtName, callback)
102
- }
103
-
104
- removeEventListener(evtName: keyof AudioLikeEvent, callback: () => void, useCapture = false) {
105
- this.off(evtName, callback)
106
- }
107
- }
108
-
109
- export default AudioLike
@@ -1,35 +0,0 @@
1
- /**
2
- * 预载器
3
- */
4
- export const Preloader = {
5
- blob: (url: string) => {
6
- const noop = () => null
7
- return new Promise<string>((resolve, reject) => {
8
- const xhr = new XMLHttpRequest()
9
- const clear = () => {
10
- xhr.ontimeout = noop
11
- xhr.onreadystatechange = noop
12
- xhr.onprogress = noop
13
- xhr.onabort = noop
14
- }
15
- xhr.ontimeout = () => {
16
- reject(new Error('timeout'))
17
- clear()
18
- }
19
- xhr.onreadystatechange = () => {
20
- if (xhr.readyState !== 4) return
21
- if (xhr.status === 0 && !xhr.response) return
22
- if (xhr.status === 200 || xhr.status === 0) {
23
- resolve(xhr.response)
24
- clear()
25
- } else {
26
- reject(new Error('status:' + xhr.status))
27
- clear()
28
- }
29
- }
30
- xhr.open('GET', url, true)
31
- xhr.responseType = 'blob'
32
- xhr.send(null)
33
- })
34
- },
35
- }
@@ -1,46 +0,0 @@
1
- type ResizeHandler = (width: number, height: number) => void
2
-
3
- const resizeObserverCache = new Map<Element, number>()
4
-
5
- export function addResizeListener(element: Element | undefined | null, resizeHandler: ResizeHandler, immediate = true) {
6
- if (!element) return () => {}
7
-
8
- if (immediate) resizeHandler(element.clientWidth, element.clientHeight)
9
-
10
- if (typeof ResizeObserver !== 'undefined' && ResizeObserver) {
11
- const resizeObserver = new ResizeObserver(() => resizeHandler(element.clientWidth, element.clientHeight))
12
-
13
- resizeObserver.observe(element)
14
- resizeObserverCache.set(element, resizeObserverCache.get(element) || 0 + 1)
15
-
16
- return () => {
17
- if (element) resizeObserver.unobserve(element)
18
- if (resizeObserverCache.get(element) === 1) {
19
- resizeObserverCache.delete(element)
20
- }
21
- }
22
- } else {
23
- const iframe = document.createElement('iframe')
24
- iframe.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;pointer-events:none;opacity:0;visibility:hidden;margin:0;border:0;padding:0;z-index:-1;'
25
- iframe.classList.add('resize-sensor-iframe')
26
- element.appendChild(iframe)
27
- if (!iframe.contentWindow) return () => {}
28
-
29
- iframe.contentWindow.addEventListener('resize', () => {
30
- resizeHandler(iframe.clientWidth, iframe.clientHeight)
31
- })
32
- resizeObserverCache.set(element, resizeObserverCache.get(element) || 0 + 1)
33
-
34
- return () => {
35
- element.removeChild(iframe)
36
- if (resizeObserverCache.get(element) === 1) {
37
- resizeObserverCache.delete(element)
38
- }
39
- }
40
- }
41
- }
42
-
43
- export function hasResizeListener(element?: Element | null) {
44
- if (!element) return false
45
- return resizeObserverCache.get(element) || 0 > 0
46
- }
@@ -1,33 +0,0 @@
1
- import TWEEN from '@tweenjs/tween.js'
2
- import { requestAnimationFrameInterval } from '.'
3
-
4
- export class BetterTween<G> extends TWEEN.Tween<G> {
5
- private disposeMethods: (() => void)[] = []
6
- private animationFrameDisposer?: () => void
7
-
8
- public onDispose = (callback: () => void) => {
9
- this.disposeMethods.push(callback)
10
- return this
11
- }
12
-
13
- public play = () => {
14
- this.start()
15
- this.animationFrameDisposer = requestAnimationFrameInterval(() => this.update())
16
- return this
17
- }
18
-
19
- public dispose = () => {
20
- this.stop()
21
- this.animationFrameDisposer?.()
22
- this.disposeMethods.forEach((fn) => fn())
23
- this.disposeMethods = []
24
- TWEEN.remove(this)
25
- }
26
- }
27
-
28
- export function tweenProgress(duration?: number, easing = TWEEN.Easing.Linear.None) {
29
- const tween = new BetterTween({ progress: 0 }).to({ progress: 1 })
30
- if (duration !== undefined) tween.duration(duration)
31
- if (easing !== undefined) tween.easing(easing)
32
- return tween
33
- }
@@ -1,48 +0,0 @@
1
- const _requestAnimationFrame = window.requestAnimationFrame || ((fn) => setTimeout(fn, 16))
2
-
3
- const _cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout
4
-
5
- export default _requestAnimationFrame
6
-
7
- export function nextFrame(fn: FrameRequestCallback, delay = 0) {
8
- if (delay <= 0) _requestAnimationFrame(fn)
9
- else _requestAnimationFrame(() => nextFrame(fn, delay - 1))
10
- }
11
-
12
- /**
13
- * 在每个 AnimationFrame 中调用传入的函数
14
- * @param callback 每次 AnimationFrame 中调用的函数
15
- * @param frame 每秒运行多少次
16
- * @returns 返回一个函数,调用可以停止 AnimationFrameLoop
17
- */
18
- export function requestAnimationFrameInterval(callback?: (time: number) => any, frame = 60) {
19
- let index = -1
20
- let oldTime = 0
21
- let startTime = -1
22
- const minDeltaTime = 1000 / frame
23
- function loop(time: number) {
24
- startTime === -1 && (startTime = time)
25
- index = _requestAnimationFrame(loop)
26
- const deltaTime = time - oldTime
27
- if (deltaTime < minDeltaTime) return
28
- oldTime = time
29
- callback && callback(time - startTime)
30
- }
31
- index = _requestAnimationFrame(loop)
32
- return function stop() {
33
- _cancelAnimationFrame(index)
34
- }
35
- }
36
-
37
- /**
38
- * 获取两个 AnimationFrame 间隔的时间
39
- * @returns 返回一个 Promise,resolve 的结果是两个 AnimationFrame 间隔的时间
40
- */
41
- export function getFrameTime() {
42
- const start = Date.now()
43
- return new Promise((resolve) => {
44
- _requestAnimationFrame(() => {
45
- resolve(Date.now() - start)
46
- })
47
- })
48
- }
@@ -1,51 +0,0 @@
1
- import * as TWEEN from '@tweenjs/tween.js'
2
- import { nextFrame, requestAnimationFrameInterval } from './index'
3
-
4
- export const Easing = TWEEN.Easing
5
-
6
- interface ITween<T> extends TWEEN.Tween<T> {
7
- onDestroy: (fn: () => void) => TWEEN.Tween<T>
8
- destroy: () => void
9
- }
10
-
11
- /**
12
- * 对象变化的补间动画
13
- * 1. 应用 requestAnimationFrameInterval 做 update
14
- * 2. 在原生 tween 上新增 destroy 方法和 onDestroy 监听
15
- * DOC: https://github.com/tweenjs/tween.js
16
- * @param from 对象起始状态
17
- * @param to 对象末尾状态
18
- * @param duration 经历时间(s)
19
- * @param easing 过程动画,默认是 Easing.Linear.None
20
- */
21
- export default function tween<T>(from: T, to: T, duration: number, easing = Easing.Linear.None) {
22
- const tween = new TWEEN.Tween(from).to(to, duration).easing(easing) as ITween<T>
23
- // 这里注意一下,因为 requestAnimationFrameInterval 给的时间是从 0 开始的,tween 动画也从 0 开始
24
- nextFrame(() => tween.start(0))
25
-
26
- const cancelAnimationFrame = requestAnimationFrameInterval((time) => {
27
- if (tween.update(time) === false) cancelAnimationFrame()
28
- })
29
- const destroyMethods: ((...params: any) => any)[] = []
30
- tween.onDestroy = (fn) => {
31
- destroyMethods.push(fn)
32
- return tween
33
- }
34
- tween.destroy = function () {
35
- this.stop()
36
- Object.assign(tween, {
37
- _onStartCallback: null,
38
- _onUpdateCallback: null,
39
- _onCompleteCallback: null,
40
- _onStopCallbackL: null,
41
- })
42
- let destroyMethod: undefined | ((...params: any) => any)
43
- while ((destroyMethod = destroyMethods.shift())) destroyMethod()
44
- cancelAnimationFrame()
45
- }
46
- return tween
47
- }
48
-
49
- export function tweenProgress(duration: number, easing: typeof Easing.Linear.None) {
50
- return tween({ progress: 0 }, { progress: 1 }, duration, easing)
51
- }
@@ -1,12 +0,0 @@
1
- import * as THREE from 'three'
2
-
3
- export function createTransMatrix(arr1: number[]) {
4
- const matrix4 = new THREE.Matrix4()
5
- matrix4.fromArray(arr1)
6
-
7
- return (arr2: number[]) => {
8
- const vector3 = new THREE.Vector3(...arr2)
9
- vector3.applyMatrix4(matrix4)
10
- return vector3.toArray()
11
- }
12
- }
@@ -1,6 +0,0 @@
1
- export default function getFileExpandedName(filePath?: string | null) {
2
- if (!filePath) return ''
3
- const index = filePath.lastIndexOf('.')
4
- const ext = filePath.substring(index + 1)
5
- return ext.toLowerCase()
6
- }
@@ -1,52 +0,0 @@
1
- import getFileExpandedName from './getFileExpandedName'
2
-
3
- export default function getMediaInfo(fileUrl: string): Promise<{
4
- duration?: number | undefined
5
- type?: 'video' | 'audio' | 'image' | 'unknown' | undefined
6
- error?: string | undefined
7
- }> {
8
- const type = getMediaType(fileUrl)
9
- if (!type) return Promise.resolve({ error: '未知的文件类型: ' + fileUrl })
10
- const mediaElement = (() => {
11
- if (type === 'video') return document.createElement('video')
12
- if (type === 'audio') return document.createElement('audio')
13
- })()
14
- if (!mediaElement) return Promise.resolve({ error: 'Unknown media element' })
15
- mediaElement.src = fileUrl
16
- return new Promise<{ duration?: number; type?: 'video' | 'audio' | 'image' | 'unknown'; error?: string }>((resolve) => {
17
- mediaElement.onerror = () => resolve({ error: 'onerror' })
18
- mediaElement.onloadedmetadata = () => {
19
- resolve({ duration: mediaElement.duration * 1000, type }) // s => ms
20
- }
21
- })
22
- }
23
-
24
- export function getMediaType(url?: string) {
25
- const fileExpandedName = getFileExpandedName(url)
26
- const type = getMediaTypeByExpandedName(fileExpandedName)
27
- return type
28
- }
29
-
30
- export function getMediaTypeByExpandedName(fileExpandedName?: string | null) {
31
- if (!fileExpandedName) return 'unknown'
32
- if (/jpg|jpeg|png$/.test(fileExpandedName)) return 'image'
33
- if (/mp3|wav$/.test(fileExpandedName)) return 'audio'
34
- if (/avi|wmv|mpeg|mp4|m4v|mov|asf|flv|f4v|rmvb|rm|3gp|vob$/.test(fileExpandedName)) return 'video'
35
- return 'unknown'
36
- }
37
-
38
- export function getMediaTypeByUrl(fileUrl?: string | null) {
39
- if (!fileUrl) return
40
- const fileExpandedName = getFileExpandedName(fileUrl)
41
- return getMediaTypeByExpandedName(fileExpandedName)
42
- }
43
-
44
- export function getFileName(fileUrl?: string) {
45
- if (!fileUrl) return ''
46
- const index1 = fileUrl.lastIndexOf('/')
47
- const index2 = fileUrl.lastIndexOf('\\')
48
- const index3 = fileUrl.lastIndexOf('\\\\')
49
- const index = Math.max(index1, index2, index3)
50
- const ext = fileUrl.substring(index + 1)
51
- return ext
52
- }
@@ -1,18 +0,0 @@
1
- export default function setElementDataset(element: any, dataset: Record<string, string | number>) {
2
- if (element) {
3
- Object.keys(dataset).forEach((key) => {
4
-
5
- const value = dataset[key].toString()
6
-
7
- if (element instanceof Element) {
8
- element.setAttribute(`data-${key}`, value)
9
- } else if (element instanceof Document) {
10
- element.documentElement.setAttribute(`data-${key}`, value)
11
- } else if (element instanceof HTMLElement) {
12
- element.dataset[key] = value
13
- } else {
14
- (element as any).setAttribute(`data-${key}`, value)
15
- }
16
- })
17
- }
18
- }