@charisol/plexo-sdk 2.0.4 → 2.0.5

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.
@@ -29,9 +29,17 @@ export interface BuiltPage {
29
29
  tree: HNode;
30
30
  css: string;
31
31
  usesRuntime: boolean;
32
+ /** Every font family the page uses (Google, uploaded or otherwise), by name. */
32
33
  fonts: string[];
34
+ /** Stylesheet addresses for the Google Fonts the page uses (only those families, only the weights they have). Empty when none. */
35
+ fontLinks: string[];
33
36
  warnings: string[];
34
37
  }
38
+ /**
39
+ * A plain CSS gradient (`linear-gradient(135deg, var(--a), #fff 40%)`): only letters, digits, spaces and the few characters a
40
+ * gradient needs, with nothing that could fetch a file or end the declaration, and balanced brackets.
41
+ */
42
+ export declare function safeGradient(v: string): boolean;
35
43
  /**
36
44
  * Turns one page into markup and CSS. This is the single compile step both outputs share (HTML and React print the
37
45
  * same tree), and it is where the visible canvas of each screen is enforced:
@@ -41,4 +49,5 @@ export interface BuiltPage {
41
49
  * - the same box model and constraints the editor uses (computeNodeCss) decide where everything lands.
42
50
  */
43
51
  export declare function buildPage(page: PageDefinition, opts?: CompileOptions): BuiltPage;
52
+ /** @deprecated use `BuiltPage.fontLinks` (one address per family group, with the right weights). Kept for older callers: the first Google Fonts address, or null. */
44
53
  export declare function googleFontsHref(fonts: string[]): string | null;
@@ -8,6 +8,14 @@ export interface CompiledHtml {
8
8
  css: string;
9
9
  /** The optional runtime as a script body ('' when the page doesn't need one or `runtime: 'none'`). */
10
10
  script: string;
11
+ /**
12
+ * `<link>` tags for the page's web fonts (preconnect + one stylesheet per Google Fonts group, with only the families and
13
+ * weights used and `display=swap`); '' when the page uses none. A host that places `html` + `css` in its own page puts this
14
+ * in that page's `<head>`. Fonts the owner uploaded need nothing here: their `@font-face` rules are already at the top of `css`.
15
+ */
16
+ head: string;
17
+ /** The same stylesheet addresses as plain strings (for hosts that build their own head). */
18
+ fontLinks: string[];
11
19
  /** A complete standalone document with all of the above (fonts included). */
12
20
  document: string;
13
21
  /** Things the owner should fix, in plain words (e.g. a form with nowhere to send messages). */
@@ -21,11 +21,17 @@ export interface SanitizeV2Options {
21
21
  allowEmbedScripts?: boolean;
22
22
  /** Extra inline `<script>` bodies to keep, matched byte for byte (e.g. the owner's custom code the host vetted). */
23
23
  allowedScripts?: string[];
24
+ /**
25
+ * https origins where the site's own uploaded fonts live (e.g. `https://cdn.example.com`), so `@font-face` may load from them.
26
+ * Without this, a font file may only come from Google Fonts (fonts.gstatic.com), the site's own paths (`/fonts/x.woff2`) or an
27
+ * embedded `data:font/…` address — never from anywhere else.
28
+ */
29
+ fontOrigins?: string[];
24
30
  }
25
31
  /**
26
32
  * Keeps the parts of a stylesheet (or a `style=""` declaration list) that are safe, and everything else byte for byte.
27
33
  * Rules and declarations that could run script or fetch from somewhere strange are removed whole.
28
34
  */
29
- export declare function sanitizeCss(css: string): string;
35
+ export declare function sanitizeCss(css: string, opts?: Pick<SanitizeV2Options, 'fontOrigins'>): string;
30
36
  /** Sanitises V2 compiler output (a fragment or a whole document) with an allow-list. See the file header. */
31
37
  export declare function sanitizeV2Html(html: string, opts?: SanitizeV2Options): string;
@@ -0,0 +1,2 @@
1
+ /** Makes the fonts a design uses (Google's and the owner's own) available to the editor canvas. Renders nothing. */
2
+ export declare const EditorFonts: () => null;
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ /** The name to show for a stored value: a stack ("'Inter', ui-sans-serif…") or a bare name. */
3
+ export declare const fontNameOf: (value: string | undefined) => string;
4
+ /**
5
+ * One font picker for everything: search, every family shown in its own letters, grouped the way people think about type
6
+ * (Your fonts, Popular, Serif, Sans serif…), and — when the host can store files — "Add a font" to use the brand's own.
7
+ * `onChange` gets the CSS font stack to store (`'Inter', ui-sans-serif, …`); `value` can be a stack or a bare name.
8
+ */
9
+ export declare const FontPicker: React.FC<{
10
+ value: string | undefined;
11
+ onChange: (stack: string, name: string) => void;
12
+ label?: string;
13
+ placeholder?: string;
14
+ className?: string;
15
+ }>;
@@ -0,0 +1,13 @@
1
+ import { type CustomFont } from '../../design/customFonts';
2
+ import { type FontRequest } from '../../design/fonts';
3
+ import type { DesignSystem } from '../../design/types';
4
+ import type { DocumentNode } from '../../types/editor';
5
+ export declare function addStylesheet(href: string): void;
6
+ /** The picker shows each family in its own letters; this loads just those letters for one family. */
7
+ export declare function loadFontPreview(family: string): void;
8
+ /** Every font family a design uses: text elements' own fonts and the design system's font tokens. */
9
+ export declare function familiesInUse(root: DocumentNode, ds: DesignSystem): FontRequest[];
10
+ /** Loads the Google fonts a design uses into the editor. Uploaded fonts are handled by `syncCustomFonts`. */
11
+ export declare function loadFontsInUse(root: DocumentNode, ds: DesignSystem): void;
12
+ /** Keeps one `<style>` of `@font-face` rules for the owner's uploaded fonts in step with the design system. */
13
+ export declare function syncCustomFonts(fonts: CustomFont[] | undefined): void;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { DocumentNode } from '../../types/editor';
3
+ /**
4
+ * Font, weight, size and line height of a text element. The numbers are what the text really is on this screen — an H1 shows
5
+ * its heading size, not a made-up 16 — and changing one starts from there. Choosing a level (H1–H6) moves the size with it,
6
+ * until the person types a size of their own (then a small "reset" brings the design's size back).
7
+ */
8
+ export declare const TypeControls: React.FC<{
9
+ node: DocumentNode;
10
+ }>;
@@ -6,7 +6,7 @@ export declare function designSystemVars(ds: DesignSystem): Record<string, strin
6
6
  export declare function plexoVars(ds: DesignSystem, viewport: ViewportMode): Record<string, string>;
7
7
  /** What the editor's frame for one screen size sets, so every element on it resolves tokens the way the published page will. */
8
8
  export declare function frameVars(ds: DesignSystem, viewport: ViewportMode): Record<string, string>;
9
- /** Google Fonts a page needs: the families behind the font tokens it uses, minus system fonts. */
9
+ /** Font families (Google or uploaded) a page needs: the families behind the font tokens it uses, minus system fonts. */
10
10
  export declare function fontsNeeded(ds: DesignSystem, css: string): string[];
11
11
  /**
12
12
  * The design system as CSS for a published page: only the variables the page uses (a page doesn't ship Strata's whole
@@ -0,0 +1,49 @@
1
+ import type { DesignSystem } from './types';
2
+ /**
3
+ * Fonts a site owner uploaded. They live in the design system (so they are saved with the site, shared by every page and
4
+ * synced nowhere else): a family name, and for each look of it (weight, italic) the address of the font file. The SDK never
5
+ * uploads anything itself — the host's `onUploadFont` stores the file and hands back its address.
6
+ */
7
+ export type CustomFontFormat = 'woff2' | 'woff' | 'truetype' | 'opentype';
8
+ export interface CustomFontVariant {
9
+ /** 100–900 in steps of 100. */
10
+ weight: number;
11
+ style: 'normal' | 'italic';
12
+ /** Where the file lives: an https address, a path on the site, or (for tiny test fonts) an embedded `data:` address. */
13
+ url: string;
14
+ format: CustomFontFormat;
15
+ }
16
+ export interface CustomFont {
17
+ /** What the font is called in the picker and in the page's CSS. Letters, digits and spaces only. */
18
+ family: string;
19
+ variants: CustomFontVariant[];
20
+ }
21
+ /** Limits that keep a hand-edited or AI-written design from bloating a page. */
22
+ export declare const MAX_CUSTOM_FONTS = 12;
23
+ export declare const MAX_FONT_VARIANTS = 12;
24
+ export declare const MAX_FONT_URL = 2000;
25
+ /** A `data:` font is stored inside the design, so it is kept small (about 400 KB of font). */
26
+ export declare const MAX_FONT_DATA_URL = 560000;
27
+ /** The biggest font file the editor accepts. */
28
+ export declare const MAX_FONT_FILE_BYTES = 3000000;
29
+ export declare const FONT_FILE_ACCEPT = ".woff2,.woff,.ttf,.otf,font/woff2,font/woff,font/ttf,font/otf";
30
+ /** Is this an address a font may load from: https, a path on the site, or an embedded font? (No quotes, brackets or spaces ever.) */
31
+ export declare function isFontUrl(url: unknown): url is string;
32
+ /** Cleans untrusted custom-font data: bad entries are dropped, extras are cut, duplicates merged. Always returns a safe list. */
33
+ export declare function sanitizeCustomFonts(input: unknown): CustomFont[];
34
+ export declare const customFontsOf: (ds: Pick<DesignSystem, "fonts"> | undefined) => CustomFont[];
35
+ export declare const findCustomFont: (fonts: CustomFont[] | undefined, family: string) => CustomFont | undefined;
36
+ /** Adds one look of a family (creating the family if needed) — what happens after an upload. Replaces a look with the same weight and style. */
37
+ export declare function addCustomFont(ds: DesignSystem, family: string, variant: CustomFontVariant): DesignSystem;
38
+ export declare function removeCustomFont(ds: DesignSystem, family: string): DesignSystem;
39
+ /** `@font-face` rules (with `font-display: swap`) for the custom families in `used` (lower-case names), or all of them when `used` is omitted. */
40
+ export declare function customFontFaceCss(fonts: CustomFont[] | undefined, used?: ReadonlySet<string>): string;
41
+ export interface GuessedFont {
42
+ family: string;
43
+ weight: number;
44
+ style: 'normal' | 'italic';
45
+ format: CustomFontFormat | null;
46
+ }
47
+ /** Best guess of a font's name, weight, style and kind of file from its file name ("Brandon-Bold-Italic.woff2"), so the owner mostly just confirms. */
48
+ export declare function guessFontFromFile(fileName: string, mimeType?: string): GuessedFont;
49
+ export declare const WEIGHT_LABELS: Record<number, string>;
@@ -1,10 +1,44 @@
1
- /** Fonts offered in the picker: a short, good list, each with a sensible fallback stack. */
1
+ /**
2
+ * Fonts the editor offers: Google Fonts (every family V1 had, plus the most used ones), each with its group, the weights it
3
+ * really has, and a sensible fallback stack. The weights matter: asking Google for a weight a family doesn't have makes the
4
+ * whole stylesheet fail, so both the picker and the compilers go by this table.
5
+ */
6
+ export type FontKind = 'sans' | 'serif' | 'display' | 'mono' | 'handwriting';
2
7
  export interface FontChoice {
3
8
  name: string;
4
- kind: 'sans' | 'serif' | 'display' | 'mono';
9
+ kind: FontKind;
5
10
  stack: string;
11
+ /** The weights this family comes in (100–900). */
12
+ weights: number[];
13
+ /** Among the most used fonts (shown first, under "Popular"). */
14
+ popular: boolean;
6
15
  }
16
+ /** The fonts shown first, under "Popular": well-loved, readable, and a good mix of looks. */
17
+ export declare const POPULAR_FONTS: string[];
7
18
  export declare const FONT_CHOICES: FontChoice[];
19
+ /** The catalogue entry for a family name (case-insensitive), if it is one of ours. */
20
+ export declare const findFont: (name: string) => FontChoice | undefined;
21
+ /** Fonts every browser already has — nothing to load. */
22
+ export declare const SYSTEM_FONTS: ReadonlySet<string>;
23
+ export declare const isSystemFont: (name: string) => boolean;
8
24
  /** The first family of a font stack, unquoted ("'Plus Jakarta Sans', ui-sans-serif…" → "Plus Jakarta Sans"). */
9
25
  export declare function primaryFamily(stack: string): string;
26
+ /** A family name worth loading: plain letters, digits and spaces (anything else can't safely go in a URL or a stylesheet). */
27
+ export declare const isLoadableFamily: (name: string) => boolean;
28
+ /** The stack to store for a font name: ours with its fallbacks, or any other name with a sans fallback. */
10
29
  export declare const stackFor: (name: string) => string;
30
+ export interface FontRequest {
31
+ family: string;
32
+ /** Weights the design actually uses, on top of the usual four. */
33
+ weights?: number[];
34
+ }
35
+ /** The weights to ask Google for: the usual four plus the ones used, but only those the family really has. */
36
+ export declare function weightsToLoad(family: string, used?: number[]): number[];
37
+ /**
38
+ * The Google Fonts stylesheets a page needs: one address for all the families we know (with exactly the weights they have,
39
+ * so it can't fail), and one each for any other name — so a name Google doesn't know can't break the rest.
40
+ * `display=swap` shows text straight away in a fallback font and swaps when the font arrives.
41
+ */
42
+ export declare function googleFontsHrefs(requests: Array<string | FontRequest>): string[];
43
+ /** A tiny stylesheet for showing a family's own name in the picker (only the letters needed, so it is a few KB). */
44
+ export declare function googleFontPreviewHref(family: string): string | null;
@@ -0,0 +1 @@
1
+ export declare const GOOGLE_FONTS_DATA: string[];
@@ -2,8 +2,11 @@ export type { DesignSystem, DesignToken, DesignComponent, DesignOptions, StrataL
2
2
  export { createDefaultDesignSystem } from './baseline';
3
3
  export { tokenCssValue, ref, refKey, tokenMap, getToken, getValue, setToken, setTokens, removeToken, resolveValue, resolveKey, nameFromKey } from './tokens';
4
4
  export { deriveShades, readableOn, tint } from './shades';
5
- export { FONT_CHOICES, primaryFamily, stackFor, type FontChoice } from './fonts';
5
+ export { FONT_CHOICES, POPULAR_FONTS, primaryFamily, stackFor, findFont, isSystemFont, isLoadableFamily, weightsToLoad, googleFontsHrefs, googleFontPreviewHref, type FontChoice, type FontKind, type FontRequest } from './fonts';
6
+ export { sanitizeCustomFonts, customFontFaceCss, addCustomFont, removeCustomFont, findCustomFont, customFontsOf, guessFontFromFile, isFontUrl, MAX_CUSTOM_FONTS, MAX_FONT_VARIANTS, MAX_FONT_FILE_BYTES, FONT_FILE_ACCEPT, WEIGHT_LABELS, type CustomFont, type CustomFontVariant, type CustomFontFormat } from './customFonts';
6
7
  export { THEME_PRESETS, applyTheme, setPrimaryColor, setSecondaryColor, setNeutralScale, neutralScaleOf, setRoundness, roundnessOf, setFonts, setStatusColor, setDensity, type StatusKind, type ThemePreset, type NeutralScale, type Roundness } from './themes';
8
+ export { effectiveTypeMetrics, evalCssLength, textStyleOf, ROOT_FONT_PX, type TypeMetrics } from './typeScale';
9
+ export { levelTextStyle, isHeadingTextStyle } from './textStyles';
7
10
  export { TEXT_STYLES, TEXT_STYLE_IDS, isTextStyle, textStyleDef, textStyleVars, textStyleCss, type TextStyleId, type TextStyleDef } from './textStyles';
8
11
  export { designSystemVars, plexoVars, frameVars, designSystemCss, fontsNeeded } from './css';
9
12
  export { componentStyle, componentVariants } from './components';
@@ -4,7 +4,7 @@ import type { ViewportMode } from '../types/editor';
4
4
  * font sizes. Change the design system's fonts or sizes and every piece of text follows; on a phone the big ones step down
5
5
  * on their own. They are derived from the tokens, so there is nothing extra to keep in sync with Strata.
6
6
  */
7
- export type TextStyleId = 'display' | 'h1' | 'h2' | 'h3' | 'h4' | 'lead' | 'body' | 'small' | 'eyebrow';
7
+ export type TextStyleId = 'display' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'lead' | 'body' | 'small' | 'eyebrow';
8
8
  export interface TextStyleDef {
9
9
  id: TextStyleId;
10
10
  label: string;
@@ -17,7 +17,7 @@ export interface TextStyleDef {
17
17
  letterSpacing?: string;
18
18
  textTransform?: string;
19
19
  /** The HTML heading level text with this style should use, if any. */
20
- tag?: 1 | 2 | 3 | 4;
20
+ tag?: 1 | 2 | 3 | 4 | 5 | 6;
21
21
  }
22
22
  export declare const TEXT_STYLES: TextStyleDef[];
23
23
  export declare const TEXT_STYLE_IDS: TextStyleId[];
@@ -27,3 +27,7 @@ export declare const textStyleDef: (id: TextStyleId) => TextStyleDef;
27
27
  export declare function textStyleVars(viewport: ViewportMode): Record<string, string>;
28
28
  /** What a style sets on an element — all by reference to the variables above. */
29
29
  export declare function textStyleCss(id: TextStyleId): Record<string, string>;
30
+ /** The text style a heading of this level gets when nothing else says (H1 → "Heading 1", … H6 → "Heading 6"). */
31
+ export declare const levelTextStyle: (level: number | undefined) => TextStyleId;
32
+ /** Is this one of the heading styles (so changing a heading's level should move it to the new level's style)? */
33
+ export declare const isHeadingTextStyle: (id: unknown) => boolean;
@@ -0,0 +1,43 @@
1
+ import type { DocumentNode, ElementStyles, ViewportMode } from '../types/editor';
2
+ import { type TextStyleId } from './textStyles';
3
+ import type { DesignSystem, DesignToken } from './types';
4
+ /**
5
+ * What a piece of text really looks like: its size, line height, weight and font, worked out the way the page does — from the
6
+ * element's own settings first, then its text style (Heading 1, Body…), which points at the design system's type scale.
7
+ * The editor shows these numbers instead of guessing "16", so an H1 reads as its real size and editing it starts from there.
8
+ */
9
+ export declare const ROOT_FONT_PX = 16;
10
+ interface Ctx {
11
+ tokens: Map<string, DesignToken>;
12
+ /** Width of the screen being designed, for `vw` and container units. */
13
+ width: number;
14
+ /** The element's own font size, for `em`. */
15
+ fontPx: number;
16
+ }
17
+ /** Evaluates a CSS length expression (px, rem, em, %, vw, calc/min/max/clamp) to pixels (or a plain number). Null when it can't. */
18
+ export declare function evalCssLength(input: string, ctx: Pick<Ctx, 'width' | 'fontPx'> & {
19
+ tokens?: Map<string, DesignToken>;
20
+ }): number | null;
21
+ export interface TypeMetrics {
22
+ /** Real size in pixels (rounded to 0.1). */
23
+ fontSize: number;
24
+ /** Line height as a multiple of the size (1.25). */
25
+ lineHeight: number;
26
+ fontWeight: number;
27
+ /** The font's name ("Inter"). */
28
+ fontFamily: string;
29
+ /** The text style it comes from, if any ("h1"). */
30
+ textStyle: TextStyleId | null;
31
+ /** Did the element set its own size / line height / font (as opposed to following the design system)? */
32
+ own: {
33
+ fontSize: boolean;
34
+ lineHeight: boolean;
35
+ fontWeight: boolean;
36
+ fontFamily: boolean;
37
+ };
38
+ }
39
+ /** The text style a node follows: its own, or for a heading with none, the style for its level. */
40
+ export declare function textStyleOf(node: Pick<DocumentNode, 'type' | 'props'>, styles: ElementStyles): TextStyleId | null;
41
+ /** Works out what the text really looks like on one screen — what the Typography panel shows. */
42
+ export declare function effectiveTypeMetrics(node: Pick<DocumentNode, 'type' | 'props'>, styles: ElementStyles, ds: DesignSystem, viewport: ViewportMode): TypeMetrics;
43
+ export {};
@@ -78,4 +78,6 @@ export interface DesignSystem {
78
78
  components: DesignComponent[];
79
79
  options?: DesignOptions;
80
80
  strata?: StrataLink;
81
+ /** Fonts the owner uploaded (see `CustomFont`). Plexo-only: never synced to Strata. */
82
+ fonts?: import('./customFonts').CustomFont[];
81
83
  }
@@ -122,6 +122,19 @@ export interface V2HostConfig {
122
122
  autoSaveDuration?: number;
123
123
  /** Upload an image, return its public URL. Absent → small images are embedded in the design. */
124
124
  onUpload?: (file: File) => Promise<string> | string;
125
+ /**
126
+ * Store a font file the site owner chose and return its public address (an `https://` URL, or a path on the site such as
127
+ * `/fonts/brand-bold.woff2`). Absent → the "Add a font" button is hidden (the SDK never uploads anything itself).
128
+ * `info` is what the owner confirmed (name, weight, italic) — handy for naming the stored file. The address ends up in the
129
+ * site's design system and, at publish time, in an `@font-face` rule: it must be reachable by visitors' browsers, and when
130
+ * it is on another origin the host passes that origin to `sanitizeV2Html({ fontOrigins })`.
131
+ */
132
+ onUploadFont?: (file: File, info: {
133
+ family: string;
134
+ weight: number;
135
+ style: 'normal' | 'italic';
136
+ format: import('../design/customFonts').CustomFontFormat;
137
+ }) => Promise<string> | string;
125
138
  /** Stock photo search, brokered by the host so API keys stay server-side. */
126
139
  stockImages?: {
127
140
  providers: StockImageProvider[];
@@ -70,3 +70,10 @@ export declare function applyBlockTweak(root: DocumentNode, nodeId: string, patc
70
70
  export declare const isManagedChild: (root: DocumentNode, nodeId: string) => boolean;
71
71
  /** Swaps a managed section for another node (same position). */
72
72
  export declare function replaceNodeById(root: DocumentNode, id: string, next: DocumentNode): DocumentNode;
73
+ /**
74
+ * Changes a heading's level (H1–H6). The level is the heading's meaning (and its tag on the published page); unless the
75
+ * heading has a size of its own, it also moves to the new level's text style, so an H2 really is the design system's H2 size.
76
+ * Inside a ready-made section the change is kept as a tweak, so it survives edits to the section's words and a change of layout.
77
+ * Returns the new tree (the same one if nothing changes).
78
+ */
79
+ export declare function setHeadingLevel(root: DocumentNode, nodeId: string, level: number): DocumentNode;
@@ -30,6 +30,10 @@ export interface NodeOverride {
30
30
  };
31
31
  responsiveVisibility?: import('../types/editor').ResponsiveVisibility;
32
32
  hidden?: boolean;
33
+ /** Settings of the element itself that a person can change on the page: a heading's level (H1–H6). */
34
+ props?: {
35
+ level?: 1 | 2 | 3 | 4 | 5 | 6;
36
+ };
33
37
  }
34
38
  export interface BlockSpec {
35
39
  kind: SectionKind;
@@ -1,41 +1,41 @@
1
- import { D as e, G as t, J as n, K as r, O as i, Qt as a, St as o, T as s, U as c, W as l, X as u, Y as d, Z as f, Zt as p, _ as m, _t as h, a as g, an as _, b as v, bt as y, c as b, cn as x, d as S, f as C, gt as w, ht as T, i as E, l as D, m as O, n as k, o as A, p as j, q as M, r as N, s as P, sn as F, t as I, u as L, un as R, vt as z, w as B, xt as V, yt as H } from "./v1-B92O2-af.js";
2
- import { n as U, t as W } from "./lint-D-2x-Yeb.js";
1
+ import { $ as e, $t as t, C as n, D as r, E as i, J as a, K as o, Q as s, Qt as c, St as l, X as u, Y as d, Z as f, _t as p, a as m, bt as h, c as g, cn as _, d as v, dn as y, et as b, f as x, g as S, gt as C, ht as w, i as T, l as E, n as D, o as O, p as k, pn as A, q as j, r as M, s as N, t as P, u as F, un as I, vt as L, w as R, xt as z, y as B, yt as V } from "./v1-DgwxU8IH.js";
2
+ import { n as H, t as U } from "./lint-CTTecyu_.js";
3
3
  //#region src/v2/compile/react.ts
4
- var G = /^[A-Z][A-Za-z0-9]*$/, K = (e) => JSON.stringify(e);
5
- function q(e) {
6
- let t = "";
7
- for (let [n, r] of Object.entries(e.attrs ?? {})) {
8
- if (r === void 0 || r === !1) continue;
9
- let e = a(n);
10
- r === !0 ? t += ` ${e}` : typeof r == "number" ? t += ` ${e}={${r}}` : t += ` ${e}={${K(String(r))}}`;
4
+ var W = /^[A-Z][A-Za-z0-9]*$/, G = (e) => JSON.stringify(e);
5
+ function K(e) {
6
+ let n = "";
7
+ for (let [r, i] of Object.entries(e.attrs ?? {})) {
8
+ if (i === void 0 || i === !1) continue;
9
+ let e = t(r);
10
+ i === !0 ? n += ` ${e}` : typeof i == "number" ? n += ` ${e}={${i}}` : n += ` ${e}={${G(String(i))}}`;
11
11
  }
12
- return e.style && (t += ` style={${JSON.stringify(e.style)}}`), t;
12
+ return e.style && (n += ` style={${JSON.stringify(e.style)}}`), n;
13
13
  }
14
- function J(e, t) {
14
+ function q(e, t) {
15
15
  let n = " ".repeat(t);
16
- if (typeof e == "string") return `${n}{${K(e)}}`;
17
- let r = q(e);
18
- return p.has(e.tag) || !e.children?.length ? `${n}<${e.tag}${r} />` : `${n}<${e.tag}${r}>\n${e.children.map((e) => J(e, t + 1)).join("\n")}\n${n}</${e.tag}>`;
16
+ if (typeof e == "string") return `${n}{${G(e)}}`;
17
+ let r = K(e);
18
+ return c.has(e.tag) || !e.children?.length ? `${n}<${e.tag}${r} />` : `${n}<${e.tag}${r}>\n${e.children.map((e) => q(e, t + 1)).join("\n")}\n${n}</${e.tag}>`;
19
19
  }
20
- function Y(e) {
20
+ function J(e) {
21
21
  let t = e.replace(/[^A-Za-z0-9]+/g, " ").trim().split(" ").filter(Boolean).map((e) => e[0].toUpperCase() + e.slice(1)).join("");
22
22
  return /^[A-Z]/.test(t) ? t : `Design${t}`;
23
23
  }
24
- function X(e, t) {
25
- if (!G.test(t.componentName)) throw Error(`"${t.componentName}" isn't a valid component name — use PascalCase letters and numbers.`);
26
- let n = j(e, t), r = t.runtime !== "none" && n.usesRuntime, a = O(n.fonts), o = "`" + n.css.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${") + "`";
24
+ function Y(e, t) {
25
+ if (!W.test(t.componentName)) throw Error(`"${t.componentName}" isn't a valid component name — use PascalCase letters and numbers.`);
26
+ let n = k(e, t), i = t.runtime !== "none" && n.usesRuntime, a = n.fontLinks, o = "`" + n.css.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${") + "`";
27
27
  return {
28
28
  code: `// Generated by Plexo from a visual design. Edit it visually in the app editor's Design view
29
29
  // (which regenerates this file), or turn it into regular code by editing here.
30
- ${r ? "// @ts-nocheck — the small runtime below is plain JavaScript.\nimport { useEffect, useRef } from \"react\";" : "import type { ReactElement } from \"react\";"}
30
+ ${i ? "// @ts-nocheck — the small runtime below is plain JavaScript.\nimport { useEffect, useRef } from \"react\";" : "import type { ReactElement } from \"react\";"}
31
31
 
32
32
  const CSS = ${o};
33
- ${a ? `const FONTS = ${K(a)};\n` : ""}${r ? `\n/** Carousel autoplay, the live timer and in-page form sending. */\nconst plexoInit = ${i};\n` : ""}
34
- export default function ${t.componentName}()${r ? "" : ": ReactElement"} {
35
- ${r ? " const root = useRef<HTMLDivElement>(null);\n useEffect(() => (root.current ? plexoInit(root.current) : undefined), []);\n" : ""} return (
33
+ ${a.length ? `const FONTS: string[] = ${JSON.stringify(a)};\n` : ""}${i ? `\n/** Carousel autoplay, the live timer and in-page form sending. */\nconst plexoInit = ${r};\n` : ""}
34
+ export default function ${t.componentName}()${i ? "" : ": ReactElement"} {
35
+ ${i ? " const root = useRef<HTMLDivElement>(null);\n useEffect(() => (root.current ? plexoInit(root.current) : undefined), []);\n" : ""} return (
36
36
  <>
37
- ${a ? " <link rel=\"stylesheet\" href={FONTS} />\n" : ""} <style>{CSS}</style>
38
- ${r ? J(n.tree, 3).replace("<div", "<div ref={root}") : J(n.tree, 3)}
37
+ ${a.length ? " {FONTS.map((href) => <link key={href} rel=\"stylesheet\" href={href} />)}\n" : ""} <style>{CSS}</style>
38
+ ${i ? q(n.tree, 3).replace("<div", "<div ref={root}") : q(n.tree, 3)}
39
39
  </>
40
40
  );
41
41
  }
@@ -44,4 +44,4 @@ ${r ? J(n.tree, 3).replace("<div", "<div ref={root}") : J(n.tree, 3)}
44
44
  };
45
45
  }
46
46
  //#endregion
47
- export { F as FRAME_WIDTH, B as MAX_CUSTOM_JS, E as MAX_DEPTH, g as MAX_NODES, x as MEDIA_QUERY, w as PAGE_TEMPLATES, c as SOL_SYSTEM_PROMPT, I as V1_DYNAMIC_EQUIVALENTS, k as V2_DYNAMIC_READY, r as applyCommands, d as blankPages, h as buildPageFromTemplate, z as buildTemplateSections, T as catalogSchema, S as compilePageToHtml, X as compilePageToReact, Y as componentNameFor, _ as computePlacements, D as convertLegacyDesign, N as convertV1Design, R as createDefaultDesignSystem, l as describeCommand, u as describeDesign, f as describeSection, H as getPageTemplate, L as isLegacyDesign, y as isPageEmpty, W as lintDesignSystem, V as listPageTemplates, A as parsePages, t as parseSolReply, v as parseVideoUrl, s as prepareCustomJs, C as printHtml, U as repairDesignSystem, m as resolveFormDestination, P as sanitizeCss, b as sanitizeV2Html, M as setPageTemplateResolver, n as solCommandSchema, o as templateSeed, e as validHtmlId };
47
+ export { I as FRAME_WIDTH, n as MAX_CUSTOM_JS, T as MAX_DEPTH, m as MAX_NODES, y as MEDIA_QUERY, C as PAGE_TEMPLATES, o as SOL_SYSTEM_PROMPT, P as V1_DYNAMIC_EQUIVALENTS, D as V2_DYNAMIC_READY, d as applyCommands, s as blankPages, p as buildPageFromTemplate, L as buildTemplateSections, w as catalogSchema, v as compilePageToHtml, Y as compilePageToReact, J as componentNameFor, _ as computePlacements, E as convertLegacyDesign, M as convertV1Design, A as createDefaultDesignSystem, j as describeCommand, e as describeDesign, b as describeSection, V as getPageTemplate, F as isLegacyDesign, h as isPageEmpty, U as lintDesignSystem, z as listPageTemplates, O as parsePages, a as parseSolReply, B as parseVideoUrl, R as prepareCustomJs, x as printHtml, H as repairDesignSystem, S as resolveFormDestination, N as sanitizeCss, g as sanitizeV2Html, u as setPageTemplateResolver, f as solCommandSchema, l as templateSeed, i as validHtmlId };
package/dist/v2-strata.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e, c as t, d as n, i as r, l as i, n as a, o, r as s, s as c, t as l, u } from "./client-DlVJt_6V.js";
1
+ import { a as e, c as t, d as n, i as r, l as i, n as a, o, r as s, s as c, t as l, u } from "./client-CAWtj9sV.js";
2
2
  export { l as StrataError, c as applySync, t as baseOf, a as componentFromStrata, s as createStrataClient, i as hasAnything, o as planAutoUpdate, u as planSync, r as projectFromStrata, n as summarize, e as tokenFromStrata };