@moku-labs/web 1.11.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.
package/dist/index.cjs CHANGED
@@ -40,6 +40,7 @@ let preact_jsx_runtime = require("preact/jsx-runtime");
40
40
  let hast_util_sanitize = require("hast-util-sanitize");
41
41
  let reading_time = require("reading-time");
42
42
  reading_time = require_convention.__toESM(reading_time, 1);
43
+ let node_process = require("node:process");
43
44
  //#region src/plugins/env/api.ts
44
45
  /** Error prefix for all env API failures. */
45
46
  const ERROR_PREFIX$16 = "[web]";
@@ -1583,14 +1584,15 @@ function validateContentConfig(config) {
1583
1584
  }
1584
1585
  /**
1585
1586
  * Validates the `fileSystemContent` provider options (fail-fast at provider
1586
- * construction). Throws when `mermaid` or `embed` is enabled without
1587
- * `trustedContent: true`: both emit raw HTML (inline SVG / the embed facade),
1588
- * which the sanitize pass (the untrusted-content XSS boundary) would strip — so
1589
- * the combination can never work. Errors use the `[web]` prefix.
1587
+ * construction). Throws when `mermaid`, `embed`, or `gallery` is enabled without
1588
+ * `trustedContent: true`: each emits raw HTML (inline SVG / the embed facade /
1589
+ * the gallery markup), which the sanitize pass (the untrusted-content XSS
1590
+ * boundary) would strip — so the combination can never work. Errors use the
1591
+ * `[web]` prefix.
1590
1592
  *
1591
1593
  * @param options - The provider options to validate.
1592
- * @throws {Error} If `mermaid` or `embed` is enabled while `trustedContent` is
1593
- * not `true`.
1594
+ * @throws {Error} If `mermaid`, `embed`, or `gallery` is enabled while
1595
+ * `trustedContent` is not `true`.
1594
1596
  * @example
1595
1597
  * ```ts
1596
1598
  * validateFileSystemContentOptions({ contentDir: "./content", trustedContent: true, mermaid: true });
@@ -1599,6 +1601,7 @@ function validateContentConfig(config) {
1599
1601
  function validateFileSystemContentOptions(options) {
1600
1602
  if (Boolean(options.mermaid) && options.trustedContent !== true) throw new Error("[web] content: `mermaid` requires `trustedContent: true`.\n Mermaid diagrams render to raw inline SVG, which the sanitize pass would strip.\n Set trustedContent: true ONLY for fully author-controlled Markdown.");
1601
1603
  if (Boolean(options.embed) && options.trustedContent !== true) throw new Error("[web] content: `embed` requires `trustedContent: true`.\n Embed directives render to a raw-HTML facade, which the sanitize pass would strip\n (and embedding third-party iframes is never safe for untrusted Markdown).\n Set trustedContent: true ONLY for fully author-controlled Markdown.");
1604
+ if (Boolean(options.gallery) && options.trustedContent !== true) throw new Error("[web] content: `gallery` requires `trustedContent: true`.\n Gallery directives render to raw-HTML markup, which the sanitize pass would strip.\n Set trustedContent: true ONLY for fully author-controlled Markdown.");
1602
1605
  }
1603
1606
  //#endregion
1604
1607
  //#region src/plugins/content/index.ts
@@ -11638,6 +11641,857 @@ function cloudflareBindings() {
11638
11641
  };
11639
11642
  }
11640
11643
  //#endregion
11644
+ //#region node_modules/unist-util-stringify-position/lib/index.js
11645
+ /**
11646
+ * @typedef {import('unist').Node} Node
11647
+ * @typedef {import('unist').Point} Point
11648
+ * @typedef {import('unist').Position} Position
11649
+ */
11650
+ /**
11651
+ * @typedef NodeLike
11652
+ * @property {string} type
11653
+ * @property {PositionLike | null | undefined} [position]
11654
+ *
11655
+ * @typedef PointLike
11656
+ * @property {number | null | undefined} [line]
11657
+ * @property {number | null | undefined} [column]
11658
+ * @property {number | null | undefined} [offset]
11659
+ *
11660
+ * @typedef PositionLike
11661
+ * @property {PointLike | null | undefined} [start]
11662
+ * @property {PointLike | null | undefined} [end]
11663
+ */
11664
+ /**
11665
+ * Serialize the positional info of a point, position (start and end points),
11666
+ * or node.
11667
+ *
11668
+ * @param {Node | NodeLike | Point | PointLike | Position | PositionLike | null | undefined} [value]
11669
+ * Node, position, or point.
11670
+ * @returns {string}
11671
+ * Pretty printed positional info of a node (`string`).
11672
+ *
11673
+ * In the format of a range `ls:cs-le:ce` (when given `node` or `position`)
11674
+ * or a point `l:c` (when given `point`), where `l` stands for line, `c` for
11675
+ * column, `s` for `start`, and `e` for end.
11676
+ * An empty string (`''`) is returned if the given value is neither `node`,
11677
+ * `position`, nor `point`.
11678
+ */
11679
+ function stringifyPosition(value) {
11680
+ if (!value || typeof value !== "object") return "";
11681
+ if ("position" in value || "type" in value) return position(value.position);
11682
+ if ("start" in value || "end" in value) return position(value);
11683
+ if ("line" in value || "column" in value) return point(value);
11684
+ return "";
11685
+ }
11686
+ /**
11687
+ * @param {Point | PointLike | null | undefined} point
11688
+ * @returns {string}
11689
+ */
11690
+ function point(point) {
11691
+ return index(point && point.line) + ":" + index(point && point.column);
11692
+ }
11693
+ /**
11694
+ * @param {Position | PositionLike | null | undefined} pos
11695
+ * @returns {string}
11696
+ */
11697
+ function position(pos) {
11698
+ return point(pos && pos.start) + "-" + point(pos && pos.end);
11699
+ }
11700
+ /**
11701
+ * @param {number | null | undefined} value
11702
+ * @returns {number}
11703
+ */
11704
+ function index(value) {
11705
+ return value && typeof value === "number" ? value : 1;
11706
+ }
11707
+ //#endregion
11708
+ //#region node_modules/vfile-message/lib/index.js
11709
+ /**
11710
+ * @import {Node, Point, Position} from 'unist'
11711
+ */
11712
+ /**
11713
+ * @typedef {object & {type: string, position?: Position | undefined}} NodeLike
11714
+ *
11715
+ * @typedef Options
11716
+ * Configuration.
11717
+ * @property {Array<Node> | null | undefined} [ancestors]
11718
+ * Stack of (inclusive) ancestor nodes surrounding the message (optional).
11719
+ * @property {Error | null | undefined} [cause]
11720
+ * Original error cause of the message (optional).
11721
+ * @property {Point | Position | null | undefined} [place]
11722
+ * Place of message (optional).
11723
+ * @property {string | null | undefined} [ruleId]
11724
+ * Category of message (optional, example: `'my-rule'`).
11725
+ * @property {string | null | undefined} [source]
11726
+ * Namespace of who sent the message (optional, example: `'my-package'`).
11727
+ */
11728
+ /**
11729
+ * Message.
11730
+ */
11731
+ var VFileMessage = class extends Error {
11732
+ /**
11733
+ * Create a message for `reason`.
11734
+ *
11735
+ * > 🪦 **Note**: also has obsolete signatures.
11736
+ *
11737
+ * @overload
11738
+ * @param {string} reason
11739
+ * @param {Options | null | undefined} [options]
11740
+ * @returns
11741
+ *
11742
+ * @overload
11743
+ * @param {string} reason
11744
+ * @param {Node | NodeLike | null | undefined} parent
11745
+ * @param {string | null | undefined} [origin]
11746
+ * @returns
11747
+ *
11748
+ * @overload
11749
+ * @param {string} reason
11750
+ * @param {Point | Position | null | undefined} place
11751
+ * @param {string | null | undefined} [origin]
11752
+ * @returns
11753
+ *
11754
+ * @overload
11755
+ * @param {string} reason
11756
+ * @param {string | null | undefined} [origin]
11757
+ * @returns
11758
+ *
11759
+ * @overload
11760
+ * @param {Error | VFileMessage} cause
11761
+ * @param {Node | NodeLike | null | undefined} parent
11762
+ * @param {string | null | undefined} [origin]
11763
+ * @returns
11764
+ *
11765
+ * @overload
11766
+ * @param {Error | VFileMessage} cause
11767
+ * @param {Point | Position | null | undefined} place
11768
+ * @param {string | null | undefined} [origin]
11769
+ * @returns
11770
+ *
11771
+ * @overload
11772
+ * @param {Error | VFileMessage} cause
11773
+ * @param {string | null | undefined} [origin]
11774
+ * @returns
11775
+ *
11776
+ * @param {Error | VFileMessage | string} causeOrReason
11777
+ * Reason for message, should use markdown.
11778
+ * @param {Node | NodeLike | Options | Point | Position | string | null | undefined} [optionsOrParentOrPlace]
11779
+ * Configuration (optional).
11780
+ * @param {string | null | undefined} [origin]
11781
+ * Place in code where the message originates (example:
11782
+ * `'my-package:my-rule'` or `'my-rule'`).
11783
+ * @returns
11784
+ * Instance of `VFileMessage`.
11785
+ */
11786
+ constructor(causeOrReason, optionsOrParentOrPlace, origin) {
11787
+ super();
11788
+ if (typeof optionsOrParentOrPlace === "string") {
11789
+ origin = optionsOrParentOrPlace;
11790
+ optionsOrParentOrPlace = void 0;
11791
+ }
11792
+ /** @type {string} */
11793
+ let reason = "";
11794
+ /** @type {Options} */
11795
+ let options = {};
11796
+ let legacyCause = false;
11797
+ if (optionsOrParentOrPlace) if ("line" in optionsOrParentOrPlace && "column" in optionsOrParentOrPlace) options = { place: optionsOrParentOrPlace };
11798
+ else if ("start" in optionsOrParentOrPlace && "end" in optionsOrParentOrPlace) options = { place: optionsOrParentOrPlace };
11799
+ else if ("type" in optionsOrParentOrPlace) options = {
11800
+ ancestors: [optionsOrParentOrPlace],
11801
+ place: optionsOrParentOrPlace.position
11802
+ };
11803
+ else options = { ...optionsOrParentOrPlace };
11804
+ if (typeof causeOrReason === "string") reason = causeOrReason;
11805
+ else if (!options.cause && causeOrReason) {
11806
+ legacyCause = true;
11807
+ reason = causeOrReason.message;
11808
+ options.cause = causeOrReason;
11809
+ }
11810
+ if (!options.ruleId && !options.source && typeof origin === "string") {
11811
+ const index = origin.indexOf(":");
11812
+ if (index === -1) options.ruleId = origin;
11813
+ else {
11814
+ options.source = origin.slice(0, index);
11815
+ options.ruleId = origin.slice(index + 1);
11816
+ }
11817
+ }
11818
+ if (!options.place && options.ancestors && options.ancestors) {
11819
+ const parent = options.ancestors[options.ancestors.length - 1];
11820
+ if (parent) options.place = parent.position;
11821
+ }
11822
+ const start = options.place && "start" in options.place ? options.place.start : options.place;
11823
+ /**
11824
+ * Stack of ancestor nodes surrounding the message.
11825
+ *
11826
+ * @type {Array<Node> | undefined}
11827
+ */
11828
+ this.ancestors = options.ancestors || void 0;
11829
+ /**
11830
+ * Original error cause of the message.
11831
+ *
11832
+ * @type {Error | undefined}
11833
+ */
11834
+ this.cause = options.cause || void 0;
11835
+ /**
11836
+ * Starting column of message.
11837
+ *
11838
+ * @type {number | undefined}
11839
+ */
11840
+ this.column = start ? start.column : void 0;
11841
+ /**
11842
+ * State of problem.
11843
+ *
11844
+ * * `true` — error, file not usable
11845
+ * * `false` — warning, change may be needed
11846
+ * * `undefined` — change likely not needed
11847
+ *
11848
+ * @type {boolean | null | undefined}
11849
+ */
11850
+ this.fatal = void 0;
11851
+ /**
11852
+ * Path of a file (used throughout the `VFile` ecosystem).
11853
+ *
11854
+ * @type {string | undefined}
11855
+ */
11856
+ this.file = "";
11857
+ /**
11858
+ * Reason for message.
11859
+ *
11860
+ * @type {string}
11861
+ */
11862
+ this.message = reason;
11863
+ /**
11864
+ * Starting line of error.
11865
+ *
11866
+ * @type {number | undefined}
11867
+ */
11868
+ this.line = start ? start.line : void 0;
11869
+ /**
11870
+ * Serialized positional info of message.
11871
+ *
11872
+ * On normal errors, this would be something like `ParseError`, buit in
11873
+ * `VFile` messages we use this space to show where an error happened.
11874
+ */
11875
+ this.name = stringifyPosition(options.place) || "1:1";
11876
+ /**
11877
+ * Place of message.
11878
+ *
11879
+ * @type {Point | Position | undefined}
11880
+ */
11881
+ this.place = options.place || void 0;
11882
+ /**
11883
+ * Reason for message, should use markdown.
11884
+ *
11885
+ * @type {string}
11886
+ */
11887
+ this.reason = this.message;
11888
+ /**
11889
+ * Category of message (example: `'my-rule'`).
11890
+ *
11891
+ * @type {string | undefined}
11892
+ */
11893
+ this.ruleId = options.ruleId || void 0;
11894
+ /**
11895
+ * Namespace of message (example: `'my-package'`).
11896
+ *
11897
+ * @type {string | undefined}
11898
+ */
11899
+ this.source = options.source || void 0;
11900
+ /**
11901
+ * Stack of message.
11902
+ *
11903
+ * This is used by normal errors to show where something happened in
11904
+ * programming code, irrelevant for `VFile` messages,
11905
+ *
11906
+ * @type {string}
11907
+ */
11908
+ this.stack = legacyCause && options.cause && typeof options.cause.stack === "string" ? options.cause.stack : "";
11909
+ /**
11910
+ * Specify the source value that’s being reported, which is deemed
11911
+ * incorrect.
11912
+ *
11913
+ * @type {string | undefined}
11914
+ */
11915
+ this.actual = void 0;
11916
+ /**
11917
+ * Suggest acceptable values that can be used instead of `actual`.
11918
+ *
11919
+ * @type {Array<string> | undefined}
11920
+ */
11921
+ this.expected = void 0;
11922
+ /**
11923
+ * Long form description of the message (you should use markdown).
11924
+ *
11925
+ * @type {string | undefined}
11926
+ */
11927
+ this.note = void 0;
11928
+ /**
11929
+ * Link to docs for the message.
11930
+ *
11931
+ * > 👉 **Note**: this must be an absolute URL that can be passed as `x`
11932
+ * > to `new URL(x)`.
11933
+ *
11934
+ * @type {string | undefined}
11935
+ */
11936
+ this.url = void 0;
11937
+ }
11938
+ };
11939
+ VFileMessage.prototype.file = "";
11940
+ VFileMessage.prototype.name = "";
11941
+ VFileMessage.prototype.reason = "";
11942
+ VFileMessage.prototype.message = "";
11943
+ VFileMessage.prototype.stack = "";
11944
+ VFileMessage.prototype.column = void 0;
11945
+ VFileMessage.prototype.line = void 0;
11946
+ VFileMessage.prototype.ancestors = void 0;
11947
+ VFileMessage.prototype.cause = void 0;
11948
+ VFileMessage.prototype.fatal = void 0;
11949
+ VFileMessage.prototype.place = void 0;
11950
+ VFileMessage.prototype.ruleId = void 0;
11951
+ VFileMessage.prototype.source = void 0;
11952
+ //#endregion
11953
+ //#region node_modules/vfile/lib/minurl.shared.js
11954
+ /**
11955
+ * Checks if a value has the shape of a WHATWG URL object.
11956
+ *
11957
+ * Using a symbol or instanceof would not be able to recognize URL objects
11958
+ * coming from other implementations (e.g. in Electron), so instead we are
11959
+ * checking some well known properties for a lack of a better test.
11960
+ *
11961
+ * We use `href` and `protocol` as they are the only properties that are
11962
+ * easy to retrieve and calculate due to the lazy nature of the getters.
11963
+ *
11964
+ * We check for auth attribute to distinguish legacy url instance with
11965
+ * WHATWG URL instance.
11966
+ *
11967
+ * @param {unknown} fileUrlOrPath
11968
+ * File path or URL.
11969
+ * @returns {fileUrlOrPath is URL}
11970
+ * Whether it’s a URL.
11971
+ */
11972
+ function isUrl(fileUrlOrPath) {
11973
+ return Boolean(fileUrlOrPath !== null && typeof fileUrlOrPath === "object" && "href" in fileUrlOrPath && fileUrlOrPath.href && "protocol" in fileUrlOrPath && fileUrlOrPath.protocol && fileUrlOrPath.auth === void 0);
11974
+ }
11975
+ //#endregion
11976
+ //#region node_modules/vfile/lib/index.js
11977
+ /**
11978
+ * @import {Node, Point, Position} from 'unist'
11979
+ * @import {Options as MessageOptions} from 'vfile-message'
11980
+ * @import {Compatible, Data, Map, Options, Value} from 'vfile'
11981
+ */
11982
+ /**
11983
+ * @typedef {object & {type: string, position?: Position | undefined}} NodeLike
11984
+ */
11985
+ /**
11986
+ * Order of setting (least specific to most), we need this because otherwise
11987
+ * `{stem: 'a', path: '~/b.js'}` would throw, as a path is needed before a
11988
+ * stem can be set.
11989
+ */
11990
+ const order = [
11991
+ "history",
11992
+ "path",
11993
+ "basename",
11994
+ "stem",
11995
+ "extname",
11996
+ "dirname"
11997
+ ];
11998
+ var VFile = class {
11999
+ /**
12000
+ * Create a new virtual file.
12001
+ *
12002
+ * `options` is treated as:
12003
+ *
12004
+ * * `string` or `Uint8Array` — `{value: options}`
12005
+ * * `URL` — `{path: options}`
12006
+ * * `VFile` — shallow copies its data over to the new file
12007
+ * * `object` — all fields are shallow copied over to the new file
12008
+ *
12009
+ * Path related fields are set in the following order (least specific to
12010
+ * most specific): `history`, `path`, `basename`, `stem`, `extname`,
12011
+ * `dirname`.
12012
+ *
12013
+ * You cannot set `dirname` or `extname` without setting either `history`,
12014
+ * `path`, `basename`, or `stem` too.
12015
+ *
12016
+ * @param {Compatible | null | undefined} [value]
12017
+ * File value.
12018
+ * @returns
12019
+ * New instance.
12020
+ */
12021
+ constructor(value) {
12022
+ /** @type {Options | VFile} */
12023
+ let options;
12024
+ if (!value) options = {};
12025
+ else if (isUrl(value)) options = { path: value };
12026
+ else if (typeof value === "string" || isUint8Array(value)) options = { value };
12027
+ else options = value;
12028
+ /**
12029
+ * Base of `path` (default: `process.cwd()` or `'/'` in browsers).
12030
+ *
12031
+ * @type {string}
12032
+ */
12033
+ this.cwd = "cwd" in options ? "" : node_process.default.cwd();
12034
+ /**
12035
+ * Place to store custom info (default: `{}`).
12036
+ *
12037
+ * It’s OK to store custom data directly on the file but moving it to
12038
+ * `data` is recommended.
12039
+ *
12040
+ * @type {Data}
12041
+ */
12042
+ this.data = {};
12043
+ /**
12044
+ * List of file paths the file moved between.
12045
+ *
12046
+ * The first is the original path and the last is the current path.
12047
+ *
12048
+ * @type {Array<string>}
12049
+ */
12050
+ this.history = [];
12051
+ /**
12052
+ * List of messages associated with the file.
12053
+ *
12054
+ * @type {Array<VFileMessage>}
12055
+ */
12056
+ this.messages = [];
12057
+ /**
12058
+ * Raw value.
12059
+ *
12060
+ * @type {Value}
12061
+ */
12062
+ this.value;
12063
+ /**
12064
+ * Source map.
12065
+ *
12066
+ * This type is equivalent to the `RawSourceMap` type from the `source-map`
12067
+ * module.
12068
+ *
12069
+ * @type {Map | null | undefined}
12070
+ */
12071
+ this.map;
12072
+ /**
12073
+ * Custom, non-string, compiled, representation.
12074
+ *
12075
+ * This is used by unified to store non-string results.
12076
+ * One example is when turning markdown into React nodes.
12077
+ *
12078
+ * @type {unknown}
12079
+ */
12080
+ this.result;
12081
+ /**
12082
+ * Whether a file was saved to disk.
12083
+ *
12084
+ * This is used by vfile reporters.
12085
+ *
12086
+ * @type {boolean}
12087
+ */
12088
+ this.stored;
12089
+ let index = -1;
12090
+ while (++index < order.length) {
12091
+ const field = order[index];
12092
+ if (field in options && options[field] !== void 0 && options[field] !== null) this[field] = field === "history" ? [...options[field]] : options[field];
12093
+ }
12094
+ /** @type {string} */
12095
+ let field;
12096
+ for (field in options) if (!order.includes(field)) this[field] = options[field];
12097
+ }
12098
+ /**
12099
+ * Get the basename (including extname) (example: `'index.min.js'`).
12100
+ *
12101
+ * @returns {string | undefined}
12102
+ * Basename.
12103
+ */
12104
+ get basename() {
12105
+ return typeof this.path === "string" ? node_path$1.default.basename(this.path) : void 0;
12106
+ }
12107
+ /**
12108
+ * Set basename (including extname) (`'index.min.js'`).
12109
+ *
12110
+ * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
12111
+ * on windows).
12112
+ * Cannot be nullified (use `file.path = file.dirname` instead).
12113
+ *
12114
+ * @param {string} basename
12115
+ * Basename.
12116
+ * @returns {undefined}
12117
+ * Nothing.
12118
+ */
12119
+ set basename(basename) {
12120
+ assertNonEmpty(basename, "basename");
12121
+ assertPart(basename, "basename");
12122
+ this.path = node_path$1.default.join(this.dirname || "", basename);
12123
+ }
12124
+ /**
12125
+ * Get the parent path (example: `'~'`).
12126
+ *
12127
+ * @returns {string | undefined}
12128
+ * Dirname.
12129
+ */
12130
+ get dirname() {
12131
+ return typeof this.path === "string" ? node_path$1.default.dirname(this.path) : void 0;
12132
+ }
12133
+ /**
12134
+ * Set the parent path (example: `'~'`).
12135
+ *
12136
+ * Cannot be set if there’s no `path` yet.
12137
+ *
12138
+ * @param {string | undefined} dirname
12139
+ * Dirname.
12140
+ * @returns {undefined}
12141
+ * Nothing.
12142
+ */
12143
+ set dirname(dirname) {
12144
+ assertPath(this.basename, "dirname");
12145
+ this.path = node_path$1.default.join(dirname || "", this.basename);
12146
+ }
12147
+ /**
12148
+ * Get the extname (including dot) (example: `'.js'`).
12149
+ *
12150
+ * @returns {string | undefined}
12151
+ * Extname.
12152
+ */
12153
+ get extname() {
12154
+ return typeof this.path === "string" ? node_path$1.default.extname(this.path) : void 0;
12155
+ }
12156
+ /**
12157
+ * Set the extname (including dot) (example: `'.js'`).
12158
+ *
12159
+ * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
12160
+ * on windows).
12161
+ * Cannot be set if there’s no `path` yet.
12162
+ *
12163
+ * @param {string | undefined} extname
12164
+ * Extname.
12165
+ * @returns {undefined}
12166
+ * Nothing.
12167
+ */
12168
+ set extname(extname) {
12169
+ assertPart(extname, "extname");
12170
+ assertPath(this.dirname, "extname");
12171
+ if (extname) {
12172
+ if (extname.codePointAt(0) !== 46) throw new Error("`extname` must start with `.`");
12173
+ if (extname.includes(".", 1)) throw new Error("`extname` cannot contain multiple dots");
12174
+ }
12175
+ this.path = node_path$1.default.join(this.dirname, this.stem + (extname || ""));
12176
+ }
12177
+ /**
12178
+ * Get the full path (example: `'~/index.min.js'`).
12179
+ *
12180
+ * @returns {string}
12181
+ * Path.
12182
+ */
12183
+ get path() {
12184
+ return this.history[this.history.length - 1];
12185
+ }
12186
+ /**
12187
+ * Set the full path (example: `'~/index.min.js'`).
12188
+ *
12189
+ * Cannot be nullified.
12190
+ * You can set a file URL (a `URL` object with a `file:` protocol) which will
12191
+ * be turned into a path with `url.fileURLToPath`.
12192
+ *
12193
+ * @param {URL | string} path
12194
+ * Path.
12195
+ * @returns {undefined}
12196
+ * Nothing.
12197
+ */
12198
+ set path(path) {
12199
+ if (isUrl(path)) path = (0, node_url.fileURLToPath)(path);
12200
+ assertNonEmpty(path, "path");
12201
+ if (this.path !== path) this.history.push(path);
12202
+ }
12203
+ /**
12204
+ * Get the stem (basename w/o extname) (example: `'index.min'`).
12205
+ *
12206
+ * @returns {string | undefined}
12207
+ * Stem.
12208
+ */
12209
+ get stem() {
12210
+ return typeof this.path === "string" ? node_path$1.default.basename(this.path, this.extname) : void 0;
12211
+ }
12212
+ /**
12213
+ * Set the stem (basename w/o extname) (example: `'index.min'`).
12214
+ *
12215
+ * Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
12216
+ * on windows).
12217
+ * Cannot be nullified (use `file.path = file.dirname` instead).
12218
+ *
12219
+ * @param {string} stem
12220
+ * Stem.
12221
+ * @returns {undefined}
12222
+ * Nothing.
12223
+ */
12224
+ set stem(stem) {
12225
+ assertNonEmpty(stem, "stem");
12226
+ assertPart(stem, "stem");
12227
+ this.path = node_path$1.default.join(this.dirname || "", stem + (this.extname || ""));
12228
+ }
12229
+ /**
12230
+ * Create a fatal message for `reason` associated with the file.
12231
+ *
12232
+ * The `fatal` field of the message is set to `true` (error; file not usable)
12233
+ * and the `file` field is set to the current file path.
12234
+ * The message is added to the `messages` field on `file`.
12235
+ *
12236
+ * > 🪦 **Note**: also has obsolete signatures.
12237
+ *
12238
+ * @overload
12239
+ * @param {string} reason
12240
+ * @param {MessageOptions | null | undefined} [options]
12241
+ * @returns {never}
12242
+ *
12243
+ * @overload
12244
+ * @param {string} reason
12245
+ * @param {Node | NodeLike | null | undefined} parent
12246
+ * @param {string | null | undefined} [origin]
12247
+ * @returns {never}
12248
+ *
12249
+ * @overload
12250
+ * @param {string} reason
12251
+ * @param {Point | Position | null | undefined} place
12252
+ * @param {string | null | undefined} [origin]
12253
+ * @returns {never}
12254
+ *
12255
+ * @overload
12256
+ * @param {string} reason
12257
+ * @param {string | null | undefined} [origin]
12258
+ * @returns {never}
12259
+ *
12260
+ * @overload
12261
+ * @param {Error | VFileMessage} cause
12262
+ * @param {Node | NodeLike | null | undefined} parent
12263
+ * @param {string | null | undefined} [origin]
12264
+ * @returns {never}
12265
+ *
12266
+ * @overload
12267
+ * @param {Error | VFileMessage} cause
12268
+ * @param {Point | Position | null | undefined} place
12269
+ * @param {string | null | undefined} [origin]
12270
+ * @returns {never}
12271
+ *
12272
+ * @overload
12273
+ * @param {Error | VFileMessage} cause
12274
+ * @param {string | null | undefined} [origin]
12275
+ * @returns {never}
12276
+ *
12277
+ * @param {Error | VFileMessage | string} causeOrReason
12278
+ * Reason for message, should use markdown.
12279
+ * @param {Node | NodeLike | MessageOptions | Point | Position | string | null | undefined} [optionsOrParentOrPlace]
12280
+ * Configuration (optional).
12281
+ * @param {string | null | undefined} [origin]
12282
+ * Place in code where the message originates (example:
12283
+ * `'my-package:my-rule'` or `'my-rule'`).
12284
+ * @returns {never}
12285
+ * Never.
12286
+ * @throws {VFileMessage}
12287
+ * Message.
12288
+ */
12289
+ fail(causeOrReason, optionsOrParentOrPlace, origin) {
12290
+ const message = this.message(causeOrReason, optionsOrParentOrPlace, origin);
12291
+ message.fatal = true;
12292
+ throw message;
12293
+ }
12294
+ /**
12295
+ * Create an info message for `reason` associated with the file.
12296
+ *
12297
+ * The `fatal` field of the message is set to `undefined` (info; change
12298
+ * likely not needed) and the `file` field is set to the current file path.
12299
+ * The message is added to the `messages` field on `file`.
12300
+ *
12301
+ * > 🪦 **Note**: also has obsolete signatures.
12302
+ *
12303
+ * @overload
12304
+ * @param {string} reason
12305
+ * @param {MessageOptions | null | undefined} [options]
12306
+ * @returns {VFileMessage}
12307
+ *
12308
+ * @overload
12309
+ * @param {string} reason
12310
+ * @param {Node | NodeLike | null | undefined} parent
12311
+ * @param {string | null | undefined} [origin]
12312
+ * @returns {VFileMessage}
12313
+ *
12314
+ * @overload
12315
+ * @param {string} reason
12316
+ * @param {Point | Position | null | undefined} place
12317
+ * @param {string | null | undefined} [origin]
12318
+ * @returns {VFileMessage}
12319
+ *
12320
+ * @overload
12321
+ * @param {string} reason
12322
+ * @param {string | null | undefined} [origin]
12323
+ * @returns {VFileMessage}
12324
+ *
12325
+ * @overload
12326
+ * @param {Error | VFileMessage} cause
12327
+ * @param {Node | NodeLike | null | undefined} parent
12328
+ * @param {string | null | undefined} [origin]
12329
+ * @returns {VFileMessage}
12330
+ *
12331
+ * @overload
12332
+ * @param {Error | VFileMessage} cause
12333
+ * @param {Point | Position | null | undefined} place
12334
+ * @param {string | null | undefined} [origin]
12335
+ * @returns {VFileMessage}
12336
+ *
12337
+ * @overload
12338
+ * @param {Error | VFileMessage} cause
12339
+ * @param {string | null | undefined} [origin]
12340
+ * @returns {VFileMessage}
12341
+ *
12342
+ * @param {Error | VFileMessage | string} causeOrReason
12343
+ * Reason for message, should use markdown.
12344
+ * @param {Node | NodeLike | MessageOptions | Point | Position | string | null | undefined} [optionsOrParentOrPlace]
12345
+ * Configuration (optional).
12346
+ * @param {string | null | undefined} [origin]
12347
+ * Place in code where the message originates (example:
12348
+ * `'my-package:my-rule'` or `'my-rule'`).
12349
+ * @returns {VFileMessage}
12350
+ * Message.
12351
+ */
12352
+ info(causeOrReason, optionsOrParentOrPlace, origin) {
12353
+ const message = this.message(causeOrReason, optionsOrParentOrPlace, origin);
12354
+ message.fatal = void 0;
12355
+ return message;
12356
+ }
12357
+ /**
12358
+ * Create a message for `reason` associated with the file.
12359
+ *
12360
+ * The `fatal` field of the message is set to `false` (warning; change may be
12361
+ * needed) and the `file` field is set to the current file path.
12362
+ * The message is added to the `messages` field on `file`.
12363
+ *
12364
+ * > 🪦 **Note**: also has obsolete signatures.
12365
+ *
12366
+ * @overload
12367
+ * @param {string} reason
12368
+ * @param {MessageOptions | null | undefined} [options]
12369
+ * @returns {VFileMessage}
12370
+ *
12371
+ * @overload
12372
+ * @param {string} reason
12373
+ * @param {Node | NodeLike | null | undefined} parent
12374
+ * @param {string | null | undefined} [origin]
12375
+ * @returns {VFileMessage}
12376
+ *
12377
+ * @overload
12378
+ * @param {string} reason
12379
+ * @param {Point | Position | null | undefined} place
12380
+ * @param {string | null | undefined} [origin]
12381
+ * @returns {VFileMessage}
12382
+ *
12383
+ * @overload
12384
+ * @param {string} reason
12385
+ * @param {string | null | undefined} [origin]
12386
+ * @returns {VFileMessage}
12387
+ *
12388
+ * @overload
12389
+ * @param {Error | VFileMessage} cause
12390
+ * @param {Node | NodeLike | null | undefined} parent
12391
+ * @param {string | null | undefined} [origin]
12392
+ * @returns {VFileMessage}
12393
+ *
12394
+ * @overload
12395
+ * @param {Error | VFileMessage} cause
12396
+ * @param {Point | Position | null | undefined} place
12397
+ * @param {string | null | undefined} [origin]
12398
+ * @returns {VFileMessage}
12399
+ *
12400
+ * @overload
12401
+ * @param {Error | VFileMessage} cause
12402
+ * @param {string | null | undefined} [origin]
12403
+ * @returns {VFileMessage}
12404
+ *
12405
+ * @param {Error | VFileMessage | string} causeOrReason
12406
+ * Reason for message, should use markdown.
12407
+ * @param {Node | NodeLike | MessageOptions | Point | Position | string | null | undefined} [optionsOrParentOrPlace]
12408
+ * Configuration (optional).
12409
+ * @param {string | null | undefined} [origin]
12410
+ * Place in code where the message originates (example:
12411
+ * `'my-package:my-rule'` or `'my-rule'`).
12412
+ * @returns {VFileMessage}
12413
+ * Message.
12414
+ */
12415
+ message(causeOrReason, optionsOrParentOrPlace, origin) {
12416
+ const message = new VFileMessage(causeOrReason, optionsOrParentOrPlace, origin);
12417
+ if (this.path) {
12418
+ message.name = this.path + ":" + message.name;
12419
+ message.file = this.path;
12420
+ }
12421
+ message.fatal = false;
12422
+ this.messages.push(message);
12423
+ return message;
12424
+ }
12425
+ /**
12426
+ * Serialize the file.
12427
+ *
12428
+ * > **Note**: which encodings are supported depends on the engine.
12429
+ * > For info on Node.js, see:
12430
+ * > <https://nodejs.org/api/util.html#whatwg-supported-encodings>.
12431
+ *
12432
+ * @param {string | null | undefined} [encoding='utf8']
12433
+ * Character encoding to understand `value` as when it’s a `Uint8Array`
12434
+ * (default: `'utf-8'`).
12435
+ * @returns {string}
12436
+ * Serialized file.
12437
+ */
12438
+ toString(encoding) {
12439
+ if (this.value === void 0) return "";
12440
+ if (typeof this.value === "string") return this.value;
12441
+ return new TextDecoder(encoding || void 0).decode(this.value);
12442
+ }
12443
+ };
12444
+ /**
12445
+ * Assert that `part` is not a path (as in, does not contain `path.sep`).
12446
+ *
12447
+ * @param {string | null | undefined} part
12448
+ * File path part.
12449
+ * @param {string} name
12450
+ * Part name.
12451
+ * @returns {undefined}
12452
+ * Nothing.
12453
+ */
12454
+ function assertPart(part, name) {
12455
+ if (part && part.includes(node_path$1.default.sep)) throw new Error("`" + name + "` cannot be a path: did not expect `" + node_path$1.default.sep + "`");
12456
+ }
12457
+ /**
12458
+ * Assert that `part` is not empty.
12459
+ *
12460
+ * @param {string | undefined} part
12461
+ * Thing.
12462
+ * @param {string} name
12463
+ * Part name.
12464
+ * @returns {asserts part is string}
12465
+ * Nothing.
12466
+ */
12467
+ function assertNonEmpty(part, name) {
12468
+ if (!part) throw new Error("`" + name + "` cannot be empty");
12469
+ }
12470
+ /**
12471
+ * Assert `path` exists.
12472
+ *
12473
+ * @param {string | undefined} path
12474
+ * Path.
12475
+ * @param {string} name
12476
+ * Dependency name.
12477
+ * @returns {asserts path is string}
12478
+ * Nothing.
12479
+ */
12480
+ function assertPath(path, name) {
12481
+ if (!path) throw new Error("Setting `" + name + "` requires `path` to be set too");
12482
+ }
12483
+ /**
12484
+ * Assert `value` is an `Uint8Array`.
12485
+ *
12486
+ * @param {unknown} value
12487
+ * thing.
12488
+ * @returns {value is Uint8Array}
12489
+ * Whether `value` is an `Uint8Array`.
12490
+ */
12491
+ function isUint8Array(value) {
12492
+ return Boolean(value && typeof value === "object" && "byteLength" in value && "byteOffset" in value);
12493
+ }
12494
+ //#endregion
11641
12495
  //#region src/plugins/content/pipeline/frontmatter.ts
11642
12496
  /**
11643
12497
  * @file content pipeline — frontmatter parsing.
@@ -11808,7 +12662,7 @@ function parseDimensions(width, height) {
11808
12662
  * collectAttributes({ src: "x", poster: "/p.jpg", flag: null }); // { src: "x", poster: "/p.jpg" }
11809
12663
  * ```
11810
12664
  */
11811
- function collectAttributes(attributes) {
12665
+ function collectAttributes$1(attributes) {
11812
12666
  const out = {};
11813
12667
  for (const [key, value] of Object.entries(attributes ?? {})) if (typeof value === "string") out[key] = value;
11814
12668
  return out;
@@ -11881,7 +12735,7 @@ function embedTransform(facade, tree) {
11881
12735
  width: dimensions.width,
11882
12736
  height: dimensions.height
11883
12737
  } : {},
11884
- attributes: collectAttributes(node.attributes)
12738
+ attributes: collectAttributes$1(node.attributes)
11885
12739
  }, dimensions)
11886
12740
  };
11887
12741
  parent.children[index] = html;
@@ -11907,6 +12761,246 @@ function embedPlugin(options = {}) {
11907
12761
  return (tree) => embedTransform(facade, tree);
11908
12762
  }
11909
12763
  //#endregion
12764
+ //#region src/plugins/content/pipeline/gallery-default.tsx
12765
+ /** CSS class on the gallery's slide track. */
12766
+ const GALLERY_TRACK_CLASS = "gallery-track";
12767
+ /**
12768
+ * Default `::gallery` inner content: a single track holding every slide `<img>`
12769
+ * in folder order. A companion gallery island (consumer-provided) can enhance
12770
+ * the track with swipe/keyboard/lightbox; with no island and no CSS it is still
12771
+ * a plain horizontally-scrollable image strip. Provided as the default and as a
12772
+ * composable building block for custom galleries.
12773
+ *
12774
+ * @param props - The gallery props (the resolved `slides`).
12775
+ * @returns The gallery inner-content VNode.
12776
+ * @example
12777
+ * ```tsx
12778
+ * // Compose the default inside a richer custom gallery:
12779
+ * const MyGallery = (p: GalleryProps) => (
12780
+ * <figure><GalleryTrack {...p} /><figcaption>{p.caption}</figcaption></figure>
12781
+ * );
12782
+ * ```
12783
+ */
12784
+ function GalleryTrack(props) {
12785
+ return /* @__PURE__ */ (0, preact_jsx_runtime.jsx)("div", {
12786
+ class: GALLERY_TRACK_CLASS,
12787
+ "data-gallery-track": true,
12788
+ children: props.slides.map((slide) => /* @__PURE__ */ (0, preact_jsx_runtime.jsx)("img", {
12789
+ src: slide.src,
12790
+ alt: slide.alt
12791
+ }, slide.src))
12792
+ });
12793
+ }
12794
+ //#endregion
12795
+ //#region src/plugins/content/pipeline/gallery.ts
12796
+ /**
12797
+ * @file content pipeline — `::gallery` folder galleries.
12798
+ *
12799
+ * Rewrites `::gallery{src="./images/dir/" caption="…"}` leaf directives into a
12800
+ * static swipeable image set at the mdast stage (BEFORE the remark-rehype bridge):
12801
+ * a framework-owned `<div class="gallery" data-component="gallery">` carrying the
12802
+ * island hook, wrapping inner content rendered (at build time, to static markup)
12803
+ * by a Preact component — the built-in {@link GalleryTrack} by default, or a
12804
+ * consumer component via `gallery.component`.
12805
+ *
12806
+ * Unlike `::embed` (one src resolved later by the provider), a gallery's `src` is a
12807
+ * co-located FOLDER that must be listed at build time, which needs the article's
12808
+ * source path. The provider supplies the article `slug` via the VFile `data`
12809
+ * (providers.ts), and the `contentDir` is bound at pipeline-build time — so this
12810
+ * transform reads `<contentDir>/<slug>/<src>` from disk, sorts its images, and
12811
+ * resolves each to its shared `/<slug>/<dir>/<file>` URL (identical from every
12812
+ * locale page, mirroring co-located images). The companion gallery SPA island
12813
+ * (consumer-provided) wires swipe/keyboard/lightbox on `[data-component="gallery"]`.
12814
+ */
12815
+ /** CSS class on the `<div>` wrapping each gallery. */
12816
+ const GALLERY_WRAPPER_CLASS = "gallery";
12817
+ /** `data-component` name binding the gallery to its SPA island. */
12818
+ const GALLERY_COMPONENT_NAME = "gallery";
12819
+ /** Image file extensions a gallery folder expands over. */
12820
+ const IMAGE_EXTENSIONS = new Set([
12821
+ ".webp",
12822
+ ".jpg",
12823
+ ".jpeg",
12824
+ ".png",
12825
+ ".gif",
12826
+ ".avif"
12827
+ ]);
12828
+ /**
12829
+ * Type guard for a `::gallery` leaf directive.
12830
+ *
12831
+ * @param node - AST node to test.
12832
+ * @returns `true` when the node is a `::gallery` leaf directive.
12833
+ * @example
12834
+ * ```ts
12835
+ * if (isGalleryDirective(node)) console.log(node.attributes?.src);
12836
+ * ```
12837
+ */
12838
+ function isGalleryDirective(node) {
12839
+ return node.type === "leafDirective" && node.name === "gallery";
12840
+ }
12841
+ /**
12842
+ * Resolve `.`/`..` segments of a path built from `slug/src/file` into the single
12843
+ * shared absolute URL the content-assets build phase copies the folder to.
12844
+ *
12845
+ * @param slug - Article directory name.
12846
+ * @param src - The directive `src` (co-located relative folder, e.g. `./images/dir/`).
12847
+ * @param file - One image file name inside the folder.
12848
+ * @returns The shared absolute slide URL (`/<slug>/<dir>/<file>`).
12849
+ * @example
12850
+ * ```ts
12851
+ * slideUrl("post", "./images/mk/", "a.webp"); // "/post/images/mk/a.webp"
12852
+ * ```
12853
+ */
12854
+ function slideUrl(slug, src, file) {
12855
+ const resolved = [];
12856
+ for (const segment of `${slug}/${src}/${file}`.split("/")) {
12857
+ if (segment === "" || segment === ".") continue;
12858
+ if (segment === "..") resolved.pop();
12859
+ else resolved.push(segment);
12860
+ }
12861
+ return `/${resolved.join("/")}`;
12862
+ }
12863
+ /**
12864
+ * Read a gallery folder from disk and build its sorted slide list. Each slide
12865
+ * gets the directive `caption` plus a ` · N` index suffix as alt (or just `N`).
12866
+ *
12867
+ * @param contentDir - The provider's content directory.
12868
+ * @param slug - Article directory name (from the VFile data).
12869
+ * @param src - The directive `src` (co-located relative folder).
12870
+ * @param caption - The directive `caption` attribute (may be empty).
12871
+ * @returns The sorted slides.
12872
+ * @throws {Error} When the folder is missing or holds no images.
12873
+ * @example
12874
+ * ```ts
12875
+ * resolveSlides("./content", "post", "./images/mk/", "Our game");
12876
+ * ```
12877
+ */
12878
+ function resolveSlides(contentDir, slug, src, caption) {
12879
+ const folder = node_path$1.default.join(contentDir, slug, src);
12880
+ let entries;
12881
+ try {
12882
+ entries = (0, node_fs.readdirSync)(folder);
12883
+ } catch {
12884
+ throw new Error(`[web] content: \`::gallery\` folder not found: "${src}" (looked in ${folder}).`);
12885
+ }
12886
+ const files = entries.filter((name) => IMAGE_EXTENSIONS.has(node_path$1.default.extname(name).toLowerCase())).toSorted((a, b) => a.localeCompare(b, "en"));
12887
+ if (files.length === 0) throw new Error(`[web] content: \`::gallery\` folder has no images: "${src}" (${folder}).`);
12888
+ return files.map((file, index) => ({
12889
+ src: slideUrl(slug, src, file),
12890
+ alt: caption ? `${caption} · ${index + 1}` : `${index + 1}`
12891
+ }));
12892
+ }
12893
+ /**
12894
+ * Collect the directive's raw attribute bag into a plain string record, dropping
12895
+ * `null`/`undefined` values (so a custom component can read arbitrary extra options).
12896
+ *
12897
+ * @param attributes - The raw directive attributes (or undefined).
12898
+ * @returns A string-valued attribute record.
12899
+ * @example
12900
+ * ```ts
12901
+ * collectAttributes({ src: "x", layout: "dots", flag: null }); // { src: "x", layout: "dots" }
12902
+ * ```
12903
+ */
12904
+ function collectAttributes(attributes) {
12905
+ const out = {};
12906
+ for (const [key, value] of Object.entries(attributes ?? {})) if (typeof value === "string") out[key] = value;
12907
+ return out;
12908
+ }
12909
+ /**
12910
+ * Build the static gallery HTML for one directive: the framework-owned `<div>`
12911
+ * (island hook in `data-component`) wrapping the component's inner content, SSR'd
12912
+ * to static markup.
12913
+ *
12914
+ * @param component - The gallery component (default {@link GalleryTrack}).
12915
+ * @param slides - The resolved slides.
12916
+ * @param caption - The directive `caption` attribute.
12917
+ * @param attributes - The raw directive attribute bag.
12918
+ * @returns The gallery HTML string.
12919
+ * @example
12920
+ * ```ts
12921
+ * galleryHtml(GalleryTrack, slides, "Our game", { src: "./images/mk/" });
12922
+ * ```
12923
+ */
12924
+ function galleryHtml(component, slides, caption, attributes) {
12925
+ return `<div class="${GALLERY_WRAPPER_CLASS}" data-component="${GALLERY_COMPONENT_NAME}">${(0, preact_render_to_string.renderToString)((0, preact.h)(component, {
12926
+ slides,
12927
+ caption,
12928
+ attributes
12929
+ }))}</div>`;
12930
+ }
12931
+ /**
12932
+ * Mdast transformer rewriting every `::gallery` leaf directive to its gallery
12933
+ * HTML node. A directive missing `src`, or pointing at a missing/empty folder,
12934
+ * fails the build with the offending value quoted. Skipped entirely when the
12935
+ * VFile carries no `slug` (the standalone `render()` path has no article context).
12936
+ *
12937
+ * @param options - Resolved transform options (component + contentDir).
12938
+ * @param tree - The mdast tree to mutate.
12939
+ * @param file - The VFile (its `data.slug` locates the article on disk).
12940
+ * @throws {Error} When a `::gallery` directive is missing `src`, or its folder is
12941
+ * missing/empty.
12942
+ * @example
12943
+ * ```ts
12944
+ * galleryTransform({ component: GalleryTrack, contentDir: "./content" }, tree, file);
12945
+ * ```
12946
+ */
12947
+ function galleryTransform(options, tree, file) {
12948
+ const slug = typeof file.data.slug === "string" ? file.data.slug : void 0;
12949
+ const component = options.component ?? GalleryTrack;
12950
+ (0, unist_util_visit.visit)(tree, (node, index, parent) => {
12951
+ if (!isGalleryDirective(node)) return;
12952
+ if (parent === void 0 || index === void 0) return;
12953
+ if (slug === void 0) return;
12954
+ const src = node.attributes?.src ?? "";
12955
+ if (src === "") throw new Error("[web] content: `::gallery` requires a `src` folder, e.g. ::gallery{src=\"./images/dir/\"}.");
12956
+ const caption = node.attributes?.caption ?? "";
12957
+ const html = {
12958
+ type: "html",
12959
+ value: galleryHtml(component, resolveSlides(options.contentDir, slug, src, caption), caption, collectAttributes(node.attributes))
12960
+ };
12961
+ parent.children[index] = html;
12962
+ });
12963
+ }
12964
+ /**
12965
+ * Normalize the provider's `gallery` config value (`boolean | options`) plus the
12966
+ * provider `contentDir` into the resolved {@link GalleryTransformOptions} the
12967
+ * transform factory needs.
12968
+ *
12969
+ * @param gallery - The raw `FileSystemContentOptions.gallery` value (truthy).
12970
+ * @param contentDir - The provider's content directory.
12971
+ * @returns The resolved transform options.
12972
+ * @example
12973
+ * ```ts
12974
+ * normalizeGalleryOptions(true, "./content"); // { contentDir: "./content" }
12975
+ * normalizeGalleryOptions({ component: MyGallery }, "./content");
12976
+ * ```
12977
+ */
12978
+ function normalizeGalleryOptions(gallery, contentDir) {
12979
+ return typeof gallery === "boolean" ? { contentDir } : {
12980
+ ...gallery,
12981
+ contentDir
12982
+ };
12983
+ }
12984
+ /**
12985
+ * Remark transform factory: rewrites `::gallery{src="…"}` leaf directives into
12986
+ * static swipeable galleries (see the file header). Opt-in via the provider's
12987
+ * `gallery` option; requires `trustedContent: true` because the markup is raw HTML
12988
+ * the sanitize pass would strip. The inner content is rendered by
12989
+ * `options.component` (a consumer Preact component) or the built-in
12990
+ * {@link GalleryTrack}; folders are read from `options.contentDir` against the
12991
+ * per-article `slug` on the VFile.
12992
+ *
12993
+ * @param options - Resolved transform options (component + contentDir).
12994
+ * @returns An mdast tree transformer.
12995
+ * @example
12996
+ * ```ts
12997
+ * unified().use(galleryPlugin, { component: MyGallery, contentDir: "./content" });
12998
+ * ```
12999
+ */
13000
+ function galleryPlugin(options) {
13001
+ return (tree, file) => galleryTransform(options, tree, file);
13002
+ }
13003
+ //#endregion
11910
13004
  //#region src/plugins/content/pipeline/mermaid.ts
11911
13005
  /** CSS class on the `<figure>` wrapper around each rendered diagram. */
11912
13006
  const MERMAID_FIGURE_CLASS = "mermaid-diagram";
@@ -12216,6 +13310,7 @@ function defaultRemarkPlugins(config) {
12216
13310
  pullQuotePlugin
12217
13311
  ];
12218
13312
  if (config?.embed) plugins.push([embedPlugin, normalizeEmbedOptions(config.embed)]);
13313
+ if (config?.gallery) plugins.push([galleryPlugin, normalizeGalleryOptions(config.gallery, config.contentDir)]);
12219
13314
  if (config?.mermaid) plugins.push([remarkMermaidDiagrams, normalizeMermaidOptions(config.mermaid)]);
12220
13315
  plugins.push([remark_rehype.default, { allowDangerousHtml: true }]);
12221
13316
  return plugins;
@@ -12617,7 +13712,10 @@ function fileSystemContent(options) {
12617
13712
  state.dirtyPaths.delete(filePath);
12618
13713
  const { frontmatter, body } = parseFrontmatter(raw, options);
12619
13714
  const processor = ensureProcessor(state, options);
12620
- const html = rewriteEmbedUrls(rewriteImageUrls(String(await processor.process(body)), slug), slug);
13715
+ const html = rewriteEmbedUrls(rewriteImageUrls(String(await processor.process(new VFile({
13716
+ value: body,
13717
+ data: { slug }
13718
+ }))), slug), slug);
12621
13719
  const { readingTime, wordCount } = calculateReadingTime(body);
12622
13720
  return {
12623
13721
  frontmatter,
@@ -12778,6 +13876,7 @@ Object.defineProperty(exports, "Env", {
12778
13876
  return types_exports$5;
12779
13877
  }
12780
13878
  });
13879
+ exports.GalleryTrack = GalleryTrack;
12781
13880
  Object.defineProperty(exports, "Head", {
12782
13881
  enumerable: true,
12783
13882
  get: function() {