react-inlinesvg 3.0.2 → 3.1.0-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx","../src/config.ts","../src/helpers.ts","../src/cache.ts"],"names":["canUseDOMFlag","convert"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AACvB,4BAAoB;;;ACDb,IAAM,aAAa;AACnB,IAAM,oBAAoB;AAE1B,IAAM,SAAS;AAAA,EACpB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,aAAa;AACf;;;ACVA,mBAA2C;AAIpC,SAAS,YAAqB;AACnC,SAAO,aAAAA;AACT;AAEO,SAAS,yBAAkC;AAChD,SAAO,kBAAkB,KAAK,OAAO,WAAW,eAAe,WAAW;AAC5E;AAEA,eAAsB,QAAQ,KAAa,SAAuB;AAChE,QAAM,WAAW,MAAM,MAAM,KAAK,OAAO;AACzC,QAAM,cAAc,SAAS,QAAQ,IAAI,cAAc;AACvD,QAAM,CAAC,QAAQ,KAAK,eAAe,IAAI,MAAM,OAAO;AAEpD,MAAI,SAAS,SAAS,KAAK;AACzB,UAAM,IAAI,MAAM,WAAW;AAAA,EAC7B;AAEA,MAAI,CAAC,CAAC,iBAAiB,YAAY,EAAE,KAAK,OAAK,SAAS,SAAS,CAAC,CAAC,GAAG;AACpE,UAAM,IAAI,MAAM,6BAA6B,QAAQ,EAAE;AAAA,EACzD;AAEA,SAAO,SAAS,KAAK;AACvB;AAEO,SAAS,MAAM,UAAU,GAAG;AACjC,SAAO,IAAI,QAAQ,aAAW;AAC5B,eAAW,SAAS,UAAU,GAAI;AAAA,EACpC,CAAC;AACH;AAEO,SAAS,oBAA6B;AAE3C,MAAI,CAAC,UAAU;AACb,WAAO;A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ACA;AAAA,IACF;AAEA,QAAI,CAAC,UAAU,GAAG;AAChB,aAAO;AAAA,IACT;AAEA,QAAI,SAAS;AACX,aAAa,mBAAa,SAA+B,EAAE,KAAK,UAAU,GAAG,aAAa,CAAC;AAAA,IAC7F;AAEA,QAAK,CAAC,OAAO,aAAa,OAAO,MAAM,EAAe,SAAS,MAAM,GAAG;AACtE,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AACF;AA5TE,cALI,gBAKU,gBAAe;AAAA,EAC3B,eAAe;AAAA,EACf,aAAa;AACf;AA2Ta,SAAR,UAA2B,OAAc;AAC9C,MAAI,CAAC,YAAY;AACf,iBAAa,IAAI,WAAW;AAAA,EAC9B;AAEA,QAAM,EAAE,OAAO,IAAI;AACnB,QAAM,CAAC,SAAS,QAAQ,IAAU,eAAS,WAAW,OAAO;AAE7D,EAAM,gBAAU,MAAM;AACpB,QAAI,CAAC,SAAS;AACZ,iBAAW,QAAQ,MAAM;AACvB,iBAAS,IAAI;AAAA,MACf,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,MAAI,CAAC,SAAS;AACZ,WAAO,UAAU;AAAA,EACnB;AAEA,SAAO,4CAAC,kBAAgB,GAAG,OAAO;AACpC","sourcesContent":["import * as React from 'react';\nimport convert from 'react-from-dom';\n\nimport CacheStore from './cache';\nimport { STATUS } from './config';\nimport { canUseDOM, isSupportedEnvironment, omit, randomString, request } from './helpers';\nimport { FetchError, Props, State, Status } from './types';\n\n// eslint-disable-next-line import/no-mutable-exports\nexport let cacheStore: CacheStore;\n\nclass ReactInlineSVG extends React.PureComponent<Props, State> {\n private readonly hash: string;\n private isActive = false;\n private isInitialized = false;\n\n public static defaultProps = {\n cacheRequests: true,\n uniquifyIDs: false,\n };\n\n constructor(props: Props) {\n super(props);\n\n this.state = {\n content: '',\n element: null,\n isCached: !!props.cacheRequests && cacheStore.isCached(props.src),\n status: STATUS.IDLE,\n };\n\n this.hash = props.uniqueHash || randomString(8);\n }\n\n public componentDidMount(): void {\n this.isActive = true;\n\n if (!canUseDOM() || this.isInitialized) {\n return;\n }\n\n const { status } = this.state;\n const { src } = this.props;\n\n try {\n /* istanbul ignore else */\n if (status === STATUS.IDLE) {\n /* istanbul ignore else */\n if (!isSupportedEnvironment()) {\n throw new Error('Browser does not support SVG');\n }\n\n /* istanbul ignore else */\n if (!src) {\n throw new Error('Missing src');\n }\n\n this.load();\n }\n } catch (error: any) {\n this.handleError(error);\n }\n\n this.isInitialized = true;\n }\n\n public componentDidUpdate(previousProps: Props, previousState: State): void {\n if (!canUseDOM()) {\n return;\n }\n\n const { isCached, status } = this.state;\n const { onLoad, src } = this.props;\n\n if (previousState.status !== STATUS.READY && status === STATUS.READY) {\n /* istanbul ignore else */\n if (onLoad) {\n onLoad(src, isCached);\n }\n }\n\n if (previousProps.src !== src) {\n if (!src) {\n this.handleError(new Error('Missing src'));\n\n return;\n }\n\n this.load();\n }\n }\n\n public componentWillUnmount(): void {\n this.isActive = false;\n }\n\n private fetchContent = async () => {\n const { fetchOptions, src } = this.props;\n\n const content: string = await request(src, fetchOptions);\n\n this.handleLoad(content);\n };\n\n private getElement() {\n try {\n const node = this.getNode() as Node;\n const element = convert(node);\n\n if (!element || !React.isValidElement(element)) {\n throw new Error('Could not convert the src to a React element');\n }\n\n this.setState({\n element,\n status: STATUS.READY,\n });\n } catch (error: any) {\n this.handleError(new Error(error.message));\n }\n }\n\n private getNode() {\n const { description, title } = this.props;\n\n try {\n const svgText = this.processSVG();\n const node = convert(svgText, { nodeOnly: true });\n\n if (!node || !(node instanceof SVGSVGElement)) {\n throw new Error('Could not convert the src to a DOM Node');\n }\n\n const svg = this.updateSVGAttributes(node);\n\n if (description) {\n const originalDesc = svg.querySelector('desc');\n\n if (originalDesc && originalDesc.parentNode) {\n originalDesc.parentNode.removeChild(originalDesc);\n }\n\n const descElement = document.createElementNS('http://www.w3.org/2000/svg', 'desc');\n\n descElement.innerHTML = description;\n svg.prepend(descElement);\n }\n\n if (typeof title !== 'undefined') {\n const originalTitle = svg.querySelector('title');\n\n if (originalTitle && originalTitle.parentNode) {\n originalTitle.parentNode.removeChild(originalTitle);\n }\n\n if (title) {\n const titleElement = document.createElementNS('http://www.w3.org/2000/svg', 'title');\n\n titleElement.innerHTML = title;\n svg.prepend(titleElement);\n }\n }\n\n return svg;\n } catch (error: any) {\n return this.handleError(error);\n }\n }\n\n private handleError = (error: Error | FetchError) => {\n const { onError } = this.props;\n const status =\n error.message === 'Browser does not support SVG' ? STATUS.UNSUPPORTED : STATUS.FAILED;\n\n /* istanbul ignore else */\n if (this.isActive) {\n this.setState({ status }, () => {\n /* istanbul ignore else */\n if (typeof onError === 'function') {\n onError(error);\n }\n });\n }\n };\n\n private handleLoad = (content: string, hasCache = false) => {\n /* istanbul ignore else */\n if (this.isActive) {\n this.setState(\n {\n content,\n isCached: hasCache,\n status: STATUS.LOADED,\n },\n this.getElement,\n );\n }\n };\n\n private load() {\n /* istanbul ignore else */\n if (this.isActive) {\n this.setState(\n {\n content: '',\n element: null,\n isCached: false,\n status: STATUS.LOADING,\n },\n async () => {\n const { cacheRequests, fetchOptions, src } = this.props;\n\n const dataURI = src.match(/^data:image\\/svg[^,]*?(;base64)?,(.*)/u);\n let inlineSrc;\n\n if (dataURI) {\n inlineSrc = dataURI[1] ? window.atob(dataURI[2]) : decodeURIComponent(dataURI[2]);\n } else if (src.includes('<svg')) {\n inlineSrc = src;\n }\n\n if (inlineSrc) {\n this.handleLoad(inlineSrc);\n\n return;\n }\n\n try {\n if (cacheRequests) {\n const content = await cacheStore.get(src, fetchOptions);\n\n this.handleLoad(content, true);\n } else {\n await this.fetchContent();\n }\n } catch (error: any) {\n this.handleError(error);\n }\n },\n );\n }\n }\n\n private processSVG() {\n const { content } = this.state;\n const { preProcessor } = this.props;\n\n if (preProcessor) {\n return preProcessor(content);\n }\n\n return content;\n }\n\n private updateSVGAttributes(node: SVGSVGElement): SVGSVGElement {\n const { baseURL = '', uniquifyIDs } = this.props;\n const replaceableAttributes = ['id', 'href', 'xlink:href', 'xlink:role', 'xlink:arcrole'];\n const linkAttributes = ['href', 'xlink:href'];\n const isDataValue = (name: string, value: string) =>\n linkAttributes.includes(name) && (value ? !value.includes('#') : false);\n\n if (!uniquifyIDs) {\n return node;\n }\n\n [...node.children].forEach(d => {\n if (d.attributes && d.attributes.length) {\n const attributes = Object.values(d.attributes).map(a => {\n const attribute = a;\n const match = a.value.match(/url\\((.*?)\\)/);\n\n if (match && match[1]) {\n attribute.value = a.value.replace(match[0], `url(${baseURL}${match[1]}__${this.hash})`);\n }\n\n return attribute;\n });\n\n replaceableAttributes.forEach(r => {\n const attribute = attributes.find(a => a.name === r);\n\n if (attribute && !isDataValue(r, attribute.value)) {\n attribute.value = `${attribute.value}__${this.hash}`;\n }\n });\n }\n\n if (d.children.length) {\n return this.updateSVGAttributes(d as SVGSVGElement);\n }\n\n return d;\n });\n\n return node;\n }\n\n public render(): React.ReactNode {\n const { element, status } = this.state;\n const { children = null, innerRef, loader = null } = this.props;\n const elementProps = omit(\n this.props,\n 'baseURL',\n 'cacheRequests',\n 'children',\n 'description',\n 'fetchOptions',\n 'innerRef',\n 'loader',\n 'onError',\n 'onLoad',\n 'preProcessor',\n 'src',\n 'title',\n 'uniqueHash',\n 'uniquifyIDs',\n );\n\n if (!canUseDOM()) {\n return loader;\n }\n\n if (element) {\n return React.cloneElement(element as React.ReactElement, { ref: innerRef, ...elementProps });\n }\n\n if (([STATUS.UNSUPPORTED, STATUS.FAILED] as Status[]).includes(status)) {\n return children;\n }\n\n return loader;\n }\n}\n\nexport default function InlineSVG(props: Props) {\n if (!cacheStore) {\n cacheStore = new CacheStore();\n }\n\n const { loader } = props;\n const [isReady, setReady] = React.useState(cacheStore.isReady);\n\n React.useEffect(() => {\n if (!isReady) {\n cacheStore.onReady(() => {\n setReady(true);\n });\n }\n }, [isReady]);\n\n if (!isReady) {\n return loader ?? null;\n }\n\n return <ReactInlineSVG {...props} />;\n}\n\nexport * from './types';\n","export const CACHE_NAME = 'react-inlinesvg';\nexport const CACHE_MAX_RETRIES = 10;\n\nexport const STATUS = {\n IDLE: 'idle',\n LOADING: 'loading',\n LOADED: 'loaded',\n FAILED: 'failed',\n READY: 'ready',\n UNSUPPORTED: 'unsupported',\n} as const;\n","import { canUseDOM as canUseDOMFlag } from 'exenv';\n\nimport type { PlainObject } from './types';\n\nexport function canUseDOM(): boolean {\n return canUseDOMFlag;\n}\n\nexport function isSupportedEnvironment(): boolean {\n return supportsInlineSVG() && typeof window !== 'undefined' && window !== null;\n}\n\nexport async function request(url: string, options?: RequestInit) {\n const response = await fetch(url, options);\n const contentType = response.headers.get('content-type');\n const [fileType] = (contentType || '').split(/ ?; ?/);\n\n if (response.status > 299) {\n throw new Error('Not found');\n }\n\n if (!['image/svg+xml', 'text/plain'].some(d => fileType.includes(d))) {\n throw new Error(`Content type isn't valid: ${fileType}`);\n }\n\n return response.text();\n}\n\nexport function sleep(seconds = 1) {\n return new Promise(resolve => {\n setTimeout(resolve, seconds * 1000);\n });\n}\n\nexport function supportsInlineSVG(): boolean {\n /* istanbul ignore next */\n if (!document) {\n return false;\n }\n\n const div = document.createElement('div');\n\n div.innerHTML = '<svg />';\n const svg = div.firstChild as SVGSVGElement;\n\n return !!svg && svg.namespaceURI === 'http://www.w3.org/2000/svg';\n}\n\nfunction randomCharacter(character: string) {\n return character[Math.floor(Math.random() * character.length)];\n}\n\nexport function randomString(length: number): string {\n const letters = 'abcdefghijklmnopqrstuvwxyz';\n const numbers = '1234567890';\n const charset = `${letters}${letters.toUpperCase()}${numbers}`;\n\n let R = '';\n\n for (let index = 0; index < length; index++) {\n R += randomCharacter(charset);\n }\n\n return R;\n}\n\n/**\n * Remove properties from an object\n */\nexport function omit<T extends PlainObject, K extends keyof T>(\n input: T,\n ...filter: K[]\n): Omit<T, K> {\n const output: any = {};\n\n for (const key in input) {\n /* istanbul ignore else */\n if ({}.hasOwnProperty.call(input, key)) {\n if (!filter.includes(key as unknown as K)) {\n output[key] = input[key];\n }\n }\n }\n\n return output as Omit<T, K>;\n}\n","import { CACHE_MAX_RETRIES, CACHE_NAME, STATUS } from './config';\nimport { request, sleep } from './helpers';\nimport { StorageItem } from './types';\n\nexport default class CacheStore {\n private cacheApi: Cache | undefined;\n private readonly cacheStore: Map<string, StorageItem>;\n private readonly subscribers: Array<() => void> = [];\n private readonly usePersistentCache: boolean;\n public isReady = false;\n\n constructor() {\n this.cacheStore = new Map<string, StorageItem>();\n\n this.usePersistentCache =\n 'REACT_INLINESVG_PERSISTENT_CACHE' in window && !!window.REACT_INLINESVG_PERSISTENT_CACHE;\n\n if (this.usePersistentCache) {\n caches.open(CACHE_NAME).then(cache => {\n this.cacheApi = cache;\n this.isReady = true;\n\n this.subscribers.forEach(callback => callback());\n });\n } else {\n this.isReady = true;\n }\n }\n\n public onReady(callback: () => void) {\n if (this.isReady) {\n callback();\n } else {\n this.subscribers.push(callback);\n }\n }\n\n public async get(url: string, fetchOptions?: RequestInit) {\n await (this.usePersistentCache\n ? this.fetchAndAddToPersistentCache(url, fetchOptions)\n : this.fetchAndAddToInternalCache(url, fetchOptions));\n\n return this.cacheStore.get(url)?.content ?? '';\n }\n\n public set(url: string, data: StorageItem) {\n this.cacheStore.set(url, data);\n }\n\n public isCached(url: string) {\n return this.cacheStore.get(url)?.status === STATUS.LOADED;\n }\n\n private async fetchAndAddToInternalCache(url: string, fetchOptions?: RequestInit) {\n const cache = this.cacheStore.get(url);\n\n if (cache?.status === STATUS.LOADING) {\n await this.handleLoading(url, async () => {\n this.cacheStore.set(url, { content: '', status: STATUS.IDLE });\n await this.fetchAndAddToInternalCache(url, fetchOptions);\n });\n\n return;\n }\n\n if (!cache?.content) {\n this.cacheStore.set(url, { content: '', status: STATUS.LOADING });\n\n try {\n const content = await request(url, fetchOptions);\n\n this.cacheStore.set(url, { content, status: STATUS.LOADED });\n } catch (error: any) {\n this.cacheStore.set(url, { content: '', status: STATUS.FAILED });\n throw error;\n }\n }\n }\n\n private async fetchAndAddToPersistentCache(url: string, fetchOptions?: RequestInit) {\n const cache = this.cacheStore.get(url);\n\n if (cache?.status === STATUS.LOADED) {\n return;\n }\n\n if (cache?.status === STATUS.LOADING) {\n await this.handleLoading(url, async () => {\n this.cacheStore.set(url, { content: '', status: STATUS.IDLE });\n await this.fetchAndAddToPersistentCache(url, fetchOptions);\n });\n\n return;\n }\n\n this.cacheStore.set(url, { content: '', status: STATUS.LOADING });\n\n const data = await this.cacheApi?.match(url);\n\n if (data) {\n const content = await data.text();\n\n this.cacheStore.set(url, { content, status: STATUS.LOADED });\n\n return;\n }\n\n try {\n await this.cacheApi?.add(new Request(url, fetchOptions));\n\n const response = await this.cacheApi?.match(url);\n const content = (await response?.text()) ?? '';\n\n this.cacheStore.set(url, { content, status: STATUS.LOADED });\n } catch (error: any) {\n this.cacheStore.set(url, { content: '', status: STATUS.FAILED });\n throw error;\n }\n }\n\n private async handleLoading(url: string, callback: () => Promise<void>) {\n let retryCount = 0;\n\n // eslint-disable-next-line no-await-in-loop\n while (this.cacheStore.get(url)?.status === STATUS.LOADING && retryCount < CACHE_MAX_RETRIES) {\n // eslint-disable-next-line no-await-in-loop\n await sleep(0.1);\n retryCount += 1;\n }\n\n if (retryCount >= CACHE_MAX_RETRIES) {\n await callback();\n }\n }\n\n public keys(): Array<string> {\n return [...this.cacheStore.keys()];\n }\n\n public data(): Array<Record<string, StorageItem>> {\n return [...this.cacheStore.entries()].map(([key, value]) => ({ [key]: value }));\n }\n\n public async delete(url: string) {\n if (this.cacheApi) {\n await this.cacheApi.delete(url);\n }\n\n this.cacheStore.delete(url);\n }\n\n public async clear() {\n if (this.cacheApi) {\n const keys = await this.cacheApi.keys();\n\n for (const key of keys) {\n // eslint-disable-next-line no-await-in-loop\n await this.cacheApi.delete(key);\n }\n }\n\n this.cacheStore.clear();\n }\n}\n"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,474 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+
8
+ // src/index.tsx
9
+ import * as React from "react";
10
+ import convert from "react-from-dom";
11
+
12
+ // src/config.ts
13
+ var CACHE_NAME = "react-inlinesvg";
14
+ var CACHE_MAX_RETRIES = 10;
15
+ var STATUS = {
16
+ IDLE: "idle",
17
+ LOADING: "loading",
18
+ LOADED: "loaded",
19
+ FAILED: "failed",
20
+ READY: "ready",
21
+ UNSUPPORTED: "unsupported"
22
+ };
23
+
24
+ // src/helpers.ts
25
+ import { canUseDOM as canUseDOMFlag } from "exenv";
26
+ function canUseDOM() {
27
+ return canUseDOMFlag;
28
+ }
29
+ function isSupportedEnvironment() {
30
+ return supportsInlineSVG() && typeof window !== "undefined" && window !== null;
31
+ }
32
+ async function request(url, options) {
33
+ const response = await fetch(url, options);
34
+ const contentType = response.headers.get("content-type");
35
+ const [fileType] = (contentType || "").split(/ ?; ?/);
36
+ if (response.status > 299) {
37
+ throw new Error("Not found");
38
+ }
39
+ if (!["image/svg+xml", "text/plain"].some((d) => fileType.includes(d))) {
40
+ throw new Error(`Content type isn't valid: ${fileType}`);
41
+ }
42
+ return response.text();
43
+ }
44
+ function sleep(seconds = 1) {
45
+ return new Promise((resolve) => {
46
+ setTimeout(resolve, seconds * 1e3);
47
+ });
48
+ }
49
+ function supportsInlineSVG() {
50
+ if (!document) {
51
+ return false;
52
+ }
53
+ const div = document.createElement("div");
54
+ div.innerHTML = "<svg />";
55
+ const svg = div.firstChild;
56
+ return !!svg && svg.namespaceURI === "http://www.w3.org/2000/svg";
57
+ }
58
+ function randomCharacter(character) {
59
+ return character[Math.floor(Math.random() * character.length)];
60
+ }
61
+ function randomString(length) {
62
+ const letters = "abcdefghijklmnopqrstuvwxyz";
63
+ const numbers = "1234567890";
64
+ const charset = `${letters}${letters.toUpperCase()}${numbers}`;
65
+ let R = "";
66
+ for (let index = 0; index < length; index++) {
67
+ R += randomCharacter(charset);
68
+ }
69
+ return R;
70
+ }
71
+ function omit(input, ...filter) {
72
+ const output = {};
73
+ for (const key in input) {
74
+ if ({}.hasOwnProperty.call(input, key)) {
75
+ if (!filter.includes(key)) {
76
+ output[key] = input[key];
77
+ }
78
+ }
79
+ }
80
+ return output;
81
+ }
82
+
83
+ // src/cache.ts
84
+ var CacheStore = class {
85
+ constructor() {
86
+ __publicField(this, "cacheApi");
87
+ __publicField(this, "cacheStore");
88
+ __publicField(this, "subscribers", []);
89
+ __publicField(this, "usePersistentCache");
90
+ __publicField(this, "isReady", false);
91
+ this.cacheStore = /* @__PURE__ */ new Map();
92
+ this.usePersistentCache = "REACT_INLINESVG_PERSISTENT_CACHE" in window && !!window.REACT_INLINESVG_PERSISTENT_CACHE;
93
+ if (this.usePersistentCache) {
94
+ caches.open(CACHE_NAME).then((cache) => {
95
+ this.cacheApi = cache;
96
+ this.isReady = true;
97
+ this.subscribers.forEach((callback) => callback());
98
+ });
99
+ } else {
100
+ this.isReady = true;
101
+ }
102
+ }
103
+ onReady(callback) {
104
+ if (this.isReady) {
105
+ callback();
106
+ } else {
107
+ this.subscribers.push(callback);
108
+ }
109
+ }
110
+ async get(url, fetchOptions) {
111
+ await (this.usePersistentCache ? this.fetchAndAddToPersistentCache(url, fetchOptions) : this.fetchAndAddToInternalCache(url, fetchOptions));
112
+ return this.cacheStore.get(url)?.content ?? "";
113
+ }
114
+ set(url, data) {
115
+ this.cacheStore.set(url, data);
116
+ }
117
+ isCached(url) {
118
+ return this.cacheStore.get(url)?.status === STATUS.LOADED;
119
+ }
120
+ async fetchAndAddToInternalCache(url, fetchOptions) {
121
+ const cache = this.cacheStore.get(url);
122
+ if (cache?.status === STATUS.LOADING) {
123
+ await this.handleLoading(url, async () => {
124
+ this.cacheStore.set(url, { content: "", status: STATUS.IDLE });
125
+ await this.fetchAndAddToInternalCache(url, fetchOptions);
126
+ });
127
+ return;
128
+ }
129
+ if (!cache?.content) {
130
+ this.cacheStore.set(url, { content: "", status: STATUS.LOADING });
131
+ try {
132
+ const content = await request(url, fetchOptions);
133
+ this.cacheStore.set(url, { content, status: STATUS.LOADED });
134
+ } catch (error) {
135
+ this.cacheStore.set(url, { content: "", status: STATUS.FAILED });
136
+ throw error;
137
+ }
138
+ }
139
+ }
140
+ async fetchAndAddToPersistentCache(url, fetchOptions) {
141
+ const cache = this.cacheStore.get(url);
142
+ if (cache?.status === STATUS.LOADED) {
143
+ return;
144
+ }
145
+ if (cache?.status === STATUS.LOADING) {
146
+ await this.handleLoading(url, async () => {
147
+ this.cacheStore.set(url, { content: "", status: STATUS.IDLE });
148
+ await this.fetchAndAddToPersistentCache(url, fetchOptions);
149
+ });
150
+ return;
151
+ }
152
+ this.cacheStore.set(url, { content: "", status: STATUS.LOADING });
153
+ const data = await this.cacheApi?.match(url);
154
+ if (data) {
155
+ const content = await data.text();
156
+ this.cacheStore.set(url, { content, status: STATUS.LOADED });
157
+ return;
158
+ }
159
+ try {
160
+ await this.cacheApi?.add(new Request(url, fetchOptions));
161
+ const response = await this.cacheApi?.match(url);
162
+ const content = await response?.text() ?? "";
163
+ this.cacheStore.set(url, { content, status: STATUS.LOADED });
164
+ } catch (error) {
165
+ this.cacheStore.set(url, { content: "", status: STATUS.FAILED });
166
+ throw error;
167
+ }
168
+ }
169
+ async handleLoading(url, callback) {
170
+ let retryCount = 0;
171
+ while (this.cacheStore.get(url)?.status === STATUS.LOADING && retryCount < CACHE_MAX_RETRIES) {
172
+ await sleep(0.1);
173
+ retryCount += 1;
174
+ }
175
+ if (retryCount >= CACHE_MAX_RETRIES) {
176
+ await callback();
177
+ }
178
+ }
179
+ keys() {
180
+ return [...this.cacheStore.keys()];
181
+ }
182
+ data() {
183
+ return [...this.cacheStore.entries()].map(([key, value]) => ({ [key]: value }));
184
+ }
185
+ async delete(url) {
186
+ if (this.cacheApi) {
187
+ await this.cacheApi.delete(url);
188
+ }
189
+ this.cacheStore.delete(url);
190
+ }
191
+ async clear() {
192
+ if (this.cacheApi) {
193
+ const keys = await this.cacheApi.keys();
194
+ for (const key of keys) {
195
+ await this.cacheApi.delete(key);
196
+ }
197
+ }
198
+ this.cacheStore.clear();
199
+ }
200
+ };
201
+
202
+ // src/index.tsx
203
+ import { jsx } from "react/jsx-runtime";
204
+ var cacheStore;
205
+ var ReactInlineSVG = class extends React.PureComponent {
206
+ constructor(props) {
207
+ super(props);
208
+ __publicField(this, "hash");
209
+ __publicField(this, "isActive", false);
210
+ __publicField(this, "isInitialized", false);
211
+ __publicField(this, "fetchContent", async () => {
212
+ const { fetchOptions, src } = this.props;
213
+ const content = await request(src, fetchOptions);
214
+ this.handleLoad(content);
215
+ });
216
+ __publicField(this, "handleError", (error) => {
217
+ const { onError } = this.props;
218
+ const status = error.message === "Browser does not support SVG" ? STATUS.UNSUPPORTED : STATUS.FAILED;
219
+ if (this.isActive) {
220
+ this.setState({ status }, () => {
221
+ if (typeof onError === "function") {
222
+ onError(error);
223
+ }
224
+ });
225
+ }
226
+ });
227
+ __publicField(this, "handleLoad", (content, hasCache = false) => {
228
+ if (this.isActive) {
229
+ this.setState(
230
+ {
231
+ content,
232
+ isCached: hasCache,
233
+ status: STATUS.LOADED
234
+ },
235
+ this.getElement
236
+ );
237
+ }
238
+ });
239
+ this.state = {
240
+ content: "",
241
+ element: null,
242
+ isCached: !!props.cacheRequests && cacheStore.isCached(props.src),
243
+ status: STATUS.IDLE
244
+ };
245
+ this.hash = props.uniqueHash || randomString(8);
246
+ }
247
+ componentDidMount() {
248
+ this.isActive = true;
249
+ if (!canUseDOM() || this.isInitialized) {
250
+ return;
251
+ }
252
+ const { status } = this.state;
253
+ const { src } = this.props;
254
+ try {
255
+ if (status === STATUS.IDLE) {
256
+ if (!isSupportedEnvironment()) {
257
+ throw new Error("Browser does not support SVG");
258
+ }
259
+ if (!src) {
260
+ throw new Error("Missing src");
261
+ }
262
+ this.load();
263
+ }
264
+ } catch (error) {
265
+ this.handleError(error);
266
+ }
267
+ this.isInitialized = true;
268
+ }
269
+ componentDidUpdate(previousProps, previousState) {
270
+ if (!canUseDOM()) {
271
+ return;
272
+ }
273
+ const { isCached, status } = this.state;
274
+ const { onLoad, src } = this.props;
275
+ if (previousState.status !== STATUS.READY && status === STATUS.READY) {
276
+ if (onLoad) {
277
+ onLoad(src, isCached);
278
+ }
279
+ }
280
+ if (previousProps.src !== src) {
281
+ if (!src) {
282
+ this.handleError(new Error("Missing src"));
283
+ return;
284
+ }
285
+ this.load();
286
+ }
287
+ }
288
+ componentWillUnmount() {
289
+ this.isActive = false;
290
+ }
291
+ getElement() {
292
+ try {
293
+ const node = this.getNode();
294
+ const element = convert(node);
295
+ if (!element || !React.isValidElement(element)) {
296
+ throw new Error("Could not convert the src to a React element");
297
+ }
298
+ this.setState({
299
+ element,
300
+ status: STATUS.READY
301
+ });
302
+ } catch (error) {
303
+ this.handleError(new Error(error.message));
304
+ }
305
+ }
306
+ getNode() {
307
+ const { description, title } = this.props;
308
+ try {
309
+ const svgText = this.processSVG();
310
+ const node = convert(svgText, { nodeOnly: true });
311
+ if (!node || !(node instanceof SVGSVGElement)) {
312
+ throw new Error("Could not convert the src to a DOM Node");
313
+ }
314
+ const svg = this.updateSVGAttributes(node);
315
+ if (description) {
316
+ const originalDesc = svg.querySelector("desc");
317
+ if (originalDesc && originalDesc.parentNode) {
318
+ originalDesc.parentNode.removeChild(originalDesc);
319
+ }
320
+ const descElement = document.createElementNS("http://www.w3.org/2000/svg", "desc");
321
+ descElement.innerHTML = description;
322
+ svg.prepend(descElement);
323
+ }
324
+ if (typeof title !== "undefined") {
325
+ const originalTitle = svg.querySelector("title");
326
+ if (originalTitle && originalTitle.parentNode) {
327
+ originalTitle.parentNode.removeChild(originalTitle);
328
+ }
329
+ if (title) {
330
+ const titleElement = document.createElementNS("http://www.w3.org/2000/svg", "title");
331
+ titleElement.innerHTML = title;
332
+ svg.prepend(titleElement);
333
+ }
334
+ }
335
+ return svg;
336
+ } catch (error) {
337
+ return this.handleError(error);
338
+ }
339
+ }
340
+ load() {
341
+ if (this.isActive) {
342
+ this.setState(
343
+ {
344
+ content: "",
345
+ element: null,
346
+ isCached: false,
347
+ status: STATUS.LOADING
348
+ },
349
+ async () => {
350
+ const { cacheRequests, fetchOptions, src } = this.props;
351
+ const dataURI = src.match(/^data:image\/svg[^,]*?(;base64)?,(.*)/u);
352
+ let inlineSrc;
353
+ if (dataURI) {
354
+ inlineSrc = dataURI[1] ? window.atob(dataURI[2]) : decodeURIComponent(dataURI[2]);
355
+ } else if (src.includes("<svg")) {
356
+ inlineSrc = src;
357
+ }
358
+ if (inlineSrc) {
359
+ this.handleLoad(inlineSrc);
360
+ return;
361
+ }
362
+ try {
363
+ if (cacheRequests) {
364
+ const content = await cacheStore.get(src, fetchOptions);
365
+ this.handleLoad(content, true);
366
+ } else {
367
+ await this.fetchContent();
368
+ }
369
+ } catch (error) {
370
+ this.handleError(error);
371
+ }
372
+ }
373
+ );
374
+ }
375
+ }
376
+ processSVG() {
377
+ const { content } = this.state;
378
+ const { preProcessor } = this.props;
379
+ if (preProcessor) {
380
+ return preProcessor(content);
381
+ }
382
+ return content;
383
+ }
384
+ updateSVGAttributes(node) {
385
+ const { baseURL = "", uniquifyIDs } = this.props;
386
+ const replaceableAttributes = ["id", "href", "xlink:href", "xlink:role", "xlink:arcrole"];
387
+ const linkAttributes = ["href", "xlink:href"];
388
+ const isDataValue = (name, value) => linkAttributes.includes(name) && (value ? !value.includes("#") : false);
389
+ if (!uniquifyIDs) {
390
+ return node;
391
+ }
392
+ [...node.children].forEach((d) => {
393
+ if (d.attributes && d.attributes.length) {
394
+ const attributes = Object.values(d.attributes).map((a) => {
395
+ const attribute = a;
396
+ const match = a.value.match(/url\((.*?)\)/);
397
+ if (match && match[1]) {
398
+ attribute.value = a.value.replace(match[0], `url(${baseURL}${match[1]}__${this.hash})`);
399
+ }
400
+ return attribute;
401
+ });
402
+ replaceableAttributes.forEach((r) => {
403
+ const attribute = attributes.find((a) => a.name === r);
404
+ if (attribute && !isDataValue(r, attribute.value)) {
405
+ attribute.value = `${attribute.value}__${this.hash}`;
406
+ }
407
+ });
408
+ }
409
+ if (d.children.length) {
410
+ return this.updateSVGAttributes(d);
411
+ }
412
+ return d;
413
+ });
414
+ return node;
415
+ }
416
+ render() {
417
+ const { element, status } = this.state;
418
+ const { children = null, innerRef, loader = null } = this.props;
419
+ const elementProps = omit(
420
+ this.props,
421
+ "baseURL",
422
+ "cacheRequests",
423
+ "children",
424
+ "description",
425
+ "fetchOptions",
426
+ "innerRef",
427
+ "loader",
428
+ "onError",
429
+ "onLoad",
430
+ "preProcessor",
431
+ "src",
432
+ "title",
433
+ "uniqueHash",
434
+ "uniquifyIDs"
435
+ );
436
+ if (!canUseDOM()) {
437
+ return loader;
438
+ }
439
+ if (element) {
440
+ return React.cloneElement(element, { ref: innerRef, ...elementProps });
441
+ }
442
+ if ([STATUS.UNSUPPORTED, STATUS.FAILED].includes(status)) {
443
+ return children;
444
+ }
445
+ return loader;
446
+ }
447
+ };
448
+ __publicField(ReactInlineSVG, "defaultProps", {
449
+ cacheRequests: true,
450
+ uniquifyIDs: false
451
+ });
452
+ function InlineSVG(props) {
453
+ if (!cacheStore) {
454
+ cacheStore = new CacheStore();
455
+ }
456
+ const { loader } = props;
457
+ const [isReady, setReady] = React.useState(cacheStore.isReady);
458
+ React.useEffect(() => {
459
+ if (!isReady) {
460
+ cacheStore.onReady(() => {
461
+ setReady(true);
462
+ });
463
+ }
464
+ }, [isReady]);
465
+ if (!isReady) {
466
+ return loader ?? null;
467
+ }
468
+ return /* @__PURE__ */ jsx(ReactInlineSVG, { ...props });
469
+ }
470
+ export {
471
+ cacheStore,
472
+ InlineSVG as default
473
+ };
474
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.tsx","../src/config.ts","../src/helpers.ts","../src/cache.ts"],"sourcesContent":["import * as React from 'react';\nimport convert from 'react-from-dom';\n\nimport CacheStore from './cache';\nimport { STATUS } from './config';\nimport { canUseDOM, isSupportedEnvironment, omit, randomString, request } from './helpers';\nimport { FetchError, Props, State, Status } from './types';\n\n// eslint-disable-next-line import/no-mutable-exports\nexport let cacheStore: CacheStore;\n\nclass ReactInlineSVG extends React.PureComponent<Props, State> {\n private readonly hash: string;\n private isActive = false;\n private isInitialized = false;\n\n public static defaultProps = {\n cacheRequests: true,\n uniquifyIDs: false,\n };\n\n constructor(props: Props) {\n super(props);\n\n this.state = {\n content: '',\n element: null,\n isCached: !!props.cacheRequests && cacheStore.isCached(props.src),\n status: STATUS.IDLE,\n };\n\n this.hash = props.uniqueHash || randomString(8);\n }\n\n public componentDidMount(): void {\n this.isActive = true;\n\n if (!canUseDOM() || this.isInitialized) {\n return;\n }\n\n const { status } = this.state;\n const { src } = this.props;\n\n try {\n /* istanbul ignore else */\n if (status === STATUS.IDLE) {\n /* istanbul ignore else */\n if (!isSupportedEnvironment()) {\n throw new Error('Browser does not support SVG');\n }\n\n /* istanbul ignore else */\n if (!src) {\n throw new Error('Missing src');\n }\n\n this.load();\n }\n } catch (error: any) {\n this.handleError(error);\n }\n\n this.isInitialized = true;\n }\n\n public componentDidUpdate(previousProps: Props, previousState: State): void {\n if (!canUseDOM()) {\n return;\n }\n\n const { isCached, status } = this.state;\n const { onLoad, src } = this.props;\n\n if (previousState.status !== STATUS.READY && status === STATUS.READY) {\n /* istanbul ignore else */\n if (onLoad) {\n onLoad(src, isCached);\n }\n }\n\n if (previousProps.src !== src) {\n if (!src) {\n this.handleError(new Error('Missing src'));\n\n return;\n }\n\n this.load();\n }\n }\n\n public componentWillUnmount(): void {\n this.isActive = false;\n }\n\n private fetchContent = async () => {\n const { fetchOptions, src } = this.props;\n\n const content: string = await request(src, fetchOptions);\n\n this.handleLoad(content);\n };\n\n private getElement() {\n try {\n const node = this.getNode() as Node;\n const element = convert(node);\n\n if (!element || !React.isValidElement(element)) {\n throw new Error('Could not convert the src to a React element');\n }\n\n this.setState({\n element,\n status: STATUS.READY,\n });\n } catch (error: any) {\n this.handleError(new Error(error.message));\n }\n }\n\n private getNode() {\n const { description, title } = this.props;\n\n try {\n const svgText = this.processSVG();\n const node = convert(svgText, { nodeOnly: true });\n\n if (!node || !(node instanceof SVGSVGElement)) {\n throw new Error('Could not convert the src to a DOM Node');\n }\n\n const svg = this.updateSVGAttributes(node);\n\n if (description) {\n const originalDesc = svg.querySelector('desc');\n\n if (originalDesc && originalDesc.parentNode) {\n originalDesc.parentNode.removeChild(originalDesc);\n }\n\n const descElement = document.createElementNS('http://www.w3.org/2000/svg', 'desc');\n\n descElement.innerHTML = description;\n svg.prepend(descElement);\n }\n\n if (typeof title !== 'undefined') {\n const originalTitle = svg.querySelector('title');\n\n if (originalTitle && originalTitle.parentNode) {\n originalTitle.parentNode.removeChild(originalTitle);\n }\n\n if (title) {\n const titleElement = document.createElementNS('http://www.w3.org/2000/svg', 'title');\n\n titleElement.innerHTML = title;\n svg.prepend(titleElement);\n }\n }\n\n return svg;\n } catch (error: any) {\n return this.handleError(error);\n }\n }\n\n private handleError = (error: Error | FetchError) => {\n const { onError } = this.props;\n const status =\n error.message === 'Browser does not support SVG' ? STATUS.UNSUPPORTED : STATUS.FAILED;\n\n /* istanbul ignore else */\n if (this.isActive) {\n this.setState({ status }, () => {\n /* istanbul ignore else */\n if (typeof onError === 'function') {\n onError(error);\n }\n });\n }\n };\n\n private handleLoad = (content: string, hasCache = false) => {\n /* istanbul ignore else */\n if (this.isActive) {\n this.setState(\n {\n content,\n isCached: hasCache,\n status: STATUS.LOADED,\n },\n this.getElement,\n );\n }\n };\n\n private load() {\n /* istanbul ignore else */\n if (this.isActive) {\n this.setState(\n {\n content: '',\n element: null,\n isCached: false,\n status: STATUS.LOADING,\n },\n async () => {\n const { cacheRequests, fetchOptions, src } = this.props;\n\n const dataURI = src.match(/^data:image\\/svg[^,]*?(;base64)?,(.*)/u);\n let inlineSrc;\n\n if (dataURI) {\n inlineSrc = dataURI[1] ? window.atob(dataURI[2]) : decodeURIComponent(dataURI[2]);\n } else if (src.includes('<svg')) {\n inlineSrc = src;\n }\n\n if (inlineSrc) {\n this.handleLoad(inlineSrc);\n\n return;\n }\n\n try {\n if (cacheRequests) {\n const content = await cacheStore.get(src, fetchOptions);\n\n this.handleLoad(content, true);\n } else {\n await this.fetchContent();\n }\n } catch (error: any) {\n this.handleError(error);\n }\n },\n );\n }\n }\n\n private processSVG() {\n const { content } = this.state;\n const { preProcessor } = this.props;\n\n if (preProcessor) {\n return preProcessor(content);\n }\n\n return content;\n }\n\n private updateSVGAttributes(node: SVGSVGElement): SVGSVGElement {\n const { baseURL = '', uniquifyIDs } = this.props;\n const replaceableAttributes = ['id', 'href', 'xlink:href', 'xlink:role', 'xlink:arcrole'];\n const linkAttributes = ['href', 'xlink:href'];\n const isDataValue = (name: string, value: string) =>\n linkAttributes.includes(name) && (value ? !value.includes('#') : false);\n\n if (!uniquifyIDs) {\n return node;\n }\n\n [...node.children].forEach(d => {\n if (d.attributes && d.attributes.length) {\n const attributes = Object.values(d.attributes).map(a => {\n const attribute = a;\n const match = a.value.match(/url\\((.*?)\\)/);\n\n if (match && match[1]) {\n attribute.value = a.value.replace(match[0], `url(${baseURL}${match[1]}__${this.hash})`);\n }\n\n return attribute;\n });\n\n replaceableAttributes.forEach(r => {\n const attribute = attributes.find(a => a.name === r);\n\n if (attribute && !isDataValue(r, attribute.value)) {\n attribute.value = `${attribute.value}__${this.hash}`;\n }\n });\n }\n\n if (d.children.length) {\n return this.updateSVGAttributes(d as SVGSVGElement);\n }\n\n return d;\n });\n\n return node;\n }\n\n public render(): React.ReactNode {\n const { element, status } = this.state;\n const { children = null, innerRef, loader = null } = this.props;\n const elementProps = omit(\n this.props,\n 'baseURL',\n 'cacheRequests',\n 'children',\n 'description',\n 'fetchOptions',\n 'innerRef',\n 'loader',\n 'onError',\n 'onLoad',\n 'preProcessor',\n 'src',\n 'title',\n 'uniqueHash',\n 'uniquifyIDs',\n );\n\n if (!canUseDOM()) {\n return loader;\n }\n\n if (element) {\n return React.cloneElement(element as React.ReactElement, { ref: innerRef, ...elementProps });\n }\n\n if (([STATUS.UNSUPPORTED, STATUS.FAILED] as Status[]).includes(status)) {\n return children;\n }\n\n return loader;\n }\n}\n\nexport default function InlineSVG(props: Props) {\n if (!cacheStore) {\n cacheStore = new CacheStore();\n }\n\n const { loader } = props;\n const [isReady, setReady] = React.useState(cacheStore.isReady);\n\n React.useEffect(() => {\n if (!isReady) {\n cacheStore.onReady(() => {\n setReady(true);\n });\n }\n }, [isReady]);\n\n if (!isReady) {\n return loader ?? null;\n }\n\n return <ReactInlineSVG {...props} />;\n}\n\nexport * from './types';\n","export const CACHE_NAME = 'react-inlinesvg';\nexport const CACHE_MAX_RETRIES = 10;\n\nexport const STATUS = {\n IDLE: 'idle',\n LOADING: 'loading',\n LOADED: 'loaded',\n FAILED: 'failed',\n READY: 'ready',\n UNSUPPORTED: 'unsupported',\n} as const;\n","import { canUseDOM as canUseDOMFlag } from 'exenv';\n\nimport type { PlainObject } from './types';\n\nexport function canUseDOM(): boolean {\n return canUseDOMFlag;\n}\n\nexport function isSupportedEnvironment(): boolean {\n return supportsInlineSVG() && typeof window !== 'undefined' && window !== null;\n}\n\nexport async function request(url: string, options?: RequestInit) {\n const response = await fetch(url, options);\n const contentType = response.headers.get('content-type');\n const [fileType] = (contentType || '').split(/ ?; ?/);\n\n if (response.status > 299) {\n throw new Error('Not found');\n }\n\n if (!['image/svg+xml', 'text/plain'].some(d => fileType.includes(d))) {\n throw new Error(`Content type isn't valid: ${fileType}`);\n }\n\n return response.text();\n}\n\nexport function sleep(seconds = 1) {\n return new Promise(resolve => {\n setTimeout(resolve, seconds * 1000);\n });\n}\n\nexport function supportsInlineSVG(): boolean {\n /* istanbul ignore next */\n if (!document) {\n return false;\n }\n\n const div = document.createElement('div');\n\n div.innerHTML = '<svg />';\n const svg = div.firstChild as SVGSVGElement;\n\n return !!svg && svg.namespaceURI === 'http://www.w3.org/2000/svg';\n}\n\nfunction randomCharacter(character: string) {\n return character[Math.floor(Math.random() * character.length)];\n}\n\nexport function randomString(length: number): string {\n const letters = 'abcdefghijklmnopqrstuvwxyz';\n const numbers = '1234567890';\n const charset = `${letters}${letters.toUpperCase()}${numbers}`;\n\n let R = '';\n\n for (let index = 0; index < length; index++) {\n R += randomCharacter(charset);\n }\n\n return R;\n}\n\n/**\n * Remove properties from an object\n */\nexport function omit<T extends PlainObject, K extends keyof T>(\n input: T,\n ...filter: K[]\n): Omit<T, K> {\n const output: any = {};\n\n for (const key in input) {\n /* istanbul ignore else */\n if ({}.hasOwnProperty.call(input, key)) {\n if (!filter.includes(key as unknown as K)) {\n output[key] = input[key];\n }\n }\n }\n\n return output as Omit<T, K>;\n}\n","import { CACHE_MAX_RETRIES, CACHE_NAME, STATUS } from './config';\nimport { request, sleep } from './helpers';\nimport { StorageItem } from './types';\n\nexport default class CacheStore {\n private cacheApi: Cache | undefined;\n private readonly cacheStore: Map<string, StorageItem>;\n private readonly subscribers: Array<() => void> = [];\n private readonly usePersistentCache: boolean;\n public isReady = false;\n\n constructor() {\n this.cacheStore = new Map<string, StorageItem>();\n\n this.usePersistentCache =\n 'REACT_INLINESVG_PERSISTENT_CACHE' in window && !!window.REACT_INLINESVG_PERSISTENT_CACHE;\n\n if (this.usePersistentCache) {\n caches.open(CACHE_NAME).then(cache => {\n this.cacheApi = cache;\n this.isReady = true;\n\n this.subscribers.forEach(callback => callback());\n });\n } else {\n this.isReady = true;\n }\n }\n\n public onReady(callback: () => void) {\n if (this.isReady) {\n callback();\n } else {\n this.subscribers.push(callback);\n }\n }\n\n public async get(url: string, fetchOptions?: RequestInit) {\n await (this.usePersistentCache\n ? this.fetchAndAddToPersistentCache(url, fetchOptions)\n : this.fetchAndAddToInternalCache(url, fetchOptions));\n\n return this.cacheStore.get(url)?.content ?? '';\n }\n\n public set(url: string, data: StorageItem) {\n this.cacheStore.set(url, data);\n }\n\n public isCached(url: string) {\n return this.cacheStore.get(url)?.status === STATUS.LOADED;\n }\n\n private async fetchAndAddToInternalCache(url: string, fetchOptions?: RequestInit) {\n const cache = this.cacheStore.get(url);\n\n if (cache?.status === STATUS.LOADING) {\n await this.handleLoading(url, async () => {\n this.cacheStore.set(url, { content: '', status: STATUS.IDLE });\n await this.fetchAndAddToInternalCache(url, fetchOptions);\n });\n\n return;\n }\n\n if (!cache?.content) {\n this.cacheStore.set(url, { content: '', status: STATUS.LOADING });\n\n try {\n const content = await request(url, fetchOptions);\n\n this.cacheStore.set(url, { content, status: STATUS.LOADED });\n } catch (error: any) {\n this.cacheStore.set(url, { content: '', status: STATUS.FAILED });\n throw error;\n }\n }\n }\n\n private async fetchAndAddToPersistentCache(url: string, fetchOptions?: RequestInit) {\n const cache = this.cacheStore.get(url);\n\n if (cache?.status === STATUS.LOADED) {\n return;\n }\n\n if (cache?.status === STATUS.LOADING) {\n await this.handleLoading(url, async () => {\n this.cacheStore.set(url, { content: '', status: STATUS.IDLE });\n await this.fetchAndAddToPersistentCache(url, fetchOptions);\n });\n\n return;\n }\n\n this.cacheStore.set(url, { content: '', status: STATUS.LOADING });\n\n const data = await this.cacheApi?.match(url);\n\n if (data) {\n const content = await data.text();\n\n this.cacheStore.set(url, { content, status: STATUS.LOADED });\n\n return;\n }\n\n try {\n await this.cacheApi?.add(new Request(url, fetchOptions));\n\n const response = await this.cacheApi?.match(url);\n const content = (await response?.text()) ?? '';\n\n this.cacheStore.set(url, { content, status: STATUS.LOADED });\n } catch (error: any) {\n this.cacheStore.set(url, { content: '', status: STATUS.FAILED });\n throw error;\n }\n }\n\n private async handleLoading(url: string, callback: () => Promise<void>) {\n let retryCount = 0;\n\n // eslint-disable-next-line no-await-in-loop\n while (this.cacheStore.get(url)?.status === STATUS.LOADING && retryCount < CACHE_MAX_RETRIES) {\n // eslint-disable-next-line no-await-in-loop\n await sleep(0.1);\n retryCount += 1;\n }\n\n if (retryCount >= CACHE_MAX_RETRIES) {\n await callback();\n }\n }\n\n public keys(): Array<string> {\n return [...this.cacheStore.keys()];\n }\n\n public data(): Array<Record<string, StorageItem>> {\n return [...this.cacheStore.entries()].map(([key, value]) => ({ [key]: value }));\n }\n\n public async delete(url: string) {\n if (this.cacheApi) {\n await this.cacheApi.delete(url);\n }\n\n this.cacheStore.delete(url);\n }\n\n public async clear() {\n if (this.cacheApi) {\n const keys = await this.cacheApi.keys();\n\n for (const key of keys) {\n // eslint-disable-next-line no-await-in-loop\n await this.cacheApi.delete(key);\n }\n }\n\n this.cacheStore.clear();\n }\n}\n"],"mappings":";;;;;;;;AAAA,YAAY,WAAW;AACvB,OAAO,aAAa;;;ACDb,IAAM,aAAa;AACnB,IAAM,oBAAoB;AAE1B,IAAM,SAAS;AAAA,EACpB,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,aAAa;AACf;;;ACVA,SAAS,aAAa,qBAAqB;AAIpC,SAAS,YAAqB;AACnC,SAAO;AACT;AAEO,SAAS,yBAAkC;AAChD,SAAO,kBAAkB,KAAK,OAAO,WAAW,eAAe,WAAW;AAC5E;AAEA,eAAsB,QAAQ,KAAa,SAAuB;AAChE,QAAM,WAAW,MAAM,MAAM,KAAK,OAAO;AACzC,QAAM,cAAc,SAAS,QAAQ,IAAI,cAAc;AACvD,QAAM,CAAC,QAAQ,KAAK,eAAe,IAAI,MAAM,OAAO;AAEpD,MAAI,SAAS,SAAS,KAAK;AACzB,UAAM,IAAI,MAAM,WAAW;AAAA,EAC7B;AAEA,MAAI,CAAC,CAAC,iBAAiB,YAAY,EAAE,KAAK,OAAK,SAAS,SAAS,CAAC,CAAC,GAAG;AACpE,UAAM,IAAI,MAAM,6BAA6B,QAAQ,EAAE;AAAA,EACzD;AAEA,SAAO,SAAS,KAAK;AACvB;AAEO,SAAS,MAAM,UAAU,GAAG;AACjC,SAAO,IAAI,QAAQ,aAAW;AAC5B,eAAW,SAAS,UAAU,GAAI;AAAA,EACpC,C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AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAEA,QAAI,CAAC,UAAU,GAAG;AAChB,aAAO;AAAA,IACT;AAEA,QAAI,SAAS;AACX,aAAa,mBAAa,SAA+B,EAAE,KAAK,UAAU,GAAG,aAAa,CAAC;AAAA,IAC7F;AAEA,QAAK,CAAC,OAAO,aAAa,OAAO,MAAM,EAAe,SAAS,MAAM,GAAG;AACtE,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AACF;AA5TE,cALI,gBAKU,gBAAe;AAAA,EAC3B,eAAe;AAAA,EACf,aAAa;AACf;AA2Ta,SAAR,UAA2B,OAAc;AAC9C,MAAI,CAAC,YAAY;AACf,iBAAa,IAAI,WAAW;AAAA,EAC9B;AAEA,QAAM,EAAE,OAAO,IAAI;AACnB,QAAM,CAAC,SAAS,QAAQ,IAAU,eAAS,WAAW,OAAO;AAE7D,EAAM,gBAAU,MAAM;AACpB,QAAI,CAAC,SAAS;AACZ,iBAAW,QAAQ,MAAM;AACvB,iBAAS,IAAI;AAAA,MACf,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,MAAI,CAAC,SAAS;AACZ,WAAO,UAAU;AAAA,EACnB;AAEA,SAAO,oBAAC,kBAAgB,GAAG,OAAO;AACpC;","names":[]}
@@ -0,0 +1,13 @@
1
+ import { ReactNode } from 'react';
2
+
3
+ interface Props {
4
+ children: ReactNode;
5
+ }
6
+ declare global {
7
+ interface Window {
8
+ REACT_INLINESVG_PERSISTENT_CACHE?: boolean;
9
+ }
10
+ }
11
+ declare function CacheProvider({ children }: Props): ReactNode;
12
+
13
+ export { CacheProvider as default };
@@ -0,0 +1,13 @@
1
+ import { ReactNode } from 'react';
2
+
3
+ interface Props {
4
+ children: ReactNode;
5
+ }
6
+ declare global {
7
+ interface Window {
8
+ REACT_INLINESVG_PERSISTENT_CACHE?: boolean;
9
+ }
10
+ }
11
+ declare function CacheProvider({ children }: Props): ReactNode;
12
+
13
+ export { CacheProvider as default };