Style

An element's style as a binding builds it: its starting style, what it's drawn with before any animation runs, from its initial (or its animate, with initial: false); how an app's own style and Wardic's are layered (over, without); and a drag element's default style. A server render draws the starting style, so an element is drawn where it starts before any code runs.

import * as Style from "@wardic/dom/Style"

const start = Style.resolveInitial({ initial: { opacity: 0, y: 8 }, animate: { opacity: 1, y: 0 } })
Style.starting(undefined, start) // { style: { transform: "translateY(8px)", opacity: 0 }, attrs: {} }

Type Aliases

DragDefaults

type DragDefaults = Readonly<Record<string, string>>;

A drag element's default style for its axis.


Input

type Input = object | string | undefined;

A style as a binding hands it over: a record of CSS properties, CSS text ("color: red", which JSX allows), or none.


Style

type Style = Readonly<Record<string, unknown>>;

A style record: CSS properties to their values.

Variables

DRAG_DEFAULT_ATTRIBUTES

const DRAG_DEFAULT_ATTRIBUTES: Readonly<{
  draggable: "false";
}>;

The attribute every drag element gets: no native drag of the element or its content.


dragDefaults

const dragDefaults: (axis) => DragDefaults;

The default style of a drag element: touch-action none for a free drag, pan-y for an x drag and pan-x for a y drag, with no text selection or iOS callout. One frozen object per axis.

Parameters

axis

boolean | "x" | "y"

Returns

DragDefaults


heldTouches

const heldTouches: {
  (prev, next): (self) => boolean;
  (self, prev, next): boolean;
};

Whether the keys the flush gate holds, changing from prev to next, change self's without: whether a key taken or let go of is one self sets, by its name or its name dash-cased. Most changes touch none, and a binding then leaves its style alone.

Call Signature

(prev, next): (self) => boolean;
Parameters
prev

readonly string[]

next

readonly string[]

Returns

(self) => boolean

Call Signature

(
   self, 
   prev, 
   next
): boolean;
Parameters
self

Style

prev

readonly string[]

next

readonly string[]

Returns

boolean


over

const over: {
  (that): (self) => Style;
  (self, that): Style;
};

self laid over that: self's keys win, and that's others stay. A chain reads from the top layer down: an element's style is its drag defaults, under its base, under the app's, under what Wardic animates. A side given as CSS text is parsed, so a framework never writes cssText over the keys Wardic holds, and a side that's undefined leaves the other as it is, the same object. Whatever self sets for user-select or -webkit-user-select it sets for both: one property in Chromium.

Call Signature

(that): (self) => Style;
Parameters
that

Input

Returns

(self) => Style

Call Signature

(self, that): Style;
Parameters
self

Input

that

Input

Returns

Style

Example

// Before the first commit: the starting style over the app's, over a base and a drag element's defaults.
pipe(starting, Style.over(user), Style.over(base), Style.over(Style.dragDefaults("x")))

reorderTouchAction

const reorderTouchAction: (axis) => string;

A Reorder group item's touch-action for the group's axis: a y list keeps sideways panning, an x row vertical panning, and a grid none.

Parameters

axis

"x" | "y" | "xy"

Returns

string


without

const without: {
  (held): (self) => Style;
  (self, held): Style;
};

self without the keys the flush gate holds on the element (held, by patch key, matched by CSS property): the style once its first frame is committed. Wardic writes those while it drives them, and the app's style is their fallback, so a key the gate lets go of comes back.

Call Signature

(held): (self) => Style;
Parameters
held

readonly string[]

Returns

(self) => Style

Call Signature

(self, held): Style;
Parameters
self

Input

held

readonly string[]

Returns

Style

Example

pipe(user, Style.over(base), Style.without(held))

Functions

starting()

function starting(tag, values): SplitPatch;

The starting style of a tag element starting from values: projected as the renderer projects a Frame, then split by tag, an SVG element's keys inside an <svg> as attributes, and the rest as style. undefined is an HTML element, as for a spread that doesn't know its tag.

Parameters

tag

string | undefined

values

Readonly<Record<string, unknown>>

Returns

SplitPatch

References

InitialConfig

Renames and re-exports failure


keyframesOf

Renames and re-exports failure


resolveInitial

Renames and re-exports failure


splitValues

Renames and re-exports failure


SplitValues

Renames and re-exports failure


StopAt

Renames and re-exports failure


Stops

Renames and re-exports failure


toValues

Renames and re-exports failure


valuesAt

Renames and re-exports failure