@wdprlib/ast 2.1.0 → 2.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/dist/index.cjs CHANGED
@@ -54,7 +54,8 @@ __export(exports_src, {
54
54
  container: () => container,
55
55
  bold: () => bold,
56
56
  STYLE_SLOT_PREFIX: () => STYLE_SLOT_PREFIX,
57
- DEFAULT_SETTINGS: () => DEFAULT_SETTINGS
57
+ DEFAULT_SETTINGS: () => DEFAULT_SETTINGS,
58
+ CSS_LENGTH_UNITS: () => CSS_LENGTH_UNITS
58
59
  });
59
60
  module.exports = __toCommonJS(exports_src);
60
61
 
@@ -253,6 +254,59 @@ function isParagraphSafe(element) {
253
254
  }
254
255
  // packages/ast/src/constants.ts
255
256
  var STYLE_SLOT_PREFIX = "\x00__IFTAGS_SLOT__";
257
+ // packages/ast/src/css.ts
258
+ var CSS_LENGTH_UNITS = [
259
+ "cqmax",
260
+ "cqmin",
261
+ "cqw",
262
+ "cqh",
263
+ "cqi",
264
+ "cqb",
265
+ "svmin",
266
+ "svmax",
267
+ "lvmin",
268
+ "lvmax",
269
+ "dvmin",
270
+ "dvmax",
271
+ "vmin",
272
+ "vmax",
273
+ "svw",
274
+ "svh",
275
+ "svi",
276
+ "svb",
277
+ "lvw",
278
+ "lvh",
279
+ "lvi",
280
+ "lvb",
281
+ "dvw",
282
+ "dvh",
283
+ "dvi",
284
+ "dvb",
285
+ "vw",
286
+ "vh",
287
+ "vi",
288
+ "vb",
289
+ "rcap",
290
+ "rem",
291
+ "rex",
292
+ "rch",
293
+ "ric",
294
+ "rlh",
295
+ "cap",
296
+ "em",
297
+ "ex",
298
+ "ch",
299
+ "ic",
300
+ "lh",
301
+ "cm",
302
+ "mm",
303
+ "in",
304
+ "pc",
305
+ "pt",
306
+ "px",
307
+ "q",
308
+ "%"
309
+ ];
256
310
  // packages/ast/src/expr-eval.ts
257
311
  var FALSE_VALUES = new Set(["false", "null", "", "0"]);
258
312
  function isTruthy(value) {
package/dist/index.d.cts CHANGED
@@ -64,22 +64,29 @@ declare function createPoint(line: number, column: number, offset: number): Poin
64
64
  */
65
65
  declare function createPosition(start: Point, end: Point): Position;
66
66
  /**
67
- * AST element types for Wikidot markup.
67
+ * Shared CSS value definitions used across parser and renderer.
68
68
  *
69
- * Wikidot markup (`+ heading`, `**bold**`, `[[module ListPages]]`, etc.) is parsed into
70
- * a structured representation defined here. Each {@link Element} is a tagged union of
71
- * `{ element: tag, data: payload }`, where the data shape for each tag is defined in
72
- * {@link ElementDataMap}.
69
+ * @module
70
+ */
71
+ /**
72
+ * All CSS length units (plus percentage) accepted where Wikidot markup
73
+ * takes a size value.
73
74
  *
74
- * @example
75
- * ```ts
76
- * import { parse } from "@wdprlib/parser";
77
- * const tree = parse("**Hello** world");
78
- * // tree.elements[0] → { element: "container", data: { type: "paragraph", ... } }
79
- * ```
75
+ * This is intentionally a superset of what legacy Wikidot accepts: wdpr
76
+ * extends size validation to modern CSS units (viewport, container-query,
77
+ * and root-relative units) instead of mirroring Wikidot's historical
78
+ * `px|em|%` allowlists. Units are canonicalized to lowercase.
80
79
  *
81
- * @module
80
+ * @group CSS
81
+ */
82
+ declare const CSS_LENGTH_UNITS: readonly ["cqmax", "cqmin", "cqw", "cqh", "cqi", "cqb", "svmin", "svmax", "lvmin", "lvmax", "dvmin", "dvmax", "vmin", "vmax", "svw", "svh", "svi", "svb", "lvw", "lvh", "lvi", "lvb", "dvw", "dvh", "dvi", "dvb", "vw", "vh", "vi", "vb", "rcap", "rem", "rex", "rch", "ric", "rlh", "cap", "em", "ex", "ch", "ic", "lh", "cm", "mm", "in", "pc", "pt", "px", "q", "%"];
83
+ /**
84
+ * A CSS length unit (or percentage) accepted in size values,
85
+ * canonicalized to lowercase.
86
+ *
87
+ * @group CSS
82
88
  */
89
+ type CssLengthUnit = (typeof CSS_LENGTH_UNITS)[number];
83
90
  /**
84
91
  * Key-value map of HTML attributes.
85
92
  * Populated from the Wikidot `_ class="foo" style="color:red"` attribute syntax.
@@ -488,6 +495,25 @@ type Module = {
488
495
  } | {
489
496
  /** `[[module Rate]]` — page rating widget */
490
497
  module: "rate";
498
+ } | {
499
+ /** `[[module TagCloud]]` — weighted cloud of page tags */
500
+ module: "tag-cloud";
501
+ /** Numeric part of the font size for the lightest-weighted tag */
502
+ "min-font-size": number;
503
+ /** Numeric part of the font size for the heaviest-weighted tag */
504
+ "max-font-size": number;
505
+ /** Unit shared by both font sizes (lowercase) */
506
+ "font-size-unit": CssLengthUnit;
507
+ /** RGB components for the lightest-weighted tag */
508
+ "min-color": [number, number, number];
509
+ /** RGB components for the heaviest-weighted tag */
510
+ "max-color": [number, number, number];
511
+ /** Normalized link target prefix, always ending with `/tag/` */
512
+ target: string;
513
+ /** Maximum number of tags to display */
514
+ limit: number;
515
+ /** Category filter, or null for all categories */
516
+ category: string | null;
491
517
  } | {
492
518
  /** `[[module ListUsers]]` — user listing with template body */
493
519
  module: "list-users";
@@ -616,6 +642,78 @@ interface ImageData {
616
642
  attributes: AttributeMap;
617
643
  }
618
644
  /**
645
+ * Image size keyword accepted by `[[gallery]]`.
646
+ * Invalid or missing values fall back to `"thumbnail"` at parse time,
647
+ * matching the Wikidot renderer.
648
+ *
649
+ * @group Element Data
650
+ */
651
+ type GallerySize = "small" | "medium" | "thumbnail" | "square" | "original";
652
+ /**
653
+ * Sort order for auto-collected gallery files, normalized at parse time.
654
+ * Deprecated Wikidot aliases (`nameDesc`, `dateAdded`, `dateAddedDesc`) and
655
+ * the ListPages-style `"... desc desc"` forms are folded into these four
656
+ * values. Only meaningful for the content-less (auto) form.
657
+ *
658
+ * @group Element Data
659
+ */
660
+ type GalleryOrder = "name" | "name desc" | "created_at" | "created_at desc";
661
+ /**
662
+ * A single `: source link="..." alt="..."` entry inside `[[gallery]]`.
663
+ *
664
+ * @group Element Data
665
+ */
666
+ interface GalleryItem {
667
+ /**
668
+ * Raw image source string with any leading `*` removed.
669
+ * Classification follows the Wikidot rules and happens at render time:
670
+ * a source containing `://` is external, one containing `/` refers to
671
+ * another page's file, anything else is a file on the current page.
672
+ */
673
+ source: string;
674
+ /**
675
+ * Link target with any leading `*` removed, or null when the item has no
676
+ * `link` attribute.
677
+ */
678
+ link: string | null;
679
+ /** Alternative text for the image, or null when no `alt` attribute is given */
680
+ alt: string | null;
681
+ /** true if the link opens in a new window (`*` prefix on source or link) */
682
+ newWindow: boolean;
683
+ }
684
+ /**
685
+ * Body of a `[[gallery]]` element.
686
+ *
687
+ * - `"items"` — the content form with explicit `: source` lines.
688
+ * `items` is always non-empty: the content form requires at least one
689
+ * line to parse.
690
+ * - `"auto"` — the content-less form, which shows the current page's image
691
+ * attachments. `files` is null until data resolution fills it with the
692
+ * attachment filenames (already sorted by the gallery's `order`).
693
+ *
694
+ * @group Element Data
695
+ */
696
+ type GalleryContent = {
697
+ type: "items";
698
+ items: GalleryItem[];
699
+ } | {
700
+ type: "auto";
701
+ files: string[] | null;
702
+ };
703
+ /**
704
+ * Data for `[[gallery]]` elements.
705
+ *
706
+ * @group Element Data
707
+ */
708
+ interface GalleryData {
709
+ size: GallerySize;
710
+ /** Sort order for auto-collected files (parse-time normalized) */
711
+ order: GalleryOrder;
712
+ /** false when `viewer="no"`/`"false"` disables the lightbox */
713
+ viewer: boolean;
714
+ content: GalleryContent;
715
+ }
716
+ /**
619
717
  * Data for `[[toc]]` (table of contents) elements.
620
718
  *
621
719
  * @group Element Data
@@ -826,6 +924,7 @@ type ElementDataMap = {
826
924
  "anchor-name": string;
827
925
  link: LinkData;
828
926
  image: ImageData;
927
+ gallery: GalleryData;
829
928
  list: ListData;
830
929
  "definition-list": DefinitionListItem[];
831
930
  collapsible: CollapsibleData;
@@ -1304,4 +1403,4 @@ declare function evaluateExpression(expr: string): ExprResult;
1304
1403
  * @group Core
1305
1404
  */
1306
1405
  type Version = "wikidot";
1307
- export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isTruthy, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, formatExprValue, evaluateExpression, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, Position, Point, ParseResult, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, FootnoteBlockData, FloatAlignment, ExprResult, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DiagnosticSeverity, Diagnostic, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
1406
+ export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isTruthy, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, formatExprValue, evaluateExpression, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, Position, Point, ParseResult, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, GallerySize, GalleryOrder, GalleryItem, GalleryData, GalleryContent, FootnoteBlockData, FloatAlignment, ExprResult, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DiagnosticSeverity, Diagnostic, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, CssLengthUnit, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, CSS_LENGTH_UNITS, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
package/dist/index.d.ts CHANGED
@@ -64,22 +64,29 @@ declare function createPoint(line: number, column: number, offset: number): Poin
64
64
  */
65
65
  declare function createPosition(start: Point, end: Point): Position;
66
66
  /**
67
- * AST element types for Wikidot markup.
67
+ * Shared CSS value definitions used across parser and renderer.
68
68
  *
69
- * Wikidot markup (`+ heading`, `**bold**`, `[[module ListPages]]`, etc.) is parsed into
70
- * a structured representation defined here. Each {@link Element} is a tagged union of
71
- * `{ element: tag, data: payload }`, where the data shape for each tag is defined in
72
- * {@link ElementDataMap}.
69
+ * @module
70
+ */
71
+ /**
72
+ * All CSS length units (plus percentage) accepted where Wikidot markup
73
+ * takes a size value.
73
74
  *
74
- * @example
75
- * ```ts
76
- * import { parse } from "@wdprlib/parser";
77
- * const tree = parse("**Hello** world");
78
- * // tree.elements[0] → { element: "container", data: { type: "paragraph", ... } }
79
- * ```
75
+ * This is intentionally a superset of what legacy Wikidot accepts: wdpr
76
+ * extends size validation to modern CSS units (viewport, container-query,
77
+ * and root-relative units) instead of mirroring Wikidot's historical
78
+ * `px|em|%` allowlists. Units are canonicalized to lowercase.
80
79
  *
81
- * @module
80
+ * @group CSS
81
+ */
82
+ declare const CSS_LENGTH_UNITS: readonly ["cqmax", "cqmin", "cqw", "cqh", "cqi", "cqb", "svmin", "svmax", "lvmin", "lvmax", "dvmin", "dvmax", "vmin", "vmax", "svw", "svh", "svi", "svb", "lvw", "lvh", "lvi", "lvb", "dvw", "dvh", "dvi", "dvb", "vw", "vh", "vi", "vb", "rcap", "rem", "rex", "rch", "ric", "rlh", "cap", "em", "ex", "ch", "ic", "lh", "cm", "mm", "in", "pc", "pt", "px", "q", "%"];
83
+ /**
84
+ * A CSS length unit (or percentage) accepted in size values,
85
+ * canonicalized to lowercase.
86
+ *
87
+ * @group CSS
82
88
  */
89
+ type CssLengthUnit = (typeof CSS_LENGTH_UNITS)[number];
83
90
  /**
84
91
  * Key-value map of HTML attributes.
85
92
  * Populated from the Wikidot `_ class="foo" style="color:red"` attribute syntax.
@@ -488,6 +495,25 @@ type Module = {
488
495
  } | {
489
496
  /** `[[module Rate]]` — page rating widget */
490
497
  module: "rate";
498
+ } | {
499
+ /** `[[module TagCloud]]` — weighted cloud of page tags */
500
+ module: "tag-cloud";
501
+ /** Numeric part of the font size for the lightest-weighted tag */
502
+ "min-font-size": number;
503
+ /** Numeric part of the font size for the heaviest-weighted tag */
504
+ "max-font-size": number;
505
+ /** Unit shared by both font sizes (lowercase) */
506
+ "font-size-unit": CssLengthUnit;
507
+ /** RGB components for the lightest-weighted tag */
508
+ "min-color": [number, number, number];
509
+ /** RGB components for the heaviest-weighted tag */
510
+ "max-color": [number, number, number];
511
+ /** Normalized link target prefix, always ending with `/tag/` */
512
+ target: string;
513
+ /** Maximum number of tags to display */
514
+ limit: number;
515
+ /** Category filter, or null for all categories */
516
+ category: string | null;
491
517
  } | {
492
518
  /** `[[module ListUsers]]` — user listing with template body */
493
519
  module: "list-users";
@@ -616,6 +642,78 @@ interface ImageData {
616
642
  attributes: AttributeMap;
617
643
  }
618
644
  /**
645
+ * Image size keyword accepted by `[[gallery]]`.
646
+ * Invalid or missing values fall back to `"thumbnail"` at parse time,
647
+ * matching the Wikidot renderer.
648
+ *
649
+ * @group Element Data
650
+ */
651
+ type GallerySize = "small" | "medium" | "thumbnail" | "square" | "original";
652
+ /**
653
+ * Sort order for auto-collected gallery files, normalized at parse time.
654
+ * Deprecated Wikidot aliases (`nameDesc`, `dateAdded`, `dateAddedDesc`) and
655
+ * the ListPages-style `"... desc desc"` forms are folded into these four
656
+ * values. Only meaningful for the content-less (auto) form.
657
+ *
658
+ * @group Element Data
659
+ */
660
+ type GalleryOrder = "name" | "name desc" | "created_at" | "created_at desc";
661
+ /**
662
+ * A single `: source link="..." alt="..."` entry inside `[[gallery]]`.
663
+ *
664
+ * @group Element Data
665
+ */
666
+ interface GalleryItem {
667
+ /**
668
+ * Raw image source string with any leading `*` removed.
669
+ * Classification follows the Wikidot rules and happens at render time:
670
+ * a source containing `://` is external, one containing `/` refers to
671
+ * another page's file, anything else is a file on the current page.
672
+ */
673
+ source: string;
674
+ /**
675
+ * Link target with any leading `*` removed, or null when the item has no
676
+ * `link` attribute.
677
+ */
678
+ link: string | null;
679
+ /** Alternative text for the image, or null when no `alt` attribute is given */
680
+ alt: string | null;
681
+ /** true if the link opens in a new window (`*` prefix on source or link) */
682
+ newWindow: boolean;
683
+ }
684
+ /**
685
+ * Body of a `[[gallery]]` element.
686
+ *
687
+ * - `"items"` — the content form with explicit `: source` lines.
688
+ * `items` is always non-empty: the content form requires at least one
689
+ * line to parse.
690
+ * - `"auto"` — the content-less form, which shows the current page's image
691
+ * attachments. `files` is null until data resolution fills it with the
692
+ * attachment filenames (already sorted by the gallery's `order`).
693
+ *
694
+ * @group Element Data
695
+ */
696
+ type GalleryContent = {
697
+ type: "items";
698
+ items: GalleryItem[];
699
+ } | {
700
+ type: "auto";
701
+ files: string[] | null;
702
+ };
703
+ /**
704
+ * Data for `[[gallery]]` elements.
705
+ *
706
+ * @group Element Data
707
+ */
708
+ interface GalleryData {
709
+ size: GallerySize;
710
+ /** Sort order for auto-collected files (parse-time normalized) */
711
+ order: GalleryOrder;
712
+ /** false when `viewer="no"`/`"false"` disables the lightbox */
713
+ viewer: boolean;
714
+ content: GalleryContent;
715
+ }
716
+ /**
619
717
  * Data for `[[toc]]` (table of contents) elements.
620
718
  *
621
719
  * @group Element Data
@@ -826,6 +924,7 @@ type ElementDataMap = {
826
924
  "anchor-name": string;
827
925
  link: LinkData;
828
926
  image: ImageData;
927
+ gallery: GalleryData;
829
928
  list: ListData;
830
929
  "definition-list": DefinitionListItem[];
831
930
  collapsible: CollapsibleData;
@@ -1304,4 +1403,4 @@ declare function evaluateExpression(expr: string): ExprResult;
1304
1403
  * @group Core
1305
1404
  */
1306
1405
  type Version = "wikidot";
1307
- export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isTruthy, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, formatExprValue, evaluateExpression, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, Position, Point, ParseResult, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, FootnoteBlockData, FloatAlignment, ExprResult, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DiagnosticSeverity, Diagnostic, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
1406
+ export { text, paragraph, listItemSubList, listItemElements, list, link, lineBreak, italics, isTruthy, isStringContainerType, isParagraphSafe, isHeaderType, isContainerTypeParagraphSafe, isAlignType, horizontalRule, heading, formatExprValue, evaluateExpression, createSettings, createPosition, createPoint, container, bold, WikitextSettings, WikitextMode, Version, VariableMap, UserData, TocEntry, TableRow, TableOfContentsData, TableData, TableCell, TabData, SyntaxTree, StringContainerType, STYLE_SLOT_PREFIX, Position, Point, ParseResult, PageRef, Module, MathInlineData, MathData, ListType, ListItem, ListData, LinkType, LinkLocation, LinkLabel, LinkData, IncludeData, ImageSource, ImageData, IframeData, IfTagsData, IfExprData, IfCondData, HtmlData, HeadingLevel, Heading, HeaderType, GallerySize, GalleryOrder, GalleryItem, GalleryData, GalleryContent, FootnoteBlockData, FloatAlignment, ExprResult, ExprData, EmbedBlockData, Embed, ElementOf, ElementName, ElementDataMap, ElementData, Element, DiagnosticSeverity, Diagnostic, DefinitionListItem, DateItem, DateData, DEFAULT_SETTINGS, CssLengthUnit, ContainerType, ContainerData, ColorData, CollapsibleData, CodeBlockData, ClearFloat, CSS_LENGTH_UNITS, BibliographyCiteData, BibliographyBlockData, AttributeMap, AnchorTarget, AnchorData, Alignment, AlignType };
package/dist/index.js CHANGED
@@ -193,6 +193,59 @@ function isParagraphSafe(element) {
193
193
  }
194
194
  // packages/ast/src/constants.ts
195
195
  var STYLE_SLOT_PREFIX = "\x00__IFTAGS_SLOT__";
196
+ // packages/ast/src/css.ts
197
+ var CSS_LENGTH_UNITS = [
198
+ "cqmax",
199
+ "cqmin",
200
+ "cqw",
201
+ "cqh",
202
+ "cqi",
203
+ "cqb",
204
+ "svmin",
205
+ "svmax",
206
+ "lvmin",
207
+ "lvmax",
208
+ "dvmin",
209
+ "dvmax",
210
+ "vmin",
211
+ "vmax",
212
+ "svw",
213
+ "svh",
214
+ "svi",
215
+ "svb",
216
+ "lvw",
217
+ "lvh",
218
+ "lvi",
219
+ "lvb",
220
+ "dvw",
221
+ "dvh",
222
+ "dvi",
223
+ "dvb",
224
+ "vw",
225
+ "vh",
226
+ "vi",
227
+ "vb",
228
+ "rcap",
229
+ "rem",
230
+ "rex",
231
+ "rch",
232
+ "ric",
233
+ "rlh",
234
+ "cap",
235
+ "em",
236
+ "ex",
237
+ "ch",
238
+ "ic",
239
+ "lh",
240
+ "cm",
241
+ "mm",
242
+ "in",
243
+ "pc",
244
+ "pt",
245
+ "px",
246
+ "q",
247
+ "%"
248
+ ];
196
249
  // packages/ast/src/expr-eval.ts
197
250
  var FALSE_VALUES = new Set(["false", "null", "", "0"]);
198
251
  function isTruthy(value) {
@@ -640,5 +693,6 @@ export {
640
693
  container,
641
694
  bold,
642
695
  STYLE_SLOT_PREFIX,
643
- DEFAULT_SETTINGS
696
+ DEFAULT_SETTINGS,
697
+ CSS_LENGTH_UNITS
644
698
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wdprlib/ast",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "AST types for Wikidot markup",
5
5
  "keywords": [
6
6
  "ast",
package/src/css.ts ADDED
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Shared CSS value definitions used across parser and renderer.
3
+ *
4
+ * @module
5
+ */
6
+
7
+ /**
8
+ * All CSS length units (plus percentage) accepted where Wikidot markup
9
+ * takes a size value.
10
+ *
11
+ * This is intentionally a superset of what legacy Wikidot accepts: wdpr
12
+ * extends size validation to modern CSS units (viewport, container-query,
13
+ * and root-relative units) instead of mirroring Wikidot's historical
14
+ * `px|em|%` allowlists. Units are canonicalized to lowercase.
15
+ *
16
+ * @group CSS
17
+ */
18
+ export const CSS_LENGTH_UNITS = [
19
+ // Container-query units
20
+ "cqmax",
21
+ "cqmin",
22
+ "cqw",
23
+ "cqh",
24
+ "cqi",
25
+ "cqb",
26
+ // Viewport units
27
+ "svmin",
28
+ "svmax",
29
+ "lvmin",
30
+ "lvmax",
31
+ "dvmin",
32
+ "dvmax",
33
+ "vmin",
34
+ "vmax",
35
+ "svw",
36
+ "svh",
37
+ "svi",
38
+ "svb",
39
+ "lvw",
40
+ "lvh",
41
+ "lvi",
42
+ "lvb",
43
+ "dvw",
44
+ "dvh",
45
+ "dvi",
46
+ "dvb",
47
+ "vw",
48
+ "vh",
49
+ "vi",
50
+ "vb",
51
+ // Root-relative font units
52
+ "rcap",
53
+ "rem",
54
+ "rex",
55
+ "rch",
56
+ "ric",
57
+ "rlh",
58
+ // Font-relative units
59
+ "cap",
60
+ "em",
61
+ "ex",
62
+ "ch",
63
+ "ic",
64
+ "lh",
65
+ // Absolute units
66
+ "cm",
67
+ "mm",
68
+ "in",
69
+ "pc",
70
+ "pt",
71
+ "px",
72
+ "q",
73
+ // Percentage
74
+ "%",
75
+ ] as const;
76
+
77
+ /**
78
+ * A CSS length unit (or percentage) accepted in size values,
79
+ * canonicalized to lowercase.
80
+ *
81
+ * @group CSS
82
+ */
83
+ export type CssLengthUnit = (typeof CSS_LENGTH_UNITS)[number];
package/src/element.ts CHANGED
@@ -16,6 +16,8 @@
16
16
  * @module
17
17
  */
18
18
 
19
+ import type { CssLengthUnit } from "./css";
20
+
19
21
  // ---------------------------------------------------------------------------
20
22
  // Primitive types
21
23
  // ---------------------------------------------------------------------------
@@ -500,6 +502,26 @@ export type Module =
500
502
  /** `[[module Rate]]` — page rating widget */
501
503
  module: "rate";
502
504
  }
505
+ | {
506
+ /** `[[module TagCloud]]` — weighted cloud of page tags */
507
+ module: "tag-cloud";
508
+ /** Numeric part of the font size for the lightest-weighted tag */
509
+ "min-font-size": number;
510
+ /** Numeric part of the font size for the heaviest-weighted tag */
511
+ "max-font-size": number;
512
+ /** Unit shared by both font sizes (lowercase) */
513
+ "font-size-unit": CssLengthUnit;
514
+ /** RGB components for the lightest-weighted tag */
515
+ "min-color": [number, number, number];
516
+ /** RGB components for the heaviest-weighted tag */
517
+ "max-color": [number, number, number];
518
+ /** Normalized link target prefix, always ending with `/tag/` */
519
+ target: string;
520
+ /** Maximum number of tags to display */
521
+ limit: number;
522
+ /** Category filter, or null for all categories */
523
+ category: string | null;
524
+ }
503
525
  | {
504
526
  /** `[[module ListUsers]]` — user listing with template body */
505
527
  module: "list-users";
@@ -636,6 +658,79 @@ export interface ImageData {
636
658
  attributes: AttributeMap;
637
659
  }
638
660
 
661
+ /**
662
+ * Image size keyword accepted by `[[gallery]]`.
663
+ * Invalid or missing values fall back to `"thumbnail"` at parse time,
664
+ * matching the Wikidot renderer.
665
+ *
666
+ * @group Element Data
667
+ */
668
+ export type GallerySize = "small" | "medium" | "thumbnail" | "square" | "original";
669
+
670
+ /**
671
+ * Sort order for auto-collected gallery files, normalized at parse time.
672
+ * Deprecated Wikidot aliases (`nameDesc`, `dateAdded`, `dateAddedDesc`) and
673
+ * the ListPages-style `"... desc desc"` forms are folded into these four
674
+ * values. Only meaningful for the content-less (auto) form.
675
+ *
676
+ * @group Element Data
677
+ */
678
+ export type GalleryOrder = "name" | "name desc" | "created_at" | "created_at desc";
679
+
680
+ /**
681
+ * A single `: source link="..." alt="..."` entry inside `[[gallery]]`.
682
+ *
683
+ * @group Element Data
684
+ */
685
+ export interface GalleryItem {
686
+ /**
687
+ * Raw image source string with any leading `*` removed.
688
+ * Classification follows the Wikidot rules and happens at render time:
689
+ * a source containing `://` is external, one containing `/` refers to
690
+ * another page's file, anything else is a file on the current page.
691
+ */
692
+ source: string;
693
+ /**
694
+ * Link target with any leading `*` removed, or null when the item has no
695
+ * `link` attribute.
696
+ */
697
+ link: string | null;
698
+ /** Alternative text for the image, or null when no `alt` attribute is given */
699
+ alt: string | null;
700
+ /** true if the link opens in a new window (`*` prefix on source or link) */
701
+ newWindow: boolean;
702
+ }
703
+
704
+ /**
705
+ * Body of a `[[gallery]]` element.
706
+ *
707
+ * - `"items"` — the content form with explicit `: source` lines.
708
+ * `items` is always non-empty: the content form requires at least one
709
+ * line to parse.
710
+ * - `"auto"` — the content-less form, which shows the current page's image
711
+ * attachments. `files` is null until data resolution fills it with the
712
+ * attachment filenames (already sorted by the gallery's `order`).
713
+ *
714
+ * @group Element Data
715
+ */
716
+ export type GalleryContent =
717
+ | { type: "items"; items: GalleryItem[] }
718
+ | { type: "auto"; files: string[] | null };
719
+
720
+ /**
721
+ * Data for `[[gallery]]` elements.
722
+ *
723
+ * @group Element Data
724
+ */
725
+ export interface GalleryData {
726
+ size: GallerySize;
727
+ /** Sort order for auto-collected files (parse-time normalized) */
728
+ order: GalleryOrder;
729
+ /** false when `viewer="no"`/`"false"` disables the lightbox */
730
+ viewer: boolean;
731
+ content: GalleryContent;
732
+ }
733
+
639
734
  /**
640
735
  * Data for `[[toc]]` (table of contents) elements.
641
736
  *
@@ -868,6 +963,7 @@ export type ElementDataMap = {
868
963
  "anchor-name": string;
869
964
  link: LinkData;
870
965
  image: ImageData;
966
+ gallery: GalleryData;
871
967
  list: ListData;
872
968
  "definition-list": DefinitionListItem[];
873
969
  collapsible: CollapsibleData;
package/src/index.ts CHANGED
@@ -67,6 +67,11 @@ export type {
67
67
  AnchorData,
68
68
  LinkData,
69
69
  ImageData,
70
+ GallerySize,
71
+ GalleryOrder,
72
+ GalleryItem,
73
+ GalleryContent,
74
+ GalleryData,
70
75
  TableOfContentsData,
71
76
  FootnoteBlockData,
72
77
  BibliographyCiteData,
@@ -110,6 +115,10 @@ export type { Diagnostic, DiagnosticSeverity, ParseResult } from "./diagnostic";
110
115
  // Constants
111
116
  export { STYLE_SLOT_PREFIX } from "./constants";
112
117
 
118
+ // CSS value definitions
119
+ export type { CssLengthUnit } from "./css";
120
+ export { CSS_LENGTH_UNITS } from "./css";
121
+
113
122
  // Wikitext settings
114
123
  export type { WikitextMode, WikitextSettings } from "./settings";
115
124