@lightningjs/renderer 2.9.0-beta2 → 2.9.0-beta4

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 (193) hide show
  1. package/COPYING +1 -0
  2. package/LICENSE +202 -202
  3. package/NOTICE +3 -3
  4. package/README.md +147 -147
  5. package/dist/src/core/CoreNode.d.ts +29 -6
  6. package/dist/src/core/CoreNode.js +118 -79
  7. package/dist/src/core/CoreNode.js.map +1 -1
  8. package/dist/src/core/CoreTextNode.d.ts +2 -2
  9. package/dist/src/core/CoreTextNode.js +7 -4
  10. package/dist/src/core/CoreTextNode.js.map +1 -1
  11. package/dist/src/core/CoreTextureManager.d.ts +61 -15
  12. package/dist/src/core/CoreTextureManager.js +179 -104
  13. package/dist/src/core/CoreTextureManager.js.map +1 -1
  14. package/dist/src/core/Stage.d.ts +7 -0
  15. package/dist/src/core/Stage.js +34 -1
  16. package/dist/src/core/Stage.js.map +1 -1
  17. package/dist/src/core/TextureMemoryManager.js +2 -5
  18. package/dist/src/core/TextureMemoryManager.js.map +1 -1
  19. package/dist/src/core/lib/ImageWorker.js +31 -28
  20. package/dist/src/core/lib/ImageWorker.js.map +1 -1
  21. package/dist/src/core/lib/WebGlContextWrapper.d.ts +1 -0
  22. package/dist/src/core/lib/WebGlContextWrapper.js +2 -0
  23. package/dist/src/core/lib/WebGlContextWrapper.js.map +1 -1
  24. package/dist/src/core/renderers/CoreContextTexture.d.ts +1 -0
  25. package/dist/src/core/renderers/CoreContextTexture.js +1 -0
  26. package/dist/src/core/renderers/CoreContextTexture.js.map +1 -1
  27. package/dist/src/core/renderers/canvas/CanvasCoreRenderer.d.ts +1 -1
  28. package/dist/src/core/renderers/canvas/CanvasCoreRenderer.js +13 -5
  29. package/dist/src/core/renderers/canvas/CanvasCoreRenderer.js.map +1 -1
  30. package/dist/src/core/renderers/canvas/CanvasCoreTexture.js +6 -8
  31. package/dist/src/core/renderers/canvas/CanvasCoreTexture.js.map +1 -1
  32. package/dist/src/core/renderers/webgl/WebGlCoreCtxSubTexture.js +3 -1
  33. package/dist/src/core/renderers/webgl/WebGlCoreCtxSubTexture.js.map +1 -1
  34. package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.d.ts +1 -2
  35. package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js +26 -24
  36. package/dist/src/core/renderers/webgl/WebGlCoreCtxTexture.js.map +1 -1
  37. package/dist/src/core/renderers/webgl/WebGlCoreRenderer.d.ts +0 -1
  38. package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js +7 -17
  39. package/dist/src/core/renderers/webgl/WebGlCoreRenderer.js.map +1 -1
  40. package/dist/src/core/renderers/webgl/shaders/DefaultShader.js +45 -45
  41. package/dist/src/core/renderers/webgl/shaders/DefaultShaderBatched.js +61 -61
  42. package/dist/src/core/renderers/webgl/shaders/DynamicShader.js +93 -93
  43. package/dist/src/core/renderers/webgl/shaders/RoundedRectangle.js +63 -63
  44. package/dist/src/core/renderers/webgl/shaders/SdfShader.js +62 -62
  45. package/dist/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.js +15 -15
  46. package/dist/src/core/renderers/webgl/shaders/effects/BorderEffect.js +6 -6
  47. package/dist/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.js +15 -15
  48. package/dist/src/core/renderers/webgl/shaders/effects/BorderRightEffect.js +15 -15
  49. package/dist/src/core/renderers/webgl/shaders/effects/BorderTopEffect.js +15 -15
  50. package/dist/src/core/renderers/webgl/shaders/effects/FadeOutEffect.js +42 -42
  51. package/dist/src/core/renderers/webgl/shaders/effects/GlitchEffect.js +44 -44
  52. package/dist/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.js +3 -3
  53. package/dist/src/core/renderers/webgl/shaders/effects/HolePunchEffect.js +22 -22
  54. package/dist/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.js +28 -28
  55. package/dist/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.js +12 -12
  56. package/dist/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.js +37 -37
  57. package/dist/src/core/renderers/webgl/shaders/effects/RadiusEffect.js +19 -19
  58. package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.js +9 -5
  59. package/dist/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.js.map +1 -1
  60. package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js +2 -1
  61. package/dist/src/core/text-rendering/renderers/CanvasTextRenderer.js.map +1 -1
  62. package/dist/src/core/textures/ColorTexture.d.ts +1 -1
  63. package/dist/src/core/textures/ColorTexture.js +2 -1
  64. package/dist/src/core/textures/ColorTexture.js.map +1 -1
  65. package/dist/src/core/textures/ImageTexture.d.ts +8 -1
  66. package/dist/src/core/textures/ImageTexture.js +39 -1
  67. package/dist/src/core/textures/ImageTexture.js.map +1 -1
  68. package/dist/src/core/textures/NoiseTexture.d.ts +1 -1
  69. package/dist/src/core/textures/NoiseTexture.js +2 -1
  70. package/dist/src/core/textures/NoiseTexture.js.map +1 -1
  71. package/dist/src/core/textures/RenderTexture.d.ts +1 -1
  72. package/dist/src/core/textures/RenderTexture.js +2 -1
  73. package/dist/src/core/textures/RenderTexture.js.map +1 -1
  74. package/dist/src/core/textures/SubTexture.d.ts +1 -1
  75. package/dist/src/core/textures/SubTexture.js +21 -4
  76. package/dist/src/core/textures/SubTexture.js.map +1 -1
  77. package/dist/src/core/textures/Texture.d.ts +44 -22
  78. package/dist/src/core/textures/Texture.js +116 -36
  79. package/dist/src/core/textures/Texture.js.map +1 -1
  80. package/dist/src/main-api/Renderer.d.ts +18 -0
  81. package/dist/src/main-api/Renderer.js +6 -4
  82. package/dist/src/main-api/Renderer.js.map +1 -1
  83. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  84. package/exports/canvas.ts +39 -39
  85. package/exports/index.ts +89 -89
  86. package/exports/inspector.ts +24 -24
  87. package/exports/utils.ts +44 -44
  88. package/exports/webgl.ts +38 -38
  89. package/package.json +1 -1
  90. package/scripts/please-use-pnpm.js +13 -13
  91. package/src/common/CommonTypes.ts +139 -139
  92. package/src/common/EventEmitter.ts +77 -77
  93. package/src/common/IAnimationController.ts +92 -92
  94. package/src/common/IEventEmitter.ts +28 -28
  95. package/src/core/CoreNode.test.ts +199 -95
  96. package/src/core/CoreNode.ts +2313 -2258
  97. package/src/core/CoreShaderManager.ts +292 -292
  98. package/src/core/CoreTextNode.ts +455 -450
  99. package/src/core/CoreTextureManager.ts +522 -432
  100. package/src/core/Stage.ts +700 -652
  101. package/src/core/TextureMemoryManager.ts +277 -279
  102. package/src/core/animations/AnimationManager.ts +38 -38
  103. package/src/core/animations/CoreAnimation.ts +340 -340
  104. package/src/core/animations/CoreAnimationController.ts +157 -157
  105. package/src/core/lib/ContextSpy.ts +41 -41
  106. package/src/core/lib/ImageWorker.ts +270 -267
  107. package/src/core/lib/Matrix3d.ts +244 -244
  108. package/src/core/lib/RenderCoords.ts +86 -86
  109. package/src/core/lib/WebGlContextWrapper.ts +1322 -1320
  110. package/src/core/lib/textureCompression.ts +152 -152
  111. package/src/core/lib/textureSvg.ts +78 -78
  112. package/src/core/lib/utils.ts +306 -306
  113. package/src/core/platform.ts +61 -61
  114. package/src/core/renderers/CoreContextTexture.ts +43 -42
  115. package/src/core/renderers/CoreRenderOp.ts +22 -22
  116. package/src/core/renderers/CoreRenderer.ts +114 -114
  117. package/src/core/renderers/CoreShader.ts +41 -41
  118. package/src/core/renderers/canvas/CanvasCoreRenderer.ts +364 -353
  119. package/src/core/renderers/canvas/CanvasCoreTexture.ts +150 -149
  120. package/src/core/renderers/canvas/internal/C2DShaderUtils.ts +231 -231
  121. package/src/core/renderers/canvas/internal/ColorUtils.ts +69 -69
  122. package/src/core/renderers/canvas/shaders/UnsupportedShader.ts +48 -48
  123. package/src/core/renderers/webgl/WebGlCoreCtxRenderTexture.ts +79 -79
  124. package/src/core/renderers/webgl/WebGlCoreCtxSubTexture.ts +50 -48
  125. package/src/core/renderers/webgl/WebGlCoreCtxTexture.ts +298 -290
  126. package/src/core/renderers/webgl/WebGlCoreRenderOp.ts +125 -125
  127. package/src/core/renderers/webgl/WebGlCoreRenderer.ts +805 -817
  128. package/src/core/renderers/webgl/WebGlCoreShader.ts +362 -362
  129. package/src/core/renderers/webgl/internal/BufferCollection.ts +54 -54
  130. package/src/core/renderers/webgl/internal/RendererUtils.ts +155 -155
  131. package/src/core/renderers/webgl/internal/ShaderUtils.ts +143 -143
  132. package/src/core/renderers/webgl/internal/WebGlUtils.ts +35 -35
  133. package/src/core/renderers/webgl/shaders/DefaultShader.ts +93 -93
  134. package/src/core/renderers/webgl/shaders/DefaultShaderBatched.ts +132 -132
  135. package/src/core/renderers/webgl/shaders/DynamicShader.ts +580 -580
  136. package/src/core/renderers/webgl/shaders/RoundedRectangle.ts +167 -167
  137. package/src/core/renderers/webgl/shaders/SdfShader.ts +204 -204
  138. package/src/core/renderers/webgl/shaders/effects/BorderBottomEffect.ts +101 -101
  139. package/src/core/renderers/webgl/shaders/effects/BorderEffect.ts +87 -87
  140. package/src/core/renderers/webgl/shaders/effects/BorderLeftEffect.ts +101 -101
  141. package/src/core/renderers/webgl/shaders/effects/BorderRightEffect.ts +101 -101
  142. package/src/core/renderers/webgl/shaders/effects/BorderTopEffect.ts +101 -101
  143. package/src/core/renderers/webgl/shaders/effects/EffectUtils.ts +159 -159
  144. package/src/core/renderers/webgl/shaders/effects/FadeOutEffect.ts +127 -127
  145. package/src/core/renderers/webgl/shaders/effects/GlitchEffect.ts +148 -148
  146. package/src/core/renderers/webgl/shaders/effects/GrayscaleEffect.ts +67 -67
  147. package/src/core/renderers/webgl/shaders/effects/HolePunchEffect.ts +157 -157
  148. package/src/core/renderers/webgl/shaders/effects/LinearGradientEffect.ts +171 -171
  149. package/src/core/renderers/webgl/shaders/effects/RadialGradientEffect.ts +168 -168
  150. package/src/core/renderers/webgl/shaders/effects/RadialProgressEffect.ts +187 -187
  151. package/src/core/renderers/webgl/shaders/effects/RadiusEffect.ts +110 -110
  152. package/src/core/renderers/webgl/shaders/effects/ShaderEffect.ts +196 -196
  153. package/src/core/text-rendering/TextRenderingUtils.ts +36 -36
  154. package/src/core/text-rendering/TextTextureRendererUtils.ts +263 -263
  155. package/src/core/text-rendering/TrFontManager.ts +183 -183
  156. package/src/core/text-rendering/font-face-types/SdfTrFontFace/SdfTrFontFace.ts +176 -171
  157. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/FontShaper.ts +139 -139
  158. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.test.ts +173 -173
  159. package/src/core/text-rendering/font-face-types/SdfTrFontFace/internal/SdfFontShaper.ts +171 -171
  160. package/src/core/text-rendering/font-face-types/TrFontFace.ts +187 -187
  161. package/src/core/text-rendering/font-face-types/WebTrFontFace.ts +89 -89
  162. package/src/core/text-rendering/renderers/CanvasTextRenderer.ts +509 -507
  163. package/src/core/text-rendering/renderers/LightningTextTextureRenderer.ts +798 -798
  164. package/src/core/text-rendering/renderers/SdfTextRenderer/SdfTextRenderer.ts +853 -853
  165. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.test.ts +48 -48
  166. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/PeekableGenerator.ts +66 -66
  167. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/SpecialCodepoints.ts +52 -52
  168. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/constants.ts +32 -32
  169. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getStartConditions.ts +117 -117
  170. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.test.ts +133 -133
  171. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/getUnicodeCodepoints.ts +38 -38
  172. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/layoutText.ts +403 -403
  173. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.test.ts +49 -49
  174. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/measureText.ts +52 -52
  175. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.test.ts +205 -205
  176. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/setRenderWindow.ts +93 -93
  177. package/src/core/text-rendering/renderers/SdfTextRenderer/internal/util.ts +40 -40
  178. package/src/core/text-rendering/renderers/TextRenderer.ts +557 -557
  179. package/src/core/textures/ColorTexture.ts +102 -100
  180. package/src/core/textures/ImageTexture.ts +378 -337
  181. package/src/core/textures/NoiseTexture.ts +104 -101
  182. package/src/core/textures/RenderTexture.ts +85 -83
  183. package/src/core/textures/SubTexture.ts +171 -146
  184. package/src/core/textures/Texture.ts +423 -318
  185. package/src/core/utils.ts +227 -227
  186. package/src/env.d.ts +7 -7
  187. package/src/main-api/DynamicShaderController.ts +104 -104
  188. package/src/main-api/INode.ts +101 -101
  189. package/src/main-api/Inspector.ts +505 -505
  190. package/src/main-api/Renderer.ts +693 -670
  191. package/src/main-api/ShaderController.ts +80 -80
  192. package/src/main-api/utils.ts +45 -45
  193. package/src/utils.ts +248 -248
@@ -1,139 +1,139 @@
1
- /*
2
- * If not stated otherwise in this file or this component's LICENSE file the
3
- * following copyright and licenses apply:
4
- *
5
- * Copyright 2023 Comcast Cable Communications Management, LLC.
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the License);
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
-
20
- import type { CoreNodeRenderState } from '../core/CoreNode.js';
21
-
22
- /**
23
- * Types shared between Main Space and Core Space
24
- *
25
- * @remarks
26
- *
27
- * @module
28
- */
29
-
30
- /**
31
- * Represents a width and height.
32
- */
33
- export interface Dimensions {
34
- width: number;
35
- height: number;
36
- }
37
-
38
- /**
39
- * Payload for when text is loaded
40
- */
41
- export type NodeTextLoadedPayload = {
42
- type: 'text';
43
- dimensions: Dimensions;
44
- };
45
-
46
- /**
47
- * Payload for when texture is loaded
48
- */
49
- export type NodeTextureLoadedPayload = {
50
- type: 'texture';
51
- dimensions: Dimensions;
52
- };
53
-
54
- /**
55
- * Combined type for all loaded payloads
56
- */
57
- export type NodeLoadedPayload =
58
- | NodeTextLoadedPayload
59
- | NodeTextureLoadedPayload;
60
-
61
- /**
62
- * Payload for when text failed to load
63
- */
64
- export type NodeTextFailedPayload = {
65
- type: 'text';
66
- error: Error;
67
- };
68
-
69
- /**
70
- * Payload for when texture failed to load
71
- */
72
- export type NodeTextureFailedPayload = {
73
- type: 'texture';
74
- error: Error;
75
- };
76
-
77
- /**
78
- * Payload for when texture failed to load
79
- */
80
- export type NodeTextureFreedPayload = {
81
- type: 'texture';
82
- };
83
-
84
- /**
85
- * Combined type for all failed payloads
86
- */
87
- export type NodeFailedPayload =
88
- | NodeTextFailedPayload
89
- | NodeTextureFailedPayload;
90
-
91
- /**
92
- * Event handler for when the texture/text of a node has loaded
93
- */
94
- export type NodeLoadedEventHandler = (
95
- target: any,
96
- payload: NodeLoadedPayload,
97
- ) => void;
98
-
99
- /**
100
- * Event handler for when the texture/text of a node has failed to load
101
- */
102
- export type NodeFailedEventHandler = (
103
- target: any,
104
- payload: NodeFailedPayload,
105
- ) => void;
106
-
107
- export type NodeRenderStatePayload = {
108
- type: 'renderState';
109
- payload: CoreNodeRenderState;
110
- };
111
-
112
- export type NodeRenderStateEventHandler = (
113
- target: any,
114
- payload: NodeRenderStatePayload,
115
- ) => void;
116
-
117
- /**
118
- * Event payload for when an FpsUpdate event is emitted by either the Stage or
119
- * MainRenderer
120
- */
121
- export interface FpsUpdatePayload {
122
- fps: number;
123
- contextSpyData: Record<string, number> | null;
124
- }
125
-
126
- /**
127
- * Event payload for when a frame tick event is emitted by the Stage
128
- */
129
- export interface FrameTickPayload {
130
- time: number;
131
- delta: number;
132
- }
133
-
134
- /**
135
- * Event payload for when a an animtion tick event is emitted
136
- */
137
- export interface AnimationTickPayload {
138
- progress: number;
139
- }
1
+ /*
2
+ * If not stated otherwise in this file or this component's LICENSE file the
3
+ * following copyright and licenses apply:
4
+ *
5
+ * Copyright 2023 Comcast Cable Communications Management, LLC.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the License);
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ import type { CoreNodeRenderState } from '../core/CoreNode.js';
21
+
22
+ /**
23
+ * Types shared between Main Space and Core Space
24
+ *
25
+ * @remarks
26
+ *
27
+ * @module
28
+ */
29
+
30
+ /**
31
+ * Represents a width and height.
32
+ */
33
+ export interface Dimensions {
34
+ width: number;
35
+ height: number;
36
+ }
37
+
38
+ /**
39
+ * Payload for when text is loaded
40
+ */
41
+ export type NodeTextLoadedPayload = {
42
+ type: 'text';
43
+ dimensions: Dimensions;
44
+ };
45
+
46
+ /**
47
+ * Payload for when texture is loaded
48
+ */
49
+ export type NodeTextureLoadedPayload = {
50
+ type: 'texture';
51
+ dimensions: Dimensions;
52
+ };
53
+
54
+ /**
55
+ * Combined type for all loaded payloads
56
+ */
57
+ export type NodeLoadedPayload =
58
+ | NodeTextLoadedPayload
59
+ | NodeTextureLoadedPayload;
60
+
61
+ /**
62
+ * Payload for when text failed to load
63
+ */
64
+ export type NodeTextFailedPayload = {
65
+ type: 'text';
66
+ error: Error;
67
+ };
68
+
69
+ /**
70
+ * Payload for when texture failed to load
71
+ */
72
+ export type NodeTextureFailedPayload = {
73
+ type: 'texture';
74
+ error: Error;
75
+ };
76
+
77
+ /**
78
+ * Payload for when texture failed to load
79
+ */
80
+ export type NodeTextureFreedPayload = {
81
+ type: 'texture';
82
+ };
83
+
84
+ /**
85
+ * Combined type for all failed payloads
86
+ */
87
+ export type NodeFailedPayload =
88
+ | NodeTextFailedPayload
89
+ | NodeTextureFailedPayload;
90
+
91
+ /**
92
+ * Event handler for when the texture/text of a node has loaded
93
+ */
94
+ export type NodeLoadedEventHandler = (
95
+ target: any,
96
+ payload: NodeLoadedPayload,
97
+ ) => void;
98
+
99
+ /**
100
+ * Event handler for when the texture/text of a node has failed to load
101
+ */
102
+ export type NodeFailedEventHandler = (
103
+ target: any,
104
+ payload: NodeFailedPayload,
105
+ ) => void;
106
+
107
+ export type NodeRenderStatePayload = {
108
+ type: 'renderState';
109
+ payload: CoreNodeRenderState;
110
+ };
111
+
112
+ export type NodeRenderStateEventHandler = (
113
+ target: any,
114
+ payload: NodeRenderStatePayload,
115
+ ) => void;
116
+
117
+ /**
118
+ * Event payload for when an FpsUpdate event is emitted by either the Stage or
119
+ * MainRenderer
120
+ */
121
+ export interface FpsUpdatePayload {
122
+ fps: number;
123
+ contextSpyData: Record<string, number> | null;
124
+ }
125
+
126
+ /**
127
+ * Event payload for when a frame tick event is emitted by the Stage
128
+ */
129
+ export interface FrameTickPayload {
130
+ time: number;
131
+ delta: number;
132
+ }
133
+
134
+ /**
135
+ * Event payload for when a an animtion tick event is emitted
136
+ */
137
+ export interface AnimationTickPayload {
138
+ progress: number;
139
+ }
@@ -1,77 +1,77 @@
1
- /*
2
- * If not stated otherwise in this file or this component's LICENSE file the
3
- * following copyright and licenses apply:
4
- *
5
- * Copyright 2023 Comcast Cable Communications Management, LLC.
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the License);
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
-
20
- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
21
- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
22
- /* eslint-disable @typescript-eslint/no-unsafe-call */
23
- /* eslint-disable @typescript-eslint/no-explicit-any */
24
- import type { IEventEmitter } from './IEventEmitter.js';
25
-
26
- /**
27
- * EventEmitter base class
28
- */
29
- export class EventEmitter implements IEventEmitter {
30
- private eventListeners: { [eventName: string]: any } = {};
31
-
32
- on(event: string, listener: (target: any, data: any) => void): void {
33
- let listeners = this.eventListeners[event];
34
- if (!listeners) {
35
- listeners = [];
36
- }
37
- listeners.push(listener);
38
- this.eventListeners[event] = listeners;
39
- }
40
-
41
- off(event: string, listener?: (target: any, data: any) => void): void {
42
- const listeners = this.eventListeners[event];
43
- if (!listeners) {
44
- return;
45
- }
46
- if (!listener) {
47
- delete this.eventListeners[event];
48
- return;
49
- }
50
- const index = listeners.indexOf(listener);
51
- if (index >= 0) {
52
- listeners.splice(index, 1);
53
- }
54
- }
55
-
56
- once(event: string, listener: (target: any, data: any) => void): void {
57
- const onceListener = (target: any, data: any) => {
58
- this.off(event, onceListener);
59
- listener(target, data);
60
- };
61
- this.on(event, onceListener);
62
- }
63
-
64
- emit(event: string, data?: any): void {
65
- const listeners = this.eventListeners[event];
66
- if (!listeners) {
67
- return;
68
- }
69
- [...listeners].forEach((listener) => {
70
- listener(this, data);
71
- });
72
- }
73
-
74
- removeAllListeners() {
75
- this.eventListeners = {};
76
- }
77
- }
1
+ /*
2
+ * If not stated otherwise in this file or this component's LICENSE file the
3
+ * following copyright and licenses apply:
4
+ *
5
+ * Copyright 2023 Comcast Cable Communications Management, LLC.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the License);
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
21
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
22
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
23
+ /* eslint-disable @typescript-eslint/no-explicit-any */
24
+ import type { IEventEmitter } from './IEventEmitter.js';
25
+
26
+ /**
27
+ * EventEmitter base class
28
+ */
29
+ export class EventEmitter implements IEventEmitter {
30
+ private eventListeners: { [eventName: string]: any } = {};
31
+
32
+ on(event: string, listener: (target: any, data: any) => void): void {
33
+ let listeners = this.eventListeners[event];
34
+ if (!listeners) {
35
+ listeners = [];
36
+ }
37
+ listeners.push(listener);
38
+ this.eventListeners[event] = listeners;
39
+ }
40
+
41
+ off(event: string, listener?: (target: any, data: any) => void): void {
42
+ const listeners = this.eventListeners[event];
43
+ if (!listeners) {
44
+ return;
45
+ }
46
+ if (!listener) {
47
+ delete this.eventListeners[event];
48
+ return;
49
+ }
50
+ const index = listeners.indexOf(listener);
51
+ if (index >= 0) {
52
+ listeners.splice(index, 1);
53
+ }
54
+ }
55
+
56
+ once(event: string, listener: (target: any, data: any) => void): void {
57
+ const onceListener = (target: any, data: any) => {
58
+ this.off(event, onceListener);
59
+ listener(target, data);
60
+ };
61
+ this.on(event, onceListener);
62
+ }
63
+
64
+ emit(event: string, data?: any): void {
65
+ const listeners = this.eventListeners[event];
66
+ if (!listeners) {
67
+ return;
68
+ }
69
+ [...listeners].forEach((listener) => {
70
+ listener(this, data);
71
+ });
72
+ }
73
+
74
+ removeAllListeners() {
75
+ this.eventListeners = {};
76
+ }
77
+ }
@@ -1,92 +1,92 @@
1
- /*
2
- * If not stated otherwise in this file or this component's LICENSE file the
3
- * following copyright and licenses apply:
4
- *
5
- * Copyright 2023 Comcast Cable Communications Management, LLC.
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the License);
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- import type { IEventEmitter } from './IEventEmitter.js';
20
-
21
- export type AnimationControllerState =
22
- | 'scheduled'
23
- | 'running'
24
- | 'paused'
25
- | 'stopped';
26
-
27
- /**
28
- * Animation Controller interface
29
- *
30
- * @remarks
31
- * This interface is used to control animations. It provides methods to start,
32
- * stop, pause, and restore animations. It also provides a way to wait for the
33
- * animation to stop.
34
- *
35
- * This interface extends the `IEventEmitter` interface, which means you can
36
- * listen to these events emitted by the animation controller:
37
- * - `animating` - Emitted when the animation finishes it's delay phase and
38
- * starts animating.
39
- * - `stopped` - Emitted when the animation stops either by calling the `stop()`
40
- * method or when the animation finishes naturally.
41
- */
42
- export interface IAnimationController extends IEventEmitter {
43
- /**
44
- * Start the animation
45
- *
46
- * @remarks
47
- * If the animation is paused this method will resume the animation.
48
- */
49
- start(): IAnimationController;
50
- /**
51
- * Stop the animation
52
- *
53
- * @remarks
54
- * Resets the animation to the start state
55
- */
56
- stop(): IAnimationController;
57
- /**
58
- * Pause the animation
59
- */
60
- pause(): IAnimationController;
61
- /**
62
- * Restore the animation to the original values
63
- */
64
- restore(): IAnimationController;
65
-
66
- /**
67
- * Promise that resolves when the last active animation is stopped (including
68
- * when the animation finishes naturally).
69
- *
70
- * @remarks
71
- * The Promise returned by this method is reset every time the animation
72
- * enters a new start/stop cycle. This means you must call `start()` before
73
- * calling this method if you want to wait for the animation to stop.
74
- *
75
- * This method always returns a resolved promise if the animation is currently
76
- * in a stopped state.
77
- *
78
- * @returns
79
- */
80
- waitUntilStopped(): Promise<void>;
81
-
82
- /**
83
- * Current state of the animation
84
- *
85
- * @remarks
86
- * - `stopped` - The animation is currently stopped (at the beggining or end
87
- * of the animation)
88
- * - `running` - The animation is currently running
89
- * - `paused` - The animation is currently paused
90
- */
91
- readonly state: AnimationControllerState;
92
- }
1
+ /*
2
+ * If not stated otherwise in this file or this component's LICENSE file the
3
+ * following copyright and licenses apply:
4
+ *
5
+ * Copyright 2023 Comcast Cable Communications Management, LLC.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the License);
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ import type { IEventEmitter } from './IEventEmitter.js';
20
+
21
+ export type AnimationControllerState =
22
+ | 'scheduled'
23
+ | 'running'
24
+ | 'paused'
25
+ | 'stopped';
26
+
27
+ /**
28
+ * Animation Controller interface
29
+ *
30
+ * @remarks
31
+ * This interface is used to control animations. It provides methods to start,
32
+ * stop, pause, and restore animations. It also provides a way to wait for the
33
+ * animation to stop.
34
+ *
35
+ * This interface extends the `IEventEmitter` interface, which means you can
36
+ * listen to these events emitted by the animation controller:
37
+ * - `animating` - Emitted when the animation finishes it's delay phase and
38
+ * starts animating.
39
+ * - `stopped` - Emitted when the animation stops either by calling the `stop()`
40
+ * method or when the animation finishes naturally.
41
+ */
42
+ export interface IAnimationController extends IEventEmitter {
43
+ /**
44
+ * Start the animation
45
+ *
46
+ * @remarks
47
+ * If the animation is paused this method will resume the animation.
48
+ */
49
+ start(): IAnimationController;
50
+ /**
51
+ * Stop the animation
52
+ *
53
+ * @remarks
54
+ * Resets the animation to the start state
55
+ */
56
+ stop(): IAnimationController;
57
+ /**
58
+ * Pause the animation
59
+ */
60
+ pause(): IAnimationController;
61
+ /**
62
+ * Restore the animation to the original values
63
+ */
64
+ restore(): IAnimationController;
65
+
66
+ /**
67
+ * Promise that resolves when the last active animation is stopped (including
68
+ * when the animation finishes naturally).
69
+ *
70
+ * @remarks
71
+ * The Promise returned by this method is reset every time the animation
72
+ * enters a new start/stop cycle. This means you must call `start()` before
73
+ * calling this method if you want to wait for the animation to stop.
74
+ *
75
+ * This method always returns a resolved promise if the animation is currently
76
+ * in a stopped state.
77
+ *
78
+ * @returns
79
+ */
80
+ waitUntilStopped(): Promise<void>;
81
+
82
+ /**
83
+ * Current state of the animation
84
+ *
85
+ * @remarks
86
+ * - `stopped` - The animation is currently stopped (at the beggining or end
87
+ * of the animation)
88
+ * - `running` - The animation is currently running
89
+ * - `paused` - The animation is currently paused
90
+ */
91
+ readonly state: AnimationControllerState;
92
+ }
@@ -1,28 +1,28 @@
1
- /*
2
- * Copyright 2023 Comcast Cable Communications Management, LLC
3
- * Licensed under the Apache License, Version 2.0 (the "License");
4
- * you may not use this file except in compliance with the License.
5
- * You may obtain a copy of the License at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * Unless required by applicable law or agreed to in writing, software
10
- * distributed under the License is distributed on an "AS IS" BASIS,
11
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- * See the License for the specific language governing permissions and
13
- * limitations under the License.
14
- *
15
- * SPDX-License-Identifier: Apache-2.0
16
- */
17
-
18
- export interface IEventEmitter<
19
- T extends object = { [s: string]: (target: any, data: any) => void },
20
- > {
21
- on<K extends keyof T>(event: Extract<K, string>, listener: T[K]): void;
22
- once<K extends keyof T>(event: Extract<K, string>, listener: T[K]): void;
23
- off<K extends keyof T>(event: Extract<K, string>, listener: T[K]): void;
24
- emit<K extends keyof T>(
25
- event: Extract<K, string>,
26
- data: Parameters<any>[1],
27
- ): void;
28
- }
1
+ /*
2
+ * Copyright 2023 Comcast Cable Communications Management, LLC
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ *
15
+ * SPDX-License-Identifier: Apache-2.0
16
+ */
17
+
18
+ export interface IEventEmitter<
19
+ T extends object = { [s: string]: (target: any, data: any) => void },
20
+ > {
21
+ on<K extends keyof T>(event: Extract<K, string>, listener: T[K]): void;
22
+ once<K extends keyof T>(event: Extract<K, string>, listener: T[K]): void;
23
+ off<K extends keyof T>(event: Extract<K, string>, listener: T[K]): void;
24
+ emit<K extends keyof T>(
25
+ event: Extract<K, string>,
26
+ data: Parameters<any>[1],
27
+ ): void;
28
+ }