mahal_map 1.6.14 → 1.6.16
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.
- package/README.md +74 -3
- package/dist/index.d.mts +45 -3
- package/dist/index.d.ts +45 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/mahal_map.sdk.js +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Me=Object.defineProperty;var k=(r,e)=>{for(var t in e)Me(r,t,{get:e[t],enumerable:!0})};var y=class{constructor(e){this.map=e}setZoom(e,t=!0){t?this.map.easeTo({zoom:e}):this.map.setZoom(e)}setBearing(e,t=!0){t?this.map.easeTo({bearing:e}):this.map.setBearing(e)}setPitch(e,t=!0){t?this.map.easeTo({pitch:e}):this.map.setPitch(e)}toggle3D(e){this.map.easeTo({pitch:e?60:0,bearing:e?this.map.getBearing():0,duration:800})}resetNorth(){this.map.easeTo({bearing:0,pitch:0,duration:600})}flyTo(e){this.map.flyTo({speed:1.2,curve:1.42,essential:!0,...e})}getPitch(){return this.map.getPitch()}};var X="https://platform.mahal.tj/api/",D=/^([-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?)),\s*([-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?))$/,B=/^([-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?)),\s*([-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?))$/;var Y="https://mtile.gram.tj/custom-styles/dark-style.json",Q="https://mtile.gram.tj/custom-styles/mapstyle.json",ee="https://mtile.gram.tj/custom-styles/style_maptiler_basic_hn.json";var T="https://
|
|
1
|
+
var Me=Object.defineProperty;var k=(r,e)=>{for(var t in e)Me(r,t,{get:e[t],enumerable:!0})};var y=class{constructor(e){this.map=e}setZoom(e,t=!0){t?this.map.easeTo({zoom:e}):this.map.setZoom(e)}setBearing(e,t=!0){t?this.map.easeTo({bearing:e}):this.map.setBearing(e)}setPitch(e,t=!0){t?this.map.easeTo({pitch:e}):this.map.setPitch(e)}toggle3D(e){this.map.easeTo({pitch:e?60:0,bearing:e?this.map.getBearing():0,duration:800})}resetNorth(){this.map.easeTo({bearing:0,pitch:0,duration:600})}flyTo(e){this.map.flyTo({speed:1.2,curve:1.42,essential:!0,...e})}getPitch(){return this.map.getPitch()}};var X="https://platform.mahal.tj/api/",D=/^([-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?)),\s*([-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?))$/,B=/^([-+]?(?:180(?:\.0+)?|(?:(?:1[0-7]\d)|(?:[1-9]?\d))(?:\.\d+)?)),\s*([-+]?(?:[1-8]?\d(?:\.\d+)?|90(?:\.0+)?))$/;var Y="https://mtile.gram.tj/custom-styles/dark-style.json",Q="https://mtile.gram.tj/custom-styles/mapstyle.json",ee="https://mtile.gram.tj/custom-styles/style_maptiler_basic_hn.json";var T="https://navi.gram.tj",L={light:"road-urban-lab-v2",dark:"standard-night"};function A(r,e){return`${r}/maps/${e}.json`}function Z(r,e,t){let i=r.includes("?")?"&":"?";return`${r}${i}${e}=${encodeURIComponent(t)}`}function F(r,e,t){let i=r;return t&&(i=Z(i,"token",t)),e==="ru"&&(i=Z(i,"lang","ru")),i}var R="";function be(r){r!==""&&(R=r)}function Le(){R=""}var v=()=>R;var Ce=/<svg[\s>]/i,Se=/<(svg|path|g|circle|rect|polygon|line|polyline|ellipse|use)\b/i,C=(r,e,t)=>{let i=new RegExp(`\\s${e}="[^"]*"`,"i");return i.test(r)?r.replace(i,` ${e}="${t}"`):r.replace(/<svg\b/i,`<svg ${e}="${t}"`)},xe=r=>r.replace(/&/g,"&").replace(/"/g,"""),te=r=>`<image href="${xe(r)}" x="14" y="12" width="22" height="22" style="filter: brightness(0) invert(1);" />`,we=r=>{let e=r.trim();if(Ce.test(e)){let t=C(e,"x","14");return t=C(t,"y","12"),t=C(t,"width","22"),t=C(t,"height","22"),/\spreserveAspectRatio="/i.test(t)||(t=t.replace(/<svg\b/i,'<svg preserveAspectRatio="xMidYMid meet"')),t}return`<g transform="translate(14 12)">${e}</g>`},Ie=({innerSvg:r,innerUrl:e})=>{let t=r?.trim(),i=e?.trim();return t?Se.test(t)?we(t):te(t):i?te(i):""},re=(r,e={})=>`<svg
|
|
2
2
|
width="50"
|
|
3
3
|
height="62"
|
|
4
4
|
viewBox="0 0 50 62"
|
|
@@ -67,7 +67,7 @@ var Me=Object.defineProperty;var k=(r,e)=>{for(var t in e)Me(r,t,{get:e[t],enume
|
|
|
67
67
|
/>
|
|
68
68
|
</clipPath>
|
|
69
69
|
</defs>
|
|
70
|
-
</svg>`;var H=class{constructor(e){this.props=e;this.element=this.createElement()}createElement(){let e=document.createElement("div");e.style.cursor="pointer";let t=this.props.svg?this.applyColorToCustomSvg(this.props.svg):re(this.props.color??"#278960",{innerSvg:this.props.innerSvg,innerUrl:this.props.innerUrl});return e.innerHTML=t,this.props.draggable&&(e.draggable=!0),e}applyColorToCustomSvg(e){return this.props.color?e.replace(/fill="[^"]*"/g,`fill="${this.props.color}"`):e}getElement(){return this.element}getCoordinates(){return this.props.coordinates}isDraggable(){return!!this.props.draggable}getAnchor(){return this.props.anchor||"center"}};function ie(r,e,t){return new r.Marker({element:t.getElement(),draggable:t.isDraggable?.()??!1,anchor:t.getAnchor?.()??"center"}).setLngLat(t.getCoordinates()).addTo(e)}var Pe={dark:Y,light:Q},Ee={dark:"#ffffff",light:"#19191a"},h=class h{constructor(){this.isReady=!1;this.readyCallbacks=[];this.language="tj";this.instanceKey="";this.engine="legacy";this.gramBase=T;this.gramPreset=L.light;this.presetIsExplicit=!1}static getInstanceKey(e){return typeof e.container=="string"&&e.container?e.container:"map"}static normalizeLanguage(e){return e==="ru"?"ru":"tj"}static setDefaultLanguage(e){h.defaultLanguage=h.normalizeLanguage(e)}static getDefaultStyle(e,t){return F(Pe[e],t,h.getMapToken())}static getVectorStyle(){return F(ee,void 0,h.getMapToken())}static getMapToken(){let e=v();if(!e)throw new Error("[MahalMap SDK] Map API key is required. Call keyUtils.saveKey() before creating the map or pass apikey in the SDK script URL.");return e}static getMaps3DCtor(e){if(e)return e;if(typeof window>"u")return;let t=window.Maps3D;return typeof t=="function"?t:t?.Maps3D}static create(e,t,i){let s=(typeof window<"u"?window.maplibregl:void 0)||t;if(!s)throw new Error("[MahalMap SDK] MapLibre GL was not found. Pass it as the second argument or include it through a script.");let o=h.normalizeLanguage(e.lang||h.defaultLanguage),p=e.theme==="dark"?"dark":"light",l=e.engine==="3d"?"3d":"legacy",a=new h,u=h.getInstanceKey(e);if(a.options=e,a.language=o,a.instanceKey=u,a.maplibre=s,a.engine=l,l==="3d"){a.gramBase=e.base||T,a.presetIsExplicit=!!e.preset,a.gramPreset=e.preset||L[p],a.maps3dCtor=h.getMaps3DCtor(i);let d=e.style?e.style:A(a.gramBase,a.gramPreset),c=a.maps3dCtor?a.maps3dCtor.transformRequest({base:a.gramBase,apiKey:v()||void 0}):void 0;if(a.map=new s.Map({container:e.container||"map",style:d,center:e.center||[69.624024,40.279687],zoom:e.zoom||5,pitch:e.pitch
|
|
70
|
+
</svg>`;var H=class{constructor(e){this.props=e;this.element=this.createElement()}createElement(){let e=document.createElement("div");e.style.cursor="pointer";let t=this.props.svg?this.applyColorToCustomSvg(this.props.svg):re(this.props.color??"#278960",{innerSvg:this.props.innerSvg,innerUrl:this.props.innerUrl});return e.innerHTML=t,this.props.draggable&&(e.draggable=!0),e}applyColorToCustomSvg(e){return this.props.color?e.replace(/fill="[^"]*"/g,`fill="${this.props.color}"`):e}getElement(){return this.element}getCoordinates(){return this.props.coordinates}isDraggable(){return!!this.props.draggable}getAnchor(){return this.props.anchor||"center"}};function ie(r,e,t){return new r.Marker({element:t.getElement(),draggable:t.isDraggable?.()??!1,anchor:t.getAnchor?.()??"center"}).setLngLat(t.getCoordinates()).addTo(e)}var Pe={dark:Y,light:Q},Ee={dark:"#ffffff",light:"#19191a"},h=class h{constructor(){this.isReady=!1;this.readyCallbacks=[];this.language="tj";this.instanceKey="";this.engine="legacy";this.gramBase=T;this.gramPreset=L.light;this.presetIsExplicit=!1}static getInstanceKey(e){return typeof e.container=="string"&&e.container?e.container:"map"}static normalizeLanguage(e){return e==="ru"?"ru":"tj"}static setDefaultLanguage(e){h.defaultLanguage=h.normalizeLanguage(e)}static getDefaultStyle(e,t){return F(Pe[e],t,h.getMapToken())}static getVectorStyle(){return F(ee,void 0,h.getMapToken())}static getMapToken(){let e=v();if(!e)throw new Error("[MahalMap SDK] Map API key is required. Call keyUtils.saveKey() before creating the map or pass apikey in the SDK script URL.");return e}static getMaps3DCtor(e){if(e)return e;if(typeof window>"u")return;let t=window.Maps3D;return typeof t=="function"?t:t?.Maps3D}static create(e,t,i){let s=(typeof window<"u"?window.maplibregl:void 0)||t;if(!s)throw new Error("[MahalMap SDK] MapLibre GL was not found. Pass it as the second argument or include it through a script.");let o=h.normalizeLanguage(e.lang||h.defaultLanguage),p=e.theme==="dark"?"dark":"light",l=e.engine==="3d"?"3d":"legacy",a=new h,u=h.getInstanceKey(e);if(a.options=e,a.language=o,a.instanceKey=u,a.maplibre=s,a.engine=l,l==="3d"){a.gramBase=e.base||T,a.presetIsExplicit=!!e.preset,a.gramPreset=e.preset||L[p],a.maps3dCtor=h.getMaps3DCtor(i);let d=e.style?e.style:A(a.gramBase,a.gramPreset),c=a.maps3dCtor?a.maps3dCtor.transformRequest({base:a.gramBase,apiKey:v()||void 0}):void 0;if(a.map=new s.Map({container:e.container||"map",style:d,center:e.center||[69.624024,40.279687],zoom:e.zoom||5,attributionControl:!1,...e.pitch!==void 0?{pitch:e.pitch}:{},...e.bearing!==void 0?{bearing:e.bearing}:{},...c?{transformRequest:c}:{}}),e.enable3D){if(!a.maps3dCtor)throw new Error("[MahalMap SDK] Maps3D was not found. Pass it as the third argument to create() or include it through a script (window.Maps3D).");a.maps3dLayer=new a.maps3dCtor({apiKey:v()||void 0,base:a.gramBase,buildings:!0,...e.maps3d}),a.maps3dLayer.attach(a.map)}}else{let d=e.autoAddVectorSource?h.getVectorStyle():e.style?e.style:h.getDefaultStyle(p,o);a.map=new s.Map({container:e.container||"map",style:d,center:e.center||[69.624024,40.279687],zoom:e.zoom||5,attributionControl:!1,...e.pitch!==void 0?{pitch:e.pitch}:{},...e.bearing!==void 0?{bearing:e.bearing}:{}})}return a.addLogo(p),a.map.on("load",()=>{a.isReady=!0,a.camera=new y(a.map),a.readyCallbacks.forEach(d=>d(a.map)),a.readyCallbacks=[]}),h.instances.set(u,a),a}static onReady(e,t){if(!h.instances.has(e)){let n=setInterval(()=>{h.instances.has(e)&&(clearInterval(n),h.onReady(e,t))},50);return}let i=h.getInstance(e);i.isReady?t(i.map):i.readyCallbacks.push(t)}static getInstance(e){let t=h.instances.get(e);if(!t)throw new Error("[MahalMap SDK] Map instance is not created");return t}static hasInstance(e){return h.instances.has(e)}static removeInstance(e){return h.instances.delete(e)}static addMarker(e,t){return e.addMarker(t)}static getCamera(e){return e.getCamera()}static getMap(e){return e.getMap()}static setStyle(e,t){e.setStyle(t)}static getMaps3DLayer(e){return e.getMaps3DLayer()}static setLanguage(e,t){e.setLanguage(t)}static setCenter(e,t){e.setCenter(t)}static setZoom(e,t){e.setZoom(t)}static destroy(e){e.destroy()}addMarker(e){return ie(this.maplibre,this.map,e)}init(e){this.map=e,this.camera=new y(e)}getCamera(){return this.camera}getMap(){return this.map}setStyle(e){if(this.options.theme=e,this.engine==="3d"){if(this.options.style||this.presetIsExplicit)return;this.gramPreset=L[e],this.map.setStyle(A(this.gramBase,this.gramPreset)),this.updateLogoColor(e);return}this.options.autoAddVectorSource||(this.options.style||this.map.setStyle(h.getDefaultStyle(e,this.language)),this.updateLogoColor(e))}setLanguage(e){if(this.language=h.normalizeLanguage(e),this.options.lang=this.language,this.engine==="3d"||this.options.autoAddVectorSource||this.options.style)return;let t=this.options.theme==="dark"?"dark":"light";this.map.setStyle(h.getDefaultStyle(t,this.language))}getMaps3DLayer(){return this.maps3dLayer}setCenter(e){this.map.setCenter(e)}setZoom(e){this.map.setZoom(e)}destroy(){this.maps3dLayer?.destroy?.(),this.maps3dLayer?.remove?.(),this.maps3dLayer=void 0,this.logoObserver?.disconnect(),this.logoObserver=void 0,this.logoHost?.remove(),this.logoHost=void 0,this.logoShadow=void 0,this.map.remove(),h.instances.delete(this.instanceKey)}addLogo(e){let t=this.map.getContainer(),i=document.createElement("div"),n=i.attachShadow({mode:"closed"});i.setAttribute("aria-label","Mahal"),i.dataset.mahal=Math.random().toString(36).slice(2),this.logoHost=i,this.logoShadow=n,this.applyLogoHostStyles(),this.renderLogo(e),t.appendChild(i),this.observeLogo(t)}updateLogoColor(e){this.logoShadow&&this.renderLogo(e)}renderLogo(e){this.logoShadow&&(this.logoShadow.innerHTML=`
|
|
71
71
|
<style>
|
|
72
72
|
:host {
|
|
73
73
|
all: initial;
|