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AK,aAAa,CAAE,KAAM,SAE9B,KAAK,WAAW,UAAY,EAI5C,CArCA,MAJI,KAAK,QAAU,CACX,OAAQ,EAyCpB,CACA,YAAA,CAAa,GACT,OAAO,CACX,EAEJ,MAAM,OAAS,CACX,OAAQ,CACJ,UAAU,IAGZ,QAAU,CACZ,OAAQ,CACJ,UAAU,EACV,QAAS,CACL,QAAQ,KAKd,GAAK,IAAI,GAAG,CACd,OAAQ,CACJ,QAAS,aACT,aAAc,CACV,GAAI,OACJ,WAAY,GACZ,OAAO,EACP,iBAAiB,EACjB,UAAU,EACV,SAAS,EACT,KAAM,GACN,iBAAkB,EAClB,cAAe,IAEnB,iBAAkB,eAClB,SAAU,CACN,KAAM,CACF,OAAQ,CACJ,OAAQ,gBACR,UAAW,mBACX,QAAS,CAAE,QAAQ,KAG3B,gBAAiB,CAAE,KAAM,UACzB,aAAc,CAAE,KAAM,UACtB,cAAe,OACf,UAAW,OACX,gBAAiB,QACjB,WAAY,WACT,iBAEP,QAAS,CACL,UAAW,CACP,QAAS,CAAC,UAAW,eAAgB,mBACrC,QAAS,CAAC,UAAW,QAAS,OAAQ,KAAM,oBAIxD,WAAY,cACZ,OAAQ,CAAC,sBAEN,MAAM,UAAY,GAAG","file":"/npm/xtal-fetch@0.0.108/xtal-fetch.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/xtal-fetch@0.0.108/xtal-fetch.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { CE } from 'trans-render/lib/CE.js';\nimport { commonPropsInfo, NotifyMixin } from 'trans-render/lib/mixins/notify.js';\nimport { getFullURL } from 'xtal-element/lib/base-link-id.js';\nexport class XtalFetchCore extends HTMLElement {\n    static cache = {};\n    #cachedResults = {};\n    #controller;\n    async getResult({ href, lastFrameHref, reqInit, as, cacheResults, insertResultsAs, fetchInProgress }) {\n        if (href !== lastFrameHref)\n            return;\n        if (!insertResultsAs)\n            this.style.display = 'none';\n        this.errorResponse = undefined;\n        if (cacheResults !== undefined) {\n            let val = undefined;\n            if (cacheResults === 'global') {\n                val = XtalFetchCore.cache[href];\n            }\n            else {\n                val = this.#cachedResults[href];\n            }\n            if (val) {\n                return { result: val };\n            }\n            else if (fetchInProgress) {\n                setTimeout(async () => {\n                    return await this.getResult(this);\n                }, 100);\n                return;\n            }\n        }\n        if (this.#controller) {\n            if (fetchInProgress) {\n                this.#controller.abort();\n            }\n        }\n        else {\n            this.#controller = new AbortController();\n        }\n        const fullHref = getFullURL(this, href);\n        const sig = this.#controller.signal;\n        let activeReqInit = reqInit;\n        if (reqInit) {\n            reqInit.signal = sig;\n        }\n        else {\n            this.reqInit = {\n                signal: sig,\n            };\n            return; //avoid duplicate requests.\n        }\n        this.fetchInProgress = true;\n        let resp;\n        try {\n            resp = await window.fetch(fullHref, activeReqInit);\n        }\n        catch (e) {\n            this.fetchInProgress = false;\n            this.errorText = e.message;\n            console.error(e);\n            return;\n        }\n        this.fetchInProgress = false;\n        if (resp.status !== 200) {\n            this.errorResponse = resp;\n            const respText = resp['text'];\n            if (respText) {\n                const val = await respText();\n                this.errorText = val;\n            }\n        }\n        else {\n            let result = await resp[as]();\n            result = this.filterResult(result);\n            if (typeof result === 'string') {\n                switch (insertResultsAs) {\n                    case 'innerHTML':\n                        this.innerHTML = result;\n                        break;\n                    case 'openShadow':\n                        if (this.shadowRoot === null) {\n                            this.attachShadow({ mode: 'open' });\n                        }\n                        this.shadowRoot.innerHTML = result;\n                        break;\n                }\n            }\n        }\n    }\n    filterResult(result) {\n        return result;\n    }\n}\nconst notify = {\n    notify: {\n        dispatch: true\n    }\n};\nconst reflect = {\n    notify: {\n        dispatch: true,\n        reflect: {\n            asAttr: true,\n        }\n    }\n};\n;\nconst ce = new CE({\n    config: {\n        tagName: 'xtal-fetch',\n        propDefaults: {\n            as: 'json',\n            baseLinkId: '',\n            fetch: false,\n            fetchInProgress: false,\n            disabled: false,\n            enabled: true,\n            href: '',\n            debounceDuration: 0,\n            lastFrameHref: '',\n        },\n        propChangeMethod: 'onPropChange',\n        propInfo: {\n            href: {\n                notify: {\n                    echoTo: 'lastFrameHref',\n                    echoDelay: 'debounceDuration',\n                    reflect: { asAttr: true }\n                }\n            },\n            insertResultsAs: { type: 'String' },\n            cacheResults: { type: 'String' },\n            errorResponse: notify,\n            errorText: notify,\n            fetchInProgress: reflect,\n            baseLinkId: reflect,\n            ...commonPropsInfo,\n        },\n        actions: {\n            getResult: {\n                ifKeyIn: ['reqInit', 'cacheResults', 'insertResultsAs'],\n                ifAllOf: ['enabled', 'fetch', 'href', 'as', 'lastFrameHref'],\n            }\n        },\n    },\n    superclass: XtalFetchCore,\n    mixins: [NotifyMixin],\n});\nexport const XtalFetch = ce.classDef;\n"]}