@feltmaps/js-sdk 1.0.0

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/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2024 Felt Maps, Inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # @feltmaps/js-sdk
2
+
3
+ An SDK for Felt maps.
4
+
5
+ Documentation site is coming soon.
6
+
7
+ ## Getting started
8
+
9
+ Install the SDK using your preferred package manager:
10
+
11
+ ```bash
12
+ npm install @feltmaps/js-sdk
13
+ ```
14
+
15
+ Embed a Felt map in your app and use the SDK to control it:
16
+
17
+ ```typescript
18
+ import { Felt } from "@feltmaps/js-sdk";
19
+
20
+ const map = await Felt.embed(
21
+ document.querySelector("#container"),
22
+ "FELT_MAP_ID",
23
+ );
24
+ const layers = await map.getLayers();
25
+ const elements = await map.getElements();
26
+ ```
@@ -0,0 +1 @@
1
+ "use strict";var c=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var I=(e,r)=>{for(var n in r)c(e,n,{get:r[n],enumerable:!0})},M=(e,r,n,i)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of F(r))!G.call(e,o)&&o!==n&&c(e,o,{get:()=>r[o],enumerable:!(i=V(r,o))||i.enumerable});return e};var b=e=>M(c({},"__esModule",{value:!0}),e);var x={};I(x,{Felt:()=>f});module.exports=b(x);function s(e,r){return({handler:n,options:i})=>{let o=new MessageChannel,a=crypto.randomUUID();return e.postMessage({type:"felt.addListener",event:i?{eventName:r,id:a,options:i}:{eventName:r,id:a}},"*",[o.port2]),o.port1.onmessage=m=>{n(m.data)},()=>{o.port1.onmessage=null,o.port1.close(),o.port2.close(),e.postMessage({type:"felt.removeListener",id:a},"*")}}}function t(e,r){return n=>{let i=new MessageChannel;return e.postMessage({type:r,params:n},"*",[i.port2]),new Promise(o=>{i.port1.onmessage=a=>{o(a.data),i.port1.close(),i.port2.close()}})}}var u=e=>({getElement:t(e,"getElement"),getElementGeometry:t(e,"getElementGeometry"),getElements:t(e,"getElements"),setElementGroupVisibility:t(e,"setElementGroupVisibility"),getElementGroup:t(e,"getElementGroup"),getElementGroups:t(e,"getElementGroups"),onElementChange:s(e,"onElementChange"),onElementGroupChange:s(e,"onElementGroupChange")});var C=e=>({onPointerClick:s(e,"onPointerClick"),onPointerMove:s(e,"onPointerMove")});var h=e=>({getLayer:t(e,"getLayer"),getLayers:t(e,"getLayers"),setLayerVisibility:t(e,"setLayerVisibility"),onLayerChange:s(e,"onLayerChange"),getLayerGroup:t(e,"getLayerGroup"),getLayerGroups:t(e,"getLayerGroups"),setLayerGroupVisibility:t(e,"setLayerGroupVisibility"),onLayerGroupChange:s(e,"onLayerGroupChange"),getLegendItem:t(e,"getLegendItem"),getLegendItems:t(e,"getLegendItems"),setLegendItemVisibility:t(e,"setLegendItemVisibility"),onLegendItemChange:s(e,"onLegendItemChange"),getLayerFilters:t(e,"getLayerFilters"),setLayerFilters:t(e,"setLayerFilters"),getRenderedFeatures:t(e,"getRenderedFeatures")});var L=e=>({onSelectionChange:s(e,"onSelectionChange"),getSelection:t(e,"getSelection")});var v=e=>({updateUiControls:t(e,"updateUiControls"),setOnMapInteractionsUi:t(e,"setOnMapInteractionsUi")});var E=e=>({getViewport:t(e,"getViewport"),setViewport:t(e,"setViewport"),fitViewportToBounds:t(e,"fitViewportToBounds"),onViewportMove:s(e,"onViewportMove"),onViewportMoveEnd:s(e,"onViewportMoveEnd")});function P(e){return{iframe:null,...E(e),...v(e),...h(e),...u(e),...L(e),...C(e)}}var f={embed(e,r,n){let i={uiControls:{showLegend:!0,cooperativeGestures:!0,fullScreenButton:!0,geolocation:!1,zoomControls:!0,scaleBar:!0},initialViewport:void 0,origin:"https://felt.com"},o={showLegend:"legend",cooperativeGestures:"cooperativeGestures",fullScreenButton:"link",geolocation:"geolocation",zoomControls:"zoomControls",scaleBar:"scaleBar"},a={...i.uiControls,...n?.uiControls},m=n?.origin??i.origin,d=new URL(`${m}/embed/map/${r}`);for(let[p,y]of T(a))y!=null&&d.searchParams.set(o[p],y?"1":"0");if(n?.initialViewport){let p=n.initialViewport;d.searchParams.set("loc",`${p.center.latitude},${p.center.longitude},${p.zoom}z`)}let g=e.tagName==="IFRAME",l=g?e:e.ownerDocument.createElement("iframe");return l.src=d.toString(),g||(l.style.width="100%",l.style.height="100%",l.style.border="none",l.style.margin="0",e.appendChild(l)),l.referrerPolicy="strict-origin-when-cross-origin",new Promise((p,y)=>{l.addEventListener("load",()=>{l.contentWindow==null?y(new Error("Failed to load Felt map")):p(l.contentWindow)},{once:!0})}).then(f.connect).then(p=>(Object.defineProperties(p,{iframe:{value:l,writable:!1,configurable:!1}}),p))},connect(e){let r=P(e);return new Promise((n,i)=>{let o=setTimeout(()=>{i(new Error("Failed to load Felt map")),clearInterval(m)},5e3),a=new MessageChannel,m=setInterval(()=>{e.postMessage({type:"felt.ready"},"*",[a.port2])},100);a.port1.onmessage=d=>{d.data===!0&&(clearInterval(m),clearTimeout(o),a.port1.close(),a.port2.close(),n(r))}})}},T=Object.entries;0&&(module.exports={Felt});