@hussmartinez/ui 0.9.0 → 0.10.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 +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/react.d.ts +134 -1
- package/dist/react.js +292 -62
- package/dist/react.js.map +1 -1
- package/dist/shared/{pair-pt-vUVwu.js → pair-MeX064R6.js} +2 -1
- package/dist/shared/pair-MeX064R6.js.map +1 -0
- package/dist/styles.css +73 -0
- package/dist/ui.d.ts +134 -1
- package/package.json +1 -1
- package/dist/shared/pair-pt-vUVwu.js.map +0 -1
|
@@ -12,6 +12,7 @@ var uiMessages = /* @__PURE__ */ defineMessages({
|
|
|
12
12
|
"fileDropZone.hint": "or drop it here",
|
|
13
13
|
"fileDropZone.hintMultiple": "or drop them here",
|
|
14
14
|
"progress.label": "Progress",
|
|
15
|
+
"reorderableList.moved": "{label} moved to position {position} of {count}",
|
|
15
16
|
"spinner.label": "Loading",
|
|
16
17
|
"errors.INVALID_THEME_TOKEN": "The theme setting {token} has a value that can't be used.",
|
|
17
18
|
"errors.INVALID_THEME_SELECTOR": "The theme can't be applied to the selector {selector}."
|
|
@@ -41,4 +42,4 @@ function isThemePair(value) {
|
|
|
41
42
|
}
|
|
42
43
|
export { uiMessages as a, warnInDevelopment as i, cssWriterOf as n, UiError as o, registerTheme as r, isThemePair as t };
|
|
43
44
|
|
|
44
|
-
//# sourceMappingURL=pair-
|
|
45
|
+
//# sourceMappingURL=pair-MeX064R6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pair-MeX064R6.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 \"reorderableList.moved\": \"{label} moved to position {position} of {count}\",\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,yBAAyB;CACzB,iBAAiB;CACjB,8BAA8B;CAC9B,iCAAiC;AACnC,CAAC;;ACLD,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
|
@@ -1558,3 +1558,76 @@
|
|
|
1558
1558
|
}
|
|
1559
1559
|
}
|
|
1560
1560
|
}
|
|
1561
|
+
@layer hm.components {
|
|
1562
|
+
/*
|
|
1563
|
+
* Layout, focus and target size: kept with unstyled, so the list stays
|
|
1564
|
+
* usable and accessible.
|
|
1565
|
+
*/
|
|
1566
|
+
.hm-reorderable-list {
|
|
1567
|
+
box-sizing: border-box;
|
|
1568
|
+
display: grid;
|
|
1569
|
+
gap: var(--hm-reorderable-list-gap, var(--hm-gap-tight));
|
|
1570
|
+
grid-template-columns: minmax(0, 1fr);
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
.hm-reorderable-list-row {
|
|
1574
|
+
align-items: center;
|
|
1575
|
+
box-sizing: border-box;
|
|
1576
|
+
display: flex;
|
|
1577
|
+
gap: var(--hm-reorderable-list-gap, var(--hm-gap-tight));
|
|
1578
|
+
min-block-size: max(
|
|
1579
|
+
var(--hm-reorderable-list-row-height, var(--hm-control-height)),
|
|
1580
|
+
var(--hm-target-size)
|
|
1581
|
+
);
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
/* The item fills its row, so the whole row selects it. */
|
|
1585
|
+
.hm-reorderable-list-item {
|
|
1586
|
+
align-items: center;
|
|
1587
|
+
align-self: stretch;
|
|
1588
|
+
box-sizing: border-box;
|
|
1589
|
+
cursor: pointer;
|
|
1590
|
+
display: flex;
|
|
1591
|
+
flex: 1;
|
|
1592
|
+
gap: var(--hm-control-gap);
|
|
1593
|
+
min-inline-size: 0;
|
|
1594
|
+
padding-inline: var(--hm-reorderable-list-row-padding-x, var(--hm-control-padding-x));
|
|
1595
|
+
user-select: none;
|
|
1596
|
+
}
|
|
1597
|
+
|
|
1598
|
+
/* Inside the cell, so a scrolling panel around the list can't clip it. */
|
|
1599
|
+
.hm-reorderable-list-item:focus-visible {
|
|
1600
|
+
outline: var(--hm-focus-ring);
|
|
1601
|
+
outline-offset: calc(var(--hm-focus-ring-width) * -1);
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
.hm-reorderable-list-control {
|
|
1605
|
+
display: flex;
|
|
1606
|
+
flex: none;
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
/* Visual styles, dropped with unstyled. */
|
|
1610
|
+
.hm-reorderable-list:not([data-hm-unstyled]) .hm-reorderable-list-row:not([data-hm-unstyled]) {
|
|
1611
|
+
border: var(--hm-border-width) solid transparent;
|
|
1612
|
+
border-radius: var(--hm-reorderable-list-row-radius, var(--hm-radius-control));
|
|
1613
|
+
color: var(--hm-reorderable-list-row-fg, var(--hm-color-text));
|
|
1614
|
+
font-family: var(--hm-font-family);
|
|
1615
|
+
font-size: var(--hm-font-size-body);
|
|
1616
|
+
letter-spacing: var(--hm-letter-spacing);
|
|
1617
|
+
line-height: var(--hm-line-height-tight);
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
/* Selection shows as a boundary too, not only as a colour (WCAG 1.4.11). */
|
|
1621
|
+
.hm-reorderable-list:not([data-hm-unstyled])
|
|
1622
|
+
.hm-reorderable-list-row[aria-selected="true"]:not([data-hm-unstyled]) {
|
|
1623
|
+
background: var(--hm-reorderable-list-row-selected-bg, var(--hm-color-accent-subtle));
|
|
1624
|
+
border-color: var(--hm-reorderable-list-row-selected-border-color, var(--hm-color-accent));
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
@media (hover: hover) {
|
|
1628
|
+
.hm-reorderable-list:not([data-hm-unstyled])
|
|
1629
|
+
.hm-reorderable-list-row:not([aria-selected="true"], [data-hm-unstyled]):hover {
|
|
1630
|
+
background: var(--hm-reorderable-list-row-bg-hover, var(--hm-color-control-hover));
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
package/dist/ui.d.ts
CHANGED
|
@@ -626,7 +626,7 @@ export declare type IconComponent = (props: IconProps) => ReactElement;
|
|
|
626
626
|
*
|
|
627
627
|
* @public
|
|
628
628
|
*/
|
|
629
|
-
export declare type IconName = "add" | "arrow" | "check" | "chevron-down" | "chevron-left" | "chevron-right" | "close" | "crop" | "delete" | "download" | "duplicate" | "ellipse" | "fade-in" | "fade-out" | "fit" | "flip-horizontal" | "flip-vertical" | "hidden" | "highlighter" | "info" | "layers" | "loop" | "menu" | "more" | "move-down" | "move-up" | "muted" | "open" | "page-add" | "page-grid" | "page-single" | "pan" | "pause" | "pen" | "play" | "rectangle" | "redact" | "redo" | "remove" | "rotate-left" | "rotate-right" | "search" | "select" | "skip-back" | "skip-forward" | "snap" | "split" | "stop" | "text" | "trim-end" | "trim-start" | "undo" | "upload" | "visible" | "volume" | "warning" | "zoom-in" | "zoom-out";
|
|
629
|
+
export declare type IconName = "add" | "arrow" | "check" | "chevron-down" | "chevron-left" | "chevron-right" | "close" | "crop" | "delete" | "download" | "duplicate" | "ellipse" | "fade-in" | "fade-out" | "fit" | "flip-horizontal" | "flip-vertical" | "hidden" | "highlighter" | "image" | "info" | "layers" | "loop" | "menu" | "more" | "move-down" | "move-up" | "muted" | "open" | "page-add" | "page-grid" | "page-single" | "pan" | "pause" | "pen" | "play" | "rectangle" | "redact" | "redo" | "remove" | "rotate-left" | "rotate-right" | "search" | "select" | "skip-back" | "skip-forward" | "snap" | "split" | "stop" | "text" | "trim-end" | "trim-start" | "undo" | "upload" | "visible" | "volume" | "warning" | "zoom-in" | "zoom-out";
|
|
630
630
|
|
|
631
631
|
/**
|
|
632
632
|
* Props of every icon. SVG attributes are passed through.
|
|
@@ -642,6 +642,13 @@ export declare interface IconProps extends Omit<SVGProps<SVGSVGElement>, "childr
|
|
|
642
642
|
readonly label?: string | undefined;
|
|
643
643
|
}
|
|
644
644
|
|
|
645
|
+
/**
|
|
646
|
+
* The `image` icon: Lucide's `image`.
|
|
647
|
+
*
|
|
648
|
+
* @public
|
|
649
|
+
*/
|
|
650
|
+
export declare function ImageIcon(props: IconProps): ReactElement;
|
|
651
|
+
|
|
645
652
|
/**
|
|
646
653
|
* The `info` icon: Lucide's `info`.
|
|
647
654
|
*
|
|
@@ -902,6 +909,131 @@ export declare function RedoIcon(props: IconProps): ReactElement;
|
|
|
902
909
|
*/
|
|
903
910
|
export declare function RemoveIcon(props: IconProps): ReactElement;
|
|
904
911
|
|
|
912
|
+
/**
|
|
913
|
+
* A list whose items the user selects, reorders and removes, with one Tab
|
|
914
|
+
* stop and room for controls in each row (docs/adr/0009). It's a WAI-ARIA
|
|
915
|
+
* grid with one column of rows.
|
|
916
|
+
*
|
|
917
|
+
* - **↑ and ↓** move between rows and select; with Ctrl or ⌘, they move
|
|
918
|
+
* without selecting. **← and →**, Home and End move between a row's
|
|
919
|
+
* cells. Ctrl or ⌘ with Home or End goes to the first or last row.
|
|
920
|
+
* Space or Enter on an item selects it.
|
|
921
|
+
* - **Alt+↑ and Alt+↓** (Option on macOS) move the focused item, through
|
|
922
|
+
* `onMove`. **Delete and Backspace** remove it, through `onRemove`.
|
|
923
|
+
* - **You own the order.** The list calls `onMove` and `onRemove`, and you
|
|
924
|
+
* render the result. Focus stays with a moved item, and goes to the next
|
|
925
|
+
* one after a removal.
|
|
926
|
+
* - **Offer buttons too.** The keys are an addition: also render buttons
|
|
927
|
+
* that move the selected item, for touch and for people who don't know
|
|
928
|
+
* the keys, and name the keys on them with `aria-keyshortcuts`.
|
|
929
|
+
*
|
|
930
|
+
* @example
|
|
931
|
+
* ```tsx
|
|
932
|
+
* <ReorderableList
|
|
933
|
+
* label={t("layers.label")}
|
|
934
|
+
* selectedId={selected}
|
|
935
|
+
* onSelectedChange={setSelected}
|
|
936
|
+
* onMove={(id, toIndex) => session.moveLayer(id, toIndex)}
|
|
937
|
+
* onRemove={(id) => session.deleteLayer(id)}
|
|
938
|
+
* >
|
|
939
|
+
* {layers.map((layer) => (
|
|
940
|
+
* <ReorderableListItem
|
|
941
|
+
* key={layer.id}
|
|
942
|
+
* id={layer.id}
|
|
943
|
+
* label={layer.name}
|
|
944
|
+
* controls={[
|
|
945
|
+
* <ToggleButton
|
|
946
|
+
* key="visible"
|
|
947
|
+
* variant="quiet"
|
|
948
|
+
* label={t("layers.visible")}
|
|
949
|
+
* icon={<VisibleIcon />}
|
|
950
|
+
* pressed={layer.visible}
|
|
951
|
+
* onPressedChange={(visible) => session.showLayer(layer.id, visible)}
|
|
952
|
+
* />,
|
|
953
|
+
* ]}
|
|
954
|
+
* >
|
|
955
|
+
* {layer.name}
|
|
956
|
+
* </ReorderableListItem>
|
|
957
|
+
* ))}
|
|
958
|
+
* </ReorderableList>
|
|
959
|
+
* ```
|
|
960
|
+
*
|
|
961
|
+
* @public
|
|
962
|
+
*/
|
|
963
|
+
export declare const ReorderableList: ForwardRefExoticComponent<ReorderableListProps & RefAttributes<HTMLDivElement>>;
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* An item of a {@link ReorderableList}: a row with the item's content, and a
|
|
967
|
+
* cell for each of its `controls`.
|
|
968
|
+
*
|
|
969
|
+
* @public
|
|
970
|
+
*/
|
|
971
|
+
export declare const ReorderableListItem: ForwardRefExoticComponent<ReorderableListItemProps & RefAttributes<HTMLDivElement>>;
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* The parts of a reorderable list's item that `classNames` can target.
|
|
975
|
+
*
|
|
976
|
+
* @public
|
|
977
|
+
*/
|
|
978
|
+
export declare type ReorderableListItemPart = "root" | "item" | "control";
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* Props of {@link ReorderableListItem}.
|
|
982
|
+
*
|
|
983
|
+
* @public
|
|
984
|
+
*/
|
|
985
|
+
export declare interface ReorderableListItemProps extends Omit<HTMLAttributes<HTMLDivElement>, "className" | "role" | "id">, StyleProps<ReorderableListItemPart> {
|
|
986
|
+
/** Identifies the item in `selectedId`, `onMove` and `onRemove`. Unique in the list. */
|
|
987
|
+
readonly id: string;
|
|
988
|
+
/**
|
|
989
|
+
* The item's accessible name, such as a layer's name. Start it with the
|
|
990
|
+
* text the item shows, if it shows any.
|
|
991
|
+
*/
|
|
992
|
+
readonly label: string;
|
|
993
|
+
/**
|
|
994
|
+
* The item's controls, such as a visibility toggle: one focusable control
|
|
995
|
+
* each, in its own cell. A control that can't act should stay focusable,
|
|
996
|
+
* as `focusableWhenDisabled` makes a button.
|
|
997
|
+
*/
|
|
998
|
+
readonly controls?: readonly ReactNode[] | undefined;
|
|
999
|
+
/** What the item shows. */
|
|
1000
|
+
readonly children?: ReactNode;
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
/**
|
|
1004
|
+
* Props of {@link ReorderableList}.
|
|
1005
|
+
*
|
|
1006
|
+
* @public
|
|
1007
|
+
*/
|
|
1008
|
+
export declare interface ReorderableListProps extends Omit<HTMLAttributes<HTMLDivElement>, "className" | "role">, StyleProps<"root"> {
|
|
1009
|
+
/** The list's accessible name, such as "Layers". Required. */
|
|
1010
|
+
readonly label: string;
|
|
1011
|
+
/** The selected item's `id`, or `null` for none. */
|
|
1012
|
+
readonly selectedId?: string | null | undefined;
|
|
1013
|
+
/** Called with an item's `id` when the user selects it. */
|
|
1014
|
+
readonly onSelectedChange?: ((id: string) => void) | undefined;
|
|
1015
|
+
/**
|
|
1016
|
+
* Called when the user moves an item with Alt+↑ or Alt+↓ (Option on
|
|
1017
|
+
* macOS), with its `id` and the position it should have, counted from 0.
|
|
1018
|
+
* Render the items in the new order, or leave them when the move isn't
|
|
1019
|
+
* allowed. Without it, the list doesn't reorder.
|
|
1020
|
+
*/
|
|
1021
|
+
readonly onMove?: ((id: string, toIndex: number) => void) | undefined;
|
|
1022
|
+
/**
|
|
1023
|
+
* Called when the user presses Delete or Backspace on an item, with its
|
|
1024
|
+
* `id`. Render the items without it. Without it, the keys do nothing.
|
|
1025
|
+
*/
|
|
1026
|
+
readonly onRemove?: ((id: string) => void) | undefined;
|
|
1027
|
+
/**
|
|
1028
|
+
* Whether the list announces a move to screen readers, through the
|
|
1029
|
+
* closest `AnnouncerProvider`. Defaults to `true`; pass `false` when you
|
|
1030
|
+
* announce it in your own words.
|
|
1031
|
+
*/
|
|
1032
|
+
readonly announceMoves?: boolean | undefined;
|
|
1033
|
+
/** The items: {@link ReorderableListItem} elements, in the order shown. */
|
|
1034
|
+
readonly children?: ReactNode;
|
|
1035
|
+
}
|
|
1036
|
+
|
|
905
1037
|
/**
|
|
906
1038
|
* The `rotate-left` icon: Lucide's `rotate-ccw`.
|
|
907
1039
|
*
|
|
@@ -1599,6 +1731,7 @@ export declare const uiMessages: {
|
|
|
1599
1731
|
readonly "fileDropZone.hint": "or drop it here";
|
|
1600
1732
|
readonly "fileDropZone.hintMultiple": "or drop them here";
|
|
1601
1733
|
readonly "progress.label": "Progress";
|
|
1734
|
+
readonly "reorderableList.moved": "{label} moved to position {position} of {count}";
|
|
1602
1735
|
readonly "spinner.label": "Loading";
|
|
1603
1736
|
readonly "errors.INVALID_THEME_TOKEN": "The theme setting {token} has a value that can't be used.";
|
|
1604
1737
|
readonly "errors.INVALID_THEME_SELECTOR": "The theme can't be applied to the selector {selector}.";
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
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"}
|