@proveanything/smartlinks 2.0.11 → 2.0.13

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.
@@ -0,0 +1,133 @@
1
+ # SmartLinks CSS baseline (`sl-baseline`)
2
+
3
+ > **Status: SHIPPED — `v1`, frozen.** The SDK ships `@proveanything/smartlinks/baseline.css`
4
+ > (+ `baseline.classes.json`); the Portal/Hub serve it and apps opt in via
5
+ > `meta.cssBaseline: "v1"`. `v1` is frozen: an existing `sl-*` rule's meaning never changes;
6
+ > new capability ships as `v2` alongside. Supersedes the earlier "shared Tailwind base" idea —
7
+ > that approach (sharing raw generated Tailwind) was too large and could never safely change;
8
+ > this is the version that survives being frozen for years.
9
+
10
+ A small, **frozen, namespaced** set of structural CSS helpers the platform guarantees are
11
+ present, so any sub-app — and any AI/markdown/dynamic content renderer inside one — can rely
12
+ on them. It is **mechanics, not aesthetics**: layout, spacing, sizing, type scale,
13
+ responsive flow, radius/border/shadow, and a little motion. It never defines colours, fonts,
14
+ or components — those are brand data and per-app.
15
+
16
+ It is the CSS sibling of the JS shared-dependency contract, and like that contract **the SDK
17
+ is the source of truth**: the SDK authors and ships the baseline; hosts and apps consume it.
18
+
19
+ ## Why this shape (and not the alternatives)
20
+
21
+ - **Small + frozen** → maintainable for years. A 60–120-rule hand-authored contract can be
22
+ honoured indefinitely; a giant generated Tailwind sheet can't.
23
+ - **Namespaced (`sl-`)** → zero collision with an app's own Tailwind (`flex`, `p-4`) or the
24
+ host. Apps use `sl-*` for the guaranteed floor *and* their own utilities side by side. This
25
+ is what removes the cascade/coexistence fragility.
26
+ - **A stable contract, decoupled from Tailwind underneath** → the SDK may build it with
27
+ Tailwind 4/5/6 internally, but apps target `sl-*`, so Tailwind upgrades are free.
28
+ - **Teachable** → ~100 stable primitives can be put in an AI prompt; the full Tailwind
29
+ surface cannot. Dynamic/AI content gets a guaranteed floor instead of hand-rolling CSS.
30
+ - **A floor, not a ceiling** → opt-in, additive; apps are free to ignore it or write their
31
+ own CSS. It just guarantees a consistent structural baseline when they want it.
32
+
33
+ ## Responsive: container-query-backed, breakpoint-named
34
+
35
+ Apps render **both** as containers (in the host document) and as iframes. Plain viewport
36
+ `@media` is inconsistent across those — in an iframe it sees the iframe size (usually right),
37
+ in a container it sees the *host* viewport (wrong for a sub-region). So the responsive
38
+ primitives are **container-query based** (`@container`), exposed with familiar breakpoint
39
+ names so authors/AI still think "phone / tablet / desktop":
40
+
41
+ - The app's mount root is a **container context** (`sl-container`, i.e. `container-type:
42
+ inline-size`) — set by the host on container mounts and by the app root in iframe mode.
43
+ - `sl-md-grid-2` then means "when **my** box is ≥ tablet width", correct in both embed modes.
44
+ - Breakpoints (container widths): `sm` ≥ 480px, `md` ≥ 768px, `lg` ≥ 1024px.
45
+
46
+ This is the "works well on mobile / tablet / desktop" house opinion, done correctly for an
47
+ embed-first platform.
48
+
49
+ ## The v1 surface (frozen)
50
+
51
+ All names `sl-`-prefixed. Responsive variants exist only for the layout-flow primitives
52
+ marked ✦ (as `sl-{sm|md|lg}-<name>`), to keep the set teachable and small.
53
+
54
+ **Reset & a11y**
55
+ `sl-reset` (border-box + margin:0 on self/descendants) · `sl-media` (max-width:100%,
56
+ height:auto) · `sl-focus` (keyboard-only focus ring) · `sl-sr-only` · `sl-container`
57
+ (responsive container context)
58
+
59
+ **Display ✦** `sl-block` · `sl-inline-block` · `sl-inline` · `sl-flex` · `sl-inline-flex` ·
60
+ `sl-grid` · `sl-hidden`
61
+
62
+ **Flex ✦(direction)** `sl-flex-row` · `sl-flex-col` · `sl-flex-wrap` · `sl-flex-nowrap` ·
63
+ `sl-items-{start,center,end,stretch,baseline}` · `sl-justify-{start,center,end,between,around}`
64
+ · `sl-flex-1` · `sl-flex-auto` · `sl-grow-0` · `sl-shrink-0`
65
+
66
+ **Grid ✦(columns)** `sl-grid-{2,3,4}` (collapse to 1 col below `sm`) · `sl-grid-auto`
67
+ (auto-fit minmax) · `sl-col-span-full`
68
+
69
+ **Spacing** — curated 8-step scale `0,1,2,3,4,5,6,7` ≈ `0, .25, .5, .75, 1, 1.5, 2, 3 rem`.
70
+ Logical properties (RTL-safe): `sl-gap-{0..7}` · `sl-p-{0..7}` · `sl-px-{0..7}` ·
71
+ `sl-py-{0..7}` · `sl-ps-{0..7}` / `sl-pe-{0..7}` (inline start/end) · `sl-m-{0..7}` ·
72
+ `sl-mx-auto` · `sl-mt-{0..7}` · `sl-mb-{0..7}`
73
+
74
+ **Sizing** `sl-w-full` · `sl-h-full` · `sl-min-w-0` · `sl-max-w-{reading(42rem),prose(65ch),
75
+ page(72rem)}` · `sl-aspect-{square,wide(16/9)}`
76
+
77
+ **Typography** — static rem scale (predictable in any embed; use the responsive `✦` align
78
+ and per-breakpoint sizing where you want type to change). `sl-text-{xs,sm,base,lg,xl,2xl,3xl,
79
+ 4xl}` · `sl-font-{normal,medium,semibold,bold}` · `sl-leading-{tight,normal,relaxed}` ·
80
+ `sl-tracking-{tight,normal}` · `sl-text-{left,center,right}` ✦(align) · `sl-truncate` ·
81
+ `sl-line-clamp-{2,3}` · `sl-balance` (text-wrap:balance) · `sl-pretty`
82
+
83
+ **Radius / border / shadow** — neutral mechanics only (no brand colour). `sl-rounded-{sm,md,
84
+ lg,xl,full}` · `sl-border` / `sl-border-0` (colour = `--sl-border`, a subtle
85
+ `color-mix(currentColor 14%, transparent)` default, overridable) · `sl-shadow-{sm,md,lg}`
86
+ (neutral)
87
+
88
+ **Object-fit / overflow** `sl-cover` · `sl-contain` · `sl-overflow-hidden` · `sl-overflow-auto`
89
+
90
+ **Position & layering** `sl-relative` · `sl-absolute` · `sl-sticky` · `sl-inset-0` ·
91
+ `sl-z-{base,raised,overlay}` (named levels — a house layering convention so apps don't fight
92
+ over z-index)
93
+
94
+ **Motion** (small, reduced-motion-safe; keyframes are `sl-`-namespaced) `sl-transition`
95
+ (standard ease/duration) · `sl-reveal` (fade-up on view) · `sl-hover-lift` · all motion is
96
+ **disabled under `prefers-reduced-motion`**. Rich motion vocabularies stay per-app (and may
97
+ become a separate versioned motion contract later if several apps want to share one).
98
+
99
+ ### Explicitly NOT in the baseline (non-goals)
100
+ - **No colours** — brand data, delivered via CSS variables / theme params.
101
+ - **No fonts** — per-app; the baseline sets a *scale*, never a family.
102
+ - **No components** — no buttons/cards/nav; those are per-app aesthetics.
103
+ - **No full utility surface** — anything bespoke ships in the app's own scoped CSS.
104
+
105
+ ## Delivery — one SDK source, two paths
106
+
107
+ The SDK ships the compiled baseline as `@proveanything/smartlinks/baseline.css` (+ the
108
+ machine-readable class list for the doctor). One authored source; two delivery mechanisms:
109
+
110
+ | Embed mode | How the app gets it |
111
+ |---|---|
112
+ | **Container (ESM/UMD)** — same document as host | Host has already loaded `baseline.css`; the app **ships nothing** and just uses `sl-*`. Declares `meta.cssBaseline: "v1"`. |
113
+ | **Iframe** — its own document | The app **imports the SDK's `baseline.css`** into its own document (it inherits nothing, exactly like it must carry its own modules). Byte-identical to the host copy. |
114
+
115
+ Cascade: baseline loads first; app CSS after → app rules win ties. `sl-*` never collides with
116
+ app utilities regardless.
117
+
118
+ ## SDK / build support (kept minimal — no CSS surgery)
119
+ - The SDK **exports `baseline.css`** (and `baseline.classes.json`), built in the SDK's own
120
+ build so the file and the class list can't drift.
121
+ - Manifest field **`meta.cssBaseline: "v1"`** — declares reliance so the host can guarantee
122
+ it's present.
123
+ - `smartlinks-doctor`: warn if an app declares `cssBaseline` but uses an `sl-*` class outside
124
+ the declared version (the useful invariant — spirit of the JS import check). No subtraction
125
+ tooling needed: `sl-*` is a fixed vocabulary apps just use.
126
+
127
+ ## Versioning & freeze
128
+ - `v1` is **frozen**: an existing `sl-*` class's meaning/output never changes in place.
129
+ - New capability ships as `v2` **alongside** `v1` (both served), never a silent mutation.
130
+ - Tailwind (or whatever builds it) may be upgraded underneath as long as the `sl-*` contract
131
+ keeps its meaning.
132
+ - Governance: additions to the surface go through review (it's a decades-long contract);
133
+ err toward *stable and generous* over minimal, since the AI builders target it.
@@ -32,7 +32,8 @@ export default defineConfig({
32
32
  'react', 'react-dom', 'react/jsx-runtime',
33
33
  '@proveanything/smartlinks',
34
34
  'react-router-dom', '@tanstack/react-query',
35
- 'lucide-react', 'date-fns', 'liquidjs', 'marked', 'class-variance-authority',
35
+ 'lucide-react', 'date-fns', 'liquidjs', 'marked', 'dompurify', 'clsx', 'tailwind-merge',
36
+ 'class-variance-authority',
36
37
  '@radix-ui/react-slot', '@radix-ui/react-dialog', '@radix-ui/react-popover',
37
38
  '@radix-ui/react-tooltip', '@radix-ui/react-tabs', '@radix-ui/react-accordion',
38
39
  '@radix-ui/react-select', '@radix-ui/react-scroll-area', '@radix-ui/react-label',
@@ -44,7 +45,8 @@ export default defineConfig({
44
45
  '@proveanything/smartlinks': 'SL',
45
46
  'react-router-dom': 'ReactRouterDOM', '@tanstack/react-query': 'ReactQuery',
46
47
  'lucide-react': 'LucideReact', 'date-fns': 'dateFns', 'liquidjs': 'LiquidJS',
47
- 'marked': 'marked', 'class-variance-authority': 'CVA',
48
+ 'marked': 'marked', 'dompurify': 'DOMPurify', 'clsx': 'clsx',
49
+ 'tailwind-merge': 'tailwindMerge', 'class-variance-authority': 'CVA',
48
50
  '@radix-ui/react-slot': 'RadixSlot', '@radix-ui/react-dialog': 'RadixDialog',
49
51
  '@radix-ui/react-popover': 'RadixPopover', '@radix-ui/react-tooltip': 'RadixTooltip',
50
52
  '@radix-ui/react-tabs': 'RadixTabs', '@radix-ui/react-accordion': 'RadixAccordion',
@@ -72,6 +74,9 @@ export default defineConfig({
72
74
  | `date-fns` | `dateFns` | 4.4 |
73
75
  | `liquidjs` | `LiquidJS` | 10.27+ |
74
76
  | `marked` | `marked` | 12+ |
77
+ | `dompurify` | `DOMPurify` | 3+ |
78
+ | `clsx` | `clsx` | 2+ |
79
+ | `tailwind-merge` | `tailwindMerge` | 3+ |
75
80
  | `class-variance-authority` | `CVA` | 0.7 |
76
81
  | `@radix-ui/react-slot` | `RadixSlot` | 1.2.4 |
77
82
  | `@radix-ui/react-dialog` | `RadixDialog` | 1.1.23 |
@@ -86,10 +91,15 @@ export default defineConfig({
86
91
  | `@radix-ui/react-progress` | `RadixProgress` | 1.1.8 |
87
92
  | `@radix-ui/react-avatar` | `RadixAvatar` | 1.1.11 |
88
93
 
89
- `liquidjs` and `marked` are **host-provided** — externalise them, don't ship a second copy
90
- (frequently missed). `marked` is new in **contract v6**: the portal and hub render markdown in the
91
- container, so an app should use the host's renderer rather than bundling its own. `marked` does not
92
- sanitise HTML — if you render untrusted markdown, sanitise the output (e.g. DOMPurify) yourself.
94
+ `liquidjs`, `marked`, `dompurify`, `clsx` and `tailwind-merge` are **host-provided** — externalise
95
+ them, don't ship a second copy (frequently missed). `marked` arrived in **v6**; `dompurify`, `clsx`
96
+ and `tailwind-merge` in **v7**. The portal and hub render markdown in the container, so use the
97
+ host's `marked` rather than bundling your own. `marked` does not sanitise HTML — pair it with the
98
+ shared `dompurify`: `el.innerHTML = DOMPurify.sanitize(marked.parse(md))`. `window.DOMPurify` is the
99
+ **configured instance** (callable, `.sanitize()`), so `import DOMPurify from 'dompurify'` behaves
100
+ exactly like a bundled default import. `clsx` + `tailwind-merge` are the standard `cn()` pair
101
+ (`import { clsx } from 'clsx'; import { twMerge } from 'tailwind-merge'`) — keep your local `cn()`
102
+ helper if you like, it just stops paying the bundle cost.
93
103
 
94
104
  ## Backwards compatibility
95
105
 
@@ -111,11 +121,18 @@ Bundles ship their own compiled CSS, so the host's Tailwind version is irrelevan
111
121
  micro-app can stay on **Tailwind 3 indefinitely**, or adopt Tailwind 4 — its choice. (The starter
112
122
  app ships the Tailwind 4 CSS-first layout as the default; see its README.)
113
123
 
124
+ > **CSS baseline (`sl-baseline` v1):** the CSS sibling of this JS contract, but deliberately
125
+ > **not** a shared Tailwind dump. It's a small, frozen, `sl-`-namespaced set of structural
126
+ > helpers (layout, spacing, responsive flow, type scale, motion — no colours, fonts, or
127
+ > components) the SDK ships (`@proveanything/smartlinks/baseline.css`) and the host serves.
128
+ > Opt-in via `meta.cssBaseline: "v1"`. See [css-baseline.md](css-baseline.md).
129
+
114
130
  ## The R5 host stack (reference)
115
131
 
116
132
  React **19.3** · Vite **8.3** · react-router-dom **7.18** · Tailwind **4.3** (CSS-first) ·
117
133
  TypeScript **6.0** · ESLint **10.11** · `@proveanything/smartlinks` **2.0.5** ·
118
- `@proveanything/smartlinks-utils-ui` **1.16.4** · liquidjs **10.29** · marked **12+**.
134
+ `@proveanything/smartlinks-utils-ui` **1.16.4** · liquidjs **10.29** · marked **12+** ·
135
+ dompurify **3+** · clsx **2+** · tailwind-merge **3+**.
119
136
 
120
137
  > **TypeScript 7** (the native/Go compiler) is **deliberately deferred** — tooling hasn't settled.
121
138
  > Target **TS 6** for R5; it compiles existing code with no source changes.
@@ -142,8 +159,8 @@ never drift:
142
159
 
143
160
  ```ts
144
161
  import {
145
- SHARED_DEPENDENCY_CONTRACT_VERSION, // 'v6'
146
- SHARED_DEPENDENCIES, // [{ specifier, globalName, minVersion, importMapPath }, …] (26)
162
+ SHARED_DEPENDENCY_CONTRACT_VERSION, // 'v7'
163
+ SHARED_DEPENDENCIES, // [{ specifier, globalName, minVersion, importMapPath }, …] (29)
147
164
  SHARED_DEPENDENCY_SPECIFIERS, // bare specifiers — drop straight into a bundler `external` list
148
165
  getHostSharedDependencies, // what the live host advertises at runtime, or null
149
166
  } from '@proveanything/smartlinks'
package/docs/overview.md CHANGED
@@ -63,6 +63,7 @@ The SmartLinks SDK (`@proveanything/smartlinks`) includes comprehensive document
63
63
  | **Agent Tools** | `docs/agent-tools.md` | Exposing your app's actions to the SmartLinks agent — an MCP facade over server functions; **opt-in per app, additive, no migration**; complements `app.admin.json` (functions serve/adapt it, don't replace it); live loop staged |
64
64
  | **Deploying & Registering** | `docs/deploying-apps.md` | Getting your app into the platform: fast dev publish, channels, deploy keys, registering releases |
65
65
  | **Host Dependency Contract (R5)** | `docs/host-dependency-contract.md` | The libraries the host provides (React 19, Router 7, Radix, liquidjs, …), the externalise-don't-bundle rule + Vite config, and React-18 backwards-compat |
66
+ | **CSS Baseline** (`sl-baseline` v1) | `docs/css-baseline.md` | A small, frozen, `sl-`-namespaced set of structural helpers (layout, spacing, responsive flow, type scale, motion) the SDK ships (`@proveanything/smartlinks/baseline.css`) and the host guarantees — a teachable floor for apps + AI content. No colours/fonts/components. Opt-in via `meta.cssBaseline` |
66
67
  | **Deep Linking** | `docs/deep-link-discovery.md` | URL state management, navigable states, portal menus, AI nav |
67
68
  | **Portal Back Button** | `docs/portal-back-button.md` | Hierarchy-aware "up" navigation inside embedded apps |
68
69
  | **Portal Request Action** | `docs/portal-request-action.md` | Triggering portal built-in actions (__qrScanner, __share, __logout, etc.) from sub-apps |
package/openapi.yaml CHANGED
@@ -17957,6 +17957,8 @@ components:
17957
17957
  - dual
17958
17958
  sharedDependencies:
17959
17959
  type: string
17960
+ cssBaseline:
17961
+ type: string
17960
17962
  globals:
17961
17963
  type: object
17962
17964
  additionalProperties:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -21,6 +21,8 @@
21
21
  "import": "./dist/*.js",
22
22
  "default": "./dist/*.js"
23
23
  },
24
+ "./baseline.css": "./dist/baseline.css",
25
+ "./baseline.classes.json": "./dist/baseline.classes.json",
24
26
  "./package.json": "./package.json"
25
27
  },
26
28
  "bin": {
@@ -39,7 +41,7 @@
39
41
  ],
40
42
  "scripts": {
41
43
  "test": "node test/run.cjs",
42
- "build": "tsc && node scripts/fix-esm-extensions.mjs && node generate-api-summary.cjs && node generate-openapi.cjs && node scripts/copy-docs-to-dist.cjs",
44
+ "build": "tsc && node scripts/fix-esm-extensions.mjs && node generate-api-summary.cjs && node generate-openapi.cjs && node scripts/copy-docs-to-dist.cjs && node scripts/build-baseline.mjs",
43
45
  "docs": "typedoc",
44
46
  "docs:summary": "node generate-api-summary.cjs",
45
47
  "docs:openapi": "node generate-openapi.cjs",
@@ -62,7 +64,8 @@
62
64
  "tag": "next"
63
65
  },
64
66
  "dependencies": {
65
- "cross-fetch": "^3.1.5"
67
+ "cross-fetch": "^3.1.5",
68
+ "es-module-lexer": "^1.7.0"
66
69
  },
67
70
  "devDependencies": {
68
71
  "ts-node": "^10.9.1",
@@ -19,6 +19,7 @@
19
19
  import { readFileSync, existsSync } from 'node:fs';
20
20
  import { resolve, dirname, join } from 'node:path';
21
21
  import { fileURLToPath, pathToFileURL } from 'node:url';
22
+ import { bareImportsOf } from './lib/bare-imports.mjs';
22
23
 
23
24
  const here = dirname(fileURLToPath(import.meta.url));
24
25
 
@@ -75,25 +76,9 @@ if (meta.sharedDependencies && meta.sharedDependencies !== SHARED_DEPENDENCY_CON
75
76
  warnings.push(`built against contract ${meta.sharedDependencies}, but this SDK ships ${SHARED_DEPENDENCY_CONTRACT_VERSION} — host may not serve a matching import map.`);
76
77
  }
77
78
 
78
- // Pull the bare imports out of a bundle (handles minified `from"x"` too).
79
- function bareImportsOf(code) {
80
- const specs = new Set();
81
- const patterns = [
82
- /\bfrom\s*["']([^"']+)["']/g, // static import/export ... from "x"
83
- /\bimport\s*["']([^"']+)["']/g, // side-effect import "x"
84
- /\bimport\(\s*["']([^"']+)["']\s*\)/g, // dynamic import("x")
85
- ];
86
- for (const re of patterns) {
87
- let m;
88
- while ((m = re.exec(code))) {
89
- const spec = m[1];
90
- if (spec.startsWith('.') || spec.startsWith('/')) continue; // internal/relative
91
- if (/^https?:/.test(spec)) continue; // absolute URL import
92
- specs.add(spec);
93
- }
94
- }
95
- return [...specs];
96
- }
79
+ // bareImportsOf (scripts/lib/bare-imports.mjs) LEXES the bundle for real import
80
+ // statements — so bundled data containing the word `from` (e.g. tailwind-merge's class
81
+ // map) is not mistaken for an import.
97
82
 
98
83
  // Resolve a manifest-relative bundle path against the likely roots (dist paths
99
84
  // are sometimes relative to the app root, sometimes to the manifest dir).