{"version":3,"file":"index.production.cjs","names":[],"sources":["../../src/yoga.ts","../../src/LightningManager.ts","../../src/manager.ts","../../src/wrappers.tsx","../../src/index.ts"],"sourcesContent":["import type { YogaOptions } from './types/YogaOptions';\nimport type { YogaManager } from './YogaManager';\nimport type { Workerized } from './YogaManagerWorker';\n\nasync function load(yogaOptions: YogaOptions = {}): Promise<YogaManager | Workerized<YogaManager>> {\n  if (yogaOptions.useWebWorker) {\n    const { default: createWorkerManager } = await import('./YogaManagerWorker');\n    const workerManager = createWorkerManager();\n\n    await workerManager.init(yogaOptions);\n\n    return workerManager;\n  } else {\n    const { YogaManager } = await import('./YogaManager');\n    const manager = new YogaManager();\n\n    await manager.init(yogaOptions);\n\n    return manager;\n  }\n}\n\nexport default load;\n","import type {\n  LightningElement,\n  LightningElementStyle,\n  LightningTextElement,\n  RendererNode,\n  TextRendererNode,\n} from '@plextv/react-lightning';\n\nimport type { YogaOptions } from './types/YogaOptions';\nimport loadYoga from './yoga';\nimport type { YogaManager } from './YogaManager';\nimport type { Workerized } from './YogaManagerWorker';\n\n/** Lifecycle of Yoga nodes for Lightning elements. Main-thread only. */\nexport class LightningManager {\n  private _elements = new Map<number, LightningElement>();\n  private _boundaries = new Set<number>();\n  private _flexRoots = new Set<number>();\n  /** childId -> yoga-side parentId. Lets boundary/flex-root marking stay sync without a worker round-trip. */\n  private _yogaParents = new Map<number, number>();\n  /** Per-parent attached-children count. Lets `_yogaIndexFor` skip the O(n) sibling walk on append-at-end. */\n  private _yogaChildCounts = new Map<number, number>();\n  private _yogaManager: YogaManager | Workerized<YogaManager> | undefined;\n\n  public async init(yogaOptions?: YogaOptions): Promise<void> {\n    this._yogaManager = await loadYoga(yogaOptions);\n    this._yogaManager.on('render', this._applyUpdates);\n  }\n\n  /**\n   * Detaches the element's subtree from yoga (and excludes future\n   * descendants). A nested {@link markFlexRoot} re-enables flex below it.\n   * No-op outside a flex root since those elements are already excluded.\n   */\n  public markBoundary(element: LightningElement): () => void {\n    if (this._boundaries.has(element.id)) {\n      return () => this.unmarkBoundary(element.id);\n    }\n\n    this._boundaries.add(element.id);\n\n    if (this._yogaManager) {\n      for (const child of element.children) {\n        if (this._yogaParents.get(child.id) === element.id) {\n          this._yogaManager.detachChildNode(element.id, child.id);\n          this._clearYogaParent(child.id, element.id);\n        }\n      }\n\n      // Tree shape changed — re-layout any flex roots that contain it.\n      this._yogaManager.queueRender(element.id);\n    }\n\n    return () => this.unmarkBoundary(element.id);\n  }\n\n  public unmarkBoundary(elementId: number): void {\n    this._boundaries.delete(elementId);\n  }\n\n  /**\n   * Opts an element and its subtree into flex layout as an independent\n   * yoga root. Flex is opt-in — without a flex root above it, an element\n   * is invisible to yoga.\n   */\n  public markFlexRoot(element: LightningElement): () => void {\n    if (this._flexRoots.has(element.id)) {\n      return () => this.unmarkFlexRoot(element.id);\n    }\n\n    this._flexRoots.add(element.id);\n\n    if (this._yogaManager) {\n      const yogaParent = this._yogaParents.get(element.id);\n\n      if (yogaParent !== undefined) {\n        this._yogaManager.detachChildNode(yogaParent, element.id);\n        this._clearYogaParent(element.id, yogaParent);\n      }\n\n      this._yogaManager.addIndependentRoot(element.id);\n\n      this._reattachChildren(element);\n\n      // First layout pass — without this the root sits at 0,0 until\n      // something else calls applyStyle.\n      this._yogaManager.queueRender(element.id);\n    }\n\n    return () => this.unmarkFlexRoot(element.id);\n  }\n\n  public unmarkFlexRoot(elementId: number): void {\n    this._flexRoots.delete(elementId);\n    this._yogaManager?.removeIndependentRoot(elementId);\n  }\n\n  /** True when the element should NOT participate in yoga (no flex root ancestor, or a boundary intervenes). */\n  private _isInBoundary(parent: LightningElement): boolean {\n    let curr: LightningElement | null = parent;\n\n    while (curr) {\n      if (this._flexRoots.has(curr.id)) {\n        return false;\n      }\n\n      if (this._boundaries.has(curr.id)) {\n        return true;\n      }\n\n      curr = curr.parent;\n    }\n\n    return true;\n  }\n\n  /**\n   * Yoga-side index for inserting at React's `reactIndex`, accounting for\n   * skipped siblings (boundaries, flex roots). Append-at-end fast path\n   * uses the cached count — turns O(N²) mass-mount into O(N).\n   */\n  private _yogaIndexFor(parent: LightningElement, reactIndex: number): number {\n    if (reactIndex === parent.children.length - 1) {\n      return this._yogaChildCounts.get(parent.id) ?? 0;\n    }\n\n    let yogaIndex = 0;\n\n    for (let i = 0; i < reactIndex; i++) {\n      const sibling = parent.children[i];\n\n      if (sibling && this._yogaParents.get(sibling.id) === parent.id) {\n        yogaIndex++;\n      }\n    }\n\n    return yogaIndex;\n  }\n\n  /** Maintains `_yogaParents` and `_yogaChildCounts` together so the fast path stays accurate. */\n  private _setYogaParent(childId: number, parentId: number): void {\n    this._yogaParents.set(childId, parentId);\n    this._yogaChildCounts.set(parentId, (this._yogaChildCounts.get(parentId) ?? 0) + 1);\n  }\n\n  /** Counterpart of `_setYogaParent`. `parentId` passed explicitly since `_yogaParents.get` may already be cleared. */\n  private _clearYogaParent(childId: number, parentId: number): void {\n    this._yogaParents.delete(childId);\n\n    const count = this._yogaChildCounts.get(parentId);\n\n    if (count !== undefined && count > 0) {\n      this._yogaChildCounts.set(parentId, count - 1);\n    }\n  }\n\n  private _reattachChildren(parent: LightningElement): void {\n    if (!this._yogaManager) {\n      return;\n    }\n\n    let yogaIndex = 0;\n\n    for (let i = 0; i < parent.children.length; i++) {\n      const child = parent.children[i];\n\n      if (!child) {\n        continue;\n      }\n\n      if (this._flexRoots.has(child.id)) {\n        // Independent yoga root — does not count toward parent's yoga children\n        continue;\n      }\n\n      const currentParent = this._yogaParents.get(child.id);\n\n      if (currentParent === parent.id) {\n        yogaIndex++;\n\n        if (!this._boundaries.has(child.id)) {\n          this._reattachChildren(child);\n        }\n\n        continue;\n      }\n\n      if (currentParent !== undefined) {\n        this._yogaManager.detachChildNode(currentParent, child.id);\n        this._clearYogaParent(child.id, currentParent);\n      }\n\n      this._yogaManager.addChildNode(parent.id, child.id, yogaIndex);\n      this._setYogaParent(child.id, parent.id);\n      yogaIndex++;\n\n      if (!this._boundaries.has(child.id)) {\n        this._reattachChildren(child);\n      }\n    }\n  }\n\n  public trackElement(element: LightningElement): void {\n    if (this._elements.has(element.id)) {\n      console.warn(`Yoga node is already attached to element #${element.id}.`);\n\n      return;\n    }\n\n    if (!this._yogaManager) {\n      throw new Error('YogaManager is not initialized. Make sure to call init() first.');\n    }\n\n    this._elements.set(element.id, element);\n    this._yogaManager.addNode(element.id);\n\n    const disposers = [\n      element.on('destroy', () => {\n        for (const dispose of disposers) {\n          dispose();\n        }\n\n        const yogaParent = this._yogaParents.get(element.id);\n\n        if (yogaParent !== undefined) {\n          this._clearYogaParent(element.id, yogaParent);\n        }\n\n        this._elements.delete(element.id);\n        this._boundaries.delete(element.id);\n        this._flexRoots.delete(element.id);\n        this._yogaChildCounts.delete(element.id);\n        // oxlint-disable-next-line typescript/no-non-null-assertion -- Guaranteed to exist. But avoiding the nullish operator for perf reasons\n        this._yogaManager!.applyStyle(element.id, null, true);\n        // oxlint-disable-next-line typescript/no-non-null-assertion -- Guaranteed to exist. See above\n        this._yogaManager!.removeIndependentRoot(element.id);\n        // oxlint-disable-next-line typescript/no-non-null-assertion -- Guaranteed to exist. See above\n        this._yogaManager!.removeNode(element.id);\n      }),\n\n      element.on('childAdded', (child, index) => {\n        if (this._isInBoundary(element)) {\n          return;\n        }\n\n        // Translate React index → yoga index. Skipped siblings (boundaries,\n        // flex roots) cause \"memory access out of bounds\" otherwise.\n        const yogaIndex = this._yogaIndexFor(element, index);\n\n        // oxlint-disable-next-line typescript/no-non-null-assertion -- Guaranteed to exist. See above\n        this._yogaManager!.addChildNode(element.id, child.id, yogaIndex);\n        this._setYogaParent(child.id, element.id);\n        this.applyStyle(element.id, element.style);\n\n        // React mounts bottom-up: `child`'s descendants were inserted\n        // before `child` joined the flex tree, so they were skipped at\n        // their own childAdded time. Promote them now.\n        if (!this._boundaries.has(child.id)) {\n          this._reattachChildren(child);\n        }\n      }),\n\n      element.on('childRemoved', (child) => {\n        const childYogaParent = this._yogaParents.get(child.id);\n\n        if (childYogaParent !== undefined) {\n          this._clearYogaParent(child.id, childYogaParent);\n        }\n\n        // oxlint-disable-next-line typescript/no-non-null-assertion -- Guaranteed to exist. See above\n        this._yogaManager!.applyStyle(child.id, null, true);\n        // oxlint-disable-next-line typescript/no-non-null-assertion -- Guaranteed to exist. See above\n        this._yogaManager!.removeNode(child.id);\n\n        // Re-layout — without this a shrink-fit parent keeps the old size\n        // (node.w/h stay at last computed) and NodeResizeObserver never\n        // fires the shrink event to consumers like VL.reportItemSize.\n        // oxlint-disable-next-line typescript/no-non-null-assertion -- Guaranteed to exist. See above\n        this._yogaManager!.queueRender(element.id);\n      }),\n\n      element.on('inViewport', () => {\n        if (!element.isTextElement && !element.isImageElement) {\n          this.applyStyle(element.id, element.props.style);\n        }\n      }),\n\n      element.on('stylesChanged', () => {\n        this.applyStyle(element.id, element.props.style);\n      }),\n\n      element.on(\n        'textureLoaded',\n        (\n          node: RendererNode<LightningElement> | TextRendererNode<LightningTextElement>,\n          event: { type: string; dimensions: { w: number; h: number } },\n        ) => {\n          if (element.isTextElement) {\n            this.applyStyle(element.id, {\n              w: event.dimensions.w,\n              h: event.dimensions.h,\n            });\n          } else {\n            this.applyStyle(element.id, {\n              w: node.w,\n              h: node.h,\n            });\n          }\n        },\n      ),\n    ];\n  }\n\n  public applyStyle(\n    elementId: number,\n    style?: Partial<LightningElementStyle> | null,\n    skipRender = false,\n  ): void {\n    if (!this._elements.has(elementId)) {\n      return;\n    }\n\n    if (style) {\n      // oxlint-disable-next-line typescript/no-non-null-assertion -- Guaranteed to exist. See above\n      this._yogaManager!.applyStyle(elementId, style, skipRender);\n    }\n  }\n\n  private _applyUpdates = (buffer: ArrayBuffer) => {\n    // Raw `DataView` over `SimpleDataView` — this is a per-frame hot path\n    // that doesn't need overflow handling or write tracking.\n    const view = new DataView(buffer);\n    const length = buffer.byteLength;\n    let offset = 0;\n\n    // See YogaManager.ts for the structure of the updates (12 bytes/entry)\n    while (offset + 12 <= length) {\n      const elementId = view.getUint32(offset, true);\n      const x = view.getInt16(offset + 4, true);\n      const y = view.getInt16(offset + 6, true);\n      const width = view.getUint16(offset + 8, true);\n      const height = view.getUint16(offset + 10, true);\n      offset += 12;\n\n      const el = this._elements.get(elementId);\n\n      if (!el) {\n        continue;\n      }\n\n      // Apply directly to the node so style retains its original value.\n      let skipX = false;\n      let skipY = false;\n      let dirty = false;\n      let resize = false;\n\n      const isText = el.isTextElement;\n\n      if (el.parent?.style.display !== 'flex') {\n        skipX =\n          el.style.x !== undefined &&\n          el.rawProps.style?.x !== undefined &&\n          el.style.transform?.translateX === undefined;\n        skipY =\n          el.style.y !== undefined &&\n          el.rawProps.style?.y !== undefined &&\n          el.style.transform?.translateY === undefined;\n      }\n\n      if (!skipX) {\n        dirty = el.setNodeProp('x', x) || dirty;\n      }\n\n      if (!skipY) {\n        dirty = el.setNodeProp('y', y) || dirty;\n      }\n\n      // Skip zero (causes layout issues) and text elements (Lightning sizes them).\n      if (width !== 0 && !isText) {\n        dirty = el.setNodeProp('w', width) || dirty;\n        resize = true;\n      }\n\n      if (height !== 0 && !isText) {\n        dirty = el.setNodeProp('h', height) || dirty;\n        resize = true;\n      }\n\n      if (resize) {\n        el.emit('resized', el, { w: width, h: height });\n      }\n\n      if (dirty || !el.hasLayout) {\n        el.emitLayoutEvent();\n      }\n    }\n  };\n}\n","import type { LightningManager } from './LightningManager';\n\nlet _instance: LightningManager | undefined;\n\nexport function setFlexboxManager(manager: LightningManager): void {\n  _instance = manager;\n}\n\nexport function getFlexboxManager(): LightningManager | undefined {\n  return _instance;\n}\n","import {\n  createContext,\n  forwardRef,\n  type ForwardRefExoticComponent,\n  type ReactElement,\n  type ReactNode,\n  type RefAttributes,\n  useContext,\n  useImperativeHandle,\n  useLayoutEffect,\n  useRef,\n} from 'react';\n\nimport type { LightningElement, LightningViewElementStyle } from '@plextv/react-lightning';\n\nimport { getFlexboxManager } from './manager';\n\nconst FlexContext = createContext<boolean>(false);\n\n/**\n * Returns true when the calling component is inside a {@link FlexRoot}\n * subtree (and not below a nested {@link FlexBoundary}). Components like\n * `VirtualList` use this to decide whether to expose flex layout to the\n * content they render.\n */\nexport function useIsInFlex(): boolean {\n  return useContext(FlexContext);\n}\n\nexport interface FlexBoundaryProps {\n  children: ReactNode;\n  style?: LightningViewElementStyle | null;\n  onResize?: (event: { w: number; h: number }) => void;\n}\n\n/**\n * Disables flex layout for everything rendered below it. The wrapper itself\n * still participates in any outer flex tree (so it can be sized), but its\n * descendants are detached from yoga until a nested {@link FlexRoot} re-opts\n * them back in.\n */\nexport function FlexBoundary({ children, style, onResize }: FlexBoundaryProps): ReactElement {\n  const ref = useRef<LightningElement>(null);\n\n  useLayoutEffect(() => {\n    const manager = getFlexboxManager();\n    const element = ref.current;\n\n    if (!manager || !element) {\n      return;\n    }\n\n    return manager.markBoundary(element);\n  }, []);\n\n  return (\n    <lng-view ref={ref} style={style} onResize={onResize}>\n      <FlexContext.Provider value={false}>{children}</FlexContext.Provider>\n    </lng-view>\n  );\n}\n\nexport interface FlexRootProps {\n  children: ReactNode;\n  style?: LightningViewElementStyle | null;\n  onResize?: (event: { w: number; h: number }) => void;\n}\n\n/**\n * Opts a subtree into flex layout by becoming an independent yoga root. Flex\n * is opt-in for this plugin — without an ancestor `FlexRoot` somewhere above,\n * elements get no flex behavior. Wrap your app's root (or any subtree that\n * should use flexbox) with this component.\n */\nexport const FlexRoot: ForwardRefExoticComponent<FlexRootProps & RefAttributes<LightningElement>> =\n  forwardRef<LightningElement, FlexRootProps>(({ children, style, onResize }, forwardedRef) => {\n    const ref = useRef<LightningElement>(null);\n\n    useImperativeHandle(forwardedRef, () => ref.current as LightningElement, []);\n\n    useLayoutEffect(() => {\n      const manager = getFlexboxManager();\n      const element = ref.current;\n\n      if (!manager || !element) {\n        return;\n      }\n\n      return manager.markFlexRoot(element);\n    }, []);\n\n    return (\n      <lng-view ref={ref} style={style} onResize={onResize}>\n        <FlexContext.Provider value={true}>{children}</FlexContext.Provider>\n      </lng-view>\n    );\n  });\n\nFlexRoot.displayName = 'FlexRoot';\n","import type { LightningElement, LightningElementStyle, Plugin } from '@plextv/react-lightning';\n\nimport { LightningManager } from './LightningManager';\nimport { setFlexboxManager } from './manager';\nimport type { YogaOptions } from './types/YogaOptions';\nimport { flexProps, isFlexStyleProp } from './util/isFlexStyleProp';\n\nexport function plugin(yogaOptions?: YogaOptions): Plugin<LightningElement> {\n  const lightningManager = new LightningManager();\n\n  setFlexboxManager(lightningManager);\n\n  return {\n    handledStyleProps: new Set(Object.keys(flexProps)),\n\n    init() {\n      return lightningManager.init(yogaOptions);\n    },\n\n    onCreateInstance(instance: LightningElement) {\n      lightningManager.trackElement(instance);\n    },\n\n    transformProps(instance, props) {\n      const styles = props.style;\n\n      if (!styles) {\n        return props;\n      }\n\n      // Fast scan: detect whether ANY flex prop is in the style object\n      // before allocating the split objects. The vast majority of elements\n      // in a typical UI tree (text nodes, image leaves, decorative views)\n      // carry no flex-relevant props, and this fast path returns the\n      // original props untouched — saving three allocations per call\n      // (`flexStyles`, `remainingStyles`, and the `{ ...props }` spread).\n      let hasFlexStyles = false;\n\n      for (const key in styles) {\n        if (\n          key === 'w' ||\n          key === 'h' ||\n          key === 'maxWidth' ||\n          key === 'maxHeight' ||\n          isFlexStyleProp(key)\n        ) {\n          hasFlexStyles = true;\n          break;\n        }\n      }\n\n      if (!hasFlexStyles) {\n        return props;\n      }\n\n      const flexStyles: Record<string, unknown> = {};\n      const remainingStyles: Record<string, unknown> = {};\n\n      for (const key in styles) {\n        const value = styles[key as keyof LightningElementStyle];\n\n        if (key === 'w' || key === 'h' || key === 'maxWidth' || key === 'maxHeight') {\n          // Width and height go to both flex and remaining styles\n          flexStyles[key] = value;\n          remainingStyles[key] = value;\n        } else if (isFlexStyleProp(key) && value != null) {\n          flexStyles[key] = value;\n        } else {\n          remainingStyles[key] = value;\n        }\n      }\n\n      lightningManager.applyStyle(instance.id, flexStyles as Partial<LightningElementStyle>, true);\n\n      return {\n        ...props,\n        style: remainingStyles as Partial<LightningElementStyle>,\n      };\n    },\n  };\n}\n\nexport { FlexBoundary, FlexRoot, useIsInFlex } from './wrappers';\nexport type { FlexBoundaryProps, FlexRootProps } from './wrappers';\nexport * from './types';\n"],"mappings":"4KAIA,eAAe,EAAK,EAA2B,EAAE,CAAkD,CACjG,GAAI,EAAY,aAAc,CAC5B,GAAM,CAAE,QAAS,GAAwB,MAAA,QAAA,SAAA,CAAA,SAAA,QAAM,oCAAA,CAAA,CACzC,EAAgB,GAAqB,CAI3C,OAFA,MAAM,EAAc,KAAK,EAAY,CAE9B,MACF,CACL,GAAM,CAAE,eAAgB,MAAA,QAAA,SAAA,CAAA,SAAA,QAAM,8BAAA,CAAA,CACxB,EAAU,IAAI,EAIpB,OAFA,MAAM,EAAQ,KAAK,EAAY,CAExB,GCJX,IAAa,EAAb,KAA8B,wBAC5B,YAAoB,IAAI,IAA+B,UACvD,cAAsB,IAAI,IAAa,UACvC,aAAqB,IAAI,IAAa,UAEtC,eAAuB,IAAI,IAAqB,UAEhD,mBAA2B,IAAI,IAAqB,UACpD,eAAA,IAAA,GAAQ,UAkTR,gBAAyB,GAAwB,CAG/C,IAAM,EAAO,IAAI,SAAS,EAAO,CAC3B,EAAS,EAAO,WAClB,EAAS,EAGb,KAAO,EAAS,IAAM,GAAQ,OAC5B,IAAM,EAAY,EAAK,UAAU,EAAQ,GAAK,CACxC,EAAI,EAAK,SAAS,EAAS,EAAG,GAAK,CACnC,EAAI,EAAK,SAAS,EAAS,EAAG,GAAK,CACnC,EAAQ,EAAK,UAAU,EAAS,EAAG,GAAK,CACxC,EAAS,EAAK,UAAU,EAAS,GAAI,GAAK,CAChD,GAAU,GAEV,IAAM,EAAK,KAAK,UAAU,IAAI,EAAU,CAExC,GAAI,CAAC,EACH,SAIF,IAAI,EAAQ,GACR,EAAQ,GACR,EAAQ,GACR,EAAS,GAEP,EAAS,EAAG,cAElB,KAAA,EAAI,EAAG,SAAA,KAAA,IAAA,GAAA,EAAQ,MAAM,WAAY,OAAQ,aAC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