{"version":3,"file":"WebComponents.mjs","sources":["../../../src/bindings/WebComponents.tsx"],"sourcesContent":["import type { Callbacks, StytchEvent, StytchProjectConfigurationInput, StytchSDKUIError } from '@stytch/core/public';\nimport { injectCssIntoNode, injectGlobalStyle } from '@stytch/internal-style-injector';\nimport type { SDKConfig } from '@stytch/web';\nimport type { B2BSDKConfig } from '@stytch/web/b2b';\nimport React, { ComponentType } from 'react';\nimport { flushSync, render, unmountComponentAtNode } from 'react-dom';\n\n// This doesn't really work I think, but it might in a future version of TS?\ntype ValidPropKeys = Exclude<string, keyof HTMLElement>;\n\n/**\n * See https://stytch.com/docs/sdks/ui-callbacks for B2C and https://stytch.com/docs/b2b/sdks/ui-callbacks for B2B\n * event types and data\n */\nexport class StytchDOMEvent<T extends StytchEvent = StytchEvent> extends Event {\n  readonly stytchEventType: T['type'];\n  readonly stytchEventData: T['data'];\n\n  constructor(event: T) {\n    // Event names are lowercase for Vue which only accepts lowercase events\n    super('stytch-event', { composed: true });\n\n    this.stytchEventType = event.type;\n    this.stytchEventData = event.data;\n  }\n}\n\n/**\n * DOM event wrapper around {@link StytchSDKUIError}\n */\nexport class StytchError extends Event {\n  constructor(public readonly error: StytchSDKUIError) {\n    super('stytch-error', { composed: true });\n  }\n}\n\n// Typing for public methods on the WebComponent\ninterface StytchWebComponentMethods<Props> {\n  render(props: Props): void;\n  flushRender(): void;\n}\n\nexport type StytchWebComponent<Props extends Record<ValidPropKeys, unknown>> = HTMLElement &\n  Props &\n  StytchWebComponentMethods<Props>;\n\nexport type StytchWebComponentConstructor<Props extends Record<ValidPropKeys, unknown>> = new (init?: {\n  shadow?: boolean;\n}) => StytchWebComponent<Props>;\n\nexport type CreateWebComponentOptions<Props extends Record<ValidPropKeys, unknown>> = {\n  /** The name of every property the component should support, i.e. every property on Props */\n  propNames: readonly (keyof Props)[];\n\n  /**\n   * The name of DOM attributes we want to support. This should be every primitive prop\n   * (i.e. string, number and boolean). Currently the code only properly supports strings, since boolean and numbers\n   * needs casting\n   **/\n  attributeNames?: readonly (keyof Props)[];\n};\n\n/**\n * Creates a web component based on a React component, and an imperative mount() function\n * (mostly for backwards compatibility).\n *\n * Implementation notes:\n * - The component allows for attributes, properties and events. Props and attributes need to be declared\n *   and are handled separately.\n * - Currently, attributes are just treated all as strings, but in the future if we want we can also write\n *   functions to cast to booleans and numbers. We reflect attributes to properties following\n *   https://web.dev/articles/custom-elements-best-practices#avoid_reentrancy_issues\n * - Events are regular DOM events and fired using regular DOM dispatchEvent function\n * - Props use a setter to trigger re-rendering. We use an internal, private #props mainly to make\n *   types work. It also prevents Props clobbering HTML element properties.\n * - To allow multiple props to be set all at once, we schedule a render rather than immediately rendering\n *   on setting props. We also expose a render() function that lets users set multiple props at once.\n * - For rare cases where users want to render immediately, we also expose a flushRender() function\n *   (similar to React)\n * - The types are quite messy. TS does not have great higher order types needed to support the stuff\n *   here so there's going to be a lot of casting. See comments for explanation. We also manually write\n *   types (StytchWebComponentConstructor) and cast them to it.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function createWebComponent<Props extends Record<ValidPropKeys, unknown>>(\n  Component: ComponentType<Props>,\n  { propNames, attributeNames = [] }: CreateWebComponentOptions<Props>,\n) {\n  // If we're not in a browser env, return noop classes and components to avoid code trying to run the code below\n  // which would only work in a browser\n  if (typeof window === 'undefined') {\n    return class implements StytchWebComponentMethods<Props> {\n      render() {\n        // noop\n      }\n      flushRender() {\n        // noop\n      }\n      // This is also missing the HTMLElement part, but it must not try to extend that class\n      // since it will not exist in non-browser environments\n    } as unknown as StytchWebComponentConstructor<Props>;\n  }\n\n  // HTML attribute names are all lowercase, so we use a map of lowercase attribute name to camelCase prop name\n  // https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute\n  const attributeNameMap = Object.fromEntries(attributeNames.map((attr) => [(attr as string).toLowerCase(), attr]));\n\n  // This class only implements StytchWebComponentMethods. It is basically impossible to type the '& Props'\n  // part of the type. We implement in the constructor using Object.defineProperties but TS do not have the\n  // higher order typings needed to make this really work, so we make a best-effort to type it, then use casts\n  // to make up for it\n  return class WebComponent extends HTMLElement implements StytchWebComponentMethods<Props> {\n    /** Root element is the element our React component is mounted into */\n    #mountPoint: HTMLElement | undefined;\n\n    static observedAttributes = Object.keys(attributeNameMap);\n\n    readonly #shadow: boolean;\n    #renderQueued = false;\n    #props = {} as Props;\n\n    constructor({ shadow }: { shadow?: boolean } = {}) {\n      super();\n\n      // The shadow attribute can be set either already on the element, or passed in via the constructor.\n      this.#shadow = shadow ?? this.getAttribute('shadow') != null;\n\n      // For other attributes, reflect attributes to property\n      for (const attr of WebComponent.observedAttributes) {\n        const value = this.getAttribute(attr as string);\n        if (value != null) {\n          const propName = attributeNameMap[attr];\n          this.#props[propName] = value as Props[typeof attr];\n        }\n      }\n\n      for (const propName of propNames) {\n        // In case properties were set before the component is registered\n        if (Object.hasOwn(this, propName)) {\n          this.#props[propName] = (this as unknown as Props)[propName];\n        }\n\n        // Make all accepted props reactive by defining getter/setter pairs for them\n        // and triggering re-render on set\n        Object.defineProperty(this, propName, {\n          get: () => this.#props[propName],\n          set: (value) => {\n            // as string to exclude symbol and number even though they are not allowed in the Record key types\n            if (attributeNames.includes(propName)) this.setAttribute(propName as string, value);\n\n            this.#props[propName] = value;\n            this.#queueRender();\n          },\n        });\n      }\n    }\n\n    connectedCallback() {\n      if (!this.#mountPoint) {\n        this.#mountPoint = document.createElement('div');\n\n        if (this.#shadow) {\n          this.setAttribute('shadow', 'true');\n          const shadowRoot = this.attachShadow({ mode: 'open' });\n          shadowRoot.appendChild(injectCssIntoNode());\n          shadowRoot.appendChild(this.#mountPoint);\n        } else {\n          injectGlobalStyle();\n          this.appendChild(this.#mountPoint);\n        }\n      }\n\n      this.#queueRender();\n    }\n\n    disconnectedCallback() {\n      if (this.#mountPoint) {\n        unmountComponentAtNode(this.#mountPoint);\n      }\n    }\n\n    attributeChangedCallback(name: string, oldValue: string, newValue: string) {\n      const propName = attributeNameMap[name];\n      this.#props[propName] = newValue as Props[typeof propName];\n    }\n\n    render(props: Props) {\n      Object.assign(this, props);\n    }\n\n    flushRender() {\n      flushSync(() => {\n        this.#renderInternal();\n      });\n    }\n\n    // Internal methods\n    #queueRender() {\n      // We only want to call render once per tick\n      if (!this.#renderQueued) {\n        this.#renderQueued = true;\n\n        window.queueMicrotask(() => {\n          this.#renderInternal();\n        });\n      }\n    }\n\n    // This works with the one-tap slot defined in B2C GoogleOneTap. The node must be visible\n    // to the outer DOM since the Google script looks for the node there, so use a slot we control\n    // ourselves to do that\n    #renderOneTap(props: Props) {\n      const config = getConfig(props);\n      if (\n        !config?.oauthOptions?.providers.some(\n          (config) => typeof config === 'object' && config.type === 'google' && config.one_tap,\n        )\n      ) {\n        return;\n      }\n\n      if (!this.querySelector('#google-parent-prompt')) {\n        const mountPoint = document.createElement('div');\n        mountPoint.id = 'google-parent-prompt';\n        mountPoint.slot = 'one-tap';\n        this.appendChild(mountPoint);\n      }\n    }\n\n    #callbacks: Callbacks<StytchProjectConfigurationInput> = {\n      onError: (error) => {\n        getCallbacks(this.#props)?.onError?.(error);\n        this.dispatchEvent(new StytchError(error));\n      },\n      onEvent: (event: StytchEvent<StytchProjectConfigurationInput>) => {\n        getCallbacks(this.#props)?.onEvent?.(event);\n        this.dispatchEvent(new StytchDOMEvent(event));\n      },\n    };\n\n    #renderInternal() {\n      // This can happen if you try to update props before inserting this into the DOM\n      if (!this.#mountPoint) return;\n\n      this.#renderQueued = false;\n\n      // Assume the component is not ready yet if there are no props\n      if (Object.keys(this.#props).length === 0) {\n        return;\n      }\n\n      this.#renderOneTap(this.#props);\n\n      // Reflect shadow attr back onto enableShadowDOM config\n      let props = this.#props;\n      if (this.#shadow) {\n        props = setShadow(props);\n      }\n\n      render(<Component {...props} callbacks={this.#callbacks} />, this.#mountPoint);\n    }\n  } as unknown as StytchWebComponentConstructor<Props>;\n}\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function createMountFn<Props extends Record<ValidPropKeys, unknown>>(\n  defaultName: string,\n  WebComponent: StytchWebComponentConstructor<Props>,\n) {\n  if (typeof window === 'undefined') {\n    return () => null as unknown as StytchWebComponent<Props>;\n  }\n\n  return ({ elementId, ...props }: Props & { elementId: string }) => {\n    // Custom elements can only be defined once\n    if (!customElements.get(defaultName)) {\n      customElements.define(defaultName, WebComponent);\n    }\n\n    const targetNode = document.querySelector(elementId);\n    if (!targetNode) {\n      throw new Error(\n        `The selector you specified (${elementId}) applies to no DOM elements that are currently on the page. Make sure the element exists on the page before calling mountLogin().`,\n      );\n    }\n\n    // Re-render if the component is already mounted\n    let node: StytchWebComponent<Props>;\n    if (\n      // HTML Node names all upper case always\n      targetNode.firstChild?.nodeName.toLowerCase() === defaultName.toLowerCase()\n    ) {\n      node = targetNode.firstChild as StytchWebComponent<Props>;\n      node.render(props as unknown as Props);\n    } else {\n      const shadow = getShadow(props);\n      node = new WebComponent({ shadow });\n      targetNode.appendChild(node);\n    }\n\n    return node;\n  };\n}\n\n// Helper to avoid having to write the long cast everywhere.\n// This duck types props have a config property which is either a B2C or B2B login config\nfunction getConfig(props: Record<string, unknown> | undefined) {\n  return (\n    props as SDKConfig<StytchProjectConfigurationInput> | B2BSDKConfig<StytchProjectConfigurationInput> | undefined\n  )?.config;\n}\n\nfunction getCallbacks(props: Record<string, unknown> | undefined) {\n  return (props as { callbacks?: Callbacks<StytchProjectConfigurationInput> }).callbacks;\n}\n\nfunction getShadow(props: Record<string, unknown>) {\n  const { config, presentation } = props as unknown as\n    | SDKConfig<StytchProjectConfigurationInput>\n    | B2BSDKConfig<StytchProjectConfigurationInput>;\n\n  return presentation?.options?.enableShadowDOM ?? config?.enableShadowDOM;\n}\n\nfunction setShadow<T extends Record<string, unknown>>(props: T): T {\n  const { presentation } = props as unknown as\n    | SDKConfig<StytchProjectConfigurationInput>\n    | B2BSDKConfig<StytchProjectConfigurationInput>;\n\n  if (getShadow(props)) {\n    return props;\n  }\n\n  return {\n    ...props,\n    presentation: {\n      ...presentation,\n      options: {\n        ...presentation?.options,\n        enableShadowDOM: true,\n      },\n    },\n  };\n}\n"],"names":["StytchDOMEvent","Event","stytchEventType","stytchEventData","event","composed","type","data","StytchError","error","createWebComponent","Component","propNames","attributeNames","window","render","flushRender","attributeNameMap","Object","fromEntries","map","attr","toLowerCase","WebComponent","HTMLElement","observedAttributes","keys","shadow","getAttribute","value","propName","hasOwn","defineProperty","get","set","includes","setAttribute","connectedCallback","document","createElement","shadowRoot","attachShadow","mode","appendChild","injectCssIntoNode","injectGlobalStyle","disconnectedCallback","unmountComponentAtNode","attributeChangedCallback","name","oldValue","newValue","props","assign","flushSync","queueMicrotask","config","getConfig","oauthOptions","providers","some","one_tap","querySelector","mountPoint","id","slot","onError","getCallbacks","dispatchEvent","onEvent","length","setShadow","React","callbacks","createMountFn","defaultName","elementId","customElements","define","targetNode","Error","node","firstChild","nodeName","getShadow","presentation","options","enableShadowDOM"],"mappings":";;;AAUA;;;IAIO,MAAMA,cAAAA,SAA4DC,KAAAA,CAAAA;IAC9DC,eAAAA;IACAC,eAAAA;AAET,IAAA,WAAA,CAAYC,KAAQ,CAAE;;AAEpB,QAAA,KAAK,CAAC,cAAA,EAAgB;YAAEC,QAAAA,EAAU;AAAK,SAAA,CAAA;AAEvC,QAAA,IAAI,CAACH,eAAe,GAAGE,KAAAA,CAAME,IAAI;AACjC,QAAA,IAAI,CAACH,eAAe,GAAGC,KAAAA,CAAMG,IAAI;AACnC,IAAA;AACF;AAEA;;IAGO,MAAMC,WAAAA,SAAoBP,KAAAA,CAAAA;;IAC/B,WAAA,CAA4BQ,KAAuB,CAAE;AACnD,QAAA,KAAK,CAAC,cAAA,EAAgB;YAAEJ,QAAAA,EAAU;AAAK,SAAA,CAAA,EAAA,IAAA,CADbI,KAAAA,GAAAA,KAAAA;AAE5B,IAAA;AACF;AA4BA;;;;;;;;;;;;;;;;;;;;AAoBC,+BAEM,SAASC,kBAAAA,CACdC,SAA+B,EAC/B,EAAEC,SAAS,EAAEC,cAAAA,GAAiB,EAAE,EAAoC,EA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