rift-ds 1.24.0 → 1.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/chat/ChatThreads.d.ts +3 -1
- package/chat/ChatThreads.js +3 -1
- package/chat/ChatWidget.css +166 -15
- package/chat/ChatWidget.d.ts +6 -2
- package/chat/ChatWidget.js +17 -3
- package/components/ActionCard/ActionCard.d.ts +1 -1
- package/components/Attachment/Attachment.css +8 -0
- package/components/Attachment/AttachmentViewer.js +26 -5
- package/components/Attachment/fileTypes.d.ts +4 -0
- package/components/ContextMenu/ContextMenu.css +11 -0
- package/components/ContextMenu/ContextMenu.d.ts +1 -1
- package/components/ContextMenu/ContextMenu.js +3 -1
- package/components/CurrencyInput/CurrencyInput.css +12 -0
- package/components/CurrencyInput/CurrencyInput.d.ts +51 -0
- package/components/CurrencyInput/CurrencyInput.js +158 -0
- package/components/DataTable/columnTypes.js +4 -16
- package/components/DatePicker/DatePicker.d.ts +2 -0
- package/components/DatePicker/DatePicker.js +44 -131
- package/components/DatePicker/MonthGrid.d.ts +56 -0
- package/components/DatePicker/MonthGrid.js +65 -0
- package/components/DatePicker/calendar.d.ts +42 -0
- package/components/DatePicker/calendar.js +108 -0
- package/components/DateRangePicker/DateRangePicker.css +92 -0
- package/components/DateRangePicker/DateRangePicker.d.ts +86 -0
- package/components/DateRangePicker/DateRangePicker.js +294 -0
- package/components/Deadline/Deadline.css +82 -0
- package/components/Deadline/Deadline.d.ts +44 -0
- package/components/Deadline/Deadline.js +94 -0
- package/components/Deadline/deadlineStatus.d.ts +15 -0
- package/components/Deadline/deadlineStatus.js +13 -0
- package/components/DescriptionList/DescriptionList.css +184 -0
- package/components/DescriptionList/DescriptionList.d.ts +64 -0
- package/components/DescriptionList/DescriptionList.js +100 -0
- package/components/DescriptionList/DescriptionListCopy.d.ts +18 -0
- package/components/DescriptionList/DescriptionListCopy.js +45 -0
- package/components/DocumentViewer/DocumentViewer.css +188 -0
- package/components/DocumentViewer/DocumentViewer.d.ts +59 -0
- package/components/DocumentViewer/DocumentViewer.js +185 -0
- package/components/DropdownMenu/DropdownMenu.css +38 -0
- package/components/DropdownMenu/DropdownMenu.d.ts +4 -0
- package/components/DropdownMenu/DropdownMenu.js +11 -5
- package/components/DropdownMenu/ShortcutHint.d.ts +9 -0
- package/components/DropdownMenu/ShortcutHint.js +6 -0
- package/components/ErrorSummary/ErrorSummary.css +94 -0
- package/components/ErrorSummary/ErrorSummary.d.ts +34 -0
- package/components/ErrorSummary/ErrorSummary.js +70 -0
- package/components/ErrorSummary/fieldErrors.d.ts +36 -0
- package/components/ErrorSummary/fieldErrors.js +19 -0
- package/components/Field/Field.css +12 -0
- package/components/Field/Field.d.ts +10 -2
- package/components/Field/Field.js +12 -5
- package/components/Heading/Heading.css +129 -0
- package/components/Heading/Heading.d.ts +31 -0
- package/components/Heading/Heading.js +39 -0
- package/components/Input/Input.css +120 -0
- package/components/Input/Input.d.ts +20 -1
- package/components/Input/Input.js +70 -5
- package/components/InterruptCard/InterruptCard.d.ts +1 -1
- package/components/Link/Link.css +84 -0
- package/components/Link/Link.d.ts +43 -0
- package/components/Link/Link.js +74 -0
- package/components/List/List.css +173 -0
- package/components/List/List.d.ts +44 -0
- package/components/List/List.js +60 -0
- package/components/MaskedInput/MaskedInput.css +16 -0
- package/components/MaskedInput/MaskedInput.d.ts +57 -0
- package/components/MaskedInput/MaskedInput.js +142 -0
- package/components/MaskedInput/mask.d.ts +58 -0
- package/components/MaskedInput/mask.js +106 -0
- package/components/MessageCard/MessageCard.css +17 -6
- package/components/MessageCard/MessageCard.d.ts +1 -1
- package/components/ShaderScene/ShaderScene.css +19 -0
- package/components/ShaderScene/ShaderScene.d.ts +82 -0
- package/components/ShaderScene/ShaderScene.js +167 -0
- package/components/ShaderScene/assemble.d.ts +5 -0
- package/components/ShaderScene/assemble.js +76 -0
- package/components/ShaderScene/common.glsl.d.ts +6 -0
- package/components/ShaderScene/common.glsl.js +49 -0
- package/components/ShaderScene/passes.d.ts +2 -0
- package/components/ShaderScene/passes.js +93 -0
- package/components/ShaderScene/renderer.d.ts +39 -0
- package/components/ShaderScene/renderer.js +170 -0
- package/components/ShaderScene/scenes.d.ts +76 -0
- package/components/ShaderScene/scenes.js +752 -0
- package/components/ShaderScene/types.d.ts +83 -0
- package/components/ShaderScene/types.js +8 -0
- package/components/SignaturePad/SignaturePad.css +141 -0
- package/components/SignaturePad/SignaturePad.d.ts +68 -0
- package/components/SignaturePad/SignaturePad.js +287 -0
- package/components/SignaturePad/signature.d.ts +32 -0
- package/components/SignaturePad/signature.js +46 -0
- package/components/Text/Text.css +129 -0
- package/components/Text/Text.d.ts +36 -0
- package/components/Text/Text.js +36 -0
- package/components/ThreadPanel/ThreadPanel.css +29 -0
- package/components/ThreadPanel/ThreadPanel.d.ts +2 -0
- package/components/ThreadPanel/ThreadPanel.js +13 -2
- package/components/Widget/Widget.css +111 -0
- package/components/Widget/Widget.d.ts +15 -1
- package/components/Widget/Widget.js +63 -11
- package/components/Widget/WidgetDisclosure.d.ts +30 -0
- package/components/Widget/WidgetDisclosure.js +52 -0
- package/components/registry.json +111 -2
- package/components/registry.json.d.ts +111 -2
- package/components/registry.json.js +2 -2
- package/format/index.d.ts +15 -0
- package/format/index.js +17 -0
- package/format/money.d.ts +89 -0
- package/format/money.js +187 -0
- package/format/relative.d.ts +49 -0
- package/format/relative.js +50 -0
- package/index.d.ts +13 -0
- package/index.js +48 -1
- package/package.json +9 -2
- package/tokens/motion.d.ts +4 -0
- package/tokens/motion.js +4 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { Mask } from './mask';
|
|
3
|
+
/** Props owned by MaskedInput itself; everything else falls through to the visible `<input>`. */
|
|
4
|
+
type MaskedInputOwnProps = {
|
|
5
|
+
/** Label text above the field. */
|
|
6
|
+
label?: string;
|
|
7
|
+
/** The shape of the value: a pattern where `#` takes a digit, `A` a letter and `*` either (`'(###) ###-####'`), or a function from the raw characters to the shown text. `MASK_PRESETS` holds common patterns. */
|
|
8
|
+
mask: Mask;
|
|
9
|
+
/** The raw value, the characters without the mask's separators (`"5550100199"`) (controlled). Pair with `onValueChange`. */
|
|
10
|
+
value?: string;
|
|
11
|
+
/** The raw value the field starts with (uncontrolled). */
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
/** Called with the raw value and the shown text as the reader types. Fires alongside the native `onChange`. */
|
|
14
|
+
onValueChange?: (value: string, formatted: string) => void;
|
|
15
|
+
/** Hide the value as dots until it is revealed: a tax ID, a card number. Defaults `autoComplete` to `off`. */
|
|
16
|
+
sensitive?: boolean;
|
|
17
|
+
/** Add a show and hide button to a sensitive field. */
|
|
18
|
+
revealable?: boolean;
|
|
19
|
+
/** Whether a sensitive value is shown (controlled). Pair with `onRevealedChange`. */
|
|
20
|
+
revealed?: boolean;
|
|
21
|
+
/** Whether a sensitive value starts shown (uncontrolled). Defaults to false. */
|
|
22
|
+
defaultRevealed?: boolean;
|
|
23
|
+
/** Called with the new state when the reader shows or hides the value, or it hides itself. */
|
|
24
|
+
onRevealedChange?: (revealed: boolean) => void;
|
|
25
|
+
/** How many of the last characters of a hidden value stay readable while the field is not focused, so a reader can tell which card it is. Defaults to 0. */
|
|
26
|
+
visibleTail?: number;
|
|
27
|
+
/** Hide a revealed value again after this many milliseconds, or after the library's reveal timeout with `true`. Off by default. */
|
|
28
|
+
autoHideAfter?: number | boolean;
|
|
29
|
+
/** Accessible name of the reveal button while the value is hidden. Defaults to "Show". */
|
|
30
|
+
showLabel?: string;
|
|
31
|
+
/** Accessible name of the reveal button while the value is shown. Defaults to "Hide". */
|
|
32
|
+
hideLabel?: string;
|
|
33
|
+
/** Component size (not the native character-width `size` attribute). */
|
|
34
|
+
size?: 'default' | 'compact';
|
|
35
|
+
/** Helper text below the field. */
|
|
36
|
+
helperText?: string;
|
|
37
|
+
/** The error message under the field; setting it marks the field invalid. */
|
|
38
|
+
errorText?: React.ReactNode;
|
|
39
|
+
/** Error state without a message of its own. */
|
|
40
|
+
error?: boolean;
|
|
41
|
+
/** The form field name. The form receives the raw value through a hidden input, never the shown text. */
|
|
42
|
+
name?: string;
|
|
43
|
+
/** Additional CSS classes, applied to the wrapper. */
|
|
44
|
+
className?: string;
|
|
45
|
+
};
|
|
46
|
+
export interface MaskedInputProps extends MaskedInputOwnProps, Omit<React.ComponentPropsWithRef<'input'>, keyof MaskedInputOwnProps | 'type' | 'prefix'> {
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A field that writes its value into a shape as the reader types: a phone
|
|
50
|
+
* number, a card number, an ID number, a licence key. The value is the raw
|
|
51
|
+
* characters; the separators are the field's, the caret holds its place
|
|
52
|
+
* across them, and a paste is cleaned up. A sensitive value hides as dots
|
|
53
|
+
* until the reader shows it.
|
|
54
|
+
*/
|
|
55
|
+
export declare function MaskedInput({ label, mask, value: valueProp, defaultValue, onValueChange, sensitive, revealable, revealed: revealedProp, defaultRevealed, onRevealedChange, visibleTail, autoHideAfter, showLabel, hideLabel, size, helperText, errorText, error, name, disabled, className, onChange, onFocus, onBlur, ref, ...rest }: MaskedInputProps): React.JSX.Element;
|
|
56
|
+
export { MASK_PRESETS, applyMask } from './mask';
|
|
57
|
+
export type { Mask, Masked } from './mask';
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useMemo, useRef, useLayoutEffect, useEffect } from "react";
|
|
4
|
+
import { Input } from "../Input/Input.js";
|
|
5
|
+
import { CircularButton } from "../CircularButton/CircularButton.js";
|
|
6
|
+
import { MOTION_SENSITIVE_HIDE_MS } from "../../tokens/motion.js";
|
|
7
|
+
import { applyMask, concealMasked, maskIsNumeric, readEdit, maskCapacity, caretFor } from "./mask.js";
|
|
8
|
+
import { MASK_PRESETS } from "./mask.js";
|
|
9
|
+
import "./MaskedInput.css";
|
|
10
|
+
function MaskedInput({
|
|
11
|
+
label,
|
|
12
|
+
mask,
|
|
13
|
+
value: valueProp,
|
|
14
|
+
defaultValue = "",
|
|
15
|
+
onValueChange,
|
|
16
|
+
sensitive = false,
|
|
17
|
+
revealable = false,
|
|
18
|
+
revealed: revealedProp,
|
|
19
|
+
defaultRevealed = false,
|
|
20
|
+
onRevealedChange,
|
|
21
|
+
visibleTail = 0,
|
|
22
|
+
autoHideAfter = false,
|
|
23
|
+
showLabel = "Show",
|
|
24
|
+
hideLabel = "Hide",
|
|
25
|
+
size = "default",
|
|
26
|
+
helperText,
|
|
27
|
+
errorText,
|
|
28
|
+
error,
|
|
29
|
+
name,
|
|
30
|
+
disabled,
|
|
31
|
+
className = "",
|
|
32
|
+
onChange,
|
|
33
|
+
onFocus,
|
|
34
|
+
onBlur,
|
|
35
|
+
ref,
|
|
36
|
+
...rest
|
|
37
|
+
}) {
|
|
38
|
+
const controlled = valueProp !== void 0;
|
|
39
|
+
const [uncontrolled, setUncontrolled] = useState(() => applyMask(defaultValue, mask).raw);
|
|
40
|
+
const raw = controlled ? applyMask(valueProp, mask).raw : uncontrolled;
|
|
41
|
+
const masked = useMemo(() => applyMask(raw, mask), [raw, mask]);
|
|
42
|
+
const revealControlled = revealedProp !== void 0;
|
|
43
|
+
const [uncontrolledRevealed, setUncontrolledRevealed] = useState(defaultRevealed);
|
|
44
|
+
const revealed = !sensitive || (revealControlled ? revealedProp : uncontrolledRevealed);
|
|
45
|
+
const setRevealed = (next) => {
|
|
46
|
+
if (!revealControlled) setUncontrolledRevealed(next);
|
|
47
|
+
onRevealedChange?.(next);
|
|
48
|
+
};
|
|
49
|
+
const [focused, setFocused] = useState(false);
|
|
50
|
+
const shown = revealed ? masked.text : concealMasked(masked, focused ? 0 : visibleTail);
|
|
51
|
+
const inputRef = useRef(null);
|
|
52
|
+
const setRef = (node) => {
|
|
53
|
+
inputRef.current = node;
|
|
54
|
+
if (typeof ref === "function") ref(node);
|
|
55
|
+
else if (ref) ref.current = node;
|
|
56
|
+
};
|
|
57
|
+
const pendingCaret = useRef(null);
|
|
58
|
+
const lastInputType = useRef(void 0);
|
|
59
|
+
useLayoutEffect(() => {
|
|
60
|
+
const input = inputRef.current;
|
|
61
|
+
if (pendingCaret.current == null || !input || document.activeElement !== input) return;
|
|
62
|
+
input.setSelectionRange(pendingCaret.current, pendingCaret.current);
|
|
63
|
+
pendingCaret.current = null;
|
|
64
|
+
});
|
|
65
|
+
const hideAfter = autoHideAfter === true ? MOTION_SENSITIVE_HIDE_MS : autoHideAfter || 0;
|
|
66
|
+
const revealedNow = sensitive && revealed;
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (!revealedNow || hideAfter <= 0) return;
|
|
69
|
+
const timer = window.setTimeout(() => setRevealed(false), hideAfter);
|
|
70
|
+
return () => window.clearTimeout(timer);
|
|
71
|
+
}, [revealedNow, hideAfter]);
|
|
72
|
+
const handleBeforeInput = (event) => {
|
|
73
|
+
lastInputType.current = event.nativeEvent.inputType;
|
|
74
|
+
};
|
|
75
|
+
const handleChange = (event) => {
|
|
76
|
+
const inputType = event.nativeEvent.inputType ?? lastInputType.current;
|
|
77
|
+
const edit = readEdit({ ...masked, text: shown }, event.target.value, inputType);
|
|
78
|
+
const capped = [...edit.raw].slice(0, maskCapacity(mask)).join("");
|
|
79
|
+
const next = applyMask(capped, mask);
|
|
80
|
+
pendingCaret.current = caretFor(next, Math.min(edit.caretRaw, next.slots.filter(Boolean).length));
|
|
81
|
+
onChange?.(event);
|
|
82
|
+
if (next.raw === raw) {
|
|
83
|
+
const input = event.target;
|
|
84
|
+
const caret = pendingCaret.current;
|
|
85
|
+
requestAnimationFrame(() => input.setSelectionRange(caret, caret));
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!controlled) setUncontrolled(next.raw);
|
|
89
|
+
onValueChange?.(next.raw, next.text);
|
|
90
|
+
};
|
|
91
|
+
const revealButton = sensitive && revealable ? /* @__PURE__ */ jsx(
|
|
92
|
+
CircularButton,
|
|
93
|
+
{
|
|
94
|
+
icon: revealed ? "visibility_off" : "visibility",
|
|
95
|
+
variant: "tertiary",
|
|
96
|
+
size: "compact",
|
|
97
|
+
ariaLabel: revealed ? hideLabel : showLabel,
|
|
98
|
+
"aria-pressed": revealed,
|
|
99
|
+
disabled,
|
|
100
|
+
onClick: () => setRevealed(!revealed)
|
|
101
|
+
}
|
|
102
|
+
) : void 0;
|
|
103
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
104
|
+
/* @__PURE__ */ jsx(
|
|
105
|
+
Input,
|
|
106
|
+
{
|
|
107
|
+
autoComplete: sensitive ? "off" : void 0,
|
|
108
|
+
spellCheck: false,
|
|
109
|
+
...rest,
|
|
110
|
+
id: rest.id ?? name,
|
|
111
|
+
ref: setRef,
|
|
112
|
+
className: ["ds-masked-input", sensitive && !revealed && "ds-masked-input--concealed", className].filter(Boolean).join(" "),
|
|
113
|
+
label,
|
|
114
|
+
size,
|
|
115
|
+
type: "text",
|
|
116
|
+
inputMode: rest.inputMode ?? (maskIsNumeric(mask) ? "numeric" : void 0),
|
|
117
|
+
value: shown,
|
|
118
|
+
disabled,
|
|
119
|
+
error,
|
|
120
|
+
helperText,
|
|
121
|
+
errorText,
|
|
122
|
+
action: revealButton,
|
|
123
|
+
onBeforeInput: handleBeforeInput,
|
|
124
|
+
onChange: handleChange,
|
|
125
|
+
onFocus: (event) => {
|
|
126
|
+
setFocused(true);
|
|
127
|
+
onFocus?.(event);
|
|
128
|
+
},
|
|
129
|
+
onBlur: (event) => {
|
|
130
|
+
setFocused(false);
|
|
131
|
+
onBlur?.(event);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
),
|
|
135
|
+
name && /* @__PURE__ */ jsx("input", { type: "hidden", name, value: raw, disabled })
|
|
136
|
+
] });
|
|
137
|
+
}
|
|
138
|
+
export {
|
|
139
|
+
MASK_PRESETS,
|
|
140
|
+
MaskedInput,
|
|
141
|
+
applyMask
|
|
142
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The mask engine behind MaskedInput: a pattern or a function turns the raw
|
|
3
|
+
* characters a person typed into the text the field shows, and a typed edit
|
|
4
|
+
* of the shown text back into raw characters. No React, so a server can
|
|
5
|
+
* format a stored value the same way.
|
|
6
|
+
*
|
|
7
|
+
* A pattern is a string where `#` takes a digit, `A` a letter, `*` either,
|
|
8
|
+
* and every other character is written as it stands: `(###) ###-####`.
|
|
9
|
+
* Letters keep the case they were typed in; a function mask can change it.
|
|
10
|
+
*/
|
|
11
|
+
/** A pattern string, or a function from the raw characters to the shown text. */
|
|
12
|
+
export type Mask = string | ((raw: string) => string);
|
|
13
|
+
/** Ready-made patterns. They are data, not a claim about any locale: pick the one that matches what you collect. */
|
|
14
|
+
export declare const MASK_PRESETS: {
|
|
15
|
+
/** A ten-digit phone number in the US shape: `(555) 010-0199`. */
|
|
16
|
+
readonly phoneUs: "(###) ###-####";
|
|
17
|
+
/** A sixteen-digit card number in four groups: `4242 4242 4242 4242`. */
|
|
18
|
+
readonly card: "#### #### #### ####";
|
|
19
|
+
/** A nine-digit ID number in three groups: `123-45-6789`. */
|
|
20
|
+
readonly idNumber: "###-##-####";
|
|
21
|
+
/** A five-digit postal code with an optional four-digit extension: `94107-1234`. */
|
|
22
|
+
readonly postalCode: "#####-####";
|
|
23
|
+
/** A licence key of four blocks of four letters or digits: `AB12-CD34-EF56-GH78`. */
|
|
24
|
+
readonly licenceKey: "****-****-****-****";
|
|
25
|
+
};
|
|
26
|
+
/** The shown text, and which of its characters stand for a raw character (the rest are the mask's literals). */
|
|
27
|
+
export type Masked = {
|
|
28
|
+
text: string;
|
|
29
|
+
raw: string;
|
|
30
|
+
slots: boolean[];
|
|
31
|
+
};
|
|
32
|
+
/** How many raw characters a pattern holds, or Infinity for a function mask. */
|
|
33
|
+
export declare function maskCapacity(mask: Mask): number;
|
|
34
|
+
/** Whether every slot in a pattern takes a digit, so the field can ask for the numeric keyboard. */
|
|
35
|
+
export declare function maskIsNumeric(mask: Mask): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Raw characters through the mask. A character that fits no slot is
|
|
38
|
+
* dropped; literals are written only up to the last filled slot, so a
|
|
39
|
+
* half-typed number never ends in a dangling separator.
|
|
40
|
+
*/
|
|
41
|
+
export declare function applyMask(raw: string, mask: Mask): Masked;
|
|
42
|
+
/** What an edit of the shown text did to the raw value, and where the caret goes. */
|
|
43
|
+
export type MaskEdit = {
|
|
44
|
+
raw: string;
|
|
45
|
+
caretRaw: number;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Read an edit of the shown text back into raw characters. The two texts
|
|
49
|
+
* are compared from each end; whatever the person removed is taken out of
|
|
50
|
+
* the raw value by slot, whatever they typed or pasted goes in, and
|
|
51
|
+
* removing only a separator (Backspace just after a dash) removes the raw
|
|
52
|
+
* character before it, which is what the person meant.
|
|
53
|
+
*/
|
|
54
|
+
export declare function readEdit(previous: Masked, nextText: string, inputType?: string): MaskEdit;
|
|
55
|
+
/** The position in the shown text just after `count` raw characters. */
|
|
56
|
+
export declare function caretFor(masked: Masked, count: number): number;
|
|
57
|
+
/** The shown text with its raw characters hidden as dots, all but the last `visibleTail`. */
|
|
58
|
+
export declare function concealMasked(masked: Masked, visibleTail?: number, dot?: string): string;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
const MASK_PRESETS = {
|
|
2
|
+
/** A ten-digit phone number in the US shape: `(555) 010-0199`. */
|
|
3
|
+
phoneUs: "(###) ###-####",
|
|
4
|
+
/** A sixteen-digit card number in four groups: `4242 4242 4242 4242`. */
|
|
5
|
+
card: "#### #### #### ####",
|
|
6
|
+
/** A nine-digit ID number in three groups: `123-45-6789`. */
|
|
7
|
+
idNumber: "###-##-####",
|
|
8
|
+
/** A five-digit postal code with an optional four-digit extension: `94107-1234`. */
|
|
9
|
+
postalCode: "#####-####",
|
|
10
|
+
/** A licence key of four blocks of four letters or digits: `AB12-CD34-EF56-GH78`. */
|
|
11
|
+
licenceKey: "****-****-****-****"
|
|
12
|
+
};
|
|
13
|
+
const TOKENS = { "#": new RegExp("\\p{Nd}", "u"), A: new RegExp("\\p{L}", "u"), "*": /[\p{L}\p{Nd}]/u };
|
|
14
|
+
const RAW_CHAR = /[\p{L}\p{Nd}]/u;
|
|
15
|
+
function maskCapacity(mask) {
|
|
16
|
+
return typeof mask === "string" ? [...mask].filter((c) => c in TOKENS).length : Infinity;
|
|
17
|
+
}
|
|
18
|
+
function maskIsNumeric(mask) {
|
|
19
|
+
return typeof mask === "string" && [...mask].every((c) => c === "#" || !(c in TOKENS));
|
|
20
|
+
}
|
|
21
|
+
function applyMask(raw, mask) {
|
|
22
|
+
const chars = [...raw].filter((c) => RAW_CHAR.test(c));
|
|
23
|
+
if (typeof mask === "function") {
|
|
24
|
+
const text2 = mask(chars.join(""));
|
|
25
|
+
const slots2 = [...text2].map((c) => RAW_CHAR.test(c));
|
|
26
|
+
return { text: text2, raw: [...text2].filter((c) => RAW_CHAR.test(c)).join(""), slots: slots2 };
|
|
27
|
+
}
|
|
28
|
+
let text = "";
|
|
29
|
+
let pending = "";
|
|
30
|
+
const slots = [];
|
|
31
|
+
const pendingSlots = [];
|
|
32
|
+
const kept = [];
|
|
33
|
+
let i = 0;
|
|
34
|
+
for (const m of mask) {
|
|
35
|
+
if (i >= chars.length) break;
|
|
36
|
+
const token = TOKENS[m];
|
|
37
|
+
if (!token) {
|
|
38
|
+
pending += m;
|
|
39
|
+
pendingSlots.push(false);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
while (i < chars.length && !token.test(chars[i])) i++;
|
|
43
|
+
if (i >= chars.length) break;
|
|
44
|
+
text += pending + chars[i];
|
|
45
|
+
slots.push(...pendingSlots, true);
|
|
46
|
+
pending = "";
|
|
47
|
+
pendingSlots.length = 0;
|
|
48
|
+
kept.push(chars[i]);
|
|
49
|
+
i++;
|
|
50
|
+
}
|
|
51
|
+
return { text, raw: kept.join(""), slots };
|
|
52
|
+
}
|
|
53
|
+
function readEdit(previous, nextText, inputType) {
|
|
54
|
+
const before = [...previous.text];
|
|
55
|
+
const after = [...nextText];
|
|
56
|
+
let start = 0;
|
|
57
|
+
while (start < before.length && start < after.length && before[start] === after[start]) start++;
|
|
58
|
+
let endBefore = before.length;
|
|
59
|
+
let endAfter = after.length;
|
|
60
|
+
while (endBefore > start && endAfter > start && before[endBefore - 1] === after[endAfter - 1]) {
|
|
61
|
+
endBefore--;
|
|
62
|
+
endAfter--;
|
|
63
|
+
}
|
|
64
|
+
const rawIndex = (displayIndex) => previous.slots.slice(0, displayIndex).filter(Boolean).length;
|
|
65
|
+
let rawStart = rawIndex(start);
|
|
66
|
+
const rawEnd = rawIndex(endBefore);
|
|
67
|
+
const inserted = after.slice(start, endAfter).filter((c) => RAW_CHAR.test(c)).join("");
|
|
68
|
+
const rawChars = [...previous.raw];
|
|
69
|
+
if (inserted === "" && rawStart === rawEnd && endBefore > start) {
|
|
70
|
+
if (inputType === "deleteContentForward") rawChars.splice(rawStart, 1);
|
|
71
|
+
else if (rawStart > 0) {
|
|
72
|
+
rawChars.splice(rawStart - 1, 1);
|
|
73
|
+
rawStart -= 1;
|
|
74
|
+
}
|
|
75
|
+
return { raw: rawChars.join(""), caretRaw: rawStart };
|
|
76
|
+
}
|
|
77
|
+
rawChars.splice(rawStart, rawEnd - rawStart, ...inserted);
|
|
78
|
+
return { raw: rawChars.join(""), caretRaw: rawStart + [...inserted].length };
|
|
79
|
+
}
|
|
80
|
+
function caretFor(masked, count) {
|
|
81
|
+
if (count <= 0) return 0;
|
|
82
|
+
let seen = 0;
|
|
83
|
+
for (let i = 0; i < masked.slots.length; i++) {
|
|
84
|
+
if (masked.slots[i]) seen++;
|
|
85
|
+
if (seen === count) return i + 1;
|
|
86
|
+
}
|
|
87
|
+
return masked.text.length;
|
|
88
|
+
}
|
|
89
|
+
function concealMasked(masked, visibleTail = 0, dot = "•") {
|
|
90
|
+
const total = masked.slots.filter(Boolean).length;
|
|
91
|
+
let seen = 0;
|
|
92
|
+
return [...masked.text].map((c, i) => {
|
|
93
|
+
if (!masked.slots[i]) return c;
|
|
94
|
+
seen++;
|
|
95
|
+
return seen > total - visibleTail ? c : dot;
|
|
96
|
+
}).join("");
|
|
97
|
+
}
|
|
98
|
+
export {
|
|
99
|
+
MASK_PRESETS,
|
|
100
|
+
applyMask,
|
|
101
|
+
caretFor,
|
|
102
|
+
concealMasked,
|
|
103
|
+
maskCapacity,
|
|
104
|
+
maskIsNumeric,
|
|
105
|
+
readEdit
|
|
106
|
+
};
|
|
@@ -36,21 +36,32 @@
|
|
|
36
36
|
margin: var(--padding-300) var(--padding-300) 0;
|
|
37
37
|
border-radius: var(--radius-300);
|
|
38
38
|
overflow: hidden;
|
|
39
|
-
/* The slot carries its own surface, so drawn media —
|
|
40
|
-
reads as the same image-shaped panel a photo would:
|
|
41
|
-
the card's crisp fill, so it shows as a slot in both
|
|
39
|
+
/* The slot carries its own surface, so drawn media — an SVG, an
|
|
40
|
+
illustration — reads as the same image-shaped panel a photo would: a
|
|
41
|
+
step in from the card's crisp fill, so it shows as a slot in both
|
|
42
|
+
themes. */
|
|
42
43
|
background-color: var(--color-bg-container-secondary);
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
/* A chart's slot takes the primary container tone instead. The secondary
|
|
47
|
+
tone is the second elevation, a mid grey in dark mode (three steps
|
|
48
|
+
lighter than the card), and a plot drawn straight on it read as a grey
|
|
49
|
+
block with its fill washed out. The primary tone is the surface every
|
|
50
|
+
chart stands on elsewhere (its own panel's fill), a step in from the card
|
|
51
|
+
and nothing like a block. */
|
|
52
|
+
.ds-message-card__media:has(.ds-chart) {
|
|
53
|
+
background-color: var(--color-bg-container-primary);
|
|
54
|
+
}
|
|
55
|
+
|
|
45
56
|
.ds-message-card__media img {
|
|
46
57
|
display: block;
|
|
47
58
|
width: 100%;
|
|
48
59
|
}
|
|
49
60
|
|
|
50
61
|
/* A Chart in the slot sheds its own panel chrome — the card is already the
|
|
51
|
-
panel, and the slot
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
panel, and the slot above gives it the same primary container tone its
|
|
63
|
+
own panel would, so the drawing sits on one surface, not a panel inside a
|
|
64
|
+
slot. */
|
|
54
65
|
.ds-message-card__media .ds-chart {
|
|
55
66
|
background-color: transparent;
|
|
56
67
|
border: none;
|
|
@@ -10,7 +10,7 @@ type MessageCardOwnProps = {
|
|
|
10
10
|
description?: string;
|
|
11
11
|
/** Top media slot — an image or chart, inset from the card edges with its own rounded corners. */
|
|
12
12
|
media?: React.ReactNode;
|
|
13
|
-
/** Small
|
|
13
|
+
/** Small icon trailing the title at the row's end — a Material Symbol name, or any custom element. */
|
|
14
14
|
icon?: string | React.ReactNode;
|
|
15
15
|
/** Free-text metadata line, e.g. a domain or date, so callers keep their own formatting. */
|
|
16
16
|
meta?: string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/* ShaderScene: the canvas, filling its positioned ancestor.
|
|
2
|
+
Placement and clipping belong to that ancestor, as with ShaderField: where
|
|
3
|
+
a scene sits is a layout decision. The ground under the canvas is the
|
|
4
|
+
page's, so a machine that cannot run WebGL2 shows the plain page. */
|
|
5
|
+
|
|
6
|
+
.ds-shader-scene {
|
|
7
|
+
position: absolute;
|
|
8
|
+
inset: 0;
|
|
9
|
+
overflow: hidden;
|
|
10
|
+
/* Scenery, never a target. */
|
|
11
|
+
pointer-events: none;
|
|
12
|
+
background-color: var(--color-bg-page-primary);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.ds-shader-scene__canvas {
|
|
16
|
+
display: block;
|
|
17
|
+
width: 100%;
|
|
18
|
+
height: 100%;
|
|
19
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { Values } from './types';
|
|
3
|
+
/** The scenes ShaderScene paints. */
|
|
4
|
+
export type ShaderSceneId = 'horizon' | 'rift' | 'glyphs' | 'prism' | 'meteors' | 'waves' | 'aurora';
|
|
5
|
+
/**
|
|
6
|
+
* How the scene resolved, the same three states ShaderField reports.
|
|
7
|
+
* `pending` while the GL context comes up (bounded by a watchdog), `active`
|
|
8
|
+
* once a frame has painted, `unavailable` when it is disabled or WebGL2
|
|
9
|
+
* cannot run it.
|
|
10
|
+
*/
|
|
11
|
+
export type ShaderSceneStatus = 'pending' | 'active' | 'unavailable';
|
|
12
|
+
/** One finishing pass's setting: whether it runs, and its own settings. */
|
|
13
|
+
export type ShaderScenePassSetting = {
|
|
14
|
+
/** Run the pass. Each pass has its own default. */
|
|
15
|
+
on?: boolean;
|
|
16
|
+
/** The pass's settings, merged over its defaults. */
|
|
17
|
+
params?: Partial<Record<string, number>>;
|
|
18
|
+
};
|
|
19
|
+
/** Props owned by ShaderScene itself; everything else falls through to the root. */
|
|
20
|
+
type ShaderSceneOwnProps = {
|
|
21
|
+
/** The scene to paint: `horizon`, a planet's limb at night, `rift`, a glowing tear, `glyphs`, soft light printed in type, `prism`, beams of light split into a spectrum, `meteors`, a shower over a planet's edge, `waves`, a rolling sea of points, or `aurora`, ribbons of colour round a void. */
|
|
22
|
+
scene?: ShaderSceneId;
|
|
23
|
+
/**
|
|
24
|
+
* The scene's settings, merged over its defaults (`SHADER_SCENES` lists each
|
|
25
|
+
* scene's keys and ranges), so passing one changes one thing. Changing them
|
|
26
|
+
* never rebuilds the GL state.
|
|
27
|
+
*/
|
|
28
|
+
params?: Partial<Record<string, number>>;
|
|
29
|
+
/**
|
|
30
|
+
* The finishing passes (`scrim`, `vignette`, `fadeTop`, `fadeBottom`,
|
|
31
|
+
* `grain`), each merged over its defaults.
|
|
32
|
+
*/
|
|
33
|
+
passes?: Partial<Record<string, ShaderScenePassSetting>>;
|
|
34
|
+
/** Scene seconds per second: how fast it moves. 0 holds it still. */
|
|
35
|
+
speed?: number;
|
|
36
|
+
/**
|
|
37
|
+
* A ref the scene reads every frame in place of `params`, `passes` and
|
|
38
|
+
* `speed`, for a host that tunes it by drag: writing the ref moves the
|
|
39
|
+
* scene and renders nothing. Empty falls back to the props.
|
|
40
|
+
*/
|
|
41
|
+
liveRef?: React.RefObject<Values | null>;
|
|
42
|
+
/**
|
|
43
|
+
* False never starts WebGL and reports `unavailable`, leaving the page
|
|
44
|
+
* ground: the kill switch, as on ShaderField.
|
|
45
|
+
*/
|
|
46
|
+
enabled?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Called whenever the status changes. Drive a fallback from this: the scene
|
|
49
|
+
* paints only the page ground when it cannot run, and what to show instead
|
|
50
|
+
* is the caller's design decision.
|
|
51
|
+
*/
|
|
52
|
+
onStatusChange?: (status: ShaderSceneStatus) => void;
|
|
53
|
+
/** Additional CSS classes */
|
|
54
|
+
className?: string;
|
|
55
|
+
};
|
|
56
|
+
export interface ShaderSceneProps extends ShaderSceneOwnProps, Omit<React.ComponentPropsWithRef<'div'>, keyof ShaderSceneOwnProps> {
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* ShaderScene paints one of the system's shader scenes, a horizon, a rift,
|
|
60
|
+
* a field of glyphs, a prism, a meteor shower, a sea of points or an aurora, in WebGL2, with finishing passes over it (a scrim, a vignette, top and
|
|
61
|
+
* bottom fades to the page, film grain). Its colours are the background
|
|
62
|
+
* field's roles (`--color-ambient-*`) read from the live cascade at the
|
|
63
|
+
* scene, so it re-themes with `data-theme`, a preset or any scoped override,
|
|
64
|
+
* and its fades melt into the page ground.
|
|
65
|
+
*
|
|
66
|
+
* Every scene is a night scene: it adds light over a dark ground. On a light
|
|
67
|
+
* page each computes its light against a dark ground of its own and lays it
|
|
68
|
+
* onto the page as a pale tint, so it reads as a soft dawn rather than a dark
|
|
69
|
+
* block. Nothing here sets `data-theme`, which would hide a preset's colours.
|
|
70
|
+
*
|
|
71
|
+
* It is scenery, not interface. It fills its positioned ancestor and is inert
|
|
72
|
+
* to pointer events and to assistive tech; give the ancestor the placement and
|
|
73
|
+
* the clipping. It honours reduced motion in JavaScript, holding a still frame
|
|
74
|
+
* that still answers its settings, and paints the page ground alone where
|
|
75
|
+
* WebGL2 is unavailable.
|
|
76
|
+
*/
|
|
77
|
+
export declare function ShaderScene({ scene, params, passes, speed, liveRef, enabled, onStatusChange, className, ref, ...rest }: ShaderSceneProps): React.JSX.Element;
|
|
78
|
+
export type { ParamSpec as ShaderSceneParamSpec, Scene as ShaderSceneDefinition, Pass as ShaderScenePass, Values as ShaderSceneValues, Recipe as ShaderSceneRecipe, } from './types';
|
|
79
|
+
export { SCENES as SHADER_SCENES } from './scenes';
|
|
80
|
+
export { PASSES as SHADER_PASSES } from './passes';
|
|
81
|
+
export { defaultsFor as shaderSceneDefaults } from './types';
|
|
82
|
+
export { bakeThumbnails as shaderSceneStills } from './renderer';
|