gis-common 5.1.20 → 5.1.22

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.
@@ -18143,6 +18143,61 @@ __publicField(_Storage, "_getPrefixedKey", function(key, options) {
18143
18143
  }
18144
18144
  });
18145
18145
  let Storage = _Storage;
18146
+ class SVGLoader {
18147
+ constructor(options = {}) {
18148
+ __publicField(this, "cache");
18149
+ __publicField(this, "defaultOptions");
18150
+ this.cache = /* @__PURE__ */ new Map();
18151
+ this.defaultOptions = {
18152
+ useCache: true,
18153
+ clearContainer: false,
18154
+ addClasses: [],
18155
+ onLoad: null,
18156
+ onError: null,
18157
+ ...options
18158
+ };
18159
+ }
18160
+ async load(url, container) {
18161
+ if (this.defaultOptions.useCache && this.cache.has(url)) {
18162
+ this._insertSVG(this.cache.get(url), container);
18163
+ return this.cache.get(url);
18164
+ }
18165
+ try {
18166
+ const response = await fetch(url);
18167
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
18168
+ const svgText = await response.text();
18169
+ const parser = new DOMParser();
18170
+ const svgDoc = parser.parseFromString(svgText, "image/svg+xml");
18171
+ const svgElement = svgDoc.documentElement;
18172
+ if (this.defaultOptions.addClasses.length) {
18173
+ svgElement.classList.add(...this.defaultOptions.addClasses);
18174
+ }
18175
+ if (this.defaultOptions.useCache) {
18176
+ this.cache.set(url, svgElement.cloneNode(true));
18177
+ }
18178
+ this._insertSVG(svgElement, container);
18179
+ if (typeof this.defaultOptions.onLoad === "function") {
18180
+ this.defaultOptions.onLoad(svgElement, url);
18181
+ }
18182
+ return svgElement;
18183
+ } catch (error) {
18184
+ console.error(`Failed to load SVG from ${url}:`, error);
18185
+ if (typeof this.defaultOptions.onError === "function") {
18186
+ this.defaultOptions.onError(error, url);
18187
+ }
18188
+ return null;
18189
+ }
18190
+ }
18191
+ _insertSVG(svgElement, container) {
18192
+ if (this.defaultOptions.clearContainer) {
18193
+ container.innerHTML = "";
18194
+ }
18195
+ container.appendChild(svgElement.cloneNode(true));
18196
+ }
18197
+ clearCache() {
18198
+ this.cache.clear();
18199
+ }
18200
+ }
18146
18201
  class WebGL {
18147
18202
  constructor(el) {
18148
18203
  __publicField(this, "ctx");
@@ -18275,6 +18330,7 @@ export {
18275
18330
  OptimizeUtil,
18276
18331
  Storage,
18277
18332
  StringUtil,
18333
+ SVGLoader as SvgLoader,
18278
18334
  TreeUtil,
18279
18335
  UrlUtil,
18280
18336
  Util,