@wwchen/stack 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +47 -2
  3. package/blocks/AGENTS.md +77 -0
  4. package/blocks/CLAUDE.md +113 -0
  5. package/blocks/env.example +32 -0
  6. package/blocks/gitignore +18 -0
  7. package/configs/biome.json +45 -0
  8. package/configs/tsconfig.next.json +22 -0
  9. package/dist/auth/better-auth/index.d.ts +316 -0
  10. package/dist/auth/better-auth/index.js +237 -0
  11. package/dist/auth/better-auth/tables.d.ts +628 -0
  12. package/dist/auth/better-auth/tables.js +74 -0
  13. package/dist/auth/better-auth/users.d.ts +27 -0
  14. package/dist/auth/better-auth/users.js +128 -0
  15. package/dist/auth/index.d.ts +58 -0
  16. package/dist/auth/index.js +120 -0
  17. package/dist/auth/proxy.d.ts +14 -0
  18. package/dist/auth/proxy.js +50 -0
  19. package/dist/auth/safe-next.d.ts +17 -0
  20. package/dist/auth/safe-next.js +36 -0
  21. package/dist/auth/types.d.ts +47 -0
  22. package/dist/auth/types.js +5 -0
  23. package/dist/cli/context.d.ts +38 -0
  24. package/dist/cli/context.js +43 -0
  25. package/dist/cli/index.d.ts +4 -0
  26. package/dist/cli/index.js +95 -0
  27. package/dist/cli/neon.d.ts +97 -0
  28. package/dist/cli/neon.js +334 -0
  29. package/dist/cli/sync-blocks.d.ts +16 -0
  30. package/dist/cli/sync-blocks.js +97 -0
  31. package/dist/cli/user-create.d.ts +2 -0
  32. package/dist/cli/user-create.js +35 -0
  33. package/dist/cli/vercel-build.d.ts +4 -0
  34. package/dist/cli/vercel-build.js +72 -0
  35. package/dist/configs/vitest.d.ts +4 -0
  36. package/dist/configs/vitest.js +50 -0
  37. package/dist/db/explaining-pool.d.ts +16 -0
  38. package/dist/db/explaining-pool.js +62 -0
  39. package/dist/db/index.d.ts +21 -0
  40. package/dist/db/index.js +36 -0
  41. package/dist/db/migration-status.d.ts +8 -0
  42. package/dist/db/migration-status.js +41 -0
  43. package/dist/db/target.d.ts +26 -0
  44. package/dist/db/target.js +72 -0
  45. package/dist/db/testing/index.d.ts +27 -0
  46. package/dist/db/testing/index.js +71 -0
  47. package/dist/db/testing/isolate.d.ts +1 -0
  48. package/dist/db/testing/isolate.js +4 -0
  49. package/dist/db/testing/pglite.d.ts +21 -0
  50. package/dist/db/testing/pglite.js +71 -0
  51. package/dist/env/define-env.d.ts +37 -0
  52. package/dist/env/define-env.js +134 -0
  53. package/dist/env/index.d.ts +3 -0
  54. package/dist/env/index.js +3 -0
  55. package/dist/env/load-env-file.d.ts +15 -0
  56. package/dist/env/load-env-file.js +52 -0
  57. package/dist/env/stack-env.d.ts +39 -0
  58. package/dist/env/stack-env.js +52 -0
  59. package/dist/env/testing.d.ts +8 -0
  60. package/dist/env/testing.js +16 -0
  61. package/dist/http/client-ip.d.ts +12 -0
  62. package/dist/http/client-ip.js +28 -0
  63. package/dist/http/guards.d.ts +17 -0
  64. package/dist/http/guards.js +57 -0
  65. package/dist/http/rate-limit.d.ts +34 -0
  66. package/dist/http/rate-limit.js +79 -0
  67. package/dist/index.d.ts +1 -0
  68. package/dist/index.js +1 -0
  69. package/dist/mail/index.d.ts +45 -0
  70. package/dist/mail/index.js +97 -0
  71. package/dist/next/api.d.ts +71 -0
  72. package/dist/next/api.js +118 -0
  73. package/dist/next/config.d.ts +8 -0
  74. package/dist/next/config.js +104 -0
  75. package/dist/next/cron.d.ts +11 -0
  76. package/dist/next/cron.js +33 -0
  77. package/dist/next/health.d.ts +19 -0
  78. package/dist/next/health.js +36 -0
  79. package/dist/next/index.d.ts +5 -0
  80. package/dist/next/index.js +4 -0
  81. package/dist/testing/next.d.ts +14 -0
  82. package/dist/testing/next.js +39 -0
  83. package/dist/ui/app.css +56 -0
  84. package/dist/ui/globals.css +152 -0
  85. package/dist/ui/icons.d.ts +17 -0
  86. package/dist/ui/icons.js +104 -0
  87. package/dist/ui/index.d.ts +33 -0
  88. package/dist/ui/index.js +41 -0
  89. package/dist/ui/theme.d.ts +18 -0
  90. package/dist/ui/theme.js +24 -0
  91. package/package.json +126 -4
@@ -0,0 +1,39 @@
1
+ // `@wwchen/stack/testing/next`: test helpers, for a stack app's tests and the package's own. Not
2
+ // for app code. Built on Next's internals, which move with the exact `next` the stack pins, so they
3
+ // ship here and an app takes a fix with the stack rather than keeping a copy.
4
+ import { workAsyncStorage } from "next/dist/server/app-render/work-async-storage.external.js";
5
+ import { workUnitAsyncStorage } from "next/dist/server/app-render/work-unit-async-storage.external.js";
6
+ import { createRequestStoreForAPI } from "next/dist/server/async-storage/request-store.js";
7
+ /**
8
+ * Runs `fn` inside a real Next request scope in its server-action phase — what Next sets up around
9
+ * a `"use server"` function — so `headers()` reads `headers` and `cookies().set()` works. Returns
10
+ * the `Set-Cookie` lines the scope would send, which is how a test sees what Better Auth's
11
+ * `nextCookies()` wrote. Built from Next's own internals (next is pinned exactly).
12
+ *
13
+ * `redirect()` and `notFound()` throw as they do in Next; `thrownBy` reads where they pointed.
14
+ */
15
+ export async function inServerAction(headers, fn) {
16
+ let setCookies = [];
17
+ const store = createRequestStoreForAPI({ headers: Object.fromEntries(new Headers(headers)) }, new URL("http://localhost:3000/sign-in"), { tags: [], expirationsByCacheKind: new Map() }, (cookies) => {
18
+ setCookies = cookies;
19
+ }, undefined, undefined);
20
+ const result = await workAsyncStorage.run({ route: "/sign-in" }, () => workUnitAsyncStorage.run(store, fn));
21
+ return { result, setCookies };
22
+ }
23
+ /** What a `redirect()` or `notFound()` thrown by `fn` means: `redirect:<url>` or `http:<status>`. */
24
+ export async function thrownBy(fn) {
25
+ try {
26
+ await fn();
27
+ }
28
+ catch (error) {
29
+ const digest = error.digest;
30
+ if (typeof digest === "string" && digest.startsWith("NEXT_REDIRECT;")) {
31
+ return `redirect:${digest.split(";")[2]}`;
32
+ }
33
+ if (typeof digest === "string" && digest.startsWith("NEXT_HTTP_ERROR_FALLBACK;")) {
34
+ return `http:${digest.split(";")[1]}`;
35
+ }
36
+ throw error;
37
+ }
38
+ throw new Error("expected a redirect or notFound, but nothing was thrown");
39
+ }
@@ -0,0 +1,56 @@
1
+ /*
2
+ * The bridge onto LDS (`@lew-ds/lds`, imported in globals.css): the only place the package adjusts
3
+ * it. Each rule says which gap it fills.
4
+ */
5
+
6
+ /*
7
+ * Fonts. The product theme names 'Inter', which LDS does not ship as a file. An app that loads
8
+ * Inter through `next/font` exposes it as `--font-inter` under a generated family name, so the
9
+ * theme's font roles point there; without it they fall back to the system font.
10
+ * `--th-mono` stays the theme's ui-monospace.
11
+ */
12
+ .theme-product {
13
+ --th-display: var(--font-inter, Inter), system-ui, sans-serif;
14
+ --th-body: var(--font-inter, Inter), system-ui, sans-serif;
15
+ --th-ui: var(--th-display);
16
+ }
17
+
18
+ /*
19
+ * Two roles LDS spells only inside a component, given a name so a layout utility can use them: the
20
+ * soft tint (`.emph-soft`'s fill and ink, for a selected nav item) and the error ink (an
21
+ * `lds-field__error`'s colour on the red ramp).
22
+ */
23
+ :root {
24
+ --app-tint: var(--c-100);
25
+ --app-tint-fg: var(--c-800);
26
+ --app-danger: var(--red-700);
27
+ }
28
+
29
+ .mode-dark {
30
+ --app-tint: var(--c-800);
31
+ --app-tint-fg: var(--c-100);
32
+ --app-danger: var(--red-200);
33
+ }
34
+
35
+ /*
36
+ * Tooltip line breaks. LDS's bubble collapses whitespace, so a label listing several items, one to
37
+ * a line, would run together. `pre-line` keeps the label's newlines and still wraps long lines; a
38
+ * label without one reads as before.
39
+ */
40
+ .lds-tooltip__bubble {
41
+ white-space: pre-line;
42
+ }
43
+
44
+ /*
45
+ * No zoom on focus. iOS Safari zooms the page into any field whose text is under 16px and leaves
46
+ * it zoomed after; LDS's fields take the 13px body. On a touch screen they take 16px, so focusing a
47
+ * field leaves the page where it was. Pinch zoom stays: the viewport is never locked
48
+ * (`maximum-scale` would break the 200% zoom rule). A desktop keeps LDS's size.
49
+ */
50
+ @media (pointer: coarse) {
51
+ .lds-field input,
52
+ .lds-field textarea,
53
+ .lds-field select {
54
+ font-size: max(16px, var(--text-body));
55
+ }
56
+ }
@@ -0,0 +1,152 @@
1
+ /*
2
+ * The design system is LDS (Lew Design System), product theme: the `@lew-ds/lds` package.
3
+ * LDS paints components through its own class names (`lds-btn`, `lds-tag`, `lds-table`, …), which
4
+ * `@lew-ds/lds-react`'s components emit. Tailwind is kept for LAYOUT, and every colour, radius
5
+ * and shadow utility below resolves to an LDS role, so there is one palette, not two.
6
+ *
7
+ * Import this file FIRST in the app's stylesheet, then Tailwind:
8
+ *
9
+ * @import "@wwchen/stack/ui/globals.css";
10
+ * @import "tailwindcss";
11
+ *
12
+ * The layer order below must be the first `@layer` statement Tailwind's own sees: LDS sits after
13
+ * Tailwind's preflight (so it styles bare buttons and links) and before `components` and
14
+ * `utilities` (so a layout utility on an LDS element still wins). LDS's root tokens therefore also
15
+ * win over any Tailwind default that shares their name (`--radius-lg`, `--shadow-sm`,
16
+ * `--leading-tight`): LDS is the system.
17
+ */
18
+ @layer theme, base, lds, components, utilities;
19
+
20
+ @import "@lew-ds/lds/css/palette" layer(lds);
21
+ @import "@lew-ds/lds/css/lds" layer(lds);
22
+ @import "@lew-ds/lds/css/themes/product" layer(lds);
23
+ @import "./app.css" layer(lds);
24
+
25
+ /*
26
+ * Dark mode is LDS's `mode-dark` class, which the SERVER writes onto <html> from the theme cookie
27
+ * beside `theme-product` (see `htmlClassName`): never a media query and never a client-side flip,
28
+ * so the first response is already correct.
29
+ */
30
+ @custom-variant dark (&:where(.mode-dark, .mode-dark *));
31
+
32
+ /*
33
+ * `inline`: each utility emits the LDS variable itself (`color: var(--text)`), so it re-resolves
34
+ * wherever an LDS emphasis or mode class re-points the role, the way LDS's own components do.
35
+ */
36
+ @theme inline {
37
+ /* ---- surfaces, borders and text: LDS's object-colour roles ---- */
38
+ --color-bg: var(--surface-page);
39
+ --color-surface: var(--surface-base);
40
+ --color-surface-raised: var(--surface-raised);
41
+ --color-sunken: var(--surface-sunken);
42
+ /* The 1px hairline that separates sections, and the quieter one inside a bounded panel. */
43
+ --color-border: var(--border);
44
+ --color-border-subdued: var(--border-subdued);
45
+ --color-fg: var(--text);
46
+ /* LDS has two text tiers: text and text-subdued. */
47
+ --color-fg-subdued: var(--text-subdued);
48
+ /* Glyphs and dashed tracks. NEVER body text. */
49
+ --color-icon: var(--icon);
50
+ --color-accent: var(--text-accent);
51
+ --color-link: var(--link);
52
+ /* LDS's soft emphasis (c-100 on c-800, mirrored in dark): a selected nav item. */
53
+ --color-tint: var(--app-tint);
54
+ --color-tint-fg: var(--app-tint-fg);
55
+ --color-danger: var(--app-danger);
56
+
57
+ /* ---- type: LDS product's scale (Inter; metadata in the theme's mono) ---- */
58
+ --font-sans: var(--th-body);
59
+ --font-mono: var(--th-mono);
60
+
61
+ --text-micro: var(--size-0);
62
+ --text-micro--line-height: var(--leading-normal);
63
+ --text-secondary: var(--size-1);
64
+ --text-secondary--line-height: var(--leading-normal);
65
+ --text-small: var(--size-2);
66
+ --text-small--line-height: var(--leading-normal);
67
+ /* LDS's body (13px under theme-product). Named `copy` because LDS owns `--text-body`. */
68
+ --text-copy: var(--text-body);
69
+ --text-copy--line-height: var(--leading-body);
70
+ --text-emphasis: var(--size-3);
71
+ --text-emphasis--line-height: var(--leading-normal);
72
+ --text-emphasis--font-weight: var(--weight-semibold);
73
+ --text-brand: var(--size-4);
74
+ --text-brand--line-height: var(--leading-tight);
75
+ --text-brand--font-weight: var(--weight-semibold);
76
+ --text-section: var(--size-4);
77
+ --text-section--line-height: var(--leading-tight);
78
+ --text-section--font-weight: var(--weight-semibold);
79
+ /* The page h1: LDS's title (19px under theme-product). */
80
+ --text-headline: var(--text-title);
81
+ --text-headline--line-height: var(--leading-tight);
82
+ --text-headline--font-weight: var(--weight-semibold);
83
+
84
+ /* ---- spacing: LDS's 4px scale ---- */
85
+ --spacing: var(--space-1);
86
+
87
+ /* ---- radius and elevation: LDS product ---- */
88
+ /* Panels take the theme's base radius (10px), not LDS's 28px card radius: a dense table frame. */
89
+ --radius-card: var(--radius);
90
+ --radius-control: var(--pill);
91
+ --shadow-panel: var(--shadow-base);
92
+
93
+ /* ---- layout ---- */
94
+ --container-page: 1280px;
95
+ --container-form: 960px;
96
+
97
+ /* ---- motion ---- */
98
+ --ease-out-ui: var(--ease-standard);
99
+ }
100
+
101
+ :root {
102
+ color-scheme: light;
103
+ }
104
+
105
+ :root.mode-dark {
106
+ color-scheme: dark;
107
+ }
108
+
109
+ @layer base {
110
+ /*
111
+ * The root stays 14px (LDS's size-3): every rem-based utility (the container widths) is measured
112
+ * from it, and LDS's own sizes are px. Text takes LDS's 13px body from the `text-copy` on <body>,
113
+ * not from here.
114
+ */
115
+ html {
116
+ font-size: var(--size-3);
117
+ line-height: var(--leading-body);
118
+ }
119
+
120
+ body {
121
+ background-color: var(--surface-page);
122
+ color: var(--text);
123
+ }
124
+
125
+ /* A visible focus ring at >= 3:1, on everything, in both themes: LDS's 2px accent outline. */
126
+ :focus-visible {
127
+ outline: 2px solid var(--text-accent);
128
+ outline-offset: 2px;
129
+ }
130
+
131
+ /* Money and count figures are tabular everywhere: misaligned digits in a column are a bug. */
132
+ [data-numeric] {
133
+ font-variant-numeric: tabular-nums;
134
+ }
135
+ }
136
+
137
+ /*
138
+ * Reduced motion, deliberately OUTSIDE every layer: unlayered CSS wins over `@layer utilities`
139
+ * whatever the specificity, so this needs no `!important` to switch off a `duration-*` utility. It
140
+ * covers LDS's own hover, focus and press transitions too.
141
+ */
142
+ @media (prefers-reduced-motion: reduce) {
143
+ [class*="duration-"],
144
+ [class*="lds-"] {
145
+ transition-duration: 0s;
146
+ animation-duration: 0s;
147
+ }
148
+
149
+ .lds-btn:active {
150
+ transform: none;
151
+ }
152
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The page's icon sprite holds the app's icons plus what LDS's components draw on their own. A
3
+ * glyph a component names but the sprite lacks renders as nothing, with no error anywhere, so this
4
+ * reads every glyph name the app's source hands an LDS component and checks it is in the sprite.
5
+ */
6
+ export interface IconReport {
7
+ /** Named in source, in neither the app's icons nor LDS's component icons. */
8
+ unknown: string[];
9
+ /** In the app's icons, named nowhere in source. */
10
+ unused: string[];
11
+ /** In the app's icons, not a glyph `@lew-ds/open-icons` ships. */
12
+ notInOpenIcons: string[];
13
+ }
14
+ export declare function checkIcons(opts: {
15
+ srcDir: string;
16
+ appIcons: readonly string[];
17
+ }): IconReport;
@@ -0,0 +1,104 @@
1
+ import { readdirSync, readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { COMPONENT_ICONS } from "@lew-ds/lds";
4
+ import * as lds from "@lew-ds/lds-react";
5
+ import names from "@lew-ds/open-icons/names.json" with { type: "json" };
6
+ /** The components `@lew-ds/lds-react` exports: only their icon props name glyphs. */
7
+ const LDS_COMPONENTS = new Set(Object.keys(lds).filter((name) => /^[A-Z]/.test(name)));
8
+ /** The icon props of an LDS element; `name` counts only on `<Icon>`. */
9
+ const ICON_PROP = /(?<![\w-])(iconStart|iconEnd|icon|name)=/g;
10
+ /** A string that could be a glyph name: lower-case words joined by hyphens. */
11
+ const GLYPH = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
12
+ /** A file that imports the design system, where `icon: "…"` in an object is an option's glyph. */
13
+ const IMPORTS_LDS = /from "(?:@wwchen\/stack\/ui|@lew-ds\/lds-react)"/;
14
+ /** The text of a `{…}` attribute value starting at `open`, braces balanced. */
15
+ function braced(text, open) {
16
+ let depth = 0;
17
+ for (let i = open; i < text.length; i++) {
18
+ if (text[i] === "{")
19
+ depth++;
20
+ if (text[i] === "}" && --depth === 0)
21
+ return text.slice(open + 1, i);
22
+ }
23
+ return text.slice(open + 1);
24
+ }
25
+ /**
26
+ * Whether the tag opened at `from` is still open at `to`: no `>` outside braces and quotes between
27
+ * them. A `=>` or `>` inside a `{…}` value or a string does not close it.
28
+ */
29
+ function tagOpenAt(text, from, to) {
30
+ let depth = 0;
31
+ let quote = "";
32
+ for (let i = from; i < to; i++) {
33
+ const ch = text[i];
34
+ if (quote) {
35
+ if (ch === quote)
36
+ quote = "";
37
+ }
38
+ else if (ch === '"' || ch === "'")
39
+ quote = ch;
40
+ else if (ch === "{")
41
+ depth++;
42
+ else if (ch === "}")
43
+ depth--;
44
+ else if (ch === ">" && depth === 0)
45
+ return false;
46
+ }
47
+ return true;
48
+ }
49
+ /** The name of the tag whose opening `<…>` the prop at `at` sits inside, or undefined. */
50
+ function enclosingTag(text, at) {
51
+ const opens = [...text.slice(0, at).matchAll(/<([A-Za-z]\w*)/g)];
52
+ for (const open of opens.reverse()) {
53
+ if (tagOpenAt(text, open.index ?? 0, at))
54
+ return open[1];
55
+ }
56
+ return undefined;
57
+ }
58
+ /**
59
+ * Every glyph name a JSX source hands an LDS component: a literal (`iconStart="edit"`) or any
60
+ * string in an expression (`iconStart={open ? "chevron-up" : "chevron-down"}`), except an
61
+ * attribute value nested inside it (`type="button"` on an element passed as the icon). Also an
62
+ * `icon: "…"` in an object literal (a SegmentedControl option), in a file that imports LDS.
63
+ */
64
+ function glyphNamesIn(text) {
65
+ const found = [];
66
+ for (const match of text.matchAll(ICON_PROP)) {
67
+ const at = match.index ?? 0;
68
+ const owner = enclosingTag(text, at);
69
+ if (!owner || !LDS_COMPONENTS.has(owner))
70
+ continue;
71
+ if (match[1] === "name" && owner !== "Icon")
72
+ continue;
73
+ const start = at + match[0].length;
74
+ if (text[start] === '"') {
75
+ found.push(text.slice(start + 1, text.indexOf('"', start + 1)));
76
+ }
77
+ else if (text[start] === "{") {
78
+ for (const literal of braced(text, start).matchAll(/(=)?"([^"]*)"/g)) {
79
+ if (!literal[1] && GLYPH.test(literal[2] ?? ""))
80
+ found.push(literal[2]);
81
+ }
82
+ }
83
+ }
84
+ if (IMPORTS_LDS.test(text)) {
85
+ for (const option of text.matchAll(/\bicon:\s*"([^"]+)"/g))
86
+ found.push(option[1]);
87
+ }
88
+ return found;
89
+ }
90
+ function tsxFiles(dir) {
91
+ return readdirSync(dir, { recursive: true, encoding: "utf8" })
92
+ .filter((file) => file.endsWith(".tsx"))
93
+ .map((file) => join(dir, file));
94
+ }
95
+ export function checkIcons(opts) {
96
+ const inSprite = new Set([...opts.appIcons, ...COMPONENT_ICONS]);
97
+ const used = new Set(tsxFiles(opts.srcDir).flatMap((f) => glyphNamesIn(readFileSync(f, "utf8"))));
98
+ const shipped = new Set(names);
99
+ return {
100
+ unknown: [...used].filter((name) => !inSprite.has(name)),
101
+ unused: opts.appIcons.filter((name) => !used.has(name)),
102
+ notInOpenIcons: opts.appIcons.filter((name) => !shipped.has(name)),
103
+ };
104
+ }
@@ -0,0 +1,33 @@
1
+ import { type ButtonProps, type IconButtonProps, type LinkProps, type RowProps } from "@lew-ds/lds-react";
2
+ import type { ReactNode } from "react";
3
+ /**
4
+ * The design system, as an app imports it: `@lew-ds/lds-react` (server components, but for the
5
+ * five stateful ones, which carry their own `"use client"`), with one thing bound. Every component
6
+ * that can take an `href` (Button, IconButton, Link, Row) renders it through `next/link`, so moving
7
+ * between pages is a client navigation rather than a full reload. LDS takes the router's link as
8
+ * `as`; a call site can still pass its own.
9
+ *
10
+ * Import every LDS component from here, never from the package directly, so no link forgets `as`.
11
+ * This module has no `"use client"`: a server component can import it, and so can a client one.
12
+ */
13
+ export * from "@lew-ds/lds-react";
14
+ export type { Theme } from "./theme.ts";
15
+ export { htmlClassName, resolveTheme, THEME_COOKIE } from "./theme.ts";
16
+ export declare function Button(props: ButtonProps): import("react").JSX.Element;
17
+ /** IconButton renders the package's own Button inside its Tooltip, so it needs the binding too. */
18
+ export declare function IconButton(props: IconButtonProps): import("react").JSX.Element;
19
+ /**
20
+ * LDS's Link renders an anchor even with no `href` (a placeholder link), which `next/link` refuses:
21
+ * the router's link only stands in when there is somewhere to go.
22
+ */
23
+ export declare function Link(props: LinkProps): import("react").JSX.Element;
24
+ export declare function Row(props: RowProps): import("react").JSX.Element;
25
+ /**
26
+ * The root of an app's `<body>`: the inline icon sprite, then the page. Masked glyphs draw blank
27
+ * from an external sprite in Chromium, so the sprite is in the document. `icons` is the app's own
28
+ * glyphs (see `checkIcons`); LDS adds the ones its components draw.
29
+ */
30
+ export declare function StackRoot({ icons, children }: {
31
+ icons: readonly string[];
32
+ children: ReactNode;
33
+ }): import("react").JSX.Element;
@@ -0,0 +1,41 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button as LdsButton, IconButton as LdsIconButton, Link as LdsLink, Row as LdsRow, } from "@lew-ds/lds-react";
3
+ import { IconSprite } from "@lew-ds/lds-react/icon-sprite";
4
+ import NextLink from "next/link.js";
5
+ /**
6
+ * The design system, as an app imports it: `@lew-ds/lds-react` (server components, but for the
7
+ * five stateful ones, which carry their own `"use client"`), with one thing bound. Every component
8
+ * that can take an `href` (Button, IconButton, Link, Row) renders it through `next/link`, so moving
9
+ * between pages is a client navigation rather than a full reload. LDS takes the router's link as
10
+ * `as`; a call site can still pass its own.
11
+ *
12
+ * Import every LDS component from here, never from the package directly, so no link forgets `as`.
13
+ * This module has no `"use client"`: a server component can import it, and so can a client one.
14
+ */
15
+ export * from "@lew-ds/lds-react";
16
+ export { htmlClassName, resolveTheme, THEME_COOKIE } from "./theme.js";
17
+ export function Button(props) {
18
+ return _jsx(LdsButton, { as: NextLink, ...props });
19
+ }
20
+ /** IconButton renders the package's own Button inside its Tooltip, so it needs the binding too. */
21
+ export function IconButton(props) {
22
+ return _jsx(LdsIconButton, { as: NextLink, ...props });
23
+ }
24
+ /**
25
+ * LDS's Link renders an anchor even with no `href` (a placeholder link), which `next/link` refuses:
26
+ * the router's link only stands in when there is somewhere to go.
27
+ */
28
+ export function Link(props) {
29
+ return _jsx(LdsLink, { as: props.href === undefined ? undefined : NextLink, ...props });
30
+ }
31
+ export function Row(props) {
32
+ return _jsx(LdsRow, { as: NextLink, ...props });
33
+ }
34
+ /**
35
+ * The root of an app's `<body>`: the inline icon sprite, then the page. Masked glyphs draw blank
36
+ * from an external sprite in Chromium, so the sprite is in the document. `icons` is the app's own
37
+ * glyphs (see `checkIcons`); LDS adds the ones its components draw.
38
+ */
39
+ export function StackRoot({ icons, children }) {
40
+ return (_jsxs(_Fragment, { children: [_jsx(IconSprite, { icons: icons }), children] }));
41
+ }
@@ -0,0 +1,18 @@
1
+ export type Theme = "light" | "dark";
2
+ export declare const THEME_COOKIE = "theme";
3
+ /**
4
+ * The classes LDS needs on `<html>`: the product theme (its ramps, type, radii and shadows) and the
5
+ * mode its dark rules key on (`.mode-dark .lds-tag`). Pure, so a root layout and Storybook write
6
+ * the same thing. `extra` is appended (an app's `next/font` class).
7
+ */
8
+ export declare function htmlClassName(theme: Theme, extra?: string): string;
9
+ /**
10
+ * The server-side theme read: the `theme` cookie, `light` unless it says `dark`. Dark mode is
11
+ * correct in the FIRST server response, before any client script runs, because the root layout
12
+ * calls this during render and writes the class onto `<html>`.
13
+ *
14
+ * `next/headers.js` is imported on call, not at the top: `@wwchen/stack/ui` also re-exports the
15
+ * design system's components, and a client component importing a Button from it must not pull
16
+ * `next/headers` into the client bundle.
17
+ */
18
+ export declare function resolveTheme(): Promise<Theme>;
@@ -0,0 +1,24 @@
1
+ export const THEME_COOKIE = "theme";
2
+ /**
3
+ * The classes LDS needs on `<html>`: the product theme (its ramps, type, radii and shadows) and the
4
+ * mode its dark rules key on (`.mode-dark .lds-tag`). Pure, so a root layout and Storybook write
5
+ * the same thing. `extra` is appended (an app's `next/font` class).
6
+ */
7
+ export function htmlClassName(theme, extra) {
8
+ const base = `theme-product mode-${theme}`;
9
+ return extra ? `${base} ${extra}` : base;
10
+ }
11
+ /**
12
+ * The server-side theme read: the `theme` cookie, `light` unless it says `dark`. Dark mode is
13
+ * correct in the FIRST server response, before any client script runs, because the root layout
14
+ * calls this during render and writes the class onto `<html>`.
15
+ *
16
+ * `next/headers.js` is imported on call, not at the top: `@wwchen/stack/ui` also re-exports the
17
+ * design system's components, and a client component importing a Button from it must not pull
18
+ * `next/headers` into the client bundle.
19
+ */
20
+ export async function resolveTheme() {
21
+ const { cookies } = await import("next/headers.js");
22
+ const store = await cookies();
23
+ return store.get(THEME_COOKIE)?.value === "dark" ? "dark" : "light";
24
+ }
package/package.json CHANGED
@@ -1,6 +1,128 @@
1
1
  {
2
2
  "name": "@wwchen/stack",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Shared Next.js, Neon, Better Auth, Resend and lew-ds building blocks.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/wwchen/bootstrap-stack.git",
9
+ "directory": "packages/stack"
10
+ },
11
+ "type": "module",
12
+ "engines": {
13
+ "node": "24.x"
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "configs",
18
+ "blocks"
19
+ ],
20
+ "bin": {
21
+ "stack": "dist/cli/index.js"
22
+ },
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ },
28
+ "./env": {
29
+ "types": "./dist/env/index.d.ts",
30
+ "default": "./dist/env/index.js"
31
+ },
32
+ "./db": {
33
+ "types": "./dist/db/index.d.ts",
34
+ "default": "./dist/db/index.js"
35
+ },
36
+ "./db/testing": {
37
+ "types": "./dist/db/testing/index.d.ts",
38
+ "default": "./dist/db/testing/index.js"
39
+ },
40
+ "./db/testing/isolate": {
41
+ "types": "./dist/db/testing/isolate.d.ts",
42
+ "default": "./dist/db/testing/isolate.js"
43
+ },
44
+ "./mail": {
45
+ "types": "./dist/mail/index.d.ts",
46
+ "default": "./dist/mail/index.js"
47
+ },
48
+ "./auth": {
49
+ "types": "./dist/auth/index.d.ts",
50
+ "default": "./dist/auth/index.js"
51
+ },
52
+ "./auth/better-auth": {
53
+ "types": "./dist/auth/better-auth/index.d.ts",
54
+ "default": "./dist/auth/better-auth/index.js"
55
+ },
56
+ "./auth/proxy": {
57
+ "types": "./dist/auth/proxy.d.ts",
58
+ "default": "./dist/auth/proxy.js"
59
+ },
60
+ "./next": {
61
+ "types": "./dist/next/index.d.ts",
62
+ "default": "./dist/next/index.js"
63
+ },
64
+ "./ui": {
65
+ "types": "./dist/ui/index.d.ts",
66
+ "default": "./dist/ui/index.js"
67
+ },
68
+ "./ui/icons": {
69
+ "types": "./dist/ui/icons.d.ts",
70
+ "default": "./dist/ui/icons.js"
71
+ },
72
+ "./ui/globals.css": "./dist/ui/globals.css",
73
+ "./ui/app.css": "./dist/ui/app.css",
74
+ "./configs/tsconfig.next.json": "./configs/tsconfig.next.json",
75
+ "./configs/biome.json": "./configs/biome.json",
76
+ "./configs/vitest": {
77
+ "types": "./dist/configs/vitest.d.ts",
78
+ "default": "./dist/configs/vitest.js"
79
+ },
80
+ "./testing/next": {
81
+ "types": "./dist/testing/next.d.ts",
82
+ "default": "./dist/testing/next.js"
83
+ },
84
+ "./blocks/*": "./blocks/*"
85
+ },
86
+ "scripts": {
87
+ "build": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.build.json && node scripts/copy-css.mjs",
88
+ "test": "vitest run",
89
+ "typecheck": "tsc --noEmit"
90
+ },
91
+ "dependencies": {
92
+ "@vercel/functions": "3.12.0",
93
+ "better-auth": "1.7.29",
94
+ "pg": "8.23.1",
95
+ "zod": "4.6.7"
96
+ },
97
+ "peerDependencies": {
98
+ "@electric-sql/pglite": "0.5.10",
99
+ "@electric-sql/pglite-socket": "0.2.13",
100
+ "@lew-ds/lds": "1.2.0",
101
+ "@lew-ds/lds-react": "2.0.0",
102
+ "@lew-ds/open-icons": "1.1.0",
103
+ "drizzle-orm": "0.45.4",
104
+ "next": "16.4.6",
105
+ "react": "19.3.1",
106
+ "react-dom": "19.3.1"
107
+ },
108
+ "peerDependenciesMeta": {
109
+ "@electric-sql/pglite": {
110
+ "optional": true
111
+ },
112
+ "@electric-sql/pglite-socket": {
113
+ "optional": true
114
+ }
115
+ },
116
+ "devDependencies": {
117
+ "@electric-sql/pglite": "0.5.10",
118
+ "@electric-sql/pglite-socket": "0.2.13",
119
+ "@types/node": "^24.19.2",
120
+ "@types/pg": "^8.23.1",
121
+ "@types/react": "19.3.0",
122
+ "@types/react-dom": "19.3.0",
123
+ "drizzle-kit": "0.31.11",
124
+ "tailwindcss": "4.3.3",
125
+ "typescript": "~6.0.3",
126
+ "vitest": "5.0.5"
127
+ }
128
+ }