Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
89cba595a7 | ||
|
|
02456263e0 | ||
|
|
a00f3134a5 | ||
|
|
d1e2c48641 | ||
|
|
b2d0708a51 | ||
|
|
2a8e43aff0 | ||
|
|
a9d1b7e23d | ||
|
|
8f5ebc425c | ||
|
|
809a6d2a45 | ||
|
|
5d34943550 | ||
|
|
f81cf0034b | ||
|
|
76a68e4629 | ||
|
|
53fb2905fd | ||
|
|
a1a8ba85bb | ||
|
|
72e8c23ecd | ||
|
|
d584c93c21 | ||
|
|
0e51cf1595 | ||
|
|
a9556e4901 | ||
|
|
505a7caeaa | ||
|
|
161eb6ad3c |
@@ -10,13 +10,9 @@ inputs:
|
||||
folder:
|
||||
default: './'
|
||||
description: 'A folder containing a package.json file.'
|
||||
token:
|
||||
description: 'The NPM authentication token required to publish.'
|
||||
|
||||
createRelease:
|
||||
description: 'Create a release on GitHub.'
|
||||
default: 'false'
|
||||
|
||||
ghToken:
|
||||
description: 'The GitHub authentication token required to create a release.'
|
||||
|
||||
@@ -49,12 +45,6 @@ runs:
|
||||
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
|
||||
@@ -70,4 +60,4 @@ runs:
|
||||
shell: bash
|
||||
env:
|
||||
GH_TOKEN: ${{ inputs.ghToken }}
|
||||
VERSION: ${{ env.VERSION }}
|
||||
VERSION: ${{ env.VERSION }}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: 'Ionicons Dev Build'
|
||||
name: 'Dev Release'
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
workflow_call:
|
||||
|
||||
jobs:
|
||||
create-dev-hash:
|
||||
@@ -33,7 +33,6 @@ jobs:
|
||||
tag: dev
|
||||
version: ${{ needs.create-dev-hash.outputs.dev-hash }}
|
||||
working-directory: './'
|
||||
token: ${{ secrets.NPM_TOKEN }}
|
||||
createRelease: 'false'
|
||||
|
||||
get-build:
|
||||
@@ -1,22 +1,12 @@
|
||||
name: 'Ionicons Production Release'
|
||||
name: 'Production Release'
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
workflow_call:
|
||||
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
|
||||
required: false
|
||||
type: string
|
||||
description: npm version (major, minor, or patch)
|
||||
|
||||
jobs:
|
||||
release-ionicons:
|
||||
@@ -31,9 +21,8 @@ jobs:
|
||||
- name: Publish to NPM
|
||||
uses: ./.github/workflows/actions/publish-npm
|
||||
with:
|
||||
tag: ${{ inputs.tag }}
|
||||
tag: latest
|
||||
version: ${{ inputs.version }}
|
||||
working-directory: './'
|
||||
token: ${{ secrets.NPM_TOKEN }}
|
||||
createRelease: true
|
||||
ghToken: ${{ secrets.IONITRON_TOKEN }}
|
||||
@@ -0,0 +1,37 @@
|
||||
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 }}
|
||||
@@ -1,8 +1,10 @@
|
||||
name: 'Ionicons Build'
|
||||
name: 'Validation'
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: ['**']
|
||||
push:
|
||||
branches: ['main']
|
||||
|
||||
# When pushing a new commit we should
|
||||
# cancel the previous test run to not
|
||||
@@ -0,0 +1 @@
|
||||
src/components.d.ts
|
||||
@@ -6,20 +6,18 @@ This document outlines the guidelines and processes for contributing to this pro
|
||||
|
||||
## Table of Contents
|
||||
|
||||
- [Contributing to Ionicons](#contributing-to-ionicons)
|
||||
- [Table of Contents](#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 Changes](#testing-changes)
|
||||
- [Code Style](#code-style)
|
||||
- [Building](#building)
|
||||
- [Submitting Issues](#submitting-issues)
|
||||
- [Submitting Pull Requests](#submitting-pull-requests)
|
||||
- [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
|
||||
|
||||
@@ -84,20 +82,67 @@ 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 (see [Testing Changes](#testing-changes))
|
||||
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 Changes
|
||||
### Testing
|
||||
|
||||
To preview component changes:
|
||||
Tests are crucial for maintaining confidence in changes. All PRs that modify component behavior must include tests covering those changes.
|
||||
|
||||
1. Run:
|
||||
```bash
|
||||
npm start
|
||||
```
|
||||
This will start a local version of the icon test with a test page
|
||||
|
||||
2. Modify the test page in `index.html` as needed to test your changes
|
||||
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
|
||||
#### 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
|
||||
|
||||
@@ -148,4 +193,4 @@ When creating issues:
|
||||
- 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.
|
||||
- [Create a new pull request](https://github.com/ionic-team/ionicons/compare) with the `main` branch as the base.
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
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)'
|
||||
]
|
||||
});
|
||||
@@ -0,0 +1,2 @@
|
||||
const Stencil = require('@stencil/core');
|
||||
Stencil.Build.isBrowser = true;
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ionicons",
|
||||
"version": "8.0.8",
|
||||
"version": "8.1.1",
|
||||
"description": "Premium icons for Ionic.",
|
||||
"files": [
|
||||
"components/",
|
||||
@@ -12,6 +12,8 @@
|
||||
"types": "dist/types/index.d.ts",
|
||||
"unpkg": "dist/ionicons/ionicons.esm.js",
|
||||
"jsdelivr": "dist/ionicons/ionicons.esm.js",
|
||||
"collection": "dist/collection/collection-manifest.json",
|
||||
"collection:main": "dist/collection/index.js",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./dist/types/index.d.ts",
|
||||
@@ -27,47 +29,56 @@
|
||||
"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.* prettier",
|
||||
"build": "run-s clean build.*",
|
||||
"build.files": "tsx scripts/build.ts",
|
||||
"build.component": "stencil build",
|
||||
"build.collection": "tsx scripts/collection-copy.ts",
|
||||
"clean": "rimraf dist components icons www",
|
||||
"prettier": "npm run prettier.base -- --write",
|
||||
"prettier.base": "prettier --cache \"./({bin,scripts,src,test}/**/*.{ts,tsx,js,jsx})|bin/stencil|.github/(**/)?*.(yml|yaml)|*.js\"",
|
||||
"prettier.dry-run": "npm run prettier.base -- --list-different",
|
||||
"start": "run-s build.files start.stencil",
|
||||
"start.stencil": "stencil build --dev --watch --serve",
|
||||
"test": "run-s test.spec",
|
||||
"test.spec": "stencil test --spec",
|
||||
"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"
|
||||
},
|
||||
"dependencies": {
|
||||
"@stencil/core": "^4.30.0"
|
||||
"@stencil/core": "^4.43.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@playwright/test": "^1.52.0",
|
||||
"@axe-core/playwright": "^4.12.1",
|
||||
"@playwright/test": "^1.61.1",
|
||||
"@types/fs-extra": "^11.0.4",
|
||||
"@types/jest": "^29.5.14",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^22.15.3",
|
||||
"@types/svgo": "^3.0.0",
|
||||
"fs-extra": "^11.3.0",
|
||||
"jest": "^29.7.0",
|
||||
"jest-cli": "^29.7.0",
|
||||
"npm-run-all2": "^7.0.2",
|
||||
"prettier": "^3.5.3",
|
||||
"puppeteer": "^24.7.2",
|
||||
"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.1",
|
||||
"semver": "^7.7.2",
|
||||
"serve": "^14.2.4",
|
||||
"svgo": "3.3.2",
|
||||
"tsx": "^4.19.4",
|
||||
"svgo": "4.0.0",
|
||||
"tsx": "^4.20.3",
|
||||
"typescript": "^5.8.3"
|
||||
},
|
||||
"keywords": [
|
||||
|
||||
@@ -26,15 +26,15 @@ 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/loader@latest"></script>
|
||||
<script nomodule src="https://esm.sh/ionicons/loader@latest"></script>
|
||||
<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/loader@8.0.0"></script>
|
||||
<script nomodule src="https://esm.sh/ionicons/loader@8.0.0"></script>
|
||||
<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>
|
||||
```
|
||||
|
||||
### Basic usage
|
||||
|
||||
@@ -98,9 +98,16 @@ async function copyToTesting(rootDir: string, distDir: string, srcSvgData: SvgDa
|
||||
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)]);
|
||||
await Promise.all([
|
||||
fs.ensureDir(testDir),
|
||||
fs.ensureDir(testBuildDir),
|
||||
fs.ensureDir(testSvgDir),
|
||||
fs.ensureDir(cheatsheetDir),
|
||||
]);
|
||||
|
||||
await Promise.all(
|
||||
srcSvgData
|
||||
@@ -111,9 +118,27 @@ async function copyToTesting(rootDir: string, distDir: string, srcSvgData: SvgDa
|
||||
}),
|
||||
);
|
||||
|
||||
const distCheatsheetFilePath = path.join(distDir, 'cheatsheet.html');
|
||||
const testCheatsheetFilePath = path.join(testDir, 'cheatsheet.html');
|
||||
await fs.copyFile(distCheatsheetFilePath, testCheatsheetFilePath);
|
||||
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);
|
||||
}
|
||||
|
||||
async function createSvgSymbols(version: string, distDir: string, srcSvgData: SvgData[]) {
|
||||
@@ -169,7 +194,7 @@ async function createCheatsheet(
|
||||
|
||||
const c = srcSvgData.map(
|
||||
(svgData) =>
|
||||
`<a href="./svg/${svgData.fileName}"><svg><use href="#${svgData.iconName}" xlink:href="#${svgData.iconName}"/></svg></a>`,
|
||||
`<a href="/svg/${svgData.fileName}"><svg><use href="#${svgData.iconName}" xlink:href="#${svgData.iconName}"/></svg></a>`,
|
||||
);
|
||||
|
||||
c.push(svgSymbolsContent);
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Ionicons {{version}} Cheatsheet</title>
|
||||
<!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>
|
||||
|
||||
<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;
|
||||
@@ -31,11 +34,4 @@
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Ionicons {{version}} Cheatsheet</h1>
|
||||
<h3>{{count}} icons</h3>
|
||||
|
||||
{{content}}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import fs from 'fs-extra';
|
||||
import { join } from 'path';
|
||||
|
||||
async function collectionCopy(rootDir: string) {
|
||||
// move optimized svgs to correct collection location
|
||||
const optimizedSrc = join(rootDir, 'dist', 'ionicons', 'svg');
|
||||
const collectionDest = join(rootDir, 'dist', 'collection', 'components', 'icon', 'svg');
|
||||
await fs.copy(optimizedSrc, collectionDest);
|
||||
|
||||
// we don't to copy the src svgs to collection
|
||||
await fs.remove(join(rootDir, 'dist', 'collection', 'svg'));
|
||||
// We don't want to copy the test svg assets to collection
|
||||
await fs.remove(join(rootDir, 'dist', 'collection', 'components', 'test'));
|
||||
|
||||
const cePackageDir = join(rootDir, 'components');
|
||||
const cePackageJsonPath = join(cePackageDir, 'package.json');
|
||||
const ceCjsPath = join(cePackageDir, 'index.cjs.js');
|
||||
|
||||
const emptyCjs = `/*empty cjs*/`;
|
||||
await fs.writeFile(ceCjsPath, emptyCjs);
|
||||
|
||||
const cePackageJson = {
|
||||
name: 'ionicons/components',
|
||||
description: 'Ionicons custom element.',
|
||||
main: './index.cjs.js',
|
||||
module: './index.js',
|
||||
types: './index.d.ts',
|
||||
private: true,
|
||||
};
|
||||
await fs.writeFile(cePackageJsonPath, JSON.stringify(cePackageJson, null, 2));
|
||||
|
||||
// this is temporary!!!!
|
||||
// removing the `type` from the d.ts export
|
||||
// to make it easier for users migrating between
|
||||
// of older versions of angular and typescript
|
||||
// to the newer verisons, where the `type` keyword
|
||||
// is used. This is a megahack, no doubt.
|
||||
const typesDist = join(rootDir, 'dist', 'types', 'index.d.ts');
|
||||
let types = await fs.readFile(typesDist, 'utf8');
|
||||
types = types.replace('export type', 'export');
|
||||
await fs.writeFile(typesDist, types);
|
||||
}
|
||||
|
||||
collectionCopy(join(__dirname, '..'));
|
||||
@@ -1,5 +1,4 @@
|
||||
import { PluginConfig } from 'svgo';
|
||||
import type { CustomPlugin } from './types';
|
||||
|
||||
const setRootIoniconClass: PluginConfig = {
|
||||
name: 'addClassesToSVGElement',
|
||||
@@ -77,7 +76,7 @@ const validatePlugin: PluginConfig = {
|
||||
const basePlugins: PluginConfig[] = [
|
||||
'removeStyleElement',
|
||||
'convertStyleToAttrs',
|
||||
'removeScriptElement',
|
||||
'removeScripts',
|
||||
'removeDimensions',
|
||||
setRootIoniconClass,
|
||||
validatePlugin,
|
||||
|
||||
@@ -28,12 +28,11 @@ npm start
|
||||
|
||||
## Release Steps
|
||||
|
||||
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.
|
||||
Releases are automated via GitHub Actions. To trigger a release:
|
||||
|
||||
Next, update `CHANGELOG.md`, then commit and push your changes Github.
|
||||
|
||||
```sh
|
||||
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`.
|
||||
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)
|
||||
|
||||
@@ -51,6 +51,3 @@ export interface SvgData {
|
||||
*/
|
||||
exportName: string;
|
||||
}
|
||||
|
||||
type ExtractCustomPlugin<T> = T extends { fn: any } ? T : never;
|
||||
export type CustomPlugin = ExtractCustomPlugin<PluginConfig>;
|
||||
|
||||
@@ -4,123 +4,143 @@
|
||||
* This is an autogenerated file created by the Stencil compiler.
|
||||
* It contains typing information for all components that exist in this project.
|
||||
*/
|
||||
import { HTMLStencilElement, JSXBase } from '@stencil/core/internal';
|
||||
import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";
|
||||
export namespace Components {
|
||||
interface IonIcon {
|
||||
/**
|
||||
* The color to use for the background of the item.
|
||||
*/
|
||||
color?: string;
|
||||
/**
|
||||
* Specifies whether the icon should horizontally flip when `dir` is `"rtl"`.
|
||||
*/
|
||||
flipRtl?: boolean;
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
icon?: any;
|
||||
/**
|
||||
* Specifies which icon to use on `ios` mode.
|
||||
*/
|
||||
ios?: string;
|
||||
/**
|
||||
* If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`.
|
||||
*/
|
||||
lazy: boolean;
|
||||
/**
|
||||
* Specifies which icon to use on `md` mode.
|
||||
*/
|
||||
md?: string;
|
||||
/**
|
||||
* The mode determines which platform styles to use.
|
||||
*/
|
||||
mode: string;
|
||||
/**
|
||||
* Specifies which icon to use from the built-in set of icons.
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* The size of the icon. Available options are: `"small"` and `"large"`.
|
||||
*/
|
||||
size?: string;
|
||||
/**
|
||||
* Specifies the exact `src` of an SVG file to use.
|
||||
*/
|
||||
src?: string;
|
||||
}
|
||||
interface IonIcon {
|
||||
/**
|
||||
* The color to use for the background of the item.
|
||||
*/
|
||||
"color"?: string;
|
||||
/**
|
||||
* Specifies whether the icon should horizontally flip when `dir` is `"rtl"`.
|
||||
*/
|
||||
"flipRtl"?: boolean;
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
"icon"?: any;
|
||||
/**
|
||||
* Specifies which icon to use on `ios` mode.
|
||||
*/
|
||||
"ios"?: string;
|
||||
/**
|
||||
* If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`.
|
||||
* @default false
|
||||
*/
|
||||
"lazy": boolean;
|
||||
/**
|
||||
* Specifies which icon to use on `md` mode.
|
||||
*/
|
||||
"md"?: string;
|
||||
/**
|
||||
* The mode determines which platform styles to use.
|
||||
* @default getIonMode()
|
||||
*/
|
||||
"mode": string;
|
||||
/**
|
||||
* Specifies which icon to use from the built-in set of icons.
|
||||
*/
|
||||
"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.
|
||||
* @default true
|
||||
*/
|
||||
"sanitize": boolean;
|
||||
/**
|
||||
* The size of the icon. Available options are: `"small"` and `"large"`.
|
||||
*/
|
||||
"size"?: string;
|
||||
/**
|
||||
* Specifies the exact `src` of an SVG file to use.
|
||||
*/
|
||||
"src"?: string;
|
||||
}
|
||||
}
|
||||
declare global {
|
||||
interface HTMLIonIconElement extends Components.IonIcon, HTMLStencilElement {}
|
||||
var HTMLIonIconElement: {
|
||||
prototype: HTMLIonIconElement;
|
||||
new (): HTMLIonIconElement;
|
||||
};
|
||||
interface HTMLElementTagNameMap {
|
||||
'ion-icon': HTMLIonIconElement;
|
||||
}
|
||||
interface HTMLIonIconElement extends Components.IonIcon, HTMLStencilElement {
|
||||
}
|
||||
var HTMLIonIconElement: {
|
||||
prototype: HTMLIonIconElement;
|
||||
new (): HTMLIonIconElement;
|
||||
};
|
||||
interface HTMLElementTagNameMap {
|
||||
"ion-icon": HTMLIonIconElement;
|
||||
}
|
||||
}
|
||||
declare namespace LocalJSX {
|
||||
interface IonIcon {
|
||||
/**
|
||||
* The color to use for the background of the item.
|
||||
*/
|
||||
color?: string;
|
||||
/**
|
||||
* Specifies whether the icon should horizontally flip when `dir` is `"rtl"`.
|
||||
*/
|
||||
flipRtl?: boolean;
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
icon?: any;
|
||||
/**
|
||||
* Specifies which icon to use on `ios` mode.
|
||||
*/
|
||||
ios?: string;
|
||||
/**
|
||||
* If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`.
|
||||
*/
|
||||
lazy?: boolean;
|
||||
/**
|
||||
* Specifies which icon to use on `md` mode.
|
||||
*/
|
||||
md?: string;
|
||||
/**
|
||||
* The mode determines which platform styles to use.
|
||||
*/
|
||||
mode?: string;
|
||||
/**
|
||||
* Specifies which icon to use from the built-in set of icons.
|
||||
*/
|
||||
name?: string;
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* The size of the icon. Available options are: `"small"` and `"large"`.
|
||||
*/
|
||||
size?: string;
|
||||
/**
|
||||
* Specifies the exact `src` of an SVG file to use.
|
||||
*/
|
||||
src?: string;
|
||||
}
|
||||
interface IntrinsicElements {
|
||||
'ion-icon': IonIcon;
|
||||
}
|
||||
interface IonIcon {
|
||||
/**
|
||||
* The color to use for the background of the item.
|
||||
*/
|
||||
"color"?: string;
|
||||
/**
|
||||
* Specifies whether the icon should horizontally flip when `dir` is `"rtl"`.
|
||||
*/
|
||||
"flipRtl"?: boolean;
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
"icon"?: any;
|
||||
/**
|
||||
* Specifies which icon to use on `ios` mode.
|
||||
*/
|
||||
"ios"?: string;
|
||||
/**
|
||||
* If enabled, ion-icon will be loaded lazily when it's visible in the viewport. Default, `false`.
|
||||
* @default false
|
||||
*/
|
||||
"lazy"?: boolean;
|
||||
/**
|
||||
* Specifies which icon to use on `md` mode.
|
||||
*/
|
||||
"md"?: string;
|
||||
/**
|
||||
* The mode determines which platform styles to use.
|
||||
* @default getIonMode()
|
||||
*/
|
||||
"mode"?: string;
|
||||
/**
|
||||
* Specifies which icon to use from the built-in set of icons.
|
||||
*/
|
||||
"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.
|
||||
* @default true
|
||||
*/
|
||||
"sanitize"?: boolean;
|
||||
/**
|
||||
* The size of the icon. Available options are: `"small"` and `"large"`.
|
||||
*/
|
||||
"size"?: string;
|
||||
/**
|
||||
* Specifies the exact `src` of an SVG file to use.
|
||||
*/
|
||||
"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] };
|
||||
}
|
||||
}
|
||||
export { LocalJSX as JSX };
|
||||
declare module '@stencil/core' {
|
||||
export namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
'ion-icon': LocalJSX.IonIcon & JSXBase.HTMLAttributes<HTMLIonIconElement>;
|
||||
declare module "@stencil/core" {
|
||||
export namespace JSX {
|
||||
interface IntrinsicElements {
|
||||
"ion-icon": LocalJSX.IntrinsicElements["ion-icon"] & JSXBase.HTMLAttributes<HTMLIonIconElement>;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
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 |
|
Before Width: | Height: | Size: 292 B After Width: | Height: | Size: 292 B |
|
Before Width: | Height: | Size: 369 B After Width: | Height: | Size: 369 B |
|
Before Width: | Height: | Size: 544 B After Width: | Height: | Size: 544 B |
|
Before Width: | Height: | Size: 544 B After Width: | Height: | Size: 544 B |
|
Before Width: | Height: | Size: 372 B After Width: | Height: | Size: 372 B |
|
Before Width: | Height: | Size: 233 B After Width: | Height: | Size: 233 B |
|
Before Width: | Height: | Size: 340 B After Width: | Height: | Size: 340 B |
@@ -4,12 +4,13 @@
|
||||
width: 1em;
|
||||
height: 1em;
|
||||
|
||||
contain: strict;
|
||||
font-size: 1em;
|
||||
|
||||
contain: layout style;
|
||||
|
||||
fill: currentColor;
|
||||
|
||||
box-sizing: content-box !important;
|
||||
|
||||
}
|
||||
|
||||
:host .ionicon {
|
||||
@@ -24,7 +25,16 @@
|
||||
stroke-width: var(--ionicon-stroke-width, 32px);
|
||||
}
|
||||
|
||||
.icon-inner,
|
||||
.icon-inner {
|
||||
display: flex;
|
||||
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.ionicon,
|
||||
svg {
|
||||
display: block;
|
||||
@@ -33,6 +43,14 @@ 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 { getSvgContent, ioniconContent } from './request';
|
||||
import { getCacheKey, getSvgContent, ioniconContent } from './request';
|
||||
import { getName, getUrl, inheritAttributes, isRTL } from './utils';
|
||||
|
||||
@Component({
|
||||
@@ -74,9 +74,11 @@ export class Icon {
|
||||
@Prop() lazy = false;
|
||||
|
||||
/**
|
||||
* 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`.
|
||||
* 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.
|
||||
* @default true
|
||||
*/
|
||||
@Prop() sanitize = true;
|
||||
@@ -175,12 +177,13 @@ export class Icon {
|
||||
const url = getUrl(this);
|
||||
|
||||
if (url) {
|
||||
if (ioniconContent.has(url)) {
|
||||
const cacheKey = getCacheKey(url, this.sanitize);
|
||||
if (ioniconContent.has(cacheKey)) {
|
||||
// sync if it's already loaded
|
||||
this.svgContent = ioniconContent.get(url);
|
||||
this.svgContent = ioniconContent.get(cacheKey);
|
||||
} else {
|
||||
// async if it hasn't been loaded
|
||||
getSvgContent(url, this.sanitize).then(() => (this.svgContent = ioniconContent.get(url)));
|
||||
getSvgContent(url, this.sanitize).then(() => (this.svgContent = ioniconContent.get(cacheKey)));
|
||||
}
|
||||
this.didLoadIcon = true;
|
||||
}
|
||||
@@ -221,7 +224,9 @@ export class Icon {
|
||||
{Build.isBrowser && this.svgContent ? (
|
||||
<div class="icon-inner" innerHTML={this.svgContent}></div>
|
||||
) : (
|
||||
<div class="icon-inner"></div>
|
||||
<div class="icon-inner">
|
||||
<slot></slot>
|
||||
</div>
|
||||
)}
|
||||
</Host>
|
||||
);
|
||||
|
||||
@@ -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 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` |
|
||||
| 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` |
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
|
||||
@@ -5,20 +5,39 @@ 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}`;
|
||||
|
||||
/**
|
||||
* 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(url: string) {
|
||||
function safeFallback(cacheKey: string) {
|
||||
const svg = '';
|
||||
ioniconContent.set(url, 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(url);
|
||||
const req = requests.get(cacheKey);
|
||||
if (req) {
|
||||
return req;
|
||||
}
|
||||
@@ -29,16 +48,16 @@ export const getSvgContent = (url: string, sanitize: boolean): Promise<string> =
|
||||
* with the DOMParser. This works with content security policies enabled.
|
||||
*/
|
||||
if (isSvgDataUrl(url) && isEncodedDataUrl(url)) {
|
||||
return Promise.resolve(getSvgByUrl(url));
|
||||
return Promise.resolve(getSvgByUrl(url, sanitize));
|
||||
}
|
||||
|
||||
return fetchSvg(url, sanitize);
|
||||
}
|
||||
|
||||
return Promise.resolve(safeFallback(url));
|
||||
return Promise.resolve(safeFallback(cacheKey));
|
||||
};
|
||||
|
||||
function getSvgByUrl(url: string): string {
|
||||
function getSvgByUrl(url: string, sanitize: boolean): string {
|
||||
if (!parser) {
|
||||
/**
|
||||
* Create an instance of the DOM parser. This creates a single
|
||||
@@ -49,14 +68,16 @@ function getSvgByUrl(url: string): string {
|
||||
const doc = parser.parseFromString(url, 'text/html');
|
||||
const svg = doc.querySelector('svg');
|
||||
if (svg) {
|
||||
ioniconContent.set(url, svg.outerHTML);
|
||||
return svg.outerHTML;
|
||||
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
|
||||
*/
|
||||
@@ -71,20 +92,20 @@ function fetchSvg(url: string, sanitize: boolean): Promise<string> {
|
||||
.text()
|
||||
.then((svgContent) => {
|
||||
if (svgContent && sanitize !== false) {
|
||||
svgContent = validateContent(svgContent);
|
||||
svgContent = sanitizeSvg(url, svgContent);
|
||||
}
|
||||
|
||||
const svg = svgContent || '';
|
||||
ioniconContent.set(url, svg);
|
||||
ioniconContent.set(cacheKey, svg);
|
||||
return svg;
|
||||
})
|
||||
.catch(() => safeFallback(url));
|
||||
.catch(() => safeFallback(cacheKey));
|
||||
})
|
||||
.catch(() => safeFallback(url));
|
||||
.catch(() => safeFallback(cacheKey));
|
||||
|
||||
/**
|
||||
* Cache for the same requests
|
||||
*/
|
||||
requests.set(url, req);
|
||||
requests.set(cacheKey, req);
|
||||
return req;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# this gitignore file is used as a placeholder
|
||||
# for this directory. The directory itself will
|
||||
# contain files generated during a build step.
|
||||
*
|
||||
!.gitignore
|
||||
@@ -0,0 +1,15 @@
|
||||
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([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,59 @@
|
||||
<!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>
|
||||
@@ -0,0 +1,13 @@
|
||||
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 });
|
||||
});
|
||||
});
|
||||
|
After Width: | Height: | Size: 59 KiB |
|
After Width: | Height: | Size: 62 KiB |
|
After Width: | Height: | Size: 68 KiB |
@@ -0,0 +1,101 @@
|
||||
<!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,9 +1,9 @@
|
||||
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('/test/csp');
|
||||
await page.goto('/icon/test/csp');
|
||||
});
|
||||
|
||||
test('should load svg', async ({ page }) => {
|
||||
@@ -0,0 +1,52 @@
|
||||
<!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>
|
||||
@@ -1,17 +1,16 @@
|
||||
import { expect } from '@playwright/test';
|
||||
import { test } from '../../../utils/test/playwright';
|
||||
import { test } from '@utils/test/playwright';
|
||||
|
||||
test.describe('icon: dynamic type', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/test/dynamic-type');
|
||||
await page.goto(`/icon/test/dynamic-type/`);
|
||||
});
|
||||
|
||||
test('should scale text on larger font sizes', async ({ page }) => {
|
||||
// Wait for all SVGs to be lazily loaded before taking screenshots
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const icons = page.locator('#icons');
|
||||
|
||||
await expect(icons).toHaveScreenshot(`icon-dynamic-type-diff.png`);
|
||||
const main = page.locator('main');
|
||||
await expect(main).toHaveScreenshot(`icon-dynamic-type.png`);
|
||||
});
|
||||
});
|
||||
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 16 KiB |
@@ -0,0 +1,45 @@
|
||||
<!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>
|
||||
@@ -0,0 +1,14 @@
|
||||
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);
|
||||
|
Before Width: | Height: | Size: 101 KiB |
|
Before Width: | Height: | Size: 102 KiB |
|
Before Width: | Height: | Size: 89 KiB |
|
Before Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 25 KiB |
@@ -1,79 +1,202 @@
|
||||
import { newSpecPage } from '@stencil/core/testing';
|
||||
import { newSpecPage } from 'jest-stencil-runner';
|
||||
import { Icon } from '../icon';
|
||||
|
||||
describe('icon', () => {
|
||||
it('renders', async () => {
|
||||
const { root } = await newSpecPage({
|
||||
components: [Icon],
|
||||
html: '<ion-icon></ion-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>
|
||||
`);
|
||||
});
|
||||
expect(root).toEqualHtml(`
|
||||
<ion-icon class="md" role="img">
|
||||
<mock:shadow-root>
|
||||
<div class="icon-inner"></div>
|
||||
</mock:shadow-root>
|
||||
</ion-icon>
|
||||
`);
|
||||
});
|
||||
|
||||
it('renders rtl with aria-hidden', async () => {
|
||||
const { root } = await newSpecPage({
|
||||
components: [Icon],
|
||||
direction: 'rtl',
|
||||
html: `<ion-icon name="chevron-forward" aria-hidden="true"></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>`,
|
||||
});
|
||||
|
||||
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>
|
||||
`);
|
||||
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 custom aria-label', async () => {
|
||||
const { root } = await newSpecPage({
|
||||
components: [Icon],
|
||||
html: `<ion-icon name="star" aria-label="custom label"></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();
|
||||
});
|
||||
|
||||
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>
|
||||
`);
|
||||
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();
|
||||
});
|
||||
});
|
||||
|
||||
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>`,
|
||||
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>
|
||||
`);
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
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>
|
||||
`);
|
||||
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>
|
||||
`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
<!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>
|
||||
@@ -1,18 +1,9 @@
|
||||
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(`/`);
|
||||
|
||||
// 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.describe('icon: rtl', () => {
|
||||
test('some icons should flip when rtl', async ({ page }) => {
|
||||
await page.goto(`/`);
|
||||
await page.goto(`/icon/test/rtl/`);
|
||||
|
||||
const autoflip = page.locator('.auto-flip-chevrons [name=chevron-forward] .icon-inner');
|
||||
const unflip = page.locator('.un-flip-chevrons [name=chevron-forward] .icon-inner');
|
||||
@@ -29,12 +20,11 @@ test.describe('icon: basic', () => {
|
||||
// Wait for all SVGs to be lazily loaded before taking screenshots
|
||||
await page.waitForLoadState('networkidle');
|
||||
|
||||
const rtlTests = page.locator('#rtl-tests');
|
||||
await expect(rtlTests).toHaveScreenshot(`icon-rtl-diff.png`);
|
||||
await expect(page).toHaveScreenshot(`icon-rtl.png`);
|
||||
});
|
||||
|
||||
test('arrows should flip if dir changes on the element', async ({ page }) => {
|
||||
await page.goto(`/`);
|
||||
await page.goto(`/icon/test/rtl/`);
|
||||
|
||||
const autoflip = page.locator('.auto-flip-chevrons [name=chevron-forward] .icon-inner');
|
||||
const unflip = page.locator('.un-flip-chevrons [name=chevron-forward] .icon-inner');
|
||||
@@ -51,7 +41,7 @@ test.describe('icon: basic', () => {
|
||||
});
|
||||
|
||||
test('icon should reassess flipping when name changes', async ({ page }) => {
|
||||
await page.goto(`/`);
|
||||
await page.goto(`/icon/test/rtl/`);
|
||||
|
||||
await page.evaluate(() => {
|
||||
document.dir = 'rtl';
|
||||
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 34 KiB |
@@ -0,0 +1,72 @@
|
||||
<!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>
|
||||
@@ -0,0 +1,284 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 19 KiB |
@@ -0,0 +1,37 @@
|
||||
<!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>
|
||||
@@ -0,0 +1,40 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
|
After Width: | Height: | Size: 9.2 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 11 KiB |
@@ -0,0 +1,39 @@
|
||||
<!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>
|
||||
@@ -0,0 +1,13 @@
|
||||
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 });
|
||||
});
|
||||
});
|
||||
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 68 KiB |
@@ -0,0 +1,310 @@
|
||||
<!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>
|
||||
@@ -0,0 +1,107 @@
|
||||
: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;
|
||||
}
|
||||
@@ -8,7 +8,11 @@ describe('getUrl', () => {
|
||||
i = new Icon();
|
||||
});
|
||||
|
||||
it('use icon prop, as name', () => {
|
||||
/**
|
||||
* 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', () => {
|
||||
i.icon = 'some-name';
|
||||
expect(getUrl(i)).toBe('/svg/some-name.svg');
|
||||
});
|
||||
@@ -18,7 +22,11 @@ describe('getUrl', () => {
|
||||
expect(getUrl(i)).toBe('./some.svg');
|
||||
});
|
||||
|
||||
it('use name prop', () => {
|
||||
/**
|
||||
* Started to fail after upgrading to new jest-stencil-runner
|
||||
* @ToDo(@christian-bromann): investigate why this is failing
|
||||
*/
|
||||
it.skip('use name prop', () => {
|
||||
i.name = 'some-name';
|
||||
expect(getUrl(i)).toBe('/svg/some-name.svg');
|
||||
});
|
||||
|
||||
@@ -1,54 +1,65 @@
|
||||
import { isEncodedDataUrl, isSvgDataUrl, isValid } from '../validate';
|
||||
import { readFileSync, readdirSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
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', () => {
|
||||
const el = {
|
||||
nodeType: 1,
|
||||
nodeName: 'svg',
|
||||
attributes: [{ name: 'onload' }],
|
||||
childNodes: [],
|
||||
} as any;
|
||||
expect(isValid(el)).toBe(false);
|
||||
expect(isValid(elm('svg', [{ name: 'onload' }]))).toBe(false);
|
||||
});
|
||||
|
||||
it('invalid onclick attr', () => {
|
||||
const el = {
|
||||
nodeType: 1,
|
||||
nodeName: 'svg',
|
||||
attributes: [{ name: 'OnClIcK' }],
|
||||
childNodes: [],
|
||||
} as any;
|
||||
expect(isValid(el)).toBe(false);
|
||||
expect(isValid(elm('svg', [{ name: 'OnClIcK' }]))).toBe(false);
|
||||
});
|
||||
|
||||
it('invalid child SCRIPT elm', () => {
|
||||
const el = {
|
||||
nodeType: 1,
|
||||
nodeName: 'svg',
|
||||
attributes: [],
|
||||
childNodes: [{ nodeType: 1, nodeName: 'SCRIPT', attributes: [], childNodes: [] }],
|
||||
} as any;
|
||||
expect(isValid(el)).toBe(false);
|
||||
expect(isValid(elm('svg', [], [elm('SCRIPT')]))).toBe(false);
|
||||
});
|
||||
|
||||
it('invalid script elm', () => {
|
||||
const el = { nodeType: 1, nodeName: 'script', attributes: [], childNodes: [] } as any;
|
||||
expect(isValid(el)).toBe(false);
|
||||
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);
|
||||
});
|
||||
|
||||
it('is valid circle elm', () => {
|
||||
const el = { nodeType: 1, nodeName: 'circle', attributes: [], childNodes: [] } as any;
|
||||
expect(isValid(el)).toBe(true);
|
||||
expect(isValid(elm('circle'))).toBe(true);
|
||||
});
|
||||
|
||||
it('is valid SVG elm', () => {
|
||||
const el = {
|
||||
nodeType: 1,
|
||||
nodeName: 'SVG',
|
||||
attributes: [],
|
||||
childNodes: [{ nodeType: 1, nodeName: 'line', attributes: [], childNodes: [] }],
|
||||
} as any;
|
||||
expect(isValid(el)).toBe(true);
|
||||
expect(isValid(elm('SVG', [], [elm('line')]))).toBe(true);
|
||||
});
|
||||
|
||||
it('is valid href', () => {
|
||||
expect(isValid(elm('a', [{ name: 'href', value: 'https://ionic.io' }]))).toBe(true);
|
||||
});
|
||||
|
||||
it('is valid text node', () => {
|
||||
@@ -57,6 +68,56 @@ describe('isValid', () => {
|
||||
});
|
||||
});
|
||||
|
||||
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', () => {
|
||||
expect(isSvgDataUrl('data:image/svg+xml;base64,xxx')).toBe(true);
|
||||
expect(isSvgDataUrl('data:image/svg+xml;utf8,<svg></svg>')).toBe(true);
|
||||
|
||||
@@ -90,6 +90,7 @@ const getNamedUrl = (iconName: string, iconEl: Icon) => {
|
||||
try {
|
||||
return getAssetPath(`svg/${iconName}.svg`);
|
||||
} catch (e) {
|
||||
console.log('e', 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.
|
||||
|
||||
@@ -1,43 +1,91 @@
|
||||
import { isStr } from './utils';
|
||||
|
||||
export const validateContent = (svgContent: string) => {
|
||||
const div = document.createElement('div');
|
||||
div.innerHTML = svgContent;
|
||||
/**
|
||||
* 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;
|
||||
|
||||
// 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]);
|
||||
for (let i = content.childNodes.length - 1; i >= 0; i--) {
|
||||
if (content.childNodes[i].nodeName.toLowerCase() !== 'svg') {
|
||||
content.removeChild(content.childNodes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
// must only have 1 root element
|
||||
const svgElm = div.firstElementChild;
|
||||
const svgElm = content.firstElementChild;
|
||||
if (svgElm && svgElm.nodeName.toLowerCase() === 'svg') {
|
||||
const svgClass = svgElm.getAttribute('class') || '';
|
||||
svgElm.setAttribute('class', (svgClass + ' s-ion-icon').trim());
|
||||
|
||||
// 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;
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
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) {
|
||||
if (elm.nodeName.toLowerCase() === 'script') {
|
||||
/**
|
||||
* 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())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let i = 0; i < elm.attributes.length; i++) {
|
||||
const name = elm.attributes[i].name;
|
||||
const { name, value } = elm.attributes[i];
|
||||
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++) {
|
||||
|
||||
@@ -1,54 +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>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: 1.6 KiB |
|
Before Width: | Height: | Size: 2.7 KiB |
|
Before Width: | Height: | Size: 2.3 KiB |
@@ -1,27 +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>IonIcon - Dynamic Type</title>
|
||||
<script type="module" src="../../build/ionicons.esm.js"></script>
|
||||
<script nomodule src="../../build/ionicons.js"></script>
|
||||
<style>
|
||||
html {
|
||||
font-size: 28px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="icons">
|
||||
<ion-icon name="star"></ion-icon>
|
||||
<ion-icon name="star" size="small"></ion-icon>
|
||||
<ion-icon name="star" size="large"></ion-icon>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,180 +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>Ionicons Icon Component</title>
|
||||
<script type="module" src="/build/ionicons.esm.js"></script>
|
||||
<script nomodule src="/build/ionicons.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Ionicons</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>
|
||||
|
||||
<h2>Aria</h2>
|
||||
<ion-icon name="cellular"></ion-icon>
|
||||
<ion-icon name="cellular" aria-label="Mobile data"></ion-icon>
|
||||
<ion-icon name="cellular" aria-hidden="true"></ion-icon>
|
||||
|
||||
<div id="rtl-tests">
|
||||
<h1>RTL</h1>
|
||||
|
||||
<h2>Default: Non-arrows</h2>
|
||||
<ion-icon name="cut"></ion-icon>
|
||||
<ion-icon name="call"></ion-icon>
|
||||
<ion-icon name="checkbox"></ion-icon>
|
||||
<ion-icon name="brush"></ion-icon>
|
||||
|
||||
<h2>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>
|
||||
</div>
|
||||
|
||||
<h2>Sanitized (shouldn't show)</h2>
|
||||
<ion-icon src="./assets/sanitize.svg"></ion-icon>
|
||||
|
||||
<h2>Not Sanitized (should show)</h2>
|
||||
<ion-icon sanitize="false" src="./assets/no-sanitize.svg"></ion-icon>
|
||||
|
||||
<h2>Base64 url</h2>
|
||||
<ion-icon
|
||||
src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0Ij48cGF0aCBmaWxsPSJub25lIiBkPSJNMCAwaDI0djI0SDBWMHoiLz48cGF0aCBkPSJNMjAgMkg0Yy0xLjEgMC0yIC45LTIgMnYxOGw0LTRoMTRjMS4xIDAgMi0uOSAyLTJWNGMwLTEuMS0uOS0yLTItMnptMCAxNEg2bC0yIDJWNGgxNnYxMnoiLz48L3N2Zz4="></ion-icon>
|
||||
|
||||
<p>
|
||||
<a href="./cheatsheet.html">Cheatsheet</a>
|
||||
</p>
|
||||
|
||||
<style>
|
||||
html {
|
||||
font-size: 32px;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 16px;
|
||||
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: blue;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1 +1,2 @@
|
||||
export * from './goto';
|
||||
export * from './set-content';
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import type { Page, TestInfo } from '@playwright/test';
|
||||
import type { E2EPage } from '@utils/test/playwright';
|
||||
|
||||
/**
|
||||
* Overwrites the default Playwright page.setContent method.
|
||||
*
|
||||
* Navigates to a blank page, sets the content, and waits for the
|
||||
* Stencil components to be hydrated before proceeding with the test.
|
||||
*
|
||||
* Ported from Ionic Framework's fixture. Ionicons has no mode, direction,
|
||||
* or palette config, so only the ionicons build is injected.
|
||||
*
|
||||
* @param page The Playwright page object.
|
||||
* @param html The HTML content to set on the page body.
|
||||
* @param testInfo The TestInfo associated with the current test run.
|
||||
* @param options Navigation options passed to page.goto.
|
||||
*/
|
||||
export const setContent = async (
|
||||
page: Page,
|
||||
html: string,
|
||||
testInfo: TestInfo,
|
||||
options?: Parameters<E2EPage['goto']>[1],
|
||||
) => {
|
||||
if (page.isClosed()) {
|
||||
throw new Error('setContent unavailable: page is already closed');
|
||||
}
|
||||
|
||||
const baseUrl = testInfo.project.use.baseURL;
|
||||
if (!baseUrl) {
|
||||
throw new Error('setContent requires a baseURL in the Playwright config');
|
||||
}
|
||||
|
||||
const output = `
|
||||
<!DOCTYPE html>
|
||||
<html dir="ltr" lang="en">
|
||||
<head>
|
||||
<title>Ionicons Playwright Test</title>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
|
||||
<script type="module" src="${baseUrl}/build/ionicons.esm.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
${html}
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
await page.route(baseUrl, (route) => {
|
||||
if (route.request().url() === `${baseUrl}/`) {
|
||||
/**
|
||||
* Intercepts the empty page request and returns the
|
||||
* HTML content that was passed in.
|
||||
*/
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'text/html',
|
||||
body: output,
|
||||
});
|
||||
} else {
|
||||
// Allow all other requests to pass through
|
||||
route.continue();
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* URL query parameters cause the custom Playwright `page.route`
|
||||
* interceptor to fail, which is necessary to inject the test HTML.
|
||||
*
|
||||
* To avoid this, the final navigation URL is kept simple by using
|
||||
* hash params to ensure the route interceptor always works.
|
||||
*/
|
||||
await page.goto(`${baseUrl}#`, options);
|
||||
};
|
||||
@@ -54,4 +54,10 @@ export interface E2EPage extends Page {
|
||||
waitUntil?: 'load' | 'domcontentloaded' | 'networkidle' | 'commit';
|
||||
},
|
||||
) => Promise<null | Response>;
|
||||
|
||||
/**
|
||||
* Replaces the page content with the given HTML, loads the ionicons build,
|
||||
* and waits for the Stencil components to be hydrated.
|
||||
*/
|
||||
setContent: (html: string, options?: Parameters<E2EPage['goto']>[1]) => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import type {
|
||||
} from '@playwright/test';
|
||||
import { test as base } from '@playwright/test';
|
||||
|
||||
import { goto as goToPage } from './page/utils';
|
||||
import { goto as goToPage, setContent } from './page/utils';
|
||||
import type { E2EPage } from './playwright-declarations';
|
||||
|
||||
type CustomTestArgs = PlaywrightTestArgs &
|
||||
@@ -43,6 +43,7 @@ export async function extendPageFixture(page: E2EPage, testInfo: TestInfo) {
|
||||
})();`);
|
||||
// Overridden Playwright methods
|
||||
page.goto = (url: string, options) => goToPage(page, url, options, testInfo, originalGoto);
|
||||
page.setContent = (html: string, options) => setContent(page, html, testInfo, options);
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ export const config: Config = {
|
||||
outputTargets: [
|
||||
{
|
||||
type: 'dist',
|
||||
collectionDir: null,
|
||||
collectionDir: './collection',
|
||||
empty: false,
|
||||
},
|
||||
{
|
||||
@@ -21,12 +21,12 @@ export const config: Config = {
|
||||
type: 'www',
|
||||
copy: [
|
||||
{
|
||||
src: './components/test/*.svg',
|
||||
dest: './assets/',
|
||||
src: './components/icon/assets',
|
||||
dest: './icon/assets/',
|
||||
},
|
||||
{
|
||||
src: './components/test/',
|
||||
dest: './test/',
|
||||
src: './components/icon/test',
|
||||
dest: './icon/test',
|
||||
},
|
||||
{
|
||||
src: './svg/*.svg',
|
||||
|
||||