progressive-share-button 1.0.0-alpha.7 → 1.0.0-alpha.8

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 CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.0-alpha.8] - 2023-02-27
9
+
10
+ ### Changed
11
+
12
+ - Turned off minification for production builds because module will be ultimately be bundled with the application using the module and minification will be handled by the application's build process.
13
+
8
14
  ## [1.0.0-alpha.7] - 2023-02-27
9
15
 
10
16
  ### Added
@@ -1,13 +1,23 @@
1
- class u extends HTMLElement {
1
+ class ProgressiveShareButtonElement extends HTMLElement {
2
2
  constructor() {
3
- super(), this.attachShadow({ mode: "open" }), this.iconSize = () => {
4
- const s = this.getAttribute("icon-size") ?? "";
5
- return o(s) ? s + "px" : s || 24 + "px";
3
+ super();
4
+ this.attachShadow({ mode: "open" });
5
+ this.iconSize = () => {
6
+ const size = this.getAttribute("icon-size") ?? "";
7
+ if (_isNumeric(size)) {
8
+ return size + "px";
9
+ } else if (size) {
10
+ return size;
11
+ } else {
12
+ return 24 + "px";
13
+ }
6
14
  };
7
- function o(s) {
8
- return /^-?\d+$/.test(s);
15
+ function _isNumeric(value) {
16
+ return /^-?\d+$/.test(value);
9
17
  }
10
- typeof navigator.share == "function" || a(this.getAttribute("debug")) ? this.shadowRoot && (this.shadowRoot.innerHTML = `
18
+ if (typeof navigator.share === "function" || _getBoolean(this.getAttribute("debug"))) {
19
+ if (this.shadowRoot) {
20
+ this.shadowRoot.innerHTML = `
11
21
  <style>
12
22
  :host {
13
23
  display: inline-block;
@@ -30,84 +40,143 @@ class u extends HTMLElement {
30
40
  </style>
31
41
  <button part="shareButton">
32
42
  <slot>
33
- ${f()}
43
+ ${_whichIcon()}
34
44
  </slot>
35
- </button>`, this.addEventListener("click", this.share)) : console.warn("ProgressiveShareButton disabled due to lack of Web Share API support on this browser.");
45
+ </button>`;
46
+ this.addEventListener("click", this.share);
47
+ }
48
+ } else {
49
+ console.warn("ProgressiveShareButton disabled due to lack of Web Share API support on this browser.");
50
+ }
36
51
  }
37
52
  share() {
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
- let c = new CustomEvent("progressive-share-success", {
44
- bubbles: !0,
45
- cancelable: !1,
46
- composed: !0,
47
- detail: t
53
+ const debug = _getBoolean(this.getAttribute("debug"));
54
+ const smartShare = _getBoolean(this.getAttribute("smart-share"));
55
+ const url = this.getAttribute("url");
56
+ let text = this.getAttribute("text");
57
+ let title = this.getAttribute("title");
58
+ let data = {};
59
+ if (url) {
60
+ data.url = url;
61
+ }
62
+ if (text) {
63
+ data.text = text;
64
+ }
65
+ if (title) {
66
+ data.title = title;
67
+ }
68
+ if (smartShare) {
69
+ if (title && title.slice(-1) !== ".") {
70
+ title = title + ".";
71
+ }
72
+ if (text && text.slice(-1) !== ".") {
73
+ text = text + ".";
74
+ }
75
+ data = {
76
+ text: `${title ? title + " " : ""}${text ? text + " " : ""}${url ? url : ""}`
77
+ };
78
+ }
79
+ if (!data.url && !data.text && !data.title) {
80
+ data.url = window.location.href;
81
+ }
82
+ let shareEvent = new CustomEvent("progressive-share-success", {
83
+ bubbles: true,
84
+ cancelable: false,
85
+ composed: true,
86
+ detail: data
48
87
  });
49
- navigator.share ? o == 1 ? console.debug("data to be shared", t) : navigator.share(t).then(() => {
50
- this.dispatchEvent(c);
51
- }).catch((l) => {
52
- let h = new CustomEvent(
53
- "progressive-share-fail",
54
- {
55
- bubbles: !0,
56
- cancelable: !1,
57
- composed: !0,
58
- detail: l
59
- }
60
- );
61
- this.dispatchEvent(h);
62
- }) : console.debug("data to be shared", t);
88
+ if (navigator.share) {
89
+ if (debug == 1) {
90
+ console.debug("data to be shared", data);
91
+ } else {
92
+ navigator.share(data).then(() => {
93
+ this.dispatchEvent(shareEvent);
94
+ }).catch((e) => {
95
+ let shareEventFail = new CustomEvent(
96
+ "progressive-share-fail",
97
+ {
98
+ bubbles: true,
99
+ cancelable: false,
100
+ composed: true,
101
+ detail: e
102
+ }
103
+ );
104
+ this.dispatchEvent(shareEventFail);
105
+ });
106
+ }
107
+ } else {
108
+ console.debug("data to be shared", data);
109
+ }
63
110
  }
64
111
  }
65
- function d() {
66
- return typeof navigator.share == "function" ? console.log(
67
- "ProgressiveShareButton support initialized. <progressive-share-success /> element now available"
68
- ) : console.log(
69
- "ProgressiveShareButton support initialized. This browser does not have Web Share API support support."
70
- ), customElements.define(
112
+ function ProgressiveShareButton() {
113
+ if (typeof navigator.share === "function") {
114
+ console.log(
115
+ "ProgressiveShareButton support initialized. <progressive-share-success /> element now available"
116
+ );
117
+ } else {
118
+ console.log(
119
+ "ProgressiveShareButton support initialized. This browser does not have Web Share API support support."
120
+ );
121
+ }
122
+ customElements.define(
71
123
  "progressive-share-button",
72
- u
73
- ), !0;
124
+ ProgressiveShareButtonElement
125
+ );
126
+ return true;
74
127
  }
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
- const e = navigator.userAgent;
77
- return /iPhone|iPad|iPod/.test(e) ? "iOS" : /Android/.test(e) ? "Android" : /Windows/.test(e) ? "Windows" : /Mac/.test(e) ? "Mac" : "Unknown";
78
- }, f = () => {
79
- switch (w()) {
128
+ const iosShareIcon = '<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>';
129
+ const androidShareIcon = '<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>';
130
+ const winShareIcon = '<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>';
131
+ const _guessOs = () => {
132
+ const userAgent = navigator.userAgent;
133
+ if (/iPhone|iPad|iPod/.test(userAgent)) {
134
+ return "iOS";
135
+ } else if (/Android/.test(userAgent)) {
136
+ return "Android";
137
+ } else if (/Windows/.test(userAgent)) {
138
+ return "Windows";
139
+ } else if (/Mac/.test(userAgent)) {
140
+ return "Mac";
141
+ } else {
142
+ return "Unknown";
143
+ }
144
+ };
145
+ const _whichIcon = () => {
146
+ const os = _guessOs();
147
+ switch (os) {
80
148
  case "iOS":
81
149
  case "Mac":
82
- return v;
150
+ return iosShareIcon;
83
151
  case "Android":
84
- return g;
152
+ return androidShareIcon;
85
153
  case "Windows":
86
154
  case "Unknown":
87
155
  default:
88
- return p;
156
+ return winShareIcon;
89
157
  }
90
158
  };
91
- function a(e) {
92
- var o;
93
- if (!e)
94
- return !1;
95
- switch ((o = e == null ? void 0 : e.toLowerCase()) == null ? void 0 : o.trim()) {
159
+ function _getBoolean(stringValue) {
160
+ var _a;
161
+ if (!stringValue) {
162
+ return false;
163
+ }
164
+ switch ((_a = stringValue == null ? void 0 : stringValue.toLowerCase()) == null ? void 0 : _a.trim()) {
96
165
  case "true":
97
166
  case "1":
98
- return !0;
167
+ return true;
99
168
  case "false":
100
169
  case "0":
101
- return !1;
170
+ return false;
102
171
  default:
103
- return JSON.parse(e);
172
+ return JSON.parse(stringValue);
104
173
  }
105
174
  }
106
- const b = (() => {
107
- d();
175
+ const main = (() => {
176
+ ProgressiveShareButton();
108
177
  })();
109
178
  export {
110
- d as ProgressiveShareButton,
111
- u as ProgressiveShareButtonElement,
112
- b as default
179
+ ProgressiveShareButton,
180
+ ProgressiveShareButtonElement,
181
+ main as default
113
182
  };
@@ -1,4 +1,27 @@
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=`
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["progressive-share-button"] = {}));
3
+ })(this, function(exports2) {
4
+ "use strict";
5
+ class ProgressiveShareButtonElement extends HTMLElement {
6
+ constructor() {
7
+ super();
8
+ this.attachShadow({ mode: "open" });
9
+ this.iconSize = () => {
10
+ const size = this.getAttribute("icon-size") ?? "";
11
+ if (_isNumeric(size)) {
12
+ return size + "px";
13
+ } else if (size) {
14
+ return size;
15
+ } else {
16
+ return 24 + "px";
17
+ }
18
+ };
19
+ function _isNumeric(value) {
20
+ return /^-?\d+$/.test(value);
21
+ }
22
+ if (typeof navigator.share === "function" || _getBoolean(this.getAttribute("debug"))) {
23
+ if (this.shadowRoot) {
24
+ this.shadowRoot.innerHTML = `
2
25
  <style>
3
26
  :host {
4
27
  display: inline-block;
@@ -21,6 +44,143 @@
21
44
  </style>
22
45
  <button part="shareButton">
23
46
  <slot>
24
- ${f()}
47
+ ${_whichIcon()}
25
48
  </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")),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"}})});
49
+ </button>`;
50
+ this.addEventListener("click", this.share);
51
+ }
52
+ } else {
53
+ console.warn("ProgressiveShareButton disabled due to lack of Web Share API support on this browser.");
54
+ }
55
+ }
56
+ share() {
57
+ const debug = _getBoolean(this.getAttribute("debug"));
58
+ const smartShare = _getBoolean(this.getAttribute("smart-share"));
59
+ const url = this.getAttribute("url");
60
+ let text = this.getAttribute("text");
61
+ let title = this.getAttribute("title");
62
+ let data = {};
63
+ if (url) {
64
+ data.url = url;
65
+ }
66
+ if (text) {
67
+ data.text = text;
68
+ }
69
+ if (title) {
70
+ data.title = title;
71
+ }
72
+ if (smartShare) {
73
+ if (title && title.slice(-1) !== ".") {
74
+ title = title + ".";
75
+ }
76
+ if (text && text.slice(-1) !== ".") {
77
+ text = text + ".";
78
+ }
79
+ data = {
80
+ text: `${title ? title + " " : ""}${text ? text + " " : ""}${url ? url : ""}`
81
+ };
82
+ }
83
+ if (!data.url && !data.text && !data.title) {
84
+ data.url = window.location.href;
85
+ }
86
+ let shareEvent = new CustomEvent("progressive-share-success", {
87
+ bubbles: true,
88
+ cancelable: false,
89
+ composed: true,
90
+ detail: data
91
+ });
92
+ if (navigator.share) {
93
+ if (debug == 1) {
94
+ console.debug("data to be shared", data);
95
+ } else {
96
+ navigator.share(data).then(() => {
97
+ this.dispatchEvent(shareEvent);
98
+ }).catch((e) => {
99
+ let shareEventFail = new CustomEvent(
100
+ "progressive-share-fail",
101
+ {
102
+ bubbles: true,
103
+ cancelable: false,
104
+ composed: true,
105
+ detail: e
106
+ }
107
+ );
108
+ this.dispatchEvent(shareEventFail);
109
+ });
110
+ }
111
+ } else {
112
+ console.debug("data to be shared", data);
113
+ }
114
+ }
115
+ }
116
+ function ProgressiveShareButton() {
117
+ if (typeof navigator.share === "function") {
118
+ console.log(
119
+ "ProgressiveShareButton support initialized. <progressive-share-success /> element now available"
120
+ );
121
+ } else {
122
+ console.log(
123
+ "ProgressiveShareButton support initialized. This browser does not have Web Share API support support."
124
+ );
125
+ }
126
+ customElements.define(
127
+ "progressive-share-button",
128
+ ProgressiveShareButtonElement
129
+ );
130
+ return true;
131
+ }
132
+ const iosShareIcon = '<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>';
133
+ const androidShareIcon = '<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>';
134
+ const winShareIcon = '<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>';
135
+ const _guessOs = () => {
136
+ const userAgent = navigator.userAgent;
137
+ if (/iPhone|iPad|iPod/.test(userAgent)) {
138
+ return "iOS";
139
+ } else if (/Android/.test(userAgent)) {
140
+ return "Android";
141
+ } else if (/Windows/.test(userAgent)) {
142
+ return "Windows";
143
+ } else if (/Mac/.test(userAgent)) {
144
+ return "Mac";
145
+ } else {
146
+ return "Unknown";
147
+ }
148
+ };
149
+ const _whichIcon = () => {
150
+ const os = _guessOs();
151
+ switch (os) {
152
+ case "iOS":
153
+ case "Mac":
154
+ return iosShareIcon;
155
+ case "Android":
156
+ return androidShareIcon;
157
+ case "Windows":
158
+ case "Unknown":
159
+ default:
160
+ return winShareIcon;
161
+ }
162
+ };
163
+ function _getBoolean(stringValue) {
164
+ var _a;
165
+ if (!stringValue) {
166
+ return false;
167
+ }
168
+ switch ((_a = stringValue == null ? void 0 : stringValue.toLowerCase()) == null ? void 0 : _a.trim()) {
169
+ case "true":
170
+ case "1":
171
+ return true;
172
+ case "false":
173
+ case "0":
174
+ return false;
175
+ default:
176
+ return JSON.parse(stringValue);
177
+ }
178
+ }
179
+ const main = (() => {
180
+ ProgressiveShareButton();
181
+ })();
182
+ exports2.ProgressiveShareButton = ProgressiveShareButton;
183
+ exports2.ProgressiveShareButtonElement = ProgressiveShareButtonElement;
184
+ exports2.default = main;
185
+ Object.defineProperties(exports2, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
186
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "progressive-share-button",
3
- "version": "1.0.0-alpha.7",
3
+ "version": "1.0.0-alpha.8",
4
4
  "description": "A web componet that creates a OS-native share button.",
5
5
  "files": [
6
6
  "dist"