@moku-labs/web 1.10.0 → 1.12.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.
@@ -1,5 +1,5 @@
1
1
  import { EmitFn } from "@moku-labs/core";
2
- import { ComponentChildren, VNode } from "preact";
2
+ import { ComponentChildren, FunctionComponent, VNode } from "preact";
3
3
  import { BundledTheme, ThemeRegistrationAny } from "shiki";
4
4
  import { Pluggable, Processor } from "unified";
5
5
 
@@ -1927,7 +1927,7 @@ type DataProvider = {
1927
1927
  */
1928
1928
  declare const dataPlugin: import("@moku-labs/core").PluginInstance<"data", DataConfig, DataState, DataProvider, {}> & Record<never, never>;
1929
1929
  declare namespace types_d_exports {
1930
- export { Api, Article, ArticleCard, ComputedFields, Config, ContentApiContext, ContentEvents, ContentProvider, ContentProviderState, FileSystemContentOptions, Frontmatter, LoadAllOptions, MermaidDiagramOptions, State };
1930
+ export { Api, Article, ArticleCard, ComputedFields, Config, ContentApiContext, ContentEvents, ContentProvider, ContentProviderState, EmbedFacade, EmbedFacadeProps, EmbedOptions, FileSystemContentOptions, Frontmatter, GalleryComponent, GalleryOptions, GalleryProps, GallerySlide, GalleryTransformOptions, LoadAllOptions, MermaidDiagramOptions, State };
1931
1931
  }
1932
1932
  /**
1933
1933
  * YAML frontmatter parsed from each article file.
@@ -2071,6 +2071,115 @@ type MermaidDiagramOptions = {
2071
2071
  */
2072
2072
  renderDiagrams?: (sources: readonly string[], mermaidConfig?: Record<string, unknown>) => Promise<readonly string[]>;
2073
2073
  };
2074
+ /**
2075
+ * Props handed to an `::embed` facade component (the click-to-activate placeholder
2076
+ * the framework renders to static markup at build time). `width`/`height` are the
2077
+ * parsed pixel dimensions when the directive set them; `attributes` is the full raw
2078
+ * directive attribute bag, so a custom facade can read arbitrary extra options
2079
+ * (e.g. `::embed{… poster="/p.jpg" label="Play"}`).
2080
+ *
2081
+ * @example
2082
+ * ```tsx
2083
+ * const Facade = ({ title, attributes }: EmbedFacadeProps) => (
2084
+ * <button type="button" class="lazy-embed-button">
2085
+ * {attributes.poster ? <img src={attributes.poster} alt="" /> : null}
2086
+ * <span class="lazy-embed-title">{title}</span>
2087
+ * </button>
2088
+ * );
2089
+ * ```
2090
+ */
2091
+ type EmbedFacadeProps = {
2092
+ /** The embed target exactly as written in the directive (the provider resolves it later). */src: string; /** The human-readable embed title (default label + iframe title). */
2093
+ title: string; /** Reserved-box width in pixels, when the directive set `width`/`height`. */
2094
+ width?: number; /** Reserved-box height in pixels, when the directive set `width`/`height`. */
2095
+ height?: number; /** The full raw directive attribute bag (custom options live here). */
2096
+ attributes: Readonly<Record<string, string>>;
2097
+ };
2098
+ /**
2099
+ * A consumer-supplied facade component: a Preact function component over
2100
+ * {@link EmbedFacadeProps}, rendered (at build time, to static markup) as the
2101
+ * facade's inner content — inside the framework-owned `<figure>` that carries the
2102
+ * island hooks + reserved-box sizing. Defaults to the built-in `EmbedFacadeButton`.
2103
+ */
2104
+ type EmbedFacade = FunctionComponent<EmbedFacadeProps>;
2105
+ /**
2106
+ * Options for the `::embed` lazy-iframe feature (the `embed` key of
2107
+ * {@link FileSystemContentOptions}). `embed: true` uses the default facade;
2108
+ * `embed: { facade }` swaps in a consumer Preact component for the placeholder.
2109
+ *
2110
+ * @example
2111
+ * ```ts
2112
+ * fileSystemContent({ contentDir: "./content", trustedContent: true, embed: { facade: MyFacade } });
2113
+ * ```
2114
+ */
2115
+ type EmbedOptions = {
2116
+ /**
2117
+ * Consumer Preact component rendering the facade's inner content (SSR'd to
2118
+ * static markup at build — no client JS). Receives {@link EmbedFacadeProps}.
2119
+ * Defaults to the built-in `EmbedFacadeButton`.
2120
+ */
2121
+ facade?: EmbedFacade;
2122
+ };
2123
+ /** One resolved gallery slide handed to a {@link GalleryComponent}. */
2124
+ type GallerySlide = {
2125
+ /** Shared absolute image URL (`/<slug>/<dir>/<file>`), identical from every locale page. */src: string; /** Per-slide alt text (the directive `caption` with a ` · N` index suffix, or just `N`). */
2126
+ alt: string;
2127
+ };
2128
+ /**
2129
+ * Props handed to a `::gallery` component (the swipeable image set the framework
2130
+ * renders to static markup at build time). The framework resolves the directive's
2131
+ * `src` folder to the sorted, URL-rewritten {@link GallerySlide} list; `caption` is
2132
+ * the directive's `caption` attribute; `attributes` is the full raw directive
2133
+ * attribute bag, so a custom component can read arbitrary extra options
2134
+ * (e.g. `::gallery{… layout="dots"}`).
2135
+ *
2136
+ * @example
2137
+ * ```tsx
2138
+ * const Gallery = ({ slides, caption }: GalleryProps) => (
2139
+ * <div class="gallery-track">
2140
+ * {slides.map(s => <img src={s.src} alt={s.alt} />)}
2141
+ * </div>
2142
+ * );
2143
+ * ```
2144
+ */
2145
+ type GalleryProps = {
2146
+ /** The resolved slides, in folder order. */slides: readonly GallerySlide[]; /** The directive's `caption` attribute (empty string when unset). */
2147
+ caption: string; /** The full raw directive attribute bag (custom options live here). */
2148
+ attributes: Readonly<Record<string, string>>;
2149
+ };
2150
+ /**
2151
+ * A consumer-supplied gallery component: a Preact function component over
2152
+ * {@link GalleryProps}, rendered (at build time, to static markup) as the inner
2153
+ * content — inside the framework-owned `<div data-component="gallery">` that carries
2154
+ * the island hook. Defaults to the built-in `GalleryTrack`.
2155
+ */
2156
+ type GalleryComponent = FunctionComponent<GalleryProps>;
2157
+ /**
2158
+ * Options for the `::gallery` feature (the `gallery` key of
2159
+ * {@link FileSystemContentOptions}). `gallery: true` uses the default component;
2160
+ * `gallery: { component }` swaps in a consumer Preact component.
2161
+ *
2162
+ * @example
2163
+ * ```ts
2164
+ * fileSystemContent({ contentDir: "./content", trustedContent: true, gallery: { component: MyGallery } });
2165
+ * ```
2166
+ */
2167
+ type GalleryOptions = {
2168
+ /**
2169
+ * Consumer Preact component rendering the gallery's inner content (SSR'd to
2170
+ * static markup at build). Receives {@link GalleryProps}. Defaults to the
2171
+ * built-in `GalleryTrack`.
2172
+ */
2173
+ component?: GalleryComponent;
2174
+ };
2175
+ /**
2176
+ * Resolved gallery transform inputs — {@link GalleryOptions} plus the provider's
2177
+ * `contentDir` (needed to read the directive's `src` folder from disk). Assembled
2178
+ * by the pipeline wiring; not part of the public config surface.
2179
+ */
2180
+ type GalleryTransformOptions = GalleryOptions & {
2181
+ /** The provider's content directory (folder reads resolve against it). */contentDir: string;
2182
+ };
2074
2183
  /**
2075
2184
  * Options for the node filesystem provider {@link ContentProvider} `fileSystemContent`.
2076
2185
  * These are the markdown-pipeline + source concerns that used to live on the content
@@ -2110,10 +2219,22 @@ type FileSystemContentOptions = {
2110
2219
  * into static click-to-activate facades (no iframe — and none of the target's
2111
2220
  * network/JS cost — until the reader clicks). Pair with the `lazyEmbed` SPA
2112
2221
  * island, which swaps the facade for the real `<iframe loading="lazy">`.
2113
- * Requires `trustedContent: true` (the facade is raw HTML the sanitize pass
2114
- * would strip). Defaults to disabled.
2115
- */
2116
- embed?: boolean;
2222
+ * `true` enables with the default facade; an object passes {@link EmbedOptions}
2223
+ * (e.g. a consumer `facade` Preact component). Requires `trustedContent: true`
2224
+ * (the facade is raw HTML the sanitize pass would strip). Defaults to disabled.
2225
+ */
2226
+ embed?: boolean | EmbedOptions;
2227
+ /**
2228
+ * Folder galleries: rewrite `::gallery{src="./images/dir/" caption="…"}` leaf
2229
+ * directives into a swipeable image set. The framework reads the co-located
2230
+ * `src` folder, sorts its images, rewrites each to its shared `/<slug>/…` URL,
2231
+ * and renders them through a consumer Preact component (pair it with a gallery
2232
+ * SPA island for swipe/keyboard/lightbox). `true` enables with the default
2233
+ * component; an object passes {@link GalleryOptions} (e.g. a consumer
2234
+ * `component`). Requires `trustedContent: true` (the markup is raw HTML the
2235
+ * sanitize pass would strip). Defaults to disabled.
2236
+ */
2237
+ gallery?: boolean | GalleryOptions;
2117
2238
  };
2118
2239
  /**
2119
2240
  * Internal mutable state of the filesystem provider: the lazy unified processor and
package/dist/browser.mjs CHANGED
@@ -4466,7 +4466,11 @@ function activateEmbed(figure) {
4466
4466
  }
4467
4467
  /**
4468
4468
  * Shared click handler (module-level so mount/unmount detach the same
4469
- * reference): a click on the facade's button activates the embed.
4469
+ * reference): any click on the not-yet-active facade activates the embed. It
4470
+ * fires on the whole facade — not a specific button class — so a consumer's
4471
+ * custom facade markup (see content `embed.facade`) works without re-wiring;
4472
+ * the default facade's `<button>` keeps it keyboard-accessible. Once active
4473
+ * (`data-embed-active`), clicks fall through to the live iframe.
4470
4474
  *
4471
4475
  * @param event - The click event from the facade figure.
4472
4476
  * @example
@@ -4475,9 +4479,10 @@ function activateEmbed(figure) {
4475
4479
  * ```
4476
4480
  */
4477
4481
  function onFacadeClick(event) {
4478
- if (!event.target.closest("button.lazy-embed-button")) return;
4479
4482
  const figure = event.currentTarget;
4480
- if (figure instanceof HTMLElement) activateEmbed(figure);
4483
+ if (!(figure instanceof HTMLElement)) return;
4484
+ if (figure.dataset.embedActive !== void 0) return;
4485
+ activateEmbed(figure);
4481
4486
  }
4482
4487
  /**
4483
4488
  * Lazy-embed island: facade button click → real `<iframe loading="lazy">`.