types.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //#SECTION selector exists
  2. export type InitOnSelectorOpts = {
  3. /** Set to true if mutations to any element's attributes are to also trigger the onSelector check (warning: this might draw a lot of performance on larger sites) */
  4. attributes?: boolean;
  5. /** Set to true if mutations to any element's character data are to also trigger the onSelector check (warning: this might draw a lot of performance on larger sites) */
  6. characterData?: boolean;
  7. }
  8. export type OnSelectorOpts<TElem extends Element = HTMLElement> = SelectorOptsOne<TElem> | SelectorOptsAll<TElem>;
  9. type SelectorOptsOne<TElem extends Element> = SelectorOptsBase & {
  10. /** Whether to use `querySelectorAll()` instead - default is false */
  11. all?: false;
  12. /** Gets called whenever the selector was found in the DOM */
  13. listener: (element: TElem) => void;
  14. };
  15. type SelectorOptsAll<TElem extends Element> = SelectorOptsBase & {
  16. /** Whether to use `querySelectorAll()` instead - default is false */
  17. all: true;
  18. /** Gets called whenever the selector was found in the DOM */
  19. listener: (elements: NodeListOf<TElem>) => void;
  20. };
  21. type SelectorOptsBase = {
  22. /** Whether to call the listener continuously instead of once - default is false */
  23. continuous?: boolean;
  24. };
  25. //#SECTION fetch advanced
  26. export type FetchAdvancedOpts = RequestInit & Partial<{
  27. /** Timeout in milliseconds after which the fetch call will be canceled with an AbortController signal */
  28. timeout: number;
  29. }>;