iconly 1.5.2-dev.4 → 1.5.2-dev.7
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.
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.es.js +36 -32
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var g=Object.defineProperty;var h=(d,r,e)=>r in d?g(d,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[r]=e;var l=(d,r,e)=>h(d,typeof r!="symbol"?r+"":r,e);const a=class a{constructor(r={}){l(this,"options");l(this,"container");const e={file:"./icons.svg",version:"1.0",debug:!1,container:document.body??document.documentElement,...r};let
|
|
1
|
+
"use strict";var g=Object.defineProperty;var h=(d,r,e)=>r in d?g(d,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[r]=e;var l=(d,r,e)=>h(d,typeof r!="symbol"?r+"":r,e);const a=class a{constructor(r={}){l(this,"options");l(this,"container");const e={file:"./icons.svg",version:"1.0",debug:!1,container:document.body??document.documentElement,...r};let n;if(typeof e.container=="string"){const i=document.querySelector(e.container);if(!(i&&i instanceof HTMLElement))throw new Error(`Invalid container selector: "${e.container}"`);n=i}else n=e.container;this.container=n,this.options={file:e.file,version:e.version,debug:e.debug},a.dbInstance||(a.dbInstance=this.openDB("iconlyDB",1))}async openDB(r,e){if(!("indexedDB"in window))throw this.logError("This browser does not support IndexedDB"),new Error("IndexedDB not supported");return await new Promise((n,i)=>{const o=indexedDB.open(r,e);o.onerror=()=>{const s=this.createErrorMessage(o.error,"IndexedDB error");i(new Error(s))},o.onupgradeneeded=s=>{const t=s.target.result;t.objectStoreNames.contains("icons")||t.createObjectStore("icons",{keyPath:"version"})},o.onsuccess=()=>{n(o.result)}})}getIconStore(r,e){return r.transaction("icons",e).objectStore("icons")}static async fetchData(r){const e=await fetch(r);if(!e.ok)throw new Error(`Failed to fetch icons from "${r}"`);return e.text()}insert(r){let e=document.getElementById("iconset");e||(e=document.createElement("div"),e.id="iconset",e.setAttribute("aria-hidden","true"),e.style.cssText="width: 0; height: 0; position: absolute; left: -9999px;",this.container.appendChild(e));const n=new DOMParser().parseFromString(r,"image/svg+xml"),i=n.querySelector("parsererror");if(i)return void this.logError("SVG parsing error:",i.textContent??"");e.innerHTML="";const o=n.documentElement;if(o){const s=document.importNode(o,!0);e.appendChild(s)}else this.logError("No valid SVG content found to insert.")}async init(){try{let r=await a.fetchData(this.options.file);const e=await a.dbInstance;if(!e)throw new Error("Failed to open IndexedDB");const n=this.getIconStore(e,"readwrite"),i=await new Promise((o,s)=>{const t=n.get(this.options.version);t.onsuccess=()=>{o(t.result)},t.onerror=()=>{const c=this.createErrorMessage(t.error,"Error getting record from store");s(new Error(c))}});i?r=i.data:await new Promise((o,s)=>{const t=n.put({version:this.options.version,data:r});t.onsuccess=()=>o(),t.onerror=()=>{const c=this.createErrorMessage(t.error,"Error putting record into store");s(new Error(c))}}),await new Promise((o,s)=>{const t=n.transaction;t.oncomplete=()=>o(),t.onerror=()=>{const c=this.createErrorMessage(t.error,"Transaction error");s(new Error(c))},t.onabort=()=>{const c=this.createErrorMessage(t.error,"Transaction aborted");s(new Error(c))}}),this.insert(r),this.logDebug("Iconly has successfully initialized.")}catch(r){const e=r instanceof Error?r:new Error(String(r));this.logError("Error initializing Iconly:",e.message)}}createErrorMessage(r,e){return r&&(r instanceof DOMException||r instanceof Error)&&r.message||e}logDebug(...r){this.options.debug}logError(...r){}};l(a,"dbInstance",null);let u=a;module.exports=u;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface IconRecord {
|
|
|
8
8
|
version: string;
|
|
9
9
|
data: string;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
declare class Iconly {
|
|
12
12
|
private static dbInstance;
|
|
13
13
|
private readonly options;
|
|
14
14
|
private readonly container;
|
|
@@ -22,3 +22,4 @@ export default class Iconly {
|
|
|
22
22
|
private logDebug;
|
|
23
23
|
private logError;
|
|
24
24
|
}
|
|
25
|
+
export default Iconly;
|
package/dist/index.es.js
CHANGED
|
@@ -6,26 +6,26 @@ const a = class a {
|
|
|
6
6
|
l(this, "options");
|
|
7
7
|
l(this, "container");
|
|
8
8
|
const e = { file: "./icons.svg", version: "1.0", debug: !1, container: document.body ?? document.documentElement, ...r };
|
|
9
|
-
let
|
|
9
|
+
let n;
|
|
10
10
|
if (typeof e.container == "string") {
|
|
11
|
-
const
|
|
12
|
-
if (!(
|
|
13
|
-
|
|
14
|
-
} else
|
|
15
|
-
this.container =
|
|
11
|
+
const i = document.querySelector(e.container);
|
|
12
|
+
if (!(i && i instanceof HTMLElement)) throw new Error(`Invalid container selector: "${e.container}"`);
|
|
13
|
+
n = i;
|
|
14
|
+
} else n = e.container;
|
|
15
|
+
this.container = n, this.options = { file: e.file, version: e.version, debug: e.debug }, a.dbInstance || (a.dbInstance = this.openDB("iconlyDB", 1));
|
|
16
16
|
}
|
|
17
17
|
async openDB(r, e) {
|
|
18
18
|
if (!("indexedDB" in window)) throw this.logError("This browser does not support IndexedDB"), new Error("IndexedDB not supported");
|
|
19
|
-
return await new Promise((
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
const t =
|
|
19
|
+
return await new Promise((n, i) => {
|
|
20
|
+
const o = indexedDB.open(r, e);
|
|
21
|
+
o.onerror = () => {
|
|
22
|
+
const s = this.createErrorMessage(o.error, "IndexedDB error");
|
|
23
|
+
i(new Error(s));
|
|
24
|
+
}, o.onupgradeneeded = (s) => {
|
|
25
|
+
const t = s.target.result;
|
|
26
26
|
t.objectStoreNames.contains("icons") || t.createObjectStore("icons", { keyPath: "version" });
|
|
27
|
-
},
|
|
28
|
-
o
|
|
27
|
+
}, o.onsuccess = () => {
|
|
28
|
+
n(o.result);
|
|
29
29
|
};
|
|
30
30
|
});
|
|
31
31
|
}
|
|
@@ -40,39 +40,43 @@ const a = class a {
|
|
|
40
40
|
insert(r) {
|
|
41
41
|
let e = document.getElementById("iconset");
|
|
42
42
|
e || (e = document.createElement("div"), e.id = "iconset", e.setAttribute("aria-hidden", "true"), e.style.cssText = "width: 0; height: 0; position: absolute; left: -9999px;", this.container.appendChild(e));
|
|
43
|
-
const
|
|
44
|
-
|
|
43
|
+
const n = new DOMParser().parseFromString(r, "image/svg+xml"), i = n.querySelector("parsererror");
|
|
44
|
+
if (i) return void this.logError("SVG parsing error:", i.textContent ?? "");
|
|
45
|
+
e.innerHTML = "";
|
|
46
|
+
const o = n.documentElement;
|
|
47
|
+
if (o) {
|
|
48
|
+
const s = document.importNode(o, !0);
|
|
49
|
+
e.appendChild(s);
|
|
50
|
+
} else this.logError("No valid SVG content found to insert.");
|
|
45
51
|
}
|
|
46
52
|
async init() {
|
|
47
53
|
try {
|
|
48
54
|
let r = await a.fetchData(this.options.file);
|
|
49
55
|
const e = await a.dbInstance;
|
|
50
56
|
if (!e) throw new Error("Failed to open IndexedDB");
|
|
51
|
-
const
|
|
52
|
-
const t =
|
|
57
|
+
const n = this.getIconStore(e, "readwrite"), i = await new Promise((o, s) => {
|
|
58
|
+
const t = n.get(this.options.version);
|
|
53
59
|
t.onsuccess = () => {
|
|
54
|
-
|
|
60
|
+
o(t.result);
|
|
55
61
|
}, t.onerror = () => {
|
|
56
62
|
const c = this.createErrorMessage(t.error, "Error getting record from store");
|
|
57
|
-
|
|
63
|
+
s(new Error(c));
|
|
58
64
|
};
|
|
59
65
|
});
|
|
60
|
-
|
|
61
|
-
const t =
|
|
62
|
-
t.onsuccess = () => {
|
|
63
|
-
s();
|
|
64
|
-
}, t.onerror = () => {
|
|
66
|
+
i ? r = i.data : await new Promise((o, s) => {
|
|
67
|
+
const t = n.put({ version: this.options.version, data: r });
|
|
68
|
+
t.onsuccess = () => o(), t.onerror = () => {
|
|
65
69
|
const c = this.createErrorMessage(t.error, "Error putting record into store");
|
|
66
|
-
|
|
70
|
+
s(new Error(c));
|
|
67
71
|
};
|
|
68
|
-
}), await new Promise((
|
|
69
|
-
const t =
|
|
70
|
-
t.oncomplete = () =>
|
|
72
|
+
}), await new Promise((o, s) => {
|
|
73
|
+
const t = n.transaction;
|
|
74
|
+
t.oncomplete = () => o(), t.onerror = () => {
|
|
71
75
|
const c = this.createErrorMessage(t.error, "Transaction error");
|
|
72
|
-
|
|
76
|
+
s(new Error(c));
|
|
73
77
|
}, t.onabort = () => {
|
|
74
78
|
const c = this.createErrorMessage(t.error, "Transaction aborted");
|
|
75
|
-
|
|
79
|
+
s(new Error(c));
|
|
76
80
|
};
|
|
77
81
|
}), this.insert(r), this.logDebug("Iconly has successfully initialized.");
|
|
78
82
|
} catch (r) {
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(s,t){typeof exports=="object"&&typeof module<"u"?module.exports=t():typeof define=="function"&&define.amd?define(t):(s=typeof globalThis<"u"?globalThis:s||self).Iconly=t()})(this,function(){"use strict";var g=Object.defineProperty;var h=(s,t,l)=>t in s?g(s,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):s[t]=l;var u=(s,t,l)=>h(s,typeof t!="symbol"?t+"":t,l);const t=class t{constructor(r={}){u(this,"options");u(this,"container");const e={file:"./icons.svg",version:"1.0",debug:!1,container:document.body??document.documentElement,...r};let
|
|
1
|
+
(function(s,t){typeof exports=="object"&&typeof module<"u"?module.exports=t():typeof define=="function"&&define.amd?define(t):(s=typeof globalThis<"u"?globalThis:s||self).Iconly=t()})(this,function(){"use strict";var g=Object.defineProperty;var h=(s,t,l)=>t in s?g(s,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):s[t]=l;var u=(s,t,l)=>h(s,typeof t!="symbol"?t+"":t,l);const t=class t{constructor(r={}){u(this,"options");u(this,"container");const e={file:"./icons.svg",version:"1.0",debug:!1,container:document.body??document.documentElement,...r};let i;if(typeof e.container=="string"){const a=document.querySelector(e.container);if(!(a&&a instanceof HTMLElement))throw new Error(`Invalid container selector: "${e.container}"`);i=a}else i=e.container;this.container=i,this.options={file:e.file,version:e.version,debug:e.debug},t.dbInstance||(t.dbInstance=this.openDB("iconlyDB",1))}async openDB(r,e){if(!("indexedDB"in window))throw this.logError("This browser does not support IndexedDB"),new Error("IndexedDB not supported");return await new Promise((i,a)=>{const n=indexedDB.open(r,e);n.onerror=()=>{const c=this.createErrorMessage(n.error,"IndexedDB error");a(new Error(c))},n.onupgradeneeded=c=>{const o=c.target.result;o.objectStoreNames.contains("icons")||o.createObjectStore("icons",{keyPath:"version"})},n.onsuccess=()=>{i(n.result)}})}getIconStore(r,e){return r.transaction("icons",e).objectStore("icons")}static async fetchData(r){const e=await fetch(r);if(!e.ok)throw new Error(`Failed to fetch icons from "${r}"`);return e.text()}insert(r){let e=document.getElementById("iconset");e||(e=document.createElement("div"),e.id="iconset",e.setAttribute("aria-hidden","true"),e.style.cssText="width: 0; height: 0; position: absolute; left: -9999px;",this.container.appendChild(e));const i=new DOMParser().parseFromString(r,"image/svg+xml"),a=i.querySelector("parsererror");if(a)return void this.logError("SVG parsing error:",a.textContent??"");e.innerHTML="";const n=i.documentElement;if(n){const c=document.importNode(n,!0);e.appendChild(c)}else this.logError("No valid SVG content found to insert.")}async init(){try{let r=await t.fetchData(this.options.file);const e=await t.dbInstance;if(!e)throw new Error("Failed to open IndexedDB");const i=this.getIconStore(e,"readwrite"),a=await new Promise((n,c)=>{const o=i.get(this.options.version);o.onsuccess=()=>{n(o.result)},o.onerror=()=>{const d=this.createErrorMessage(o.error,"Error getting record from store");c(new Error(d))}});a?r=a.data:await new Promise((n,c)=>{const o=i.put({version:this.options.version,data:r});o.onsuccess=()=>n(),o.onerror=()=>{const d=this.createErrorMessage(o.error,"Error putting record into store");c(new Error(d))}}),await new Promise((n,c)=>{const o=i.transaction;o.oncomplete=()=>n(),o.onerror=()=>{const d=this.createErrorMessage(o.error,"Transaction error");c(new Error(d))},o.onabort=()=>{const d=this.createErrorMessage(o.error,"Transaction aborted");c(new Error(d))}}),this.insert(r),this.logDebug("Iconly has successfully initialized.")}catch(r){const e=r instanceof Error?r:new Error(String(r));this.logError("Error initializing Iconly:",e.message)}}createErrorMessage(r,e){return r&&(r instanceof DOMException||r instanceof Error)&&r.message||e}logDebug(...r){this.options.debug}logError(...r){}};u(t,"dbInstance",null);let s=t;return s});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "iconly",
|
|
3
|
-
"version": "1.5.2-dev.
|
|
3
|
+
"version": "1.5.2-dev.7",
|
|
4
4
|
"description": "Iconly is designed to load and cache SVG icons in the browser, using IndexedDB to store the data. It retrieves the icons from a given SVG file, stores them in IndexedDB, and inserts them into the DOM for easy access and use.",
|
|
5
5
|
"author": "ux-ui.pro",
|
|
6
6
|
"license": "MIT",
|