@hussmartinez/ui 0.8.0 → 0.9.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 +3 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +113 -0
- package/dist/react.js +227 -33
- package/dist/react.js.map +1 -1
- package/dist/shared/{pair-DLVFV6vU.js → pair-pt-vUVwu.js} +2 -1
- package/dist/shared/pair-pt-vUVwu.js.map +1 -0
- package/dist/styles.css +112 -0
- package/dist/ui.d.ts +113 -0
- package/package.json +1 -1
- package/dist/shared/pair-DLVFV6vU.js.map +0 -1
|
@@ -5,6 +5,7 @@ var UiError = class extends SdkError {
|
|
|
5
5
|
};
|
|
6
6
|
// src/messages/en.ts
|
|
7
7
|
var uiMessages = /* @__PURE__ */ defineMessages({
|
|
8
|
+
"colorField.swatches": "swatches",
|
|
8
9
|
"dialog.close": "Close",
|
|
9
10
|
"fileDropZone.choose": "Choose a file",
|
|
10
11
|
"fileDropZone.chooseMultiple": "Choose files",
|
|
@@ -40,4 +41,4 @@ function isThemePair(value) {
|
|
|
40
41
|
}
|
|
41
42
|
export { uiMessages as a, warnInDevelopment as i, cssWriterOf as n, UiError as o, registerTheme as r, isThemePair as t };
|
|
42
43
|
|
|
43
|
-
//# sourceMappingURL=pair-
|
|
44
|
+
//# sourceMappingURL=pair-pt-vUVwu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pair-pt-vUVwu.js","names":[],"sources":["../../src/errors/ui-error.ts","../../src/messages/en.ts","../../src/internal/development.ts","../../src/theme/registry.ts","../../src/theme/pair.ts"],"sourcesContent":["import { SdkError } from \"@hussmartinez/sdk-core\";\n\n/**\n * Error codes of `@hussmartinez/ui`. They never change once released.\n *\n * - `INVALID_THEME_TOKEN`: a theme token has an unknown name, or a value that\n * isn't allowed for its type. `details` has `token`, `value` and `reason`.\n * - `INVALID_THEME_SELECTOR`: the selector passed to `themeToCss` isn't a\n * plain CSS selector. `details` has `selector` and `reason`.\n *\n * @public\n */\nexport type UiErrorCode = \"INVALID_THEME_TOKEN\" | \"INVALID_THEME_SELECTOR\";\n\n/**\n * The error `@hussmartinez/ui` throws, with a stable `code` and structured\n * `details`. Show users the text for its code from {@link uiMessages}, never\n * its `message`.\n *\n * @example\n * ```ts\n * try {\n * createTheme({ extends: \"light\", tokens: { \"color-accent\": brandColour } });\n * } catch (error) {\n * if (isSdkError(error, \"INVALID_THEME_TOKEN\")) {\n * // Ask for another colour.\n * }\n * }\n * ```\n *\n * @public\n */\nexport class UiError extends SdkError<UiErrorCode> {\n override readonly name = \"UiError\";\n}\n","import { defineMessages } from \"@hussmartinez/sdk-core\";\n\n/**\n * English text for `@hussmartinez/ui`'s error codes. Applications and SDKs\n * spread it into their catalogue, next to `sdkCoreMessages`, so\n * `messages.error()` can describe a `UiError`. Components add their\n * text here as they arrive.\n *\n * @example\n * ```ts\n * export const en = defineMessages({ ...sdkCoreMessages, ...uiMessages });\n * ```\n *\n * @public\n */\nexport const uiMessages = /* @__PURE__ */ defineMessages({\n \"colorField.swatches\": \"swatches\",\n \"dialog.close\": \"Close\",\n \"fileDropZone.choose\": \"Choose a file\",\n \"fileDropZone.chooseMultiple\": \"Choose files\",\n \"fileDropZone.hint\": \"or drop it here\",\n \"fileDropZone.hintMultiple\": \"or drop them here\",\n \"progress.label\": \"Progress\",\n \"spinner.label\": \"Loading\",\n \"errors.INVALID_THEME_TOKEN\": \"The theme setting {token} has a value that can't be used.\",\n \"errors.INVALID_THEME_SELECTOR\": \"The theme can't be applied to the selector {selector}.\",\n});\n","declare const process: { readonly env: { readonly NODE_ENV?: string } };\n\n/**\n * Whether development-only checks and warnings are on, as a runtime check.\n * The same pattern as sdk-core's.\n *\n * It keeps a forgotten guard from warning in production, but it can't make a\n * bundle smaller: a bundler can't see through a function call, so the\n * message passed to {@link warnInDevelopment} would still ship. Every call\n * site therefore also guards itself inline, with exactly this expression,\n * which bundlers fold away when they replace `process.env.NODE_ENV`:\n *\n * ```ts\n * if (typeof process !== \"undefined\" && process.env.NODE_ENV !== \"production\") {\n * warnInDevelopment(`…`);\n * }\n * ```\n *\n * `development.test.ts` checks every call site, and `build.test.ts` checks\n * that a production bundle drops the messages. Where nothing defines\n * `process`, such as a page loading the module directly, warnings are off.\n */\nexport function isDevelopment(): boolean {\n try {\n return process.env.NODE_ENV !== \"production\";\n } catch {\n return false;\n }\n}\n\n/**\n * Logs a development-only warning. Call it only inside the inline guard\n * shown on {@link isDevelopment}.\n *\n * @param message - What's wrong and how to fix it.\n */\nexport function warnInDevelopment(message: string): void {\n if (isDevelopment()) {\n // biome-ignore lint/suspicious/noConsole: development-only diagnostics are the purpose of this helper.\n console.warn(`[@hussmartinez/ui] ${message}`);\n }\n}\n","import type { Theme } from \"./types.js\";\n\n/** Writes validated themes as CSS. Lives in css-writer.ts. */\nexport type CssWriter = (light: Theme, dark: Theme | undefined, selector: string) => string;\n\n/**\n * Themes from `createTheme`, with the function that writes them as CSS.\n *\n * Kept apart from `createTheme` so `ThemeProvider` can apply themes without\n * importing the validator, the colour parser or the token data: an\n * application that only uses the built-in themes doesn't ship them.\n */\nconst writers = /* @__PURE__ */ new WeakMap<Theme, CssWriter>();\n\n/** Records a validated theme, and how to write it as CSS. */\nexport function registerTheme(theme: Theme, writer: CssWriter): void {\n writers.set(theme, writer);\n}\n\n/**\n * The CSS writer of a theme from `createTheme`, or `undefined` for anything\n * else, such as a theme parsed from JSON.\n */\nexport function cssWriterOf(theme: unknown): CssWriter | undefined {\n return typeof theme === \"object\" && theme !== null ? writers.get(theme as Theme) : undefined;\n}\n","import type { Theme, ThemePair } from \"./types.js\";\n\n/** Whether a value is a light and dark pair rather than a single theme. */\nexport function isThemePair(value: Theme | ThemePair): value is ThemePair {\n return typeof value === \"object\" && value !== null && \"light\" in value && \"dark\" in value;\n}\n"],"mappings":";;AAgCA,IAAa,UAAb,cAA6B,SAAsB;CACjD,OAAyB;AAC3B;;ACnBA,IAAa,aAA6B,+BAAe;CACvD,uBAAuB;CACvB,gBAAgB;CAChB,uBAAuB;CACvB,+BAA+B;CAC/B,qBAAqB;CACrB,6BAA6B;CAC7B,kBAAkB;CAClB,iBAAiB;CACjB,8BAA8B;CAC9B,iCAAiC;AACnC,CAAC;;ACJD,SAAgB,gBAAyB;CACvC,IAAI;EACF,OAAA,QAAA,IAAA,aAAgC;CAClC,QAAQ;EACN,OAAO;CACT;AACF;AAQA,SAAgB,kBAAkB,SAAuB;CACvD,IAAI,cAAc,GAEhB,QAAQ,KAAK,sBAAsB,SAAS;AAEhD;;AC7BA,IAAM,0BAA0B,IAAI,QAA0B;AAG9D,SAAgB,cAAc,OAAc,QAAyB;CACnE,QAAQ,IAAI,OAAO,MAAM;AAC3B;AAMA,SAAgB,YAAY,OAAuC;CACjE,OAAO,OAAO,UAAU,YAAY,UAAU,OAAO,QAAQ,IAAI,KAAc,IAAI,KAAA;AACrF;;ACtBA,SAAgB,YAAY,OAA8C;CACxE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,WAAW,SAAS,UAAU;AACtF"}
|
package/dist/styles.css
CHANGED
|
@@ -1219,6 +1219,118 @@
|
|
|
1219
1219
|
}
|
|
1220
1220
|
}
|
|
1221
1221
|
}
|
|
1222
|
+
@layer hm.components {
|
|
1223
|
+
/*
|
|
1224
|
+
* A text field with several lines: text-field.css gives it the field's
|
|
1225
|
+
* size floor, focus ring, colours, border and states, and this adds what
|
|
1226
|
+
* lines of text need. Kept with unstyled.
|
|
1227
|
+
*/
|
|
1228
|
+
.hm-text-area {
|
|
1229
|
+
max-inline-size: 100%;
|
|
1230
|
+
padding-block: var(--hm-text-area-padding-y, var(--hm-inset-tight));
|
|
1231
|
+
/* Taller only: a wider area would break the layout around it. */
|
|
1232
|
+
resize: vertical;
|
|
1233
|
+
/* An inline box would leave room for descenders under it. */
|
|
1234
|
+
vertical-align: top;
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
/* Visual styles, dropped with unstyled. */
|
|
1238
|
+
.hm-text-area:not([data-hm-unstyled]) {
|
|
1239
|
+
line-height: var(--hm-line-height-body);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
@layer hm.components {
|
|
1243
|
+
/*
|
|
1244
|
+
* Layout, focus and target size: kept with unstyled, so the field stays
|
|
1245
|
+
* usable and accessible. The input is a text field, with its class and
|
|
1246
|
+
* tokens.
|
|
1247
|
+
*/
|
|
1248
|
+
.hm-color-field {
|
|
1249
|
+
box-sizing: border-box;
|
|
1250
|
+
display: inline-grid;
|
|
1251
|
+
gap: var(--hm-color-field-gap, var(--hm-gap-tight));
|
|
1252
|
+
grid-template-columns: minmax(0, 1fr);
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1255
|
+
.hm-color-field-control {
|
|
1256
|
+
display: flex;
|
|
1257
|
+
gap: var(--hm-color-field-gap, var(--hm-gap-tight));
|
|
1258
|
+
}
|
|
1259
|
+
|
|
1260
|
+
/* As wide as the input is tall, and stretched to its height. */
|
|
1261
|
+
.hm-color-field-preview {
|
|
1262
|
+
box-sizing: border-box;
|
|
1263
|
+
flex: none;
|
|
1264
|
+
inline-size: max(var(--hm-text-field-height, var(--hm-control-height)), var(--hm-target-size));
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
.hm-color-field-input {
|
|
1268
|
+
flex: 1;
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
.hm-color-field-swatches {
|
|
1272
|
+
display: flex;
|
|
1273
|
+
flex-wrap: wrap;
|
|
1274
|
+
gap: var(--hm-color-field-gap, var(--hm-gap-tight));
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
/* The padding keeps the checked ring apart from the colour. */
|
|
1278
|
+
.hm-color-field-swatch {
|
|
1279
|
+
block-size: max(
|
|
1280
|
+
var(--hm-color-field-swatch-size, var(--hm-control-height-small)),
|
|
1281
|
+
var(--hm-target-size)
|
|
1282
|
+
);
|
|
1283
|
+
box-sizing: border-box;
|
|
1284
|
+
cursor: pointer;
|
|
1285
|
+
display: inline-flex;
|
|
1286
|
+
inline-size: max(
|
|
1287
|
+
var(--hm-color-field-swatch-size, var(--hm-control-height-small)),
|
|
1288
|
+
var(--hm-target-size)
|
|
1289
|
+
);
|
|
1290
|
+
padding: var(--hm-focus-ring-offset);
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
.hm-color-field-swatch:focus-visible {
|
|
1294
|
+
outline: var(--hm-focus-ring);
|
|
1295
|
+
outline-offset: var(--hm-focus-ring-offset);
|
|
1296
|
+
}
|
|
1297
|
+
|
|
1298
|
+
.hm-color-field-swatch:disabled {
|
|
1299
|
+
cursor: not-allowed;
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
.hm-color-field-swatch-fill {
|
|
1303
|
+
block-size: 100%;
|
|
1304
|
+
box-sizing: border-box;
|
|
1305
|
+
inline-size: 100%;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
/*
|
|
1309
|
+
* Visual styles, dropped with unstyled. Every colour has a border, so one
|
|
1310
|
+
* close to the surface's still shows its edge (WCAG 1.4.11).
|
|
1311
|
+
*/
|
|
1312
|
+
.hm-color-field:not([data-hm-unstyled]) .hm-color-field-preview,
|
|
1313
|
+
.hm-color-field:not([data-hm-unstyled]) .hm-color-field-swatch-fill {
|
|
1314
|
+
border: var(--hm-border-width) solid
|
|
1315
|
+
var(--hm-color-field-swatch-border-color, var(--hm-color-border-strong));
|
|
1316
|
+
border-radius: var(--hm-color-field-swatch-radius, var(--hm-radius-control));
|
|
1317
|
+
}
|
|
1318
|
+
|
|
1319
|
+
.hm-color-field:not([data-hm-unstyled]) .hm-color-field-swatch {
|
|
1320
|
+
background: transparent;
|
|
1321
|
+
border: var(--hm-focus-ring-width) solid transparent;
|
|
1322
|
+
border-radius: var(--hm-color-field-swatch-radius, var(--hm-radius-control));
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
/* The checked swatch has a ring, whatever its colour. */
|
|
1326
|
+
.hm-color-field:not([data-hm-unstyled]) .hm-color-field-swatch[aria-checked="true"] {
|
|
1327
|
+
border-color: var(--hm-color-field-swatch-checked-border-color, var(--hm-color-text));
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
.hm-color-field:not([data-hm-unstyled]) .hm-color-field-swatch:disabled {
|
|
1331
|
+
opacity: var(--hm-opacity-disabled);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1222
1334
|
@layer hm.components {
|
|
1223
1335
|
.hm-spinner {
|
|
1224
1336
|
block-size: var(--hm-spinner-size, var(--hm-icon-size));
|
package/dist/ui.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ import { RefAttributes } from 'react';
|
|
|
24
24
|
import { RefObject } from 'react';
|
|
25
25
|
import type { ShortcutPart } from '@hussmartinez/sdk-core';
|
|
26
26
|
import type { SVGProps } from 'react';
|
|
27
|
+
import { TextareaHTMLAttributes } from 'react';
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* The `add` icon: Lucide's `plus`.
|
|
@@ -175,6 +176,68 @@ export declare type ClassNames<Part extends string> = {
|
|
|
175
176
|
*/
|
|
176
177
|
export declare function CloseIcon(props: IconProps): ReactElement;
|
|
177
178
|
|
|
179
|
+
/**
|
|
180
|
+
* A colour input: a hex field with a preview of the colour, and optional
|
|
181
|
+
* swatches to pick from. It works with the keyboard alone and doesn't use
|
|
182
|
+
* the browser's own colour picker, which differs between browsers and can't
|
|
183
|
+
* be themed or translated.
|
|
184
|
+
*
|
|
185
|
+
* - **The input** takes `#rrggbb`, `#rgb` or either without the `#`. Typing
|
|
186
|
+
* doesn't change the value: the text is committed on blur or Enter. Text
|
|
187
|
+
* that isn't a colour goes back to the last value, and Escape throws the
|
|
188
|
+
* typing away.
|
|
189
|
+
* - **The swatches** are a radio group: one Tab stop, and the arrow keys move
|
|
190
|
+
* and select. A swatch is checked while the value is its colour.
|
|
191
|
+
* - **The value** is always lowercase `#rrggbb`. With `name`, forms receive it.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```tsx
|
|
195
|
+
* <Field label={t("shape.fill")}>
|
|
196
|
+
* <ColorField
|
|
197
|
+
* value={fill}
|
|
198
|
+
* onValueChange={setFill}
|
|
199
|
+
* swatches={[
|
|
200
|
+
* { value: "#d92d20", label: t("colors.red") },
|
|
201
|
+
* { value: "#1570ef", label: t("colors.blue") },
|
|
202
|
+
* ]}
|
|
203
|
+
* />
|
|
204
|
+
* </Field>
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* @public
|
|
208
|
+
*/
|
|
209
|
+
export declare const ColorField: ForwardRefExoticComponent<ColorFieldProps & RefAttributes<HTMLDivElement>>;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* The parts of a colour field that `classNames` can target.
|
|
213
|
+
*
|
|
214
|
+
* @public
|
|
215
|
+
*/
|
|
216
|
+
export declare type ColorFieldPart = "root" | "control" | "preview" | "input" | "swatches" | "swatch";
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Props of {@link ColorField}. Other props go to the hex input.
|
|
220
|
+
*
|
|
221
|
+
* @public
|
|
222
|
+
*/
|
|
223
|
+
export declare interface ColorFieldProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "className" | "type" | "value" | "defaultValue" | "onChange">, StyleProps<ColorFieldPart> {
|
|
224
|
+
/** The colour, as `#rrggbb`. With it, the field is controlled. */
|
|
225
|
+
readonly value?: string | undefined;
|
|
226
|
+
/** The first colour of an uncontrolled field. Defaults to `#000000`. */
|
|
227
|
+
readonly defaultValue?: string | undefined;
|
|
228
|
+
/** Called with the new colour, always as lowercase `#rrggbb`. */
|
|
229
|
+
readonly onValueChange?: ((value: string) => void) | undefined;
|
|
230
|
+
/** Colours to pick from, shown under the input. Leave it out for the input alone. */
|
|
231
|
+
readonly swatches?: readonly ColorSwatch[] | undefined;
|
|
232
|
+
/**
|
|
233
|
+
* The accessible name, such as "Fill". Leave it out inside a `Field`, or
|
|
234
|
+
* when a visible `<label>` points at the field's `id`.
|
|
235
|
+
*/
|
|
236
|
+
readonly label?: string | undefined;
|
|
237
|
+
/** The word that follows the label in the swatch group's name. Defaults to "swatches". */
|
|
238
|
+
readonly swatchesLabel?: string | undefined;
|
|
239
|
+
}
|
|
240
|
+
|
|
178
241
|
/**
|
|
179
242
|
* How a subtree picks between light and dark: one of them, or whichever the
|
|
180
243
|
* operating system prefers (`prefers-color-scheme`).
|
|
@@ -183,6 +246,18 @@ export declare function CloseIcon(props: IconProps): ReactElement;
|
|
|
183
246
|
*/
|
|
184
247
|
export declare type ColorMode = "light" | "dark" | "system";
|
|
185
248
|
|
|
249
|
+
/**
|
|
250
|
+
* A colour a {@link ColorField} offers as a swatch.
|
|
251
|
+
*
|
|
252
|
+
* @public
|
|
253
|
+
*/
|
|
254
|
+
export declare interface ColorSwatch {
|
|
255
|
+
/** The colour, as `#rrggbb` or `#rgb`. */
|
|
256
|
+
readonly value: string;
|
|
257
|
+
/** The swatch's accessible name, such as "Red". Use text from your message catalogue. */
|
|
258
|
+
readonly label: string;
|
|
259
|
+
}
|
|
260
|
+
|
|
186
261
|
/**
|
|
187
262
|
* The `crop` icon: Lucide's `crop`.
|
|
188
263
|
*
|
|
@@ -1064,6 +1139,43 @@ export declare interface StyleProps<Part extends string> {
|
|
|
1064
1139
|
readonly unstyled?: boolean | undefined;
|
|
1065
1140
|
}
|
|
1066
1141
|
|
|
1142
|
+
/**
|
|
1143
|
+
* A multi-line text input, styled like `TextField`, with its tokens. `rows`
|
|
1144
|
+
* sets its height, three by default, and the user can drag it taller. Inside
|
|
1145
|
+
* a `Field`, it takes the field's label, description and error.
|
|
1146
|
+
*
|
|
1147
|
+
* Enter adds a line, so it doesn't submit a form. Its value separates lines
|
|
1148
|
+
* with `\n`, whatever was pasted.
|
|
1149
|
+
*
|
|
1150
|
+
* @example
|
|
1151
|
+
* ```tsx
|
|
1152
|
+
* <Field label={t("text.content")}>
|
|
1153
|
+
* <TextArea value={text} onValueChange={setText} rows={4} />
|
|
1154
|
+
* </Field>
|
|
1155
|
+
* ```
|
|
1156
|
+
*
|
|
1157
|
+
* @public
|
|
1158
|
+
*/
|
|
1159
|
+
export declare const TextArea: ForwardRefExoticComponent<TextAreaProps & RefAttributes<HTMLTextAreaElement>>;
|
|
1160
|
+
|
|
1161
|
+
/**
|
|
1162
|
+
* Props of {@link TextArea}. Native textarea props are passed through, so it
|
|
1163
|
+
* works controlled with `value` and `onChange`, or uncontrolled with
|
|
1164
|
+
* `defaultValue`.
|
|
1165
|
+
*
|
|
1166
|
+
* @public
|
|
1167
|
+
*/
|
|
1168
|
+
export declare interface TextAreaProps extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, "className">, StyleProps<"root"> {
|
|
1169
|
+
/** Called with the new text as it changes, as well as `onChange`. */
|
|
1170
|
+
readonly onValueChange?: ((value: string) => void) | undefined;
|
|
1171
|
+
/**
|
|
1172
|
+
* The accessible name, such as "Caption". Leave it out inside a `Field`,
|
|
1173
|
+
* or when a visible `<label>` points at the field's `id`, or
|
|
1174
|
+
* `aria-labelledby` names it.
|
|
1175
|
+
*/
|
|
1176
|
+
readonly label?: string | undefined;
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1067
1179
|
/**
|
|
1068
1180
|
* A single-line text input, styled like the family's other fields. Inside a
|
|
1069
1181
|
* `Field`, it takes the field's label, description and error.
|
|
@@ -1480,6 +1592,7 @@ export declare type UiMessages = Messages<typeof uiMessages>;
|
|
|
1480
1592
|
* @public
|
|
1481
1593
|
*/
|
|
1482
1594
|
export declare const uiMessages: {
|
|
1595
|
+
readonly "colorField.swatches": "swatches";
|
|
1483
1596
|
readonly "dialog.close": "Close";
|
|
1484
1597
|
readonly "fileDropZone.choose": "Choose a file";
|
|
1485
1598
|
readonly "fileDropZone.chooseMultiple": "Choose files";
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pair-DLVFV6vU.js","names":[],"sources":["../../src/errors/ui-error.ts","../../src/messages/en.ts","../../src/internal/development.ts","../../src/theme/registry.ts","../../src/theme/pair.ts"],"sourcesContent":["import { SdkError } from \"@hussmartinez/sdk-core\";\n\n/**\n * Error codes of `@hussmartinez/ui`. They never change once released.\n *\n * - `INVALID_THEME_TOKEN`: a theme token has an unknown name, or a value that\n * isn't allowed for its type. `details` has `token`, `value` and `reason`.\n * - `INVALID_THEME_SELECTOR`: the selector passed to `themeToCss` isn't a\n * plain CSS selector. `details` has `selector` and `reason`.\n *\n * @public\n */\nexport type UiErrorCode = \"INVALID_THEME_TOKEN\" | \"INVALID_THEME_SELECTOR\";\n\n/**\n * The error `@hussmartinez/ui` throws, with a stable `code` and structured\n * `details`. Show users the text for its code from {@link uiMessages}, never\n * its `message`.\n *\n * @example\n * ```ts\n * try {\n * createTheme({ extends: \"light\", tokens: { \"color-accent\": brandColour } });\n * } catch (error) {\n * if (isSdkError(error, \"INVALID_THEME_TOKEN\")) {\n * // Ask for another colour.\n * }\n * }\n * ```\n *\n * @public\n */\nexport class UiError extends SdkError<UiErrorCode> {\n override readonly name = \"UiError\";\n}\n","import { defineMessages } from \"@hussmartinez/sdk-core\";\n\n/**\n * English text for `@hussmartinez/ui`'s error codes. Applications and SDKs\n * spread it into their catalogue, next to `sdkCoreMessages`, so\n * `messages.error()` can describe a `UiError`. Components add their\n * text here as they arrive.\n *\n * @example\n * ```ts\n * export const en = defineMessages({ ...sdkCoreMessages, ...uiMessages });\n * ```\n *\n * @public\n */\nexport const uiMessages = /* @__PURE__ */ defineMessages({\n \"dialog.close\": \"Close\",\n \"fileDropZone.choose\": \"Choose a file\",\n \"fileDropZone.chooseMultiple\": \"Choose files\",\n \"fileDropZone.hint\": \"or drop it here\",\n \"fileDropZone.hintMultiple\": \"or drop them here\",\n \"progress.label\": \"Progress\",\n \"spinner.label\": \"Loading\",\n \"errors.INVALID_THEME_TOKEN\": \"The theme setting {token} has a value that can't be used.\",\n \"errors.INVALID_THEME_SELECTOR\": \"The theme can't be applied to the selector {selector}.\",\n});\n","declare const process: { readonly env: { readonly NODE_ENV?: string } };\n\n/**\n * Whether development-only checks and warnings are on, as a runtime check.\n * The same pattern as sdk-core's.\n *\n * It keeps a forgotten guard from warning in production, but it can't make a\n * bundle smaller: a bundler can't see through a function call, so the\n * message passed to {@link warnInDevelopment} would still ship. Every call\n * site therefore also guards itself inline, with exactly this expression,\n * which bundlers fold away when they replace `process.env.NODE_ENV`:\n *\n * ```ts\n * if (typeof process !== \"undefined\" && process.env.NODE_ENV !== \"production\") {\n * warnInDevelopment(`…`);\n * }\n * ```\n *\n * `development.test.ts` checks every call site, and `build.test.ts` checks\n * that a production bundle drops the messages. Where nothing defines\n * `process`, such as a page loading the module directly, warnings are off.\n */\nexport function isDevelopment(): boolean {\n try {\n return process.env.NODE_ENV !== \"production\";\n } catch {\n return false;\n }\n}\n\n/**\n * Logs a development-only warning. Call it only inside the inline guard\n * shown on {@link isDevelopment}.\n *\n * @param message - What's wrong and how to fix it.\n */\nexport function warnInDevelopment(message: string): void {\n if (isDevelopment()) {\n // biome-ignore lint/suspicious/noConsole: development-only diagnostics are the purpose of this helper.\n console.warn(`[@hussmartinez/ui] ${message}`);\n }\n}\n","import type { Theme } from \"./types.js\";\n\n/** Writes validated themes as CSS. Lives in css-writer.ts. */\nexport type CssWriter = (light: Theme, dark: Theme | undefined, selector: string) => string;\n\n/**\n * Themes from `createTheme`, with the function that writes them as CSS.\n *\n * Kept apart from `createTheme` so `ThemeProvider` can apply themes without\n * importing the validator, the colour parser or the token data: an\n * application that only uses the built-in themes doesn't ship them.\n */\nconst writers = /* @__PURE__ */ new WeakMap<Theme, CssWriter>();\n\n/** Records a validated theme, and how to write it as CSS. */\nexport function registerTheme(theme: Theme, writer: CssWriter): void {\n writers.set(theme, writer);\n}\n\n/**\n * The CSS writer of a theme from `createTheme`, or `undefined` for anything\n * else, such as a theme parsed from JSON.\n */\nexport function cssWriterOf(theme: unknown): CssWriter | undefined {\n return typeof theme === \"object\" && theme !== null ? writers.get(theme as Theme) : undefined;\n}\n","import type { Theme, ThemePair } from \"./types.js\";\n\n/** Whether a value is a light and dark pair rather than a single theme. */\nexport function isThemePair(value: Theme | ThemePair): value is ThemePair {\n return typeof value === \"object\" && value !== null && \"light\" in value && \"dark\" in value;\n}\n"],"mappings":";;AAgCA,IAAa,UAAb,cAA6B,SAAsB;CACjD,OAAyB;AAC3B;;ACnBA,IAAa,aAA6B,+BAAe;CACvD,gBAAgB;CAChB,uBAAuB;CACvB,+BAA+B;CAC/B,qBAAqB;CACrB,6BAA6B;CAC7B,kBAAkB;CAClB,iBAAiB;CACjB,8BAA8B;CAC9B,iCAAiC;AACnC,CAAC;;ACHD,SAAgB,gBAAyB;CACvC,IAAI;EACF,OAAA,QAAA,IAAA,aAAgC;CAClC,QAAQ;EACN,OAAO;CACT;AACF;AAQA,SAAgB,kBAAkB,SAAuB;CACvD,IAAI,cAAc,GAEhB,QAAQ,KAAK,sBAAsB,SAAS;AAEhD;;AC7BA,IAAM,0BAA0B,IAAI,QAA0B;AAG9D,SAAgB,cAAc,OAAc,QAAyB;CACnE,QAAQ,IAAI,OAAO,MAAM;AAC3B;AAMA,SAAgB,YAAY,OAAuC;CACjE,OAAO,OAAO,UAAU,YAAY,UAAU,OAAO,QAAQ,IAAI,KAAc,IAAI,KAAA;AACrF;;ACtBA,SAAgB,YAAY,OAA8C;CACxE,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,WAAW,SAAS,UAAU;AACtF"}
|