import { TagName } from "@fluid-example/flow-util-lib" ; import { DocSegmentKind } from "../document" ; const segmentKindToIdPrefix = { [ DocSegmentKind . beginTags ] : "b:" , [ DocSegmentKind . endTags ] : "e:" } ; const segmentKindToOppositeIdPrefix = { [ DocSegmentKind . beginTags ] : "e:" , [ DocSegmentKind . endTags ] : "b:" } ; export function createTags ( tags ) { const root = document . createElement ( tags [ 0 ] ) ; let slot = root ; for ( let i = 1 ; i < tags . length ; i ++ ) { slot . appendChild ( document . createElement ( tags [ i ] ) ) ; slot = slot . lastElementChild as HTMLElement ; } return { root , slot } ; } export function addIdPrefix ( kind , id ) { const prefix = segmentKindToIdPrefix [ kind ] ; return prefix ? `${ prefix }${ id }` : id ; } export function removeIdPrefix ( kind , id ) { const prefix = segmentKindToIdPrefix [ kind ] ; return prefix ? id . slice ( prefix . length ) : id ; } export function getIdForOpposite ( kind , id ) { const oldPrefix = segmentKindToIdPrefix [ kind ] ; const newPrefix = segmentKindToOppositeIdPrefix [ kind ] ; return `${ newPrefix }${ id . slice ( oldPrefix . length ) }` ; }