From a9abd51959a547cc306e24e7aa11b87e874c7075 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 27 Sep 2023 12:09:59 +0000 Subject: [PATCH] chore(release): 1.2.1 [skip ci] ## [1.2.1](https://github.com/adobe/aem-lib/compare/v1.2.0...v1.2.1) (2023-09-27) ### Bug Fixes * revert icons to simple decoration ([#15](https://github.com/adobe/aem-lib/issues/15)) ([17af83b](https://github.com/adobe/aem-lib/commit/17af83bf1838cc4b5dfad19c40124c22c70780eb)) --- CHANGELOG.md | 7 ++++ dist/aem.js | 86 +++++++++++------------------------------------ package-lock.json | 4 +-- package.json | 2 +- 4 files changed, 30 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c88025..84c1284 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [1.2.1](https://github.com/adobe/aem-lib/compare/v1.2.0...v1.2.1) (2023-09-27) + + +### Bug Fixes + +* revert icons to simple decoration ([#15](https://github.com/adobe/aem-lib/issues/15)) ([17af83b](https://github.com/adobe/aem-lib/commit/17af83bf1838cc4b5dfad19c40124c22c70780eb)) + # [1.2.0](https://github.com/adobe/aem-lib/compare/v1.1.0...v1.2.0) (2023-09-22) diff --git a/dist/aem.js b/dist/aem.js index f3f5a16..0f2e15b 100644 --- a/dist/aem.js +++ b/dist/aem.js @@ -392,77 +392,31 @@ function decorateButtons(element) { }); } -const ICONS_CACHE = {}; /** - * Replace icons with inline SVG and prefix with codeBasePath. - * @param {Element} [element] Element containing icons + * Add for icon, prefixed with codeBasePath and optional prefix. + * @param {span} [element] span element with icon classes + * @param {string} [prefix] prefix to be added to icon the src */ -async function decorateIcons(element) { - // Prepare the inline sprite - let svgSprite = document.getElementById('franklin-svg-sprite'); - if (!svgSprite) { - const div = document.createElement('div'); - div.innerHTML = ''; - svgSprite = div.firstElementChild; - document.body.append(div.firstElementChild); - } +function decorateIcon(span, prefix = '') { + const iconName = Array.from(span.classList) + .find((c) => c.startsWith('icon-')) + .substring(5); + const img = document.createElement('img'); + img.dataset.iconName = iconName; + img.src = `${window.codeBasePath}${prefix}/icons/${iconName}.svg`; + img.loading = 'lazy'; + span.append(img); +} - // Download all new icons +/** + * Add for icons, prefixed with codeBasePath and optional prefix. + * @param {Element} [element] Element containing icons + * @param {string} [prefix] prefix to be added to icon the src + */ +function decorateIcons(element, prefix = '') { const icons = [...element.querySelectorAll('span.icon')]; - await Promise.all( - icons.map(async (span) => { - const iconName = Array.from(span.classList) - .find((c) => c.startsWith('icon-')) - .substring(5); - if (!ICONS_CACHE[iconName]) { - ICONS_CACHE[iconName] = true; - try { - const response = await fetch(`${window.hlx.codeBasePath}/icons/${iconName}.svg`); - if (!response.ok) { - ICONS_CACHE[iconName] = false; - return; - } - // Styled icons don't play nice with the sprite approach because of shadow dom isolation - const svg = await response.text(); - if (svg.match(/(