{"version":3,"file":"runtime.mjs","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","collectSubjectElements","root","Array","from","querySelectorAll","validateSubjectElements","elements","errors","element","validate","nextErrors","isArray","length","push","valid","async","serializeSubjectElements","results","toJSON","error","SubjectError","message","serializeSubjectsWithPageIndex"],"mappings":"oHAGaA,EAA2B,CACtC,qBACA,iBACA,gBACA,YACA,gBACAC,KAAK,MAOA,SAASC,EAAuBC,GACrC,OAAOC,MAAMC,KAAKF,EAAKG,iBAAiCN,GAC1D,CAEO,SAASO,EAAwBC,GACtC,MAAMC,EAAyB,GAE/B,IAAA,MAAWC,KAAWF,EAAU,CAC9B,GAAgC,mBAArBE,EAAQC,SACjB,SAEF,MAAMC,EAAaF,EAAQC,WACvBP,MAAMS,QAAQD,IAAeA,EAAWE,QAC1CL,EAAOM,QAAQH,EAEnB,CAEA,MAAO,CACLI,MAAyB,IAAlBP,EAAOK,OACdL,SAEJ,CAEAQ,eAAsBC,EAAyBV,GAC7C,MAAMW,EAAiB,GACjBV,EAAyB,GAE/B,IAAA,MAAWC,KAAWF,EACpB,GAA8B,mBAAnBE,EAAQU,OAGnB,IACED,EAAQJ,WAAWL,EAAQU,SAC7B,OACOC,GACDA,aAAiBC,EACnBb,EAAOM,KAAKM,GAGZZ,EAAOM,KAAK,IAAIO,EAAaD,GAAOE,SAAW,OAAQ,UAAW,WAEtE,CAGF,GAAId,EAAOK,OACT,MAAML,EAGR,OAAOe,EAA+BL,EACxC"}