2
0
mirror of https://github.com/iconify/iconify.git synced 2024-11-09 23:00:56 +00:00

Update Ember component for new code

This commit is contained in:
Vjacheslav Trushkin 2021-09-27 18:47:41 +03:00
parent 933202d617
commit f3dffba74f
8 changed files with 151 additions and 221 deletions

View File

@ -1 +1,2 @@
export { default } from '@iconify/ember/components/iconify-icon'; import Icon from '@iconify/ember/components/iconify-icon';
export default Icon;

View File

@ -1,3 +1,4 @@
/* eslint-disable */
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
const child_process = require('child_process'); const child_process = require('child_process');
@ -57,7 +58,7 @@ const fileExists = (file) => {
return true; return true;
}; };
if (compile.lib && !fileExists(packagesDir + '/core/lib/modules.js')) { if (compile.lib && !fileExists(packagesDir + '/core/lib/cache.js')) {
compile.core = true; compile.core = true;
} }

View File

@ -1,5 +1,35 @@
const fs = require('fs'); const fs = require('fs');
/**
* Fix default export syntax
*/
function fixDefaultExport(filename) {
const source = __dirname + '/' + filename;
const data = fs.readFileSync(source, 'utf8');
const search = 'IconifyIconComponent as default';
if (data.indexOf(search) === -1) {
console.log(`Exports are fine in ${filename}`);
return;
}
let foundMatch = 0;
const lines = data.split(',').filter((line) => {
if (line.trim() === search) {
foundMatch++;
return false;
}
return true;
});
if (foundMatch !== 1) {
throw new Error(`Error fixing exports in ${filename}`);
}
const newCode =
lines.join(',') + '\nexport default IconifyIconComponent;\n';
fs.writeFileSync(source, newCode, 'utf8');
console.log(`Fixed default export in ${filename}`);
}
/** /**
* Restore decorator in component * Restore decorator in component
*/ */
@ -128,5 +158,6 @@ function copyFile(source, target) {
} }
restoreDecorator('lib/component.js'); restoreDecorator('lib/component.js');
fixDefaultExport('addon/components/iconify-icon.js');
restoreDecorator('addon/components/iconify-icon.js'); restoreDecorator('addon/components/iconify-icon.js');
copyFile('src/iconify-icon.hbs', 'addon/components/iconify-icon.hbs'); copyFile('src/iconify-icon.hbs', 'addon/components/iconify-icon.hbs');

View File

@ -15,11 +15,8 @@
"ember-cli-htmlbars": "^5.7.1" "ember-cli-htmlbars": "^5.7.1"
}, },
"devDependencies": { "devDependencies": {
"@iconify/core": "^1.2.0-beta.2", "@iconify/core": "^1.2.0-beta.3",
"@iconify/types": "^1.0.6",
"@iconify/utils": "^1.0.7",
"@microsoft/api-extractor": "^7.18.4", "@microsoft/api-extractor": "^7.18.4",
"@rollup/plugin-commonjs": "^18.1.0",
"@rollup/plugin-node-resolve": "^11.2.1", "@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-typescript": "^8.2.3", "@rollup/plugin-typescript": "^8.2.3",
"rollup": "^2.53.2", "rollup": "^2.53.2",
@ -1596,12 +1593,6 @@
"node": ">=6.9.0" "node": ">=6.9.0"
} }
}, },
"node_modules/@cyberalien/redundancy": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@cyberalien/redundancy/-/redundancy-1.1.0.tgz",
"integrity": "sha512-+ZvuwtVXzyxX1CWnP+X5XgDelseU9KSYgmPu3/DSraR7Qyi/vLZwuRRX0sYO24M/gZaChNXRBEK6RHRe3uBndw==",
"dev": true
},
"node_modules/@ember-data/rfc395-data": { "node_modules/@ember-data/rfc395-data": {
"version": "0.0.4", "version": "0.0.4",
"resolved": "https://registry.npmjs.org/@ember-data/rfc395-data/-/rfc395-data-0.0.4.tgz", "resolved": "https://registry.npmjs.org/@ember-data/rfc395-data/-/rfc395-data-0.0.4.tgz",
@ -1665,31 +1656,37 @@
"resolved": "https://registry.npmjs.org/@glimmer/validator/-/validator-0.44.0.tgz", "resolved": "https://registry.npmjs.org/@glimmer/validator/-/validator-0.44.0.tgz",
"integrity": "sha512-i01plR0EgFVz69GDrEuFgq1NheIjZcyTy3c7q+w7d096ddPVeVcRzU3LKaqCfovvLJ+6lJx40j45ecycASUUyw==" "integrity": "sha512-i01plR0EgFVz69GDrEuFgq1NheIjZcyTy3c7q+w7d096ddPVeVcRzU3LKaqCfovvLJ+6lJx40j45ecycASUUyw=="
}, },
"node_modules/@iconify/api-redundancy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@iconify/api-redundancy/-/api-redundancy-1.0.2.tgz",
"integrity": "sha512-/i2sIQSL+ygsPXPkmj368mf0UAaJRMd4+TVAvWPQQU0aaS0Km9p+0ZTR0UtD07F9O1oAgfzGAzkMYIh0gAhvJg==",
"dev": true
},
"node_modules/@iconify/core": { "node_modules/@iconify/core": {
"version": "1.2.0-beta.2", "version": "1.2.0-beta.3",
"resolved": "https://registry.npmjs.org/@iconify/core/-/core-1.2.0-beta.2.tgz", "resolved": "https://registry.npmjs.org/@iconify/core/-/core-1.2.0-beta.3.tgz",
"integrity": "sha512-BnlanmZB5h+OXP0FIsfjMqsrAaDdHxVN5Y5jjYU4KrqaEwh9BiaIIr7lS/rXGk4UdnLps2NDjhkobuC7DXqm6A==", "integrity": "sha512-B9N0jdk1Ik2r/BpKfZGj+BPLUd5rNuwwyWaCiHSwlnt/n3jORwLtt689OPo2lVCaIcgwI9Uvw6I0O53smIKayQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@cyberalien/redundancy": "^1.1.0", "@iconify/api-redundancy": "^1.0.2",
"@iconify/types": "^1.0.6", "@iconify/types": "^1.0.7",
"@iconify/utils": "^1.0.6", "@iconify/utils": "^1.0.9",
"cross-fetch": "^3.1.4" "cross-fetch": "^3.1.4"
} }
}, },
"node_modules/@iconify/types": { "node_modules/@iconify/types": {
"version": "1.0.7", "version": "1.0.9",
"resolved": "https://registry.npmjs.org/@iconify/types/-/types-1.0.7.tgz", "resolved": "https://registry.npmjs.org/@iconify/types/-/types-1.0.9.tgz",
"integrity": "sha512-zdwkVc67O9SqI/svsogD2s+XB3Uk4Xx+PrMEn5Qm3ktKSXFveZL0iP3yzqbrFg1KRRd93nRs4QycLaIRMhA0Pg==", "integrity": "sha512-ALO6IGXBEztcySLq+vGJrgUJqGgiZJ8sTQ8mM6e3i77okM9fw8F23h6GLbbaMz/pNfeK8QHJBAOmx3LjhZ3YZw==",
"dev": true "dev": true
}, },
"node_modules/@iconify/utils": { "node_modules/@iconify/utils": {
"version": "1.0.7", "version": "1.0.9",
"resolved": "https://registry.npmjs.org/@iconify/utils/-/utils-1.0.7.tgz", "resolved": "https://registry.npmjs.org/@iconify/utils/-/utils-1.0.9.tgz",
"integrity": "sha512-ciJNYlqSxWdIZcCbE9FPL3o9o/U8ok0s8B7uf4lcGR57qyMaz3IUfihiBIb8YBr4eVp7eQDT2zV1Xpikkh/ePg==", "integrity": "sha512-HgHho6s0hQ7hIgx27J6YBg/4Jse0OZxQGQqE8ZT1lELWDOqrvR4RB1AIR2O3JFIts8u0a7uBwDhbjZPBwzj4TQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"@iconify/types": "^1.0.6" "@iconify/types": "^1.0.7"
} }
}, },
"node_modules/@microsoft/api-extractor": { "node_modules/@microsoft/api-extractor": {
@ -1770,27 +1767,6 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/@rollup/plugin-commonjs": {
"version": "18.1.0",
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-18.1.0.tgz",
"integrity": "sha512-h3e6T9rUxVMAQswpDIobfUHn/doMzM9sgkMrsMWCFLmB84PSoC8mV8tOloAJjSRwdqhXBqstlX2BwBpHJvbhxg==",
"dev": true,
"dependencies": {
"@rollup/pluginutils": "^3.1.0",
"commondir": "^1.0.1",
"estree-walker": "^2.0.1",
"glob": "^7.1.6",
"is-reference": "^1.2.1",
"magic-string": "^0.25.7",
"resolve": "^1.17.0"
},
"engines": {
"node": ">= 8.0.0"
},
"peerDependencies": {
"rollup": "^2.30.0"
}
},
"node_modules/@rollup/plugin-node-resolve": { "node_modules/@rollup/plugin-node-resolve": {
"version": "11.2.1", "version": "11.2.1",
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.2.1.tgz", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.2.1.tgz",
@ -2641,12 +2617,6 @@
"node": ">=4.0.0" "node": ">=4.0.0"
} }
}, },
"node_modules/commondir": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
"integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=",
"dev": true
},
"node_modules/concat-map": { "node_modules/concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@ -3380,12 +3350,6 @@
"node": ">=0.8.0" "node": ">=0.8.0"
} }
}, },
"node_modules/estree-walker": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
"dev": true
},
"node_modules/esutils": { "node_modules/esutils": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",
@ -3926,15 +3890,6 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/is-reference": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz",
"integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==",
"dev": true,
"dependencies": {
"@types/estree": "*"
}
},
"node_modules/is-regex": { "node_modules/is-regex": {
"version": "1.1.4", "version": "1.1.4",
"resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz",
@ -6193,12 +6148,6 @@
"to-fast-properties": "^2.0.0" "to-fast-properties": "^2.0.0"
} }
}, },
"@cyberalien/redundancy": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@cyberalien/redundancy/-/redundancy-1.1.0.tgz",
"integrity": "sha512-+ZvuwtVXzyxX1CWnP+X5XgDelseU9KSYgmPu3/DSraR7Qyi/vLZwuRRX0sYO24M/gZaChNXRBEK6RHRe3uBndw==",
"dev": true
},
"@ember-data/rfc395-data": { "@ember-data/rfc395-data": {
"version": "0.0.4", "version": "0.0.4",
"resolved": "https://registry.npmjs.org/@ember-data/rfc395-data/-/rfc395-data-0.0.4.tgz", "resolved": "https://registry.npmjs.org/@ember-data/rfc395-data/-/rfc395-data-0.0.4.tgz",
@ -6259,31 +6208,37 @@
"resolved": "https://registry.npmjs.org/@glimmer/validator/-/validator-0.44.0.tgz", "resolved": "https://registry.npmjs.org/@glimmer/validator/-/validator-0.44.0.tgz",
"integrity": "sha512-i01plR0EgFVz69GDrEuFgq1NheIjZcyTy3c7q+w7d096ddPVeVcRzU3LKaqCfovvLJ+6lJx40j45ecycASUUyw==" "integrity": "sha512-i01plR0EgFVz69GDrEuFgq1NheIjZcyTy3c7q+w7d096ddPVeVcRzU3LKaqCfovvLJ+6lJx40j45ecycASUUyw=="
}, },
"@iconify/api-redundancy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@iconify/api-redundancy/-/api-redundancy-1.0.2.tgz",
"integrity": "sha512-/i2sIQSL+ygsPXPkmj368mf0UAaJRMd4+TVAvWPQQU0aaS0Km9p+0ZTR0UtD07F9O1oAgfzGAzkMYIh0gAhvJg==",
"dev": true
},
"@iconify/core": { "@iconify/core": {
"version": "1.2.0-beta.2", "version": "1.2.0-beta.3",
"resolved": "https://registry.npmjs.org/@iconify/core/-/core-1.2.0-beta.2.tgz", "resolved": "https://registry.npmjs.org/@iconify/core/-/core-1.2.0-beta.3.tgz",
"integrity": "sha512-BnlanmZB5h+OXP0FIsfjMqsrAaDdHxVN5Y5jjYU4KrqaEwh9BiaIIr7lS/rXGk4UdnLps2NDjhkobuC7DXqm6A==", "integrity": "sha512-B9N0jdk1Ik2r/BpKfZGj+BPLUd5rNuwwyWaCiHSwlnt/n3jORwLtt689OPo2lVCaIcgwI9Uvw6I0O53smIKayQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@cyberalien/redundancy": "^1.1.0", "@iconify/api-redundancy": "^1.0.2",
"@iconify/types": "^1.0.6", "@iconify/types": "^1.0.7",
"@iconify/utils": "^1.0.6", "@iconify/utils": "^1.0.9",
"cross-fetch": "^3.1.4" "cross-fetch": "^3.1.4"
} }
}, },
"@iconify/types": { "@iconify/types": {
"version": "1.0.7", "version": "1.0.9",
"resolved": "https://registry.npmjs.org/@iconify/types/-/types-1.0.7.tgz", "resolved": "https://registry.npmjs.org/@iconify/types/-/types-1.0.9.tgz",
"integrity": "sha512-zdwkVc67O9SqI/svsogD2s+XB3Uk4Xx+PrMEn5Qm3ktKSXFveZL0iP3yzqbrFg1KRRd93nRs4QycLaIRMhA0Pg==", "integrity": "sha512-ALO6IGXBEztcySLq+vGJrgUJqGgiZJ8sTQ8mM6e3i77okM9fw8F23h6GLbbaMz/pNfeK8QHJBAOmx3LjhZ3YZw==",
"dev": true "dev": true
}, },
"@iconify/utils": { "@iconify/utils": {
"version": "1.0.7", "version": "1.0.9",
"resolved": "https://registry.npmjs.org/@iconify/utils/-/utils-1.0.7.tgz", "resolved": "https://registry.npmjs.org/@iconify/utils/-/utils-1.0.9.tgz",
"integrity": "sha512-ciJNYlqSxWdIZcCbE9FPL3o9o/U8ok0s8B7uf4lcGR57qyMaz3IUfihiBIb8YBr4eVp7eQDT2zV1Xpikkh/ePg==", "integrity": "sha512-HgHho6s0hQ7hIgx27J6YBg/4Jse0OZxQGQqE8ZT1lELWDOqrvR4RB1AIR2O3JFIts8u0a7uBwDhbjZPBwzj4TQ==",
"dev": true, "dev": true,
"requires": { "requires": {
"@iconify/types": "^1.0.6" "@iconify/types": "^1.0.7"
} }
}, },
"@microsoft/api-extractor": { "@microsoft/api-extractor": {
@ -6355,21 +6310,6 @@
} }
} }
}, },
"@rollup/plugin-commonjs": {
"version": "18.1.0",
"resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-18.1.0.tgz",
"integrity": "sha512-h3e6T9rUxVMAQswpDIobfUHn/doMzM9sgkMrsMWCFLmB84PSoC8mV8tOloAJjSRwdqhXBqstlX2BwBpHJvbhxg==",
"dev": true,
"requires": {
"@rollup/pluginutils": "^3.1.0",
"commondir": "^1.0.1",
"estree-walker": "^2.0.1",
"glob": "^7.1.6",
"is-reference": "^1.2.1",
"magic-string": "^0.25.7",
"resolve": "^1.17.0"
}
},
"@rollup/plugin-node-resolve": { "@rollup/plugin-node-resolve": {
"version": "11.2.1", "version": "11.2.1",
"resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.2.1.tgz", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.2.1.tgz",
@ -7084,12 +7024,6 @@
"resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.8.0.tgz", "resolved": "https://registry.npmjs.org/common-tags/-/common-tags-1.8.0.tgz",
"integrity": "sha512-6P6g0uetGpW/sdyUy/iQQCbFF0kWVMSIVSyYz7Zgjcgh8mgw8PQzDNZeyZ5DQ2gM7LBoZPHmnjz8rUthkBG5tw==" "integrity": "sha512-6P6g0uetGpW/sdyUy/iQQCbFF0kWVMSIVSyYz7Zgjcgh8mgw8PQzDNZeyZ5DQ2gM7LBoZPHmnjz8rUthkBG5tw=="
}, },
"commondir": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz",
"integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=",
"dev": true
},
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@ -7665,12 +7599,6 @@
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
}, },
"estree-walker": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz",
"integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==",
"dev": true
},
"esutils": { "esutils": {
"version": "2.0.3", "version": "2.0.3",
"resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz",
@ -8091,15 +8019,6 @@
"has-tostringtag": "^1.0.0" "has-tostringtag": "^1.0.0"
} }
}, },
"is-reference": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz",
"integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==",
"dev": true,
"requires": {
"@types/estree": "*"
}
},
"is-regex": { "is-regex": {
"version": "1.1.4", "version": "1.1.4",
"resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz",

View File

@ -23,11 +23,8 @@
"build:cleanup": "node cleanup" "build:cleanup": "node cleanup"
}, },
"devDependencies": { "devDependencies": {
"@iconify/core": "^1.2.0-beta.2", "@iconify/core": "^1.2.0-beta.3",
"@iconify/types": "^1.0.6",
"@iconify/utils": "^1.0.7",
"@microsoft/api-extractor": "^7.18.4", "@microsoft/api-extractor": "^7.18.4",
"@rollup/plugin-commonjs": "^18.1.0",
"@rollup/plugin-node-resolve": "^11.2.1", "@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-typescript": "^8.2.3", "@rollup/plugin-typescript": "^8.2.3",
"rollup": "^2.53.2", "rollup": "^2.53.2",

View File

@ -1,5 +1,4 @@
import resolve from '@rollup/plugin-node-resolve'; import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript'; import typescript from '@rollup/plugin-typescript';
// Write all packages // Write all packages
@ -13,7 +12,13 @@ const config = [
}, },
], ],
external: ['@glimmer/component', '@glimmer/tracking'], external: ['@glimmer/component', '@glimmer/tracking'],
plugins: [resolve(), commonjs(), typescript()], plugins: [
resolve({
browser: true,
extensions: ['.ts', '.mjs', '.js'],
}),
typescript(),
],
}, },
]; ];

View File

@ -2,12 +2,15 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking'; import { tracked } from '@glimmer/tracking';
// Core // Core
import { IconifyIconName, stringToIcon } from '@iconify/utils/lib/icon/name'; import type { IconifyIconName } from '@iconify/utils/lib/icon/name';
import { stringToIcon } from '@iconify/utils/lib/icon/name';
import { getIconData } from '@iconify/core/lib/storage/functions'; import { getIconData } from '@iconify/core/lib/storage/functions';
import { fullIcon, FullIconifyIcon } from '@iconify/utils/lib/icon'; import type { FullIconifyIcon } from '@iconify/utils/lib/icon';
import { fullIcon } from '@iconify/utils/lib/icon';
// API // API
import { loadIcons, IconifyIconLoaderAbort } from '@iconify/core/lib/api/icons'; import type { IconifyIconLoaderAbort } from '@iconify/core/lib/api/icons';
import { loadIcons } from '@iconify/core/lib/api/icons';
// Component stuff // Component stuff
import type { IconifyIconProps } from './props'; import type { IconifyIconProps } from './props';

View File

@ -7,49 +7,53 @@ import type {
IconifyHorizontalIconAlignment, IconifyHorizontalIconAlignment,
IconifyVerticalIconAlignment, IconifyVerticalIconAlignment,
} from '@iconify/utils/lib/customisations'; } from '@iconify/utils/lib/customisations';
import type { IconifyStorageFunctions } from '@iconify/core/lib/storage/functions';
import { import {
IconifyStorageFunctions, iconExists,
storageFunctions, getIcon,
addIcon,
addCollection,
allowSimpleNames, allowSimpleNames,
} from '@iconify/core/lib/storage/functions'; } from '@iconify/core/lib/storage/functions';
import { import { listIcons } from '@iconify/core/lib/storage/storage';
IconifyBuilderFunctions, import type { IconifyBuilderFunctions } from '@iconify/core/lib/builder/functions';
builderFunctions, import { buildIcon } from '@iconify/core/lib/builder/functions';
} from '@iconify/core/lib/builder/functions'; import { replaceIDs } from '@iconify/utils/lib/svg/id';
import { calculateSize } from '@iconify/utils/lib/svg/size';
import type { IconifyIconBuildResult } from '@iconify/utils/lib/svg/build'; import type { IconifyIconBuildResult } from '@iconify/utils/lib/svg/build';
// API // API
import { import type {
IconifyAPIFunctions, IconifyAPIFunctions,
IconifyAPIInternalFunctions, IconifyAPIInternalFunctions,
APIFunctions,
APIInternalFunctions,
IconifyAPIQueryParams, IconifyAPIQueryParams,
IconifyAPICustomQueryParams, IconifyAPICustomQueryParams,
IconifyAPIMergeQueryParams, IconifyAPIMergeQueryParams,
} from '@iconify/core/lib/api/functions'; } from '@iconify/core/lib/api/functions';
import { import type {
setAPIModule,
IconifyAPIModule, IconifyAPIModule,
IconifyAPISendQuery, IconifyAPISendQuery,
IconifyAPIPrepareIconsQuery, IconifyAPIPrepareIconsQuery,
} from '@iconify/core/lib/api/modules'; } from '@iconify/core/lib/api/modules';
import { jsonpAPIModule } from '@iconify/core/lib/api/modules/jsonp'; import { setAPIModule } from '@iconify/core/lib/api/modules';
import { import type {
fetchAPIModule,
getFetch,
setFetch,
} from '@iconify/core/lib/api/modules/fetch';
import {
setAPIConfig,
PartialIconifyAPIConfig, PartialIconifyAPIConfig,
IconifyAPIConfig, IconifyAPIConfig,
GetAPIConfig, GetAPIConfig,
} from '@iconify/core/lib/api/config'; } from '@iconify/core/lib/api/config';
import {
addAPIProvider,
getAPIConfig,
listAPIProviders,
} from '@iconify/core/lib/api/config';
import { fetchAPIModule, setFetch } from '@iconify/core/lib/api/modules/fetch';
import type { import type {
IconifyIconLoaderCallback, IconifyIconLoaderCallback,
IconifyIconLoaderAbort, IconifyIconLoaderAbort,
} from '@iconify/core/lib/api/icons'; } from '@iconify/core/lib/api/icons';
import { loadIcons } from '@iconify/core/lib/api/icons';
import { sendAPIQuery } from '@iconify/core/lib/api/query';
import { mergeParams } from '@iconify/core/lib/api/params';
// Cache // Cache
import { cache } from '@iconify/core/lib/cache'; import { cache } from '@iconify/core/lib/cache';
@ -118,71 +122,18 @@ export { RawIconCustomisations, IconifyIconBuildResult };
export { IconifyBrowserCacheType }; export { IconifyBrowserCacheType };
/** /**
* Enable and disable browser cache * Enable cache
*/ */
export const enableCache = (storage: IconifyBrowserCacheType) => function enableCache(storage: IconifyBrowserCacheType): void {
toggleBrowserCache(storage, true); toggleBrowserCache(storage, true);
}
export const disableCache = (storage: IconifyBrowserCacheType) => /**
* Disable cache
*/
function disableCache(storage: IconifyBrowserCacheType): void {
toggleBrowserCache(storage, false); toggleBrowserCache(storage, false);
}
/* Storage functions */
/**
* Check if icon exists
*/
export const iconExists = storageFunctions.iconExists;
/**
* Get icon data
*/
export const getIcon = storageFunctions.getIcon;
/**
* List available icons
*/
export const listIcons = storageFunctions.listIcons;
/**
* Add one icon
*/
export const addIcon = storageFunctions.addIcon;
/**
* Add icon set
*/
export const addCollection = storageFunctions.addCollection;
/* Builder functions */
/**
* Calculate icon size
*/
export const calculateSize = builderFunctions.calculateSize;
/**
* Replace unique ids in content
*/
export const replaceIDs = builderFunctions.replaceIDs;
/**
* Build SVG
*/
export const buildIcon = builderFunctions.buildIcon;
/* API functions */
/**
* Load icons
*/
export const loadIcons = APIFunctions.loadIcons;
/**
* Add API provider
*/
export const addAPIProvider = APIFunctions.addAPIProvider;
/**
* Export internal functions that can be used by third party implementations
*/
export const _api = APIInternalFunctions;
/** /**
* Initialise stuff * Initialise stuff
@ -191,15 +142,7 @@ export const _api = APIInternalFunctions;
allowSimpleNames(true); allowSimpleNames(true);
// Set API module // Set API module
setAPIModule('', getFetch() ? fetchAPIModule : jsonpAPIModule); setAPIModule('', fetchAPIModule);
/**
* Function to enable node-fetch for getting icons on server side
*/
_api.setFetch = (nodeFetch: typeof fetch) => {
setFetch(nodeFetch);
setAPIModule('', fetchAPIModule);
};
/** /**
* Browser stuff * Browser stuff
@ -257,7 +200,7 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
) { ) {
continue; continue;
} }
if (!setAPIConfig(key, value)) { if (!addAPIProvider(key, value)) {
console.error(err); console.error(err);
} }
} catch (e) { } catch (e) {
@ -268,6 +211,36 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
} }
} }
/**
* Internal API
*/
const _api: IconifyAPIInternalFunctions = {
getAPIConfig,
setAPIModule,
sendAPIQuery,
setFetch,
listAPIProviders,
mergeParams,
};
/**
* Export functions
*/
// IconifyAPIInternalFunctions
export { _api };
// IconifyAPIFunctions
export { addAPIProvider, loadIcons };
// IconifyStorageFunctions
export { iconExists, getIcon, listIcons, addIcon, addCollection };
// IconifyBuilderFunctions
export { replaceIDs, calculateSize, buildIcon };
// IconifyBrowserCacheFunctions
export { enableCache, disableCache };
/** /**
* Component * Component
*/ */