{"version":3,"file":"sdcorejs-angular-services-loading.mjs","sources":["../../../projects/sdcorejs-angular/services/loading/src/loading.service.ts","../../../projects/sdcorejs-angular/services/loading/sdcorejs-angular-services-loading.ts"],"sourcesContent":["import { DOCUMENT, isPlatformBrowser } from '@angular/common';\nimport { DestroyRef, Injectable, PLATFORM_ID, Renderer2, RendererFactory2, inject } from '@angular/core';\n\nexport interface SdLoadingRef {\n  readonly closed: boolean;\n  close(): void;\n}\n\ninterface SdLoadingDocumentRecord {\n  readonly hostStates: WeakMap<Element, SdLoadingHostState>;\n  readonly liveHosts: Set<Element>;\n  style: SdLoadingStyleRecord | undefined;\n}\n\ninterface SdLoadingHostState {\n  readonly overlay: HTMLElement;\n  readonly previousAriaBusy: string | null;\n  readonly contributions: SdLoadingContribution[];\n  count: number;\n}\n\ninterface SdLoadingHandleState {\n  readonly selector: string;\n  readonly contributions: SdLoadingContribution[];\n  closed: boolean;\n}\n\ninterface SdLoadingContribution {\n  readonly host: Element;\n  readonly owner: SdLoadingHandleState;\n  readonly service: SdLoadingService;\n  released: boolean;\n}\n\ninterface SdLoadingStyleRecord {\n  readonly element: HTMLStyleElement;\n  readonly libraryOwned: boolean;\n  readonly owners: Set<SdLoadingService>;\n  ownedText: Text | null;\n}\n\nconst SD_LOADING_STYLE_ATTRIBUTE = 'data-sd-loading-styles';\nconst SD_LOADING_STYLES = `\n.sd-loading {\n  position: absolute;\n  inset: 0;\n  width: 100%;\n  height: 100%;\n  opacity: 0.6;\n  background: #fff;\n  z-index: 99999;\n}\n\n.sd-loading-spinner {\n  position: absolute;\n  top: calc(50% - 2.5rem);\n  left: calc(50% - 2.5rem);\n  width: 5rem;\n  height: 5rem;\n  border: 0.5rem solid var(--sd-primary);\n  border-top-color: var(--sd-border);\n  border-radius: 50%;\n  animation: sd-loading-spin 1s linear infinite;\n}\n\n@keyframes sd-loading-spin {\n  from { transform: rotate(0deg); }\n  to { transform: rotate(360deg); }\n}\n`;\n\nconst CLOSED_LOADING_REF: SdLoadingRef = Object.freeze({\n  closed: true,\n  close(): void {\n    // A closed ref deliberately has no work to release.\n  },\n});\n\n@Injectable({\n  providedIn: 'root',\n})\nexport class SdLoadingService {\n  private static readonly documentRecords = new WeakMap<Document, SdLoadingDocumentRecord>();\n\n  readonly #document: Document;\n  readonly #renderer: Renderer2 | null;\n  readonly #isBrowser: boolean;\n  readonly #destroyRef = inject(DestroyRef);\n  readonly #handleQueue: SdLoadingHandleState[] = [];\n\n  #styleRegistered = false;\n  #destroyed = false;\n\n  /** Inserted by Angular inject() migration for backwards compatibility. */\n  constructor(...args: unknown[]);\n  constructor() {\n    this.#document = inject(DOCUMENT);\n    this.#isBrowser = isPlatformBrowser(inject(PLATFORM_ID));\n\n    const rendererFactory = inject(RendererFactory2);\n    this.#renderer = this.#isBrowser ? rendererFactory.createRenderer(null, null) : null;\n    this.#destroyRef.onDestroy(() => this.#destroy());\n  }\n\n  /** Starts loading for every current selector match and returns ownership of those exact hosts. */\n  start = (selector = 'body'): SdLoadingRef => {\n    const renderer = this.#renderer;\n    if (this.#destroyed || !this.#isBrowser || !renderer) return CLOSED_LOADING_REF;\n\n    const hosts = Array.from(this.#document.querySelectorAll(selector));\n    if (hosts.length === 0) return CLOSED_LOADING_REF;\n\n    const documentRecord = this.#getOrCreateDocumentRecord();\n    this.#ensureStyles(documentRecord, renderer);\n    const state: SdLoadingHandleState = { selector, contributions: [], closed: false };\n    for (const host of hosts) {\n      const contribution: SdLoadingContribution = {\n        host,\n        owner: state,\n        service: this,\n        released: false,\n      };\n      state.contributions.push(contribution);\n      this.#acquireHost(documentRecord, contribution, renderer);\n    }\n    this.#handleQueue.push(state);\n\n    return {\n      get closed(): boolean {\n        return state.closed;\n      },\n      close: () => this.#closeHandle(state, renderer),\n    };\n  };\n\n  /** Returns the first matched globally loading host, `false` for idle matches, or `null` when unavailable. */\n  isLoading = (selector = 'body'): Element | false | null => {\n    if (this.#destroyed || !this.#isBrowser) return null;\n\n    const hosts = this.#document.querySelectorAll(selector);\n    if (hosts.length === 0) return null;\n\n    const documentRecord = SdLoadingService.documentRecords.get(this.#document);\n    for (const host of Array.from(hosts)) {\n      const state = documentRecord?.hostStates.get(host);\n      if (state && state.count > 0 && state.overlay.parentNode === host) return host;\n    }\n    return false;\n  };\n\n  /** Releases the oldest exact-selector start, with a current-host fallback for legacy cross-selector calls. */\n  stop = (selector = 'body'): void => {\n    const renderer = this.#renderer;\n    if (this.#destroyed || !this.#isBrowser || !renderer) return;\n\n    const exactHandle = this.#handleQueue.find(state => !state.closed && state.selector === selector);\n    if (exactHandle) {\n      this.#closeHandle(exactHandle, renderer);\n      return;\n    }\n\n    const documentRecord = SdLoadingService.documentRecords.get(this.#document);\n    if (!documentRecord) return;\n\n    for (const host of Array.from(this.#document.querySelectorAll(selector))) {\n      const contribution = documentRecord.hostStates\n        .get(host)\n        ?.contributions.find(candidate => !candidate.released && candidate.service === this);\n      if (contribution) this.#releaseContribution(documentRecord, contribution, renderer);\n    }\n  };\n\n  run<T>(task: () => T | PromiseLike<T>, selector?: string): Promise<T>;\n  run<T>(task: PromiseLike<T>, selector?: string): Promise<T>;\n  /** Runs a task inside a loading lifetime and always releases it without replacing the task result or error. */\n  async run<T>(task: (() => T | PromiseLike<T>) | PromiseLike<T>, selector = 'body'): Promise<T> {\n    const ref = this.start(selector);\n    try {\n      const result = typeof task === 'function' ? task() : task;\n      return await result;\n    } finally {\n      ref.close();\n    }\n  }\n\n  #getOrCreateDocumentRecord(): SdLoadingDocumentRecord {\n    let record = SdLoadingService.documentRecords.get(this.#document);\n    if (!record) {\n      record = {\n        hostStates: new WeakMap<Element, SdLoadingHostState>(),\n        liveHosts: new Set<Element>(),\n        style: undefined,\n      };\n      SdLoadingService.documentRecords.set(this.#document, record);\n    }\n    return record;\n  }\n\n  #acquireHost(documentRecord: SdLoadingDocumentRecord, contribution: SdLoadingContribution, renderer: Renderer2): void {\n    const host = contribution.host;\n    const existing = documentRecord.hostStates.get(host);\n    if (existing) {\n      this.#repairOverlay(host, existing, renderer);\n      existing.count += 1;\n      existing.contributions.push(contribution);\n      return;\n    }\n\n    const state: SdLoadingHostState = {\n      overlay: this.#createOverlay(renderer),\n      previousAriaBusy: host.getAttribute('aria-busy'),\n      contributions: [contribution],\n      count: 1,\n    };\n    renderer.setAttribute(host, 'aria-busy', 'true');\n    renderer.appendChild(host, state.overlay);\n    documentRecord.hostStates.set(host, state);\n    documentRecord.liveHosts.add(host);\n  }\n\n  #repairOverlay(host: Element, state: SdLoadingHostState, renderer: Renderer2): void {\n    const currentParent = state.overlay.parentNode;\n    if (currentParent !== host) {\n      if (currentParent) renderer.removeChild(currentParent, state.overlay);\n      renderer.appendChild(host, state.overlay);\n    }\n    if (host.getAttribute('aria-busy') !== 'true') renderer.setAttribute(host, 'aria-busy', 'true');\n  }\n\n  #releaseContribution(documentRecord: SdLoadingDocumentRecord, contribution: SdLoadingContribution, renderer: Renderer2): void {\n    if (contribution.released) return;\n    contribution.released = true;\n\n    const state = documentRecord.hostStates.get(contribution.host);\n    if (state) {\n      const contributionIndex = state.contributions.indexOf(contribution);\n      if (contributionIndex >= 0) state.contributions.splice(contributionIndex, 1);\n      state.count -= 1;\n\n      if (state.count <= 0) this.#removeHost(documentRecord, contribution.host, state, renderer);\n    }\n\n    contribution.service.#closeOwnerWhenReleased(contribution.owner);\n  }\n\n  #removeHost(documentRecord: SdLoadingDocumentRecord, host: Element, state: SdLoadingHostState, renderer: Renderer2): void {\n    const parent = state.overlay.parentNode;\n    if (parent) renderer.removeChild(parent, state.overlay);\n\n    if (host.getAttribute('aria-busy') === 'true') {\n      if (state.previousAriaBusy === null) renderer.removeAttribute(host, 'aria-busy');\n      else renderer.setAttribute(host, 'aria-busy', state.previousAriaBusy);\n    }\n\n    documentRecord.hostStates.delete(host);\n    documentRecord.liveHosts.delete(host);\n    this.#deleteDocumentRecordWhenEmpty(documentRecord);\n  }\n\n  #closeHandle(state: SdLoadingHandleState, renderer: Renderer2): void {\n    if (state.closed) return;\n\n    state.closed = true;\n    this.#dequeueHandle(state);\n    const documentRecord = SdLoadingService.documentRecords.get(this.#document);\n    if (documentRecord) {\n      for (const contribution of [...state.contributions]) {\n        this.#releaseContribution(documentRecord, contribution, renderer);\n      }\n    } else {\n      for (const contribution of state.contributions) contribution.released = true;\n    }\n    state.contributions.length = 0;\n  }\n\n  #closeOwnerWhenReleased(state: SdLoadingHandleState): void {\n    if (state.closed || state.contributions.some(contribution => !contribution.released)) return;\n\n    state.closed = true;\n    this.#dequeueHandle(state);\n    state.contributions.length = 0;\n  }\n\n  #dequeueHandle(state: SdLoadingHandleState): void {\n    const handleIndex = this.#handleQueue.indexOf(state);\n    if (handleIndex >= 0) this.#handleQueue.splice(handleIndex, 1);\n  }\n\n  #createOverlay(renderer: Renderer2): HTMLElement {\n    const container: HTMLElement = renderer.createElement('div');\n    const spinner: HTMLElement = renderer.createElement('div');\n\n    renderer.addClass(container, 'sd-loading');\n    renderer.setAttribute(container, 'role', 'status');\n    renderer.setAttribute(container, 'aria-live', 'polite');\n    renderer.setAttribute(container, 'aria-label', 'Loading');\n\n    renderer.addClass(spinner, 'sd-loading-spinner');\n    renderer.setAttribute(spinner, 'aria-hidden', 'true');\n    renderer.appendChild(container, spinner);\n    return container;\n  }\n\n  #ensureStyles(documentRecord: SdLoadingDocumentRecord, renderer: Renderer2): void {\n    let record = documentRecord.style;\n    if (record && !this.#isCurrentStyle(record.element)) {\n      const owners = record.owners;\n      this.#detachOwnedStyleContent(record, renderer);\n      record = this.#createStyleRecord(renderer, owners);\n      documentRecord.style = record;\n    } else if (!record) {\n      record = this.#createStyleRecord(renderer, new Set<SdLoadingService>());\n      documentRecord.style = record;\n    } else {\n      this.#ensureRequiredStyleText(record, renderer);\n    }\n\n    record.owners.add(this);\n    this.#styleRegistered = true;\n  }\n\n  #isCurrentStyle(element: HTMLStyleElement): boolean {\n    return element.isConnected && element.parentNode === this.#document.head && element.hasAttribute(SD_LOADING_STYLE_ATTRIBUTE);\n  }\n\n  #createStyleRecord(renderer: Renderer2, owners: Set<SdLoadingService>): SdLoadingStyleRecord {\n    const existing = this.#document.head.querySelector<HTMLStyleElement>(`style[${SD_LOADING_STYLE_ATTRIBUTE}]`);\n    if (existing) {\n      const record: SdLoadingStyleRecord = {\n        element: existing,\n        libraryOwned: false,\n        owners,\n        ownedText: null,\n      };\n      this.#ensureRequiredStyleText(record, renderer);\n      return record;\n    }\n\n    const style: HTMLStyleElement = renderer.createElement('style');\n    const ownedText: Text = renderer.createText(SD_LOADING_STYLES);\n    renderer.setAttribute(style, SD_LOADING_STYLE_ATTRIBUTE, '');\n    renderer.appendChild(style, ownedText);\n    renderer.appendChild(this.#document.head, style);\n    return { element: style, libraryOwned: true, owners, ownedText };\n  }\n\n  #ensureRequiredStyleText(record: SdLoadingStyleRecord, renderer: Renderer2): void {\n    const currentText = record.element.textContent ?? '';\n    const hasRequiredRules =\n      currentText.includes('.sd-loading {') &&\n      currentText.includes('.sd-loading-spinner') &&\n      currentText.includes('@keyframes sd-loading-spin');\n    if (hasRequiredRules) return;\n\n    if (record.ownedText && record.ownedText.parentNode !== record.element) record.ownedText = null;\n    if (!record.ownedText) {\n      record.ownedText = renderer.createText(SD_LOADING_STYLES);\n      renderer.appendChild(record.element, record.ownedText);\n    }\n  }\n\n  #detachOwnedStyleContent(record: SdLoadingStyleRecord, renderer: Renderer2): void {\n    if (record.libraryOwned) {\n      const parent = record.element.parentNode;\n      if (parent) renderer.removeChild(parent, record.element);\n    } else if (record.ownedText) {\n      const textParent = record.ownedText.parentNode;\n      if (textParent) renderer.removeChild(textParent, record.ownedText);\n    }\n    record.ownedText = null;\n  }\n\n  #destroy(): void {\n    if (this.#destroyed) return;\n    this.#destroyed = true;\n\n    const renderer = this.#renderer;\n    if (renderer) {\n      for (const state of [...this.#handleQueue]) this.#closeHandle(state, renderer);\n      this.#unregisterStyles(renderer);\n    } else {\n      for (const state of this.#handleQueue) {\n        state.closed = true;\n        state.contributions.length = 0;\n      }\n      this.#handleQueue.length = 0;\n    }\n  }\n\n  #unregisterStyles(renderer: Renderer2): void {\n    if (!this.#styleRegistered) return;\n    this.#styleRegistered = false;\n\n    const documentRecord = SdLoadingService.documentRecords.get(this.#document);\n    const record = documentRecord?.style;\n    if (!documentRecord || !record) return;\n\n    record.owners.delete(this);\n    if (record.owners.size === 0) {\n      this.#detachOwnedStyleContent(record, renderer);\n      documentRecord.style = undefined;\n    }\n    this.#deleteDocumentRecordWhenEmpty(documentRecord);\n  }\n\n  #deleteDocumentRecordWhenEmpty(documentRecord: SdLoadingDocumentRecord): void {\n    if (documentRecord.liveHosts.size === 0 && !documentRecord.style) {\n      SdLoadingService.documentRecords.delete(this.#document);\n    }\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAyCA,MAAM,0BAA0B,GAAG,wBAAwB;AAC3D,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BzB;AAED,MAAM,kBAAkB,GAAiB,MAAM,CAAC,MAAM,CAAC;AACrD,IAAA,MAAM,EAAE,IAAI;IACZ,KAAK,GAAA;;IAEL,CAAC;AACF,CAAA,CAAC;MAKW,gBAAgB,CAAA;AACnB,IAAA,OAAgB,eAAe,GAAG,IAAI,OAAO,EAAqC;AAEjF,IAAA,SAAS;AACT,IAAA,SAAS;AACT,IAAA,UAAU;AACV,IAAA,WAAW,GAAG,MAAM,CAAC,UAAU,CAAC;IAChC,YAAY,GAA2B,EAAE;IAElD,gBAAgB,GAAG,KAAK;IACxB,UAAU,GAAG,KAAK;AAIlB,IAAA,WAAA,GAAA;AACE,QAAA,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,iBAAiB,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAExD,QAAA,MAAM,eAAe,GAAG,MAAM,CAAC,gBAAgB,CAAC;QAChD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,GA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