@maplibre-yaml/core 0.1.3-beta.1 → 0.2.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.
@@ -11297,6 +11297,44 @@ var coerce = {
11297
11297
  };
11298
11298
  var NEVER = INVALID;
11299
11299
 
11300
+ // src/schemas/base.schema.ts
11301
+ var LongitudeSchema = external_exports.number().min(-180, "Longitude must be >= -180").max(180, "Longitude must be <= 180").describe("Longitude in degrees (-180 to 180)");
11302
+ var LatitudeSchema = external_exports.number().min(-90, "Latitude must be >= -90").max(90, "Latitude must be <= 90").describe("Latitude in degrees (-90 to 90)");
11303
+ var LngLatSchema = external_exports.tuple([LongitudeSchema, LatitudeSchema]).describe("Geographic coordinates as [longitude, latitude]");
11304
+ var LngLatBoundsSchema = external_exports.tuple([
11305
+ LongitudeSchema,
11306
+ // west
11307
+ LatitudeSchema,
11308
+ // south
11309
+ LongitudeSchema,
11310
+ // east
11311
+ LatitudeSchema
11312
+ // north
11313
+ ]).describe("Bounding box as [west, south, east, north]");
11314
+ var ColorSchema = external_exports.string().refine(
11315
+ (val) => {
11316
+ if (val.startsWith("#")) {
11317
+ return /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(val);
11318
+ }
11319
+ if (val.startsWith("rgb")) {
11320
+ return /^rgba?\s*\([^)]+\)$/.test(val);
11321
+ }
11322
+ if (val.startsWith("hsl")) {
11323
+ return /^hsla?\s*\([^)]+\)$/.test(val);
11324
+ }
11325
+ return true;
11326
+ },
11327
+ {
11328
+ message: "Invalid color format. Use hex (#rgb, #rrggbb), rgb(), rgba(), hsl(), hsla(), or named colors."
11329
+ }
11330
+ ).describe("CSS color value");
11331
+ var ExpressionSchema = external_exports.array(external_exports.any()).refine((val) => val.length > 0 && typeof val[0] === "string", {
11332
+ message: 'Expression must be an array starting with a string operator (e.g., ["get", "property"])'
11333
+ }).describe("MapLibre expression for data-driven styling");
11334
+ var NumberOrExpressionSchema = external_exports.union([external_exports.number(), ExpressionSchema]).describe("Number value or MapLibre expression");
11335
+ var ColorOrExpressionSchema = external_exports.union([ColorSchema, ExpressionSchema]).describe("Color value or MapLibre expression");
11336
+ var ZoomLevelSchema = external_exports.number().min(0, "Zoom level must be >= 0").max(24, "Zoom level must be <= 24").describe("Map zoom level (0-24)");
11337
+
11300
11338
  // src/schemas/content.schema.ts
11301
11339
  var ValidTagNames = [
11302
11340
  "h1",
@@ -11349,44 +11387,6 @@ var ContentBlockSchema = external_exports.object({
11349
11387
  content: external_exports.array(ContentItemSchema).describe("Array of content items to render")
11350
11388
  }).describe("Content block for rich text and media");
11351
11389
 
11352
- // src/schemas/base.schema.ts
11353
- var LongitudeSchema = external_exports.number().min(-180, "Longitude must be >= -180").max(180, "Longitude must be <= 180").describe("Longitude in degrees (-180 to 180)");
11354
- var LatitudeSchema = external_exports.number().min(-90, "Latitude must be >= -90").max(90, "Latitude must be <= 90").describe("Latitude in degrees (-90 to 90)");
11355
- var LngLatSchema = external_exports.tuple([LongitudeSchema, LatitudeSchema]).describe("Geographic coordinates as [longitude, latitude]");
11356
- var LngLatBoundsSchema = external_exports.tuple([
11357
- LongitudeSchema,
11358
- // west
11359
- LatitudeSchema,
11360
- // south
11361
- LongitudeSchema,
11362
- // east
11363
- LatitudeSchema
11364
- // north
11365
- ]).describe("Bounding box as [west, south, east, north]");
11366
- var ColorSchema = external_exports.string().refine(
11367
- (val) => {
11368
- if (val.startsWith("#")) {
11369
- return /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(val);
11370
- }
11371
- if (val.startsWith("rgb")) {
11372
- return /^rgba?\s*\([^)]+\)$/.test(val);
11373
- }
11374
- if (val.startsWith("hsl")) {
11375
- return /^hsla?\s*\([^)]+\)$/.test(val);
11376
- }
11377
- return true;
11378
- },
11379
- {
11380
- message: "Invalid color format. Use hex (#rgb, #rrggbb), rgb(), rgba(), hsl(), hsla(), or named colors."
11381
- }
11382
- ).describe("CSS color value");
11383
- var ExpressionSchema = external_exports.array(external_exports.any()).refine((val) => val.length > 0 && typeof val[0] === "string", {
11384
- message: 'Expression must be an array starting with a string operator (e.g., ["get", "property"])'
11385
- }).describe("MapLibre expression for data-driven styling");
11386
- var NumberOrExpressionSchema = external_exports.union([external_exports.number(), ExpressionSchema]).describe("Number value or MapLibre expression");
11387
- var ColorOrExpressionSchema = external_exports.union([ColorSchema, ExpressionSchema]).describe("Color value or MapLibre expression");
11388
- var ZoomLevelSchema = external_exports.number().min(0, "Zoom level must be >= 0").max(24, "Zoom level must be <= 24").describe("Map zoom level (0-24)");
11389
-
11390
11390
  // src/schemas/source.schema.ts
11391
11391
  var StreamConfigSchema = external_exports.object({
11392
11392
  type: external_exports.enum(["websocket", "sse"]).describe("Streaming connection type"),
@@ -11887,6 +11887,7 @@ var MapBlockSchema = external_exports.object({
11887
11887
  className: external_exports.string().optional().describe("CSS class name for container"),
11888
11888
  style: external_exports.string().optional().describe("Inline CSS styles for container"),
11889
11889
  config: MapConfigSchema.describe("Map configuration"),
11890
+ sources: external_exports.record(external_exports.string(), LayerSourceSchema).optional().describe("Map sources"),
11890
11891
  layers: external_exports.array(LayerOrReferenceSchema).default([]).describe("Map layers"),
11891
11892
  controls: ControlsConfigSchema.optional().describe("Map controls"),
11892
11893
  legend: LegendConfigSchema.optional().describe("Legend configuration")
@@ -11897,6 +11898,7 @@ var MapFullPageBlockSchema = external_exports.object({
11897
11898
  className: external_exports.string().optional().describe("CSS class name for container"),
11898
11899
  style: external_exports.string().optional().describe("Inline CSS styles for container"),
11899
11900
  config: MapConfigSchema.describe("Map configuration"),
11901
+ sources: external_exports.record(external_exports.string(), LayerSourceSchema).optional().describe("Map sources"),
11900
11902
  layers: external_exports.array(LayerOrReferenceSchema).default([]).describe("Map layers"),
11901
11903
  controls: ControlsConfigSchema.optional().describe("Map controls"),
11902
11904
  legend: LegendConfigSchema.optional().describe("Legend configuration")
@@ -12004,6 +12006,10 @@ var GlobalConfigSchema = external_exports.object({
12004
12006
  description: external_exports.string().optional().describe("Application description"),
12005
12007
  defaultMapStyle: external_exports.string().url().optional().describe("Default map style URL"),
12006
12008
  theme: external_exports.enum(["light", "dark"]).default("light").describe("Default theme"),
12009
+ defaultZoom: external_exports.number().min(0).max(24).optional().describe("Default zoom level for all maps"),
12010
+ defaultCenter: LngLatSchema.optional().describe(
12011
+ "Default center [lng, lat] for all maps"
12012
+ ),
12007
12013
  dataFetching: external_exports.object({
12008
12014
  defaultStrategy: external_exports.enum(["runtime", "build", "hybrid"]).default("runtime").describe("Default fetch strategy"),
12009
12015
  timeout: external_exports.number().min(1e3).default(3e4).describe("Default timeout in milliseconds"),
@@ -14864,9 +14870,16 @@ var LayerManager = class {
14864
14870
  this.abortControllers = /* @__PURE__ */ new Map();
14865
14871
  }
14866
14872
  async addLayer(layer) {
14867
- const sourceId = `${layer.id}-source`;
14873
+ const isSourceRef = typeof layer.source === "string";
14874
+ const sourceId = isSourceRef ? layer.source : `${layer.id}-source`;
14868
14875
  this.layerToSource.set(layer.id, sourceId);
14869
- await this.addSource(sourceId, layer);
14876
+ if (!isSourceRef) {
14877
+ await this.addSource(sourceId, layer);
14878
+ } else if (!this.map.getSource(sourceId)) {
14879
+ throw new Error(
14880
+ `Source '${sourceId}' referenced by layer '${layer.id}' not found. Ensure it is defined in the block-level 'sources' map.`
14881
+ );
14882
+ }
14870
14883
  const layerSpec = {
14871
14884
  id: layer.id,
14872
14885
  type: layer.type,
@@ -14894,12 +14907,6 @@ var LayerManager = class {
14894
14907
  }
14895
14908
  }
14896
14909
  async addSource(sourceId, layer) {
14897
- if (typeof layer.source === "string") {
14898
- if (!this.map.getSource(layer.source)) {
14899
- throw new Error(`Source reference '${layer.source}' not found`);
14900
- }
14901
- return;
14902
- }
14903
14910
  const source = layer.source;
14904
14911
  if (source.type === "geojson") {
14905
14912
  const geojsonSource = source;
@@ -15119,7 +15126,10 @@ var LayerManager = class {
15119
15126
  }
15120
15127
  if (this.map.getLayer(layerId)) this.map.removeLayer(layerId);
15121
15128
  const sourceId = this.layerToSource.get(layerId) || `${layerId}-source`;
15122
- if (this.map.getSource(sourceId)) this.map.removeSource(sourceId);
15129
+ const isInlineSource = sourceId === `${layerId}-source`;
15130
+ if (isInlineSource && this.map.getSource(sourceId)) {
15131
+ this.map.removeSource(sourceId);
15132
+ }
15123
15133
  this.sourceData.delete(sourceId);
15124
15134
  this.layerToSource.delete(layerId);
15125
15135
  }
@@ -15481,7 +15491,7 @@ var MapRenderer = class {
15481
15491
  controlsManager;
15482
15492
  eventListeners;
15483
15493
  isLoaded;
15484
- constructor(container, config, layers = [], options = {}) {
15494
+ constructor(container, config, layers = [], options = {}, sources) {
15485
15495
  this.eventListeners = /* @__PURE__ */ new Map();
15486
15496
  this.isLoaded = false;
15487
15497
  this.map = new maplibregl2.Map({
@@ -15509,6 +15519,13 @@ var MapRenderer = class {
15509
15519
  this.controlsManager = new ControlsManager(this.map);
15510
15520
  this.map.on("load", () => {
15511
15521
  this.isLoaded = true;
15522
+ if (sources) {
15523
+ for (const [id, sourceSpec] of Object.entries(sources)) {
15524
+ if (!this.map.getSource(id)) {
15525
+ this.map.addSource(id, sourceSpec);
15526
+ }
15527
+ }
15528
+ }
15512
15529
  Promise.all(layers.map((layer) => this.addLayer(layer))).then(() => {
15513
15530
  this.emit("load", void 0);
15514
15531
  options.onLoad?.();
@@ -15808,7 +15825,7 @@ var MLMap = class extends HTMLElement {
15808
15825
  }
15809
15826
  this.appendChild(this.mapContainer);
15810
15827
  try {
15811
- const { config, layers = [] } = mapBlock;
15828
+ const { config, sources, layers = [] } = mapBlock;
15812
15829
  this.renderer = new MapRenderer(this.mapContainer, config, layers, {
15813
15830
  onLoad: () => {
15814
15831
  },
@@ -15820,7 +15837,7 @@ var MLMap = class extends HTMLElement {
15820
15837
  })
15821
15838
  );
15822
15839
  }
15823
- });
15840
+ }, sources);
15824
15841
  this.setupEventForwarding();
15825
15842
  } catch (error) {
15826
15843
  this.handleError([