@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.
@@ -10741,76 +10741,9 @@ var checker_small_default = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAA
10741
10741
  // src/fetch-map/patterns/solid.png
10742
10742
  var solid_default = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAABHNCSVQICAgIfAhkiAAAAAFzUkdCAK7OHOkAAACWSURBVHic7dBBEcAwAMOwrPw5dzD0qIXA52/b3cOODtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QGuADtAaoAO0BugArQE6QPsBULQBfwAqZPkAAAAASUVORK5CYII=";
10743
10743
 
10744
- // src/fetch-map/patterns/hlines-large.svg
10745
- 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';
10746
-
10747
- // src/fetch-map/patterns/hlines-medium.svg
10748
- 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';
10749
-
10750
- // src/fetch-map/patterns/hlines-small.svg
10751
- 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';
10752
-
10753
- // src/fetch-map/patterns/vlines-large.svg
10754
- 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';
10755
-
10756
- // src/fetch-map/patterns/vlines-medium.svg
10757
- 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';
10758
-
10759
- // src/fetch-map/patterns/vlines-small.svg
10760
- 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';
10761
-
10762
- // src/fetch-map/patterns/diag-left-large.svg
10763
- 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';
10764
-
10765
- // src/fetch-map/patterns/diag-left-medium.svg
10766
- 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';
10767
-
10768
- // src/fetch-map/patterns/diag-left-small.svg
10769
- 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';
10770
-
10771
- // src/fetch-map/patterns/diag-right-large.svg
10772
- 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';
10773
-
10774
- // src/fetch-map/patterns/diag-right-medium.svg
10775
- 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';
10776
-
10777
- // src/fetch-map/patterns/diag-right-small.svg
10778
- 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';
10779
-
10780
- // src/fetch-map/patterns/cross-hatch-large.svg
10781
- 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';
10782
-
10783
- // src/fetch-map/patterns/cross-hatch-medium.svg
10784
- 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';
10785
-
10786
- // src/fetch-map/patterns/cross-hatch-small.svg
10787
- 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';
10788
-
10789
- // src/fetch-map/patterns/dots-large.svg
10790
- 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';
10791
-
10792
- // src/fetch-map/patterns/dots-medium.svg
10793
- 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';
10794
-
10795
- // src/fetch-map/patterns/dots-small.svg
10796
- 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';
10797
-
10798
- // src/fetch-map/patterns/checker-large.svg
10799
- 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';
10800
-
10801
- // src/fetch-map/patterns/checker-medium.svg
10802
- 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';
10803
-
10804
- // src/fetch-map/patterns/checker-small.svg
10805
- 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';
10806
-
10807
- // src/fetch-map/patterns/solid.svg
10808
- 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';
10809
-
10810
10744
  // src/fetch-map/pattern-atlas.ts
10811
10745
  var DEFAULT_CELL_SIZE = 128;
10812
10746
  var SOURCE_TILE_SIZE = 64;
10813
- var VECTOR_RENDER_SIZE = 128;
10814
10747
  var PATTERN_ROWS = [
10815
10748
  "hlines",
10816
10749
  "vlines",
@@ -10845,30 +10778,6 @@ var CELL_URLS = {
10845
10778
  "checker-small": checker_small_default,
10846
10779
  solid: solid_default
10847
10780
  };
10848
- var CELL_SVG_URLS = {
10849
- "hlines-large": hlines_large_default2,
10850
- "hlines-medium": hlines_medium_default2,
10851
- "hlines-small": hlines_small_default2,
10852
- "vlines-large": vlines_large_default2,
10853
- "vlines-medium": vlines_medium_default2,
10854
- "vlines-small": vlines_small_default2,
10855
- "diag-left-large": diag_left_large_default2,
10856
- "diag-left-medium": diag_left_medium_default2,
10857
- "diag-left-small": diag_left_small_default2,
10858
- "diag-right-large": diag_right_large_default2,
10859
- "diag-right-medium": diag_right_medium_default2,
10860
- "diag-right-small": diag_right_small_default2,
10861
- "cross-hatch-large": cross_hatch_large_default2,
10862
- "cross-hatch-medium": cross_hatch_medium_default2,
10863
- "cross-hatch-small": cross_hatch_small_default2,
10864
- "dots-large": dots_large_default2,
10865
- "dots-medium": dots_medium_default2,
10866
- "dots-small": dots_small_default2,
10867
- "checker-large": checker_large_default2,
10868
- "checker-medium": checker_medium_default2,
10869
- "checker-small": checker_small_default2,
10870
- solid: solid_default2
10871
- };
10872
10781
  function debugGlobals() {
10873
10782
  return globalThis;
10874
10783
  }
@@ -10876,20 +10785,12 @@ function getPatternCellSize() {
10876
10785
  const cell = debugGlobals().__CARTO_PATTERN_CELL_SIZE__;
10877
10786
  return typeof cell === "number" && cell > 0 ? cell : DEFAULT_CELL_SIZE;
10878
10787
  }
10879
- function getPatternAssetSource() {
10880
- const source = debugGlobals().__CARTO_PATTERN_ASSET_SOURCE__;
10881
- return source === "svg" || source === "procedural" ? source : "png";
10882
- }
10883
10788
  function getPatternTextureParameters() {
10884
10789
  const params = debugGlobals().__CARTO_PATTERN_TEXTURE_PARAMS__;
10885
10790
  return params && typeof params === "object" ? params : void 0;
10886
10791
  }
10887
- function getPatternRepeats(cell, source = getPatternAssetSource()) {
10888
- const repeatSize = source === "png" ? SOURCE_TILE_SIZE : VECTOR_RENDER_SIZE;
10889
- return Math.max(1, Math.floor(cell / repeatSize));
10890
- }
10891
10792
  function getPatternScaleAdjustment(cell = getPatternCellSize()) {
10892
- return SOURCE_TILE_SIZE * getPatternRepeats(cell) / cell;
10793
+ return SOURCE_TILE_SIZE / cell;
10893
10794
  }
10894
10795
  function getPatternCellPadding(cell) {
10895
10796
  return Math.max(2, Math.round(cell / 16));
@@ -10938,96 +10839,45 @@ async function loadImage(dataUrl) {
10938
10839
  img.src = dataUrl;
10939
10840
  });
10940
10841
  }
10941
- function loadSvgImage(dataUrl) {
10942
- return new Promise((resolve, reject) => {
10943
- const img = new Image();
10944
- img.onload = () => resolve(img);
10945
- img.onerror = reject;
10946
- img.src = dataUrl;
10947
- });
10948
- }
10949
- var DENSITY_STEP = { small: 1, medium: 2, large: 4 };
10950
- function paintDesignTile(ctx, key) {
10951
- const [, name, density] = key.match(/^(.*?)(?:-(small|medium|large))?$/) ?? [];
10952
- const step = DENSITY_STEP[density ?? ""] ?? 1;
10953
- const linePeriod = 4 * step;
10954
- const diagPeriod = 16 * step;
10955
- const square = 2 * step;
10956
- ctx.fillStyle = "#000";
10957
- ctx.strokeStyle = "#000";
10958
- const diag = (dir) => {
10959
- ctx.lineWidth = Math.SQRT2;
10960
- ctx.beginPath();
10961
- for (let k = -Math.ceil(64 / diagPeriod); k <= 2 * Math.ceil(64 / diagPeriod); k++) {
10962
- ctx.moveTo(k * diagPeriod - 8 * dir, -8);
10963
- ctx.lineTo(k * diagPeriod + 72 * dir, 72);
10964
- }
10965
- ctx.stroke();
10966
- };
10967
- switch (name) {
10968
- case "solid":
10969
- ctx.fillRect(0, 0, 64, 64);
10970
- break;
10971
- case "hlines":
10972
- for (let y = 0; y < 64; y += linePeriod) ctx.fillRect(0, y, 64, 2);
10973
- break;
10974
- case "vlines":
10975
- for (let x = 0; x < 64; x += linePeriod) ctx.fillRect(x, 0, 2, 64);
10976
- break;
10977
- case "dots":
10978
- for (let y = 0; y < 64; y += linePeriod)
10979
- for (let x = 0; x < 64; x += linePeriod) ctx.fillRect(x, y, 2, 2);
10980
- break;
10981
- case "checker":
10982
- for (let j = 0; j * square < 64; j++)
10983
- for (let i = 0; i * square < 64; i++)
10984
- if ((i + j) % 2 === 0)
10985
- ctx.fillRect(i * square, j * square, square, square);
10986
- break;
10987
- case "diag-left":
10988
- diag(1);
10989
- break;
10990
- case "diag-right":
10991
- diag(-1);
10992
- break;
10993
- case "cross-hatch":
10994
- diag(1);
10995
- diag(-1);
10996
- break;
10842
+ var atlasPromises = /* @__PURE__ */ new Map();
10843
+ function getPatternAtlas(cell = getPatternCellSize()) {
10844
+ let promise = atlasPromises.get(cell);
10845
+ if (!promise) {
10846
+ promise = build(cell);
10847
+ promise.catch(() => {
10848
+ });
10849
+ atlasPromises.set(cell, promise);
10997
10850
  }
10851
+ return promise;
10998
10852
  }
10999
- function paintTileCanvas(key, size) {
11000
- const canvas = createCanvas(size, size);
11001
- const ctx = canvas.getContext("2d");
11002
- if (!ctx)
11003
- throw new Error(
11004
- "carto-api-client: 2D context unavailable for pattern tile"
11005
- );
11006
- ctx.scale(size / 64, size / 64);
11007
- paintDesignTile(ctx, key);
11008
- return canvas;
11009
- }
11010
- async function composeAtlas(cell, reps, images) {
10853
+ async function build(cell) {
11011
10854
  const mapping = getPatternAtlasMapping(cell);
11012
10855
  const pad = getPatternCellPadding(cell);
11013
10856
  const pitch = cell + 2 * pad;
11014
- const step = cell / reps;
11015
10857
  const canvas = createCanvas(pitch * 3, pitch * (PATTERN_ROWS.length + 1));
11016
10858
  const ctx = canvas.getContext("2d");
11017
10859
  if (!ctx)
11018
10860
  throw new Error(
11019
10861
  "carto-api-client: 2D context unavailable for pattern atlas"
11020
10862
  );
10863
+ const images = {};
10864
+ await Promise.all(
10865
+ Object.entries(CELL_URLS).map(async ([key, url]) => {
10866
+ images[key] = await loadImage(url);
10867
+ })
10868
+ );
11021
10869
  for (const [key, frame] of Object.entries(mapping)) {
11022
10870
  const img = images[key];
11023
10871
  if (!img) continue;
10872
+ ctx.imageSmoothingEnabled = /^(diag-|cross-hatch)/.test(key);
10873
+ if ("imageSmoothingQuality" in ctx) ctx.imageSmoothingQuality = "high";
11024
10874
  ctx.save();
11025
10875
  ctx.beginPath();
11026
10876
  ctx.rect(frame.x - pad, frame.y - pad, cell + 2 * pad, cell + 2 * pad);
11027
10877
  ctx.clip();
11028
- for (let i = -1; i <= reps; i++) {
11029
- for (let j = -1; j <= reps; j++) {
11030
- ctx.drawImage(img, frame.x + i * step, frame.y + j * step, step, step);
10878
+ for (const dx of [-cell, 0, cell]) {
10879
+ for (const dy of [-cell, 0, cell]) {
10880
+ ctx.drawImage(img, frame.x + dx, frame.y + dy, cell, cell);
11031
10881
  }
11032
10882
  }
11033
10883
  ctx.restore();
@@ -11036,51 +10886,6 @@ async function composeAtlas(cell, reps, images) {
11036
10886
  return createImageBitmap(canvas);
11037
10887
  return canvas;
11038
10888
  }
11039
- async function buildPngAtlas(cell) {
11040
- const images = {};
11041
- await Promise.all(
11042
- Object.entries(CELL_URLS).map(async ([key, url]) => {
11043
- images[key] = await loadImage(url);
11044
- })
11045
- );
11046
- return composeAtlas(cell, getPatternRepeats(cell, "png"), images);
11047
- }
11048
- async function buildSvgAtlas(cell) {
11049
- const images = {};
11050
- await Promise.all(
11051
- Object.entries(CELL_SVG_URLS).map(async ([key, url]) => {
11052
- images[key] = await loadSvgImage(url);
11053
- })
11054
- );
11055
- return composeAtlas(cell, getPatternRepeats(cell, "svg"), images);
11056
- }
11057
- async function buildProceduralAtlas(cell) {
11058
- const reps = getPatternRepeats(cell, "procedural");
11059
- const step = cell / reps;
11060
- const images = {};
11061
- for (const key of Object.keys(CELL_URLS)) {
11062
- images[key] = paintTileCanvas(key, step);
11063
- }
11064
- return composeAtlas(cell, reps, images);
11065
- }
11066
- var ATLAS_BUILDERS = {
11067
- png: buildPngAtlas,
11068
- svg: buildSvgAtlas,
11069
- procedural: buildProceduralAtlas
11070
- };
11071
- var atlasPromises = /* @__PURE__ */ new Map();
11072
- function getPatternAtlas(cell = getPatternCellSize()) {
11073
- const source = getPatternAssetSource();
11074
- const memoKey = `${source}:${cell}`;
11075
- let promise = atlasPromises.get(memoKey);
11076
- if (!promise) {
11077
- promise = ATLAS_BUILDERS[source](cell);
11078
- promise.catch(() => {
11079
- });
11080
- atlasPromises.set(memoKey, promise);
11081
- }
11082
- return promise;
11083
- }
11084
10889
 
11085
10890
  // src/fetch-map/parse-map.ts
11086
10891
  function getLayerDescriptor({