Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3cf1fb9cb |
@@ -0,0 +1,80 @@
|
||||
# Contributing
|
||||
|
||||
Thanks for your interest in contributing to Ionicons! :tada:
|
||||
|
||||
|
||||
## Contributing Etiquette
|
||||
|
||||
Please see our [Contributor Code of Conduct](./CODE_OF_CONDUCT.md) for information on our rules of conduct.
|
||||
|
||||
|
||||
## 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 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.
|
||||
|
||||
* The issue list of this repository is exclusively for bug reports and feature requests. Non-conforming issues will be closed immediately.
|
||||
|
||||
* If you think you have found a bug, or have a new feature idea, please start by making sure it hasn't already been [reported](https://github.com/ionic-team/ionicons/issues?utf8=%E2%9C%93&q=is%3Aissue). You can search through existing issues to see if there is a similar one reported. Include closed issues as it may have been closed with a solution.
|
||||
|
||||
* Next, [create a new issue](https://github.com/ionic-team/ionicons/issues/new/choose) that thoroughly explains the problem.
|
||||
|
||||
|
||||
## Creating a Pull Request
|
||||
|
||||
* We appreciate you taking the time to contribute! Before submitting a pull request, we ask that you please [create an issue](#creating-an-issue) that explains the bug or feature request and let us know that you plan on creating a pull request for it. If an issue already exists, please comment on that issue letting us know you would like to submit a pull request for it. This helps us to keep track of the pull request and make sure there isn't duplicated effort.
|
||||
|
||||
* Looking for an issue to fix? Make sure to look through our issues with the [help wanted](https://github.com/ionic-team/ionicons/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) label!
|
||||
|
||||
|
||||
## Adding or Modifiying Icons
|
||||
|
||||
While we appreciate all contributions, please note that we do not accept contributions that add or modify icon SVG assets. All SVG asset modifications are done by Ionic's in-house design team to ensure design consistency across the entire icon set. If there is an icon you need added or an existing icon you need modified please [create a new issue](https://github.com/ionic-team/ionicons/issues/new/choose).
|
||||
|
||||
Contributions that fix bugs in or add features to the `ion-icon` component are welcome!
|
||||
|
||||
|
||||
### Setup
|
||||
|
||||
1. [Download the installer](https://nodejs.org/) for the LTS version of Node.js. This is the best way to also [install npm](https://blog.npmjs.org/post/85484771375/how-to-install-npm#_=_).
|
||||
2. Fork this repository.
|
||||
3. Clone your fork.
|
||||
4. Create a new branch from `main` for your change.
|
||||
5. Run `npm install` from the root directory to install dependencies for this package.
|
||||
6. Run `npm run build` to perform a first time build.
|
||||
7. [Modify the Icon Component](#modifying-components) if desired.
|
||||
8. Or, modify and [preview the site](#preview-site).
|
||||
|
||||
|
||||
#### 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 the changes](#preview-component-changes).
|
||||
|
||||
|
||||
#### Preview Component Changes
|
||||
|
||||
1. Run `npm start` from the root directory to start a local version of the icon test.
|
||||
2. Modify the icon test as needed in the `index.html` file.
|
||||
3. If you are modifying icons, you can run `npm run build.files` to re-run the SVG optimization script to verify there are no changes after optimizing the SVG.
|
||||
|
||||
<!-- #### Building Changes
|
||||
|
||||
TODO -->
|
||||
|
||||
|
||||
### Submit Pull Request
|
||||
|
||||
1. [Create a new pull request](https://github.com/ionic-team/ionicons/compare) with the `main` branch as the `base`. You may need to click on `compare across forks` to find your changes.
|
||||
2. See the [Creating a pull request from a fork](https://help.github.com/articles/creating-a-pull-request-from-a-fork/) GitHub help article for more information.
|
||||
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.
|
||||
@@ -1,7 +1,7 @@
|
||||
name: 🐛 Bug Report
|
||||
description: Report a bug in the ion-icon component. Incorrect icons should use the "Incorrect Icon" template instead.
|
||||
labels: ['triage']
|
||||
title: 'bug: '
|
||||
labels: ["triage"]
|
||||
title: "bug: "
|
||||
body:
|
||||
- type: textarea
|
||||
attributes:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: 💡 Feature Request
|
||||
description: Suggest a new feature for the ion-icon component. Icon requests should use the "Icon Request" template instead.
|
||||
labels: ['triage']
|
||||
title: 'feat: '
|
||||
labels: ["triage"]
|
||||
title: "feat: "
|
||||
body:
|
||||
- type: textarea
|
||||
attributes:
|
||||
@@ -20,4 +20,4 @@ body:
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional Information
|
||||
description: Add any other context or screenshots about the feature request here.
|
||||
description: Add any other context or screenshots about the feature request here.
|
||||
@@ -1,7 +1,7 @@
|
||||
name: 🚀 Icon Request
|
||||
description: Request a new icon
|
||||
labels: ['triage']
|
||||
title: 'icon request: '
|
||||
labels: ["triage"]
|
||||
title: "icon request: "
|
||||
body:
|
||||
- type: textarea
|
||||
attributes:
|
||||
@@ -16,4 +16,4 @@ body:
|
||||
- type: textarea
|
||||
attributes:
|
||||
label: Additional Information
|
||||
description: Add any other context about the icon request here.
|
||||
description: Add any other context about the icon request here.
|
||||
@@ -1,7 +1,7 @@
|
||||
name: 😒 Incorrect Icon
|
||||
description: Report an incorrect icon
|
||||
labels: ['triage']
|
||||
title: 'incorrect icon: '
|
||||
labels: ["triage"]
|
||||
title: "incorrect icon: "
|
||||
body:
|
||||
- type: textarea
|
||||
attributes:
|
||||
@@ -14,4 +14,4 @@ body:
|
||||
label: Expected Behavior
|
||||
description: A clear description of what the icon should look like. Please include any relevant screenshots.
|
||||
validations:
|
||||
required: true
|
||||
required: true
|
||||
@@ -26,7 +26,7 @@ closeAndLock:
|
||||
|
||||
comment:
|
||||
labels:
|
||||
- label: 'help wanted'
|
||||
- label: "help wanted"
|
||||
message: >
|
||||
This issue has been labeled as `help wanted`. This label is added to issues
|
||||
that we believe would be good for contributors.
|
||||
@@ -54,13 +54,13 @@ comment:
|
||||
|
||||
If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was
|
||||
not enough for our team to reproduce the issue.
|
||||
- label: 'community feedback wanted'
|
||||
- label: "community feedback wanted"
|
||||
message: >
|
||||
This issue has been labeled as `community feedback wanted`. This label is added to issues that we would like to hear from the community on before moving forward with any final decision on the feature request.
|
||||
|
||||
|
||||
If the requested feature is something you would find useful for your applications, please react to the original post with 👍 (`+1`). If you would like to provide an additional use case for the feature, please post a comment.
|
||||
|
||||
|
||||
|
||||
The team will review this feedback and make a final decision. Any decision will be posted on this thread, but please note that we may ultimately decide not to pursue this feature.
|
||||
|
||||
@@ -71,7 +71,7 @@ comment:
|
||||
noReply:
|
||||
days: 14
|
||||
maxIssuesPerRun: 100
|
||||
label: 'needs: reply'
|
||||
label: "needs: reply"
|
||||
responseLabel: triage
|
||||
exemptProjects: true
|
||||
exemptMilestones: true
|
||||
@@ -89,7 +89,7 @@ noReply:
|
||||
noReproduction:
|
||||
days: 14
|
||||
maxIssuesPerRun: 100
|
||||
label: 'ionitron: needs reproduction'
|
||||
label: "ionitron: needs reproduction"
|
||||
responseLabel: triage
|
||||
exemptProjects: true
|
||||
exemptMilestones: true
|
||||
|
||||
@@ -3,14 +3,14 @@ description: 'Build Ionicons'
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
# Checkout the latest commit in this branch
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
- uses: actions/setup-node@v4
|
||||
- uses: actions/setup-node@v3
|
||||
|
||||
- name: Cache Node Modules
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: node-modules
|
||||
with:
|
||||
@@ -31,4 +31,4 @@ runs:
|
||||
with:
|
||||
name: ionicons-src
|
||||
output: IoniconsSrc.zip
|
||||
paths: src
|
||||
paths: src
|
||||
@@ -10,10 +10,10 @@ inputs:
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- uses: actions/download-artifact@v4
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: ${{ inputs.name }}
|
||||
path: ${{ inputs.path }}
|
||||
- name: Exract Archive
|
||||
run: unzip -q -o ${{ inputs.path }}/${{ inputs.filename }}
|
||||
shell: bash
|
||||
shell: bash
|
||||
@@ -10,18 +10,14 @@ inputs:
|
||||
folder:
|
||||
default: './'
|
||||
description: 'A folder containing a package.json file.'
|
||||
createRelease:
|
||||
description: 'Create a release on GitHub.'
|
||||
default: 'false'
|
||||
ghToken:
|
||||
description: 'The GitHub authentication token required to create a release.'
|
||||
|
||||
token:
|
||||
description: 'The NPM authentication token required to publish.'
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- uses: actions/setup-node@v4
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 22.x
|
||||
node-version: 18.x
|
||||
- name: Install latest npm
|
||||
run: npm install -g npm@latest
|
||||
shell: bash
|
||||
@@ -29,35 +25,21 @@ runs:
|
||||
run: npm ci
|
||||
shell: bash
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
- name: Set Git User
|
||||
run: |
|
||||
git config user.name ionitron
|
||||
git config user.email hi@ionicframework.com
|
||||
shell: bash
|
||||
- name: Update Version
|
||||
id: update_version
|
||||
run: |
|
||||
npm version ${{ inputs.version }}
|
||||
echo "VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_ENV
|
||||
run: npm version ${{ inputs.version }} --git-tag-version false
|
||||
shell: bash
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
- name: Run Build
|
||||
run: npm run build
|
||||
shell: bash
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
- name: Prepare NPM Token
|
||||
run: echo //registry.npmjs.org/:_authToken=${NPM_TOKEN} > .npmrc
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
shell: bash
|
||||
env:
|
||||
NPM_TOKEN: ${{ inputs.token }}
|
||||
- name: Publish to NPM
|
||||
run: npm publish ${{ inputs.folder }} --tag ${{ inputs.tag }} --provenance
|
||||
shell: bash
|
||||
working-directory: ${{ inputs.working-directory }}
|
||||
|
||||
- name: Create Release
|
||||
if: ${{ inputs.createRelease == 'true' }}
|
||||
run: |
|
||||
git remote set-url origin https://${GH_TOKEN}:x-oauth-basic@github.com/ionic-team/ionicons.git
|
||||
git remote -v
|
||||
git push origin main --tags
|
||||
gh release create "v$VERSION" --title "v$VERSION" --generate-notes
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ inputs.ghToken }}
|
||||
VERSION: ${{ env.VERSION }}
|
||||
|
||||
@@ -10,10 +10,10 @@ inputs:
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- uses: actions/setup-node@v4
|
||||
- uses: actions/setup-node@v3
|
||||
|
||||
- name: Cache Node Modules
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: node-modules
|
||||
with:
|
||||
@@ -65,7 +65,7 @@ runs:
|
||||
shell: bash
|
||||
- name: Archive Updated Screenshots
|
||||
if: inputs.update == 'true' && steps.test-and-update.outputs.hasUpdatedScreenshots == 'true'
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: updated-screenshots-${{ inputs.shard }}-${{ inputs.totalShards }}
|
||||
path: UpdatedScreenshots-${{ inputs.shard }}-${{ inputs.totalShards }}.zip
|
||||
@@ -81,4 +81,4 @@ runs:
|
||||
with:
|
||||
name: test-results-${{ inputs.shard }}-${{ inputs.totalShards }}
|
||||
output: TestResults-${{ inputs.shard }}-${{ inputs.totalShards }}.zip
|
||||
paths: playwright-report
|
||||
paths: playwright-report
|
||||
@@ -3,10 +3,10 @@ description: 'Test Spec'
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- uses: actions/setup-node@v4
|
||||
- uses: actions/setup-node@v3
|
||||
|
||||
- name: Cache Node Modules
|
||||
uses: actions/cache@v4
|
||||
uses: actions/cache@v3
|
||||
env:
|
||||
cache-name: node-modules
|
||||
with:
|
||||
|
||||
@@ -7,8 +7,8 @@ on:
|
||||
runs:
|
||||
using: 'composite'
|
||||
steps:
|
||||
- uses: actions/setup-node@v4
|
||||
- uses: actions/download-artifact@v4
|
||||
- uses: actions/setup-node@v3
|
||||
- uses: actions/download-artifact@v3
|
||||
with:
|
||||
path: ./artifacts
|
||||
- name: Extract Archives
|
||||
@@ -35,4 +35,4 @@ runs:
|
||||
git add src/\*.png --force
|
||||
git commit -m "chore(): add updated snapshots"
|
||||
git push
|
||||
shell: bash
|
||||
shell: bash
|
||||
@@ -13,7 +13,7 @@ runs:
|
||||
- name: Create Archive
|
||||
run: zip -q -r ${{ inputs.output }} ${{ inputs.paths }}
|
||||
shell: bash
|
||||
- uses: actions/upload-artifact@v4
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{ inputs.name }}
|
||||
path: ${{ inputs.output }}
|
||||
path: ${{ inputs.output }}
|
||||
@@ -1,10 +1,8 @@
|
||||
name: 'Validation'
|
||||
name: 'Ionicons Build'
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: ['**']
|
||||
push:
|
||||
branches: ['main']
|
||||
branches: [ '**' ]
|
||||
|
||||
# When pushing a new commit we should
|
||||
# cancel the previous test run to not
|
||||
@@ -17,7 +15,7 @@ jobs:
|
||||
build-core:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
# Checkout the latest commit in this branch
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
@@ -27,9 +25,9 @@ jobs:
|
||||
needs: [build-core]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ./.github/workflows/actions/test-spec
|
||||
|
||||
|
||||
test-e2e:
|
||||
strategy:
|
||||
# This ensures that all screenshot shard
|
||||
@@ -48,12 +46,12 @@ jobs:
|
||||
needs: [build-core]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ./.github/workflows/actions/test-e2e
|
||||
with:
|
||||
shard: ${{ matrix.shard }}
|
||||
totalShards: ${{ matrix.totalShards }}
|
||||
|
||||
|
||||
# Screenshots are required to pass
|
||||
# in order for the branch to be merge
|
||||
# eligible. However, the screenshot tests
|
||||
@@ -70,4 +68,4 @@ jobs:
|
||||
steps:
|
||||
- name: Check build matrix status
|
||||
if: ${{ needs.test-e2e.result != 'success' }}
|
||||
run: exit 1
|
||||
run: exit 1
|
||||
@@ -1,7 +1,7 @@
|
||||
name: 'Dev Release'
|
||||
name: 'Ionicons Dev Build'
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
create-dev-hash:
|
||||
@@ -9,7 +9,7 @@ jobs:
|
||||
outputs:
|
||||
dev-hash: ${{ steps.create-dev-hash.outputs.DEV_HASH }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- name: Install Dependencies
|
||||
run: npm ci --no-package-lock
|
||||
shell: bash
|
||||
@@ -20,20 +20,13 @@ jobs:
|
||||
shell: bash
|
||||
|
||||
release-ionicons:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [create-dev-hash]
|
||||
permissions:
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Publish to NPM
|
||||
uses: ./.github/workflows/actions/publish-npm
|
||||
with:
|
||||
tag: dev
|
||||
version: ${{ needs.create-dev-hash.outputs.dev-hash }}
|
||||
working-directory: './'
|
||||
createRelease: 'false'
|
||||
uses: ./.github/workflows/release-ionicons.yml
|
||||
with:
|
||||
tag: dev
|
||||
version: ${{ needs.create-dev-hash.outputs.dev-hash }}
|
||||
secrets:
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
get-build:
|
||||
name: Get your dev build!
|
||||
@@ -1,28 +0,0 @@
|
||||
name: 'Production Release'
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
version:
|
||||
required: false
|
||||
type: string
|
||||
description: npm version (major, minor, or patch)
|
||||
|
||||
jobs:
|
||||
release-ionicons:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
token: ${{ secrets.IONITRON_TOKEN }}
|
||||
- name: Publish to NPM
|
||||
uses: ./.github/workflows/actions/publish-npm
|
||||
with:
|
||||
tag: latest
|
||||
version: ${{ inputs.version }}
|
||||
working-directory: './'
|
||||
createRelease: true
|
||||
ghToken: ${{ secrets.IONITRON_TOKEN }}
|
||||
@@ -0,0 +1,30 @@
|
||||
name: 'Release Ionicons'
|
||||
|
||||
on:
|
||||
workflow_call:
|
||||
inputs:
|
||||
version:
|
||||
description: 'The type of version to release.'
|
||||
type: string
|
||||
required: true
|
||||
tag:
|
||||
description: 'The tag to publish to on NPM.'
|
||||
type: string
|
||||
required: true
|
||||
secrets:
|
||||
NPM_TOKEN:
|
||||
required: true
|
||||
|
||||
jobs:
|
||||
release-core:
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
id-token: write
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ./.github/workflows/actions/publish-npm
|
||||
with:
|
||||
tag: ${{ inputs.tag }}
|
||||
version: ${{ inputs.version }}
|
||||
working-directory: './'
|
||||
token: ${{ secrets.NPM_TOKEN }}
|
||||
@@ -1,37 +0,0 @@
|
||||
name: 'Release Orchestrator'
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
release-type:
|
||||
description: 'Release type'
|
||||
required: true
|
||||
type: choice
|
||||
options:
|
||||
- dev
|
||||
- production
|
||||
version:
|
||||
description: 'Version for production releases'
|
||||
required: false
|
||||
type: choice
|
||||
options:
|
||||
- patch
|
||||
- minor
|
||||
- major
|
||||
|
||||
permissions:
|
||||
id-token: write
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
run-dev:
|
||||
if: ${{ inputs.release-type == 'dev' }}
|
||||
uses: ./.github/workflows/dev-release.yml
|
||||
secrets: inherit
|
||||
|
||||
run-production:
|
||||
if: ${{ inputs.release-type == 'production' }}
|
||||
uses: ./.github/workflows/production-release.yml
|
||||
secrets: inherit
|
||||
with:
|
||||
version: ${{ inputs.version }}
|
||||
@@ -0,0 +1,97 @@
|
||||
name: 'Ionicons Production Release'
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
required: true
|
||||
type: choice
|
||||
description: Which version should be published?
|
||||
options:
|
||||
- patch
|
||||
- minor
|
||||
- major
|
||||
tag:
|
||||
required: true
|
||||
type: choice
|
||||
description: Which npm tag should this be published to?
|
||||
options:
|
||||
- latest
|
||||
|
||||
jobs:
|
||||
release-ionicons:
|
||||
uses: ./.github/workflows/release-ionicons.yml
|
||||
with:
|
||||
tag: ${{ inputs.tag }}
|
||||
version: ${{ inputs.version }}
|
||||
secrets:
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
finalize-release:
|
||||
needs: [release-ionicons]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
token: ${{ secrets.IONITRON_TOKEN }}
|
||||
fetch-depth: 0
|
||||
- name: Configure Identity
|
||||
# Commits from github-actions do not
|
||||
# trigger other GitHub Actions. As a result,
|
||||
# we publish releases from Ionitron instead
|
||||
# so actions run when merging the release branch
|
||||
# back into main.
|
||||
run: |
|
||||
git config user.name ionitron
|
||||
git config user.email hi@ionicframework.com
|
||||
shell: bash
|
||||
# This ensures the local version of Lerna is installed
|
||||
# and that we do not use the global Lerna version. We currently
|
||||
# rely on functionality that does not exist in newer versions of Lerna.
|
||||
- name: Install root dependencies
|
||||
run: npm ci
|
||||
shell: bash
|
||||
- name: Create GitHub Release
|
||||
run: npx lerna@5 version ${{ inputs.version }} --yes --force-publish='*' --conventional-commits --create-release github
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
shell: bash
|
||||
|
||||
update-package-lock:
|
||||
# This needs to run after finalize-release
|
||||
# because we also push to the repo in that
|
||||
# job. If these jobs ran in parallel then it is
|
||||
# possible for them to push at the same time.
|
||||
needs: [finalize-release]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
# Pull the latest version of the reference
|
||||
# branch instead of the revision that triggered
|
||||
# the workflow otherwise we won't get the commit
|
||||
# created in the previous job and this next job
|
||||
# will fail.
|
||||
with:
|
||||
ref: ${{ github.ref }}
|
||||
- name: Configure Identity
|
||||
# Commits from github-actions do not
|
||||
# trigger other GitHub Actions. As a result,
|
||||
# we push from Ionitron instead so actions
|
||||
# run when merging the release branch
|
||||
# back into main.
|
||||
run: |
|
||||
git config user.name ionitron
|
||||
git config user.email hi@ionicframework.com
|
||||
shell: bash
|
||||
# Lerna does not automatically bump versions
|
||||
# of Ionicons dependencies that have changed,
|
||||
# so we do that here.
|
||||
- name: Bump Package Lock
|
||||
run: |
|
||||
npx lerna@5 exec "npm install --package-lock-only --legacy-peer-deps"
|
||||
git add .
|
||||
git commit -m "chore(): update package lock files"
|
||||
git push
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
shell: bash
|
||||
@@ -7,7 +7,7 @@ jobs:
|
||||
build-core:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ./.github/workflows/actions/build-core
|
||||
|
||||
test-e2e:
|
||||
@@ -28,7 +28,7 @@ jobs:
|
||||
needs: [build-core]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ./.github/workflows/actions/test-e2e
|
||||
with:
|
||||
shard: ${{ matrix.shard }}
|
||||
@@ -39,7 +39,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [test-e2e]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v3
|
||||
# Normally, we could just push with the
|
||||
# default GITHUB_TOKEN, but that will
|
||||
# not cause the build workflow
|
||||
@@ -49,4 +49,4 @@ jobs:
|
||||
# to run when the screenshots are pushed.
|
||||
with:
|
||||
token: ${{ secrets.IONITRON_TOKEN }}
|
||||
- uses: ./.github/workflows/actions/update-reference-screenshots
|
||||
- uses: ./.github/workflows/actions/update-reference-screenshots
|
||||
@@ -24,4 +24,3 @@ www/
|
||||
/playwright-report/
|
||||
/playwright/.cache/
|
||||
/src/**/*-snapshots
|
||||
*.tgz
|
||||
@@ -1 +0,0 @@
|
||||
src/components.d.ts
|
||||
@@ -1,3 +1,224 @@
|
||||
# Change Log
|
||||
|
||||
Please see https://github.com/ionic-team/ionicons/releases
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
# [7.4.0](https://github.com/ionic-team/ionicons/compare/v7.3.1...v7.4.0) (2024-05-01)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add X logo ([#1371](https://github.com/ionic-team/ionicons/issues/1371)) ([0963fe2](https://github.com/ionic-team/ionicons/commit/0963fe20b77a03b0b8b7f4e94b646cd5d7b25f03)), closes [#1249](https://github.com/ionic-team/ionicons/issues/1249)
|
||||
* export setAssetPath ([#1372](https://github.com/ionic-team/ionicons/issues/1372)) ([87f2094](https://github.com/ionic-team/ionicons/commit/87f2094890c22b7b03bf754b6fd2651a83fe20ed)), closes [#1302](https://github.com/ionic-team/ionicons/issues/1302)
|
||||
* update server icon ([#1259](https://github.com/ionic-team/ionicons/issues/1259)) ([b4ade9d](https://github.com/ionic-team/ionicons/commit/b4ade9d887c0d5ecc29e25f8e12b576106de712a)), closes [#407](https://github.com/ionic-team/ionicons/issues/407)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [7.3.1](https://github.com/ionic-team/ionicons/compare/v7.3.0...v7.3.1) (2024-03-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* filled ellipsis circle icons renders correctly ([#1353](https://github.com/ionic-team/ionicons/issues/1353)) ([63e60ec](https://github.com/ionic-team/ionicons/commit/63e60ec44c11bda5902b5a496113f65a5e6f3d85)), closes [#1320](https://github.com/ionic-team/ionicons/issues/1320)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [7.3.0](https://github.com/ionic-team/ionicons/compare/v7.2.3...v7.3.0) (2024-03-20)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add appflow icon ([#1262](https://github.com/ionic-team/ionicons/issues/1262)) ([fa5e765](https://github.com/ionic-team/ionicons/commit/fa5e7659fc1622908c4e55b01d0573017a36af6a))
|
||||
* add arrow box icons ([#1265](https://github.com/ionic-team/ionicons/issues/1265)) ([d5a55f8](https://github.com/ionic-team/ionicons/commit/d5a55f8541b208ab46dd41e53528aab48a90ed10))
|
||||
* add binoculars icons ([#1258](https://github.com/ionic-team/ionicons/issues/1258)) ([3024818](https://github.com/ionic-team/ionicons/commit/302481846e48428a354bc36220506001ac4c645e))
|
||||
* add trapeze icon ([#1260](https://github.com/ionic-team/ionicons/issues/1260)) ([3b85413](https://github.com/ionic-team/ionicons/commit/3b85413a059b2c91f10105d576cc717fd687a491))
|
||||
* add updated wifi logos ([#1264](https://github.com/ionic-team/ionicons/issues/1264)) ([26aac36](https://github.com/ionic-team/ionicons/commit/26aac36334cc09e5887523bc99c3d746586ebb63)), closes [#323](https://github.com/ionic-team/ionicons/issues/323)
|
||||
* add updated yahoo icon ([#1266](https://github.com/ionic-team/ionicons/issues/1266)) ([c6ed6b6](https://github.com/ionic-team/ionicons/commit/c6ed6b629e45465b49e8e35db3830083ca9520ef))
|
||||
* **doc:** add Web Types ([#1301](https://github.com/ionic-team/ionicons/issues/1301)) ([f946a3e](https://github.com/ionic-team/ionicons/commit/f946a3ee3a4a1c2bdf9508b11a71fcb0a419d571))
|
||||
* update gitlab logo ([#1261](https://github.com/ionic-team/ionicons/issues/1261)) ([2586fb2](https://github.com/ionic-team/ionicons/commit/2586fb26b2a493fcb4b5b0156dd00d6b5eab1ab0)), closes [#613](https://github.com/ionic-team/ionicons/issues/613)
|
||||
* update ionic logo ([#1263](https://github.com/ionic-team/ionicons/issues/1263)) ([50fe570](https://github.com/ionic-team/ionicons/commit/50fe570566d4c28de7fb10694543cd6dc72f3935))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [7.3.0](https://github.com/ionic-team/ionicons/compare/v7.2.3...v7.3.0) (2024-03-20)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* add appflow icon ([#1262](https://github.com/ionic-team/ionicons/issues/1262)) ([fa5e765](https://github.com/ionic-team/ionicons/commit/fa5e7659fc1622908c4e55b01d0573017a36af6a))
|
||||
* add arrow box icons ([#1265](https://github.com/ionic-team/ionicons/issues/1265)) ([d5a55f8](https://github.com/ionic-team/ionicons/commit/d5a55f8541b208ab46dd41e53528aab48a90ed10))
|
||||
* add binoculars icons ([#1258](https://github.com/ionic-team/ionicons/issues/1258)) ([3024818](https://github.com/ionic-team/ionicons/commit/302481846e48428a354bc36220506001ac4c645e))
|
||||
* add trapeze icon ([#1260](https://github.com/ionic-team/ionicons/issues/1260)) ([3b85413](https://github.com/ionic-team/ionicons/commit/3b85413a059b2c91f10105d576cc717fd687a491))
|
||||
* add updated wifi logos ([#1264](https://github.com/ionic-team/ionicons/issues/1264)) ([26aac36](https://github.com/ionic-team/ionicons/commit/26aac36334cc09e5887523bc99c3d746586ebb63)), closes [#323](https://github.com/ionic-team/ionicons/issues/323)
|
||||
* add updated yahoo icon ([#1266](https://github.com/ionic-team/ionicons/issues/1266)) ([c6ed6b6](https://github.com/ionic-team/ionicons/commit/c6ed6b629e45465b49e8e35db3830083ca9520ef))
|
||||
* **doc:** add Web Types ([#1301](https://github.com/ionic-team/ionicons/issues/1301)) ([f946a3e](https://github.com/ionic-team/ionicons/commit/f946a3ee3a4a1c2bdf9508b11a71fcb0a419d571))
|
||||
* update gitlab logo ([#1261](https://github.com/ionic-team/ionicons/issues/1261)) ([2586fb2](https://github.com/ionic-team/ionicons/commit/2586fb26b2a493fcb4b5b0156dd00d6b5eab1ab0)), closes [#613](https://github.com/ionic-team/ionicons/issues/613)
|
||||
* update ionic logo ([#1263](https://github.com/ionic-team/ionicons/issues/1263)) ([50fe570](https://github.com/ionic-team/ionicons/commit/50fe570566d4c28de7fb10694543cd6dc72f3935))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [7.2.3](https://github.com/ionic-team/ionicons/compare/v7.2.2...v7.2.3) (2024-03-20)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **icon:** icon names with numbers are correctly converted to kebab case ([#1339](https://github.com/ionic-team/ionicons/issues/1339)) ([077168d](https://github.com/ionic-team/ionicons/commit/077168dac9347f25d2b8ce440bd0a3e8576f4cdf)), closes [#1338](https://github.com/ionic-team/ionicons/issues/1338)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [7.2.2](https://github.com/ionic-team/ionicons/compare/v7.2.1...v7.2.2) (2023-12-13)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **icon:** add better warning when loading icons ([#1297](https://github.com/ionic-team/ionicons/issues/1297)) ([d582e62](https://github.com/ionic-team/ionicons/commit/d582e6208e626722e4350426a509a6870e90a0bc))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [7.2.1](https://github.com/ionic-team/ionicons/compare/v7.2.0...v7.2.1) (2023-10-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **icon:** font scales without host style ([#1289](https://github.com/ionic-team/ionicons/issues/1289)) ([875bfd8](https://github.com/ionic-team/ionicons/commit/875bfd8300144c62e55a5a76dc2cff8cf1f01bfe))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [7.2.0](https://github.com/ionic-team/ionicons/compare/v7.1.2...v7.2.0) (2023-10-10)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **icon:** mapping same icon does not warn ([#1279](https://github.com/ionic-team/ionicons/issues/1279)) ([8297018](https://github.com/ionic-team/ionicons/commit/8297018cb591f5e33a815ceb9e4e765271ecf5ad))
|
||||
* **icon:** verify the icon loads in the lifecycle ([#1278](https://github.com/ionic-team/ionicons/issues/1278)) ([7f7f346](https://github.com/ionic-team/ionicons/commit/7f7f346af47f45531046e1d2f1a88f53acee77fa))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* allow passing in only icon SVG data to addIcons ([#1256](https://github.com/ionic-team/ionicons/issues/1256)) ([1e33313](https://github.com/ionic-team/ionicons/commit/1e3331347328c11a8b4c58c9200059bfd76b0e59))
|
||||
* **icon:** support for dynamic type ([#1246](https://github.com/ionic-team/ionicons/issues/1246)) ([45c04dd](https://github.com/ionic-team/ionicons/commit/45c04dda6c905e535083b171cead374b1c993afa))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
## [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)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **icon:** remove default <title> ([#1166](https://github.com/ionic-team/ionicons/issues/1166)) ([e0efa5f](https://github.com/ionic-team/ionicons/commit/e0efa5f28d61adcaf2e1fa121f7e2f10cfad6d65)), closes [#838](https://github.com/ionic-team/ionicons/issues/838) [#1049](https://github.com/ionic-team/ionicons/issues/1049) [#1082](https://github.com/ionic-team/ionicons/issues/1082)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# [6.1.0](https://github.com/ionic-team/ionicons/compare/v6.0.4...v6.1.0) (2023-01-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **icon:** remove default <title> ([#1166](https://github.com/ionic-team/ionicons/issues/1166)) ([e0efa5f](https://github.com/ionic-team/ionicons/commit/e0efa5f28d61adcaf2e1fa121f7e2f10cfad6d65)), closes [#838](https://github.com/ionic-team/ionicons/issues/838) [#1049](https://github.com/ionic-team/ionicons/issues/1049) [#1082](https://github.com/ionic-team/ionicons/issues/1082)
|
||||
|
||||
@@ -1,196 +0,0 @@
|
||||
# Contributing to Ionicons
|
||||
|
||||
Thank you for your interest in contributing to Ionicons! :tada:
|
||||
|
||||
This document outlines the guidelines and processes for contributing to this project.
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Code of Conduct](#code-of-conduct)
|
||||
- [Getting Started](#getting-started)
|
||||
* [Prerequisites](#prerequisites)
|
||||
* [Environment Setup](#environment-setup)
|
||||
- [Development Workflow](#development-workflow)
|
||||
* [Branch Strategy](#branch-strategy)
|
||||
* [Component Modifications](#component-modifications)
|
||||
* [Testing](#testing)
|
||||
* [Code Style](#code-style)
|
||||
* [Building](#building)
|
||||
- [Submitting Issues](#submitting-issues)
|
||||
- [Submitting Pull Requests](#submitting-pull-requests)
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
Please read our [Contributor Code of Conduct](./CODE_OF_CONDUCT.md) for information on our rules of conduct. By contributing to Ionicons, you agree to abide by its terms.
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- [Node.js](https://nodejs.org/) (LTS version recommended)
|
||||
- [npm](https://www.npmjs.com/) (comes with Node.js)
|
||||
- Git
|
||||
|
||||
### Environment Setup
|
||||
|
||||
1. We recommend using [nvm](https://github.com/nvm-sh/nvm) (Node Version Manager) to manage Node.js versions:
|
||||
- For macOS/Linux: `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash`
|
||||
- For Windows: Use [nvm-windows](https://github.com/coreybutler/nvm-windows)
|
||||
- Install and use the LTS version: `nvm install --lts && nvm use --lts`
|
||||
|
||||
Alternatively, you can [download the installer](https://nodejs.org/) for the LTS version of Node.js directly.
|
||||
|
||||
2. Fork the repository on GitHub
|
||||
3. Clone your fork locally:
|
||||
```bash
|
||||
git clone https://github.com/YOUR-USERNAME/ionicons.git
|
||||
cd ionicons
|
||||
```
|
||||
4. Add the original repository as an upstream remote:
|
||||
```bash
|
||||
git remote add upstream https://github.com/ionic-team/ionicons.git
|
||||
```
|
||||
5. Create a new branch from `main` for your change:
|
||||
```bash
|
||||
git checkout -b your-feature-branch
|
||||
```
|
||||
6. Install dependencies:
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
7. Run the initial build:
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
8. If desired, [modify the Icon Component](#component-modifications)
|
||||
9. Or, modify and preview the site
|
||||
|
||||
## Development Workflow
|
||||
|
||||
### Branch Strategy
|
||||
|
||||
- Always create a new branch from `main` for your changes:
|
||||
```bash
|
||||
git checkout main
|
||||
git pull upstream main
|
||||
git checkout -b your-feature-branch
|
||||
```
|
||||
|
||||
### Component Modifications
|
||||
|
||||
If you're modifying the `ion-icon` component:
|
||||
|
||||
1. Navigate to `src/components/` directory and open the `icon` component to modify
|
||||
2. Make your changes to the component code
|
||||
3. Test your changes locally with `npm start`
|
||||
4. Run the full test suite: `npm run test.spec` for unit tests and `npm run test.e2e` for E2E tests
|
||||
5. All PRs that change component behavior must include tests covering the changes
|
||||
|
||||
### Testing
|
||||
|
||||
Tests are crucial for maintaining confidence in changes. All PRs that modify component behavior must include tests covering those changes.
|
||||
|
||||
#### Local Development & Previewing
|
||||
|
||||
To preview component changes during development:
|
||||
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
|
||||
This starts the dev server with live-reloading. The test landing page displays all available test pages.
|
||||
|
||||
Test pages are organized in `src/components/icon/test/` with individual folders for each test scenario.
|
||||
|
||||
#### Unit Tests
|
||||
|
||||
Run Jest tests for component logic:
|
||||
|
||||
```bash
|
||||
npm run test.spec
|
||||
```
|
||||
|
||||
#### E2E Tests
|
||||
|
||||
Run Playwright tests to generate visual regression snapshots and verify component behavior:
|
||||
|
||||
```bash
|
||||
npm run test.e2e
|
||||
```
|
||||
|
||||
View the HTML report after tests complete:
|
||||
|
||||
```bash
|
||||
npx playwright show-report
|
||||
```
|
||||
|
||||
> [!IMPORTANT]
|
||||
> All E2E test navigation URLs must include a trailing slash (e.g., `/icon/test/basic/` not `/icon/test/basic`). The trailing slash ensures proper directory routing, correct timing for script initialization, and consistent page loading across browsers.
|
||||
|
||||
##### Updating Snapshots
|
||||
|
||||
To update visual regression snapshots with new baselines:
|
||||
|
||||
```bash
|
||||
npm run test.e2e -- --update-snapshots
|
||||
```
|
||||
|
||||
Or for a specific test:
|
||||
|
||||
```bash
|
||||
npm run test.e2e -- src/components/icon/test/basic/icon.e2e.ts --update-snapshots
|
||||
```
|
||||
|
||||
> [!NOTE]
|
||||
> Updating snapshots locally updates your gitignored screenshot files for local testing. To update the official repository snapshots, run the "Update Reference Screenshots" GitHub action with your development branch selected.
|
||||
|
||||
### Code Style
|
||||
|
||||
- This project uses Prettier for code formatting
|
||||
- Run `npm run prettier` to format your code before submitting
|
||||
|
||||
### Building
|
||||
|
||||
- Run `npm run build` to build the complete package
|
||||
- Run `npm run build.files` to rebuild only the SVG icon files
|
||||
|
||||
## Submitting Issues
|
||||
|
||||
Please submit issues for:
|
||||
- Bug reports
|
||||
- Feature requests
|
||||
- General questions about the project
|
||||
|
||||
When creating issues:
|
||||
|
||||
1. 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).
|
||||
|
||||
2. 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.
|
||||
|
||||
3. The issue list of this repository is exclusively for bug reports and feature requests. Non-conforming issues will be closed immediately.
|
||||
|
||||
4. Check if a similar issue already exists by searching through [existing issues](https://github.com/ionic-team/ionicons/issues?utf8=%E2%9C%93&q=is%3Aissue). You can search through existing issues to see if there is a similar one reported. Include closed issues as it may have been closed with a solution.
|
||||
|
||||
5. Use the provided issue templates and clearly describe:
|
||||
- Expected behavior
|
||||
- Actual behavior
|
||||
- Steps to reproduce (for bugs)
|
||||
- Browser/device information when relevant
|
||||
|
||||
6. [Create a new issue](https://github.com/ionic-team/ionicons/issues/new/choose) that thoroughly explains the problem.
|
||||
|
||||
## Submitting Pull Requests
|
||||
|
||||
1. Before submitting a Pull Request (PR), please:
|
||||
- Create an issue first to discuss the proposed changes
|
||||
- Comment on an existing issue mentioning you'd like to work on it
|
||||
- Look for issues labeled with [`help wanted`](https://github.com/ionic-team/ionicons/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22) if you're new to the project
|
||||
|
||||
2. Creating the PR:
|
||||
- Update your fork to the latest upstream main
|
||||
- Make your changes in a new git branch
|
||||
- Follow the code style of the project
|
||||
- Include relevant tests
|
||||
- Make sure all tests pass: `npm test`
|
||||
- Update documentation if needed
|
||||
- [Create a new pull request](https://github.com/ionic-team/ionicons/compare) with the `main` branch as the base.
|
||||
@@ -1,20 +0,0 @@
|
||||
import path from 'path';
|
||||
import url from 'url';
|
||||
|
||||
import { createJestStencilPreset } from 'jest-stencil-runner';
|
||||
|
||||
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
|
||||
|
||||
export default createJestStencilPreset({
|
||||
rootDir: __dirname,
|
||||
// Add any additional Jest configuration here
|
||||
setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
|
||||
collectCoverageFrom: [
|
||||
'src/**/*.{ts,tsx}',
|
||||
'!src/**/*.d.ts',
|
||||
],
|
||||
testMatch: [
|
||||
'**/__tests__/**/*.(ts|tsx|js)',
|
||||
'**/*.(test|spec).(ts|tsx|js)'
|
||||
]
|
||||
});
|
||||
@@ -1,2 +0,0 @@
|
||||
const Stencil = require('@stencil/core');
|
||||
Stencil.Build.isBrowser = true;
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"packages": [
|
||||
"./"
|
||||
],
|
||||
"version": "7.4.0"
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ionicons",
|
||||
"version": "8.1.1",
|
||||
"version": "7.4.0",
|
||||
"description": "Premium icons for Ionic.",
|
||||
"files": [
|
||||
"components/",
|
||||
@@ -10,76 +10,37 @@
|
||||
"main": "./dist/index.cjs.js",
|
||||
"module": "./dist/index.js",
|
||||
"types": "dist/types/index.d.ts",
|
||||
"unpkg": "dist/ionicons/ionicons.esm.js",
|
||||
"jsdelivr": "dist/ionicons/ionicons.esm.js",
|
||||
"unpkg": "dist/ionicons.js",
|
||||
"collection": "dist/collection/collection-manifest.json",
|
||||
"collection:main": "dist/collection/index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/types/index.d.ts",
|
||||
"import": "./dist/index.js",
|
||||
"require": "./dist/index.cjs.js"
|
||||
},
|
||||
"./loader": {
|
||||
"types": "./dist/loader/index.d.ts",
|
||||
"import": "./dist/loader/index.js",
|
||||
"require": "./dist/loader/index.cjs.js"
|
||||
},
|
||||
"./components": {
|
||||
"types": "./components/index.d.ts",
|
||||
"import": "./components/index.js"
|
||||
},
|
||||
"./components/ion-icon.js": {
|
||||
"types": "./components/ion-icon.d.ts",
|
||||
"import": "./components/ion-icon.js"
|
||||
},
|
||||
"./icons": {
|
||||
"types": "./icons/index.d.ts",
|
||||
"import": "./icons/index.mjs",
|
||||
"require": "./icons/index.js"
|
||||
},
|
||||
"./dist/ionicons.json": {
|
||||
"default": "./dist/ionicons.json"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "run-s clean build.*",
|
||||
"build.files": "tsx scripts/build.ts",
|
||||
"compile.scripts": "tsc -p scripts/tsconfig.json",
|
||||
"build": "npm run compile.scripts && npm run build.files && npm run build.component && npm run collection.copy",
|
||||
"build.files": "node scripts/build.js",
|
||||
"build.component": "stencil build",
|
||||
"build.collection": "tsx scripts/collection-copy.ts",
|
||||
"clean": "rimraf dist components icons www",
|
||||
"lint": "npm run prettier -- --write",
|
||||
"prettier": "prettier \"./src/**/*.{html,ts,tsx,js,jsx,scss}\"",
|
||||
"prettier.dry-run": "npm run prettier -- --list-different",
|
||||
"start": "run-s build.files && stencil build --dev --watch --serve",
|
||||
"test": "run-s test.spec test.e2e",
|
||||
"test.spec": "jest",
|
||||
"test.e2e": "playwright test",
|
||||
"test.e2e.install": "playwright install && playwright install-deps"
|
||||
"collection.copy": "node scripts/collection-copy.js",
|
||||
"start": "npm run compile.scripts && npm run build.files && stencil build --dev --watch --serve",
|
||||
"test": "npm run test.spec",
|
||||
"test.spec": "stencil test --spec"
|
||||
},
|
||||
"dependencies": {
|
||||
"@stencil/core": "^4.43.5"
|
||||
"@stencil/core": "^4.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@axe-core/playwright": "^4.12.1",
|
||||
"@playwright/test": "^1.61.1",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^22.15.3",
|
||||
"@types/svgo": "^3.0.0",
|
||||
"fs-extra": "^11.3.0",
|
||||
"jest": "^30.0.4",
|
||||
"jest-cli": "^30.0.4",
|
||||
"jest-stencil-runner": "^0.0.20",
|
||||
"npm-run-all2": "^8.0.4",
|
||||
"prettier": "^3.6.2",
|
||||
"puppeteer": "^24.12.0",
|
||||
"rimraf": "^6.0.1",
|
||||
"semver": "^7.7.2",
|
||||
"serve": "^14.2.4",
|
||||
"svgo": "4.0.0",
|
||||
"tsx": "^4.20.3",
|
||||
"typescript": "^5.8.3"
|
||||
"@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": "^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": "^5.0.4"
|
||||
},
|
||||
"keywords": [
|
||||
"icon pack",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { PlaywrightTestConfig } from '@playwright/test';
|
||||
import { devices, expect } from '@playwright/test';
|
||||
|
||||
const projects: PlaywrightTestConfig['projects'] = [
|
||||
const projects = [
|
||||
{
|
||||
/**
|
||||
* This is really just desktop Firefox
|
||||
@@ -19,6 +19,10 @@ const projects: PlaywrightTestConfig['projects'] = [
|
||||
viewport: {
|
||||
width: 393,
|
||||
height: 727
|
||||
},
|
||||
screen: {
|
||||
width: 393,
|
||||
height: 851
|
||||
}
|
||||
},
|
||||
},
|
||||
@@ -48,23 +52,7 @@ const config: PlaywrightTestConfig = {
|
||||
* Maximum time expect() should wait for the condition to be met.
|
||||
* For example in `await expect(locator).toHaveText();`
|
||||
*/
|
||||
timeout: 5000,
|
||||
|
||||
/**
|
||||
* Configure screenshot comparison settings
|
||||
* to be more tolerant of minor visual differences
|
||||
*/
|
||||
toHaveScreenshot: {
|
||||
// Increase the threshold to allow for small font rendering differences
|
||||
// This sets the maximum allowed ratio of pixels that can be different
|
||||
maxDiffPixelRatio: 0.02, // Allow up to 2% of pixels to be different
|
||||
|
||||
// Alternatively, you can use absolute pixel count
|
||||
// maxDiffPixels: 100, // Allow up to 100 pixels to be different
|
||||
|
||||
// Add a threshold for per-pixel difference to handle anti-aliasing
|
||||
threshold: 0.2, // Default is 0.1
|
||||
}
|
||||
timeout: 5000
|
||||
},
|
||||
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||
forbidOnly: !!process.env.CI,
|
||||
@@ -91,7 +79,7 @@ const config: PlaywrightTestConfig = {
|
||||
},
|
||||
|
||||
/* Configure projects for major browsers */
|
||||
projects,
|
||||
projects: projects,
|
||||
webServer: {
|
||||
command: 'serve www -p 3333',
|
||||
port: 3333,
|
||||
|
||||
@@ -10,7 +10,7 @@ We intend for this icon pack to be used with [Ionic](http://ionicframework.com/)
|
||||
## Contributing
|
||||
|
||||
Thanks for your interest in contributing! Read up on our guidelines for
|
||||
[contributing](https://github.com/ionic-team/ionicons/blob/main/CONTRIBUTING.md)
|
||||
[contributing](https://github.com/ionic-team/ionicons/blob/master/.github/CONTRIBUTING.md)
|
||||
and then look through our issues with a [help wanted](https://github.com/ionic-team/ionicons/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22)
|
||||
label.
|
||||
|
||||
@@ -26,15 +26,8 @@ Also note that only visible icons are loaded, and icons that are "below the fold
|
||||
If you're using [Ionic Framework](https://ionicframework.com/), Ionicons is packaged by default, so no installation is necessary. Want to use Ionicons without Ionic Framework? Place the following `<script>` near the end of your page, right before the closing `</body>` tag, to enable them.
|
||||
|
||||
```html
|
||||
<script type="module" src="https://esm.sh/ionicons@latest/loader"></script>
|
||||
<script nomodule src="https://esm.sh/ionicons@latest/loader"></script>
|
||||
```
|
||||
|
||||
you can replace `latest` to pick any version of Ionicon, e.g.:
|
||||
|
||||
```html
|
||||
<script type="module" src="https://esm.sh/ionicons@8.0.0/loader"></script>
|
||||
<script nomodule src="https://esm.sh/ionicons@8.0.0/loader"></script>
|
||||
<script type="module" src="https://cdn.jsdelivr.net/npm/ionicons@latest/dist/ionicons/ionicons.esm.js"></script>
|
||||
<script nomodule src="https://cdn.jsdelivr.net/npm/ionicons@latest/dist/ionicons/ionicons.js"></script>
|
||||
```
|
||||
|
||||
### Basic usage
|
||||
@@ -58,14 +51,10 @@ To use a custom SVG, provide its url in the `src` attribute to request the exter
|
||||
If you have a different set of icons you would like to load or if the Ionicon icons are hosted on a different page or path, you can set the asset url from which Ionicons pulls the icons via:
|
||||
|
||||
```ts
|
||||
import { setAssetPath, addIcons } from 'ionicons';
|
||||
import { add, logoIonic, save } from 'ionicons/icons';
|
||||
import { setAssetPath } from '@stencil/core'
|
||||
|
||||
// set root path for loading icons to "<root>/public/svg"
|
||||
setAssetPath(`${window.location.origin}/public/svg/`);
|
||||
|
||||
// only load specific icons
|
||||
addIcons({ add, logoIonic, save });
|
||||
```
|
||||
|
||||
This allows the use of named icons like this:
|
||||
|
||||
@@ -1,49 +1,27 @@
|
||||
import path from 'node:path';
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import { optimize } from 'svgo';
|
||||
|
||||
import { webComponentPassPlugins, sourcePassPlugins } from './plugins';
|
||||
import { reservedKeywords } from './constants';
|
||||
import pkgData from '../package.json' with { type: 'json' };
|
||||
import type { SvgData } from './types';
|
||||
import { join } from 'path';
|
||||
import Svgo from 'svgo';
|
||||
|
||||
async function build(rootDir: string) {
|
||||
try {
|
||||
const srcDir = path.join(rootDir, 'src');
|
||||
const srcSvgDir = path.join(srcDir, 'svg');
|
||||
const iconDir = path.join(rootDir, 'icons');
|
||||
const distDir = path.join(rootDir, 'dist');
|
||||
const distIoniconsDir = path.join(distDir, 'ionicons');
|
||||
const distSvgDir = path.join(distDir, 'svg');
|
||||
const optimizedSvgDir = path.join(distIoniconsDir, 'svg');
|
||||
const pkgJsonPath = join(rootDir, 'package.json');
|
||||
const srcDir = join(rootDir, 'src');
|
||||
const srcSvgDir = join(srcDir, 'svg');
|
||||
const iconDir = join(rootDir, 'icons');
|
||||
const distDir = join(rootDir, 'dist');
|
||||
const distIoniconsDir = join(distDir, 'ionicons');
|
||||
const distSvgDir = join(distDir, 'svg');
|
||||
|
||||
/**
|
||||
* Create the directories first, then empty them
|
||||
* This ensures they exist before we try to write files to them
|
||||
*/
|
||||
await Promise.all([
|
||||
fs.ensureDir(iconDir),
|
||||
fs.ensureDir(distDir),
|
||||
fs.ensureDir(distSvgDir),
|
||||
fs.ensureDir(optimizedSvgDir),
|
||||
fs.ensureDir(distIoniconsDir),
|
||||
]);
|
||||
|
||||
/**
|
||||
* Empty the directories
|
||||
*/
|
||||
await Promise.all([
|
||||
fs.emptyDir(iconDir),
|
||||
fs.emptyDir(distDir),
|
||||
fs.emptyDir(distSvgDir),
|
||||
fs.emptyDir(optimizedSvgDir),
|
||||
fs.emptyDir(distIoniconsDir),
|
||||
]);
|
||||
await Promise.all([fs.emptyDir(iconDir), fs.emptyDir(distDir)]);
|
||||
await fs.emptyDir(distSvgDir), await fs.emptyDir(distIoniconsDir);
|
||||
|
||||
const pkgData = await fs.readJson(pkgJsonPath);
|
||||
const version = pkgData.version as string;
|
||||
const srcSvgData = await getSvgs(srcSvgDir, distSvgDir, optimizedSvgDir);
|
||||
|
||||
const srcSvgData = await getSvgs(srcSvgDir, distSvgDir, distIoniconsDir);
|
||||
|
||||
await optimizeSvgs(srcSvgData);
|
||||
|
||||
await Promise.all([
|
||||
createDataJson(version, srcDir, distDir, srcSvgData),
|
||||
createIconPackage(version, iconDir, srcSvgData),
|
||||
@@ -52,7 +30,9 @@ async function build(rootDir: string) {
|
||||
const svgSymbolsContent = await createSvgSymbols(version, distDir, srcSvgData);
|
||||
|
||||
await createCheatsheet(version, rootDir, distDir, svgSymbolsContent, srcSvgData);
|
||||
|
||||
await createWebTypes(version, rootDir, distDir, srcSvgData);
|
||||
|
||||
await copyToTesting(rootDir, distDir, srcSvgData);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
@@ -61,84 +41,173 @@ async function build(rootDir: string) {
|
||||
}
|
||||
|
||||
async function optimizeSvgs(srcSvgData: SvgData[]) {
|
||||
// https://github.com/svg/svgo
|
||||
const optimizePass = new Svgo({});
|
||||
const webComponentPass = new Svgo({
|
||||
full: true,
|
||||
plugins: [
|
||||
{
|
||||
addFillNoneCss: {
|
||||
type: 'perItem',
|
||||
fn: (item, params) => {
|
||||
if (!Array.isArray(params.attrs)) {
|
||||
params.attrs = [params.attrs];
|
||||
}
|
||||
|
||||
/**
|
||||
* All host SVG elements must have
|
||||
* the ionicons class otherwise styles
|
||||
* will not apply.
|
||||
*/
|
||||
if (item.elem === 'svg') {
|
||||
item.class.add('ionicon');
|
||||
}
|
||||
|
||||
if (item.isElem()) {
|
||||
item.eachAttr((attr) => {
|
||||
if (attr.name === 'fill') {
|
||||
if (attr.value === 'none') {
|
||||
item.class.add('ionicon-fill-none');
|
||||
}
|
||||
item.removeAttr('fill');
|
||||
} else if (attr.name === 'stroke') {
|
||||
item.removeAttr('stroke');
|
||||
} else if (attr.name === 'stroke-width' && attr.value === '32') {
|
||||
item.removeAttr('stroke-width');
|
||||
item.class.add('ionicon-stroke-width');
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
} as any,
|
||||
{
|
||||
removeStyleElement: true,
|
||||
},
|
||||
{
|
||||
removeScriptElement: true,
|
||||
},
|
||||
{
|
||||
removeDimensions: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const sourcePass = new Svgo({
|
||||
full: true,
|
||||
plugins: [
|
||||
{
|
||||
addFillNoneCss: {
|
||||
type: 'perItem',
|
||||
fn: (item, params) => {
|
||||
if (!Array.isArray(params.attrs)) {
|
||||
params.attrs = [params.attrs];
|
||||
}
|
||||
if (item.isElem()) {
|
||||
item.eachAttr((attr) => {
|
||||
if (attr.name === 'stroke' || attr.name === 'fill') {
|
||||
if (attr.value === '#000' || attr.value === 'currentColor') {
|
||||
item.addAttr({
|
||||
name: attr.name,
|
||||
value: 'currentColor',
|
||||
prefix: '',
|
||||
local: attr.name,
|
||||
});
|
||||
} else if (attr.value !== 'none') {
|
||||
throw new Error(`invalid "${attr.name}" value: ${attr.value}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
} as any,
|
||||
{
|
||||
removeStyleElement: true,
|
||||
},
|
||||
{
|
||||
removeScriptElement: true,
|
||||
},
|
||||
{
|
||||
removeDimensions: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const validatePass = new Svgo({
|
||||
full: true,
|
||||
plugins: [
|
||||
{
|
||||
addFillNoneCss: {
|
||||
type: 'perItem',
|
||||
fn: (item, params) => {
|
||||
if (!Array.isArray(params.attrs)) {
|
||||
params.attrs = [params.attrs];
|
||||
}
|
||||
if (item.isElem()) {
|
||||
item.eachAttr((attr) => {
|
||||
if (attr.name === 'style') {
|
||||
throw new Error('Inline style attributed detected');
|
||||
}
|
||||
});
|
||||
}
|
||||
if (item.isElem('style')) {
|
||||
throw new Error('Inline style element detected');
|
||||
}
|
||||
},
|
||||
},
|
||||
} as any,
|
||||
],
|
||||
});
|
||||
|
||||
await Promise.all(
|
||||
srcSvgData.map(async (svgData) => {
|
||||
return optimizeSvg(svgData);
|
||||
return optimizeSvg(optimizePass, webComponentPass, sourcePass, validatePass, svgData);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
async function optimizeSvg(svgData: SvgData) {
|
||||
async function optimizeSvg(
|
||||
optimizePass: Svgo,
|
||||
webComponentPass: Svgo,
|
||||
sourcePass: Svgo,
|
||||
validatePass: Svgo,
|
||||
svgData: SvgData,
|
||||
) {
|
||||
const srcSvgContent = await fs.readFile(svgData.srcFilePath, 'utf8');
|
||||
|
||||
const optimizedSvg = await optimize(srcSvgContent, { path: svgData.srcFilePath });
|
||||
const webComponentSvg = await optimize(optimizedSvg.data, {
|
||||
path: svgData.srcFilePath,
|
||||
plugins: webComponentPassPlugins,
|
||||
});
|
||||
const sourceSvg = await optimize(optimizedSvg.data, {
|
||||
path: svgData.srcFilePath,
|
||||
plugins: sourcePassPlugins,
|
||||
});
|
||||
|
||||
// Ensure directories exist before writing files
|
||||
await Promise.all([
|
||||
fs.ensureDir(path.dirname(svgData.optimizedFilePath)),
|
||||
fs.ensureDir(path.dirname(svgData.distSvgFilePath)),
|
||||
]);
|
||||
const optimizedSvg = await optimizePass.optimize(srcSvgContent, { path: svgData.srcFilePath });
|
||||
const webComponentSvg = await webComponentPass.optimize(optimizedSvg.data, { path: svgData.srcFilePath });
|
||||
const sourceSvg = await sourcePass.optimize(optimizedSvg.data, { path: svgData.srcFilePath });
|
||||
|
||||
svgData.optimizedSvgContent = webComponentSvg.data;
|
||||
await Promise.all([
|
||||
fs.writeFile(svgData.optimizedFilePath, svgData.optimizedSvgContent),
|
||||
fs.writeFile(svgData.distSvgFilePath, sourceSvg.data),
|
||||
]);
|
||||
|
||||
try {
|
||||
await validatePass.optimize(svgData.optimizedSvgContent, { path: svgData.srcFilePath });
|
||||
} catch (e) {
|
||||
console.error(`${e.message}: ${svgData.srcFilePath}`);
|
||||
}
|
||||
|
||||
await fs.writeFile(svgData.optimizedFilePath, svgData.optimizedSvgContent);
|
||||
await fs.writeFile(svgData.distSvgFilePath, sourceSvg.data);
|
||||
}
|
||||
|
||||
async function copyToTesting(rootDir: string, distDir: string, srcSvgData: SvgData[]) {
|
||||
const testDir = path.join(rootDir, 'www');
|
||||
const testBuildDir = path.join(testDir, 'build');
|
||||
const testSvgDir = path.join(testBuildDir, 'svg');
|
||||
const cheatsheetDir = path.join(testDir, 'icon', 'test', 'cheatsheet');
|
||||
const version = (await fs.readJson(path.join(rootDir, 'package.json'))).version;
|
||||
|
||||
// Ensure all directories exist
|
||||
await Promise.all([
|
||||
fs.ensureDir(testDir),
|
||||
fs.ensureDir(testBuildDir),
|
||||
fs.ensureDir(testSvgDir),
|
||||
fs.ensureDir(cheatsheetDir),
|
||||
]);
|
||||
const testDir = join(rootDir, 'www');
|
||||
const testBuildDir = join(testDir, 'build');
|
||||
const testSvgDir = join(testBuildDir, 'svg');
|
||||
await fs.ensureDir(testSvgDir);
|
||||
|
||||
await Promise.all(
|
||||
srcSvgData
|
||||
.filter((svgData): svgData is SvgData & { optimizedSvgContent: string } => Boolean(svgData.optimizedSvgContent))
|
||||
.map(async (svgData) => {
|
||||
const testSvgFilePath = path.join(testSvgDir, svgData.fileName);
|
||||
await fs.writeFile(testSvgFilePath, svgData.optimizedSvgContent);
|
||||
}),
|
||||
srcSvgData.map(async (svgData) => {
|
||||
const testSvgFilePath = join(testSvgDir, svgData.fileName);
|
||||
await fs.writeFile(testSvgFilePath, svgData.optimizedSvgContent);
|
||||
}),
|
||||
);
|
||||
|
||||
const wwwCheatsheetFilePath = path.join(cheatsheetDir, 'index.html');
|
||||
const srcIndexFilePath = path.join(rootDir, 'src', 'components', 'icon', 'test', 'index.html');
|
||||
const testIndexFilePath = path.join(testDir, 'index.html');
|
||||
|
||||
await fs.copyFile(srcIndexFilePath, testIndexFilePath);
|
||||
|
||||
// Generate the cheatsheet with placeholders filled in
|
||||
const svgSymbolsContent = await fs.readFile(path.join(distDir, 'ionicons.symbols.svg'), 'utf8');
|
||||
const c = srcSvgData.map(
|
||||
(svgData) =>
|
||||
`<a href="/svg/${svgData.fileName}"><svg><use href="#${svgData.iconName}" xlink:href="#${svgData.iconName}"/></svg></a>`,
|
||||
);
|
||||
c.push(svgSymbolsContent);
|
||||
|
||||
const cheatsheetTemplate = await fs.readFile(path.join(rootDir, 'scripts', 'cheatsheet-template.html'), 'utf8');
|
||||
const cheatsheetHtml = cheatsheetTemplate
|
||||
.replace(/{{version}}/g, version)
|
||||
.replace(/{{count}}/g, srcSvgData.length.toString())
|
||||
.replace(/{{content}}/g, c.join('\n'));
|
||||
|
||||
await fs.writeFile(wwwCheatsheetFilePath, cheatsheetHtml);
|
||||
const distCheatsheetFilePath = join(distDir, 'cheatsheet.html');
|
||||
const testCheatsheetFilePath = join(testDir, 'cheatsheet.html');
|
||||
await fs.copyFile(distCheatsheetFilePath, testCheatsheetFilePath);
|
||||
}
|
||||
|
||||
async function createSvgSymbols(version: string, distDir: string, srcSvgData: SvgData[]) {
|
||||
@@ -148,7 +217,7 @@ async function createSvgSymbols(version: string, distDir: string, srcSvgData: Sv
|
||||
return 0;
|
||||
});
|
||||
|
||||
const symbolsSvgFilePath = path.join(distDir, 'ionicons.symbols.svg');
|
||||
const symbolsSvgFilePath = join(distDir, 'ionicons.symbols.svg');
|
||||
|
||||
const lines = [
|
||||
`<svg data-ionicons="${version}" style="display:none">`,
|
||||
@@ -166,19 +235,19 @@ async function createSvgSymbols(version: string, distDir: string, srcSvgData: Sv
|
||||
`</style>`,
|
||||
];
|
||||
|
||||
srcSvgData
|
||||
.filter((svgData): svgData is SvgData & { optimizedSvgContent: string } => Boolean(svgData.optimizedSvgContent))
|
||||
.forEach((svgData) => {
|
||||
const svg = svgData.optimizedSvgContent
|
||||
.replace(`<svg xmlns="http://www.w3.org/2000/svg"`, `<symbol id="${svgData.iconName}"`)
|
||||
.replace(`</svg>`, `</symbol>`);
|
||||
lines.push(svg);
|
||||
});
|
||||
srcSvgData.forEach((svgData) => {
|
||||
const svg = svgData.optimizedSvgContent
|
||||
.replace(`<svg xmlns="http://www.w3.org/2000/svg"`, `<symbol id="${svgData.iconName}"`)
|
||||
.replace(`</svg>`, `</symbol>`);
|
||||
lines.push(svg);
|
||||
});
|
||||
|
||||
lines.push(`</svg>`, ``);
|
||||
|
||||
const content = lines.join('\n');
|
||||
|
||||
await fs.writeFile(symbolsSvgFilePath, content);
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
@@ -189,12 +258,11 @@ async function createCheatsheet(
|
||||
svgSymbolsContent: string,
|
||||
srcSvgData: SvgData[],
|
||||
) {
|
||||
const CheatsheetTmpFilePath = path.join(rootDir, 'scripts', 'cheatsheet-template.html');
|
||||
const distCheatsheetFilePath = path.join(distDir, 'cheatsheet.html');
|
||||
const CheatsheetTmpFilePath = join(rootDir, 'scripts', 'cheatsheet-template.html');
|
||||
const distCheatsheetFilePath = join(distDir, 'cheatsheet.html');
|
||||
|
||||
const c = srcSvgData.map(
|
||||
(svgData) =>
|
||||
`<a href="/svg/${svgData.fileName}"><svg><use href="#${svgData.iconName}" xlink:href="#${svgData.iconName}"/></svg></a>`,
|
||||
(svgData) => `<a href="./svg/${svgData.fileName}"><svg><use href="#${svgData.iconName}" xlink:href="#${svgData.iconName}"/></svg></a>`,
|
||||
);
|
||||
|
||||
c.push(svgSymbolsContent);
|
||||
@@ -207,26 +275,35 @@ async function createCheatsheet(
|
||||
await fs.writeFile(distCheatsheetFilePath, html);
|
||||
}
|
||||
|
||||
async function createWebTypes(version: string, rootDir: string, distDir: string, srcSvgData: SvgData[]) {
|
||||
const srcWebTypeFilePath = path.join(rootDir, 'src/ionicons.web-types.json');
|
||||
const distWebTypesFilePath = path.join(distDir, 'ionicons.web-types.json');
|
||||
const webTypes = JSON.parse(await fs.readFile(srcWebTypeFilePath, 'utf8'));
|
||||
async function createWebTypes(
|
||||
version: string,
|
||||
rootDir: string,
|
||||
distDir: any,
|
||||
srcSvgData: SvgData[]
|
||||
) {
|
||||
const srcWebTypeFilePath = join(rootDir, 'src/ionicons.web-types.json');
|
||||
const distWebTypesFilePath = join(distDir, 'ionicons.web-types.json');
|
||||
|
||||
webTypes.version = version;
|
||||
const webTypes = JSON.parse(await fs.readFile(srcWebTypeFilePath, 'utf8'))
|
||||
|
||||
const icons = webTypes.contributions.html.ionicons;
|
||||
webTypes.version = version
|
||||
|
||||
const icons = webTypes.contributions.html.ionicons
|
||||
for (let data of srcSvgData) {
|
||||
icons.push({
|
||||
name: data.iconName,
|
||||
icon: 'dist/svg/' + data.fileName,
|
||||
});
|
||||
icon: "dist/svg/" + data.fileName
|
||||
})
|
||||
}
|
||||
|
||||
const jsonStr = JSON.stringify(webTypes, null, 2) + '\n';
|
||||
await fs.writeFile(distWebTypesFilePath, jsonStr);
|
||||
}
|
||||
|
||||
async function getSvgs(srcSvgDir: string, distSvgDir: string, optimizedSvgDir: string): Promise<SvgData[]> {
|
||||
async function getSvgs(srcSvgDir: string, distSvgDir: string, distIoniconsDir: string): Promise<SvgData[]> {
|
||||
const optimizedSvgDir = join(distIoniconsDir, 'svg');
|
||||
await fs.emptyDir(optimizedSvgDir);
|
||||
|
||||
const svgFiles = (await fs.readdir(srcSvgDir)).filter((fileName) => {
|
||||
return !fileName.startsWith('.') && fileName.endsWith('.svg');
|
||||
});
|
||||
@@ -240,13 +317,13 @@ async function getSvgs(srcSvgDir: string, distSvgDir: string, optimizedSvgDir: s
|
||||
}
|
||||
|
||||
// srcFilePath: /src/svg/airplane-outline.svg
|
||||
const srcFilePath = path.join(srcSvgDir, fileName);
|
||||
const srcFilePath = join(srcSvgDir, fileName);
|
||||
|
||||
// srcFilePath: /src/svg/airplane-outline.svg
|
||||
const distSvgFilePath = path.join(distSvgDir, fileName);
|
||||
const distSvgFilePath = join(distSvgDir, fileName);
|
||||
|
||||
// optimizedFilePath: /dist/ionicons/svg/airplane-outline.svg
|
||||
const optimizedFilePath = path.join(optimizedSvgDir, fileName);
|
||||
const optimizedFilePath = join(optimizedSvgDir, fileName);
|
||||
|
||||
const dotSplit = fileName.split('.');
|
||||
if (dotSplit.length > 2) {
|
||||
@@ -280,6 +357,7 @@ async function getSvgs(srcSvgDir: string, distSvgDir: string, optimizedSvgDir: s
|
||||
distSvgFilePath,
|
||||
srcSvgContent: await fs.readFile(srcFilePath, 'utf8'),
|
||||
optimizedFilePath,
|
||||
optimizedSvgContent: null,
|
||||
iconName,
|
||||
fileNameMjs,
|
||||
fileNameCjs,
|
||||
@@ -296,15 +374,29 @@ async function getSvgs(srcSvgDir: string, distSvgDir: string, optimizedSvgDir: s
|
||||
}
|
||||
|
||||
async function createIconPackage(version: string, iconDir: string, srcSvgData: SvgData[]) {
|
||||
const iconPkgJsonFilePath = join(iconDir, 'package.json');
|
||||
|
||||
await Promise.all([
|
||||
createEsmIcons(version, iconDir, srcSvgData),
|
||||
createCjsIcons(version, iconDir, srcSvgData),
|
||||
createDtsIcons(version, iconDir, srcSvgData),
|
||||
]);
|
||||
|
||||
const iconPkgJson = {
|
||||
name: 'ionicons/icons',
|
||||
version,
|
||||
module: 'index.mjs',
|
||||
main: 'index.js',
|
||||
typings: 'index.d.ts',
|
||||
private: true,
|
||||
};
|
||||
|
||||
const jsonStr = JSON.stringify(iconPkgJson, null, 2) + '\n';
|
||||
await fs.writeFile(iconPkgJsonFilePath, jsonStr);
|
||||
}
|
||||
|
||||
async function createEsmIcons(version: string, iconDir: string, srcSvgData: SvgData[]) {
|
||||
const iconEsmFilePath = path.join(iconDir, 'index.mjs');
|
||||
const iconEsmFilePath = join(iconDir, 'index.mjs');
|
||||
|
||||
const o = [`/* Ionicons v${version}, ES Modules */`, ``];
|
||||
|
||||
@@ -316,7 +408,7 @@ async function createEsmIcons(version: string, iconDir: string, srcSvgData: SvgD
|
||||
}
|
||||
|
||||
async function createCjsIcons(version: string, iconDir: string, srcSvgData: SvgData[]) {
|
||||
const iconCjsFilePath = path.join(iconDir, 'index.js');
|
||||
const iconCjsFilePath = join(iconDir, 'index.js');
|
||||
|
||||
const o = [`/* Ionicons v${version}, CommonJS */`, ``];
|
||||
|
||||
@@ -328,7 +420,7 @@ async function createCjsIcons(version: string, iconDir: string, srcSvgData: SvgD
|
||||
}
|
||||
|
||||
async function createDtsIcons(version: string, iconDir: string, srcSvgData: SvgData[]) {
|
||||
const iconDtsFilePath = path.join(iconDir, 'index.d.ts');
|
||||
const iconDtsFilePath = join(iconDir, 'index.d.ts');
|
||||
|
||||
const o = [`/* Ionicons v${version}, Types */`, ``];
|
||||
|
||||
@@ -341,11 +433,6 @@ async function createDtsIcons(version: string, iconDir: string, srcSvgData: SvgD
|
||||
|
||||
function getDataUrl(svgData: SvgData) {
|
||||
let svg = svgData.optimizedSvgContent;
|
||||
|
||||
if (!svg) {
|
||||
throw new Error(`oh no! no optimized SVG content! ${svgData.fileName}`);
|
||||
}
|
||||
|
||||
if (svg.includes(`'`)) {
|
||||
throw new Error(`oh no! no single quotes allowed! ${svgData.fileName}`);
|
||||
}
|
||||
@@ -357,10 +444,17 @@ function getDataUrl(svgData: SvgData) {
|
||||
}
|
||||
|
||||
async function createDataJson(version: string, srcDir: string, distDir: string, srcSvgData: SvgData[]) {
|
||||
const srcDataJsonPath = path.join(srcDir, 'data.json');
|
||||
const distDataJsonPath = path.join(distDir, 'ionicons.json');
|
||||
const srcDataJsonPath = join(srcDir, 'data.json');
|
||||
const distDataJsonPath = join(distDir, 'ionicons.json');
|
||||
|
||||
let data: JsonData;
|
||||
|
||||
try {
|
||||
data = await fs.readJson(srcDataJsonPath);
|
||||
} catch (e) {
|
||||
data = {} as any;
|
||||
}
|
||||
|
||||
const data = await fs.readJson(srcDataJsonPath).catch(() => ({}));
|
||||
data.icons = data.icons || [];
|
||||
|
||||
// add new icons
|
||||
@@ -409,6 +503,60 @@ function upFirst(word: string) {
|
||||
return word[0].toUpperCase() + word.toLowerCase().slice(1);
|
||||
}
|
||||
|
||||
interface SvgData {
|
||||
/**
|
||||
* airplane-outline.svg
|
||||
*/
|
||||
fileName: string;
|
||||
|
||||
/**
|
||||
* airplane
|
||||
*/
|
||||
title: string;
|
||||
|
||||
/**
|
||||
* /src/svg/airplane-outline.svg
|
||||
*/
|
||||
srcFilePath: string;
|
||||
|
||||
/**
|
||||
* /dist/ionicons/svg/airplane-outline.svg
|
||||
*/
|
||||
optimizedFilePath: string;
|
||||
|
||||
/**
|
||||
* /dist/svg/airplane-outline.svg
|
||||
*/
|
||||
distSvgFilePath: string;
|
||||
|
||||
optimizedSvgContent: string;
|
||||
|
||||
/**
|
||||
* airplane-outline
|
||||
*/
|
||||
iconName: string;
|
||||
|
||||
/**
|
||||
* airplane-outline.mjs
|
||||
*/
|
||||
fileNameMjs: string;
|
||||
|
||||
/**
|
||||
* airplane-outline.js
|
||||
*/
|
||||
fileNameCjs: string;
|
||||
|
||||
/**
|
||||
* airplaneOutline
|
||||
*/
|
||||
exportName: string;
|
||||
}
|
||||
|
||||
interface JsonData {
|
||||
icons: { name: string; tags?: string[] }[];
|
||||
version?: string;
|
||||
}
|
||||
|
||||
function toTitleCase(str: string) {
|
||||
const s = str.trim().toLowerCase().split(' ');
|
||||
for (var i = 0; i < s.length; i++) {
|
||||
@@ -417,5 +565,58 @@ function toTitleCase(str: string) {
|
||||
return s.join(' ');
|
||||
}
|
||||
|
||||
// https://mathiasbynens.be/notes/reserved-keywords
|
||||
const reservedKeywords = new Set([
|
||||
'do',
|
||||
'if',
|
||||
'in',
|
||||
'for',
|
||||
'let',
|
||||
'new',
|
||||
'try',
|
||||
'var',
|
||||
'case',
|
||||
'else',
|
||||
'enum',
|
||||
'eval',
|
||||
'null',
|
||||
'this',
|
||||
'true',
|
||||
'void',
|
||||
'with',
|
||||
'await',
|
||||
'break',
|
||||
'catch',
|
||||
'class',
|
||||
'const',
|
||||
'false',
|
||||
'super',
|
||||
'throw',
|
||||
'while',
|
||||
'yield',
|
||||
'delete',
|
||||
'export',
|
||||
'import',
|
||||
'public',
|
||||
'return',
|
||||
'static',
|
||||
'switch',
|
||||
'typeof',
|
||||
'default',
|
||||
'extends',
|
||||
'finally',
|
||||
'package',
|
||||
'private',
|
||||
'continue',
|
||||
'debugger',
|
||||
'function',
|
||||
'arguments',
|
||||
'interface',
|
||||
'protected',
|
||||
'implements',
|
||||
'instanceof',
|
||||
'constructor',
|
||||
]);
|
||||
|
||||
// let's do this
|
||||
build(path.join(__dirname, '..'));
|
||||
build(join(__dirname, '..'));
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html dir="ltr" lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
|
||||
<title>Ionicons {{version}} Cheatsheet</title>
|
||||
<script type="module" src="/build/ionicons.esm.js"></script>
|
||||
<script nomodule src="/build/ionicons.js"></script>
|
||||
<link rel="stylesheet" href="../styles.css" />
|
||||
<script src="../header.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<test-header></test-header>
|
||||
|
||||
<main>
|
||||
<h1>Ionicons {{version}} Cheatsheet</h1>
|
||||
<h3>{{count}} icons</h3>
|
||||
|
||||
{{content}}
|
||||
</main>
|
||||
</body>
|
||||
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Ionicons {{version}} Cheatsheet</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
||||
background: #fff;
|
||||
}
|
||||
h1 {
|
||||
margin: 0;
|
||||
}
|
||||
.options {
|
||||
padding: 15px 0 20px 0;
|
||||
}
|
||||
label {
|
||||
display: inline-block;
|
||||
width: 100px;
|
||||
font-size: 12px;
|
||||
}
|
||||
svg {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
@@ -34,4 +31,11 @@
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Ionicons {{version}} Cheatsheet</h1>
|
||||
<h3>{{count}} icons</h3>
|
||||
|
||||
{{content}}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -29,6 +29,18 @@ async function collectionCopy(rootDir: string) {
|
||||
};
|
||||
await fs.writeFile(cePackageJsonPath, JSON.stringify(cePackageJson, null, 2));
|
||||
|
||||
/**
|
||||
* TODO: Remove this in Ionicons v6.0
|
||||
* Stencil 2 removed the legacy loader,
|
||||
* but that is what Ionicons users were using
|
||||
* to load Ionicons from a CDN. The lines
|
||||
* below will add in a legacy loader for users
|
||||
* to use so there is no breaking change in usage.
|
||||
*/
|
||||
const installLoaderSrc = join(rootDir, 'scripts', 'install-loader.js');
|
||||
const installLoaderDest = join(rootDir, 'dist', 'ionicons.js');
|
||||
await fs.copyFile(installLoaderSrc, installLoaderDest)
|
||||
|
||||
// this is temporary!!!!
|
||||
// removing the `type` from the d.ts export
|
||||
// to make it easier for users migrating between
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
// https://mathiasbynens.be/notes/reserved-keywords
|
||||
export const reservedKeywords = new Set([
|
||||
'do',
|
||||
'if',
|
||||
'in',
|
||||
'for',
|
||||
'let',
|
||||
'new',
|
||||
'try',
|
||||
'var',
|
||||
'case',
|
||||
'else',
|
||||
'enum',
|
||||
'eval',
|
||||
'null',
|
||||
'this',
|
||||
'true',
|
||||
'void',
|
||||
'with',
|
||||
'await',
|
||||
'break',
|
||||
'catch',
|
||||
'class',
|
||||
'const',
|
||||
'false',
|
||||
'super',
|
||||
'throw',
|
||||
'while',
|
||||
'yield',
|
||||
'delete',
|
||||
'export',
|
||||
'import',
|
||||
'public',
|
||||
'return',
|
||||
'static',
|
||||
'switch',
|
||||
'typeof',
|
||||
'default',
|
||||
'extends',
|
||||
'finally',
|
||||
'package',
|
||||
'private',
|
||||
'continue',
|
||||
'debugger',
|
||||
'function',
|
||||
'arguments',
|
||||
'interface',
|
||||
'protected',
|
||||
'implements',
|
||||
'instanceof',
|
||||
'constructor',
|
||||
]);
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
(function(doc){
|
||||
var scriptElm = doc.scripts[doc.scripts.length - 1];
|
||||
var warn = ['[ionicons] Deprecated script, please remove: ' + scriptElm.outerHTML];
|
||||
|
||||
warn.push('To improve performance it is recommended to set the differential scripts in the head as follows:')
|
||||
|
||||
var parts = scriptElm.src.split('/');
|
||||
parts.pop();
|
||||
parts.push('ionicons');
|
||||
var url = parts.join('/');
|
||||
|
||||
var scriptElm = doc.createElement('script');
|
||||
scriptElm.setAttribute('type', 'module');
|
||||
scriptElm.src = url + '/ionicons.esm.js';
|
||||
warn.push(scriptElm.outerHTML);
|
||||
scriptElm.setAttribute('data-stencil-namespace', 'ionicons');
|
||||
doc.head.appendChild(scriptElm);
|
||||
|
||||
|
||||
scriptElm = doc.createElement('script');
|
||||
scriptElm.setAttribute('nomodule', '');
|
||||
scriptElm.src = url + '/ionicons.js';
|
||||
warn.push(scriptElm.outerHTML);
|
||||
scriptElm.setAttribute('data-stencil-namespace', 'ionicons');
|
||||
doc.head.appendChild(scriptElm)
|
||||
|
||||
console.warn(warn.join('\n'));
|
||||
|
||||
})(document);
|
||||
@@ -1,87 +0,0 @@
|
||||
import { PluginConfig } from 'svgo';
|
||||
|
||||
const setRootIoniconClass: PluginConfig = {
|
||||
name: 'addClassesToSVGElement',
|
||||
params: {
|
||||
className: 'ionicon',
|
||||
},
|
||||
};
|
||||
|
||||
const addFillNoneCss: PluginConfig = {
|
||||
name: 'addFillNoneCss',
|
||||
fn: () => ({
|
||||
element: {
|
||||
enter: (element) => {
|
||||
if (element.attributes.fill) {
|
||||
if (element.attributes.fill === 'none') {
|
||||
element.attributes.class = [...(element.attributes.class?.split(' ') || []), 'ionicon-fill-none'].join(' ');
|
||||
}
|
||||
delete element.attributes.fill;
|
||||
}
|
||||
if (element.attributes.stroke) {
|
||||
delete element.attributes.stroke;
|
||||
}
|
||||
if (
|
||||
element.attributes['stroke-width'] &&
|
||||
(element.attributes['stroke-width'] === '32px' || element.attributes['stroke-width'] === '32')
|
||||
) {
|
||||
delete element.attributes['stroke-width'];
|
||||
element.attributes.class = [...(element.attributes.class?.split(' ') || []), 'ionicon-stroke-width'].join(
|
||||
' ',
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
const forceCurrentColor: PluginConfig = {
|
||||
name: 'forceCurrentColor',
|
||||
fn: () => ({
|
||||
element: {
|
||||
enter: (element) => {
|
||||
const attr = element.attributes.stroke || element.attributes.fill;
|
||||
const attrName = element.attributes.stroke ? 'stroke' : element.attributes.fill ? 'fill' : undefined;
|
||||
|
||||
if (attrName) {
|
||||
if (attr === '#000' || attr === 'currentColor') {
|
||||
element.attributes[attrName] = 'currentColor';
|
||||
} else if (attr !== 'none') {
|
||||
throw new Error(`invalid "${attrName}" value: ${element.attributes[attrName]}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
const validatePlugin: PluginConfig = {
|
||||
name: 'validate',
|
||||
fn: () => ({
|
||||
element: {
|
||||
enter: (element) => {
|
||||
if (element.attributes.style) {
|
||||
console.warn(
|
||||
`Inline style attributed detected: <${element.name} style="${element.attributes.style}">...</${element.name}>`,
|
||||
);
|
||||
}
|
||||
if (element.name === 'style') {
|
||||
console.warn('Inline style element detected');
|
||||
}
|
||||
},
|
||||
},
|
||||
}),
|
||||
};
|
||||
|
||||
const basePlugins: PluginConfig[] = [
|
||||
'removeStyleElement',
|
||||
'convertStyleToAttrs',
|
||||
'removeScripts',
|
||||
'removeDimensions',
|
||||
setRootIoniconClass,
|
||||
validatePlugin,
|
||||
];
|
||||
|
||||
export const webComponentPassPlugins: PluginConfig[] = [...basePlugins, addFillNoneCss];
|
||||
|
||||
export const sourcePassPlugins: PluginConfig[] = [...basePlugins, forceCurrentColor];
|
||||
@@ -4,35 +4,38 @@
|
||||
|
||||
The `src/svg` directory is the single source of truth for svgs. They should not already be optimized and can be the original svg export straight out of an svg editor. A build step before releasing will optimize the source svgs (remove comments, reduce the size, etc) and ensure they'll work within `ion-icon`.
|
||||
|
||||
|
||||
## Build Locally
|
||||
|
||||
After an svg has been updated, added or deleted from the `src/svg` directory, run:
|
||||
|
||||
```sh
|
||||
npm run build
|
||||
```
|
||||
npm run build
|
||||
|
||||
The build command will optimize all of the icons and generate the files to be distributed. After the build command, all of the optimized svgs are saved in `dist/ionicons/svg`. Additionally the `dist` directory contains the distribution files for the `ion-icon` web component.
|
||||
|
||||
|
||||
## Svg Symbols Cheatsheet
|
||||
|
||||
After a build, a new `www/cheatsheet.html` file will be created. This version uses svg symbols rather than `ion-icon`.
|
||||
|
||||
|
||||
## ion-icon Component Preview
|
||||
|
||||
To see the `ion-icon` component in action, run:
|
||||
|
||||
```sh
|
||||
npm start
|
||||
```
|
||||
npm start
|
||||
|
||||
|
||||
## Release Steps
|
||||
|
||||
Releases are automated via GitHub Actions. To trigger a release:
|
||||
npm run release.prepare
|
||||
|
||||
1. Go to the [Release Orchestrator](https://github.com/ionic-team/ionicons/actions/workflows/release-orchestrator.yml) workflow
|
||||
2. Click "Run workflow"
|
||||
3. Select the release type:
|
||||
- **dev** — Creates a pre-release with a timestamp-based version (e.g., `8.0.14-dev.11784821417.1c794397`)
|
||||
- **production** — Creates a semver release; select `patch`, `minor`, or `major`
|
||||
4. The workflow will build, publish to NPM, and create a GitHub release (for production releases)
|
||||
The release script will ask what version to use. After the script completes, double check the `www/cheatsheet.html` to ensure everything is good to go.
|
||||
|
||||
Next, update `CHANGELOG.md`, then commit and push your changes Github.
|
||||
|
||||
Next run:
|
||||
|
||||
npm run release
|
||||
|
||||
Triple check the version number is correct, and choose which tag this should be released as. If it's a pre-release, it should be `dev`.
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"esModuleInterop": true,
|
||||
"module": "commonjs",
|
||||
"target": "es2017"
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
import { PluginConfig } from 'svgo';
|
||||
|
||||
export interface SvgData {
|
||||
/**
|
||||
* airplane-outline.svg
|
||||
*/
|
||||
fileName: string;
|
||||
|
||||
/**
|
||||
* airplane
|
||||
*/
|
||||
title: string;
|
||||
|
||||
/**
|
||||
* /src/svg/airplane-outline.svg
|
||||
*/
|
||||
srcFilePath: string;
|
||||
|
||||
/**
|
||||
* /dist/ionicons/svg/airplane-outline.svg
|
||||
*/
|
||||
optimizedFilePath: string;
|
||||
|
||||
/**
|
||||
* /dist/svg/airplane-outline.svg
|
||||
*/
|
||||
distSvgFilePath: string;
|
||||
|
||||
/**
|
||||
* optimized svg content
|
||||
*/
|
||||
optimizedSvgContent?: string;
|
||||
|
||||
/**
|
||||
* airplane-outline
|
||||
*/
|
||||
iconName: string;
|
||||
|
||||
/**
|
||||
* airplane-outline.mjs
|
||||
*/
|
||||
fileNameMjs: string;
|
||||
|
||||
/**
|
||||
* airplane-outline.js
|
||||
*/
|
||||
fileNameCjs: string;
|
||||
|
||||
/**
|
||||
* airplaneOutline
|
||||
*/
|
||||
exportName: string;
|
||||
}
|
||||
@@ -25,7 +25,6 @@ export namespace Components {
|
||||
"ios"?: string;
|
||||
/**
|
||||
* If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`.
|
||||
* @default false
|
||||
*/
|
||||
"lazy": boolean;
|
||||
/**
|
||||
@@ -34,7 +33,6 @@ export namespace Components {
|
||||
"md"?: string;
|
||||
/**
|
||||
* The mode determines which platform styles to use.
|
||||
* @default getIonMode()
|
||||
*/
|
||||
"mode": string;
|
||||
/**
|
||||
@@ -42,7 +40,7 @@ export namespace Components {
|
||||
*/
|
||||
"name"?: string;
|
||||
/**
|
||||
* When `true`, SVG content, including SVG `data:` URLs, is checked before it renders. SVGs with `<script>` elements, attributes that start with `on` (like `onclick`), `javascript:` URLs, or non-SVG elements aren't rendered, and `<foreignObject>` elements are removed. Only set this to `false` for SVG content from a trusted source.
|
||||
* When set to `false`, SVG content that is HTTP fetched will not be checked if the response SVG content has any `<script>` elements, or any attributes that start with `on`, such as `onclick`.
|
||||
* @default true
|
||||
*/
|
||||
"sanitize": boolean;
|
||||
@@ -87,7 +85,6 @@ declare namespace LocalJSX {
|
||||
"ios"?: string;
|
||||
/**
|
||||
* If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`.
|
||||
* @default false
|
||||
*/
|
||||
"lazy"?: boolean;
|
||||
/**
|
||||
@@ -96,7 +93,6 @@ declare namespace LocalJSX {
|
||||
"md"?: string;
|
||||
/**
|
||||
* The mode determines which platform styles to use.
|
||||
* @default getIonMode()
|
||||
*/
|
||||
"mode"?: string;
|
||||
/**
|
||||
@@ -104,7 +100,7 @@ declare namespace LocalJSX {
|
||||
*/
|
||||
"name"?: string;
|
||||
/**
|
||||
* When `true`, SVG content, including SVG `data:` URLs, is checked before it renders. SVGs with `<script>` elements, attributes that start with `on` (like `onclick`), `javascript:` URLs, or non-SVG elements aren't rendered, and `<foreignObject>` elements are removed. Only set this to `false` for SVG content from a trusted source.
|
||||
* When set to `false`, SVG content that is HTTP fetched will not be checked if the response SVG content has any `<script>` elements, or any attributes that start with `on`, such as `onclick`.
|
||||
* @default true
|
||||
*/
|
||||
"sanitize"?: boolean;
|
||||
@@ -117,30 +113,15 @@ declare namespace LocalJSX {
|
||||
*/
|
||||
"src"?: string;
|
||||
}
|
||||
|
||||
interface IonIconAttributes {
|
||||
"mode": string;
|
||||
"color": string;
|
||||
"ios": string;
|
||||
"md": string;
|
||||
"flipRtl": boolean;
|
||||
"name": string;
|
||||
"src": string;
|
||||
"icon": string;
|
||||
"size": string;
|
||||
"lazy": boolean;
|
||||
"sanitize": boolean;
|
||||
}
|
||||
|
||||
interface IntrinsicElements {
|
||||
"ion-icon": Omit<IonIcon, keyof IonIconAttributes> & { [K in keyof IonIcon & keyof IonIconAttributes]?: IonIcon[K] } & { [K in keyof IonIcon & keyof IonIconAttributes as `attr:${K}`]?: IonIconAttributes[K] } & { [K in keyof IonIcon & keyof IonIconAttributes as `prop:${K}`]?: IonIcon[K] };
|
||||
"ion-icon": IonIcon;
|
||||
}
|
||||
}
|
||||
export { LocalJSX as JSX };
|
||||
declare module "@stencil/core" {
|
||||
export namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
"ion-icon": LocalJSX.IntrinsicElements["ion-icon"] & JSXBase.HTMLAttributes<HTMLIonIconElement>;
|
||||
"ion-icon": LocalJSX.IonIcon & JSXBase.HTMLAttributes<HTMLIonIconElement>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
|
||||
font-size: 1em;
|
||||
|
||||
contain: layout style;
|
||||
contain: strict;
|
||||
|
||||
fill: currentColor;
|
||||
|
||||
box-sizing: content-box !important;
|
||||
|
||||
}
|
||||
|
||||
:host .ionicon {
|
||||
@@ -25,16 +24,7 @@
|
||||
stroke-width: var(--ionicon-stroke-width, 32px);
|
||||
}
|
||||
|
||||
.icon-inner {
|
||||
display: flex;
|
||||
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.icon-inner,
|
||||
.ionicon,
|
||||
svg {
|
||||
display: block;
|
||||
@@ -43,14 +33,6 @@ svg {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Slotted Content
|
||||
* -----------------------------------------------------------
|
||||
*/
|
||||
|
||||
::slotted(*) {
|
||||
font-size: inherit !important;
|
||||
}
|
||||
|
||||
/* Icon RTL
|
||||
* -----------------------------------------------------------
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Build, Component, Element, Host, Prop, State, Watch, h } from '@stencil/core';
|
||||
import { getCacheKey, getSvgContent, ioniconContent } from './request';
|
||||
import { getSvgContent, ioniconContent } from './request';
|
||||
import { getName, getUrl, inheritAttributes, isRTL } from './utils';
|
||||
|
||||
@Component({
|
||||
@@ -74,11 +74,9 @@ export class Icon {
|
||||
@Prop() lazy = false;
|
||||
|
||||
/**
|
||||
* When `true`, SVG content, including SVG `data:` URLs, is checked before it
|
||||
* renders. SVGs with `<script>` elements, attributes that start with `on`
|
||||
* (like `onclick`), `javascript:` URLs, or non-SVG elements aren't rendered,
|
||||
* and `<foreignObject>` elements are removed. Only set this to `false` for
|
||||
* SVG content from a trusted source.
|
||||
* When set to `false`, SVG content that is HTTP fetched will not be checked
|
||||
* if the response SVG content has any `<script>` elements, or any attributes
|
||||
* that start with `on`, such as `onclick`.
|
||||
* @default true
|
||||
*/
|
||||
@Prop() sanitize = true;
|
||||
@@ -88,20 +86,15 @@ export class Icon {
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
/**
|
||||
* purposely do not return the promise here because loading
|
||||
* the svg file should not hold up loading the app
|
||||
* only load the svg if it's visible
|
||||
*/
|
||||
// purposely do not return the promise here because loading
|
||||
// the svg file should not hold up loading the app
|
||||
// only load the svg if it's visible
|
||||
this.waitUntilVisible(this.el, '50px', () => {
|
||||
this.isVisible = true;
|
||||
this.loadIcon();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the icon after the component has finished rendering.
|
||||
*/
|
||||
componentDidLoad() {
|
||||
/**
|
||||
* Addresses an Angular issue where property values are assigned after the 'connectedCallback' but prior to the registration of watchers.
|
||||
@@ -114,59 +107,33 @@ export class Icon {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect the IntersectionObserver.
|
||||
*/
|
||||
disconnectedCallback() {
|
||||
if (this.io) {
|
||||
this.io.disconnect();
|
||||
this.io = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the icon is visible in the viewport.
|
||||
* @param el - The element to observe.
|
||||
* @param rootMargin - The root margin of the observer.
|
||||
* @param cb - The callback to call when the element is visible.
|
||||
*/
|
||||
private waitUntilVisible(el: HTMLElement, rootMargin: string, cb: () => void) {
|
||||
/**
|
||||
* IntersectionObserver is a browser API that allows you to observe
|
||||
* the visibility of an element relative to a root element. It is
|
||||
* supported in all modern browsers, except IE and when server-side
|
||||
* rendering.
|
||||
*/
|
||||
const hasIntersectionObserverSupport = Boolean(
|
||||
Build.isBrowser && this.lazy && typeof window !== 'undefined' && window.IntersectionObserver,
|
||||
);
|
||||
if (Build.isBrowser && this.lazy && typeof window !== 'undefined' && (window as any).IntersectionObserver) {
|
||||
const io = (this.io = new (window as any).IntersectionObserver(
|
||||
(data: IntersectionObserverEntry[]) => {
|
||||
if (data[0].isIntersecting) {
|
||||
io.disconnect();
|
||||
this.io = undefined;
|
||||
cb();
|
||||
}
|
||||
},
|
||||
{ rootMargin },
|
||||
));
|
||||
|
||||
/**
|
||||
* browser doesn't support IntersectionObserver
|
||||
* so just fallback to always show it
|
||||
*/
|
||||
if (!hasIntersectionObserverSupport) {
|
||||
return cb();
|
||||
io.observe(el);
|
||||
} else {
|
||||
// browser doesn't support IntersectionObserver
|
||||
// so just fallback to always show it
|
||||
cb();
|
||||
}
|
||||
|
||||
const io = (this.io = new window.IntersectionObserver(
|
||||
(data: IntersectionObserverEntry[]) => {
|
||||
if (data[0].isIntersecting) {
|
||||
io.disconnect();
|
||||
this.io = undefined;
|
||||
cb();
|
||||
}
|
||||
},
|
||||
{ rootMargin },
|
||||
));
|
||||
|
||||
io.observe(el);
|
||||
}
|
||||
|
||||
/**
|
||||
* Watch for changes to the icon name, src, icon, ios, or md properties.
|
||||
* When a change is detected, the icon will be loaded.
|
||||
*/
|
||||
@Watch('name')
|
||||
@Watch('src')
|
||||
@Watch('icon')
|
||||
@@ -177,13 +144,12 @@ export class Icon {
|
||||
const url = getUrl(this);
|
||||
|
||||
if (url) {
|
||||
const cacheKey = getCacheKey(url, this.sanitize);
|
||||
if (ioniconContent.has(cacheKey)) {
|
||||
if (ioniconContent.has(url)) {
|
||||
// sync if it's already loaded
|
||||
this.svgContent = ioniconContent.get(cacheKey);
|
||||
this.svgContent = ioniconContent.get(url);
|
||||
} else {
|
||||
// async if it hasn't been loaded
|
||||
getSvgContent(url, this.sanitize).then(() => (this.svgContent = ioniconContent.get(cacheKey)));
|
||||
getSvgContent(url, this.sanitize).then(() => (this.svgContent = ioniconContent.get(url)));
|
||||
}
|
||||
this.didLoadIcon = true;
|
||||
}
|
||||
@@ -195,18 +161,11 @@ export class Icon {
|
||||
render() {
|
||||
const { flipRtl, iconName, inheritedAttributes, el } = this;
|
||||
const mode = this.mode || 'md';
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
// 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
|
||||
*/
|
||||
// if shouldBeFlippable is true, the icon should change direction when `dir` changes
|
||||
const shouldBeFlippable = flipRtl || shouldAutoFlip;
|
||||
|
||||
return (
|
||||
@@ -217,34 +176,23 @@ export class Icon {
|
||||
...createColorClasses(this.color),
|
||||
[`icon-${this.size}`]: !!this.size,
|
||||
'flip-rtl': shouldBeFlippable,
|
||||
'icon-rtl': shouldBeFlippable && isRTL(el),
|
||||
'icon-rtl': shouldBeFlippable && isRTL(el)
|
||||
}}
|
||||
{...inheritedAttributes}
|
||||
>
|
||||
{Build.isBrowser && this.svgContent ? (
|
||||
<div class="icon-inner" innerHTML={this.svgContent}></div>
|
||||
) : (
|
||||
<div class="icon-inner">
|
||||
<slot></slot>
|
||||
</div>
|
||||
<div class="icon-inner"></div>
|
||||
)}
|
||||
</Host>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the mode of the document.
|
||||
* @returns The mode of the document.
|
||||
*/
|
||||
const getIonMode = () =>
|
||||
(Build.isBrowser && typeof document !== 'undefined' && document.documentElement.getAttribute('mode')) || 'md';
|
||||
|
||||
/**
|
||||
* Create color classes for the icon.
|
||||
* @param color - The color of the icon.
|
||||
* @returns The color classes for the icon.
|
||||
*/
|
||||
const createColorClasses = (color: string | undefined) => {
|
||||
return color
|
||||
? {
|
||||
|
||||
@@ -7,19 +7,19 @@
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Attribute | Description | Type | Default |
|
||||
| ---------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | -------------- |
|
||||
| `color` | `color` | The color to use for the background of the item. | `string \| undefined` | `undefined` |
|
||||
| `flipRtl` | `flip-rtl` | Specifies whether the icon should horizontally flip when `dir` is `"rtl"`. | `boolean \| undefined` | `undefined` |
|
||||
| `icon` | `icon` | A combination of both `name` and `src`. If a `src` url is detected it will set the `src` property. Otherwise it assumes it's a built-in named SVG and set the `name` property. | `any` | `undefined` |
|
||||
| `ios` | `ios` | Specifies which icon to use on `ios` mode. | `string \| undefined` | `undefined` |
|
||||
| `lazy` | `lazy` | If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`. | `boolean` | `false` |
|
||||
| `md` | `md` | Specifies which icon to use on `md` mode. | `string \| undefined` | `undefined` |
|
||||
| `mode` | `mode` | The mode determines which platform styles to use. | `string` | `getIonMode()` |
|
||||
| `name` | `name` | Specifies which icon to use from the built-in set of icons. | `string \| undefined` | `undefined` |
|
||||
| `sanitize` | `sanitize` | When `true`, SVG content, including SVG `data:` URLs, is checked before it renders. SVGs with `<script>` elements, attributes that start with `on` (like `onclick`), `javascript:` URLs, or non-SVG elements aren't rendered, and `<foreignObject>` elements are removed. Only set this to `false` for SVG content from a trusted source. | `boolean` | `true` |
|
||||
| `size` | `size` | The size of the icon. Available options are: `"small"` and `"large"`. | `string \| undefined` | `undefined` |
|
||||
| `src` | `src` | Specifies the exact `src` of an SVG file to use. | `string \| undefined` | `undefined` |
|
||||
| Property | Attribute | Description | Type | Default |
|
||||
| ---------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------- | -------------- |
|
||||
| `color` | `color` | The color to use for the background of the item. | `string \| undefined` | `undefined` |
|
||||
| `flipRtl` | `flip-rtl` | Specifies whether the icon should horizontally flip when `dir` is `"rtl"`. | `boolean \| undefined` | `undefined` |
|
||||
| `icon` | `icon` | A combination of both `name` and `src`. If a `src` url is detected it will set the `src` property. Otherwise it assumes it's a built-in named SVG and set the `name` property. | `any` | `undefined` |
|
||||
| `ios` | `ios` | Specifies which icon to use on `ios` mode. | `string \| undefined` | `undefined` |
|
||||
| `lazy` | `lazy` | If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`. | `boolean` | `false` |
|
||||
| `md` | `md` | Specifies which icon to use on `md` mode. | `string \| undefined` | `undefined` |
|
||||
| `mode` | `mode` | The mode determines which platform styles to use. | `string` | `getIonMode()` |
|
||||
| `name` | `name` | Specifies which icon to use from the built-in set of icons. | `string \| undefined` | `undefined` |
|
||||
| `sanitize` | `sanitize` | When set to `false`, SVG content that is HTTP fetched will not be checked if the response SVG content has any `<script>` elements, or any attributes that start with `on`, such as `onclick`. | `boolean` | `true` |
|
||||
| `size` | `size` | The size of the icon. Available options are: `"small"` and `"large"`. | `string \| undefined` | `undefined` |
|
||||
| `src` | `src` | Specifies the exact `src` of an SVG file to use. | `string \| undefined` | `undefined` |
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
|
||||
@@ -5,107 +5,53 @@ const requests = new Map<string, Promise<any>>();
|
||||
|
||||
let parser: DOMParser;
|
||||
|
||||
/**
|
||||
* Unsanitized content gets its own key so it's never served to an icon that
|
||||
* sanitizes.
|
||||
*/
|
||||
export const getCacheKey = (url: string, sanitize: boolean) =>
|
||||
`${sanitize !== false ? 'sanitized' : 'unsanitized'}:${url}`;
|
||||
export const getSvgContent = (url: string, sanitize: boolean) => {
|
||||
// see if we already have a request for this url
|
||||
let req = requests.get(url);
|
||||
|
||||
/**
|
||||
* Warns when the whole icon is rejected so it doesn't silently render nothing.
|
||||
*/
|
||||
const sanitizeSvg = (url: string, svgContent: string) =>
|
||||
validateContent(svgContent, () => {
|
||||
const source = url.length > 100 ? `${url.slice(0, 100)}...` : url;
|
||||
console.warn(
|
||||
`[Ionicons Warning]: The SVG from "${source}" was not rendered because it failed sanitization. Only set sanitize="false" for SVG content from a trusted source.`,
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Safely fallback to an empty svg
|
||||
*/
|
||||
function safeFallback(cacheKey: string) {
|
||||
const svg = '';
|
||||
ioniconContent.set(cacheKey, svg);
|
||||
return svg;
|
||||
}
|
||||
|
||||
export const getSvgContent = (url: string, sanitize: boolean): Promise<string> => {
|
||||
const cacheKey = getCacheKey(url, sanitize);
|
||||
/**
|
||||
* See if we already have a request for this url
|
||||
*/
|
||||
const req = requests.get(cacheKey);
|
||||
if (req) {
|
||||
return req;
|
||||
}
|
||||
|
||||
if (typeof fetch !== 'undefined' && typeof document !== 'undefined') {
|
||||
/**
|
||||
* 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)) {
|
||||
return Promise.resolve(getSvgByUrl(url, sanitize));
|
||||
}
|
||||
|
||||
return fetchSvg(url, sanitize);
|
||||
}
|
||||
|
||||
return Promise.resolve(safeFallback(cacheKey));
|
||||
};
|
||||
|
||||
function getSvgByUrl(url: string, sanitize: boolean): string {
|
||||
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 doc = parser.parseFromString(url, 'text/html');
|
||||
const svg = doc.querySelector('svg');
|
||||
if (svg) {
|
||||
const svgContent = sanitize !== false ? sanitizeSvg(url, svg.outerHTML) : svg.outerHTML;
|
||||
ioniconContent.set(getCacheKey(url, sanitize), svgContent);
|
||||
return svgContent;
|
||||
}
|
||||
|
||||
throw new Error(`Could not parse svg from ${url}`);
|
||||
}
|
||||
|
||||
function fetchSvg(url: string, sanitize: boolean): Promise<string> {
|
||||
const cacheKey = getCacheKey(url, sanitize);
|
||||
/**
|
||||
* We don't already have a request
|
||||
*/
|
||||
const req = fetch(url)
|
||||
.then((rsp) => {
|
||||
if (!req) {
|
||||
if (typeof fetch !== 'undefined' && typeof document !== 'undefined') {
|
||||
/**
|
||||
* When fetching from a file:// URL, some browsers return
|
||||
* a 0 status code even when the request succeeds so don't
|
||||
* rely on rsp.ok as the only signal of success.
|
||||
* 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.
|
||||
*/
|
||||
return rsp
|
||||
.text()
|
||||
.then((svgContent) => {
|
||||
if (svgContent && sanitize !== false) {
|
||||
svgContent = sanitizeSvg(url, svgContent);
|
||||
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();
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
const svg = svgContent || '';
|
||||
ioniconContent.set(cacheKey, svg);
|
||||
return svg;
|
||||
})
|
||||
.catch(() => safeFallback(cacheKey));
|
||||
})
|
||||
.catch(() => safeFallback(cacheKey));
|
||||
} else {
|
||||
// set to empty for ssr scenarios and resolve promise
|
||||
ioniconContent.set(url, '');
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache for the same requests
|
||||
*/
|
||||
requests.set(cacheKey, req);
|
||||
return req;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# this gitignore file is used as a placeholder
|
||||
# for this directory. The directory itself will
|
||||
# contain files generated during a build step.
|
||||
*
|
||||
!.gitignore
|
||||
@@ -1,15 +0,0 @@
|
||||
import { expect } from '@playwright/test';
|
||||
import { test } from '@utils/test/playwright';
|
||||
import { AxeBuilder } from '@axe-core/playwright';
|
||||
|
||||
test.describe('icon: a11y', () => {
|
||||
test('should pass accessibility checks', async ({ page }) => {
|
||||
await page.goto(`/icon/test/a11y/`);
|
||||
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const results = await new AxeBuilder({ page }).analyze();
|
||||
|
||||
expect(results.violations).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -1,59 +0,0 @@
|
||||
<!doctype html>
|
||||
<html dir="ltr" lang="en" mode="ios">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
|
||||
<title>Icon - Accessibility</title>
|
||||
<script type="module" src="/build/ionicons.esm.js"></script>
|
||||
<script nomodule src="/build/ionicons.js"></script>
|
||||
<link rel="stylesheet" href="../styles.css" />
|
||||
<script src="../header.js"></script>
|
||||
|
||||
<!-- Font Awesome Icons -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<test-header></test-header>
|
||||
|
||||
<main>
|
||||
<h1>Icon - Accessibility</h1>
|
||||
|
||||
<h2>SVG icon with aria-label</h2>
|
||||
<ion-icon name="cellular" aria-label="Mobile data"></ion-icon>
|
||||
|
||||
<h2>Button with aria-label and SVG icon</h2>
|
||||
<button aria-label="Mobile data">
|
||||
<ion-icon name="cellular" aria-hidden="true"></ion-icon>
|
||||
</button>
|
||||
|
||||
<h2>SVG icon with aria-hidden</h2>
|
||||
<ion-icon name="cellular" aria-hidden="true"></ion-icon>
|
||||
|
||||
<hr />
|
||||
|
||||
<h2>Font icon with aria-label</h2>
|
||||
<ion-icon aria-label="Mobile data">
|
||||
<i class="fa fa-home"></i>
|
||||
</ion-icon>
|
||||
|
||||
<h2>Button with aria-label and font icon</h2>
|
||||
<button aria-label="Mobile data">
|
||||
<ion-icon aria-hidden="true">
|
||||
<i class="fa fa-home"></i>
|
||||
</ion-icon>
|
||||
</button>
|
||||
|
||||
<h2>Font icon with aria-hidden</h2>
|
||||
<ion-icon aria-hidden="true">
|
||||
<i class="fa fa-home"></i>
|
||||
</ion-icon>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
ion-icon {
|
||||
font-size: 32px;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,13 +0,0 @@
|
||||
import { expect } from '@playwright/test';
|
||||
import { test } from '@utils/test/playwright';
|
||||
|
||||
test.describe('icon: basic', () => {
|
||||
test('should not have visual regressions', async ({ page }) => {
|
||||
await page.goto(`/icon/test/basic/`);
|
||||
|
||||
// Wait for all SVGs to be lazily loaded before taking screenshots
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await expect(page).toHaveScreenshot(`icon-basic.png`, { fullPage: true });
|
||||
});
|
||||
});
|
||||
|
Before Width: | Height: | Size: 59 KiB |
|
Before Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 68 KiB |
@@ -1,101 +0,0 @@
|
||||
<!doctype html>
|
||||
<html dir="ltr" lang="en" mode="ios">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
|
||||
<title>Icon - Basic</title>
|
||||
<script type="module" src="/build/ionicons.esm.js"></script>
|
||||
<script nomodule src="/build/ionicons.js"></script>
|
||||
<link rel="stylesheet" href="../styles.css" />
|
||||
<script src="../header.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<test-header></test-header>
|
||||
|
||||
<main>
|
||||
<h1>Icon - Basic</h1>
|
||||
|
||||
<h2>Default</h2>
|
||||
<ion-icon name="cellular"></ion-icon>
|
||||
<ion-icon name="at"></ion-icon>
|
||||
<ion-icon name="call"></ion-icon>
|
||||
<ion-icon name="football"></ion-icon>
|
||||
<ion-icon name="analytics"></ion-icon>
|
||||
<ion-icon name="grid"></ion-icon>
|
||||
<ion-icon name="funnel"></ion-icon>
|
||||
<ion-icon name="watch"></ion-icon>
|
||||
<ion-icon name="add-circle-outline"></ion-icon>
|
||||
|
||||
<h2>Mode from html ios mode attribute</h2>
|
||||
<ion-icon md="logo-android" ios="logo-apple"></ion-icon>
|
||||
<ion-icon md="logo-android" ios="logo-apple"></ion-icon>
|
||||
|
||||
<h2>Mode set on icon</h2>
|
||||
<ion-icon mode="ios" md="logo-android" ios="logo-apple"></ion-icon>
|
||||
<ion-icon mode="md" md="logo-android" ios="logo-apple"></ion-icon>
|
||||
|
||||
<h2>Colors</h2>
|
||||
<ion-icon color="primary" name="cellular"></ion-icon>
|
||||
<ion-icon color="secondary" name="at"></ion-icon>
|
||||
<ion-icon color="tertiary" name="call"></ion-icon>
|
||||
<ion-icon color="success" name="football"></ion-icon>
|
||||
<ion-icon color="warning" name="analytics"></ion-icon>
|
||||
<ion-icon color="danger" name="grid"></ion-icon>
|
||||
<ion-icon color="light" name="funnel"></ion-icon>
|
||||
<ion-icon color="medium" name="watch"></ion-icon>
|
||||
<ion-icon color="dark" name="toggle"></ion-icon>
|
||||
|
||||
<h2>Stroke width</h2>
|
||||
<ion-icon name="heart-outline" style="--ionicon-stroke-width: 8px"></ion-icon>
|
||||
|
||||
<h2>Font size</h2>
|
||||
<ion-icon name="book" style="font-size: 50px"></ion-icon>
|
||||
<ion-icon src="../../assets/bug_report.svg" style="font-size: 50px"></ion-icon>
|
||||
|
||||
<h2>Custom SVGs</h2>
|
||||
<ion-icon src="../../assets/bug_report.svg"></ion-icon>
|
||||
<ion-icon src="../../assets/chat.svg"></ion-icon>
|
||||
<ion-icon src="../../assets/commute.svg"></ion-icon>
|
||||
<ion-icon src="../../assets/copyright.svg"></ion-icon>
|
||||
<ion-icon src="../../assets/done_all.svg"></ion-icon>
|
||||
<ion-icon src="../../assets/lock_open.svg"></ion-icon>
|
||||
<ion-icon src="../../assets/toll.svg"></ion-icon>
|
||||
<ion-icon src="../../assets/web_asset.svg"></ion-icon>
|
||||
<ion-icon src="../../assets/work_outline.svg"></ion-icon>
|
||||
|
||||
<h2>Custom SVGs: colors</h2>
|
||||
<ion-icon color="primary" src="../../assets/bug_report.svg"></ion-icon>
|
||||
<ion-icon color="secondary" src="../../assets/chat.svg"></ion-icon>
|
||||
<ion-icon color="tertiary" src="../../assets/commute.svg"></ion-icon>
|
||||
<ion-icon color="success" src="../../assets/copyright.svg"></ion-icon>
|
||||
<ion-icon color="warning" src="../../assets/done_all.svg"></ion-icon>
|
||||
<ion-icon color="danger" src="../../assets/lock_open.svg"></ion-icon>
|
||||
<ion-icon color="light" src="../../assets/toll.svg"></ion-icon>
|
||||
<ion-icon color="medium" src="../../assets/web_asset.svg"></ion-icon>
|
||||
<ion-icon color="dark" src="../../assets/work_outline.svg"></ion-icon>
|
||||
|
||||
<h2>Custom CSS</h2>
|
||||
<ion-icon class="custom" name="grid"></ion-icon>
|
||||
<ion-icon class="custom" name="funnel"></ion-icon>
|
||||
<ion-icon class="custom" name="watch"></ion-icon>
|
||||
<ion-icon class="custom" name="logo-react"></ion-icon>
|
||||
<ion-icon class="custom" name="logo-javascript"></ion-icon>
|
||||
<ion-icon class="custom" name="logo-angular"></ion-icon>
|
||||
<ion-icon class="custom" src="../../assets/done_all.svg"></ion-icon>
|
||||
<ion-icon class="custom" src="../../assets/web_asset.svg"></ion-icon>
|
||||
<ion-icon class="custom" src="../../assets/work_outline.svg"></ion-icon>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
ion-icon {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.custom {
|
||||
stroke: red;
|
||||
fill: blue;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,52 +0,0 @@
|
||||
<!doctype html>
|
||||
<html dir="ltr" lang="en" mode="ios">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
|
||||
<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="default-src 'none'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com/*; img-src 'self'; connect-src 'self'; font-src https://fonts.gstatic.com/*'"
|
||||
/>
|
||||
<title>Icon - Content Security Policy</title>
|
||||
<script type="module" src="/build/ionicons.esm.js"></script>
|
||||
<script nomodule src="/build/ionicons.js"></script>
|
||||
<link rel="stylesheet" href="../styles.css" />
|
||||
<script src="../header.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<test-header></test-header>
|
||||
|
||||
<main>
|
||||
<h1>Icon - Content Security Policy</h1>
|
||||
|
||||
<h2>Default</h2>
|
||||
<ion-icon src="/assets/chat.svg"></ion-icon>
|
||||
<ion-icon name="add"></ion-icon>
|
||||
|
||||
<ion-icon
|
||||
id="icon-usage"
|
||||
icon="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><title>Watch</title><rect x='136' y='136' width='240' height='240' rx='8' ry='8'/><path d='M384 96h-48V16H176v80h-48a32 32 0 00-32 32v256a32 32 0 0032 32h48v80h160v-80h48a32 32 0 0032-32V128a32 32 0 00-32-32zm8 272a24 24 0 01-24 24H144a24 24 0 01-24-24V144a24 24 0 0124-24h224a24 24 0 0124 24z'/></svg>"
|
||||
>
|
||||
</ion-icon>
|
||||
|
||||
<ion-icon
|
||||
class="custom"
|
||||
icon="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><title>Watch</title><rect x='136' y='136' width='240' height='240' rx='8' ry='8'/><path d='M384 96h-48V16H176v80h-48a32 32 0 00-32 32v256a32 32 0 0032 32h48v80h160v-80h48a32 32 0 0032-32V128a32 32 0 00-32-32zm8 272a24 24 0 01-24 24H144a24 24 0 01-24-24V144a24 24 0 0124-24h224a24 24 0 0124 24z'/></svg>"
|
||||
>
|
||||
</ion-icon>
|
||||
</main>
|
||||
</body>
|
||||
|
||||
<style>
|
||||
ion-icon {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
.custom {
|
||||
stroke: red;
|
||||
fill: goldenrod;
|
||||
color: black;
|
||||
}
|
||||
</style>
|
||||
</html>
|
||||
|
Before Width: | Height: | Size: 13 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 16 KiB |
@@ -1,45 +0,0 @@
|
||||
<!doctype html>
|
||||
<html dir="ltr" lang="en" mode="ios">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
|
||||
<title>Icon - Dynamic Type</title>
|
||||
<script type="module" src="/build/ionicons.esm.js"></script>
|
||||
<script nomodule src="/build/ionicons.js"></script>
|
||||
<link rel="stylesheet" href="../styles.css" />
|
||||
<script src="../header.js"></script>
|
||||
|
||||
<!-- Font Awesome Icons -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<test-header></test-header>
|
||||
|
||||
<main>
|
||||
<h1>Icon - Dynamic Type</h1>
|
||||
|
||||
<h2>Default Icons</h2>
|
||||
<ion-icon name="star"></ion-icon>
|
||||
<ion-icon name="star" size="small"></ion-icon>
|
||||
<ion-icon name="star" size="large"></ion-icon>
|
||||
|
||||
<h2>Font Icons</h2>
|
||||
<ion-icon>
|
||||
<i class="fa fa-star"></i>
|
||||
</ion-icon>
|
||||
<ion-icon size="small">
|
||||
<i class="fa fa-star"></i>
|
||||
</ion-icon>
|
||||
<ion-icon size="large">
|
||||
<i class="fa fa-star"></i>
|
||||
</ion-icon>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
html {
|
||||
font-size: 28px;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,14 +0,0 @@
|
||||
class TestHeader extends HTMLElement {
|
||||
connectedCallback() {
|
||||
const header = document.createElement('header');
|
||||
header.innerHTML = `
|
||||
<a href="/" class="back-button">
|
||||
<ion-icon name="arrow-back" aria-hidden="true"></ion-icon>
|
||||
Back
|
||||
</a>
|
||||
`;
|
||||
this.appendChild(header);
|
||||
}
|
||||
}
|
||||
|
||||
customElements.define('test-header', TestHeader);
|
||||
@@ -1,9 +1,18 @@
|
||||
import { expect } from '@playwright/test';
|
||||
import { test } from '@utils/test/playwright';
|
||||
|
||||
test.describe('icon: rtl', () => {
|
||||
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');
|
||||
|
||||
await expect(page).toHaveScreenshot(`icon-diff.png`, { fullPage: true });
|
||||
});
|
||||
|
||||
test('some icons should flip when rtl', async ({ page }) => {
|
||||
await page.goto(`/icon/test/rtl/`);
|
||||
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');
|
||||
@@ -20,11 +29,12 @@ test.describe('icon: rtl', () => {
|
||||
// Wait for all SVGs to be lazily loaded before taking screenshots
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await expect(page).toHaveScreenshot(`icon-rtl.png`);
|
||||
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(`/icon/test/rtl/`);
|
||||
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');
|
||||
@@ -41,7 +51,7 @@ test.describe('icon: rtl', () => {
|
||||
});
|
||||
|
||||
test('icon should reassess flipping when name changes', async ({ page }) => {
|
||||
await page.goto(`/icon/test/rtl/`);
|
||||
await page.goto(`/`);
|
||||
|
||||
await page.evaluate(() => {
|
||||
document.dir = 'rtl';
|
||||
@@ -57,4 +67,5 @@ test.describe('icon: rtl', () => {
|
||||
await expect(iconLoc).toHaveAttribute('name', 'brush');
|
||||
await expect(iconLoc).not.toHaveClass(/flip-rtl/);
|
||||
});
|
||||
|
||||
});
|
||||
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 102 KiB |
|
After Width: | Height: | Size: 89 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 25 KiB |
@@ -1,202 +1,79 @@
|
||||
import { newSpecPage } from 'jest-stencil-runner';
|
||||
import { newSpecPage } from '@stencil/core/testing';
|
||||
import { Icon } from '../icon';
|
||||
|
||||
describe('icon', () => {
|
||||
describe('basic rendering', () => {
|
||||
it('renders', async () => {
|
||||
const { root } = await newSpecPage({
|
||||
components: [Icon],
|
||||
html: '<ion-icon></ion-icon>',
|
||||
});
|
||||
expect(root).toEqualHtml(`
|
||||
<ion-icon class="md" role="img">
|
||||
<mock:shadow-root>
|
||||
<div class="icon-inner">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</mock:shadow-root>
|
||||
</ion-icon>
|
||||
`);
|
||||
});
|
||||
|
||||
it('renders rtl with aria-hidden', async () => {
|
||||
const { root } = await newSpecPage({
|
||||
components: [Icon],
|
||||
direction: 'rtl',
|
||||
html: `<ion-icon name="chevron-forward" aria-hidden="true"></ion-icon>`,
|
||||
});
|
||||
|
||||
expect(root).toEqualHtml(`
|
||||
<ion-icon class="md flip-rtl icon-rtl" name="chevron-forward" role="img" aria-hidden="true">
|
||||
<mock:shadow-root>
|
||||
<div class="icon-inner">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</mock:shadow-root>
|
||||
</ion-icon>
|
||||
`);
|
||||
});
|
||||
|
||||
it('renders custom aria-label', async () => {
|
||||
const { root } = await newSpecPage({
|
||||
components: [Icon],
|
||||
html: `<ion-icon name="star" aria-label="custom label"></ion-icon>`,
|
||||
});
|
||||
|
||||
expect(root).toEqualHtml(`
|
||||
<ion-icon class="md" name="star" role="img" aria-label="custom label">
|
||||
<mock:shadow-root>
|
||||
<div class="icon-inner">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</mock:shadow-root>
|
||||
</ion-icon>
|
||||
`);
|
||||
it('renders', async () => {
|
||||
const { root } = await newSpecPage({
|
||||
components: [Icon],
|
||||
html: '<ion-icon></ion-icon>',
|
||||
});
|
||||
expect(root).toEqualHtml(`
|
||||
<ion-icon class="md" role="img">
|
||||
<mock:shadow-root>
|
||||
<div class="icon-inner"></div>
|
||||
</mock:shadow-root>
|
||||
</ion-icon>
|
||||
`);
|
||||
});
|
||||
|
||||
describe('dynamic rendering', () => {
|
||||
it('renders custom label after changing source', async () => {
|
||||
const page = await newSpecPage({
|
||||
components: [Icon],
|
||||
html: `<ion-icon name="chevron-forward" aria-label="custom label"></ion-icon>`,
|
||||
});
|
||||
|
||||
const icon = page.root;
|
||||
|
||||
expect(icon).toEqualHtml(`
|
||||
<ion-icon class="flip-rtl md" name="chevron-forward" role="img" aria-label="custom label">
|
||||
<mock:shadow-root>
|
||||
<div class="icon-inner">
|
||||
<slot></slot>
|
||||
</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="custom label">
|
||||
<mock:shadow-root>
|
||||
<div class="icon-inner">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</mock:shadow-root>
|
||||
</ion-icon>
|
||||
`);
|
||||
it('renders rtl with aria-hidden', async () => {
|
||||
const { root } = await newSpecPage({
|
||||
components: [Icon],
|
||||
direction: 'rtl',
|
||||
html: `<ion-icon name="chevron-forward" aria-hidden="true"></ion-icon>`,
|
||||
});
|
||||
|
||||
expect(root).toEqualHtml(`
|
||||
<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>
|
||||
</ion-icon>
|
||||
`);
|
||||
});
|
||||
|
||||
describe('svg rendering scenarios', () => {
|
||||
it('svgContent=true: renders svg without slot', async () => {
|
||||
const page = await newSpecPage({
|
||||
components: [Icon],
|
||||
html: `<ion-icon aria-hidden="true" part="close-icon" class="close-icon"></ion-icon>`,
|
||||
});
|
||||
|
||||
const icon = page.root as any;
|
||||
const instance = page.rootInstance as any;
|
||||
instance.svgContent = '<svg><circle cx="50" cy="50" r="40"/></svg>';
|
||||
await page.waitForChanges();
|
||||
|
||||
const shadowRoot = icon.shadowRoot;
|
||||
const iconInner = shadowRoot?.querySelector('.icon-inner');
|
||||
|
||||
// Should have no slot
|
||||
const slot = iconInner?.querySelector('slot');
|
||||
expect(slot).toBeNull();
|
||||
|
||||
// SVG should be a direct child of icon-inner,
|
||||
// not nested in another div
|
||||
expect(iconInner?.children.length).toBe(1);
|
||||
const firstChild = iconInner?.children[0];
|
||||
expect((firstChild as any)?.tagName?.toLowerCase()).toBe('svg');
|
||||
expect(firstChild?.querySelector('circle')).not.toBeNull();
|
||||
|
||||
it('renders custom aria-label', async () => {
|
||||
const { root } = await newSpecPage({
|
||||
components: [Icon],
|
||||
html: `<ion-icon name="star" aria-label="custom label"></ion-icon>`,
|
||||
});
|
||||
|
||||
it('svgContent=false: renders slot for custom content', async () => {
|
||||
const page = await newSpecPage({
|
||||
components: [Icon],
|
||||
html: `<ion-icon aria-hidden="true" part="close-icon" class="close-icon"></ion-icon>`,
|
||||
});
|
||||
|
||||
const icon = page.root as any;
|
||||
const shadowRoot = icon.shadowRoot;
|
||||
const iconInner = shadowRoot?.querySelector('.icon-inner');
|
||||
const slot = iconInner?.querySelector('slot');
|
||||
const svg = iconInner?.querySelector('svg');
|
||||
|
||||
expect(slot).not.toBeNull();
|
||||
expect(svg).toBeNull();
|
||||
});
|
||||
expect(root).toEqualHtml(`
|
||||
<ion-icon class="md" name="star" role="img" aria-label="custom label">
|
||||
<mock:shadow-root>
|
||||
<div class="icon-inner"></div>
|
||||
</mock:shadow-root>
|
||||
</ion-icon>
|
||||
`);
|
||||
});
|
||||
|
||||
describe('slotted content', () => {
|
||||
it('renders slotted font icon (Font Awesome)', async () => {
|
||||
const { root } = await newSpecPage({
|
||||
components: [Icon],
|
||||
html: `
|
||||
<ion-icon>
|
||||
<i class="fa fa-home"></i>
|
||||
</ion-icon>
|
||||
`,
|
||||
});
|
||||
expect(root).toEqualHtml(`
|
||||
<ion-icon class="md" role="img">
|
||||
<mock:shadow-root>
|
||||
<div class="icon-inner">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</mock:shadow-root>
|
||||
<i class="fa fa-home"></i>
|
||||
</ion-icon>
|
||||
`);
|
||||
|
||||
it('renders custom label after changing source', async () => {
|
||||
const page = await newSpecPage({
|
||||
components: [Icon],
|
||||
html: `<ion-icon name="chevron-forward" aria-label="custom label"></ion-icon>`,
|
||||
});
|
||||
|
||||
const icon = page.root;
|
||||
|
||||
it('renders slotted font icon with color', async () => {
|
||||
const { root } = await newSpecPage({
|
||||
components: [Icon],
|
||||
html: `
|
||||
<ion-icon color="primary">
|
||||
<i class="fa fa-heart"></i>
|
||||
</ion-icon>
|
||||
`,
|
||||
});
|
||||
expect(root).toEqualHtml(`
|
||||
<ion-icon class="md ion-color ion-color-primary" color="primary" role="img">
|
||||
<mock:shadow-root>
|
||||
<div class="icon-inner">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</mock:shadow-root>
|
||||
<i class="fa fa-heart"></i>
|
||||
</ion-icon>
|
||||
`);
|
||||
});
|
||||
expect(icon).toEqualHtml(`
|
||||
<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>
|
||||
</ion-icon>
|
||||
`);
|
||||
|
||||
if (icon) {
|
||||
icon.name = 'trash';
|
||||
}
|
||||
await page.waitForChanges();
|
||||
|
||||
it('renders slotted font icon with custom style', async () => {
|
||||
const { root } = await newSpecPage({
|
||||
components: [Icon],
|
||||
html: `
|
||||
<ion-icon style="font-size: 48px">
|
||||
<i class="fa fa-star"></i>
|
||||
</ion-icon>
|
||||
`,
|
||||
});
|
||||
expect(root).toEqualHtml(`
|
||||
<ion-icon class="md" role="img" style="font-size: 48px">
|
||||
<mock:shadow-root>
|
||||
<div class="icon-inner">
|
||||
<slot></slot>
|
||||
</div>
|
||||
</mock:shadow-root>
|
||||
<i class="fa fa-star"></i>
|
||||
</ion-icon>
|
||||
`);
|
||||
});
|
||||
expect(icon).toEqualHtml(`
|
||||
<ion-icon class="md" name="trash" role="img" aria-label="custom label">
|
||||
<mock:shadow-root>
|
||||
<div class="icon-inner"></div>
|
||||
</mock:shadow-root>
|
||||
</ion-icon>
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
<!doctype html>
|
||||
<html dir="ltr" lang="en" mode="ios">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
|
||||
<title>Icon Tests</title>
|
||||
<script type="module" src="/build/ionicons.esm.js"></script>
|
||||
<script nomodule src="/build/ionicons.js"></script>
|
||||
<link rel="stylesheet" href="./icon/test/styles.css" />
|
||||
<script src="./icon/test/header.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<h1>Icon Tests</h1>
|
||||
<p>Select a test category to view the icon component tests.</p>
|
||||
|
||||
<div class="grid">
|
||||
<a href="/icon/test/a11y/" class="card">
|
||||
<h3>Accessibility</h3>
|
||||
<p>ARIA labels and accessible icon patterns</p>
|
||||
</a>
|
||||
|
||||
<a href="/icon/test/basic/" class="card">
|
||||
<h3>Basic</h3>
|
||||
<p>Default SVG icons, modes, colors, sizes, and custom SVGs</p>
|
||||
</a>
|
||||
|
||||
<a href="/icon/test/cheatsheet/" class="card">
|
||||
<h3>Cheatsheet</h3>
|
||||
<p>Visual reference of all available ionicons</p>
|
||||
</a>
|
||||
|
||||
<a href="/icon/test/csp/" class="card">
|
||||
<h3>Content Security Policy</h3>
|
||||
<p>SVG content loading with Content Security Policy</p>
|
||||
</a>
|
||||
|
||||
<a href="/icon/test/dynamic-type/" class="card">
|
||||
<h3>Dynamic Type</h3>
|
||||
<p>Font size scaling and dynamic text sizing behavior</p>
|
||||
</a>
|
||||
|
||||
<a href="/icon/test/rtl/" class="card">
|
||||
<h3>RTL</h3>
|
||||
<p>Right-to-left text direction and icon flipping behavior</p>
|
||||
</a>
|
||||
|
||||
<a href="/icon/test/sanitization/" class="card">
|
||||
<h3>Sanitization</h3>
|
||||
<p>SVG content sanitization and security</p>
|
||||
</a>
|
||||
|
||||
<a href="/icon/test/size/" class="card">
|
||||
<h3>Size</h3>
|
||||
<p>Size prop with small and large variants for native and slotted icons</p>
|
||||
</a>
|
||||
|
||||
<a href="/icon/test/slotted/" class="card">
|
||||
<h3>Slotted Content</h3>
|
||||
<p>Font Awesome, Material, Phosphor, Bootstrap, and custom SVGs</p>
|
||||
</a>
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 34 KiB |
@@ -1,72 +0,0 @@
|
||||
<!doctype html>
|
||||
<html dir="ltr" lang="en" mode="ios">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
|
||||
<title>Icon - RTL</title>
|
||||
<script type="module" src="/build/ionicons.esm.js"></script>
|
||||
<script nomodule src="/build/ionicons.js"></script>
|
||||
<link rel="stylesheet" href="../styles.css" />
|
||||
<script src="../header.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<test-header></test-header>
|
||||
|
||||
<main>
|
||||
<h1>Icon - 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>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>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>
|
||||
<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>
|
||||
<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>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
ion-icon {
|
||||
font-size: 32px;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,284 +0,0 @@
|
||||
import { expect } from '@playwright/test';
|
||||
import type { E2EPage } from '@utils/test/playwright';
|
||||
import { test } from '@utils/test/playwright';
|
||||
|
||||
/**
|
||||
* An SVG whose handler pushes `label` to `window.xssFired` if it ever runs.
|
||||
*/
|
||||
const imageOnErrorSvg = (label: string) =>
|
||||
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><image href="x" onerror="window.xssFired.push('${label}')"/></svg>`;
|
||||
|
||||
const utf8DataUrl = (svg: string) => `data:image/svg+xml;utf8,${svg}`;
|
||||
|
||||
/**
|
||||
* Sets `sanitize` before `src` so the icon loads with the intended setting.
|
||||
*/
|
||||
const addIcon = (page: E2EPage, id: string, src: string, sanitize?: boolean) =>
|
||||
page.evaluate(
|
||||
([id, src, sanitize]) => {
|
||||
const icon = document.createElement('ion-icon') as any;
|
||||
icon.id = id;
|
||||
if (sanitize !== undefined) {
|
||||
icon.sanitize = sanitize;
|
||||
}
|
||||
icon.src = src;
|
||||
document.body.appendChild(icon);
|
||||
},
|
||||
[id, src, sanitize] as const,
|
||||
);
|
||||
|
||||
/**
|
||||
* Waits for the unsanitized control icon's handler to fire. Any `data:` URL
|
||||
* payload added before it has had at least as long to fire.
|
||||
*/
|
||||
const waitForControl = (page: E2EPage) => page.waitForFunction(() => (window as any).xssFired.includes('control'));
|
||||
|
||||
const getFired = (page: E2EPage) => page.evaluate(() => (window as any).xssFired as string[]);
|
||||
|
||||
test.describe('icon: sanitization', () => {
|
||||
test('should not have visual regressions', async ({ page }) => {
|
||||
await page.goto(`/icon/test/sanitization/`);
|
||||
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const main = page.locator('main');
|
||||
await expect(main).toHaveScreenshot(`icon-sanitization.png`);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe('icon: sanitization: unsafe content', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.setContent(`<script>window.xssFired = [];</script>`);
|
||||
});
|
||||
|
||||
test('should not run handlers from a utf8 svg data url', async ({ page }) => {
|
||||
await addIcon(page, 'attack', utf8DataUrl(imageOnErrorSvg('attack')));
|
||||
await addIcon(page, 'control', utf8DataUrl(imageOnErrorSvg('control')), false);
|
||||
await waitForControl(page);
|
||||
|
||||
expect(await getFired(page)).not.toContain('attack');
|
||||
await expect(page.locator('#attack .icon-inner svg')).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('should render a clean utf8 svg data url', async ({ page }) => {
|
||||
const clean = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/></svg>`;
|
||||
await addIcon(page, 'clean', utf8DataUrl(clean));
|
||||
|
||||
await expect(page.locator('#clean .icon-inner svg path')).toHaveCount(1);
|
||||
});
|
||||
|
||||
test('should warn when an svg is rejected', async ({ page }) => {
|
||||
const warnings: string[] = [];
|
||||
page.on('console', (msg) => {
|
||||
if (msg.type() === 'warning') {
|
||||
warnings.push(msg.text());
|
||||
}
|
||||
});
|
||||
|
||||
await addIcon(page, 'attack', utf8DataUrl(imageOnErrorSvg('attack')));
|
||||
|
||||
await expect.poll(() => warnings.some((warning) => warning.includes('[Ionicons Warning]'))).toBe(true);
|
||||
});
|
||||
|
||||
test('should not warn about sanitizing when the response is not an svg', async ({ page }) => {
|
||||
const warnings: string[] = [];
|
||||
page.on('console', (msg) => {
|
||||
if (msg.type() === 'warning') {
|
||||
warnings.push(msg.text());
|
||||
}
|
||||
});
|
||||
await page.route('**/missing.svg', (route) =>
|
||||
route.fulfill({ status: 404, contentType: 'text/html', body: '<html><body>Not found</body></html>' }),
|
||||
);
|
||||
await page.route('**/rejected.svg', (route) =>
|
||||
route.fulfill({ contentType: 'image/svg+xml', body: imageOnErrorSvg('attack') }),
|
||||
);
|
||||
|
||||
const missingLoaded = page.waitForResponse('**/missing.svg');
|
||||
await addIcon(page, 'missing', '/missing.svg');
|
||||
await missingLoaded;
|
||||
// This takes the same fetch and sanitize steps, so once it warns the 404 has been handled
|
||||
await addIcon(page, 'rejected', '/rejected.svg');
|
||||
await expect.poll(() => warnings.some((warning) => warning.includes('rejected.svg'))).toBe(true);
|
||||
|
||||
expect(warnings.filter((warning) => warning.includes('missing.svg'))).toHaveLength(0);
|
||||
});
|
||||
|
||||
test('should not run handlers from a fetched svg while sanitizing it', async ({ page }) => {
|
||||
await page.route('**/xss/*.svg', (route) => {
|
||||
const label = route.request().url().includes('control') ? 'control' : 'attack';
|
||||
route.fulfill({
|
||||
contentType: 'image/svg+xml',
|
||||
body: `<img src="x" onerror="window.xssFired.push('${label}')">${imageOnErrorSvg(label)}`,
|
||||
});
|
||||
});
|
||||
|
||||
// Fetches resolve independently, so let the attack load before the control starts
|
||||
const attackLoaded = page.waitForResponse('**/xss/attack.svg');
|
||||
await addIcon(page, 'attack', '/xss/attack.svg');
|
||||
await attackLoaded;
|
||||
await addIcon(page, 'control', '/xss/control.svg', false);
|
||||
await waitForControl(page);
|
||||
|
||||
expect(await getFired(page)).not.toContain('attack');
|
||||
await expect(page.locator('#attack .icon-inner svg')).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('should reject a fetched svg with more than one root svg', async ({ page }) => {
|
||||
await page.route('**/xss/*.svg', (route) => {
|
||||
const label = route.request().url().includes('control') ? 'control' : 'attack';
|
||||
route.fulfill({
|
||||
contentType: 'image/svg+xml',
|
||||
body: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/></svg>${imageOnErrorSvg(label)}`,
|
||||
});
|
||||
});
|
||||
|
||||
const attackLoaded = page.waitForResponse('**/xss/attack.svg');
|
||||
await addIcon(page, 'attack', '/xss/attack.svg');
|
||||
await attackLoaded;
|
||||
await addIcon(page, 'control', '/xss/control.svg', false);
|
||||
await waitForControl(page);
|
||||
|
||||
expect(await getFired(page)).not.toContain('attack');
|
||||
await expect(page.locator('#attack .icon-inner svg')).toHaveCount(0);
|
||||
});
|
||||
|
||||
const htmlInSvgPayloads = [
|
||||
{
|
||||
name: 'noscript',
|
||||
inner: `<desc><noscript><p title="</noscript><img src=x onerror=top.xssFired.push('attack')>"></p></noscript></desc>`,
|
||||
},
|
||||
{
|
||||
name: 'template',
|
||||
inner: `<desc><template><img src="x" onerror="top.xssFired.push('attack')"></template></desc>`,
|
||||
},
|
||||
];
|
||||
|
||||
htmlInSvgPayloads.forEach(({ name, inner }) => {
|
||||
test(`should reject an svg containing an html ${name} element`, async ({ page }) => {
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">${inner}<path d="M0 0h24v24H0z"/></svg>`;
|
||||
await addIcon(page, 'attack', utf8DataUrl(svg));
|
||||
await addIcon(page, 'control', utf8DataUrl(imageOnErrorSvg('control')), false);
|
||||
await waitForControl(page);
|
||||
|
||||
expect(await getFired(page)).not.toContain('attack');
|
||||
await expect(page.locator('#attack .icon-inner svg')).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
const foreignObjectPayloads = [
|
||||
{
|
||||
name: 'iframe srcdoc',
|
||||
inner: `<iframe xmlns="http://www.w3.org/1999/xhtml" srcdoc="<script>top.xssFired.push('attack')</script>"></iframe>`,
|
||||
},
|
||||
{
|
||||
name: 'iframe javascript: src',
|
||||
inner: `<iframe xmlns="http://www.w3.org/1999/xhtml" src="javascript:top.xssFired.push('attack')"></iframe>`,
|
||||
},
|
||||
];
|
||||
|
||||
foreignObjectPayloads.forEach(({ name, inner }) => {
|
||||
test(`should remove a foreignObject containing an ${name}`, async ({ page }) => {
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><foreignObject width="24" height="24">${inner}</foreignObject><path d="M0 0h24v24H0z"/></svg>`;
|
||||
await addIcon(page, 'attack', utf8DataUrl(svg));
|
||||
await addIcon(page, 'control', utf8DataUrl(imageOnErrorSvg('control')), false);
|
||||
await waitForControl(page);
|
||||
|
||||
expect(await getFired(page)).not.toContain('attack');
|
||||
await expect(page.locator('#attack .icon-inner svg path')).toHaveCount(1);
|
||||
await expect(page.locator('#attack .icon-inner svg > :not(path)')).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
test('should render an illustrator export that uses a switch with a foreignObject', async ({ page }) => {
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:i="http://ns.adobe.com/AdobeIllustrator/10.0/" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 24 24"><switch><foreignObject requiredExtensions="http://ns.adobe.com/AdobeIllustrator/10.0/" x="0" y="0" width="1" height="1"><i:pgfRef xlink:href="#adobe_illustrator_pgf"></i:pgfRef></foreignObject><g i:extraneous="self"><path d="M0 0h24v24H0z"/></g></switch></svg>`;
|
||||
await addIcon(page, 'illustrator', utf8DataUrl(svg));
|
||||
|
||||
await expect(page.locator('#illustrator .icon-inner svg path')).toHaveCount(1);
|
||||
});
|
||||
|
||||
const javascriptUrlPayloads = [
|
||||
{ name: 'an anchor href', inner: `<a href="javascript:top.xssFired.push('attack')"><path d="M0 0h24v24H0z"/></a>` },
|
||||
{
|
||||
name: 'an obfuscated xlink:href',
|
||||
inner: `<a xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href=" JaVa	ScRiPt:top.xssFired.push('attack')"><path d="M0 0h24v24H0z"/></a>`,
|
||||
},
|
||||
{
|
||||
name: 'an animate element',
|
||||
inner: `<a><animate attributeName="href" values="https://ionic.io;javascript:top.xssFired.push('attack')"/><path d="M0 0h24v24H0z"/></a>`,
|
||||
},
|
||||
{
|
||||
name: 'a set element',
|
||||
inner: `<a><set attributeName="href" to="javascript:top.xssFired.push('attack')"/><path d="M0 0h24v24H0z"/></a>`,
|
||||
},
|
||||
];
|
||||
|
||||
javascriptUrlPayloads.forEach(({ name, inner }) => {
|
||||
test(`should reject an svg with a javascript: url in ${name}`, async ({ page }) => {
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">${inner}</svg>`;
|
||||
await addIcon(page, 'attack', utf8DataUrl(svg));
|
||||
await addIcon(page, 'control', utf8DataUrl(imageOnErrorSvg('control')), false);
|
||||
await waitForControl(page);
|
||||
|
||||
await expect(page.locator('#attack .icon-inner svg')).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
test('should not reuse unsanitized content cached for the same data url', async ({ page }) => {
|
||||
const shared = utf8DataUrl(imageOnErrorSvg('shared'));
|
||||
|
||||
await addIcon(page, 'unsanitized', shared, false);
|
||||
await page.waitForFunction(() => (window as any).xssFired.includes('shared'));
|
||||
|
||||
await addIcon(page, 'sanitized', shared);
|
||||
await addIcon(page, 'control', utf8DataUrl(imageOnErrorSvg('control')), false);
|
||||
await waitForControl(page);
|
||||
|
||||
await expect(page.locator('#sanitized .icon-inner svg')).toHaveCount(0);
|
||||
expect((await getFired(page)).filter((label) => label === 'shared')).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('should not reuse sanitized content cached for the same data url', async ({ page }) => {
|
||||
const shared = utf8DataUrl(imageOnErrorSvg('shared'));
|
||||
|
||||
await addIcon(page, 'sanitized', shared);
|
||||
await addIcon(page, 'unsanitized', shared, false);
|
||||
|
||||
await expect(page.locator('#unsanitized .icon-inner svg')).toHaveCount(1);
|
||||
});
|
||||
|
||||
test('should not let a src forge the unsanitized cache key', async ({ page }) => {
|
||||
const shared = utf8DataUrl(imageOnErrorSvg('shared'));
|
||||
|
||||
await addIcon(page, 'unsanitized', shared, false);
|
||||
await page.waitForFunction(() => (window as any).xssFired.includes('shared'));
|
||||
|
||||
await addIcon(page, 'sanitized', `unsanitized:${shared}`);
|
||||
await addIcon(page, 'control', utf8DataUrl(imageOnErrorSvg('control')), false);
|
||||
await waitForControl(page);
|
||||
|
||||
await expect(page.locator('#sanitized .icon-inner svg')).toHaveCount(0);
|
||||
expect((await getFired(page)).filter((label) => label === 'shared')).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('should not reuse an unsanitized in-flight fetch for the same url', async ({ page }) => {
|
||||
await page.route('**/xss/*.svg', (route) => {
|
||||
const label = route.request().url().includes('control') ? 'control' : 'shared';
|
||||
// Sanitizing drops the <img> sibling and keeps the clean <svg>
|
||||
route.fulfill({
|
||||
contentType: 'image/svg+xml',
|
||||
body: `<img src="x" onerror="window.xssFired.push('${label}')"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0z"/></svg>`,
|
||||
});
|
||||
});
|
||||
|
||||
await addIcon(page, 'unsanitized', '/xss/shared.svg', false);
|
||||
await addIcon(page, 'sanitized', '/xss/shared.svg');
|
||||
await addIcon(page, 'control', '/xss/control.svg', false);
|
||||
await waitForControl(page);
|
||||
await page.waitForFunction(() => (window as any).xssFired.includes('shared'));
|
||||
|
||||
await expect(page.locator('#sanitized .icon-inner svg path')).toHaveCount(1);
|
||||
await expect(page.locator('#sanitized .icon-inner img')).toHaveCount(0);
|
||||
expect((await getFired(page)).filter((label) => label === 'shared')).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 19 KiB |
@@ -1,37 +0,0 @@
|
||||
<!doctype html>
|
||||
<html dir="ltr" lang="en" mode="ios">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
|
||||
<title>Icon - Sanitization</title>
|
||||
<script type="module" src="/build/ionicons.esm.js"></script>
|
||||
<script nomodule src="/build/ionicons.js"></script>
|
||||
<link rel="stylesheet" href="../styles.css" />
|
||||
<script src="../header.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<test-header></test-header>
|
||||
|
||||
<main>
|
||||
<h1>Icon - Sanitization</h1>
|
||||
|
||||
<h2>Sanitized (shouldn't show)</h2>
|
||||
<ion-icon src="/icon/assets/sanitize.svg"></ion-icon>
|
||||
|
||||
<h2>Not Sanitized (should show)</h2>
|
||||
<ion-icon sanitize="false" src="/icon/assets/no-sanitize.svg"></ion-icon>
|
||||
|
||||
<h2>Base64 URL</h2>
|
||||
<ion-icon
|
||||
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSJub25lIiBkPSJNMCAwaDI0djI0SDBWMHoiLz48cGF0aCBkPSJNMjAgMkg0Yy0xLjEgMC0yIC45LTIgMnYxOGw0LTRoMTRjMS4xIDAgMi0uOSAyLTJWNGMwLTEuMS0uOS0yLTItMnptMCAxNEg2bC0yIDJWNGgxNnYxMnoiLz48L3N2Zz4="
|
||||
></ion-icon>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
ion-icon {
|
||||
font-size: 32px;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,40 +0,0 @@
|
||||
import { expect } from '@playwright/test';
|
||||
import { test } from '@utils/test/playwright';
|
||||
|
||||
test.describe('icon: size', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto(`/icon/test/size/`);
|
||||
});
|
||||
|
||||
test('should scale the icon based on the size property', async ({ page }) => {
|
||||
// Wait for all SVGs to be lazily loaded before taking screenshots
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const main = page.locator('main');
|
||||
await expect(main).toHaveScreenshot(`icon-size.png`);
|
||||
});
|
||||
|
||||
test('size prop should apply correct font-size to SVG icons', async ({ page }) => {
|
||||
// Wait for all SVGs to be lazily loaded
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const icons = page.locator('ion-icon[name="heart"]');
|
||||
|
||||
// Default size is 16px, small is 18px, large is 32px
|
||||
expect(await icons.nth(0).evaluate((el) => window.getComputedStyle(el).fontSize)).toBe('16px');
|
||||
expect(await icons.nth(1).evaluate((el) => window.getComputedStyle(el).fontSize)).toBe('18px');
|
||||
expect(await icons.nth(2).evaluate((el) => window.getComputedStyle(el).fontSize)).toBe('32px');
|
||||
});
|
||||
|
||||
test('size prop should apply correct font-size to font icons', async ({ page }) => {
|
||||
// Wait for document fonts to be ready
|
||||
await page.evaluate(() => document.fonts.ready);
|
||||
|
||||
const icons = page.locator('ion-icon:not([name])');
|
||||
|
||||
// Default size is 16px, small is 18px, large is 32px
|
||||
expect(await icons.nth(0).evaluate((el) => window.getComputedStyle(el).fontSize)).toBe('16px');
|
||||
expect(await icons.nth(1).evaluate((el) => window.getComputedStyle(el).fontSize)).toBe('18px');
|
||||
expect(await icons.nth(2).evaluate((el) => window.getComputedStyle(el).fontSize)).toBe('32px');
|
||||
});
|
||||
});
|
||||
|
Before Width: | Height: | Size: 9.2 KiB |
|
Before Width: | Height: | Size: 10 KiB |
|
Before Width: | Height: | Size: 11 KiB |
@@ -1,39 +0,0 @@
|
||||
<!doctype html>
|
||||
<html dir="ltr" lang="en" mode="ios">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
|
||||
<title>Icon - Size</title>
|
||||
<script type="module" src="/build/ionicons.esm.js"></script>
|
||||
<script nomodule src="/build/ionicons.js"></script>
|
||||
<link rel="stylesheet" href="../styles.css" />
|
||||
<script src="../header.js"></script>
|
||||
|
||||
<!-- Font Awesome Icons -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<test-header></test-header>
|
||||
|
||||
<main>
|
||||
<h1>Icon - Size</h1>
|
||||
|
||||
<h2>Default Icons</h2>
|
||||
<ion-icon name="heart"></ion-icon>
|
||||
<ion-icon name="heart" size="small"></ion-icon>
|
||||
<ion-icon name="heart" size="large"></ion-icon>
|
||||
|
||||
<h2>Font Icons</h2>
|
||||
<ion-icon>
|
||||
<i class="fa fa-heart"></i>
|
||||
</ion-icon>
|
||||
<ion-icon size="small">
|
||||
<i class="fa fa-heart"></i>
|
||||
</ion-icon>
|
||||
<ion-icon size="large">
|
||||
<i class="fa fa-heart"></i>
|
||||
</ion-icon>
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,13 +0,0 @@
|
||||
import { expect } from '@playwright/test';
|
||||
import { test } from '@utils/test/playwright';
|
||||
|
||||
test.describe('icon: slotted', () => {
|
||||
test('should not have visual regressions', async ({ page }) => {
|
||||
await page.goto(`/icon/test/slotted/`);
|
||||
|
||||
// Wait for all SVGs to be lazily loaded before taking screenshots
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
await expect(page).toHaveScreenshot(`icon-slotted.png`, { fullPage: true });
|
||||
});
|
||||
});
|
||||
|
Before Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 68 KiB |
@@ -1,310 +0,0 @@
|
||||
<!doctype html>
|
||||
<html dir="ltr" lang="en" mode="ios">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
|
||||
<title>Icon - Slotted Content</title>
|
||||
<script type="module" src="/build/ionicons.esm.js"></script>
|
||||
<script nomodule src="/build/ionicons.js"></script>
|
||||
<link rel="stylesheet" href="../styles.css" />
|
||||
<script src="../header.js"></script>
|
||||
|
||||
<!-- Font Awesome Icons -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css" />
|
||||
<!-- Material Icons -->
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
|
||||
<!-- Phosphor Icons -->
|
||||
<link
|
||||
rel="stylesheet"
|
||||
type="text/css"
|
||||
href="https://cdn.jsdelivr.net/npm/@phosphor-icons/web@2.1.1/src/fill/style.css"
|
||||
/>
|
||||
<!-- Bootstrap Icons -->
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<test-header></test-header>
|
||||
|
||||
<main>
|
||||
<h1>Icon - Slotted Content</h1>
|
||||
|
||||
<div class="grid">
|
||||
<div class="grid-item">
|
||||
<h2>Material Icons</h2>
|
||||
<ion-icon>
|
||||
<span class="material-icons">home</span>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<span class="material-icons">favorite</span>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<span class="material-icons">star</span>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<span class="material-icons">person</span>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<span class="material-icons">settings</span>
|
||||
</ion-icon>
|
||||
|
||||
<br />
|
||||
|
||||
<ion-icon color="primary">
|
||||
<span class="material-icons">home</span>
|
||||
</ion-icon>
|
||||
<ion-icon color="secondary">
|
||||
<span class="material-icons">favorite</span>
|
||||
</ion-icon>
|
||||
<ion-icon color="success">
|
||||
<span class="material-icons">star</span>
|
||||
</ion-icon>
|
||||
<ion-icon color="warning">
|
||||
<span class="material-icons">warning</span>
|
||||
</ion-icon>
|
||||
<ion-icon color="danger">
|
||||
<span class="material-icons">delete</span>
|
||||
</ion-icon>
|
||||
|
||||
<br />
|
||||
|
||||
<ion-icon style="font-size: 24px">
|
||||
<span class="material-icons">home</span>
|
||||
</ion-icon>
|
||||
<ion-icon style="font-size: 36px">
|
||||
<span class="material-icons">favorite</span>
|
||||
</ion-icon>
|
||||
<ion-icon style="font-size: 48px">
|
||||
<span class="material-icons">star</span>
|
||||
</ion-icon>
|
||||
</div>
|
||||
|
||||
<div class="grid-item">
|
||||
<h2>Phosphor Icons</h2>
|
||||
<ion-icon>
|
||||
<i class="ph-fill ph-house"></i>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<i class="ph-fill ph-heart"></i>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<i class="ph-fill ph-star"></i>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<i class="ph-fill ph-user"></i>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<i class="ph-fill ph-gear"></i>
|
||||
</ion-icon>
|
||||
|
||||
<br />
|
||||
|
||||
<ion-icon color="primary">
|
||||
<i class="ph-fill ph-house"></i>
|
||||
</ion-icon>
|
||||
<ion-icon color="secondary">
|
||||
<i class="ph-fill ph-heart"></i>
|
||||
</ion-icon>
|
||||
<ion-icon color="success">
|
||||
<i class="ph-fill ph-star"></i>
|
||||
</ion-icon>
|
||||
<ion-icon color="warning">
|
||||
<i class="ph-fill ph-warning"></i>
|
||||
</ion-icon>
|
||||
<ion-icon color="danger">
|
||||
<i class="ph-fill ph-trash"></i>
|
||||
</ion-icon>
|
||||
|
||||
<br />
|
||||
|
||||
<ion-icon style="font-size: 24px">
|
||||
<i class="ph-fill ph-house"></i>
|
||||
</ion-icon>
|
||||
<ion-icon style="font-size: 36px">
|
||||
<i class="ph-fill ph-heart"></i>
|
||||
</ion-icon>
|
||||
<ion-icon style="font-size: 48px">
|
||||
<i class="ph-fill ph-star"></i>
|
||||
</ion-icon>
|
||||
</div>
|
||||
|
||||
<div class="grid-item">
|
||||
<h2>Font Awesome Icons</h2>
|
||||
<ion-icon>
|
||||
<i class="fa fa-home"></i>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<i class="fa fa-heart"></i>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<i class="fa fa-star"></i>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<i class="fa fa-user"></i>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<i class="fa fa-cog"></i>
|
||||
</ion-icon>
|
||||
|
||||
<br />
|
||||
|
||||
<ion-icon color="primary">
|
||||
<i class="fa fa-home"></i>
|
||||
</ion-icon>
|
||||
<ion-icon color="secondary">
|
||||
<i class="fa fa-heart"></i>
|
||||
</ion-icon>
|
||||
<ion-icon color="success">
|
||||
<i class="fa fa-star"></i>
|
||||
</ion-icon>
|
||||
<ion-icon color="warning">
|
||||
<i class="fa fa-exclamation-triangle"></i>
|
||||
</ion-icon>
|
||||
<ion-icon color="danger">
|
||||
<i class="fa fa-trash"></i>
|
||||
</ion-icon>
|
||||
|
||||
<br />
|
||||
|
||||
<ion-icon style="font-size: 24px">
|
||||
<i class="fa fa-home"></i>
|
||||
</ion-icon>
|
||||
<ion-icon style="font-size: 36px">
|
||||
<i class="fa fa-heart"></i>
|
||||
</ion-icon>
|
||||
<ion-icon style="font-size: 48px">
|
||||
<i class="fa fa-star"></i>
|
||||
</ion-icon>
|
||||
</div>
|
||||
|
||||
<div class="grid-item">
|
||||
<h2>Bootstrap Icons</h2>
|
||||
<ion-icon>
|
||||
<i class="bi bi-house-fill"></i>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<i class="bi bi-heart-fill"></i>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<i class="bi bi-star-fill"></i>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<i class="bi bi-person-fill"></i>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<i class="bi bi-gear-fill"></i>
|
||||
</ion-icon>
|
||||
|
||||
<br />
|
||||
|
||||
<ion-icon color="primary">
|
||||
<i class="bi bi-house-fill"></i>
|
||||
</ion-icon>
|
||||
<ion-icon color="secondary">
|
||||
<i class="bi bi-heart-fill"></i>
|
||||
</ion-icon>
|
||||
<ion-icon color="success">
|
||||
<i class="bi bi-star-fill"></i>
|
||||
</ion-icon>
|
||||
<ion-icon color="warning">
|
||||
<i class="bi bi-exclamation-triangle-fill"></i>
|
||||
</ion-icon>
|
||||
<ion-icon color="danger">
|
||||
<i class="bi bi-trash-fill"></i>
|
||||
</ion-icon>
|
||||
|
||||
<br />
|
||||
|
||||
<ion-icon style="font-size: 24px">
|
||||
<i class="bi bi-house-fill"></i>
|
||||
</ion-icon>
|
||||
<ion-icon style="font-size: 36px">
|
||||
<i class="bi bi-heart-fill"></i>
|
||||
</ion-icon>
|
||||
<ion-icon style="font-size: 48px">
|
||||
<i class="bi bi-star-fill"></i>
|
||||
</ion-icon>
|
||||
</div>
|
||||
|
||||
<div class="grid-item">
|
||||
<h2>Custom Slotted SVG</h2>
|
||||
<ion-icon>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path
|
||||
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm3.5-9c.83 0 1.5-.67 1.5-1.5S16.33 8 15.5 8 14 8.67 14 9.5s.67 1.5 1.5 1.5zm-7 0c.83 0 1.5-.67 1.5-1.5S9.33 8 8.5 8 7 8.67 7 9.5 7.67 11 8.5 11zm3.5 6.5c2.33 0 4.31-1.46 5.11-3.5H6.89c.8 2.04 2.78 3.5 5.11 3.5z"
|
||||
/>
|
||||
</svg>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path
|
||||
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
|
||||
/>
|
||||
</svg>
|
||||
</ion-icon>
|
||||
<ion-icon>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path
|
||||
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"
|
||||
/>
|
||||
</svg>
|
||||
</ion-icon>
|
||||
|
||||
<br />
|
||||
|
||||
<ion-icon color="primary">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path
|
||||
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm3.5-9c.83 0 1.5-.67 1.5-1.5S16.33 8 15.5 8 14 8.67 14 9.5s.67 1.5 1.5 1.5zm-7 0c.83 0 1.5-.67 1.5-1.5S9.33 8 8.5 8 7 8.67 7 9.5 7.67 11 8.5 11zm3.5 6.5c2.33 0 4.31-1.46 5.11-3.5H6.89c.8 2.04 2.78 3.5 5.11 3.5z"
|
||||
/>
|
||||
</svg>
|
||||
</ion-icon>
|
||||
<ion-icon color="success">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path
|
||||
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
|
||||
/>
|
||||
</svg>
|
||||
</ion-icon>
|
||||
<ion-icon color="danger">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path
|
||||
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"
|
||||
/>
|
||||
</svg>
|
||||
</ion-icon>
|
||||
|
||||
<br />
|
||||
|
||||
<ion-icon style="font-size: 24px">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path
|
||||
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8zm3.5-9c.83 0 1.5-.67 1.5-1.5S16.33 8 15.5 8 14 8.67 14 9.5s.67 1.5 1.5 1.5zm-7 0c.83 0 1.5-.67 1.5-1.5S9.33 8 8.5 8 7 8.67 7 9.5 7.67 11 8.5 11zm3.5 6.5c2.33 0 4.31-1.46 5.11-3.5H6.89c.8 2.04 2.78 3.5 5.11 3.5z"
|
||||
/>
|
||||
</svg>
|
||||
</ion-icon>
|
||||
<ion-icon style="font-size: 36px">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path
|
||||
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
|
||||
/>
|
||||
</svg>
|
||||
</ion-icon>
|
||||
<ion-icon style="font-size: 48px">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">
|
||||
<path
|
||||
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-2h2v2zm0-4h-2V7h2v6z"
|
||||
/>
|
||||
</svg>
|
||||
</ion-icon>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
ion-icon {
|
||||
font-size: 32px;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,107 +0,0 @@
|
||||
:root {
|
||||
--color-primary: #0054e9;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
font-size: 16px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
main {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-bottom: 10px;
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 20px 0 10px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
h3 {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
p {
|
||||
margin-bottom: 10px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
min-height: 54px;
|
||||
padding: 0 20px;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
background: #ffffff;
|
||||
}
|
||||
|
||||
.card {
|
||||
min-height: 150px;
|
||||
padding: 20px;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 8px;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
transition: all 0.2s;
|
||||
}
|
||||
|
||||
.card:hover {
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.card h3 {
|
||||
margin: 0 0 8px;
|
||||
font-size: 18px;
|
||||
color: var(--color-primary);
|
||||
}
|
||||
|
||||
.card p {
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.back-button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
text-decoration: none;
|
||||
color: var(--color-primary);
|
||||
font-size: 18px;
|
||||
font-weight: 500;
|
||||
transition: opacity 0.2s;
|
||||
}
|
||||
|
||||
.back-button ion-icon {
|
||||
font-size: inherit;
|
||||
}
|
||||
|
||||
.back-button:hover {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||
gap: 16px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.grid-item {
|
||||
padding: 16px;
|
||||
border: 1px solid #e0e0e0;
|
||||
border-radius: 4px;
|
||||
background: #ffffff;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Icon } from '../icon';
|
||||
import { addIcons, getIconMap, getName, getSrc, getUrl } from '../utils';
|
||||
|
||||
|
||||
describe('getUrl', () => {
|
||||
let i: Icon;
|
||||
|
||||
@@ -8,11 +9,7 @@ describe('getUrl', () => {
|
||||
i = new Icon();
|
||||
});
|
||||
|
||||
/**
|
||||
* Started to fail after upgrading to new jest-stencil-runner
|
||||
* @ToDo(@christian-bromann): investigate why this is failing
|
||||
*/
|
||||
it.skip('use icon prop, as name', () => {
|
||||
it('use icon prop, as name', () => {
|
||||
i.icon = 'some-name';
|
||||
expect(getUrl(i)).toBe('/svg/some-name.svg');
|
||||
});
|
||||
@@ -22,11 +19,7 @@ describe('getUrl', () => {
|
||||
expect(getUrl(i)).toBe('./some.svg');
|
||||
});
|
||||
|
||||
/**
|
||||
* Started to fail after upgrading to new jest-stencil-runner
|
||||
* @ToDo(@christian-bromann): investigate why this is failing
|
||||
*/
|
||||
it.skip('use name prop', () => {
|
||||
it('use name prop', () => {
|
||||
i.name = 'some-name';
|
||||
expect(getUrl(i)).toBe('/svg/some-name.svg');
|
||||
});
|
||||
@@ -37,9 +30,12 @@ describe('getUrl', () => {
|
||||
i.icon = 'some-icon';
|
||||
expect(getUrl(i)).toBe('./some.svg');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('getSrc', () => {
|
||||
|
||||
it('both . and /', () => {
|
||||
expect(getSrc('./somefile.svg')).toBe('./somefile.svg');
|
||||
});
|
||||
@@ -59,9 +55,12 @@ describe('getSrc', () => {
|
||||
it('no . or /', () => {
|
||||
expect(getSrc('some-name')).toBe(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('getName', () => {
|
||||
|
||||
it('not allow special chars', () => {
|
||||
expect(getName('some\\name', '', 'io', '', '')).toBe(null);
|
||||
expect(getName('some$name', '', 'io', '', '')).toBe(null);
|
||||
@@ -81,6 +80,7 @@ describe('getName', () => {
|
||||
it('should not use name if no name, ios or md', () => {
|
||||
expect(getName(undefined, undefined, '', '', '')).toBe(null);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('addIcons', () => {
|
||||
@@ -105,7 +105,7 @@ describe('addIcons', () => {
|
||||
expect(getIconMap().get('logo-ionitron')).toEqual(logoIonitron);
|
||||
expect(getIconMap().get('logoIonitron')).toEqual(logoIonitron);
|
||||
|
||||
const logoIonitron0 = 'stubbed data 0';
|
||||
const logoIonitron0 = 'stubbed data 0'
|
||||
|
||||
expect(getIconMap().get('logo-ionitron-0')).toEqual(undefined);
|
||||
expect(getIconMap().get('logoIonitron0')).toEqual(undefined);
|
||||
@@ -131,7 +131,7 @@ describe('addIcons', () => {
|
||||
|
||||
expect(getIconMap().get('myCoolIcon')).toEqual(undefined);
|
||||
|
||||
addIcons({ myCoolIcon: logoIonitron });
|
||||
addIcons({ 'myCoolIcon': logoIonitron });
|
||||
|
||||
expect(getIconMap().get('myCoolIcon')).toEqual(logoIonitron);
|
||||
});
|
||||
@@ -169,4 +169,5 @@ describe('addIcons', () => {
|
||||
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -1,121 +1,61 @@
|
||||
import { readFileSync, readdirSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { isEncodedDataUrl, isSvgDataUrl, isValid } from '../validate';
|
||||
|
||||
import { isEncodedDataUrl, isSvgDataUrl, isValid, validateContent } from '../validate';
|
||||
|
||||
const SVG_NS = 'http://www.w3.org/2000/svg';
|
||||
|
||||
const elm = (nodeName: string, attributes: { name: string; value?: string }[] = [], childNodes: any[] = []) =>
|
||||
({ nodeType: 1, namespaceURI: SVG_NS, nodeName, attributes, childNodes }) as any;
|
||||
|
||||
describe('isValid', () => {
|
||||
|
||||
it('invalid onload attr', () => {
|
||||
expect(isValid(elm('svg', [{ name: 'onload' }]))).toBe(false);
|
||||
const el = {
|
||||
nodeType: 1,
|
||||
nodeName: 'svg',
|
||||
attributes: [{ name: 'onload' }],
|
||||
childNodes: []
|
||||
} as any;
|
||||
expect(isValid(el)).toBe(false);
|
||||
});
|
||||
|
||||
it('invalid onclick attr', () => {
|
||||
expect(isValid(elm('svg', [{ name: 'OnClIcK' }]))).toBe(false);
|
||||
const el = {
|
||||
nodeType: 1,
|
||||
nodeName: 'svg',
|
||||
attributes: [{ name: 'OnClIcK' }],
|
||||
childNodes: []
|
||||
} as any;
|
||||
expect(isValid(el)).toBe(false);
|
||||
});
|
||||
|
||||
it('invalid child SCRIPT elm', () => {
|
||||
expect(isValid(elm('svg', [], [elm('SCRIPT')]))).toBe(false);
|
||||
const el = {
|
||||
nodeType: 1, nodeName: 'svg', attributes: [], childNodes: [
|
||||
{ nodeType: 1, nodeName: 'SCRIPT', attributes: [], childNodes: [] }
|
||||
]
|
||||
} as any;
|
||||
expect(isValid(el)).toBe(false);
|
||||
});
|
||||
|
||||
it('invalid script elm', () => {
|
||||
expect(isValid(elm('script'))).toBe(false);
|
||||
});
|
||||
|
||||
it('invalid foreignObject elm', () => {
|
||||
expect(isValid(elm('svg', [], [elm('foreignObject')]))).toBe(false);
|
||||
});
|
||||
|
||||
it.each(['iframe', 'embed', 'object'])('invalid %s elm', (name) => {
|
||||
expect(isValid(elm('svg', [], [elm(name)]))).toBe(false);
|
||||
});
|
||||
|
||||
it('invalid html namespace elm', () => {
|
||||
const noscript = { ...elm('noscript'), namespaceURI: 'http://www.w3.org/1999/xhtml' };
|
||||
expect(isValid(elm('svg', [], [elm('desc', [], [noscript])]))).toBe(false);
|
||||
});
|
||||
|
||||
it('invalid javascript: url', () => {
|
||||
expect(isValid(elm('a', [{ name: 'href', value: 'javascript:alert(1)' }]))).toBe(false);
|
||||
});
|
||||
|
||||
it('invalid obfuscated javascript: url', () => {
|
||||
expect(isValid(elm('a', [{ name: 'xlink:href', value: ' JaVa\tScRiPt:alert(1)' }]))).toBe(false);
|
||||
});
|
||||
|
||||
it('invalid javascript: url in a value list', () => {
|
||||
expect(isValid(elm('animate', [{ name: 'values', value: 'https://ionic.io;javascript:alert(1)' }]))).toBe(false);
|
||||
const el = { nodeType: 1, nodeName: 'script', attributes: [], childNodes: [] } as any;
|
||||
expect(isValid(el)).toBe(false);
|
||||
});
|
||||
|
||||
it('is valid circle elm', () => {
|
||||
expect(isValid(elm('circle'))).toBe(true);
|
||||
const el = { nodeType: 1, nodeName: 'circle', attributes: [], childNodes: [] } as any;
|
||||
expect(isValid(el)).toBe(true);
|
||||
});
|
||||
|
||||
it('is valid SVG elm', () => {
|
||||
expect(isValid(elm('SVG', [], [elm('line')]))).toBe(true);
|
||||
});
|
||||
|
||||
it('is valid href', () => {
|
||||
expect(isValid(elm('a', [{ name: 'href', value: 'https://ionic.io' }]))).toBe(true);
|
||||
const el = {
|
||||
nodeType: 1, nodeName: 'SVG', attributes: [], childNodes: [
|
||||
{ nodeType: 1, nodeName: 'line', attributes: [], childNodes: [] }
|
||||
]
|
||||
} as any;
|
||||
expect(isValid(el)).toBe(true);
|
||||
});
|
||||
|
||||
it('is valid text node', () => {
|
||||
const el = { nodeType: 3, nodeName: '#text' } as any;
|
||||
expect(isValid(el)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateContent', () => {
|
||||
it('removes foreignObject and keeps the artwork', () => {
|
||||
const onRejected = jest.fn();
|
||||
const result = validateContent(
|
||||
`<svg xmlns="${SVG_NS}"><switch><foreignObject><iframe></iframe></foreignObject><g><path d="M0 0"></path></g></switch></svg>`,
|
||||
onRejected,
|
||||
);
|
||||
expect(result).toContain('<path');
|
||||
expect(result).not.toContain('foreignObject');
|
||||
expect(onRejected).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('strips non-svg siblings', () => {
|
||||
const result = validateContent(
|
||||
`<img src="x" onerror="alert(1)"><svg xmlns="${SVG_NS}"><path d="M0 0"></path></svg>`,
|
||||
);
|
||||
expect(result).toContain('<path');
|
||||
expect(result).not.toContain('<img');
|
||||
});
|
||||
|
||||
it('rejects html inside desc and calls onRejected', () => {
|
||||
const onRejected = jest.fn();
|
||||
expect(validateContent(`<svg xmlns="${SVG_NS}"><desc><noscript><p></p></noscript></desc></svg>`, onRejected)).toBe(
|
||||
'',
|
||||
);
|
||||
expect(onRejected).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('rejects more than one root svg', () => {
|
||||
const onRejected = jest.fn();
|
||||
const svg = `<svg xmlns="${SVG_NS}"><path d="M0 0"></path></svg>`;
|
||||
expect(validateContent(svg + svg, onRejected)).toBe('');
|
||||
expect(onRejected).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('accepts every shipped icon', () => {
|
||||
const svgDir = join(__dirname, '../../../svg');
|
||||
const rejected = readdirSync(svgDir)
|
||||
.filter((file) => file.endsWith('.svg'))
|
||||
.filter((file) => !validateContent(readFileSync(join(svgDir, file), 'utf8')));
|
||||
expect(rejected).toEqual([]);
|
||||
});
|
||||
|
||||
it('does not call onRejected when there is no svg', () => {
|
||||
const onRejected = jest.fn();
|
||||
expect(validateContent('<html><body>Not found</body></html>', onRejected)).toBe('');
|
||||
expect(onRejected).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('isSvgDataUrl', () => {
|
||||
@@ -130,4 +70,4 @@ it('isEncodedDataUrl', () => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,7 @@
|
||||
import { getAssetPath } from '@stencil/core';
|
||||
import { Icon } from './icon';
|
||||
|
||||
|
||||
let CACHED_MAP: Map<string, string>;
|
||||
|
||||
export const getIconMap = (): Map<string, string> => {
|
||||
@@ -16,8 +17,8 @@ export const getIconMap = (): Map<string, string> => {
|
||||
}
|
||||
};
|
||||
|
||||
export const addIcons = (icons: { [name: string]: string }) => {
|
||||
Object.keys(icons).forEach((name) => {
|
||||
export const addIcons = (icons: { [name: string]: string; }) => {
|
||||
Object.keys(icons).forEach(name => {
|
||||
addToIconMap(name, icons[name]);
|
||||
|
||||
/**
|
||||
@@ -30,7 +31,7 @@ export const addIcons = (icons: { [name: string]: string }) => {
|
||||
* Using name="addCircleOutline" is valid too, but the
|
||||
* kebab case naming is preferred.
|
||||
*/
|
||||
const toKebabCase = name.replace(/([a-z0-9]|(?=[A-Z]))([A-Z0-9])/g, '$1-$2').toLowerCase();
|
||||
const toKebabCase = name.replace(/([a-z0-9]|(?=[A-Z]))([A-Z0-9])/g, "$1-$2").toLowerCase();
|
||||
if (name !== toKebabCase) {
|
||||
addToIconMap(toKebabCase, icons[name]);
|
||||
}
|
||||
@@ -45,16 +46,15 @@ const addToIconMap = (name: string, data: any) => {
|
||||
if (existingIcon === undefined) {
|
||||
map.set(name, data);
|
||||
|
||||
/**
|
||||
* Importing and defining the same icon reference
|
||||
* multiple times should not yield a warning.
|
||||
*/
|
||||
/**
|
||||
* Importing and defining the same icon reference
|
||||
* multiple times should not yield a warning.
|
||||
*/
|
||||
} else if (existingIcon !== data) {
|
||||
console.warn(
|
||||
`[Ionicons Warning]: Multiple icons were mapped to name "${name}". Ensure that multiple icons are not mapped to the same icon name.`,
|
||||
);
|
||||
console.warn(`[Ionicons Warning]: Multiple icons were mapped to name "${name}". Ensure that multiple icons are not mapped to the same icon name.`)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
export const getUrl = (i: Icon) => {
|
||||
let url = getSrc(i.src);
|
||||
@@ -82,6 +82,7 @@ export const getUrl = (i: Icon) => {
|
||||
return null;
|
||||
};
|
||||
|
||||
|
||||
const getNamedUrl = (iconName: string, iconEl: Icon) => {
|
||||
const url = getIconMap().get(iconName);
|
||||
if (url) {
|
||||
@@ -89,8 +90,7 @@ const getNamedUrl = (iconName: string, iconEl: Icon) => {
|
||||
}
|
||||
try {
|
||||
return getAssetPath(`svg/${iconName}.svg`);
|
||||
} catch (e) {
|
||||
console.log('e', e);
|
||||
} catch(e) {
|
||||
/**
|
||||
* In the custom elements build version of ionicons, referencing an icon
|
||||
* by name will throw an invalid URL error because the asset path is not defined.
|
||||
@@ -98,19 +98,17 @@ const getNamedUrl = (iconName: string, iconEl: Icon) => {
|
||||
* We also include a reference to the ion-icon element so developers can
|
||||
* figure out which instance of ion-icon needs to be updated.
|
||||
*/
|
||||
console.warn(
|
||||
`[Ionicons Warning]: Could not load icon with name "${iconName}". Ensure that the icon is registered using addIcons or that the icon SVG data is passed directly to the icon component.`,
|
||||
iconEl,
|
||||
);
|
||||
console.warn(`[Ionicons Warning]: Could not load icon with name "${iconName}". Ensure that the icon is registered using addIcons or that the icon SVG data is passed directly to the icon component.`, iconEl);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const getName = (
|
||||
iconName: string | undefined,
|
||||
icon: string | undefined,
|
||||
mode: string | undefined,
|
||||
ios: string | undefined,
|
||||
md: string | undefined,
|
||||
md: string | undefined
|
||||
) => {
|
||||
// default to "md" if somehow the mode wasn't set
|
||||
mode = (mode && toLower(mode)) === 'ios' ? 'ios' : 'md';
|
||||
@@ -119,8 +117,10 @@ export const getName = (
|
||||
// set the iconName to whatever was passed in
|
||||
if (ios && mode === 'ios') {
|
||||
iconName = toLower(ios);
|
||||
|
||||
} else if (md && mode === 'md') {
|
||||
iconName = toLower(md);
|
||||
|
||||
} else {
|
||||
if (!iconName && icon && !isSrc(icon)) {
|
||||
iconName = icon;
|
||||
@@ -172,7 +172,7 @@ export const toLower = (val: string) => val.toLowerCase();
|
||||
export const inheritAttributes = (el: HTMLElement, attributes: string[] = []) => {
|
||||
const attributeObject: { [k: string]: any } = {};
|
||||
|
||||
attributes.forEach((attr) => {
|
||||
attributes.forEach(attr => {
|
||||
if (el.hasAttribute(attr)) {
|
||||
const value = el.getAttribute(attr);
|
||||
if (value !== null) {
|
||||
@@ -183,7 +183,7 @@ export const inheritAttributes = (el: HTMLElement, attributes: string[] = []) =>
|
||||
});
|
||||
|
||||
return attributeObject;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns `true` if the document or host element
|
||||
@@ -197,4 +197,4 @@ export const isRTL = (hostEl?: Pick<HTMLElement, 'dir'>) => {
|
||||
}
|
||||
}
|
||||
return document?.dir.toLowerCase() === 'rtl';
|
||||
};
|
||||
};
|
||||
@@ -1,91 +1,43 @@
|
||||
import { isStr } from './utils';
|
||||
|
||||
/**
|
||||
* Calls `onRejected` only when an `<svg>` was found and failed validation,
|
||||
* not when there's no `<svg>` at all (like an HTML 404 page).
|
||||
*/
|
||||
export const validateContent = (svgContent: string, onRejected?: () => void) => {
|
||||
/**
|
||||
* Parse into a template so nothing loads or runs yet. Parsing into a live
|
||||
* element would fire handlers like `<img onerror>` before validation.
|
||||
*/
|
||||
const template = document.createElement('template');
|
||||
template.innerHTML = svgContent;
|
||||
const content = template.content;
|
||||
export const validateContent = (svgContent: string) => {
|
||||
const div = document.createElement('div');
|
||||
div.innerHTML = svgContent;
|
||||
|
||||
for (let i = content.childNodes.length - 1; i >= 0; i--) {
|
||||
if (content.childNodes[i].nodeName.toLowerCase() !== 'svg') {
|
||||
content.removeChild(content.childNodes[i]);
|
||||
// setup this way to ensure it works on our buddy IE
|
||||
for (let i = div.childNodes.length - 1; i >= 0; i--) {
|
||||
if (div.childNodes[i].nodeName.toLowerCase() !== 'svg') {
|
||||
div.removeChild(div.childNodes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
const svgElm = content.firstElementChild;
|
||||
// must only have 1 root element
|
||||
const svgElm = div.firstElementChild;
|
||||
if (svgElm && svgElm.nodeName.toLowerCase() === 'svg') {
|
||||
const svgClass = svgElm.getAttribute('class') || '';
|
||||
svgElm.setAttribute('class', (svgClass + ' s-ion-icon').trim());
|
||||
|
||||
/**
|
||||
* Illustrator exports keep editor data in a `<foreignObject>` next to the
|
||||
* artwork, so remove it instead of rejecting the icon.
|
||||
*/
|
||||
removeForeignObjects(svgElm);
|
||||
|
||||
// every root is serialized, so a second <svg> would skip validation
|
||||
if (content.children.length === 1 && isValid(svgElm as any)) {
|
||||
return template.innerHTML;
|
||||
// root element must be an svg
|
||||
// lets double check we've got valid elements
|
||||
// do not allow scripts
|
||||
if (isValid(svgElm as any)) {
|
||||
return div.innerHTML;
|
||||
}
|
||||
onRejected?.();
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
const removeForeignObjects = (elm: Element) => {
|
||||
for (let i = elm.children.length - 1; i >= 0; i--) {
|
||||
const child = elm.children[i];
|
||||
if (child.nodeName.toLowerCase() === 'foreignobject') {
|
||||
child.remove();
|
||||
} else {
|
||||
removeForeignObjects(child);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Elements that can run script or load a document without an `on*` attribute.
|
||||
*/
|
||||
const disallowedElements = new Set(['script', 'foreignobject', 'iframe', 'embed', 'object']);
|
||||
|
||||
/**
|
||||
* Browsers ignore whitespace and control characters in a URL scheme, so strip
|
||||
* them first. Checking the whole value also catches lists like
|
||||
* `<animate values="a;javascript:...">`.
|
||||
*/
|
||||
const hasJavascriptUrl = (value: string) =>
|
||||
value
|
||||
.replace(/[\u0000-\u0020]/g, '')
|
||||
.toLowerCase()
|
||||
.includes('javascript:');
|
||||
|
||||
const SVG_NS = 'http://www.w3.org/2000/svg';
|
||||
|
||||
export const isValid = (elm: HTMLElement) => {
|
||||
if (elm.nodeType === 1) {
|
||||
/**
|
||||
* HTML inside `<desc>` or `<title>` (like `<noscript>`) can parse
|
||||
* differently when it renders than it did here, so only allow SVG elements.
|
||||
*/
|
||||
if (elm.namespaceURI !== SVG_NS || disallowedElements.has(elm.nodeName.toLowerCase())) {
|
||||
if (elm.nodeName.toLowerCase() === 'script') {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < elm.attributes.length; i++) {
|
||||
const { name, value } = elm.attributes[i];
|
||||
const name = elm.attributes[i].name;
|
||||
if (isStr(name) && name.toLowerCase().indexOf('on') === 0) {
|
||||
return false;
|
||||
}
|
||||
if (isStr(value) && hasJavascriptUrl(value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < elm.childNodes.length; i++) {
|
||||
@@ -98,4 +50,4 @@ export const isValid = (elm: HTMLElement) => {
|
||||
};
|
||||
|
||||
export const isSvgDataUrl = (url: string) => url.startsWith('data:image/svg+xml');
|
||||
export const isEncodedDataUrl = (url: string) => url.indexOf(';utf8,') !== -1;
|
||||
export const isEncodedDataUrl = (url: string) => url.indexOf(';utf8,') !== -1;
|
||||
|
Before Width: | Height: | Size: 512 B After Width: | Height: | Size: 512 B |
|
Before Width: | Height: | Size: 227 B After Width: | Height: | Size: 227 B |
|
Before Width: | Height: | Size: 641 B After Width: | Height: | Size: 641 B |
|
Before Width: | Height: | Size: 1000 B After Width: | Height: | Size: 1000 B |
@@ -1,13 +1,15 @@
|
||||
import { expect } from '@playwright/test';
|
||||
import { test } from '@utils/test/playwright';
|
||||
import { test } from '../../../utils/test/playwright';
|
||||
|
||||
test.describe('icon: csp', () => {
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/icon/test/csp');
|
||||
await page.goto('/test/csp');
|
||||
});
|
||||
|
||||
test('should load svg', async ({ page }) => {
|
||||
const svg = page.locator('ion-icon#icon-usage svg');
|
||||
await expect(svg).toBeVisible();
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
<!DOCTYPE html>
|
||||
<html dir="ltr" lang="en" mode="ios">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0" />
|
||||
<meta http-equiv="Content-Security-Policy"
|
||||
content="default-src 'none'; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com/*; img-src 'self'; connect-src 'self'; font-src https://fonts.gstatic.com/*'">
|
||||
<title>IonIcon - Content Security Policy</title>
|
||||
<script type="module" src="../../build/ionicons.esm.js"></script>
|
||||
<script nomodule src="../../build/ionicons.js"></script>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 16px;
|
||||
font-size: 32px;
|
||||
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin: 15px 0 5px;
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 15px 0 5px;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.custom {
|
||||
stroke: red;
|
||||
fill: goldenrod;
|
||||
color: black;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Ionicons - Test </h1>
|
||||
|
||||
<h2>Default</h2>
|
||||
<ion-icon src="/assets/chat.svg"></ion-icon>
|
||||
<ion-icon name="add"></ion-icon>
|
||||
|
||||
<ion-icon id="icon-usage"
|
||||
icon="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><title>Watch</title><rect x='136' y='136' width='240' height='240' rx='8' ry='8'/><path d='M384 96h-48V16H176v80h-48a32 32 0 00-32 32v256a32 32 0 0032 32h48v80h160v-80h48a32 32 0 0032-32V128a32 32 0 00-32-32zm8 272a24 24 0 01-24 24H144a24 24 0 01-24-24V144a24 24 0 0124-24h224a24 24 0 0124 24z'/></svg>">
|
||||
</ion-icon>
|
||||
|
||||
<ion-icon class="custom"
|
||||
icon="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' class='ionicon' viewBox='0 0 512 512'><title>Watch</title><rect x='136' y='136' width='240' height='240' rx='8' ry='8'/><path d='M384 96h-48V16H176v80h-48a32 32 0 00-32 32v256a32 32 0 0032 32h48v80h160v-80h48a32 32 0 0032-32V128a32 32 0 00-32-32zm8 272a24 24 0 01-24 24H144a24 24 0 01-24-24V144a24 24 0 0124-24h224a24 24 0 0124 24z'/></svg>">
|
||||
</ion-icon>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
Before Width: | Height: | Size: 292 B After Width: | Height: | Size: 292 B |