@lightningjs/renderer 2.15.0 → 2.16.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 (203) hide show
  1. package/dist/exports/canvas-shaders.d.ts +10 -0
  2. package/dist/exports/canvas-shaders.js +27 -0
  3. package/dist/exports/canvas-shaders.js.map +1 -0
  4. package/dist/exports/webgl-shaders.d.ts +11 -0
  5. package/dist/exports/webgl-shaders.js +28 -0
  6. package/dist/exports/webgl-shaders.js.map +1 -0
  7. package/dist/src/core/CoreNode.d.ts +8 -0
  8. package/dist/src/core/CoreNode.js +11 -0
  9. package/dist/src/core/CoreNode.js.map +1 -1
  10. package/dist/src/core/Stage.d.ts +16 -0
  11. package/dist/src/core/Stage.js +39 -1
  12. package/dist/src/core/Stage.js.map +1 -1
  13. package/dist/src/core/lib/utils.d.ts +1 -0
  14. package/dist/src/core/lib/utils.js +3 -0
  15. package/dist/src/core/lib/utils.js.map +1 -1
  16. package/dist/src/core/platforms/Platform.d.ts +37 -0
  17. package/dist/src/core/platforms/Platform.js +22 -0
  18. package/dist/src/core/platforms/Platform.js.map +1 -0
  19. package/dist/src/core/platforms/web/WebPlatform.d.ts +9 -0
  20. package/dist/src/core/platforms/web/WebPlatform.js +58 -0
  21. package/dist/src/core/platforms/web/WebPlatform.js.map +1 -0
  22. package/dist/src/core/renderers/CoreShaderNode.d.ts +59 -0
  23. package/dist/src/core/renderers/CoreShaderNode.js +113 -0
  24. package/dist/src/core/renderers/CoreShaderNode.js.map +1 -0
  25. package/dist/src/core/renderers/CoreShaderProgram.d.ts +4 -0
  26. package/dist/src/core/renderers/CoreShaderProgram.js +20 -0
  27. package/dist/src/core/renderers/CoreShaderProgram.js.map +1 -0
  28. package/dist/src/core/renderers/canvas/CanvasRenderer.d.ts +37 -0
  29. package/dist/src/core/renderers/canvas/CanvasRenderer.js +215 -0
  30. package/dist/src/core/renderers/canvas/CanvasRenderer.js.map +1 -0
  31. package/dist/src/core/renderers/canvas/CanvasShaderNode.d.ts +21 -0
  32. package/dist/src/core/renderers/canvas/CanvasShaderNode.js +57 -0
  33. package/dist/src/core/renderers/canvas/CanvasShaderNode.js.map +1 -0
  34. package/dist/src/core/renderers/canvas/CanvasTexture.d.ts +16 -0
  35. package/dist/src/core/renderers/canvas/CanvasTexture.js +124 -0
  36. package/dist/src/core/renderers/canvas/CanvasTexture.js.map +1 -0
  37. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.d.ts +12 -0
  38. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js +55 -0
  39. package/dist/src/core/renderers/webgl/WebGlCtxRenderTexture.js.map +1 -0
  40. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.d.ts +9 -0
  41. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js +38 -0
  42. package/dist/src/core/renderers/webgl/WebGlCtxSubTexture.js.map +1 -0
  43. package/dist/src/core/renderers/webgl/WebGlCtxTexture.d.ts +57 -0
  44. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js +224 -0
  45. package/dist/src/core/renderers/webgl/WebGlCtxTexture.js.map +1 -0
  46. package/dist/src/core/renderers/webgl/WebGlRenderOp.d.ts +44 -0
  47. package/dist/src/core/renderers/webgl/WebGlRenderOp.js +125 -0
  48. package/dist/src/core/renderers/webgl/WebGlRenderOp.js.map +1 -0
  49. package/dist/src/core/renderers/webgl/WebGlRenderer.d.ts +136 -0
  50. package/dist/src/core/renderers/webgl/WebGlRenderer.js +573 -0
  51. package/dist/src/core/renderers/webgl/WebGlRenderer.js.map +1 -0
  52. package/dist/src/core/renderers/webgl/WebGlShaderNode.d.ts +222 -0
  53. package/dist/src/core/renderers/webgl/WebGlShaderNode.js +331 -0
  54. package/dist/src/core/renderers/webgl/WebGlShaderNode.js.map +1 -0
  55. package/dist/src/core/renderers/webgl/WebGlShaderProgram.d.ts +35 -0
  56. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js +201 -0
  57. package/dist/src/core/renderers/webgl/WebGlShaderProgram.js.map +1 -0
  58. package/dist/src/core/shaders/canvas/Border.d.ts +9 -0
  59. package/dist/src/core/shaders/canvas/Border.js +57 -0
  60. package/dist/src/core/shaders/canvas/Border.js.map +1 -0
  61. package/dist/src/core/shaders/canvas/HolePunch.d.ts +7 -0
  62. package/dist/src/core/shaders/canvas/HolePunch.js +38 -0
  63. package/dist/src/core/shaders/canvas/HolePunch.js.map +1 -0
  64. package/dist/src/core/shaders/canvas/LinearGradient.d.ts +10 -0
  65. package/dist/src/core/shaders/canvas/LinearGradient.js +48 -0
  66. package/dist/src/core/shaders/canvas/LinearGradient.js.map +1 -0
  67. package/dist/src/core/shaders/canvas/RadialGradient.d.ts +11 -0
  68. package/dist/src/core/shaders/canvas/RadialGradient.js +70 -0
  69. package/dist/src/core/shaders/canvas/RadialGradient.js.map +1 -0
  70. package/dist/src/core/shaders/canvas/Rounded.d.ts +7 -0
  71. package/dist/src/core/shaders/canvas/Rounded.js +33 -0
  72. package/dist/src/core/shaders/canvas/Rounded.js.map +1 -0
  73. package/dist/src/core/shaders/canvas/RoundedWithBorder.d.ts +7 -0
  74. package/dist/src/core/shaders/canvas/RoundedWithBorder.js +43 -0
  75. package/dist/src/core/shaders/canvas/RoundedWithBorder.js.map +1 -0
  76. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.d.ts +8 -0
  77. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js +41 -0
  78. package/dist/src/core/shaders/canvas/RoundedWithBorderAndShadow.js.map +1 -0
  79. package/dist/src/core/shaders/canvas/RoundedWithShadow.d.ts +7 -0
  80. package/dist/src/core/shaders/canvas/RoundedWithShadow.js +40 -0
  81. package/dist/src/core/shaders/canvas/RoundedWithShadow.js.map +1 -0
  82. package/dist/src/core/shaders/canvas/Shadow.d.ts +8 -0
  83. package/dist/src/core/shaders/canvas/Shadow.js +31 -0
  84. package/dist/src/core/shaders/canvas/Shadow.js.map +1 -0
  85. package/dist/src/core/shaders/canvas/utils/render.d.ts +5 -0
  86. package/dist/src/core/shaders/canvas/utils/render.js +84 -0
  87. package/dist/src/core/shaders/canvas/utils/render.js.map +1 -0
  88. package/dist/src/core/shaders/templates/BorderTemplate.d.ts +37 -0
  89. package/dist/src/core/shaders/templates/BorderTemplate.js +73 -0
  90. package/dist/src/core/shaders/templates/BorderTemplate.js.map +1 -0
  91. package/dist/src/core/shaders/templates/HolePunchTemplate.d.ts +46 -0
  92. package/dist/src/core/shaders/templates/HolePunchTemplate.js +35 -0
  93. package/dist/src/core/shaders/templates/HolePunchTemplate.js.map +1 -0
  94. package/dist/src/core/shaders/templates/LinearGradientTemplate.d.ts +23 -0
  95. package/dist/src/core/shaders/templates/LinearGradientTemplate.js +47 -0
  96. package/dist/src/core/shaders/templates/LinearGradientTemplate.js.map +1 -0
  97. package/dist/src/core/shaders/templates/RadialGradientTemplate.d.ts +31 -0
  98. package/dist/src/core/shaders/templates/RadialGradientTemplate.js +49 -0
  99. package/dist/src/core/shaders/templates/RadialGradientTemplate.js.map +1 -0
  100. package/dist/src/core/shaders/templates/RoundedTemplate.d.ts +29 -0
  101. package/dist/src/core/shaders/templates/RoundedTemplate.js +67 -0
  102. package/dist/src/core/shaders/templates/RoundedTemplate.js.map +1 -0
  103. package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.d.ts +7 -0
  104. package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js +24 -0
  105. package/dist/src/core/shaders/templates/RoundedWithBorderAndShadowTemplate.js.map +1 -0
  106. package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.d.ts +6 -0
  107. package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js +23 -0
  108. package/dist/src/core/shaders/templates/RoundedWithBorderTemplate.js.map +1 -0
  109. package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.d.ts +6 -0
  110. package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js +23 -0
  111. package/dist/src/core/shaders/templates/RoundedWithShadowTemplate.js.map +1 -0
  112. package/dist/src/core/shaders/templates/ShadowTemplate.d.ts +34 -0
  113. package/dist/src/core/shaders/templates/ShadowTemplate.js +66 -0
  114. package/dist/src/core/shaders/templates/ShadowTemplate.js.map +1 -0
  115. package/dist/src/core/shaders/templates/shaderUtils.d.ts +5 -0
  116. package/dist/src/core/shaders/templates/shaderUtils.js +41 -0
  117. package/dist/src/core/shaders/templates/shaderUtils.js.map +1 -0
  118. package/dist/src/core/shaders/utils.d.ts +5 -0
  119. package/dist/src/core/shaders/utils.js +41 -0
  120. package/dist/src/core/shaders/utils.js.map +1 -0
  121. package/dist/src/core/shaders/webgl/Border.d.ts +3 -0
  122. package/dist/src/core/shaders/webgl/Border.js +110 -0
  123. package/dist/src/core/shaders/webgl/Border.js.map +1 -0
  124. package/dist/src/core/shaders/webgl/Default.d.ts +2 -0
  125. package/dist/src/core/shaders/webgl/Default.js +86 -0
  126. package/dist/src/core/shaders/webgl/Default.js.map +1 -0
  127. package/dist/src/core/shaders/webgl/DefaultBatched.d.ts +2 -0
  128. package/dist/src/core/shaders/webgl/DefaultBatched.js +104 -0
  129. package/dist/src/core/shaders/webgl/DefaultBatched.js.map +1 -0
  130. package/dist/src/core/shaders/webgl/HolePunch.d.ts +3 -0
  131. package/dist/src/core/shaders/webgl/HolePunch.js +65 -0
  132. package/dist/src/core/shaders/webgl/HolePunch.js.map +1 -0
  133. package/dist/src/core/shaders/webgl/LinearGradient.d.ts +3 -0
  134. package/dist/src/core/shaders/webgl/LinearGradient.js +76 -0
  135. package/dist/src/core/shaders/webgl/LinearGradient.js.map +1 -0
  136. package/dist/src/core/shaders/webgl/RadialGradient.d.ts +3 -0
  137. package/dist/src/core/shaders/webgl/RadialGradient.js +74 -0
  138. package/dist/src/core/shaders/webgl/RadialGradient.js.map +1 -0
  139. package/dist/src/core/shaders/webgl/Rounded.d.ts +7 -0
  140. package/dist/src/core/shaders/webgl/Rounded.js +86 -0
  141. package/dist/src/core/shaders/webgl/Rounded.js.map +1 -0
  142. package/dist/src/core/shaders/webgl/RoundedWithBorder.d.ts +3 -0
  143. package/dist/src/core/shaders/webgl/RoundedWithBorder.js +140 -0
  144. package/dist/src/core/shaders/webgl/RoundedWithBorder.js.map +1 -0
  145. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.d.ts +3 -0
  146. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js +162 -0
  147. package/dist/src/core/shaders/webgl/RoundedWithBorderAndShadow.js.map +1 -0
  148. package/dist/src/core/shaders/webgl/RoundedWithShadow.d.ts +3 -0
  149. package/dist/src/core/shaders/webgl/RoundedWithShadow.js +84 -0
  150. package/dist/src/core/shaders/webgl/RoundedWithShadow.js.map +1 -0
  151. package/dist/src/core/shaders/webgl/SdfShader.d.ts +32 -0
  152. package/dist/src/core/shaders/webgl/SdfShader.js +116 -0
  153. package/dist/src/core/shaders/webgl/SdfShader.js.map +1 -0
  154. package/dist/src/core/shaders/webgl/Shadow.d.ts +3 -0
  155. package/dist/src/core/shaders/webgl/Shadow.js +110 -0
  156. package/dist/src/core/shaders/webgl/Shadow.js.map +1 -0
  157. package/dist/src/core/shaders/webgl/Spinner.js +2 -0
  158. package/dist/src/core/shaders/webgl/Spinner.js.map +1 -0
  159. package/dist/src/core/text-rendering/CanvasFontHandler.d.ts +25 -0
  160. package/dist/src/core/text-rendering/CanvasFontHandler.js +117 -0
  161. package/dist/src/core/text-rendering/CanvasFontHandler.js.map +1 -0
  162. package/dist/src/core/text-rendering/CanvasTextRenderer.d.ts +6 -0
  163. package/dist/src/core/text-rendering/CanvasTextRenderer.js +139 -0
  164. package/dist/src/core/text-rendering/CanvasTextRenderer.js.map +1 -0
  165. package/dist/src/core/text-rendering/SdfFontHandler.d.ts +137 -0
  166. package/dist/src/core/text-rendering/SdfFontHandler.js +336 -0
  167. package/dist/src/core/text-rendering/SdfFontHandler.js.map +1 -0
  168. package/dist/src/core/text-rendering/SdfTextRenderer.d.ts +21 -0
  169. package/dist/src/core/text-rendering/SdfTextRenderer.js +324 -0
  170. package/dist/src/core/text-rendering/SdfTextRenderer.js.map +1 -0
  171. package/dist/src/core/text-rendering/TextRenderer.d.ts +425 -0
  172. package/dist/src/core/text-rendering/TextRenderer.js +70 -0
  173. package/dist/src/core/text-rendering/TextRenderer.js.map +1 -0
  174. package/dist/src/core/text-rendering/Utils.d.ts +71 -0
  175. package/dist/src/core/text-rendering/Utils.js +212 -0
  176. package/dist/src/core/text-rendering/Utils.js.map +1 -0
  177. package/dist/src/core/text-rendering/canvas/Settings.d.ts +53 -0
  178. package/dist/src/core/text-rendering/canvas/Settings.js +20 -0
  179. package/dist/src/core/text-rendering/canvas/Settings.js.map +1 -0
  180. package/dist/src/core/text-rendering/canvas/Utils.d.ts +19 -0
  181. package/dist/src/core/text-rendering/canvas/Utils.js +139 -0
  182. package/dist/src/core/text-rendering/canvas/Utils.js.map +1 -0
  183. package/dist/src/core/text-rendering/canvas/calculateRenderInfo.d.ts +37 -0
  184. package/dist/src/core/text-rendering/canvas/calculateRenderInfo.js +188 -0
  185. package/dist/src/core/text-rendering/canvas/calculateRenderInfo.js.map +1 -0
  186. package/dist/src/core/text-rendering/canvas/draw.d.ts +12 -0
  187. package/dist/src/core/text-rendering/canvas/draw.js +133 -0
  188. package/dist/src/core/text-rendering/canvas/draw.js.map +1 -0
  189. package/dist/src/core/text-rendering/sdf/PeekableGenerator.d.ts +12 -0
  190. package/dist/src/core/text-rendering/sdf/PeekableGenerator.js +61 -0
  191. package/dist/src/core/text-rendering/sdf/PeekableGenerator.js.map +1 -0
  192. package/dist/src/core/text-rendering/sdf/SimpleFontShaper.d.ts +45 -0
  193. package/dist/src/core/text-rendering/sdf/SimpleFontShaper.js +69 -0
  194. package/dist/src/core/text-rendering/sdf/SimpleFontShaper.js.map +1 -0
  195. package/dist/src/core/utils.d.ts +1 -1
  196. package/dist/tsconfig.dist.tsbuildinfo +1 -1
  197. package/package.json +2 -1
  198. package/src/core/CoreNode.ts +19 -0
  199. package/src/core/Stage.ts +50 -1
  200. package/src/core/lib/utils.ts +4 -0
  201. package/dist/src/core/renderers/webgl/WebGlCoreShader.destroy.js +0 -2
  202. package/dist/src/core/renderers/webgl/WebGlCoreShader.destroy.js.map +0 -1
  203. /package/dist/src/core/{renderers/webgl/WebGlCoreShader.destroy.d.ts → shaders/webgl/Spinner.d.ts} +0 -0
@@ -0,0 +1,212 @@
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 2025 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
+ * Returns CSS font setting string for use in canvas context.
21
+ *
22
+ * @param fontFace
23
+ * @param fontStyle
24
+ * @param fontSize
25
+ * @param precision
26
+ * @param defaultFontFace
27
+ * @returns
28
+ */
29
+ export function getFontSetting(fontFace, fontStyle, fontSize, precision, defaultFontFace) {
30
+ let ff = fontFace;
31
+ if (!Array.isArray(ff)) {
32
+ ff = [ff];
33
+ }
34
+ const ffs = [];
35
+ for (let i = 0, n = ff.length; i < n; i++) {
36
+ let curFf = ff[i];
37
+ // Replace the default font face `null` with the actual default font face set
38
+ // on the stage.
39
+ if (curFf === null || curFf === undefined) {
40
+ curFf = defaultFontFace;
41
+ }
42
+ if (curFf === 'serif' || curFf === 'sans-serif') {
43
+ ffs.push(curFf);
44
+ }
45
+ else {
46
+ ffs.push(`"${curFf}"`);
47
+ }
48
+ }
49
+ return `${fontStyle} ${fontSize * precision}px ${ffs.join(',')}`;
50
+ }
51
+ /**
52
+ * Returns true if the given character is a zero-width space.
53
+ *
54
+ * @param space
55
+ */
56
+ export function isZeroWidthSpace(space) {
57
+ return space === '' || space === '\u200B';
58
+ }
59
+ /**
60
+ * Returns true if the given character is a zero-width space or a regular space.
61
+ *
62
+ * @param space
63
+ */
64
+ export function isSpace(space) {
65
+ return isZeroWidthSpace(space) || space === ' ';
66
+ }
67
+ /**
68
+ * Converts a string into an array of tokens and the words between them.
69
+ *
70
+ * @param tokenRegex
71
+ * @param text
72
+ */
73
+ export function tokenizeString(tokenRegex, text) {
74
+ const delimeters = text.match(tokenRegex) || [];
75
+ const words = text.split(tokenRegex) || [];
76
+ const final = [];
77
+ for (let i = 0; i < words.length; i++) {
78
+ final.push(words[i], delimeters[i]);
79
+ }
80
+ final.pop();
81
+ return final.filter((word) => word != '');
82
+ }
83
+ /**
84
+ * Measure the width of a string accounting for letter spacing.
85
+ *
86
+ * @param context
87
+ * @param word
88
+ * @param space
89
+ */
90
+ export function measureText(context, word, space = 0) {
91
+ if (!space) {
92
+ return context.measureText(word).width;
93
+ }
94
+ return word.split('').reduce((acc, char) => {
95
+ // Zero-width spaces should not include letter spacing.
96
+ // And since we know the width of a zero-width space is 0, we can skip
97
+ // measuring it.
98
+ if (isZeroWidthSpace(char)) {
99
+ return acc;
100
+ }
101
+ return acc + context.measureText(char).width + space;
102
+ }, 0);
103
+ }
104
+ /**
105
+ * Get the font metrics for a font face.
106
+ *
107
+ * @remarks
108
+ * This function will attempt to grab the explicitly defined metrics from the
109
+ * font face first. If the font face does not have metrics defined, it will
110
+ * attempt to calculate the metrics using the browser's measureText method.
111
+ *
112
+ * If the browser does not support the font metrics API, it will use some
113
+ * default values.
114
+ *
115
+ * @param context
116
+ * @param fontFace
117
+ * @param fontSize
118
+ * @returns
119
+ */
120
+ export function calculateFontMetrics(context, fontFamily, fontSize) {
121
+ // If the font face doesn't have metrics defined, we fallback to using the
122
+ // browser's measureText method to calculate take a best guess at the font
123
+ // actual font's metrics.
124
+ // - fontBoundingBox[Ascent|Descent] is the best estimate but only supported
125
+ // in Chrome 87+ (2020), Firefox 116+ (2023), and Safari 11.1+ (2018).
126
+ // - It is an estimate as it can vary between browsers.
127
+ // - actualBoundingBox[Ascent|Descent] is less accurate and supported in
128
+ // Chrome 77+ (2019), Firefox 74+ (2020), and Safari 11.1+ (2018).
129
+ // - If neither are supported, we'll use some default values which will
130
+ // get text on the screen but likely not be great.
131
+ // NOTE: It's been decided not to rely on fontBoundingBox[Ascent|Descent]
132
+ // as it's browser support is limited and it also tends to produce higher than
133
+ // expected values. It is instead HIGHLY RECOMMENDED that developers provide
134
+ // explicit metrics in the font face definition.
135
+ const browserMetrics = context.measureText('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz');
136
+ console.warn(`Font metrics not provided for Canvas Web font ${fontFamily}. ` +
137
+ 'Using fallback values. It is HIGHLY recommended you use the latest ' +
138
+ 'version of the Lightning 3 `msdf-generator` tool to extract the default ' +
139
+ 'metrics for the font and provide them in the Canvas Web font definition.');
140
+ let metrics;
141
+ if (browserMetrics.actualBoundingBoxDescent &&
142
+ browserMetrics.actualBoundingBoxAscent) {
143
+ metrics = {
144
+ ascender: browserMetrics.actualBoundingBoxAscent / fontSize,
145
+ descender: -browserMetrics.actualBoundingBoxDescent / fontSize,
146
+ lineGap: 0.2,
147
+ };
148
+ }
149
+ else {
150
+ // If the browser doesn't support the font metrics API, we'll use some
151
+ // default values.
152
+ metrics = {
153
+ ascender: 0.8,
154
+ descender: -0.2,
155
+ lineGap: 0.2,
156
+ };
157
+ }
158
+ return metrics;
159
+ }
160
+ /**
161
+ * Applies newlines to a string to have it optimally fit into the horizontal
162
+ * bounds set by the Text object's wordWrapWidth property.
163
+ *
164
+ * @param context
165
+ * @param text
166
+ * @param wordWrapWidth
167
+ * @param letterSpacing
168
+ * @param indent
169
+ */
170
+ export function wrapText(context, text, wordWrapWidth, letterSpacing, indent) {
171
+ // Greedy wrapping algorithm that will wrap words as the line grows longer.
172
+ // than its horizontal bounds.
173
+ const spaceRegex = / |\u200B/g;
174
+ const lines = text.split(/\r?\n/g);
175
+ let allLines = [];
176
+ const realNewlines = [];
177
+ for (let i = 0; i < lines.length; i++) {
178
+ const resultLines = [];
179
+ let result = '';
180
+ let spaceLeft = wordWrapWidth - indent;
181
+ const words = lines[i].split(spaceRegex);
182
+ const spaces = lines[i].match(spaceRegex) || [];
183
+ for (let j = 0; j < words.length; j++) {
184
+ const space = spaces[j - 1] || '';
185
+ const word = words[j];
186
+ const wordWidth = measureText(context, word, letterSpacing);
187
+ const wordWidthWithSpace = wordWidth + measureText(context, space, letterSpacing);
188
+ if (j === 0 || wordWidthWithSpace > spaceLeft) {
189
+ // Skip printing the newline if it's the first word of the line that is.
190
+ // greater than the word wrap width.
191
+ if (j > 0) {
192
+ resultLines.push(result);
193
+ result = '';
194
+ }
195
+ result += word;
196
+ spaceLeft = wordWrapWidth - wordWidth - (j === 0 ? indent : 0);
197
+ }
198
+ else {
199
+ spaceLeft -= wordWidthWithSpace;
200
+ result += space + word;
201
+ }
202
+ }
203
+ resultLines.push(result);
204
+ result = '';
205
+ allLines = allLines.concat(resultLines);
206
+ if (i < lines.length - 1) {
207
+ realNewlines.push(allLines.length);
208
+ }
209
+ }
210
+ return { l: allLines, n: realNewlines };
211
+ }
212
+ //# sourceMappingURL=Utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../src/core/text-rendering/Utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH;;;;;;;;;GASG;AACH,MAAM,UAAU,cAAc,CAC5B,QAA2B,EAC3B,SAAiB,EACjB,QAAgB,EAChB,SAAiB,EACjB,eAAuB;IAEvB,IAAI,EAAE,GAAG,QAAQ,CAAC;IAElB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC;QACvB,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;IACZ,CAAC;IAED,M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CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;IAED,OAAO,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,53 @@
1
+ import type { RGBA } from '../../lib/utils.js';
2
+ import type { TextAlign, TextBaseline, TextFontStyle, TextVerticalAlign, TextWordBreak } from '../TextRenderer.js';
3
+ /**
4
+ * Text Overflow Values
5
+ */
6
+ export type TextOverflow = 'ellipsis' | 'clip' | (string & Record<never, never>);
7
+ /**
8
+ * Text Texture Settings
9
+ */
10
+ export interface Settings {
11
+ w: number;
12
+ h: number;
13
+ text: string;
14
+ fontStyle: TextFontStyle;
15
+ fontSize: number;
16
+ fontBaselineRatio: number;
17
+ fontFamily: string | null;
18
+ wordWrap: boolean;
19
+ wordWrapWidth: number;
20
+ wordBreak: TextWordBreak;
21
+ textOverflow: TextOverflow | null;
22
+ lineHeight: number | null;
23
+ textBaseline: TextBaseline;
24
+ textAlign: TextAlign;
25
+ verticalAlign: TextVerticalAlign;
26
+ offsetY: number | null;
27
+ maxLines: number;
28
+ maxHeight: number | null;
29
+ overflowSuffix: string;
30
+ precision: number;
31
+ textColor: RGBA;
32
+ paddingLeft: number;
33
+ paddingRight: number;
34
+ shadow: boolean;
35
+ shadowColor: RGBA;
36
+ shadowOffsetX: number;
37
+ shadowOffsetY: number;
38
+ shadowBlur: number;
39
+ highlight: boolean;
40
+ highlightHeight: number;
41
+ highlightColor: RGBA;
42
+ highlightOffset: number;
43
+ highlightPaddingLeft: number;
44
+ highlightPaddingRight: number;
45
+ letterSpacing: number;
46
+ textIndent: number;
47
+ cutSx: number;
48
+ cutSy: number;
49
+ cutEx: number;
50
+ cutEy: number;
51
+ advancedRenderer: boolean;
52
+ textRenderIssueMargin: number;
53
+ }
@@ -0,0 +1,20 @@
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 2025 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
+ export {};
20
+ //# sourceMappingURL=Settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Settings.js","sourceRoot":"","sources":["../../../../../src/core/text-rendering/canvas/Settings.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG"}
@@ -0,0 +1,19 @@
1
+ import { TextBaseline, type NormalizedFontMetrics } from '../TextRenderer.js';
2
+ export declare const measureText: (context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, word: string, space?: number) => number;
3
+ export declare const wrapWord: (context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, word: string, wordWrapWidth: number, suffix: string, letterSpacing: number) => string;
4
+ export declare const wrapText: (context: CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D, text: string, wordWrapWidth: number, letterSpacing: number, indent: number) => {
5
+ l: string[];
6
+ n: number[];
7
+ };
8
+ export declare const isNormalizedFontMetrics: (obj: unknown) => obj is NormalizedFontMetrics;
9
+ /**
10
+ * Calculate height for the canvas
11
+ *
12
+ * @param textBaseline
13
+ * @param fontSize
14
+ * @param lineHeight
15
+ * @param numLines
16
+ * @param offsetY
17
+ * @returns
18
+ */
19
+ export declare const calcHeight: (textBaseline: TextBaseline, fontSize: number, lineHeight: number, numLines: number, offsetY: number | null) => number;
@@ -0,0 +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 2025 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 { TextBaseline } from '../TextRenderer.js';
20
+ import { isZeroWidthSpace } from '../Utils.js';
21
+ export const measureText = (context, word, space = 0) => {
22
+ if (space === 0) {
23
+ return context.measureText(word).width;
24
+ }
25
+ return word.split('').reduce((acc, char) => {
26
+ if (isZeroWidthSpace(char) === true) {
27
+ return acc;
28
+ }
29
+ return acc + context.measureText(char).width + space;
30
+ }, 0);
31
+ };
32
+ // Helper functions
33
+ export const wrapWord = (context, word, wordWrapWidth, suffix, letterSpacing) => {
34
+ const suffixWidth = measureText(context, suffix, letterSpacing);
35
+ const wordLen = word.length;
36
+ const wordWidth = measureText(context, word, letterSpacing);
37
+ if (wordWidth <= wordWrapWidth) {
38
+ return word;
39
+ }
40
+ let cutoffIndex = Math.floor((wordWrapWidth * wordLen) / wordWidth);
41
+ let truncWordWidth = measureText(context, word.substring(0, cutoffIndex), letterSpacing) +
42
+ suffixWidth;
43
+ if (truncWordWidth > wordWrapWidth) {
44
+ while (cutoffIndex > 0) {
45
+ truncWordWidth =
46
+ measureText(context, word.substring(0, cutoffIndex), letterSpacing) +
47
+ suffixWidth;
48
+ if (truncWordWidth > wordWrapWidth) {
49
+ cutoffIndex -= 1;
50
+ }
51
+ else {
52
+ break;
53
+ }
54
+ }
55
+ }
56
+ else {
57
+ while (cutoffIndex < wordLen) {
58
+ truncWordWidth =
59
+ measureText(context, word.substring(0, cutoffIndex), letterSpacing) +
60
+ suffixWidth;
61
+ if (truncWordWidth < wordWrapWidth) {
62
+ cutoffIndex += 1;
63
+ }
64
+ else {
65
+ cutoffIndex -= 1;
66
+ break;
67
+ }
68
+ }
69
+ }
70
+ return (word.substring(0, cutoffIndex) +
71
+ (wordWrapWidth >= suffixWidth ? suffix : ''));
72
+ };
73
+ export const wrapText = (context, text, wordWrapWidth, letterSpacing, indent) => {
74
+ const spaceRegex = / |\u200B/g;
75
+ const lines = text.split(/\r?\n/g);
76
+ let allLines = [];
77
+ const realNewlines = [];
78
+ for (let i = 0; i < lines.length; i++) {
79
+ const resultLines = [];
80
+ let result = '';
81
+ let spaceLeft = wordWrapWidth - indent;
82
+ const line = lines[i] ?? '';
83
+ const words = line.split(spaceRegex);
84
+ const spaces = line.match(spaceRegex) || [];
85
+ for (let j = 0; j < words.length; j++) {
86
+ const space = spaces[j - 1] || '';
87
+ const word = words[j] || '';
88
+ const wordWidth = measureText(context, word, letterSpacing);
89
+ const wordWidthWithSpace = wordWidth + measureText(context, space, letterSpacing);
90
+ if (j === 0 || wordWidthWithSpace > spaceLeft) {
91
+ if (j > 0) {
92
+ resultLines.push(result);
93
+ result = '';
94
+ }
95
+ result += word;
96
+ spaceLeft = wordWrapWidth - wordWidth - (j === 0 ? indent : 0);
97
+ }
98
+ else {
99
+ spaceLeft -= wordWidthWithSpace;
100
+ result += space + word;
101
+ }
102
+ }
103
+ resultLines.push(result);
104
+ result = '';
105
+ allLines = allLines.concat(resultLines);
106
+ if (i < lines.length - 1) {
107
+ realNewlines.push(allLines.length);
108
+ }
109
+ }
110
+ return { l: allLines, n: realNewlines };
111
+ };
112
+ export const isNormalizedFontMetrics = (obj) => {
113
+ return (typeof obj === 'object' &&
114
+ obj !== null &&
115
+ 'ascender' in obj &&
116
+ typeof obj.ascender === 'number' &&
117
+ 'descender' in obj &&
118
+ typeof obj.descender === 'number' &&
119
+ 'lineGap' in obj &&
120
+ typeof obj.lineGap === 'number');
121
+ };
122
+ /**
123
+ * Calculate height for the canvas
124
+ *
125
+ * @param textBaseline
126
+ * @param fontSize
127
+ * @param lineHeight
128
+ * @param numLines
129
+ * @param offsetY
130
+ * @returns
131
+ */
132
+ export const calcHeight = (textBaseline, fontSize, lineHeight, numLines, offsetY) => {
133
+ const baselineOffset = textBaseline !== TextBaseline.bottom ? 0.5 * fontSize : 0;
134
+ return (lineHeight * (numLines - 1) +
135
+ baselineOffset +
136
+ Math.max(lineHeight, fontSize) +
137
+ (offsetY || 0));
138
+ };
139
+ //# sourceMappingURL=Utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Utils.js","sourceRoot":"","sources":["../../../../../src/core/text-rendering/canvas/Utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,YAAY,EAA8B,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,OAAqE,EACrE,IAAY,EACZ,KAAK,GAAG,CAAC,EACT,EAAE;IACF,IAAI,KAAK,KAAK,CAAC,EAAE,CAAC;QAChB,OAAO,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC;IACzC,CAAC;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QACzC,IAAI,gBAAgB,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YACpC,OAAO,GAAG,CAAC;QACb,CAAC;QACD,OAAO,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC;IACvD,CAAC,EAAE,CAAC,CAAC,CAAC;AACR,CAAC,CAAC;AAEF,mBAAmB;AACnB,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,OAAqE,EACrE,IAAY,EACZ,aAAqB,EACrB,MAAc,EACd,aAAqB,EACrB,EAAE;IACF,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S,IAAI,GAAG;QAChB,OAAQ,GAA4B,CAAC,OAAO,KAAK,QAAQ,CAC1D,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,YAA0B,EAC1B,QAAgB,EAChB,UAAkB,EAClB,QAAgB,EAChB,OAAsB,EACtB,EAAE;IACF,MAAM,cAAc,GAAG,YAAY,KAAK,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACjF,OAAO,CACL,UAAU,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC;QAC3B,cAAc;QACd,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC;QAC9B,CAAC,OAAO,IAAI,CAAC,CAAC,CACf,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { type NormalizedFontMetrics } from '../TextRenderer.js';
2
+ import type { Settings } from './Settings.js';
3
+ export interface RenderInfo {
4
+ w: number;
5
+ h: number;
6
+ lines: string[];
7
+ precision: number;
8
+ remainingText: string;
9
+ moreTextLines: boolean;
10
+ width: number;
11
+ innerWidth: number;
12
+ height: number;
13
+ fontSize: number;
14
+ cutSx: number;
15
+ cutSy: number;
16
+ cutEx: number;
17
+ cutEy: number;
18
+ lineHeight: number;
19
+ defLineHeight: number;
20
+ lineWidths: number[];
21
+ offsetY: number;
22
+ paddingLeft: number;
23
+ paddingRight: number;
24
+ letterSpacing: number;
25
+ textIndent: number;
26
+ metrics: NormalizedFontMetrics;
27
+ }
28
+ export interface LineType {
29
+ text: string;
30
+ x: number;
31
+ y: number;
32
+ w: number;
33
+ }
34
+ export declare function calculateRenderInfo({ context, settings, }: {
35
+ context: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D;
36
+ settings: Settings;
37
+ }): RenderInfo;