diff --git a/.changeset/dom-inline-styles.md b/.changeset/dom-inline-styles.md new file mode 100644 index 0000000..158a636 --- /dev/null +++ b/.changeset/dom-inline-styles.md @@ -0,0 +1,5 @@ +--- +'@clack/ui': patch +--- + +Add inline style declarations with shared camelCase, dashed, and setProperty access, supported CSS value parsing, and change notifications. diff --git a/packages/ui/package.json b/packages/ui/package.json index a60b9d0..3c92e57 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -36,7 +36,9 @@ "test": "pnpm --filter @bomb.sh/web-platform-tests build && bsh test" }, "dependencies": { - "@bomb.sh/tty": "catalog:" + "@bomb.sh/tty": "catalog:", + "@standard-schema/spec": "^1.1.0", + "hueful": "^0.8.1" }, "devEngines": { "packageManager": { diff --git a/packages/ui/src/dom.ts b/packages/ui/src/dom.ts index 95493cb..6033ece 100644 --- a/packages/ui/src/dom.ts +++ b/packages/ui/src/dom.ts @@ -3,6 +3,7 @@ import { asciiUppercase, asciiLowercase } from './ascii.ts'; import { NamedNodeMap } from './named-node-map.ts'; import { HTMLCollection } from './html-collection.ts'; +import { StyleDeclaration } from './style.ts'; import { validateElementName, validateElementNamespace, @@ -330,6 +331,7 @@ export abstract class Node extends EventTarget { } export class Element extends Node { + readonly style: StyleDeclaration; readonly localName: string; readonly nodeName: string; readonly namespaceURI: string | null; @@ -344,6 +346,7 @@ export class Element extends Node { { namespaceURI = HTML_NS, prefix = null }: Partial = {}, ) { super(owner, notify); + this.style = new StyleDeclaration(this.notify); this.localName = localName; this.namespaceURI = namespaceURI; this.prefix = prefix; diff --git a/packages/ui/src/index.ts b/packages/ui/src/index.ts index ca4a46a..f8c0e77 100644 --- a/packages/ui/src/index.ts +++ b/packages/ui/src/index.ts @@ -1 +1,9 @@ export { createUI } from './ui.ts'; +export type { + ColorValue, + BorderWidthValue, + FlexDirectionValue, + DisplayValue, + LengthValue, + BorderStyleValue, +} from './style.ts'; diff --git a/packages/ui/src/style.test.ts b/packages/ui/src/style.test.ts new file mode 100644 index 0000000..c862516 --- /dev/null +++ b/packages/ui/src/style.test.ts @@ -0,0 +1,366 @@ +// Independent tests for our terminal style subset; upstream coverage runs through WPT. +import { describe, expect, expectTypeOf, it } from 'vitest'; +import { Document } from './dom.ts'; +import { StyleDeclaration, type ColorValue } from './style.ts'; + +describe('inline style declarations', () => { + // These checks cover the shared declaration and terminal notification behavior. + it('shares declarations between camelCase, dashed aliases, and setProperty', () => { + const style = new StyleDeclaration(); + const properties = [ + ['flexDirection', 'flex-direction', 'row', 'column'], + ['paddingTop', 'padding-top', '1px', '2px'], + ['paddingRight', 'padding-right', '1px', '2px'], + ['paddingBottom', 'padding-bottom', '1px', '2px'], + ['paddingLeft', 'padding-left', '1px', '2px'], + ['borderTopWidth', 'border-top-width', '0px', '1px'], + ['borderRightWidth', 'border-right-width', '0px', '1px'], + ['borderBottomWidth', 'border-bottom-width', '0px', '1px'], + ['borderLeftWidth', 'border-left-width', '0px', '1px'], + ['borderStyle', 'border-style', 'none', 'solid'], + ['borderColor', 'border-color', 'red', 'blue'], + ] as const; + for (const [camel, dashed, first, second] of properties) { + Reflect.set(style, camel, first); + expect(style[dashed], dashed).toBe(first); + Reflect.set(style, dashed, second); + expect(style[camel], camel).toBe(second); + expect(style.getPropertyValue(dashed), dashed).toBe(second); + style.setProperty(dashed, first); + expect(style[camel], camel).toBe(first); + expect(style[dashed], dashed).toBe(first); + style.setProperty(dashed, ''); + expect(style[camel], camel).toBe(''); + } + }); + + it('commits values and priorities together before notifying the terminal', () => { + const changes: [string, string][] = []; + const style = new StyleDeclaration(() => { + changes.push([style.paddingTop, style.getPropertyPriority('padding-top')]); + }); + style.setProperty('PADDING-TOP', '2px', 'IMPORTANT'); + expect(changes).toEqual([['2px', 'important']]); + + style.setProperty('padding-top', '-1px'); + style.setProperty('padding-top', ' \t\n'); + style.setProperty('padding-top', '3px', ' important '); + style.setProperty('paddingTop', '3px'); + style.setProperty(' padding-top ', '3px'); + expect(changes).toEqual([['2px', 'important']]); + expect(style.paddingTop).toBe('2px'); + expect(style.getPropertyPriority('padding-top')).toBe('important'); + + style['padding-top'] = '2px'; + expect(changes).toEqual([ + ['2px', 'important'], + ['2px', ''], + ]); + style.setProperty('padding-top', '1px', 'important'); + style.setProperty('padding-top', '', 'invalid'); + expect(changes.at(-1)).toEqual(['', '']); + }); + + it('converts setProperty arguments and clears declarations assigned null', () => { + const style = new StyleDeclaration(); + style.color = 'white'; + Reflect.apply(style.setProperty, style, ['color', undefined]); + expect(style.color).toBe('white'); + style.setProperty('color', 'red', undefined); + expect(style.color).toBe('red'); + expect(style.getPropertyPriority('color')).toBe(''); + style.setProperty('color', 'blue', null); + expect(style.color).toBe('blue'); + style.setProperty('color', null); + expect(style.color).toBe(''); + style.color = 'red'; + Reflect.set(style, 'color', null); + expect(style.color).toBe(''); + Reflect.apply(style.setProperty, style, ['padding-left', { toString: () => '2px' }]); + expect(style.paddingLeft).toBe('2px'); + expect(() => Reflect.apply(style.setProperty, style, ['padding-left'])).toThrow(TypeError); + expect(() => Reflect.apply(style.setProperty, style, ['unknown', Symbol()])).toThrow(TypeError); + }); + + it('keeps a stable style object for each element', () => { + const document = new Document(() => {}); + const first = document.createElement('div'); + const second = document.createElement('span'); + const style = first.style; + + expect(style).toBeDefined(); + expect(first.style).toBe(style); + expect(second.style).not.toBe(style); + + style.color = 'green'; + + expect(first.style).toBe(style); + expect(second.style.color).toBe(''); + }); + + it('reads undeclared properties as empty strings, including element defaults', () => { + const document = new Document(() => {}); + const { documentElement } = document; + + expect(documentElement.style.display, `${documentElement.tagName}.style.display`).toBe(''); + expect( + documentElement.style.flexDirection, + `${documentElement.tagName}.style.flexDirection`, + ).toBe(''); + expect(documentElement.style.gap, `${documentElement.tagName}.style.gap`).toBe(''); + expect(documentElement.style.paddingTop, `${documentElement.tagName}.style.paddingTop`).toBe( + '', + ); + expect( + documentElement.style.paddingRight, + `${documentElement.tagName}.style.paddingRight`, + ).toBe(''); + expect( + documentElement.style.paddingBottom, + `${documentElement.tagName}.style.paddingBottom`, + ).toBe(''); + expect(documentElement.style.paddingLeft, `${documentElement.tagName}.style.paddingLeft`).toBe( + '', + ); + expect(documentElement.style.borderStyle, `${documentElement.tagName}.style.borderStyle`).toBe( + '', + ); + expect( + documentElement.style.borderTopWidth, + `${documentElement.tagName}.style.borderTopWidth`, + ).toBe(''); + expect( + documentElement.style.borderRightWidth, + `${documentElement.tagName}.style.borderRightWidth`, + ).toBe(''); + expect( + documentElement.style.borderBottomWidth, + `${documentElement.tagName}.style.borderBottomWidth`, + ).toBe(''); + expect( + documentElement.style.borderLeftWidth, + `${documentElement.tagName}.style.borderLeftWidth`, + ).toBe(''); + expect(documentElement.style.borderColor, `${documentElement.tagName}.style.borderColor`).toBe( + '', + ); + expect(documentElement.style.color, `${documentElement.tagName}.style.color`).toBe(''); + + const div = document.createElement('div'); + + expect(div.style.display, `${div.tagName}.style.display`).toBe(''); + expect(div.style.flexDirection, `${div.tagName}.style.flexDirection`).toBe(''); + expect(div.style.gap, `${div.tagName}.style.gap`).toBe(''); + expect(div.style.paddingTop, `${div.tagName}.style.paddingTop`).toBe(''); + expect(div.style.paddingRight, `${div.tagName}.style.paddingRight`).toBe(''); + expect(div.style.paddingBottom, `${div.tagName}.style.paddingBottom`).toBe(''); + expect(div.style.paddingLeft, `${div.tagName}.style.paddingLeft`).toBe(''); + expect(div.style.borderStyle, `${div.tagName}.style.borderStyle`).toBe(''); + expect(div.style.borderTopWidth, `${div.tagName}.style.borderTopWidth`).toBe(''); + expect(div.style.borderRightWidth, `${div.tagName}.style.borderRightWidth`).toBe(''); + expect(div.style.borderBottomWidth, `${div.tagName}.style.borderBottomWidth`).toBe(''); + expect(div.style.borderLeftWidth, `${div.tagName}.style.borderLeftWidth`).toBe(''); + expect(div.style.borderColor, `${div.tagName}.style.borderColor`).toBe(''); + expect(div.style.color, `${div.tagName}.style.color`).toBe(''); + + const span = document.createElement('span'); + + expect(span.style.display, `${span.tagName}.style.display`).toBe(''); + expect(span.style.flexDirection, `${span.tagName}.style.flexDirection`).toBe(''); + expect(span.style.gap, `${span.tagName}.style.gap`).toBe(''); + expect(span.style.paddingTop, `${span.tagName}.style.paddingTop`).toBe(''); + expect(span.style.paddingRight, `${span.tagName}.style.paddingRight`).toBe(''); + expect(span.style.paddingBottom, `${span.tagName}.style.paddingBottom`).toBe(''); + expect(span.style.paddingLeft, `${span.tagName}.style.paddingLeft`).toBe(''); + expect(span.style.borderStyle, `${span.tagName}.style.borderStyle`).toBe(''); + expect(span.style.borderTopWidth, `${span.tagName}.style.borderTopWidth`).toBe(''); + expect(span.style.borderRightWidth, `${span.tagName}.style.borderRightWidth`).toBe(''); + expect(span.style.borderBottomWidth, `${span.tagName}.style.borderBottomWidth`).toBe(''); + expect(span.style.borderLeftWidth, `${span.tagName}.style.borderLeftWidth`).toBe(''); + expect(span.style.borderColor, `${span.tagName}.style.borderColor`).toBe(''); + expect(span.style.color, `${span.tagName}.style.color`).toBe(''); + }); + + it('accepts direct display and flexDirection assignments', () => { + const style = new Document(() => {}).createElement('div').style; + + style.display = 'inline'; + style.flexDirection = 'column'; + expect(style.display).toBe('inline'); + expect(style.flexDirection).toBe('column'); + + style.display = 'flex'; + style.flexDirection = 'row'; + expect(style.display).toBe('flex'); + expect(style.flexDirection).toBe('row'); + }); + + it('ignores unsupported display and flexDirection values', () => { + const style = new Document(() => {}).createElement('div').style; + style.display = 'inline'; + style.flexDirection = 'column'; + + Reflect.set(style, 'display', 'grid'); + Reflect.set(style, 'flexDirection', 'row-reverse'); + + expect(style.display).toBe('inline'); + expect(style.flexDirection).toBe('column'); + }); + + it('accepts nonnegative whole-cell px lengths for gap and each padding side', () => { + const style = new Document(() => {}).createElement('div').style; + style.gap = '0px'; + style.paddingTop = '1px'; + style.paddingRight = '2px'; + style.paddingBottom = '3px'; + style.paddingLeft = '4px'; + + expect(style.gap).toBe('0px'); + expect(style.paddingTop).toBe('1px'); + expect(style.paddingRight).toBe('2px'); + expect(style.paddingBottom).toBe('3px'); + expect(style.paddingLeft).toBe('4px'); + }); + + it('types gap and padding as px strings or empty declarations', () => { + const style = new Document(() => {}).createElement('div').style; + + expectTypeOf(style.gap).toEqualTypeOf<`${number}px` | ''>(); + expectTypeOf(style.paddingTop).toEqualTypeOf<`${number}px` | ''>(); + expectTypeOf(style.paddingRight).toEqualTypeOf<`${number}px` | ''>(); + expectTypeOf(style.paddingBottom).toEqualTypeOf<`${number}px` | ''>(); + expectTypeOf(style.paddingLeft).toEqualTypeOf<`${number}px` | ''>(); + }); + + it('preserves previous lengths after invalid assignments', () => { + const style = new Document(() => {}).createElement('div').style; + + for (const property of [ + 'gap', + 'paddingTop', + 'paddingRight', + 'paddingBottom', + 'paddingLeft', + ] as const) { + style[property] = '2px'; + + for (const value of ['-1px', '1.5px', '1ch', '2', 'auto', 'NaNpx', 2]) { + Reflect.set(style, property, value); + expect(style[property], `${property} after ${String(value)}`).toBe('2px'); + } + } + }); + + it('accepts zero or one cell for each border width and preserves other sides', () => { + const style = new Document(() => {}).createElement('div').style; + style.borderTopWidth = '0px'; + style.borderRightWidth = '1px'; + style.borderBottomWidth = '0px'; + style.borderLeftWidth = '1px'; + + expect(style.borderTopWidth).toBe('0px'); + expect(style.borderRightWidth).toBe('1px'); + expect(style.borderBottomWidth).toBe('0px'); + expect(style.borderLeftWidth).toBe('1px'); + }); + + it('preserves previous border widths after unsupported assignments', () => { + const style = new Document(() => {}).createElement('div').style; + + for (const property of [ + 'borderTopWidth', + 'borderRightWidth', + 'borderBottomWidth', + 'borderLeftWidth', + ] as const) { + style[property] = '1px'; + + for (const value of ['2px', '-1px', '0.5px', '1ch', 'thick', 1]) { + Reflect.set(style, property, value); + expect(style[property], `${property} after ${String(value)}`).toBe('1px'); + } + } + }); + + it('supports solid and none without erasing border width or color declarations', () => { + const style = new Document(() => {}).createElement('div').style; + style.borderTopWidth = '1px'; + style.borderColor = 'blue'; + const color = style.borderColor; + style.borderStyle = 'solid'; + expect(style.borderStyle).toBe('solid'); + + style.borderStyle = 'none'; + expect(style.borderStyle).toBe('none'); + expect(style.borderTopWidth).toBe('1px'); + expect(style.borderColor).toBe(color); + + Reflect.set(style, 'borderStyle', 'dashed'); + expect(style.borderStyle).toBe('none'); + }); + + it.each(['rgb(0 205 0)', 'rgba(0, 205, 0, 0.5)', '#00cd00', 'green', 'hsl(120 100% 40%)'])( + 'accepts %s for text and border colors', + (value) => { + const style = new Document(() => {}).createElement('span').style; + const color = value as ColorValue; + style.color = color; + style.borderColor = color; + + // Valid declarations may serialize into a normalized CSS color string. + expect(style.color).toEqual(expect.any(String)); + expect(style.color).not.toBe(''); + expect(style.borderColor).toEqual(expect.any(String)); + expect(style.borderColor).not.toBe(''); + }, + ); + + it('accepts currentColor as an explicit border color declaration', () => { + const style = new Document(() => {}).createElement('div').style; + style.borderColor = 'currentColor'; + + expect(style.borderColor.toLowerCase()).toBe('currentcolor'); + expect(style.color).toBe(''); + }); + + it('preserves previous color declarations after invalid assignments', () => { + const style = new Document(() => {}).createElement('span').style; + style.color = 'green'; + style.borderColor = 'blue'; + + for (const property of ['color', 'borderColor'] as const) { + const previous = style[property]; + + for (const value of ['not-a-color', '#xyz', 'rgb(0 205)', 42]) { + Reflect.set(style, property, value); + expect(style[property], `${property} after ${String(value)}`).toBe(previous); + } + } + }); + + it('removes inline declarations when assigned an empty string', () => { + const style = new Document(() => {}).createElement('div').style; + style.display = 'inline'; + style.flexDirection = 'column'; + style.gap = '1px'; + style.paddingLeft = '2px'; + style.borderStyle = 'solid'; + style.borderLeftWidth = '1px'; + style.borderColor = 'blue'; + style.color = 'green'; + + for (const property of [ + 'display', + 'flexDirection', + 'gap', + 'paddingLeft', + 'borderStyle', + 'borderLeftWidth', + 'borderColor', + 'color', + ] as const) { + style[property] = ''; + expect(style[property], property).toBe(''); + } + }); +}); diff --git a/packages/ui/src/style.ts b/packages/ui/src/style.ts new file mode 100644 index 0000000..f99a4da --- /dev/null +++ b/packages/ui/src/style.ts @@ -0,0 +1,451 @@ +/* oxlint-disable bombshell-dev/max-params -- Style setters take a property, value, and priority. */ +/* oxlint-disable bombshell-dev/no-generic-error -- Web IDL requires TypeError for missing arguments. */ +import { parse, type names, type ParseResult } from 'hueful'; +import type { StandardSchemaV1 } from '@standard-schema/spec'; +import { asciiLowercase } from './ascii.ts'; + +/** Approximate CSS color syntax; Hueful validates the contents at runtime. */ +export type ColorValue = + | keyof typeof names + | 'transparent' + | 'currentColor' + | `#${string}` + | `${'rgb' | 'rgba' | 'hsl' | 'hsla' | 'hwb' | 'lab' | 'lch' | 'oklab' | 'oklch' | 'device-cmyk'}(${string})`; + +export type DisplayValue = 'inline' | 'flex'; + +export type FlexDirectionValue = 'row' | 'column'; + +export type LengthValue = `${number}px`; +export type BorderWidthValue = '0px' | '1px'; +export type BorderStyleValue = 'solid' | 'none'; + +export interface StyleValues { + color: StyleValue; + display: StyleValue; + flexDirection: StyleValue; + gap: StyleValue; + paddingTop: StyleValue; + paddingRight: StyleValue; + paddingBottom: StyleValue; + paddingLeft: StyleValue; + borderStyle: StyleValue; + borderTopWidth: StyleValue; + borderRightWidth: StyleValue; + borderBottomWidth: StyleValue; + borderLeftWidth: StyleValue; + borderColor: StyleValue; +} + +export interface StyleValue { + value: T; + representation: R; +} + +export class StyleDeclaration { + #values: Partial; + #important = new Set(); + #changed: () => void; + constructor(changed: () => void = () => {}) { + this.#values = {}; + this.#changed = changed; + } + + get values(): Readonly> { + return { ...this.#values }; + } + + getPropertyValue(property: string): string { + if (arguments.length === 0) { + throw new TypeError('getPropertyValue requires a property name'); + } + const key = styleProperty(`${property}`); + return key === undefined ? '' : this.#getProperty(key); + } + + getPropertyPriority(property: string): string { + if (arguments.length === 0) { + throw new TypeError('getPropertyPriority requires a property name'); + } + const key = styleProperty(`${property}`); + return key !== undefined && this.#important.has(key) ? 'important' : ''; + } + + setProperty(property: string, value: string | null, priority: string | null = ''): void { + if (arguments.length < 2) { + throw new TypeError('setProperty requires a property name and value'); + } + const name = `${property}`; + const normalValue = value === null ? '' : `${value}`; + const normalPriority = priority === null ? '' : asciiLowercase(`${priority}`); + const key = styleProperty(name); + if (key === undefined) { + return; + } + if (normalValue !== '' && normalPriority !== '' && normalPriority !== 'important') { + return; + } + this.#setProperty(key, normalValue, normalPriority === 'important'); + } + + set color(value: ColorValue | '') { + this.#setProperty('color', value); + } + + get color(): ColorValue | '' { + return this.#getProperty('color'); + } + + set display(value: DisplayValue | '') { + this.#setProperty('display', value); + } + + get display(): DisplayValue | '' { + return this.#getProperty('display'); + } + + set flexDirection(value: FlexDirectionValue | '') { + this.#setProperty('flexDirection', value); + } + + get flexDirection(): FlexDirectionValue | '' { + return this.#getProperty('flexDirection'); + } + + set 'flex-direction'(value: FlexDirectionValue | '') { + this.flexDirection = value; + } + + get 'flex-direction'(): FlexDirectionValue | '' { + return this.flexDirection; + } + + set gap(value: LengthValue | '') { + this.#setProperty('gap', value); + } + + get gap(): LengthValue | '' { + return this.#getProperty('gap'); + } + + set paddingTop(value: LengthValue | '') { + this.#setProperty('paddingTop', value); + } + + get paddingTop(): LengthValue | '' { + return this.#getProperty('paddingTop'); + } + + set 'padding-top'(value: LengthValue | '') { + this.paddingTop = value; + } + + get 'padding-top'(): LengthValue | '' { + return this.paddingTop; + } + + set paddingRight(value: LengthValue | '') { + this.#setProperty('paddingRight', value); + } + + get paddingRight(): LengthValue | '' { + return this.#getProperty('paddingRight'); + } + + set 'padding-right'(value: LengthValue | '') { + this.paddingRight = value; + } + + get 'padding-right'(): LengthValue | '' { + return this.paddingRight; + } + + set paddingBottom(value: LengthValue | '') { + this.#setProperty('paddingBottom', value); + } + + get paddingBottom(): LengthValue | '' { + return this.#getProperty('paddingBottom'); + } + + set 'padding-bottom'(value: LengthValue | '') { + this.paddingBottom = value; + } + + get 'padding-bottom'(): LengthValue | '' { + return this.paddingBottom; + } + + set paddingLeft(value: LengthValue | '') { + this.#setProperty('paddingLeft', value); + } + + get paddingLeft(): LengthValue | '' { + return this.#getProperty('paddingLeft'); + } + + set 'padding-left'(value: LengthValue | '') { + this.paddingLeft = value; + } + + get 'padding-left'(): LengthValue | '' { + return this.paddingLeft; + } + + set borderTopWidth(value: BorderWidthValue | '') { + this.#setProperty('borderTopWidth', value); + } + + get borderTopWidth(): BorderWidthValue | '' { + return this.#getProperty('borderTopWidth'); + } + + set 'border-top-width'(value: BorderWidthValue | '') { + this.borderTopWidth = value; + } + + get 'border-top-width'(): BorderWidthValue | '' { + return this.borderTopWidth; + } + + set borderRightWidth(value: BorderWidthValue | '') { + this.#setProperty('borderRightWidth', value); + } + + get borderRightWidth(): BorderWidthValue | '' { + return this.#getProperty('borderRightWidth'); + } + + set 'border-right-width'(value: BorderWidthValue | '') { + this.borderRightWidth = value; + } + + get 'border-right-width'(): BorderWidthValue | '' { + return this.borderRightWidth; + } + + set borderBottomWidth(value: BorderWidthValue | '') { + this.#setProperty('borderBottomWidth', value); + } + + get borderBottomWidth(): BorderWidthValue | '' { + return this.#getProperty('borderBottomWidth'); + } + + set 'border-bottom-width'(value: BorderWidthValue | '') { + this.borderBottomWidth = value; + } + + get 'border-bottom-width'(): BorderWidthValue | '' { + return this.borderBottomWidth; + } + + set borderLeftWidth(value: BorderWidthValue | '') { + this.#setProperty('borderLeftWidth', value); + } + + get borderLeftWidth(): BorderWidthValue | '' { + return this.#getProperty('borderLeftWidth'); + } + + set 'border-left-width'(value: BorderWidthValue | '') { + this.borderLeftWidth = value; + } + + get 'border-left-width'(): BorderWidthValue | '' { + return this.borderLeftWidth; + } + + set borderStyle(value: BorderStyleValue | '') { + this.#setProperty('borderStyle', value); + } + + get borderStyle(): BorderStyleValue | '' { + return this.#getProperty('borderStyle'); + } + + set 'border-style'(value: BorderStyleValue | '') { + this.borderStyle = value; + } + + get 'border-style'(): BorderStyleValue | '' { + return this.borderStyle; + } + + set borderColor(value: ColorValue | '') { + this.#setProperty('borderColor', value); + } + + get borderColor(): ColorValue | '' { + return this.#getProperty('borderColor'); + } + + set 'border-color'(value: ColorValue | '') { + this.borderColor = value; + } + + get 'border-color'(): ColorValue | '' { + return this.borderColor; + } + + #setProperty(key: K, input: unknown, important = false): void { + const value = input === null ? '' : `${input}`; + if (value === '') { + if (this.#values[key] !== undefined) { + delete this.#values[key]; + this.#important.delete(key); + this.#changed(); + } + return; + } + const representation = value.trim() as StyleValues[K]['representation']; + const result = propertySchemas[key]['~standard'].validate( + representation, + ) as StandardSchemaV1.Result; + + // ignore styles that can't be validated and converted; + if (result.issues) { + return; //todo: issue warning. + } + + this.#values[key] = { value: result.value, representation } as StyleValues[K]; + if (important) { + this.#important.add(key); + } else { + this.#important.delete(key); + } + this.#changed(); + } + + #getProperty(property: K): StyleValues[K]['representation'] | '' { + return this.#values[property]?.representation ?? ''; + } +} + +const propertyNames = { + color: 'color', + display: 'display', + 'flex-direction': 'flexDirection', + gap: 'gap', + 'padding-top': 'paddingTop', + 'padding-right': 'paddingRight', + 'padding-bottom': 'paddingBottom', + 'padding-left': 'paddingLeft', + 'border-style': 'borderStyle', + 'border-top-width': 'borderTopWidth', + 'border-right-width': 'borderRightWidth', + 'border-bottom-width': 'borderBottomWidth', + 'border-left-width': 'borderLeftWidth', + 'border-color': 'borderColor', +} as const satisfies Record; + +function styleProperty(property: string): keyof StyleValues | undefined { + const name = asciiLowercase(property); + return Object.hasOwn(propertyNames, name) + ? propertyNames[name as keyof typeof propertyNames] + : undefined; +} + +function parseLength(representation: LengthValue): number | null { + const value = Number(representation.slice(0, -2)); + return /^\d+px$/.test(representation) && Number.isSafeInteger(value) ? value : null; +} + +function parseBorderWidth(representation: BorderWidthValue): number | null { + const value = parseLength(representation); + return value !== null && value <= 1 ? value : null; +} + +const schema = { + enum(...values: T[]) { + return { + '~standard': { + version: 1, + vendor: '@clack/ui', + validate(input: unknown): StandardSchemaV1.Result { + const value = values.find((candidate) => candidate === input); + return value === undefined + ? { issues: [{ message: `Expected one of: ${values.join(', ')}` }] } + : { value }; + }, + }, + } satisfies StandardSchemaV1; + }, + length: { + '~standard': { + version: 1, + vendor: '@clack/ui', + validate(input: unknown): StandardSchemaV1.Result { + const value = typeof input === 'string' ? parseLength(input as LengthValue) : null; + return value === null + ? { issues: [{ message: 'Expected a nonnegative whole-cell px length' }] } + : { value }; + }, + }, + } satisfies StandardSchemaV1, + borderWidth: { + '~standard': { + version: 1, + vendor: '@clack/ui', + validate(input: unknown): StandardSchemaV1.Result { + const value = + typeof input === 'string' ? parseBorderWidth(input as BorderWidthValue) : null; + return value === null + ? { issues: [{ message: 'Expected a border width of 0px or 1px' }] } + : { value }; + }, + }, + } satisfies StandardSchemaV1, + borderColor: { + '~standard': { + version: 1, + vendor: '@clack/ui', + validate(input: unknown): StandardSchemaV1.Result { + if (input === 'currentColor') { + return { value: input }; + } + return schema.color['~standard'].validate(input); + }, + }, + } satisfies StandardSchemaV1, + + color: { + '~standard': { + version: 1, + vendor: '@clack/ui', + validate(input: unknown): StandardSchemaV1.Result { + if (typeof input !== 'string') { + return { issues: [{ message: 'Expected a CSS color string' }] }; + } + const representation = input.trim(); + if (representation === 'currentColor') { + return { value: representation }; + } + const value = parse(representation); + return value === null ? { issues: [{ message: 'Invalid CSS color' }] } : { value }; + }, + }, + } satisfies StandardSchemaV1, +}; + +const propertySchemas = { + color: schema.color, + display: schema.enum('inline', 'flex'), + flexDirection: schema.enum('row', 'column'), + gap: schema.length, + paddingTop: schema.length, + paddingRight: schema.length, + paddingBottom: schema.length, + paddingLeft: schema.length, + borderStyle: schema.enum('solid', 'none'), + borderTopWidth: schema.borderWidth, + borderRightWidth: schema.borderWidth, + borderBottomWidth: schema.borderWidth, + borderLeftWidth: schema.borderWidth, + borderColor: schema.borderColor, +} satisfies { + [K in keyof StyleValues]: StandardSchemaV1< + StyleValues[K]['representation'], + StyleValues[K]['value'] + >; +}; diff --git a/packages/ui/test/wpt.config.ts b/packages/ui/test/wpt.config.ts index 13e5088..3be3733 100644 --- a/packages/ui/test/wpt.config.ts +++ b/packages/ui/test/wpt.config.ts @@ -15,6 +15,7 @@ import { } from '../src/dom.ts'; import { NamedNodeMap } from '../src/named-node-map.ts'; import { HTMLCollection } from '../src/html-collection.ts'; +import { StyleDeclaration } from '../src/style.ts'; const config: WPTConfig = { globals: { @@ -22,6 +23,7 @@ const config: WPTConfig = { Attr, CharacterData, Comment, + CSSStyleDeclaration: StyleDeclaration, CustomEvent: globalThis.CustomEvent, Document, DOMException: globalThis.DOMException, @@ -40,6 +42,56 @@ const config: WPTConfig = { TypeError: globalThis.TypeError, }, include: { + 'css/css-align/parsing/gap-invalid.html': true, + 'css/css-backgrounds/parsing/border-color-invalid.html': true, + 'css/css-backgrounds/parsing/border-style-invalid.html': true, + 'css/css-backgrounds/parsing/border-style-valid.html': [ + 'e.style[\'border-style\'] = "none" should set the property value', + // Per-side styles and multi-value shorthands are not supported yet. + ], + 'css/css-backgrounds/parsing/border-width-valid.html': [ + 'e.style[\'border-top-width\'] = "0px" should set the property value', + // Other cases require border-width shorthand or keyword widths. + ], + 'css/css-box/parsing/padding-invalid.html': [ + 'e.style[\'padding-top\'] = "auto" should not set the property value', + 'e.style[\'padding-bottom\'] = "10px 20px calc(2em + 3ex) auto" should not set the property value', + 'e.style[\'padding-top\'] = "-10px" should not set the property value', + 'e.style[\'padding-right\'] = "-20%" should not set the property value', + // Remaining cases target padding shorthand or an unknown property. + ], + 'css/css-box/parsing/padding-valid.html': [ + 'e.style[\'padding-top\'] = "10px" should set the property value', + 'e.style[\'padding-right\'] = "20px" should set the property value', + 'e.style[\'padding-bottom\'] = "30px" should set the property value', + 'e.style[\'padding-left\'] = "40px" should set the property value', + // Shorthands, percentages, and calc() remain unsupported. + ], + 'css/css-color/parsing/color-invalid-hex-color.html': true, + 'css/css-color/parsing/color-invalid-hwb.html': true, + 'css/css-color/parsing/color-invalid-lab.html': true, + 'css/css-color/parsing/color-valid.html': [ + 'e.style[\'color\'] = "transparent" should set the property value', + 'e.style[\'color\'] = "red" should set the property value', + 'e.style[\'color\'] = "magenta" should set the property value', + 'e.style[\'color\'] = "rgb(2, 3, 4)" should set the property value', + 'e.style[\'color\'] = "rgba(2, 3, 4, 0.5)" should set the property value', + // Other cases need canonical serialization, currentcolor, or light-dark(). + ], + 'css/css-display/parsing/display-invalid.html': true, + 'css/css-display/parsing/display-valid.html': [ + 'e.style[\'display\'] = "inline" should set the property value', + 'e.style[\'display\'] = "flex" should set the property value', + // Other cases need additional display modes or multi-keyword parsing. + ], + 'css/css-flexbox/parsing/flex-direction-valid.html': [ + 'e.style[\'flex-direction\'] = "row" should set the property value', + 'e.style[\'flex-direction\'] = "column" should set the property value', + // Reverse directions require terminal layout support. + ], + 'css/css-flexbox/parsing/flex-direction-invalid.html': true, + 'css/cssom/cssstyledeclaration-properties.html': true, + 'css/cssom/cssstyledeclaration-setter-attr.html': true, 'dom/events/Event-constructors.any.js': true, 'dom/events/EventTarget-addEventListener.any.js': true, 'dom/events/EventTarget-add-remove-listener.any.js': true, diff --git a/packages/web-platform-tests/README.md b/packages/web-platform-tests/README.md index 68f1f8e..b50b60d 100644 --- a/packages/web-platform-tests/README.md +++ b/packages/web-platform-tests/README.md @@ -88,6 +88,15 @@ The suite asserts resulting DOM behavior, never browser pixel values. Browser ta Browser validation keeps upstream expectations intact. Failures remain enabled and produce a nonzero exit code. +Chromium 156 fails `css/cssom/cssstyledeclaration-properties.html` because it +exposes `color` as an own property. The pinned upstream test fails the same +assertion. This case remains enabled in both the browser and UI configurations. + +The imported `css/css-display/parsing/display-valid.html` matrix also exposes +Chromium's unsupported `run-in` and `ruby-base` values. These cases fail +identically upstream and remain enabled in browser validation; the UI selects +its supported `inline` and `flex` cases. + ### Coverage boundaries The [adapted sources](src/wpt) and generated [registry](src/shared/registry.ts) describe the executable coverage. Harness tests check source identity, case selection, and reachability of every source module. The [UI configuration](../ui/test/wpt.config.ts) records the cases enforced by that integration; the [UI test README](../ui/test/README.md) explains how to select additional cases while implementing them. Passing selected cases does not imply complete standards conformance. diff --git a/packages/web-platform-tests/src/shared/globals.ts b/packages/web-platform-tests/src/shared/globals.ts index 3e71e9b..298b090 100644 --- a/packages/web-platform-tests/src/shared/globals.ts +++ b/packages/web-platform-tests/src/shared/globals.ts @@ -7,6 +7,7 @@ export const globalNames = [ 'Array', 'Attr', 'CSSMediaRule', + 'CSSStyleDeclaration', 'CSSStyleSheet', 'CharacterData', 'Comment', diff --git a/packages/web-platform-tests/src/shared/registry.ts b/packages/web-platform-tests/src/shared/registry.ts index 347da1c..1ff9604 100644 --- a/packages/web-platform-tests/src/shared/registry.ts +++ b/packages/web-platform-tests/src/shared/registry.ts @@ -1,10 +1,27 @@ // Generated from src/wpt filenames by scripts/generate-registry.mjs. import type { CompatibilityModule } from './context.ts'; +import { register as register_css_css_align_parsing_gap_invalid_html } from '../wpt/css/css-align/parsing/gap-invalid.html.ts'; +import { register as register_css_css_backgrounds_parsing_border_color_invalid_html } from '../wpt/css/css-backgrounds/parsing/border-color-invalid.html.ts'; +import { register as register_css_css_backgrounds_parsing_border_color_valid_html } from '../wpt/css/css-backgrounds/parsing/border-color-valid.html.ts'; +import { register as register_css_css_backgrounds_parsing_border_style_invalid_html } from '../wpt/css/css-backgrounds/parsing/border-style-invalid.html.ts'; +import { register as register_css_css_backgrounds_parsing_border_style_valid_html } from '../wpt/css/css-backgrounds/parsing/border-style-valid.html.ts'; +import { register as register_css_css_backgrounds_parsing_border_width_invalid_html } from '../wpt/css/css-backgrounds/parsing/border-width-invalid.html.ts'; +import { register as register_css_css_backgrounds_parsing_border_width_valid_html } from '../wpt/css/css-backgrounds/parsing/border-width-valid.html.ts'; +import { register as register_css_css_box_parsing_padding_invalid_html } from '../wpt/css/css-box/parsing/padding-invalid.html.ts'; +import { register as register_css_css_box_parsing_padding_valid_html } from '../wpt/css/css-box/parsing/padding-valid.html.ts'; import { register as register_css_css_cascade_inherit_initial_html } from '../wpt/css/css-cascade/inherit-initial.html.ts'; import { register as register_css_css_cascade_layer_basic_html } from '../wpt/css/css-cascade/layer-basic.html.ts'; import { register as register_css_css_cascade_layer_important_html } from '../wpt/css/css-cascade/layer-important.html.ts'; import { register as register_css_css_cascade_layer_vs_inline_style_html } from '../wpt/css/css-cascade/layer-vs-inline-style.html.ts'; import { register as register_css_css_cascade_unset_value_storage_html } from '../wpt/css/css-cascade/unset-value-storage.html.ts'; +import { register as register_css_css_color_parsing_color_invalid_hex_color_html } from '../wpt/css/css-color/parsing/color-invalid-hex-color.html.ts'; +import { register as register_css_css_color_parsing_color_invalid_hwb_html } from '../wpt/css/css-color/parsing/color-invalid-hwb.html.ts'; +import { register as register_css_css_color_parsing_color_invalid_lab_html } from '../wpt/css/css-color/parsing/color-invalid-lab.html.ts'; +import { register as register_css_css_color_parsing_color_valid_html } from '../wpt/css/css-color/parsing/color-valid.html.ts'; +import { register as register_css_css_display_parsing_display_invalid_html } from '../wpt/css/css-display/parsing/display-invalid.html.ts'; +import { register as register_css_css_display_parsing_display_valid_html } from '../wpt/css/css-display/parsing/display-valid.html.ts'; +import { register as register_css_css_flexbox_parsing_flex_direction_invalid_html } from '../wpt/css/css-flexbox/parsing/flex-direction-invalid.html.ts'; +import { register as register_css_css_flexbox_parsing_flex_direction_valid_html } from '../wpt/css/css-flexbox/parsing/flex-direction-valid.html.ts'; import { register as register_css_css_variables_variable_cycles_html } from '../wpt/css/css-variables/variable-cycles.html.ts'; import { register as register_css_css_variables_variable_reference_cssom_html } from '../wpt/css/css-variables/variable-reference-cssom.html.ts'; import { register as register_css_css_variables_variable_reference_shorthands_cssom_html } from '../wpt/css/css-variables/variable-reference-shorthands-cssom.html.ts'; @@ -19,6 +36,8 @@ import { register as register_css_cssom_computed_style_set_property_html } from import { register as register_css_cssom_css_style_attr_decl_block_html } from '../wpt/css/cssom/css-style-attr-decl-block.html.ts'; import { register as register_css_cssom_css_style_attribute_modifications_html } from '../wpt/css/cssom/css-style-attribute-modifications.html.ts'; import { register as register_css_cssom_cssom_setProperty_shorthand_html } from '../wpt/css/cssom/cssom-setProperty-shorthand.html.ts'; +import { register as register_css_cssom_cssstyledeclaration_properties_html } from '../wpt/css/cssom/cssstyledeclaration-properties.html.ts'; +import { register as register_css_cssom_cssstyledeclaration_setter_attr_html } from '../wpt/css/cssom/cssstyledeclaration-setter-attr.html.ts'; import { register as register_css_selectors_focus_visible_001_html, input as input_css_selectors_focus_visible_001_html, @@ -458,11 +477,28 @@ import { register as register_xhr_formdata_constructor_submitter_html } from '.. // prettier-ignore export const registry = { + 'css/css-align/parsing/gap-invalid.html': { register: register_css_css_align_parsing_gap_invalid_html }, + 'css/css-backgrounds/parsing/border-color-invalid.html': { register: register_css_css_backgrounds_parsing_border_color_invalid_html }, + 'css/css-backgrounds/parsing/border-color-valid.html': { register: register_css_css_backgrounds_parsing_border_color_valid_html }, + 'css/css-backgrounds/parsing/border-style-invalid.html': { register: register_css_css_backgrounds_parsing_border_style_invalid_html }, + 'css/css-backgrounds/parsing/border-style-valid.html': { register: register_css_css_backgrounds_parsing_border_style_valid_html }, + 'css/css-backgrounds/parsing/border-width-invalid.html': { register: register_css_css_backgrounds_parsing_border_width_invalid_html }, + 'css/css-backgrounds/parsing/border-width-valid.html': { register: register_css_css_backgrounds_parsing_border_width_valid_html }, + 'css/css-box/parsing/padding-invalid.html': { register: register_css_css_box_parsing_padding_invalid_html }, + 'css/css-box/parsing/padding-valid.html': { register: register_css_css_box_parsing_padding_valid_html }, 'css/css-cascade/inherit-initial.html': { register: register_css_css_cascade_inherit_initial_html }, 'css/css-cascade/layer-basic.html': { register: register_css_css_cascade_layer_basic_html }, 'css/css-cascade/layer-important.html': { register: register_css_css_cascade_layer_important_html }, 'css/css-cascade/layer-vs-inline-style.html': { register: register_css_css_cascade_layer_vs_inline_style_html }, 'css/css-cascade/unset-value-storage.html': { register: register_css_css_cascade_unset_value_storage_html }, + 'css/css-color/parsing/color-invalid-hex-color.html': { register: register_css_css_color_parsing_color_invalid_hex_color_html }, + 'css/css-color/parsing/color-invalid-hwb.html': { register: register_css_css_color_parsing_color_invalid_hwb_html }, + 'css/css-color/parsing/color-invalid-lab.html': { register: register_css_css_color_parsing_color_invalid_lab_html }, + 'css/css-color/parsing/color-valid.html': { register: register_css_css_color_parsing_color_valid_html }, + 'css/css-display/parsing/display-invalid.html': { register: register_css_css_display_parsing_display_invalid_html }, + 'css/css-display/parsing/display-valid.html': { register: register_css_css_display_parsing_display_valid_html }, + 'css/css-flexbox/parsing/flex-direction-invalid.html': { register: register_css_css_flexbox_parsing_flex_direction_invalid_html }, + 'css/css-flexbox/parsing/flex-direction-valid.html': { register: register_css_css_flexbox_parsing_flex_direction_valid_html }, 'css/css-variables/variable-cycles.html': { register: register_css_css_variables_variable_cycles_html }, 'css/css-variables/variable-reference-cssom.html': { register: register_css_css_variables_variable_reference_cssom_html }, 'css/css-variables/variable-reference-shorthands-cssom.html': { register: register_css_css_variables_variable_reference_shorthands_cssom_html }, @@ -477,6 +513,8 @@ export const registry = { 'css/cssom/css-style-attr-decl-block.html': { register: register_css_cssom_css_style_attr_decl_block_html }, 'css/cssom/css-style-attribute-modifications.html': { register: register_css_cssom_css_style_attribute_modifications_html }, 'css/cssom/cssom-setProperty-shorthand.html': { register: register_css_cssom_cssom_setProperty_shorthand_html }, + 'css/cssom/cssstyledeclaration-properties.html': { register: register_css_cssom_cssstyledeclaration_properties_html }, + 'css/cssom/cssstyledeclaration-setter-attr.html': { register: register_css_cssom_cssstyledeclaration_setter_attr_html }, 'css/selectors/focus-visible-001.html': { register: register_css_selectors_focus_visible_001_html, input: input_css_selectors_focus_visible_001_html }, 'css/selectors/focus-visible-002.html': { register: register_css_selectors_focus_visible_002_html, input: input_css_selectors_focus_visible_002_html }, 'css/selectors/focus-visible-003.html': { register: register_css_selectors_focus_visible_003_html, input: input_css_selectors_focus_visible_003_html }, diff --git a/packages/web-platform-tests/src/wpt/css/css-align/parsing/gap-invalid.html.ts b/packages/web-platform-tests/src/wpt/css/css-align/parsing/gap-invalid.html.ts new file mode 100644 index 0000000..5aebea5 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-align/parsing/gap-invalid.html.ts @@ -0,0 +1,15 @@ +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_invalid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + for (const value of ['auto', '-10px', '10px 20% 30px', 'normal 10px normal']) { + context.test( + `e.style['gap'] = ${JSON.stringify(value)} should not set the property value`, + ({ document }) => { + test_invalid_value({ document, expect }, 'gap', value); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-color-invalid.html.ts b/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-color-invalid.html.ts new file mode 100644 index 0000000..888fc6f --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-color-invalid.html.ts @@ -0,0 +1,21 @@ +// Author: Eric Willigers . +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_invalid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + const values: [string, string][] = [ + ['border-color', 'auto'], + ['border-color', 'black, white'], + ['border-color', 'black white red green blue'], + ]; + for (const [property, value] of values) { + context.test( + `e.style['${property}'] = ${JSON.stringify(value)} should not set the property value`, + ({ document }) => { + test_invalid_value({ document, expect }, property, value); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-color-valid.html.ts b/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-color-valid.html.ts new file mode 100644 index 0000000..90cbbf2 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-color-valid.html.ts @@ -0,0 +1,25 @@ +// Author: Eric Willigers . +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_valid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + const values: [string, string, string?][] = [ + ['border-color', 'currentcolor', 'currentcolor'], + ['border-color', 'currentColor', 'currentcolor'], + ['border-color', 'red yellow green blue'], + ['border-top-color', 'red'], + ['border-right-color', 'yellow'], + ['border-bottom-color', 'green'], + ['border-left-color', 'blue'], + ]; + for (const [property, value, serializedValue = value] of values) { + context.test( + `e.style['${property}'] = ${JSON.stringify(value)} should set the property value`, + ({ document }) => { + test_valid_value({ document, expect }, property, value, serializedValue); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-style-invalid.html.ts b/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-style-invalid.html.ts new file mode 100644 index 0000000..8f329f1 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-style-invalid.html.ts @@ -0,0 +1,20 @@ +// Author: Eric Willigers . +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_invalid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + const values: [string, string][] = [ + ['border-style', 'auto'], + ['border-style', 'solid double groove ridge none'], + ]; + for (const [property, value] of values) { + context.test( + `e.style['${property}'] = ${JSON.stringify(value)} should not set the property value`, + ({ document }) => { + test_invalid_value({ document, expect }, property, value); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-style-valid.html.ts b/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-style-valid.html.ts new file mode 100644 index 0000000..dcd1595 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-style-valid.html.ts @@ -0,0 +1,26 @@ +// Author: Eric Willigers . +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_valid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + const values: [string, string, string?][] = [ + ['border-style', 'none'], + ['border-style', 'none hidden dotted dashed'], + ['border-style', 'solid double groove ridge'], + ['border-style', 'inset outset'], + ['border-top-style', 'solid'], + ['border-right-style', 'double'], + ['border-bottom-style', 'groove'], + ['border-left-style', 'ridge'], + ]; + for (const [property, value, serializedValue = value] of values) { + context.test( + `e.style['${property}'] = ${JSON.stringify(value)} should set the property value`, + ({ document }) => { + test_valid_value({ document, expect }, property, value, serializedValue); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-width-invalid.html.ts b/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-width-invalid.html.ts new file mode 100644 index 0000000..7619ce5 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-width-invalid.html.ts @@ -0,0 +1,21 @@ +// Author: Eric Willigers . +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_invalid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + const values: [string, string][] = [ + ['border-width', 'none'], + ['border-width', 'thin medium thick medium thin'], + ['border-width', '-1px'], + ]; + for (const [property, value] of values) { + context.test( + `e.style['${property}'] = ${JSON.stringify(value)} should not set the property value`, + ({ document }) => { + test_invalid_value({ document, expect }, property, value); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-width-valid.html.ts b/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-width-valid.html.ts new file mode 100644 index 0000000..4072a6e --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-backgrounds/parsing/border-width-valid.html.ts @@ -0,0 +1,24 @@ +// Author: Eric Willigers . +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_valid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + const values: [string, string, string?][] = [ + ['border-width', '1em'], + ['border-width', '2px thin medium thick'], + ['border-top-width', '0px'], + ['border-right-width', 'thin'], + ['border-bottom-width', 'medium'], + ['border-left-width', 'thick'], + ]; + for (const [property, value, serializedValue = value] of values) { + context.test( + `e.style['${property}'] = ${JSON.stringify(value)} should set the property value`, + ({ document }) => { + test_valid_value({ document, expect }, property, value, serializedValue); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-box/parsing/padding-invalid.html.ts b/packages/web-platform-tests/src/wpt/css/css-box/parsing/padding-invalid.html.ts new file mode 100644 index 0000000..52ec6f8 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-box/parsing/padding-invalid.html.ts @@ -0,0 +1,27 @@ +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_invalid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + const values: [string, string][] = [ + ['padding', 'auto'], + ['padding', 'available'], + ['padding', '10px border-box'], + ['padding', 'calc(2em + 3ex) auto'], + ['padding', '10px 20px 30px 40px 50px'], + ['padding-top', 'auto'], + ['padding-bottom', '10px 20px calc(2em + 3ex) auto'], + ['padding-bottom-left', '10px 20px'], + ['padding-top', '-10px'], + ['padding-right', '-20%'], + ]; + for (const [property, value] of values) { + context.test( + `e.style['${property}'] = ${JSON.stringify(value)} should not set the property value`, + ({ document }) => { + test_invalid_value({ document, expect }, property, value); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-box/parsing/padding-valid.html.ts b/packages/web-platform-tests/src/wpt/css/css-box/parsing/padding-valid.html.ts new file mode 100644 index 0000000..6655ac4 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-box/parsing/padding-valid.html.ts @@ -0,0 +1,28 @@ +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_valid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + const values: [string, string, string?][] = [ + ['padding', '10px'], + ['padding', '10px 20px 30px 40px'], + ['padding', 'calc(2em + 3ex)'], + ['padding-top', '10px'], + ['padding-right', '20px'], + ['padding-bottom', '30px'], + ['padding-left', '40px'], + ['padding', '20%'], + ['padding', '10px 20% 30% 40px'], + ['padding-right', '20%'], + ['padding-right', 'calc(2em + 3%)', 'calc(3% + 2em)'], + ]; + for (const [property, value, serializedValue = value] of values) { + context.test( + `e.style['${property}'] = ${JSON.stringify(value)} should set the property value`, + ({ document }) => { + test_valid_value({ document, expect }, property, value, serializedValue); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-color/parsing/color-invalid-hex-color.html.ts b/packages/web-platform-tests/src/wpt/css/css-color/parsing/color-invalid-hex-color.html.ts new file mode 100644 index 0000000..a9eaba3 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-color/parsing/color-invalid-hex-color.html.ts @@ -0,0 +1,29 @@ +// Author: Chris Nardi . +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_invalid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + const tests = [ + ['#', 'Should not parse invalid hex'], + ['#f', 'Should not parse invalid hex'], + ['#ff', 'Should not parse invalid hex'], + ['#ffg', 'Should not parse invalid hex'], + ['#fffg', 'Should not parse invalid hex'], + ['#fffff', 'Should not parse invalid hex'], + ['#fffffg', 'Should not parse invalid hex'], + ['#fffffff', 'Should not parse invalid hex'], + ['#fffffffg', 'Should not parse invalid hex'], + ['#fffffffff', 'Should not parse invalid hex'], + ] as const; + + for (const [value] of tests) { + context.test( + `e.style['color'] = ${JSON.stringify(value)} should not set the property value`, + ({ document }) => { + test_invalid_value({ document, expect }, 'color', value); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-color/parsing/color-invalid-hwb.html.ts b/packages/web-platform-tests/src/wpt/css/css-color/parsing/color-invalid-hwb.html.ts new file mode 100644 index 0000000..67a3720 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-color/parsing/color-invalid-hwb.html.ts @@ -0,0 +1,25 @@ +// Author: Sam Weinig . +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_invalid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + const tests = [ + ['hwba(120 30% 50%)', 'HWB syntax does not have the hwba function'], + ['hwba(120 30% 50% / 0.5)', 'HWB syntax does not have the hwba function'], + ['hwb(90deg, 50%, 50%)', 'HWB value with commas should not be parsed'], + ['hwb(90deg, 50%, 50%, 0.2)', 'HWB value with commas should not be parsed'], + ['hwb(90, 50%, 50%)', 'HWB value with commas should not be parsed'], + ['hwb(90, 50%, 50%, 0.2)', 'HWB value with commas should not be parsed'], + ] as const; + + for (const [value] of tests) { + context.test( + `e.style['color'] = ${JSON.stringify(value)} should not set the property value`, + ({ document }) => { + test_invalid_value({ document, expect }, 'color', value); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-color/parsing/color-invalid-lab.html.ts b/packages/web-platform-tests/src/wpt/css/css-color/parsing/color-invalid-lab.html.ts new file mode 100644 index 0000000..4dc28f3 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-color/parsing/color-invalid-lab.html.ts @@ -0,0 +1,39 @@ +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_invalid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + for (const colorSpace of ['lab', 'oklab']) { + for (const value of [ + `${colorSpace}(0% 0 0 1)`, + `${colorSpace}(0% 0 0 10%)`, + `${colorSpace}(0% 0 0deg)`, + `${colorSpace}(0% 0% 0deg)`, + `${colorSpace}(40% 0 0deg)`, + `color(${colorSpace} 20% 0 10 / 50%)`, + ]) { + context.test( + `e.style['color'] = ${JSON.stringify(value)} should not set the property value`, + ({ document }) => { + test_invalid_value({ document, expect }, 'color', value); + }, + ); + } + } + + for (const colorSpace of ['lch', 'oklch']) { + for (const value of [ + `${colorSpace}(20% 10 10deg 10)`, + `${colorSpace}(20% 10 10deg 10 / 0.5)`, + `color(${colorSpace} 20% 0 10 / 50%)`, + ]) { + context.test( + `e.style['color'] = ${JSON.stringify(value)} should not set the property value`, + ({ document }) => { + test_invalid_value({ document, expect }, 'color', value); + }, + ); + } + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-color/parsing/color-valid.html.ts b/packages/web-platform-tests/src/wpt/css/css-color/parsing/color-valid.html.ts new file mode 100644 index 0000000..0576d32 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-color/parsing/color-valid.html.ts @@ -0,0 +1,36 @@ +// Author: Eric Willigers . +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_valid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + const tests: ReadonlyArray = [ + ['currentcolor'], + ['transparent'], + ['red'], + ['magenta'], + ['#234', 'rgb(34, 51, 68)'], + ['#FEDCBA', 'rgb(254, 220, 186)'], + ['rgb(2, 3, 4)'], + ['rgb(100%, 0%, 0%)', 'rgb(255, 0, 0)'], + ['rgba(2, 3, 4, 0.5)'], + ['rgba(2, 3, 4, 50%)', 'rgba(2, 3, 4, 0.5)'], + ['hsl(120, 100%, 50%)', 'rgb(0, 255, 0)'], + ['hsla(120, 100%, 50%, 0.25)', 'rgba(0, 255, 0, 0.25)'], + ['rgb(-2, 3, 4)', 'rgb(0, 3, 4)'], + ['rgb(100, 200, 300)', 'rgb(100, 200, 255)'], + ['rgb(20, 10, 0, -10)', 'rgba(20, 10, 0, 0)'], + ['rgb(100%, 200%, 300%)', 'rgb(255, 255, 255)'], + ['light-dark(black, white)'], + ]; + + for (const [value, serializedValue] of tests) { + context.test( + `e.style['color'] = ${JSON.stringify(value)} should set the property value`, + ({ document }) => { + test_valid_value({ document, expect }, 'color', value, serializedValue); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-display/parsing/display-invalid.html.ts b/packages/web-platform-tests/src/wpt/css/css-display/parsing/display-invalid.html.ts new file mode 100644 index 0000000..fde6ab7 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-display/parsing/display-invalid.html.ts @@ -0,0 +1,72 @@ +// Author: Eric Willigers . +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_invalid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + for (const value of [ + 'grid inline-grid', + 'none grid', + 'none flow', + 'none ruby', + 'none flow-root', + 'none list-item', + 'contents list-item', + 'list-item contents', + 'flow flow', + 'block block', + 'flow flow-root', + 'flow-root flow-root', + 'block inline', + 'flex ruby', + 'ruby flex', + 'inline inline', + 'flex flex', + 'grid flex', + 'ruby grid', + 'flex grid', + 'grid table', + 'table flex', + 'flex table', + 'ruby table', + 'table table', + 'table flow-root', + 'flow-root ruby', + 'list-item list-item', + 'list-item table', + 'flex list-item', + 'list-item grid', + 'flow flow list-item', + 'grid flow list-item', + 'flow list-item flow', + 'block list-item block', + 'list-item flow-root flow', + 'list-item block block', + 'list-item block list-item', + 'list-item flow-root list-item', + 'list-item flow-root block list-item', + 'list-item block flow-root list-item', + 'block list-item flow-root list-item', + 'flow-root list-item block list-item', + 'list-item ruby', + 'ruby list-item', + 'ruby ruby', + 'ruby flow', + 'flow ruby', + 'ruby flow-root', + 'grid ruby', + 'table ruby', + 'table-row flow', + 'flow table-row', + 'table-row-group flow-root', + 'flex table-row-group', + ]) { + context.test( + `e.style['display'] = ${JSON.stringify(value)} should not set the property value`, + ({ document }) => { + test_invalid_value({ document, expect }, 'display', value); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-display/parsing/display-valid.html.ts b/packages/web-platform-tests/src/wpt/css/css-display/parsing/display-valid.html.ts new file mode 100644 index 0000000..cda9a87 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-display/parsing/display-valid.html.ts @@ -0,0 +1,126 @@ +// Author: Eric Willigers . +// Helper: /css/support/parsing-testcommon.js. +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_valid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + const values: [string, string?][] = [ + ['grid'], + ['inline-grid'], + ['inline'], + ['block'], + ['list-item'], + ['inline-block'], + ['table'], + ['inline-table'], + ['table-row-group'], + ['table-header-group'], + ['table-footer-group'], + ['table-row'], + ['table-column-group'], + ['table-column'], + ['table-cell'], + ['table-caption'], + ['none'], + ['flex'], + ['inline-flex'], + ['contents'], + ['run-in'], + ['flow', 'block'], + ['flow-root'], + ['ruby'], + ['ruby-base'], + ['ruby-text'], + ['flow list-item', 'list-item'], + ['list-item flow', 'list-item'], + ['flow-root list-item', 'flow-root list-item'], + ['list-item flow-root', 'flow-root list-item'], + ['block flow', 'block'], + ['flow block', 'block'], + ['flow-root block', 'flow-root'], + ['block flow-root', 'flow-root'], + ['flex block', 'flex'], + ['block flex', 'flex'], + ['grid block', 'grid'], + ['block grid', 'grid'], + ['table block', 'table'], + ['block table', 'table'], + ['block ruby', 'block ruby'], + ['ruby block', 'block ruby'], + ['block list-item', 'list-item'], + ['list-item block', 'list-item'], + ['flow block list-item', 'list-item'], + ['block flow list-item', 'list-item'], + ['flow list-item block', 'list-item'], + ['block list-item flow', 'list-item'], + ['list-item block flow', 'list-item'], + ['list-item flow block', 'list-item'], + ['flow-root block list-item', 'flow-root list-item'], + ['block flow-root list-item', 'flow-root list-item'], + ['flow-root list-item block', 'flow-root list-item'], + ['block list-item flow-root', 'flow-root list-item'], + ['list-item block flow-root', 'flow-root list-item'], + ['list-item flow-root block', 'flow-root list-item'], + ['inline flow', 'inline'], + ['flow inline', 'inline'], + ['flow-root inline', 'inline-block'], + ['inline flow-root', 'inline-block'], + ['flex inline', 'inline-flex'], + ['inline flex', 'inline-flex'], + ['grid inline', 'inline-grid'], + ['inline grid', 'inline-grid'], + ['table inline', 'inline-table'], + ['inline table', 'inline-table'], + ['inline ruby', 'ruby'], + ['ruby inline', 'ruby'], + ['inline list-item', 'inline list-item'], + ['list-item inline', 'inline list-item'], + ['flow inline list-item', 'inline list-item'], + ['inline flow list-item', 'inline list-item'], + ['flow list-item inline', 'inline list-item'], + ['inline list-item flow', 'inline list-item'], + ['list-item inline flow', 'inline list-item'], + ['list-item flow inline', 'inline list-item'], + ['flow-root inline list-item', 'inline flow-root list-item'], + ['inline flow-root list-item', 'inline flow-root list-item'], + ['flow-root list-item inline', 'inline flow-root list-item'], + ['inline list-item flow-root', 'inline flow-root list-item'], + ['list-item inline flow-root', 'inline flow-root list-item'], + ['list-item flow-root inline', 'inline flow-root list-item'], + ['run-in flow', 'run-in'], + ['flow run-in', 'run-in'], + ['flow-root run-in', 'run-in flow-root'], + ['run-in flow-root', 'run-in flow-root'], + ['flex run-in', 'run-in flex'], + ['run-in flex', 'run-in flex'], + ['grid run-in', 'run-in grid'], + ['run-in grid', 'run-in grid'], + ['table run-in', 'run-in table'], + ['run-in table', 'run-in table'], + ['run-in ruby', 'run-in ruby'], + ['ruby run-in', 'run-in ruby'], + ['run-in list-item', 'run-in list-item'], + ['list-item run-in', 'run-in list-item'], + ['flow run-in list-item', 'run-in list-item'], + ['run-in flow list-item', 'run-in list-item'], + ['flow list-item run-in', 'run-in list-item'], + ['run-in list-item flow', 'run-in list-item'], + ['list-item run-in flow', 'run-in list-item'], + ['list-item flow run-in', 'run-in list-item'], + ['flow-root run-in list-item', 'run-in flow-root list-item'], + ['run-in flow-root list-item', 'run-in flow-root list-item'], + ['flow-root list-item run-in', 'run-in flow-root list-item'], + ['run-in list-item flow-root', 'run-in flow-root list-item'], + ['list-item run-in flow-root', 'run-in flow-root list-item'], + ['list-item flow-root run-in', 'run-in flow-root list-item'], + ]; + for (const [value, serializedValue = value] of values) { + context.test( + `e.style['display'] = ${JSON.stringify(value)} should set the property value`, + ({ document }) => { + test_valid_value({ document, expect }, 'display', value, serializedValue); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-flexbox/parsing/flex-direction-invalid.html.ts b/packages/web-platform-tests/src/wpt/css/css-flexbox/parsing/flex-direction-invalid.html.ts new file mode 100644 index 0000000..82d68d8 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-flexbox/parsing/flex-direction-invalid.html.ts @@ -0,0 +1,15 @@ +// Author: Eric Willigers . +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_invalid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + for (const value of ['auto', 'column row-reverse']) { + context.test( + `e.style['flex-direction'] = ${JSON.stringify(value)} should not set the property value`, + ({ document }) => { + test_invalid_value({ document, expect }, 'flex-direction', value); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/css-flexbox/parsing/flex-direction-valid.html.ts b/packages/web-platform-tests/src/wpt/css/css-flexbox/parsing/flex-direction-valid.html.ts new file mode 100644 index 0000000..77b103c --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/css-flexbox/parsing/flex-direction-valid.html.ts @@ -0,0 +1,15 @@ +// Author: Eric Willigers . +import type { CompatibilityContext } from '../../../../shared/context.ts'; +import { test_valid_value } from '../../support/parsing-testcommon.js.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + for (const value of ['row', 'row-reverse', 'column', 'column-reverse']) { + context.test( + `e.style['flex-direction'] = ${JSON.stringify(value)} should set the property value`, + ({ document }) => { + test_valid_value({ document, expect }, 'flex-direction', value); + }, + ); + } +} diff --git a/packages/web-platform-tests/src/wpt/css/cssom/cssstyledeclaration-properties.html.ts b/packages/web-platform-tests/src/wpt/css/cssom/cssstyledeclaration-properties.html.ts new file mode 100644 index 0000000..1673995 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/cssom/cssstyledeclaration-properties.html.ts @@ -0,0 +1,20 @@ +// Author: Emilio Cobos Álvarez , Mozilla. +import type { CompatibilityContext } from '../../../shared/context.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + context.test( + 'CSS Test: CSSStyleDeclaration properties are defined as WebIDL attributes, not using getOwnPropertyNames()', + ({ document, CSSStyleDeclaration }) => { + const declaration = document.documentElement.style; + expect(declaration instanceof CSSStyleDeclaration, 'Should be a CSStyleDeclaration').toBe( + true, + ); + expect('color' in declaration, 'Should support the color property').toBe(true); + expect( + declaration.hasOwnProperty('color'), + "shouldn't have an own property for WebIDL attributes", + ).toBe(false); + }, + ); +} diff --git a/packages/web-platform-tests/src/wpt/css/cssom/cssstyledeclaration-setter-attr.html.ts b/packages/web-platform-tests/src/wpt/css/cssom/cssstyledeclaration-setter-attr.html.ts new file mode 100644 index 0000000..f0f2b64 --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/cssom/cssstyledeclaration-setter-attr.html.ts @@ -0,0 +1,22 @@ +// Author: Emilio Cobos Álvarez . +import type { CompatibilityContext } from '../../../shared/context.ts'; + +export function register(context: CompatibilityContext): void { + const { expect } = context.runner; + context.test( + "Setting an invalid property via the declaration setter doesn't create a declaration", + ({ document }) => { + const element = document.createElement('div'); + element.style.setProperty('doesntexist', '0'); + expect(element.hasAttribute('style')).toBe(false); + }, + ); + context.test( + "Setting an invalid value via the declaration setter doesn't create a declaration", + ({ document }) => { + const element = document.createElement('div'); + element.style.setProperty('width', '-100'); + expect(element.hasAttribute('style')).toBe(false); + }, + ); +} diff --git a/packages/web-platform-tests/src/wpt/css/support/parsing-testcommon.js.ts b/packages/web-platform-tests/src/wpt/css/support/parsing-testcommon.js.ts new file mode 100644 index 0000000..b3e38ff --- /dev/null +++ b/packages/web-platform-tests/src/wpt/css/support/parsing-testcommon.js.ts @@ -0,0 +1,39 @@ +import type { CompatibilityExpect } from '../../../shared/context.ts'; + +interface ParsingContext { + document: Document; + expect: CompatibilityExpect; +} + +// The source entrypoints register the cases; these are the callback bodies of +// the upstream value-parsing helpers with string expected serializations. +// oxlint-disable-next-line bombshell-dev/max-params -- Keep upstream property, input, and expected serialization arguments. +export function test_valid_value( + { document, expect }: ParsingContext, + property: string, + value: string, + serializedValue = value, +): void { + const div = document.getElementById('target') || document.createElement('div'); + const style = div.style as CSSStyleDeclaration & Record; + style[property] = ''; + style[property] = value; + const readValue = style.getPropertyValue(property); + expect(readValue, 'property should be set').not.toBe(''); + expect(readValue, 'serialization should be canonical').toBe(serializedValue); + + style[property] = readValue; + expect(style.getPropertyValue(property), 'serialization should round-trip').toBe(readValue); +} + +export function test_invalid_value( + { document, expect }: ParsingContext, + property: string, + value: string, +): void { + const div = document.getElementById('target') || document.createElement('div'); + const style = div.style as CSSStyleDeclaration & Record; + style[property] = ''; + style[property] = value; + expect(style.getPropertyValue(property)).toBe(''); +} diff --git a/packages/web-platform-tests/test/browser/wpt.config.ts b/packages/web-platform-tests/test/browser/wpt.config.ts index 97389c7..ccc6eba 100644 --- a/packages/web-platform-tests/test/browser/wpt.config.ts +++ b/packages/web-platform-tests/test/browser/wpt.config.ts @@ -23,7 +23,9 @@ export function browserWPTConfig( if (input && inputOnly) { config.exclude = { '**': true }; config.include = inputCases; - } else config.exclude = inputCases; + } else { + config.exclude = inputCases; + } return config; } @@ -118,6 +120,7 @@ function browserGlobals(fixtureDocument: Document): DOMGlobalBindings { NodeList: view.NodeList, TypeError: view.TypeError, CSSStyleSheet: view.CSSStyleSheet, + CSSStyleDeclaration: view.CSSStyleDeclaration, CSSMediaRule: view.CSSMediaRule, ShadowRoot: view.ShadowRoot, DOMParser: view.DOMParser, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7597c3f..979a399 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,6 +44,12 @@ importers: '@bomb.sh/tty': specifier: 'catalog:' version: 0.10.0 + '@standard-schema/spec': + specifier: ^1.1.0 + version: 1.1.0 + hueful: + specifier: ^0.8.1 + version: 0.8.1 devDependencies: '@bomb.sh/web-platform-tests': specifier: workspace:* @@ -1449,6 +1455,9 @@ packages: resolution: {integrity: sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==} engines: {node: '>= 6'} + hueful@0.8.1: + resolution: {integrity: sha512-5JmU/74TAKM9BCRcwY046VImUb6dhvrsB2kvj5eEJ1eaCKu6EPPxtONF/kueY9PdzYgUz3g5zrrj+YENz2xy3A==} + human-id@4.2.2: resolution: {integrity: sha512-Z+8unD6em/MJwyrkWQ2M3wygRGI1+MztbutiNwk1DCuEPXOZRWGjtcMPZYP1exY9iNZMhd7ZOSMQSo9WYtiQRw==} hasBin: true @@ -3007,6 +3016,8 @@ snapshots: transitivePeerDependencies: - supports-color + hueful@0.8.1: {} + human-id@4.2.2: {} import-meta-resolve@4.2.0: {}