@histoire/plugin-designs 0.0.0-stage → 1.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ import type { EmbedDesignType } from '../types.js';
2
+ /**
3
+ * URL loaded in the iframe of an embedded design, or `undefined` for a Figma page that cannot
4
+ * be embedded. Penpot view links and plain iframes embed as they are.
5
+ * @param type Embedded design type.
6
+ * @param url Validated design link.
7
+ * @param embedHost Figma `embed-host` value.
8
+ */
9
+ export declare function toEmbedUrl(type: EmbedDesignType, url: URL, embedHost: string): string | undefined;
@@ -0,0 +1,11 @@
1
+ import type { ResolvedEmbedDesign } from '../types.js';
2
+ /**
3
+ * Iframe attributes of an embedded design, shared by the inspector tab and canvas view.
4
+ * Design tools run scripts and need their own origin (cookies for sign-in, live viewer); that
5
+ * origin is distinct from the workbench, so they still cannot reach it nor navigate it. A
6
+ * design served from the workbench origin keeps an opaque origin instead: with both
7
+ * `allow-scripts` and `allow-same-origin`, it could script the workbench and lift its sandbox.
8
+ * @param design Embedded design.
9
+ * @param origin Workbench origin; defaults to the current document's.
10
+ */
11
+ export declare function iframeAttributes(design: ResolvedEmbedDesign, origin?: string | undefined): Record<string, string>;
@@ -0,0 +1,30 @@
1
+ import type { HistoireCatalogStory } from '@histoire/protocol';
2
+ import type { DesignIssue, ResolvedDesign } from '../types.js';
3
+ /** Settings of design resolution. */
4
+ export interface ResolveOptions {
5
+ /** Figma `embed-host` value. */
6
+ embedHost: string;
7
+ /** Absolute URL of the book base; relative image paths resolve against it. */
8
+ baseUrl: string;
9
+ }
10
+ /** Designs of one variant plus entries that cannot be shown. */
11
+ export interface ResolvedDesigns {
12
+ /** Valid designs in declaration order. */
13
+ designs: ResolvedDesign[];
14
+ /** Invalid entries. */
15
+ issues: DesignIssue[];
16
+ /** Why the story could not be loaded; both lists are empty then. */
17
+ error?: string;
18
+ }
19
+ /**
20
+ * User-facing line of an invalid entry, shared by the inspector tab and canvas view.
21
+ * @param issue Invalid entry.
22
+ */
23
+ export declare function formatIssue(issue: DesignIssue): string;
24
+ /**
25
+ * Designs declared for one variant through `meta.design` (single entry or list).
26
+ * @param story Catalog story.
27
+ * @param variantId Variant id.
28
+ * @param options Resolution settings.
29
+ */
30
+ export declare function resolveDesigns(story: HistoireCatalogStory, variantId: string, options: ResolveOptions): ResolvedDesigns;
@@ -0,0 +1,9 @@
1
+ import type { Plugin } from '@histoire/shared';
2
+ import type { DesignsOptions } from './options.js';
3
+ export type { DesignsOptions } from './options.js';
4
+ export type { DesignInput, EmbedDesignInput, EmbedDesignType, ImageDesignInput, LinkDesignInput } from './types.js';
5
+ /**
6
+ * Show designs declared in story and variant `meta.design` next to the rendered variant.
7
+ * @param options Plugin options.
8
+ */
9
+ export declare function HstDesigns(options?: DesignsOptions): Plugin;
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ import { fileURLToPath } from 'node:url';
2
+ import { normalizeOptions } from './options.js';
3
+ /**
4
+ * Show designs declared in story and variant `meta.design` next to the rendered variant.
5
+ * @param options Plugin options.
6
+ */
7
+ export function HstDesigns(options = {}) {
8
+ const browser = normalizeOptions(options);
9
+ return {
10
+ name: '@histoire/plugin-designs',
11
+ metadata: { displayName: 'Designs', description: 'Figma, Penpot, Sketch and image designs next to stories', icon: 'color-palette', docsUrl: 'https://histoire.dev/guide/plugins/designs.html', repoUrl: 'https://github.com/histoire-dev/histoire/tree/main/packages/histoire-plugin-designs' },
12
+ workbench: options.enabled === false
13
+ ? undefined
14
+ : {
15
+ id: 'designs',
16
+ apiVersion: 1,
17
+ client: fileURLToPath(new URL('./client.js', import.meta.url)),
18
+ options: browser,
19
+ devOnly: options.devOnly ?? false,
20
+ },
21
+ };
22
+ }
@@ -0,0 +1,23 @@
1
+ /** Configuration of HstDesigns. */
2
+ export interface DesignsOptions {
3
+ /** Enable the plugin; defaults to true. */
4
+ enabled?: boolean;
5
+ /** Exclude the plugin from static books; defaults to false. */
6
+ devOnly?: boolean;
7
+ /** Site name sent to Figma as `embed-host`; defaults to `histoire`. */
8
+ embedHost?: string;
9
+ /** Add the Design canvas arrangement showing the variant next to its design; defaults to true. */
10
+ canvasView?: boolean;
11
+ }
12
+ /** Serializable settings shared with the workbench module. */
13
+ export interface BrowserOptions {
14
+ /** Figma `embed-host` value. */
15
+ embedHost: string;
16
+ /** Register the Design canvas arrangement. */
17
+ canvasView: boolean;
18
+ }
19
+ /**
20
+ * Applies defaults and validates user options.
21
+ * @param options User options.
22
+ */
23
+ export declare function normalizeOptions(options: DesignsOptions): BrowserOptions;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Applies defaults and validates user options.
3
+ * @param options User options.
4
+ */
5
+ export function normalizeOptions(options) {
6
+ const embedHost = options.embedHost ?? 'histoire';
7
+ if (typeof embedHost !== 'string' || !embedHost.trim())
8
+ throw new TypeError('[@histoire/plugin-designs] embedHost must be a non-empty string');
9
+ return { embedHost: embedHost.trim(), canvasView: options.canvasView ?? true };
10
+ }
@@ -0,0 +1,90 @@
1
+ /** Design types shown in an iframe. */
2
+ export type EmbedDesignType = 'figma' | 'penpot' | 'sketch' | 'iframe';
3
+ /** Fields shared by every design entry. */
4
+ interface DesignBase {
5
+ /** Link to the design; `http(s)`, or a path relative to the book base for images. */
6
+ url: string;
7
+ /** Label in the design switcher; defaults to the design tool or host name. */
8
+ name?: string;
9
+ }
10
+ /** Design shown in an iframe: Figma, Penpot or Sketch link, or any embeddable page. */
11
+ export interface EmbedDesignInput extends DesignBase {
12
+ /** Embed type. */
13
+ type: EmbedDesignType;
14
+ /** Let the embedded page go fullscreen. */
15
+ allowFullscreen?: boolean;
16
+ }
17
+ /** Static image with zoom and pan. */
18
+ export interface ImageDesignInput extends DesignBase {
19
+ /** Image design. */
20
+ type: 'image';
21
+ /** Initial zoom factor, greater than 0; defaults to fitting the image. */
22
+ scale?: number;
23
+ /** Initial offset in pixels; positive `x` moves right, positive `y` moves down. */
24
+ offset?: [number, number];
25
+ /** Alternative text. */
26
+ alt?: string;
27
+ }
28
+ /** Design that only opens in a new browser tab. */
29
+ export interface LinkDesignInput extends DesignBase {
30
+ /** Link design. */
31
+ type: 'link';
32
+ /** Link text; defaults to `name` or the host name. */
33
+ label?: string;
34
+ }
35
+ /** One design entry of `meta.design`. */
36
+ export type DesignInput = EmbedDesignInput | ImageDesignInput | LinkDesignInput;
37
+ /** Fields shared by every validated design. */
38
+ interface ResolvedBase {
39
+ /** Position in the entry list, stable while metadata is unchanged. */
40
+ index: number;
41
+ /** Switcher label. */
42
+ name: string;
43
+ /** Link opened in a new tab. */
44
+ externalUrl: string;
45
+ }
46
+ /** Validated iframe design. */
47
+ export interface ResolvedEmbedDesign extends ResolvedBase {
48
+ /** Embed type. */
49
+ type: EmbedDesignType;
50
+ /** Iframe URL. */
51
+ src: string;
52
+ /** Fullscreen permission. */
53
+ allowFullscreen: boolean;
54
+ }
55
+ /** Validated image design. */
56
+ export interface ResolvedImageDesign extends ResolvedBase {
57
+ /** Image design. */
58
+ type: 'image';
59
+ /** Absolute image URL. */
60
+ src: string;
61
+ /** Initial zoom; fit when absent. */
62
+ scale?: number;
63
+ /** Initial offset in pixels. */
64
+ offset?: [number, number];
65
+ /** Alternative text. */
66
+ alt: string;
67
+ }
68
+ /** Validated link design. */
69
+ export interface ResolvedLinkDesign extends ResolvedBase {
70
+ /** Link design. */
71
+ type: 'link';
72
+ /** Link text. */
73
+ label: string;
74
+ }
75
+ /** Validated design ready to render. */
76
+ export type ResolvedDesign = ResolvedEmbedDesign | ResolvedImageDesign | ResolvedLinkDesign;
77
+ /** Entry of `meta.design` that cannot be shown. */
78
+ export interface DesignIssue {
79
+ /** Position in the entry list. */
80
+ index: number;
81
+ /** User-facing reason. */
82
+ message: string;
83
+ }
84
+ declare module '@histoire/shared' {
85
+ interface CommonMeta {
86
+ /** Designs shown by `@histoire/plugin-designs`; a variant's list replaces its story's. */
87
+ design?: DesignInput | DesignInput[];
88
+ }
89
+ }
90
+ export {};
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ import type { ResolvedDesign } from '../types.js';
2
+ type __VLS_Props = {
3
+ /** Design to show. */
4
+ design: ResolvedDesign;
5
+ };
6
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
@@ -0,0 +1,11 @@
1
+ import type { FrameScopedContext } from '@histoire/plugin-kit';
2
+ import type { DesignModel } from './model.js';
3
+ type __VLS_Props = {
4
+ /** Frame scope supplied by the host. */
5
+ context: FrameScopedContext;
6
+ /** Shared design model. */
7
+ model: DesignModel;
8
+ };
9
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
+ declare const _default: typeof __VLS_export;
11
+ export default _default;
@@ -0,0 +1,8 @@
1
+ import type { ResolvedEmbedDesign } from '../types.js';
2
+ type __VLS_Props = {
3
+ /** Embedded design to show. */
4
+ design: ResolvedEmbedDesign;
5
+ };
6
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import type { OverlayState } from './overlay-state.js';
2
+ type __VLS_Props = {
3
+ /** Comparison mode and opacity shared with the canvas view. */
4
+ overlay: OverlayState;
5
+ };
6
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
7
+ reset: () => any;
8
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
9
+ onReset?: (() => any) | undefined;
10
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
11
+ declare const _default: typeof __VLS_export;
12
+ export default _default;
@@ -0,0 +1,43 @@
1
+ import type { ResolvedDesign } from '../../types.js';
2
+ /** Canvas-space size of a design box. */
3
+ export interface BoxSize {
4
+ /** Width in canvas units. */
5
+ width: number;
6
+ /** Height in canvas units. */
7
+ height: number;
8
+ }
9
+ /** Callbacks of image designs, which settle after the element is placed. */
10
+ export interface DesignElementEvents {
11
+ /** Receives the final box size once an image with an intrinsic size loads. */
12
+ onSize: (size: BoxSize) => void;
13
+ /** Called when an image fails to load; the box keeps its default size. */
14
+ onError: () => void;
15
+ }
16
+ /** Default box of iframes, of images before they load and of images without intrinsic size. */
17
+ export declare const EMBED_SIZE: BoxSize;
18
+ /**
19
+ * Creates an element with a class and optional text.
20
+ * @param tag Tag name.
21
+ * @param className Class attribute.
22
+ * @param text Text content.
23
+ */
24
+ export declare function element<K extends keyof HTMLElementTagNameMap>(tag: K, className: string, text?: string): HTMLElementTagNameMap[K];
25
+ /**
26
+ * Renders one design for the canvas. Images report their natural size (times the declared
27
+ * scale) once loaded so the view can size its box and re-fit. The image `offset` is ignored
28
+ * here: the canvas is panned by the user, so it only applies to the inspector viewer.
29
+ * @param design Design to render.
30
+ * @param events Image load callbacks.
31
+ */
32
+ export declare function createDesignElement(design: ResolvedDesign, events: DesignElementEvents): {
33
+ node: HTMLElement;
34
+ size: BoxSize;
35
+ };
36
+ /**
37
+ * Lays an embedded document out at its native size and scales it into a box, so resizing an
38
+ * overlay zooms the embed instead of reflowing it. Without a box, the embed fills its parent.
39
+ * @param node Rendered design element; only iframes are scaled.
40
+ * @param native Native box size of the design.
41
+ * @param box Target size in canvas units.
42
+ */
43
+ export declare function scaleEmbed(node: Element | null, native: BoxSize, box?: BoxSize): void;
@@ -0,0 +1,18 @@
1
+ import type { ResolvedDesign } from '../../types.js';
2
+ /** Canvas label above the design box, with a switch when several designs are declared. */
3
+ export interface DesignLabel {
4
+ /** Label element, placed once in the design column. */
5
+ node: HTMLElement;
6
+ /**
7
+ * Shows the name of a single design, or one switch button per design.
8
+ * @param designs Valid designs of the selected variant.
9
+ * @param activeIndex Entry index of the active design.
10
+ */
11
+ render: (designs: ResolvedDesign[], activeIndex: number) => void;
12
+ }
13
+ /**
14
+ * Creates the design label. Switch buttons are reused across renders, only their text and
15
+ * pressed state change, so keyboard focus survives clicks and model notifications.
16
+ * @param onSelect Receives the entry index (`ResolvedDesign.index`) of a clicked design.
17
+ */
18
+ export declare function createDesignLabel(onSelect: (entryIndex: number) => void): DesignLabel;
@@ -0,0 +1,14 @@
1
+ import type { OverlayState } from './overlay-state.js';
2
+ /** Floating comparison bar at the bottom of the canvas view. */
3
+ export interface ModeBar {
4
+ /** Bar element, placed once in the view root outside the pan and zoom layer. */
5
+ node: HTMLElement;
6
+ /** Unmounts the bar's Vue app. */
7
+ dispose: () => void;
8
+ }
9
+ /**
10
+ * Mounts the comparison bar in its own Vue app: the canvas view itself is a DOM view.
11
+ * @param overlay Comparison mode and opacity.
12
+ * @param onReset Restores the default placement of the shown design.
13
+ */
14
+ export declare function createModeBar(overlay: OverlayState, onReset: () => void): ModeBar;
@@ -0,0 +1,29 @@
1
+ import type { CanvasMode, OverlayPlacement } from './overlay-geometry.js';
2
+ /** Callbacks wiring the chrome to the canvas view. */
3
+ export interface OverlayChromeEvents {
4
+ /** Current canvas zoom; converts pointer deltas into canvas units. */
5
+ zoom: () => number;
6
+ /** Placement at gesture start. */
7
+ current: () => OverlayPlacement | undefined;
8
+ /** Live placement while a gesture runs. */
9
+ onChange: (placement: OverlayPlacement) => void;
10
+ /** Final placement once a gesture or key nudge ends; the view stores it. */
11
+ onCommit: (placement: OverlayPlacement) => void;
12
+ }
13
+ /** Outline, move and resize grips and split divider over a laid-over design. */
14
+ export interface OverlayChrome {
15
+ /** Chrome element, placed once in the canvas layer above the variant frame. */
16
+ node: HTMLElement;
17
+ /**
18
+ * Places the chrome on the design box; the divider only shows in Split mode.
19
+ * @param placement Design box.
20
+ * @param mode Comparison mode (Overlay or Split).
21
+ */
22
+ render: (placement: OverlayPlacement, mode: CanvasMode) => void;
23
+ }
24
+ /**
25
+ * Creates the overlay chrome. Pointer gestures capture the pointer, so moving over the story
26
+ * frame never interrupts them; arrow keys nudge (Shift for bigger steps).
27
+ * @param events View callbacks.
28
+ */
29
+ export declare function createOverlayChrome(events: OverlayChromeEvents): OverlayChrome;
@@ -0,0 +1,62 @@
1
+ import type { HistoireRect } from '@histoire/protocol';
2
+ import type { BoxSize } from './design-element.js';
3
+ /** How the canvas view compares the variant with its design. */
4
+ export type CanvasMode = 'side-by-side' | 'overlay' | 'split';
5
+ /** Canvas modes in toggle order. */
6
+ export declare const CANVAS_MODES: readonly CanvasMode[];
7
+ /** Design box laid over the variant frame, in canvas units. */
8
+ export interface OverlayPlacement {
9
+ /** Left edge in canvas units. */
10
+ x: number;
11
+ /** Top edge in canvas units. */
12
+ y: number;
13
+ /** Width in canvas units. */
14
+ width: number;
15
+ /** Height in canvas units. */
16
+ height: number;
17
+ /** Split divider position as a ratio (0–1) of the design width; the design shows right of it. */
18
+ split: number;
19
+ }
20
+ /**
21
+ * Initial overlay: top-left on the frame box, scaled down to the frame width when wider.
22
+ * @param frame Frame box in canvas space (label excluded).
23
+ * @param design Design box size.
24
+ */
25
+ export declare function defaultPlacement(frame: HistoireRect, design: BoxSize): OverlayPlacement;
26
+ /**
27
+ * Moves the design box.
28
+ * @param placement Current placement.
29
+ * @param dx Horizontal delta in canvas units.
30
+ * @param dy Vertical delta in canvas units.
31
+ */
32
+ export declare function movePlacement(placement: OverlayPlacement, dx: number, dy: number): OverlayPlacement;
33
+ /**
34
+ * Resizes the design box from its bottom-right corner.
35
+ * @param placement Current placement.
36
+ * @param dx Horizontal delta in canvas units.
37
+ * @param dy Vertical delta in canvas units.
38
+ * @param keepAspect Keep the width/height ratio; the larger relative change drives both edges.
39
+ */
40
+ export declare function resizePlacement(placement: OverlayPlacement, dx: number, dy: number, keepAspect: boolean): OverlayPlacement;
41
+ /**
42
+ * Moves the split divider to a canvas x position, clamped to the design box.
43
+ * @param placement Current placement.
44
+ * @param canvasX Divider position in canvas units.
45
+ */
46
+ export declare function setSplit(placement: OverlayPlacement, canvasX: number): OverlayPlacement;
47
+ /**
48
+ * Union of the variant column and the design box, framed by Fit.
49
+ * @param column Variant column box (label included).
50
+ * @param placement Design box.
51
+ */
52
+ export declare function overlayBounds(column: HistoireRect, placement: OverlayPlacement): HistoireRect;
53
+ /**
54
+ * Stored mode, or side by side for anything unknown (preferences are user storage).
55
+ * @param value Stored value.
56
+ */
57
+ export declare function parseMode(value: unknown): CanvasMode;
58
+ /**
59
+ * Stored placement, or `undefined` when it is not a usable box.
60
+ * @param value Stored value.
61
+ */
62
+ export declare function parsePlacement(value: unknown): OverlayPlacement | undefined;
@@ -0,0 +1,30 @@
1
+ import type { WorkbenchPluginApi } from '@histoire/plugin-kit';
2
+ import type { HistoireTarget } from '@histoire/protocol';
3
+ import type { CanvasMode, OverlayPlacement } from './overlay-geometry.js';
4
+ /** Plugin API members the overlay state uses. */
5
+ export type OverlayStateApi = Pick<WorkbenchPluginApi, 'preferences'>;
6
+ /** Canvas comparison settings shared by the canvas view and its comparison bar. */
7
+ export interface OverlayState {
8
+ /** Current comparison mode. */
9
+ mode: () => CanvasMode;
10
+ /** Switches the comparison mode. */
11
+ setMode: (mode: CanvasMode) => void;
12
+ /** Design opacity in Overlay mode, between 0.1 and 1. */
13
+ opacity: () => number;
14
+ /** Sets the design opacity; clamped like {@link OverlayState.opacity}. */
15
+ setOpacity: (value: number) => void;
16
+ /** Moved or resized design box of one variant design; `undefined` keeps the default box. */
17
+ placement: (target: HistoireTarget, entryIndex: number) => OverlayPlacement | undefined;
18
+ /** Stores the design box of one variant design. */
19
+ setPlacement: (target: HistoireTarget, entryIndex: number, placement: OverlayPlacement) => void;
20
+ /** Restores the default design box of one variant design. */
21
+ reset: (target: HistoireTarget, entryIndex: number) => void;
22
+ /** Notified after any setter. */
23
+ subscribe: (listener: () => void) => () => void;
24
+ }
25
+ /**
26
+ * Creates the preferences-backed overlay state. Mode and opacity are global; placements are
27
+ * per variant design entry.
28
+ * @param api Plugin API.
29
+ */
30
+ export declare function createOverlayState(api: OverlayStateApi): OverlayState;
@@ -0,0 +1,10 @@
1
+ import type { CanvasViewContext, CanvasViewInput, MountView } from '@histoire/plugin-kit';
2
+ import type { DesignModel } from '../model.js';
3
+ import type { OverlayState } from './overlay-state.js';
4
+ /**
5
+ * `canvas.view` comparing the selected variant with its design: side by side, or laid over it
6
+ * with transparency or a split divider. DOM view: geometry-heavy code stays framework-free.
7
+ * @param model Design model.
8
+ * @param overlay Comparison mode and design placements.
9
+ */
10
+ export declare function sideBySideView(model: DesignModel, overlay: OverlayState): MountView<CanvasViewContext> & Pick<CanvasViewInput, 'layout' | 'toolbar'>;
@@ -0,0 +1,21 @@
1
+ import type { WorkbenchState } from '@histoire/plugin-kit';
2
+ import type { HistoireTarget } from '@histoire/protocol';
3
+ import type { ResolvedDesigns } from '../../designs/resolve.js';
4
+ import type { ResolvedDesign } from '../../types.js';
5
+ /**
6
+ * Whether a lease failure only means the lease was released first (view switched, selection changed).
7
+ * @param error Rejection of `acquireFrame` or `ready`.
8
+ */
9
+ export declare function isReleased(error: unknown): boolean;
10
+ /**
11
+ * Full-view state replacing the variant and its design, or `null` when a design can be shown.
12
+ * @param target Selected variant.
13
+ * @param designs Its designs; `undefined` while loading.
14
+ * @param active Its active design.
15
+ */
16
+ export declare function viewState(target: HistoireTarget | null | undefined, designs: ResolvedDesigns | undefined, active: ResolvedDesign | undefined): WorkbenchState | null;
17
+ /**
18
+ * Error shown in the design box when an image fails to load.
19
+ * @param design Image design.
20
+ */
21
+ export declare function imageError(design: ResolvedDesign): HTMLElement;
@@ -0,0 +1,8 @@
1
+ import type { ResolvedImageDesign } from '../../types.js';
2
+ type __VLS_Props = {
3
+ /** Image design to show. */
4
+ design: ResolvedImageDesign;
5
+ };
6
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const _default: typeof __VLS_export;
8
+ export default _default;
@@ -0,0 +1,72 @@
1
+ /** Width and height in CSS pixels. */
2
+ export interface Size {
3
+ /** Width. */
4
+ width: number;
5
+ /** Height. */
6
+ height: number;
7
+ }
8
+ /** Image placement: zoom factor and top-left corner in container pixels. */
9
+ export interface ImageView {
10
+ /** Zoom factor. */
11
+ scale: number;
12
+ /** Left edge of the image. */
13
+ x: number;
14
+ /** Top edge of the image. */
15
+ y: number;
16
+ }
17
+ /** Smallest zoom factor. */
18
+ export declare const MIN_SCALE = 0.05;
19
+ /** Largest zoom factor. */
20
+ export declare const MAX_SCALE = 16;
21
+ /** Zoom multiplier of one zoom button press or `+` key. */
22
+ export declare const ZOOM_STEP = 1.25;
23
+ /**
24
+ * Places the image at `scale`, centered in the container, then shifted by `offset`.
25
+ * @param container Viewer size.
26
+ * @param image Natural image size.
27
+ * @param scale Zoom factor.
28
+ * @param offset Shift from the centered position; positive moves right and down.
29
+ */
30
+ export declare function centeredView(container: Size, image: Size, scale: number, offset?: readonly [number, number]): ImageView;
31
+ /**
32
+ * Shows the whole image centered, then shifted by `offset`; small images keep their natural size.
33
+ * @param container Viewer size.
34
+ * @param image Natural image size.
35
+ * @param offset Shift from the centered position; positive moves right and down.
36
+ */
37
+ export declare function fitView(container: Size, image: Size, offset?: readonly [number, number]): ImageView;
38
+ /**
39
+ * Zooms by `factor` around `point` (container pixels): the image pixel under it stays put.
40
+ * @param view Current placement.
41
+ * @param factor Zoom multiplier.
42
+ * @param point Zoom origin in container pixels.
43
+ * @param point.x Horizontal position.
44
+ * @param point.y Vertical position.
45
+ */
46
+ export declare function zoomAt(view: ImageView, factor: number, point: {
47
+ x: number;
48
+ y: number;
49
+ }): ImageView;
50
+ /** View change requested from the keyboard. */
51
+ export type KeyCommand = {
52
+ pan: [number, number];
53
+ } | {
54
+ zoom: number;
55
+ } | 'fit';
56
+ /**
57
+ * Maps a key press in the image viewer to a view change: arrows pan (Shift for a bigger step),
58
+ * `+`/`=` and `-`/`_` zoom, `0` fits. Presses with Ctrl, Meta or Alt are left to the browser.
59
+ * @param event Key press.
60
+ * @param event.key Pressed key value.
61
+ * @param event.shiftKey Shift held.
62
+ * @param event.ctrlKey Ctrl held.
63
+ * @param event.metaKey Meta held.
64
+ * @param event.altKey Alt held.
65
+ */
66
+ export declare function keyCommand(event: {
67
+ key: string;
68
+ shiftKey: boolean;
69
+ ctrlKey?: boolean;
70
+ metaKey?: boolean;
71
+ altKey?: boolean;
72
+ }): KeyCommand | undefined;
@@ -0,0 +1,40 @@
1
+ import type { WorkbenchPluginApi } from '@histoire/plugin-kit';
2
+ import type { HistoireCatalogVariant, HistoireTarget } from '@histoire/protocol';
3
+ import type { ResolvedDesigns, ResolveOptions } from '../designs/resolve.js';
4
+ import type { ResolvedDesign } from '../types.js';
5
+ /** Plugin API members the model uses. */
6
+ export type DesignModelApi = Pick<WorkbenchPluginApi, 'preferences' | 'invalidate' | 'signal'> & {
7
+ /** Root context; only the catalog is read. */
8
+ readonly context: Pick<WorkbenchPluginApi['context'], 'catalog'>;
9
+ };
10
+ /** Designs of the stories surfaces asked for, shared by the inspector tab and canvas view. */
11
+ export interface DesignModel {
12
+ /**
13
+ * Designs of a variant; `undefined` while its story loads (the first read starts loading).
14
+ * When the story cannot be loaded, `error` holds the reason and both lists are empty.
15
+ */
16
+ get: (target: HistoireTarget) => ResolvedDesigns | undefined;
17
+ /** Whether a variant has a design, an invalid entry or a load failure to show; starts loading like `get`. */
18
+ has: (target: HistoireTarget) => boolean;
19
+ /** Catalog entry of a loaded variant. */
20
+ variant: (target: HistoireTarget) => HistoireCatalogVariant | undefined;
21
+ /** Design selected in the switcher, the first valid one by default. */
22
+ active: (target: HistoireTarget) => ResolvedDesign | undefined;
23
+ /** Selects a design by its entry index (`ResolvedDesign.index`). */
24
+ select: (target: HistoireTarget, entryIndex: number) => void;
25
+ /** Notified (at most once per microtask) when designs load or the selection changes. */
26
+ subscribe: (listener: () => void) => () => void;
27
+ /**
28
+ * Loads a story ahead of the first read, so availability is known before surfaces restore
29
+ * (e.g. a Design tab reopened from the URL). Resolves once loaded or failed.
30
+ */
31
+ preload: (storyId: string) => Promise<void>;
32
+ }
33
+ /**
34
+ * Creates the design model. Stories are fetched lazily from the catalog and the most recently
35
+ * read ones are refetched after each catalog publication; stale data stays readable until the
36
+ * new version arrives, so surfaces never flash empty while a story file is edited.
37
+ * @param api Plugin API.
38
+ * @param options Design resolution settings.
39
+ */
40
+ export declare function createDesignModel(api: DesignModelApi, options: ResolveOptions): DesignModel;