markdown-flow-ui 0.1.109 → 0.1.112-beta.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/dist/_virtual/index.cjs10.js +1 -1
- package/dist/_virtual/index.cjs4.js +1 -1
- package/dist/_virtual/index.cjs6.js +1 -1
- package/dist/_virtual/index.cjs7.js +1 -1
- package/dist/_virtual/index.cjs9.js +1 -1
- package/dist/_virtual/index.es10.js +2 -2
- package/dist/_virtual/index.es4.js +4 -4
- package/dist/_virtual/index.es6.js +5 -2
- package/dist/_virtual/index.es6.js.map +1 -1
- package/dist/_virtual/index.es7.js +2 -5
- package/dist/_virtual/index.es7.js.map +1 -1
- package/dist/_virtual/index.es9.js +2 -2
- package/dist/assets/markdown-flow-ui.css +1 -1
- package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs.js +1 -1
- package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js +321 -317
- package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.cjs.js +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.cjs.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.es.js +48 -44
- package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.cjs.js +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.cjs.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.d.ts +1 -0
- package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.es.js +38 -28
- package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.cjs.js +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.cjs.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.es.js +28 -26
- package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.es.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/utils.cjs.js +1 -1
- package/dist/components/MarkdownFlowEditor/utils.cjs.js.map +1 -1
- package/dist/components/MarkdownFlowEditor/utils.d.ts +8 -1
- package/dist/components/MarkdownFlowEditor/utils.es.js +59 -39
- package/dist/components/MarkdownFlowEditor/utils.es.js.map +1 -1
- package/dist/components/Slide/Slide.cjs.js +1 -1
- package/dist/components/Slide/Slide.cjs.js.map +1 -1
- package/dist/components/Slide/Slide.d.ts +8 -0
- package/dist/components/Slide/Slide.es.js +641 -543
- package/dist/components/Slide/Slide.es.js.map +1 -1
- package/dist/components/Slide/Slide.stories.d.ts +13 -0
- package/dist/components/Slide/constants.cjs.js +1 -1
- package/dist/components/Slide/constants.cjs.js.map +1 -1
- package/dist/components/Slide/constants.d.ts +4 -0
- package/dist/components/Slide/constants.es.js +6 -2
- package/dist/components/Slide/constants.es.js.map +1 -1
- package/dist/components/Slide/index.d.ts +2 -1
- package/dist/components/Slide/useSlide.cjs.js +1 -1
- package/dist/components/Slide/useSlide.cjs.js.map +1 -1
- package/dist/components/Slide/useSlide.es.js +106 -97
- package/dist/components/Slide/useSlide.es.js.map +1 -1
- package/dist/components/Slide/utils/appendedMarkerAdvance.cjs.js +2 -0
- package/dist/components/Slide/utils/appendedMarkerAdvance.cjs.js.map +1 -0
- package/dist/components/Slide/utils/appendedMarkerAdvance.d.ts +17 -0
- package/dist/components/Slide/utils/appendedMarkerAdvance.es.js +21 -0
- package/dist/components/Slide/utils/appendedMarkerAdvance.es.js.map +1 -0
- package/dist/components/Slide/utils/appendedMarkerAdvance.test.d.ts +1 -0
- package/dist/components/Slide/utils/streamingNavigation.cjs.js +2 -0
- package/dist/components/Slide/utils/streamingNavigation.cjs.js.map +1 -0
- package/dist/components/Slide/utils/streamingNavigation.d.ts +8 -0
- package/dist/components/Slide/utils/streamingNavigation.es.js +16 -0
- package/dist/components/Slide/utils/streamingNavigation.es.js.map +1 -0
- package/dist/components/Slide/utils/streamingNavigation.test.d.ts +1 -0
- package/dist/components/index.d.ts +2 -2
- package/dist/components/ui/inputGroup/textarea.cjs.js +1 -1
- package/dist/components/ui/inputGroup/textarea.es.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.cjs.js.map +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/@braintree_sanitize-url@7.1.1/node_modules/@braintree/sanitize-url/dist/index.es.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.es.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/hast-util-to-jsx-runtime@2.3.6/node_modules/hast-util-to-jsx-runtime/lib/index.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/hast-util-to-jsx-runtime@2.3.6/node_modules/hast-util-to-jsx-runtime/lib/index.es.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/rc-input@1.8.0_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-input/es/BaseInput.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/rc-input@1.8.0_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-input/es/BaseInput.es.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/ResizableTextArea.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/ResizableTextArea.es.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.es.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/index.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/index.es.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/style-to-object@1.0.11/node_modules/style-to-object/cjs/index.cjs.js +1 -1
- package/dist/markdown-flow-ui/node_modules/.pnpm/style-to-object@1.0.11/node_modules/style-to-object/cjs/index.es.js +1 -1
- package/dist/markdown-flow-ui-lib.css +1 -1
- package/dist/slide.cjs.js +1 -1
- package/dist/slide.es.js +6 -4
- package/dist/slide.es.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSlide.cjs.js","sources":["../../../src/components/Slide/useSlide.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport { applyDiffElement } from \"./diff-utils\";\nimport type { Element, ElementAudioSegment } from \"./types\";\n\nexport interface SlideAudioItem {\n audioKey?: string;\n sequenceNumber?: number;\n audioUrl?: string;\n audioSegments?: ElementAudioSegment[];\n isAudioStreaming?: boolean;\n element?: Element;\n}\n\nexport interface UseSlideResult {\n currentElementList: Element[];\n stepElementLists: Element[][];\n slideElementList: Element[];\n currentIndex: number;\n audioList: SlideAudioItem[];\n currentAudioSequenceIndexes: number[];\n currentStepHasSpeakableElement: boolean;\n currentInteractionElement?: Element;\n canGoPrev: boolean;\n canGoNext: boolean;\n handlePrev: () => void;\n handleNext: () => void;\n}\n\nconst getMarkerElementList = (elementList: Element[]) =>\n elementList.filter((element) => element.is_marker);\n\nconst getMarkerElementIndexes = (elementList: Element[]) =>\n elementList.reduce<number[]>((indexes, element, index) => {\n if (element.is_marker) {\n indexes.push(index);\n }\n\n return indexes;\n }, []);\n\nconst hasPlayableAudio = (element?: Element) =>\n Boolean(\n element?.is_speakable &&\n (element.audio_url || (element.audio_segments?.length ?? 0) > 0)\n );\n\nconst isStreamingAudio = (segments: ElementAudioSegment[] = []) =>\n segments.length > 0 && !segments.some((segment) => segment.is_final);\n\nconst getElementAudioKey = (element: Element, index: number) => {\n const candidateElement = element as Element & {\n element_bid?: string;\n blockBid?: string;\n generated_block_bid?: string;\n };\n\n return (\n candidateElement.element_bid ||\n candidateElement.blockBid ||\n candidateElement.generated_block_bid ||\n `${element.type}:${String(element.sequence_number ?? index)}`\n );\n};\n\nconst getAudioList = (elementList: Element[]) =>\n elementList.reduce<SlideAudioItem[]>((list, element, elementIndex) => {\n if (hasPlayableAudio(element)) {\n const normalizedAudioSegments = element.audio_segments ?? [];\n const hasAudioSegments = normalizedAudioSegments.length > 0;\n\n list.push({\n audioKey: getElementAudioKey(element, elementIndex),\n sequenceNumber: element.sequence_number,\n // Keep one canonical source to avoid duplicated playback resets.\n // When streaming segments exist, keep playback on the segment source.\n audioUrl: hasAudioSegments ? \"\" : element.audio_url,\n audioSegments: normalizedAudioSegments,\n isAudioStreaming: isStreamingAudio(normalizedAudioSegments),\n element,\n });\n }\n\n return list;\n }, []);\n\nconst getAudioIndexMap = (elementList: Element[]) => {\n const audioIndexMap = new Map<number, number>();\n let audioIndex = 0;\n\n elementList.forEach((element, index) => {\n if (hasPlayableAudio(element)) {\n audioIndexMap.set(index, audioIndex);\n audioIndex += 1;\n }\n });\n\n return audioIndexMap;\n};\n\nconst getSlideAudioSequenceMap = (\n elementList: Element[],\n markerElementIndexes: number[],\n audioIndexMap: Map<number, number>\n) =>\n markerElementIndexes.reduce<Map<number, number[]>>(\n (sequenceMap, startIndex, slideIndex) => {\n const nextMarkerIndex =\n markerElementIndexes[slideIndex + 1] ?? elementList.length;\n const sequenceIndexes: number[] = [];\n\n for (let index = startIndex; index < nextMarkerIndex; index += 1) {\n const element = elementList[index];\n\n if (!hasPlayableAudio(element)) {\n continue;\n }\n\n const audioIndex = audioIndexMap.get(index);\n\n if (audioIndex == null) {\n continue;\n }\n\n sequenceIndexes.push(audioIndex);\n }\n\n sequenceMap.set(slideIndex, sequenceIndexes);\n return sequenceMap;\n },\n new Map<number, number[]>()\n );\n\nconst getInitialSlideIndex = (slideElementList: Element[]) => {\n const visibleIndex = slideElementList.findIndex(\n (element) => element.is_renderable === true\n );\n\n if (visibleIndex >= 0) {\n return visibleIndex;\n }\n\n return slideElementList.findIndex(\n (element) => element.is_renderable !== false\n );\n};\n\nconst getVisibleElement = (element: Element): Element => ({\n ...element,\n is_renderable: true,\n});\n\nconst getCurrentElementList = (\n slideElementList: Element[],\n currentIndex: number\n) => {\n if (currentIndex < 0) {\n return [];\n }\n\n return slideElementList\n .slice(0, currentIndex + 1)\n .reduce<Element[]>((currentList, element) => {\n if (element.type === \"interaction\") {\n return currentList;\n }\n\n const visibleElement = getVisibleElement(element);\n\n if (visibleElement.type === \"diff\") {\n const nextList = applyDiffElement(currentList, visibleElement);\n\n return nextList ?? [...currentList, visibleElement];\n }\n\n if (element.is_new) {\n return [visibleElement];\n }\n\n if (currentList.length === 0) {\n return [visibleElement];\n }\n\n return [...currentList, visibleElement];\n }, []);\n};\n\nconst getStepElementLists = (slideElementList: Element[]) =>\n slideElementList.map((_, index) =>\n getCurrentElementList(slideElementList, index)\n );\n\nconst getStepHasSpeakableElement = (\n elementList: Element[],\n markerElementIndexes: number[],\n currentIndex: number\n) => {\n if (currentIndex < 0) {\n return false;\n }\n\n const startIndex = markerElementIndexes[currentIndex];\n\n if (typeof startIndex !== \"number\") {\n return false;\n }\n\n const nextMarkerIndex =\n markerElementIndexes[currentIndex + 1] ?? elementList.length;\n\n for (let index = startIndex; index < nextMarkerIndex; index += 1) {\n if (elementList[index]?.is_speakable) {\n return true;\n }\n }\n\n return false;\n};\n\nconst hasSameElementReferences = (\n prevElementList: Element[],\n nextElementList: Element[]\n) =>\n prevElementList.length === nextElementList.length &&\n prevElementList.every((element, index) => element === nextElementList[index]);\n\nconst hasSameNumberValues = (prevValues: number[], nextValues: number[]) =>\n prevValues.length === nextValues.length &&\n prevValues.every((value, index) => value === nextValues[index]);\n\nconst useSlide = (elementList: Element[] = []): UseSlideResult => {\n const stableElementListRef = useRef(elementList);\n const stableCurrentAudioSequenceIndexesRef = useRef<number[]>([]);\n const stableElementList = useMemo(() => {\n if (hasSameElementReferences(stableElementListRef.current, elementList)) {\n return stableElementListRef.current;\n }\n\n // Reuse the previous wrapper array when the element references are unchanged.\n stableElementListRef.current = elementList;\n return elementList;\n }, [elementList]);\n const slideElementList = useMemo(\n () => getMarkerElementList(stableElementList),\n [stableElementList]\n );\n const markerElementIndexes = useMemo(\n () => getMarkerElementIndexes(stableElementList),\n [stableElementList]\n );\n const audioList = useMemo(\n () => getAudioList(stableElementList),\n [stableElementList]\n );\n const audioIndexMap = useMemo(\n () => getAudioIndexMap(stableElementList),\n [stableElementList]\n );\n const slideAudioSequenceMap = useMemo(\n () =>\n getSlideAudioSequenceMap(\n stableElementList,\n markerElementIndexes,\n audioIndexMap\n ),\n [audioIndexMap, markerElementIndexes, stableElementList]\n );\n const [currentIndex, setCurrentIndex] = useState(() =>\n getInitialSlideIndex(slideElementList)\n );\n\n useEffect(() => {\n setCurrentIndex((prevIndex) => {\n if (slideElementList.length === 0) {\n return -1;\n }\n\n if (prevIndex >= 0 && prevIndex < slideElementList.length) {\n return prevIndex;\n }\n\n return getInitialSlideIndex(slideElementList);\n });\n }, [slideElementList]);\n\n const handlePrev = useCallback(() => {\n setCurrentIndex((prevIndex) => {\n if (prevIndex <= 0) {\n return Math.max(prevIndex, 0);\n }\n\n return Math.max(prevIndex - 1, 0);\n });\n }, []);\n\n const handleNext = useCallback(() => {\n setCurrentIndex((prevIndex) => {\n if (prevIndex < 0) {\n return prevIndex;\n }\n\n return Math.min(prevIndex + 1, slideElementList.length - 1);\n });\n }, [slideElementList.length]);\n\n const canGoPrev = currentIndex > 0;\n const canGoNext =\n currentIndex >= 0 && currentIndex < slideElementList.length - 1;\n const currentStepElement = useMemo(() => {\n if (currentIndex < 0) {\n return undefined;\n }\n\n const element = slideElementList[currentIndex];\n\n if (!element) {\n return undefined;\n }\n\n return getVisibleElement(element);\n }, [currentIndex, slideElementList]);\n const currentElementList = useMemo(\n () => getCurrentElementList(slideElementList, currentIndex),\n [currentIndex, slideElementList]\n );\n const stepElementLists = useMemo(\n () => getStepElementLists(slideElementList),\n [slideElementList]\n );\n const currentAudioSequenceIndexes = useMemo(() => {\n const nextAudioSequenceIndexes =\n slideAudioSequenceMap.get(currentIndex) ?? [];\n\n if (\n hasSameNumberValues(\n stableCurrentAudioSequenceIndexesRef.current,\n nextAudioSequenceIndexes\n )\n ) {\n return stableCurrentAudioSequenceIndexesRef.current;\n }\n\n stableCurrentAudioSequenceIndexesRef.current = nextAudioSequenceIndexes;\n\n return nextAudioSequenceIndexes;\n }, [currentIndex, slideAudioSequenceMap]);\n const currentStepHasSpeakableElement = useMemo(\n () =>\n getStepHasSpeakableElement(\n stableElementList,\n markerElementIndexes,\n currentIndex\n ),\n [currentIndex, markerElementIndexes, stableElementList]\n );\n const currentInteractionElement = useMemo(\n () =>\n currentStepElement?.type === \"interaction\"\n ? currentStepElement\n : undefined,\n [currentStepElement]\n );\n\n return {\n currentElementList,\n stepElementLists,\n slideElementList,\n currentIndex,\n audioList,\n currentAudioSequenceIndexes,\n currentStepHasSpeakableElement,\n currentInteractionElement,\n canGoPrev,\n canGoNext,\n handlePrev,\n handleNext,\n };\n};\n\nexport default useSlide;\n"],"names":["getMarkerElementList","elementList","element","getMarkerElementIndexes","indexes","index","hasPlayableAudio","isStreamingAudio","segments","segment","getElementAudioKey","candidateElement","getAudioList","list","elementIndex","normalizedAudioSegments","hasAudioSegments","getAudioIndexMap","audioIndexMap","audioIndex","getSlideAudioSequenceMap","markerElementIndexes","sequenceMap","startIndex","slideIndex","nextMarkerIndex","sequenceIndexes","getInitialSlideIndex","slideElementList","visibleIndex","getVisibleElement","getCurrentElementList","currentIndex","currentList","visibleElement","applyDiffElement","getStepElementLists","_","getStepHasSpeakableElement","hasSameElementReferences","prevElementList","nextElementList","hasSameNumberValues","prevValues","nextValues","value","useSlide","stableElementListRef","useRef","stableCurrentAudioSequenceIndexesRef","stableElementList","useMemo","audioList","slideAudioSequenceMap","setCurrentIndex","useState","useEffect","prevIndex","handlePrev","useCallback","handleNext","canGoPrev","canGoNext","currentStepElement","currentElementList","stepElementLists","currentAudioSequenceIndexes","nextAudioSequenceIndexes","currentStepHasSpeakableElement","currentInteractionElement"],"mappings":"sKA6BMA,EAAwBC,GAC5BA,EAAY,OAAQC,GAAYA,EAAQ,SAAS,EAE7CC,EAA2BF,GAC/BA,EAAY,OAAiB,CAACG,EAASF,EAASG,KAC1CH,EAAQ,WACVE,EAAQ,KAAKC,CAAK,EAGbD,GACN,EAAE,EAEDE,EAAoBJ,GACxB,GACEA,GAAS,eACRA,EAAQ,YAAcA,EAAQ,gBAAgB,QAAU,GAAK,IAG5DK,EAAmB,CAACC,EAAkC,KAC1DA,EAAS,OAAS,GAAK,CAACA,EAAS,KAAMC,GAAYA,EAAQ,QAAQ,EAE/DC,EAAqB,CAACR,EAAkBG,IAAkB,CAC9D,MAAMM,EAAmBT,EAMzB,OACES,EAAiB,aACjBA,EAAiB,UACjBA,EAAiB,qBACjB,GAAGT,EAAQ,IAAI,IAAI,OAAOA,EAAQ,iBAAmBG,CAAK,CAAC,EAE/D,EAEMO,EAAg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AgB,GAAKA,EAAeJ,EAAiB,OAAS,EAC1DmC,EAAqBZ,EAAAA,QAAQ,IAAM,CACvC,GAAInB,EAAe,EACjB,OAGF,MAAM9B,EAAU0B,EAAiBI,CAAY,EAE7C,GAAK9B,EAIL,OAAO4B,EAAkB5B,CAAO,CAClC,EAAG,CAAC8B,EAAcJ,CAAgB,CAAC,EAC7BoC,EAAqBb,EAAAA,QACzB,IAAMpB,EAAsBH,EAAkBI,CAAY,EAC1D,CAACA,EAAcJ,CAAgB,CAAA,EAE3BqC,EAAmBd,EAAAA,QACvB,IAAMf,EAAoBR,CAAgB,EAC1C,CAACA,CAAgB,CAAA,EAEbsC,EAA8Bf,EAAAA,QAAQ,IAAM,CAChD,MAAMgB,EACJd,EAAsB,IAAIrB,CAAY,GAAK,CAAA,EAE7C,OACEU,EACEO,EAAqC,QACrCkB,CAAA,EAGKlB,EAAqC,SAG9CA,EAAqC,QAAUkB,EAExCA,EACT,EAAG,CAACnC,EAAcqB,CAAqB,CAAC,EAClCe,EAAiCjB,EAAAA,QACrC,IACEb,EACEY,EACA7B,EACAW,CAAA,EAEJ,CAACA,EAAcX,EAAsB6B,CAAiB,CAAA,EAElDmB,EAA4BlB,EAAAA,QAChC,IACEY,GAAoB,OAAS,cACzBA,EACA,OACN,CAACA,CAAkB,CAAA,EAGrB,MAAO,CACL,mBAAAC,EACA,iBAAAC,EACA,iBAAArC,EACA,aAAAI,EACA,UAAAoB,EACA,4BAAAc,EACA,+BAAAE,EACA,0BAAAC,EACA,UAAAR,EACA,UAAAC,EACA,WAAAJ,EACA,WAAAE,CAAA,CAEJ"}
|
|
1
|
+
{"version":3,"file":"useSlide.cjs.js","sources":["../../../src/components/Slide/useSlide.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport { applyDiffElement } from \"./diff-utils\";\nimport type { Element, ElementAudioSegment } from \"./types\";\nimport { resolveNextSlideIndexAfterMarkerAppend } from \"./utils/streamingNavigation\";\n\nexport interface SlideAudioItem {\n audioKey?: string;\n sequenceNumber?: number;\n audioUrl?: string;\n audioSegments?: ElementAudioSegment[];\n isAudioStreaming?: boolean;\n element?: Element;\n}\n\nexport interface UseSlideResult {\n currentElementList: Element[];\n stepElementLists: Element[][];\n slideElementList: Element[];\n currentIndex: number;\n audioList: SlideAudioItem[];\n currentAudioSequenceIndexes: number[];\n currentStepHasSpeakableElement: boolean;\n currentInteractionElement?: Element;\n canGoPrev: boolean;\n canGoNext: boolean;\n handlePrev: () => void;\n handleNext: () => void;\n}\n\nconst getMarkerElementList = (elementList: Element[]) =>\n elementList.filter((element) => element.is_marker);\n\nconst getMarkerElementIndexes = (elementList: Element[]) =>\n elementList.reduce<number[]>((indexes, element, index) => {\n if (element.is_marker) {\n indexes.push(index);\n }\n\n return indexes;\n }, []);\n\nconst hasPlayableAudio = (element?: Element) =>\n Boolean(\n element?.is_speakable &&\n (element.audio_url || (element.audio_segments?.length ?? 0) > 0)\n );\n\nconst isStreamingAudio = (segments: ElementAudioSegment[] = []) =>\n segments.length > 0 && !segments.some((segment) => segment.is_final);\n\nconst getElementAudioKey = (element: Element, index: number) => {\n const candidateElement = element as Element & {\n element_bid?: string;\n blockBid?: string;\n generated_block_bid?: string;\n };\n\n return (\n candidateElement.element_bid ||\n candidateElement.blockBid ||\n candidateElement.generated_block_bid ||\n `${element.type}:${String(element.sequence_number ?? index)}`\n );\n};\n\nconst getAudioList = (elementList: Element[]) =>\n elementList.reduce<SlideAudioItem[]>((list, element, elementIndex) => {\n if (hasPlayableAudio(element)) {\n const normalizedAudioSegments = element.audio_segments ?? [];\n const hasAudioSegments = normalizedAudioSegments.length > 0;\n\n list.push({\n audioKey: getElementAudioKey(element, elementIndex),\n sequenceNumber: element.sequence_number,\n // Keep one canonical source to avoid duplicated playback resets.\n // When streaming segments exist, keep playback on the segment source.\n audioUrl: hasAudioSegments ? \"\" : element.audio_url,\n audioSegments: normalizedAudioSegments,\n isAudioStreaming: isStreamingAudio(normalizedAudioSegments),\n element,\n });\n }\n\n return list;\n }, []);\n\nconst getAudioIndexMap = (elementList: Element[]) => {\n const audioIndexMap = new Map<number, number>();\n let audioIndex = 0;\n\n elementList.forEach((element, index) => {\n if (hasPlayableAudio(element)) {\n audioIndexMap.set(index, audioIndex);\n audioIndex += 1;\n }\n });\n\n return audioIndexMap;\n};\n\nconst getSlideAudioSequenceMap = (\n elementList: Element[],\n markerElementIndexes: number[],\n audioIndexMap: Map<number, number>\n) =>\n markerElementIndexes.reduce<Map<number, number[]>>(\n (sequenceMap, startIndex, slideIndex) => {\n const nextMarkerIndex =\n markerElementIndexes[slideIndex + 1] ?? elementList.length;\n const sequenceIndexes: number[] = [];\n\n for (let index = startIndex; index < nextMarkerIndex; index += 1) {\n const element = elementList[index];\n\n if (!hasPlayableAudio(element)) {\n continue;\n }\n\n const audioIndex = audioIndexMap.get(index);\n\n if (audioIndex == null) {\n continue;\n }\n\n sequenceIndexes.push(audioIndex);\n }\n\n sequenceMap.set(slideIndex, sequenceIndexes);\n return sequenceMap;\n },\n new Map<number, number[]>()\n );\n\nconst getInitialSlideIndex = (slideElementList: Element[]) => {\n const visibleIndex = slideElementList.findIndex(\n (element) => element.is_renderable === true\n );\n\n if (visibleIndex >= 0) {\n return visibleIndex;\n }\n\n return slideElementList.findIndex(\n (element) => element.is_renderable !== false\n );\n};\n\nconst getVisibleElement = (element: Element): Element => ({\n ...element,\n is_renderable: true,\n});\n\nconst getCurrentElementList = (\n slideElementList: Element[],\n currentIndex: number\n) => {\n if (currentIndex < 0) {\n return [];\n }\n\n return slideElementList\n .slice(0, currentIndex + 1)\n .reduce<Element[]>((currentList, element) => {\n if (element.type === \"interaction\") {\n return currentList;\n }\n\n const visibleElement = getVisibleElement(element);\n\n if (visibleElement.type === \"diff\") {\n const nextList = applyDiffElement(currentList, visibleElement);\n\n return nextList ?? [...currentList, visibleElement];\n }\n\n if (element.is_new) {\n return [visibleElement];\n }\n\n if (currentList.length === 0) {\n return [visibleElement];\n }\n\n return [...currentList, visibleElement];\n }, []);\n};\n\nconst getStepElementLists = (slideElementList: Element[]) =>\n slideElementList.map((_, index) =>\n getCurrentElementList(slideElementList, index)\n );\n\nconst getStepHasSpeakableElement = (\n elementList: Element[],\n markerElementIndexes: number[],\n currentIndex: number\n) => {\n if (currentIndex < 0) {\n return false;\n }\n\n const startIndex = markerElementIndexes[currentIndex];\n\n if (typeof startIndex !== \"number\") {\n return false;\n }\n\n const nextMarkerIndex =\n markerElementIndexes[currentIndex + 1] ?? elementList.length;\n\n for (let index = startIndex; index < nextMarkerIndex; index += 1) {\n if (elementList[index]?.is_speakable) {\n return true;\n }\n }\n\n return false;\n};\n\nconst hasSameElementReferences = (\n prevElementList: Element[],\n nextElementList: Element[]\n) =>\n prevElementList.length === nextElementList.length &&\n prevElementList.every((element, index) => element === nextElementList[index]);\n\nconst hasSameNumberValues = (prevValues: number[], nextValues: number[]) =>\n prevValues.length === nextValues.length &&\n prevValues.every((value, index) => value === nextValues[index]);\n\nconst useSlide = (elementList: Element[] = []): UseSlideResult => {\n const stableElementListRef = useRef(elementList);\n const stableCurrentAudioSequenceIndexesRef = useRef<number[]>([]);\n const stableElementList = useMemo(() => {\n if (hasSameElementReferences(stableElementListRef.current, elementList)) {\n return stableElementListRef.current;\n }\n\n // Reuse the previous wrapper array when the element references are unchanged.\n stableElementListRef.current = elementList;\n return elementList;\n }, [elementList]);\n const slideElementList = useMemo(\n () => getMarkerElementList(stableElementList),\n [stableElementList]\n );\n const previousSlideElementListRef = useRef(slideElementList);\n const markerElementIndexes = useMemo(\n () => getMarkerElementIndexes(stableElementList),\n [stableElementList]\n );\n const audioList = useMemo(\n () => getAudioList(stableElementList),\n [stableElementList]\n );\n const audioIndexMap = useMemo(\n () => getAudioIndexMap(stableElementList),\n [stableElementList]\n );\n const slideAudioSequenceMap = useMemo(\n () =>\n getSlideAudioSequenceMap(\n stableElementList,\n markerElementIndexes,\n audioIndexMap\n ),\n [audioIndexMap, markerElementIndexes, stableElementList]\n );\n const [currentIndex, setCurrentIndex] = useState(() =>\n getInitialSlideIndex(slideElementList)\n );\n\n useEffect(() => {\n const previousSlideElementList = previousSlideElementListRef.current;\n\n setCurrentIndex((prevIndex) => {\n const resolvedNextIndex = resolveNextSlideIndexAfterMarkerAppend({\n previousIndex: prevIndex,\n previousSlideElementList,\n nextSlideElementList: slideElementList,\n });\n\n if (resolvedNextIndex >= 0) {\n return resolvedNextIndex;\n }\n\n return getInitialSlideIndex(slideElementList);\n });\n\n previousSlideElementListRef.current = slideElementList;\n }, [slideElementList]);\n\n const handlePrev = useCallback(() => {\n setCurrentIndex((prevIndex) => {\n if (prevIndex <= 0) {\n return Math.max(prevIndex, 0);\n }\n\n return Math.max(prevIndex - 1, 0);\n });\n }, []);\n\n const handleNext = useCallback(() => {\n setCurrentIndex((prevIndex) => {\n if (prevIndex < 0) {\n return prevIndex;\n }\n\n return Math.min(prevIndex + 1, slideElementList.length - 1);\n });\n }, [slideElementList.length]);\n\n const canGoPrev = currentIndex > 0;\n const canGoNext =\n currentIndex >= 0 && currentIndex < slideElementList.length - 1;\n const currentStepElement = useMemo(() => {\n if (currentIndex < 0) {\n return undefined;\n }\n\n const element = slideElementList[currentIndex];\n\n if (!element) {\n return undefined;\n }\n\n return getVisibleElement(element);\n }, [currentIndex, slideElementList]);\n const currentElementList = useMemo(\n () => getCurrentElementList(slideElementList, currentIndex),\n [currentIndex, slideElementList]\n );\n const stepElementLists = useMemo(\n () => getStepElementLists(slideElementList),\n [slideElementList]\n );\n const currentAudioSequenceIndexes = useMemo(() => {\n const nextAudioSequenceIndexes =\n slideAudioSequenceMap.get(currentIndex) ?? [];\n\n if (\n hasSameNumberValues(\n stableCurrentAudioSequenceIndexesRef.current,\n nextAudioSequenceIndexes\n )\n ) {\n return stableCurrentAudioSequenceIndexesRef.current;\n }\n\n stableCurrentAudioSequenceIndexesRef.current = nextAudioSequenceIndexes;\n\n return nextAudioSequenceIndexes;\n }, [currentIndex, slideAudioSequenceMap]);\n const currentStepHasSpeakableElement = useMemo(\n () =>\n getStepHasSpeakableElement(\n stableElementList,\n markerElementIndexes,\n currentIndex\n ),\n [currentIndex, markerElementIndexes, stableElementList]\n );\n const currentInteractionElement = useMemo(\n () =>\n currentStepElement?.type === \"interaction\"\n ? currentStepElement\n : undefined,\n [currentStepElement]\n );\n\n return {\n currentElementList,\n stepElementLists,\n slideElementList,\n currentIndex,\n audioList,\n currentAudioSequenceIndexes,\n currentStepHasSpeakableElement,\n currentInteractionElement,\n canGoPrev,\n canGoNext,\n handlePrev,\n handleNext,\n };\n};\n\nexport default useSlide;\n"],"names":["getMarkerElementList","elementList","element","getMarkerElementIndexes","indexes","index","hasPlayableAudio","isStreamingAudio","segments","segment","getElementAudioKey","candidateElement","getAudioList","list","elementIndex","normalizedAudioSegments","hasAudioSegments","getAudioIndexMap","audioIndexMap","audioIndex","getSlideAudioSequenceMap","markerElementIndexes","sequenceMap","startIndex","slideIndex","nextMarkerIndex","sequenceIndexes","getInitialSlideIndex","slideElementList","visibleIndex","getVisibleElement","getCurrentElementList","currentIndex","currentList","visibleElement","applyDiffElement","getStepElementLists","_","getStepHasSpeakableElement","hasSameElementReferences","prevElementList","nextElementList","hasSameNumberValues","prevValues","nextValues","value","useSlide","stableElementListRef","useRef","stableCurrentAudioSequenceIndexesRef","stableElementList","useMemo","previousSlideElementListRef","audioList","slideAudioSequenceMap","setCurrentIndex","useState","useEffect","previousSlideElementList","prevIndex","resolvedNextIndex","resolveNextSlideIndexAfterMarkerAppend","handlePrev","useCallback","handleNext","canGoPrev","canGoNext","currentStepElement","currentElementList","stepElementLists","currentAudioSequenceIndexes","nextAudioSequenceIndexes","currentStepHasSpeakableElement","currentInteractionElement"],"mappings":"sNA8BMA,EAAwBC,GAC5BA,EAAY,OAAQC,GAAYA,EAAQ,SAAS,EAE7CC,EAA2BF,GAC/BA,EAAY,OAAiB,CAACG,EAASF,EAASG,KAC1CH,EAAQ,WACVE,EAAQ,KAAKC,CAAK,EAGbD,GACN,EAAE,E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cX,EAAsB6B,CAAiB,CAAA,EAElDuB,EAA4BtB,EAAAA,QAChC,IACEgB,GAAoB,OAAS,cACzBA,EACA,OACN,CAACA,CAAkB,CAAA,EAGrB,MAAO,CACL,mBAAAC,EACA,iBAAAC,EACA,iBAAAzC,EACA,aAAAI,EACA,UAAAqB,EACA,4BAAAiB,EACA,+BAAAE,EACA,0BAAAC,EACA,UAAAR,EACA,UAAAC,EACA,WAAAJ,EACA,WAAAE,CAAA,CAEJ"}
|
|
@@ -1,145 +1,154 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import { applyDiffElement as
|
|
3
|
-
|
|
1
|
+
import { useRef as p, useMemo as c, useState as w, useEffect as P, useCallback as x } from "react";
|
|
2
|
+
import { applyDiffElement as B } from "./diff-utils.es.js";
|
|
3
|
+
import { resolveNextSlideIndexAfterMarkerAppend as G } from "./utils/streamingNavigation.es.js";
|
|
4
|
+
const H = (e) => e.filter((n) => n.is_marker), K = (e) => e.reduce((n, t, s) => (t.is_marker && n.push(s), n), []), S = (e) => !!(e?.is_speakable && (e.audio_url || (e.audio_segments?.length ?? 0) > 0)), $ = (e = []) => e.length > 0 && !e.some((n) => n.is_final), z = (e, n) => {
|
|
4
5
|
const t = e;
|
|
5
6
|
return t.element_bid || t.blockBid || t.generated_block_bid || `${e.type}:${String(e.sequence_number ?? n)}`;
|
|
6
|
-
},
|
|
7
|
-
if (
|
|
8
|
-
const
|
|
7
|
+
}, D = (e) => e.reduce((n, t, s) => {
|
|
8
|
+
if (S(t)) {
|
|
9
|
+
const r = t.audio_segments ?? [], u = r.length > 0;
|
|
9
10
|
n.push({
|
|
10
|
-
audioKey:
|
|
11
|
+
audioKey: z(t, s),
|
|
11
12
|
sequenceNumber: t.sequence_number,
|
|
12
13
|
// Keep one canonical source to avoid duplicated playback resets.
|
|
13
14
|
// When streaming segments exist, keep playback on the segment source.
|
|
14
|
-
audioUrl:
|
|
15
|
-
audioSegments:
|
|
16
|
-
isAudioStreaming:
|
|
15
|
+
audioUrl: u ? "" : t.audio_url,
|
|
16
|
+
audioSegments: r,
|
|
17
|
+
isAudioStreaming: $(r),
|
|
17
18
|
element: t
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
21
|
return n;
|
|
21
|
-
}, []),
|
|
22
|
+
}, []), L = (e) => {
|
|
22
23
|
const n = /* @__PURE__ */ new Map();
|
|
23
24
|
let t = 0;
|
|
24
|
-
return e.forEach((
|
|
25
|
-
|
|
25
|
+
return e.forEach((s, r) => {
|
|
26
|
+
S(s) && (n.set(r, t), t += 1);
|
|
26
27
|
}), n;
|
|
27
|
-
},
|
|
28
|
-
(
|
|
29
|
-
const
|
|
30
|
-
for (let a =
|
|
31
|
-
const
|
|
32
|
-
if (!
|
|
28
|
+
}, U = (e, n, t) => n.reduce(
|
|
29
|
+
(s, r, u) => {
|
|
30
|
+
const d = n[u + 1] ?? e.length, l = [];
|
|
31
|
+
for (let a = r; a < d; a += 1) {
|
|
32
|
+
const f = e[a];
|
|
33
|
+
if (!S(f))
|
|
33
34
|
continue;
|
|
34
|
-
const
|
|
35
|
-
|
|
35
|
+
const o = t.get(a);
|
|
36
|
+
o != null && l.push(o);
|
|
36
37
|
}
|
|
37
|
-
return
|
|
38
|
+
return s.set(u, l), s;
|
|
38
39
|
},
|
|
39
40
|
/* @__PURE__ */ new Map()
|
|
40
|
-
),
|
|
41
|
+
), b = (e) => {
|
|
41
42
|
const n = e.findIndex(
|
|
42
43
|
(t) => t.is_renderable === !0
|
|
43
44
|
);
|
|
44
45
|
return n >= 0 ? n : e.findIndex(
|
|
45
46
|
(t) => t.is_renderable !== !1
|
|
46
47
|
);
|
|
47
|
-
},
|
|
48
|
+
}, E = (e) => ({
|
|
48
49
|
...e,
|
|
49
50
|
is_renderable: !0
|
|
50
|
-
}), _ = (e, n) => n < 0 ? [] : e.slice(0, n + 1).reduce((t,
|
|
51
|
-
if (
|
|
51
|
+
}), _ = (e, n) => n < 0 ? [] : e.slice(0, n + 1).reduce((t, s) => {
|
|
52
|
+
if (s.type === "interaction")
|
|
52
53
|
return t;
|
|
53
|
-
const
|
|
54
|
-
return
|
|
55
|
-
}, []),
|
|
54
|
+
const r = E(s);
|
|
55
|
+
return r.type === "diff" ? B(t, r) ?? [...t, r] : s.is_new ? [r] : t.length === 0 ? [r] : [...t, r];
|
|
56
|
+
}, []), j = (e) => e.map(
|
|
56
57
|
(n, t) => _(e, t)
|
|
57
|
-
),
|
|
58
|
+
), F = (e, n, t) => {
|
|
58
59
|
if (t < 0)
|
|
59
60
|
return !1;
|
|
60
|
-
const
|
|
61
|
-
if (typeof
|
|
61
|
+
const s = n[t];
|
|
62
|
+
if (typeof s != "number")
|
|
62
63
|
return !1;
|
|
63
|
-
const
|
|
64
|
-
for (let
|
|
65
|
-
if (e[
|
|
64
|
+
const r = n[t + 1] ?? e.length;
|
|
65
|
+
for (let u = s; u < r; u += 1)
|
|
66
|
+
if (e[u]?.is_speakable)
|
|
66
67
|
return !0;
|
|
67
68
|
return !1;
|
|
68
|
-
},
|
|
69
|
-
const n =
|
|
70
|
-
() =>
|
|
71
|
-
[
|
|
72
|
-
),
|
|
73
|
-
() =>
|
|
74
|
-
[
|
|
75
|
-
), f = c(
|
|
76
|
-
() => K(r),
|
|
77
|
-
[r]
|
|
69
|
+
}, J = (e, n) => e.length === n.length && e.every((t, s) => t === n[s]), O = (e, n) => e.length === n.length && e.every((t, s) => t === n[s]), W = (e = []) => {
|
|
70
|
+
const n = p(e), t = p([]), s = c(() => J(n.current, e) ? n.current : (n.current = e, e), [e]), r = c(
|
|
71
|
+
() => H(s),
|
|
72
|
+
[s]
|
|
73
|
+
), u = p(r), d = c(
|
|
74
|
+
() => K(s),
|
|
75
|
+
[s]
|
|
78
76
|
), l = c(
|
|
79
|
-
() =>
|
|
80
|
-
[
|
|
77
|
+
() => D(s),
|
|
78
|
+
[s]
|
|
81
79
|
), a = c(
|
|
82
|
-
() =>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
() => L(s),
|
|
81
|
+
[s]
|
|
82
|
+
), f = c(
|
|
83
|
+
() => U(
|
|
84
|
+
s,
|
|
85
|
+
d,
|
|
86
|
+
a
|
|
86
87
|
),
|
|
87
|
-
[
|
|
88
|
-
), [
|
|
89
|
-
() =>
|
|
88
|
+
[a, d, s]
|
|
89
|
+
), [o, g] = w(
|
|
90
|
+
() => b(r)
|
|
90
91
|
);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
P(() => {
|
|
93
|
+
const i = u.current;
|
|
94
|
+
g((C) => {
|
|
95
|
+
const h = G({
|
|
96
|
+
previousIndex: C,
|
|
97
|
+
previousSlideElementList: i,
|
|
98
|
+
nextSlideElementList: r
|
|
99
|
+
});
|
|
100
|
+
return h >= 0 ? h : b(r);
|
|
101
|
+
}), u.current = r;
|
|
102
|
+
}, [r]);
|
|
103
|
+
const A = x(() => {
|
|
104
|
+
g((i) => i <= 0 ? Math.max(i, 0) : Math.max(i - 1, 0));
|
|
105
|
+
}, []), I = x(() => {
|
|
106
|
+
g((i) => i < 0 ? i : Math.min(i + 1, r.length - 1));
|
|
107
|
+
}, [r.length]), M = o > 0, k = o >= 0 && o < r.length - 1, m = c(() => {
|
|
108
|
+
if (o < 0)
|
|
100
109
|
return;
|
|
101
|
-
const
|
|
102
|
-
if (
|
|
103
|
-
return
|
|
104
|
-
}, [
|
|
105
|
-
() => _(
|
|
106
|
-
[
|
|
107
|
-
),
|
|
108
|
-
() =>
|
|
109
|
-
[
|
|
110
|
-
),
|
|
111
|
-
const
|
|
112
|
-
return
|
|
110
|
+
const i = r[o];
|
|
111
|
+
if (i)
|
|
112
|
+
return E(i);
|
|
113
|
+
}, [o, r]), y = c(
|
|
114
|
+
() => _(r, o),
|
|
115
|
+
[o, r]
|
|
116
|
+
), q = c(
|
|
117
|
+
() => j(r),
|
|
118
|
+
[r]
|
|
119
|
+
), v = c(() => {
|
|
120
|
+
const i = f.get(o) ?? [];
|
|
121
|
+
return O(
|
|
113
122
|
t.current,
|
|
123
|
+
i
|
|
124
|
+
) ? t.current : (t.current = i, i);
|
|
125
|
+
}, [o, f]), N = c(
|
|
126
|
+
() => F(
|
|
127
|
+
s,
|
|
128
|
+
d,
|
|
114
129
|
o
|
|
115
|
-
) ? t.current : (t.current = o, o);
|
|
116
|
-
}, [u, a]), q = c(
|
|
117
|
-
() => D(
|
|
118
|
-
r,
|
|
119
|
-
i,
|
|
120
|
-
u
|
|
121
130
|
),
|
|
122
|
-
[
|
|
123
|
-
),
|
|
124
|
-
() =>
|
|
125
|
-
[
|
|
131
|
+
[o, d, s]
|
|
132
|
+
), R = c(
|
|
133
|
+
() => m?.type === "interaction" ? m : void 0,
|
|
134
|
+
[m]
|
|
126
135
|
);
|
|
127
136
|
return {
|
|
128
|
-
currentElementList:
|
|
129
|
-
stepElementLists:
|
|
130
|
-
slideElementList:
|
|
131
|
-
currentIndex:
|
|
132
|
-
audioList:
|
|
133
|
-
currentAudioSequenceIndexes:
|
|
134
|
-
currentStepHasSpeakableElement:
|
|
135
|
-
currentInteractionElement:
|
|
137
|
+
currentElementList: y,
|
|
138
|
+
stepElementLists: q,
|
|
139
|
+
slideElementList: r,
|
|
140
|
+
currentIndex: o,
|
|
141
|
+
audioList: l,
|
|
142
|
+
currentAudioSequenceIndexes: v,
|
|
143
|
+
currentStepHasSpeakableElement: N,
|
|
144
|
+
currentInteractionElement: R,
|
|
136
145
|
canGoPrev: M,
|
|
137
|
-
canGoNext:
|
|
138
|
-
handlePrev:
|
|
139
|
-
handleNext:
|
|
146
|
+
canGoNext: k,
|
|
147
|
+
handlePrev: A,
|
|
148
|
+
handleNext: I
|
|
140
149
|
};
|
|
141
150
|
};
|
|
142
151
|
export {
|
|
143
|
-
|
|
152
|
+
W as default
|
|
144
153
|
};
|
|
145
154
|
//# sourceMappingURL=useSlide.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSlide.es.js","sources":["../../../src/components/Slide/useSlide.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport { applyDiffElement } from \"./diff-utils\";\nimport type { Element, ElementAudioSegment } from \"./types\";\n\nexport interface SlideAudioItem {\n audioKey?: string;\n sequenceNumber?: number;\n audioUrl?: string;\n audioSegments?: ElementAudioSegment[];\n isAudioStreaming?: boolean;\n element?: Element;\n}\n\nexport interface UseSlideResult {\n currentElementList: Element[];\n stepElementLists: Element[][];\n slideElementList: Element[];\n currentIndex: number;\n audioList: SlideAudioItem[];\n currentAudioSequenceIndexes: number[];\n currentStepHasSpeakableElement: boolean;\n currentInteractionElement?: Element;\n canGoPrev: boolean;\n canGoNext: boolean;\n handlePrev: () => void;\n handleNext: () => void;\n}\n\nconst getMarkerElementList = (elementList: Element[]) =>\n elementList.filter((element) => element.is_marker);\n\nconst getMarkerElementIndexes = (elementList: Element[]) =>\n elementList.reduce<number[]>((indexes, element, index) => {\n if (element.is_marker) {\n indexes.push(index);\n }\n\n return indexes;\n }, []);\n\nconst hasPlayableAudio = (element?: Element) =>\n Boolean(\n element?.is_speakable &&\n (element.audio_url || (element.audio_segments?.length ?? 0) > 0)\n );\n\nconst isStreamingAudio = (segments: ElementAudioSegment[] = []) =>\n segments.length > 0 && !segments.some((segment) => segment.is_final);\n\nconst getElementAudioKey = (element: Element, index: number) => {\n const candidateElement = element as Element & {\n element_bid?: string;\n blockBid?: string;\n generated_block_bid?: string;\n };\n\n return (\n candidateElement.element_bid ||\n candidateElement.blockBid ||\n candidateElement.generated_block_bid ||\n `${element.type}:${String(element.sequence_number ?? index)}`\n );\n};\n\nconst getAudioList = (elementList: Element[]) =>\n elementList.reduce<SlideAudioItem[]>((list, element, elementIndex) => {\n if (hasPlayableAudio(element)) {\n const normalizedAudioSegments = element.audio_segments ?? [];\n const hasAudioSegments = normalizedAudioSegments.length > 0;\n\n list.push({\n audioKey: getElementAudioKey(element, elementIndex),\n sequenceNumber: element.sequence_number,\n // Keep one canonical source to avoid duplicated playback resets.\n // When streaming segments exist, keep playback on the segment source.\n audioUrl: hasAudioSegments ? \"\" : element.audio_url,\n audioSegments: normalizedAudioSegments,\n isAudioStreaming: isStreamingAudio(normalizedAudioSegments),\n element,\n });\n }\n\n return list;\n }, []);\n\nconst getAudioIndexMap = (elementList: Element[]) => {\n const audioIndexMap = new Map<number, number>();\n let audioIndex = 0;\n\n elementList.forEach((element, index) => {\n if (hasPlayableAudio(element)) {\n audioIndexMap.set(index, audioIndex);\n audioIndex += 1;\n }\n });\n\n return audioIndexMap;\n};\n\nconst getSlideAudioSequenceMap = (\n elementList: Element[],\n markerElementIndexes: number[],\n audioIndexMap: Map<number, number>\n) =>\n markerElementIndexes.reduce<Map<number, number[]>>(\n (sequenceMap, startIndex, slideIndex) => {\n const nextMarkerIndex =\n markerElementIndexes[slideIndex + 1] ?? elementList.length;\n const sequenceIndexes: number[] = [];\n\n for (let index = startIndex; index < nextMarkerIndex; index += 1) {\n const element = elementList[index];\n\n if (!hasPlayableAudio(element)) {\n continue;\n }\n\n const audioIndex = audioIndexMap.get(index);\n\n if (audioIndex == null) {\n continue;\n }\n\n sequenceIndexes.push(audioIndex);\n }\n\n sequenceMap.set(slideIndex, sequenceIndexes);\n return sequenceMap;\n },\n new Map<number, number[]>()\n );\n\nconst getInitialSlideIndex = (slideElementList: Element[]) => {\n const visibleIndex = slideElementList.findIndex(\n (element) => element.is_renderable === true\n );\n\n if (visibleIndex >= 0) {\n return visibleIndex;\n }\n\n return slideElementList.findIndex(\n (element) => element.is_renderable !== false\n );\n};\n\nconst getVisibleElement = (element: Element): Element => ({\n ...element,\n is_renderable: true,\n});\n\nconst getCurrentElementList = (\n slideElementList: Element[],\n currentIndex: number\n) => {\n if (currentIndex < 0) {\n return [];\n }\n\n return slideElementList\n .slice(0, currentIndex + 1)\n .reduce<Element[]>((currentList, element) => {\n if (element.type === \"interaction\") {\n return currentList;\n }\n\n const visibleElement = getVisibleElement(element);\n\n if (visibleElement.type === \"diff\") {\n const nextList = applyDiffElement(currentList, visibleElement);\n\n return nextList ?? [...currentList, visibleElement];\n }\n\n if (element.is_new) {\n return [visibleElement];\n }\n\n if (currentList.length === 0) {\n return [visibleElement];\n }\n\n return [...currentList, visibleElement];\n }, []);\n};\n\nconst getStepElementLists = (slideElementList: Element[]) =>\n slideElementList.map((_, index) =>\n getCurrentElementList(slideElementList, index)\n );\n\nconst getStepHasSpeakableElement = (\n elementList: Element[],\n markerElementIndexes: number[],\n currentIndex: number\n) => {\n if (currentIndex < 0) {\n return false;\n }\n\n const startIndex = markerElementIndexes[currentIndex];\n\n if (typeof startIndex !== \"number\") {\n return false;\n }\n\n const nextMarkerIndex =\n markerElementIndexes[currentIndex + 1] ?? elementList.length;\n\n for (let index = startIndex; index < nextMarkerIndex; index += 1) {\n if (elementList[index]?.is_speakable) {\n return true;\n }\n }\n\n return false;\n};\n\nconst hasSameElementReferences = (\n prevElementList: Element[],\n nextElementList: Element[]\n) =>\n prevElementList.length === nextElementList.length &&\n prevElementList.every((element, index) => element === nextElementList[index]);\n\nconst hasSameNumberValues = (prevValues: number[], nextValues: number[]) =>\n prevValues.length === nextValues.length &&\n prevValues.every((value, index) => value === nextValues[index]);\n\nconst useSlide = (elementList: Element[] = []): UseSlideResult => {\n const stableElementListRef = useRef(elementList);\n const stableCurrentAudioSequenceIndexesRef = useRef<number[]>([]);\n const stableElementList = useMemo(() => {\n if (hasSameElementReferences(stableElementListRef.current, elementList)) {\n return stableElementListRef.current;\n }\n\n // Reuse the previous wrapper array when the element references are unchanged.\n stableElementListRef.current = elementList;\n return elementList;\n }, [elementList]);\n const slideElementList = useMemo(\n () => getMarkerElementList(stableElementList),\n [stableElementList]\n );\n const markerElementIndexes = useMemo(\n () => getMarkerElementIndexes(stableElementList),\n [stableElementList]\n );\n const audioList = useMemo(\n () => getAudioList(stableElementList),\n [stableElementList]\n );\n const audioIndexMap = useMemo(\n () => getAudioIndexMap(stableElementList),\n [stableElementList]\n );\n const slideAudioSequenceMap = useMemo(\n () =>\n getSlideAudioSequenceMap(\n stableElementList,\n markerElementIndexes,\n audioIndexMap\n ),\n [audioIndexMap, markerElementIndexes, stableElementList]\n );\n const [currentIndex, setCurrentIndex] = useState(() =>\n getInitialSlideIndex(slideElementList)\n );\n\n useEffect(() => {\n setCurrentIndex((prevIndex) => {\n if (slideElementList.length === 0) {\n return -1;\n }\n\n if (prevIndex >= 0 && prevIndex < slideElementList.length) {\n return prevIndex;\n }\n\n return getInitialSlideIndex(slideElementList);\n });\n }, [slideElementList]);\n\n const handlePrev = useCallback(() => {\n setCurrentIndex((prevIndex) => {\n if (prevIndex <= 0) {\n return Math.max(prevIndex, 0);\n }\n\n return Math.max(prevIndex - 1, 0);\n });\n }, []);\n\n const handleNext = useCallback(() => {\n setCurrentIndex((prevIndex) => {\n if (prevIndex < 0) {\n return prevIndex;\n }\n\n return Math.min(prevIndex + 1, slideElementList.length - 1);\n });\n }, [slideElementList.length]);\n\n const canGoPrev = currentIndex > 0;\n const canGoNext =\n currentIndex >= 0 && currentIndex < slideElementList.length - 1;\n const currentStepElement = useMemo(() => {\n if (currentIndex < 0) {\n return undefined;\n }\n\n const element = slideElementList[currentIndex];\n\n if (!element) {\n return undefined;\n }\n\n return getVisibleElement(element);\n }, [currentIndex, slideElementList]);\n const currentElementList = useMemo(\n () => getCurrentElementList(slideElementList, currentIndex),\n [currentIndex, slideElementList]\n );\n const stepElementLists = useMemo(\n () => getStepElementLists(slideElementList),\n [slideElementList]\n );\n const currentAudioSequenceIndexes = useMemo(() => {\n const nextAudioSequenceIndexes =\n slideAudioSequenceMap.get(currentIndex) ?? [];\n\n if (\n hasSameNumberValues(\n stableCurrentAudioSequenceIndexesRef.current,\n nextAudioSequenceIndexes\n )\n ) {\n return stableCurrentAudioSequenceIndexesRef.current;\n }\n\n stableCurrentAudioSequenceIndexesRef.current = nextAudioSequenceIndexes;\n\n return nextAudioSequenceIndexes;\n }, [currentIndex, slideAudioSequenceMap]);\n const currentStepHasSpeakableElement = useMemo(\n () =>\n getStepHasSpeakableElement(\n stableElementList,\n markerElementIndexes,\n currentIndex\n ),\n [currentIndex, markerElementIndexes, stableElementList]\n );\n const currentInteractionElement = useMemo(\n () =>\n currentStepElement?.type === \"interaction\"\n ? currentStepElement\n : undefined,\n [currentStepElement]\n );\n\n return {\n currentElementList,\n stepElementLists,\n slideElementList,\n currentIndex,\n audioList,\n currentAudioSequenceIndexes,\n currentStepHasSpeakableElement,\n currentInteractionElement,\n canGoPrev,\n canGoNext,\n handlePrev,\n handleNext,\n };\n};\n\nexport default useSlide;\n"],"names":["getMarkerElementList","elementList","element","getMarkerElementIndexes","indexes","index","hasPlayableAudio","isStreamingAudio","segments","segment","getElementAudioKey","candidateElement","getAudioList","list","elementIndex","normalizedAudioSegments","hasAudioSegments","getAudioIndexMap","audioIndexMap","audioIndex","getSlideAudioSequenceMap","markerElementIndexes","sequenceMap","startIndex","slideIndex","nextMarkerIndex","sequenceIndexes","getInitialSlideIndex","slideElementList","visibleIndex","getVisibleElement","getCurrentElementList","currentIndex","currentList","visibleElement","applyDiffElement","getStepElementLists","_","getStepHasSpeakableElement","hasSameElementReferences","prevElementList","nextElementList","hasSameNumberValues","prevValues","nextValues","value","useSlide","stableElementListRef","useRef","stableCurrentAudioSequenceIndexesRef","stableElementList","useMemo","audioList","slideAudioSequenceMap","setCurrentIndex","useState","useEffect","prevIndex","handlePrev","useCallback","handleNext","canGoPrev","canGoNext","currentStepElement","currentElementList","stepElementLists","currentAudioSequenceIndexes","nextAudioSequenceIndexes","currentStepHasSpeakableElement","currentInteractionElement"],"mappings":";;AA6BA,MAAMA,IAAuB,CAACC,MAC5BA,EAAY,OAAO,CAACC,MAAYA,EAAQ,SAAS,GAE7CC,IAA0B,CAACF,MAC/BA,EAAY,OAAiB,CAACG,GAASF,GAASG,OAC1CH,EAAQ,aACVE,EAAQ,KAAKC,CAAK,GAGbD,IACN,EAAE,GAEDE,IAAmB,C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lB,EAAqC,WAG9CA,EAAqC,UAAUkB,GAExCA;AAAA,EACT,GAAG,CAACnC,GAAcqB,CAAqB,CAAC,GAClCe,IAAiCjB;AAAA,IACrC,MACEb;AAAA,MACEY;AAAA,MACA7B;AAAA,MACAW;AAAA,IAAA;AAAA,IAEJ,CAACA,GAAcX,GAAsB6B,CAAiB;AAAA,EAAA,GAElDmB,IAA4BlB;AAAA,IAChC,MACEY,GAAoB,SAAS,gBACzBA,IACA;AAAA,IACN,CAACA,CAAkB;AAAA,EAAA;AAGrB,SAAO;AAAA,IACL,oBAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,kBAAArC;AAAA,IACA,cAAAI;AAAA,IACA,WAAAoB;AAAA,IACA,6BAAAc;AAAA,IACA,gCAAAE;AAAA,IACA,2BAAAC;AAAA,IACA,WAAAR;AAAA,IACA,WAAAC;AAAA,IACA,YAAAJ;AAAA,IACA,YAAAE;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"useSlide.es.js","sources":["../../../src/components/Slide/useSlide.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport { applyDiffElement } from \"./diff-utils\";\nimport type { Element, ElementAudioSegment } from \"./types\";\nimport { resolveNextSlideIndexAfterMarkerAppend } from \"./utils/streamingNavigation\";\n\nexport interface SlideAudioItem {\n audioKey?: string;\n sequenceNumber?: number;\n audioUrl?: string;\n audioSegments?: ElementAudioSegment[];\n isAudioStreaming?: boolean;\n element?: Element;\n}\n\nexport interface UseSlideResult {\n currentElementList: Element[];\n stepElementLists: Element[][];\n slideElementList: Element[];\n currentIndex: number;\n audioList: SlideAudioItem[];\n currentAudioSequenceIndexes: number[];\n currentStepHasSpeakableElement: boolean;\n currentInteractionElement?: Element;\n canGoPrev: boolean;\n canGoNext: boolean;\n handlePrev: () => void;\n handleNext: () => void;\n}\n\nconst getMarkerElementList = (elementList: Element[]) =>\n elementList.filter((element) => element.is_marker);\n\nconst getMarkerElementIndexes = (elementList: Element[]) =>\n elementList.reduce<number[]>((indexes, element, index) => {\n if (element.is_marker) {\n indexes.push(index);\n }\n\n return indexes;\n }, []);\n\nconst hasPlayableAudio = (element?: Element) =>\n Boolean(\n element?.is_speakable &&\n (element.audio_url || (element.audio_segments?.length ?? 0) > 0)\n );\n\nconst isStreamingAudio = (segments: ElementAudioSegment[] = []) =>\n segments.length > 0 && !segments.some((segment) => segment.is_final);\n\nconst getElementAudioKey = (element: Element, index: number) => {\n const candidateElement = element as Element & {\n element_bid?: string;\n blockBid?: string;\n generated_block_bid?: string;\n };\n\n return (\n candidateElement.element_bid ||\n candidateElement.blockBid ||\n candidateElement.generated_block_bid ||\n `${element.type}:${String(element.sequence_number ?? index)}`\n );\n};\n\nconst getAudioList = (elementList: Element[]) =>\n elementList.reduce<SlideAudioItem[]>((list, element, elementIndex) => {\n if (hasPlayableAudio(element)) {\n const normalizedAudioSegments = element.audio_segments ?? [];\n const hasAudioSegments = normalizedAudioSegments.length > 0;\n\n list.push({\n audioKey: getElementAudioKey(element, elementIndex),\n sequenceNumber: element.sequence_number,\n // Keep one canonical source to avoid duplicated playback resets.\n // When streaming segments exist, keep playback on the segment source.\n audioUrl: hasAudioSegments ? \"\" : element.audio_url,\n audioSegments: normalizedAudioSegments,\n isAudioStreaming: isStreamingAudio(normalizedAudioSegments),\n element,\n });\n }\n\n return list;\n }, []);\n\nconst getAudioIndexMap = (elementList: Element[]) => {\n const audioIndexMap = new Map<number, number>();\n let audioIndex = 0;\n\n elementList.forEach((element, index) => {\n if (hasPlayableAudio(element)) {\n audioIndexMap.set(index, audioIndex);\n audioIndex += 1;\n }\n });\n\n return audioIndexMap;\n};\n\nconst getSlideAudioSequenceMap = (\n elementList: Element[],\n markerElementIndexes: number[],\n audioIndexMap: Map<number, number>\n) =>\n markerElementIndexes.reduce<Map<number, number[]>>(\n (sequenceMap, startIndex, slideIndex) => {\n const nextMarkerIndex =\n markerElementIndexes[slideIndex + 1] ?? elementList.length;\n const sequenceIndexes: number[] = [];\n\n for (let index = startIndex; index < nextMarkerIndex; index += 1) {\n const element = elementList[index];\n\n if (!hasPlayableAudio(element)) {\n continue;\n }\n\n const audioIndex = audioIndexMap.get(index);\n\n if (audioIndex == null) {\n continue;\n }\n\n sequenceIndexes.push(audioIndex);\n }\n\n sequenceMap.set(slideIndex, sequenceIndexes);\n return sequenceMap;\n },\n new Map<number, number[]>()\n );\n\nconst getInitialSlideIndex = (slideElementList: Element[]) => {\n const visibleIndex = slideElementList.findIndex(\n (element) => element.is_renderable === true\n );\n\n if (visibleIndex >= 0) {\n return visibleIndex;\n }\n\n return slideElementList.findIndex(\n (element) => element.is_renderable !== false\n );\n};\n\nconst getVisibleElement = (element: Element): Element => ({\n ...element,\n is_renderable: true,\n});\n\nconst getCurrentElementList = (\n slideElementList: Element[],\n currentIndex: number\n) => {\n if (currentIndex < 0) {\n return [];\n }\n\n return slideElementList\n .slice(0, currentIndex + 1)\n .reduce<Element[]>((currentList, element) => {\n if (element.type === \"interaction\") {\n return currentList;\n }\n\n const visibleElement = getVisibleElement(element);\n\n if (visibleElement.type === \"diff\") {\n const nextList = applyDiffElement(currentList, visibleElement);\n\n return nextList ?? [...currentList, visibleElement];\n }\n\n if (element.is_new) {\n return [visibleElement];\n }\n\n if (currentList.length === 0) {\n return [visibleElement];\n }\n\n return [...currentList, visibleElement];\n }, []);\n};\n\nconst getStepElementLists = (slideElementList: Element[]) =>\n slideElementList.map((_, index) =>\n getCurrentElementList(slideElementList, index)\n );\n\nconst getStepHasSpeakableElement = (\n elementList: Element[],\n markerElementIndexes: number[],\n currentIndex: number\n) => {\n if (currentIndex < 0) {\n return false;\n }\n\n const startIndex = markerElementIndexes[currentIndex];\n\n if (typeof startIndex !== \"number\") {\n return false;\n }\n\n const nextMarkerIndex =\n markerElementIndexes[currentIndex + 1] ?? elementList.length;\n\n for (let index = startIndex; index < nextMarkerIndex; index += 1) {\n if (elementList[index]?.is_speakable) {\n return true;\n }\n }\n\n return false;\n};\n\nconst hasSameElementReferences = (\n prevElementList: Element[],\n nextElementList: Element[]\n) =>\n prevElementList.length === nextElementList.length &&\n prevElementList.every((element, index) => element === nextElementList[index]);\n\nconst hasSameNumberValues = (prevValues: number[], nextValues: number[]) =>\n prevValues.length === nextValues.length &&\n prevValues.every((value, index) => value === nextValues[index]);\n\nconst useSlide = (elementList: Element[] = []): UseSlideResult => {\n const stableElementListRef = useRef(elementList);\n const stableCurrentAudioSequenceIndexesRef = useRef<number[]>([]);\n const stableElementList = useMemo(() => {\n if (hasSameElementReferences(stableElementListRef.current, elementList)) {\n return stableElementListRef.current;\n }\n\n // Reuse the previous wrapper array when the element references are unchanged.\n stableElementListRef.current = elementList;\n return elementList;\n }, [elementList]);\n const slideElementList = useMemo(\n () => getMarkerElementList(stableElementList),\n [stableElementList]\n );\n const previousSlideElementListRef = useRef(slideElementList);\n const markerElementIndexes = useMemo(\n () => getMarkerElementIndexes(stableElementList),\n [stableElementList]\n );\n const audioList = useMemo(\n () => getAudioList(stableElementList),\n [stableElementList]\n );\n const audioIndexMap = useMemo(\n () => getAudioIndexMap(stableElementList),\n [stableElementList]\n );\n const slideAudioSequenceMap = useMemo(\n () =>\n getSlideAudioSequenceMap(\n stableElementList,\n markerElementIndexes,\n audioIndexMap\n ),\n [audioIndexMap, markerElementIndexes, stableElementList]\n );\n const [currentIndex, setCurrentIndex] = useState(() =>\n getInitialSlideIndex(slideElementList)\n );\n\n useEffect(() => {\n const previousSlideElementList = previousSlideElementListRef.current;\n\n setCurrentIndex((prevIndex) => {\n const resolvedNextIndex = resolveNextSlideIndexAfterMarkerAppend({\n previousIndex: prevIndex,\n previousSlideElementList,\n nextSlideElementList: slideElementList,\n });\n\n if (resolvedNextIndex >= 0) {\n return resolvedNextIndex;\n }\n\n return getInitialSlideIndex(slideElementList);\n });\n\n previousSlideElementListRef.current = slideElementList;\n }, [slideElementList]);\n\n const handlePrev = useCallback(() => {\n setCurrentIndex((prevIndex) => {\n if (prevIndex <= 0) {\n return Math.max(prevIndex, 0);\n }\n\n return Math.max(prevIndex - 1, 0);\n });\n }, []);\n\n const handleNext = useCallback(() => {\n setCurrentIndex((prevIndex) => {\n if (prevIndex < 0) {\n return prevIndex;\n }\n\n return Math.min(prevIndex + 1, slideElementList.length - 1);\n });\n }, [slideElementList.length]);\n\n const canGoPrev = currentIndex > 0;\n const canGoNext =\n currentIndex >= 0 && currentIndex < slideElementList.length - 1;\n const currentStepElement = useMemo(() => {\n if (currentIndex < 0) {\n return undefined;\n }\n\n const element = slideElementList[currentIndex];\n\n if (!element) {\n return undefined;\n }\n\n return getVisibleElement(element);\n }, [currentIndex, slideElementList]);\n const currentElementList = useMemo(\n () => getCurrentElementList(slideElementList, currentIndex),\n [currentIndex, slideElementList]\n );\n const stepElementLists = useMemo(\n () => getStepElementLists(slideElementList),\n [slideElementList]\n );\n const currentAudioSequenceIndexes = useMemo(() => {\n const nextAudioSequenceIndexes =\n slideAudioSequenceMap.get(currentIndex) ?? [];\n\n if (\n hasSameNumberValues(\n stableCurrentAudioSequenceIndexesRef.current,\n nextAudioSequenceIndexes\n )\n ) {\n return stableCurrentAudioSequenceIndexesRef.current;\n }\n\n stableCurrentAudioSequenceIndexesRef.current = nextAudioSequenceIndexes;\n\n return nextAudioSequenceIndexes;\n }, [currentIndex, slideAudioSequenceMap]);\n const currentStepHasSpeakableElement = useMemo(\n () =>\n getStepHasSpeakableElement(\n stableElementList,\n markerElementIndexes,\n currentIndex\n ),\n [currentIndex, markerElementIndexes, stableElementList]\n );\n const currentInteractionElement = useMemo(\n () =>\n currentStepElement?.type === \"interaction\"\n ? currentStepElement\n : undefined,\n [currentStepElement]\n );\n\n return {\n currentElementList,\n stepElementLists,\n slideElementList,\n currentIndex,\n audioList,\n currentAudioSequenceIndexes,\n currentStepHasSpeakableElement,\n currentInteractionElement,\n canGoPrev,\n canGoNext,\n handlePrev,\n handleNext,\n };\n};\n\nexport default useSlide;\n"],"names":["getMarkerElementList","elementList","element","getMarkerElementIndexes","indexes","index","hasPlayableAudio","isStreamingAudio","segments","segment","getElementAudioKey","candidateElement","getAudioList","list","elementIndex","normalizedAudioSegments","hasAudioSegments","getAudioIndexMap","audioIndexMap","audioIndex","getSlideAudioSequenceMap","markerElementIndexes","sequenceMap","startIndex","slideIndex","nextMarkerIndex","sequenceIndexes","getInitialSlideIndex","slideElementList","visibleIndex","getVisibleElement","getCurrentElementList","currentIndex","currentList","visibleElement","applyDiffElement","getStepElementLists","_","getStepHasSpeakableElement","hasSameElementReferences","prevElementList","nextElementList","hasSameNumberValues","prevValues","nextValues","value","useSlide","stableElementListRef","useRef","stableCurrentAudioSequenceIndexesRef","stableElementList","useMemo","previousSlideElementListRef","audioList","slideAudioSequenceMap","setCurrentIndex","useState","useEffect","previousSlideElementList","prevIndex","resolvedNextIndex","resolveNextSlideIndexAfterMarkerAppend","handlePrev","useCallback","handleNext","canGoPrev","canGoNext","currentStepElement","currentElementList","stepElementLists","currentAudioSequenceIndexes","nextAudioSequenceIndexes","currentStepHasSpeakableElement","currentInteractionElement"],"mappings":";;;AA8BA,MAAMA,IAAuB,CAACC,MAC5BA,EAAY,OAAO,CAACC,MAAYA,EAAQ,SAAS,GAE7CC,IAA0B,CAACF,MAC/BA,EAAY,OAAiB,CAACG,GAASF,GAASG,OAC1CH,EAAQ,aACVE,EAAQ,KAAKC,CAAK,GAGbD,IACN,EAAE,GAEDE,IAAmB,CAACJ,MACxB,GACEA,GAAS,iBACRA,EAAQ,cAAcA,EAAQ,gBAAgB,UAAU,KAAK,KAG5DK,IAAmB,CAACC,IAAkC,OAC1DA,EAAS,SAAS,KAAK,CAACA,EAAS,KAAK,CAACC,MAAYA,EAAQ,QAAQ,GAE/DC,IAAqB,CAACR,GAAkBG,MAAkB;AAC9D,QAAMM,IAAmBT;AAMzB,SACES,EAAiB,eACjBA,EAAiB,YACjBA,EAAiB,uBACjB,GAAGT,EAAQ,IAAI,IAAI,OAAOA,EAAQ,mBAAmBG,CAAK,CAAC;AAE/D,GAEMO,IAAe,C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B6B,CAAiB;AAAA,EAAA,GAElDuB,IAA4BtB;AAAA,IAChC,MACEgB,GAAoB,SAAS,gBACzBA,IACA;AAAA,IACN,CAACA,CAAkB;AAAA,EAAA;AAGrB,SAAO;AAAA,IACL,oBAAAC;AAAA,IACA,kBAAAC;AAAA,IACA,kBAAAzC;AAAA,IACA,cAAAI;AAAA,IACA,WAAAqB;AAAA,IACA,6BAAAiB;AAAA,IACA,gCAAAE;AAAA,IACA,2BAAAC;AAAA,IACA,WAAAR;AAAA,IACA,WAAAC;AAAA,IACA,YAAAJ;AAAA,IACA,YAAAE;AAAA,EAAA;AAEJ;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=({previousMarkerCount:e,nextMarkerCount:o,previousIndex:n,previousCanGoNext:d,nextCanGoNext:a,currentAudioKey:c,hasCompletedCurrentStepAudio:l,hasResolvedCurrentInteraction:i,currentStepHasSpeakableElement:t,currentInteractionElement:s,isAutoAdvanceEnabled:p,shouldUseSilentStepAutoAdvanceToggle:S})=>{const r=o>e,u=e>0&&n===e-1,A=!d&&a,f=!!s&&i,h=t&&l,v=!t&&!s&&(!S||p);return!r||!u||!A||c?!1:f||h||v};exports.shouldAutoAdvanceIntoAppendedMarker=k;
|
|
2
|
+
//# sourceMappingURL=appendedMarkerAdvance.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appendedMarkerAdvance.cjs.js","sources":["../../../../src/components/Slide/utils/appendedMarkerAdvance.ts"],"sourcesContent":["import type { Element } from \"../types\";\n\ninterface ShouldAutoAdvanceIntoAppendedMarkerParams {\n previousMarkerCount: number;\n nextMarkerCount: number;\n previousIndex: number;\n previousCanGoNext: boolean;\n nextCanGoNext: boolean;\n currentAudioKey: string | null;\n hasCompletedCurrentStepAudio: boolean;\n hasResolvedCurrentInteraction: boolean;\n currentStepHasSpeakableElement: boolean;\n currentInteractionElement?: Element;\n isAutoAdvanceEnabled: boolean;\n shouldUseSilentStepAutoAdvanceToggle: boolean;\n}\n\nexport const shouldAutoAdvanceIntoAppendedMarker = ({\n previousMarkerCount,\n nextMarkerCount,\n previousIndex,\n previousCanGoNext,\n nextCanGoNext,\n currentAudioKey,\n hasCompletedCurrentStepAudio,\n hasResolvedCurrentInteraction,\n currentStepHasSpeakableElement,\n currentInteractionElement,\n isAutoAdvanceEnabled,\n shouldUseSilentStepAutoAdvanceToggle,\n}: ShouldAutoAdvanceIntoAppendedMarkerParams) => {\n const hasAppendedMarker = nextMarkerCount > previousMarkerCount;\n const wasFocusedOnPreviousLastMarker =\n previousMarkerCount > 0 && previousIndex === previousMarkerCount - 1;\n const hasJustUnlockedNextStep = !previousCanGoNext && nextCanGoNext;\n const isResolvedInteractionStep =\n Boolean(currentInteractionElement) && hasResolvedCurrentInteraction;\n const isCompletedSpeakableStep =\n currentStepHasSpeakableElement && hasCompletedCurrentStepAudio;\n const isSilentStep =\n !currentStepHasSpeakableElement && !currentInteractionElement;\n const shouldAutoAdvanceSilentStep =\n isSilentStep &&\n (!shouldUseSilentStepAutoAdvanceToggle || isAutoAdvanceEnabled);\n\n if (!hasAppendedMarker || !wasFocusedOnPreviousLastMarker) {\n return false;\n }\n\n if (!hasJustUnlockedNextStep || currentAudioKey) {\n return false;\n }\n\n return (\n isResolvedInteractionStep ||\n isCompletedSpeakableStep ||\n shouldAutoAdvanceSilentStep\n );\n};\n"],"names":["shouldAutoAdvanceIntoAppendedMarker","previousMarkerCount","nextMarkerCount","previousIndex","previousCanGoNext","nextCanGoNext","currentAudioKey","hasCompletedCurrentStepAudio","hasResolvedCurrentInteraction","currentStepHasSpeakableElement","currentInteractionElement","isAutoAdvanceEnabled","shouldUseSilentStepAutoAdvanceToggle","hasAppendedMarker","wasFocusedOnPreviousLastMarker","hasJustUnlockedNextStep","isResolvedInteractionStep","isCompletedSpeakableStep","shouldAutoAdvanceSilentStep"],"mappings":"gFAiBO,MAAMA,EAAsC,CAAC,CAClD,oBAAAC,EACA,gBAAAC,EACA,cAAAC,EACA,kBAAAC,EACA,cAAAC,EACA,gBAAAC,EACA,6BAAAC,EACA,8BAAAC,EACA,+BAAAC,EACA,0BAAAC,EACA,qBAAAC,EACA,qCAAAC,CACF,IAAiD,CAC/C,MAAMC,EAAoBX,EAAkBD,EACtCa,EACJb,EAAsB,GAAKE,IAAkBF,EAAsB,EAC/Dc,EAA0B,CAACX,GAAqBC,EAChDW,EACJ,EAAQN,GAA8BF,EAClCS,EACJR,GAAkCF,EAG9BW,EADJ,CAACT,GAAkC,CAACC,IAGnC,CAACE,GAAwCD,GAM5C,MAJI,CAACE,GAAqB,CAACC,GAIvB,CAACC,GAA2BT,EACvB,GAIPU,GACAC,GACAC,CAEJ"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Element } from '../types';
|
|
2
|
+
interface ShouldAutoAdvanceIntoAppendedMarkerParams {
|
|
3
|
+
previousMarkerCount: number;
|
|
4
|
+
nextMarkerCount: number;
|
|
5
|
+
previousIndex: number;
|
|
6
|
+
previousCanGoNext: boolean;
|
|
7
|
+
nextCanGoNext: boolean;
|
|
8
|
+
currentAudioKey: string | null;
|
|
9
|
+
hasCompletedCurrentStepAudio: boolean;
|
|
10
|
+
hasResolvedCurrentInteraction: boolean;
|
|
11
|
+
currentStepHasSpeakableElement: boolean;
|
|
12
|
+
currentInteractionElement?: Element;
|
|
13
|
+
isAutoAdvanceEnabled: boolean;
|
|
14
|
+
shouldUseSilentStepAutoAdvanceToggle: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare const shouldAutoAdvanceIntoAppendedMarker: ({ previousMarkerCount, nextMarkerCount, previousIndex, previousCanGoNext, nextCanGoNext, currentAudioKey, hasCompletedCurrentStepAudio, hasResolvedCurrentInteraction, currentStepHasSpeakableElement, currentInteractionElement, isAutoAdvanceEnabled, shouldUseSilentStepAutoAdvanceToggle, }: ShouldAutoAdvanceIntoAppendedMarkerParams) => boolean;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const x = ({
|
|
2
|
+
previousMarkerCount: e,
|
|
3
|
+
nextMarkerCount: o,
|
|
4
|
+
previousIndex: n,
|
|
5
|
+
previousCanGoNext: d,
|
|
6
|
+
nextCanGoNext: c,
|
|
7
|
+
currentAudioKey: a,
|
|
8
|
+
hasCompletedCurrentStepAudio: l,
|
|
9
|
+
hasResolvedCurrentInteraction: p,
|
|
10
|
+
currentStepHasSpeakableElement: s,
|
|
11
|
+
currentInteractionElement: t,
|
|
12
|
+
isAutoAdvanceEnabled: i,
|
|
13
|
+
shouldUseSilentStepAutoAdvanceToggle: S
|
|
14
|
+
}) => {
|
|
15
|
+
const A = o > e, f = e > 0 && n === e - 1, h = !d && c, r = !!t && p, u = s && l, k = !s && !t && (!S || i);
|
|
16
|
+
return !A || !f || !h || a ? !1 : r || u || k;
|
|
17
|
+
};
|
|
18
|
+
export {
|
|
19
|
+
x as shouldAutoAdvanceIntoAppendedMarker
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=appendedMarkerAdvance.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"appendedMarkerAdvance.es.js","sources":["../../../../src/components/Slide/utils/appendedMarkerAdvance.ts"],"sourcesContent":["import type { Element } from \"../types\";\n\ninterface ShouldAutoAdvanceIntoAppendedMarkerParams {\n previousMarkerCount: number;\n nextMarkerCount: number;\n previousIndex: number;\n previousCanGoNext: boolean;\n nextCanGoNext: boolean;\n currentAudioKey: string | null;\n hasCompletedCurrentStepAudio: boolean;\n hasResolvedCurrentInteraction: boolean;\n currentStepHasSpeakableElement: boolean;\n currentInteractionElement?: Element;\n isAutoAdvanceEnabled: boolean;\n shouldUseSilentStepAutoAdvanceToggle: boolean;\n}\n\nexport const shouldAutoAdvanceIntoAppendedMarker = ({\n previousMarkerCount,\n nextMarkerCount,\n previousIndex,\n previousCanGoNext,\n nextCanGoNext,\n currentAudioKey,\n hasCompletedCurrentStepAudio,\n hasResolvedCurrentInteraction,\n currentStepHasSpeakableElement,\n currentInteractionElement,\n isAutoAdvanceEnabled,\n shouldUseSilentStepAutoAdvanceToggle,\n}: ShouldAutoAdvanceIntoAppendedMarkerParams) => {\n const hasAppendedMarker = nextMarkerCount > previousMarkerCount;\n const wasFocusedOnPreviousLastMarker =\n previousMarkerCount > 0 && previousIndex === previousMarkerCount - 1;\n const hasJustUnlockedNextStep = !previousCanGoNext && nextCanGoNext;\n const isResolvedInteractionStep =\n Boolean(currentInteractionElement) && hasResolvedCurrentInteraction;\n const isCompletedSpeakableStep =\n currentStepHasSpeakableElement && hasCompletedCurrentStepAudio;\n const isSilentStep =\n !currentStepHasSpeakableElement && !currentInteractionElement;\n const shouldAutoAdvanceSilentStep =\n isSilentStep &&\n (!shouldUseSilentStepAutoAdvanceToggle || isAutoAdvanceEnabled);\n\n if (!hasAppendedMarker || !wasFocusedOnPreviousLastMarker) {\n return false;\n }\n\n if (!hasJustUnlockedNextStep || currentAudioKey) {\n return false;\n }\n\n return (\n isResolvedInteractionStep ||\n isCompletedSpeakableStep ||\n shouldAutoAdvanceSilentStep\n );\n};\n"],"names":["shouldAutoAdvanceIntoAppendedMarker","previousMarkerCount","nextMarkerCount","previousIndex","previousCanGoNext","nextCanGoNext","currentAudioKey","hasCompletedCurrentStepAudio","hasResolvedCurrentInteraction","currentStepHasSpeakableElement","currentInteractionElement","isAutoAdvanceEnabled","shouldUseSilentStepAutoAdvanceToggle","hasAppendedMarker","wasFocusedOnPreviousLastMarker","hasJustUnlockedNextStep","isResolvedInteractionStep","isCompletedSpeakableStep","shouldAutoAdvanceSilentStep"],"mappings":"AAiBO,MAAMA,IAAsC,CAAC;AAAA,EAClD,qBAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,eAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,eAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,8BAAAC;AAAA,EACA,+BAAAC;AAAA,EACA,gCAAAC;AAAA,EACA,2BAAAC;AAAA,EACA,sBAAAC;AAAA,EACA,sCAAAC;AACF,MAAiD;AAC/C,QAAMC,IAAoBX,IAAkBD,GACtCa,IACJb,IAAsB,KAAKE,MAAkBF,IAAsB,GAC/Dc,IAA0B,CAACX,KAAqBC,GAChDW,IACJ,EAAQN,KAA8BF,GAClCS,IACJR,KAAkCF,GAG9BW,IADJ,CAACT,KAAkC,CAACC,MAGnC,CAACE,KAAwCD;AAM5C,SAJI,CAACE,KAAqB,CAACC,KAIvB,CAACC,KAA2BT,IACvB,KAIPU,KACAC,KACAC;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=r=>!!(r?.type==="interaction"&&(r.readonly||r.user_input?.trim())),h=(r,a)=>r.length<=a.length&&r.every((n,t)=>n===a[t]),f=({previousIndex:r,previousSlideElementList:a,nextSlideElementList:n})=>{if(n.length===0)return-1;const t=n.length>a.length&&h(a,n),o=a.length-1,c=r===o,e=r>=0?a[r]:void 0;return t&&c&&g(e)?a.length:r>=0&&r<n.length?r:-1};exports.resolveNextSlideIndexAfterMarkerAppend=f;
|
|
2
|
+
//# sourceMappingURL=streamingNavigation.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamingNavigation.cjs.js","sources":["../../../../src/components/Slide/utils/streamingNavigation.ts"],"sourcesContent":["import type { Element } from \"../types\";\n\ninterface ResolveNextSlideIndexParams {\n previousIndex: number;\n previousSlideElementList: Element[];\n nextSlideElementList: Element[];\n}\n\nconst isResolvedInteractionElement = (element?: Element) =>\n Boolean(\n element?.type === \"interaction\" &&\n (element.readonly || element.user_input?.trim())\n );\n\nconst hasStableMarkerPrefix = (\n previousSlideElementList: Element[],\n nextSlideElementList: Element[]\n) =>\n previousSlideElementList.length <= nextSlideElementList.length &&\n previousSlideElementList.every(\n (element, index) => element === nextSlideElementList[index]\n );\n\nexport const resolveNextSlideIndexAfterMarkerAppend = ({\n previousIndex,\n previousSlideElementList,\n nextSlideElementList,\n}: ResolveNextSlideIndexParams) => {\n if (nextSlideElementList.length === 0) {\n return -1;\n }\n\n const hasAppendedMarkers =\n nextSlideElementList.length > previousSlideElementList.length &&\n hasStableMarkerPrefix(previousSlideElementList, nextSlideElementList);\n const previousLastMarkerIndex = previousSlideElementList.length - 1;\n const wasFocusedOnPreviousLastMarker =\n previousIndex === previousLastMarkerIndex;\n const previousCurrentElement =\n previousIndex >= 0 ? previousSlideElementList[previousIndex] : undefined;\n\n // When a resolved interaction is already the terminal step and SSE appends\n // the first follow-up marker, jump into that new marker immediately instead\n // of waiting for the interaction auto-close and silent-step delay.\n if (\n hasAppendedMarkers &&\n wasFocusedOnPreviousLastMarker &&\n isResolvedInteractionElement(previousCurrentElement)\n ) {\n return previousSlideElementList.length;\n }\n\n if (previousIndex >= 0 && previousIndex < nextSlideElementList.length) {\n return previousIndex;\n }\n\n return -1;\n};\n"],"names":["isResolvedInteractionElement","element","hasStableMarkerPrefix","previousSlideElementList","nextSlideElementList","index","resolveNextSlideIndexAfterMarkerAppend","previousIndex","hasAppendedMarkers","previousLastMarkerIndex","wasFocusedOnPreviousLastMarker","previousCurrentElement"],"mappings":"gFAQA,MAAMA,EAAgCC,GACpC,GACEA,GAAS,OAAS,gBACjBA,EAAQ,UAAYA,EAAQ,YAAY,KAAA,IAGvCC,EAAwB,CAC5BC,EACAC,IAEAD,EAAyB,QAAUC,EAAqB,QACxDD,EAAyB,MACvB,CAACF,EAASI,IAAUJ,IAAYG,EAAqBC,CAAK,CAC5D,EAEWC,EAAyC,CAAC,CACrD,cAAAC,EACA,yBAAAJ,EACA,qBAAAC,CACF,IAAmC,CACjC,GAAIA,EAAqB,SAAW,EAClC,MAAO,GAGT,MAAMI,EACJJ,EAAqB,OAASD,EAAyB,QACvDD,EAAsBC,EAA0BC,CAAoB,EAChEK,EAA0BN,EAAyB,OAAS,EAC5DO,EACJH,IAAkBE,EACdE,EACJJ,GAAiB,EAAIJ,EAAyBI,CAAa,EAAI,OAKjE,OACEC,GACAE,GACAV,EAA6BW,CAAsB,EAE5CR,EAAyB,OAG9BI,GAAiB,GAAKA,EAAgBH,EAAqB,OACtDG,EAGF,EACT"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Element } from '../types';
|
|
2
|
+
interface ResolveNextSlideIndexParams {
|
|
3
|
+
previousIndex: number;
|
|
4
|
+
previousSlideElementList: Element[];
|
|
5
|
+
nextSlideElementList: Element[];
|
|
6
|
+
}
|
|
7
|
+
export declare const resolveNextSlideIndexAfterMarkerAppend: ({ previousIndex, previousSlideElementList, nextSlideElementList, }: ResolveNextSlideIndexParams) => number;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const g = (r) => !!(r?.type === "interaction" && (r.readonly || r.user_input?.trim())), f = (r, a) => r.length <= a.length && r.every(
|
|
2
|
+
(n, t) => n === a[t]
|
|
3
|
+
), k = ({
|
|
4
|
+
previousIndex: r,
|
|
5
|
+
previousSlideElementList: a,
|
|
6
|
+
nextSlideElementList: n
|
|
7
|
+
}) => {
|
|
8
|
+
if (n.length === 0)
|
|
9
|
+
return -1;
|
|
10
|
+
const t = n.length > a.length && f(a, n), c = a.length - 1, h = r === c, o = r >= 0 ? a[r] : void 0;
|
|
11
|
+
return t && h && g(o) ? a.length : r >= 0 && r < n.length ? r : -1;
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
k as resolveNextSlideIndexAfterMarkerAppend
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=streamingNavigation.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"streamingNavigation.es.js","sources":["../../../../src/components/Slide/utils/streamingNavigation.ts"],"sourcesContent":["import type { Element } from \"../types\";\n\ninterface ResolveNextSlideIndexParams {\n previousIndex: number;\n previousSlideElementList: Element[];\n nextSlideElementList: Element[];\n}\n\nconst isResolvedInteractionElement = (element?: Element) =>\n Boolean(\n element?.type === \"interaction\" &&\n (element.readonly || element.user_input?.trim())\n );\n\nconst hasStableMarkerPrefix = (\n previousSlideElementList: Element[],\n nextSlideElementList: Element[]\n) =>\n previousSlideElementList.length <= nextSlideElementList.length &&\n previousSlideElementList.every(\n (element, index) => element === nextSlideElementList[index]\n );\n\nexport const resolveNextSlideIndexAfterMarkerAppend = ({\n previousIndex,\n previousSlideElementList,\n nextSlideElementList,\n}: ResolveNextSlideIndexParams) => {\n if (nextSlideElementList.length === 0) {\n return -1;\n }\n\n const hasAppendedMarkers =\n nextSlideElementList.length > previousSlideElementList.length &&\n hasStableMarkerPrefix(previousSlideElementList, nextSlideElementList);\n const previousLastMarkerIndex = previousSlideElementList.length - 1;\n const wasFocusedOnPreviousLastMarker =\n previousIndex === previousLastMarkerIndex;\n const previousCurrentElement =\n previousIndex >= 0 ? previousSlideElementList[previousIndex] : undefined;\n\n // When a resolved interaction is already the terminal step and SSE appends\n // the first follow-up marker, jump into that new marker immediately instead\n // of waiting for the interaction auto-close and silent-step delay.\n if (\n hasAppendedMarkers &&\n wasFocusedOnPreviousLastMarker &&\n isResolvedInteractionElement(previousCurrentElement)\n ) {\n return previousSlideElementList.length;\n }\n\n if (previousIndex >= 0 && previousIndex < nextSlideElementList.length) {\n return previousIndex;\n }\n\n return -1;\n};\n"],"names":["isResolvedInteractionElement","element","hasStableMarkerPrefix","previousSlideElementList","nextSlideElementList","index","resolveNextSlideIndexAfterMarkerAppend","previousIndex","hasAppendedMarkers","previousLastMarkerIndex","wasFocusedOnPreviousLastMarker","previousCurrentElement"],"mappings":"AAQA,MAAMA,IAA+B,CAACC,MACpC,GACEA,GAAS,SAAS,kBACjBA,EAAQ,YAAYA,EAAQ,YAAY,KAAA,KAGvCC,IAAwB,CAC5BC,GACAC,MAEAD,EAAyB,UAAUC,EAAqB,UACxDD,EAAyB;AAAA,EACvB,CAACF,GAASI,MAAUJ,MAAYG,EAAqBC,CAAK;AAC5D,GAEWC,IAAyC,CAAC;AAAA,EACrD,eAAAC;AAAA,EACA,0BAAAJ;AAAA,EACA,sBAAAC;AACF,MAAmC;AACjC,MAAIA,EAAqB,WAAW;AAClC,WAAO;AAGT,QAAMI,IACJJ,EAAqB,SAASD,EAAyB,UACvDD,EAAsBC,GAA0BC,CAAoB,GAChEK,IAA0BN,EAAyB,SAAS,GAC5DO,IACJH,MAAkBE,GACdE,IACJJ,KAAiB,IAAIJ,EAAyBI,CAAa,IAAI;AAKjE,SACEC,KACAE,KACAV,EAA6BW,CAAsB,IAE5CR,EAAyB,SAG9BI,KAAiB,KAAKA,IAAgBH,EAAqB,SACtDG,IAGF;AACT;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -3,12 +3,12 @@ export { default as MarkdownFlow } from './MarkdownFlow';
|
|
|
3
3
|
export { default as ScrollableMarkdown } from './MarkdownFlow/ScrollableMarkdownFlow';
|
|
4
4
|
export { default as MarkdownFlowEditor } from './MarkdownFlowEditor';
|
|
5
5
|
export { default as Slide } from './Slide';
|
|
6
|
-
export { Player, useSlide } from './Slide';
|
|
6
|
+
export { Player, useSlide, SLIDE_ERROR_CODES } from './Slide';
|
|
7
7
|
export { getInteractionDefaultValues, getInteractionDefaultSelectedValues, } from '../lib/interaction-defaults';
|
|
8
8
|
export type { ContentRenderProps } from './ContentRender/ContentRender';
|
|
9
9
|
export type { OnSendContentParams, CustomRenderBarProps } from './types';
|
|
10
10
|
export type { EditMode, UploadProps, ImageResource, } from './MarkdownFlowEditor';
|
|
11
|
-
export type { Element, ElementSubtitleCue, SlideInteractionTexts, SlideProps, } from './Slide';
|
|
11
|
+
export type { Element, ElementSubtitleCue, SlideInteractionTexts, SlideErrorCode, SlideErrorContext, SlideProps, } from './Slide';
|
|
12
12
|
export type { InteractionDefaultResolver, InteractionDefaultResolverParams, InteractionDefaultValueOptions, InteractionDefaultValues, InteractionParseResult, } from '../lib/interaction-defaults';
|
|
13
13
|
export type { PlayerProps } from './Slide';
|
|
14
14
|
export type { UseSlideResult } from './Slide';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../../../_virtual/jsx-runtime.cjs.js"),s=require("react"),u=require("../../../markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.cjs.js");require("../../../_virtual/index.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../../../_virtual/jsx-runtime.cjs.js"),s=require("react"),u=require("../../../markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.cjs.js");require("../../../_virtual/index.cjs4.js");require("../../../markdown-flow-ui/node_modules/.pnpm/rc-resize-observer@1.4.3_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-resize-observer/es/index.cjs.js");require("../../../markdown-flow-ui/node_modules/.pnpm/rc-util@5.44.4_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-util/es/hooks/useLayoutEffect.cjs.js");require("../../../markdown-flow-ui/node_modules/.pnpm/rc-util@5.44.4_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-util/es/raf.cjs.js");const d=require("../../../lib/utils.cjs.js");function c(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const a=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,a.get?a:{enumerable:!0,get:()=>e[r]})}}return t.default=e,Object.freeze(t)}const l=c(s),i=l.forwardRef(({className:e,autoSize:t={minRows:1},style:r,...a},n)=>o.jsxRuntimeExports.jsx(u.default,{ref:n,autoSize:t,className:d.cn("border-input placeholder:text-muted-foreground aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 w-full rounded-md border bg-transparent pl-3 py-1.5 text-base shadow-xs transition-[color,box-shadow] outline-none disabled:cursor-not-allowed disabled:opacity-50","resize-none",e),style:{whiteSpace:"pre-wrap",wordBreak:"break-word",...r},...a}));i.displayName="Textarea";exports.Textarea=i;
|
|
2
2
|
//# sourceMappingURL=textarea.cjs.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { j as i } from "../../../_virtual/jsx-runtime.es.js";
|
|
2
2
|
import * as d from "react";
|
|
3
3
|
import n from "../../../markdown-flow-ui/node_modules/.pnpm/rc-textarea@1.10.2_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-textarea/es/TextArea.es.js";
|
|
4
|
-
import "../../../_virtual/index.
|
|
4
|
+
import "../../../_virtual/index.es4.js";
|
|
5
5
|
import "../../../markdown-flow-ui/node_modules/.pnpm/rc-resize-observer@1.4.3_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-resize-observer/es/index.es.js";
|
|
6
6
|
import "../../../markdown-flow-ui/node_modules/.pnpm/rc-util@5.44.4_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-util/es/hooks/useLayoutEffect.es.js";
|
|
7
7
|
import "../../../markdown-flow-ui/node_modules/.pnpm/rc-util@5.44.4_react-dom@19.0.1_react@19.0.1__react@19.0.1/node_modules/rc-util/es/raf.es.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../../../../../../../_virtual/index.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../../../../../../../_virtual/index.cjs10.js"),v=require("./constants.cjs.js");var d;function x(){if(d)return c.__exports;d=1,Object.defineProperty(c.__exports,"__esModule",{value:!0}),c.__exports.sanitizeUrl=void 0;var e=v.__require();function m(r){return e.relativeFirstCharacters.indexOf(r[0])>-1}function p(r){var i=r.replace(e.ctrlCharactersRegex,"");return i.replace(e.htmlEntitiesRegex,function(t,a){return String.fromCharCode(a)})}function R(r){return URL.canParse(r)}function l(r){try{return decodeURIComponent(r)}catch{return r}}function f(r){if(!r)return e.BLANK_URL;var i,t=l(r.trim());do t=p(t).replace(e.htmlCtrlEntityRegex,"").replace(e.ctrlCharactersRegex,"").replace(e.whitespaceEscapeCharsRegex,"").trim(),t=l(t),i=t.match(e.ctrlCharactersRegex)||t.match(e.htmlEntitiesRegex)||t.match(e.htmlCtrlEntityRegex)||t.match(e.whitespaceEscapeCharsRegex);while(i&&i.length>0);var a=t;if(!a)return e.BLANK_URL;if(m(a))return a;var u=a.trimStart(),h=u.match(e.urlSchemeRegex);if(!h)return a;var n=h[0].toLowerCase().trim();if(e.invalidProtocolRegex.test(n))return e.BLANK_URL;var s=u.replace(/\\/g,"/");if(n==="mailto:"||n.includes("://"))return s;if(n==="http:"||n==="https:"){if(!R(s))return e.BLANK_URL;var o=new URL(s);return o.protocol=o.protocol.toLowerCase(),o.hostname=o.hostname.toLowerCase(),o.toString()}return s}return c.__exports.sanitizeUrl=f,c.__exports}exports.__require=x;
|
|
2
2
|
//# sourceMappingURL=index.cjs.js.map
|