{
  "version": 3,
  "sources": ["../src/index.ts", "../src/Parser.SunoParser.ts"],
  "sourcesContent": ["export * from \"./Parser.SunoParser\";\n", "import { Lyric, type LyricCreateArgs, type WordTimeline } from \"@ioris/core\";\n\nexport type SunoChar = {\n  word: string;\n  start_s: number;\n  end_s: number;\n  success: boolean;\n  p_align: number;\n};\n\ntype sunoChar = SunoChar & {\n  hasWhitespace: boolean;\n  hasNewline: boolean;\n};\n\ntype sunoWord = sunoChar[];\ntype sunoLine = sunoWord[];\ntype sunoParagraph = sunoLine[];\n\nfunction parseLineTimelines(line: sunoLine) {\n  const wordTimelines = [];\n\n  for (const word of Array.from(line)) {\n    if (!word.length) {\n      continue;\n    }\n    const { wordTimeline } = parseWordTimelines(word);\n    wordTimelines.push(wordTimeline);\n  }\n\n  return {\n    wordTimelines,\n  };\n}\n\nfunction parseWordTimelines(word: sunoWord) {\n  const joinedText = word.reduce<string>(\n    (acc, char) => `${acc}${char.hasWhitespace ? `${char.word} ` : char.word}`,\n    \"\",\n  );\n  const text = joinedText\n    // \u8907\u6570\u884C\u306B\u307E\u305F\u304C\u308B\u62EC\u5F27\u3067\u56F2\u307E\u308C\u305F\u90E8\u5206\u3092\u524A\u9664\n    .replace(/\u3010[\\s\\S]*?\u3011/g, \"\")\n    .replace(/\\[[\\s\\S]*?\\]/g, \"\")\n    .replace(/\\([\\s\\S]*?\\)/g, \"\")\n    .replace(/\uFF08[\\s\\S]*?\uFF09/g, \"\")\n    // \u8907\u6570\u306E\u7A7A\u767D\u30921\u3064\u306B\u307E\u3068\u3081\u308B\n    .replace(/[^\\S\\r\\n]+/g, \" \")\n    .trim();\n  const wordTimeline: WordTimeline = {\n    wordID: crypto.randomUUID(),\n    begin: word[0].start_s,\n    end: word[word.length - 1].end_s,\n    hasNewLine: word.reduce<boolean>(\n      (acc, char) => acc || char.hasNewline,\n      false,\n    ),\n    hasWhitespace: word.reduce<boolean>(\n      (acc, char) => acc || char.hasWhitespace,\n      false,\n    ),\n    text,\n  };\n  return { wordTimeline };\n}\n\nfunction parseParagraphTimelines(paragraph: sunoParagraph) {\n  const lineTimelines = [];\n\n  for (const line of Array.from(paragraph)) {\n    const { wordTimelines } = parseLineTimelines(line);\n    lineTimelines.push(wordTimelines);\n  }\n\n  return {\n    lineTimelines,\n  };\n}\n\nexport function SunoCharsToLyricCreateArgs(chars: SunoChar[]) {\n  const timelines = [];\n  const paragraphs = chars.reduce<sunoParagraph[]>(\n    (acc, char, index) => {\n      const newChar = { ...char, hasWhitespace: false, hasNewline: false };\n      const nextChar = chars[index + 1];\n\n      const lastParagraphIndex = acc.length ? acc.length - 1 : 0;\n      const lastLineIndex = acc[lastParagraphIndex].length\n        ? acc[lastParagraphIndex].length - 1\n        : 0;\n      const lastWordIndex = acc[lastParagraphIndex][lastLineIndex].length\n        ? acc[lastParagraphIndex][lastLineIndex].length - 1\n        : 0;\n\n      //[]\u3067\u56F2\u307E\u308C\u305F\u90E8\u5206\u304C\u5B58\u5728\u3059\u308B\u304B\u30C1\u30A7\u30C3\u30AF\n      const hasBrackets =\n        newChar.word.match(/\u3010[\\s\\S]*?\u3011/g) ||\n        newChar.word.match(/\\[[\\s\\S]*?\\]/g) ||\n        newChar.word.match(/\\([\\s\\S]*?\\)/g) ||\n        newChar.word.match(/\uFF08[\\s\\S]*?\uFF09/g);\n      if (hasBrackets) {\n        newChar.word = newChar.word.replace(/\u3010[\\s\\S]*?\u3011/g, \"\");\n        newChar.word = newChar.word.replace(/\\[[\\s\\S]*?\\]/g, \"\");\n        newChar.word = newChar.word.replace(/\\([\\s\\S]*?\\)/g, \"\");\n        acc.push([[[]]]);\n      }\n\n      if (newChar.word.startsWith(\"\\n\")) {\n        // \u76F4\u524D\u306E\u3082\u306E\u306EhasNewline\u3092true\u306B\u3059\u308B\n        if (acc[lastParagraphIndex][lastLineIndex][lastWordIndex]) {\n          acc[lastParagraphIndex][lastLineIndex][lastWordIndex].findLast(\n            (word) => {\n              word.hasNewline = true;\n              return true;\n            },\n          );\n        }\n        newChar.word = newChar.word.replaceAll(\"\\n\", \"\");\n        acc[acc.length - 1].push([[newChar]]);\n        return acc;\n      }\n      if (newChar.word.endsWith(\"\\n\\n\")) {\n        nextChar ? acc.push([[[]]]) : null;\n        newChar.word = newChar.word.slice(0, -2);\n      }\n      if (newChar.word.endsWith(\"\\n\")) {\n        nextChar ? acc[acc.length - 1].push([[]]) : null;\n        newChar.word = newChar.word.slice(0, -1);\n        newChar.hasNewline = true;\n      }\n      if (newChar.word.endsWith(\"\u3000\")) {\n        newChar.word = newChar.word.slice(0, -1);\n        newChar.hasNewline = true;\n      }\n      if (newChar.word.endsWith(\" \")) {\n        newChar.word = newChar.word.slice(0, -1);\n        newChar.hasWhitespace = true;\n      }\n\n      acc[lastParagraphIndex][lastLineIndex][lastWordIndex].push(newChar);\n\n      return acc;\n    },\n    [[[[]]]],\n  );\n\n  for (const paragraph of Array.from(paragraphs)) {\n    const { lineTimelines } = parseParagraphTimelines(paragraph);\n    timelines.push(lineTimelines);\n  }\n\n  return timelines;\n}\n\nexport class SunoParser {\n  lineTokenizer?: LyricCreateArgs[\"lineTokenizer\"];\n  paragraphTokenizer?: LyricCreateArgs[\"paragraphTokenizer\"];\n  offsetSec?: number;\n\n  constructor(props?: {\n    lineTokenizer?: LyricCreateArgs[\"lineTokenizer\"];\n    paragraphTokenizer?: LyricCreateArgs[\"paragraphTokenizer\"];\n    offsetSec?: number;\n  }) {\n    this.lineTokenizer = props ? props.lineTokenizer : undefined;\n    this.paragraphTokenizer = props ? props.paragraphTokenizer : undefined;\n    this.offsetSec = props ? props.offsetSec : undefined;\n  }\n\n  public async parse(chars: SunoChar[], resourceID: string) {\n    const timelines = SunoCharsToLyricCreateArgs(chars);\n    const lyric = await new Lyric({\n      resourceID,\n      duration: 0,\n      timelines,\n      lineTokenizer: this.lineTokenizer,\n      paragraphTokenizer: this.paragraphTokenizer,\n      offsetSec: this.offsetSec,\n    }).init();\n\n    return lyric;\n  }\n}\n\nexport default SunoParser;\n"],
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EAAE,GAErCA,EAAQ,KAAK,SAAS;AAAA,CAAI,IAC5BC,GAAWX,EAAIA,EAAI,OAAS,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,EACxCU,EAAQ,KAAOA,EAAQ,KAAK,MAAM,EAAG,EAAE,EACvCA,EAAQ,WAAa,IAEnBA,EAAQ,KAAK,SAAS,QAAG,IAC3BA,EAAQ,KAAOA,EAAQ,KAAK,MAAM,EAAG,EAAE,EACvCA,EAAQ,WAAa,IAEnBA,EAAQ,KAAK,SAAS,GAAG,IAC3BA,EAAQ,KAAOA,EAAQ,KAAK,MAAM,EAAG,EAAE,EACvCA,EAAQ,cAAgB,IAG1BV,EAAIY,CAAkB,EAAEC,CAAa,EAAEC,CAAa,EAAE,KAAKJ,CAAO,EAE3DV,EACT,EACA,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CACT,EAEA,QAAWG,KAAa,MAAM,KAAKK,CAAU,EAAG,CAC9C,GAAM,CAAE,cAAAJ,CAAc,EAAIF,EAAwBC,CAAS,EAC3DI,EAAU,KAAKH,CAAa,CAC9B,CAEA,OAAOG,CACT,CAEO,IAAMQ,EAAN,KAAiB,CACtB,cACA,mBACA,UAEA,YAAYC,EAIT,CACD,KAAK,cAAgBA,EAAQA,EAAM,cAAgB,OACnD,KAAK,mBAAqBA,EAAQA,EAAM,mBAAqB,OAC7D,KAAK,UAAYA,EAAQA,EAAM,UAAY,MAC7C,CAEA,MAAa,MAAMV,EAAmBW,EAAoB,CACxD,IAAMV,EAAYF,EAA2BC,CAAK,EAUlD,OATc,MAAM,IAAI,QAAM,CAC5B,WAAAW,EACA,SAAU,EACV,UAAAV,EACA,cAAe,KAAK,cACpB,mBAAoB,KAAK,mBACzB,UAAW,KAAK,SAClB,CAAC,EAAE,KAAK,CAGV,CACF",
  "names": ["index_exports", "__export", "SunoCharsToLyricCreateArgs", "SunoParser", "__toCommonJS", "import_core", "parseLineTimelines", "line", "wordTimelines", "word", "wordTimeline", "parseWordTimelines", "text", "acc", "char", "parseParagraphTimelines", "paragraph", "lineTimelines", "SunoCharsToLyricCreateArgs", "chars", "timelines", "paragraphs", "index", "newChar", "nextChar", "lastParagraphIndex", "lastLineIndex", "lastWordIndex", "SunoParser", "props", "resourceID"]
}
