{"version":3,"file":"patron-web-api.min.mjs","sources":["../src/history-api/HistoryPoppedPage.ts","../src/history-api/HistoryNewPage.ts","../src/fetch/Fetched.ts","../src/dom/Element.ts","../src/dom/Attribute.ts","../src/dom/StyleInstalled.ts","../src/console/Log.ts"],"sourcesContent":["import { give, GuestType } from \"patron-oop\";\n\nexport class HistoryPoppedPage {\n  public constructor(private pageSource: GuestType<string>) {}\n\n  public watchPop() {\n    window.addEventListener(\"popstate\", (event) => {\n      const { state } = event;\n      if (state?.url) {\n        give(state.url, this.pageSource);\n      }\n    });\n  }\n}\n","import { GuestObjectType } from \"patron-oop\";\n\nexport class HistoryNewPage implements GuestObjectType<string> {\n  public give(url: string) {\n    const correctUrl = location.href.replace(location.origin, \"\");\n    if (url === correctUrl) {\n      return this;\n    }\n    history.pushState(\n      {\n        url,\n        date: Date.now(),\n      },\n      \"Loading...\",\n      url,\n    );\n    return this;\n  }\n}\n","import { Guest, SourceWithPool } from \"patron-oop\";\n\ninterface FetchRequestType extends RequestInit {\n  url: string;\n  asJson: boolean;\n}\n\n/**\n * Wrapper around FetchAPI\n * https://kosukhin.github.io/patron-web-api/#/fetch/fetched\n */\nexport class Fetched<T> {\n  private source = new SourceWithPool<T>();\n\n  public constructor(private errors: Guest<Error>) {}\n\n  public do() {\n    return new Guest<FetchRequestType>((request) => {\n      fetch(request.url, request)\n        .then((resp) => {\n          if (!resp.ok) {\n            return Promise.reject(new Error(\"Error of status \" + resp.status));\n          }\n          if (request.asJson) {\n            return resp.json();\n          }\n          return resp.text();\n        })\n        .then((content) => {\n          this.source.give(content);\n        })\n        .catch((e) => {\n          this.errors.give(e);\n        });\n    });\n  }\n\n  public result() {\n    return this.source;\n  }\n}\n","import {\n  give,\n  GuestCast,\n  GuestType,\n  SourceObjectType,\n  SourceType,\n  value,\n} from \"patron-oop\";\n\nexport class Element implements SourceObjectType<HTMLElement> {\n  public constructor(private selector: SourceType<string>) {}\n\n  public value(guest: GuestType<HTMLElement>) {\n    value(\n      this.selector,\n      new GuestCast(guest, (selectorContent) => {\n        const element = document.querySelector(selectorContent);\n        if (element) {\n          give(element as HTMLElement, guest);\n        } else {\n          const targetNode = document.body;\n          const config = { childList: true, subtree: true };\n\n          const observer = new MutationObserver((mutationsList) => {\n            for (const mutation of mutationsList) {\n              if (mutation.type === \"childList\") {\n                const element = document.querySelector(selectorContent);\n                if (element) {\n                  give(element as HTMLElement, guest);\n                  observer.disconnect();\n                  break;\n                }\n              }\n            }\n          });\n\n          observer.observe(targetNode, config);\n        }\n      }),\n    );\n\n    return this;\n  }\n}\n","import {\n  give,\n  GuestCast,\n  GuestType,\n  SourceObjectType,\n  SourceType,\n  value,\n} from \"patron-oop\";\n\nexport class Attribute implements SourceObjectType<string> {\n  public constructor(\n    private element: SourceType<HTMLElement>,\n    private attrName: string,\n    private defaultValue: string = \"\",\n  ) {}\n\n  public value(guest: GuestType<string>) {\n    value(\n      this.element,\n      new GuestCast(guest, (el) => {\n        give(el.getAttribute(this.attrName) || this.defaultValue, guest);\n      }),\n    );\n    return this;\n  }\n}\n","import { GuestObjectType } from \"patron-oop\";\n\nexport class StyleInstalled implements GuestObjectType<string> {\n  public give(value: string): this {\n    const styleEl = document.createElement(\"style\");\n    styleEl.textContent = value;\n    document.head.appendChild(styleEl);\n    return this;\n  }\n}\n","import { GuestObjectType } from \"patron-oop\";\n\nexport class Log implements GuestObjectType<unknown> {\n  public constructor(private title: string = \"\") {}\n\n  public introduction(): \"guest\" | \"patron\" {\n    return \"patron\";\n  }\n\n  public give(value: unknown): this {\n    console.log(\"LOG: \", this.title, value);\n    return this;\n  }\n}\n"],"names":["HistoryPoppedPage","constructor","pageSource","this","watchPop","window","addEventListener","event","state","url","give","HistoryNewPage","location","href","replace","origin","history","pushState","date","Date","now","Fetched","errors","__publicField","SourceWithPool","Guest","request","fetch","then","resp","ok","asJson","json","text","Promise","reject","Error","status","content","source","catch","e","result","Element","selector","value","guest","GuestCast","selectorContent","element","document","querySelector","targetNode","body","config","childList","subtree","observer","MutationObserver","mutationsList","mutation","type","disconnect","observe","Attribute","attrName","defaultValue","el","getAttribute","StyleInstalled","styleEl","createElement","textContent","head","appendChild","Log","title","introduction","console","log"],"mappings":"2FAEO,MAAMA,EACJ,WAAAC,CAAoBC,GAAAC,KAAAD,WAAAA,CAAA,CAEpB,QAAAE,GACEC,OAAAC,iBAAiB,YAAaC,IAC7B,MAAAC,MAAEA,GAAUD,EACdC,GAAOC,KACJC,EAAAF,EAAMC,IAAKN,KAAKD,WAAU,GAElC,ECTE,MAAMS,EACJ,IAAAD,CAAKD,GAEV,OAAIA,IADeG,SAASC,KAAKC,QAAQF,SAASG,OAAQ,KAIlDC,QAAAC,UACN,CACER,MACAS,KAAMC,KAAKC,OAEb,aACAX,GARON,IAUF,uICLJ,MAAMkB,EAGJ,WAAApB,CAAoBqB,GAAAnB,KAAAmB,OAAAA,EAFnBC,EAAApB,KAAA,SAAS,IAAIqB,EAAkB,CAIhC,KACE,OAAA,IAAIC,GAAyBC,IAClCC,MAAMD,EAAQjB,IAAKiB,GAChBE,MAAMC,GACAA,EAAKC,GAGNJ,EAAQK,OACHF,EAAKG,OAEPH,EAAKI,OALHC,QAAQC,OAAO,IAAIC,MAAM,mBAAqBP,EAAKQ,WAO7DT,MAAMU,IACAnC,KAAAoC,OAAO7B,KAAK4B,EAAO,IAEzBE,OAAOC,IACDtC,KAAAmB,OAAOZ,KAAK+B,EAAC,GACnB,GACJ,CAGI,MAAAC,GACL,OAAOvC,KAAKoC,MAAA,EC7BT,MAAMI,EACJ,WAAA1C,CAAoB2C,GAAAzC,KAAAyC,SAAAA,CAAA,CAEpB,KAAAC,CAAMC,GA6BJ,OA5BPD,EACE1C,KAAKyC,SACL,IAAIG,EAAUD,GAAQE,IACd,MAAAC,EAAUC,SAASC,cAAcH,GACvC,GAAIC,EACFvC,EAAKuC,EAAwBH,OACxB,CACL,MAAMM,EAAaF,SAASG,KACtBC,EAAS,CAAEC,WAAW,EAAMC,SAAS,GAErCC,EAAW,IA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