@carto/api-client 0.5.32-alpha.723d642.132 → 0.5.32-alpha.72cdcfe.130

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.
@@ -10376,76 +10376,9 @@ var checker_small_default = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAA
10376
10376
  // src/fetch-map/patterns/solid.png
10377
10377
  var solid_default = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAAAFzUkdCAK7OHOkAAACWSURBVHic7dBBEcAwAMOwrPw5dzD0qIXA52/b3cOODtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QPsBULQBfwAqZPkAAAAASUVORK5CYII=";
10378
10378
 
10379
- // src/fetch-map/patterns/hlines-large.svg
10380
- var hlines_large_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="64" height="16" patternUnits="userSpaceOnUse"><rect width="64" height="2"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10381
-
10382
- // src/fetch-map/patterns/hlines-medium.svg
10383
- var hlines_medium_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="64" height="8" patternUnits="userSpaceOnUse"><rect width="64" height="2"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10384
-
10385
- // src/fetch-map/patterns/hlines-small.svg
10386
- var hlines_small_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="64" height="4" patternUnits="userSpaceOnUse"><rect width="64" height="2"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10387
-
10388
- // src/fetch-map/patterns/vlines-large.svg
10389
- var vlines_large_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="16" height="64" patternUnits="userSpaceOnUse"><rect width="2" height="64"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10390
-
10391
- // src/fetch-map/patterns/vlines-medium.svg
10392
- var vlines_medium_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="8" height="64" patternUnits="userSpaceOnUse"><rect width="2" height="64"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10393
-
10394
- // src/fetch-map/patterns/vlines-small.svg
10395
- var vlines_small_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="4" height="64" patternUnits="userSpaceOnUse"><rect width="2" height="64"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10396
-
10397
- // src/fetch-map/patterns/diag-left-large.svg
10398
- var diag_left_large_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="45.2548" height="64" patternUnits="userSpaceOnUse" patternTransform="rotate(-45)"><rect width="1.4142" height="64"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10399
-
10400
- // src/fetch-map/patterns/diag-left-medium.svg
10401
- var diag_left_medium_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="22.6274" height="64" patternUnits="userSpaceOnUse" patternTransform="rotate(-45)"><rect width="1.4142" height="64"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10402
-
10403
- // src/fetch-map/patterns/diag-left-small.svg
10404
- var diag_left_small_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="11.3137" height="64" patternUnits="userSpaceOnUse" patternTransform="rotate(-45)"><rect width="1.4142" height="64"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10405
-
10406
- // src/fetch-map/patterns/diag-right-large.svg
10407
- var diag_right_large_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="45.2548" height="64" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="1.4142" height="64"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10408
-
10409
- // src/fetch-map/patterns/diag-right-medium.svg
10410
- var diag_right_medium_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="22.6274" height="64" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="1.4142" height="64"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10411
-
10412
- // src/fetch-map/patterns/diag-right-small.svg
10413
- var diag_right_small_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="11.3137" height="64" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="1.4142" height="64"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10414
-
10415
- // src/fetch-map/patterns/cross-hatch-large.svg
10416
- var cross_hatch_large_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="a" width="45.2548" height="64" patternUnits="userSpaceOnUse" patternTransform="rotate(-45)"><rect width="1.4142" height="64"/></pattern><pattern id="b" width="45.2548" height="64" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="1.4142" height="64"/></pattern></defs><rect width="64" height="64" fill="url(%23a)"/><rect width="64" height="64" fill="url(%23b)"/></svg>%0A';
10417
-
10418
- // src/fetch-map/patterns/cross-hatch-medium.svg
10419
- var cross_hatch_medium_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="a" width="22.6274" height="64" patternUnits="userSpaceOnUse" patternTransform="rotate(-45)"><rect width="1.4142" height="64"/></pattern><pattern id="b" width="22.6274" height="64" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="1.4142" height="64"/></pattern></defs><rect width="64" height="64" fill="url(%23a)"/><rect width="64" height="64" fill="url(%23b)"/></svg>%0A';
10420
-
10421
- // src/fetch-map/patterns/cross-hatch-small.svg
10422
- var cross_hatch_small_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="a" width="11.3137" height="64" patternUnits="userSpaceOnUse" patternTransform="rotate(-45)"><rect width="1.4142" height="64"/></pattern><pattern id="b" width="11.3137" height="64" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="1.4142" height="64"/></pattern></defs><rect width="64" height="64" fill="url(%23a)"/><rect width="64" height="64" fill="url(%23b)"/></svg>%0A';
10423
-
10424
- // src/fetch-map/patterns/dots-large.svg
10425
- var dots_large_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="16" height="16" patternUnits="userSpaceOnUse"><rect width="2" height="2"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10426
-
10427
- // src/fetch-map/patterns/dots-medium.svg
10428
- var dots_medium_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="8" height="8" patternUnits="userSpaceOnUse"><rect width="2" height="2"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10429
-
10430
- // src/fetch-map/patterns/dots-small.svg
10431
- var dots_small_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="4" height="4" patternUnits="userSpaceOnUse"><rect width="2" height="2"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10432
-
10433
- // src/fetch-map/patterns/checker-large.svg
10434
- var checker_large_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="16" height="16" patternUnits="userSpaceOnUse"><rect width="8" height="8"/><rect x="8" y="8" width="8" height="8"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10435
-
10436
- // src/fetch-map/patterns/checker-medium.svg
10437
- var checker_medium_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="8" height="8" patternUnits="userSpaceOnUse"><rect width="4" height="4"/><rect x="4" y="4" width="4" height="4"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10438
-
10439
- // src/fetch-map/patterns/checker-small.svg
10440
- var checker_small_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs><pattern id="p" width="4" height="4" patternUnits="userSpaceOnUse"><rect width="2" height="2"/><rect x="2" y="2" width="2" height="2"/></pattern></defs><rect width="64" height="64" fill="url(%23p)"/></svg>%0A';
10441
-
10442
- // src/fetch-map/patterns/solid.svg
10443
- var solid_default2 = 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64"><defs></defs><rect width="64" height="64"/></svg>%0A';
10444
-
10445
10379
  // src/fetch-map/pattern-atlas.ts
10446
10380
  var DEFAULT_CELL_SIZE = 128;
10447
10381
  var SOURCE_TILE_SIZE = 64;
10448
- var VECTOR_RENDER_SIZE = 128;
10449
10382
  var PATTERN_ROWS = [
10450
10383
  "hlines",
10451
10384
  "vlines",
@@ -10480,30 +10413,6 @@ var CELL_URLS = {
10480
10413
  "checker-small": checker_small_default,
10481
10414
  solid: solid_default
10482
10415
  };
10483
- var CELL_SVG_URLS = {
10484
- "hlines-large": hlines_large_default2,
10485
- "hlines-medium": hlines_medium_default2,
10486
- "hlines-small": hlines_small_default2,
10487
- "vlines-large": vlines_large_default2,
10488
- "vlines-medium": vlines_medium_default2,
10489
- "vlines-small": vlines_small_default2,
10490
- "diag-left-large": diag_left_large_default2,
10491
- "diag-left-medium": diag_left_medium_default2,
10492
- "diag-left-small": diag_left_small_default2,
10493
- "diag-right-large": diag_right_large_default2,
10494
- "diag-right-medium": diag_right_medium_default2,
10495
- "diag-right-small": diag_right_small_default2,
10496
- "cross-hatch-large": cross_hatch_large_default2,
10497
- "cross-hatch-medium": cross_hatch_medium_default2,
10498
- "cross-hatch-small": cross_hatch_small_default2,
10499
- "dots-large": dots_large_default2,
10500
- "dots-medium": dots_medium_default2,
10501
- "dots-small": dots_small_default2,
10502
- "checker-large": checker_large_default2,
10503
- "checker-medium": checker_medium_default2,
10504
- "checker-small": checker_small_default2,
10505
- solid: solid_default2
10506
- };
10507
10416
  function debugGlobals() {
10508
10417
  return globalThis;
10509
10418
  }
@@ -10511,20 +10420,12 @@ function getPatternCellSize() {
10511
10420
  const cell = debugGlobals().__CARTO_PATTERN_CELL_SIZE__;
10512
10421
  return typeof cell === "number" && cell > 0 ? cell : DEFAULT_CELL_SIZE;
10513
10422
  }
10514
- function getPatternAssetSource() {
10515
- const source = debugGlobals().__CARTO_PATTERN_ASSET_SOURCE__;
10516
- return source === "svg" || source === "procedural" ? source : "png";
10517
- }
10518
10423
  function getPatternTextureParameters() {
10519
10424
  const params = debugGlobals().__CARTO_PATTERN_TEXTURE_PARAMS__;
10520
10425
  return params && typeof params === "object" ? params : void 0;
10521
10426
  }
10522
- function getPatternRepeats(cell, source = getPatternAssetSource()) {
10523
- const repeatSize = source === "png" ? SOURCE_TILE_SIZE : VECTOR_RENDER_SIZE;
10524
- return Math.max(1, Math.floor(cell / repeatSize));
10525
- }
10526
10427
  function getPatternScaleAdjustment(cell = getPatternCellSize()) {
10527
- return SOURCE_TILE_SIZE * getPatternRepeats(cell) / cell;
10428
+ return SOURCE_TILE_SIZE / cell;
10528
10429
  }
10529
10430
  function getPatternCellPadding(cell) {
10530
10431
  return Math.max(2, Math.round(cell / 16));
@@ -10573,96 +10474,45 @@ async function loadImage(dataUrl) {
10573
10474
  img.src = dataUrl;
10574
10475
  });
10575
10476
  }
10576
- function loadSvgImage(dataUrl) {
10577
- return new Promise((resolve, reject) => {
10578
- const img = new Image();
10579
- img.onload = () => resolve(img);
10580
- img.onerror = reject;
10581
- img.src = dataUrl;
10582
- });
10583
- }
10584
- var DENSITY_STEP = { small: 1, medium: 2, large: 4 };
10585
- function paintDesignTile(ctx, key) {
10586
- const [, name, density] = key.match(/^(.*?)(?:-(small|medium|large))?$/) ?? [];
10587
- const step = DENSITY_STEP[density ?? ""] ?? 1;
10588
- const linePeriod = 4 * step;
10589
- const diagPeriod = 16 * step;
10590
- const square = 2 * step;
10591
- ctx.fillStyle = "#000";
10592
- ctx.strokeStyle = "#000";
10593
- const diag = (dir) => {
10594
- ctx.lineWidth = Math.SQRT2;
10595
- ctx.beginPath();
10596
- for (let k = -Math.ceil(64 / diagPeriod); k <= 2 * Math.ceil(64 / diagPeriod); k++) {
10597
- ctx.moveTo(k * diagPeriod - 8 * dir, -8);
10598
- ctx.lineTo(k * diagPeriod + 72 * dir, 72);
10599
- }
10600
- ctx.stroke();
10601
- };
10602
- switch (name) {
10603
- case "solid":
10604
- ctx.fillRect(0, 0, 64, 64);
10605
- break;
10606
- case "hlines":
10607
- for (let y = 0; y < 64; y += linePeriod) ctx.fillRect(0, y, 64, 2);
10608
- break;
10609
- case "vlines":
10610
- for (let x = 0; x < 64; x += linePeriod) ctx.fillRect(x, 0, 2, 64);
10611
- break;
10612
- case "dots":
10613
- for (let y = 0; y < 64; y += linePeriod)
10614
- for (let x = 0; x < 64; x += linePeriod) ctx.fillRect(x, y, 2, 2);
10615
- break;
10616
- case "checker":
10617
- for (let j = 0; j * square < 64; j++)
10618
- for (let i = 0; i * square < 64; i++)
10619
- if ((i + j) % 2 === 0)
10620
- ctx.fillRect(i * square, j * square, square, square);
10621
- break;
10622
- case "diag-left":
10623
- diag(1);
10624
- break;
10625
- case "diag-right":
10626
- diag(-1);
10627
- break;
10628
- case "cross-hatch":
10629
- diag(1);
10630
- diag(-1);
10631
- break;
10477
+ var atlasPromises = /* @__PURE__ */ new Map();
10478
+ function getPatternAtlas(cell = getPatternCellSize()) {
10479
+ let promise = atlasPromises.get(cell);
10480
+ if (!promise) {
10481
+ promise = build(cell);
10482
+ promise.catch(() => {
10483
+ });
10484
+ atlasPromises.set(cell, promise);
10632
10485
  }
10486
+ return promise;
10633
10487
  }
10634
- function paintTileCanvas(key, size) {
10635
- const canvas = createCanvas(size, size);
10636
- const ctx = canvas.getContext("2d");
10637
- if (!ctx)
10638
- throw new Error(
10639
- "carto-api-client: 2D context unavailable for pattern tile"
10640
- );
10641
- ctx.scale(size / 64, size / 64);
10642
- paintDesignTile(ctx, key);
10643
- return canvas;
10644
- }
10645
- async function composeAtlas(cell, reps, images) {
10488
+ async function build(cell) {
10646
10489
  const mapping = getPatternAtlasMapping(cell);
10647
10490
  const pad = getPatternCellPadding(cell);
10648
10491
  const pitch = cell + 2 * pad;
10649
- const step = cell / reps;
10650
10492
  const canvas = createCanvas(pitch * 3, pitch * (PATTERN_ROWS.length + 1));
10651
10493
  const ctx = canvas.getContext("2d");
10652
10494
  if (!ctx)
10653
10495
  throw new Error(
10654
10496
  "carto-api-client: 2D context unavailable for pattern atlas"
10655
10497
  );
10498
+ const images = {};
10499
+ await Promise.all(
10500
+ Object.entries(CELL_URLS).map(async ([key, url]) => {
10501
+ images[key] = await loadImage(url);
10502
+ })
10503
+ );
10656
10504
  for (const [key, frame] of Object.entries(mapping)) {
10657
10505
  const img = images[key];
10658
10506
  if (!img) continue;
10507
+ ctx.imageSmoothingEnabled = /^(diag-|cross-hatch)/.test(key);
10508
+ if ("imageSmoothingQuality" in ctx) ctx.imageSmoothingQuality = "high";
10659
10509
  ctx.save();
10660
10510
  ctx.beginPath();
10661
10511
  ctx.rect(frame.x - pad, frame.y - pad, cell + 2 * pad, cell + 2 * pad);
10662
10512
  ctx.clip();
10663
- for (let i = -1; i <= reps; i++) {
10664
- for (let j = -1; j <= reps; j++) {
10665
- ctx.drawImage(img, frame.x + i * step, frame.y + j * step, step, step);
10513
+ for (const dx of [-cell, 0, cell]) {
10514
+ for (const dy of [-cell, 0, cell]) {
10515
+ ctx.drawImage(img, frame.x + dx, frame.y + dy, cell, cell);
10666
10516
  }
10667
10517
  }
10668
10518
  ctx.restore();
@@ -10671,51 +10521,6 @@ async function composeAtlas(cell, reps, images) {
10671
10521
  return createImageBitmap(canvas);
10672
10522
  return canvas;
10673
10523
  }
10674
- async function buildPngAtlas(cell) {
10675
- const images = {};
10676
- await Promise.all(
10677
- Object.entries(CELL_URLS).map(async ([key, url]) => {
10678
- images[key] = await loadImage(url);
10679
- })
10680
- );
10681
- return composeAtlas(cell, getPatternRepeats(cell, "png"), images);
10682
- }
10683
- async function buildSvgAtlas(cell) {
10684
- const images = {};
10685
- await Promise.all(
10686
- Object.entries(CELL_SVG_URLS).map(async ([key, url]) => {
10687
- images[key] = await loadSvgImage(url);
10688
- })
10689
- );
10690
- return composeAtlas(cell, getPatternRepeats(cell, "svg"), images);
10691
- }
10692
- async function buildProceduralAtlas(cell) {
10693
- const reps = getPatternRepeats(cell, "procedural");
10694
- const step = cell / reps;
10695
- const images = {};
10696
- for (const key of Object.keys(CELL_URLS)) {
10697
- images[key] = paintTileCanvas(key, step);
10698
- }
10699
- return composeAtlas(cell, reps, images);
10700
- }
10701
- var ATLAS_BUILDERS = {
10702
- png: buildPngAtlas,
10703
- svg: buildSvgAtlas,
10704
- procedural: buildProceduralAtlas
10705
- };
10706
- var atlasPromises = /* @__PURE__ */ new Map();
10707
- function getPatternAtlas(cell = getPatternCellSize()) {
10708
- const source = getPatternAssetSource();
10709
- const memoKey = `${source}:${cell}`;
10710
- let promise = atlasPromises.get(memoKey);
10711
- if (!promise) {
10712
- promise = ATLAS_BUILDERS[source](cell);
10713
- promise.catch(() => {
10714
- });
10715
- atlasPromises.set(memoKey, promise);
10716
- }
10717
- return promise;
10718
- }
10719
10524
 
10720
10525
  // src/fetch-map/parse-map.ts
10721
10526
  function getLayerDescriptor({