@derelicious/ds 0.0.0-stage → 0.2.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/CHANGELOG.md +22 -0
- package/LICENSE +21 -0
- package/README.md +147 -2
- package/dist/a2ui/Surface.css +140 -0
- package/dist/a2ui/Surface.css.d.ts +22 -0
- package/dist/a2ui/Surface.css.js +29 -0
- package/dist/a2ui/Surface.d.ts +56 -0
- package/dist/a2ui/Surface.js +1411 -0
- package/dist/a2ui/catalog.d.ts +93 -0
- package/dist/a2ui/catalog.js +1666 -0
- package/dist/a2ui/clientMessages.d.ts +36 -0
- package/dist/a2ui/clientMessages.js +65 -0
- package/dist/a2ui/examples.d.ts +8 -0
- package/dist/a2ui/examples.js +877 -0
- package/dist/a2ui/functions.d.ts +55 -0
- package/dist/a2ui/functions.js +341 -0
- package/dist/a2ui/ids.d.ts +5 -0
- package/dist/a2ui/ids.js +7 -0
- package/dist/a2ui/index.d.ts +16 -0
- package/dist/a2ui/index.js +12 -0
- package/dist/a2ui/jsonl.d.ts +41 -0
- package/dist/a2ui/jsonl.js +127 -0
- package/dist/a2ui/links.d.ts +17 -0
- package/dist/a2ui/links.js +29 -0
- package/dist/a2ui/pointer.d.ts +22 -0
- package/dist/a2ui/pointer.js +85 -0
- package/dist/a2ui/processor.d.ts +126 -0
- package/dist/a2ui/processor.js +497 -0
- package/dist/a2ui/react.d.ts +2 -0
- package/dist/a2ui/react.js +1 -0
- package/dist/a2ui/toTsx.d.ts +9 -0
- package/dist/a2ui/toTsx.js +1389 -0
- package/dist/a2ui/types.d.ts +96 -0
- package/dist/a2ui/validate.d.ts +90 -0
- package/dist/a2ui/validate.js +750 -0
- package/dist/a2ui-catalog.json +4369 -0
- package/dist/a2ui-conformance.json +71 -0
- package/dist/components/Accordion/Accordion.css +58 -0
- package/dist/components/Accordion/Accordion.css.d.ts +5 -0
- package/dist/components/Accordion/Accordion.css.js +10 -0
- package/dist/components/Accordion/Accordion.d.ts +23 -0
- package/dist/components/Accordion/Accordion.docs.d.ts +19 -0
- package/dist/components/Accordion/Accordion.docs.js +43 -0
- package/dist/components/Accordion/Accordion.js +55 -0
- package/dist/components/Accordion/index.d.ts +1 -0
- package/dist/components/Accordion/index.js +1 -0
- package/dist/components/AiLabel/AiLabel.css +70 -0
- package/dist/components/AiLabel/AiLabel.css.d.ts +8 -0
- package/dist/components/AiLabel/AiLabel.css.js +11 -0
- package/dist/components/AiLabel/AiLabel.d.ts +29 -0
- package/dist/components/AiLabel/AiLabel.docs.d.ts +19 -0
- package/dist/components/AiLabel/AiLabel.docs.js +51 -0
- package/dist/components/AiLabel/AiLabel.js +41 -0
- package/dist/components/AiLabel/index.d.ts +1 -0
- package/dist/components/AiLabel/index.js +1 -0
- package/dist/components/Alert/Alert.css +76 -0
- package/dist/components/Alert/Alert.css.d.ts +9 -0
- package/dist/components/Alert/Alert.css.js +23 -0
- package/dist/components/Alert/Alert.d.ts +21 -0
- package/dist/components/Alert/Alert.docs.d.ts +19 -0
- package/dist/components/Alert/Alert.docs.js +57 -0
- package/dist/components/Alert/Alert.js +55 -0
- package/dist/components/Alert/index.d.ts +1 -0
- package/dist/components/Alert/index.js +1 -0
- package/dist/components/Avatar/Avatar.css +42 -0
- package/dist/components/Avatar/Avatar.css.d.ts +3 -0
- package/dist/components/Avatar/Avatar.css.js +12 -0
- package/dist/components/Avatar/Avatar.d.ts +13 -0
- package/dist/components/Avatar/Avatar.docs.d.ts +19 -0
- package/dist/components/Avatar/Avatar.docs.js +43 -0
- package/dist/components/Avatar/Avatar.js +31 -0
- package/dist/components/Avatar/index.d.ts +1 -0
- package/dist/components/Avatar/index.js +1 -0
- package/dist/components/Avatar/initials.d.ts +2 -0
- package/dist/components/Avatar/initials.js +8 -0
- package/dist/components/Badge/Badge.css +63 -0
- package/dist/components/Badge/Badge.css.d.ts +5 -0
- package/dist/components/Badge/Badge.css.js +16 -0
- package/dist/components/Badge/Badge.d.ts +15 -0
- package/dist/components/Badge/Badge.docs.d.ts +19 -0
- package/dist/components/Badge/Badge.docs.js +52 -0
- package/dist/components/Badge/Badge.js +24 -0
- package/dist/components/Badge/index.d.ts +1 -0
- package/dist/components/Badge/index.js +1 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.css +40 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.css.d.ts +5 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.css.js +10 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +17 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.docs.d.ts +19 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.docs.js +38 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.js +48 -0
- package/dist/components/Breadcrumbs/index.d.ts +1 -0
- package/dist/components/Breadcrumbs/index.js +1 -0
- package/dist/components/Button/Button.css +101 -0
- package/dist/components/Button/Button.css.d.ts +72 -0
- package/dist/components/Button/Button.css.js +35 -0
- package/dist/components/Button/Button.d.ts +53 -0
- package/dist/components/Button/Button.docs.d.ts +19 -0
- package/dist/components/Button/Button.docs.js +71 -0
- package/dist/components/Button/Button.js +68 -0
- package/dist/components/Button/index.d.ts +1 -0
- package/dist/components/Button/index.js +1 -0
- package/dist/components/Card/Card.css +122 -0
- package/dist/components/Card/Card.css.d.ts +12 -0
- package/dist/components/Card/Card.css.js +25 -0
- package/dist/components/Card/Card.d.ts +306 -0
- package/dist/components/Card/Card.docs.d.ts +19 -0
- package/dist/components/Card/Card.docs.js +65 -0
- package/dist/components/Card/Card.js +53 -0
- package/dist/components/Card/index.d.ts +1 -0
- package/dist/components/Card/index.js +1 -0
- package/dist/components/ChatMessage/ChatMessage.css +56 -0
- package/dist/components/ChatMessage/ChatMessage.css.d.ts +7 -0
- package/dist/components/ChatMessage/ChatMessage.css.js +15 -0
- package/dist/components/ChatMessage/ChatMessage.d.ts +35 -0
- package/dist/components/ChatMessage/ChatMessage.docs.d.ts +19 -0
- package/dist/components/ChatMessage/ChatMessage.docs.js +45 -0
- package/dist/components/ChatMessage/ChatMessage.js +49 -0
- package/dist/components/ChatMessage/index.d.ts +1 -0
- package/dist/components/ChatMessage/index.js +1 -0
- package/dist/components/Checkbox/Checkbox.css +70 -0
- package/dist/components/Checkbox/Checkbox.css.d.ts +1 -0
- package/dist/components/Checkbox/Checkbox.css.js +6 -0
- package/dist/components/Checkbox/Checkbox.d.ts +28 -0
- package/dist/components/Checkbox/Checkbox.docs.d.ts +19 -0
- package/dist/components/Checkbox/Checkbox.docs.js +53 -0
- package/dist/components/Checkbox/Checkbox.js +63 -0
- package/dist/components/Checkbox/index.d.ts +1 -0
- package/dist/components/Checkbox/index.js +1 -0
- package/dist/components/Code/Code.css +12 -0
- package/dist/components/Code/Code.css.d.ts +1 -0
- package/dist/components/Code/Code.css.js +5 -0
- package/dist/components/Code/Code.d.ts +7 -0
- package/dist/components/Code/Code.docs.d.ts +19 -0
- package/dist/components/Code/Code.docs.js +26 -0
- package/dist/components/Code/Code.js +12 -0
- package/dist/components/Code/index.d.ts +1 -0
- package/dist/components/Code/index.js +1 -0
- package/dist/components/CodeBlock/CodeBlock.css +76 -0
- package/dist/components/CodeBlock/CodeBlock.css.d.ts +12 -0
- package/dist/components/CodeBlock/CodeBlock.css.js +21 -0
- package/dist/components/CodeBlock/CodeBlock.d.ts +19 -0
- package/dist/components/CodeBlock/CodeBlock.docs.d.ts +19 -0
- package/dist/components/CodeBlock/CodeBlock.docs.js +47 -0
- package/dist/components/CodeBlock/CodeBlock.js +82 -0
- package/dist/components/CodeBlock/highlight.d.ts +28 -0
- package/dist/components/CodeBlock/highlight.js +118 -0
- package/dist/components/CodeBlock/index.d.ts +1 -0
- package/dist/components/CodeBlock/index.js +1 -0
- package/dist/components/Container/Container.css +21 -0
- package/dist/components/Container/Container.css.d.ts +3 -0
- package/dist/components/Container/Container.css.js +12 -0
- package/dist/components/Container/Container.d.ts +295 -0
- package/dist/components/Container/Container.docs.d.ts +19 -0
- package/dist/components/Container/Container.docs.js +31 -0
- package/dist/components/Container/Container.js +12 -0
- package/dist/components/Container/index.d.ts +1 -0
- package/dist/components/Container/index.js +1 -0
- package/dist/components/Dialog/Dialog.css +94 -0
- package/dist/components/Dialog/Dialog.css.d.ts +9 -0
- package/dist/components/Dialog/Dialog.css.js +17 -0
- package/dist/components/Dialog/Dialog.d.ts +29 -0
- package/dist/components/Dialog/Dialog.docs.d.ts +19 -0
- package/dist/components/Dialog/Dialog.docs.js +50 -0
- package/dist/components/Dialog/Dialog.js +90 -0
- package/dist/components/Dialog/index.d.ts +1 -0
- package/dist/components/Dialog/index.js +1 -0
- package/dist/components/Divider/Divider.css +41 -0
- package/dist/components/Divider/Divider.css.d.ts +6 -0
- package/dist/components/Divider/Divider.css.js +16 -0
- package/dist/components/Divider/Divider.d.ts +11 -0
- package/dist/components/Divider/Divider.docs.d.ts +19 -0
- package/dist/components/Divider/Divider.docs.js +43 -0
- package/dist/components/Divider/Divider.js +30 -0
- package/dist/components/Divider/index.d.ts +1 -0
- package/dist/components/Divider/index.js +1 -0
- package/dist/components/Grid/Grid.css +11 -0
- package/dist/components/Grid/Grid.css.d.ts +8 -0
- package/dist/components/Grid/Grid.css.js +8 -0
- package/dist/components/Grid/Grid.d.ts +18 -0
- package/dist/components/Grid/Grid.docs.d.ts +19 -0
- package/dist/components/Grid/Grid.docs.js +41 -0
- package/dist/components/Grid/Grid.js +22 -0
- package/dist/components/Grid/index.d.ts +1 -0
- package/dist/components/Grid/index.js +1 -0
- package/dist/components/Heading/Heading.css +44 -0
- package/dist/components/Heading/Heading.css.d.ts +3 -0
- package/dist/components/Heading/Heading.css.js +17 -0
- package/dist/components/Heading/Heading.d.ts +298 -0
- package/dist/components/Heading/Heading.docs.d.ts +19 -0
- package/dist/components/Heading/Heading.docs.js +48 -0
- package/dist/components/Heading/Heading.js +20 -0
- package/dist/components/Heading/index.d.ts +1 -0
- package/dist/components/Heading/index.js +1 -0
- package/dist/components/Icon/Icon.css +25 -0
- package/dist/components/Icon/Icon.css.d.ts +4 -0
- package/dist/components/Icon/Icon.css.js +13 -0
- package/dist/components/Icon/Icon.d.ts +16 -0
- package/dist/components/Icon/Icon.docs.d.ts +19 -0
- package/dist/components/Icon/Icon.docs.js +56 -0
- package/dist/components/Icon/Icon.js +25 -0
- package/dist/components/Icon/index.d.ts +1 -0
- package/dist/components/Icon/index.js +1 -0
- package/dist/components/IconButton/IconButton.css +70 -0
- package/dist/components/IconButton/IconButton.css.d.ts +57 -0
- package/dist/components/IconButton/IconButton.css.js +27 -0
- package/dist/components/IconButton/IconButton.d.ts +46 -0
- package/dist/components/IconButton/IconButton.docs.d.ts +19 -0
- package/dist/components/IconButton/IconButton.docs.js +48 -0
- package/dist/components/IconButton/IconButton.js +44 -0
- package/dist/components/IconButton/index.d.ts +1 -0
- package/dist/components/IconButton/index.js +1 -0
- package/dist/components/Image/Image.css +53 -0
- package/dist/components/Image/Image.css.d.ts +7 -0
- package/dist/components/Image/Image.css.js +18 -0
- package/dist/components/Image/Image.d.ts +23 -0
- package/dist/components/Image/Image.docs.d.ts +19 -0
- package/dist/components/Image/Image.docs.js +48 -0
- package/dist/components/Image/Image.js +75 -0
- package/dist/components/Image/index.d.ts +1 -0
- package/dist/components/Image/index.js +1 -0
- package/dist/components/Inline/Inline.css +38 -0
- package/dist/components/Inline/Inline.css.d.ts +4 -0
- package/dist/components/Inline/Inline.css.js +18 -0
- package/dist/components/Inline/Inline.d.ts +300 -0
- package/dist/components/Inline/Inline.docs.d.ts +19 -0
- package/dist/components/Inline/Inline.docs.js +48 -0
- package/dist/components/Inline/Inline.js +13 -0
- package/dist/components/Inline/index.d.ts +1 -0
- package/dist/components/Inline/index.js +1 -0
- package/dist/components/Link/Link.css +57 -0
- package/dist/components/Link/Link.css.d.ts +5 -0
- package/dist/components/Link/Link.css.js +14 -0
- package/dist/components/Link/Link.d.ts +19 -0
- package/dist/components/Link/Link.docs.d.ts +19 -0
- package/dist/components/Link/Link.docs.js +51 -0
- package/dist/components/Link/Link.js +39 -0
- package/dist/components/Link/index.d.ts +1 -0
- package/dist/components/Link/index.js +1 -0
- package/dist/components/List/List.css +39 -0
- package/dist/components/List/List.css.d.ts +5 -0
- package/dist/components/List/List.css.js +14 -0
- package/dist/components/List/List.d.ts +294 -0
- package/dist/components/List/List.docs.d.ts +19 -0
- package/dist/components/List/List.docs.js +43 -0
- package/dist/components/List/List.js +25 -0
- package/dist/components/List/index.d.ts +1 -0
- package/dist/components/List/index.js +1 -0
- package/dist/components/Menu/Menu.css +65 -0
- package/dist/components/Menu/Menu.css.d.ts +5 -0
- package/dist/components/Menu/Menu.css.js +9 -0
- package/dist/components/Menu/Menu.d.ts +60 -0
- package/dist/components/Menu/Menu.docs.d.ts +19 -0
- package/dist/components/Menu/Menu.docs.js +53 -0
- package/dist/components/Menu/Menu.js +192 -0
- package/dist/components/Menu/index.d.ts +1 -0
- package/dist/components/Menu/index.js +1 -0
- package/dist/components/NavBar/NavBar.css +187 -0
- package/dist/components/NavBar/NavBar.css.d.ts +16 -0
- package/dist/components/NavBar/NavBar.css.js +19 -0
- package/dist/components/NavBar/NavBar.d.ts +31 -0
- package/dist/components/NavBar/NavBar.docs.d.ts +19 -0
- package/dist/components/NavBar/NavBar.docs.js +53 -0
- package/dist/components/NavBar/NavBar.js +110 -0
- package/dist/components/NavBar/index.d.ts +1 -0
- package/dist/components/NavBar/index.js +1 -0
- package/dist/components/Popover/Popover.css +28 -0
- package/dist/components/Popover/Popover.css.d.ts +3 -0
- package/dist/components/Popover/Popover.css.js +8 -0
- package/dist/components/Popover/Popover.d.ts +40 -0
- package/dist/components/Popover/Popover.docs.d.ts +19 -0
- package/dist/components/Popover/Popover.docs.js +50 -0
- package/dist/components/Popover/Popover.js +69 -0
- package/dist/components/Popover/index.d.ts +1 -0
- package/dist/components/Popover/index.js +1 -0
- package/dist/components/Progress/Progress.css +106 -0
- package/dist/components/Progress/Progress.css.d.ts +10 -0
- package/dist/components/Progress/Progress.css.js +24 -0
- package/dist/components/Progress/Progress.d.ts +23 -0
- package/dist/components/Progress/Progress.docs.d.ts +19 -0
- package/dist/components/Progress/Progress.docs.js +43 -0
- package/dist/components/Progress/Progress.js +54 -0
- package/dist/components/Progress/index.d.ts +1 -0
- package/dist/components/Progress/index.js +1 -0
- package/dist/components/PromptInput/PromptInput.css +25 -0
- package/dist/components/PromptInput/PromptInput.css.d.ts +5 -0
- package/dist/components/PromptInput/PromptInput.css.js +8 -0
- package/dist/components/PromptInput/PromptInput.d.ts +65 -0
- package/dist/components/PromptInput/PromptInput.docs.d.ts +19 -0
- package/dist/components/PromptInput/PromptInput.docs.js +45 -0
- package/dist/components/PromptInput/PromptInput.js +91 -0
- package/dist/components/PromptInput/index.d.ts +1 -0
- package/dist/components/PromptInput/index.js +1 -0
- package/dist/components/Quote/Quote.css +31 -0
- package/dist/components/Quote/Quote.css.d.ts +5 -0
- package/dist/components/Quote/Quote.css.js +9 -0
- package/dist/components/Quote/Quote.d.ts +13 -0
- package/dist/components/Quote/Quote.docs.d.ts +19 -0
- package/dist/components/Quote/Quote.docs.js +30 -0
- package/dist/components/Quote/Quote.js +26 -0
- package/dist/components/Quote/index.d.ts +1 -0
- package/dist/components/Quote/index.js +1 -0
- package/dist/components/RadioGroup/RadioGroup.css +70 -0
- package/dist/components/RadioGroup/RadioGroup.css.d.ts +4 -0
- package/dist/components/RadioGroup/RadioGroup.css.js +12 -0
- package/dist/components/RadioGroup/RadioGroup.d.ts +32 -0
- package/dist/components/RadioGroup/RadioGroup.docs.d.ts +19 -0
- package/dist/components/RadioGroup/RadioGroup.docs.js +47 -0
- package/dist/components/RadioGroup/RadioGroup.js +85 -0
- package/dist/components/RadioGroup/index.d.ts +1 -0
- package/dist/components/RadioGroup/index.js +1 -0
- package/dist/components/Select/Select.css +17 -0
- package/dist/components/Select/Select.css.d.ts +3 -0
- package/dist/components/Select/Select.css.js +7 -0
- package/dist/components/Select/Select.d.ts +26 -0
- package/dist/components/Select/Select.docs.d.ts +19 -0
- package/dist/components/Select/Select.docs.js +35 -0
- package/dist/components/Select/Select.js +57 -0
- package/dist/components/Select/index.d.ts +1 -0
- package/dist/components/Select/index.js +1 -0
- package/dist/components/SideNav/SideNav.css +74 -0
- package/dist/components/SideNav/SideNav.css.d.ts +7 -0
- package/dist/components/SideNav/SideNav.css.js +12 -0
- package/dist/components/SideNav/SideNav.d.ts +23 -0
- package/dist/components/SideNav/SideNav.docs.d.ts +19 -0
- package/dist/components/SideNav/SideNav.docs.js +43 -0
- package/dist/components/SideNav/SideNav.js +55 -0
- package/dist/components/SideNav/index.d.ts +1 -0
- package/dist/components/SideNav/index.js +1 -0
- package/dist/components/Skeleton/Skeleton.css +45 -0
- package/dist/components/Skeleton/Skeleton.css.d.ts +3 -0
- package/dist/components/Skeleton/Skeleton.css.js +11 -0
- package/dist/components/Skeleton/Skeleton.d.ts +25 -0
- package/dist/components/Skeleton/Skeleton.docs.d.ts +19 -0
- package/dist/components/Skeleton/Skeleton.docs.js +43 -0
- package/dist/components/Skeleton/Skeleton.js +27 -0
- package/dist/components/Skeleton/index.d.ts +1 -0
- package/dist/components/Skeleton/index.js +1 -0
- package/dist/components/Spinner/Spinner.css +46 -0
- package/dist/components/Spinner/Spinner.css.d.ts +5 -0
- package/dist/components/Spinner/Spinner.css.js +13 -0
- package/dist/components/Spinner/Spinner.d.ts +24 -0
- package/dist/components/Spinner/Spinner.docs.d.ts +19 -0
- package/dist/components/Spinner/Spinner.docs.js +44 -0
- package/dist/components/Spinner/Spinner.js +46 -0
- package/dist/components/Spinner/index.d.ts +1 -0
- package/dist/components/Spinner/index.js +1 -0
- package/dist/components/Stack/Stack.css +21 -0
- package/dist/components/Stack/Stack.css.d.ts +2 -0
- package/dist/components/Stack/Stack.css.js +10 -0
- package/dist/components/Stack/Stack.d.ts +296 -0
- package/dist/components/Stack/Stack.docs.d.ts +19 -0
- package/dist/components/Stack/Stack.docs.js +48 -0
- package/dist/components/Stack/Stack.js +13 -0
- package/dist/components/Stack/index.d.ts +1 -0
- package/dist/components/Stack/index.js +1 -0
- package/dist/components/Stat/Stat.css +59 -0
- package/dist/components/Stat/Stat.css.d.ts +13 -0
- package/dist/components/Stat/Stat.css.js +18 -0
- package/dist/components/Stat/Stat.d.ts +20 -0
- package/dist/components/Stat/Stat.docs.d.ts +19 -0
- package/dist/components/Stat/Stat.docs.js +52 -0
- package/dist/components/Stat/Stat.js +49 -0
- package/dist/components/Stat/index.d.ts +1 -0
- package/dist/components/Stat/index.js +1 -0
- package/dist/components/StreamingIndicator/StreamingIndicator.css +46 -0
- package/dist/components/StreamingIndicator/StreamingIndicator.css.d.ts +5 -0
- package/dist/components/StreamingIndicator/StreamingIndicator.css.js +13 -0
- package/dist/components/StreamingIndicator/StreamingIndicator.d.ts +22 -0
- package/dist/components/StreamingIndicator/StreamingIndicator.docs.d.ts +19 -0
- package/dist/components/StreamingIndicator/StreamingIndicator.docs.js +43 -0
- package/dist/components/StreamingIndicator/StreamingIndicator.js +31 -0
- package/dist/components/StreamingIndicator/index.d.ts +1 -0
- package/dist/components/StreamingIndicator/index.js +1 -0
- package/dist/components/Switch/Switch.css +89 -0
- package/dist/components/Switch/Switch.css.d.ts +4 -0
- package/dist/components/Switch/Switch.css.js +9 -0
- package/dist/components/Switch/Switch.d.ts +21 -0
- package/dist/components/Switch/Switch.docs.d.ts +19 -0
- package/dist/components/Switch/Switch.docs.js +36 -0
- package/dist/components/Switch/Switch.js +51 -0
- package/dist/components/Switch/index.d.ts +1 -0
- package/dist/components/Switch/index.js +1 -0
- package/dist/components/TabBar/TabBar.css +94 -0
- package/dist/components/TabBar/TabBar.css.d.ts +7 -0
- package/dist/components/TabBar/TabBar.css.js +12 -0
- package/dist/components/TabBar/TabBar.d.ts +23 -0
- package/dist/components/TabBar/TabBar.docs.d.ts +19 -0
- package/dist/components/TabBar/TabBar.docs.js +43 -0
- package/dist/components/TabBar/TabBar.js +50 -0
- package/dist/components/TabBar/index.d.ts +1 -0
- package/dist/components/TabBar/index.js +1 -0
- package/dist/components/Table/Table.css +75 -0
- package/dist/components/Table/Table.css.d.ts +10 -0
- package/dist/components/Table/Table.css.js +22 -0
- package/dist/components/Table/Table.d.ts +32 -0
- package/dist/components/Table/Table.docs.d.ts +19 -0
- package/dist/components/Table/Table.docs.js +49 -0
- package/dist/components/Table/Table.js +69 -0
- package/dist/components/Table/index.d.ts +1 -0
- package/dist/components/Table/index.js +1 -0
- package/dist/components/Tabs/Tabs.css +79 -0
- package/dist/components/Tabs/Tabs.css.d.ts +6 -0
- package/dist/components/Tabs/Tabs.css.js +14 -0
- package/dist/components/Tabs/Tabs.d.ts +33 -0
- package/dist/components/Tabs/Tabs.docs.d.ts +19 -0
- package/dist/components/Tabs/Tabs.docs.js +56 -0
- package/dist/components/Tabs/Tabs.js +90 -0
- package/dist/components/Tabs/index.d.ts +1 -0
- package/dist/components/Tabs/index.js +1 -0
- package/dist/components/Tag/Tag.css +63 -0
- package/dist/components/Tag/Tag.css.d.ts +5 -0
- package/dist/components/Tag/Tag.css.js +10 -0
- package/dist/components/Tag/Tag.d.ts +13 -0
- package/dist/components/Tag/Tag.docs.d.ts +19 -0
- package/dist/components/Tag/Tag.docs.js +39 -0
- package/dist/components/Tag/Tag.js +35 -0
- package/dist/components/Tag/index.d.ts +1 -0
- package/dist/components/Tag/index.js +1 -0
- package/dist/components/Text/Text.css +86 -0
- package/dist/components/Text/Text.css.d.ts +6 -0
- package/dist/components/Text/Text.css.js +39 -0
- package/dist/components/Text/Text.d.ts +310 -0
- package/dist/components/Text/Text.docs.d.ts +19 -0
- package/dist/components/Text/Text.docs.js +52 -0
- package/dist/components/Text/Text.js +12 -0
- package/dist/components/Text/index.d.ts +1 -0
- package/dist/components/Text/index.js +1 -0
- package/dist/components/TextArea/TextArea.css +8 -0
- package/dist/components/TextArea/TextArea.css.d.ts +1 -0
- package/dist/components/TextArea/TextArea.css.js +5 -0
- package/dist/components/TextArea/TextArea.d.ts +15 -0
- package/dist/components/TextArea/TextArea.docs.d.ts +19 -0
- package/dist/components/TextArea/TextArea.docs.js +31 -0
- package/dist/components/TextArea/TextArea.js +33 -0
- package/dist/components/TextArea/index.d.ts +1 -0
- package/dist/components/TextArea/index.js +1 -0
- package/dist/components/TextField/TextField.d.ts +14 -0
- package/dist/components/TextField/TextField.docs.d.ts +19 -0
- package/dist/components/TextField/TextField.docs.js +59 -0
- package/dist/components/TextField/TextField.js +32 -0
- package/dist/components/TextField/index.d.ts +1 -0
- package/dist/components/TextField/index.js +1 -0
- package/dist/components/Timeline/Timeline.css +100 -0
- package/dist/components/Timeline/Timeline.css.d.ts +10 -0
- package/dist/components/Timeline/Timeline.css.js +15 -0
- package/dist/components/Timeline/Timeline.d.ts +22 -0
- package/dist/components/Timeline/Timeline.docs.d.ts +19 -0
- package/dist/components/Timeline/Timeline.docs.js +39 -0
- package/dist/components/Timeline/Timeline.js +42 -0
- package/dist/components/Timeline/index.d.ts +1 -0
- package/dist/components/Timeline/index.js +1 -0
- package/dist/components/Toast/Toast.css +106 -0
- package/dist/components/Toast/Toast.css.d.ts +11 -0
- package/dist/components/Toast/Toast.css.js +25 -0
- package/dist/components/Toast/Toast.d.ts +30 -0
- package/dist/components/Toast/Toast.docs.d.ts +19 -0
- package/dist/components/Toast/Toast.docs.js +49 -0
- package/dist/components/Toast/Toast.js +68 -0
- package/dist/components/Toast/ToastProvider.d.ts +12 -0
- package/dist/components/Toast/ToastProvider.js +140 -0
- package/dist/components/Toast/index.d.ts +3 -0
- package/dist/components/Toast/index.js +4 -0
- package/dist/components/Toast/toast-context.d.ts +21 -0
- package/dist/components/Toast/toast-context.js +11 -0
- package/dist/components/Tooltip/Tooltip.css +18 -0
- package/dist/components/Tooltip/Tooltip.css.d.ts +1 -0
- package/dist/components/Tooltip/Tooltip.css.js +5 -0
- package/dist/components/Tooltip/Tooltip.d.ts +45 -0
- package/dist/components/Tooltip/Tooltip.docs.d.ts +19 -0
- package/dist/components/Tooltip/Tooltip.docs.js +47 -0
- package/dist/components/Tooltip/Tooltip.js +93 -0
- package/dist/components/Tooltip/index.d.ts +1 -0
- package/dist/components/Tooltip/index.js +1 -0
- package/dist/icons/index.d.ts +293 -0
- package/dist/icons/index.js +395 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.js +59 -0
- package/dist/internal/Field.d.ts +31 -0
- package/dist/internal/Field.js +54 -0
- package/dist/internal/field-ids.d.ts +7 -0
- package/dist/internal/field-ids.js +18 -0
- package/dist/internal/field.css +131 -0
- package/dist/internal/field.css.d.ts +16 -0
- package/dist/internal/field.css.js +22 -0
- package/dist/internal/floating-geometry.d.ts +42 -0
- package/dist/internal/floating-geometry.js +55 -0
- package/dist/internal/floating.css +36 -0
- package/dist/internal/floating.css.d.ts +8 -0
- package/dist/internal/floating.css.js +6 -0
- package/dist/internal/floating.d.ts +27 -0
- package/dist/internal/floating.js +118 -0
- package/dist/internal/useControllableState.d.ts +16 -0
- package/dist/internal/useControllableState.js +28 -0
- package/dist/internal/useOverflow.d.ts +7 -0
- package/dist/internal/useOverflow.js +24 -0
- package/dist/internal/usePopover.d.ts +28 -0
- package/dist/internal/usePopover.js +91 -0
- package/dist/manifest.json +12308 -0
- package/dist/patterns/dashboard-overview.docs.d.ts +22 -0
- package/dist/patterns/dashboard-overview.docs.js +80 -0
- package/dist/patterns/empty-state.docs.d.ts +22 -0
- package/dist/patterns/empty-state.docs.js +60 -0
- package/dist/patterns/index.d.ts +6 -0
- package/dist/patterns/index.js +14 -0
- package/dist/patterns/profile-card.docs.d.ts +22 -0
- package/dist/patterns/profile-card.docs.js +72 -0
- package/dist/patterns/settings-page.docs.d.ts +22 -0
- package/dist/patterns/settings-page.docs.js +76 -0
- package/dist/patterns/sign-in-form.docs.d.ts +22 -0
- package/dist/patterns/sign-in-form.docs.js +84 -0
- package/dist/primitives/VisuallyHidden.d.ts +13 -0
- package/dist/primitives/VisuallyHidden.js +18 -0
- package/dist/providers/LinkProvider.d.ts +18 -0
- package/dist/providers/LinkProvider.js +23 -0
- package/dist/providers/StringsProvider.d.ts +14 -0
- package/dist/providers/StringsProvider.js +25 -0
- package/dist/providers/link-context.d.ts +12 -0
- package/dist/providers/link-context.js +15 -0
- package/dist/providers/strings.d.ts +64 -0
- package/dist/providers/strings.js +38 -0
- package/dist/registry/gaps.d.ts +30 -0
- package/dist/registry/gaps.js +208 -0
- package/dist/registry/generated.d.ts +5 -0
- package/dist/registry/generated.js +2821 -0
- package/dist/registry/index.d.ts +36 -0
- package/dist/registry/index.js +201 -0
- package/dist/registry/types.d.ts +84 -0
- package/dist/styles/base.css +9 -0
- package/dist/styles/base.css.d.ts +1 -0
- package/dist/styles/base.css.js +1 -0
- package/dist/styles/layout.css +33 -0
- package/dist/styles/layout.css.d.ts +1 -0
- package/dist/styles/layout.css.js +17 -0
- package/dist/styles/shared.css +16 -0
- package/dist/styles/shared.css.d.ts +35 -0
- package/dist/styles/shared.css.js +5 -0
- package/dist/styles.css +3406 -0
- package/dist/themes/blueprint.css +115 -0
- package/dist/themes/contrast.d.ts +26 -0
- package/dist/themes/contrast.js +114 -0
- package/dist/themes/define.d.ts +9 -0
- package/dist/themes/define.js +29 -0
- package/dist/themes/dtcg.d.ts +126 -0
- package/dist/themes/dtcg.js +268 -0
- package/dist/themes/index.d.ts +19 -0
- package/dist/themes/index.js +21 -0
- package/dist/themes/letterpress.css +115 -0
- package/dist/themes/letterpress.d.ts +7 -0
- package/dist/themes/letterpress.js +187 -0
- package/dist/themes/presets/blueprint.d.ts +6 -0
- package/dist/themes/presets/blueprint.js +183 -0
- package/dist/themes/runtime/browser.d.ts +47 -0
- package/dist/themes/runtime/browser.js +164 -0
- package/dist/themes/runtime/cache.d.ts +43 -0
- package/dist/themes/runtime/cache.js +87 -0
- package/dist/themes/runtime/css.d.ts +43 -0
- package/dist/themes/runtime/css.js +89 -0
- package/dist/themes/runtime/diff.d.ts +22 -0
- package/dist/themes/runtime/diff.js +43 -0
- package/dist/themes/types.d.ts +59 -0
- package/dist/themes/values.d.ts +12 -0
- package/dist/themes/values.js +40 -0
- package/dist/tokens/blueprint.dark.tokens.json +1361 -0
- package/dist/tokens/blueprint.light.tokens.json +1361 -0
- package/dist/tokens/contract.d.ts +252 -0
- package/dist/tokens/contract.js +249 -0
- package/dist/tokens/index.d.ts +6 -0
- package/dist/tokens/index.js +1 -0
- package/dist/tokens/letterpress.dark.tokens.json +1391 -0
- package/dist/tokens/letterpress.light.tokens.json +1391 -0
- package/dist/tokens/tokens.css +117 -0
- package/dist/tokens/tokens.css.d.ts +128 -0
- package/dist/tokens/tokens.css.js +121 -0
- package/dist/utils/cx.d.ts +7 -0
- package/dist/utils/cx.js +14 -0
- package/dist/utils/space.d.ts +5 -0
- package/dist/utils/space.js +7 -0
- package/package.json +104 -3
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The catalog's client-side functions: formatting, checks, and logic. Pure,
|
|
3
|
+
* so the processor can evaluate bindings anywhere, including Node tests.
|
|
4
|
+
*/
|
|
5
|
+
import type { FunctionCall } from './types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Test text against a pattern from model output. Unsafe patterns (see
|
|
8
|
+
* `unsafePatternReason`) and over-long text never run; both count as no match.
|
|
9
|
+
*/
|
|
10
|
+
export declare function testPattern(pattern: unknown, text: string): boolean;
|
|
11
|
+
export type EvalContext = {
|
|
12
|
+
/** Read a data path relative to the current scope. */
|
|
13
|
+
read(path: string): unknown;
|
|
14
|
+
locale: string;
|
|
15
|
+
/** IANA time zone for dates. Undefined means the runtime's zone. */
|
|
16
|
+
timeZone?: string;
|
|
17
|
+
now: () => Date;
|
|
18
|
+
};
|
|
19
|
+
export declare function isBinding(value: unknown): value is {
|
|
20
|
+
path: string;
|
|
21
|
+
};
|
|
22
|
+
export declare function isFunctionCall(value: unknown): value is FunctionCall;
|
|
23
|
+
/**
|
|
24
|
+
* A readable name from an identifier: "skipPrevious" or "arrow-left" becomes
|
|
25
|
+
* "Skip previous" or "Arrow left". Used to name icon-only controls whose
|
|
26
|
+
* accessible name the model left out.
|
|
27
|
+
*/
|
|
28
|
+
export declare function humanize(name: string): string;
|
|
29
|
+
/** Resolve a literal, a binding, or a function call to its current value. */
|
|
30
|
+
export declare function evaluate(value: unknown, context: EvalContext): unknown;
|
|
31
|
+
/** Text for display: null and undefined become "". */
|
|
32
|
+
export declare function toText(value: unknown): string;
|
|
33
|
+
export declare function callFunction(call: FunctionCall, context: EvalContext): unknown;
|
|
34
|
+
export declare function formatNumber(value: unknown, locale: string, options?: {
|
|
35
|
+
decimals?: number | null;
|
|
36
|
+
grouping?: boolean;
|
|
37
|
+
}): string;
|
|
38
|
+
export declare function formatCurrency(value: unknown, currency: string, locale: string, options?: {
|
|
39
|
+
decimals?: number | null;
|
|
40
|
+
grouping?: boolean;
|
|
41
|
+
}): string;
|
|
42
|
+
/**
|
|
43
|
+
* Format a date with a Unicode TR35 pattern. Supports yyyy, yy, MMMM, MMM,
|
|
44
|
+
* MM, M, dd, d, EEEE, EEE, E, HH, H, hh, h, mm, m, ss, s, a, and quoted text.
|
|
45
|
+
*/
|
|
46
|
+
export declare function formatDate(value: unknown, pattern: string, options: {
|
|
47
|
+
locale: string;
|
|
48
|
+
timeZone?: string;
|
|
49
|
+
}): string;
|
|
50
|
+
/**
|
|
51
|
+
* Fill `${...}` expressions: `${/absolute/path}`, `${relative/path}`, and
|
|
52
|
+
* `${fn(name: value, other: 'text')}` where values are `${...}`, quoted text,
|
|
53
|
+
* numbers, true, false, or null. `\${` is a literal `${`.
|
|
54
|
+
*/
|
|
55
|
+
export declare function formatTemplate(template: string, context: EvalContext): string;
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
import { safeRegExp } from "./validate.js";
|
|
2
|
+
// src/a2ui/functions.ts
|
|
3
|
+
/**
|
|
4
|
+
* Test text against a pattern from model output. Unsafe patterns (see
|
|
5
|
+
* `unsafePatternReason`) and over-long text never run; both count as no match.
|
|
6
|
+
*/
|
|
7
|
+
function testPattern(pattern, text) {
|
|
8
|
+
if (text.length > 1e3) return false;
|
|
9
|
+
const regex = safeRegExp(pattern);
|
|
10
|
+
return regex ? regex.test(text) : false;
|
|
11
|
+
}
|
|
12
|
+
function isBinding(value) {
|
|
13
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.path === "string" && Object.keys(value).length === 1;
|
|
14
|
+
}
|
|
15
|
+
function isFunctionCall(value) {
|
|
16
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && typeof value.call === "string";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A readable name from an identifier: "skipPrevious" or "arrow-left" becomes
|
|
20
|
+
* "Skip previous" or "Arrow left". Used to name icon-only controls whose
|
|
21
|
+
* accessible name the model left out.
|
|
22
|
+
*/
|
|
23
|
+
function humanize(name) {
|
|
24
|
+
const words = name.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[-_]+/g, " ").trim().toLowerCase();
|
|
25
|
+
return words ? words.charAt(0).toUpperCase() + words.slice(1) : "";
|
|
26
|
+
}
|
|
27
|
+
/** Resolve a literal, a binding, or a function call to its current value. */
|
|
28
|
+
function evaluate(value, context) {
|
|
29
|
+
if (isBinding(value)) return context.read(value.path);
|
|
30
|
+
if (isFunctionCall(value)) return callFunction(value, context);
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
/** Text for display: null and undefined become "". */
|
|
34
|
+
function toText(value) {
|
|
35
|
+
if (value === null || value === void 0) return "";
|
|
36
|
+
if (typeof value === "string") return value;
|
|
37
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
38
|
+
if (Array.isArray(value)) return value.map(toText).join(", ");
|
|
39
|
+
try {
|
|
40
|
+
return JSON.stringify(value);
|
|
41
|
+
} catch {
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function toNumber(value) {
|
|
46
|
+
if (typeof value === "number") return Number.isFinite(value) ? value : null;
|
|
47
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
48
|
+
const parsed = Number(value);
|
|
49
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function isEmpty(value) {
|
|
54
|
+
return value === null || value === void 0 || value === "" || Array.isArray(value) && value.length === 0;
|
|
55
|
+
}
|
|
56
|
+
function callFunction(call, context) {
|
|
57
|
+
const args = call.args ?? {};
|
|
58
|
+
const arg = (name) => evaluate(args[name], context);
|
|
59
|
+
switch (call.call) {
|
|
60
|
+
case "required": return !isEmpty(arg("value"));
|
|
61
|
+
case "regex": return testPattern(args.pattern, toText(arg("value")));
|
|
62
|
+
case "length": {
|
|
63
|
+
const length = toText(arg("value")).length;
|
|
64
|
+
const min = toNumber(arg("min"));
|
|
65
|
+
const max = toNumber(arg("max"));
|
|
66
|
+
return (min === null || length >= min) && (max === null || length <= max);
|
|
67
|
+
}
|
|
68
|
+
case "numeric": {
|
|
69
|
+
const value = toNumber(arg("value"));
|
|
70
|
+
if (value === null) return false;
|
|
71
|
+
const min = toNumber(arg("min"));
|
|
72
|
+
const max = toNumber(arg("max"));
|
|
73
|
+
return (min === null || value >= min) && (max === null || value <= max);
|
|
74
|
+
}
|
|
75
|
+
case "email": return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(toText(arg("value")));
|
|
76
|
+
case "and": return (Array.isArray(args.values) ? args.values : []).every((item) => Boolean(evaluate(item, context)));
|
|
77
|
+
case "or": return (Array.isArray(args.values) ? args.values : []).some((item) => Boolean(evaluate(item, context)));
|
|
78
|
+
case "not": return !arg("value");
|
|
79
|
+
case "formatString": return formatTemplate(toText(arg("value")), context);
|
|
80
|
+
case "formatNumber": return formatNumber(arg("value"), context.locale, {
|
|
81
|
+
decimals: toNumber(arg("decimals")),
|
|
82
|
+
grouping: arg("grouping") !== false
|
|
83
|
+
});
|
|
84
|
+
case "formatCurrency": return formatCurrency(arg("value"), toText(arg("currency")), context.locale, {
|
|
85
|
+
decimals: toNumber(arg("decimals")),
|
|
86
|
+
grouping: arg("grouping") !== false
|
|
87
|
+
});
|
|
88
|
+
case "formatDate": return formatDate(arg("value"), toText(arg("format")), {
|
|
89
|
+
locale: context.locale,
|
|
90
|
+
timeZone: context.timeZone
|
|
91
|
+
});
|
|
92
|
+
case "pluralize": {
|
|
93
|
+
const count = toNumber(arg("value")) ?? 0;
|
|
94
|
+
const category = count === 0 && args.zero !== void 0 ? "zero" : new Intl.PluralRules(context.locale).select(count);
|
|
95
|
+
return toText(arg(args[category] !== void 0 ? category : "other"));
|
|
96
|
+
}
|
|
97
|
+
case "now": return context.now().toISOString();
|
|
98
|
+
case "openUrl":
|
|
99
|
+
case "showToast": return;
|
|
100
|
+
default: return;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function formatNumber(value, locale, options = {}) {
|
|
104
|
+
const number = toNumber(value);
|
|
105
|
+
if (number === null) return toText(value);
|
|
106
|
+
const decimals = options.decimals ?? void 0;
|
|
107
|
+
return new Intl.NumberFormat(locale, {
|
|
108
|
+
useGrouping: options.grouping !== false,
|
|
109
|
+
...decimals === void 0 ? {} : {
|
|
110
|
+
minimumFractionDigits: Math.max(0, Math.min(20, decimals)),
|
|
111
|
+
maximumFractionDigits: Math.max(0, Math.min(20, decimals))
|
|
112
|
+
}
|
|
113
|
+
}).format(number);
|
|
114
|
+
}
|
|
115
|
+
function formatCurrency(value, currency, locale, options = {}) {
|
|
116
|
+
const number = toNumber(value);
|
|
117
|
+
if (number === null) return toText(value);
|
|
118
|
+
const decimals = options.decimals ?? void 0;
|
|
119
|
+
try {
|
|
120
|
+
return new Intl.NumberFormat(locale, {
|
|
121
|
+
style: "currency",
|
|
122
|
+
currency: currency || "USD",
|
|
123
|
+
useGrouping: options.grouping !== false,
|
|
124
|
+
...decimals === void 0 ? {} : {
|
|
125
|
+
minimumFractionDigits: Math.max(0, Math.min(20, decimals)),
|
|
126
|
+
maximumFractionDigits: Math.max(0, Math.min(20, decimals))
|
|
127
|
+
}
|
|
128
|
+
}).format(number);
|
|
129
|
+
} catch {
|
|
130
|
+
return `${formatNumber(number, locale, options)} ${currency}`.trim();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function toDate(value) {
|
|
134
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? null : {
|
|
135
|
+
date: value,
|
|
136
|
+
dateOnly: false
|
|
137
|
+
};
|
|
138
|
+
if (typeof value === "number") {
|
|
139
|
+
const date = new Date(value);
|
|
140
|
+
return Number.isNaN(date.getTime()) ? null : {
|
|
141
|
+
date,
|
|
142
|
+
dateOnly: false
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
if (typeof value === "string" && value.trim() !== "") {
|
|
146
|
+
const date = new Date(value);
|
|
147
|
+
if (Number.isNaN(date.getTime())) return null;
|
|
148
|
+
return {
|
|
149
|
+
date,
|
|
150
|
+
dateOnly: /^\d{4}-\d{2}-\d{2}$/.test(value.trim())
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Format a date with a Unicode TR35 pattern. Supports yyyy, yy, MMMM, MMM,
|
|
157
|
+
* MM, M, dd, d, EEEE, EEE, E, HH, H, hh, h, mm, m, ss, s, a, and quoted text.
|
|
158
|
+
*/
|
|
159
|
+
function formatDate(value, pattern, options) {
|
|
160
|
+
const parsed = toDate(value);
|
|
161
|
+
if (!parsed) return toText(value);
|
|
162
|
+
const timeZone = parsed.dateOnly ? "UTC" : options.timeZone;
|
|
163
|
+
const parts = (opts) => Object.fromEntries(new Intl.DateTimeFormat(options.locale, {
|
|
164
|
+
timeZone,
|
|
165
|
+
...opts
|
|
166
|
+
}).formatToParts(parsed.date).map((part) => [part.type, part.value]));
|
|
167
|
+
const numeric = parts({
|
|
168
|
+
year: "numeric",
|
|
169
|
+
month: "numeric",
|
|
170
|
+
day: "numeric",
|
|
171
|
+
hour: "numeric",
|
|
172
|
+
minute: "numeric",
|
|
173
|
+
second: "numeric",
|
|
174
|
+
hourCycle: "h23"
|
|
175
|
+
});
|
|
176
|
+
const year = Number(numeric.year);
|
|
177
|
+
const month = Number(numeric.month);
|
|
178
|
+
const day = Number(numeric.day);
|
|
179
|
+
const hour = Number(numeric.hour) % 24;
|
|
180
|
+
const minute = Number(numeric.minute);
|
|
181
|
+
const second = Number(numeric.second);
|
|
182
|
+
const pad = (n, width = 2) => String(n).padStart(width, "0");
|
|
183
|
+
const named = (opts, type) => parts(opts)[type] ?? "";
|
|
184
|
+
const tokens = {
|
|
185
|
+
yyyy: () => String(year),
|
|
186
|
+
yy: () => pad(year % 100),
|
|
187
|
+
y: () => String(year),
|
|
188
|
+
MMMM: () => named({ month: "long" }, "month"),
|
|
189
|
+
MMM: () => named({ month: "short" }, "month"),
|
|
190
|
+
MM: () => pad(month),
|
|
191
|
+
M: () => String(month),
|
|
192
|
+
dd: () => pad(day),
|
|
193
|
+
d: () => String(day),
|
|
194
|
+
EEEE: () => named({ weekday: "long" }, "weekday"),
|
|
195
|
+
EEE: () => named({ weekday: "short" }, "weekday"),
|
|
196
|
+
E: () => named({ weekday: "short" }, "weekday"),
|
|
197
|
+
HH: () => pad(hour),
|
|
198
|
+
H: () => String(hour),
|
|
199
|
+
hh: () => pad(hour % 12 || 12),
|
|
200
|
+
h: () => String(hour % 12 || 12),
|
|
201
|
+
mm: () => pad(minute),
|
|
202
|
+
m: () => String(minute),
|
|
203
|
+
ss: () => pad(second),
|
|
204
|
+
s: () => String(second),
|
|
205
|
+
a: () => hour < 12 ? "AM" : "PM"
|
|
206
|
+
};
|
|
207
|
+
const order = Object.keys(tokens).sort((a, b) => b.length - a.length);
|
|
208
|
+
let out = "";
|
|
209
|
+
let index = 0;
|
|
210
|
+
while (index < pattern.length) {
|
|
211
|
+
const char = pattern[index];
|
|
212
|
+
if (char === "'") {
|
|
213
|
+
const end = pattern.indexOf("'", index + 1);
|
|
214
|
+
if (end === index + 1) {
|
|
215
|
+
out += "'";
|
|
216
|
+
index += 2;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const stop = end === -1 ? pattern.length : end;
|
|
220
|
+
out += pattern.slice(index + 1, stop);
|
|
221
|
+
index = stop + 1;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
const token = order.find((item) => pattern.startsWith(item, index));
|
|
225
|
+
if (token) {
|
|
226
|
+
out += tokens[token]();
|
|
227
|
+
index += token.length;
|
|
228
|
+
} else {
|
|
229
|
+
out += char;
|
|
230
|
+
index += 1;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Fill `${...}` expressions: `${/absolute/path}`, `${relative/path}`, and
|
|
237
|
+
* `${fn(name: value, other: 'text')}` where values are `${...}`, quoted text,
|
|
238
|
+
* numbers, true, false, or null. `\${` is a literal `${`.
|
|
239
|
+
*/
|
|
240
|
+
function formatTemplate(template, context) {
|
|
241
|
+
let out = "";
|
|
242
|
+
let index = 0;
|
|
243
|
+
while (index < template.length) {
|
|
244
|
+
if (template.startsWith("\\${", index)) {
|
|
245
|
+
out += "${";
|
|
246
|
+
index += 3;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (template.startsWith("${", index)) {
|
|
250
|
+
const end = matchingBrace(template, index + 2);
|
|
251
|
+
if (end === -1) {
|
|
252
|
+
out += template.slice(index);
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
const expression = template.slice(index + 2, end).trim();
|
|
256
|
+
out += toText(evaluateExpression(expression, context));
|
|
257
|
+
index = end + 1;
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
out += template[index];
|
|
261
|
+
index += 1;
|
|
262
|
+
}
|
|
263
|
+
return out;
|
|
264
|
+
}
|
|
265
|
+
/** Index of the `}` closing an expression that starts at `start`. */
|
|
266
|
+
function matchingBrace(text, start) {
|
|
267
|
+
let depth = 1;
|
|
268
|
+
let quote = null;
|
|
269
|
+
for (let index = start; index < text.length; index += 1) {
|
|
270
|
+
const char = text[index];
|
|
271
|
+
if (quote) {
|
|
272
|
+
if (char === "\\") index += 1;
|
|
273
|
+
else if (char === quote) quote = null;
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
if (char === "'" || char === "\"") quote = char;
|
|
277
|
+
else if (char === "{") depth += 1;
|
|
278
|
+
else if (char === "}") {
|
|
279
|
+
depth -= 1;
|
|
280
|
+
if (depth === 0) return index;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return -1;
|
|
284
|
+
}
|
|
285
|
+
function evaluateExpression(expression, context) {
|
|
286
|
+
const call = /^([A-Za-z_]\w*)\s*\(([\s\S]*)\)$/.exec(expression);
|
|
287
|
+
if (call) {
|
|
288
|
+
const args = {};
|
|
289
|
+
for (const part of splitArgs(call[2])) {
|
|
290
|
+
const colon = part.indexOf(":");
|
|
291
|
+
if (colon === -1) continue;
|
|
292
|
+
const name = part.slice(0, colon).trim();
|
|
293
|
+
args[name] = parseArgValue(part.slice(colon + 1).trim(), context);
|
|
294
|
+
}
|
|
295
|
+
return callFunction({
|
|
296
|
+
call: call[1],
|
|
297
|
+
args
|
|
298
|
+
}, context);
|
|
299
|
+
}
|
|
300
|
+
return context.read(expression);
|
|
301
|
+
}
|
|
302
|
+
/** Split "a: 1, b: 'x, y', c: ${f(a: 1, b: 2)}" at top-level commas. */
|
|
303
|
+
function splitArgs(text) {
|
|
304
|
+
const parts = [];
|
|
305
|
+
let depth = 0;
|
|
306
|
+
let quote = null;
|
|
307
|
+
let current = "";
|
|
308
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
309
|
+
const char = text[index];
|
|
310
|
+
if (quote) {
|
|
311
|
+
current += char;
|
|
312
|
+
if (char === "\\") {
|
|
313
|
+
current += text[index + 1] ?? "";
|
|
314
|
+
index += 1;
|
|
315
|
+
} else if (char === quote) quote = null;
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
if (char === "'" || char === "\"") quote = char;
|
|
319
|
+
if (char === "{" || char === "(") depth += 1;
|
|
320
|
+
if (char === "}" || char === ")") depth -= 1;
|
|
321
|
+
if (char === "," && depth === 0) {
|
|
322
|
+
parts.push(current);
|
|
323
|
+
current = "";
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
current += char;
|
|
327
|
+
}
|
|
328
|
+
if (current.trim()) parts.push(current);
|
|
329
|
+
return parts;
|
|
330
|
+
}
|
|
331
|
+
function parseArgValue(raw, context) {
|
|
332
|
+
if (raw.startsWith("${") && raw.endsWith("}")) return evaluateExpression(raw.slice(2, -1).trim(), context);
|
|
333
|
+
const quoted = /^(['"])([\s\S]*)\1$/.exec(raw);
|
|
334
|
+
if (quoted) return quoted[2].replace(/\\(['"\\])/g, "$1");
|
|
335
|
+
if (raw === "true") return true;
|
|
336
|
+
if (raw === "false") return false;
|
|
337
|
+
if (raw === "null") return null;
|
|
338
|
+
if (/^-?\d+(\.\d+)?$/.test(raw)) return Number(raw);
|
|
339
|
+
return raw;
|
|
340
|
+
}
|
|
341
|
+
export { callFunction, evaluate, formatCurrency, formatDate, formatNumber, formatTemplate, humanize, isBinding, isFunctionCall, testPattern, toText };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Catalog ids and paths, in their own module so data files can share them. */
|
|
2
|
+
export declare const catalogId = "https://derekwatson.site/derelicious-ds/a2ui/v0.9/catalog.json";
|
|
3
|
+
export declare const basicCatalogId = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json";
|
|
4
|
+
/** Where the generated catalog document is served on the site. */
|
|
5
|
+
export declare const catalogPath = "/derelicious-ds/a2ui/v0.9/catalog.json";
|
package/dist/a2ui/ids.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// src/a2ui/ids.ts
|
|
2
|
+
/** Catalog ids and paths, in their own module so data files can share them. */
|
|
3
|
+
var catalogId = "https://derekwatson.site/derelicious-ds/a2ui/v0.9/catalog.json";
|
|
4
|
+
var basicCatalogId = "https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json";
|
|
5
|
+
/** Where the generated catalog document is served on the site. */
|
|
6
|
+
var catalogPath = "/derelicious-ds/a2ui/v0.9/catalog.json";
|
|
7
|
+
export { basicCatalogId, catalogId, catalogPath };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @derelicious/ds/a2ui: the Derelicious A2UI v0.9 catalog, message processor,
|
|
3
|
+
* stream parsers, and TSX export. Plain TypeScript with no styles or JSX, so
|
|
4
|
+
* Node can import it. The React renderer is `@derelicious/ds/a2ui/react`.
|
|
5
|
+
*/
|
|
6
|
+
export { A2UI_VERSION, basicCatalogId, basicIconMap, buildCatalogJson, type CatalogComponent, type CatalogDocument, type CatalogFunction, type CatalogSummary, catalogComponents, catalogFunctions, catalogId, catalogPath, catalogSummary, getCatalogComponent, protocolRules, } from './catalog.js';
|
|
7
|
+
export { type A2uiClientAction, type A2uiClientError, type A2uiClientMessage, actionMessage, MAX_CLIENT_ERROR_LENGTH, MAX_CLIENT_ERRORS, surfaceErrors, validationError, } from './clientMessages.js';
|
|
8
|
+
export { type CatalogExample, catalogExampleMessages, catalogExamples, } from './examples.js';
|
|
9
|
+
export { callFunction, evaluate, formatDate, formatTemplate, humanize, isBinding, isFunctionCall, testPattern, toText, } from './functions.js';
|
|
10
|
+
export { createJsonlParser, createSseParser, type JsonlItem, readSse, type SseEvent, } from './jsonl.js';
|
|
11
|
+
export { isInternalHref, safeHref, safeImage } from './links.js';
|
|
12
|
+
export { formatPointer, getAt, parsePointer, removeAt, resolvePath, setAt, } from './pointer.js';
|
|
13
|
+
export { A2uiProcessor, createProcessor, type ProcessorOptions, type ProcessResult, type SurfaceSnapshot, } from './processor.js';
|
|
14
|
+
export { surfaceToTsx, type ToTsxOptions } from './toTsx.js';
|
|
15
|
+
export type * from './types.js';
|
|
16
|
+
export { type CatalogValidator, createCatalogValidator, type MessageCheck, type SchemaIssue, safeRegExp, unsafePatternReason, valueHasUnsafeKey, } from './validate.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { basicCatalogId, catalogId, catalogPath } from "./ids.js";
|
|
2
|
+
import { basicIconMap, buildCatalogJson, catalogComponents, catalogFunctions, catalogSummary, getCatalogComponent, protocolRules } from "./catalog.js";
|
|
3
|
+
import { MAX_CLIENT_ERRORS, MAX_CLIENT_ERROR_LENGTH, actionMessage, surfaceErrors, validationError } from "./clientMessages.js";
|
|
4
|
+
import { catalogExampleMessages, catalogExamples } from "./examples.js";
|
|
5
|
+
import { callFunction, evaluate, formatDate, formatTemplate, humanize, isBinding, isFunctionCall, testPattern, toText } from "./functions.js";
|
|
6
|
+
import { createJsonlParser, createSseParser, readSse } from "./jsonl.js";
|
|
7
|
+
import { isInternalHref, safeHref, safeImage } from "./links.js";
|
|
8
|
+
import { formatPointer, getAt, parsePointer, removeAt, resolvePath, setAt } from "./pointer.js";
|
|
9
|
+
import { A2uiProcessor, createProcessor } from "./processor.js";
|
|
10
|
+
import { surfaceToTsx } from "./toTsx.js";
|
|
11
|
+
import { A2UI_VERSION, createCatalogValidator, safeRegExp, unsafePatternReason, valueHasUnsafeKey } from "./validate.js";
|
|
12
|
+
export { A2UI_VERSION, A2uiProcessor, MAX_CLIENT_ERRORS, MAX_CLIENT_ERROR_LENGTH, actionMessage, basicCatalogId, basicIconMap, buildCatalogJson, callFunction, catalogComponents, catalogExampleMessages, catalogExamples, catalogFunctions, catalogId, catalogPath, catalogSummary, createCatalogValidator, createJsonlParser, createProcessor, createSseParser, evaluate, formatDate, formatPointer, formatTemplate, getAt, getCatalogComponent, humanize, isBinding, isFunctionCall, isInternalHref, parsePointer, protocolRules, readSse, removeAt, resolvePath, safeHref, safeImage, safeRegExp, setAt, surfaceErrors, surfaceToTsx, testPattern, toText, unsafePatternReason, validationError, valueHasUnsafeKey };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Incremental parsers for streamed A2UI: JSON Lines (one message per line)
|
|
3
|
+
* and server-sent events. Both take chunks of any size, split anywhere, and
|
|
4
|
+
* hand back whole items as soon as they are complete.
|
|
5
|
+
*/
|
|
6
|
+
export type JsonlItem = {
|
|
7
|
+
ok: true;
|
|
8
|
+
value: unknown;
|
|
9
|
+
line: string;
|
|
10
|
+
} | {
|
|
11
|
+
ok: false;
|
|
12
|
+
error: string;
|
|
13
|
+
line: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Parse JSON Lines from arbitrary chunks. Blank lines are skipped; a line
|
|
17
|
+
* that is not JSON comes back as `{ ok: false }` instead of throwing.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createJsonlParser(): {
|
|
20
|
+
/** Add a chunk. Returns the lines it completed. */
|
|
21
|
+
push(chunk: string): JsonlItem[];
|
|
22
|
+
/** The stream ended. Returns the last line if it had no newline. */
|
|
23
|
+
end(): JsonlItem[];
|
|
24
|
+
};
|
|
25
|
+
export type SseEvent = {
|
|
26
|
+
/** The `event:` field, or "message". */
|
|
27
|
+
event: string;
|
|
28
|
+
/** Every `data:` line, joined with newlines. */
|
|
29
|
+
data: string;
|
|
30
|
+
id?: string;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Parse a server-sent event stream from text chunks, following the HTML
|
|
34
|
+
* spec: `event:`, `data:`, `id:`, comments, and CRLF, CR, or LF line ends.
|
|
35
|
+
*/
|
|
36
|
+
export declare function createSseParser(): {
|
|
37
|
+
push(chunk: string): SseEvent[];
|
|
38
|
+
end(): SseEvent[];
|
|
39
|
+
};
|
|
40
|
+
/** Read a fetch body as server-sent events. Stops when the signal aborts. */
|
|
41
|
+
export declare function readSse(body: ReadableStream<Uint8Array>, signal?: AbortSignal): AsyncGenerator<SseEvent>;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// src/a2ui/jsonl.ts
|
|
2
|
+
/**
|
|
3
|
+
* Parse JSON Lines from arbitrary chunks. Blank lines are skipped; a line
|
|
4
|
+
* that is not JSON comes back as `{ ok: false }` instead of throwing.
|
|
5
|
+
*/
|
|
6
|
+
function createJsonlParser() {
|
|
7
|
+
let buffer = "";
|
|
8
|
+
function parseLine(raw) {
|
|
9
|
+
const line = raw.replace(/\r$/, "").trim();
|
|
10
|
+
if (line === "") return null;
|
|
11
|
+
try {
|
|
12
|
+
return {
|
|
13
|
+
ok: true,
|
|
14
|
+
value: JSON.parse(line),
|
|
15
|
+
line
|
|
16
|
+
};
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return {
|
|
19
|
+
ok: false,
|
|
20
|
+
line,
|
|
21
|
+
error: error instanceof Error ? error.message : "Invalid JSON"
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
/** Add a chunk. Returns the lines it completed. */
|
|
27
|
+
push(chunk) {
|
|
28
|
+
buffer += chunk;
|
|
29
|
+
const items = [];
|
|
30
|
+
let newline = buffer.indexOf("\n");
|
|
31
|
+
while (newline !== -1) {
|
|
32
|
+
const item = parseLine(buffer.slice(0, newline));
|
|
33
|
+
if (item) items.push(item);
|
|
34
|
+
buffer = buffer.slice(newline + 1);
|
|
35
|
+
newline = buffer.indexOf("\n");
|
|
36
|
+
}
|
|
37
|
+
return items;
|
|
38
|
+
},
|
|
39
|
+
/** The stream ended. Returns the last line if it had no newline. */
|
|
40
|
+
end() {
|
|
41
|
+
const item = parseLine(buffer);
|
|
42
|
+
buffer = "";
|
|
43
|
+
return item ? [item] : [];
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Parse a server-sent event stream from text chunks, following the HTML
|
|
49
|
+
* spec: `event:`, `data:`, `id:`, comments, and CRLF, CR, or LF line ends.
|
|
50
|
+
*/
|
|
51
|
+
function createSseParser() {
|
|
52
|
+
let buffer = "";
|
|
53
|
+
let event = "";
|
|
54
|
+
let data = [];
|
|
55
|
+
let id;
|
|
56
|
+
function dispatch(out) {
|
|
57
|
+
if (data.length > 0) out.push({
|
|
58
|
+
event: event || "message",
|
|
59
|
+
data: data.join("\n"),
|
|
60
|
+
...id === void 0 ? {} : { id }
|
|
61
|
+
});
|
|
62
|
+
event = "";
|
|
63
|
+
data = [];
|
|
64
|
+
}
|
|
65
|
+
function line(text, out) {
|
|
66
|
+
if (text === "") {
|
|
67
|
+
dispatch(out);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (text.startsWith(":")) return;
|
|
71
|
+
const colon = text.indexOf(":");
|
|
72
|
+
const field = colon === -1 ? text : text.slice(0, colon);
|
|
73
|
+
let value = colon === -1 ? "" : text.slice(colon + 1);
|
|
74
|
+
if (value.startsWith(" ")) value = value.slice(1);
|
|
75
|
+
if (field === "event") event = value;
|
|
76
|
+
else if (field === "data") data.push(value);
|
|
77
|
+
else if (field === "id" && !value.includes("\0")) id = value;
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
push(chunk) {
|
|
81
|
+
buffer += chunk;
|
|
82
|
+
const out = [];
|
|
83
|
+
const match = /\r\n|\r|\n/g;
|
|
84
|
+
let start = 0;
|
|
85
|
+
let found = match.exec(buffer);
|
|
86
|
+
while (found) {
|
|
87
|
+
if (found[0] === "\r" && found.index === buffer.length - 1) break;
|
|
88
|
+
line(buffer.slice(start, found.index), out);
|
|
89
|
+
start = found.index + found[0].length;
|
|
90
|
+
found = match.exec(buffer);
|
|
91
|
+
}
|
|
92
|
+
buffer = buffer.slice(start);
|
|
93
|
+
return out;
|
|
94
|
+
},
|
|
95
|
+
end() {
|
|
96
|
+
const out = [];
|
|
97
|
+
if (buffer !== "") line(buffer.replace(/\r$/, ""), out);
|
|
98
|
+
buffer = "";
|
|
99
|
+
dispatch(out);
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** Read a fetch body as server-sent events. Stops when the signal aborts. */
|
|
105
|
+
async function* readSse(body, signal) {
|
|
106
|
+
const reader = body.getReader();
|
|
107
|
+
const decoder = new TextDecoder();
|
|
108
|
+
const parser = createSseParser();
|
|
109
|
+
const onAbort = () => {
|
|
110
|
+
reader.cancel().catch(() => {});
|
|
111
|
+
};
|
|
112
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
113
|
+
try {
|
|
114
|
+
while (true) {
|
|
115
|
+
if (signal?.aborted) return;
|
|
116
|
+
const { done, value } = await reader.read();
|
|
117
|
+
if (done) break;
|
|
118
|
+
for (const item of parser.push(decoder.decode(value, { stream: true }))) yield item;
|
|
119
|
+
}
|
|
120
|
+
for (const item of parser.push(decoder.decode())) yield item;
|
|
121
|
+
for (const item of parser.end()) yield item;
|
|
122
|
+
} finally {
|
|
123
|
+
signal?.removeEventListener("abort", onAbort);
|
|
124
|
+
reader.releaseLock?.();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export { createJsonlParser, createSseParser, readSse };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL checks for generated UI. Model output decides where links point, so the
|
|
3
|
+
* renderer only accepts site paths, same-page anchors, https, and mailto.
|
|
4
|
+
*/
|
|
5
|
+
/** A link target, or undefined when the value is not safe to follow. */
|
|
6
|
+
export declare function safeHref(value: unknown): string | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* An image source, or "" (the Image placeholder) when it is not allowed.
|
|
9
|
+
* Only site paths load by default: a remote image in model output can track
|
|
10
|
+
* the visitor or leak what they asked through its URL. Pass
|
|
11
|
+
* `{ allowRemote: true }` to also accept https URLs, for trusted content.
|
|
12
|
+
*/
|
|
13
|
+
export declare function safeImage(value: unknown, { allowRemote }?: {
|
|
14
|
+
allowRemote?: boolean;
|
|
15
|
+
}): string;
|
|
16
|
+
/** True for paths inside the site, which should navigate client-side. */
|
|
17
|
+
export declare function isInternalHref(href: string): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/a2ui/links.ts
|
|
2
|
+
/**
|
|
3
|
+
* URL checks for generated UI. Model output decides where links point, so the
|
|
4
|
+
* renderer only accepts site paths, same-page anchors, https, and mailto.
|
|
5
|
+
*/
|
|
6
|
+
/** A link target, or undefined when the value is not safe to follow. */
|
|
7
|
+
function safeHref(value) {
|
|
8
|
+
if (typeof value !== "string") return void 0;
|
|
9
|
+
const href = value.trim();
|
|
10
|
+
if (/^\/(?!\/)/.test(href) || /^#[\w-]*$/.test(href)) return href;
|
|
11
|
+
if (/^(https:\/\/|mailto:)\S+$/i.test(href)) return href;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* An image source, or "" (the Image placeholder) when it is not allowed.
|
|
15
|
+
* Only site paths load by default: a remote image in model output can track
|
|
16
|
+
* the visitor or leak what they asked through its URL. Pass
|
|
17
|
+
* `{ allowRemote: true }` to also accept https URLs, for trusted content.
|
|
18
|
+
*/
|
|
19
|
+
function safeImage(value, { allowRemote = false } = {}) {
|
|
20
|
+
if (typeof value !== "string") return "";
|
|
21
|
+
const src = value.trim();
|
|
22
|
+
if (/^\/(?!\/)\S*$/.test(src)) return src;
|
|
23
|
+
return allowRemote && /^https:\/\/\S+$/i.test(src) ? src : "";
|
|
24
|
+
}
|
|
25
|
+
/** True for paths inside the site, which should navigate client-side. */
|
|
26
|
+
function isInternalHref(href) {
|
|
27
|
+
return /^\/(?!\/)/.test(href) || href.startsWith("#");
|
|
28
|
+
}
|
|
29
|
+
export { isInternalHref, safeHref, safeImage };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON Pointer helpers for the A2UI data model. Updates copy only the objects
|
|
3
|
+
* along the path, so earlier snapshots stay unchanged.
|
|
4
|
+
*
|
|
5
|
+
* A2UI treats "" and "/" as the whole model. Inside a template, a path
|
|
6
|
+
* without a leading slash is relative to the current item's path (its scope).
|
|
7
|
+
*/
|
|
8
|
+
/** "/a/b~1c" → ["a", "b/c"]. "" and "/" → []. */
|
|
9
|
+
export declare function parsePointer(path: string): string[];
|
|
10
|
+
/** ["a", "b/c"] → "/a/b~1c". */
|
|
11
|
+
export declare function formatPointer(tokens: readonly string[]): string;
|
|
12
|
+
/**
|
|
13
|
+
* An absolute pointer for `path` read from `scope`. Absolute paths ignore the
|
|
14
|
+
* scope. "./x" and "x" both mean the `x` field of the scope.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolvePath(path: string, scope?: string): string;
|
|
17
|
+
/** The value at `path`, or undefined. */
|
|
18
|
+
export declare function getAt(root: unknown, path: string): unknown;
|
|
19
|
+
/** A copy of `root` with `value` at `path`. Creates missing parents. */
|
|
20
|
+
export declare function setAt(root: unknown, path: string, value: unknown): unknown;
|
|
21
|
+
/** A copy of `root` without the value at `path`. */
|
|
22
|
+
export declare function removeAt(root: unknown, path: string): unknown;
|