@salla.sa/twilight-components
Version:
Salla Web Component
198 lines (189 loc) • 12.4 kB
JavaScript
/*!
* Crafted with ❤ by Salla
*/
import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { a as anime } from './anime.es.js';
import { f as facebook, t as twitter } from './facebook.js';
import { M as MailIcon } from './mail.js';
import { C as Cancel } from './cancel.js';
import { d as defineCustomElement$2 } from './salla-button2.js';
var copy_link = `<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
<title>link</title>
<path d="M19.247 23.019l-4.189 4.189c-2.831 2.831-7.435 2.831-10.265 0-1.371-1.372-2.125-3.193-2.125-5.132s0.755-3.761 2.125-5.133l4.189-4.191c0.521-0.521 0.521-1.364 0-1.885s-1.364-0.521-1.885 0l-4.189 4.191c-1.875 1.875-2.907 4.367-2.907 7.019s1.032 5.143 2.907 7.017 4.368 2.907 7.019 2.907 5.143-1.032 7.017-2.908l4.189-4.189c0.521-0.521 0.521-1.364 0-1.885s-1.364-0.52-1.885 0.001zM22.276 9.724c-0.521-0.521-1.364-0.521-1.885 0l-10.667 10.667c-0.521 0.521-0.521 1.364 0 1.885 0.26 0.26 0.601 0.391 0.943 0.391s0.683-0.131 0.943-0.391l10.667-10.667c0.521-0.521 0.521-1.364 0-1.885zM29.093 2.908c-1.875-1.876-4.368-2.908-7.019-2.908s-5.143 1.032-7.017 2.908l-4.189 4.188c-0.521 0.521-0.521 1.364 0 1.885s1.364 0.521 1.885 0l4.189-4.189c2.831-2.831 7.435-2.831 10.265 0 1.371 1.372 2.125 3.193 2.125 5.132s-0.755 3.761-2.125 5.133l-4.189 4.191c-0.521 0.521-0.521 1.364 0 1.885 0.26 0.26 0.601 0.391 0.943 0.391s0.683-0.131 0.943-0.391l4.189-4.191c1.875-1.875 2.907-4.367 2.907-7.019s-1.032-5.143-2.907-7.016z"></path>
</svg>
`;
var whatsapp = `<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
<title>whatsapp</title>
<path d="M16 32c-0.008 0-0.018 0-0.028 0-3.1 0-5.993-0.887-8.439-2.421l0.066 0.039-7.2 2.3 2.336-6.964c-1.713-2.492-2.736-5.575-2.736-8.897 0-0.020 0-0.040 0-0.060v0.003c0.009-8.833 7.167-15.991 15.999-16h0.001c8.837 0 16 7.163 16 16s-7.163 16-16 16v0zM7.906 27.424l0.4 0.264c2.169 1.449 4.837 2.312 7.707 2.312 7.732 0 14-6.268 14-14s-6.268-14-14-14c-0.004 0-0.009 0-0.013 0h0.001c-7.729 0.008-13.992 6.271-14 13.999v0.001c-0 0.010-0 0.021-0 0.032 0 3.072 1 5.909 2.693 8.206l-0.027-0.038 0.304 0.416-1.4 4.2zM20.716 24.958c-1.684-0.131-3.237-0.574-4.641-1.271l0.073 0.033c-3.098-1.456-5.634-3.668-7.438-6.405l-0.042-0.067c-1.102-1.357-1.819-3.067-1.962-4.938l-0.002-0.030c-0.001-0.036-0.001-0.078-0.001-0.12 0-1.575 0.66-2.995 1.719-4l0.002-0.002c0.547-0.52 1.289-0.839 2.105-0.839 0.033 0 0.066 0.001 0.099 0.002l-0.005-0c0.2 0 0.378 0 0.542 0.018 0.016-0.001 0.035-0.001 0.054-0.001 0.815 0 1.502 0.549 1.711 1.298l0.003 0.012 0.324 0.782c0.376 0.906 0.858 2.068 0.942 2.244 0.144 0.251 0.23 0.552 0.23 0.873 0 0.286-0.068 0.557-0.188 0.797l0.005-0.010c-0.149 0.307-0.332 0.57-0.55 0.802l0.002-0.002c-0.148 0.168-0.248 0.274-0.346 0.378s-0.172 0.18-0.26 0.284c0.575 0.92 1.237 1.713 1.992 2.406l0.008 0.008c0.829 0.758 1.802 1.373 2.872 1.8l0.064 0.022c0.369-0.266 0.672-0.6 0.896-0.985l0.008-0.015 0.174-0.232c0.328-0.484 0.875-0.798 1.495-0.798 0.249 0 0.487 0.051 0.703 0.142l-0.012-0.004c0.492 0.168 2.922 1.372 2.946 1.384l0.228 0.11c0.415 0.149 0.758 0.417 0.996 0.763l0.004 0.007c0.107 0.349 0.169 0.75 0.169 1.166 0 0.591-0.125 1.153-0.349 1.661l0.010-0.026c-0.702 1.368-1.983 2.353-3.511 2.637l-0.031 0.005c-0.309 0.071-0.663 0.112-1.028 0.112-0.004 0-0.007 0-0.011 0h0.001zM10.632 9.318c-0.028-0.002-0.062-0.004-0.095-0.004-0.245 0-0.472 0.076-0.659 0.206l0.004-0.002c-0.726 0.651-1.18 1.591-1.18 2.638 0 0.044 0.001 0.087 0.002 0.13l-0-0.006c0.122 1.404 0.662 2.662 1.495 3.671l-0.009-0.011 0.12 0.168c1.627 2.491 3.865 4.46 6.504 5.723l0.096 0.041c3.136 1.288 3.916 1.124 4.426 1.014 0.87-0.159 1.601-0.656 2.067-1.347l0.007-0.011c0.12-0.316 0.204-0.682 0.237-1.063l0.001-0.015-0.040-0.018-0.256-0.124c-0.8-0.4-2.46-1.2-2.734-1.292l-0.058 0.184c-0.346 0.501-0.684 0.934-1.045 1.347l0.015-0.017c-0.344 0.349-0.821 0.565-1.349 0.565-0.28 0-0.546-0.061-0.785-0.17l0.012 0.005c-1.403-0.547-2.609-1.301-3.646-2.239l0.010 0.009c-0.975-0.891-1.81-1.912-2.486-3.039l-0.034-0.061c-0.152-0.244-0.242-0.54-0.242-0.857 0-0.463 0.191-0.88 0.499-1.178l0-0c0.13-0.162 0.264-0.302 0.4-0.444l0.236-0.256c0.091-0.096 0.177-0.201 0.254-0.311l0.006-0.009c-0.158-0.36-0.622-1.472-0.988-2.352l-0.322-0.772-0.038-0.086c-0.188-0.010-0.302-0.016-0.426-0.016zM12.462 12.442v0.012z"></path>
</svg>
`;
var Socials;
(function (Socials) {
Socials["FACEBOOK"] = "facebook";
Socials["TWITTER"] = "twitter";
Socials["WHATSAPP"] = "whatsapp";
Socials["EMAIL"] = "email";
Socials["COPY_LINK"] = "copy_link";
})(Socials || (Socials = {}));
var ShareAlt = `<!-- Generated by IcoMoon.io -->
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
<title>share-alt</title>
<path d="M26.667 21.333c-1.699 0-3.196 0.812-4.173 2.052l-11.912-5.211c0.044-0.276 0.085-0.553 0.085-0.841 0-0.472-0.081-0.923-0.197-1.359l12.361-6.952c0.971 1.009 2.328 1.644 3.836 1.644 2.941 0 5.333-2.392 5.333-5.333s-2.392-5.333-5.333-5.333-5.333 2.392-5.333 5.333c0 0.472 0.081 0.923 0.197 1.359l-12.361 6.952c-0.971-1.009-2.328-1.644-3.836-1.644-2.941 0-5.333 2.392-5.333 5.333s2.392 5.333 5.333 5.333c1.699 0 3.196-0.812 4.173-2.052l11.912 5.211c-0.044 0.276-0.085 0.553-0.085 0.841 0 2.941 2.392 5.333 5.333 5.333s5.333-2.392 5.333-5.333-2.392-5.333-5.333-5.333zM26.667 2.667c1.471 0 2.667 1.196 2.667 2.667s-1.196 2.667-2.667 2.667-2.667-1.196-2.667-2.667 1.196-2.667 2.667-2.667zM5.333 20c-1.471 0-2.667-1.196-2.667-2.667s1.196-2.667 2.667-2.667 2.667 1.196 2.667 2.667-1.196 2.667-2.667 2.667zM26.667 29.333c-1.471 0-2.667-1.196-2.667-2.667s1.196-2.667 2.667-2.667 2.667 1.196 2.667 2.667-1.196 2.667-2.667 2.667z"></path>
</svg>
`;
const sallaSocialShareCss = "";
const SallaSocialShare$1 = /*@__PURE__*/ proxyCustomElement(class SallaSocialShare extends HTMLElement {
constructor() {
super();
this.__registerHost();
this.opened = false;
this.allPlatforms = [Socials.WHATSAPP, Socials.FACEBOOK, Socials.TWITTER, Socials.EMAIL, Socials.COPY_LINK];
this.platformIcons = [{ icon: whatsapp, name: Socials.WHATSAPP }, {
icon: facebook,
name: Socials.FACEBOOK
}, { icon: twitter, name: Socials.TWITTER }, { icon: MailIcon, name: Socials.EMAIL }, {
icon: copy_link,
name: Socials.COPY_LINK
}];
this.convertedPlatforms = [];
/**
* page url that will be shared custom | current page url
*/
this.url = "";
/**
* page url name that will be shared custom | current page url
*/
this.urlName = "";
/**
* selected platforms to share | all platforms
*/
this.platforms = 'facebook,twitter,whatsapp,email,copy_link';
}
componentWillLoad() {
if (this.host.hasAttribute('aria-label')) {
this.host.removeAttribute('aria-label');
}
if (document.getElementById('a2a-script')) {
return;
}
const script = document.createElement('script');
script.src = 'https://static.addtoany.com/menu/page.js';
script.setAttribute('id', 'a2a-script');
script.async = true;
script.onload = function () {
window.a2a_config.locale = salla.config.get('user.language_code', salla.lang.getLocale());
window.a2a_config.callbacks = window.a2a_config.callbacks || [];
window.a2a_config.callbacks.push({
share: (data) => {
// Handle share event
const shareData = {
share_via: data.service.toLowerCase(),
url: data.url,
title: data.title
};
// Dispatch the share event
salla.event.emit('share-element', shareData);
}
});
};
document.body.appendChild(script);
}
/**
* Activate or open the share menu.
*/
async open() {
const animateList = new anime.timeline().add({
targets: this.shareMenu,
translateY: [-50, 0],
opacity: [0, 1],
duration: 300,
podding: '0',
easing: 'easeInOutSine'
});
animateList.add({
targets: this.shareMenu.children,
translateZ: 0,
translateY: [-30, 0],
scaleY: [0, 1],
opacity: [0, 1],
duration: 1400,
delay: anime.stagger(100)
}, '-=200');
this.opened = !this.opened;
if (this.opened) {
this.shareMenu.classList.add('opened');
}
else {
animateList.pause();
animateList.seek(0);
this.shareMenu.classList.remove('opened');
}
}
/**
* Asynchronously initializes the "AddToAny" (a2a) social sharing tool on the current page.
* If the global object `window.a2a` is available, it initializes the tool with the 'page' mode.
* The 'page' mode is typically used to enable sharing of the current webpage.
*
* @remarks
* This function is designed to be used in scenarios where dynamic loading or refreshing of social sharing tools is needed.
* Ensure that the AddToAny script is properly included in the HTML document before calling this function.
*
* @example
* // Call the refresh function to initialize AddToAny on the page.
* await refresh();
*
* @throws {Error} Throws an error if the AddToAny script is not properly included or if there are issues during initialization.
*
* @async
* @returns {Promise<void>} A promise that resolves once the initialization is complete.
*/
async refresh() {
// Attempt to initialize AddToAny with 'page' mode if the global object `window.a2a` is available.
window.a2a?.init('page');
}
render() {
return (h("div", { key: 'e9f050078f7be9b5b000d4703e0e2f2394c7860c', class: "s-social-share-wrapper" }, h("slot", { key: 'aec685219966868f2332a9060b94346fa361b53c', name: 'widget' }, h("salla-button", { key: '4daf053aa6594659c17df827555633e0f95f8007', "aria-label": "Share", onClick: () => this.open(), class: "s-social-share-btn", shape: "icon", fill: "outline", color: "light" }, h("span", { key: '1d85fcea2fbc80c2b9c7d70cfc86263dcd109a82', innerHTML: this.opened ? Cancel : ShareAlt }))), h("ul", { key: '42cf458f62c4eac7509f66ba3a8a4e209698c392', ref: el => this.shareMenu = el, class: "s-social-share-list a2a_kit share", "data-a2a-url": this.url ? this.url : window.location.href, "data-a2a-title": this.urlName ? this.urlName : document.title }, this.platforms.split(',').map(platform => {
return (h("li", null, h("a", { class: `a2a_button_${platform}`, "aria-label": `Share Via ${platform}` }, this.platformIcons.map((icon) => {
if (icon.name === platform) {
return h("span", { class: "s-social-share-icon", innerHTML: icon.icon });
}
}))));
}))));
}
get host() { return this; }
static get style() { return sallaSocialShareCss; }
}, [4, "salla-social-share", {
"url": [513],
"urlName": [513, "url-name"],
"platforms": [513],
"opened": [32],
"allPlatforms": [32],
"platformIcons": [32],
"convertedPlatforms": [32],
"open": [64],
"refresh": [64]
}]);
function defineCustomElement$1() {
if (typeof customElements === "undefined") {
return;
}
const components = ["salla-social-share", "salla-button"];
components.forEach(tagName => { switch (tagName) {
case "salla-social-share":
if (!customElements.get(tagName)) {
customElements.define(tagName, SallaSocialShare$1);
}
break;
case "salla-button":
if (!customElements.get(tagName)) {
defineCustomElement$2();
}
break;
} });
}
defineCustomElement$1();
const SallaSocialShare = SallaSocialShare$1;
const defineCustomElement = defineCustomElement$1;
export { SallaSocialShare, defineCustomElement };