{"version":3,"file":"index.cjs","sources":["../src/embed-pdf.tsx"],"sourcesContent":["// The React home for embedding + agentically driving the SimplePDF editor, built\n// on the framework-free @simplepdf/embed core.\n//\n//   <EmbedPDF companyIdentifier=\"acme\" document={{ url }} onEmbedEvent={…} />   // render\n//   const { embedRef, actions } = useEmbed()                                   // drive\n//     - actions: imperative methods you call (actions.goTo({ page }))\n//   The agentic tools are the opt-in @simplepdf/react-embed-pdf/ai-sdk subpath\n//   (useEmbedTools(embedRef)), keeping zod off this entry.\n//\n// Config + actions are camelCase (JS/TS idiom); the bridge transforms to the\n// snake_case wire. ONE deliberate exception: onEmbedEvent forwards the editor's\n// outbound events VERBATIM (SCREAMING_SNAKE `type` + snake_case `data`) — the stable\n// EmbedEvent contract. useEffect is deliberate: mounting / driving the editor\n// iframe is exactly the \"synchronize with an external system\" case.\n\nimport * as React from 'react';\nimport { createPortal } from 'react-dom';\nimport { createEmbed, type EmbedDocument } from '@simplepdf/embed';\nimport type {\n  BridgeLogger,\n  BridgeResult,\n  EditorEvent,\n  EditorEventMap,\n  Embed,\n  IframeActions,\n  Locale,\n  LogPayload,\n  SelectToolInput,\n  SubmitInput,\n} from '@simplepdf/embed';\nimport { notMounted } from './not-mounted';\n\nimport './styles.scss';\n\nconst DEFAULT_COMPANY_IDENTIFIER = 'react-editor';\n\nconst assignRef = (ref: React.ForwardedRef<EmbedActions | null>, value: EmbedActions | null): void => {\n  if (typeof ref === 'function') {\n    ref(value);\n  } else if (ref !== null) {\n    ref.current = value;\n  }\n};\n\n// Deprecated argument shapes for the two imperative actions whose shape changed (the new\n// shapes supersede them). Defined once at the single boundary to the (pure camelCase) core, so\n// BOTH the forwarded ref handle and useEmbed().actions accept the deprecated forms.\nconst normalizeSelectTool = (input: SelectToolInput | SelectToolInput['tool']): SelectToolInput =>\n  typeof input === 'object' && input !== null ? input : { tool: input };\nconst normalizeSubmit = (input: SubmitInput | { downloadCopyOnDevice: boolean }): SubmitInput =>\n  'downloadCopyOnDevice' in input ? { downloadCopy: input.downloadCopyOnDevice } : input;\n\n// Earlier published versions accepted a relative `documentURL` / trigger href (it fetched the URL, which resolves\n// against the page); the core now requires an absolute URL, so resolve relative values here\n// to stay backward-compatible. Absolute URLs pass through unchanged; under SSR (no window)\n// or an unusable base (e.g. about:blank), the raw value is kept — the core then validates it.\nconst toAbsoluteUrl = (url: string): string => {\n  if (typeof window === 'undefined') {\n    return url;\n  }\n  try {\n    return new URL(url, window.location.href).href;\n  } catch {\n    return url;\n  }\n};\n\n// The forwarded ref is the FLAT EmbedActions (`embedRef.current.selectTool(...)`), not\n// the core's grouped handle — so existing ref consumers keep working (this stays a\n// non-breaking minor). It flattens the core's `embed.actions` group and overloads\n// selectTool/submit for the deprecated argument shapes.\nconst toEmbedActions = (embed: Embed): EmbedActions => ({\n  ...embed.actions,\n  selectTool: (input) => embed.actions.selectTool(normalizeSelectTool(input)),\n  submit: (input) => embed.actions.submit(normalizeSubmit(input)),\n});\n\n// --- EmbedPDF ---------------------------------------------------------------\n\n// The editor's outbound events, forwarded to onEmbedEvent VERBATIM — the stable,\n// established event contract (SCREAMING_SNAKE `type` + snake_case `data`). It is\n// the core's EditorEvent re-exported (single owner; no restated copy).\nexport type EmbedEvent = EditorEvent;\n\ntype CommonEmbedPDFProps = {\n  // Your companyIdentifier: the <companyIdentifier>.simplepdf.com subdomain from\n  // your SimplePDF account (defaults to the free no-account 'react-editor').\n  companyIdentifier?: string;\n  baseDomain?: string;\n  // The document to open, same typed shape as createEmbed: one of { url } |\n  // { dataUrl } | { file }. A SimplePDF documents URL loads directly (prefill etc.).\n  document?: EmbedDocument;\n  /** @deprecated Use `document={{ url: '…' }}` instead (still accepted). */\n  documentURL?: string;\n  context?: Record<string, unknown>;\n  locale?: Locale;\n  onEmbedEvent?: (event: EmbedEvent) => void | Promise<void>;\n  // Optional: structured logging of the bridge lifecycle + errors.\n  logger?: BridgeLogger;\n};\n\ntype InlineEmbedPDFProps = CommonEmbedPDFProps & {\n  // Opt into inline: the editor renders directly in your layout.\n  mode: 'inline';\n  className?: string;\n  style?: React.CSSProperties;\n};\n\ntype ModalEmbedPDFProps = CommonEmbedPDFProps & {\n  // Modal is the DEFAULT (mode omitted === 'modal'): a click-to-open editor.\n  mode?: 'modal';\n  // The clickable trigger; clicking it opens the editor (loading `document`) in a modal.\n  children: React.ReactNode;\n};\n\nexport type EmbedPDFProps = InlineEmbedPDFProps | ModalEmbedPDFProps;\n\ntype SurfaceProps = {\n  companyIdentifier: string;\n  baseDomain?: string;\n  document?: EmbedDocument;\n  locale?: Locale;\n  context?: Record<string, unknown>;\n  logger?: BridgeLogger;\n  onEmbedEvent?: (event: EmbedEvent) => void | Promise<void>;\n  className?: string;\n  style?: React.CSSProperties;\n};\n\n// Renders a container div and mounts the editor iframe inside it via createEmbed.\n// Mount/unmount of this component drives create/dispose, so the modal gets the\n// same lifecycle for free (it mounts the surface only while open).\nconst EmbedSurface = React.forwardRef<EmbedActions | null, SurfaceProps>((props, ref) => {\n  const { companyIdentifier, baseDomain, document: embedDocument, locale, context, className, style } = props;\n  const containerRef = React.useRef<HTMLDivElement>(null);\n\n  // Keep callbacks + logger in a ref so changing them does not remount the iframe.\n  const callbacksRef = React.useRef({ onEmbedEvent: props.onEmbedEvent, logger: props.logger });\n  callbacksRef.current = { onEmbedEvent: props.onEmbedEvent, logger: props.logger };\n\n  // A stable logger that always delegates to the latest `logger` prop, so a\n  // changed logger reaches the already-mounted bridge without a remount.\n  const stableLogger = React.useMemo<BridgeLogger>(() => {\n    const delegate =\n      (level: 'debug' | 'info' | 'warn' | 'error') =>\n      (event: string, payload: LogPayload): void => {\n        // A consumer logger that throws must never break the bridge or event\n        // forwarding (this is the catch sink for onEmbedEvent failures too).\n        try {\n          callbacksRef.current.logger?.[level](event, payload);\n        } catch {\n          // swallow: logging is best-effort.\n        }\n      };\n    return { debug: delegate('debug'), info: delegate('info'), warn: delegate('warn'), error: delegate('error') };\n  }, []);\n\n  // Remount the iframe only when the editor config actually changes. Key a url /\n  // data-URL on the string itself; key a File/Blob on object IDENTITY via a counter\n  // that bumps when a different instance is passed (two distinct same-metadata Files\n  // must still remount). A fresh `{ url }` literal each render does not remount.\n  const currentFile = embedDocument !== undefined && 'file' in embedDocument ? embedDocument.file : null;\n  const fileKeyRef = React.useRef<{ file: Blob | null; key: number }>({ file: null, key: 0 });\n  if (currentFile !== fileKeyRef.current.file) {\n    fileKeyRef.current = { file: currentFile, key: fileKeyRef.current.key + 1 };\n  }\n  const documentSource = ((): string | null => {\n    if (embedDocument === undefined) {\n      return null;\n    }\n    if ('url' in embedDocument) {\n      return embedDocument.url;\n    }\n    if ('dataUrl' in embedDocument) {\n      return embedDocument.dataUrl;\n    }\n    return `file:${fileKeyRef.current.key}`;\n  })();\n  const documentName = embedDocument?.name ?? null;\n  const documentPage = embedDocument?.page ?? null;\n  const contextKey = React.useMemo((): string => {\n    if (context === undefined) {\n      return 'null';\n    }\n    try {\n      return JSON.stringify(context);\n    } catch {\n      // Circular / non-serializable context (a programmer error; encodeContext\n      // drops it too). Key on the top-level shape so render never throws.\n      return `unserializable:${Object.keys(context).sort().join(',')}`;\n    }\n  }, [context]);\n\n  React.useEffect(() => {\n    const container = containerRef.current;\n    if (container === null) {\n      return;\n    }\n    const embed = createEmbed({\n      target: container,\n      companyIdentifier,\n      baseDomain,\n      document: embedDocument,\n      locale,\n      context,\n      logger: stableLogger,\n    });\n    assignRef(ref, toEmbedActions(embed));\n    // Forward each editor event to onEmbedEvent as the verbatim { type, data }. The\n    // `forwarders` map is exhaustiveness-checked (satisfies) so a NEW editor event is a\n    // compile error here until it is forwarded; the explicit per-type subscriptions below\n    // keep each payload typed (no cast). The consumer callback is isolated so a throw /\n    // rejected promise can't break the bridge.\n    const forwardEvent = (event: EmbedEvent): void => {\n      void Promise.resolve()\n        .then(() => callbacksRef.current.onEmbedEvent?.(event))\n        .catch((error) => {\n          stableLogger.error('on_embed_event_failed', {\n            message: error instanceof Error ? error.message : String(error),\n          });\n        });\n    };\n    const forwarders = {\n      EDITOR_READY: (data) => forwardEvent({ type: 'EDITOR_READY', data }),\n      DOCUMENT_LOADED: (data) => forwardEvent({ type: 'DOCUMENT_LOADED', data }),\n      PAGE_FOCUSED: (data) => forwardEvent({ type: 'PAGE_FOCUSED', data }),\n      SUBMISSION_SENT: (data) => forwardEvent({ type: 'SUBMISSION_SENT', data }),\n    } satisfies { [TEventType in keyof EditorEventMap]: (data: EditorEventMap[TEventType]) => void };\n    const unsubscribers = [\n      embed.events.on('EDITOR_READY', forwarders.EDITOR_READY),\n      embed.events.on('DOCUMENT_LOADED', forwarders.DOCUMENT_LOADED),\n      embed.events.on('PAGE_FOCUSED', forwarders.PAGE_FOCUSED),\n      embed.events.on('SUBMISSION_SENT', forwarders.SUBMISSION_SENT),\n    ];\n    return () => {\n      for (const unsubscribe of unsubscribers) {\n        unsubscribe();\n      }\n      embed.lifecycle.dispose();\n      assignRef(ref, null);\n    };\n    // embedDocument/context are read here but fully determined by the document\n    // primitives + contextKey deps below; stableLogger is stable. `ref` is deliberately\n    // EXCLUDED: a stable object ref (the useEmbed norm) is captured once, and excluding it\n    // means an unstable inline callback ref can't trigger a full iframe teardown + remount\n    // (which would silently lose editor state) on every parent re-render.\n  }, [companyIdentifier, baseDomain, locale, documentSource, documentName, documentPage, contextKey, stableLogger]);\n\n  return <div ref={containerRef} className={className} style={style} />;\n});\nEmbedSurface.displayName = 'EmbedSurface';\n\nconst CloseIcon: React.FC = () => (\n  <svg height=\"512\" viewBox=\"0 0 512 512\" width=\"512\" xmlSpace=\"preserve\" xmlns=\"http://www.w3.org/2000/svg\">\n    <path d=\"M443.6 387.1 312.4 255.4l131.5-130c5.4-5.4 5.4-14.2 0-19.6l-37.4-37.6c-2.6-2.6-6.1-4-9.8-4-3.7 0-7.2 1.5-9.8 4L256 197.8 124.9 68.3c-2.6-2.6-6.1-4-9.8-4-3.7 0-7.2 1.5-9.8 4L68 105.9c-5.4 5.4-5.4 14.2 0 19.6l131.5 130L68.4 387.1c-2.6 2.6-4.1 6.1-4.1 9.8 0 3.7 1.4 7.2 4.1 9.8l37.4 37.6c2.7 2.7 6.2 4.1 9.8 4.1 3.5 0 7.1-1.3 9.8-4.1L256 313.1l130.7 131.1c2.7 2.7 6.2 4.1 9.8 4.1 3.5 0 7.1-1.3 9.8-4.1l37.4-37.6c2.6-2.6 4.1-6.1 4.1-9.8-.1-3.6-1.6-7.1-4.2-9.7z\" />\n  </svg>\n);\n\n// A valid React element is assumed to accept onClick + carry an href (DOM elements\n// + components that forward them). Narrowing via a type guard avoids an `as` cast\n// at the clone / href read.\nconst isTriggerElement = (\n  node: React.ReactNode,\n): node is React.ReactElement<{ href?: string; onClick?: React.MouseEventHandler }> => React.isValidElement(node);\n\n// The trigger child's href, the modal document fallback (the established pattern: a\n// <a href=\"doc.pdf\"> trigger opens that PDF). The `document` prop takes precedence.\nconst hrefOf = (node: React.ReactNode): string | undefined => (isTriggerElement(node) ? node.props.href : undefined);\n\n// Click-to-open modal chrome. The editor surface is only mounted while open, so\n// the embed is created on open and disposed on close.\nconst ModalChrome = ({\n  trigger,\n  children,\n}: {\n  trigger: React.ReactNode;\n  children: React.ReactNode;\n}): React.ReactElement => {\n  const [isOpen, setIsOpen] = React.useState(false);\n  const handleOpen = React.useCallback((event: React.MouseEvent): void => {\n    event.preventDefault();\n    setIsOpen(true);\n  }, []);\n  const handleClose = React.useCallback((): void => setIsOpen(false), []);\n  return (\n    <>\n      {isOpen\n        ? createPortal(\n            <div className=\"simplePDF_container\" role=\"dialog\" aria-modal=\"true\">\n              <div className=\"simplePDF_content\">\n                <button\n                  type=\"button\"\n                  onClick={handleClose}\n                  className=\"simplePDF_close\"\n                  aria-label=\"Close PDF editor modal\"\n                >\n                  <CloseIcon />\n                </button>\n                <div className=\"simplePDF_iframeContainer\">{children}</div>\n              </div>\n            </div>,\n            document.body,\n          )\n        : null}\n      {isTriggerElement(trigger) ? React.cloneElement(trigger, { onClick: handleOpen }) : trigger}\n    </>\n  );\n};\n\n// The single React entry point for embedding the editor: a click-to-open modal by\n// default, or inline with `mode=\"inline\"`. Forwards the typed Embed handle.\nexport const EmbedPDF = React.forwardRef<EmbedActions | null, EmbedPDFProps>((props, ref) => {\n  const companyIdentifier = props.companyIdentifier ?? DEFAULT_COMPANY_IDENTIFIER;\n  // `document` wins; otherwise the deprecated `documentURL`, resolved if relative.\n  const propDocument =\n    props.document ?? (props.documentURL !== undefined ? { url: toAbsoluteUrl(props.documentURL) } : undefined);\n  if (props.mode !== 'inline') {\n    // Modal is the default. Document: `document` / `documentURL`, else the trigger\n    // child's href (the established pattern). On click, open the editor in a portal.\n    const triggerHref = hrefOf(props.children);\n    const modalDocument = propDocument ?? (triggerHref !== undefined ? { url: toAbsoluteUrl(triggerHref) } : undefined);\n    return (\n      <ModalChrome trigger={props.children}>\n        <EmbedSurface\n          ref={ref}\n          companyIdentifier={companyIdentifier}\n          baseDomain={props.baseDomain}\n          document={modalDocument}\n          locale={props.locale}\n          context={props.context}\n          logger={props.logger}\n          onEmbedEvent={props.onEmbedEvent}\n          className=\"simplePDF_iframe\"\n        />\n      </ModalChrome>\n    );\n  }\n  // Inline: the editor renders directly in your layout.\n  return (\n    <EmbedSurface\n      ref={ref}\n      companyIdentifier={companyIdentifier}\n      baseDomain={props.baseDomain}\n      document={propDocument}\n      locale={props.locale}\n      context={props.context}\n      logger={props.logger}\n      onEmbedEvent={props.onEmbedEvent}\n      className={props.className}\n      style={props.style}\n    />\n  );\n});\nEmbedPDF.displayName = 'EmbedPDF';\n\n// --- useEmbed ---------------------------------------------------------------\n\n// The editor operations (the `embed.actions` group), derived from IframeActions so a new\n// editor operation fails the build here until it is added. Two methods carry deprecated\n// argument-shape overloads (their shapes changed this release): `selectTool` also\n// accepts the old positional tool, and `submit` also accepts the old\n// `{ downloadCopyOnDevice }`. Both normalize to the new shape before hitting the (pure\n// camelCase) core — the deprecated forms keep existing callers working, so this stays a\n// non-breaking minor.\nexport type EmbedActions = Omit<IframeActions, 'selectTool' | 'submit'> & {\n  /** Pass `{ tool }`. The bare tool value is the deprecated positional form. */\n  selectTool: (input: SelectToolInput | SelectToolInput['tool']) => Promise<BridgeResult>;\n  /** Pass `{ downloadCopy }`. `{ downloadCopyOnDevice }` is the deprecated form. */\n  submit: (input: SubmitInput | { downloadCopyOnDevice: boolean }) => Promise<BridgeResult>;\n};\n\n// The single hook. Attach `embedRef` to <EmbedPDF ref={embedRef} />, then drive the\n// editor with `actions` (imperative), stable + null-safe before the editor mounts;\n// lifecycle is observed via <EmbedPDF onEmbedEvent>. The agentic tools live in the\n// opt-in `@simplepdf/react-embed-pdf/ai-sdk` subpath (useEmbedTools(embedRef)) — keeping\n// `zod` off this entry, so a <EmbedPDF>-only app never loads it.\nexport const useEmbed = (): {\n  embedRef: React.RefObject<EmbedActions | null>;\n  actions: EmbedActions;\n} => {\n  const embedRef = React.useRef<EmbedActions | null>(null);\n\n  const actions = React.useMemo<EmbedActions>(\n    () => ({\n      createField: (input) => embedRef.current?.createField(input) ?? notMounted(),\n      deleteFields: (input) => embedRef.current?.deleteFields(input) ?? notMounted(),\n      deletePages: (input) => embedRef.current?.deletePages(input) ?? notMounted(),\n      detectFields: () => embedRef.current?.detectFields() ?? notMounted(),\n      download: () => embedRef.current?.download() ?? notMounted(),\n      focusField: (input) => embedRef.current?.focusField(input) ?? notMounted(),\n      getDocumentContent: (input) => embedRef.current?.getDocumentContent(input) ?? notMounted(),\n      getFields: () => embedRef.current?.getFields() ?? notMounted(),\n      goTo: (input) => embedRef.current?.goTo(input) ?? notMounted(),\n      loadDocument: (input) => embedRef.current?.loadDocument(input) ?? notMounted(),\n      movePage: (input) => embedRef.current?.movePage(input) ?? notMounted(),\n      rotatePage: (input) => embedRef.current?.rotatePage(input) ?? notMounted(),\n      // selectTool/submit normalize the deprecated arg shapes inside\n      // embedRef.current (the flat EmbedActions), so actions just delegate.\n      selectTool: (input) => embedRef.current?.selectTool(input) ?? notMounted(),\n      setFieldValue: (input) => embedRef.current?.setFieldValue(input) ?? notMounted(),\n      submit: (input) => embedRef.current?.submit(input) ?? notMounted(),\n    }),\n    [],\n  );\n\n  return { embedRef, actions };\n};\n"],"names":["assignRef","ref","value","current","toAbsoluteUrl","url","window","URL","location","href","_a","EmbedSurface","React","forwardRef","props","companyIdentifier","baseDomain","embedDocument","document","locale","context","className","style","containerRef","useRef","callbacksRef","onEmbedEvent","logger","stableLogger","useMemo","delegate","level","event","payload","_b","debug","info","warn","error","currentFile","undefined","file","fileKeyRef","key","documentSource","dataUrl","documentName","name","documentPage","page","contextKey","JSON","stringify","Object","keys","sort","join","useEffect","container","embed","createEmbed","target","__assign","actions","selectTool","input","tool","normalizeSelectTool","submit","downloadCopy","downloadCopyOnDevice","normalizeSubmit","toEmbedActions","forwardEvent","Promise","resolve","then","call","catch","message","Error","String","forwarders","data","type","unsubscribers","events","on","_i","unsubscribers_1","unsubscribe","lifecycle","dispose","createElement","displayName","CloseIcon","height","viewBox","width","xmlSpace","xmlns","d","isTriggerElement","node","isValidElement","ModalChrome","trigger","children","useState","isOpen","setIsOpen","handleOpen","useCallback","preventDefault","handleClose","Fragment","createPortal","role","onClick","body","cloneElement","EmbedPDF","propDocument","documentURL","mode","triggerHref","modalDocument","embedRef","createField","notMounted","deleteFields","deletePages","detectFields","download","focusField","getDocumentContent","getFields","goTo","loadDocument","movePage","rotatePage","setFieldValue"],"mappings":"wwDAkCA,IAEMA,EAAY,SAACC,EAA8CC,GAC5C,mBAARD,EACTA,EAAIC,GACa,OAARD,IACTA,EAAIE,QAAUD,EAElB,EAcME,EAAgB,SAACC,GACrB,GAAsB,oBAAXC,OACT,OAAOD,EAET,IACE,OAAO,IAAIE,IAAIF,EAAKC,OAAOE,SAASC,MAAMA,IAC5C,CAAE,MAAAC,GACA,OAAOL,CACT,CACF,EAmEMM,EAAeC,EAAMC,WAA8C,SAACC,EAAOb,WACvEc,EAA8FD,EAAKC,kBAAhFC,EAA2EF,EAAKE,WAA1DC,EAAqDH,EAAKI,SAA3CC,EAAsCL,EAAK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