uhuu-components 0.2.97 → 0.3.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/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import type {
4
4
  CSSProperties,
5
5
  ImgHTMLAttributes,
6
6
  Key,
7
+ MouseEventHandler,
7
8
  ReactElement,
8
9
  ReactEventHandler,
9
10
  ReactNode,
@@ -222,8 +223,248 @@ export interface EditableProps {
222
223
  children?: ReactNode;
223
224
  }
224
225
 
226
+ /**
227
+ * Wraps its children in a `div` bound to `dialog`. The element is rendered even when the
228
+ * children are empty (null, false, whitespace): it is the click target. A bound, empty
229
+ * Editable carries `uhuu-text-empty`, which gets a one-line box in the editor.
230
+ * Template CSS controls print layout. Only text/textarea/markdown dialogs get the marker.
231
+ * Pass `null`, not a renderer element around an empty string.
232
+ */
225
233
  export const Editable: ComponentType<EditableProps>;
226
234
 
235
+ /** What `getDialogProps` returns. Spread it onto the element that renders the field. */
236
+ export interface DialogBindingProps {
237
+ /** Marks the element for the editor: `""`, or the serialised dialog under legacy dynamic pagination. */
238
+ "data-uhuu"?: string;
239
+ /** `dialog.type`, so CSS can tell an empty text binding from an empty image. */
240
+ "data-uhuu-type"?: string;
241
+ /** Opens the dialog in the interactive editor. Never set in renderer mode (`window.$uhuu_renderer`). */
242
+ onClick?: MouseEventHandler<HTMLElement>;
243
+ }
244
+
245
+ /**
246
+ * The props `Editable` and `ImageBlock` attach, for a template that binds its own element:
247
+ * `<p {...getDialogProps({ dialog: { path, type: "textarea", value } })}>`. Renderer mode gets
248
+ * the markers without a click handler. No dialog returns `{}`. Never returns `className`.
249
+ */
250
+ export function getDialogProps(props: { dialog?: object | null } | null | undefined): DialogBindingProps;
251
+
252
+ // --- Image URLs (src/uhuu/image/image-url.js). See docs/image-url.md. ---
253
+
254
+ /** An image as payloads store it: an ImageObject, the dialogs' legacy `{ url }`, a URL, or nothing. */
255
+ export type ImageSource =
256
+ | string
257
+ | {
258
+ contentUrl?: string;
259
+ url?: string;
260
+ src?: string;
261
+ encodingFormat?: string;
262
+ mimeType?: string;
263
+ [key: string]: unknown;
264
+ }
265
+ | null
266
+ | undefined;
267
+
268
+ export interface ImageUrlOptions {
269
+ /** Print-product sizing. Default: the host's `$uhuu.is.printProduct()` (false without a host). */
270
+ print?: boolean;
271
+ /** Screen size as `WxH`. Default `2000x2000`. */
272
+ size?: string;
273
+ /** Print size as `WxH`. Default `4000x4000`. */
274
+ printSize?: string;
275
+ /** Thumbnail output format, e.g. `image/jpeg`. Default: the source's own (keeps transparency). */
276
+ format?: string;
277
+ }
278
+
279
+ /**
280
+ * The thumbnailer URL to render an image at: print-aware size, encoded source URL, SVG/`data:`/
281
+ * relative sources passed through, already-thumbnailed URLs rebuilt rather than nested.
282
+ * No image returns `undefined`, which renders no `src` attribute.
283
+ */
284
+ export function imageUrl(src: ImageSource, options?: ImageUrlOptions): string | undefined;
285
+
286
+ // --- Brand-kit runtime (src/uhuu/brand-kit/). See docs/brand-kit-runtime.md. ---
287
+
288
+ export interface BrandKitFontFile {
289
+ src: string;
290
+ weight?: number | string;
291
+ style?: "normal" | "italic";
292
+ format?: string;
293
+ }
294
+
295
+ export interface BrandKitFont {
296
+ id?: string;
297
+ family?: string;
298
+ /** Role-keyed fonts (`fonts.body`, `fonts.heading`): the stack after `family`. */
299
+ fallback?: string;
300
+ source?: string;
301
+ provider?: string;
302
+ cssUrl?: string;
303
+ weights?: number[];
304
+ styles?: Array<"normal" | "italic">;
305
+ files?: BrandKitFontFile[];
306
+ faces?: Array<{
307
+ weight?: number;
308
+ style?: "normal" | "italic";
309
+ cssUrl?: string;
310
+ files?: BrandKitFontFile[] | Record<string, string>;
311
+ [key: string]: unknown;
312
+ }>;
313
+ [key: string]: unknown;
314
+ }
315
+
316
+ /** A brandkit.json document. Only the parts the runtime reads are typed. */
317
+ export interface BrandKitJson {
318
+ version?: string | number;
319
+ id?: string;
320
+ name?: string;
321
+ baseUrl?: string;
322
+ assignments?: Record<string, string>;
323
+ fonts?: Record<string, BrandKitFont> | BrandKitFont[];
324
+ tokens?: {
325
+ light?: {
326
+ semantic?: Record<string, string | undefined>;
327
+ aliases?: Record<string, string | Record<string, string | undefined> | undefined>;
328
+ };
329
+ primitives?: { typography?: Record<string, unknown>; [key: string]: unknown };
330
+ [token: string]: unknown;
331
+ };
332
+ colorMode?: "light" | "manual" | "shade";
333
+ /** Template variables Brand Kit precomputed at publish. Applied as is when `version` is 2. */
334
+ runtime?: BrandKitRuntimeBlock;
335
+ [key: string]: unknown;
336
+ }
337
+
338
+ /**
339
+ * `brandkit.json.runtime` (brandkit.json "2.0"): shadcn role variables (`--primary`, `--color-primary`),
340
+ * `--color-kit-*` / `--font-*` / `--font-kit-*` values, ready to apply, and the fonts to load.
341
+ */
342
+ export interface BrandKitRuntimeBlock {
343
+ version: 2;
344
+ light: Record<string, string>;
345
+ fontStylesheets?: string[];
346
+ fontFaces?: Array<{ family: string; src: string; weight?: number; style?: "normal" | "italic"; format?: string }>;
347
+ }
348
+
349
+ export interface BrandKitLogo {
350
+ /** Absolute URL (SVG preferred, else PNG). */
351
+ src: string;
352
+ alt?: string;
353
+ kind: "primary" | "mark" | "wordmark";
354
+ background?: "light" | "dark" | "any";
355
+ minWidth?: { value: number; unit: "px" | "mm" };
356
+ clearSpace?: { value: number; unit: "px" | "mm" | "mark" };
357
+ }
358
+
359
+ export interface BrandKitCollectionItem {
360
+ key: string;
361
+ /** Absolute URL. */
362
+ src: string;
363
+ label?: string;
364
+ name?: string;
365
+ type?: string;
366
+ mimeType?: string;
367
+ tags?: string[];
368
+ [key: string]: unknown;
369
+ }
370
+
371
+ export interface BrandKitCollection {
372
+ id: string;
373
+ name?: string;
374
+ type?: string;
375
+ versionId?: string;
376
+ items: BrandKitCollectionItem[];
377
+ }
378
+
379
+ export interface BrandKitMapStyle {
380
+ url: string;
381
+ name?: string;
382
+ source: "config.maps" | "config.env";
383
+ }
384
+
385
+ export type BrandKitLogoKind = "primary" | "logo" | "lockup" | "mark" | "icon" | "symbol" | "wordmark";
386
+ export type BrandKitMediaKind = "photos" | "icons" | "graphics" | "backgrounds" | "templates";
387
+
388
+ /** What `useBrandKit()` returns. */
389
+ export interface BrandKitRuntime {
390
+ /** The kit being rendered: the fetched one, else the `brandKit` prop. */
391
+ brandKit: BrandKitJson | null;
392
+ /** `--<role>`, `--color-<role>`, `--color-kit-*`, `--font-*` and `--font-kit-*`, as the provider's scope element carries them. */
393
+ cssVars: Record<string, string>;
394
+ /** Where the rendered kit came from (`src` once fetched, else the `sourceUrl` prop). */
395
+ sourceUrl?: string;
396
+ /** `idle` without `src`; `loading` until it arrives; `ready`; `error` (the `brandKit` prop renders). */
397
+ status: "idle" | "loading" | "ready" | "error";
398
+ /** A logo, resolved: `logoSystem` first, then `logos`. Default `{ kind: "primary", background: "light" }`. */
399
+ logo(options?: { kind?: BrandKitLogoKind; background?: "light" | "dark" }): BrandKitLogo | null;
400
+ /** The assigned media collection's promoted version, items resolved. */
401
+ collection(kind: BrandKitMediaKind | string, options?: { versionId?: string }): BrandKitCollection | null;
402
+ mapStyle(mode: "micro" | "macro"): BrandKitMapStyle | null;
403
+ /** A `config.env` value; keys compare case- and punctuation-insensitively, first present wins. */
404
+ env(keys: string | string[]): string | undefined;
405
+ /** A kit-relative asset path made absolute. */
406
+ resolveUrl(path: unknown): string | undefined;
407
+ }
408
+
409
+ export interface BrandKitProviderProps {
410
+ /** The kit to render; with `src`, the fallback until the fetched kit arrives or when the fetch fails. */
411
+ brandKit?: BrandKitJson | null;
412
+ /** A brandkit.json URL to fetch, usually `brandKitSourceUrl(payload)`. */
413
+ src?: string | null;
414
+ /** Custom properties for whatever the kit leaves out; the kit wins. Pass a stable object. */
415
+ defaults?: Record<string, string>;
416
+ /** Where a `brandKit` passed in came from; its directory resolves relative URLs when the kit has no `baseUrl`. */
417
+ sourceUrl?: string;
418
+ onLoad?: (brandKit: BrandKitJson) => void;
419
+ /** Default: `console.error`. */
420
+ onError?: (error: unknown) => void;
421
+ /** For the scope element. `style` is applied last, so `{ display: "block" }` gives it a box. */
422
+ className?: string;
423
+ style?: CSSProperties;
424
+ children?: ReactNode;
425
+ }
426
+
427
+ /**
428
+ * Scopes a kit's CSS variables around the pages and their overlay chrome, on a `display: contents`
429
+ * element (`data-uhuu-brand-kit-status` tells a print step when a fetched kit has arrived), and
430
+ * loads the fonts the kit declares. Colours are hex, `rgb()`/`rgba()`, `oklch()`/`oklab()` or
431
+ * keywords: HSL is converted, anything else is skipped as if absent.
432
+ */
433
+ export const BrandKitProvider: ComponentType<BrandKitProviderProps>;
434
+
435
+ /** The nearest `BrandKitProvider`'s runtime, or `null` outside one. */
436
+ export function useBrandKit(): BrandKitRuntime | null;
437
+
438
+ /** Brand Kit's production location for published kits. */
439
+ export const BRAND_KIT_PUBLIC_BASE_URL: string;
440
+
441
+ /**
442
+ * The brandkit.json URL a payload points at: `brandKitUrl` (URL or `kit-…` id), `brandKitId`, or
443
+ * `brandKit.storage.publicUrl`. Ids need `brandKitTeamId` (or `teamId`) and resolve under `publicBaseUrl`.
444
+ */
445
+ export function brandKitSourceUrl(
446
+ payload: Record<string, unknown> | null | undefined,
447
+ options?: { publicBaseUrl?: string; teamId?: string | number },
448
+ ): string | null;
449
+
450
+ /** Fetches a brandkit.json; rejects on network errors, non-2xx and non-object bodies. */
451
+ export function loadBrandKit(url: string, options?: { fetch?: typeof fetch; signal?: AbortSignal }): Promise<BrandKitJson>;
452
+
453
+ export function brandKitLogo(
454
+ brandKit: BrandKitJson | null | undefined,
455
+ options?: { kind?: BrandKitLogoKind; background?: "light" | "dark"; sourceUrl?: string },
456
+ ): BrandKitLogo | null;
457
+
458
+ export function brandKitCollection(
459
+ brandKit: BrandKitJson | null | undefined,
460
+ kind: BrandKitMediaKind | string,
461
+ options?: { sourceUrl?: string; versionId?: string },
462
+ ): BrandKitCollection | null;
463
+
464
+ export function brandKitMapStyle(brandKit: BrandKitJson | null | undefined, mode: "micro" | "macro"): BrandKitMapStyle | null;
465
+
466
+ export function brandKitEnv(brandKit: BrandKitJson | null | undefined, keys: string | string[]): string | undefined;
467
+
227
468
  export interface InteractiveModeContextValue {
228
469
  interactive: boolean;
229
470
  setInteractive: (interactive: boolean) => void;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.97",
2
+ "version": "0.3.0",
3
3
  "name": "uhuu-components",
4
4
  "main": "uhuu-components.umd.cjs",
5
5
  "module": "uhuu-components.es.js",