@lightningtv/solid 3.0.7-1 → 3.0.7

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 (34) hide show
  1. package/dist/src/core/intrinsicTypes.d.ts +3 -0
  2. package/dist/src/core/shaders.js +2 -272
  3. package/dist/src/core/shaders.js.map +1 -1
  4. package/dist/src/primitives/borderBox.jsx +10 -7
  5. package/dist/src/primitives/borderBox.jsx.map +1 -1
  6. package/dist/tsconfig.tsbuildinfo +1 -1
  7. package/package.json +3 -3
  8. package/src/core/intrinsicTypes.ts +3 -0
  9. package/src/core/shaders.ts +4 -291
  10. package/src/primitives/borderBox.tsx +10 -7
  11. package/dist/src/shaders/Rounded.d.ts +0 -7
  12. package/dist/src/shaders/Rounded.js +0 -88
  13. package/dist/src/shaders/Rounded.js.map +0 -1
  14. package/dist/src/shaders/RoundedWithBorder.d.ts +0 -3
  15. package/dist/src/shaders/RoundedWithBorder.js +0 -217
  16. package/dist/src/shaders/RoundedWithBorder.js.map +0 -1
  17. package/dist/src/shaders/index.d.ts +0 -4
  18. package/dist/src/shaders/index.js +0 -5
  19. package/dist/src/shaders/index.js.map +0 -1
  20. package/dist/src/shaders/templates/RoundedTemplate.d.ts +0 -12
  21. package/dist/src/shaders/templates/RoundedTemplate.js +0 -48
  22. package/dist/src/shaders/templates/RoundedTemplate.js.map +0 -1
  23. package/dist/src/shaders/templates/RoundedWithBorderTemplate.d.ts +0 -20
  24. package/dist/src/shaders/templates/RoundedWithBorderTemplate.js +0 -93
  25. package/dist/src/shaders/templates/RoundedWithBorderTemplate.js.map +0 -1
  26. package/dist/src/shaders/utils.d.ts +0 -3
  27. package/dist/src/shaders/utils.js +0 -31
  28. package/dist/src/shaders/utils.js.map +0 -1
  29. package/src/shaders/Rounded.ts +0 -100
  30. package/src/shaders/RoundedWithBorder.ts +0 -245
  31. package/src/shaders/index.ts +0 -4
  32. package/src/shaders/templates/RoundedTemplate.ts +0 -57
  33. package/src/shaders/templates/RoundedWithBorderTemplate.ts +0 -110
  34. package/src/shaders/utils.ts +0 -44
@@ -73,6 +73,9 @@ export const defaultShaderRadialGradient: ShaderRadialGradient =
73
73
  export const defaultShaderLinearGradient: ShaderLinearGradient =
74
74
  lngr_shaders.LinearGradient;
75
75
 
76
+ export const defaultShaderRoundedWithBorder =
77
+ lngr_shaders.RoundedWithBorder as ShaderRoundedWithBorder;
78
+
76
79
  function calcFactoredRadiusArray(
77
80
  radius: Vec4,
78
81
  width: number,
@@ -123,6 +126,7 @@ const roundedWithBorderProps: lngr.ShaderProps<ShaderRoundedWithBorderProps> = {
123
126
  return toValidVec4(value);
124
127
  },
125
128
  },
129
+ 'border-align': 0,
126
130
  'top-left': {
127
131
  default: 0,
128
132
  set(value, props) {
@@ -206,297 +210,6 @@ const roundedWithBorderProps: lngr.ShaderProps<ShaderRoundedWithBorderProps> = {
206
210
  'border-inset': true,
207
211
  };
208
212
 
209
- export const defaultShaderRoundedWithBorder: ShaderRoundedWithBorder = {
210
- props: roundedWithBorderProps,
211
- canBatch: () => false,
212
- update(node) {
213
- let props = this.props!;
214
- let borderWidth = props['border-w'] as Vec4;
215
- let borderGap = props['border-gap'];
216
- let inset = props['border-inset'];
217
-
218
- let [b_t, b_r, b_b, b_l] = borderWidth;
219
-
220
- this.uniformRGBA('u_borderColor', props['border-color']);
221
- this.uniform4fa('u_border', borderWidth);
222
- this.uniform1f('u_gap', borderGap);
223
- this.uniform1i('u_inset', inset ? 1 : 0);
224
-
225
- // Check if border is zero (no border widths)
226
- let borderZero = b_t === 0 && b_r === 0 && b_b === 0 && b_l === 0;
227
- this.uniform1i('u_borderZero', borderZero ? 1 : 0);
228
-
229
- let origWidth = node.w;
230
- let origHeight = node.h;
231
- this.uniform2f('u_dimensions_orig', origWidth, origHeight);
232
-
233
- let finalWidth = origWidth;
234
- let finalHeight = origHeight;
235
- if (!inset) {
236
- // For outside borders, expand dimensions
237
- finalWidth = origWidth + b_l + b_r + borderGap * 2;
238
- finalHeight = origHeight + b_t + b_b + borderGap * 2;
239
- }
240
-
241
- // u_dimensions for the shader's SDF functions
242
- this.uniform2f('u_dimensions', finalWidth, finalHeight);
243
-
244
- // The `radius` property is for the content rectangle.
245
- // Factor it against the appropriate dimensions to prevent self-intersection.
246
- let contentRadius = calcFactoredRadiusArray(
247
- props.radius as Vec4,
248
- origWidth,
249
- origHeight,
250
- );
251
-
252
- // Calculate the appropriate radius for the shader based on inset mode
253
- let finalRadius = contentRadius;
254
- if (!inset) {
255
- // For each corner, the total radius is content radius + gap + border thickness.
256
- // Border thickness at a corner is approximated as the max of the two adjacent border sides.
257
- let outerRadius: Vec4 = [
258
- contentRadius[0] + borderGap + Math.max(b_t, b_l), // top-left
259
- contentRadius[1] + borderGap + Math.max(b_t, b_r), // top-right
260
- contentRadius[2] + borderGap + Math.max(b_b, b_r), // bottom-right
261
- contentRadius[3] + borderGap + Math.max(b_b, b_l), // bottom-left
262
- ];
263
- calcFactoredRadiusArray(
264
- outerRadius,
265
- finalWidth,
266
- finalHeight,
267
- finalRadius,
268
- );
269
- }
270
-
271
- this.uniform4fa('u_radius', finalRadius);
272
- },
273
- vertex: /*glsl*/ `
274
- # ifdef GL_FRAGMENT_PRECISION_HIGH
275
- precision highp float;
276
- # else
277
- precision mediump float;
278
- # endif
279
-
280
- /* Passed by lightning renderer */
281
- attribute vec2 a_position;
282
- attribute vec2 a_textureCoords;
283
- attribute vec4 a_color;
284
- attribute vec2 a_nodeCoords;
285
-
286
- uniform vec2 u_resolution;
287
- uniform float u_pixelRatio;
288
-
289
- /* Passed by shader setup */
290
- uniform vec2 u_dimensions;
291
- uniform vec2 u_dimensions_orig;
292
- uniform vec4 u_radius;
293
- uniform vec4 u_border;
294
- uniform float u_gap;
295
- uniform bool u_inset;
296
- uniform bool u_borderZero;
297
-
298
- varying vec4 v_color;
299
- varying vec2 v_texcoords;
300
- varying vec2 v_nodeCoords;
301
- varying vec4 v_borderEndRadius;
302
- varying vec2 v_borderEndSize;
303
-
304
- varying vec4 v_innerRadius;
305
- varying vec2 v_innerSize;
306
- varying vec2 v_halfDimensions;
307
-
308
- void main() {
309
- vec2 screen_space = vec2(2.0 / u_resolution.x, -2.0 / u_resolution.y);
310
-
311
- v_color = a_color;
312
- v_nodeCoords = a_nodeCoords;
313
-
314
- float b_t = u_border.x;
315
- float b_r = u_border.y;
316
- float b_b = u_border.z;
317
- float b_l = u_border.w;
318
-
319
- // Calculate the offset to expand/contract the quad for border and gap
320
- vec2 expansion_offset = vec2(0.0);
321
- if (!u_inset) {
322
- // Outside border: expand the quad
323
- if (a_nodeCoords.x == 0.0) { // Left edge vertex
324
- expansion_offset.x = -(b_l + u_gap);
325
- } else { // Right edge vertex (a_nodeCoords.x == 1.0)
326
- expansion_offset.x = (b_r + u_gap);
327
- }
328
- if (a_nodeCoords.y == 0.0) { // Top edge vertex
329
- expansion_offset.y = -(b_t + u_gap);
330
- } else { // Bottom edge vertex (a_nodeCoords.y == 1.0)
331
- expansion_offset.y = (b_b + u_gap);
332
- }
333
- }
334
- // For inset borders, no expansion needed - use original position
335
-
336
- // Texture coordinate calculation
337
- v_texcoords = a_textureCoords;
338
- if (!u_inset) { // For outside borders, adjust texture coordinates for expansion
339
- v_texcoords *= u_dimensions;
340
- v_texcoords.x -= b_l + u_gap;
341
- v_texcoords.y -= b_t + u_gap;
342
- v_texcoords /= u_dimensions_orig;
343
- }
344
-
345
- v_halfDimensions = u_dimensions * 0.5;
346
- if (!u_borderZero) {
347
-
348
- float gap_x2 = u_gap * 2.0;
349
-
350
- if (u_inset) {
351
- // For inset borders, flip the meaning:
352
- // v_borderEndRadius/Size represents the gap area
353
- // v_innerRadius/Size represents the border area
354
-
355
- // Gap area (v_borderEnd represents gap boundary) - uniform gap
356
- v_borderEndRadius = u_radius - u_gap - 0.5;
357
- v_borderEndSize = (u_dimensions - gap_x2 - 1.0) * 0.5;
358
-
359
- // Border area (v_inner represents border boundary) - individual border widths
360
- v_innerRadius.x = u_radius.x - u_gap - max(b_t, b_l) - 0.5;
361
- v_innerRadius.y = u_radius.y - u_gap - max(b_t, b_r) - 0.5;
362
- v_innerRadius.z = u_radius.z - u_gap - max(b_b, b_r) - 0.5;
363
- v_innerRadius.w = u_radius.w - u_gap - max(b_b, b_l) - 0.5;
364
-
365
- v_innerSize = (u_dimensions - gap_x2 - vec2(b_l + b_r, b_t + b_b) - 1.0) * 0.5;
366
- } else {
367
- // For outside borders, calculate from expanded dimensions inward
368
- v_borderEndRadius.x = u_radius.x - max(b_t, b_l) - 0.5;
369
- v_borderEndRadius.y = u_radius.y - max(b_t, b_r) - 0.5;
370
- v_borderEndRadius.z = u_radius.z - max(b_b, b_r) - 0.5;
371
- v_borderEndRadius.w = u_radius.w - max(b_b, b_l) - 0.5;
372
-
373
- v_borderEndSize = (u_dimensions - vec2(b_l + b_r, b_t + b_b) - 1.0) * 0.5;
374
-
375
- v_innerRadius.x = u_radius.x - max(b_t, b_l) - u_gap - 0.5;
376
- v_innerRadius.y = u_radius.y - max(b_t, b_r) - u_gap - 0.5;
377
- v_innerRadius.z = u_radius.z - max(b_b, b_r) - u_gap - 0.5;
378
- v_innerRadius.w = u_radius.w - max(b_b, b_l) - u_gap - 0.5;
379
-
380
- v_innerSize.x = u_dimensions.x - (b_l + b_r) - gap_x2 - 1.0;
381
- v_innerSize.y = u_dimensions.y - (b_t + b_b) - gap_x2 - 1.0;
382
- v_innerSize *= 0.5;
383
- }
384
-
385
- v_borderEndRadius = max(v_borderEndRadius, vec4(0.0));
386
- v_innerRadius = max(v_innerRadius, vec4(0.0));
387
- }
388
-
389
- vec2 normalized = (a_position + expansion_offset) * u_pixelRatio;
390
-
391
- gl_Position = vec4(normalized.x * screen_space.x - 1.0, normalized.y * -abs(screen_space.y) + 1.0, 0.0, 1.0);
392
- gl_Position.y = -sign(screen_space.y) * gl_Position.y;
393
- }
394
- `,
395
- fragment: /*glsl*/ `
396
- # ifdef GL_FRAGMENT_PRECISION_HIGH
397
- precision highp float;
398
- # else
399
- precision mediump float;
400
- # endif
401
-
402
- /* Passed by lightning renderer */
403
- uniform vec2 u_resolution;
404
- uniform float u_pixelRatio;
405
- uniform float u_alpha;
406
- uniform vec2 u_dimensions;
407
- uniform sampler2D u_texture;
408
-
409
- /* Passed by shader setup */
410
- uniform vec4 u_radius;
411
-
412
- uniform vec4 u_border;
413
- uniform vec4 u_borderColor;
414
- uniform bool u_inset;
415
- uniform bool u_borderZero;
416
-
417
- varying vec4 v_borderEndRadius;
418
- varying vec2 v_borderEndSize;
419
-
420
- varying vec4 v_color;
421
- varying vec2 v_texcoords;
422
- varying vec2 v_nodeCoords;
423
-
424
- varying vec2 v_halfDimensions;
425
- varying vec4 v_innerRadius;
426
- varying vec2 v_innerSize;
427
-
428
- float roundedBox(vec2 p, vec2 s, vec4 r) {
429
- r.xy = (p.x > 0.0) ? r.yz : r.xw;
430
- r.x = (p.y > 0.0) ? r.y : r.x;
431
- vec2 q = abs(p) - s + r.x;
432
- return (min(max(q.x, q.y), 0.0) + length(max(q, 0.0))) - r.x;
433
- }
434
-
435
- void main() {
436
- vec4 contentTexColor = texture2D(u_texture, v_texcoords) * v_color;
437
-
438
- vec2 boxUv = v_nodeCoords.xy * u_dimensions - v_halfDimensions;
439
- float outerShapeDist = roundedBox(boxUv, v_halfDimensions, u_radius);
440
- float outerShapeAlpha = 1.0 - smoothstep(0.0, 1.0, outerShapeDist); // 1 inside, 0 outside
441
-
442
- if (u_borderZero) { // No border, effectively no gap from border logic
443
- gl_FragColor = mix(vec4(0.0), contentTexColor, outerShapeAlpha) * u_alpha;
444
- return;
445
- }
446
-
447
- // Adjust boxUv for non-uniform borders
448
- // This adjusted UV is used for calculating distances to border-end and content shapes
449
- vec2 adjustedBoxUv = boxUv;
450
- vec2 borderAdjustedBoxUv = boxUv;
451
-
452
- if (!u_inset) {
453
- // For outside borders, use same adjustment for both calculations
454
- adjustedBoxUv.x += (u_border.y - u_border.w) * 0.5;
455
- adjustedBoxUv.y += (u_border.z - u_border.x) * 0.5;
456
- borderAdjustedBoxUv = adjustedBoxUv;
457
- } else {
458
- // For inset borders, gap calculation uses no adjustment (uniform gap)
459
- // Border calculation uses adjustment (non-uniform border)
460
- borderAdjustedBoxUv.x += (u_border.y - u_border.w) * 0.5;
461
- borderAdjustedBoxUv.y += (u_border.z - u_border.x) * 0.5;
462
- }
463
-
464
- // Distance to the inner edge of the border (where the gap begins)
465
- float borderEndDist = roundedBox(adjustedBoxUv, v_borderEndSize, v_borderEndRadius);
466
- float borderEndAlpha = 1.0 - smoothstep(0.0, 1.0, borderEndDist); // 1 if inside gap or content, 0 if in border or outside
467
-
468
- // Distance to the content area (after the gap)
469
- float contentDist = roundedBox(borderAdjustedBoxUv, v_innerSize, v_innerRadius);
470
- float contentAlpha = 1.0 - smoothstep(0.0, 1.0, contentDist); // 1 if inside content, 0 if in gap, border or outside
471
-
472
- vec4 finalColor;
473
- if (u_inset) { // For inset borders: border <- gap <- element
474
- // flip the logic: borderEndAlpha becomes gap, contentAlpha becomes border+content
475
- if (contentAlpha > 0.0) { // Pixel is inside the content area (innermost)
476
- finalColor = contentTexColor;
477
- } else if (borderEndAlpha > 0.0) { // Pixel is inside the border area (middle)
478
- vec4 borderColor = u_borderColor;
479
- finalColor = mix(contentTexColor, vec4(borderColor.rgb, 1.0), borderColor.a);
480
- } else { // Pixel is in the gap area (outermost) - show content through gap
481
- finalColor = contentTexColor;
482
- }
483
- } else { // For outside borders: element -> gap -> border
484
- if (contentAlpha > 0.0) { // Pixel is inside the content area
485
- finalColor = contentTexColor;
486
- } else if (borderEndAlpha > 0.0) { // Pixel is inside the gap area
487
- finalColor = vec4(0.0); // Transparent gap
488
- } else { // Pixel is inside the border area
489
- vec4 borderColor = u_borderColor;
490
- finalColor = borderColor;
491
- finalColor.rgb *= finalColor.a;
492
- }
493
- }
494
-
495
- gl_FragColor = mix(vec4(0.0), finalColor, outerShapeAlpha) * u_alpha;
496
- }
497
- `,
498
- };
499
-
500
213
  export function registerDefaultShaderRounded(
501
214
  shManager: IRendererShaderManager,
502
215
  ) {
@@ -5,7 +5,6 @@ import {
5
5
  type NodeStyles,
6
6
  } from '@lightningtv/solid';
7
7
  import { getOwner, runWithOwner, type Accessor } from 'solid-js';
8
- import { fadeIn, fadeOut } from './FadeInOut.jsx';
9
8
  import { chainFunctions } from '@lightningtv/solid/primitives';
10
9
 
11
10
  export const BorderBoxStyle: NodeStyles = {
@@ -13,23 +12,27 @@ export const BorderBoxStyle: NodeStyles = {
13
12
  borderSpace: 6,
14
13
  borderRadius: 20,
15
14
  border: { color: 0xffffff, width: 2 },
16
- scale: 1,
15
+ transition: { alpha: { duration: 100, easing: 'linear' } },
17
16
  };
18
17
 
19
18
  type BorderProps = NodeProps & { borderSpace?: number };
20
19
  const borderComponent = (props: BorderProps) => {
21
20
  const space = props.borderSpace ?? (BorderBoxStyle.borderSpace as number);
22
- const scale = props.scale ?? (BorderBoxStyle.scale as number);
23
21
  return (
24
22
  <view
25
23
  skipFocus
26
24
  onCreate={(el) => {
27
25
  const parent = el.parent!;
28
- el.width = parent.width * scale + space * 2;
29
- el.height = parent.height * scale + space * 2;
30
- fadeIn(el);
26
+ el.width = parent.width + space * 2;
27
+ el.height = parent.height + space * 2;
28
+ el.alpha = 1;
29
+ }}
30
+ onDestroy={(el) => {
31
+ return el
32
+ .animate({ alpha: 0 }, el.transition as any)
33
+ .start()
34
+ .waitUntilStopped();
31
35
  }}
32
- onDestroy={fadeOut}
33
36
  style={BorderBoxStyle}
34
37
  x={-space}
35
38
  y={-space}
@@ -1,7 +0,0 @@
1
- import type { WebGlShaderType } from '@lightningjs/renderer/webgl';
2
- import { type RoundedProps } from './templates/RoundedTemplate.js';
3
- /**
4
- * Similar to the {@link DefaultShader} but cuts out 4 rounded rectangle corners
5
- * as defined by the specified corner {@link RoundedProps.radius}
6
- */
7
- export declare const Rounded: WebGlShaderType<RoundedProps>;
@@ -1,88 +0,0 @@
1
- import { calcFactoredRadiusArray } from './utils.js';
2
- import { RoundedTemplate, } from './templates/RoundedTemplate.js';
3
- /**
4
- * Similar to the {@link DefaultShader} but cuts out 4 rounded rectangle corners
5
- * as defined by the specified corner {@link RoundedProps.radius}
6
- */
7
- export const Rounded = {
8
- props: RoundedTemplate.props,
9
- update(node) {
10
- this.uniform4fa('u_radius', calcFactoredRadiusArray(this.props.radius, node.w, node.h));
11
- },
12
- vertex: `
13
- # ifdef GL_FRAGMENT_PRECISION_HIGH
14
- precision highp float;
15
- # else
16
- precision mediump float;
17
- # endif
18
-
19
- attribute vec2 a_position;
20
- attribute vec2 a_textureCoords;
21
- attribute vec4 a_color;
22
- attribute vec2 a_nodeCoords;
23
-
24
- uniform vec2 u_resolution;
25
- uniform float u_pixelRatio;
26
-
27
- varying vec4 v_color;
28
- varying vec2 v_textureCoords;
29
- varying vec2 v_nodeCoords;
30
-
31
- void main() {
32
- vec2 normalized = a_position * u_pixelRatio;
33
- vec2 screenSpace = vec2(2.0 / u_resolution.x, -2.0 / u_resolution.y);
34
-
35
- v_color = a_color;
36
- v_nodeCoords = a_nodeCoords;
37
- v_textureCoords = a_textureCoords;
38
-
39
- gl_Position = vec4(
40
- normalized.x * screenSpace.x - 1.0,
41
- normalized.y * -abs(screenSpace.y) + 1.0,
42
- 0.0,
43
- 1.0
44
- );
45
- }
46
- `,
47
- fragment: `
48
- # ifdef GL_FRAGMENT_PRECISION_HIGH
49
- precision highp float;
50
- # else
51
- precision mediump float;
52
- # endif
53
-
54
- uniform vec2 u_dimensions;
55
- uniform float u_alpha;
56
- uniform float u_pixelRatio;
57
- uniform sampler2D u_texture;
58
- uniform vec4 u_radius;
59
-
60
- varying vec4 v_color;
61
- varying vec2 v_textureCoords;
62
- varying vec2 v_nodeCoords;
63
-
64
- void main() {
65
- vec2 halfDimensions = u_dimensions * 0.5;
66
- vec2 boxUv = v_nodeCoords * u_dimensions - halfDimensions;
67
-
68
- // Branchless radius selection based on quadrant
69
- // x: TL, y: TR, z: BR, w: BL
70
- vec2 stepVal = step(vec2(0.0), boxUv);
71
- float r = mix(
72
- mix(u_radius.x, u_radius.y, stepVal.x),
73
- mix(u_radius.w, u_radius.z, stepVal.x),
74
- stepVal.y
75
- );
76
-
77
- vec2 q = abs(boxUv) - halfDimensions + r;
78
- float d = min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r;
79
-
80
- float edgeWidth = 1.0 / u_pixelRatio;
81
- float alpha = 1.0 - smoothstep(-0.5 * edgeWidth, 0.5 * edgeWidth, d);
82
-
83
- vec4 color = texture2D(u_texture, v_textureCoords) * v_color;
84
- gl_FragColor = color * alpha * u_alpha;
85
- }
86
- `,
87
- };
88
- //# sourceMappingURL=Rounded.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Rounded.js","sourceRoot":"","sources":["../../../src/shaders/Rounded.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAa,MAAM,YAAY,CAAC;AAChE,OAAO,EACL,eAAe,GAEhB,MAAM,gCAAgC,CAAC;AAOxC;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAkC;IACpD,KAAK,EAAE,eAAe,CAAC,KAAK;IAC5B,MAAM,CAAC,IAAc;QACnB,IAAI,CAAC,UAAU,CACb,UAAU,EACV,uBAAuB,CAAC,IAAI,CAAC,KAAM,CAAC,MAAc,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CACpE,CAAC;IACJ,CAAC;IACD,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCT;IACC,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCT;CACF,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { WebGlShaderType } from '@lightningjs/renderer/webgl';
2
- import { type RoundedWithBorderProps } from './templates/RoundedWithBorderTemplate.js';
3
- export declare const RoundedWithBorder: WebGlShaderType<RoundedWithBorderProps>;
@@ -1,217 +0,0 @@
1
- import { calcFactoredRadiusArray } from './utils.js';
2
- import { RoundedWithBorderTemplate, } from './templates/RoundedWithBorderTemplate.js';
3
- export const RoundedWithBorder = {
4
- props: RoundedWithBorderTemplate.props,
5
- update(node) {
6
- const props = this.props;
7
- const borderWidth = props['border-w'];
8
- const borderGap = props['border-gap'] || 0;
9
- this.uniformRGBA('u_borderColor', props['border-color']);
10
- this.uniform4fa('u_borderWidth', borderWidth);
11
- this.uniform1f('u_borderGap', borderGap);
12
- this.uniformRGBA('u_borderGapColor', props['border-gapColor']);
13
- const origWidth = node.w;
14
- const origHeight = node.h;
15
- this.uniform2f('u_dimensions_orig', origWidth, origHeight);
16
- const expandedWidth = origWidth + borderWidth[3] + borderWidth[1] + borderGap * 2; // original + left + right + 2*gap
17
- const expandedHeight = origHeight + borderWidth[0] + borderWidth[2] + borderGap * 2; // original + top + bottom + 2*gap
18
- // u_dimensions for the shader's SDF functions should be the expanded size
19
- this.uniform2f('u_dimensions', expandedWidth, expandedHeight);
20
- // The `radius` property is for the content rectangle.
21
- // Factor it against the original dimensions to prevent self-intersection.
22
- const contentRadius = calcFactoredRadiusArray(this.props.radius, origWidth, origHeight);
23
- // From the content radius, calculate the outer radius of the border.
24
- // For each corner, the total radius is content radius + gap + border thickness.
25
- // Border thickness at a corner is approximated as the max of the two adjacent border sides.
26
- const bTop = borderWidth[0], bRight = borderWidth[1], bBottom = borderWidth[2], bLeft = borderWidth[3];
27
- const outerRadius = [
28
- Math.max(0, contentRadius[0] + borderGap + Math.max(bTop, bLeft)), // top-left
29
- Math.max(0, contentRadius[1] + borderGap + Math.max(bTop, bRight)), // top-right
30
- Math.max(0, contentRadius[2] + borderGap + Math.max(bBottom, bRight)), // bottom-right
31
- Math.max(0, contentRadius[3] + borderGap + Math.max(bBottom, bLeft)), // bottom-left
32
- ];
33
- // The final radius passed to the shader is the outer radius of the whole shape.
34
- // It also needs to be factored against the expanded dimensions.
35
- // The shader will then work inwards to calculate the radii for the gap and content.
36
- this.uniform4fa('u_radius', calcFactoredRadiusArray(outerRadius, expandedWidth, expandedHeight));
37
- },
38
- vertex: `
39
- # ifdef GL_FRAGMENT_PRECISION_HIGH
40
- precision highp float;
41
- # else
42
- precision mediump float;
43
- # endif
44
-
45
- attribute vec2 a_position;
46
- attribute vec2 a_textureCoords;
47
- attribute vec4 a_color;
48
- attribute vec2 a_nodeCoords;
49
-
50
- uniform vec2 u_resolution;
51
- uniform float u_pixelRatio;
52
- uniform vec2 u_dimensions;
53
- uniform vec2 u_dimensions_orig;
54
-
55
- uniform vec4 u_radius;
56
- uniform vec4 u_borderWidth;
57
- uniform float u_borderGap;
58
-
59
- varying vec4 v_color;
60
- varying vec2 v_textureCoords;
61
- varying vec2 v_nodeCoords;
62
- varying vec4 v_borderEndRadius;
63
- varying vec2 v_borderEndSize;
64
-
65
- varying vec4 v_innerRadius;
66
- varying vec2 v_innerSize;
67
- varying vec2 v_halfDimensions;
68
- varying float v_borderZero;
69
-
70
- void main() {
71
- vec2 screenSpace = vec2(2.0 / u_resolution.x, -2.0 / u_resolution.y);
72
-
73
- v_color = a_color;
74
- v_nodeCoords = a_nodeCoords;
75
-
76
- float bTop = u_borderWidth.x;
77
- float bRight = u_borderWidth.y;
78
- float bBottom = u_borderWidth.z;
79
- float bLeft = u_borderWidth.w;
80
- float gap = u_borderGap;
81
-
82
- // Calculate the offset to expand the quad for border and gap
83
- vec2 expansionOffset = vec2(0.0);
84
- if (a_nodeCoords.x == 0.0) { // Left edge vertex
85
- expansionOffset.x = -(bLeft + gap);
86
- } else { // Right edge vertex (a_nodeCoords.x == 1.0)
87
- expansionOffset.x = (bRight + gap);
88
- }
89
- if (a_nodeCoords.y == 0.0) { // Top edge vertex
90
- expansionOffset.y = -(bTop + gap);
91
- } else { // Bottom edge vertex (a_nodeCoords.y == 1.0)
92
- expansionOffset.y = (bBottom + gap);
93
- }
94
-
95
- vec2 expanded_a_position = a_position + expansionOffset;
96
- vec2 normalized = expanded_a_position * u_pixelRatio;
97
-
98
- // u_dimensions is expanded, u_dimensions_orig is original content size
99
- v_textureCoords.x = (a_textureCoords.x * u_dimensions.x - (bLeft + gap)) / u_dimensions_orig.x;
100
- v_textureCoords.y = (a_textureCoords.y * u_dimensions.y - (bTop + gap)) / u_dimensions_orig.y;
101
-
102
- v_borderZero = (u_borderWidth.x == 0.0 && u_borderWidth.y == 0.0 && u_borderWidth.z == 0.0 && u_borderWidth.w == 0.0) ? 1.0 : 0.0;
103
- // If there's no border, there's no gap from the border logic perspective
104
- // The Rounded shader itself would handle radius if borderZero is true.
105
- v_halfDimensions = u_dimensions * 0.5; // u_dimensions is now expanded_dimensions
106
- if(v_borderZero == 0.0) {
107
- // Calculate radius and size for the inner edge of the border (where the gap begins)
108
- v_borderEndRadius = vec4(
109
- max(0.0, u_radius.x - max(bTop, bLeft) - 0.5),
110
- max(0.0, u_radius.y - max(bTop, bRight) - 0.5),
111
- max(0.0, u_radius.z - max(bBottom, bRight) - 0.5),
112
- max(0.0, u_radius.w - max(bBottom, bLeft) - 0.5)
113
- );
114
- v_borderEndSize = vec2(
115
- (u_dimensions.x - (bLeft + bRight) - 1.0),
116
- (u_dimensions.y - (bTop + bBottom) - 1.0)
117
- ) * 0.5;
118
-
119
- // Calculate radius and size for the content area (after the gap)
120
- v_innerRadius = vec4(
121
- max(0.0, u_radius.x - max(bTop, bLeft) - u_borderGap - 0.5),
122
- max(0.0, u_radius.y - max(bTop, bRight) - u_borderGap - 0.5),
123
- max(0.0, u_radius.z - max(bBottom, bRight) - u_borderGap - 0.5),
124
- max(0.0, u_radius.w - max(bBottom, bLeft) - u_borderGap - 0.5)
125
- );
126
- v_innerSize = vec2(
127
- (u_dimensions.x - (bLeft + bRight) - (u_borderGap * 2.0) - 1.0),
128
- (u_dimensions.y - (bTop + bBottom) - (u_borderGap * 2.0) - 1.0)
129
- ) * 0.5;
130
- }
131
-
132
- gl_Position = vec4(normalized.x * screenSpace.x - 1.0, normalized.y * -abs(screenSpace.y) + 1.0, 0.0, 1.0);
133
- gl_Position.y = -sign(screenSpace.y) * gl_Position.y;
134
- }
135
- `,
136
- fragment: `
137
- # ifdef GL_FRAGMENT_PRECISION_HIGH
138
- precision highp float;
139
- # else
140
- precision mediump float;
141
- # endif
142
-
143
- uniform vec2 u_resolution;
144
- uniform float u_pixelRatio;
145
- uniform float u_alpha;
146
- uniform vec2 u_dimensions;
147
- uniform sampler2D u_texture;
148
-
149
- uniform vec4 u_radius;
150
-
151
- uniform vec4 u_borderWidth;
152
- uniform vec4 u_borderColor;
153
- uniform vec4 u_borderGapColor;
154
-
155
- varying vec4 v_borderEndRadius;
156
- varying vec2 v_borderEndSize;
157
-
158
- varying vec4 v_color;
159
- varying vec2 v_textureCoords;
160
- varying vec2 v_nodeCoords;
161
-
162
- varying vec2 v_halfDimensions;
163
- varying vec4 v_innerRadius;
164
- varying vec2 v_innerSize;
165
- varying float v_borderZero;
166
-
167
- float roundedBox(vec2 p, vec2 s, vec4 r) {
168
- r.xy = (p.x > 0.0) ? r.yz : r.xw;
169
- r.x = (p.y > 0.0) ? r.y : r.x;
170
- vec2 q = abs(p) - s + r.x;
171
- return (min(max(q.x, q.y), 0.0) + length(max(q, 0.0))) - r.x;
172
- }
173
-
174
- void main() {
175
- vec4 contentTexColor = texture2D(u_texture, v_textureCoords) * v_color;
176
-
177
- vec2 boxUv = v_nodeCoords.xy * u_dimensions - v_halfDimensions;
178
- float outerShapeDist = roundedBox(boxUv, v_halfDimensions, u_radius);
179
-
180
- float edgeWidth = 1.0 / u_pixelRatio;
181
- float outerShapeAlpha = 1.0 - smoothstep(-0.5 * edgeWidth, 0.5 * edgeWidth, outerShapeDist);
182
-
183
- if(v_borderZero == 1.0) { // No border, effectively no gap from border logic
184
- gl_FragColor = mix(vec4(0.0), contentTexColor, outerShapeAlpha) * u_alpha;
185
- return;
186
- }
187
-
188
- // Adjust boxUv for non-uniform borders
189
- vec2 adjustedBoxUv = boxUv;
190
- adjustedBoxUv.x += (u_borderWidth.y - u_borderWidth.w) * 0.5;
191
- adjustedBoxUv.y += (u_borderWidth.z - u_borderWidth.x) * 0.5;
192
-
193
- // Inner Border Edge (Gap starts here)
194
- float borderEndDist = roundedBox(adjustedBoxUv, v_borderEndSize, v_borderEndRadius);
195
- float borderEndAlpha = 1.0 - smoothstep(-0.5 * edgeWidth, 0.5 * edgeWidth, borderEndDist);
196
-
197
- // Content Area (Gap ends here)
198
- float contentDist = roundedBox(adjustedBoxUv, v_innerSize, v_innerRadius);
199
- float contentAlpha = 1.0 - smoothstep(-0.5 * edgeWidth, 0.5 * edgeWidth, contentDist);
200
-
201
- // Calculate Masks for mutually exclusive regions based on priority (Border Top, Gap Middle, Content Bottom)
202
- float borderMask = clamp(outerShapeAlpha - borderEndAlpha, 0.0, 1.0);
203
- float gapMask = clamp(borderEndAlpha - contentAlpha, 0.0, 1.0);
204
-
205
- // Composite Layers
206
- // 1. Content
207
- vec4 composite = mix(vec4(0.0), contentTexColor, contentAlpha);
208
- // 2. Gap
209
- composite = mix(composite, u_borderGapColor, gapMask);
210
- // 3. Border
211
- composite = mix(composite, u_borderColor, borderMask);
212
-
213
- gl_FragColor = composite * u_alpha;
214
- }
215
- `,
216
- };
217
- //# sourceMappingURL=RoundedWithBorder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RoundedWithBorder.js","sourceRoot":"","sources":["../../../src/shaders/RoundedWithBorder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAa,MAAM,YAAY,CAAC;AAEhE,OAAO,EACL,yBAAyB,GAE1B,MAAM,0CAA0C,CAAC;AAOlD,MAAM,CAAC,MAAM,iBAAiB,GAA4C;IACxE,KAAK,EAAE,yBAAyB,CAAC,KAAK;IACtC,MAAM,CAAC,IAAc;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAM,CAAC;QAC1B,MAAM,WAAW,GAAG,KAAK,CAAC,UAAU,CAAS,CAAC;QAC9C,MAAM,SAAS,GAAG,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAE3C,IAAI,CAAC,WAAW,CAAC,eAAe,EA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