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 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 o;if(typeof e.container=="string"){const n=document.querySelector(e.container);if(!(n&&n instanceof HTMLElement))throw new Error(`Invalid container selector: "${e.container}"`);o=n}else o=e.container;this.container=o,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((o,n)=>{const s=indexedDB.open(r,e);s.onerror=()=>{const i=this.createErrorMessage(s.error,"IndexedDB error");n(new Error(i))},s.onupgradeneeded=i=>{const t=i.target.result;t.objectStoreNames.contains("icons")||t.createObjectStore("icons",{keyPath:"version"})},s.onsuccess=()=>{o(s.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 o=new DOMParser().parseFromString(r,"image/svg+xml"),n=o.querySelector("parsererror");n?this.logError("SVG parsing error:",n.textContent??""):(e.innerHTML="",o.documentElement?e.appendChild(o.documentElement):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 o=this.getIconStore(e,"readwrite"),n=await new Promise((s,i)=>{const t=o.get(this.options.version);t.onsuccess=()=>{s(t.result)},t.onerror=()=>{const c=this.createErrorMessage(t.error,"Error getting record from store");i(new Error(c))}});n?r=n.data:await new Promise((s,i)=>{const t=o.put({version:this.options.version,data:r});t.onsuccess=()=>{s()},t.onerror=()=>{const c=this.createErrorMessage(t.error,"Error putting record into store");i(new Error(c))}}),await new Promise((s,i)=>{const t=o.transaction;t.oncomplete=()=>s(),t.onerror=()=>{const c=this.createErrorMessage(t.error,"Transaction error");i(new Error(c))},t.onabort=()=>{const c=this.createErrorMessage(t.error,"Transaction aborted");i(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;
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
- export default class Iconly {
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 o;
9
+ let n;
10
10
  if (typeof e.container == "string") {
11
- const n = document.querySelector(e.container);
12
- if (!(n && n instanceof HTMLElement)) throw new Error(`Invalid container selector: "${e.container}"`);
13
- o = n;
14
- } else o = e.container;
15
- this.container = o, this.options = { file: e.file, version: e.version, debug: e.debug }, a.dbInstance || (a.dbInstance = this.openDB("iconlyDB", 1));
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((o, n) => {
20
- const s = indexedDB.open(r, e);
21
- s.onerror = () => {
22
- const i = this.createErrorMessage(s.error, "IndexedDB error");
23
- n(new Error(i));
24
- }, s.onupgradeneeded = (i) => {
25
- const t = i.target.result;
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
- }, s.onsuccess = () => {
28
- o(s.result);
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 o = new DOMParser().parseFromString(r, "image/svg+xml"), n = o.querySelector("parsererror");
44
- n ? this.logError("SVG parsing error:", n.textContent ?? "") : (e.innerHTML = "", o.documentElement ? e.appendChild(o.documentElement) : this.logError("No valid SVG content found to insert."));
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 o = this.getIconStore(e, "readwrite"), n = await new Promise((s, i) => {
52
- const t = o.get(this.options.version);
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
- s(t.result);
60
+ o(t.result);
55
61
  }, t.onerror = () => {
56
62
  const c = this.createErrorMessage(t.error, "Error getting record from store");
57
- i(new Error(c));
63
+ s(new Error(c));
58
64
  };
59
65
  });
60
- n ? r = n.data : await new Promise((s, i) => {
61
- const t = o.put({ version: this.options.version, data: r });
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
- i(new Error(c));
70
+ s(new Error(c));
67
71
  };
68
- }), await new Promise((s, i) => {
69
- const t = o.transaction;
70
- t.oncomplete = () => s(), t.onerror = () => {
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
- i(new Error(c));
76
+ s(new Error(c));
73
77
  }, t.onabort = () => {
74
78
  const c = this.createErrorMessage(t.error, "Transaction aborted");
75
- i(new Error(c));
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 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},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((n,i)=>{const c=indexedDB.open(r,e);c.onerror=()=>{const a=this.createErrorMessage(c.error,"IndexedDB error");i(new Error(a))},c.onupgradeneeded=a=>{const o=a.target.result;o.objectStoreNames.contains("icons")||o.createObjectStore("icons",{keyPath:"version"})},c.onsuccess=()=>{n(c.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");i?this.logError("SVG parsing error:",i.textContent??""):(e.innerHTML="",n.documentElement?e.appendChild(n.documentElement):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 n=this.getIconStore(e,"readwrite"),i=await new Promise((c,a)=>{const o=n.get(this.options.version);o.onsuccess=()=>{c(o.result)},o.onerror=()=>{const d=this.createErrorMessage(o.error,"Error getting record from store");a(new Error(d))}});i?r=i.data:await new Promise((c,a)=>{const o=n.put({version:this.options.version,data:r});o.onsuccess=()=>{c()},o.onerror=()=>{const d=this.createErrorMessage(o.error,"Error putting record into store");a(new Error(d))}}),await new Promise((c,a)=>{const o=n.transaction;o.oncomplete=()=>c(),o.onerror=()=>{const d=this.createErrorMessage(o.error,"Transaction error");a(new Error(d))},o.onabort=()=>{const d=this.createErrorMessage(o.error,"Transaction aborted");a(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});
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.4",
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",