From 66834a3944f915614fa386f573cfbcc37e10eee4 Mon Sep 17 00:00:00 2001 From: Lorenzo Pantano Date: Tue, 1 Dec 2026 17:35:52 +0100 Subject: [PATCH] feat(shaders): dashedBorder prop, default registration and DOM renderer fallback @solidtv/renderer 2.0.9 ships a built-in DashedBorder shader. Wire it into Solid like the other default shaders: - defaultShaderDashedBorder / registerDefaultShaderDashedBorder, registered by registerDefaultShaders as 'dashedBorder' - a `dashedBorder` prop (raw shader accessor), typed in Effects and the DOM renderer's shader props - DOM renderer: CSS gradients in the node's border layer, so dash, gap, width, color and radius come from the props there too: a dashed strip per straight side and, with a radius, a quarter ring per corner (drawn as one dash). -webkit- syntax first for older WebKit. The renderer peer range moves to ^2.0.9, the first version with DashedBorder. Co-Authored-By: Claude Opus 5.5 --- docs/essentials/effects.md | 22 ++- package.json | 2 +- pnpm-lock.yaml | 10 +- src/core/dom-renderer/dashedBorderStyle.ts | 128 ++++++++++++++++ src/core/dom-renderer/domRenderer.ts | 15 +- src/core/dom-renderer/domRendererTypes.ts | 2 + src/core/elementNode.ts | 11 ++ src/core/intrinsicTypes.ts | 2 + src/core/shaders.ts | 12 ++ tests/contract-types.tsx | 3 + tests/dashedBorder.test.tsx | 161 +++++++++++++++++++++ tests/publicApi.test.ts | 8 +- 12 files changed, 366 insertions(+), 10 deletions(-) create mode 100644 src/core/dom-renderer/dashedBorderStyle.ts create mode 100644 tests/dashedBorder.test.tsx diff --git a/docs/essentials/effects.md b/docs/essentials/effects.md index c68a391..874c711 100644 --- a/docs/essentials/effects.md +++ b/docs/essentials/effects.md @@ -1,6 +1,6 @@ # Shaders and Effects -The shader prop allows you to specify a custom shader. Most of the common use ones have shortcuts like `borderRadius`, `border`, `linearGradient`. These shortcuts get combined to create one dynamic shader from the Renderer. The order that they are listed in the props / style object affect how it gets created and could change the UI. Typically you want borderRadius to be the last one. If you have a custom shader, you'll need to use the `shader` prop and create it directly. A shader type named in a `shader` tuple must be registered with the renderer first, with `renderer.registerShaderType(name, type)`; renderer 2.0 draws nothing for an unregistered name and warns. `registerDefaultShaders(renderer)` registers the types Solid's style shortcuts create (`rounded`, `roundedWithBorder`, `roundedWithShadow`, `roundedWithBorderWithShadow`, `shadow`, `holePunch`, `linearGradient`, `radialGradient`). Check out this [example](https://github.com/lightning-js/renderer/blob/main/examples/tests/dynamic-shader.ts) from the renderer for more information. +The shader prop allows you to specify a custom shader. Most of the common use ones have shortcuts like `borderRadius`, `border`, `linearGradient`. These shortcuts get combined to create one dynamic shader from the Renderer. The order that they are listed in the props / style object affect how it gets created and could change the UI. Typically you want borderRadius to be the last one. If you have a custom shader, you'll need to use the `shader` prop and create it directly. A shader type named in a `shader` tuple must be registered with the renderer first, with `renderer.registerShaderType(name, type)`; renderer 2.0 draws nothing for an unregistered name and warns. `registerDefaultShaders(renderer)` registers the types Solid's style shortcuts create (`rounded`, `roundedWithBorder`, `roundedWithShadow`, `roundedWithBorderWithShadow`, `shadow`, `holePunch`, `dashedBorder`, `linearGradient`, `radialGradient`). Check out this [example](https://github.com/lightning-js/renderer/blob/main/examples/tests/dynamic-shader.ts) from the renderer for more information. ```jsx const RoundedRectangle = ['RoundedRectangle', { radius: 6 }]; @@ -37,6 +37,26 @@ const style = { }; ``` +## Dashed Border + +`dashedBorder` clips the node's fill to a rounded rectangle and draws a dashed border inside its edge, e.g. for an empty placeholder. The dashes follow the corners, and the dash and gap are stretched slightly so that a whole number of dashes fits the perimeter. A transparent node draws only the dashes. A `gap` of 0 draws a solid border. It is a shader of its own, so it can't be combined with `border`, `borderRadius` or `shadow` on the same node. Needs `@solidtv/renderer` 2.0.9 or later. + +```jsx + +``` + +The DOM renderer draws it with CSS gradients, so `dash`, `gap`, `width`, `color` and `radius` work there too: a dashed strip per side and, with a `radius`, a quarter ring per corner. Each rounded corner is drawn as one dash, which is longer than `dash` when the radius is large. + ## Linear Gradient & Radial Gradient `linearGradient` and `radialGradient` are effects that can be used by setting the effects prop. diff --git a/package.json b/package.json index aef34de..3366902 100644 --- a/package.json +++ b/package.json @@ -115,7 +115,7 @@ }, "peerDependencies": { "@solidjs/router": "^0.16.1", - "@solidtv/renderer": "^2.0.7", + "@solidtv/renderer": "^2.0.9", "solid-js": "*" }, "peerDependenciesMeta": {}, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 25b46bf..b56567a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -24,8 +24,8 @@ importers: specifier: ^0.16.1 version: 0.16.1(solid-js@1.9.3) '@solidtv/renderer': - specifier: ^2.0.7 - version: 2.0.7 + specifier: ^2.0.9 + version: 2.0.9 solid-js: specifier: '*' version: 1.9.3 @@ -1235,8 +1235,8 @@ packages: '@solidjs/router': optional: true - '@solidtv/renderer@2.0.7': - resolution: {integrity: sha512-NVF4L42mIamJbqaYEN/RAO2bMadqJZXGjku1N1iUq0F2dr4HrY7MffjQVjeGMQ03/YfdUhIwizG18nThm1B3uw==} + '@solidtv/renderer@2.0.9': + resolution: {integrity: sha512-erc/N9tZDxyHI3q1Sz9dtqx/CZOyE5rddevmkrxaqHYcP6AzKqgeWcjo2U3BKNT3Bl6pDmxYSB2TJI9mzTnHsw==} engines: {node: '>= 18.0.0', npm: '>= 10.0.0', pnpm: '>= 10.17.0'} '@standard-schema/spec@1.1.0': @@ -3559,7 +3559,7 @@ snapshots: optionalDependencies: '@solidjs/router': 0.16.1(solid-js@1.9.3) - '@solidtv/renderer@2.0.7': {} + '@solidtv/renderer@2.0.9': {} '@standard-schema/spec@1.1.0': {} diff --git a/src/core/dom-renderer/dashedBorderStyle.ts b/src/core/dom-renderer/dashedBorderStyle.ts new file mode 100644 index 0000000..2b953d3 --- /dev/null +++ b/src/core/dom-renderer/dashedBorderStyle.ts @@ -0,0 +1,128 @@ +import type { DashedBorderProps } from '@solidtv/renderer'; + +/** + * The DOM renderer's `dashedBorder`, in CSS only, so that `dash`, `gap`, + * `width`, `color` and `radius` draw as the WebGL shader draws them: + * + * - each straight side is a repeating linear gradient strip, `width` thick; + * - with a radius, each corner is a quarter ring (a radial gradient), drawn + * as one dash, and the straight sides run gap, dash, ..., dash, gap + * between them; without one, each side starts and ends with a dash, and + * the corners' dashes meet. + * + * On each side the dash and gap are stretched so that a whole number of + * them fits. A `gap` of 0 or less draws a solid border. Returns '' when + * nothing is drawn: a `dash`, `width` or colour alpha of 0 or less, or a + * node without size. + * + * Each gradient is written twice, the `-webkit-` syntax first, for older + * WebKit (e.g. PS4); a browser keeps the last declaration it can read. + */ +export function dashedBorderStyle( + w: number, + h: number, + props: Partial, +): string { + const width = props.width ?? 2; + const color = props.color ?? 0xffffffff; + const dash = props.dash ?? 10; + const gap = props.gap ?? 10; + if (w <= 0 || h <= 0 || width <= 0 || dash <= 0 || (color & 0xff) === 0) { + return ''; + } + const rgba = `rgba(${(color >>> 24) & 0xff},${(color >>> 16) & 0xff},${(color >>> 8) & 0xff},${round((color & 0xff) / 255)})`; + const r = round(Math.max(0, Math.min(props.radius ?? 0, w / 2, h / 2))); + const px = `${width}px`; + + // [-webkit- image, image, size, position] + const layers: [string, string, string, string][] = []; + const side = ( + length: number, + dirs: [string, string], + size: string, + position: string, + ) => { + const stops = strip(length, dash, gap, rgba, r > 0); + if (stops !== '') { + layers.push([ + `-webkit-repeating-linear-gradient(${dirs[0]}, ${stops})`, + `repeating-linear-gradient(${dirs[1]}, ${stops})`, + size, + position, + ]); + } + }; + const straightX = round(w - 2 * r); + const straightY = round(h - 2 * r); + side(straightX, ['left', 'to right'], `${straightX}px ${px}`, `${r}px 0`); + side(straightX, ['left', 'to right'], `${straightX}px ${px}`, `${r}px 100%`); + side(straightY, ['top', 'to bottom'], `${px} ${straightY}px`, `0 ${r}px`); + side(straightY, ['top', 'to bottom'], `${px} ${straightY}px`, `100% ${r}px`); + + if (r > 0) { + // A quarter ring around the corner's centre; the layer's border-radius + // clips (and smooths) its outer edge. + const inner = round(r - width); + const ring = + inner > 0 + ? `transparent ${round(inner - 0.5)}px, ${rgba} ${round(inner + 0.5)}px, ${rgba} ${r}px, transparent ${r}px` + : `${rgba} 0, ${rgba} ${r}px, transparent ${r}px`; + // The corner box's position, and the ring's centre in that box + const corners: [string, string][] = [ + ['0 0', '100% 100%'], + ['100% 0', '0 100%'], + ['0 100%', '100% 0'], + ['100% 100%', '0 0'], + ]; + for (const [position, centre] of corners) { + layers.push([ + `-webkit-radial-gradient(${centre}, circle, ${ring})`, + `radial-gradient(circle at ${centre}, ${ring})`, + `${r}px ${r}px`, + position, + ]); + } + } + + const list = (i: number) => layers.map((layer) => layer[i]).join(', '); + return ( + `background-image: ${list(0)};` + + `background-image: ${list(1)};` + + `background-size: ${list(2)};` + + `background-position: ${list(3)};` + + 'background-repeat: no-repeat;' + ); +} + +/** + * The colour stops of a straight side `length` long. Between rounded + * corners (which are dashes) it starts and ends with a gap: count dashes, + * count + 1 gaps. Without corners it starts and ends with a dash: count + * dashes, count - 1 gaps. '' when the side holds no dash. + */ +function strip( + length: number, + dash: number, + gap: number, + rgba: string, + betweenCorners: boolean, +): string { + if (length <= 0) return ''; + if (gap <= 0) return `${rgba} 0, ${rgba} ${length}px`; + const pair = dash + gap; + const gaps = betweenCorners ? 1 : -1; + const count = Math.max( + betweenCorners ? 0 : 1, + Math.round((length - gaps * gap) / pair), + ); + if (count === 0) return ''; + const scale = length / (count * dash + (count + gaps) * gap); + const d = round(dash * scale); + const g = round(gap * scale); + const p = round(d + g); + return betweenCorners + ? `transparent 0, transparent ${g}px, ${rgba} ${g}px, ${rgba} ${p}px` + : `${rgba} 0, ${rgba} ${d}px, transparent ${d}px, transparent ${p}px`; +} + +const round = (n: number) => Math.round(n * 1000) / 1000; diff --git a/src/core/dom-renderer/domRenderer.ts b/src/core/dom-renderer/domRenderer.ts index de58a66..5f0db86 100644 --- a/src/core/dom-renderer/domRenderer.ts +++ b/src/core/dom-renderer/domRenderer.ts @@ -9,6 +9,7 @@ import * as lng from '@solidtv/renderer'; import { EventEmitter } from '@solidtv/renderer/utils'; import { Config } from '../config.js'; import { FontLoadOptions } from '../intrinsicTypes.js'; +import { dashedBorderStyle } from './dashedBorderStyle.js'; import type { DomRendererMainSettings, ExtractProps, @@ -542,6 +543,7 @@ function updateNodeStyles(node: DOMNode | DOMText) { let bgStyle = ''; let borderStyle = ''; + let needsDashedBorderLayer = false; let radiusStyle = ''; let maskStyle = ''; let needsBackgroundLayer = false; @@ -713,6 +715,16 @@ function updateNodeStyles(node: DOMNode | DOMText) { } } } + // Dashed border: gradient strips with the props' dash and gap, in a + // layer of its own above the node's fill and below its children, so + // that it neither grows the node nor moves its children. + if (props.shader.shaderType === 'dashedBorder') { + const dashedStyle = dashedBorderStyle(props.w, props.h, shaderProps); + if (dashedStyle !== '') { + borderStyle += dashedStyle; + needsDashedBorderLayer = true; + } + } // Rounded if (typeof radius === 'number' && radius > 0) { radiusStyle += `border-radius: ${radius}px;`; @@ -1091,7 +1103,8 @@ function updateNodeStyles(node: DOMNode | DOMText) { if (node.blobUrls !== null) releaseBlobUrls(node, false); - const needsSeparateBorderLayer = needsBackgroundLayer && maskStyle !== ''; + const needsSeparateBorderLayer = + needsDashedBorderLayer || (needsBackgroundLayer && maskStyle !== ''); if (needsSeparateBorderLayer) { if (node.divBorder == null) { diff --git a/src/core/dom-renderer/domRendererTypes.ts b/src/core/dom-renderer/domRendererTypes.ts index cb2af74..16a045c 100644 --- a/src/core/dom-renderer/domRendererTypes.ts +++ b/src/core/dom-renderer/domRendererTypes.ts @@ -2,6 +2,7 @@ import * as lng from '@solidtv/renderer'; import { EventEmitter } from '@solidtv/renderer/utils'; import { ShaderBorderPrefixedProps, + ShaderDashedBorderProps, ShaderHolePunchProps, ShaderLinearGradientProps, ShaderRadialGradientProps, @@ -45,6 +46,7 @@ export type IRendererShaderProps = Partial & Partial & Partial & Partial & + Partial & Partial & Partial; diff --git a/src/core/elementNode.ts b/src/core/elementNode.ts index 85ac096..6f25b6c 100644 --- a/src/core/elementNode.ts +++ b/src/core/elementNode.ts @@ -35,6 +35,7 @@ import type { RendererMain, INode, AnimateProps, + DashedBorderProps, IAnimationController, LinearGradientProps, RadialGradientProps, @@ -1000,6 +1001,14 @@ export interface ElementNode extends RendererNode, FocusNode { * @see https://solid-tv.github.io/solid/#/essentials/effects */ radialGradient?: RadialGradientProps; + /** + * Clips the element to a rounded rectangle and draws a dashed border + * inside its edge. The DOM renderer draws it with CSS gradients: dash and + * gap lengths match, and each rounded corner is drawn as one dash. + * + * @see https://solid-tv.github.io/solid/#/essentials/effects + */ + dashedBorder?: Partial; /** * The margin on the bottom side of the element for a flexItem. * @@ -3699,4 +3708,6 @@ Object.defineProperties(ElementNode.prototype, { createRawShaderAccessor('linearGradient'), radialGradient: createRawShaderAccessor('radialGradient'), + dashedBorder: + createRawShaderAccessor>('dashedBorder'), }); diff --git a/src/core/intrinsicTypes.ts b/src/core/intrinsicTypes.ts index b159952..5f066f2 100644 --- a/src/core/intrinsicTypes.ts +++ b/src/core/intrinsicTypes.ts @@ -4,6 +4,7 @@ import type { TextNode } from './nodeTypes.js'; import { NodeStates } from './states.js'; import { ShaderBorderProps, + ShaderDashedBorderProps, ShaderHolePunchProps, ShaderLinearGradientProps, ShaderRadialGradientProps, @@ -47,6 +48,7 @@ export interface Effects { linearGradient?: Partial; radialGradient?: Partial; holePunch?: Partial; + dashedBorder?: Partial; shadow?: Partial; rounded?: Partial; borderRadius?: Partial; diff --git a/src/core/shaders.ts b/src/core/shaders.ts index 4f45b98..fb54074 100644 --- a/src/core/shaders.ts +++ b/src/core/shaders.ts @@ -2,6 +2,7 @@ import * as lngr from '@solidtv/renderer'; import * as lngr_shaders from '@solidtv/renderer/webgl/shaders'; import type { + DashedBorderProps as ShaderDashedBorderProps, HolePunchProps as ShaderHolePunchProps, LinearGradientProps as ShaderLinearGradientProps, RadialGradientProps as ShaderRadialGradientProps, @@ -10,6 +11,7 @@ import type { } from '@solidtv/renderer'; import { type WebGlShaderType as WebGlShader } from '@solidtv/renderer'; export { + ShaderDashedBorderProps, ShaderHolePunchProps, ShaderLinearGradientProps, ShaderRadialGradientProps, @@ -57,6 +59,7 @@ export type ShaderRoundedWithShadow = WebGlShader; export type ShaderRoundedWithBorderAndShadow = WebGlShader; export type ShaderHolePunch = WebGlShader; +export type ShaderDashedBorder = WebGlShader; export type ShaderRadialGradient = WebGlShader; export type ShaderLinearGradient = WebGlShader; @@ -68,6 +71,8 @@ export const defaultShaderRoundedWithShadow: ShaderRoundedWithShadow = export const defaultShaderRoundedWithBorderAndShadow = lngr_shaders.RoundedWithBorderAndShadow as ShaderRoundedWithBorderAndShadow; export const defaultShaderHolePunch: ShaderHolePunch = lngr_shaders.HolePunch; +export const defaultShaderDashedBorder: ShaderDashedBorder = + lngr_shaders.DashedBorder; export const defaultShaderRadialGradient: ShaderRadialGradient = lngr_shaders.RadialGradient; export const defaultShaderLinearGradient: ShaderLinearGradient = @@ -160,6 +165,12 @@ export function registerDefaultShaderHolePunch(shManager: CoreShaderManager) { if (SHADERS_ENABLED && !isDomRendererActive()) shManager.registerShaderType('holePunch', defaultShaderHolePunch); } +export function registerDefaultShaderDashedBorder( + shManager: CoreShaderManager, +) { + if (SHADERS_ENABLED && !isDomRendererActive()) + shManager.registerShaderType('dashedBorder', defaultShaderDashedBorder); +} export function registerDefaultShaderRadialGradient( shManager: CoreShaderManager, ) { @@ -181,6 +192,7 @@ export function registerDefaultShaders(shManager: CoreShaderManager) { registerDefaultShaderRoundedWithShadow(shManager); registerDefaultShaderRoundedWithBorderAndShadow(shManager); registerDefaultShaderHolePunch(shManager); + registerDefaultShaderDashedBorder(shManager); registerDefaultShaderRadialGradient(shManager); registerDefaultShaderLinearGradient(shManager); } diff --git a/tests/contract-types.tsx b/tests/contract-types.tsx index ebcb1ea..ee99b76 100644 --- a/tests/contract-types.tsx +++ b/tests/contract-types.tsx @@ -191,6 +191,8 @@ export type { SdfFontType, ShaderBorderPrefixedProps, ShaderBorderProps, + ShaderDashedBorder, + ShaderDashedBorderProps, ShaderHolePunch, ShaderHolePunchProps, ShaderLinearGradient, @@ -239,6 +241,7 @@ export type { ColorTextureProps, CoreNodeRenderState, CoreSettings, + DashedBorderProps, Dimensions, EdgeFadeProps, EventEmitter, diff --git a/tests/dashedBorder.test.tsx b/tests/dashedBorder.test.tsx new file mode 100644 index 0000000..e689244 --- /dev/null +++ b/tests/dashedBorder.test.tsx @@ -0,0 +1,161 @@ +// The `dashedBorder` prop: a `dashedBorder` shader with the given props. The +// DOM renderer has no shader: it draws one gradient strip per side, with the +// props' dash and gap, in a layer of its own (`divBorder`), so the node keeps +// its size and its children their place. +import * as v from 'vitest'; +import * as lng from '@solidtv/solid'; +import { dashedBorderStyle } from '../src/core/dom-renderer/dashedBorderStyle.js'; +import { renderer } from './setup.js'; + +const RED = 0xff0000ff; +const RED_CSS = 'rgba(255,0,0,1)'; + +type DomHandle = { + div: HTMLElement; + divBorder?: HTMLElement; + shader: { shaderType: string; props: Record }; +}; +const dom = (node: lng.ElementNode) => node.lng as unknown as DomHandle; +const tick = () => new Promise((r) => setTimeout(r, 0)); + +function renderView(props: lng.NodeProps) { + let node!: lng.ElementNode; + const dispose = renderer.render(() => ( + + )); + return { node, dispose }; +} + +/** A side's colour stops: dash length d, period p. */ +const stops = (color: string, d: number, p: number) => + `${color} 0, ${color} ${d}px, transparent ${d}px, transparent ${p}px`; + +v.describe('dashedBorder', () => { + v.test('renders with the dashedBorder shader and its props', () => { + const props = { radius: 8, width: 2, color: RED, dash: 6, gap: 4 }; + const { node, dispose } = renderView({ dashedBorder: props }); + v.expect(dom(node).shader.shaderType).toBe('dashedBorder'); + v.expect(dom(node).shader.props).toEqual(props); + dispose(); + }); + + v.test('the DOM renderer draws it in its own layer', async () => { + const { node, dispose } = renderView({ + color: 0x000000ff, + dashedBorder: { radius: 8, width: 3, color: RED, dash: 6, gap: 4 }, + }); + await tick(); + const { div, divBorder } = dom(node); + v.expect(divBorder).toBeDefined(); + v.expect(divBorder!.parentElement).toBe(div); + const style = divBorder!.getAttribute('style')!; + v.expect(style).toContain('repeating-linear-gradient'); + v.expect(style).toContain('border-radius: 8px'); + // The node itself: no border, its fill clipped to the radius + v.expect(div.getAttribute('style')).not.toContain('gradient'); + v.expect(div.style.borderRadius).toBe('8px'); + dispose(); + }); + + v.test('an update after render restyles the border layer', async () => { + const { node, dispose } = renderView({ + dashedBorder: { width: 2, color: RED }, + }); + await tick(); + node.dashedBorder = { width: 4, color: 0x00ff00ff, dash: 20, gap: 5 }; + await tick(); + const style = dom(node).divBorder!.getAttribute('style')!; + // 100 wide: 4 dashes and 3 gaps, x 100/95 + v.expect(style).toContain('rgba(0,255,0,1) 21.053px'); + v.expect(style).toContain('100px 4px'); + dispose(); + }); + + v.test('a dash of 0 draws nothing', async () => { + const { node, dispose } = renderView({ + dashedBorder: { color: RED, dash: 0 }, + }); + await tick(); + v.expect(dom(node).divBorder).toBeUndefined(); + dispose(); + }); +}); + +v.describe('dashedBorderStyle', () => { + v.test('each side starts and ends with a dash, the pair stretched', () => { + // 100 wide: 10 dashes and 9 gaps, x 100/96; 50 high: 5 and 4, x 50/46 + const css = dashedBorderStyle(100, 50, { + width: 2, + color: RED, + dash: 6, + gap: 4, + }); + const top = stops(RED_CSS, 6.25, 10.417); + const left = stops(RED_CSS, 6.522, 10.87); + v.expect(css).toContain( + `background-image: repeating-linear-gradient(to right, ${top}), ` + + `repeating-linear-gradient(to right, ${top}), ` + + `repeating-linear-gradient(to bottom, ${left}), ` + + `repeating-linear-gradient(to bottom, ${left});`, + ); + v.expect(css).toContain( + 'background-size: 100px 2px, 100px 2px, 2px 50px, 2px 50px;', + ); + v.expect(css).toContain( + 'background-position: 0px 0, 0px 100%, 0 0px, 100% 0px;', + ); + }); + + v.test( + 'with a radius, the corners are rings and the sides start with a gap', + () => { + // 100 x 50, radius 8: straight sides 84 and 34 between the corners + // 84: 8 dashes and 9 gaps; 34: 3 dashes and 4 gaps, x 34/34 + const css = dashedBorderStyle(100, 50, { + radius: 8, + width: 2, + color: RED, + dash: 6, + gap: 4, + }); + v.expect(css).toContain( + `repeating-linear-gradient(to right, transparent 0, transparent 4px, ${RED_CSS} 4px, ${RED_CSS} 10px)`, + ); + v.expect(css).toContain( + `repeating-linear-gradient(to bottom, transparent 0, transparent 4px, ${RED_CSS} 4px, ${RED_CSS} 10px)`, + ); + v.expect(css).toContain( + `radial-gradient(circle at 100% 100%, transparent 5.5px, ${RED_CSS} 6.5px, ${RED_CSS} 8px, transparent 8px)`, + ); + v.expect(css).toContain( + 'background-size: 84px 2px, 84px 2px, 2px 34px, 2px 34px, 8px 8px, 8px 8px, 8px 8px, 8px 8px;', + ); + v.expect(css).toContain( + 'background-position: 8px 0, 8px 100%, 0 8px, 100% 8px, 0 0, 100% 0, 0 100%, 100% 100%;', + ); + }, + ); + + v.test('writes the -webkit- syntax first, for older WebKit', () => { + const css = dashedBorderStyle(100, 50, { color: RED }); + v.expect(css.indexOf('-webkit-repeating-linear-gradient(left,')).toBe( + 'background-image: '.length, + ); + v.expect(css.indexOf('-webkit-')).toBeLessThan(css.indexOf('(to right,')); + }); + + v.test('a gap of 0 draws a solid border', () => { + const css = dashedBorderStyle(100, 50, { color: RED, dash: 10, gap: 0 }); + v.expect(css).toContain( + `repeating-linear-gradient(to right, ${RED_CSS} 0, ${RED_CSS} 100px)`, + ); + v.expect(css).not.toContain('transparent'); + }); + + v.test('draws nothing without a dash, width, alpha or size', () => { + v.expect(dashedBorderStyle(100, 50, { dash: 0 })).toBe(''); + v.expect(dashedBorderStyle(100, 50, { width: 0 })).toBe(''); + v.expect(dashedBorderStyle(100, 50, { color: 0xff000000 })).toBe(''); + v.expect(dashedBorderStyle(0, 50, {})).toBe(''); + }); +}); diff --git a/tests/publicApi.test.ts b/tests/publicApi.test.ts index c20935e..b7fdb56 100644 --- a/tests/publicApi.test.ts +++ b/tests/publicApi.test.ts @@ -24,7 +24,7 @@ import * as focusManager from '@solidtv/solid/focusManager'; const names = (mod: object) => Object.keys(mod).sort(); v.describe('Exports: runtime export names of every entry point', () => { - v.test('@solidtv/solid (src/index.ts): 97 names', () => { + v.test('@solidtv/solid (src/index.ts): 99 names', () => { v.expect(names(main)).toEqual([ 'Config', 'DOMNode', @@ -57,6 +57,7 @@ v.describe('Exports: runtime export names of every entry point', () => { 'createRawShaderAccessor', 'createRenderer', 'createTextNode', + 'defaultShaderDashedBorder', 'defaultShaderHolePunch', 'defaultShaderLinearGradient', 'defaultShaderRadialGradient', @@ -99,6 +100,7 @@ v.describe('Exports: runtime export names of every entry point', () => { 'mergeProps', 'mod', 'registerDefaultShader', + 'registerDefaultShaderDashedBorder', 'registerDefaultShaderHolePunch', 'registerDefaultShaderLinearGradient', 'registerDefaultShaderRadialGradient', @@ -230,8 +232,9 @@ v.describe('Exports: runtime export names of every entry point', () => { }); // B21: ./shaders and ./focusManager are entry points of their own. - v.test('@solidtv/solid/shaders (src/core/shaders.ts): 17 names', () => { + v.test('@solidtv/solid/shaders (src/core/shaders.ts): 19 names', () => { v.expect(names(shaders)).toEqual([ + 'defaultShaderDashedBorder', 'defaultShaderHolePunch', 'defaultShaderLinearGradient', 'defaultShaderRadialGradient', @@ -240,6 +243,7 @@ v.describe('Exports: runtime export names of every entry point', () => { 'defaultShaderRoundedWithBorderAndShadow', 'defaultShaderRoundedWithShadow', 'defaultShaderShadow', + 'registerDefaultShaderDashedBorder', 'registerDefaultShaderHolePunch', 'registerDefaultShaderLinearGradient', 'registerDefaultShaderRadialGradient',