stripe-pwa-elements 4.0.0 → 4.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/factory-tenFFIul.js +1200 -0
- package/dist/cjs/{factory-da3xAKkz.js → i18n-FhEOc8vz.js} +6 -1131
- package/dist/cjs/ion-icon_2.cjs.entry.js +723 -0
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/stripe-address-element.cjs.entry.js +12 -4
- package/dist/cjs/stripe-card-element-modal.cjs.entry.js +3 -2
- package/dist/cjs/{stripe-card-element_2.cjs.entry.js → stripe-card-element.cjs.entry.js} +15 -82
- package/dist/cjs/stripe-currency-selector.cjs.entry.js +11 -3
- package/dist/cjs/stripe-elements.cjs.js +1 -1
- package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +31 -5
- package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +11 -3
- package/dist/cjs/stripe-payment-element.cjs.entry.js +106 -161
- package/dist/cjs/stripe-payment-element.helpers-DukP33RI.js +122 -0
- package/dist/cjs/stripe-payment-request-button.cjs.entry.js +23 -16
- package/dist/cjs/stripe-payment-sheet.cjs.entry.js +506 -0
- package/dist/collection/collection-manifest.json +3 -2
- package/dist/collection/components/stripe-address-element/stripe-address-element.js +7 -0
- package/dist/collection/components/stripe-card-element/stripe-card-element.js +10 -2
- package/dist/collection/components/stripe-card-element-modal/stripe-card-element-modal.js +4 -3
- package/dist/collection/components/stripe-currency-selector/stripe-currency-selector.js +7 -0
- package/dist/collection/components/stripe-express-checkout-element/stripe-express-checkout-element.js +25 -0
- package/dist/collection/components/stripe-link-authentication-element/stripe-link-authentication-element.js +7 -0
- package/dist/collection/components/stripe-modal/stripe-modal.css +23 -1
- package/dist/collection/components/stripe-modal/stripe-modal.js +147 -6
- package/dist/collection/components/stripe-payment-element/stripe-payment-element.js +94 -37
- package/dist/collection/components/stripe-payment-request-button/stripe-payment-request-button.js +17 -10
- package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +179 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.css +68 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.helpers.js +90 -0
- package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +544 -0
- package/dist/collection/services/express-checkout-element-manager.js +36 -2
- package/dist/collection/services/stripe-service.js +37 -5
- package/dist/collection/utils/focus.js +76 -0
- package/dist/collection/utils/i18n.js +6 -0
- package/dist/components/factory.js +1 -1
- package/dist/components/i18n.js +1 -0
- package/dist/components/stripe-address-element.js +1 -1
- package/dist/components/stripe-card-element-modal.js +1 -1
- package/dist/components/stripe-card-element2.js +1 -1
- package/dist/components/stripe-currency-selector.js +1 -1
- package/dist/components/stripe-express-checkout-element.js +1 -1
- package/dist/components/stripe-link-authentication-element.js +1 -1
- package/dist/components/stripe-modal2.js +1 -1
- package/dist/components/stripe-payment-element.helpers.js +1 -0
- package/dist/components/stripe-payment-element.js +1 -1
- package/dist/components/stripe-payment-request-button2.js +1 -1
- package/dist/components/stripe-payment-sheet.d.ts +11 -0
- package/dist/components/stripe-payment-sheet.js +1 -0
- package/dist/esm/factory-Cd6OGTWN.js +1198 -0
- package/dist/esm/{factory-DeqoYLf_.js → i18n-B6JoQetF.js} +7 -1131
- package/dist/esm/ion-icon_2.entry.js +720 -0
- package/dist/esm/loader.js +1 -1
- package/dist/esm/stripe-address-element.entry.js +9 -1
- package/dist/esm/stripe-card-element-modal.entry.js +3 -2
- package/dist/esm/{stripe-card-element_2.entry.js → stripe-card-element.entry.js} +13 -79
- package/dist/esm/stripe-currency-selector.entry.js +9 -1
- package/dist/esm/stripe-elements.js +1 -1
- package/dist/esm/stripe-express-checkout-element.entry.js +27 -1
- package/dist/esm/stripe-link-authentication-element.entry.js +9 -1
- package/dist/esm/stripe-payment-element.entry.js +98 -153
- package/dist/esm/stripe-payment-element.helpers-CipV87b8.js +117 -0
- package/dist/esm/stripe-payment-request-button.entry.js +18 -11
- package/dist/esm/stripe-payment-sheet.entry.js +504 -0
- package/dist/stripe-elements/{p-38e7b187.entry.js → p-4891edf0.entry.js} +1 -1
- package/dist/stripe-elements/p-5338bc5e.entry.js +1 -0
- package/dist/stripe-elements/p-6a9c8b7a.entry.js +1 -0
- package/dist/stripe-elements/p-7fe4a287.entry.js +1 -0
- package/dist/stripe-elements/p-915b86ed.entry.js +1 -0
- package/dist/stripe-elements/p-B6JoQetF.js +1 -0
- package/dist/stripe-elements/p-C7MQk9FK.js +1 -0
- package/dist/stripe-elements/p-DFAhQS0n.js +1 -0
- package/dist/stripe-elements/p-b06a254f.entry.js +1 -0
- package/dist/stripe-elements/p-b91c4fa7.entry.js +1 -0
- package/dist/stripe-elements/p-ba791c8f.entry.js +1 -0
- package/dist/stripe-elements/p-e7372ca7.entry.js +1 -0
- package/dist/stripe-elements/p-f892e375.entry.js +1 -0
- package/dist/stripe-elements/stripe-elements.esm.js +1 -1
- package/dist/types/components/stripe-address-element/stripe-address-element.d.ts +6 -0
- package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +8 -1
- package/dist/types/components/stripe-card-element-modal/stripe-card-element-modal.d.ts +2 -1
- package/dist/types/components/stripe-currency-selector/stripe-currency-selector.d.ts +6 -0
- package/dist/types/components/stripe-express-checkout-element/stripe-express-checkout-element.d.ts +11 -0
- package/dist/types/components/stripe-link-authentication-element/stripe-link-authentication-element.d.ts +6 -0
- package/dist/types/components/stripe-modal/stripe-modal.d.ts +44 -0
- package/dist/types/components/stripe-payment-element/stripe-payment-element.d.ts +18 -0
- package/dist/types/components/stripe-payment-request-button/stripe-payment-request-button.d.ts +7 -2
- package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +104 -0
- package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +112 -0
- package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +95 -0
- package/dist/types/components.d.ts +169 -10
- package/dist/types/index.d.ts +2 -0
- package/dist/types/services/interfaces.d.ts +2 -0
- package/dist/types/services/stripe-service.d.ts +12 -3
- package/dist/types/utils/focus.d.ts +15 -0
- package/package.json +5 -3
- package/readme.md +46 -10
- package/dist/cjs/ion-icon.cjs.entry.js +0 -431
- package/dist/components/utils.js +0 -1
- package/dist/esm/ion-icon.entry.js +0 -429
- package/dist/stripe-elements/p--sA2m1ad.js +0 -1
- package/dist/stripe-elements/p-44495284.entry.js +0 -1
- package/dist/stripe-elements/p-4ba675fa.entry.js +0 -1
- package/dist/stripe-elements/p-5cf62945.entry.js +0 -1
- package/dist/stripe-elements/p-c24ae181.entry.js +0 -1
- package/dist/stripe-elements/p-d9e86451.entry.js +0 -1
- package/dist/stripe-elements/p-f09c86a0.entry.js +0 -1
- package/dist/stripe-elements/p-f64f394d.entry.js +0 -1
- package/dist/stripe-elements/p-f6d2425e.entry.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Stripe, StripeElements, StripeCheckoutElementsSdk } from '@stripe/stripe-js';
|
|
1
|
+
import { Stripe, StripeElements, StripeElementsOptionsMode, StripeCheckoutElementsSdk } from '@stripe/stripe-js';
|
|
2
2
|
import type { IStripeService, StripeServiceState, CheckoutSessionOptions } from './interfaces';
|
|
3
3
|
/**
|
|
4
4
|
* Core Stripe Service
|
|
@@ -7,6 +7,11 @@ import type { IStripeService, StripeServiceState, CheckoutSessionOptions } from
|
|
|
7
7
|
*/
|
|
8
8
|
declare class StripeServiceClass implements IStripeService {
|
|
9
9
|
private store;
|
|
10
|
+
private intentClientSecret?;
|
|
11
|
+
/** Serialized `elementsOptions` of the last init, used to detect real changes */
|
|
12
|
+
private elementsOptionsKey?;
|
|
13
|
+
/** Incremented on every init so that a slower, older call cannot overwrite newer state */
|
|
14
|
+
private initGeneration;
|
|
10
15
|
private changeListeners;
|
|
11
16
|
/**
|
|
12
17
|
* Get the reactive state object
|
|
@@ -23,17 +28,21 @@ declare class StripeServiceClass implements IStripeService {
|
|
|
23
28
|
/**
|
|
24
29
|
* Initialize Stripe.js client with Payment Intent mode
|
|
25
30
|
* @param publishableKey - Your Stripe publishable API key
|
|
26
|
-
* @param options - Optional configuration
|
|
31
|
+
* @param options - Optional configuration. `clientSecret` is the PaymentIntent / SetupIntent client secret;
|
|
32
|
+
* `elementsOptions` (mode / amount / currency) is used to create Elements when there is no client secret.
|
|
33
|
+
* `clientSecret` takes priority when both are given.
|
|
27
34
|
*/
|
|
28
35
|
initialize(publishableKey: string, options?: {
|
|
29
36
|
stripeAccount?: string;
|
|
30
37
|
applicationName?: string;
|
|
38
|
+
clientSecret?: string;
|
|
39
|
+
elementsOptions?: StripeElementsOptionsMode;
|
|
31
40
|
}): Promise<void>;
|
|
32
41
|
/**
|
|
33
42
|
* Initialize Stripe.js client with Checkout Session mode
|
|
34
43
|
* @param publishableKey - Your Stripe publishable API key
|
|
35
44
|
* @param checkoutSessionClientSecret - The client secret from Checkout Session
|
|
36
|
-
* @param options - Optional configuration
|
|
45
|
+
* @param options - Optional configuration (`clientSecret` is the PaymentIntent / SetupIntent client secret)
|
|
37
46
|
*/
|
|
38
47
|
initializeWithCheckoutSession(publishableKey: string, checkoutSessionClientSecret: string, options?: {
|
|
39
48
|
stripeAccount?: string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the element can be reached with the Tab key.
|
|
3
|
+
* Elements hidden with `display: none` / `visibility: hidden` are excluded when the browser supports `checkVisibility()`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const isTabbable: (element: Element) => element is HTMLElement;
|
|
6
|
+
/**
|
|
7
|
+
* Collect tabbable elements under `root` in DOM order, following the composed (flattened) tree:
|
|
8
|
+
* open shadow roots are entered and `<slot>` elements are replaced by their assigned elements.
|
|
9
|
+
* Positive `tabindex` ordering is not taken into account.
|
|
10
|
+
*/
|
|
11
|
+
export declare const getTabbableElements: (root: Element | ShadowRoot) => HTMLElement[];
|
|
12
|
+
/**
|
|
13
|
+
* Return the focused element, descending into open shadow roots.
|
|
14
|
+
*/
|
|
15
|
+
export declare const getDeepActiveElement: (doc?: Document) => Element | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stripe-pwa-elements",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Framework-agnostic Stripe Payment Elements as Web Components",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
},
|
|
61
61
|
"license": "MIT",
|
|
62
62
|
"devDependencies": {
|
|
63
|
+
"@changesets/cli": "^3.0.3",
|
|
63
64
|
"@eslint/eslintrc": "^3.3.3",
|
|
64
65
|
"@eslint/js": "^9.39.2",
|
|
65
66
|
"@jsr/circleci__jest-circleci-coverage": "^0.4.0",
|
|
@@ -76,7 +77,6 @@
|
|
|
76
77
|
"jest": "^29.7.0",
|
|
77
78
|
"jest-cli": "^29.7.0",
|
|
78
79
|
"jest-junit": "^17.0.0",
|
|
79
|
-
"np": "^10.2.0",
|
|
80
80
|
"prettier": "^3.6.2",
|
|
81
81
|
"prettier-eslint": "^16.4.2",
|
|
82
82
|
"prettier-eslint-cli": "^8.0.1",
|
|
@@ -104,6 +104,8 @@
|
|
|
104
104
|
"format": "prettier --write src",
|
|
105
105
|
"example:copy": "stencil build --docs && cp -R dist/stripe-elements example/",
|
|
106
106
|
"example:serve": "pnpm dlx serve example",
|
|
107
|
-
"
|
|
107
|
+
"changeset": "changeset",
|
|
108
|
+
"changeset:version": "changeset version",
|
|
109
|
+
"changeset:publish": "pnpm run build && pnpm -F hono-stripe-elements run build && changeset publish"
|
|
108
110
|
}
|
|
109
111
|
}
|
package/readme.md
CHANGED
|
@@ -11,6 +11,18 @@ Framework-agnostic Stripe payment components built with Web Components. Works wi
|
|
|
11
11
|
> **Note:** The current npm package is **`stripe-pwa-elements`** (this repo).
|
|
12
12
|
> The old package `@stripe-elements/stripe-elements` (v2.0.2) is deprecated and superseded — please use `stripe-pwa-elements` instead.
|
|
13
13
|
|
|
14
|
+
## Try it first
|
|
15
|
+
|
|
16
|
+
[](https://codesandbox.io/p/devbox/github/hideokamoto/stripe-pwa-elements/tree/main/examples/codesandbox)
|
|
17
|
+
|
|
18
|
+
Open the live demo in CodeSandbox (Stripe test mode, no setup or API keys needed) before installing anything. The demo covers:
|
|
19
|
+
|
|
20
|
+
- `<stripe-card-element>` — card number / expiry / CVC with a PaymentIntent confirm flow
|
|
21
|
+
- `<stripe-address-element>` — billing address form
|
|
22
|
+
- `<stripe-express-checkout-element>` — Apple Pay / Google Pay / Link (device-dependent)
|
|
23
|
+
|
|
24
|
+
There is no `<stripe-payment-element>` demo yet. See [`examples/codesandbox`](examples/codesandbox) for details.
|
|
25
|
+
|
|
14
26
|
## Used in production
|
|
15
27
|
|
|
16
28
|
[](https://github.com/capacitor-community/stripe)
|
|
@@ -153,7 +165,7 @@ import 'stripe-pwa-elements/dist/components/stripe-payment-element';
|
|
|
153
165
|
|
|
154
166
|
This avoids the runtime dynamic import the lazy `loader` relies on, which can fail
|
|
155
167
|
with `Failed to fetch dynamically imported module` under Vite. See the
|
|
156
|
-
[Bundler Integration guide](https://stripe-pwa-elements-docs.workers.dev/en/guides/bundler-integration/)
|
|
168
|
+
[Bundler Integration guide](https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/en/guides/bundler-integration/)
|
|
157
169
|
for Vite/webpack/Rollup and Capacitor setup examples.
|
|
158
170
|
|
|
159
171
|
## Components
|
|
@@ -291,9 +303,9 @@ The documentation site publishes machine-readable plain-text files that AI codin
|
|
|
291
303
|
|
|
292
304
|
| File | Purpose |
|
|
293
305
|
| --- | --- |
|
|
294
|
-
| [`/llms.txt`](https://stripe-pwa-elements-docs.workers.dev/llms.txt) | Index — links to the full and compact documentation sets |
|
|
295
|
-
| [`/llms-full.txt`](https://stripe-pwa-elements-docs.workers.dev/llms-full.txt) | Full API reference for all components |
|
|
296
|
-
| [`/llms-small.txt`](https://stripe-pwa-elements-docs.workers.dev/llms-small.txt) | Compact version with non-essential content removed |
|
|
306
|
+
| [`/llms.txt`](https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/llms.txt) | Index — links to the full and compact documentation sets |
|
|
307
|
+
| [`/llms-full.txt`](https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/llms-full.txt) | Full API reference for all components |
|
|
308
|
+
| [`/llms-small.txt`](https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/llms-small.txt) | Compact version with non-essential content removed |
|
|
297
309
|
|
|
298
310
|
These files are generated automatically from the documentation source at build time using the [`starlight-llms-txt`](https://github.com/HiDeoo/starlight-llms-txt) plugin and always reflect the latest published docs.
|
|
299
311
|
|
|
@@ -308,22 +320,39 @@ See the [example/](./example) directory for complete working examples:
|
|
|
308
320
|
- [Address Element](./example/address-example.html) — Address collection
|
|
309
321
|
- [Express Checkout](./example/example-express-checkout.html) — Apple Pay, Google Pay, etc.
|
|
310
322
|
|
|
311
|
-
## Use with
|
|
323
|
+
## Use with coding agents (Agent Skill)
|
|
324
|
+
|
|
325
|
+
This repo ships an [Agent Skill](https://agentskills.io/specification) that teaches
|
|
326
|
+
coding agents how to integrate `stripe-pwa-elements` correctly — picking the right
|
|
327
|
+
component, wiring the publishable key + client secret, handling the
|
|
328
|
+
submit/confirm flow, and asking before anything that changes your Stripe account.
|
|
329
|
+
The skill lives in [`plugins/stripe-pwa-elements/skills/stripe-pwa-elements/`](./plugins/stripe-pwa-elements/skills/stripe-pwa-elements/SKILL.md).
|
|
312
330
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
331
|
+
Install it with the [`skills`](https://www.npmjs.com/package/skills) CLI:
|
|
332
|
+
|
|
333
|
+
```bash
|
|
334
|
+
npx skills add hideokamoto/stripe-pwa-elements
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
Or, in [Claude Code](https://claude.com/claude-code), install it as a plugin:
|
|
317
338
|
|
|
318
339
|
```text
|
|
319
340
|
/plugin marketplace add hideokamoto/stripe-pwa-elements
|
|
320
341
|
/plugin install stripe-pwa-elements@stripe-pwa-elements
|
|
321
342
|
```
|
|
322
343
|
|
|
323
|
-
Once installed, the skill activates automatically when Claude detects you are
|
|
344
|
+
Once installed in Claude Code, the skill activates automatically when Claude detects you are
|
|
324
345
|
working with the library, or you can invoke it explicitly with
|
|
325
346
|
`/stripe-pwa-elements:stripe-pwa-elements`.
|
|
326
347
|
|
|
348
|
+
The documentation site also serves the skill over HTTP, built from the same file:
|
|
349
|
+
|
|
350
|
+
| URL | Purpose |
|
|
351
|
+
| --- | --- |
|
|
352
|
+
| [`/skill.md`](https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/skill.md) | The skill's `SKILL.md` |
|
|
353
|
+
| [`/.well-known/agent-skills/index.json`](https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/.well-known/agent-skills/index.json) | Discovery index ([Agent Skills Discovery RFC](https://github.com/cloudflare/agent-skills-discovery-rfc), draft v0.2.0) with a SHA-256 digest per skill |
|
|
354
|
+
| [`/.well-known/agent-skills/stripe-pwa-elements/SKILL.md`](https://stripe-pwa-elements-docs.wp-kyoto.workers.dev/.well-known/agent-skills/stripe-pwa-elements/SKILL.md) | The skill at the path the discovery index points to |
|
|
355
|
+
|
|
327
356
|
## Contribution
|
|
328
357
|
|
|
329
358
|
### Getting Started
|
|
@@ -345,6 +374,13 @@ To run the unit tests for the components, run:
|
|
|
345
374
|
npm test
|
|
346
375
|
```
|
|
347
376
|
|
|
377
|
+
### Keep the Agent Skill up to date
|
|
378
|
+
|
|
379
|
+
When you add, rename or remove a component, or change its props, events, methods or how it is loaded,
|
|
380
|
+
update the Agent Skill in [`plugins/stripe-pwa-elements/skills/stripe-pwa-elements/`](./plugins/stripe-pwa-elements/skills/stripe-pwa-elements/)
|
|
381
|
+
in the same pull request. `src/agent-skill.unit.spec.ts` fails when the skill's component tags,
|
|
382
|
+
CDN bundle path or i18n languages no longer match the code.
|
|
383
|
+
|
|
348
384
|
## Security & PCI DSS SAQ-A
|
|
349
385
|
|
|
350
386
|
Card data **never** passes through this library's DOM, JavaScript state, or network requests.
|
|
@@ -1,431 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var index = require('./index-Dkb0SxZc.js');
|
|
4
|
-
|
|
5
|
-
let CACHED_MAP;
|
|
6
|
-
const getIconMap = () => {
|
|
7
|
-
if (typeof window === 'undefined') {
|
|
8
|
-
return new Map();
|
|
9
|
-
}
|
|
10
|
-
else {
|
|
11
|
-
if (!CACHED_MAP) {
|
|
12
|
-
const win = window;
|
|
13
|
-
win.Ionicons = win.Ionicons || {};
|
|
14
|
-
CACHED_MAP = win.Ionicons.map = win.Ionicons.map || new Map();
|
|
15
|
-
}
|
|
16
|
-
return CACHED_MAP;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
const getUrl = (i) => {
|
|
20
|
-
let url = getSrc(i.src);
|
|
21
|
-
if (url) {
|
|
22
|
-
return url;
|
|
23
|
-
}
|
|
24
|
-
url = getName(i.name, i.icon, i.mode, i.ios, i.md);
|
|
25
|
-
if (url) {
|
|
26
|
-
return getNamedUrl(url, i);
|
|
27
|
-
}
|
|
28
|
-
if (i.icon) {
|
|
29
|
-
url = getSrc(i.icon);
|
|
30
|
-
if (url) {
|
|
31
|
-
return url;
|
|
32
|
-
}
|
|
33
|
-
url = getSrc(i.icon[i.mode]);
|
|
34
|
-
if (url) {
|
|
35
|
-
return url;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return null;
|
|
39
|
-
};
|
|
40
|
-
const getNamedUrl = (iconName, iconEl) => {
|
|
41
|
-
const url = getIconMap().get(iconName);
|
|
42
|
-
if (url) {
|
|
43
|
-
return url;
|
|
44
|
-
}
|
|
45
|
-
try {
|
|
46
|
-
return index.getAssetPath(`svg/${iconName}.svg`);
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
console.log('e', e);
|
|
50
|
-
/**
|
|
51
|
-
* In the custom elements build version of ionicons, referencing an icon
|
|
52
|
-
* by name will throw an invalid URL error because the asset path is not defined.
|
|
53
|
-
* This catches that error and logs something that is more developer-friendly.
|
|
54
|
-
* We also include a reference to the ion-icon element so developers can
|
|
55
|
-
* figure out which instance of ion-icon needs to be updated.
|
|
56
|
-
*/
|
|
57
|
-
console.warn(`[Ionicons Warning]: Could not load icon with name "${iconName}". Ensure that the icon is registered using addIcons or that the icon SVG data is passed directly to the icon component.`, iconEl);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
const getName = (iconName, icon, mode, ios, md) => {
|
|
61
|
-
// default to "md" if somehow the mode wasn't set
|
|
62
|
-
mode = (mode && toLower(mode)) === 'ios' ? 'ios' : 'md';
|
|
63
|
-
// if an icon was passed in using the ios or md attributes
|
|
64
|
-
// set the iconName to whatever was passed in
|
|
65
|
-
if (ios && mode === 'ios') {
|
|
66
|
-
iconName = toLower(ios);
|
|
67
|
-
}
|
|
68
|
-
else if (md && mode === 'md') {
|
|
69
|
-
iconName = toLower(md);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
if (!iconName && icon && !isSrc(icon)) {
|
|
73
|
-
iconName = icon;
|
|
74
|
-
}
|
|
75
|
-
if (isStr(iconName)) {
|
|
76
|
-
iconName = toLower(iconName);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (!isStr(iconName) || iconName.trim() === '') {
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
// only allow alpha characters and dash
|
|
83
|
-
const invalidChars = iconName.replace(/[a-z]|-|\d/gi, '');
|
|
84
|
-
if (invalidChars !== '') {
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
87
|
-
return iconName;
|
|
88
|
-
};
|
|
89
|
-
const getSrc = (src) => {
|
|
90
|
-
if (isStr(src)) {
|
|
91
|
-
src = src.trim();
|
|
92
|
-
if (isSrc(src)) {
|
|
93
|
-
return src;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return null;
|
|
97
|
-
};
|
|
98
|
-
const isSrc = (str) => str.length > 0 && /(\/|\.)/.test(str);
|
|
99
|
-
const isStr = (val) => typeof val === 'string';
|
|
100
|
-
const toLower = (val) => val.toLowerCase();
|
|
101
|
-
/**
|
|
102
|
-
* Elements inside of web components sometimes need to inherit global attributes
|
|
103
|
-
* set on the host. For example, the inner input in `ion-input` should inherit
|
|
104
|
-
* the `title` attribute that developers set directly on `ion-input`. This
|
|
105
|
-
* helper function should be called in componentWillLoad and assigned to a variable
|
|
106
|
-
* that is later used in the render function.
|
|
107
|
-
*
|
|
108
|
-
* This does not need to be reactive as changing attributes on the host element
|
|
109
|
-
* does not trigger a re-render.
|
|
110
|
-
*/
|
|
111
|
-
const inheritAttributes = (el, attributes = []) => {
|
|
112
|
-
const attributeObject = {};
|
|
113
|
-
attributes.forEach((attr) => {
|
|
114
|
-
if (el.hasAttribute(attr)) {
|
|
115
|
-
const value = el.getAttribute(attr);
|
|
116
|
-
if (value !== null) {
|
|
117
|
-
attributeObject[attr] = el.getAttribute(attr);
|
|
118
|
-
}
|
|
119
|
-
el.removeAttribute(attr);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
return attributeObject;
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* Returns `true` if the document or host element
|
|
126
|
-
* has a `dir` set to `rtl`. The host value will always
|
|
127
|
-
* take priority over the root document value.
|
|
128
|
-
*/
|
|
129
|
-
const isRTL = (hostEl) => {
|
|
130
|
-
if (hostEl) {
|
|
131
|
-
if (hostEl.dir !== '') {
|
|
132
|
-
return hostEl.dir.toLowerCase() === 'rtl';
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return (document === null || document === void 0 ? void 0 : document.dir.toLowerCase()) === 'rtl';
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const validateContent = (svgContent) => {
|
|
139
|
-
const div = document.createElement('div');
|
|
140
|
-
div.innerHTML = svgContent;
|
|
141
|
-
// setup this way to ensure it works on our buddy IE
|
|
142
|
-
for (let i = div.childNodes.length - 1; i >= 0; i--) {
|
|
143
|
-
if (div.childNodes[i].nodeName.toLowerCase() !== 'svg') {
|
|
144
|
-
div.removeChild(div.childNodes[i]);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
// must only have 1 root element
|
|
148
|
-
const svgElm = div.firstElementChild;
|
|
149
|
-
if (svgElm && svgElm.nodeName.toLowerCase() === 'svg') {
|
|
150
|
-
const svgClass = svgElm.getAttribute('class') || '';
|
|
151
|
-
svgElm.setAttribute('class', (svgClass + ' s-ion-icon').trim());
|
|
152
|
-
// root element must be an svg
|
|
153
|
-
// lets double check we've got valid elements
|
|
154
|
-
// do not allow scripts
|
|
155
|
-
if (isValid(svgElm)) {
|
|
156
|
-
return div.innerHTML;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return '';
|
|
160
|
-
};
|
|
161
|
-
const isValid = (elm) => {
|
|
162
|
-
if (elm.nodeType === 1) {
|
|
163
|
-
if (elm.nodeName.toLowerCase() === 'script') {
|
|
164
|
-
return false;
|
|
165
|
-
}
|
|
166
|
-
for (let i = 0; i < elm.attributes.length; i++) {
|
|
167
|
-
const name = elm.attributes[i].name;
|
|
168
|
-
if (isStr(name) && name.toLowerCase().indexOf('on') === 0) {
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
for (let i = 0; i < elm.childNodes.length; i++) {
|
|
173
|
-
if (!isValid(elm.childNodes[i])) {
|
|
174
|
-
return false;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return true;
|
|
179
|
-
};
|
|
180
|
-
const isSvgDataUrl = (url) => url.startsWith('data:image/svg+xml');
|
|
181
|
-
const isEncodedDataUrl = (url) => url.indexOf(';utf8,') !== -1;
|
|
182
|
-
|
|
183
|
-
const ioniconContent = new Map();
|
|
184
|
-
const requests = new Map();
|
|
185
|
-
let parser;
|
|
186
|
-
/**
|
|
187
|
-
* Safely fallback to an empty svg
|
|
188
|
-
*/
|
|
189
|
-
function safeFallback(url) {
|
|
190
|
-
const svg = '';
|
|
191
|
-
ioniconContent.set(url, svg);
|
|
192
|
-
return svg;
|
|
193
|
-
}
|
|
194
|
-
const getSvgContent = (url, sanitize) => {
|
|
195
|
-
/**
|
|
196
|
-
* See if we already have a request for this url
|
|
197
|
-
*/
|
|
198
|
-
const req = requests.get(url);
|
|
199
|
-
if (req) {
|
|
200
|
-
return req;
|
|
201
|
-
}
|
|
202
|
-
if (typeof fetch !== 'undefined' && typeof document !== 'undefined') {
|
|
203
|
-
/**
|
|
204
|
-
* If the url is a data url of an svg, then try to parse it
|
|
205
|
-
* with the DOMParser. This works with content security policies enabled.
|
|
206
|
-
*/
|
|
207
|
-
if (isSvgDataUrl(url) && isEncodedDataUrl(url)) {
|
|
208
|
-
return Promise.resolve(getSvgByUrl(url));
|
|
209
|
-
}
|
|
210
|
-
return fetchSvg(url, sanitize);
|
|
211
|
-
}
|
|
212
|
-
return Promise.resolve(safeFallback(url));
|
|
213
|
-
};
|
|
214
|
-
function getSvgByUrl(url) {
|
|
215
|
-
if (!parser) {
|
|
216
|
-
/**
|
|
217
|
-
* Create an instance of the DOM parser. This creates a single
|
|
218
|
-
* parser instance for the entire app, which is more efficient.
|
|
219
|
-
*/
|
|
220
|
-
parser = new DOMParser();
|
|
221
|
-
}
|
|
222
|
-
const doc = parser.parseFromString(url, 'text/html');
|
|
223
|
-
const svg = doc.querySelector('svg');
|
|
224
|
-
if (svg) {
|
|
225
|
-
ioniconContent.set(url, svg.outerHTML);
|
|
226
|
-
return svg.outerHTML;
|
|
227
|
-
}
|
|
228
|
-
throw new Error(`Could not parse svg from ${url}`);
|
|
229
|
-
}
|
|
230
|
-
function fetchSvg(url, sanitize) {
|
|
231
|
-
/**
|
|
232
|
-
* We don't already have a request
|
|
233
|
-
*/
|
|
234
|
-
const req = fetch(url)
|
|
235
|
-
.then((rsp) => {
|
|
236
|
-
/**
|
|
237
|
-
* When fetching from a file:// URL, some browsers return
|
|
238
|
-
* a 0 status code even when the request succeeds so don't
|
|
239
|
-
* rely on rsp.ok as the only signal of success.
|
|
240
|
-
*/
|
|
241
|
-
return rsp
|
|
242
|
-
.text()
|
|
243
|
-
.then((svgContent) => {
|
|
244
|
-
if (svgContent && sanitize !== false) {
|
|
245
|
-
svgContent = validateContent(svgContent);
|
|
246
|
-
}
|
|
247
|
-
const svg = svgContent || '';
|
|
248
|
-
ioniconContent.set(url, svg);
|
|
249
|
-
return svg;
|
|
250
|
-
})
|
|
251
|
-
.catch(() => safeFallback(url));
|
|
252
|
-
})
|
|
253
|
-
.catch(() => safeFallback(url));
|
|
254
|
-
/**
|
|
255
|
-
* Cache for the same requests
|
|
256
|
-
*/
|
|
257
|
-
requests.set(url, req);
|
|
258
|
-
return req;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
const iconCss = () => `:host{display:inline-block;width:1em;height:1em;contain:strict;fill:currentColor;box-sizing:content-box !important}:host .ionicon{stroke:currentColor}.ionicon-fill-none{fill:none}.ionicon-stroke-width{stroke-width:var(--ionicon-stroke-width, 32px)}.icon-inner,.ionicon,svg{display:block;height:100%;width:100%}@supports (background: -webkit-named-image(i)){:host(.icon-rtl) .icon-inner{transform:scaleX(-1)}}@supports not selector(:dir(rtl)) and selector(:host-context([dir='rtl'])){:host(.icon-rtl) .icon-inner{transform:scaleX(-1)}}:host(.flip-rtl):host-context([dir='rtl']) .icon-inner{transform:scaleX(-1)}@supports selector(:dir(rtl)){:host(.flip-rtl:dir(rtl)) .icon-inner{transform:scaleX(-1)}:host(.flip-rtl:dir(ltr)) .icon-inner{transform:scaleX(1)}}:host(.icon-small){font-size:1.125rem !important}:host(.icon-large){font-size:2rem !important}:host(.ion-color){color:var(--ion-color-base) !important}:host(.ion-color-primary){--ion-color-base:var(--ion-color-primary, #3880ff)}:host(.ion-color-secondary){--ion-color-base:var(--ion-color-secondary, #0cd1e8)}:host(.ion-color-tertiary){--ion-color-base:var(--ion-color-tertiary, #f4a942)}:host(.ion-color-success){--ion-color-base:var(--ion-color-success, #10dc60)}:host(.ion-color-warning){--ion-color-base:var(--ion-color-warning, #ffce00)}:host(.ion-color-danger){--ion-color-base:var(--ion-color-danger, #f14141)}:host(.ion-color-light){--ion-color-base:var(--ion-color-light, #f4f5f8)}:host(.ion-color-medium){--ion-color-base:var(--ion-color-medium, #989aa2)}:host(.ion-color-dark){--ion-color-base:var(--ion-color-dark, #222428)}`;
|
|
262
|
-
|
|
263
|
-
const Icon = class {
|
|
264
|
-
constructor(hostRef) {
|
|
265
|
-
index.registerInstance(this, hostRef);
|
|
266
|
-
this.iconName = null;
|
|
267
|
-
this.inheritedAttributes = {};
|
|
268
|
-
this.didLoadIcon = false;
|
|
269
|
-
this.isVisible = false;
|
|
270
|
-
/**
|
|
271
|
-
* The mode determines which platform styles to use.
|
|
272
|
-
*/
|
|
273
|
-
this.mode = getIonMode();
|
|
274
|
-
/**
|
|
275
|
-
* If enabled, ion-icon will be loaded lazily when it's visible in the viewport.
|
|
276
|
-
* Default, `false`.
|
|
277
|
-
*/
|
|
278
|
-
this.lazy = false;
|
|
279
|
-
/**
|
|
280
|
-
* When set to `false`, SVG content that is HTTP fetched will not be checked
|
|
281
|
-
* if the response SVG content has any `<script>` elements, or any attributes
|
|
282
|
-
* that start with `on`, such as `onclick`.
|
|
283
|
-
* @default true
|
|
284
|
-
*/
|
|
285
|
-
this.sanitize = true;
|
|
286
|
-
}
|
|
287
|
-
componentWillLoad() {
|
|
288
|
-
this.inheritedAttributes = inheritAttributes(this.el, ['aria-label']);
|
|
289
|
-
}
|
|
290
|
-
connectedCallback() {
|
|
291
|
-
/**
|
|
292
|
-
* purposely do not return the promise here because loading
|
|
293
|
-
* the svg file should not hold up loading the app
|
|
294
|
-
* only load the svg if it's visible
|
|
295
|
-
*/
|
|
296
|
-
this.waitUntilVisible(this.el, '50px', () => {
|
|
297
|
-
this.isVisible = true;
|
|
298
|
-
this.loadIcon();
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Loads the icon after the component has finished rendering.
|
|
303
|
-
*/
|
|
304
|
-
componentDidLoad() {
|
|
305
|
-
/**
|
|
306
|
-
* Addresses an Angular issue where property values are assigned after the 'connectedCallback' but prior to the registration of watchers.
|
|
307
|
-
* This enhancement ensures the loading of an icon when the component has finished rendering and the icon has yet to apply the SVG data.
|
|
308
|
-
* This modification pertains to the usage of Angular's binding syntax:
|
|
309
|
-
* `<ion-icon [name]="myIconName"></ion-icon>`
|
|
310
|
-
*/
|
|
311
|
-
if (!this.didLoadIcon) {
|
|
312
|
-
this.loadIcon();
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Disconnect the IntersectionObserver.
|
|
317
|
-
*/
|
|
318
|
-
disconnectedCallback() {
|
|
319
|
-
if (this.io) {
|
|
320
|
-
this.io.disconnect();
|
|
321
|
-
this.io = undefined;
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
/**
|
|
325
|
-
* Wait until the icon is visible in the viewport.
|
|
326
|
-
* @param el - The element to observe.
|
|
327
|
-
* @param rootMargin - The root margin of the observer.
|
|
328
|
-
* @param cb - The callback to call when the element is visible.
|
|
329
|
-
*/
|
|
330
|
-
waitUntilVisible(el, rootMargin, cb) {
|
|
331
|
-
/**
|
|
332
|
-
* IntersectionObserver is a browser API that allows you to observe
|
|
333
|
-
* the visibility of an element relative to a root element. It is
|
|
334
|
-
* supported in all modern browsers, except IE and when server-side
|
|
335
|
-
* rendering.
|
|
336
|
-
*/
|
|
337
|
-
const hasIntersectionObserverSupport = Boolean(index.Build.isBrowser && this.lazy && typeof window !== 'undefined' && window.IntersectionObserver);
|
|
338
|
-
/**
|
|
339
|
-
* browser doesn't support IntersectionObserver
|
|
340
|
-
* so just fallback to always show it
|
|
341
|
-
*/
|
|
342
|
-
if (!hasIntersectionObserverSupport) {
|
|
343
|
-
return cb();
|
|
344
|
-
}
|
|
345
|
-
const io = (this.io = new window.IntersectionObserver((data) => {
|
|
346
|
-
if (data[0].isIntersecting) {
|
|
347
|
-
io.disconnect();
|
|
348
|
-
this.io = undefined;
|
|
349
|
-
cb();
|
|
350
|
-
}
|
|
351
|
-
}, { rootMargin }));
|
|
352
|
-
io.observe(el);
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Watch for changes to the icon name, src, icon, ios, or md properties.
|
|
356
|
-
* When a change is detected, the icon will be loaded.
|
|
357
|
-
*/
|
|
358
|
-
loadIcon() {
|
|
359
|
-
if (index.Build.isBrowser && this.isVisible) {
|
|
360
|
-
const url = getUrl(this);
|
|
361
|
-
if (url) {
|
|
362
|
-
if (ioniconContent.has(url)) {
|
|
363
|
-
// sync if it's already loaded
|
|
364
|
-
this.svgContent = ioniconContent.get(url);
|
|
365
|
-
}
|
|
366
|
-
else {
|
|
367
|
-
// async if it hasn't been loaded
|
|
368
|
-
getSvgContent(url, this.sanitize).then(() => (this.svgContent = ioniconContent.get(url)));
|
|
369
|
-
}
|
|
370
|
-
this.didLoadIcon = true;
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
this.iconName = getName(this.name, this.icon, this.mode, this.ios, this.md);
|
|
374
|
-
}
|
|
375
|
-
render() {
|
|
376
|
-
const { flipRtl, iconName, inheritedAttributes, el } = this;
|
|
377
|
-
const mode = this.mode || 'md';
|
|
378
|
-
/**
|
|
379
|
-
* we have designated that arrows & chevrons should automatically flip (unless flip-rtl
|
|
380
|
-
* is set to false) because "back" is left in ltr and right in rtl, and "forward" is the opposite
|
|
381
|
-
*/
|
|
382
|
-
const shouldAutoFlip = iconName
|
|
383
|
-
? (iconName.includes('arrow') || iconName.includes('chevron')) && flipRtl !== false
|
|
384
|
-
: false;
|
|
385
|
-
/**
|
|
386
|
-
* if shouldBeFlippable is true, the icon should change direction when `dir` changes
|
|
387
|
-
*/
|
|
388
|
-
const shouldBeFlippable = flipRtl || shouldAutoFlip;
|
|
389
|
-
return (index.h(index.Host, Object.assign({ key: '0578c899781ca145dd8205acd9670af39b57cf2e', role: "img", class: Object.assign(Object.assign({ [mode]: true }, createColorClasses(this.color)), { [`icon-${this.size}`]: !!this.size, 'flip-rtl': shouldBeFlippable, 'icon-rtl': shouldBeFlippable && isRTL(el) }) }, inheritedAttributes), index.Build.isBrowser && this.svgContent ? (index.h("div", { class: "icon-inner", innerHTML: this.svgContent })) : (index.h("div", { class: "icon-inner" }))));
|
|
390
|
-
}
|
|
391
|
-
static get assetsDirs() { return ["svg"]; }
|
|
392
|
-
get el() { return index.getElement(this); }
|
|
393
|
-
static get watchers() { return {
|
|
394
|
-
"name": [{
|
|
395
|
-
"loadIcon": 0
|
|
396
|
-
}],
|
|
397
|
-
"src": [{
|
|
398
|
-
"loadIcon": 0
|
|
399
|
-
}],
|
|
400
|
-
"icon": [{
|
|
401
|
-
"loadIcon": 0
|
|
402
|
-
}],
|
|
403
|
-
"ios": [{
|
|
404
|
-
"loadIcon": 0
|
|
405
|
-
}],
|
|
406
|
-
"md": [{
|
|
407
|
-
"loadIcon": 0
|
|
408
|
-
}]
|
|
409
|
-
}; }
|
|
410
|
-
};
|
|
411
|
-
/**
|
|
412
|
-
* Get the mode of the document.
|
|
413
|
-
* @returns The mode of the document.
|
|
414
|
-
*/
|
|
415
|
-
const getIonMode = () => (index.Build.isBrowser && typeof document !== 'undefined' && document.documentElement.getAttribute('mode')) || 'md';
|
|
416
|
-
/**
|
|
417
|
-
* Create color classes for the icon.
|
|
418
|
-
* @param color - The color of the icon.
|
|
419
|
-
* @returns The color classes for the icon.
|
|
420
|
-
*/
|
|
421
|
-
const createColorClasses = (color) => {
|
|
422
|
-
return color
|
|
423
|
-
? {
|
|
424
|
-
'ion-color': true,
|
|
425
|
-
[`ion-color-${color}`]: true,
|
|
426
|
-
}
|
|
427
|
-
: null;
|
|
428
|
-
};
|
|
429
|
-
Icon.style = iconCss();
|
|
430
|
-
|
|
431
|
-
exports.ion_icon = Icon;
|
package/dist/components/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const i=i=>Object.keys(c).filter((o=>c[o](i))),o=i=>!!d(i,/iPad/i)||!(!d(i,/Macintosh/i)||!e(i)),n=i=>d(i,/android|sink/i),e=i=>s(i,"(any-pointer:coarse)"),t=i=>r(i)||a(i),r=i=>!!(i.cordova||i.phonegap||i.PhoneGap),a=i=>{const o=i.Capacitor;return!(!o||!o.isNative)},d=(i,o)=>o.test(i.navigator.userAgent),s=(i,o)=>i.matchMedia(o).matches,c={ipad:o,iphone:i=>d(i,/iPhone/i),ios:i=>d(i,/iPhone|iPod/i)||o(i),android:n,phablet:i=>{const o=i.innerWidth,n=i.innerHeight,e=Math.min(o,n),t=Math.max(o,n);return e>390&&e<520&&t>620&&t<800},tablet:i=>{const e=i.innerWidth,t=i.innerHeight,r=Math.min(e,t),a=Math.max(e,t);return o(i)||(i=>n(i)&&!d(i,/mobile/i))(i)||r>460&&r<820&&a>780&&a<1400},cordova:r,capacitor:a,electron:i=>d(i,/electron/i),pwa:i=>!(!i.matchMedia("(display-mode: standalone)").matches&&!i.navigator.standalone),mobile:e,mobileweb:i=>e(i)&&!t(i),desktop:i=>!e(i),hybrid:t},l=()=>{const o=((o=window)=>{if(void 0===o)return[];o.Ionic=o.Ionic||{};let n=o.Ionic.platforms;return null==n&&(n=o.Ionic.platforms=i(o),n.forEach((i=>o.document.documentElement.classList.add(`plt-${i}`)))),n})(undefined);return o.includes("ios")?"ios":o.includes("android")?"android":void 0};export{l as c}
|