@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/components/index.d.ts +2 -2
- package/dist/components/index.js +101 -1
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +101 -1
- package/dist/index.js.map +1 -1
- package/dist/{map-renderer-DOLO9y-3.d.ts → map-renderer-IvxniEQy.d.ts} +72 -2
- package/dist/{page.schema-CzdCyPFI.d.ts → page.schema-VBytF9l5.d.ts} +544 -6
- package/dist/register.browser.js +101 -1
- package/dist/register.browser.js.map +1 -1
- package/dist/register.d.ts +2 -2
- package/dist/register.js +101 -1
- package/dist/register.js.map +1 -1
- package/dist/schemas/index.d.ts +2 -483
- package/dist/schemas/index.js +3 -1
- package/dist/schemas/index.js.map +1 -1
- package/package.json +1 -1
package/dist/components/index.js
CHANGED
|
@@ -538,7 +538,9 @@ var MapConfigSchema = z.object({
|
|
|
538
538
|
// Required
|
|
539
539
|
center: LngLatSchema.describe("Initial map center [longitude, latitude]"),
|
|
540
540
|
zoom: ZoomLevelSchema.describe("Initial zoom level (0-24)"),
|
|
541
|
-
mapStyle: z.union([z.string().url(), z.any()]).describe(
|
|
541
|
+
mapStyle: z.union([z.string().url(), z.any()]).optional().describe(
|
|
542
|
+
"MapLibre style URL or style object. Optional when global config.defaultMapStyle is set."
|
|
543
|
+
),
|
|
542
544
|
// View
|
|
543
545
|
pitch: z.number().min(0).max(85).default(0).describe("Camera pitch angle in degrees (0-85)"),
|
|
544
546
|
bearing: z.number().min(-180).max(180).default(0).describe("Camera bearing (rotation) in degrees (-180 to 180)"),
|
|
@@ -916,6 +918,104 @@ var YAMLParser = class {
|
|
|
916
918
|
};
|
|
917
919
|
}
|
|
918
920
|
}
|
|
921
|
+
/**
|
|
922
|
+
* Parse YAML string for a scrollytelling block and validate against ScrollytellingBlockSchema
|
|
923
|
+
*
|
|
924
|
+
* @param yaml - YAML string to parse (should be a scrollytelling block, not a full document)
|
|
925
|
+
* @returns Validated scrollytelling block object
|
|
926
|
+
* @throws {Error} If YAML syntax is invalid
|
|
927
|
+
* @throws {ZodError} If validation fails
|
|
928
|
+
*
|
|
929
|
+
* @remarks
|
|
930
|
+
* This method is specifically for parsing individual scrollytelling blocks (e.g., in documentation
|
|
931
|
+
* or component usage). Unlike {@link parse}, it validates against ScrollytellingBlockSchema rather
|
|
932
|
+
* than RootSchema, so it expects a single scrollytelling configuration without the pages array wrapper.
|
|
933
|
+
*
|
|
934
|
+
* @example
|
|
935
|
+
* ```typescript
|
|
936
|
+
* const yaml = `
|
|
937
|
+
* type: scrollytelling
|
|
938
|
+
* id: story
|
|
939
|
+
* config:
|
|
940
|
+
* center: [0, 0]
|
|
941
|
+
* zoom: 2
|
|
942
|
+
* mapStyle: "https://example.com/style.json"
|
|
943
|
+
* chapters:
|
|
944
|
+
* - id: intro
|
|
945
|
+
* title: "Introduction"
|
|
946
|
+
* center: [0, 0]
|
|
947
|
+
* zoom: 3
|
|
948
|
+
* description: "Welcome to our story."
|
|
949
|
+
* - id: chapter2
|
|
950
|
+
* title: "Chapter 2"
|
|
951
|
+
* center: [10, 10]
|
|
952
|
+
* zoom: 5
|
|
953
|
+
* description: "The story continues."
|
|
954
|
+
* `;
|
|
955
|
+
*
|
|
956
|
+
* const scrollyBlock = YAMLParser.parseScrollytellingBlock(yaml);
|
|
957
|
+
* ```
|
|
958
|
+
*/
|
|
959
|
+
static parseScrollytellingBlock(yaml) {
|
|
960
|
+
let parsed;
|
|
961
|
+
try {
|
|
962
|
+
parsed = parse(yaml);
|
|
963
|
+
} catch (error) {
|
|
964
|
+
throw new Error(
|
|
965
|
+
`YAML syntax error: ${error instanceof Error ? error.message : String(error)}`
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
return ScrollytellingBlockSchema.parse(parsed);
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Parse YAML string for a scrollytelling block, returning a result object
|
|
972
|
+
*
|
|
973
|
+
* @param yaml - YAML string to parse (should be a scrollytelling block, not a full document)
|
|
974
|
+
* @returns Result object with success flag and either data or errors
|
|
975
|
+
*
|
|
976
|
+
* @remarks
|
|
977
|
+
* This is the non-throwing version of {@link parseScrollytellingBlock}. Instead of throwing
|
|
978
|
+
* errors, it returns a result object that indicates success or failure.
|
|
979
|
+
* Use this when you want to handle errors gracefully without try/catch.
|
|
980
|
+
*
|
|
981
|
+
* @example
|
|
982
|
+
* ```typescript
|
|
983
|
+
* const result = YAMLParser.safeParseScrollytellingBlock(yamlString);
|
|
984
|
+
* if (result.success) {
|
|
985
|
+
* console.log('Scrollytelling config:', result.data);
|
|
986
|
+
* } else {
|
|
987
|
+
* result.errors.forEach(err => {
|
|
988
|
+
* console.error(`Error at ${err.path}: ${err.message}`);
|
|
989
|
+
* });
|
|
990
|
+
* }
|
|
991
|
+
* ```
|
|
992
|
+
*/
|
|
993
|
+
static safeParseScrollytellingBlock(yaml) {
|
|
994
|
+
try {
|
|
995
|
+
const data = this.parseScrollytellingBlock(yaml);
|
|
996
|
+
return {
|
|
997
|
+
success: true,
|
|
998
|
+
data,
|
|
999
|
+
errors: []
|
|
1000
|
+
};
|
|
1001
|
+
} catch (error) {
|
|
1002
|
+
if (error instanceof ZodError) {
|
|
1003
|
+
return {
|
|
1004
|
+
success: false,
|
|
1005
|
+
errors: this.formatZodErrors(error)
|
|
1006
|
+
};
|
|
1007
|
+
}
|
|
1008
|
+
return {
|
|
1009
|
+
success: false,
|
|
1010
|
+
errors: [
|
|
1011
|
+
{
|
|
1012
|
+
path: "",
|
|
1013
|
+
message: error instanceof Error ? error.message : String(error)
|
|
1014
|
+
}
|
|
1015
|
+
]
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
919
1019
|
/**
|
|
920
1020
|
* Resolve $ref references to global layers and sources
|
|
921
1021
|
*
|