progressive-share-button 1.0.0-alpha.1 → 1.0.0-alpha.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/README.md CHANGED
@@ -1,17 +1,9 @@
1
1
  # Progressive Share Button
2
2
 
3
- The _Progressive Share Button_ web component is a simple way to add a share button to your web page. The button will only be displayed if the browser supports the [Web Share API](https://w3c.github.io/web-share/).
3
+ The _Progressive Share Button_ web component is a simple way to add a share button to your web page that will show the user the OS native share options using the [Web Share API](https://w3c.github.io/web-share/). The "progressive" part of the name comes from the fact that the component will only display the share button if the browser supports the Web Share API. If the browser does not support the Web Share API, the component will not display anything.
4
4
 
5
5
  The web component is a wrapper around the [Web Share API](https://w3c.github.io/web-share/) that attempts to display a share icon appropriate to the user's device with icons that will be recognizable to iOS/Mac, Android and Windows. If the device type can't be determined, the component will display a Windows share icon.
6
6
 
7
- ## Limitations
8
-
9
- The [Web Share API](https://w3c.github.io/web-share/), while still in draft, has wide support on mobile. Desktop support is decent on Windows. Mac support works in Safari, but lags on third-party browsers. Check [caniuse/web-share](https://caniuse.com/web-share) for the most up-to-date information on its progress.
10
-
11
- The component will only display the share button if the browser supports the Web Share API. If the browser does not support the Web Share API, the component will not display anything.
12
-
13
- _Progressive Share Button_ does not support the sharing of files.
14
-
15
7
  ## Basic Usage
16
8
 
17
9
  The most basic usage of the component is to pass the URL to be shared. The component will render a share icon that will open the native share dialog when clicked.
@@ -24,6 +16,14 @@ This will render one of the following, depending on the device and browser. This
24
16
 
25
17
  ![Basic Example](./img/button-examples.png)
26
18
 
19
+ ## Limitations
20
+
21
+ The [Web Share API](https://w3c.github.io/web-share/), while still in draft, has wide support on mobile. Desktop support is decent on Windows. Mac support works in Safari, but lags on third-party browsers. Check [caniuse/web-share](https://caniuse.com/web-share) for the most up-to-date information on its progress.
22
+
23
+ The component will only display the share button if the browser supports the Web Share API. If the browser does not support the Web Share API, the component will not display anything.
24
+
25
+ _Progressive Share Button_ does not support the sharing of files.
26
+
27
27
  ## Installation as a module
28
28
 
29
29
  Run the following command to install it.
@@ -40,10 +40,10 @@ customElements.define('progressive-share-button', ProgressiveShareButton);
40
40
 
41
41
  ### CDN
42
42
 
43
- https://unpkg.com/ info to come
43
+ You can also use the component directly from a CDN. The component is available on [unpkg](https://unpkg.com/progressive-share-button).
44
44
 
45
45
  ```html
46
- <script src="https://unpkg.com/TBD/progressive-share-button"></script>
46
+ <script src="https://unpkg.com/progressive-share-button"></script>
47
47
  ```
48
48
 
49
49
  ## Customizing the Component
@@ -55,14 +55,30 @@ The component accepts the following attributes:
55
55
  | title | string | null | The title of the page to be shared. |
56
56
  | text | string | null | The text string to be shared. |
57
57
  | url | string | null | The URL to be shared. |
58
- | smart-share | boolean | false | Accepts 0, false, 1, or true. If true, the component concatenate the title, text, and url into a single string. See the [_Why use smart-share_](#why-use-smart-share) section below for more information. |
58
+ | smart-share | boolean | false | Accepts 0, false, 1, or true. If true, the component concatenate the title, text, and url into a single string. See the [_Why use smart-share_](#why-use-the-smart-share-feature) section below for more information. |
59
59
  | icon-size | string or int | 24 | The size of the SVG share icon. The icon is rendered in a square. If an integer is passed, the component assumes the value is given in pixels, 24 becomes "24px", but you may also pass a string with a valid CSS size, like "1rem". |
60
- | debug | boolean | false | Accepts 0, false, 1, or true. If true is passed, the share icon will be displayed even if the Web Share API is not supported in the browser. The share behavior will *not* open the share dialog but, but instead will pass the data to be shared to the console for debugging. |
60
+ | debug | boolean | false | Accepts 0, false, 1, or true. If true is passed, the share icon will be displayed even if the Web Share API is not supported in the browser. The share behavior will *not* open the share dialog but, but instead will pass the data to be shared to the console for debugging. No custom events will be fired. |
61
61
  ## Styling
62
62
 
63
63
  The component uses the [Shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM) to encapsulate the styles. This means that the styles are not inherited by the parent page. To style the component, you must use the [::part()](https://developer.mozilla.org/en-US/docs/Web/CSS/::part) pseudo-element. There are two parts that can be styled: `shareButton` and `shareIcon`.
64
64
 
65
- ### shareButton
65
+ The basic Shadow DOM strutcture of the component is as follows:
66
+
67
+ ```html
68
+ <progressive-share-button>
69
+ <button part="shareButton">
70
+ <slot>
71
+ <svg part="shareIcon">
72
+ <!-- content of SVG here -->
73
+ </svg>
74
+ </slot>
75
+ </button>
76
+ </progressive-share-button>
77
+ ```
78
+
79
+ If you place style directly on the component, i.e., the _progressive-share-button_ element, you may have unintended visual glitches on devices that would normally not display the share button. For example, if you place a background color and padding on the component, the background color will be displayed on devices that do not support the Web Share API.
80
+
81
+ ### The _shareButton_ part
66
82
 
67
83
  The `shareButton` part is the button that is displayed when the Web Share API is supported. The button is a [button](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button) element. The button has the following default styles:
68
84
 
@@ -76,7 +92,7 @@ button {
76
92
  }
77
93
  ```
78
94
 
79
- ### shareIcon
95
+ ### The _shareIcon_ part
80
96
 
81
97
  The `shareIcon` part is the icon that is displayed when the Web Share API is supported. The icon is an [svg](https://developer.mozilla.org/en-US/docs/Web/SVG) element. The icon has the following default styles:
82
98
 
@@ -89,18 +105,23 @@ svg {
89
105
  }
90
106
  ```
91
107
 
92
- ## Usage Examples
108
+ ## Usage examples
93
109
 
94
- ### Basic Usage
110
+ ### Basic usage
111
+
112
+ As shown earlier, the most basic usage of the component is to pass the URL to be shared. You may also pass the title and text to be shared.
95
113
 
96
- As shown earlier, the most basic usage of the component is to pass the URL to be shared.
97
114
  ```
98
115
  <progressive-share-button url="https://example.com" />
116
+
117
+ <progressive-share-button title="Example.com" url="https://example.com" />
118
+
119
+ <progressive-share-button title="Example.com" text="The example.com URL is a useful placehold during web development." url="https://example.com" />
99
120
  ```
100
121
 
101
- ### Usage with Text
122
+ ### Replacing the share icon with text
102
123
 
103
- You can replace the share icon with text by inserting text into the component's slot. The following example replaces the share icon with the text "Share this link". The text is styled with the `text-share-example-1` class using using the [::part()](https://developer.mozilla.org/en-US/docs/Web/CSS/::part) pseudo-element named `shareButton`.
124
+ You can replace the share icon with text by inserting text into the component's slot. The following example replaces the share icon with the text "Share this link". The text is styled using the [::part()](https://developer.mozilla.org/en-US/docs/Web/CSS/::part) pseudo-element named `shareButton` to apply the updated style to the button. This example also shows how you can target the component by assigning the `text-share-example-1` class to the element.
104
125
 
105
126
  ```
106
127
  <progressive-share-button url="https://example.com" class="text-share-example-1">Share this link</progressive-share-button>
@@ -114,18 +135,17 @@ progressive-share-button.text-share-example-1::part(shareButton) {
114
135
  </style>
115
136
  ```
116
137
 
117
- ### Advanced Usage with Options
138
+ ### Advanced usage with options
118
139
 
119
- In the following example,
140
+ In the following example, the component is assigned the `text-share-example-2` class. The component is styled using the [::part()](https://developer.mozilla.org/en-US/docs/Web/CSS/::part) pseudo-element named `shareIcon` to apply the updated style to the icon. The component is also assigned the `smart-share` attribute to pass the title, text, and url as a single string to the Web Share API. The icon will be displayed at 20 pixels wide and high.
120
141
 
121
142
  ```
122
143
  <progressive-share-button
123
- title="Progressive Share Button Web Component"
124
- text="Check out this cool web component that creates a share button that will only be displayed if the browser supports the Web Share API."
144
+ title="Example.com"
145
+ text="The example.com URL is a useful placehold during web development."
125
146
  url="https://example.com"
126
147
  smart-share=1
127
- icon-size="20"
128
- debug=0
148
+ icon-size=20
129
149
  class="text-share-example-2"
130
150
  />
131
151
 
@@ -137,9 +157,9 @@ progressive-share-button.text-share-example-2::part(shareIcon) {
137
157
  }
138
158
  ```
139
159
 
140
- ## Why use smart-share
160
+ ## Why use the "smart-share" feature?
141
161
 
142
- The Web Share API requires that the data to be shared be passed as an object with the following optional properties:
162
+ The _smart-share_ feature is an attempt to address a situation that might be viewed as a bug in the implementation of the Web Share API on some platforms. The Web Share API requires that the data to be shared be passed as an object with the following optional properties:
143
163
 
144
164
  * title
145
165
  * text
@@ -157,7 +177,7 @@ The _Progressive Share Button_ web component by default simply passes your data
157
177
 
158
178
  The problem is that when multiple properties are passed as separate properties what actually gets shared doesn't always include all the pieces of data you pass into the API. Some devices and applications receiving the data object will only share a single property, most often the URL in my tests.
159
179
 
160
- If have `smart-share` set to true, the component will concatenate all of the data into a single string and pass it to the Web Share API as text. The `title` and `text` will have a period added at the end of the string if it is not present. This will allow the data to be shared on any device or application that supports sharing text. The data will be shared as a single string, like this:
180
+ If `smart-share` attribute is true, the component will concatenate all of the data into a single string and pass it to the Web Share API as text. The `title` and `text` will have a period added at the end of the string if it is not present. This will allow the data to be shared on any device or application that supports sharing text. The data will be shared as a single string, like this:
161
181
 
162
182
  ```
163
183
  {
@@ -169,11 +189,32 @@ The following link lets you test the Web Share API on your devices to make a mor
169
189
 
170
190
  https://w3c.github.io/web-share/demos/share-files.html
171
191
 
172
- ## Demo
192
+ ## Custom events
173
193
 
174
- Demo to come.
194
+ There are two custom event emitted by the component: `progressive-share-success` and `progressive-share-fail`.
195
+
196
+ | Event name | Description |
197
+ | --- | --- |
198
+ | `progressive-share-success` | Emitted when the Web Share API is supported and the data is successfully shared. |
199
+ | `progressive-share-fail` | Emitted when the Web Share API is supported but the data is not successfully shared. This is typically emitted when a user opens the share dialog box but exits out of it without sharing. |
200
+
201
+
202
+
203
+ ```javascript
204
+ // example of listening for the custom events
205
+ document.addEventListener('progressive-share-success', (e) => {
206
+ // e.detail contains the share data that was shared
207
+ console.log('The progressive-share event was heard.', e.detail);
208
+ });
209
+ document.addEventListener('progressive-share-fail', (e) => {
210
+ // e.detail contains the error message
211
+ console.log('The progressive-share-fail event was heard.', e.detail);
212
+ });
213
+ ```
214
+
215
+ ## Demo
175
216
 
176
- ~~[https://johnfmorton.github.io/progressive-share-button/](https://johnfmorton.github.io/progressive-share-button/)~~
217
+ [https://johnfmorton.github.io/progressive-share-button/](https://johnfmorton.github.io/progressive-share-button/)
177
218
 
178
219
  ## License
179
220
 
@@ -1,70 +1,87 @@
1
- class g extends HTMLElement {
1
+ class p extends HTMLElement {
2
2
  constructor() {
3
3
  super(), this.attachShadow({ mode: "open" }), this.iconSize = () => {
4
4
  const e = this.getAttribute("icon-size");
5
- return i(e) ? e + "px" : e || 24 + "px";
5
+ return c(e) ? e + "px" : e || 24 + "px";
6
6
  };
7
- function i(e) {
7
+ function c(e) {
8
8
  return /^-?\d+$/.test(e);
9
9
  }
10
- (navigator.share || c(this.getAttribute("debug"))) && (this.shadowRoot.innerHTML = `
11
- <style>
12
- :host {
13
- display: inline-block;
14
- cursor: pointer;
15
- }
16
- svg {
17
- width: ${this.iconSize()};
18
- height: ${this.iconSize()};
19
- fill: currentColor;
20
- vertical-align: bottom;
21
- }
22
- button {
23
- background: none;
24
- border: none;
25
- padding: 1px 2px 1px 2px;
26
- margin: 0;
27
- cursor: pointer;
28
- }
29
- :host(:hover) {
30
- }
31
- </style>
32
- <button part="shareButton">
33
- <slot>
34
- ${d()}
35
- </slot>
36
- </button>
10
+ (navigator.share || o(this.getAttribute("debug"))) && (this.shadowRoot.innerHTML = `
11
+ <style>
12
+ :host {
13
+ display: inline-block;
14
+ cursor: pointer;
15
+ }
16
+ svg {
17
+ width: ${this.iconSize()};
18
+ height: ${this.iconSize()};
19
+ fill: currentColor;
20
+ vertical-align: bottom;
21
+ }
22
+ button {
23
+ all: unset;
24
+ padding: 1px 2px 1px 2px;
25
+ margin: 0;
26
+ cursor: pointer;
27
+ }
28
+ :host(:hover) {
29
+ }
30
+ </style>
31
+ <button part="shareButton">
32
+ <slot>
33
+ ${w()}
34
+ </slot>
35
+ </button>
37
36
  `, this.addEventListener("click", this.share));
38
37
  }
39
38
  share() {
40
- const i = c(this.getAttribute("debug")), e = c(this.getAttribute("smart-share")), n = this.getAttribute("url");
41
- let s = this.getAttribute("text"), r = this.getAttribute("title"), o = {};
42
- n && (o.url = n), s && (o.text = s), r && (o.title = r), e && (r && r.slice(-1) !== "." && (r = r + "."), s && s.slice(-1) !== "." && (s = s + "."), o = {
39
+ const c = o(this.getAttribute("debug")), e = o(this.getAttribute("smart-share")), n = this.getAttribute("url");
40
+ let s = this.getAttribute("text"), r = this.getAttribute("title"), i = {};
41
+ n && (i.url = n), s && (i.text = s), r && (i.title = r), e && (r && r.slice(-1) !== "." && (r = r + "."), s && s.slice(-1) !== "." && (s = s + "."), i = {
43
42
  text: `${r ? r + " " : ""}${s ? s + " " : ""}${n || ""}`
44
- }), navigator.share ? i == 1 ? console.debug("data to be shared", o) : navigator.share(o).then(() => {
45
- console.log("Thanks for sharing!");
46
- }).catch(console.error) : console.debug("data to be shared", o);
43
+ });
44
+ let h = new CustomEvent("progressive-share-success", {
45
+ bubbles: !0,
46
+ cancelable: !1,
47
+ composed: !0,
48
+ detail: i
49
+ });
50
+ navigator.share ? c == 1 ? console.debug("data to be shared", i) : navigator.share(i).then(() => {
51
+ this.dispatchEvent(h);
52
+ }).catch((l) => {
53
+ let u = new CustomEvent(
54
+ "progressive-share-fail",
55
+ {
56
+ bubbles: !0,
57
+ cancelable: !1,
58
+ composed: !0,
59
+ detail: l
60
+ }
61
+ );
62
+ this.dispatchEvent(u);
63
+ }) : console.debug("data to be shared", i);
47
64
  }
48
65
  }
49
- const h = () => '<svg xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 84.53 108.43" class="icon"><title>Share icon</title><desc>Square with upward arrow</desc><path d="m76.21,33.15h-23.38v5.28h23.38c1.72,0,3.04,1.32,3.04,2.91v58.77c0,1.58-1.32,2.91-3.04,2.91H8.32c-1.72,0-3.04-1.32-3.04-2.9v-58.64c0-1.58,1.32-2.91,3.04-2.91h20.74v-5.28H8.32c-4.62,0-8.32,3.7-8.32,8.19v58.77c0,4.49,3.7,8.19,8.32,8.19h67.88c4.62,0,8.32-3.7,8.32-8.19v-58.77c0-4.62-3.7-8.32-8.32-8.32h0Z"/><path d="m39.62,8.58v69.21h5.28V8.58l13.6,10.04,3.17-4.23L42.26,0l-19.41,14.4,3.17,4.23,13.6-10.04Z"/></svg>', l = () => '<svg id="b" xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 18.19 21.46" class="icon"><title>Share icon</title><desc>Circle with smaller circles radiating out</desc><g id="c"><path d="m15.1,15.29c-.89,0-1.7.38-2.28.98l-6.98-3.84c.24-.43.38-.94.38-1.49s-.14-1.03-.38-1.49l7.22-4.03c.55.48,1.25.77,2.04.77,1.7,0,3.1-1.39,3.1-3.1s-1.39-3.1-3.1-3.1-3.1,1.39-3.1,3.1c0,.67.22,1.27.58,1.78l-7.18,4.01c-.58-.62-1.39-1.03-2.3-1.03-1.7,0-3.1,1.39-3.1,3.1s1.39,3.1,3.1,3.1c.91,0,1.73-.41,2.3-1.03l6.98,3.84c-.26.46-.41.96-.41,1.51,0,1.7,1.39,3.1,3.1,3.1s3.1-1.39,3.1-3.1-1.37-3.07-3.07-3.07h0Zm0-14.54c1.32,0,2.38,1.08,2.38,2.38s-1.08,2.38-2.38,2.38-2.38-1.08-2.38-2.38,1.06-2.38,2.38-2.38ZM3.1,13.32c-1.32,0-2.38-1.08-2.38-2.38s1.08-2.38,2.38-2.38,2.38,1.08,2.38,2.38-1.06,2.38-2.38,2.38Zm12,7.44c-1.32,0-2.38-1.08-2.38-2.38s1.08-2.38,2.38-2.38,2.38,1.08,2.38,2.38-1.08,2.38-2.38,2.38Z"/></g></svg>', a = () => '<svg id="b" xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 112.98 100.64" class="icon" ><title>Share icon</title><desc>Square with arrow coming out to the right</desc><g id="c"><path d="m80.68,16.3l22.7,22.65-22.7,22.64v-11.44h-6.78c-18.27,0-33.35,6.91-43.25,13.14,2.34-12.07,7.94-21.2,16.75-27.16,10.12-6.84,22.02-7.83,26.67-7.94l6.6-.15v-11.73M73.93,0v21.43c-12.15.29-51.56,5.17-51.27,56.46,0,0,21.02-20.94,51.27-20.98v20.98l39.05-38.98L73.93,0ZM0,28.24v72.39h86.95v-20.98l-6.6,6.61v7.26H8.12V28.24H0Z"/></g></svg>', u = () => {
66
+ const d = () => '<svg xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 84.53 108.43" class="icon"><title>Share icon</title><desc>Square with upward arrow</desc><path d="m76.21,33.15h-23.38v5.28h23.38c1.72,0,3.04,1.32,3.04,2.91v58.77c0,1.58-1.32,2.91-3.04,2.91H8.32c-1.72,0-3.04-1.32-3.04-2.9v-58.64c0-1.58,1.32-2.91,3.04-2.91h20.74v-5.28H8.32c-4.62,0-8.32,3.7-8.32,8.19v58.77c0,4.49,3.7,8.19,8.32,8.19h67.88c4.62,0,8.32-3.7,8.32-8.19v-58.77c0-4.62-3.7-8.32-8.32-8.32h0Z"/><path d="m39.62,8.58v69.21h5.28V8.58l13.6,10.04,3.17-4.23L42.26,0l-19.41,14.4,3.17,4.23,13.6-10.04Z"/></svg>', v = () => '<svg id="b" xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 18.19 21.46" class="icon"><title>Share icon</title><desc>Circle with smaller circles radiating out</desc><g id="c"><path d="m15.1,15.29c-.89,0-1.7.38-2.28.98l-6.98-3.84c.24-.43.38-.94.38-1.49s-.14-1.03-.38-1.49l7.22-4.03c.55.48,1.25.77,2.04.77,1.7,0,3.1-1.39,3.1-3.1s-1.39-3.1-3.1-3.1-3.1,1.39-3.1,3.1c0,.67.22,1.27.58,1.78l-7.18,4.01c-.58-.62-1.39-1.03-2.3-1.03-1.7,0-3.1,1.39-3.1,3.1s1.39,3.1,3.1,3.1c.91,0,1.73-.41,2.3-1.03l6.98,3.84c-.26.46-.41.96-.41,1.51,0,1.7,1.39,3.1,3.1,3.1s3.1-1.39,3.1-3.1-1.37-3.07-3.07-3.07h0Zm0-14.54c1.32,0,2.38,1.08,2.38,2.38s-1.08,2.38-2.38,2.38-2.38-1.08-2.38-2.38,1.06-2.38,2.38-2.38ZM3.1,13.32c-1.32,0-2.38-1.08-2.38-2.38s1.08-2.38,2.38-2.38,2.38,1.08,2.38,2.38-1.06,2.38-2.38,2.38Zm12,7.44c-1.32,0-2.38-1.08-2.38-2.38s1.08-2.38,2.38-2.38,2.38,1.08,2.38,2.38-1.08,2.38-2.38,2.38Z"/></g></svg>', a = () => '<svg id="b" xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 112.98 100.64" class="icon" ><title>Share icon</title><desc>Square with arrow coming out to the right</desc><g id="c"><path d="m80.68,16.3l22.7,22.65-22.7,22.64v-11.44h-6.78c-18.27,0-33.35,6.91-43.25,13.14,2.34-12.07,7.94-21.2,16.75-27.16,10.12-6.84,22.02-7.83,26.67-7.94l6.6-.15v-11.73M73.93,0v21.43c-12.15.29-51.56,5.17-51.27,56.46,0,0,21.02-20.94,51.27-20.98v20.98l39.05-38.98L73.93,0ZM0,28.24v72.39h86.95v-20.98l-6.6,6.61v7.26H8.12V28.24H0Z"/></g></svg>', g = () => {
50
67
  const t = navigator.userAgent;
51
68
  return /iPhone|iPad|iPod/.test(t) ? "iOS" : /Android/.test(t) ? "Android" : /_whichIcon/.test(t) ? "Windows" : /Mac/.test(t) ? "Mac" : "Unknown";
52
- }, d = (t) => {
53
- switch (u()) {
69
+ }, w = (t) => {
70
+ switch (g()) {
54
71
  case "iOS":
55
72
  case "Mac":
56
- return h();
73
+ return d();
57
74
  case "Android":
58
- return l();
75
+ return v();
59
76
  case "Windows":
60
77
  return a();
61
78
  default:
62
79
  return a();
63
80
  }
64
81
  };
65
- function c(t) {
66
- var i;
67
- switch ((i = t == null ? void 0 : t.toLowerCase()) == null ? void 0 : i.trim()) {
82
+ function o(t) {
83
+ var c;
84
+ switch ((c = t == null ? void 0 : t.toLowerCase()) == null ? void 0 : c.trim()) {
68
85
  case "true":
69
86
  case "1":
70
87
  return !0;
@@ -78,5 +95,5 @@ function c(t) {
78
95
  }
79
96
  }
80
97
  export {
81
- g as default
98
+ p as default
82
99
  };
@@ -1,28 +1,27 @@
1
- (function(o,c){typeof exports=="object"&&typeof module<"u"?module.exports=c():typeof define=="function"&&define.amd?define(c):(o=typeof globalThis<"u"?globalThis:o||self,o["progressive-share-button"]=c())})(this,function(){"use strict";class o extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.iconSize=()=>{const e=this.getAttribute("icon-size");return i(e)?e+"px":e||24+"px"};function i(e){return/^-?\d+$/.test(e)}(navigator.share||h(this.getAttribute("debug")))&&(this.shadowRoot.innerHTML=`
2
- <style>
3
- :host {
4
- display: inline-block;
5
- cursor: pointer;
6
- }
7
- svg {
8
- width: ${this.iconSize()};
9
- height: ${this.iconSize()};
10
- fill: currentColor;
11
- vertical-align: bottom;
12
- }
13
- button {
14
- background: none;
15
- border: none;
16
- padding: 1px 2px 1px 2px;
17
- margin: 0;
18
- cursor: pointer;
19
- }
20
- :host(:hover) {
21
- }
22
- </style>
23
- <button part="shareButton">
24
- <slot>
25
- ${g()}
26
- </slot>
27
- </button>
28
- `,this.addEventListener("click",this.share))}share(){const i=h(this.getAttribute("debug")),e=h(this.getAttribute("smart-share")),a=this.getAttribute("url");let s=this.getAttribute("text"),r=this.getAttribute("title"),n={};a&&(n.url=a),s&&(n.text=s),r&&(n.title=r),e&&(r&&r.slice(-1)!=="."&&(r=r+"."),s&&s.slice(-1)!=="."&&(s=s+"."),n={text:`${r?r+" ":""}${s?s+" ":""}${a||""}`}),navigator.share?i==1?console.debug("data to be shared",n):navigator.share(n).then(()=>{console.log("Thanks for sharing!")}).catch(console.error):console.debug("data to be shared",n)}}const c=()=>'<svg xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 84.53 108.43" class="icon"><title>Share icon</title><desc>Square with upward arrow</desc><path d="m76.21,33.15h-23.38v5.28h23.38c1.72,0,3.04,1.32,3.04,2.91v58.77c0,1.58-1.32,2.91-3.04,2.91H8.32c-1.72,0-3.04-1.32-3.04-2.9v-58.64c0-1.58,1.32-2.91,3.04-2.91h20.74v-5.28H8.32c-4.62,0-8.32,3.7-8.32,8.19v58.77c0,4.49,3.7,8.19,8.32,8.19h67.88c4.62,0,8.32-3.7,8.32-8.19v-58.77c0-4.62-3.7-8.32-8.32-8.32h0Z"/><path d="m39.62,8.58v69.21h5.28V8.58l13.6,10.04,3.17-4.23L42.26,0l-19.41,14.4,3.17,4.23,13.6-10.04Z"/></svg>',u=()=>'<svg id="b" xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 18.19 21.46" class="icon"><title>Share icon</title><desc>Circle with smaller circles radiating out</desc><g id="c"><path d="m15.1,15.29c-.89,0-1.7.38-2.28.98l-6.98-3.84c.24-.43.38-.94.38-1.49s-.14-1.03-.38-1.49l7.22-4.03c.55.48,1.25.77,2.04.77,1.7,0,3.1-1.39,3.1-3.1s-1.39-3.1-3.1-3.1-3.1,1.39-3.1,3.1c0,.67.22,1.27.58,1.78l-7.18,4.01c-.58-.62-1.39-1.03-2.3-1.03-1.7,0-3.1,1.39-3.1,3.1s1.39,3.1,3.1,3.1c.91,0,1.73-.41,2.3-1.03l6.98,3.84c-.26.46-.41.96-.41,1.51,0,1.7,1.39,3.1,3.1,3.1s3.1-1.39,3.1-3.1-1.37-3.07-3.07-3.07h0Zm0-14.54c1.32,0,2.38,1.08,2.38,2.38s-1.08,2.38-2.38,2.38-2.38-1.08-2.38-2.38,1.06-2.38,2.38-2.38ZM3.1,13.32c-1.32,0-2.38-1.08-2.38-2.38s1.08-2.38,2.38-2.38,2.38,1.08,2.38,2.38-1.06,2.38-2.38,2.38Zm12,7.44c-1.32,0-2.38-1.08-2.38-2.38s1.08-2.38,2.38-2.38,2.38,1.08,2.38,2.38-1.08,2.38-2.38,2.38Z"/></g></svg>',l=()=>'<svg id="b" xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 112.98 100.64" class="icon" ><title>Share icon</title><desc>Square with arrow coming out to the right</desc><g id="c"><path d="m80.68,16.3l22.7,22.65-22.7,22.64v-11.44h-6.78c-18.27,0-33.35,6.91-43.25,13.14,2.34-12.07,7.94-21.2,16.75-27.16,10.12-6.84,22.02-7.83,26.67-7.94l6.6-.15v-11.73M73.93,0v21.43c-12.15.29-51.56,5.17-51.27,56.46,0,0,21.02-20.94,51.27-20.98v20.98l39.05-38.98L73.93,0ZM0,28.24v72.39h86.95v-20.98l-6.6,6.61v7.26H8.12V28.24H0Z"/></g></svg>',d=()=>{const t=navigator.userAgent;return/iPhone|iPad|iPod/.test(t)?"iOS":/Android/.test(t)?"Android":/_whichIcon/.test(t)?"Windows":/Mac/.test(t)?"Mac":"Unknown"},g=t=>{switch(d()){case"iOS":case"Mac":return c();case"Android":return u();case"Windows":return l();default:return l()}};function h(t){var i;switch((i=t==null?void 0:t.toLowerCase())==null?void 0:i.trim()){case"true":case"1":return!0;case"false":case"0":case null:case void 0:return!1;default:return JSON.parse(t)}}return o});
1
+ (function(o,c){typeof exports=="object"&&typeof module<"u"?module.exports=c():typeof define=="function"&&define.amd?define(c):(o=typeof globalThis<"u"?globalThis:o||self,o["progressive-share-button"]=c())})(this,function(){"use strict";class o extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.iconSize=()=>{const t=this.getAttribute("icon-size");return n(t)?t+"px":t||24+"px"};function n(t){return/^-?\d+$/.test(t)}(navigator.share||h(this.getAttribute("debug")))&&(this.shadowRoot.innerHTML=`
2
+ <style>
3
+ :host {
4
+ display: inline-block;
5
+ cursor: pointer;
6
+ }
7
+ svg {
8
+ width: ${this.iconSize()};
9
+ height: ${this.iconSize()};
10
+ fill: currentColor;
11
+ vertical-align: bottom;
12
+ }
13
+ button {
14
+ all: unset;
15
+ padding: 1px 2px 1px 2px;
16
+ margin: 0;
17
+ cursor: pointer;
18
+ }
19
+ :host(:hover) {
20
+ }
21
+ </style>
22
+ <button part="shareButton">
23
+ <slot>
24
+ ${v()}
25
+ </slot>
26
+ </button>
27
+ `,this.addEventListener("click",this.share))}share(){const n=h(this.getAttribute("debug")),t=h(this.getAttribute("smart-share")),a=this.getAttribute("url");let s=this.getAttribute("text"),i=this.getAttribute("title"),r={};a&&(r.url=a),s&&(r.text=s),i&&(r.title=i),t&&(i&&i.slice(-1)!=="."&&(i=i+"."),s&&s.slice(-1)!=="."&&(s=s+"."),r={text:`${i?i+" ":""}${s?s+" ":""}${a||""}`});let g=new CustomEvent("progressive-share-success",{bubbles:!0,cancelable:!1,composed:!0,detail:r});navigator.share?n==1?console.debug("data to be shared",r):navigator.share(r).then(()=>{this.dispatchEvent(g)}).catch(p=>{let f=new CustomEvent("progressive-share-fail",{bubbles:!0,cancelable:!1,composed:!0,detail:p});this.dispatchEvent(f)}):console.debug("data to be shared",r)}}const c=()=>'<svg xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 84.53 108.43" class="icon"><title>Share icon</title><desc>Square with upward arrow</desc><path d="m76.21,33.15h-23.38v5.28h23.38c1.72,0,3.04,1.32,3.04,2.91v58.77c0,1.58-1.32,2.91-3.04,2.91H8.32c-1.72,0-3.04-1.32-3.04-2.9v-58.64c0-1.58,1.32-2.91,3.04-2.91h20.74v-5.28H8.32c-4.62,0-8.32,3.7-8.32,8.19v58.77c0,4.49,3.7,8.19,8.32,8.19h67.88c4.62,0,8.32-3.7,8.32-8.19v-58.77c0-4.62-3.7-8.32-8.32-8.32h0Z"/><path d="m39.62,8.58v69.21h5.28V8.58l13.6,10.04,3.17-4.23L42.26,0l-19.41,14.4,3.17,4.23,13.6-10.04Z"/></svg>',u=()=>'<svg id="b" xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 18.19 21.46" class="icon"><title>Share icon</title><desc>Circle with smaller circles radiating out</desc><g id="c"><path d="m15.1,15.29c-.89,0-1.7.38-2.28.98l-6.98-3.84c.24-.43.38-.94.38-1.49s-.14-1.03-.38-1.49l7.22-4.03c.55.48,1.25.77,2.04.77,1.7,0,3.1-1.39,3.1-3.1s-1.39-3.1-3.1-3.1-3.1,1.39-3.1,3.1c0,.67.22,1.27.58,1.78l-7.18,4.01c-.58-.62-1.39-1.03-2.3-1.03-1.7,0-3.1,1.39-3.1,3.1s1.39,3.1,3.1,3.1c.91,0,1.73-.41,2.3-1.03l6.98,3.84c-.26.46-.41.96-.41,1.51,0,1.7,1.39,3.1,3.1,3.1s3.1-1.39,3.1-3.1-1.37-3.07-3.07-3.07h0Zm0-14.54c1.32,0,2.38,1.08,2.38,2.38s-1.08,2.38-2.38,2.38-2.38-1.08-2.38-2.38,1.06-2.38,2.38-2.38ZM3.1,13.32c-1.32,0-2.38-1.08-2.38-2.38s1.08-2.38,2.38-2.38,2.38,1.08,2.38,2.38-1.06,2.38-2.38,2.38Zm12,7.44c-1.32,0-2.38-1.08-2.38-2.38s1.08-2.38,2.38-2.38,2.38,1.08,2.38,2.38-1.08,2.38-2.38,2.38Z"/></g></svg>',l=()=>'<svg id="b" xmlns="http://www.w3.org/2000/svg" part="shareIcon" viewBox="0 0 112.98 100.64" class="icon" ><title>Share icon</title><desc>Square with arrow coming out to the right</desc><g id="c"><path d="m80.68,16.3l22.7,22.65-22.7,22.64v-11.44h-6.78c-18.27,0-33.35,6.91-43.25,13.14,2.34-12.07,7.94-21.2,16.75-27.16,10.12-6.84,22.02-7.83,26.67-7.94l6.6-.15v-11.73M73.93,0v21.43c-12.15.29-51.56,5.17-51.27,56.46,0,0,21.02-20.94,51.27-20.98v20.98l39.05-38.98L73.93,0ZM0,28.24v72.39h86.95v-20.98l-6.6,6.61v7.26H8.12V28.24H0Z"/></g></svg>',d=()=>{const e=navigator.userAgent;return/iPhone|iPad|iPod/.test(e)?"iOS":/Android/.test(e)?"Android":/_whichIcon/.test(e)?"Windows":/Mac/.test(e)?"Mac":"Unknown"},v=e=>{switch(d()){case"iOS":case"Mac":return c();case"Android":return u();case"Windows":return l();default:return l()}};function h(e){var n;switch((n=e==null?void 0:e.toLowerCase())==null?void 0:n.trim()){case"true":case"1":return!0;case"false":case"0":case null:case void 0:return!1;default:return JSON.parse(e)}}return o});
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "progressive-share-button",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.2",
4
4
  "description": "A web componet that creates a OS-native share button.",
5
- "files":["dist"],
6
- "main":"./dist/progressive-share-button.umd.js",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "./dist/progressive-share-button.umd.js",
7
9
  "repository": {
8
10
  "type": "git",
9
11
  "url": "https://github.com/johnfmorton/progressive-share-button"
10
12
  },
11
- "module":"./dist/progressive-share-button.es.js",
13
+ "module": "./es/progressive-share-button.es.js",
12
14
  "exports": {
13
15
  ".": {
14
16
  "import": "./dist/progressive-share-button.es.js",