@sdxc/kit 2026.10.20 → 2026.10.21
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 +95 -90
- package/changelog.jsonl +11 -0
- package/config.schema.json +6 -0
- package/dist/commands/make.d.ts +6 -0
- package/dist/commands/make.js +7 -1
- package/dist/commands/scaffold.d.ts +1 -0
- package/dist/commands/scaffold.js +1 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +4 -0
- package/dist/contract.d.ts +4 -0
- package/dist/contract.js +16 -5
- package/dist/dependencies.d.ts +2 -1
- package/dist/dependencies.js +4 -1
- package/dist/destroy.d.ts +4 -4
- package/dist/destroy.js +11 -5
- package/dist/doctor/checks.js +2 -0
- package/dist/doctor/jsdoc.d.ts +44 -0
- package/dist/doctor/jsdoc.js +201 -0
- package/dist/make/generate.d.ts +11 -2
- package/dist/make/generate.js +47 -16
- package/dist/make/index.d.ts +4 -2
- package/dist/make/index.js +4 -1
- package/dist/make/kinds.d.ts +5 -0
- package/dist/make/kinds.js +14 -2
- package/dist/make/stubs.d.ts +7 -2
- package/dist/make/stubs.js +8 -3
- package/dist/make/test.js +1 -0
- package/dist/scaffold/index.d.ts +2 -0
- package/dist/scaffold/index.js +13 -4
- package/dist/scaffold/render.d.ts +11 -1
- package/dist/scaffold/render.js +86 -1
- package/package.json +2 -2
- package/registry/ui/sidebar.json +3 -3
- package/registry/ui/typeset.json +3 -3
- package/stubs/command.spec.stub +15 -0
- package/stubs/controller.api.spec.stub +15 -0
- package/stubs/controller.spec.stub +15 -0
- package/stubs/mcp.spec.stub +16 -0
- package/stubs/scaffold.migration.stub +2 -1
- package/stubs/scaffold.spec.stub +7 -0
- package/templates/app/AGENTS.md +8 -4
- package/templates/app/README.md +6 -3
- package/templates/app/app/commands/typegen.test.ts +20 -1
- package/templates/app/app/commands/typegen.ts +16 -2
- package/templates/app/app/initializers/cli.ts +7 -0
- package/templates/app/app/initializers/mail-transport.test.ts +8 -2
- package/templates/app/app/test/cloudflare-workers.ts +2 -0
- package/templates/app/package.json +1 -0
- package/templates/app/spec/config.jsonc +16 -0
package/registry/ui/typeset.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "typeset",
|
|
3
|
-
"changedIn": "2026.10.
|
|
3
|
+
"changedIn": "2026.10.21",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"Typeset"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "typeset.tsx",
|
|
10
|
-
"content": "/**\n * A typography layer wrapping already-rendered markdown or HTML content and\n * supplying every size, weight, spacing, and color decision through three\n * custom properties: `--ui-typeset-size`, `--ui-typeset-leading`, and\n * `--ui-typeset-flow`. `data-preset` swaps all three for a different rhythm\n * context; `data-not-typeset` opts a subtree out of the whole layer.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { keyframes } from \"@sdxc/u/animation\";\nimport { bg, border, borderEdge, fg, outline } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport { block, container } from \"@sdxc/u/layout\";\nimport { overflow, overflowBlock, overflowInline } from \"@sdxc/u/overflow\";\nimport { at } from \"@sdxc/u/responsive\";\nimport { is, maxIs, pb, pi, pis } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport {\n\tbalance,\n\tleading,\n\tpretty,\n\ttabularNums,\n\ttextAlign,\n\ttextDecoration,\n\ttracking,\n\tweight,\n} from \"@sdxc/u/typography\";\nimport { css } from \"remix/component\";\n\nimport { easings } from \"@sdxc/ui/animations\";\n\n/**\n * Named container {@link Typeset} declares on its own host, so its wide-table\n * handling can grant roomier cell and code-block padding once there's enough\n * space, instead of reading the viewport.\n */\nconst CONTAINER_NAME = \"ui-typeset\";\n\n/** Rhythm context {@link Typeset} falls back to when `preset` is omitted. */\nconst DEFAULT_PRESET: Typeset.Preset = \"docs\";\n\n/** CSS length each edge of a wide table's own fade tapers over. */\nconst TABLE_FADE_SIZE = \"2.5rem\";\n\n/**\n * Custom property carrying the gradient direction a wide table's edge fade\n * paints along, mirrored under `:dir(rtl)` so the same mask string works in\n * both writing directions without a second, mirrored gradient.\n */\nconst TABLE_FADE_DIRECTION_PROPERTY = \"--ui-typeset-table-fade-direction\";\n\n/**\n * `@keyframes` name backing a wide table's scroll-linked edge fade; the\n * `keyframes()` call using it must stay a top-level mixin rather than nested\n * under the table selector, since the serializer only recognizes stops there.\n */\nconst TABLE_FADE_KEYFRAMES_NAME = \"ui-typeset-table-fade\";\n\n/** Proportion of a wide table's own scroll range its edge fade ramps across. */\nconst TABLE_FADE_RAMP_PERCENT = 10;\n\n/** The style shape {@link css} accepts, reused so a keyframes block can be built ahead of the call. */\ntype Styles = Parameters<typeof css>[0];\n\n/**\n * Builds the four-stop mask-image gradient a wide table's edge fade paints:\n * a leading stop, two middle stops marking where the faded band meets the\n * fully opaque middle, and a trailing stop; only the middle stops move.\n */\nfunction tableFadeMask(startStop: string, endStop: string): string {\n\treturn `linear-gradient(to var(${TABLE_FADE_DIRECTION_PROPERTY}, right), transparent 0%, black ${startStop}, black ${endStop}, transparent 100%)`;\n}\n\nconst TABLE_FADE_SETTLED_STOP = `calc(100% - ${TABLE_FADE_SIZE})`;\nconst TABLE_FADE_SETTLED_MASK = tableFadeMask(TABLE_FADE_SIZE, TABLE_FADE_SETTLED_STOP);\n\n/**\n * Stops the wide-table edge fade animates through: fully faded on the leading\n * edge at rest, settled on both edges across the long middle of the scroll\n * range, and fully faded on the trailing edge at the end.\n */\nconst TABLE_FADE_KEYFRAMES: Record<string, Styles> = {\n\t\"0%\": { maskImage: tableFadeMask(\"0%\", TABLE_FADE_SETTLED_STOP) },\n\t[`${TABLE_FADE_RAMP_PERCENT}%, ${100 - TABLE_FADE_RAMP_PERCENT}%`]: {\n\t\tmaskImage: TABLE_FADE_SETTLED_MASK,\n\t},\n\t\"100%\": { maskImage: tableFadeMask(TABLE_FADE_SIZE, \"100%\") },\n};\n\n/**\n * Prop types for {@link Typeset}.\n */\nexport namespace Typeset {\n\t/**\n\t * Rhythm context: `\"docs\"` is the spacious default, `\"chat\"` tightens the\n\t * scale for a conversational bubble's denser turn-taking, and `\"reading\"`\n\t * opens both further for a long-form article.\n\t */\n\texport type Preset = \"docs\" | \"chat\" | \"reading\";\n\n\t/**\n\t * Every native `<div>` attribute plus `mix`. `preset` defaults to\n\t * {@link DEFAULT_PRESET}; setting a `--ui-typeset-*` property directly\n\t * overrides it, and `data-not-typeset` opts a subtree out entirely.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Rhythm context. Defaults to {@link DEFAULT_PRESET}. */\n\t\tpreset?: Preset;\n\t}\n}\n\n/**\n * Renders a `<div>` that sizes and colors already-rendered markdown or HTML\n * content through `--ui-typeset-size`, `--ui-typeset-leading`, and\n * `--ui-typeset-flow`, computing heading sizes via `calc()` off one shared value.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the typeset layer's markup.\n * @example\n * <Typeset preset=\"reading\">{renderedArticleHtml}</Typeset>\n * @example\n * <Typeset preset=\"chat\">\n * \t<p>{t(\"assistant.reply\")}</p>\n * </Typeset>\n * @example\n * <Typeset>\n * \t<p>{t(\"docs.intro\")}</p>\n * \t<div data-not-typeset>\n * \t\t<EmbeddedWidget />\n * \t</div>\n * </Typeset>\n */\nexport function Typeset(handle: Handle<Typeset.Props>) {\n\treturn () => {\n\t\tlet { preset, mix, ...rest } = handle.props;\n\t\tlet resolvedPreset = preset ?? DEFAULT_PRESET;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-preset={resolvedPreset}\n\t\t\t\tdata-slot=\"typeset\"\n\t\t\t\tmix={[\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\n\t\t\t\t\tkeyframes(TABLE_FADE_KEYFRAMES_NAME, TABLE_FADE_KEYFRAMES),\n\t\t\t\t\traw({\n\t\t\t\t\t\tfontSize: \"var(--ui-typeset-size, 1rem)\",\n\t\t\t\t\t\tlineHeight: \"var(--ui-typeset-leading, 1.75)\",\n\n\t\t\t\t\t\t'&[data-preset=\"docs\"]': {\n\t\t\t\t\t\t\t\"--ui-typeset-size\": \"1rem\",\n\t\t\t\t\t\t\t\"--ui-typeset-leading\": \"1.75\",\n\t\t\t\t\t\t\t\"--ui-typeset-flow\": \"1.25em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t'&[data-preset=\"chat\"]': {\n\t\t\t\t\t\t\t\"--ui-typeset-size\": \"0.9375rem\",\n\t\t\t\t\t\t\t\"--ui-typeset-leading\": \"1.5\",\n\t\t\t\t\t\t\t\"--ui-typeset-flow\": \"0.75em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t'&[data-preset=\"reading\"]': {\n\t\t\t\t\t\t\t\"--ui-typeset-size\": \"1.125rem\",\n\t\t\t\t\t\t\t\"--ui-typeset-leading\": \"1.8\",\n\t\t\t\t\t\t\t\"--ui-typeset-flow\": \"1.5em\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& > * + *\": {\n\t\t\t\t\t\t\tmarginBlockStart: \"var(--ui-typeset-flow, 1.25em)\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(blockquote, li) > * + *\": {\n\t\t\t\t\t\t\tmarginBlockStart: \"var(--ui-typeset-flow, 1.25em)\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(h1)\": {\n\t\t\t\t\t\t\tfontSize: \"calc(var(--ui-typeset-size, 1rem) * 2)\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h2)\": {\n\t\t\t\t\t\t\tfontSize: \"calc(var(--ui-typeset-size, 1rem) * 1.5)\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h3)\": {\n\t\t\t\t\t\t\tfontSize: \"calc(var(--ui-typeset-size, 1rem) * 1.25)\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h4)\": {\n\t\t\t\t\t\t\tfontSize: \"calc(var(--ui-typeset-size, 1rem) * 1.125)\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h5)\": {\n\t\t\t\t\t\t\tfontSize: \"var(--ui-typeset-size, 1rem)\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h6)\": {\n\t\t\t\t\t\t\tfontSize: \"calc(var(--ui-typeset-size, 1rem) * 0.875)\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(ul)\": {\n\t\t\t\t\t\t\tlistStyleType: \"disc\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(ol)\": {\n\t\t\t\t\t\t\tlistStyleType: \"decimal\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(ul, ol) :where(ul)\": {\n\t\t\t\t\t\t\tlistStyleType: \"circle\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(blockquote)\": {\n\t\t\t\t\t\t\tfontStyle: \"italic\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(a)\": {\n\t\t\t\t\t\t\ttextUnderlineOffset: \"0.15em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(a):hover\": {\n\t\t\t\t\t\t\ttextDecorationThickness: \"2px\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(em, i)\": {\n\t\t\t\t\t\t\tfontStyle: \"italic\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(code)\": {\n\t\t\t\t\t\t\tfontSize: \"0.875em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(pre)\": {\n\t\t\t\t\t\t\tfontSize: \"0.875em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(pre code)\": {\n\t\t\t\t\t\t\tpadding: \"0\",\n\t\t\t\t\t\t\tfontSize: \"1em\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(table)\": {\n\t\t\t\t\t\t\tborderCollapse: \"collapse\",\n\t\t\t\t\t\t\tfontSize: \"0.875em\",\n\t\t\t\t\t\t\tscrollbarWidth: \"thin\",\n\t\t\t\t\t\t\tscrollbarGutter: \"stable\",\n\n\t\t\t\t\t\t\t[TABLE_FADE_DIRECTION_PROPERTY]: \"right\",\n\t\t\t\t\t\t\tmaskImage: \"none\",\n\t\t\t\t\t\t\t\"-webkit-mask-image\": \"none\",\n\n\t\t\t\t\t\t\t\"&:dir(rtl)\": {\n\t\t\t\t\t\t\t\t[TABLE_FADE_DIRECTION_PROPERTY]: \"left\",\n\t\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\t\"&::-webkit-scrollbar\": {\n\t\t\t\t\t\t\t\twidth: \"0.75rem\",\n\t\t\t\t\t\t\t\theight: \"0.75rem\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"&::-webkit-scrollbar-track\": {\n\t\t\t\t\t\t\t\tbackgroundColor: \"transparent\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"&::-webkit-scrollbar-thumb\": {\n\t\t\t\t\t\t\t\tborderRadius: \"var(--ui-radius-full, 9999px)\",\n\t\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-neutral-border)\",\n\t\t\t\t\t\t\t\tborderWidth: \"3px\",\n\t\t\t\t\t\t\t\tborderStyle: \"solid\",\n\t\t\t\t\t\t\t\tborderColor: \"transparent\",\n\t\t\t\t\t\t\t\tbackgroundClip: \"content-box\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"&::-webkit-scrollbar-thumb:hover\": {\n\t\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-neutral-border-strong)\",\n\t\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\t\"@supports (animation-timeline: scroll())\": {\n\t\t\t\t\t\t\t\tanimationName: TABLE_FADE_KEYFRAMES_NAME,\n\t\t\t\t\t\t\t\tanimationDuration: \"auto\",\n\t\t\t\t\t\t\t\tanimationTimingFunction: easings.linear,\n\t\t\t\t\t\t\t\tanimationFillMode: \"both\",\n\t\t\t\t\t\t\t\tanimationTimeline: \"scroll(self inline)\",\n\t\t\t\t\t\t\t\t\"@media (prefers-reduced-motion: reduce)\": {\n\t\t\t\t\t\t\t\t\tanimationName: \"none\",\n\t\t\t\t\t\t\t\t\tmaskImage: TABLE_FADE_SETTLED_MASK,\n\t\t\t\t\t\t\t\t\t\"-webkit-mask-image\": TABLE_FADE_SETTLED_MASK,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where([data-not-typeset], [data-not-typeset] *)\": {\n\t\t\t\t\t\t\tall: \"revert-layer\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\n\t\t\t\t\tat(\n\t\t\t\t\t\t\"30rem\",\n\t\t\t\t\t\tCONTAINER_NAME,\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\"& :where(th, td)\": {\n\t\t\t\t\t\t\t\tpaddingInline: \"1em\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"& :where(pre)\": {\n\t\t\t\t\t\t\t\tpaddingInline: \"1.25em\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\n\t\t\t\t\twhen(\"& :where(pre)\", leading(1.6)),\n\n\t\t\t\t\twhen(\"& :where(h1, h2, h3, h4, h5, h6)\", [\n\t\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\t\tleading(1.25),\n\t\t\t\t\t\ttracking(\"tight\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tbalance(),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"& :where(h6)\", fg(\"neutral\")),\n\n\t\t\t\t\twhen(\"& :where(p, li, blockquote, dd)\", pretty()),\n\n\t\t\t\t\twhen(\"& :where(ul, ol)\", pis(\"1.5em\")),\n\t\t\t\t\twhen(\"& :where(li)::marker\", fg(\"neutral.muted\")),\n\n\t\t\t\t\twhen(\"& :where(blockquote)\", [\n\t\t\t\t\t\tpis(\"1em\"),\n\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\tborderEdge(\"inline-start\", { color: \"neutral\", width: \"0.25em\" }),\n\t\t\t\t\t]),\n\n\t\t\t\t\twhen(\"& :where(hr)\", borderEdge(\"block-start\", { color: \"neutral\", width: \"1px\" })),\n\n\t\t\t\t\twhen(\"& :where(a)\", [fg(\"brand\"), textDecoration(\"underline\")]),\n\t\t\t\t\twhen(\"& :where(a):focus-visible\", [\n\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\trounded(\"xs\"),\n\t\t\t\t\t]),\n\n\t\t\t\t\twhen(\"& :where(strong, b)\", [weight(\"semibold\"), fg(\"neutral.emphasis\")]),\n\n\t\t\t\t\twhen(\"& :where(code)\", [\n\t\t\t\t\t\trounded(\"sm\"),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tpi(\"0.3em\"),\n\t\t\t\t\t\tpb(\"0.15em\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"& :where(pre)\", [\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tborder({ color: \"neutral.border\", width: 1 }),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tpi(\"1em\"),\n\t\t\t\t\t\tpb(\"0.875em\"),\n\t\t\t\t\t\toverflowInline(\"auto\"),\n\t\t\t\t\t\toverflowBlock(\"hidden\"),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\toverscrollBehaviorInline: \"contain\",\n\t\t\t\t\t\t\toverscrollBehaviorX: \"contain\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t\t/**\n\t\t\t\t\t * A fenced block's `code` is an inline box, so the chip padding above would\n\t\t\t\t\t * apply at the start of the box alone and indent the block's first line\n\t\t\t\t\t * past every line under it. The block's own padding is the `pre`'s.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"& :where(pre code)\", [\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tfg(\"inherit\"),\n\t\t\t\t\t\trounded(\"none\"),\n\t\t\t\t\t\tpi(0),\n\t\t\t\t\t\tpb(0),\n\t\t\t\t\t]),\n\n\t\t\t\t\twhen(\"& :where(table)\", [\n\t\t\t\t\t\tblock(),\n\t\t\t\t\t\tis(\"max(100%, max-content)\"),\n\t\t\t\t\t\tmaxIs(\"full\"),\n\t\t\t\t\t\toverflow(\"auto\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"& :where(th, td):not([align])\", textAlign(\"start\")),\n\t\t\t\t\twhen(\"& :where(th)\", [weight(\"semibold\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\twhen(\"& :where(th, td)\", [\n\t\t\t\t\t\ttabularNums(),\n\t\t\t\t\t\tpi(\"0.75em\"),\n\t\t\t\t\t\tpb(\"0.5em\"),\n\t\t\t\t\t\tborderEdge(\"block-end\", { color: \"neutral\", width: \"1px\" }),\n\t\t\t\t\t]),\n\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
10
|
+
"content": "/**\n * A typography layer wrapping already-rendered markdown or HTML content and\n * supplying every size, weight, spacing, and color decision through three\n * custom properties: `--ui-typeset-size`, `--ui-typeset-leading`, and\n * `--ui-typeset-flow`. `data-preset` swaps all three for a different rhythm\n * context; `data-not-typeset` opts a subtree out of the whole layer.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { keyframes } from \"@sdxc/u/animation\";\nimport { bg, border, borderEdge, fg, outline } from \"@sdxc/u/color\";\nimport { rounded } from \"@sdxc/u/effects\";\nimport { raw } from \"@sdxc/u/general\";\nimport { block, container } from \"@sdxc/u/layout\";\nimport { overflow, overflowBlock, overflowInline } from \"@sdxc/u/overflow\";\nimport { at } from \"@sdxc/u/responsive\";\nimport { is, maxIs, pb, pi, pis } from \"@sdxc/u/size\";\nimport { when } from \"@sdxc/u/state\";\nimport {\n\tbalance,\n\tleading,\n\tpretty,\n\ttabularNums,\n\ttextAlign,\n\ttextDecoration,\n\ttracking,\n\tweight,\n} from \"@sdxc/u/typography\";\nimport { css } from \"remix/component\";\n\nimport { easings } from \"@sdxc/ui/animations\";\n\n/**\n * Named container {@link Typeset} declares on its own host, so its wide-table\n * handling can grant roomier cell and code-block padding once there's enough\n * space, instead of reading the viewport.\n */\nconst CONTAINER_NAME = \"ui-typeset\";\n\n/** Rhythm context {@link Typeset} falls back to when `preset` is omitted. */\nconst DEFAULT_PRESET: Typeset.Preset = \"docs\";\n\n/**\n * Body size each preset writes to `--ui-typeset-size`. On a 16px root, `docs`\n * is 18px and `reading` is 20px, so long-form copy is large enough to read;\n * `chat` is 15px for a turn taken in a denser column.\n */\nconst PRESET_BODY_SIZE: Record<Typeset.Preset, string> = {\n\tdocs: \"1.125rem\",\n\tchat: \"0.9375rem\",\n\treading: \"1.25rem\",\n};\n\n/**\n * Size body copy and headings compute from. Clearing `--ui-typeset-size`\n * still leaves the docs body, which is the preset a host uses by default.\n */\nconst TYPESET_SIZE = `var(--ui-typeset-size, ${PRESET_BODY_SIZE.docs})`;\n\n/** CSS length each edge of a wide table's own fade tapers over. */\nconst TABLE_FADE_SIZE = \"2.5rem\";\n\n/**\n * Custom property carrying the gradient direction a wide table's edge fade\n * paints along, mirrored under `:dir(rtl)` so the same mask string works in\n * both writing directions without a second, mirrored gradient.\n */\nconst TABLE_FADE_DIRECTION_PROPERTY = \"--ui-typeset-table-fade-direction\";\n\n/**\n * `@keyframes` name backing a wide table's scroll-linked edge fade; the\n * `keyframes()` call using it must stay a top-level mixin rather than nested\n * under the table selector, since the serializer only recognizes stops there.\n */\nconst TABLE_FADE_KEYFRAMES_NAME = \"ui-typeset-table-fade\";\n\n/** Proportion of a wide table's own scroll range its edge fade ramps across. */\nconst TABLE_FADE_RAMP_PERCENT = 10;\n\n/** The style shape {@link css} accepts, reused so a keyframes block can be built ahead of the call. */\ntype Styles = Parameters<typeof css>[0];\n\n/**\n * Builds the four-stop mask-image gradient a wide table's edge fade paints:\n * a leading stop, two middle stops marking where the faded band meets the\n * fully opaque middle, and a trailing stop; only the middle stops move.\n */\nfunction tableFadeMask(startStop: string, endStop: string): string {\n\treturn `linear-gradient(to var(${TABLE_FADE_DIRECTION_PROPERTY}, right), transparent 0%, black ${startStop}, black ${endStop}, transparent 100%)`;\n}\n\nconst TABLE_FADE_SETTLED_STOP = `calc(100% - ${TABLE_FADE_SIZE})`;\nconst TABLE_FADE_SETTLED_MASK = tableFadeMask(TABLE_FADE_SIZE, TABLE_FADE_SETTLED_STOP);\n\n/**\n * Stops the wide-table edge fade animates through: fully faded on the leading\n * edge at rest, settled on both edges across the long middle of the scroll\n * range, and fully faded on the trailing edge at the end.\n */\nconst TABLE_FADE_KEYFRAMES: Record<string, Styles> = {\n\t\"0%\": { maskImage: tableFadeMask(\"0%\", TABLE_FADE_SETTLED_STOP) },\n\t[`${TABLE_FADE_RAMP_PERCENT}%, ${100 - TABLE_FADE_RAMP_PERCENT}%`]: {\n\t\tmaskImage: TABLE_FADE_SETTLED_MASK,\n\t},\n\t\"100%\": { maskImage: tableFadeMask(TABLE_FADE_SIZE, \"100%\") },\n};\n\n/**\n * Prop types for {@link Typeset}.\n */\nexport namespace Typeset {\n\t/**\n\t * Rhythm context. `\"docs\"` sets the body at 18px, the size for a page meant\n\t * to be read. `\"reading\"` sets it at 20px for a long-form article. `\"chat\"`\n\t * sets it at 15px for a turn in a denser column.\n\t */\n\texport type Preset = \"docs\" | \"chat\" | \"reading\";\n\n\t/**\n\t * Every native `<div>` attribute plus `mix`. `preset` defaults to\n\t * {@link DEFAULT_PRESET}; setting a `--ui-typeset-*` property directly\n\t * overrides it, and `data-not-typeset` opts a subtree out entirely.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Rhythm context. Defaults to {@link DEFAULT_PRESET}. */\n\t\tpreset?: Preset;\n\t}\n}\n\n/**\n * Renders a `<div>` that sizes and colors already-rendered markdown or HTML\n * content through `--ui-typeset-size`, `--ui-typeset-leading`, and\n * `--ui-typeset-flow`, computing heading sizes via `calc()` off one shared value.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props.\n * @returns The render function producing the typeset layer's markup.\n * @example\n * <Typeset preset=\"reading\">{renderedArticleHtml}</Typeset>\n * @example\n * <Typeset preset=\"chat\">\n * \t<p>{t(\"assistant.reply\")}</p>\n * </Typeset>\n * @example\n * <Typeset>\n * \t<p>{t(\"docs.intro\")}</p>\n * \t<div data-not-typeset>\n * \t\t<EmbeddedWidget />\n * \t</div>\n * </Typeset>\n */\nexport function Typeset(handle: Handle<Typeset.Props>) {\n\treturn () => {\n\t\tlet { preset, mix, ...rest } = handle.props;\n\t\tlet resolvedPreset = preset ?? DEFAULT_PRESET;\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\t{...rest}\n\t\t\t\tdata-preset={resolvedPreset}\n\t\t\t\tdata-slot=\"typeset\"\n\t\t\t\tmix={[\n\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\tcontainer(CONTAINER_NAME),\n\t\t\t\t\tkeyframes(TABLE_FADE_KEYFRAMES_NAME, TABLE_FADE_KEYFRAMES),\n\t\t\t\t\traw({\n\t\t\t\t\t\tfontSize: TYPESET_SIZE,\n\t\t\t\t\t\tlineHeight: \"var(--ui-typeset-leading, 1.75)\",\n\n\t\t\t\t\t\t'&[data-preset=\"docs\"]': {\n\t\t\t\t\t\t\t\"--ui-typeset-size\": PRESET_BODY_SIZE.docs,\n\t\t\t\t\t\t\t\"--ui-typeset-leading\": \"1.75\",\n\t\t\t\t\t\t\t\"--ui-typeset-flow\": \"1.25em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t'&[data-preset=\"chat\"]': {\n\t\t\t\t\t\t\t\"--ui-typeset-size\": PRESET_BODY_SIZE.chat,\n\t\t\t\t\t\t\t\"--ui-typeset-leading\": \"1.5\",\n\t\t\t\t\t\t\t\"--ui-typeset-flow\": \"0.75em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t'&[data-preset=\"reading\"]': {\n\t\t\t\t\t\t\t\"--ui-typeset-size\": PRESET_BODY_SIZE.reading,\n\t\t\t\t\t\t\t\"--ui-typeset-leading\": \"1.8\",\n\t\t\t\t\t\t\t\"--ui-typeset-flow\": \"1.5em\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& > * + *\": {\n\t\t\t\t\t\t\tmarginBlockStart: \"var(--ui-typeset-flow, 1.25em)\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(blockquote, li) > * + *\": {\n\t\t\t\t\t\t\tmarginBlockStart: \"var(--ui-typeset-flow, 1.25em)\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(h1)\": {\n\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 2)`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h2)\": {\n\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 1.5)`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h3)\": {\n\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 1.25)`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h4)\": {\n\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 1.125)`,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h5)\": {\n\t\t\t\t\t\t\tfontSize: TYPESET_SIZE,\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(h6)\": {\n\t\t\t\t\t\t\tfontSize: `calc(${TYPESET_SIZE} * 0.875)`,\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(ul)\": {\n\t\t\t\t\t\t\tlistStyleType: \"disc\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(ol)\": {\n\t\t\t\t\t\t\tlistStyleType: \"decimal\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(ul, ol) :where(ul)\": {\n\t\t\t\t\t\t\tlistStyleType: \"circle\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(blockquote)\": {\n\t\t\t\t\t\t\tfontStyle: \"italic\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(a)\": {\n\t\t\t\t\t\t\ttextUnderlineOffset: \"0.15em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(a):hover\": {\n\t\t\t\t\t\t\ttextDecorationThickness: \"2px\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(em, i)\": {\n\t\t\t\t\t\t\tfontStyle: \"italic\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(code)\": {\n\t\t\t\t\t\t\tfontSize: \"0.875em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(pre)\": {\n\t\t\t\t\t\t\tfontSize: \"0.875em\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where(pre code)\": {\n\t\t\t\t\t\t\tpadding: \"0\",\n\t\t\t\t\t\t\tfontSize: \"1em\",\n\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\"& :where(table)\": {\n\t\t\t\t\t\t\tborderCollapse: \"collapse\",\n\t\t\t\t\t\t\tfontSize: \"0.875em\",\n\t\t\t\t\t\t\tscrollbarWidth: \"thin\",\n\t\t\t\t\t\t\tscrollbarGutter: \"stable\",\n\n\t\t\t\t\t\t\t[TABLE_FADE_DIRECTION_PROPERTY]: \"right\",\n\t\t\t\t\t\t\tmaskImage: \"none\",\n\t\t\t\t\t\t\t\"-webkit-mask-image\": \"none\",\n\n\t\t\t\t\t\t\t\"&:dir(rtl)\": {\n\t\t\t\t\t\t\t\t[TABLE_FADE_DIRECTION_PROPERTY]: \"left\",\n\t\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\t\"&::-webkit-scrollbar\": {\n\t\t\t\t\t\t\t\twidth: \"0.75rem\",\n\t\t\t\t\t\t\t\theight: \"0.75rem\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"&::-webkit-scrollbar-track\": {\n\t\t\t\t\t\t\t\tbackgroundColor: \"transparent\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"&::-webkit-scrollbar-thumb\": {\n\t\t\t\t\t\t\t\tborderRadius: \"var(--ui-radius-full, 9999px)\",\n\t\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-neutral-border)\",\n\t\t\t\t\t\t\t\tborderWidth: \"3px\",\n\t\t\t\t\t\t\t\tborderStyle: \"solid\",\n\t\t\t\t\t\t\t\tborderColor: \"transparent\",\n\t\t\t\t\t\t\t\tbackgroundClip: \"content-box\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"&::-webkit-scrollbar-thumb:hover\": {\n\t\t\t\t\t\t\t\tbackgroundColor: \"var(--ui-neutral-border-strong)\",\n\t\t\t\t\t\t\t},\n\n\t\t\t\t\t\t\t\"@supports (animation-timeline: scroll())\": {\n\t\t\t\t\t\t\t\tanimationName: TABLE_FADE_KEYFRAMES_NAME,\n\t\t\t\t\t\t\t\tanimationDuration: \"auto\",\n\t\t\t\t\t\t\t\tanimationTimingFunction: easings.linear,\n\t\t\t\t\t\t\t\tanimationFillMode: \"both\",\n\t\t\t\t\t\t\t\tanimationTimeline: \"scroll(self inline)\",\n\t\t\t\t\t\t\t\t\"@media (prefers-reduced-motion: reduce)\": {\n\t\t\t\t\t\t\t\t\tanimationName: \"none\",\n\t\t\t\t\t\t\t\t\tmaskImage: TABLE_FADE_SETTLED_MASK,\n\t\t\t\t\t\t\t\t\t\"-webkit-mask-image\": TABLE_FADE_SETTLED_MASK,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t\t\"& :where([data-not-typeset], [data-not-typeset] *)\": {\n\t\t\t\t\t\t\tall: \"revert-layer\",\n\t\t\t\t\t\t},\n\t\t\t\t\t}),\n\n\t\t\t\t\tat(\n\t\t\t\t\t\t\"30rem\",\n\t\t\t\t\t\tCONTAINER_NAME,\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\"& :where(th, td)\": {\n\t\t\t\t\t\t\t\tpaddingInline: \"1em\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"& :where(pre)\": {\n\t\t\t\t\t\t\t\tpaddingInline: \"1.25em\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\n\t\t\t\t\twhen(\"& :where(pre)\", leading(1.6)),\n\n\t\t\t\t\twhen(\"& :where(h1, h2, h3, h4, h5, h6)\", [\n\t\t\t\t\t\tweight(\"semibold\"),\n\t\t\t\t\t\tleading(1.25),\n\t\t\t\t\t\ttracking(\"tight\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tbalance(),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"& :where(h6)\", fg(\"neutral\")),\n\n\t\t\t\t\twhen(\"& :where(p, li, blockquote, dd)\", pretty()),\n\n\t\t\t\t\twhen(\"& :where(ul, ol)\", pis(\"1.5em\")),\n\t\t\t\t\twhen(\"& :where(li)::marker\", fg(\"neutral.muted\")),\n\n\t\t\t\t\twhen(\"& :where(blockquote)\", [\n\t\t\t\t\t\tpis(\"1em\"),\n\t\t\t\t\t\tfg(\"neutral\"),\n\t\t\t\t\t\tborderEdge(\"inline-start\", { color: \"neutral\", width: \"0.25em\" }),\n\t\t\t\t\t]),\n\n\t\t\t\t\twhen(\"& :where(hr)\", borderEdge(\"block-start\", { color: \"neutral\", width: \"1px\" })),\n\n\t\t\t\t\twhen(\"& :where(a)\", [fg(\"brand\"), textDecoration(\"underline\")]),\n\t\t\t\t\twhen(\"& :where(a):focus-visible\", [\n\t\t\t\t\t\toutline({ color: \"brand.ring\", offset: 2 }),\n\t\t\t\t\t\trounded(\"xs\"),\n\t\t\t\t\t]),\n\n\t\t\t\t\twhen(\"& :where(strong, b)\", [weight(\"semibold\"), fg(\"neutral.emphasis\")]),\n\n\t\t\t\t\twhen(\"& :where(code)\", [\n\t\t\t\t\t\trounded(\"sm\"),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tpi(\"0.3em\"),\n\t\t\t\t\t\tpb(\"0.15em\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"& :where(pre)\", [\n\t\t\t\t\t\trounded(\"md\"),\n\t\t\t\t\t\tborder({ color: \"neutral.border\", width: 1 }),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t\tpi(\"1em\"),\n\t\t\t\t\t\tpb(\"0.875em\"),\n\t\t\t\t\t\toverflowInline(\"auto\"),\n\t\t\t\t\t\toverflowBlock(\"hidden\"),\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\toverscrollBehaviorInline: \"contain\",\n\t\t\t\t\t\t\toverscrollBehaviorX: \"contain\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t]),\n\t\t\t\t\t/**\n\t\t\t\t\t * A fenced block's `code` is an inline box, so the chip padding above would\n\t\t\t\t\t * apply at the start of the box alone and indent the block's first line\n\t\t\t\t\t * past every line under it. The block's own padding is the `pre`'s.\n\t\t\t\t\t */\n\t\t\t\t\twhen(\"& :where(pre code)\", [\n\t\t\t\t\t\tbg(\"transparent\"),\n\t\t\t\t\t\tfg(\"inherit\"),\n\t\t\t\t\t\trounded(\"none\"),\n\t\t\t\t\t\tpi(0),\n\t\t\t\t\t\tpb(0),\n\t\t\t\t\t]),\n\n\t\t\t\t\twhen(\"& :where(table)\", [\n\t\t\t\t\t\tblock(),\n\t\t\t\t\t\tis(\"max(100%, max-content)\"),\n\t\t\t\t\t\tmaxIs(\"full\"),\n\t\t\t\t\t\toverflow(\"auto\"),\n\t\t\t\t\t]),\n\t\t\t\t\twhen(\"& :where(th, td):not([align])\", textAlign(\"start\")),\n\t\t\t\t\twhen(\"& :where(th)\", [weight(\"semibold\"), fg(\"neutral.emphasis\")]),\n\t\t\t\t\twhen(\"& :where(th, td)\", [\n\t\t\t\t\t\ttabularNums(),\n\t\t\t\t\t\tpi(\"0.75em\"),\n\t\t\t\t\t\tpb(\"0.5em\"),\n\t\t\t\t\t\tborderEdge(\"block-end\", { color: \"neutral\", width: \"1px\" }),\n\t\t\t\t\t]),\n\n\t\t\t\t\tmix,\n\t\t\t\t]}\n\t\t\t/>\n\t\t);\n\t};\n}\n"
|
|
11
11
|
},
|
|
12
12
|
"test": {
|
|
13
13
|
"path": "typeset.test.tsx",
|
|
14
|
-
"content": "/**\n * Regression tests for the wide-table edge fade's `@keyframes` rule. Its stops\n * are percentages, and `remix/component`'s serializer only reads keyframe stops as\n * stop selectors while the `@keyframes` rule sits outside any selector block —\n * nested inside the table's own selector, every stop serialized as a dropped\n * `0%: [object Object]` declaration and the animation did nothing.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { Typeset } from \"@sdxc/ui/typeset\";\n\n/** The stylesheet {@link Typeset} emits, with every `<style>` tag joined. */\nasync function typesetCss(): Promise<string> {\n\tlet html = await renderToString(<Typeset />);\n\treturn [...html.matchAll(/<style[^>]*>([\\s\\S]*?)<\\/style>/g)].map((match) => match[1]).join(\"\\n\");\n}\n\ndescribe(Typeset.name, () => {\n\ttest(\"emits the table fade keyframes as real stop blocks\", async () => {\n\t\tlet css = await typesetCss();\n\n\t\texpect(css).toContain(\"@keyframes ui-typeset-table-fade\");\n\t\texpect(css).toMatch(/\\b0%\\s*\\{/);\n\t\texpect(css).toMatch(/\\b100%\\s*\\{/);\n\t\texpect(css).toMatch(/\\b10%,\\s*90%\\s*\\{/);\n\t\t/** The stops are only worth emitting if they actually carry the mask. */\n\t\texpect(css).toContain(\"mask-image\");\n\t});\n\n\ttest(\"never serializes a nested style block as a declaration value\", async () => {\n\t\texpect(await typesetCss()).not.toContain(\"[object Object]\");\n\t});\n\n\ttest(\"drives the animation it defines\", async () => {\n\t\tlet css = await typesetCss();\n\n\t\texpect(css).toContain(\"animation-name: ui-typeset-table-fade\");\n\t\texpect(css).toContain(\"animation-timeline: scroll(self inline)\");\n\t});\n\n\ttest(\"lets a vertical wheel over a code block chain to the page\", async () => {\n\t\tlet css = await typesetCss();\n\n\t\texpect(css).toContain(\"overflow-inline: auto\");\n\t\texpect(css).toContain(\"overflow-block: hidden\");\n\t\texpect(css).toContain(\"overscroll-behavior-inline: contain\");\n\t\texpect(css).toContain(\"overscroll-behavior-x: contain\");\n\t\texpect(css).not.toMatch(/overscroll-behavior:\\s*contain/);\n\t});\n});\n"
|
|
14
|
+
"content": "/**\n * Regression tests for the wide-table edge fade's `@keyframes` rule. Its stops\n * are percentages, and `remix/component`'s serializer only reads keyframe stops as\n * stop selectors while the `@keyframes` rule sits outside any selector block —\n * nested inside the table's own selector, every stop serialized as a dropped\n * `0%: [object Object]` declaration and the animation did nothing.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { renderToString } from \"remix/component/server\";\nimport { describe, expect, test } from \"vitest\";\n\nimport { Typeset } from \"@sdxc/ui/typeset\";\n\n/** The stylesheet {@link Typeset} emits, with every `<style>` tag joined. */\nasync function typesetCss(): Promise<string> {\n\tlet html = await renderToString(<Typeset />);\n\treturn [...html.matchAll(/<style[^>]*>([\\s\\S]*?)<\\/style>/g)].map((match) => match[1]).join(\"\\n\");\n}\n\ndescribe(Typeset.name, () => {\n\ttest(\"emits the table fade keyframes as real stop blocks\", async () => {\n\t\tlet css = await typesetCss();\n\n\t\texpect(css).toContain(\"@keyframes ui-typeset-table-fade\");\n\t\texpect(css).toMatch(/\\b0%\\s*\\{/);\n\t\texpect(css).toMatch(/\\b100%\\s*\\{/);\n\t\texpect(css).toMatch(/\\b10%,\\s*90%\\s*\\{/);\n\t\t/** The stops are only worth emitting if they actually carry the mask. */\n\t\texpect(css).toContain(\"mask-image\");\n\t});\n\n\ttest(\"never serializes a nested style block as a declaration value\", async () => {\n\t\texpect(await typesetCss()).not.toContain(\"[object Object]\");\n\t});\n\n\ttest(\"drives the animation it defines\", async () => {\n\t\tlet css = await typesetCss();\n\n\t\texpect(css).toContain(\"animation-name: ui-typeset-table-fade\");\n\t\texpect(css).toContain(\"animation-timeline: scroll(self inline)\");\n\t});\n\n\ttest(\"sets long-form body copy at 18px for docs and 20px for reading\", async () => {\n\t\tlet css = await typesetCss();\n\n\t\texpect(css).toContain(\"--ui-typeset-size: 1.125rem\");\n\t\texpect(css).toContain(\"--ui-typeset-size: 1.25rem\");\n\t\texpect(css).toContain(\"--ui-typeset-size: 0.9375rem\");\n\t\texpect(css).not.toContain(\"--ui-typeset-size: 1rem\");\n\t\texpect(css).toContain(\"font-size: var(--ui-typeset-size, 1.125rem)\");\n\t\texpect(css).toContain(\"font-size: calc(var(--ui-typeset-size, 1.125rem) * 2)\");\n\t});\n\n\ttest(\"lets a vertical wheel over a code block chain to the page\", async () => {\n\t\tlet css = await typesetCss();\n\n\t\texpect(css).toContain(\"overflow-inline: auto\");\n\t\texpect(css).toContain(\"overflow-block: hidden\");\n\t\texpect(css).toContain(\"overscroll-behavior-inline: contain\");\n\t\texpect(css).toContain(\"overscroll-behavior-x: contain\");\n\t\texpect(css).not.toMatch(/overscroll-behavior:\\s*contain/);\n\t});\n});\n"
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# The `{{command}}` command, run through the app's command line as a black box.
|
|
2
|
+
#
|
|
3
|
+
# @see https://sdxc.dev/docs/operations-and-testing/testing
|
|
4
|
+
# @see https://sdxc.dev/docs/operations-and-testing/your-apps-command-line
|
|
5
|
+
|
|
6
|
+
use cli
|
|
7
|
+
|
|
8
|
+
test "{{command}} runs" {
|
|
9
|
+
when {
|
|
10
|
+
let result = cli.run "bun" "run" "cli" {{args}} in "."
|
|
11
|
+
}
|
|
12
|
+
then {
|
|
13
|
+
expect result.exit_code 0
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# The {{title}} endpoint, called over HTTP the way a client calls it.
|
|
2
|
+
#
|
|
3
|
+
# @see https://sdxc.dev/docs/operations-and-testing/testing
|
|
4
|
+
# @see https://sdxc.dev/docs/http-apis/json-apis
|
|
5
|
+
|
|
6
|
+
use http
|
|
7
|
+
|
|
8
|
+
test "{{title}} answers" {
|
|
9
|
+
when {
|
|
10
|
+
let result = http.get "{{url}}" on "web"
|
|
11
|
+
}
|
|
12
|
+
then {
|
|
13
|
+
expect result.status 200
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# The {{title}} page, opened through a real browser the way a visitor reaches it.
|
|
2
|
+
#
|
|
3
|
+
# @see https://sdxc.dev/docs/operations-and-testing/testing
|
|
4
|
+
# @see https://sdxc.dev/docs/building-remix-apps/wire-the-router
|
|
5
|
+
|
|
6
|
+
use browser
|
|
7
|
+
|
|
8
|
+
test "{{title}} page loads" {
|
|
9
|
+
when {
|
|
10
|
+
browser.open "{{url}}"
|
|
11
|
+
}
|
|
12
|
+
then {
|
|
13
|
+
expect browser.heading "{{title}}"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# The {{title}} MCP tool, called over `/mcp` the way a client calls it.
|
|
2
|
+
#
|
|
3
|
+
# @see https://sdxc.dev/docs/operations-and-testing/testing
|
|
4
|
+
# @see https://sdxc.dev/docs/operations-and-testing/mcp-server
|
|
5
|
+
|
|
6
|
+
use mcp
|
|
7
|
+
|
|
8
|
+
test "{{tool}} answers over /mcp" {
|
|
9
|
+
when {
|
|
10
|
+
let result = mcp.call "/mcp" "{{tool}}" {} on "web"
|
|
11
|
+
}
|
|
12
|
+
then {
|
|
13
|
+
expect result.ok true
|
|
14
|
+
expect result.is_error false
|
|
15
|
+
}
|
|
16
|
+
}
|
package/templates/app/AGENTS.md
CHANGED
|
@@ -18,7 +18,7 @@ https://sdxc.dev/docs/getting-started/the-sdxc-command.
|
|
|
18
18
|
sdxc make <kind> <name> # write a file where the layout puts it, with its test
|
|
19
19
|
sdxc make <kind> <name> --dry-run # print what it would write, and write nothing
|
|
20
20
|
sdxc make model <name> [field...] # a model, the migration creating its table, and its factory
|
|
21
|
-
sdxc scaffold <name> [field:type] # model, migration, pages
|
|
21
|
+
sdxc scaffold <name> [field:type] # model, migration, pages, tests and a feature .spec
|
|
22
22
|
sdxc ui add <component> # copy an @sdxc/ui component into the app to edit it
|
|
23
23
|
sdxc routes --json # every route, its controller and the middleware it runs
|
|
24
24
|
sdxc doctor --json # release drift, installs, secrets, migrations and wiring
|
|
@@ -28,6 +28,7 @@ sdxc run db fresh --seed # drop every local table, apply every migrati
|
|
|
28
28
|
sdxc run console # Bun's REPL with the local db and models on globalThis
|
|
29
29
|
sdxc upgrade # move every @sdxc package to the latest release
|
|
30
30
|
sdxc deploy --dry-run # build and print the deploy plan, changing nothing
|
|
31
|
+
bunx spec run spec --allow-config # black-box .spec suite under spec/
|
|
31
32
|
bun check # format, lint and type check
|
|
32
33
|
bun run test # every test, under Vitest
|
|
33
34
|
```
|
|
@@ -36,10 +37,13 @@ bun run test # every test, under Vitest
|
|
|
36
37
|
`controller`, `middleware`, `validator`, `job`, `model`, `migration`, `factory`, `service`,
|
|
37
38
|
`policy`, `initializer`, `email`, `mcp` and `command`. `make` writes the test beside the file
|
|
38
39
|
and declares and maps controllers, jobs, MCP tools, commands and emails, so the file works at
|
|
39
|
-
once.
|
|
40
|
-
|
|
40
|
+
once. Controllers, commands and MCP tools also get a pairing `.spec` under `spec/` (pages use
|
|
41
|
+
`browser`, API routes use `http`, commands use `cli`, MCP tools use `mcp`); `--no-spec` or
|
|
42
|
+
`make.specs: false` skips it. `sdxc make email <name> field ...` takes fields as `make model`
|
|
43
|
+
does; they become the email's props.
|
|
41
44
|
- For a resource people list, show, create, edit and delete, start from
|
|
42
|
-
`sdxc scaffold <name> title body:text` (`--mcp` and `--command` add its tools and commands
|
|
45
|
+
`sdxc scaffold <name> title body:text` (`--mcp` and `--command` add its tools and commands, and
|
|
46
|
+
one feature `.spec` mixes the surfaces the scaffold wrote).
|
|
43
47
|
- `sdxc make policy <resource>` adds the resource's `create`, `read`, `update` and `delete`
|
|
44
48
|
abilities to `app/policies/abilities.ts` and grants them in `app/policies/policy.ts`, reads to
|
|
45
49
|
`everyone` and writes to `member`. Check them in a handler with `ctx.access.can(…)`: a hidden
|
package/templates/app/README.md
CHANGED
|
@@ -25,7 +25,7 @@ sdxc make migration create-tags name # then: sdxc run db migrate
|
|
|
25
25
|
sdxc make job reports/daily --cron "0 8 * * *"
|
|
26
26
|
sdxc make email welcome name # then: ctx.email.later(emails.welcome, { to, props })
|
|
27
27
|
sdxc make command users/grant # then: sdxc run users grant
|
|
28
|
-
sdxc scaffold post title body:text # model, migration, CRUD pages and
|
|
28
|
+
sdxc scaffold post title body:text # model, migration, CRUD pages, tests and a .spec
|
|
29
29
|
|
|
30
30
|
sdxc run db console # SQL prompt over the local database
|
|
31
31
|
sdxc run console # Bun's REPL with db and models loaded
|
|
@@ -34,12 +34,15 @@ sdxc run db fresh --seed # drop every local table, migrate, se
|
|
|
34
34
|
sdxc run emails preview welcome # print an email from its preview(); /_emails in bun dev
|
|
35
35
|
sdxc routes # every route and its controller (-g, -c, --unused)
|
|
36
36
|
sdxc doctor # release drift, secrets, migrations and wiring
|
|
37
|
+
bunx spec run spec --allow-config # black-box .spec suite under spec/
|
|
37
38
|
bun check # format, lint and types
|
|
38
39
|
bun run test
|
|
39
40
|
```
|
|
40
41
|
|
|
41
|
-
`sdxc make` writes the file where it belongs with a test beside it, and
|
|
42
|
-
|
|
42
|
+
`sdxc make` writes the file where it belongs with a test beside it, and for a controller, command
|
|
43
|
+
or MCP tool a pairing `.spec` under `spec/` so you can exercise it as a black box. It maps the
|
|
44
|
+
file so it works right away. `sdxc` comes with the project; `npm add -g @sdxc/kit` puts it on
|
|
45
|
+
your path.
|
|
43
46
|
|
|
44
47
|
`AGENTS.md` teaches an AI coding agent these commands and conventions, and `CLAUDE.md` points
|
|
45
48
|
Claude Code at it. `sdxc upgrade` keeps its sdxc section current; add your own rules below it.
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The `typegen` command, which hands type generation to `cf` in the project's root
|
|
2
|
+
* The `typegen` command, which hands type generation to `cf` in the project's root and stamps the
|
|
3
|
+
* types as current even when `cf` found nothing to change.
|
|
3
4
|
*/
|
|
4
5
|
|
|
6
|
+
import { mkdir, stat, utimes, writeFile } from "node:fs/promises";
|
|
7
|
+
import { dirname } from "node:path";
|
|
8
|
+
|
|
5
9
|
import { invoke } from "@sdxc/cli/test";
|
|
10
|
+
import { isFailure, wrap } from "@sdxc/result";
|
|
6
11
|
import { describe, expect, test } from "vitest";
|
|
7
12
|
|
|
13
|
+
import { TYPES_FILE } from "~/app/commands/typegen";
|
|
8
14
|
import { cli } from "~/app/initializers/cli";
|
|
9
15
|
|
|
10
16
|
describe("typegen", () => {
|
|
@@ -14,4 +20,17 @@ describe("typegen", () => {
|
|
|
14
20
|
expect(run.code).toBe(0);
|
|
15
21
|
expect(run.exec.map((call) => call.command)).toEqual([["cf", "workers", "types"]]);
|
|
16
22
|
});
|
|
23
|
+
|
|
24
|
+
test("stamps types cf left unchanged, so sdxc doctor reads them as current", async () => {
|
|
25
|
+
if (isFailure(await wrap(() => stat(TYPES_FILE)))) {
|
|
26
|
+
await mkdir(dirname(TYPES_FILE), { recursive: true });
|
|
27
|
+
await writeFile(TYPES_FILE, "");
|
|
28
|
+
}
|
|
29
|
+
await utimes(TYPES_FILE, new Date(0), new Date(0));
|
|
30
|
+
let started = Date.now();
|
|
31
|
+
|
|
32
|
+
await invoke(cli, ["typegen"], { exec: { "cf workers types": { code: 0 } } });
|
|
33
|
+
|
|
34
|
+
expect((await stat(TYPES_FILE)).mtimeMs).toBeGreaterThanOrEqual(started - 1_000);
|
|
35
|
+
});
|
|
17
36
|
});
|
|
@@ -4,13 +4,27 @@
|
|
|
4
4
|
* type check against what the Worker receives. Safe to run twice.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
import { utimes } from "node:fs/promises";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
|
|
7
10
|
import { createCommand, success } from "@sdxc/cli";
|
|
8
|
-
import { isFailure } from "@sdxc/result";
|
|
11
|
+
import { isFailure, wrap } from "@sdxc/result";
|
|
9
12
|
|
|
10
13
|
import commandset from "~/app/commands";
|
|
11
14
|
import { PROJECT_ROOT } from "~/app/initializers/local-database";
|
|
12
15
|
|
|
16
|
+
/** Where `cf workers types` writes the types, the file the project's tsconfig includes. */
|
|
17
|
+
export const TYPES_FILE = join(PROJECT_ROOT, ".cloudflare/types/index.d.ts");
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Generates the types, then stamps them with the current time: `cf` keeps an unchanged file as it
|
|
21
|
+
* was, and the stamp is what tells `sdxc doctor` the types match the config after an edit that
|
|
22
|
+
* adds no binding, like a cron trigger.
|
|
23
|
+
*/
|
|
13
24
|
export default createCommand(commandset.typegen, async (ctx) => {
|
|
14
25
|
let generated = await ctx.exec(["cf", "workers", "types"], { cwd: PROJECT_ROOT });
|
|
15
|
-
|
|
26
|
+
if (isFailure(generated)) return generated;
|
|
27
|
+
let now = new Date();
|
|
28
|
+
await wrap(() => utimes(TYPES_FILE, now, now));
|
|
29
|
+
return success();
|
|
16
30
|
});
|
|
@@ -99,3 +99,10 @@ cli.map(
|
|
|
99
99
|
commandset.typegen,
|
|
100
100
|
lazy(() => import("~/app/commands/typegen")),
|
|
101
101
|
);
|
|
102
|
+
|
|
103
|
+
declare module "@sdxc/cli" {
|
|
104
|
+
/** Types every command handler's `ctx` with what the middleware above publishes: `ctx.db`, `ctx.models`, `ctx.email` and `ctx.intl`. */
|
|
105
|
+
interface CLITypes {
|
|
106
|
+
cli: typeof cli;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The app's mail transport, delivering into the in-memory `send_email` stand-in tests receive
|
|
3
|
-
* as the `EMAIL` binding.
|
|
3
|
+
* as the `EMAIL` binding, and its queue, handing deliveries to the `QUEUE` binding.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { Mailer } from "@sdxc/mail";
|
|
7
7
|
import { env } from "cloudflare:workers";
|
|
8
8
|
import { describe, expect, test } from "vitest";
|
|
9
9
|
|
|
10
|
-
import { transport } from "~/app/initializers/mail-transport";
|
|
10
|
+
import { queue, transport } from "~/app/initializers/mail-transport";
|
|
11
11
|
import { MAIL_FROM } from "~/config/constants";
|
|
12
12
|
|
|
13
13
|
describe("transport", () => {
|
|
@@ -24,4 +24,10 @@ describe("transport", () => {
|
|
|
24
24
|
messages: [expect.objectContaining({ subject: "Welcome" })],
|
|
25
25
|
});
|
|
26
26
|
});
|
|
27
|
+
|
|
28
|
+
test("queues a delivery for the email job on the QUEUE binding", async () => {
|
|
29
|
+
await queue({ email: "welcome", to: "ada@example.com", props: {} });
|
|
30
|
+
|
|
31
|
+
expect(env.QUEUE).toMatchObject({ messages: [expect.anything()] });
|
|
32
|
+
});
|
|
27
33
|
});
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import {
|
|
9
9
|
createD1Database,
|
|
10
10
|
createKVNamespace,
|
|
11
|
+
createQueue,
|
|
11
12
|
createRateLimit,
|
|
12
13
|
createSendEmail,
|
|
13
14
|
} from "@sdxc/cloudflare-mocks";
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
export const env = {
|
|
17
18
|
DB: createD1Database(),
|
|
18
19
|
EMAIL: createSendEmail(),
|
|
20
|
+
QUEUE: createQueue(),
|
|
19
21
|
RATE_LIMITER: createRateLimit(),
|
|
20
22
|
SESSIONS: createKVNamespace(),
|
|
21
23
|
SESSION_SECRET: "development-session-secret",
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
// The URL `browser`, `http` and `mcp` resolve `/path` targets against. Set APP_BASE_URL
|
|
3
|
+
// to point the suite at another host; the default matches `bun run dev`.
|
|
4
|
+
"bases": {
|
|
5
|
+
"web": { "env": "APP_BASE_URL", "default": "http://localhost:5173" },
|
|
6
|
+
},
|
|
7
|
+
// Applied once a run adds `--allow-config`. Pairing specs from `sdxc make` and
|
|
8
|
+
// `sdxc scaffold` expect these grants for a local black-box run.
|
|
9
|
+
"permissions": {
|
|
10
|
+
"allow": [
|
|
11
|
+
["run", "bun"],
|
|
12
|
+
["host-fs", "."],
|
|
13
|
+
["net", "localhost:5173"],
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
}
|