Compare commits

...
45 Commits
Author SHA1 Message Date
ionitron 24d92f8f1d v7.1.2 2023-05-30 19:21:52 +00:00
Liam DeBeasi 06fa4a528d fix(icon): add :dir fallback (#1223) 2023-05-30 15:17:36 -04:00
Liam DeBeasi 3992b01883 merge release-7.1.1
Release 7.1.1
2023-05-23 13:57:07 -04:00
Liam DeBeasi 909a6cf1c4 chore: remove duplicate changelog entry 2023-05-23 13:48:49 -04:00
ionitron cdd0623792 chore(): update package lock files 2023-05-23 17:46:20 +00:00
ionitron 0fd63998b9 v7.1.1 2023-05-23 17:46:14 +00:00
Shawn TaylorandLiam DeBeasi 7466383539 chore(): update dev dependencies (#1216)
Co-authored-by: Liam DeBeasi <liamdebeasi@users.noreply.github.com>
2023-05-23 07:55:51 -04:00
Shawn Taylor 31ea9450b6 docs(): change link from slack to discord (#1217) 2023-05-20 09:24:45 -06:00
Shawn Taylorandionitron e70bf214b8 fix(icon): respond to changes of document dir (#1210)
* fix(icon): respond to changes of document dir

* Add snapshot for rtl

* Remove unused function

* Add tests

* CSS-only solution

* chore(): add updated snapshots

---------

Co-authored-by: ionitron <hi@ionicframework.com>
2023-05-19 10:17:26 -04:00
Liam DeBeasi fb46c75128 chore(ci): update workflows for upcoming deprecations (#1209) 2023-05-03 08:34:27 -04:00
jaredcbaumandLiam DeBeasi 4b2ed58009 chore(readme): ionic slack -> discord (#1208)
* chore(readme): ionic slack -> discord

* chore(contributing): slack -> discord

* Update .github/CONTRIBUTING.md

Co-authored-by: Liam DeBeasi <liamdebeasi@users.noreply.github.com>

* Update readme.md

Co-authored-by: Liam DeBeasi <liamdebeasi@users.noreply.github.com>

---------

Co-authored-by: Liam DeBeasi <liamdebeasi@users.noreply.github.com>
2023-04-26 11:45:56 -06:00
Lars Mikkelsen c86778cc7b chore(ci): enable npm package provenance (#1206) 2023-04-24 15:19:50 -04:00
Sean Perkins 99bb8f64f6 merge release-7.1.0
v7.1.0
2023-03-23 14:52:07 -04:00
Sean Perkins 3691e75d77 chore: remove duplicate changelog diff 2023-03-23 13:10:41 -04:00
ionitron 3904e85e61 chore(): update package lock files 2023-03-23 15:49:23 +00:00
ionitron 4fcee649df v7.1.0 2023-03-23 15:49:18 +00:00
Sean Perkins e4bf096aaf Merge remote-tracking branch 'origin/feature-7.1' into release-7.1.0 2023-03-23 11:43:25 -04:00
Sean Perkins cdb0d80cde feat: chevron-expand and chevron-collapse icons (#1198) 2023-03-22 16:13:00 -04:00
Liam DeBeasi e358a4f418 merge feature-7.0
Feature 7.0
2023-03-07 13:07:44 -05:00
Liam DeBeasi 0f6c84f976 merge release-7.0.0
Release 7.0.0
2023-03-07 08:52:02 -05:00
Liam DeBeasi 63788874db chore(): add migration note 2023-03-07 08:51:36 -05:00
ionitron ac450cbd28 chore(): update package lock files 2023-03-07 13:49:51 +00:00
ionitron 2ffcb6a012 v7.0.0 2023-03-07 13:49:46 +00:00
Liam DeBeasi 998b9207f3 chore(): sync with main
chore(): sync with main
2023-03-07 08:47:10 -05:00
Liam DeBeasi c290bea476 chore(): sync with main 2023-03-07 08:42:57 -05:00
Brandy Carney f2ed84a256 docs(contributing): include a link to contribute to the ionicons site (#1183) 2023-03-03 11:32:27 -05:00
Liam DeBeasi 7f3f55c94e merge release-6.1.3
Release 6.1.3
2023-02-09 12:39:57 -05:00
Liam DeBeasi ffcf9f9034 chore(): cleanup changelog 2023-02-09 12:35:41 -05:00
ionitron 6116bc2627 chore(): update package lock files 2023-02-09 17:34:58 +00:00
ionitron b7c9bb024a v6.1.3 2023-02-09 17:34:54 +00:00
Sean Perkins 8c412f6748 fix: DomParser usage in SSR (#1180)
Resolves #1179
2023-02-09 12:30:17 -05:00
Liam DeBeasi 53ce49e929 merge release-6.1.2
Release 6.1.2
2023-02-08 09:20:16 -05:00
Liam DeBeasi b27268f7db fix changelog 2023-02-08 09:13:59 -05:00
ionitron 2c1b968bff chore(): update package lock files 2023-02-08 14:05:12 +00:00
ionitron 3342166f7f v6.1.2 2023-02-08 14:05:08 +00:00
Sean Perkins 72f09369de fix(icon): load base64 data urls (#1172) 2023-02-07 16:37:42 -05:00
Liam DeBeasi 6e7ff0defc merge release-6.1.1
Merge Release 6.1.1
2023-02-06 15:08:02 -05:00
Liam DeBeasi 193e7f565a Merge branch 'main' into release-6.1.1 2023-02-06 09:44:14 -05:00
Liam DeBeasi 65bcbb4777 fix(icon): md and ios properties are reactive (#1174)
resolves #802
2023-02-03 09:19:32 -05:00
Amanda Johnston 98975ec0f5 fix(icon): remove auto-generated aria-label (#1170) 2023-01-20 10:18:28 -06:00
ionitron 2e9b493a05 chore(): update package lock files 2023-01-18 13:41:57 +00:00
ionitron 8f1f7fe9f3 v6.1.1 2023-01-18 13:41:52 +00:00
jonz94 93b4fa449b fix(icon): remove <title> during build step (#1169)
resolves #1168
2023-01-18 08:39:28 -05:00
Liam DeBeasi ee16638d07 merge release-6.1.0
Release 6.1.0
2023-01-17 14:32:46 -05:00
ionitron 2e76547a79 chore(): update package lock files 2023-01-17 19:28:11 +00:00
34 changed files with 12299 additions and 13186 deletions
+6 -2
View File
@@ -10,7 +10,7 @@ Please see our [Contributor Code of Conduct](./CODE_OF_CONDUCT.md) for informati
## Creating an Issue
* If you have a question about using Ionicons, please ask on the [Ionic Forum](http://forum.ionicframework.com/) or in the [Ionic Worldwide Slack](http://ionicworldwide.herokuapp.com/) group.
* If you have a question about using Ionicons, please ask on the [Ionic Forum](http://forum.ionicframework.com/) or in the [Ionic Discord](https://ionic.link/discord).
* It is required that you clearly describe the steps necessary to reproduce the issue you are running into. Although we would love to help our users as much as possible, diagnosing issues without clear reproduction steps is extremely time-consuming and simply not sustainable.
@@ -43,7 +43,7 @@ Please see our [Contributor Code of Conduct](./CODE_OF_CONDUCT.md) for informati
#### Modifying Components
1. Navigate to the `src/components/` directory and open the `icon` component to modify.
2. Make any changes to the icon component and then [preview-changes](#preview-component-changes).
2. Make any changes to the icon component and then [preview the changes](#preview-component-changes).
#### Preview Component Changes
@@ -64,6 +64,10 @@ TODO -->
3. Please fill out the Pull Request template to the best of your ability and include any issues that are related.
## Updating Documentation
The documentation site for Ionicons is located in the [ionicons-site](https://github.com/ionic-team/ionicons-site) repository.
## License
By contributing your code to the ionic-team/ionicons GitHub Repository, you agree to license your contribution under the MIT license.
@@ -10,7 +10,7 @@ inputs:
runs:
using: 'composite'
steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v3
with:
name: ${{ inputs.name }}
path: ${{ inputs.path }}
@@ -18,6 +18,9 @@ runs:
- uses: actions/setup-node@v3
with:
node-version: 16.x
- name: Install latest npm
run: npm install -g npm@latest
shell: bash
- name: Install Dependencies
run: npm ci
shell: bash
@@ -37,6 +40,6 @@ runs:
env:
NPM_TOKEN: ${{ inputs.token }}
- name: Publish to NPM
run: npm publish ${{ inputs.folder }} --tag ${{ inputs.tag }}
run: npm publish ${{ inputs.folder }} --tag ${{ inputs.tag }} --provenance
shell: bash
working-directory: ${{ inputs.working-directory }}
working-directory: ${{ inputs.working-directory }}
@@ -59,7 +59,7 @@ runs:
rsync -R --progress $(git diff --name-only --cached) updated-screenshots
echo 'copied images'
if [ -d updated-screenshots ]; then
echo "::set-output name=hasUpdatedScreenshots::$(echo 'true')"
echo "hasUpdatedScreenshots=$(echo 'true')" >> $GITHUB_OUTPUT
cd updated-screenshots
ls
zip -q -r ../UpdatedScreenshots-${{ inputs.shard }}-${{ inputs.totalShards }}.zip ./
@@ -13,7 +13,7 @@ runs:
- name: Create Archive
run: zip -q -r ${{ inputs.output }} ${{ inputs.paths }}
shell: bash
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: ${{ inputs.name }}
path: ${{ inputs.output }}
+3 -1
View File
@@ -18,6 +18,8 @@ on:
jobs:
release-core:
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v3
- uses: ./.github/workflows/actions/publish-npm
@@ -25,4 +27,4 @@ jobs:
tag: ${{ inputs.tag }}
version: ${{ inputs.version }}
working-directory: './'
token: ${{ secrets.NPM_TOKEN }}
token: ${{ secrets.NPM_TOKEN }}
+1 -1
View File
@@ -39,7 +39,7 @@ jobs:
runs-on: ubuntu-latest
needs: [test-e2e]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
# Normally, we could just push with the
# default GITHUB_TOKEN, but that will
# not cause the build workflow
+100
View File
@@ -3,6 +3,106 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [7.1.2](https://github.com/ionic-team/ionicons/compare/v7.1.1...v7.1.2) (2023-05-30)
### Bug Fixes
* **icon:** add :dir fallback ([#1223](https://github.com/ionic-team/ionicons/issues/1223)) ([06fa4a5](https://github.com/ionic-team/ionicons/commit/06fa4a528dd1906a5673ff6d80d22aef0f6e113b))
## [7.1.2](https://github.com/ionic-team/ionicons/compare/v7.1.1...v7.1.2) (2023-05-30)
### Bug Fixes
* **icon:** add :dir fallback ([#1223](https://github.com/ionic-team/ionicons/issues/1223)) ([06fa4a5](https://github.com/ionic-team/ionicons/commit/06fa4a528dd1906a5673ff6d80d22aef0f6e113b))
## [7.1.1](https://github.com/ionic-team/ionicons/compare/v7.1.0...v7.1.1) (2023-05-23)
### Bug Fixes
* **icon:** respond to changes of document dir ([#1210](https://github.com/ionic-team/ionicons/issues/1210)) ([e70bf21](https://github.com/ionic-team/ionicons/commit/e70bf214b82cd2187ea9394803283570d28ab28c))
# [7.1.0](https://github.com/ionic-team/ionicons/compare/v7.0.0...v7.1.0) (2023-03-23)
### Features
* chevron-expand and chevron-collapse icons ([#1198](https://github.com/ionic-team/ionicons/issues/1198)) ([cdb0d80](https://github.com/ionic-team/ionicons/commit/cdb0d80cde1dc5dd90fb2a1c3b4fa31d68294821))
# [7.0.0](https://github.com/ionic-team/ionicons/compare/v6.1.3...v7.0.0) (2023-03-07)
**Migration Note:** Developers should ensure that their `<ion-icon>` usages have either `aria-label` or `aria-hidden` to avoid accessibility issues. See https://ionic.io/ionicons/usage for more information.
### Bug Fixes
* **icon:** remove auto-generated aria-label ([#1170](https://github.com/ionic-team/ionicons/issues/1170)) ([98975ec](https://github.com/ionic-team/ionicons/commit/98975ec0f54b825c33f528683834a5e38298d598))
## [6.1.3](https://github.com/ionic-team/ionicons/compare/v6.1.2...v6.1.3) (2023-02-09)
### Bug Fixes
* DomParser usage in SSR ([#1180](https://github.com/ionic-team/ionicons/issues/1180)) ([8c412f6](https://github.com/ionic-team/ionicons/commit/8c412f67486d6cc9725de63f0c15b6c6cd8d47ce)), closes [#1179](https://github.com/ionic-team/ionicons/issues/1179)
## [6.1.2](https://github.com/ionic-team/ionicons/compare/v6.1.1...v6.1.2) (2023-02-08)
### Bug Fixes
* **icon:** load base64 data urls ([#1172](https://github.com/ionic-team/ionicons/issues/1172)) ([72f0936](https://github.com/ionic-team/ionicons/commit/72f09369de76b00697437f54d919782307843a87))
* **icon:** md and ios properties are reactive ([#1174](https://github.com/ionic-team/ionicons/issues/1174)) ([65bcbb4](https://github.com/ionic-team/ionicons/commit/65bcbb477734e33901a6f0c650d3f1f2c3084fca)), closes [#802](https://github.com/ionic-team/ionicons/issues/802)
## [6.1.1](https://github.com/ionic-team/ionicons/compare/v6.1.0...v6.1.1) (2023-01-18)
### Bug Fixes
* **icon:** remove <title> during build step ([#1169](https://github.com/ionic-team/ionicons/issues/1169)) ([93b4fa4](https://github.com/ionic-team/ionicons/commit/93b4fa449b0a072b24ef920fe73e1cb04d6f9b43)), closes [#1168](https://github.com/ionic-team/ionicons/issues/1168)
## [6.1.1](https://github.com/ionic-team/ionicons/compare/v6.1.0...v6.1.1) (2023-01-18)
### Bug Fixes
* **icon:** remove <title> during build step ([#1169](https://github.com/ionic-team/ionicons/issues/1169)) ([93b4fa4](https://github.com/ionic-team/ionicons/commit/93b4fa449b0a072b24ef920fe73e1cb04d6f9b43)), closes [#1168](https://github.com/ionic-team/ionicons/issues/1168)
# [6.1.0](https://github.com/ionic-team/ionicons/compare/v6.0.4...v6.1.0) (2023-01-17)
+1 -1
View File
@@ -2,5 +2,5 @@
"packages": [
"./"
],
"version": "6.1.0"
"version": "7.1.2"
}
+11880 -12983
View File
File diff suppressed because it is too large Load Diff
+13 -13
View File
@@ -1,6 +1,6 @@
{
"name": "ionicons",
"version": "6.1.0",
"version": "7.1.2",
"description": "Premium icons for Ionic.",
"files": [
"components/",
@@ -26,20 +26,20 @@
"@stencil/core": "^2.18.0"
},
"devDependencies": {
"@playwright/test": "^1.26.1",
"@types/fs-extra": "^9.0.6",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.22",
"@playwright/test": "^1.33.0",
"@types/fs-extra": "^11.0.1",
"@types/jest": "^27.0.3",
"@types/node": "^20.2.1",
"@types/svgo": "^1.3.3",
"fs-extra": "^9.1.0",
"jest": "^26.6.3",
"jest-cli": "^26.6.3",
"lerna": "^6.0.3",
"puppeteer": "^10.4.0",
"semver": "^7.3.8",
"serve": "^14.0.1",
"fs-extra": "^11.1.1",
"jest": "^27.0.3",
"jest-cli": "^27.0.3",
"lerna": "^6.6.2",
"puppeteer": "^20.2.1",
"semver": "^7.5.1",
"serve": "^14.2.0",
"svgo": "1.3.2",
"typescript": "^4.1.3"
"typescript": "^5.0.4"
},
"keywords": [
"icon pack",
+1 -2
View File
@@ -114,8 +114,7 @@ Ionicons is licensed under the [MIT license](http://opensource.org/licenses/MIT)
* [Ionicons Homepage](http://ionicons.com/)
* [Ionic Framework](https://ionicframework.com/)
* [Ionic Worldwide Slack](http://ionicworldwide.herokuapp.com/)
* [Ionic Discord](https://ionic.link/discord)
* [Ionic Forum](https://forum.ionicframework.com/)
* [Stencil](https://stenciljs.com/)
* [Stencil Worldwide Slack](https://stencil-worldwide.slack.com)
* [Capacitor](https://capacitorjs.com/)
+2 -2
View File
@@ -94,7 +94,7 @@ async function optimizeSvgs(srcSvgData: SvgData[]) {
if (item.isElem()) {
item.eachAttr((attr) => {
if (attr.name === 'stroke' || attr.name === 'fill') {
if (attr.value === '#000') {
if (attr.value === '#000' || attr.value === 'currentColor') {
item.addAttr({
name: attr.name,
value: 'currentColor',
@@ -168,7 +168,7 @@ async function optimizeSvg(
const optimizedCode = optimizedSvg.data.replace(
/<svg (.*?)>/,
`<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512"><title>${svgData.title}</title>`,
`<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512">`,
);
const webComponentSvg = await webComponentPass.optimize(optimizedCode, { path: svgData.srcFilePath });
+46 -4
View File
@@ -33,15 +33,58 @@ svg {
width: 100%;
}
/* Icon RTL
* -----------------------------------------------------------
*/
/**
* Safari <16.4 incorrectly reports
* that it supports :dir(rtl) when it does not.
* This @supports statement lets us target
* WebKit browsers to apply the RTL fallback.
* -webkit-named-image only exists on WebKit.
* For WebKit browsers that do support :dir(rtl)
* (i.e. Safari >= 16.4) then the :dir(rtl)
* code farther down on the page will take
* effect and override this fallback.
*/
@supports (background: -webkit-named-image(i)) {
:host(.icon-rtl) .icon-inner {
transform: scaleX(-1);
}
}
/**
* Fallback for browsers that support
* neither :host-context nor :dir.
* The icon will not react to dir
* changes, but it will at least
* respect the dir on component load.
*/
@supports not selector(:dir(rtl)) and selector(:host-context([dir='rtl'])) {
:host(.icon-rtl) .icon-inner {
transform: scaleX(-1);
}
}
:host(.flip-rtl) .icon-inner {
/* :host-context is supported in chromium; :dir is supported in safari & firefox */
:host(.flip-rtl):host-context([dir='rtl']) .icon-inner {
transform: scaleX(-1);
}
@supports selector(:dir(rtl)) {
:host(.flip-rtl:dir(rtl)) .icon-inner {
transform: scaleX(-1);
}
/**
* This is needed for WebKit otherwise the fallback
* will always cause the icon to be flipped if the document
* loads in RTL.
*/
:host(.flip-rtl:dir(ltr)) .icon-inner {
transform: scaleX(1);
}
}
/* Icon Sizes
* -----------------------------------------------------------
@@ -51,11 +94,10 @@ svg {
font-size: 18px !important;
}
:host(.icon-large){
:host(.icon-large) {
font-size: 32px !important;
}
/* Icon Colors
* -----------------------------------------------------------
*/
+13 -50
View File
@@ -2,8 +2,6 @@ import { Build, Component, Element, Host, Prop, State, Watch, h } from '@stencil
import { getSvgContent, ioniconContent } from './request';
import { getName, getUrl, inheritAttributes, isRTL } from './utils';
let parser: DOMParser;
@Component({
tag: 'ion-icon',
assetsDirs: ['svg'],
@@ -19,7 +17,6 @@ export class Icon {
@State() private svgContent?: string;
@State() private isVisible = false;
@State() private ariaLabel?: string;
/**
* The mode determines which platform styles to use.
@@ -82,7 +79,7 @@ export class Icon {
* @default true
*/
@Prop() sanitize = true;
componentWillLoad() {
this.inheritedAttributes = inheritAttributes(this.el, ['aria-label']);
}
@@ -103,7 +100,6 @@ export class Icon {
this.io = undefined;
}
}
private waitUntilVisible(el: HTMLElement, rootMargin: string, cb: () => void) {
if (Build.isBrowser && this.lazy && typeof window !== 'undefined' && (window as any).IntersectionObserver) {
const io = (this.io = new (window as any).IntersectionObserver(
@@ -124,39 +120,20 @@ export class Icon {
cb();
}
}
private hasAriaHidden = () => {
const { el } = this;
return el.hasAttribute('aria-hidden') && el.getAttribute('aria-hidden') === 'true';
}
@Watch('name')
@Watch('src')
@Watch('icon')
@Watch('ios')
@Watch('md')
loadIcon() {
if (Build.isBrowser && this.isVisible) {
if (!parser) {
/**
* Create an instance of the DOM parser. This creates a single
* parser instance for the entire app, which is more efficient.
*/
parser = new DOMParser();
}
const url = getUrl(this);
if (url) {
if (ioniconContent.has(url)) {
// sync if it's already loaded
this.svgContent = ioniconContent.get(url);
} else if (url.startsWith('data:')) {
const doc = parser.parseFromString(url, 'text/html');
const svgEl = doc.body.querySelector('svg');
if (svgEl !== null) {
this.svgContent = svgEl.outerHTML;
} else {
this.svgContent = '';
}
} else {
// async if it hasn't been loaded
getSvgContent(url, this.sanitize).then(() => (this.svgContent = ioniconContent.get(url)));
@@ -164,42 +141,28 @@ export class Icon {
}
}
const label = this.iconName = getName(this.name, this.icon, this.mode, this.ios, this.md);
/**
* Come up with a default label
* in case user does not provide their own.
*/
if (label) {
this.ariaLabel = label.replace(/\-/g, ' ');
}
this.iconName = getName(this.name, this.icon, this.mode, this.ios, this.md);
}
render() {
const { iconName, ariaLabel, el, inheritedAttributes } = this;
const { flipRtl, iconName, inheritedAttributes, el } = this;
const mode = this.mode || 'md';
const flipRtl =
this.flipRtl ||
(iconName &&
(iconName.indexOf('arrow') > -1 || iconName.indexOf('chevron') > -1) &&
this.flipRtl !== false);
// we have designated that arrows & chevrons should automatically flip (unless flip-rtl is set to false) because "back" is left in ltr and right in rtl, and "forward" is the opposite
const shouldAutoFlip = iconName
? (iconName.includes('arrow') || iconName.includes('chevron')) && flipRtl !== false
: false;
// if shouldBeFlippable is true, the icon should change direction when `dir` changes
const shouldBeFlippable = flipRtl || shouldAutoFlip;
/**
* Only set the aria-label if a) we have generated
* one for the icon and if aria-hidden is not set to "true".
* If developer wants to set their own aria-label, then
* inheritedAttributes down below will override whatever
* default label we have set.
*/
return (
<Host
aria-label={ariaLabel !== undefined && !this.hasAriaHidden() ? ariaLabel : null}
role="img"
class={{
[mode]: true,
...createColorClasses(this.color),
[`icon-${this.size}`]: !!this.size,
'flip-rtl': !!flipRtl && isRTL(el),
'flip-rtl': shouldBeFlippable,
'icon-rtl': shouldBeFlippable && isRTL(el)
}}
{...inheritedAttributes}
>
+36 -14
View File
@@ -1,29 +1,51 @@
import { validateContent } from './validate';
import { isEncodedDataUrl, isSvgDataUrl, validateContent } from './validate';
export const ioniconContent = new Map<string, string>();
const requests = new Map<string, Promise<any>>();
let parser: DOMParser;
export const getSvgContent = (url: string, sanitize: boolean) => {
// see if we already have a request for this url
let req = requests.get(url);
if (!req) {
if (typeof fetch !== 'undefined' && typeof document !== 'undefined') {
// we don't already have a request
req = fetch(url).then((rsp) => {
if (rsp.ok) {
return rsp.text().then((svgContent) => {
if (svgContent && sanitize !== false) {
svgContent = validateContent(svgContent);
}
ioniconContent.set(url, svgContent || '');
});
/**
* If the url is a data url of an svg, then try to parse it
* with the DOMParser. This works with content security policies enabled.
*/
if (isSvgDataUrl(url) && isEncodedDataUrl(url)) {
if (!parser) {
/**
* Create an instance of the DOM parser. This creates a single
* parser instance for the entire app, which is more efficient.
*/
parser = new DOMParser();
}
ioniconContent.set(url, '');
});
const doc = parser.parseFromString(url, 'text/html');
const svg = doc.querySelector('svg');
if (svg) {
ioniconContent.set(url, svg.outerHTML);
}
return Promise.resolve();
} else {
// we don't already have a request
req = fetch(url).then((rsp) => {
if (rsp.ok) {
return rsp.text().then((svgContent) => {
if (svgContent && sanitize !== false) {
svgContent = validateContent(svgContent);
}
ioniconContent.set(url, svgContent || '');
});
}
ioniconContent.set(url, '');
});
// cache for the same requests
requests.set(url, req);
}
// cache for the same requests
requests.set(url, req);
} else {
// set to empty for ssr scenarios and resolve promise
ioniconContent.set(url, '');
+59 -2
View File
@@ -4,10 +4,67 @@ import { test } from '@utils/test/playwright';
test.describe('icon: basic', () => {
test('should not have visual regressions', async ({ page }) => {
await page.goto(`/`);
// Wait for all SVGs to be lazily loaded before taking screenshots
await page.waitForLoadState('networkidle');
expect(await page.screenshot({ fullPage: true })).toMatchSnapshot(`icon-diff.png`);
});
});
test('some icons should flip when rtl', async ({ page }) => {
await page.goto(`/`);
const autoflip = page.locator('.auto-flip-chevrons [name=chevron-forward] .icon-inner');
const unflip = page.locator('.un-flip-chevrons [name=chevron-forward] .icon-inner');
await expect(autoflip).not.toHaveCSS('transform', /matrix\(-1/);
await expect(unflip).not.toHaveCSS('transform', /matrix\(-1/);
await page.evaluate(() => {
document.dir = 'rtl';
});
await expect(autoflip).toHaveCSS('transform', /matrix\(-1/);
await expect(unflip).not.toHaveCSS('transform', /matrix\(-1/);
// Wait for all SVGs to be lazily loaded before taking screenshots
await page.waitForLoadState('networkidle');
const rtlTests = page.locator('#rtl-tests');
await expect(rtlTests).toHaveScreenshot(`icon-rtl-diff.png`);
});
test('arrows should flip if dir changes on the element', async ({ page }) => {
await page.goto(`/`);
const autoflip = page.locator('.auto-flip-chevrons [name=chevron-forward] .icon-inner');
const unflip = page.locator('.un-flip-chevrons [name=chevron-forward] .icon-inner');
await expect(autoflip).not.toHaveCSS('transform', /matrix\(-1/);
await expect(unflip).not.toHaveCSS('transform', /matrix\(-1/);
const autoflipEl = await page.$('.auto-flip-chevrons [name=chevron-forward]');
const unflipEl = await page.$('.un-flip-chevrons [name=chevron-forward]');
await autoflipEl!.evaluate((node) => node.setAttribute('dir', 'rtl'));
await unflipEl!.evaluate((node) => node.setAttribute('dir', 'rtl'));
await expect(autoflip).toHaveCSS('transform', /matrix\(-1/);
await expect(unflip).not.toHaveCSS('transform', /matrix\(-1/);
});
test('icon should reassess flipping when name changes', async ({ page }) => {
await page.goto(`/`);
await page.evaluate(() => {
document.dir = 'rtl';
});
const iconLoc = page.locator('.auto-flip-chevrons ion-icon:nth-child(2)');
await expect(iconLoc).toHaveAttribute('name', 'chevron-forward');
await expect(iconLoc).toHaveClass(/flip-rtl/);
const iconEl = await page.$('.auto-flip-chevrons ion-icon:nth-child(2)');
await iconEl!.evaluate((node) => node.setAttribute('name', 'brush'));
await expect(iconLoc).toHaveAttribute('name', 'brush');
await expect(iconLoc).not.toHaveClass(/flip-rtl/);
});
});
Binary file not shown.

Before

Width:  |  Height:  |  Size: 325 KiB

After

Width:  |  Height:  |  Size: 316 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 98 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 301 KiB

After

Width:  |  Height:  |  Size: 306 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

+4 -63
View File
@@ -16,20 +16,6 @@ describe('icon', () => {
`);
});
it('renders aria-hidden and no aria-label', async () => {
const { root } = await newSpecPage({
components: [Icon],
html: `<ion-icon aria-hidden="true"></ion-icon>`,
});
expect(root).toEqualHtml(`
<ion-icon class="md" role="img" aria-hidden="true">
<mock:shadow-root>
<div class="icon-inner"></div>
</mock:shadow-root>
</ion-icon>
`);
});
it('renders rtl with aria-hidden', async () => {
const { root } = await newSpecPage({
components: [Icon],
@@ -38,22 +24,7 @@ describe('icon', () => {
});
expect(root).toEqualHtml(`
<ion-icon class="md flip-rtl" name="chevron-forward" role="img" aria-hidden="true">
<mock:shadow-root>
<div class="icon-inner"></div>
</mock:shadow-root>
</ion-icon>
`);
});
it('renders default aria-label', async () => {
const { root } = await newSpecPage({
components: [Icon],
html: `<ion-icon name="chevron-forward"></ion-icon>`,
});
expect(root).toEqualHtml(`
<ion-icon class="md" name="chevron-forward" role="img" aria-label="chevron forward">
<ion-icon class="md flip-rtl icon-rtl" name="chevron-forward" role="img" aria-hidden="true">
<mock:shadow-root>
<div class="icon-inner"></div>
</mock:shadow-root>
@@ -64,11 +35,11 @@ describe('icon', () => {
it('renders custom aria-label', async () => {
const { root } = await newSpecPage({
components: [Icon],
html: `<ion-icon name="chevron-forward" aria-label="custom label"></ion-icon>`,
html: `<ion-icon name="star" aria-label="custom label"></ion-icon>`,
});
expect(root).toEqualHtml(`
<ion-icon class="md" name="chevron-forward" role="img" aria-label="custom label">
<ion-icon class="md" name="star" role="img" aria-label="custom label">
<mock:shadow-root>
<div class="icon-inner"></div>
</mock:shadow-root>
@@ -85,7 +56,7 @@ describe('icon', () => {
const icon = page.root;
expect(icon).toEqualHtml(`
<ion-icon class="md" name="chevron-forward" role="img" aria-label="custom label">
<ion-icon class="flip-rtl md" name="chevron-forward" role="img" aria-label="custom label">
<mock:shadow-root>
<div class="icon-inner"></div>
</mock:shadow-root>
@@ -105,34 +76,4 @@ describe('icon', () => {
</ion-icon>
`);
});
it('renders default label after changing source', async () => {
const page = await newSpecPage({
components: [Icon],
html: `<ion-icon name="chevron-forward"></ion-icon>`,
});
const icon = page.root;
expect(icon).toEqualHtml(`
<ion-icon class="md" name="chevron-forward" role="img" aria-label="chevron forward">
<mock:shadow-root>
<div class="icon-inner"></div>
</mock:shadow-root>
</ion-icon>
`);
if (icon) {
icon.name = 'trash';
}
await page.waitForChanges();
expect(icon).toEqualHtml(`
<ion-icon class="md" name="trash" role="img" aria-label="trash">
<mock:shadow-root>
<div class="icon-inner"></div>
</mock:shadow-root>
</ion-icon>
`);
});
});
+25 -7
View File
@@ -1,4 +1,4 @@
import { isValid } from '../validate';
import { isEncodedDataUrl, isSvgDataUrl, isValid } from '../validate';
describe('isValid', () => {
@@ -24,9 +24,11 @@ describe('isValid', () => {
});
it('invalid child SCRIPT elm', () => {
const el = { nodeType: 1, nodeName: 'svg', attributes: [], childNodes: [
{ nodeType: 1, nodeName: 'SCRIPT', attributes: [], childNodes: [] }
] } as any;
const el = {
nodeType: 1, nodeName: 'svg', attributes: [], childNodes: [
{ nodeType: 1, nodeName: 'SCRIPT', attributes: [], childNodes: [] }
]
} as any;
expect(isValid(el)).toBe(false);
});
@@ -41,9 +43,11 @@ describe('isValid', () => {
});
it('is valid SVG elm', () => {
const el = { nodeType: 1, nodeName: 'SVG', attributes: [], childNodes: [
{ nodeType: 1, nodeName: 'line', attributes: [], childNodes: [] }
] } as any;
const el = {
nodeType: 1, nodeName: 'SVG', attributes: [], childNodes: [
{ nodeType: 1, nodeName: 'line', attributes: [], childNodes: [] }
]
} as any;
expect(isValid(el)).toBe(true);
});
@@ -53,3 +57,17 @@ describe('isValid', () => {
});
});
it('isSvgDataUrl', () => {
expect(isSvgDataUrl('data:image/svg+xml;base64,xxx')).toBe(true);
expect(isSvgDataUrl('data:image/svg+xml;utf8,<svg></svg>')).toBe(true);
expect(isSvgDataUrl('https://example.com/icon.svg')).toBe(false);
expect(isSvgDataUrl('http://example.com/icon.svg')).toBe(false);
});
it('isEncodedDataUrl', () => {
expect(isEncodedDataUrl('data:image/svg+xml;base64,xxx')).toBe(false);
expect(isEncodedDataUrl('data:image/svg+xml;utf8,<svg></svg>')).toBe(true);
expect(isEncodedDataUrl('https://example.com/icon.svg')).toBe(false);
expect(isEncodedDataUrl('http://example.com/icon.svg')).toBe(false);
});
+3
View File
@@ -48,3 +48,6 @@ export const isValid = (elm: HTMLElement) => {
}
return true;
};
export const isSvgDataUrl = (url: string) => url.startsWith('data:image/svg+xml');
export const isEncodedDataUrl = (url: string) => url.indexOf(';utf8,') !== -1;
+46
View File
@@ -2545,6 +2545,29 @@
"sharp"
]
},
{
"name": "chevron-collapse",
"tags": [
"chevron",
"collapse"
]
},
{
"name": "chevron-collapse-outline",
"tags": [
"chevron",
"collapse",
"outline"
]
},
{
"name": "chevron-collapse-sharp",
"tags": [
"chevron",
"collapse",
"sharp"
]
},
{
"name": "chevron-down",
"tags": [
@@ -2600,6 +2623,29 @@
"sharp"
]
},
{
"name": "chevron-expand",
"tags": [
"chevron",
"expand"
]
},
{
"name": "chevron-expand-outline",
"tags": [
"chevron",
"expand",
"outline"
]
},
{
"name": "chevron-expand-sharp",
"tags": [
"chevron",
"expand",
"sharp"
]
},
{
"name": "chevron-forward",
"tags": [
+46 -36
View File
@@ -86,49 +86,55 @@
<ion-icon name="cellular" aria-label="Mobile data"></ion-icon>
<ion-icon name="cellular" aria-hidden="true"></ion-icon>
<h1>RTL</h1>
<div id="rtl-tests">
<h1>RTL</h1>
<h2>Default: Non-arrows</h2>
<ion-icon name="cut"></ion-icon>
<ion-icon name="call"></ion-icon>
<ion-icon name="checkbox"></ion-icon>
<ion-icon name="brush"></ion-icon>
<h2>Default: Non-arrows</h2>
<ion-icon name="cut"></ion-icon>
<ion-icon name="call"></ion-icon>
<ion-icon name="checkbox"></ion-icon>
<ion-icon name="brush"></ion-icon>
<h2>Flip: Non-arrows</h2>
<ion-icon name="cut" flip-rtl></ion-icon>
<ion-icon name="call" flip-rtl></ion-icon>
<ion-icon name="checkbox" flip-rtl></ion-icon>
<ion-icon name="brush" flip-rtl></ion-icon>
<h2>Flip: Non-arrows</h2>
<ion-icon name="cut" flip-rtl></ion-icon>
<ion-icon name="call" flip-rtl></ion-icon>
<ion-icon name="checkbox" flip-rtl></ion-icon>
<ion-icon name="brush" flip-rtl></ion-icon>
<h2>Auto Flip: arrows</h2>
<ion-icon name="arrow-up"></ion-icon>
<ion-icon name="arrow-forward"></ion-icon>
<ion-icon name="arrow-down"></ion-icon>
<ion-icon name="arrow-back"></ion-icon>
<h2>Auto Flip: arrows</h2>
<ion-icon name="arrow-up"></ion-icon>
<ion-icon name="arrow-forward"></ion-icon>
<ion-icon name="arrow-down"></ion-icon>
<ion-icon name="arrow-back"></ion-icon>
<h2>Un-flip: arrows</h2>
<ion-icon name="arrow-up" flip-rtl="false"></ion-icon>
<ion-icon name="arrow-forward" flip-rtl="false"></ion-icon>
<ion-icon name="arrow-down" flip-rtl="false"></ion-icon>
<ion-icon name="arrow-back" flip-rtl="false"></ion-icon>
<h2>Un-flip: arrows</h2>
<ion-icon name="arrow-up" flip-rtl="false"></ion-icon>
<ion-icon name="arrow-forward" flip-rtl="false"></ion-icon>
<ion-icon name="arrow-down" flip-rtl="false"></ion-icon>
<ion-icon name="arrow-back" flip-rtl="false"></ion-icon>
<h2>Auto Flip: chevrons</h2>
<ion-icon name="chevron-up"></ion-icon>
<ion-icon name="chevron-forward"></ion-icon>
<ion-icon name="chevron-down"></ion-icon>
<ion-icon name="chevron-back"></ion-icon>
<h2>Auto Flip: chevrons</h2>
<div class="auto-flip-chevrons">
<ion-icon name="chevron-up"></ion-icon>
<ion-icon name="chevron-forward"></ion-icon>
<ion-icon name="chevron-down"></ion-icon>
<ion-icon name="chevron-back"></ion-icon>
</div>
<h2>Un-flip: chevrons</h2>
<ion-icon name="chevron-up" flip-rtl="false"></ion-icon>
<ion-icon name="chevron-forward" flip-rtl="false"></ion-icon>
<ion-icon name="chevron-down" flip-rtl="false"></ion-icon>
<ion-icon name="chevron-back" flip-rtl="false"></ion-icon>
<h2>Un-flip: chevrons</h2>
<div class="un-flip-chevrons">
<ion-icon name="chevron-up" flip-rtl="false"></ion-icon>
<ion-icon name="chevron-forward" flip-rtl="false"></ion-icon>
<ion-icon name="chevron-down" flip-rtl="false"></ion-icon>
<ion-icon name="chevron-back" flip-rtl="false"></ion-icon>
</div>
<h2>Auto Flip, RTL on components</h2>
<ion-icon name="arrow-up" dir="rtl" flip-rtl></ion-icon>
<ion-icon name="arrow-forward" dir="rtl" flip-rtl></ion-icon>
<ion-icon name="arrow-down" dir="rtl" flip-rtl></ion-icon>
<ion-icon name="arrow-back" dir="rtl" flip-rtl></ion-icon>
<h2>Auto Flip, RTL on components</h2>
<ion-icon name="arrow-up" dir="rtl" flip-rtl></ion-icon>
<ion-icon name="arrow-forward" dir="rtl" flip-rtl></ion-icon>
<ion-icon name="arrow-down" dir="rtl" flip-rtl></ion-icon>
<ion-icon name="arrow-back" dir="rtl" flip-rtl></ion-icon>
</div>
<h2>Sanitized (shouldn't show)</h2>
<ion-icon src="./assets/sanitize.svg"></ion-icon>
@@ -136,6 +142,10 @@
<h2>Not Sanitized (should show)</h2>
<ion-icon sanitize="false" src="./assets/no-sanitize.svg"></ion-icon>
<h2>Base64 url</h2>
<ion-icon
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSJub25lIiBkPSJNMCAwaDI0djI0SDBWMHoiLz48cGF0aCBkPSJNMjAgMkg0Yy0xLjEgMC0yIC45LTIgMnYxOGw0LTRoMTRjMS4xIDAgMi0uOSAyLTJWNGMwLTEuMS0uOS0yLTItMnptMCAxNEg2bC0yIDJWNGgxNnYxMnoiLz48L3N2Zz4="></ion-icon>
<p>
<a href="./cheatsheet.html">Cheatsheet</a>
</p>
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M136 104L256 208L376 104" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/><path d="M136 408L256 304L376 408" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="32"/></svg>

After

Width:  |  Height:  |  Size: 338 B

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor"><path d="M102.145 108.514L256 241.855l153.855-133.341-31.437-36.273L256 178.337 133.582 72.241l-31.437 36.273zm0 294.972L256 270.145l153.855 133.341-31.437 36.273L256 333.663 133.582 439.759l-31.437-36.273z"/></svg>

After

Width:  |  Height:  |  Size: 297 B

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M117.863 88.282c-8.681 10.017-7.598 25.174 2.419 33.855l120 104c9.02 7.818 22.416 7.818 31.436 0l120-104c10.017-8.681 11.1-23.838 2.419-33.855s-23.839-11.099-33.855-2.418L256 176.241 151.718 85.864c-10.016-8.681-25.174-7.598-33.855 2.418zm0 335.436c-8.681-10.017-7.598-25.174 2.419-33.855l120-104c9.02-7.818 22.416-7.818 31.436 0l120 104c10.017 8.681 11.1 23.838 2.419 33.855s-23.839 11.099-33.855 2.418L256 335.759l-104.282 90.377c-10.016 8.681-25.174 7.598-33.855-2.418z"/></svg>

After

Width:  |  Height:  |  Size: 552 B

+1
View File
@@ -0,0 +1 @@
<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="M136 208L256 104L376 208" stroke="currentColor" fill="none" stroke-width="32" stroke-linecap="round" stroke-linejoin="round"/><path d="M136 304L256 408L376 304" stroke="currentColor" fill="none" stroke-width="32" stroke-linecap="round" stroke-linejoin="round"/></svg>

After

Width:  |  Height:  |  Size: 339 B

+1
View File
@@ -0,0 +1 @@
<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="M136 208L256 104L376 208" fill="none" stroke="currentColor" stroke-width="48" stroke-linecap="square"/><path d="M136 304L256 408L376 304" fill="none" stroke="currentColor" stroke-width="48" stroke-linecap="square"/></svg>

After

Width:  |  Height:  |  Size: 293 B

+1
View File
@@ -0,0 +1 @@
<svg viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path d="M136 208L256 104L376 208" fill="none" stroke="currentColor" stroke-width="48" stroke-linecap="round" stroke-linejoin="round"/><path d="M136 304L256 408L376 304" fill="none" stroke="currentColor" stroke-width="48" stroke-linecap="round" stroke-linejoin="round"/></svg>

After

Width:  |  Height:  |  Size: 339 B