stripe-pwa-elements 4.0.1 → 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.
Files changed (100) hide show
  1. package/dist/cjs/factory-tenFFIul.js +1200 -0
  2. package/dist/cjs/{factory-Cd2VI_N2.js → i18n-FhEOc8vz.js} +6 -1149
  3. package/dist/cjs/ion-icon_2.cjs.entry.js +723 -0
  4. package/dist/cjs/loader.cjs.js +1 -1
  5. package/dist/cjs/stripe-address-element.cjs.entry.js +5 -4
  6. package/dist/cjs/stripe-card-element-modal.cjs.entry.js +3 -2
  7. package/dist/cjs/{stripe-card-element_2.cjs.entry.js → stripe-card-element.cjs.entry.js} +8 -93
  8. package/dist/cjs/stripe-currency-selector.cjs.entry.js +4 -3
  9. package/dist/cjs/stripe-elements.cjs.js +1 -1
  10. package/dist/cjs/stripe-express-checkout-element.cjs.entry.js +24 -5
  11. package/dist/cjs/stripe-link-authentication-element.cjs.entry.js +4 -3
  12. package/dist/cjs/stripe-payment-element.cjs.entry.js +12 -124
  13. package/dist/cjs/stripe-payment-element.helpers-DukP33RI.js +122 -0
  14. package/dist/cjs/stripe-payment-request-button.cjs.entry.js +2 -2
  15. package/dist/cjs/stripe-payment-sheet.cjs.entry.js +506 -0
  16. package/dist/collection/collection-manifest.json +2 -1
  17. package/dist/collection/components/stripe-card-element/stripe-card-element.js +3 -2
  18. package/dist/collection/components/stripe-card-element-modal/stripe-card-element-modal.js +4 -3
  19. package/dist/collection/components/stripe-express-checkout-element/stripe-express-checkout-element.js +18 -0
  20. package/dist/collection/components/stripe-modal/stripe-modal.css +23 -1
  21. package/dist/collection/components/stripe-modal/stripe-modal.js +130 -1
  22. package/dist/collection/components/stripe-payment-request-button/stripe-payment-request-button.js +3 -3
  23. package/dist/collection/components/stripe-payment-sheet/payment-sheet-state.js +179 -0
  24. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.css +68 -0
  25. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.helpers.js +90 -0
  26. package/dist/collection/components/stripe-payment-sheet/stripe-payment-sheet.js +544 -0
  27. package/dist/collection/services/express-checkout-element-manager.js +36 -2
  28. package/dist/collection/services/stripe-service.js +20 -6
  29. package/dist/collection/utils/focus.js +76 -0
  30. package/dist/collection/utils/i18n.js +6 -0
  31. package/dist/components/factory.js +1 -1
  32. package/dist/components/i18n.js +1 -0
  33. package/dist/components/stripe-address-element.js +1 -1
  34. package/dist/components/stripe-card-element-modal.js +1 -1
  35. package/dist/components/stripe-card-element2.js +1 -1
  36. package/dist/components/stripe-currency-selector.js +1 -1
  37. package/dist/components/stripe-express-checkout-element.js +1 -1
  38. package/dist/components/stripe-link-authentication-element.js +1 -1
  39. package/dist/components/stripe-modal2.js +1 -1
  40. package/dist/components/stripe-payment-element.helpers.js +1 -0
  41. package/dist/components/stripe-payment-element.js +1 -1
  42. package/dist/components/stripe-payment-request-button2.js +1 -1
  43. package/dist/components/stripe-payment-sheet.d.ts +11 -0
  44. package/dist/components/stripe-payment-sheet.js +1 -0
  45. package/dist/esm/factory-Cd6OGTWN.js +1198 -0
  46. package/dist/esm/{factory-VTa1Gc94.js → i18n-B6JoQetF.js} +7 -1149
  47. package/dist/esm/ion-icon_2.entry.js +720 -0
  48. package/dist/esm/loader.js +1 -1
  49. package/dist/esm/stripe-address-element.entry.js +2 -1
  50. package/dist/esm/stripe-card-element-modal.entry.js +3 -2
  51. package/dist/esm/{stripe-card-element_2.entry.js → stripe-card-element.entry.js} +6 -90
  52. package/dist/esm/stripe-currency-selector.entry.js +2 -1
  53. package/dist/esm/stripe-elements.js +1 -1
  54. package/dist/esm/stripe-express-checkout-element.entry.js +20 -1
  55. package/dist/esm/stripe-link-authentication-element.entry.js +2 -1
  56. package/dist/esm/stripe-payment-element.entry.js +4 -116
  57. package/dist/esm/stripe-payment-element.helpers-CipV87b8.js +117 -0
  58. package/dist/esm/stripe-payment-request-button.entry.js +2 -2
  59. package/dist/esm/stripe-payment-sheet.entry.js +504 -0
  60. package/dist/stripe-elements/{p-ae0c336e.entry.js → p-4891edf0.entry.js} +1 -1
  61. package/dist/stripe-elements/p-5338bc5e.entry.js +1 -0
  62. package/dist/stripe-elements/p-6a9c8b7a.entry.js +1 -0
  63. package/dist/stripe-elements/p-7fe4a287.entry.js +1 -0
  64. package/dist/stripe-elements/p-915b86ed.entry.js +1 -0
  65. package/dist/stripe-elements/p-B6JoQetF.js +1 -0
  66. package/dist/stripe-elements/p-C7MQk9FK.js +1 -0
  67. package/dist/stripe-elements/p-DFAhQS0n.js +1 -0
  68. package/dist/stripe-elements/p-b06a254f.entry.js +1 -0
  69. package/dist/stripe-elements/p-b91c4fa7.entry.js +1 -0
  70. package/dist/stripe-elements/p-ba791c8f.entry.js +1 -0
  71. package/dist/stripe-elements/p-e7372ca7.entry.js +1 -0
  72. package/dist/stripe-elements/p-f892e375.entry.js +1 -0
  73. package/dist/stripe-elements/stripe-elements.esm.js +1 -1
  74. package/dist/types/components/stripe-card-element/stripe-card-element.d.ts +2 -1
  75. package/dist/types/components/stripe-card-element-modal/stripe-card-element-modal.d.ts +2 -1
  76. package/dist/types/components/stripe-express-checkout-element/stripe-express-checkout-element.d.ts +5 -0
  77. package/dist/types/components/stripe-modal/stripe-modal.d.ts +43 -0
  78. package/dist/types/components/stripe-payment-request-button/stripe-payment-request-button.d.ts +1 -1
  79. package/dist/types/components/stripe-payment-sheet/payment-sheet-state.d.ts +104 -0
  80. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.d.ts +112 -0
  81. package/dist/types/components/stripe-payment-sheet/stripe-payment-sheet.helpers.d.ts +95 -0
  82. package/dist/types/components.d.ts +169 -10
  83. package/dist/types/index.d.ts +2 -0
  84. package/dist/types/services/interfaces.d.ts +1 -0
  85. package/dist/types/services/stripe-service.d.ts +7 -2
  86. package/dist/types/utils/focus.d.ts +15 -0
  87. package/package.json +5 -3
  88. package/readme.md +42 -6
  89. package/dist/cjs/ion-icon.cjs.entry.js +0 -431
  90. package/dist/components/utils.js +0 -1
  91. package/dist/esm/ion-icon.entry.js +0 -429
  92. package/dist/stripe-elements/p-1bd46766.entry.js +0 -1
  93. package/dist/stripe-elements/p-1c6e0a45.entry.js +0 -1
  94. package/dist/stripe-elements/p-3f42ca0c.entry.js +0 -1
  95. package/dist/stripe-elements/p-5cf62945.entry.js +0 -1
  96. package/dist/stripe-elements/p-74de1556.entry.js +0 -1
  97. package/dist/stripe-elements/p-76e57d78.entry.js +0 -1
  98. package/dist/stripe-elements/p-840d499f.entry.js +0 -1
  99. package/dist/stripe-elements/p-CrjrbGJ3.js +0 -1
  100. package/dist/stripe-elements/p-cfd8e081.entry.js +0 -1
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
+ [![Edit in CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](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
  [![capacitor-community/stripe](https://img.shields.io/badge/capacitor--community%2Fstripe-4000%2B%20weekly%20downloads-brightgreen)](https://github.com/capacitor-community/stripe)
@@ -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 Claude Code
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
- This repo ships a [Claude Code](https://claude.com/claude-code) skill that teaches
314
- the assistant how to integrate `stripe-pwa-elements` correctly — picking the right
315
- component, wiring the publishable key + client secret, and handling the
316
- submit/confirm flow. Install it as a plugin:
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;
@@ -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}