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.
Files changed (117) hide show
  1. package/README.md +5 -4
  2. package/chat/ChatThreads.d.ts +3 -1
  3. package/chat/ChatThreads.js +3 -1
  4. package/chat/ChatWidget.css +166 -15
  5. package/chat/ChatWidget.d.ts +6 -2
  6. package/chat/ChatWidget.js +17 -3
  7. package/components/ActionCard/ActionCard.d.ts +1 -1
  8. package/components/Attachment/Attachment.css +8 -0
  9. package/components/Attachment/AttachmentViewer.js +26 -5
  10. package/components/Attachment/fileTypes.d.ts +4 -0
  11. package/components/ContextMenu/ContextMenu.css +11 -0
  12. package/components/ContextMenu/ContextMenu.d.ts +1 -1
  13. package/components/ContextMenu/ContextMenu.js +3 -1
  14. package/components/CurrencyInput/CurrencyInput.css +12 -0
  15. package/components/CurrencyInput/CurrencyInput.d.ts +51 -0
  16. package/components/CurrencyInput/CurrencyInput.js +158 -0
  17. package/components/DataTable/columnTypes.js +4 -16
  18. package/components/DatePicker/DatePicker.d.ts +2 -0
  19. package/components/DatePicker/DatePicker.js +44 -131
  20. package/components/DatePicker/MonthGrid.d.ts +56 -0
  21. package/components/DatePicker/MonthGrid.js +65 -0
  22. package/components/DatePicker/calendar.d.ts +42 -0
  23. package/components/DatePicker/calendar.js +108 -0
  24. package/components/DateRangePicker/DateRangePicker.css +92 -0
  25. package/components/DateRangePicker/DateRangePicker.d.ts +86 -0
  26. package/components/DateRangePicker/DateRangePicker.js +294 -0
  27. package/components/Deadline/Deadline.css +82 -0
  28. package/components/Deadline/Deadline.d.ts +44 -0
  29. package/components/Deadline/Deadline.js +94 -0
  30. package/components/Deadline/deadlineStatus.d.ts +15 -0
  31. package/components/Deadline/deadlineStatus.js +13 -0
  32. package/components/DescriptionList/DescriptionList.css +184 -0
  33. package/components/DescriptionList/DescriptionList.d.ts +64 -0
  34. package/components/DescriptionList/DescriptionList.js +100 -0
  35. package/components/DescriptionList/DescriptionListCopy.d.ts +18 -0
  36. package/components/DescriptionList/DescriptionListCopy.js +45 -0
  37. package/components/DocumentViewer/DocumentViewer.css +188 -0
  38. package/components/DocumentViewer/DocumentViewer.d.ts +59 -0
  39. package/components/DocumentViewer/DocumentViewer.js +185 -0
  40. package/components/DropdownMenu/DropdownMenu.css +38 -0
  41. package/components/DropdownMenu/DropdownMenu.d.ts +4 -0
  42. package/components/DropdownMenu/DropdownMenu.js +11 -5
  43. package/components/DropdownMenu/ShortcutHint.d.ts +9 -0
  44. package/components/DropdownMenu/ShortcutHint.js +6 -0
  45. package/components/ErrorSummary/ErrorSummary.css +94 -0
  46. package/components/ErrorSummary/ErrorSummary.d.ts +34 -0
  47. package/components/ErrorSummary/ErrorSummary.js +70 -0
  48. package/components/ErrorSummary/fieldErrors.d.ts +36 -0
  49. package/components/ErrorSummary/fieldErrors.js +19 -0
  50. package/components/Field/Field.css +12 -0
  51. package/components/Field/Field.d.ts +10 -2
  52. package/components/Field/Field.js +12 -5
  53. package/components/Heading/Heading.css +129 -0
  54. package/components/Heading/Heading.d.ts +31 -0
  55. package/components/Heading/Heading.js +39 -0
  56. package/components/Input/Input.css +120 -0
  57. package/components/Input/Input.d.ts +20 -1
  58. package/components/Input/Input.js +70 -5
  59. package/components/InterruptCard/InterruptCard.d.ts +1 -1
  60. package/components/Link/Link.css +84 -0
  61. package/components/Link/Link.d.ts +43 -0
  62. package/components/Link/Link.js +74 -0
  63. package/components/List/List.css +173 -0
  64. package/components/List/List.d.ts +44 -0
  65. package/components/List/List.js +60 -0
  66. package/components/MaskedInput/MaskedInput.css +16 -0
  67. package/components/MaskedInput/MaskedInput.d.ts +57 -0
  68. package/components/MaskedInput/MaskedInput.js +142 -0
  69. package/components/MaskedInput/mask.d.ts +58 -0
  70. package/components/MaskedInput/mask.js +106 -0
  71. package/components/MessageCard/MessageCard.css +17 -6
  72. package/components/MessageCard/MessageCard.d.ts +1 -1
  73. package/components/ShaderScene/ShaderScene.css +19 -0
  74. package/components/ShaderScene/ShaderScene.d.ts +82 -0
  75. package/components/ShaderScene/ShaderScene.js +167 -0
  76. package/components/ShaderScene/assemble.d.ts +5 -0
  77. package/components/ShaderScene/assemble.js +76 -0
  78. package/components/ShaderScene/common.glsl.d.ts +6 -0
  79. package/components/ShaderScene/common.glsl.js +49 -0
  80. package/components/ShaderScene/passes.d.ts +2 -0
  81. package/components/ShaderScene/passes.js +93 -0
  82. package/components/ShaderScene/renderer.d.ts +39 -0
  83. package/components/ShaderScene/renderer.js +170 -0
  84. package/components/ShaderScene/scenes.d.ts +76 -0
  85. package/components/ShaderScene/scenes.js +752 -0
  86. package/components/ShaderScene/types.d.ts +83 -0
  87. package/components/ShaderScene/types.js +8 -0
  88. package/components/SignaturePad/SignaturePad.css +141 -0
  89. package/components/SignaturePad/SignaturePad.d.ts +68 -0
  90. package/components/SignaturePad/SignaturePad.js +287 -0
  91. package/components/SignaturePad/signature.d.ts +32 -0
  92. package/components/SignaturePad/signature.js +46 -0
  93. package/components/Text/Text.css +129 -0
  94. package/components/Text/Text.d.ts +36 -0
  95. package/components/Text/Text.js +36 -0
  96. package/components/ThreadPanel/ThreadPanel.css +29 -0
  97. package/components/ThreadPanel/ThreadPanel.d.ts +2 -0
  98. package/components/ThreadPanel/ThreadPanel.js +13 -2
  99. package/components/Widget/Widget.css +111 -0
  100. package/components/Widget/Widget.d.ts +15 -1
  101. package/components/Widget/Widget.js +63 -11
  102. package/components/Widget/WidgetDisclosure.d.ts +30 -0
  103. package/components/Widget/WidgetDisclosure.js +52 -0
  104. package/components/registry.json +111 -2
  105. package/components/registry.json.d.ts +111 -2
  106. package/components/registry.json.js +2 -2
  107. package/format/index.d.ts +15 -0
  108. package/format/index.js +17 -0
  109. package/format/money.d.ts +89 -0
  110. package/format/money.js +187 -0
  111. package/format/relative.d.ts +49 -0
  112. package/format/relative.js +50 -0
  113. package/index.d.ts +13 -0
  114. package/index.js +48 -1
  115. package/package.json +9 -2
  116. package/tokens/motion.d.ts +4 -0
  117. package/tokens/motion.js +4 -0
@@ -0,0 +1,83 @@
1
+ /**
2
+ * The playground's shader vocabulary (the Shaders view, and the ground it
3
+ * lays under every view). A scene is one look (a horizon, a blob field); a pass is a finishing step any scene can take (grain, a fade, a
4
+ * vignette); a recipe is a scene, its settings, and which passes are on
5
+ * with theirs. Every setting is declared as data, so the panel draws its
6
+ * sliders from the declaration and never needs a hand-built control.
7
+ */
8
+ /** One numeric setting, drawn as a slider. */
9
+ export type ParamSpec = {
10
+ key: string;
11
+ label: string;
12
+ min: number;
13
+ max: number;
14
+ step: number;
15
+ default: number;
16
+ };
17
+ /**
18
+ * A look. `glsl` defines `vec3 scene(vec2 uv, float t)`, returning the
19
+ * final linear colour of the pixel over the page ground (`u_ground`). Its
20
+ * settings arrive as `uniform float u_<key>`, and its colours as
21
+ * `u_col[i]` in the order `colours` lists their tokens.
22
+ */
23
+ export type Scene = {
24
+ id: string;
25
+ label: string;
26
+ description: string;
27
+ /** Colour tokens, resolved from the live cascade into `u_col[0..]`. */
28
+ colours: string[];
29
+ /**
30
+ * `dark` for a scene that only reads on a dark ground (it adds light).
31
+ * On a light page its surface paints a near-black ground of its own
32
+ * (coloursFor), rather than setting data-theme on itself: a nested
33
+ * [data-theme] matches the base dark tokens and would hide the theme
34
+ * preset's colours.
35
+ */
36
+ mode?: "dark";
37
+ /**
38
+ * A ramp of characters, thin to heavy, for a scene that prints type. The
39
+ * renderer draws it once into a strip texture in the theme's code face
40
+ * (`--font-family-code`) and hands it to the GLSL as `u_glyphs`, with
41
+ * the number of characters in `u_glyphCount`.
42
+ */
43
+ glyphs?: string;
44
+ /**
45
+ * The most drawing-buffer pixels per CSS pixel the scene may use, for a
46
+ * scene with detail finer than soft light (type). Defaults to 1; the
47
+ * ratio in use reaches the GLSL as `u_ratio`.
48
+ */
49
+ pixelRatio?: number;
50
+ params: ParamSpec[];
51
+ glsl: string;
52
+ };
53
+ /**
54
+ * A finishing step. `glsl` defines one function named `pass_<id>`: a
55
+ * `light` pass takes and returns the linear colour, before encoding; an
56
+ * `srgb` pass takes and returns the encoded colour. Its settings arrive as
57
+ * `uniform float u_<id>_<key>`, and `u_<id>_on` switches it.
58
+ */
59
+ export type Pass = {
60
+ id: string;
61
+ label: string;
62
+ stage: "light" | "srgb";
63
+ on: boolean;
64
+ params: ParamSpec[];
65
+ glsl: string;
66
+ };
67
+ /** What the canvas reads every frame. A ref holds it, so a drag never renders. */
68
+ export type Values = {
69
+ speed: number;
70
+ scene: Record<string, number>;
71
+ passes: Record<string, {
72
+ on: boolean;
73
+ params: Record<string, number>;
74
+ }>;
75
+ };
76
+ /** A recipe as it is copied out: the scene's id with the values above. */
77
+ export type Recipe = Values & {
78
+ sceneId: string;
79
+ };
80
+ export declare const MAX_COLOURS = 8;
81
+ export declare function defaultsFor(params: ParamSpec[]): {
82
+ [k: string]: number;
83
+ };
@@ -0,0 +1,8 @@
1
+ const MAX_COLOURS = 8;
2
+ function defaultsFor(params) {
3
+ return Object.fromEntries(params.map((param) => [param.key, param.default]));
4
+ }
5
+ export {
6
+ MAX_COLOURS,
7
+ defaultsFor
8
+ };
@@ -0,0 +1,141 @@
1
+ /* ============================================
2
+ SIGNATURE PAD
3
+ The input surface (fill, hairline, radius,
4
+ hover, error, disabled) holding a drawing
5
+ area over a dashed baseline. Strokes draw in
6
+ the primary text colour; the typed name sets
7
+ in the body face, italic, on the same line.
8
+ ============================================ */
9
+
10
+ /* Base */
11
+ .ds-signature-pad {
12
+ display: flex;
13
+ flex-direction: column;
14
+ gap: var(--gap-200);
15
+ width: 100%;
16
+ }
17
+
18
+ .ds-signature-pad__body {
19
+ display: flex;
20
+ flex-direction: column;
21
+ gap: var(--gap-200);
22
+ min-width: 0;
23
+ }
24
+
25
+ .ds-signature-pad__mode {
26
+ align-self: flex-start;
27
+ }
28
+
29
+ .ds-signature-pad__typed {
30
+ display: flex;
31
+ flex-direction: column;
32
+ gap: var(--gap-200);
33
+ }
34
+
35
+ /* Surface */
36
+ .ds-signature-pad__surface {
37
+ position: relative;
38
+ box-sizing: border-box;
39
+ block-size: calc(var(--control-height-default) * 4);
40
+ border: var(--border-025) solid var(--color-input-border-primary);
41
+ border-radius: var(--radius-300);
42
+ background-color: var(--color-input-bg-primary);
43
+ color: var(--color-text-primary);
44
+ overflow: hidden;
45
+ transition: border-color var(--motion-duration-base) var(--motion-ease-standard);
46
+ }
47
+
48
+ .ds-signature-pad__surface:hover {
49
+ border-color: var(--color-input-border-hover);
50
+ }
51
+
52
+ .ds-signature-pad--height-tall .ds-signature-pad__surface {
53
+ block-size: calc(var(--control-height-default) * 6);
54
+ }
55
+
56
+ .ds-signature-pad--compact .ds-signature-pad__surface {
57
+ block-size: calc(var(--control-height-compact) * 4);
58
+ }
59
+
60
+ .ds-signature-pad--compact.ds-signature-pad--height-tall .ds-signature-pad__surface {
61
+ block-size: calc(var(--control-height-compact) * 6);
62
+ }
63
+
64
+ .ds-signature-pad__surface--typed {
65
+ display: flex;
66
+ align-items: flex-end;
67
+ }
68
+
69
+ /* The baseline sits seven tenths down, inset from both ends. */
70
+ .ds-signature-pad__baseline {
71
+ position: absolute;
72
+ inset-inline: var(--padding-500);
73
+ inset-block-start: 70%;
74
+ border-block-start: var(--border-025) dashed var(--color-divider);
75
+ pointer-events: none;
76
+ }
77
+
78
+ .ds-signature-pad__placeholder {
79
+ position: absolute;
80
+ inset-block-end: var(--gap-100);
81
+ inset-inline-start: 0;
82
+ font-family: var(--font-caption-family);
83
+ font-size: var(--font-caption-size);
84
+ font-weight: var(--font-caption-weight);
85
+ line-height: var(--font-caption-line-height);
86
+ letter-spacing: var(--font-caption-letter-spacing);
87
+ color: var(--color-text-tertiary);
88
+ }
89
+
90
+ /* Drawing */
91
+ .ds-signature-pad__canvas {
92
+ position: absolute;
93
+ inset: 0;
94
+ inline-size: 100%;
95
+ block-size: 100%;
96
+ touch-action: none;
97
+ cursor: crosshair;
98
+ }
99
+
100
+ .ds-signature-pad__stroke {
101
+ fill: none;
102
+ stroke: currentColor;
103
+ stroke-linecap: round;
104
+ stroke-linejoin: round;
105
+ }
106
+
107
+ /* The typed name, set on the baseline */
108
+ .ds-signature-pad__preview {
109
+ position: absolute;
110
+ inset-inline-start: var(--padding-500);
111
+ inset-inline-end: var(--padding-500);
112
+ inset-block-end: 30%;
113
+ overflow: hidden;
114
+ font-family: var(--font-family-body);
115
+ font-size: var(--font-heading-2-size);
116
+ font-style: italic;
117
+ line-height: var(--font-heading-2-line-height);
118
+ white-space: nowrap;
119
+ text-overflow: ellipsis;
120
+ }
121
+
122
+ /* Actions */
123
+ .ds-signature-pad__actions {
124
+ display: flex;
125
+ justify-content: flex-end;
126
+ gap: var(--gap-100);
127
+ }
128
+
129
+ /* States */
130
+ .ds-signature-pad--error .ds-signature-pad__surface {
131
+ border-color: var(--color-status-error-border);
132
+ }
133
+
134
+ .ds-signature-pad--disabled .ds-signature-pad__surface {
135
+ opacity: 0.4;
136
+ cursor: not-allowed;
137
+ }
138
+
139
+ .ds-signature-pad--disabled .ds-signature-pad__canvas {
140
+ pointer-events: none;
141
+ }
@@ -0,0 +1,68 @@
1
+ import { default as React } from 'react';
2
+ import { SignatureValue } from './signature';
3
+ /** Props owned by SignaturePad itself; everything else falls through to the wrapper. */
4
+ type SignaturePadOwnProps = {
5
+ /** Label text above the pad. */
6
+ label?: string;
7
+ /** `draw` takes a drawn signature, `type` a typed name, `both` lets the reader choose. Defaults to `both`, since typing is the way in for anyone who cannot draw with a pointer. */
8
+ mode?: 'draw' | 'type' | 'both';
9
+ /** The signature (controlled). A drawn one cannot be loaded back for editing: pass `null` to clear the pad, or keep the value the pad last handed over. */
10
+ value?: SignatureValue | null;
11
+ /** The typed name the pad starts with (uncontrolled), which also starts it on the type tab. */
12
+ defaultValue?: {
13
+ kind: 'typed';
14
+ text: string;
15
+ } | null;
16
+ /** Called with the signature after each stroke, each change to the typed name, and each clear (with `null`). */
17
+ onValueChange?: (value: SignatureValue | null) => void;
18
+ /** The pad's height: `default`, or `tall` for a wider hand or a touch screen. */
19
+ height?: 'default' | 'tall';
20
+ /** Component size */
21
+ size?: 'default' | 'compact';
22
+ /** Whether the pad is disabled */
23
+ disabled?: boolean;
24
+ /** Error state without a message of its own. */
25
+ error?: boolean;
26
+ /** The error message under the pad; setting it marks the pad invalid. */
27
+ errorText?: React.ReactNode;
28
+ /** Helper text below the pad. */
29
+ helperText?: string;
30
+ /** Marks the pad required. */
31
+ required?: boolean;
32
+ /** The form field name: the form receives the signature's SVG through a hidden input. */
33
+ name?: string;
34
+ /** Text on the baseline before anything is drawn. Defaults to "Sign here". */
35
+ placeholderLabel?: string;
36
+ /** The drawing surface's accessible name. Defaults to "Signature drawing area". */
37
+ padLabel?: string;
38
+ /** Accessible name of the draw and type choice. Defaults to "Signature method". */
39
+ modeLabel?: string;
40
+ /** The draw tab's text. Defaults to "Draw". */
41
+ drawLabel?: string;
42
+ /** The type tab's text. Defaults to "Type". */
43
+ typeLabel?: string;
44
+ /** The typed name's field label. Defaults to "Type your full name". */
45
+ nameLabel?: string;
46
+ /** The clear button's text. Defaults to "Clear". */
47
+ clearLabel?: string;
48
+ /** The undo button's text. Defaults to "Undo". */
49
+ undoLabel?: string;
50
+ /** Announced politely after a stroke is drawn. Defaults to "Signature added". */
51
+ addedLabel?: string;
52
+ /** Announced politely after the pad is cleared. Defaults to "Signature cleared". */
53
+ clearedLabel?: string;
54
+ /** Additional CSS classes */
55
+ className?: string;
56
+ };
57
+ export interface SignaturePadProps extends SignaturePadOwnProps, Omit<React.ComponentPropsWithRef<'div'>, keyof SignaturePadOwnProps | 'children'> {
58
+ }
59
+ /**
60
+ * A signature, drawn with a pointer or typed. Drawn strokes are smoothed and
61
+ * kept as SVG path data, so the signature scales and prints; a PNG is made
62
+ * on demand. Undo takes back the last stroke and Clear empties the pad. The
63
+ * typed name is the way in for a reader who cannot draw, so the pad offers
64
+ * both by default.
65
+ */
66
+ export declare function SignaturePad({ label, mode, value: valueProp, defaultValue, onValueChange, height, size, disabled, error, errorText, helperText, required, name, placeholderLabel, padLabel, modeLabel, drawLabel, typeLabel, nameLabel, clearLabel, undoLabel, addedLabel, clearedLabel, className, id, ref, ...rest }: SignaturePadProps): React.JSX.Element;
67
+ export { strokePath, svgToPng } from './signature';
68
+ export type { SignatureStroke, SignatureValue } from './signature';
@@ -0,0 +1,287 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useId, useState, useRef, useEffect } from "react";
4
+ import { Field } from "../Field/Field.js";
5
+ import { Input } from "../Input/Input.js";
6
+ import { Button } from "../Button/Button.js";
7
+ import { SegmentedControl } from "../SegmentedControl/SegmentedControl.js";
8
+ import "../../behaviors/visually-hidden.css";
9
+ import { strokePath, typedSvg, svgToPng, drawnSvg } from "./signature.js";
10
+ import "./SignaturePad.css";
11
+ const FALLBACK_SIZE = { width: 600, height: 200 };
12
+ function SignaturePad({
13
+ label,
14
+ mode = "both",
15
+ value: valueProp,
16
+ defaultValue = null,
17
+ onValueChange,
18
+ height = "default",
19
+ size = "default",
20
+ disabled = false,
21
+ error,
22
+ errorText,
23
+ helperText,
24
+ required,
25
+ name,
26
+ placeholderLabel = "Sign here",
27
+ padLabel = "Signature drawing area",
28
+ modeLabel = "Signature method",
29
+ drawLabel = "Draw",
30
+ typeLabel = "Type",
31
+ nameLabel = "Type your full name",
32
+ clearLabel = "Clear",
33
+ undoLabel = "Undo",
34
+ addedLabel = "Signature added",
35
+ clearedLabel = "Signature cleared",
36
+ className = "",
37
+ id,
38
+ ref,
39
+ ...rest
40
+ }) {
41
+ const generatedId = useId();
42
+ const baseId = id ?? generatedId;
43
+ const [tab, setTab] = useState(
44
+ mode === "type" || mode === "both" && defaultValue?.kind === "typed" ? "type" : "draw"
45
+ );
46
+ const activeTab = mode === "both" ? tab : mode;
47
+ const [strokes, setStrokes] = useState([]);
48
+ const [typed, setTyped] = useState(defaultValue?.kind === "typed" ? defaultValue.text : "");
49
+ const [announcement, setAnnouncement] = useState("");
50
+ const [svgValue, setSvgValue] = useState("");
51
+ const svgRef = useRef(null);
52
+ const liveRef = useRef(null);
53
+ const previewRef = useRef(null);
54
+ const [box, setBox] = useState(FALLBACK_SIZE);
55
+ const drawing = useRef(null);
56
+ const padEmpty = strokes.length === 0;
57
+ useEffect(() => {
58
+ const svg = svgRef.current;
59
+ if (!svg || typeof ResizeObserver === "undefined") return;
60
+ const observer = new ResizeObserver(([entry]) => {
61
+ if (drawing.current) return;
62
+ const { width, height: h } = entry.contentRect;
63
+ if (width > 0 && h > 0) setBox({ width, height: h });
64
+ });
65
+ if (padEmpty) observer.observe(svg);
66
+ return () => observer.disconnect();
67
+ }, [activeTab, padEmpty]);
68
+ const [lastValue, setLastValue] = useState(valueProp);
69
+ if (valueProp !== lastValue) {
70
+ setLastValue(valueProp);
71
+ if (valueProp === null) {
72
+ setStrokes([]);
73
+ setTyped("");
74
+ setSvgValue("");
75
+ }
76
+ }
77
+ const emitDrawn = (next) => {
78
+ if (next.length === 0) {
79
+ setSvgValue("");
80
+ onValueChange?.(null);
81
+ return;
82
+ }
83
+ const svg = drawnSvg(next, box.width, box.height);
84
+ setSvgValue(svg);
85
+ onValueChange?.({ kind: "drawn", svg, png: () => svgToPng(svg, box.width, box.height) });
86
+ };
87
+ const emitTyped = (text) => {
88
+ if (text.trim() === "") {
89
+ setSvgValue("");
90
+ onValueChange?.(null);
91
+ return;
92
+ }
93
+ const preview = previewRef.current;
94
+ const style = preview ? getComputedStyle(preview) : null;
95
+ const fontSize = style ? Number.parseFloat(style.fontSize) : 32;
96
+ const svg = typedSvg(text, box.width, box.height, style?.fontFamily ?? "serif", fontSize);
97
+ setSvgValue(svg);
98
+ onValueChange?.({ kind: "typed", svg, text, png: () => svgToPng(svg, box.width, box.height) });
99
+ };
100
+ const pointOf = (event) => {
101
+ const rect = svgRef.current.getBoundingClientRect();
102
+ return [(event.clientX - rect.left) / rect.width * box.width, (event.clientY - rect.top) / rect.height * box.height];
103
+ };
104
+ const baseWidth = size === "compact" ? 2 : 2.5;
105
+ const handlePointerDown = (event) => {
106
+ if (disabled || event.button !== 0) return;
107
+ event.preventDefault();
108
+ event.currentTarget.setPointerCapture(event.pointerId);
109
+ const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
110
+ path.setAttribute("class", "ds-signature-pad__stroke");
111
+ path.setAttribute("stroke-width", String(baseWidth));
112
+ liveRef.current?.appendChild(path);
113
+ const stroke = { points: [pointOf(event)], width: baseWidth };
114
+ drawing.current = { stroke, path, pressures: [event.pressure || 0.5] };
115
+ path.setAttribute("d", strokePath(stroke.points));
116
+ };
117
+ const handlePointerMove = (event) => {
118
+ const current = drawing.current;
119
+ if (!current) return;
120
+ const events = event.nativeEvent.getCoalescedEvents?.() ?? [event.nativeEvent];
121
+ for (const e of events.length ? events : [event.nativeEvent]) {
122
+ current.stroke.points.push(pointOf(e));
123
+ if (e.pointerType !== "mouse") current.pressures.push(e.pressure || 0.5);
124
+ }
125
+ current.path.setAttribute("d", strokePath(current.stroke.points));
126
+ };
127
+ const finishStroke = () => {
128
+ const current = drawing.current;
129
+ if (!current) return;
130
+ drawing.current = null;
131
+ current.path.remove();
132
+ const average = current.pressures.reduce((a, b) => a + b, 0) / current.pressures.length;
133
+ current.stroke.width = baseWidth * (0.5 + average);
134
+ const next = [...strokes, current.stroke];
135
+ setStrokes(next);
136
+ emitDrawn(next);
137
+ setAnnouncement(addedLabel);
138
+ };
139
+ const undo = () => {
140
+ const next = strokes.slice(0, -1);
141
+ setStrokes(next);
142
+ emitDrawn(next);
143
+ };
144
+ const clear = () => {
145
+ if (activeTab === "draw") {
146
+ setStrokes([]);
147
+ emitDrawn([]);
148
+ } else {
149
+ setTyped("");
150
+ emitTyped("");
151
+ }
152
+ setAnnouncement(clearedLabel);
153
+ };
154
+ const switchTab = (next) => {
155
+ const target = next === "type" ? "type" : "draw";
156
+ setTab(target);
157
+ if (target === "type") emitTyped(typed);
158
+ else emitDrawn(strokes);
159
+ };
160
+ const empty = activeTab === "draw" ? strokes.length === 0 : typed.trim() === "";
161
+ const invalid = Boolean(error) || errorText != null && errorText !== false && errorText !== "";
162
+ const classes = [
163
+ "ds-signature-pad",
164
+ `ds-signature-pad--${size}`,
165
+ `ds-signature-pad--height-${height}`,
166
+ invalid && "ds-signature-pad--error",
167
+ disabled && "ds-signature-pad--disabled",
168
+ className
169
+ ].filter(Boolean).join(" ");
170
+ const drawPanelId = `${baseId}-draw`;
171
+ const typePanelId = `${baseId}-type`;
172
+ return /* @__PURE__ */ jsx(
173
+ Field,
174
+ {
175
+ ...rest,
176
+ ref,
177
+ id: baseId,
178
+ className: classes,
179
+ label,
180
+ helperText,
181
+ errorText,
182
+ error,
183
+ required,
184
+ disabled,
185
+ size,
186
+ group: true,
187
+ children: /* @__PURE__ */ jsxs("div", { className: "ds-signature-pad__body", role: "group", "aria-labelledby": label ? `${baseId}-label` : void 0, children: [
188
+ mode === "both" && /* @__PURE__ */ jsx(
189
+ SegmentedControl,
190
+ {
191
+ className: "ds-signature-pad__mode",
192
+ "aria-label": modeLabel,
193
+ size: "compact",
194
+ segments: [
195
+ { value: "draw", label: drawLabel, panelId: drawPanelId, disabled },
196
+ { value: "type", label: typeLabel, panelId: typePanelId, disabled }
197
+ ],
198
+ value: activeTab,
199
+ onValueChange: switchTab
200
+ }
201
+ ),
202
+ activeTab === "draw" ? /* @__PURE__ */ jsxs(
203
+ "div",
204
+ {
205
+ className: "ds-signature-pad__surface",
206
+ id: drawPanelId,
207
+ role: mode === "both" ? "tabpanel" : void 0,
208
+ "aria-label": mode === "both" ? drawLabel : void 0,
209
+ children: [
210
+ /* @__PURE__ */ jsx("div", { className: "ds-signature-pad__baseline", "aria-hidden": "true", children: empty && /* @__PURE__ */ jsx("span", { className: "ds-signature-pad__placeholder", children: placeholderLabel }) }),
211
+ /* @__PURE__ */ jsxs(
212
+ "svg",
213
+ {
214
+ ref: svgRef,
215
+ className: "ds-signature-pad__canvas",
216
+ viewBox: `0 0 ${box.width} ${box.height}`,
217
+ role: "img",
218
+ "aria-label": padLabel,
219
+ "aria-disabled": disabled || void 0,
220
+ onPointerDown: handlePointerDown,
221
+ onPointerMove: handlePointerMove,
222
+ onPointerUp: finishStroke,
223
+ onPointerCancel: finishStroke,
224
+ onLostPointerCapture: finishStroke,
225
+ children: [
226
+ strokes.map((stroke, index) => /* @__PURE__ */ jsx("path", { className: "ds-signature-pad__stroke", d: strokePath(stroke.points), strokeWidth: stroke.width }, index)),
227
+ /* @__PURE__ */ jsx("g", { ref: liveRef })
228
+ ]
229
+ }
230
+ )
231
+ ]
232
+ }
233
+ ) : /* @__PURE__ */ jsxs(
234
+ "div",
235
+ {
236
+ className: "ds-signature-pad__typed",
237
+ id: typePanelId,
238
+ role: mode === "both" ? "tabpanel" : void 0,
239
+ "aria-label": mode === "both" ? typeLabel : void 0,
240
+ children: [
241
+ /* @__PURE__ */ jsx(
242
+ Input,
243
+ {
244
+ label: mode === "type" && label ? void 0 : nameLabel,
245
+ "aria-label": mode === "type" && label ? label : void 0,
246
+ size,
247
+ value: typed,
248
+ disabled,
249
+ autoComplete: "name",
250
+ onValueChange: (text) => {
251
+ setTyped(text);
252
+ emitTyped(text);
253
+ }
254
+ }
255
+ ),
256
+ /* @__PURE__ */ jsxs("div", { className: "ds-signature-pad__surface ds-signature-pad__surface--typed", "aria-hidden": "true", children: [
257
+ /* @__PURE__ */ jsx("div", { className: "ds-signature-pad__baseline", children: empty && /* @__PURE__ */ jsx("span", { className: "ds-signature-pad__placeholder", children: placeholderLabel }) }),
258
+ /* @__PURE__ */ jsx("span", { ref: previewRef, className: "ds-signature-pad__preview", children: typed })
259
+ ] })
260
+ ]
261
+ }
262
+ ),
263
+ /* @__PURE__ */ jsxs("div", { className: "ds-signature-pad__actions", children: [
264
+ activeTab === "draw" && /* @__PURE__ */ jsx(
265
+ Button,
266
+ {
267
+ variant: "tertiary",
268
+ size: "compact",
269
+ iconLeft: "undo",
270
+ label: undoLabel,
271
+ disabled: disabled || strokes.length === 0,
272
+ onClick: undo
273
+ }
274
+ ),
275
+ /* @__PURE__ */ jsx(Button, { variant: "tertiary", size: "compact", label: clearLabel, disabled: disabled || empty, onClick: clear })
276
+ ] }),
277
+ /* @__PURE__ */ jsx("span", { className: "ds-visually-hidden", "aria-live": "polite", children: announcement }),
278
+ name && /* @__PURE__ */ jsx("input", { type: "hidden", name, value: svgValue, disabled })
279
+ ] })
280
+ }
281
+ );
282
+ }
283
+ export {
284
+ SignaturePad,
285
+ strokePath,
286
+ svgToPng
287
+ };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The drawing half of SignaturePad without React: strokes as points, the
3
+ * smoothed path each draws, and the SVG and PNG a signature is kept as.
4
+ */
5
+ /** One stroke: the points the pointer passed through, in the pad's own units, and the line's width. */
6
+ export type SignatureStroke = {
7
+ points: [number, number][];
8
+ width: number;
9
+ };
10
+ /** A signature as the pad hands it over. */
11
+ export type SignatureValue = {
12
+ /** Whether it was drawn or typed. */
13
+ kind: 'drawn' | 'typed';
14
+ /** The signature as a standalone SVG document in `currentColor`, so it scales and prints. */
15
+ svg: string;
16
+ /** The typed name, for a typed signature. */
17
+ text?: string;
18
+ /** Renders the signature to a PNG on demand, at twice its size. */
19
+ png: () => Promise<Blob>;
20
+ };
21
+ /**
22
+ * A stroke's path, smoothed: a quadratic curve through the midpoints of
23
+ * successive points, so a slow hand's jitter and a fast hand's gaps both
24
+ * read as one line. A single point is a dot.
25
+ */
26
+ export declare function strokePath(points: readonly [number, number][]): string;
27
+ /** Drawn strokes as a standalone SVG document. */
28
+ export declare function drawnSvg(strokes: readonly SignatureStroke[], width: number, height: number): string;
29
+ /** A typed name as a standalone SVG document, set on the baseline in the face it was shown in. */
30
+ export declare function typedSvg(text: string, width: number, height: number, fontFamily: string, fontSize: number): string;
31
+ /** An SVG document drawn onto a canvas and read back as a PNG, at `scale` times its size. */
32
+ export declare function svgToPng(svg: string, width: number, height: number, scale?: number): Promise<Blob>;
@@ -0,0 +1,46 @@
1
+ const round = (n) => Math.round(n * 10) / 10;
2
+ function strokePath(points) {
3
+ if (points.length === 0) return "";
4
+ const [x0, y0] = points[0];
5
+ if (points.length === 1) return `M${round(x0)} ${round(y0)}l0.1 0`;
6
+ let d = `M${round(x0)} ${round(y0)}`;
7
+ for (let i = 1; i < points.length - 1; i++) {
8
+ const [x, y] = points[i];
9
+ const [nx, ny] = points[i + 1];
10
+ d += `Q${round(x)} ${round(y)} ${round((x + nx) / 2)} ${round((y + ny) / 2)}`;
11
+ }
12
+ const [lx, ly] = points[points.length - 1];
13
+ return `${d}L${round(lx)} ${round(ly)}`;
14
+ }
15
+ const escapeXml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
16
+ function drawnSvg(strokes, width, height) {
17
+ const paths = strokes.map(
18
+ (s) => `<path d="${strokePath(s.points)}" fill="none" stroke="currentColor" stroke-width="${round(s.width)}" stroke-linecap="round" stroke-linejoin="round"/>`
19
+ ).join("");
20
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${round(width)} ${round(height)}" width="${round(width)}" height="${round(height)}">${paths}</svg>`;
21
+ }
22
+ function typedSvg(text, width, height, fontFamily, fontSize) {
23
+ return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${round(width)} ${round(height)}" width="${round(width)}" height="${round(height)}"><text x="${round(width * 0.06)}" y="${round(height * 0.7)}" fill="currentColor" font-family="${escapeXml(fontFamily)}" font-style="italic" font-size="${round(fontSize)}">${escapeXml(text)}</text></svg>`;
24
+ }
25
+ function svgToPng(svg, width, height, scale = 2) {
26
+ return new Promise((resolve, reject) => {
27
+ const image = new Image();
28
+ image.onload = () => {
29
+ const canvas = document.createElement("canvas");
30
+ canvas.width = Math.ceil(width * scale);
31
+ canvas.height = Math.ceil(height * scale);
32
+ const context = canvas.getContext("2d");
33
+ if (!context) return reject(new Error("No 2D canvas context"));
34
+ context.drawImage(image, 0, 0, canvas.width, canvas.height);
35
+ canvas.toBlob((blob) => blob ? resolve(blob) : reject(new Error("The canvas gave no PNG")), "image/png");
36
+ };
37
+ image.onerror = () => reject(new Error("The signature SVG did not load"));
38
+ image.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svg)}`;
39
+ });
40
+ }
41
+ export {
42
+ drawnSvg,
43
+ strokePath,
44
+ svgToPng,
45
+ typedSvg
46
+ };