progressive-share-button 1.0.0-alpha.5 → 1.0.0-alpha.7
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/CHANGELOG.md +16 -0
- package/README.md +11 -6
- package/dist/progressive-share-button.es.js +26 -22
- package/dist/progressive-share-button.umd.js +3 -3
- package/package.json +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [1.0.0-alpha.7] - 2023-02-27
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Added `CHANGELOG.md` file. Sorry for the delay on this one, if you've been watching this as it has gone through development. I'll try to keep this up to date from now on. We're still in an alpha state, so breaking changes will still happen, but I will document them here.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- Changed: (breaking change) the import statement now initialized the web component without needing to call the imported function.
|
package/README.md
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
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 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
|
|
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
7
|
## Basic Usage
|
|
8
8
|
|
|
9
|
-
The most basic usage of the component is to
|
|
9
|
+
The most basic usage of the component is to use no attributes. The component will share the current page's URL.
|
|
10
10
|
|
|
11
11
|
```html
|
|
12
|
-
|
|
12
|
+
<progressive-share-button />
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
You may also pass the URL to be shared. The component will share the URL that has been specified.
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<progressive-share-button url="https://example.com" />
|
|
13
19
|
```
|
|
14
20
|
|
|
15
21
|
This will render one of the following, depending on the device and browser. This example shows the Windows sharing icon, the Android sharing icon, and the iOS sharing icon.
|
|
@@ -33,11 +39,10 @@ npm install progressive-share-button
|
|
|
33
39
|
```
|
|
34
40
|
|
|
35
41
|
main.js, if installed with npm
|
|
42
|
+
|
|
36
43
|
```javascript
|
|
37
44
|
// Import the component, which is the default export, so no curly braces are needed.
|
|
38
45
|
import ProgressiveShareButton from 'progressive-share-button';
|
|
39
|
-
// Initialie the component
|
|
40
|
-
ProgressiveShareButton();
|
|
41
46
|
```
|
|
42
47
|
|
|
43
48
|
### Customizing the component name
|
|
@@ -47,7 +52,7 @@ If you want to customize the component name, you can import the element class di
|
|
|
47
52
|
|
|
48
53
|
```javascript
|
|
49
54
|
import { ProgressiveShareButtonElement } from 'progressive-share-button';
|
|
50
|
-
//
|
|
55
|
+
// Initialize the component
|
|
51
56
|
customElements.define('my-share-button', ProgressiveShareButtonElement);
|
|
52
57
|
|
|
53
58
|
```
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
class u extends HTMLElement {
|
|
2
2
|
constructor() {
|
|
3
3
|
super(), this.attachShadow({ mode: "open" }), this.iconSize = () => {
|
|
4
|
-
const
|
|
5
|
-
return o(
|
|
4
|
+
const s = this.getAttribute("icon-size") ?? "";
|
|
5
|
+
return o(s) ? s + "px" : s || 24 + "px";
|
|
6
6
|
};
|
|
7
|
-
function o(
|
|
8
|
-
return /^-?\d+$/.test(
|
|
7
|
+
function o(s) {
|
|
8
|
+
return /^-?\d+$/.test(s);
|
|
9
9
|
}
|
|
10
10
|
typeof navigator.share == "function" || a(this.getAttribute("debug")) ? this.shadowRoot && (this.shadowRoot.innerHTML = `
|
|
11
11
|
<style>
|
|
@@ -30,23 +30,23 @@ class u extends HTMLElement {
|
|
|
30
30
|
</style>
|
|
31
31
|
<button part="shareButton">
|
|
32
32
|
<slot>
|
|
33
|
-
${
|
|
33
|
+
${f()}
|
|
34
34
|
</slot>
|
|
35
35
|
</button>`, this.addEventListener("click", this.share)) : console.warn("ProgressiveShareButton disabled due to lack of Web Share API support on this browser.");
|
|
36
36
|
}
|
|
37
37
|
share() {
|
|
38
|
-
const o = a(this.getAttribute("debug")),
|
|
39
|
-
let
|
|
40
|
-
n && (
|
|
41
|
-
text: `${
|
|
42
|
-
});
|
|
38
|
+
const o = a(this.getAttribute("debug")), s = a(this.getAttribute("smart-share")), n = this.getAttribute("url");
|
|
39
|
+
let r = this.getAttribute("text"), i = this.getAttribute("title"), t = {};
|
|
40
|
+
n && (t.url = n), r && (t.text = r), i && (t.title = i), s && (i && i.slice(-1) !== "." && (i = i + "."), r && r.slice(-1) !== "." && (r = r + "."), t = {
|
|
41
|
+
text: `${i ? i + " " : ""}${r ? r + " " : ""}${n || ""}`
|
|
42
|
+
}), !t.url && !t.text && !t.title && (t.url = window.location.href);
|
|
43
43
|
let c = new CustomEvent("progressive-share-success", {
|
|
44
44
|
bubbles: !0,
|
|
45
45
|
cancelable: !1,
|
|
46
46
|
composed: !0,
|
|
47
|
-
detail:
|
|
47
|
+
detail: t
|
|
48
48
|
});
|
|
49
|
-
navigator.share ? o == 1 ? console.debug("data to be shared",
|
|
49
|
+
navigator.share ? o == 1 ? console.debug("data to be shared", t) : navigator.share(t).then(() => {
|
|
50
50
|
this.dispatchEvent(c);
|
|
51
51
|
}).catch((l) => {
|
|
52
52
|
let h = new CustomEvent(
|
|
@@ -59,10 +59,10 @@ class u extends HTMLElement {
|
|
|
59
59
|
}
|
|
60
60
|
);
|
|
61
61
|
this.dispatchEvent(h);
|
|
62
|
-
}) : console.debug("data to be shared",
|
|
62
|
+
}) : console.debug("data to be shared", t);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function d() {
|
|
66
66
|
return typeof navigator.share == "function" ? console.log(
|
|
67
67
|
"ProgressiveShareButton support initialized. <progressive-share-success /> element now available"
|
|
68
68
|
) : console.log(
|
|
@@ -72,38 +72,42 @@ function b() {
|
|
|
72
72
|
u
|
|
73
73
|
), !0;
|
|
74
74
|
}
|
|
75
|
-
const
|
|
75
|
+
const v = '<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>', g = '<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>', p = '<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>', w = () => {
|
|
76
76
|
const e = navigator.userAgent;
|
|
77
77
|
return /iPhone|iPad|iPod/.test(e) ? "iOS" : /Android/.test(e) ? "Android" : /Windows/.test(e) ? "Windows" : /Mac/.test(e) ? "Mac" : "Unknown";
|
|
78
|
-
},
|
|
79
|
-
switch (
|
|
78
|
+
}, f = () => {
|
|
79
|
+
switch (w()) {
|
|
80
80
|
case "iOS":
|
|
81
81
|
case "Mac":
|
|
82
|
-
return d;
|
|
83
|
-
case "Android":
|
|
84
82
|
return v;
|
|
83
|
+
case "Android":
|
|
84
|
+
return g;
|
|
85
85
|
case "Windows":
|
|
86
86
|
case "Unknown":
|
|
87
87
|
default:
|
|
88
|
-
return
|
|
88
|
+
return p;
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
91
|
function a(e) {
|
|
92
92
|
var o;
|
|
93
|
+
if (!e)
|
|
94
|
+
return !1;
|
|
93
95
|
switch ((o = e == null ? void 0 : e.toLowerCase()) == null ? void 0 : o.trim()) {
|
|
94
96
|
case "true":
|
|
95
97
|
case "1":
|
|
96
98
|
return !0;
|
|
97
99
|
case "false":
|
|
98
100
|
case "0":
|
|
99
|
-
case null:
|
|
100
|
-
case void 0:
|
|
101
101
|
return !1;
|
|
102
102
|
default:
|
|
103
103
|
return JSON.parse(e);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
|
+
const b = (() => {
|
|
107
|
+
d();
|
|
108
|
+
})();
|
|
106
109
|
export {
|
|
110
|
+
d as ProgressiveShareButton,
|
|
107
111
|
u as ProgressiveShareButtonElement,
|
|
108
112
|
b as default
|
|
109
113
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(s,n){typeof exports=="object"&&typeof module<"u"?n(exports):typeof define=="function"&&define.amd?define(["exports"],n):(s=typeof globalThis<"u"?globalThis:s||self,n(s["progressive-share-button"]={}))})(this,function(s){"use strict";class n extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.iconSize=()=>{const i=this.getAttribute("icon-size")??"";return a(i)?i+"px":i||24+"px"};function a(i){return/^-?\d+$/.test(i)}typeof navigator.share=="function"||l(this.getAttribute("debug"))?this.shadowRoot&&(this.shadowRoot.innerHTML=`
|
|
2
2
|
<style>
|
|
3
3
|
:host {
|
|
4
4
|
display: inline-block;
|
|
@@ -21,6 +21,6 @@
|
|
|
21
21
|
</style>
|
|
22
22
|
<button part="shareButton">
|
|
23
23
|
<slot>
|
|
24
|
-
${
|
|
24
|
+
${f()}
|
|
25
25
|
</slot>
|
|
26
|
-
</button>`,this.addEventListener("click",this.share)):console.warn("ProgressiveShareButton disabled due to lack of Web Share API support on this browser.")}share(){const a=l(this.getAttribute("debug")),
|
|
26
|
+
</button>`,this.addEventListener("click",this.share)):console.warn("ProgressiveShareButton disabled due to lack of Web Share API support on this browser.")}share(){const a=l(this.getAttribute("debug")),i=l(this.getAttribute("smart-share")),c=this.getAttribute("url");let r=this.getAttribute("text"),o=this.getAttribute("title"),t={};c&&(t.url=c),r&&(t.text=r),o&&(t.title=o),i&&(o&&o.slice(-1)!=="."&&(o=o+"."),r&&r.slice(-1)!=="."&&(r=r+"."),t={text:`${o?o+" ":""}${r?r+" ":""}${c||""}`}),!t.url&&!t.text&&!t.title&&(t.url=window.location.href);let w=new CustomEvent("progressive-share-success",{bubbles:!0,cancelable:!1,composed:!0,detail:t});navigator.share?a==1?console.debug("data to be shared",t):navigator.share(t).then(()=>{this.dispatchEvent(w)}).catch(b=>{let m=new CustomEvent("progressive-share-fail",{bubbles:!0,cancelable:!1,composed:!0,detail:b});this.dispatchEvent(m)}):console.debug("data to be shared",t)}}function h(){return typeof navigator.share=="function"?console.log("ProgressiveShareButton support initialized. <progressive-share-success /> element now available"):console.log("ProgressiveShareButton support initialized. This browser does not have Web Share API support support."),customElements.define("progressive-share-button",n),!0}const u='<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>',d='<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>',v='<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=()=>{const e=navigator.userAgent;return/iPhone|iPad|iPod/.test(e)?"iOS":/Android/.test(e)?"Android":/Windows/.test(e)?"Windows":/Mac/.test(e)?"Mac":"Unknown"},f=()=>{switch(g()){case"iOS":case"Mac":return u;case"Android":return d;case"Windows":case"Unknown":default:return v}};function l(e){var a;if(!e)return!1;switch((a=e==null?void 0:e.toLowerCase())==null?void 0:a.trim()){case"true":case"1":return!0;case"false":case"0":return!1;default:return JSON.parse(e)}}const p=(()=>{h()})();s.ProgressiveShareButton=h,s.ProgressiveShareButtonElement=n,s.default=p,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|