{"version":3,"file":"runtime.cjs","sources":["../../../../packages/components-wc/src/subject/runtime.ts"],"sourcesContent":["import { serializeSubjectsWithPageIndex } from './pagination'\nimport { SubjectError } from './single'\n\nexport const SUBJECT_ELEMENT_SELECTOR = [\n  'qxs-subject-single',\n  'qxs-blank-fill',\n  'qxs-text-fill',\n  'qxs-scale',\n  'qxs-page-end',\n].join(', ')\n\nexport type SubjectElement = HTMLElement & {\n  toJSON?: () => Promise<any>\n  validate?: () => SubjectError[]\n}\n\nexport function collectSubjectElements(root: ParentNode): SubjectElement[] {\n  return Array.from(root.querySelectorAll<SubjectElement>(SUBJECT_ELEMENT_SELECTOR))\n}\n\nexport function validateSubjectElements(elements: Iterable<SubjectElement>): { valid: boolean, errors: SubjectError[] } {\n  const errors: SubjectError[] = []\n\n  for (const element of elements) {\n    if (typeof element.validate !== 'function') {\n      continue\n    }\n    const nextErrors = element.validate()\n    if (Array.isArray(nextErrors) && nextErrors.length) {\n      errors.push(...nextErrors)\n    }\n  }\n\n  return {\n    valid: errors.length === 0,\n    errors,\n  }\n}\n\nexport async function serializeSubjectElements(elements: Iterable<SubjectElement>): Promise<any[]> {\n  const results: any[] = []\n  const errors: SubjectError[] = []\n\n  for (const element of elements) {\n    if (typeof element.toJSON !== 'function') {\n      continue\n    }\n    try {\n      results.push(await element.toJSON())\n    }\n    catch (error: any) {\n      if (error instanceof SubjectError) {\n        errors.push(error)\n      }\n      else {\n        errors.push(new SubjectError(error?.message || '未知错误', 'UNKNOWN', 'unknown'))\n      }\n    }\n  }\n\n  if (errors.length) {\n    throw errors\n  }\n\n  return serializeSubjectsWithPageIndex(results)\n}\n"],"names":["SUBJECT_ELEMENT_SELECTOR","join","root","Array","from","querySelectorAll","async","elements","results","errors","element","toJSON","push","error","SubjectError","message","length","serializeSubjectsWithPageIndex","validate","nextErrors","isArray","valid"],"mappings":"+EAGaA,EAA2B,CACtC,qBACA,iBACA,gBACA,YACA,gBACAC,KAAK,wEAOA,SAAgCC,GACrC,OAAOC,MAAMC,KAAKF,EAAKG,iBAAiCL,GAC1D,mCAqBAM,eAA+CC,GAC7C,MAAMC,EAAiB,GACjBC,EAAyB,GAE/B,IAAA,MAAWC,KAAWH,EACpB,GAA8B,mBAAnBG,EAAQC,OAGnB,IACEH,EAAQI,WAAWF,EAAQC,SAC7B,OACOE,GACDA,aAAiBC,EAAAA,aACnBL,EAAOG,KAAKC,GAGZJ,EAAOG,KAAK,IAAIE,eAAaD,GAAOE,SAAW,OAAQ,UAAW,WAEtE,CAGF,GAAIN,EAAOO,OACT,MAAMP,EAGR,OAAOQ,EAAAA,+BAA+BT,EACxC,kCA7CO,SAAiCD,GACtC,MAAME,EAAyB,GAE/B,IAAA,MAAWC,KAAWH,EAAU,CAC9B,GAAgC,mBAArBG,EAAQQ,SACjB,SAEF,MAAMC,EAAaT,EAAQQ,WACvBf,MAAMiB,QAAQD,IAAeA,EAAWH,QAC1CP,EAAOG,QAAQO,EAEnB,CAEA,MAAO,CACLE,MAAyB,IAAlBZ,EAAOO,OACdP,SAEJ"}