{"version":3,"sources":["../../../../src/transpiler/insertion/insertion.ts"],"sourcesContent":["import {\n  formatNodeType,\n  NodeType,\n  type TypedNodeModel,\n} from '../../types/index';\nimport { getInsertionValues } from './getInsertionValues';\n\nexport type InsertionContentConstructor<\n  Content = unknown,\n  T extends Record<string, any> = {},\n> = TypedNodeModel<NodeType.Insertion, Content, T>;\n\nexport type InsertionContent<Content = unknown> = InsertionContentConstructor<\n  Content,\n  {\n    fields: string[];\n  }\n>;\n\n/**\n * Function intended to be used to build intlayer dictionaries.\n *\n * Allow to identify insertions inside a content.\n *\n * Usage:\n *\n * ```ts\n * insertion('Hi, my name is {{name}} and I am {{age}} years old.')\n * ```\n *\n */\nconst insertion = <Content = unknown>(\n  content: Content\n): InsertionContent<Content> => {\n  const getInsertions = () => {\n    if (typeof content === 'string') {\n      return getInsertionValues(content);\n    }\n\n    let stringContent = undefined;\n\n    if (typeof content === 'function') {\n      stringContent = content();\n    } else if (typeof (content as Promise<string>).then === 'function') {\n      stringContent = async () =>\n        getInsertionValues(await (content as Promise<string>));\n    }\n\n    if (typeof stringContent === 'string') {\n      return getInsertionValues(stringContent);\n    }\n\n    try {\n      return getInsertionValues(JSON.stringify(content));\n    } catch (e) {\n      return [];\n    }\n  };\n\n  return formatNodeType(NodeType.Insertion, content, {\n    fields: getInsertions(),\n  });\n};\n\nexport { insertion as insert };\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAIO;AACP,gCAAmC;AA0BnC,MAAM,YAAY,CAChB,YAC8B;AAC9B,QAAM,gBAAgB,MAAM;AAC1B,QAAI,OAAO,YAAY,UAAU;AAC/B,iBAAO,8CAAmB,OAAO;AAAA,IACnC;AAEA,QAAI,gBAAgB;AAEpB,QAAI,OAAO,YAAY,YAAY;AACjC,sBAAgB,QAAQ;AAAA,IAC1B,WAAW,OAAQ,QAA4B,SAAS,YAAY;AAClE,sBAAgB,gBACd,8CAAmB,MAAO,OAA2B;AAAA,IACzD;AAEA,QAAI,OAAO,kBAAkB,UAAU;AACrC,iBAAO,8CAAmB,aAAa;AAAA,IACzC;AAEA,QAAI;AACF,iBAAO,8CAAmB,KAAK,UAAU,OAAO,CAAC;AAAA,IACnD,SAAS,GAAG;AACV,aAAO,CAAC;AAAA,IACV;AAAA,EACF;AAEA,aAAO,6BAAe,sBAAS,WAAW,SAAS;AAAA,IACjD,QAAQ,cAAc;AAAA,EACxB,CAAC;AACH;","names":[]}