{
  "version": 3,
  "sources": ["../../../../shared/src/ServiceMap.ts"],
  "sourcesContent": ["import type { BootstrappedWindow, ServiceMap } from \"@framerjs/bootstrap\"\nexport type { ServiceMap }\n\nlet cachedServiceMap: ServiceMap | undefined\n\nexport function getServiceMap(): ServiceMap {\n\t// In non browser contexts there is no service map so we just return non functional stub which\n\t// is good enough for code to initialize.\n\tif (typeof window === \"undefined\") return {} as ServiceMap\n\n\tif (cachedServiceMap) return cachedServiceMap\n\tcachedServiceMap = extractServiceMap()\n\treturn cachedServiceMap\n}\n\nfunction extractServiceMap(): ServiceMap {\n\tconst location = window.location\n\n\t// First check for the service map embedded on the page.\n\t// TODO: Embed it in a nicer way (a script tag that exposes getServiceMap()).\n\tlet services = (window as BootstrappedWindow)?.bootstrap?.services\n\tif (services) {\n\t\treturn services\n\t}\n\t// If the service map is not available, try accessing the top frame.\n\tlet topOrigin: string | undefined\n\ttry {\n\t\tconst topWindow = window.top as BootstrappedWindow\n\t\t// This fails if we are sandboxed from the top frame.\n\t\ttopOrigin = topWindow.location.origin\n\t\tservices = (window.top as BootstrappedWindow)?.bootstrap?.services\n\t\tif (services) {\n\t\t\treturn services\n\t\t}\n\t} catch (e) {\n\t\t// Ignore\n\t}\n\tif (process.env.NODE_ENV !== \"development\" && topOrigin && topOrigin !== location.origin) {\n\t\tthrow Error(`Unexpectedly embedded by ${topOrigin} (expected ${location.origin})`)\n\t}\n\t// Don't trust any values if we get here on what seems to be a framer.com domain.\n\tif (location.origin.endsWith(\"framer.com\") || location.origin.endsWith(\"framer.dev\")) {\n\t\tthrow Error(\"ServiceMap data was not provided in document\")\n\t}\n\t// If we get here we're sandboxed from the top frame.\n\t// TODO: Provide this data via a trusted endpoint instead of query string.\n\ttry {\n\t\tconst servicesJSON =\n\t\t\tnew URLSearchParams(location.search).get(\"services\") ||\n\t\t\tnew URLSearchParams(location.hash.substring(1)).get(\"services\")\n\t\tif (servicesJSON) {\n\t\t\tservices = JSON.parse(servicesJSON)\n\t\t}\n\t} catch (e) {\n\t\t// Ignore\n\t}\n\tif (services && typeof services === \"object\" && services.api) {\n\t\treturn services\n\t}\n\tthrow Error(\"ServiceMap requested but not available\")\n}\n"],
  "mappings": ";AAGA,IAAI;AAEG,SAAS,gBAA4B;AAG3C,MAAI,OAAO,WAAW,YAAa,QAAO,CAAC;AAE3C,MAAI,iBAAkB,QAAO;AAC7B,qBAAmB,kBAAkB;AACrC,SAAO;AACR;AAEA,SAAS,oBAAgC;AACxC,QAAM,WAAW,OAAO;AAIxB,MAAI,WAAY,QAA+B,WAAW;AAC1D,MAAI,UAAU;AACb,WAAO;AAAA,EACR;AAEA,MAAI;AACJ,MAAI;AACH,UAAM,YAAY,OAAO;AAEzB,gBAAY,UAAU,SAAS;AAC/B,eAAY,OAAO,KAA4B,WAAW;AAC1D,QAAI,UAAU;AACb,aAAO;AAAA,IACR;AAAA,EACD,SAAS,GAAG;AAAA,EAEZ;AACA,MAAI,OAAsF;AACzF,UAAM,MAAM,4BAA4B,SAAS,cAAc,SAAS,MAAM,GAAG;AAAA,EAClF;AAEA,MAAI,SAAS,OAAO,SAAS,YAAY,KAAK,SAAS,OAAO,SAAS,YAAY,GAAG;AACrF,UAAM,MAAM,8CAA8C;AAAA,EAC3D;AAGA,MAAI;AACH,UAAM,eACL,IAAI,gBAAgB,SAAS,MAAM,EAAE,IAAI,UAAU,KACnD,IAAI,gBAAgB,SAAS,KAAK,UAAU,CAAC,CAAC,EAAE,IAAI,UAAU;AAC/D,QAAI,cAAc;AACjB,iBAAW,KAAK,MAAM,YAAY;AAAA,IACnC;AAAA,EACD,SAAS,GAAG;AAAA,EAEZ;AACA,MAAI,YAAY,OAAO,aAAa,YAAY,SAAS,KAAK;AAC7D,WAAO;AAAA,EACR;AACA,QAAM,MAAM,wCAAwC;AACrD;",
  "names": []
}
