{"version":3,"sources":["../../src/core/section-collection.ts"],"sourcesContent":["import IOSection from \"./section\";\r\n\r\n/**\r\n * IOSectionCollection manages multiple IOSection instances within a document.\r\n *\r\n * Features:\r\n * - Index-based access for ordered sections (collection[0])\r\n * - Name-based access for named sections (collection['users'])\r\n * - Proxy-based access supporting both patterns transparently\r\n * - Iterable for iterating over all sections\r\n *\r\n * @template T The type of data items in the sections\r\n *\r\n * @example\r\n * ```typescript\r\n * const sections = new IOSectionCollection();\r\n * sections.push(new IOSection(users, 'users'));\r\n * sections.push(new IOSection(products, 'products'));\r\n *\r\n * // Access by name\r\n * const usersSection = sections.get('users');\r\n *\r\n * // Access by index\r\n * const firstSection = sections.get(0);\r\n *\r\n * // Iteration\r\n * for (const section of sections) {\r\n *   console.log(section.name);\r\n * }\r\n * ```\r\n */\r\nclass IOSectionCollection<T = any> {\r\n  private _sections: Array<IOSection<T>> = [];\r\n  private _sectionNames: { [key: string]: number } = {};\r\n\r\n  // Support index access\r\n  [key: string]: any;\r\n\r\n  constructor() {\r\n    return new Proxy(this, proxy);\r\n  }\r\n\r\n  public get sections(): Array<IOSection<T>> {\r\n    return this._sections;\r\n  }\r\n\r\n  public get length(): number {\r\n    return this._sections.length;\r\n  }\r\n\r\n  public get(nameOrIndex: string | number): IOSection<T> | undefined {\r\n    if (typeof nameOrIndex === 'string') {\r\n      const index = this._sectionNames[nameOrIndex];\r\n      if (index === undefined) {\r\n        return undefined;\r\n      }\r\n      return this._sections[index];\r\n    }\r\n    return this._sections[nameOrIndex];\r\n  }\r\n\r\n  /**\r\n   * Return a clean object for nodejs console logging.\r\n   */\r\n  [Symbol.for('nodejs.util.inspect.custom')]() {\r\n    return this._sections;\r\n  }\r\n\r\n  public push(section: IOSection<T>) {\r\n    if (section.name !== undefined) {\r\n      this._sectionNames[section.name] = this._sections.length;\r\n    }\r\n    this._sections.push(section);\r\n  }\r\n\r\n  /**\r\n   * Makes the IOSectionCollection iterable, yielding key-value pairs.\r\n   */\r\n  *[Symbol.iterator]() {\r\n    for (const section of this._sections) {\r\n      yield section;\r\n    }\r\n  }\r\n}\r\n\r\nconst proxy = {\r\n  get: (target: IOSectionCollection<any>, property: string | symbol) => {\r\n    if (property in target) {\r\n      return Reflect.get(target, property);\r\n    }\r\n    if (typeof property === 'string') {\r\n      if (/^[0-9]+$/.test(property)) {\r\n        return target.get(Number(property));\r\n      }\r\n      return target.get(property);\r\n    }\r\n  },\r\n  set: (target: IOSectionCollection<any>, property: string | number | symbol, value: any) => {\r\n    throw new Error('Cannot set a value on a IOSectionCollection');\r\n  }\r\n};\r\n\r\nexport default IOSectionCollection;\r\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BA,MAAM,oBAA6B;AAAA,EACzB,YAAiC,CAAC;AAAA,EAClC,gBAA2C,CAAC;AAAA,EAKpD,cAAc;AACZ,WAAO,IAAI,MAAM,MAAM,KAAK;AAAA,EAC9B;AAAA,EAEA,IAAW,WAAgC;AACzC,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,SAAiB;AAC1B,WAAO,KAAK,UAAU;AAAA,EACxB;AAAA,EAEO,IAAI,aAAwD;AACjE,QAAI,OAAO,gBAAgB,UAAU;AACnC,YAAM,QAAQ,KAAK,cAAc,WAAW;AAC5C,UAAI,UAAU,QAAW;AACvB,eAAO;AAAA,MACT;AACA,aAAO,KAAK,UAAU,KAAK;AAAA,IAC7B;AACA,WAAO,KAAK,UAAU,WAAW;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,CAAC,OAAO,IAAI,4BAA4B,CAAC,IAAI;AAC3C,WAAO,KAAK;AAAA,EACd;AAAA,EAEO,KAAK,SAAuB;AACjC,QAAI,QAAQ,SAAS,QAAW;AAC9B,WAAK,cAAc,QAAQ,IAAI,IAAI,KAAK,UAAU;AAAA,IACpD;AACA,SAAK,UAAU,KAAK,OAAO;AAAA,EAC7B;AAAA;AAAA;AAAA;AAAA,EAKA,EAAE,OAAO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