iconly 1.5.1 → 1.5.2-dev.1

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
+ "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);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});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;exports.Iconly=u;
package/dist/index.d.ts CHANGED
@@ -1,12 +1,30 @@
1
- export default class Iconly {
2
- constructor(options?: {
3
- file?: string;
4
- version?: string;
5
- debug?: boolean;
6
- container?: string | HTMLElement;
7
- });
1
+ export interface IconlyOptions {
2
+ file?: string;
3
+ version?: string;
4
+ debug?: boolean;
5
+ container?: string | HTMLElement;
6
+ }
7
+ export interface IconRecord {
8
+ version: string;
9
+ data: string;
10
+ }
11
+ export declare class Iconly {
12
+ private static dbInstance;
13
+ /**
14
+ * Остальные поля из IconlyOptions (file, version, debug), "разрешённые" (не optional)
15
+ */
16
+ private readonly options;
17
+ /**
18
+ * Здесь храним итоговый контейнер. Он точно HTMLElement.
19
+ */
20
+ private readonly container;
21
+ constructor(options?: IconlyOptions);
22
+ private openDB;
23
+ private getIconStore;
24
+ private static fetchData;
25
+ private insert;
8
26
  init(): Promise<void>;
27
+ private createErrorMessage;
28
+ private logDebug;
29
+ private logError;
9
30
  }
10
- export default Iconly;
11
-
12
- //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,96 @@
1
+ var u = Object.defineProperty;
2
+ var h = (d, r, e) => r in d ? u(d, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : d[r] = e;
3
+ var l = (d, r, e) => h(d, typeof r != "symbol" ? r + "" : r, e);
4
+ const a = class a {
5
+ constructor(r = {}) {
6
+ l(this, "options");
7
+ l(this, "container");
8
+ const e = { file: "./icons.svg", version: "1.0", debug: !1, container: document.body ?? document.documentElement, ...r };
9
+ let o;
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));
16
+ }
17
+ async openDB(r, e) {
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;
26
+ t.objectStoreNames.contains("icons") || t.createObjectStore("icons", { keyPath: "version" });
27
+ }, s.onsuccess = () => {
28
+ o(s.result);
29
+ };
30
+ });
31
+ }
32
+ getIconStore(r, e) {
33
+ return r.transaction("icons", e).objectStore("icons");
34
+ }
35
+ static async fetchData(r) {
36
+ const e = await fetch(r);
37
+ if (!e.ok) throw new Error(`Failed to fetch icons from "${r}"`);
38
+ return e.text();
39
+ }
40
+ insert(r) {
41
+ let e = document.getElementById("iconset");
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."));
45
+ }
46
+ async init() {
47
+ try {
48
+ let r = await a.fetchData(this.options.file);
49
+ const e = await a.dbInstance;
50
+ 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);
53
+ t.onsuccess = () => {
54
+ s(t.result);
55
+ }, t.onerror = () => {
56
+ const c = this.createErrorMessage(t.error, "Error getting record from store");
57
+ i(new Error(c));
58
+ };
59
+ });
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 = () => {
65
+ const c = this.createErrorMessage(t.error, "Error putting record into store");
66
+ i(new Error(c));
67
+ };
68
+ }), await new Promise((s, i) => {
69
+ const t = o.transaction;
70
+ t.oncomplete = () => s(), t.onerror = () => {
71
+ const c = this.createErrorMessage(t.error, "Transaction error");
72
+ i(new Error(c));
73
+ }, t.onabort = () => {
74
+ const c = this.createErrorMessage(t.error, "Transaction aborted");
75
+ i(new Error(c));
76
+ };
77
+ }), this.insert(r), this.logDebug("Iconly has successfully initialized.");
78
+ } catch (r) {
79
+ const e = r instanceof Error ? r : new Error(String(r));
80
+ this.logError("Error initializing Iconly:", e.message);
81
+ }
82
+ }
83
+ createErrorMessage(r, e) {
84
+ return r && (r instanceof DOMException || r instanceof Error) && r.message || e;
85
+ }
86
+ logDebug(...r) {
87
+ this.options.debug;
88
+ }
89
+ logError(...r) {
90
+ }
91
+ };
92
+ l(a, "dbInstance", null);
93
+ let g = a;
94
+ export {
95
+ g as Iconly
96
+ };
@@ -0,0 +1 @@
1
+ (function(i,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):o((i=typeof globalThis<"u"?globalThis:i||self).Iconly={})})(this,function(i){"use strict";var g=Object.defineProperty;var h=(i,o,s)=>o in i?g(i,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):i[o]=s;var u=(i,o,s)=>h(i,typeof o!="symbol"?o+"":o,s);const s=class s{constructor(t={}){u(this,"options");u(this,"container");const e={file:"./icons.svg",version:"1.0",debug:!1,container:document.body??document.documentElement,...t};let n;if(typeof e.container=="string"){const c=document.querySelector(e.container);if(!(c&&c instanceof HTMLElement))throw new Error(`Invalid container selector: "${e.container}"`);n=c}else n=e.container;this.container=n,this.options={file:e.file,version:e.version,debug:e.debug},s.dbInstance||(s.dbInstance=this.openDB("iconlyDB",1))}async openDB(t,e){if(!("indexedDB"in window))throw this.logError("This browser does not support IndexedDB"),new Error("IndexedDB not supported");return await new Promise((n,c)=>{const a=indexedDB.open(t,e);a.onerror=()=>{const d=this.createErrorMessage(a.error,"IndexedDB error");c(new Error(d))},a.onupgradeneeded=d=>{const r=d.target.result;r.objectStoreNames.contains("icons")||r.createObjectStore("icons",{keyPath:"version"})},a.onsuccess=()=>{n(a.result)}})}getIconStore(t,e){return t.transaction("icons",e).objectStore("icons")}static async fetchData(t){const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch icons from "${t}"`);return e.text()}insert(t){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(t,"image/svg+xml"),c=n.querySelector("parsererror");c?this.logError("SVG parsing error:",c.textContent??""):(e.innerHTML="",n.documentElement?e.appendChild(n.documentElement):this.logError("No valid SVG content found to insert."))}async init(){try{let t=await s.fetchData(this.options.file);const e=await s.dbInstance;if(!e)throw new Error("Failed to open IndexedDB");const n=this.getIconStore(e,"readwrite"),c=await new Promise((a,d)=>{const r=n.get(this.options.version);r.onsuccess=()=>{a(r.result)},r.onerror=()=>{const l=this.createErrorMessage(r.error,"Error getting record from store");d(new Error(l))}});c?t=c.data:await new Promise((a,d)=>{const r=n.put({version:this.options.version,data:t});r.onsuccess=()=>{a()},r.onerror=()=>{const l=this.createErrorMessage(r.error,"Error putting record into store");d(new Error(l))}}),await new Promise((a,d)=>{const r=n.transaction;r.oncomplete=()=>a(),r.onerror=()=>{const l=this.createErrorMessage(r.error,"Transaction error");d(new Error(l))},r.onabort=()=>{const l=this.createErrorMessage(r.error,"Transaction aborted");d(new Error(l))}}),this.insert(t),this.logDebug("Iconly has successfully initialized.")}catch(t){const e=t instanceof Error?t:new Error(String(t));this.logError("Error initializing Iconly:",e.message)}}createErrorMessage(t,e){return t&&(t instanceof DOMException||t instanceof Error)&&t.message||e}logDebug(...t){this.options.debug}logError(...t){}};u(s,"dbInstance",null);let o=s;i.Iconly=o,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "iconly",
3
- "version": "1.5.1",
3
+ "version": "1.5.2-dev.1",
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",
@@ -14,26 +14,42 @@
14
14
  "homepage": "https://github.com/ux-ui-pro/iconly",
15
15
  "sideEffects": false,
16
16
  "scripts": {
17
- "clean": "rm -rf dist .parcel-cache",
18
- "build": "yarn clean && parcel build",
17
+ "clean": "rimraf dist",
18
+ "build": "vite build",
19
19
  "lint:js": "eslint **/*.{ts,js}",
20
- "lintfix": "yarn lint:js --fix"
20
+ "lint:fix:js": "eslint **/*.{ts,js} --fix",
21
+ "format:js": "prettier --write **/*.{ts,js}",
22
+ "lint:fix": "yarn lint:fix:js && yarn format:js"
21
23
  },
22
- "browserslist": "> 0.5%, last 2 versions, not dead",
23
24
  "source": "src/index.ts",
24
- "main": "dist/index.js",
25
- "module": "dist/index.module.js",
25
+ "main": "dist/index.cjs.js",
26
+ "module": "dist/index.es.js",
27
+ "browser": "./dist/index.umd.js",
26
28
  "types": "dist/index.d.ts",
29
+ "exports": {
30
+ "require": "./dist/index.cjs.js",
31
+ "import": "./dist/index.es.js",
32
+ "default": "./dist/index.umd.js"
33
+ },
34
+ "files": [
35
+ "dist/"
36
+ ],
27
37
  "devDependencies": {
28
- "@parcel/packager-ts": "2.12.0",
29
- "@parcel/transformer-typescript-types": "2.12.0",
30
- "@typescript-eslint/eslint-plugin": "^7.11.0",
31
- "@typescript-eslint/parser": "^7.11.0",
32
- "eslint": "^7.32.0 || ^8.57.0",
33
- "eslint-config-airbnb-base": "^15.0.0",
34
- "eslint-plugin-import": "^2.29.1",
35
- "parcel": "^2.12.0",
36
- "typescript": "^5.4.5"
38
+ "@eslint/js": "9.21.0",
39
+ "@rollup/plugin-terser": "0.4.4",
40
+ "@types/node": "22.13.8",
41
+ "@typescript-eslint/eslint-plugin": "8.25.0",
42
+ "@typescript-eslint/parser": "8.25.0",
43
+ "eslint": "9.18.0",
44
+ "eslint-config-prettier": "10.0.2",
45
+ "eslint-import-resolver-typescript": "3.8.3",
46
+ "eslint-plugin-import": "2.31.0",
47
+ "globals": "16.0.0",
48
+ "prettier": "3.5.2",
49
+ "rimraf": "6.0.1",
50
+ "typescript": "5.8.2",
51
+ "vite": "6.2.0",
52
+ "vite-plugin-dts": "4.5.1"
37
53
  },
38
54
  "keywords": [
39
55
  "icon",
package/.eslintignore DELETED
@@ -1,3 +0,0 @@
1
- node_modules
2
- .parcel
3
- dist
package/.eslintrc.json DELETED
@@ -1,26 +0,0 @@
1
- {
2
- "env": {
3
- "browser": true,
4
- "es2022": true
5
- },
6
- "extends": [
7
- "airbnb-base",
8
- "plugin:@typescript-eslint/recommended"
9
- ],
10
- "parser": "@typescript-eslint/parser",
11
- "parserOptions": {
12
- "ecmaVersion": "latest",
13
- "sourceType": "module",
14
- "project": "./tsconfig.json"
15
- },
16
- "plugins": ["@typescript-eslint"],
17
- "rules": {
18
- "max-len": [
19
- "off",
20
- {
21
- "code": 100,
22
- "ignoreUrls": true
23
- }
24
- ]
25
- }
26
- }
@@ -1,37 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, ethnicity, level of experience, nationality, personal appearance, race, or religion.
6
-
7
- ## Our Standards
8
-
9
- Examples of behavior that contributes to creating a positive environment include:
10
-
11
- * Using welcoming language
12
- * Being respectful of differing viewpoints and experiences
13
- * Gracefully accepting constructive criticism
14
- * Focusing on what is best for the community
15
-
16
- Examples of unacceptable behavior by participants include:
17
-
18
- * Trolling, insulting/derogatory comments, and personal or political attacks
19
- * Public or private harassment
20
- * Publishing others' private information, such as a physical or electronic address, without explicit permission
21
- * Other conduct which could reasonably be considered inappropriate in a professional setting
22
-
23
- ## Our Responsibilities
24
-
25
- Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
26
-
27
- Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
28
-
29
- ## Scope
30
-
31
- This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
32
-
33
- ## Enforcement
34
-
35
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident.
36
-
37
- Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
@@ -1 +0,0 @@
1
- {"mappings":"AAAA,qBAAM,MAAM;gBAUE,OAAO,GAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,GAAG,WAAW,CAAA;KAAO;IAiE1G,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CA4C5B;AAED,eAAe,MAAM,CAAC","sources":["src/src/index.ts","src/index.ts"],"sourcesContent":[null,"class Iconly {\n private static dbInstance: Promise<IDBDatabase> | null = null;\n\n private readonly options: {\n file: string;\n version: string;\n debug: boolean;\n container: HTMLElement;\n };\n\n constructor(options: { file?: string; version?: string; debug?: boolean; container?: string | HTMLElement } = {}) {\n const defaultOptions = {\n file: './icons.svg',\n version: '1.0',\n debug: false,\n container: document.body ?? document.documentElement,\n };\n\n this.options = {\n ...defaultOptions,\n ...options,\n container: typeof options.container === 'string'\n ? document.querySelector(options.container) ?? defaultOptions.container\n : options.container ?? defaultOptions.container,\n };\n\n if (!this.options.container) {\n throw new Error('Invalid container element');\n }\n\n if (!Iconly.dbInstance) {\n Iconly.dbInstance = this.openDB('iconlyDB', 1);\n }\n }\n\n private async openDB(name: string, version: number): Promise<IDBDatabase> {\n if (!('indexedDB' in window)) {\n this.logError('This browser doesn\\'t support IndexedDB');\n throw new Error('IndexedDB not supported');\n }\n\n return new Promise<IDBDatabase>((resolve, reject) => {\n const request = indexedDB.open(name, version);\n\n request.onerror = () => reject(new Error(`IndexedDB error: ${request.error}`));\n request.onupgradeneeded = (event: IDBVersionChangeEvent) => {\n const db = (event.target as IDBOpenDBRequest).result;\n if (!db.objectStoreNames.contains('icons')) {\n db.createObjectStore('icons', { keyPath: 'version' });\n }\n };\n request.onsuccess = () => resolve(request.result);\n });\n }\n\n private static async fetchData(file: string): Promise<string> {\n const response = await fetch(file);\n if (!response.ok) throw new Error('Network response was not ok');\n return response.text();\n }\n\n private insert(data: string): void {\n let iconSetDiv = document.getElementById('iconset');\n\n if (!iconSetDiv) {\n iconSetDiv = document.createElement('div');\n iconSetDiv.id = 'iconset';\n iconSetDiv.setAttribute('aria-hidden', 'true');\n iconSetDiv.style.cssText = 'width: 0; height: 0; position: absolute; left: -9999px;';\n this.options.container.appendChild(iconSetDiv);\n }\n\n iconSetDiv.innerHTML = data;\n }\n\n async init(): Promise<void> {\n const { file, version } = this.options;\n\n try {\n let data = await Iconly.fetchData(file);\n\n const db = await Iconly.dbInstance;\n const store = db.transaction('icons', 'readwrite').objectStore('icons');\n\n const dbVersion = await new Promise<{ version: string; data: string } | undefined>((resolve, reject) => {\n const request = store.get(version);\n request.onsuccess = () => resolve(request.result);\n request.onerror = () => reject(request.error);\n });\n\n if (!dbVersion) {\n await new Promise<void>((resolve, reject) => {\n const request = store.put({ version, data });\n request.onsuccess = () => resolve();\n request.onerror = () => reject(request.error);\n });\n } else {\n data = dbVersion.data;\n }\n\n await new Promise<void>((resolve, reject) => {\n const tx = store.transaction;\n tx.oncomplete = () => resolve();\n tx.onerror = () => reject(tx.error);\n tx.onabort = () => reject(tx.error);\n });\n\n this.insert(data);\n } catch (error) {\n this.logError('Error initializing Iconly:', error);\n }\n }\n\n private logError(...messages: unknown[]): void {\n if (this.options.debug) {\n // eslint-disable-next-line no-console\n console.error(...messages);\n }\n }\n}\n\nexport default Iconly;\n"],"names":[],"version":3,"file":"index.d.ts.map"}
package/dist/index.js DELETED
@@ -1,103 +0,0 @@
1
-
2
- function $parcel$defineInteropFlag(a) {
3
- Object.defineProperty(a, '__esModule', {value: true, configurable: true});
4
- }
5
-
6
- function $parcel$export(e, n, v, s) {
7
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
8
- }
9
-
10
- $parcel$defineInteropFlag(module.exports);
11
-
12
- $parcel$export(module.exports, "default", function () { return $a196c1ed25598f0e$export$2e2bcd8739ae039; });
13
- class $a196c1ed25598f0e$var$Iconly {
14
- static dbInstance = null;
15
- options;
16
- constructor(options = {}){
17
- const defaultOptions = {
18
- file: "./icons.svg",
19
- version: "1.0",
20
- debug: false,
21
- container: document.body ?? document.documentElement
22
- };
23
- this.options = {
24
- ...defaultOptions,
25
- ...options,
26
- container: typeof options.container === "string" ? document.querySelector(options.container) ?? defaultOptions.container : options.container ?? defaultOptions.container
27
- };
28
- if (!this.options.container) throw new Error("Invalid container element");
29
- if (!$a196c1ed25598f0e$var$Iconly.dbInstance) $a196c1ed25598f0e$var$Iconly.dbInstance = this.openDB("iconlyDB", 1);
30
- }
31
- async openDB(name, version) {
32
- if (!("indexedDB" in window)) {
33
- this.logError("This browser doesn't support IndexedDB");
34
- throw new Error("IndexedDB not supported");
35
- }
36
- return new Promise((resolve, reject)=>{
37
- const request = indexedDB.open(name, version);
38
- request.onerror = ()=>reject(new Error(`IndexedDB error: ${request.error}`));
39
- request.onupgradeneeded = (event)=>{
40
- const db = event.target.result;
41
- if (!db.objectStoreNames.contains("icons")) db.createObjectStore("icons", {
42
- keyPath: "version"
43
- });
44
- };
45
- request.onsuccess = ()=>resolve(request.result);
46
- });
47
- }
48
- static async fetchData(file) {
49
- const response = await fetch(file);
50
- if (!response.ok) throw new Error("Network response was not ok");
51
- return response.text();
52
- }
53
- insert(data) {
54
- let iconSetDiv = document.getElementById("iconset");
55
- if (!iconSetDiv) {
56
- iconSetDiv = document.createElement("div");
57
- iconSetDiv.id = "iconset";
58
- iconSetDiv.setAttribute("aria-hidden", "true");
59
- iconSetDiv.style.cssText = "width: 0; height: 0; position: absolute; left: -9999px;";
60
- this.options.container.appendChild(iconSetDiv);
61
- }
62
- iconSetDiv.innerHTML = data;
63
- }
64
- async init() {
65
- const { file: file, version: version } = this.options;
66
- try {
67
- let data = await $a196c1ed25598f0e$var$Iconly.fetchData(file);
68
- const db = await $a196c1ed25598f0e$var$Iconly.dbInstance;
69
- const store = db.transaction("icons", "readwrite").objectStore("icons");
70
- const dbVersion = await new Promise((resolve, reject)=>{
71
- const request = store.get(version);
72
- request.onsuccess = ()=>resolve(request.result);
73
- request.onerror = ()=>reject(request.error);
74
- });
75
- if (!dbVersion) await new Promise((resolve, reject)=>{
76
- const request = store.put({
77
- version: version,
78
- data: data
79
- });
80
- request.onsuccess = ()=>resolve();
81
- request.onerror = ()=>reject(request.error);
82
- });
83
- else data = dbVersion.data;
84
- await new Promise((resolve, reject)=>{
85
- const tx = store.transaction;
86
- tx.oncomplete = ()=>resolve();
87
- tx.onerror = ()=>reject(tx.error);
88
- tx.onabort = ()=>reject(tx.error);
89
- });
90
- this.insert(data);
91
- } catch (error) {
92
- this.logError("Error initializing Iconly:", error);
93
- }
94
- }
95
- logError(...messages) {
96
- if (this.options.debug) // eslint-disable-next-line no-console
97
- console.error(...messages);
98
- }
99
- }
100
- var $a196c1ed25598f0e$export$2e2bcd8739ae039 = $a196c1ed25598f0e$var$Iconly;
101
-
102
-
103
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"mappings":"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","sources":["src/index.ts"],"sourcesContent":["class Iconly {\n private static dbInstance: Promise<IDBDatabase> | null = null;\n\n private readonly options: {\n file: string;\n version: string;\n debug: boolean;\n container: HTMLElement;\n };\n\n constructor(options: { file?: string; version?: string; debug?: boolean; container?: string | HTMLElement } = {}) {\n const defaultOptions = {\n file: './icons.svg',\n version: '1.0',\n debug: false,\n container: document.body ?? document.documentElement,\n };\n\n this.options = {\n ...defaultOptions,\n ...options,\n container: typeof options.container === 'string'\n ? document.querySelector(options.container) ?? defaultOptions.container\n : options.container ?? defaultOptions.container,\n };\n\n if (!this.options.container) {\n throw new Error('Invalid container element');\n }\n\n if (!Iconly.dbInstance) {\n Iconly.dbInstance = this.openDB('iconlyDB', 1);\n }\n }\n\n private async openDB(name: string, version: number): Promise<IDBDatabase> {\n if (!('indexedDB' in window)) {\n this.logError('This browser doesn\\'t support IndexedDB');\n throw new Error('IndexedDB not supported');\n }\n\n return new Promise<IDBDatabase>((resolve, reject) => {\n const request = indexedDB.open(name, version);\n\n request.onerror = () => reject(new Error(`IndexedDB error: ${request.error}`));\n request.onupgradeneeded = (event: IDBVersionChangeEvent) => {\n const db = (event.target as IDBOpenDBRequest).result;\n if (!db.objectStoreNames.contains('icons')) {\n db.createObjectStore('icons', { keyPath: 'version' });\n }\n };\n request.onsuccess = () => resolve(request.result);\n });\n }\n\n private static async fetchData(file: string): Promise<string> {\n const response = await fetch(file);\n if (!response.ok) throw new Error('Network response was not ok');\n return response.text();\n }\n\n private insert(data: string): void {\n let iconSetDiv = document.getElementById('iconset');\n\n if (!iconSetDiv) {\n iconSetDiv = document.createElement('div');\n iconSetDiv.id = 'iconset';\n iconSetDiv.setAttribute('aria-hidden', 'true');\n iconSetDiv.style.cssText = 'width: 0; height: 0; position: absolute; left: -9999px;';\n this.options.container.appendChild(iconSetDiv);\n }\n\n iconSetDiv.innerHTML = data;\n }\n\n async init(): Promise<void> {\n const { file, version } = this.options;\n\n try {\n let data = await Iconly.fetchData(file);\n\n const db = await Iconly.dbInstance;\n const store = db.transaction('icons', 'readwrite').objectStore('icons');\n\n const dbVersion = await new Promise<{ version: string; data: string } | undefined>((resolve, reject) => {\n const request = store.get(version);\n request.onsuccess = () => resolve(request.result);\n request.onerror = () => reject(request.error);\n });\n\n if (!dbVersion) {\n await new Promise<void>((resolve, reject) => {\n const request = store.put({ version, data });\n request.onsuccess = () => resolve();\n request.onerror = () => reject(request.error);\n });\n } else {\n data = dbVersion.data;\n }\n\n await new Promise<void>((resolve, reject) => {\n const tx = store.transaction;\n tx.oncomplete = () => resolve();\n tx.onerror = () => reject(tx.error);\n tx.onabort = () => reject(tx.error);\n });\n\n this.insert(data);\n } catch (error) {\n this.logError('Error initializing Iconly:', error);\n }\n }\n\n private logError(...messages: unknown[]): void {\n if (this.options.debug) {\n // eslint-disable-next-line no-console\n console.error(...messages);\n }\n }\n}\n\nexport default Iconly;\n"],"names":[],"version":3,"file":"index.js.map"}
@@ -1,92 +0,0 @@
1
- class $643fcf18b2d2e76f$var$Iconly {
2
- static dbInstance = null;
3
- options;
4
- constructor(options = {}){
5
- const defaultOptions = {
6
- file: "./icons.svg",
7
- version: "1.0",
8
- debug: false,
9
- container: document.body ?? document.documentElement
10
- };
11
- this.options = {
12
- ...defaultOptions,
13
- ...options,
14
- container: typeof options.container === "string" ? document.querySelector(options.container) ?? defaultOptions.container : options.container ?? defaultOptions.container
15
- };
16
- if (!this.options.container) throw new Error("Invalid container element");
17
- if (!$643fcf18b2d2e76f$var$Iconly.dbInstance) $643fcf18b2d2e76f$var$Iconly.dbInstance = this.openDB("iconlyDB", 1);
18
- }
19
- async openDB(name, version) {
20
- if (!("indexedDB" in window)) {
21
- this.logError("This browser doesn't support IndexedDB");
22
- throw new Error("IndexedDB not supported");
23
- }
24
- return new Promise((resolve, reject)=>{
25
- const request = indexedDB.open(name, version);
26
- request.onerror = ()=>reject(new Error(`IndexedDB error: ${request.error}`));
27
- request.onupgradeneeded = (event)=>{
28
- const db = event.target.result;
29
- if (!db.objectStoreNames.contains("icons")) db.createObjectStore("icons", {
30
- keyPath: "version"
31
- });
32
- };
33
- request.onsuccess = ()=>resolve(request.result);
34
- });
35
- }
36
- static async fetchData(file) {
37
- const response = await fetch(file);
38
- if (!response.ok) throw new Error("Network response was not ok");
39
- return response.text();
40
- }
41
- insert(data) {
42
- let iconSetDiv = document.getElementById("iconset");
43
- if (!iconSetDiv) {
44
- iconSetDiv = document.createElement("div");
45
- iconSetDiv.id = "iconset";
46
- iconSetDiv.setAttribute("aria-hidden", "true");
47
- iconSetDiv.style.cssText = "width: 0; height: 0; position: absolute; left: -9999px;";
48
- this.options.container.appendChild(iconSetDiv);
49
- }
50
- iconSetDiv.innerHTML = data;
51
- }
52
- async init() {
53
- const { file: file, version: version } = this.options;
54
- try {
55
- let data = await $643fcf18b2d2e76f$var$Iconly.fetchData(file);
56
- const db = await $643fcf18b2d2e76f$var$Iconly.dbInstance;
57
- const store = db.transaction("icons", "readwrite").objectStore("icons");
58
- const dbVersion = await new Promise((resolve, reject)=>{
59
- const request = store.get(version);
60
- request.onsuccess = ()=>resolve(request.result);
61
- request.onerror = ()=>reject(request.error);
62
- });
63
- if (!dbVersion) await new Promise((resolve, reject)=>{
64
- const request = store.put({
65
- version: version,
66
- data: data
67
- });
68
- request.onsuccess = ()=>resolve();
69
- request.onerror = ()=>reject(request.error);
70
- });
71
- else data = dbVersion.data;
72
- await new Promise((resolve, reject)=>{
73
- const tx = store.transaction;
74
- tx.oncomplete = ()=>resolve();
75
- tx.onerror = ()=>reject(tx.error);
76
- tx.onabort = ()=>reject(tx.error);
77
- });
78
- this.insert(data);
79
- } catch (error) {
80
- this.logError("Error initializing Iconly:", error);
81
- }
82
- }
83
- logError(...messages) {
84
- if (this.options.debug) // eslint-disable-next-line no-console
85
- console.error(...messages);
86
- }
87
- }
88
- var $643fcf18b2d2e76f$export$2e2bcd8739ae039 = $643fcf18b2d2e76f$var$Iconly;
89
-
90
-
91
- export {$643fcf18b2d2e76f$export$2e2bcd8739ae039 as default};
92
- //# sourceMappingURL=index.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":"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","sources":["src/index.ts"],"sourcesContent":["class Iconly {\n private static dbInstance: Promise<IDBDatabase> | null = null;\n\n private readonly options: {\n file: string;\n version: string;\n debug: boolean;\n container: HTMLElement;\n };\n\n constructor(options: { file?: string; version?: string; debug?: boolean; container?: string | HTMLElement } = {}) {\n const defaultOptions = {\n file: './icons.svg',\n version: '1.0',\n debug: false,\n container: document.body ?? document.documentElement,\n };\n\n this.options = {\n ...defaultOptions,\n ...options,\n container: typeof options.container === 'string'\n ? document.querySelector(options.container) ?? defaultOptions.container\n : options.container ?? defaultOptions.container,\n };\n\n if (!this.options.container) {\n throw new Error('Invalid container element');\n }\n\n if (!Iconly.dbInstance) {\n Iconly.dbInstance = this.openDB('iconlyDB', 1);\n }\n }\n\n private async openDB(name: string, version: number): Promise<IDBDatabase> {\n if (!('indexedDB' in window)) {\n this.logError('This browser doesn\\'t support IndexedDB');\n throw new Error('IndexedDB not supported');\n }\n\n return new Promise<IDBDatabase>((resolve, reject) => {\n const request = indexedDB.open(name, version);\n\n request.onerror = () => reject(new Error(`IndexedDB error: ${request.error}`));\n request.onupgradeneeded = (event: IDBVersionChangeEvent) => {\n const db = (event.target as IDBOpenDBRequest).result;\n if (!db.objectStoreNames.contains('icons')) {\n db.createObjectStore('icons', { keyPath: 'version' });\n }\n };\n request.onsuccess = () => resolve(request.result);\n });\n }\n\n private static async fetchData(file: string): Promise<string> {\n const response = await fetch(file);\n if (!response.ok) throw new Error('Network response was not ok');\n return response.text();\n }\n\n private insert(data: string): void {\n let iconSetDiv = document.getElementById('iconset');\n\n if (!iconSetDiv) {\n iconSetDiv = document.createElement('div');\n iconSetDiv.id = 'iconset';\n iconSetDiv.setAttribute('aria-hidden', 'true');\n iconSetDiv.style.cssText = 'width: 0; height: 0; position: absolute; left: -9999px;';\n this.options.container.appendChild(iconSetDiv);\n }\n\n iconSetDiv.innerHTML = data;\n }\n\n async init(): Promise<void> {\n const { file, version } = this.options;\n\n try {\n let data = await Iconly.fetchData(file);\n\n const db = await Iconly.dbInstance;\n const store = db.transaction('icons', 'readwrite').objectStore('icons');\n\n const dbVersion = await new Promise<{ version: string; data: string } | undefined>((resolve, reject) => {\n const request = store.get(version);\n request.onsuccess = () => resolve(request.result);\n request.onerror = () => reject(request.error);\n });\n\n if (!dbVersion) {\n await new Promise<void>((resolve, reject) => {\n const request = store.put({ version, data });\n request.onsuccess = () => resolve();\n request.onerror = () => reject(request.error);\n });\n } else {\n data = dbVersion.data;\n }\n\n await new Promise<void>((resolve, reject) => {\n const tx = store.transaction;\n tx.oncomplete = () => resolve();\n tx.onerror = () => reject(tx.error);\n tx.onabort = () => reject(tx.error);\n });\n\n this.insert(data);\n } catch (error) {\n this.logError('Error initializing Iconly:', error);\n }\n }\n\n private logError(...messages: unknown[]): void {\n if (this.options.debug) {\n // eslint-disable-next-line no-console\n console.error(...messages);\n }\n }\n}\n\nexport default Iconly;\n"],"names":[],"version":3,"file":"index.module.js.map"}
package/src/index.ts DELETED
@@ -1,122 +0,0 @@
1
- class Iconly {
2
- private static dbInstance: Promise<IDBDatabase> | null = null;
3
-
4
- private readonly options: {
5
- file: string;
6
- version: string;
7
- debug: boolean;
8
- container: HTMLElement;
9
- };
10
-
11
- constructor(options: { file?: string; version?: string; debug?: boolean; container?: string | HTMLElement } = {}) {
12
- const defaultOptions = {
13
- file: './icons.svg',
14
- version: '1.0',
15
- debug: false,
16
- container: document.body ?? document.documentElement,
17
- };
18
-
19
- this.options = {
20
- ...defaultOptions,
21
- ...options,
22
- container: typeof options.container === 'string'
23
- ? document.querySelector(options.container) ?? defaultOptions.container
24
- : options.container ?? defaultOptions.container,
25
- };
26
-
27
- if (!this.options.container) {
28
- throw new Error('Invalid container element');
29
- }
30
-
31
- if (!Iconly.dbInstance) {
32
- Iconly.dbInstance = this.openDB('iconlyDB', 1);
33
- }
34
- }
35
-
36
- private async openDB(name: string, version: number): Promise<IDBDatabase> {
37
- if (!('indexedDB' in window)) {
38
- this.logError('This browser doesn\'t support IndexedDB');
39
- throw new Error('IndexedDB not supported');
40
- }
41
-
42
- return new Promise<IDBDatabase>((resolve, reject) => {
43
- const request = indexedDB.open(name, version);
44
-
45
- request.onerror = () => reject(new Error(`IndexedDB error: ${request.error}`));
46
- request.onupgradeneeded = (event: IDBVersionChangeEvent) => {
47
- const db = (event.target as IDBOpenDBRequest).result;
48
- if (!db.objectStoreNames.contains('icons')) {
49
- db.createObjectStore('icons', { keyPath: 'version' });
50
- }
51
- };
52
- request.onsuccess = () => resolve(request.result);
53
- });
54
- }
55
-
56
- private static async fetchData(file: string): Promise<string> {
57
- const response = await fetch(file);
58
- if (!response.ok) throw new Error('Network response was not ok');
59
- return response.text();
60
- }
61
-
62
- private insert(data: string): void {
63
- let iconSetDiv = document.getElementById('iconset');
64
-
65
- if (!iconSetDiv) {
66
- iconSetDiv = document.createElement('div');
67
- iconSetDiv.id = 'iconset';
68
- iconSetDiv.setAttribute('aria-hidden', 'true');
69
- iconSetDiv.style.cssText = 'width: 0; height: 0; position: absolute; left: -9999px;';
70
- this.options.container.appendChild(iconSetDiv);
71
- }
72
-
73
- iconSetDiv.innerHTML = data;
74
- }
75
-
76
- async init(): Promise<void> {
77
- const { file, version } = this.options;
78
-
79
- try {
80
- let data = await Iconly.fetchData(file);
81
-
82
- const db = await Iconly.dbInstance;
83
- const store = db.transaction('icons', 'readwrite').objectStore('icons');
84
-
85
- const dbVersion = await new Promise<{ version: string; data: string } | undefined>((resolve, reject) => {
86
- const request = store.get(version);
87
- request.onsuccess = () => resolve(request.result);
88
- request.onerror = () => reject(request.error);
89
- });
90
-
91
- if (!dbVersion) {
92
- await new Promise<void>((resolve, reject) => {
93
- const request = store.put({ version, data });
94
- request.onsuccess = () => resolve();
95
- request.onerror = () => reject(request.error);
96
- });
97
- } else {
98
- data = dbVersion.data;
99
- }
100
-
101
- await new Promise<void>((resolve, reject) => {
102
- const tx = store.transaction;
103
- tx.oncomplete = () => resolve();
104
- tx.onerror = () => reject(tx.error);
105
- tx.onabort = () => reject(tx.error);
106
- });
107
-
108
- this.insert(data);
109
- } catch (error) {
110
- this.logError('Error initializing Iconly:', error);
111
- }
112
- }
113
-
114
- private logError(...messages: unknown[]): void {
115
- if (this.options.debug) {
116
- // eslint-disable-next-line no-console
117
- console.error(...messages);
118
- }
119
- }
120
- }
121
-
122
- export default Iconly;
package/src/sprite.svg DELETED
@@ -1,14 +0,0 @@
1
- <svg preserveAspectRatio="none" fill="none">
2
- <symbol id="i-shopping" viewBox="0 0 24 24">
3
- <path d="M7,18c-1.1,0-1.99,0.9-1.99,2S5.9,22,7,22s2-0.9,2-2S8.1,18,7,18z M17,18c-1.1,0-1.99,0.9-1.99,2s0.89,2,1.99,2s2-0.9,2-2 S18.1,18,17,18z M19,16c0-0.55-0.45-1-1-1H7l1.1-2h7.45c0.75,0,1.41-0.41,1.75-1.03l3.24-6.14c0.25-0.48,0.08-1.08-0.4-1.34 c-0.49-0.27-1.1-0.08-1.36,0.41L15.55,11H8.53L4.54,2.57C4.38,2.22,4.02,2,3.64,2H2C1.45,2,1,2.45,1,3s0.45,1,1,1h1l3.6,7.59 l-1.35,2.44C4.52,15.37,5.48,17,7,17h11C18.55,17,19,16.55,19,16z M11.29,2.71c0.39-0.39,1.02-0.39,1.41,0l2.59,2.59 c0.39,0.39,0.39,1.02,0,1.41l-2.59,2.59c-0.39,0.39-1.02,0.39-1.41,0c-0.39-0.39-0.39-1.02,0-1.41L12.17,7L9,7C8.45,7,8,6.55,8,6 c0-0.55,0.45-1,1-1l3.17,0l-0.88-0.88C10.9,3.73,10.9,3.1,11.29,2.71z"/>
4
- </symbol>
5
- <symbol id="i-percent" viewBox="0 0 24 24">
6
- <path d="M7.5,4C5.57,4,4,5.57,4,7.5S5.57,11,7.5,11S11,9.43,11,7.5S9.43,4,7.5,4z M7.5,9C6.67,9,6,8.33,6,7.5S6.67,6,7.5,6 S9,6.67,9,7.5S8.33,9,7.5,9z M16.5,13c-1.93,0-3.5,1.57-3.5,3.5s1.57,3.5,3.5,3.5s3.5-1.57,3.5-3.5S18.43,13,16.5,13z M16.5,18 c-0.83,0-1.5-0.67-1.5-1.5s0.67-1.5,1.5-1.5s1.5,0.67,1.5,1.5S17.33,18,16.5,18z M19.29,4.71c0.39,0.39,0.39,1.02,0,1.41 L6.12,19.29c-0.39,0.39-1.02,0.39-1.41,0s-0.39-1.02,0-1.41L17.88,4.71C18.27,4.32,18.9,4.32,19.29,4.71z"/>
7
- </symbol>
8
- <symbol id="i-rocket" viewBox="0 0 24 24">
9
- <path d="M9.19,6.35c-2.04,2.29-3.44,5.58-3.57,5.89l-2.26-0.97c-0.65-0.28-0.81-1.13-0.31-1.63l3.01-3.01 c0.47-0.47,1.15-0.68,1.81-0.55L9.19,6.35L9.19,6.35z M10.68,16.51c0.3,0.3,0.74,0.38,1.12,0.2c1.16-0.54,3.65-1.81,5.26-3.42 c4.59-4.59,4.63-8.33,4.36-9.93c-0.07-0.4-0.39-0.72-0.79-0.79c-1.6-0.27-5.34-0.23-9.93,4.36c-1.61,1.61-2.87,4.1-3.42,5.26 c-0.18,0.38-0.09,0.83,0.2,1.12L10.68,16.51z M17.65,14.81c-2.29,2.04-5.58,3.44-5.89,3.57l0.97,2.26 c0.28,0.65,1.13,0.81,1.63,0.31l3.01-3.01c0.47-0.47,0.68-1.15,0.55-1.81L17.65,14.81L17.65,14.81z M8.94,17.41 c0.2,1.06-0.15,2.04-0.82,2.71c-0.77,0.77-3.16,1.34-4.71,1.64c-0.69,0.13-1.3-0.48-1.17-1.17c0.3-1.55,0.86-3.94,1.64-4.71 c0.67-0.67,1.65-1.02,2.71-0.82C7.76,15.28,8.72,16.24,8.94,17.41z M13,9c0-1.1,0.9-2,2-2s2,0.9,2,2s-0.9,2-2,2S13,10.1,13,9z"/>
10
- </symbol>
11
- <symbol id="i-phone" viewBox="0 0 24 24">
12
- <path d="M12.88 5.05c3.18.4 5.67 2.89 6.07 6.07.06.51.49.88.99.88.04 0 .08 0 .12-.01.55-.07.94-.57.87-1.12-.51-4.09-3.72-7.3-7.81-7.81-.55-.06-1.05.33-1.11.88-.07.55.32 1.05.87 1.11zm.38 2.11c-.53-.14-1.08.18-1.22.72s.18 1.08.72 1.22c1.05.27 1.87 1.09 2.15 2.15.12.45.52.75.97.75.08 0 .17-.01.25-.03.53-.14.85-.69.72-1.22-.47-1.77-1.84-3.14-3.59-3.59zm5.97 8.1l-2.54-.29c-.61-.07-1.21.14-1.64.57l-1.84 1.84c-2.83-1.44-5.15-3.75-6.59-6.59l1.85-1.85c.43-.43.64-1.03.57-1.64l-.29-2.52c-.12-1.01-.97-1.77-1.99-1.77H5.03c-1.13 0-2.07.94-2 2.07.53 8.54 7.36 15.36 15.89 15.89 1.13.07 2.07-.87 2.07-2v-1.73c.01-1.01-.75-1.86-1.76-1.98z"/>
13
- </symbol>
14
- </svg>
package/tsconfig.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "isolatedModules": true,
4
- "target": "es2022"
5
- }
6
- }