@bettercms-ai/sdk 1.43.2 → 1.45.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bindings.cjs +2 -0
- package/dist/bindings.cjs.map +1 -1
- package/dist/bindings.d.cts +7 -0
- package/dist/bindings.d.ts +7 -0
- package/dist/bindings.js +3 -1
- package/dist/bindings.js.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -3
- package/dist/index.d.ts +7 -3
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/{read-BGBG_JvH.d.ts → read-CMasc3wt.d.ts} +1 -1
- package/dist/{read-CDoVuCrS.d.cts → read-DTTdE_Xl.d.cts} +1 -1
- package/dist/{read-client-DHQb3lve.d.cts → read-client-E9OHtQAW.d.cts} +2 -0
- package/dist/{read-client-DHQb3lve.d.ts → read-client-E9OHtQAW.d.ts} +2 -0
- package/dist/read.cjs +2 -0
- package/dist/read.cjs.map +1 -1
- package/dist/read.d.cts +2 -2
- package/dist/read.d.ts +2 -2
- package/dist/read.js +2 -0
- package/dist/read.js.map +1 -1
- package/dist/sections.cjs +2 -0
- package/dist/sections.cjs.map +1 -1
- package/dist/sections.d.cts +1 -1
- package/dist/sections.d.ts +1 -1
- package/dist/sections.js +3 -1
- package/dist/sections.js.map +1 -1
- package/package.json +2 -2
package/dist/bindings.cjs
CHANGED
|
@@ -73,7 +73,9 @@ function sectionRootAttrs(block) {
|
|
|
73
73
|
const css = (0, import_types.blockStyleToCss)(block?.style ?? void 0);
|
|
74
74
|
const id = typeof block?.id === "string" && block.id !== "" ? block.id : void 0;
|
|
75
75
|
const hide = (0, import_types.hideOnAttr)(block?.style);
|
|
76
|
+
const anchor = (0, import_types.sectionIdentityAttrs)(block?.style).id;
|
|
76
77
|
return {
|
|
78
|
+
...anchor ? { id: anchor } : {},
|
|
77
79
|
...id !== void 0 ? { "data-bcms-block": id } : {},
|
|
78
80
|
"data-bcms-style": "",
|
|
79
81
|
...hide ? { "data-bcms-hide": hide } : {},
|
package/dist/bindings.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bindings.ts"],"sourcesContent":["/**\n * The attributes a site's OWN markup spreads so the BetterCMS editor binds it: a page field, a\n * collection entry, a section root and its content column. Plain objects of string attributes\n * (the style is a CSS string), so they spread as they are in every template language:\n *\n * Astro / Svelte <h1 {...fieldAttrs(\"hero-title\", page.fieldStyles)}>…</h1>\n * Vue <h1 v-bind=\"fieldAttrs('hero-title', page.fieldStyles)\">…</h1>\n *\n * @bettercms-ai/astro, /sveltekit and /nuxt re-export these; @bettercms-ai/next keeps twins whose\n * `style` is a React style object.\n */\nimport imageUrlBuilder, {\n focalInCrop,\n normalizeImageCrop,\n normalizeImageFocal,\n objectPosition,\n type ImageFit,\n type ImageFormat,\n type ImageSource,\n} from \"@bettercms-ai/image-url\";\nimport { blockStyleToColumnCss, blockStyleToCss, fieldStyleCssText, hideOnAttr, type BlockStyle, type FieldStyle, type FieldStyles } from \"@bettercms-ai/types\";\n\n/**\n * C3 — `fieldAttrs(path, fieldStyles)`: the attributes a site's OWN element spreads to bind a PAGE\n * FIELD and apply that field's stored style, so the BetterCMS editor offers its width and spacing\n * handles and its Align / Size / Weight controls.\n *\n * ---\n * const page = await loadPage(Astro, \"home\");\n * ---\n * <h1 class=\"title\" {...fieldAttrs(\"hero-title\", page?.fieldStyles)}>{entry.data[\"hero-title\"]}</h1>\n *\n * `data-bcms-style` is the site's promise that \"this element's inline style is\n * `fieldStyleToCss(fieldStyles[path])`\". The editor offers a field's handles only on an element that\n * carries it: a handle on one that does not would paint the canvas and never ship. The marker is\n * present even when the field has no style (then there is no `style` attribute at all, byte for\n * byte the element it was): an unstyled field is the one an author is about to give its first edit.\n */\nexport interface FieldAttrs {\n \"data-bcms-field\": string;\n /** The marker's revision: \"2\" promises `size` (zoom) too. Section roots keep \"\". */\n \"data-bcms-style\": \"2\";\n /** `fieldStyleToCss(fieldStyles[path])` as a CSS string; absent when the field has no style. */\n style?: string;\n}\n\n/** The stored style for `path`, by OWN key only — a path like `constructor` never reads the prototype. */\nexport function fieldStyleOf(path: string, fieldStyles: FieldStyles | Record<string, unknown> | null | undefined): FieldStyle | undefined {\n if (!fieldStyles || typeof fieldStyles !== \"object\" || !Object.prototype.hasOwnProperty.call(fieldStyles, path)) return undefined;\n const style = (fieldStyles as Record<string, unknown>)[path];\n return style && typeof style === \"object\" ? (style as FieldStyle) : undefined;\n}\n\nexport function fieldAttrs(path: string, fieldStyles?: FieldStyles | Record<string, unknown> | null): FieldAttrs {\n const style = fieldStyleCssText(fieldStyleOf(path, fieldStyles));\n return { \"data-bcms-field\": path, \"data-bcms-style\": \"2\", ...(style ? { style } : {}) };\n}\n\n/**\n * P7 — `entryAttrs(entry)` and `entryField(entry, path)`: the attributes a site's OWN card spreads to\n * declare a collection ENTRY, so the editor binds it without guessing from the rendered text.\n *\n * <article {...entryAttrs(post)}><h3 {...entryField(post, \"title\")}>{post.fields.title}</h3></article>\n *\n * The field address is ABSOLUTE (`entry:<id>:<path>`). With a `transform` the value is shown\n * changed (a date formatted, text truncated), so it is declared as `data-bcms-entry-from`: the\n * editor knows where it is but cannot re-render it.\n */\nexport type EntryRef = { id?: string } | string;\nexport type EntryTransform = \"format\" | \"truncate\" | \"rendition\" | \"route\";\n/** One key is present: `data-bcms-entry-field`, or `data-bcms-entry-from` when transformed; none without an id. */\nexport interface EntryFieldAttrs {\n \"data-bcms-entry-field\"?: string;\n \"data-bcms-entry-from\"?: string;\n}\n\nfunction entryIdOf(entry: EntryRef): string | null {\n const id = typeof entry === \"string\" ? entry : entry?.id;\n return typeof id === \"string\" && id.trim() !== \"\" ? id : null;\n}\n\n/** An entry with no id (a snapshot written before ids were kept) renders unbound, never fails the build. */\nexport function entryAttrs(entry: EntryRef): { \"data-bcms-entry\"?: string } {\n const id = entryIdOf(entry);\n return id ? { \"data-bcms-entry\": id } : {};\n}\n\nexport function entryField(entry: EntryRef, path: string, opts?: { transform?: EntryTransform }): EntryFieldAttrs {\n const id = entryIdOf(entry);\n if (typeof path !== \"string\" || path.trim() === \"\") throw new Error(`entryField: no field path given for entry ${id ?? \"(no id)\"}`);\n if (!id) return {};\n const address = `entry:${id}:${path}`;\n return opts?.transform ? { \"data-bcms-entry-from\": `${address}|${opts.transform}` } : { \"data-bcms-entry-field\": address };\n}\n\n/**\n * C3/C4 — `sectionRootAttrs(block)`: the attributes a site's OWN section root spreads so the\n * BetterCMS editor offers that section's spacing and style handles.\n *\n * <section class=\"hero\" {...sectionRootAttrs(block)}>…</section>\n *\n * The editor shows those handles on a site-rendered page only when EVERY root the site stamps\n * with `data-bcms-block` also carries `data-bcms-style`, which is the site's promise that \"this\n * root's inline style is `blockStyleToCss(block.style)`\" — the same declarations `<BcmsBlocks>`\n * puts on its own wrapper. A root that stamps the block without applying its style would get a\n * capsule that paints the canvas and never ships, so the marker must travel with the style.\n *\n * The marker is present even when the style is EMPTY (then there is no `style` attribute at all):\n * an unstyled section is exactly the one an author is about to give its first spacing edit.\n */\nexport interface SectionRootBlock {\n id?: string | null;\n style?: BlockStyle | Record<string, unknown> | null;\n}\n\nexport interface SectionRootAttrs {\n \"data-bcms-block\"?: string;\n \"data-bcms-style\": \"\";\n /** `\"mobile tablet\"` when `style.hideOn` hides it there; the site ships `RESPONSIVE_CSS` for it. */\n \"data-bcms-hide\"?: string;\n /** `blockStyleToCss(block.style)` as a CSS string; absent when the block has no style. */\n style?: string;\n}\n\n/** `paddingTop` → `padding-top`, joined the way `<BcmsBlocks>` writes its wrapper's attribute. */\nfunction cssText(css: Record<string, string | number>): string {\n return Object.entries(css)\n .map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}:${v}`)\n .join(\";\");\n}\n\nexport function sectionRootAttrs(block: SectionRootBlock | null | undefined): SectionRootAttrs {\n const css = blockStyleToCss((block?.style ?? undefined) as BlockStyle | undefined);\n const id = typeof block?.id === \"string\" && block.id !== \"\" ? block.id : undefined;\n const hide = hideOnAttr(block?.style);\n return {\n ...(id !== undefined ? { \"data-bcms-block\": id } : {}),\n \"data-bcms-style\": \"\",\n ...(hide ? { \"data-bcms-hide\": hide } : {}),\n ...(css ? { style: cssText(css) } : {}),\n };\n}\n\nexport interface SectionColumnAttrs {\n \"data-bcms-column\": \"\";\n /** `blockStyleToColumnCss(block.style)` as a CSS string; absent when the section has no column. */\n style?: string;\n}\n\n/**\n * C3 — `sectionColumnAttrs(block)`: the attributes a site's own INNER container spreads so the\n * section's content WIDTH (`style.contentWidth`, placed by `contentAlign`) ships.\n *\n * <section {...sectionRootAttrs(block)}>\n * <div class=\"container\" {...sectionColumnAttrs(block)}>…</div>\n * </section>\n *\n * The width is the column BetterCMS draws as `.bcms-block-inner` inside the section's styled box —\n * never on the root itself, whose background must stay full-bleed. `data-bcms-column` is the\n * site's promise that this box's inline style is the column; the editor offers the width handle\n * on a site-rendered page only where every styled root holds one. Max-width plus left/right\n * margins, so the container keeps its own vertical margins and, with no column, its own width.\n */\nexport function sectionColumnAttrs(block: SectionRootBlock | null | undefined): SectionColumnAttrs {\n const css = blockStyleToColumnCss((block?.style ?? undefined) as BlockStyle | undefined);\n return { \"data-bcms-column\": \"\", ...(css ? { style: cssText(css) } : {}) };\n}\n\n/** The image facts a value or asset may carry beside its URL. */\ntype ImageFacts = { altText?: string | null; alt?: string | null; width?: number | null; height?: number | null; focalX?: number | null; focalY?: number | null };\n\nexport interface ImageOptions {\n /** The field this image renders, in the editor grammar (`cover`, `hero.image`). */\n path?: string;\n alt?: string;\n width?: number;\n height?: number;\n format?: ImageFormat;\n quality?: number;\n fit?: ImageFit;\n sizes?: string;\n loading?: \"lazy\" | \"eager\";\n /** Focal point override, 0–1. Normally omitted: the value and the asset carry their own. */\n focalX?: number | null;\n focalY?: number | null;\n /** Media host for a `src` that is only an asset id. Defaults to the platform's. */\n baseUrl?: string;\n}\n\n/** The widths a `sizes` image offers: phone to desktop, and never an upscale of the picture. */\nconst LADDER = [480, 768, 1080, 1440, 1920];\nconst num = (v: unknown): number | undefined => (typeof v === \"number\" && Number.isFinite(v) ? v : undefined);\n\n/**\n * What every `<BcmsImage>` renders, computed once for all of them: the transform URL, a srcset\n * (a WIDTH ladder with `sizes` and no `width`, else 1x/2x), the alt (the value's `altText` unless\n * `alt` says otherwise) and the style declarations, camel-cased. The value's crop and focal point\n * are applied by image-url itself; a source-relative focal is re-expressed inside the crop.\n */\nexport function imageCore(src: ImageSource | (Exclude<ImageSource, string> & ImageFacts), opts: ImageOptions = {}) {\n const { width, height, format = \"webp\", quality, fit, sizes, focalX, focalY, baseUrl } = opts;\n const asset = (typeof src === \"object\" && src !== null ? src : {}) as Record<string, unknown>;\n const explicit = focalX != null || focalY != null;\n const stored =\n normalizeImageFocal(asset.focal) ??\n (num(asset.focalX) != null || num(asset.focalY) != null ? { x: num(asset.focalX) ?? 0.5, y: num(asset.focalY) ?? 0.5 } : null);\n const inWindow = stored ? focalInCrop(stored, normalizeImageCrop(asset.crop)) : null;\n const fx = explicit ? focalX : inWindow?.x;\n const fy = explicit ? focalY : inWindow?.y;\n const hasFocal = fx != null || fy != null;\n const builder = imageUrlBuilder({ baseUrl });\n const make = () => {\n let b = builder(src as ImageSource);\n if (width) b = b.width(width);\n if (height) b = b.height(height);\n if (format) b = b.format(format);\n if (quality) b = b.quality(quality);\n if (fit) b = b.fit(fit);\n if (hasFocal) b = b.focal(fx ?? 0.5, fy ?? 0.5);\n return b;\n };\n const url = make().url();\n const own = num(asset.width);\n const ladder = own ? [...new Set([...LADDER.filter((w) => w < own), Math.min(own, LADDER[LADDER.length - 1]!)])] : LADDER;\n const srcset = sizes && !width ? ladder.map((w) => `${make().width(w).url()} ${w}w`).join(\", \") : `${url} 1x, ${make().dpr(2).url()} 2x`;\n // A pixel width is the author's size for THIS image, so it also goes on as a style (a site rule\n // like `img { width: 100% }` beats a bare attribute), capped at the column it sits in. The focal\n // point rides as object-position, inert unless the site's CSS sets object-fit.\n const css: Record<string, string> = {\n ...(width ? { width: `${width}px`, maxWidth: \"100%\", height: \"auto\" } : {}),\n ...(hasFocal ? { objectPosition: objectPosition({ x: fx, y: fy }) } : {}),\n };\n const alt = opts.alt ?? (typeof asset.altText === \"string\" ? asset.altText : typeof asset.alt === \"string\" ? asset.alt : \"\");\n return { src: url, srcset, alt, css };\n}\n\nexport interface ImageAttrs {\n src: string;\n srcset: string;\n alt: string;\n loading: \"lazy\" | \"eager\";\n sizes?: string;\n width?: number;\n height?: number;\n style?: string;\n \"data-bcms-field\"?: string;\n \"data-bcms-kind\"?: \"image\";\n}\n\n/**\n * The `<img>` attributes for an image value, the same markup as every `<BcmsImage>`. Given `path`,\n * the image declares its field, so the editor binds it and a publish writes the new picture in:\n *\n * <img {...imageAttrs(page.hero.image, { path: \"hero.image\", sizes: \"100vw\" })} class=\"hero\" />\n */\nexport function imageAttrs(src: Parameters<typeof imageCore>[0], opts: ImageOptions = {}): ImageAttrs {\n const { src: url, srcset, alt, css } = imageCore(src, opts);\n const style = cssText(css);\n return {\n src: url,\n srcset,\n alt,\n loading: opts.loading ?? \"lazy\",\n ...(opts.sizes ? { sizes: opts.sizes } : {}),\n ...(opts.width ? { width: opts.width } : {}),\n ...(opts.height ? { height: opts.height } : {}),\n ...(style ? { style } : {}),\n ...(opts.path ? { \"data-bcms-field\": opts.path, \"data-bcms-kind\": \"image\" as const } : {}),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,uBAQO;AACP,mBAA0I;AA2BnI,SAAS,aAAa,MAAc,aAA+F;AACxI,MAAI,CAAC,eAAe,OAAO,gBAAgB,YAAY,CAAC,OAAO,UAAU,eAAe,KAAK,aAAa,IAAI,EAAG,QAAO;AACxH,QAAM,QAAS,YAAwC,IAAI;AAC3D,SAAO,SAAS,OAAO,UA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AE,KAAK,KAAK,QAAQ,KAAK,IAAI,IAAI,UAAU,KAAK,IAAI;AAC1D,QAAM,QAAQ,QAAQ,GAAG;AACzB,SAAO;AAAA,IACL,KAAK;AAAA,IACL;AAAA,IACA;AAAA,IACA,SAAS,KAAK,WAAW;AAAA,IACzB,GAAI,KAAK,QAAQ,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;AAAA,IAC1C,GAAI,KAAK,QAAQ,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;AAAA,IAC1C,GAAI,KAAK,SAAS,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC;AAAA,IAC7C,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;AAAA,IACzB,GAAI,KAAK,OAAO,EAAE,mBAAmB,KAAK,MAAM,kBAAkB,QAAiB,IAAI,CAAC;AAAA,EAC1F;AACF;","names":["imageUrlBuilder"]}
|
|
1
|
+
{"version":3,"sources":["../src/bindings.ts"],"sourcesContent":["/**\n * The attributes a site's OWN markup spreads so the BetterCMS editor binds it: a page field, a\n * collection entry, a section root and its content column. Plain objects of string attributes\n * (the style is a CSS string), so they spread as they are in every template language:\n *\n * Astro / Svelte <h1 {...fieldAttrs(\"hero-title\", page.fieldStyles)}>…</h1>\n * Vue <h1 v-bind=\"fieldAttrs('hero-title', page.fieldStyles)\">…</h1>\n *\n * @bettercms-ai/astro, /sveltekit and /nuxt re-export these; @bettercms-ai/next keeps twins whose\n * `style` is a React style object.\n */\nimport imageUrlBuilder, {\n focalInCrop,\n normalizeImageCrop,\n normalizeImageFocal,\n objectPosition,\n type ImageFit,\n type ImageFormat,\n type ImageSource,\n} from \"@bettercms-ai/image-url\";\nimport { blockStyleToColumnCss, blockStyleToCss, fieldStyleCssText, hideOnAttr, sectionIdentityAttrs, type BlockStyle, type FieldStyle, type FieldStyles } from \"@bettercms-ai/types\";\n\n/**\n * C3 — `fieldAttrs(path, fieldStyles)`: the attributes a site's OWN element spreads to bind a PAGE\n * FIELD and apply that field's stored style, so the BetterCMS editor offers its width and spacing\n * handles and its Align / Size / Weight controls.\n *\n * ---\n * const page = await loadPage(Astro, \"home\");\n * ---\n * <h1 class=\"title\" {...fieldAttrs(\"hero-title\", page?.fieldStyles)}>{entry.data[\"hero-title\"]}</h1>\n *\n * `data-bcms-style` is the site's promise that \"this element's inline style is\n * `fieldStyleToCss(fieldStyles[path])`\". The editor offers a field's handles only on an element that\n * carries it: a handle on one that does not would paint the canvas and never ship. The marker is\n * present even when the field has no style (then there is no `style` attribute at all, byte for\n * byte the element it was): an unstyled field is the one an author is about to give its first edit.\n */\nexport interface FieldAttrs {\n \"data-bcms-field\": string;\n /** The marker's revision: \"2\" promises `size` (zoom) too. Section roots keep \"\". */\n \"data-bcms-style\": \"2\";\n /** `fieldStyleToCss(fieldStyles[path])` as a CSS string; absent when the field has no style. */\n style?: string;\n}\n\n/** The stored style for `path`, by OWN key only — a path like `constructor` never reads the prototype. */\nexport function fieldStyleOf(path: string, fieldStyles: FieldStyles | Record<string, unknown> | null | undefined): FieldStyle | undefined {\n if (!fieldStyles || typeof fieldStyles !== \"object\" || !Object.prototype.hasOwnProperty.call(fieldStyles, path)) return undefined;\n const style = (fieldStyles as Record<string, unknown>)[path];\n return style && typeof style === \"object\" ? (style as FieldStyle) : undefined;\n}\n\nexport function fieldAttrs(path: string, fieldStyles?: FieldStyles | Record<string, unknown> | null): FieldAttrs {\n const style = fieldStyleCssText(fieldStyleOf(path, fieldStyles));\n return { \"data-bcms-field\": path, \"data-bcms-style\": \"2\", ...(style ? { style } : {}) };\n}\n\n/**\n * P7 — `entryAttrs(entry)` and `entryField(entry, path)`: the attributes a site's OWN card spreads to\n * declare a collection ENTRY, so the editor binds it without guessing from the rendered text.\n *\n * <article {...entryAttrs(post)}><h3 {...entryField(post, \"title\")}>{post.fields.title}</h3></article>\n *\n * The field address is ABSOLUTE (`entry:<id>:<path>`). With a `transform` the value is shown\n * changed (a date formatted, text truncated), so it is declared as `data-bcms-entry-from`: the\n * editor knows where it is but cannot re-render it.\n */\nexport type EntryRef = { id?: string } | string;\nexport type EntryTransform = \"format\" | \"truncate\" | \"rendition\" | \"route\";\n/** One key is present: `data-bcms-entry-field`, or `data-bcms-entry-from` when transformed; none without an id. */\nexport interface EntryFieldAttrs {\n \"data-bcms-entry-field\"?: string;\n \"data-bcms-entry-from\"?: string;\n}\n\nfunction entryIdOf(entry: EntryRef): string | null {\n const id = typeof entry === \"string\" ? entry : entry?.id;\n return typeof id === \"string\" && id.trim() !== \"\" ? id : null;\n}\n\n/** An entry with no id (a snapshot written before ids were kept) renders unbound, never fails the build. */\nexport function entryAttrs(entry: EntryRef): { \"data-bcms-entry\"?: string } {\n const id = entryIdOf(entry);\n return id ? { \"data-bcms-entry\": id } : {};\n}\n\nexport function entryField(entry: EntryRef, path: string, opts?: { transform?: EntryTransform }): EntryFieldAttrs {\n const id = entryIdOf(entry);\n if (typeof path !== \"string\" || path.trim() === \"\") throw new Error(`entryField: no field path given for entry ${id ?? \"(no id)\"}`);\n if (!id) return {};\n const address = `entry:${id}:${path}`;\n return opts?.transform ? { \"data-bcms-entry-from\": `${address}|${opts.transform}` } : { \"data-bcms-entry-field\": address };\n}\n\n/**\n * C3/C4 — `sectionRootAttrs(block)`: the attributes a site's OWN section root spreads so the\n * BetterCMS editor offers that section's spacing and style handles.\n *\n * <section class=\"hero\" {...sectionRootAttrs(block)}>…</section>\n *\n * The editor shows those handles on a site-rendered page only when EVERY root the site stamps\n * with `data-bcms-block` also carries `data-bcms-style`, which is the site's promise that \"this\n * root's inline style is `blockStyleToCss(block.style)`\" — the same declarations `<BcmsBlocks>`\n * puts on its own wrapper. A root that stamps the block without applying its style would get a\n * capsule that paints the canvas and never ships, so the marker must travel with the style.\n *\n * The marker is present even when the style is EMPTY (then there is no `style` attribute at all):\n * an unstyled section is exactly the one an author is about to give its first spacing edit.\n */\nexport interface SectionRootBlock {\n id?: string | null;\n style?: BlockStyle | Record<string, unknown> | null;\n}\n\nexport interface SectionRootAttrs {\n /**\n * The section's Anchor ID (`style.anchor`), present only when one is set, so a root with its own\n * `id` keeps it otherwise. The section's CSS class (`style.cssClass`) is NOT spread: it would\n * replace the root's own class. Read it with `sectionIdentityAttrs(block.style).className` and\n * join it into the root's class list.\n */\n id?: string;\n \"data-bcms-block\"?: string;\n \"data-bcms-style\": \"\";\n /** `\"mobile tablet\"` when `style.hideOn` hides it there; the site ships `RESPONSIVE_CSS` for it. */\n \"data-bcms-hide\"?: string;\n /** `blockStyleToCss(block.style)` as a CSS string; absent when the block has no style. */\n style?: string;\n}\n\n/** `paddingTop` → `padding-top`, joined the way `<BcmsBlocks>` writes its wrapper's attribute. */\nfunction cssText(css: Record<string, string | number>): string {\n return Object.entries(css)\n .map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}:${v}`)\n .join(\";\");\n}\n\nexport function sectionRootAttrs(block: SectionRootBlock | null | undefined): SectionRootAttrs {\n const css = blockStyleToCss((block?.style ?? undefined) as BlockStyle | undefined);\n const id = typeof block?.id === \"string\" && block.id !== \"\" ? block.id : undefined;\n const hide = hideOnAttr(block?.style);\n const anchor = sectionIdentityAttrs(block?.style).id;\n return {\n ...(anchor ? { id: anchor } : {}),\n ...(id !== undefined ? { \"data-bcms-block\": id } : {}),\n \"data-bcms-style\": \"\",\n ...(hide ? { \"data-bcms-hide\": hide } : {}),\n ...(css ? { style: cssText(css) } : {}),\n };\n}\n\nexport interface SectionColumnAttrs {\n \"data-bcms-column\": \"\";\n /** `blockStyleToColumnCss(block.style)` as a CSS string; absent when the section has no column. */\n style?: string;\n}\n\n/**\n * C3 — `sectionColumnAttrs(block)`: the attributes a site's own INNER container spreads so the\n * section's content WIDTH (`style.contentWidth`, placed by `contentAlign`) ships.\n *\n * <section {...sectionRootAttrs(block)}>\n * <div class=\"container\" {...sectionColumnAttrs(block)}>…</div>\n * </section>\n *\n * The width is the column BetterCMS draws as `.bcms-block-inner` inside the section's styled box —\n * never on the root itself, whose background must stay full-bleed. `data-bcms-column` is the\n * site's promise that this box's inline style is the column; the editor offers the width handle\n * on a site-rendered page only where every styled root holds one. Max-width plus left/right\n * margins, so the container keeps its own vertical margins and, with no column, its own width.\n */\nexport function sectionColumnAttrs(block: SectionRootBlock | null | undefined): SectionColumnAttrs {\n const css = blockStyleToColumnCss((block?.style ?? undefined) as BlockStyle | undefined);\n return { \"data-bcms-column\": \"\", ...(css ? { style: cssText(css) } : {}) };\n}\n\n/** The image facts a value or asset may carry beside its URL. */\ntype ImageFacts = { altText?: string | null; alt?: string | null; width?: number | null; height?: number | null; focalX?: number | null; focalY?: number | null };\n\nexport interface ImageOptions {\n /** The field this image renders, in the editor grammar (`cover`, `hero.image`). */\n path?: string;\n alt?: string;\n width?: number;\n height?: number;\n format?: ImageFormat;\n quality?: number;\n fit?: ImageFit;\n sizes?: string;\n loading?: \"lazy\" | \"eager\";\n /** Focal point override, 0–1. Normally omitted: the value and the asset carry their own. */\n focalX?: number | null;\n focalY?: number | null;\n /** Media host for a `src` that is only an asset id. Defaults to the platform's. */\n baseUrl?: string;\n}\n\n/** The widths a `sizes` image offers: phone to desktop, and never an upscale of the picture. */\nconst LADDER = [480, 768, 1080, 1440, 1920];\nconst num = (v: unknown): number | undefined => (typeof v === \"number\" && Number.isFinite(v) ? v : undefined);\n\n/**\n * What every `<BcmsImage>` renders, computed once for all of them: the transform URL, a srcset\n * (a WIDTH ladder with `sizes` and no `width`, else 1x/2x), the alt (the value's `altText` unless\n * `alt` says otherwise) and the style declarations, camel-cased. The value's crop and focal point\n * are applied by image-url itself; a source-relative focal is re-expressed inside the crop.\n */\nexport function imageCore(src: ImageSource | (Exclude<ImageSource, string> & ImageFacts), opts: ImageOptions = {}) {\n const { width, height, format = \"webp\", quality, fit, sizes, focalX, focalY, baseUrl } = opts;\n const asset = (typeof src === \"object\" && src !== null ? src : {}) as Record<string, unknown>;\n const explicit = focalX != null || focalY != null;\n const stored =\n normalizeImageFocal(asset.focal) ??\n (num(asset.focalX) != null || num(asset.focalY) != null ? { x: num(asset.focalX) ?? 0.5, y: num(asset.focalY) ?? 0.5 } : null);\n const inWindow = stored ? focalInCrop(stored, normalizeImageCrop(asset.crop)) : null;\n const fx = explicit ? focalX : inWindow?.x;\n const fy = explicit ? focalY : inWindow?.y;\n const hasFocal = fx != null || fy != null;\n const builder = imageUrlBuilder({ baseUrl });\n const make = () => {\n let b = builder(src as ImageSource);\n if (width) b = b.width(width);\n if (height) b = b.height(height);\n if (format) b = b.format(format);\n if (quality) b = b.quality(quality);\n if (fit) b = b.fit(fit);\n if (hasFocal) b = b.focal(fx ?? 0.5, fy ?? 0.5);\n return b;\n };\n const url = make().url();\n const own = num(asset.width);\n const ladder = own ? [...new Set([...LADDER.filter((w) => w < own), Math.min(own, LADDER[LADDER.length - 1]!)])] : LADDER;\n const srcset = sizes && !width ? ladder.map((w) => `${make().width(w).url()} ${w}w`).join(\", \") : `${url} 1x, ${make().dpr(2).url()} 2x`;\n // A pixel width is the author's size for THIS image, so it also goes on as a style (a site rule\n // like `img { width: 100% }` beats a bare attribute), capped at the column it sits in. The focal\n // point rides as object-position, inert unless the site's CSS sets object-fit.\n const css: Record<string, string> = {\n ...(width ? { width: `${width}px`, maxWidth: \"100%\", height: \"auto\" } : {}),\n ...(hasFocal ? { objectPosition: objectPosition({ x: fx, y: fy }) } : {}),\n };\n const alt = opts.alt ?? (typeof asset.altText === \"string\" ? asset.altText : typeof asset.alt === \"string\" ? asset.alt : \"\");\n return { src: url, srcset, alt, css };\n}\n\nexport interface ImageAttrs {\n src: string;\n srcset: string;\n alt: string;\n loading: \"lazy\" | \"eager\";\n sizes?: string;\n width?: number;\n height?: number;\n style?: string;\n \"data-bcms-field\"?: string;\n \"data-bcms-kind\"?: \"image\";\n}\n\n/**\n * The `<img>` attributes for an image value, the same markup as every `<BcmsImage>`. Given `path`,\n * the image declares its field, so the editor binds it and a publish writes the new picture in:\n *\n * <img {...imageAttrs(page.hero.image, { path: \"hero.image\", sizes: \"100vw\" })} class=\"hero\" />\n */\nexport function imageAttrs(src: Parameters<typeof imageCore>[0], opts: ImageOptions = {}): ImageAttrs {\n const { src: url, srcset, alt, css } = imageCore(src, opts);\n const style = cssText(css);\n return {\n src: url,\n srcset,\n alt,\n loading: opts.loading ?? \"lazy\",\n ...(opts.sizes ? { sizes: opts.sizes } : {}),\n ...(opts.width ? { width: opts.width } : {}),\n ...(opts.height ? { height: opts.height } : {}),\n ...(style ? { style } : {}),\n ...(opts.path ? { \"data-bcms-field\": opts.path, \"data-bcms-kind\": \"image\" as const } : {}),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA,uBAQO;AACP,mBAAgK;AA2BzJ,SAAS,aAAa,MAAc,aAA+F;AACxI,MAAI,CAAC,eAAe,OAAO,gBAAgB,YAAY,CAAC,OAAO,UAAU,eAAe,KAAK,aAAa,IAAI,EAAG,QAAO;AACxH,QAAM,QAAS,YAAwC,IAAI;AAC3D,SAAO,SAAS,OAAO,UAAU,WAAY,QAAuB;AACtE;AAEO,SAAS,WAAW,MAAc,aAAwE;AAC/G,QAAM,YAAQ,gCAAkB,aAAa,MAAM,WAAW,CAAC;AAC/D,SAAO,EAAE,mBAAmB,MAAM,mBAAmB,KAAK,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC,EAAG;AACxF;AAoBA,SAAS,UAAU,OAAgC;AACjD,QAAM,KAAK,OAAO,UAAU,WAAW,QAAQ,OAAO;AACtD,SAAO,OAAO,OAAO,YAAY,GAAG,KAAK,MAAM,KAAK,KAAK;AAC3D;AAGO,SAAS,WAAW,OAAiD;AAC1E,QAAM,KAAK,UAAU,KAAK;AAC1B,SAAO,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAAC;AAC3C;AAEO,SAAS,WAAW,OAAiB,MAAc,MAAwD;AAChH,QAAM,KAAK,UAAU,KAAK;AAC1B,MAAI,OAAO,SAAS,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EAAE,mBAAmB,KAAK,MAAM,kBAAkB,QAAiB,IAAI,CAAC;AAAA,EAC1F;AACF;","names":["imageUrlBuilder"]}
|
package/dist/bindings.d.cts
CHANGED
|
@@ -85,6 +85,13 @@ interface SectionRootBlock {
|
|
|
85
85
|
style?: BlockStyle | Record<string, unknown> | null;
|
|
86
86
|
}
|
|
87
87
|
interface SectionRootAttrs {
|
|
88
|
+
/**
|
|
89
|
+
* The section's Anchor ID (`style.anchor`), present only when one is set, so a root with its own
|
|
90
|
+
* `id` keeps it otherwise. The section's CSS class (`style.cssClass`) is NOT spread: it would
|
|
91
|
+
* replace the root's own class. Read it with `sectionIdentityAttrs(block.style).className` and
|
|
92
|
+
* join it into the root's class list.
|
|
93
|
+
*/
|
|
94
|
+
id?: string;
|
|
88
95
|
"data-bcms-block"?: string;
|
|
89
96
|
"data-bcms-style": "";
|
|
90
97
|
/** `"mobile tablet"` when `style.hideOn` hides it there; the site ships `RESPONSIVE_CSS` for it. */
|
package/dist/bindings.d.ts
CHANGED
|
@@ -85,6 +85,13 @@ interface SectionRootBlock {
|
|
|
85
85
|
style?: BlockStyle | Record<string, unknown> | null;
|
|
86
86
|
}
|
|
87
87
|
interface SectionRootAttrs {
|
|
88
|
+
/**
|
|
89
|
+
* The section's Anchor ID (`style.anchor`), present only when one is set, so a root with its own
|
|
90
|
+
* `id` keeps it otherwise. The section's CSS class (`style.cssClass`) is NOT spread: it would
|
|
91
|
+
* replace the root's own class. Read it with `sectionIdentityAttrs(block.style).className` and
|
|
92
|
+
* join it into the root's class list.
|
|
93
|
+
*/
|
|
94
|
+
id?: string;
|
|
88
95
|
"data-bcms-block"?: string;
|
|
89
96
|
"data-bcms-style": "";
|
|
90
97
|
/** `"mobile tablet"` when `style.hideOn` hides it there; the site ships `RESPONSIVE_CSS` for it. */
|
package/dist/bindings.js
CHANGED
|
@@ -5,7 +5,7 @@ import imageUrlBuilder, {
|
|
|
5
5
|
normalizeImageFocal,
|
|
6
6
|
objectPosition
|
|
7
7
|
} from "@bettercms-ai/image-url";
|
|
8
|
-
import { blockStyleToColumnCss, blockStyleToCss, fieldStyleCssText, hideOnAttr } from "@bettercms-ai/types";
|
|
8
|
+
import { blockStyleToColumnCss, blockStyleToCss, fieldStyleCssText, hideOnAttr, sectionIdentityAttrs } from "@bettercms-ai/types";
|
|
9
9
|
function fieldStyleOf(path, fieldStyles) {
|
|
10
10
|
if (!fieldStyles || typeof fieldStyles !== "object" || !Object.prototype.hasOwnProperty.call(fieldStyles, path)) return void 0;
|
|
11
11
|
const style = fieldStyles[path];
|
|
@@ -37,7 +37,9 @@ function sectionRootAttrs(block) {
|
|
|
37
37
|
const css = blockStyleToCss(block?.style ?? void 0);
|
|
38
38
|
const id = typeof block?.id === "string" && block.id !== "" ? block.id : void 0;
|
|
39
39
|
const hide = hideOnAttr(block?.style);
|
|
40
|
+
const anchor = sectionIdentityAttrs(block?.style).id;
|
|
40
41
|
return {
|
|
42
|
+
...anchor ? { id: anchor } : {},
|
|
41
43
|
...id !== void 0 ? { "data-bcms-block": id } : {},
|
|
42
44
|
"data-bcms-style": "",
|
|
43
45
|
...hide ? { "data-bcms-hide": hide } : {},
|
package/dist/bindings.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bindings.ts"],"sourcesContent":["/**\n * The attributes a site's OWN markup spreads so the BetterCMS editor binds it: a page field, a\n * collection entry, a section root and its content column. Plain objects of string attributes\n * (the style is a CSS string), so they spread as they are in every template language:\n *\n * Astro / Svelte <h1 {...fieldAttrs(\"hero-title\", page.fieldStyles)}>…</h1>\n * Vue <h1 v-bind=\"fieldAttrs('hero-title', page.fieldStyles)\">…</h1>\n *\n * @bettercms-ai/astro, /sveltekit and /nuxt re-export these; @bettercms-ai/next keeps twins whose\n * `style` is a React style object.\n */\nimport imageUrlBuilder, {\n focalInCrop,\n normalizeImageCrop,\n normalizeImageFocal,\n objectPosition,\n type ImageFit,\n type ImageFormat,\n type ImageSource,\n} from \"@bettercms-ai/image-url\";\nimport { blockStyleToColumnCss, blockStyleToCss, fieldStyleCssText, hideOnAttr, type BlockStyle, type FieldStyle, type FieldStyles } from \"@bettercms-ai/types\";\n\n/**\n * C3 — `fieldAttrs(path, fieldStyles)`: the attributes a site's OWN element spreads to bind a PAGE\n * FIELD and apply that field's stored style, so the BetterCMS editor offers its width and spacing\n * handles and its Align / Size / Weight controls.\n *\n * ---\n * const page = await loadPage(Astro, \"home\");\n * ---\n * <h1 class=\"title\" {...fieldAttrs(\"hero-title\", page?.fieldStyles)}>{entry.data[\"hero-title\"]}</h1>\n *\n * `data-bcms-style` is the site's promise that \"this element's inline style is\n * `fieldStyleToCss(fieldStyles[path])`\". The editor offers a field's handles only on an element that\n * carries it: a handle on one that does not would paint the canvas and never ship. The marker is\n * present even when the field has no style (then there is no `style` attribute at all, byte for\n * byte the element it was): an unstyled field is the one an author is about to give its first edit.\n */\nexport interface FieldAttrs {\n \"data-bcms-field\": string;\n /** The marker's revision: \"2\" promises `size` (zoom) too. Section roots keep \"\". */\n \"data-bcms-style\": \"2\";\n /** `fieldStyleToCss(fieldStyles[path])` as a CSS string; absent when the field has no style. */\n style?: string;\n}\n\n/** The stored style for `path`, by OWN key only — a path like `constructor` never reads the prototype. */\nexport function fieldStyleOf(path: string, fieldStyles: FieldStyles | Record<string, unknown> | null | undefined): FieldStyle | undefined {\n if (!fieldStyles || typeof fieldStyles !== \"object\" || !Object.prototype.hasOwnProperty.call(fieldStyles, path)) return undefined;\n const style = (fieldStyles as Record<string, unknown>)[path];\n return style && typeof style === \"object\" ? (style as FieldStyle) : undefined;\n}\n\nexport function fieldAttrs(path: string, fieldStyles?: FieldStyles | Record<string, unknown> | null): FieldAttrs {\n const style = fieldStyleCssText(fieldStyleOf(path, fieldStyles));\n return { \"data-bcms-field\": path, \"data-bcms-style\": \"2\", ...(style ? { style } : {}) };\n}\n\n/**\n * P7 — `entryAttrs(entry)` and `entryField(entry, path)`: the attributes a site's OWN card spreads to\n * declare a collection ENTRY, so the editor binds it without guessing from the rendered text.\n *\n * <article {...entryAttrs(post)}><h3 {...entryField(post, \"title\")}>{post.fields.title}</h3></article>\n *\n * The field address is ABSOLUTE (`entry:<id>:<path>`). With a `transform` the value is shown\n * changed (a date formatted, text truncated), so it is declared as `data-bcms-entry-from`: the\n * editor knows where it is but cannot re-render it.\n */\nexport type EntryRef = { id?: string } | string;\nexport type EntryTransform = \"format\" | \"truncate\" | \"rendition\" | \"route\";\n/** One key is present: `data-bcms-entry-field`, or `data-bcms-entry-from` when transformed; none without an id. */\nexport interface EntryFieldAttrs {\n \"data-bcms-entry-field\"?: string;\n \"data-bcms-entry-from\"?: string;\n}\n\nfunction entryIdOf(entry: EntryRef): string | null {\n const id = typeof entry === \"string\" ? entry : entry?.id;\n return typeof id === \"string\" && id.trim() !== \"\" ? id : null;\n}\n\n/** An entry with no id (a snapshot written before ids were kept) renders unbound, never fails the build. */\nexport function entryAttrs(entry: EntryRef): { \"data-bcms-entry\"?: string } {\n const id = entryIdOf(entry);\n return id ? { \"data-bcms-entry\": id } : {};\n}\n\nexport function entryField(entry: EntryRef, path: string, opts?: { transform?: EntryTransform }): EntryFieldAttrs {\n const id = entryIdOf(entry);\n if (typeof path !== \"string\" || path.trim() === \"\") throw new Error(`entryField: no field path given for entry ${id ?? \"(no id)\"}`);\n if (!id) return {};\n const address = `entry:${id}:${path}`;\n return opts?.transform ? { \"data-bcms-entry-from\": `${address}|${opts.transform}` } : { \"data-bcms-entry-field\": address };\n}\n\n/**\n * C3/C4 — `sectionRootAttrs(block)`: the attributes a site's OWN section root spreads so the\n * BetterCMS editor offers that section's spacing and style handles.\n *\n * <section class=\"hero\" {...sectionRootAttrs(block)}>…</section>\n *\n * The editor shows those handles on a site-rendered page only when EVERY root the site stamps\n * with `data-bcms-block` also carries `data-bcms-style`, which is the site's promise that \"this\n * root's inline style is `blockStyleToCss(block.style)`\" — the same declarations `<BcmsBlocks>`\n * puts on its own wrapper. A root that stamps the block without applying its style would get a\n * capsule that paints the canvas and never ships, so the marker must travel with the style.\n *\n * The marker is present even when the style is EMPTY (then there is no `style` attribute at all):\n * an unstyled section is exactly the one an author is about to give its first spacing edit.\n */\nexport interface SectionRootBlock {\n id?: string | null;\n style?: BlockStyle | Record<string, unknown> | null;\n}\n\nexport interface SectionRootAttrs {\n \"data-bcms-block\"?: string;\n \"data-bcms-style\": \"\";\n /** `\"mobile tablet\"` when `style.hideOn` hides it there; the site ships `RESPONSIVE_CSS` for it. */\n \"data-bcms-hide\"?: string;\n /** `blockStyleToCss(block.style)` as a CSS string; absent when the block has no style. */\n style?: string;\n}\n\n/** `paddingTop` → `padding-top`, joined the way `<BcmsBlocks>` writes its wrapper's attribute. */\nfunction cssText(css: Record<string, string | number>): string {\n return Object.entries(css)\n .map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}:${v}`)\n .join(\";\");\n}\n\nexport function sectionRootAttrs(block: SectionRootBlock | null | undefined): SectionRootAttrs {\n const css = blockStyleToCss((block?.style ?? undefined) as BlockStyle | undefined);\n const id = typeof block?.id === \"string\" && block.id !== \"\" ? block.id : undefined;\n const hide = hideOnAttr(block?.style);\n return {\n ...(id !== undefined ? { \"data-bcms-block\": id } : {}),\n \"data-bcms-style\": \"\",\n ...(hide ? { \"data-bcms-hide\": hide } : {}),\n ...(css ? { style: cssText(css) } : {}),\n };\n}\n\nexport interface SectionColumnAttrs {\n \"data-bcms-column\": \"\";\n /** `blockStyleToColumnCss(block.style)` as a CSS string; absent when the section has no column. */\n style?: string;\n}\n\n/**\n * C3 — `sectionColumnAttrs(block)`: the attributes a site's own INNER container spreads so the\n * section's content WIDTH (`style.contentWidth`, placed by `contentAlign`) ships.\n *\n * <section {...sectionRootAttrs(block)}>\n * <div class=\"container\" {...sectionColumnAttrs(block)}>…</div>\n * </section>\n *\n * The width is the column BetterCMS draws as `.bcms-block-inner` inside the section's styled box —\n * never on the root itself, whose background must stay full-bleed. `data-bcms-column` is the\n * site's promise that this box's inline style is the column; the editor offers the width handle\n * on a site-rendered page only where every styled root holds one. Max-width plus left/right\n * margins, so the container keeps its own vertical margins and, with no column, its own width.\n */\nexport function sectionColumnAttrs(block: SectionRootBlock | null | undefined): SectionColumnAttrs {\n const css = blockStyleToColumnCss((block?.style ?? undefined) as BlockStyle | undefined);\n return { \"data-bcms-column\": \"\", ...(css ? { style: cssText(css) } : {}) };\n}\n\n/** The image facts a value or asset may carry beside its URL. */\ntype ImageFacts = { altText?: string | null; alt?: string | null; width?: number | null; height?: number | null; focalX?: number | null; focalY?: number | null };\n\nexport interface ImageOptions {\n /** The field this image renders, in the editor grammar (`cover`, `hero.image`). */\n path?: string;\n alt?: string;\n width?: number;\n height?: number;\n format?: ImageFormat;\n quality?: number;\n fit?: ImageFit;\n sizes?: string;\n loading?: \"lazy\" | \"eager\";\n /** Focal point override, 0–1. Normally omitted: the value and the asset carry their own. */\n focalX?: number | null;\n focalY?: number | null;\n /** Media host for a `src` that is only an asset id. Defaults to the platform's. */\n baseUrl?: string;\n}\n\n/** The widths a `sizes` image offers: phone to desktop, and never an upscale of the picture. */\nconst LADDER = [480, 768, 1080, 1440, 1920];\nconst num = (v: unknown): number | undefined => (typeof v === \"number\" && Number.isFinite(v) ? v : undefined);\n\n/**\n * What every `<BcmsImage>` renders, computed once for all of them: the transform URL, a srcset\n * (a WIDTH ladder with `sizes` and no `width`, else 1x/2x), the alt (the value's `altText` unless\n * `alt` says otherwise) and the style declarations, camel-cased. The value's crop and focal point\n * are applied by image-url itself; a source-relative focal is re-expressed inside the crop.\n */\nexport function imageCore(src: ImageSource | (Exclude<ImageSource, string> & ImageFacts), opts: ImageOptions = {}) {\n const { width, height, format = \"webp\", quality, fit, sizes, focalX, focalY, baseUrl } = opts;\n const asset = (typeof src === \"object\" && src !== null ? src : {}) as Record<string, unknown>;\n const explicit = focalX != null || focalY != null;\n const stored =\n normalizeImageFocal(asset.focal) ??\n (num(asset.focalX) != null || num(asset.focalY) != null ? { x: num(asset.focalX) ?? 0.5, y: num(asset.focalY) ?? 0.5 } : null);\n const inWindow = stored ? focalInCrop(stored, normalizeImageCrop(asset.crop)) : null;\n const fx = explicit ? focalX : inWindow?.x;\n const fy = explicit ? focalY : inWindow?.y;\n const hasFocal = fx != null || fy != null;\n const builder = imageUrlBuilder({ baseUrl });\n const make = () => {\n let b = builder(src as ImageSource);\n if (width) b = b.width(width);\n if (height) b = b.height(height);\n if (format) b = b.format(format);\n if (quality) b = b.quality(quality);\n if (fit) b = b.fit(fit);\n if (hasFocal) b = b.focal(fx ?? 0.5, fy ?? 0.5);\n return b;\n };\n const url = make().url();\n const own = num(asset.width);\n const ladder = own ? [...new Set([...LADDER.filter((w) => w < own), Math.min(own, LADDER[LADDER.length - 1]!)])] : LADDER;\n const srcset = sizes && !width ? ladder.map((w) => `${make().width(w).url()} ${w}w`).join(\", \") : `${url} 1x, ${make().dpr(2).url()} 2x`;\n // A pixel width is the author's size for THIS image, so it also goes on as a style (a site rule\n // like `img { width: 100% }` beats a bare attribute), capped at the column it sits in. The focal\n // point rides as object-position, inert unless the site's CSS sets object-fit.\n const css: Record<string, string> = {\n ...(width ? { width: `${width}px`, maxWidth: \"100%\", height: \"auto\" } : {}),\n ...(hasFocal ? { objectPosition: objectPosition({ x: fx, y: fy }) } : {}),\n };\n const alt = opts.alt ?? (typeof asset.altText === \"string\" ? asset.altText : typeof asset.alt === \"string\" ? asset.alt : \"\");\n return { src: url, srcset, alt, css };\n}\n\nexport interface ImageAttrs {\n src: string;\n srcset: string;\n alt: string;\n loading: \"lazy\" | \"eager\";\n sizes?: string;\n width?: number;\n height?: number;\n style?: string;\n \"data-bcms-field\"?: string;\n \"data-bcms-kind\"?: \"image\";\n}\n\n/**\n * The `<img>` attributes for an image value, the same markup as every `<BcmsImage>`. Given `path`,\n * the image declares its field, so the editor binds it and a publish writes the new picture in:\n *\n * <img {...imageAttrs(page.hero.image, { path: \"hero.image\", sizes: \"100vw\" })} class=\"hero\" />\n */\nexport function imageAttrs(src: Parameters<typeof imageCore>[0], opts: ImageOptions = {}): ImageAttrs {\n const { src: url, srcset, alt, css } = imageCore(src, opts);\n const style = cssText(css);\n return {\n src: url,\n srcset,\n alt,\n loading: opts.loading ?? \"lazy\",\n ...(opts.sizes ? { sizes: opts.sizes } : {}),\n ...(opts.width ? { width: opts.width } : {}),\n ...(opts.height ? { height: opts.height } : {}),\n ...(style ? { style } : {}),\n ...(opts.path ? { \"data-bcms-field\": opts.path, \"data-bcms-kind\": \"image\" as const } : {}),\n };\n}\n"],"mappings":";AAWA,OAAO;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,uBAAuB,iBAAiB,mBAAmB,kBAAsE;AA2BnI,SAAS,aAAa,MAAc,aAA+F;AACxI,MAAI,CAAC,eAAe,OAAO,gBAAgB,YAAY,CAAC,OAAO,UAAU,eAAe,KAAK,aAAa,IAAI,EAAG,QAAO;AACxH,QAAM,QAAS,YAAwC,IAAI;AAC3D,SAAO,SAAS,OAAO,UAAU,WAAY,QAAuB;AACtE;AAEO,SAAS,WAAW,MAAc,aAAwE;AAC/G,QAAM,QAAQ,kBAAkB,aAAa,MAAM,WAAW,CAAC;AAC/D,SAAO,EAAE,mBAAmB,MAAM,mBAAmB,KAAK,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC,EAAG;AACxF;AAoBA,SAAS,UAAU,OAAgC;AACjD,QAAM,KAAK,OAAO,UAAU,WAAW,QAAQ,OAAO;AACtD,SAAO,OAAO,OAAO,YAAY,GAAG,KAAK,MAAM,KAAK,KAAK;AAC3D;AAGO,SAAS,WAAW,OAAiD;AAC1E,QAAM,KAAK,UAAU,KAAK;AAC1B,SAAO,KAAK,EAAE,mBAAmB,GAAG,IAAI,CAAC;AAC3C;AAEO,SAAS,WAAW,OAAiB,MAAc,MAAwD;AAChH,QAAM,KAAK,UAAU,KAAK;AAC1B,MAAI,OAAO,SAAS,YAAY,KAAK,KAAK,MAAM,GAAI,OAAM,IAAI,MA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the BetterCMS editor binds it: a page field, a\n * collection entry, a section root and its content column. Plain objects of string attributes\n * (the style is a CSS string), so they spread as they are in every template language:\n *\n * Astro / Svelte <h1 {...fieldAttrs(\"hero-title\", page.fieldStyles)}>…</h1>\n * Vue <h1 v-bind=\"fieldAttrs('hero-title', page.fieldStyles)\">…</h1>\n *\n * @bettercms-ai/astro, /sveltekit and /nuxt re-export these; @bettercms-ai/next keeps twins whose\n * `style` is a React style object.\n */\nimport imageUrlBuilder, {\n focalInCrop,\n normalizeImageCrop,\n normalizeImageFocal,\n objectPosition,\n type ImageFit,\n type ImageFormat,\n type ImageSource,\n} from \"@bettercms-ai/image-url\";\nimport { blockStyleToColumnCss, blockStyleToCss, fieldStyleCssText, hideOnAttr, sectionIdentityAttrs, type BlockStyle, type FieldStyle, type FieldStyles } from \"@bettercms-ai/types\";\n\n/**\n * C3 — `fieldAttrs(path, fieldStyles)`: the attributes a site's OWN element spreads to bind a PAGE\n * FIELD and apply that field's stored style, so the BetterCMS editor offers its width and spacing\n * handles and its Align / Size / Weight controls.\n *\n * ---\n * const page = await loadPage(Astro, \"home\");\n * ---\n * <h1 class=\"title\" {...fieldAttrs(\"hero-title\", page?.fieldStyles)}>{entry.data[\"hero-title\"]}</h1>\n *\n * `data-bcms-style` is the site's promise that \"this element's inline style is\n * `fieldStyleToCss(fieldStyles[path])`\". The editor offers a field's handles only on an element that\n * carries it: a handle on one that does not would paint the canvas and never ship. The marker is\n * present even when the field has no style (then there is no `style` attribute at all, byte for\n * byte the element it was): an unstyled field is the one an author is about to give its first edit.\n */\nexport interface FieldAttrs {\n \"data-bcms-field\": string;\n /** The marker's revision: \"2\" promises `size` (zoom) too. Section roots keep \"\". */\n \"data-bcms-style\": \"2\";\n /** `fieldStyleToCss(fieldStyles[path])` as a CSS string; absent when the field has no style. */\n style?: string;\n}\n\n/** The stored style for `path`, by OWN key only — a path like `constructor` never reads the prototype. */\nexport function fieldStyleOf(path: string, fieldStyles: FieldStyles | Record<string, unknown> | null | undefined): FieldStyle | undefined {\n if (!fieldStyles || typeof fieldStyles !== \"object\" || !Object.prototype.hasOwnProperty.call(fieldStyles, path)) return undefined;\n const style = (fieldStyles as Record<string, unknown>)[path];\n return style && typeof style === \"object\" ? (style as FieldStyle) : undefined;\n}\n\nexport function fieldAttrs(path: string, fieldStyles?: FieldStyles | Record<string, unknown> | null): FieldAttrs {\n const style = fieldStyleCssText(fieldStyleOf(path, fieldStyles));\n return { \"data-bcms-field\": path, \"data-bcms-style\": \"2\", ...(style ? { style } : {}) };\n}\n\n/**\n * P7 — `entryAttrs(entry)` and `entryField(entry, path)`: the attributes a site's OWN card spreads to\n * declare a collection ENTRY, so the editor binds it without guessing from the rendered text.\n *\n * <article {...entryAttrs(post)}><h3 {...entryField(post, \"title\")}>{post.fields.title}</h3></article>\n *\n * The field address is ABSOLUTE (`entry:<id>:<path>`). With a `transform` the value is shown\n * changed (a date formatted, text truncated), so it is declared as `data-bcms-entry-from`: the\n * editor knows where it is but cannot re-render it.\n */\nexport type EntryRef = { id?: string } | string;\nexport type EntryTransform = \"format\" | \"truncate\" | \"rendition\" | \"route\";\n/** One key is present: `data-bcms-entry-field`, or `data-bcms-entry-from` when transformed; none without an id. */\nexport interface EntryFieldAttrs {\n \"data-bcms-entry-field\"?: string;\n \"data-bcms-entry-from\"?: string;\n}\n\nfunction entryIdOf(entry: EntryRef): string | null {\n const id = typeof entry === \"string\" ? entry : entry?.id;\n return typeof id === \"string\" && id.trim() !== \"\" ? id : null;\n}\n\n/** An entry with no id (a snapshot written before ids were kept) renders unbound, never fails the build. */\nexport function entryAttrs(entry: EntryRef): { \"data-bcms-entry\"?: string } {\n const id = entryIdOf(entry);\n return id ? { \"data-bcms-entry\": id } : {};\n}\n\nexport function entryField(entry: EntryRef, path: string, opts?: { transform?: EntryTransform }): EntryFieldAttrs {\n const id = entryIdOf(entry);\n if (typeof path !== \"string\" || path.trim() === \"\") throw new Error(`entryField: no field path given for entry ${id ?? \"(no id)\"}`);\n if (!id) return {};\n const address = `entry:${id}:${path}`;\n return opts?.transform ? { \"data-bcms-entry-from\": `${address}|${opts.transform}` } : { \"data-bcms-entry-field\": address };\n}\n\n/**\n * C3/C4 — `sectionRootAttrs(block)`: the attributes a site's OWN section root spreads so the\n * BetterCMS editor offers that section's spacing and style handles.\n *\n * <section class=\"hero\" {...sectionRootAttrs(block)}>…</section>\n *\n * The editor shows those handles on a site-rendered page only when EVERY root the site stamps\n * with `data-bcms-block` also carries `data-bcms-style`, which is the site's promise that \"this\n * root's inline style is `blockStyleToCss(block.style)`\" — the same declarations `<BcmsBlocks>`\n * puts on its own wrapper. A root that stamps the block without applying its style would get a\n * capsule that paints the canvas and never ships, so the marker must travel with the style.\n *\n * The marker is present even when the style is EMPTY (then there is no `style` attribute at all):\n * an unstyled section is exactly the one an author is about to give its first spacing edit.\n */\nexport interface SectionRootBlock {\n id?: string | null;\n style?: BlockStyle | Record<string, unknown> | null;\n}\n\nexport interface SectionRootAttrs {\n /**\n * The section's Anchor ID (`style.anchor`), present only when one is set, so a root with its own\n * `id` keeps it otherwise. The section's CSS class (`style.cssClass`) is NOT spread: it would\n * replace the root's own class. Read it with `sectionIdentityAttrs(block.style).className` and\n * join it into the root's class list.\n */\n id?: string;\n \"data-bcms-block\"?: string;\n \"data-bcms-style\": \"\";\n /** `\"mobile tablet\"` when `style.hideOn` hides it there; the site ships `RESPONSIVE_CSS` for it. */\n \"data-bcms-hide\"?: string;\n /** `blockStyleToCss(block.style)` as a CSS string; absent when the block has no style. */\n style?: string;\n}\n\n/** `paddingTop` → `padding-top`, joined the way `<BcmsBlocks>` writes its wrapper's attribute. */\nfunction cssText(css: Record<string, string | number>): string {\n return Object.entries(css)\n .map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}:${v}`)\n .join(\";\");\n}\n\nexport function sectionRootAttrs(block: SectionRootBlock | null | undefined): SectionRootAttrs {\n const css = blockStyleToCss((block?.style ?? undefined) as BlockStyle | undefined);\n const id = typeof block?.id === \"string\" && block.id !== \"\" ? block.id : undefined;\n const hide = hideOnAttr(block?.style);\n const anchor = sectionIdentityAttrs(block?.style).id;\n return {\n ...(anchor ? { id: anchor } : {}),\n ...(id !== undefined ? { \"data-bcms-block\": id } : {}),\n \"data-bcms-style\": \"\",\n ...(hide ? { \"data-bcms-hide\": hide } : {}),\n ...(css ? { style: cssText(css) } : {}),\n };\n}\n\nexport interface SectionColumnAttrs {\n \"data-bcms-column\": \"\";\n /** `blockStyleToColumnCss(block.style)` as a CSS string; absent when the section has no column. */\n style?: string;\n}\n\n/**\n * C3 — `sectionColumnAttrs(block)`: the attributes a site's own INNER container spreads so the\n * section's content WIDTH (`style.contentWidth`, placed by `contentAlign`) ships.\n *\n * <section {...sectionRootAttrs(block)}>\n * <div class=\"container\" {...sectionColumnAttrs(block)}>…</div>\n * </section>\n *\n * The width is the column BetterCMS draws as `.bcms-block-inner` inside the section's styled box —\n * never on the root itself, whose background must stay full-bleed. `data-bcms-column` is the\n * site's promise that this box's inline style is the column; the editor offers the width handle\n * on a site-rendered page only where every styled root holds one. Max-width plus left/right\n * margins, so the container keeps its own vertical margins and, with no column, its own width.\n */\nexport function sectionColumnAttrs(block: SectionRootBlock | null | undefined): SectionColumnAttrs {\n const css = blockStyleToColumnCss((block?.style ?? undefined) as BlockStyle | undefined);\n return { \"data-bcms-column\": \"\", ...(css ? { style: cssText(css) } : {}) };\n}\n\n/** The image facts a value or asset may carry beside its URL. */\ntype ImageFacts = { altText?: string | null; alt?: string | null; width?: number | null; height?: number | null; focalX?: number | null; focalY?: number | null };\n\nexport interface ImageOptions {\n /** The field this image renders, in the editor grammar (`cover`, `hero.image`). */\n path?: string;\n alt?: string;\n width?: number;\n height?: number;\n format?: ImageFormat;\n quality?: number;\n fit?: ImageFit;\n sizes?: string;\n loading?: \"lazy\" | \"eager\";\n /** Focal point override, 0–1. Normally omitted: the value and the asset carry their own. */\n focalX?: number | null;\n focalY?: number | null;\n /** Media host for a `src` that is only an asset id. Defaults to the platform's. */\n baseUrl?: string;\n}\n\n/** The widths a `sizes` image offers: phone to desktop, and never an upscale of the picture. */\nconst LADDER = [480, 768, 1080, 1440, 1920];\nconst num = (v: unknown): number | undefined => (typeof v === \"number\" && Number.isFinite(v) ? v : undefined);\n\n/**\n * What every `<BcmsImage>` renders, computed once for all of them: the transform URL, a srcset\n * (a WIDTH ladder with `sizes` and no `width`, else 1x/2x), the alt (the value's `altText` unless\n * `alt` says otherwise) and the style declarations, camel-cased. The value's crop and focal point\n * are applied by image-url itself; a source-relative focal is re-expressed inside the crop.\n */\nexport function imageCore(src: ImageSource | (Exclude<ImageSource, string> & ImageFacts), opts: ImageOptions = {}) {\n const { width, height, format = \"webp\", quality, fit, sizes, focalX, focalY, baseUrl } = opts;\n const asset = (typeof src === \"object\" && src !== null ? src : {}) as Record<string, unknown>;\n const explicit = focalX != null || focalY != null;\n const stored =\n normalizeImageFocal(asset.focal) ??\n (num(asset.focalX) != null || num(asset.focalY) != null ? { x: num(asset.focalX) ?? 0.5, y: num(asset.focalY) ?? 0.5 } : null);\n const inWindow = stored ? focalInCrop(stored, normalizeImageCrop(asset.crop)) : null;\n const fx = explicit ? focalX : inWindow?.x;\n const fy = explicit ? focalY : inWindow?.y;\n const hasFocal = fx != null || fy != null;\n const builder = imageUrlBuilder({ baseUrl });\n const make = () => {\n let b = builder(src as ImageSource);\n if (width) b = b.width(width);\n if (height) b = b.height(height);\n if (format) b = b.format(format);\n if (quality) b = b.quality(quality);\n if (fit) b = b.fit(fit);\n if (hasFocal) b = b.focal(fx ?? 0.5, fy ?? 0.5);\n return b;\n };\n const url = make().url();\n const own = num(asset.width);\n const ladder = own ? [...new Set([...LADDER.filter((w) => w < own), Math.min(own, LADDER[LADDER.length - 1]!)])] : LADDER;\n const srcset = sizes && !width ? ladder.map((w) => `${make().width(w).url()} ${w}w`).join(\", \") : `${url} 1x, ${make().dpr(2).url()} 2x`;\n // A pixel width is the author's size for THIS image, so it also goes on as a style (a site rule\n // like `img { width: 100% }` beats a bare attribute), capped at the column it sits in. The focal\n // point rides as object-position, inert unless the site's CSS sets object-fit.\n const css: Record<string, string> = {\n ...(width ? { width: `${width}px`, maxWidth: \"100%\", height: \"auto\" } : {}),\n ...(hasFocal ? { objectPosition: objectPosition({ x: fx, y: fy }) } : {}),\n };\n const alt = opts.alt ?? (typeof asset.altText === \"string\" ? asset.altText : typeof asset.alt === \"string\" ? asset.alt : \"\");\n return { src: url, srcset, alt, css };\n}\n\nexport interface ImageAttrs {\n src: string;\n srcset: string;\n alt: string;\n loading: \"lazy\" | \"eager\";\n sizes?: string;\n width?: number;\n height?: number;\n style?: string;\n \"data-bcms-field\"?: string;\n \"data-bcms-kind\"?: \"image\";\n}\n\n/**\n * The `<img>` attributes for an image value, the same markup as every `<BcmsImage>`. Given `path`,\n * the image declares its field, so the editor binds it and a publish writes the new picture in:\n *\n * <img {...imageAttrs(page.hero.image, { path: \"hero.image\", sizes: \"100vw\" })} class=\"hero\" />\n */\nexport function imageAttrs(src: Parameters<typeof imageCore>[0], opts: ImageOptions = {}): ImageAttrs {\n const { src: url, srcset, alt, css } = imageCore(src, opts);\n const style = cssText(css);\n return {\n src: url,\n srcset,\n alt,\n loading: opts.loading ?? \"lazy\",\n ...(opts.sizes ? { sizes: opts.sizes } : {}),\n ...(opts.width ? { width: opts.width } : {}),\n ...(opts.height ? { height: opts.height } : {}),\n ...(style ? { style } : {}),\n ...(opts.path ? { \"data-bcms-field\": opts.path, \"data-bcms-kind\": \"image\" as const } : {}),\n };\n}\n"],"mappings":";AAWA,OAAO;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,uBAAuB,iBAAiB,mBAAmB,YAAY,4BAAgF;AA2BzJ,SAAS,aAAa,MAAc,aAA+F;AACxI,MAAI,CAAC,eAAe,OAAO,gBAAgB,YAAY,CAAC,OAAO,UAAU,eAAe,KAAK,aAAa,IAAI,EAAG,QAAO;AACxH,QAAM,QAAS,YAAwC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M,MAAM;AACzH,SAAO,EAAE,KAAK,KAAK,QAAQ,KAAK,IAAI;AACtC;AAqBO,SAAS,WAAW,KAAsC,OAAqB,CAAC,GAAe;AACpG,QAAM,EAAE,KAAK,KAAK,QAAQ,KAAK,IAAI,IAAI,UAAU,KAAK,IAAI;AAC1D,QAAM,QAAQ,QAAQ,GAAG;AACzB,SAAO;AAAA,IACL,KAAK;AAAA,IACL;AAAA,IACA;AAAA,IACA,SAAS,KAAK,WAAW;AAAA,IACzB,GAAI,KAAK,QAAQ,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;AAAA,IAC1C,GAAI,KAAK,QAAQ,EAAE,OAAO,KAAK,MAAM,IAAI,CAAC;AAAA,IAC1C,GAAI,KAAK,SAAS,EAAE,QAAQ,KAAK,OAAO,IAAI,CAAC;AAAA,IAC7C,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;AAAA,IACzB,GAAI,KAAK,OAAO,EAAE,mBAAmB,KAAK,MAAM,kBAAkB,QAAiB,IAAI,CAAC;AAAA,EAC1F;AACF;","names":[]}
|
package/dist/index.cjs
CHANGED
|
@@ -2143,6 +2143,8 @@ async function submitForm(opts) {
|
|
|
2143
2143
|
const baseUrl = (opts.baseUrl ?? DEFAULT_BASE_URL5).replace(/\/+$/, "");
|
|
2144
2144
|
const doFetch = opts.fetchImpl ?? globalThis.fetch;
|
|
2145
2145
|
const body = { data: opts.data };
|
|
2146
|
+
const page = opts.page ?? globalThis.location?.pathname;
|
|
2147
|
+
if (page) body.page = page;
|
|
2146
2148
|
if (opts.turnstileToken) body["cf-turnstile-response"] = opts.turnstileToken;
|
|
2147
2149
|
let res;
|
|
2148
2150
|
try {
|