@india-boundary-corrector/leaflet-layer 0.0.1 → 0.0.3

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.
@@ -28,17 +28,23 @@ var IndiaBoundaryCorrector = (() => {
28
28
  });
29
29
 
30
30
  // ../data/version.js
31
- var packageVersion = "0.0.1";
31
+ var packageVersion = "0.0.3";
32
32
 
33
33
  // ../data/index.js
34
34
  var import_meta = {};
35
35
  var PACKAGE_NAME = "@india-boundary-corrector/data";
36
36
  var PMTILES_FILENAME = "india_boundary_corrections.pmtiles";
37
37
  var DEFAULT_CDN_URL = `https://unpkg.com/${PACKAGE_NAME}@${packageVersion}/${PMTILES_FILENAME}`;
38
+ function shouldUseCdnFallback(hostname) {
39
+ return hostname === "esm.sh";
40
+ }
38
41
  function detectPmtilesUrl() {
39
42
  try {
40
43
  if (typeof import_meta !== "undefined" && import_meta.url) {
41
44
  const moduleUrl = new URL(".", import_meta.url);
45
+ if (shouldUseCdnFallback(moduleUrl.hostname)) {
46
+ return DEFAULT_CDN_URL;
47
+ }
42
48
  return new URL(PMTILES_FILENAME, moduleUrl).href;
43
49
  }
44
50
  } catch {
@@ -164,10 +170,10 @@ var IndiaBoundaryCorrector = (() => {
164
170
  let pattern = template.replace(/[.*+?^${}()|[\]\\]/g, (char) => {
165
171
  if (char === "{" || char === "}") return char;
166
172
  return "\\" + char;
167
- }).replace(/^https:\/\//, "https?://").replace(/^http:\/\//, "https?://").replace(/\{([a-z0-9])-([a-z0-9])\}/gi, (_2, start, end) => `(\\{${start}-${end}\\}|[a-z0-9]+)`).replace(/\{(z|x|y|s|r)\}/gi, (_2, name) => {
173
+ }).replace(/^https:\/\//, "https?://").replace(/^http:\/\//, "https?://").replace(/\{([a-z0-9])-([a-z0-9])\}/gi, (_2, start, end) => `(\\{${start}-${end}\\}|\\{s\\}|[a-z0-9]+)`).replace(/\{(z|x|y|s|r)\}/gi, (_2, name) => {
168
174
  const lowerName = name.toLowerCase();
169
175
  if (lowerName === "s") {
170
- return "(\\{s\\}|[a-z0-9]+)";
176
+ return "(\\{s\\}|\\{[a-z0-9]-[a-z0-9]\\}|[a-z0-9]+)";
171
177
  }
172
178
  if (lowerName === "r") {
173
179
  return "(\\{r\\}|@\\d+x)?";
@@ -201,6 +207,9 @@ var IndiaBoundaryCorrector = (() => {
201
207
  if (!id || typeof id !== "string") {
202
208
  throw new Error("LayerConfig requires a non-empty string id");
203
209
  }
210
+ if (id.includes("/")) {
211
+ throw new Error(`LayerConfig id cannot contain slashes: "${id}"`);
212
+ }
204
213
  this.id = id;
205
214
  this.startZoom = startZoom;
206
215
  this.zoomThreshold = zoomThreshold;
@@ -2702,7 +2711,7 @@ var IndiaBoundaryCorrector = (() => {
2702
2711
  if (!maskCanvas || maskCanvas.width !== tileSize || maskCanvas.height !== tileSize) {
2703
2712
  maskCanvas = new OffscreenCanvas(tileSize, tileSize);
2704
2713
  }
2705
- const maskCtx = maskCanvas.getContext("2d");
2714
+ const maskCtx = maskCanvas.getContext("2d", { willReadFrequently: true });
2706
2715
  maskCtx.fillStyle = "black";
2707
2716
  maskCtx.fillRect(0, 0, tileSize, tileSize);
2708
2717
  maskCtx.strokeStyle = "white";
@@ -2904,8 +2913,11 @@ var IndiaBoundaryCorrector = (() => {
2904
2913
  const useOsm = zoom >= zoomThreshold;
2905
2914
  const addLayerName = useOsm ? "to-add-osm" : "to-add-ne";
2906
2915
  const delLayerName = useOsm ? "to-del-osm" : "to-del-ne";
2907
- const canvas = new OffscreenCanvas(tileSize, tileSize);
2908
- const ctx = canvas.getContext("2d");
2916
+ if (!this._canvas || this._canvas.width !== tileSize) {
2917
+ this._canvas = new OffscreenCanvas(tileSize, tileSize);
2918
+ }
2919
+ const canvas = this._canvas;
2920
+ const ctx = canvas.getContext("2d", { willReadFrequently: true });
2909
2921
  const blob = new Blob([rasterTile]);
2910
2922
  const imageBitmap = await createImageBitmap(blob);
2911
2923
  ctx.drawImage(imageBitmap, 0, 0, tileSize, tileSize);