@maplibre-yaml/core 0.1.2 → 0.1.3-beta.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.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { ChapterActionSchema, ChapterLayersSchema, ChapterSchema, ColorOrExpressionSchema, ColorSchema, ContentBlockSchema, ContentElementSchema, ContentItemSchema, ExpressionSchema, GeoJSONSourceSchema, ImageSourceSchema, LatitudeSchema, LayerSourceSchema, LngLatBoundsSchema, LngLatSchema, LoadingConfigSchema, LongitudeSchema, NumberOrExpressionSchema, RasterSourceSchema, ScrollytellingBlockSchema, StreamConfigSchema, ValidTagNames, VectorSourceSchema, VideoSourceSchema, ZoomLevelSchema } from './schemas/index.js';
2
- import { L as LayerSchema, P as PopupContentSchema, C as ControlsConfigSchema } from './page.schema-CzdCyPFI.js';
3
- export { j as BackgroundLayerSchema, B as BaseLayerPropertiesSchema, p as BlockSchema, e as CircleLayerSchema, m as ControlPositionSchema, h as FillExtrusionLayerSchema, F as FillLayerSchema, G as GlobalConfigSchema, H as HeatmapLayerSchema, i as HillshadeLayerSchema, I as InteractiveConfigSchema, l as LayerOrReferenceSchema, k as LayerReferenceSchema, a as LegendConfigSchema, d as LegendItemSchema, f as LineLayerSchema, M as MapBlockSchema, b as MapConfigSchema, n as MapFullPageBlockSchema, o as MixedBlockSchema, q as PageSchema, c as PopupContentItemSchema, g as RasterLayerSchema, R as RootSchema, S as SymbolLayerSchema } from './page.schema-CzdCyPFI.js';
4
- export { L as LegendBuilder, M as MapBlock, b as MapRenderer, d as MapRendererEvents, c as MapRendererOptions, P as ParseError, a as ParseResult, R as RootConfig, Y as YAMLParser, p as parseYAMLConfig, s as safeParseYAMLConfig } from './map-renderer-DOLO9y-3.js';
1
+ export { ColorOrExpressionSchema, ColorSchema, ContentBlockSchema, ContentElementSchema, ContentItemSchema, ExpressionSchema, GeoJSONSourceSchema, ImageSourceSchema, LatitudeSchema, LayerSourceSchema, LngLatBoundsSchema, LngLatSchema, LoadingConfigSchema, LongitudeSchema, NumberOrExpressionSchema, RasterSourceSchema, StreamConfigSchema, ValidTagNames, VectorSourceSchema, VideoSourceSchema, ZoomLevelSchema } from './schemas/index.js';
2
+ import { L as LayerSchema, P as PopupContentSchema, C as ControlsConfigSchema } from './page.schema-VBytF9l5.js';
3
+ export { k as BackgroundLayerSchema, B as BaseLayerPropertiesSchema, O as Block, G as BlockSchema, y as Chapter, z as ChapterAction, v as ChapterActionSchema, A as ChapterLayers, w as ChapterLayersSchema, x as ChapterSchema, e as CircleLayerSchema, p as ControlPosition, n as ControlPositionSchema, q as ControlsConfig, i as FillExtrusionLayerSchema, F as FillLayerSchema, T as GlobalConfig, K as GlobalConfigSchema, H as HeatmapLayerSchema, j as HillshadeLayerSchema, I as InteractiveConfigSchema, m as LayerOrReferenceSchema, l as LayerReferenceSchema, r as LegendConfig, a as LegendConfigSchema, d as LegendItemSchema, f as LineLayerSchema, t as MapBlock, M as MapBlockSchema, s as MapConfig, b as MapConfigSchema, u as MapFullPageBlock, o as MapFullPageBlockSchema, N as MixedBlock, E as MixedBlockSchema, Q as Page, J as PageSchema, c as PopupContentItemSchema, h as RasterLayerSchema, U as RootConfig, R as RootSchema, D as ScrollytellingBlock, S as ScrollytellingBlockSchema, g as SymbolLayerSchema } from './page.schema-VBytF9l5.js';
4
+ export { L as LegendBuilder, M as MapRenderer, c as MapRendererEvents, b as MapRendererOptions, P as ParseError, a as ParseResult, Y as YAMLParser, p as parseYAMLConfig, s as safeParseYAMLConfig } from './map-renderer-IvxniEQy.js';
5
5
  import { Map, LngLat } from 'maplibre-gl';
6
6
  import { z } from 'zod';
7
7
  import { FeatureCollection } from 'geojson';
package/dist/index.js CHANGED
@@ -534,7 +534,9 @@ var MapConfigSchema = z.object({
534
534
  // Required
535
535
  center: LngLatSchema.describe("Initial map center [longitude, latitude]"),
536
536
  zoom: ZoomLevelSchema.describe("Initial zoom level (0-24)"),
537
- mapStyle: z.union([z.string().url(), z.any()]).describe("MapLibre style URL or style object"),
537
+ mapStyle: z.union([z.string().url(), z.any()]).optional().describe(
538
+ "MapLibre style URL or style object. Optional when global config.defaultMapStyle is set."
539
+ ),
538
540
  // View
539
541
  pitch: z.number().min(0).max(85).default(0).describe("Camera pitch angle in degrees (0-85)"),
540
542
  bearing: z.number().min(-180).max(180).default(0).describe("Camera bearing (rotation) in degrees (-180 to 180)"),
@@ -908,6 +910,104 @@ var YAMLParser = class {
908
910
  };
909
911
  }
910
912
  }
913
+ /**
914
+ * Parse YAML string for a scrollytelling block and validate against ScrollytellingBlockSchema
915
+ *
916
+ * @param yaml - YAML string to parse (should be a scrollytelling block, not a full document)
917
+ * @returns Validated scrollytelling block object
918
+ * @throws {Error} If YAML syntax is invalid
919
+ * @throws {ZodError} If validation fails
920
+ *
921
+ * @remarks
922
+ * This method is specifically for parsing individual scrollytelling blocks (e.g., in documentation
923
+ * or component usage). Unlike {@link parse}, it validates against ScrollytellingBlockSchema rather
924
+ * than RootSchema, so it expects a single scrollytelling configuration without the pages array wrapper.
925
+ *
926
+ * @example
927
+ * ```typescript
928
+ * const yaml = `
929
+ * type: scrollytelling
930
+ * id: story
931
+ * config:
932
+ * center: [0, 0]
933
+ * zoom: 2
934
+ * mapStyle: "https://example.com/style.json"
935
+ * chapters:
936
+ * - id: intro
937
+ * title: "Introduction"
938
+ * center: [0, 0]
939
+ * zoom: 3
940
+ * description: "Welcome to our story."
941
+ * - id: chapter2
942
+ * title: "Chapter 2"
943
+ * center: [10, 10]
944
+ * zoom: 5
945
+ * description: "The story continues."
946
+ * `;
947
+ *
948
+ * const scrollyBlock = YAMLParser.parseScrollytellingBlock(yaml);
949
+ * ```
950
+ */
951
+ static parseScrollytellingBlock(yaml) {
952
+ let parsed;
953
+ try {
954
+ parsed = parse(yaml);
955
+ } catch (error) {
956
+ throw new Error(
957
+ `YAML syntax error: ${error instanceof Error ? error.message : String(error)}`
958
+ );
959
+ }
960
+ return ScrollytellingBlockSchema.parse(parsed);
961
+ }
962
+ /**
963
+ * Parse YAML string for a scrollytelling block, returning a result object
964
+ *
965
+ * @param yaml - YAML string to parse (should be a scrollytelling block, not a full document)
966
+ * @returns Result object with success flag and either data or errors
967
+ *
968
+ * @remarks
969
+ * This is the non-throwing version of {@link parseScrollytellingBlock}. Instead of throwing
970
+ * errors, it returns a result object that indicates success or failure.
971
+ * Use this when you want to handle errors gracefully without try/catch.
972
+ *
973
+ * @example
974
+ * ```typescript
975
+ * const result = YAMLParser.safeParseScrollytellingBlock(yamlString);
976
+ * if (result.success) {
977
+ * console.log('Scrollytelling config:', result.data);
978
+ * } else {
979
+ * result.errors.forEach(err => {
980
+ * console.error(`Error at ${err.path}: ${err.message}`);
981
+ * });
982
+ * }
983
+ * ```
984
+ */
985
+ static safeParseScrollytellingBlock(yaml) {
986
+ try {
987
+ const data = this.parseScrollytellingBlock(yaml);
988
+ return {
989
+ success: true,
990
+ data,
991
+ errors: []
992
+ };
993
+ } catch (error) {
994
+ if (error instanceof ZodError) {
995
+ return {
996
+ success: false,
997
+ errors: this.formatZodErrors(error)
998
+ };
999
+ }
1000
+ return {
1001
+ success: false,
1002
+ errors: [
1003
+ {
1004
+ path: "",
1005
+ message: error instanceof Error ? error.message : String(error)
1006
+ }
1007
+ ]
1008
+ };
1009
+ }
1010
+ }
911
1011
  /**
912
1012
  * Resolve $ref references to global layers and sources
913
1013
  *