@calcom/embed-core
Advanced tools
Comparing version 1.2.0 to 1.2.1
# @calcom/embed-core | ||
## 1.2.1 | ||
### Patch Changes | ||
- Fix the build for embed-react | ||
## 1.2.0 | ||
@@ -4,0 +10,0 @@ |
@@ -88,3 +88,3 @@ !function(){const v=({buttonText:n,buttonClasses:t,buttonColor:r,buttonTextColor:e})=>`<button class="z-[10000000000] hidden fixed md:bottom-6 bottom-4 md:right-10 right-4 md:left-10 left-4 ${t.join(" ")} flex h-16 origin-center bg-red-50 transform cursor-pointer items-center | ||
`;function b(n,t){const r=new window.CustomEvent(n,{detail:t});window.dispatchEvent(r)}class x{static parseAction(t){if(!t)return null;const[r,e,o]=t.split(":");return r!=="CAL"?null:{ns:e,type:o}}getFullActionName(t){return this.namespace?`CAL:${this.namespace}:${t}`:`CAL::${t}`}fire(t,r){const e=this.getFullActionName(t),o={type:t,namespace:this.namespace,fullType:e,data:r};b(e,o),b(this.getFullActionName("*"),o)}on(t,r){const e=this.getFullActionName(t);window.addEventListener(e,r)}off(t,r){const e=this.getFullActionName(t);window.removeEventListener(e,r)}constructor(t){t=t||"",this.namespace=t}}const M=`*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:#e5e7eb}:before,:after{--tw-content: ""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:var(--font-inter),ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:Roboto Mono,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}[type=text],[type=email],[type=url],[type=password],[type=number],[type=date],[type=datetime-local],[type=month],[type=search],[type=tel],[type=time],[type=week],[multiple],textarea,select{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:#fff;border-color:#6b7280;border-width:1px;border-radius:0;padding:.5rem .75rem;font-size:1rem;line-height:1.5rem;--tw-shadow: 0 0 #0000}[type=text]:focus,[type=email]:focus,[type=url]:focus,[type=password]:focus,[type=number]:focus,[type=date]:focus,[type=datetime-local]:focus,[type=month]:focus,[type=search]:focus,[type=tel]:focus,[type=time]:focus,[type=week]:focus,[multiple]:focus,textarea:focus,select:focus{outline:2px solid transparent;outline-offset:2px;--tw-ring-inset: var(--tw-empty, );--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: #2563eb;--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow);border-color:#2563eb}input::-moz-placeholder,textarea::-moz-placeholder{color:#6b7280;opacity:1}input::placeholder,textarea::placeholder{color:#6b7280;opacity:1}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-date-and-time-value{min-height:1.5em}::-webkit-datetime-edit,::-webkit-datetime-edit-year-field,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute-field,::-webkit-datetime-edit-second-field,::-webkit-datetime-edit-millisecond-field,::-webkit-datetime-edit-meridiem-field{padding-top:0;padding-bottom:0}select{background-image:url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236B7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");background-position:right .5rem center;background-repeat:no-repeat;background-size:1.5em 1.5em;padding-right:2.5rem;-webkit-print-color-adjust:exact;print-color-adjust:exact}[multiple]{background-image:initial;background-position:initial;background-repeat:unset;background-size:initial;padding-right:.75rem;-webkit-print-color-adjust:unset;print-color-adjust:unset}[type=checkbox],[type=radio]{-webkit-appearance:none;-moz-appearance:none;appearance:none;padding:0;-webkit-print-color-adjust:exact;print-color-adjust:exact;display:inline-block;vertical-align:middle;background-origin:border-box;-webkit-user-select:none;-moz-user-select:none;user-select:none;flex-shrink:0;height:1rem;width:1rem;color:#2563eb;background-color:#fff;border-color:#6b7280;border-width:1px;--tw-shadow: 0 0 #0000}[type=checkbox]{border-radius:0}[type=radio]{border-radius:100%}[type=checkbox]:focus,[type=radio]:focus{outline:2px solid transparent;outline-offset:2px;--tw-ring-inset: var(--tw-empty, );--tw-ring-offset-width: 2px;--tw-ring-offset-color: #fff;--tw-ring-color: #2563eb;--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}[type=checkbox]:checked,[type=radio]:checked{border-color:transparent;background-color:currentColor;background-size:100% 100%;background-position:center;background-repeat:no-repeat}[type=checkbox]:checked{background-image:url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e")}[type=radio]:checked{background-image:url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3ccircle cx='8' cy='8' r='3'/%3e%3c/svg%3e")}[type=checkbox]:checked:hover,[type=checkbox]:checked:focus,[type=radio]:checked:hover,[type=radio]:checked:focus{border-color:transparent;background-color:currentColor}[type=checkbox]:indeterminate{background-image:url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3e%3cpath stroke='white' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M4 8h8'/%3e%3c/svg%3e");border-color:transparent;background-color:currentColor;background-size:100% 100%;background-position:center;background-repeat:no-repeat}[type=checkbox]:indeterminate:hover,[type=checkbox]:indeterminate:focus{border-color:transparent;background-color:currentColor}[type=file]{background:unset;border-color:inherit;border-width:0;border-radius:0;padding:0;font-size:unset;line-height:inherit}[type=file]:focus{outline:1px solid ButtonText;outline:1px auto -webkit-focus-ring-color}*{scrollbar-color:initial;scrollbar-width:initial}*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.visible{visibility:visible}.fixed{position:fixed}.absolute{position:absolute}.relative{position:relative}.bottom-4{bottom:1rem}.right-4{right:1rem}.left-4{left:1rem}.left-1\\/2{left:50%}.z-\\[10000000000\\]{z-index:10000000000}.z-\\[999999999999\\]{z-index:999999999999}.mr-3{margin-right:.75rem}.flex{display:flex}.hidden{display:none}.h-16{height:4rem}.h-7{height:1.75rem}.w-7{width:1.75rem}.w-full{width:100%}.origin-center{transform-origin:center}.-translate-x-1\\/2{--tw-translate-x: -50%;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.transform{transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.cursor-pointer{cursor:pointer}.items-center{align-items:center}.justify-center{justify-content:center}.rounded-full{border-radius:9999px}.bg-red-50{--tw-bg-opacity: 1;background-color:rgb(254 242 242 / var(--tw-bg-opacity))}.bg-brand{background-color:var(--cal-brand-color, black)}.py-4{padding-top:1rem;padding-bottom:1rem}.px-6{padding-left:1.5rem;padding-right:1.5rem}.text-base{font-size:1rem;line-height:1.5rem}.font-semibold{font-weight:600}.leading-5{line-height:1.25rem}.text-inverted{color:var(--cal-text-inverted, white)}.antialiased{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.outline-none{outline:2px solid transparent;outline-offset:2px}.drop-shadow-md{--tw-drop-shadow: drop-shadow(0 4px 3px rgb(0 0 0 / .07)) drop-shadow(0 2px 2px rgb(0 0 0 / .06));filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow)}.transition{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,-webkit-backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter;transition-property:color,background-color,border-color,text-decoration-color,fill,stroke,opacity,box-shadow,transform,filter,backdrop-filter,-webkit-backdrop-filter;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}@font-face{font-family:Cal Sans;src:url(https://cal.com/cal.ttf)}h1,h2,h3,h4,h5,h6{font-family:Cal Sans;font-weight:400;letter-spacing:normal}html,body,:host{font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji}.focus\\:outline-none:focus{outline:2px solid transparent;outline-offset:2px}.focus\\:ring-gray-600:focus{--tw-ring-opacity: 1;--tw-ring-color: rgb(75 85 99 / var(--tw-ring-opacity))}.focus\\:ring-opacity-50:focus{--tw-ring-opacity: .5}.active\\:scale-95:active{--tw-scale-x: .95;--tw-scale-y: .95;transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}@media (min-width: 768px){.md\\:bottom-6{bottom:1.5rem}.md\\:right-10{right:2.5rem}.md\\:left-10{left:2.5rem}} | ||
`,j="https://app.cal.com";customElements.define("cal-modal-box",g);customElements.define("cal-floating-button",m);customElements.define("cal-inline",z);const h=window.Cal;if(!h||!h.q)throw new Error("Cal is not defined. This shouldn't happen");h.fingerprint="da968d30f";h.__css=M;document.head.appendChild(document.createElement("style")).innerHTML=L;function y(...n){console.log(...n)}function w(n,t){function r(o,i){return typeof i=="string"?typeof o==i:o instanceof i}function e(o){return typeof o>"u"}if(t.required&&e(n))throw new Error("Argument is required");for(const[o,i]of Object.entries(t.props||{})){if(i.required&&e(n[o]))throw new Error(`"${o}" is required`);let a=!0;if(i.type&&!e(n[o])&&(i.type instanceof Array?i.type.forEach(s=>{a=a||r(n[o],s)}):a=r(n[o],i.type)),!a)throw new Error(`"${o}" is of wrong type.Expected type "${i.type}"`)}}class p{constructor(t,r){this.iframeDoQueue=[],this.__config={calOrigin:j},this.api=new q(this),this.namespace=t,this.actionManager=new x(t),p.actionsManagers=p.actionsManagers||{},p.actionsManagers[t]=this.actionManager,this.processQueue(r),this.actionManager.on("__dimensionChanged",e=>{const{data:o}=e.detail,i=this.iframe;if(!i)return;const a="px";o.iframeHeight&&(i.style.height=o.iframeHeight+a),this.modalBox&&(i.style.maxHeight=window.innerHeight-100+"px")}),this.actionManager.on("__iframeReady",()=>{this.iframeReady=!0,this.doInIframe({method:"parentKnowsIframeReady"}),this.iframeDoQueue.forEach(e=>{this.doInIframe(e)})}),this.actionManager.on("__routeChanged",()=>{const{top:e,height:o}=this.inlineEl.getBoundingClientRect();e<0&&Math.abs(e/o)>=.25&&this.inlineEl.scrollIntoView({behavior:"smooth"})}),this.actionManager.on("linkReady",()=>{var e,o;(e=this.modalBox)==null||e.setAttribute("state","loaded"),(o=this.inlineEl)==null||o.setAttribute("loading","done")}),this.actionManager.on("linkFailed",e=>{var i,a,s,d;this.iframe&&((i=this.inlineEl)==null||i.setAttribute("data-error-code",e.detail.data.code),(a=this.modalBox)==null||a.setAttribute("data-error-code",e.detail.data.code),(s=this.inlineEl)==null||s.setAttribute("loading","failed"),(d=this.modalBox)==null||d.setAttribute("state","failed"))})}static getQueryObject(t){return t=t||{},{...t,guest:t.guests??void 0}}processInstruction(t){const r=[].slice.call(t);if(typeof r[0]!="string"){r.forEach(i=>{this.processInstruction(i)});return}const[e,...o]=r;this.api[e]||y(`Instruction ${e} not FOUND`);try{this.api[e](...o)}catch(i){y("Instruction couldn't be executed",i)}return r}processQueue(t){t.forEach(r=>{this.processInstruction(r)}),t.splice(0),t.push=r=>{this.processInstruction(r)}}createIframe({calLink:t,queryObject:r={},calOrigin:e}){const o=this.iframe=document.createElement("iframe");o.className="cal-embed",o.name="cal-embed";const i=this.getConfig(),{iframeAttrs:a,...s}=r;a&&a.id&&o.setAttribute("id",a.id);const d=new URLSearchParams;for(const[u,l]of Object.entries(s))l!==void 0&&(l instanceof Array?l.forEach(f=>d.append(u,f)):d.set(u,l));const c=new URL(`${e||i.calOrigin}/${t}`);c.pathname.endsWith("embed")||(c.pathname=`${c.pathname}/embed`),c.searchParams.set("embed",this.namespace),i.debug&&c.searchParams.set("debug",""+i.debug),i.uiDebug&&(o.style.border="1px solid green");for(const[u,l]of d)c.searchParams.append(u,l);return o.src=c.toString(),o}getConfig(){return this.__config}doInIframe(t){if(!this.iframeReady){this.iframeDoQueue.push(t);return}if(!this.iframe)throw new Error("iframe doesn't exist. `createIframe` must be called before `doInIframe`");this.iframe.contentWindow&&this.iframe.contentWindow.postMessage({originator:"CAL",method:t.method,arg:t.arg},"*")}}class q{constructor(t){this.cal=t}init(t,r={}){typeof t!="string"&&(r=t||{});const{calOrigin:e,origin:o,...i}=r;this.cal.__config.calOrigin=e||o||this.cal.__config.calOrigin,this.cal.__config={...this.cal.__config,...i}}inline({calLink:t,elementOrSelector:r,config:e}){if(w(arguments[0],{required:!0,props:{calLink:{required:!0,type:"string"},elementOrSelector:{required:!0,type:["string",HTMLElement]},config:{required:!1,type:Object}}}),e=e||{},typeof e.iframeAttrs=="string"||e.iframeAttrs instanceof Array)throw new Error("iframeAttrs should be an object");e.embedType="inline";const o=this.cal.createIframe({calLink:t,queryObject:p.getQueryObject(e)});o.style.height="100%",o.style.width="100%";const i=r instanceof HTMLElement?r:document.querySelector(r);if(!i)throw new Error("Element not found");i.classList.add("cal-inline-container");const a=document.createElement("template");a.innerHTML='<cal-inline style="max-height:inherit;height:inherit;min-height:inherit;display:flex;position:relative;flex-wrap:wrap;width:100%"></cal-inline><style>.cal-inline-container::-webkit-scrollbar{display:none}.cal-inline-container{scrollbar-width:none}</style>',this.cal.inlineEl=a.content.children[0],this.cal.inlineEl.appendChild(o),i.appendChild(a.content)}floatingButton({calLink:t,buttonText:r="Book my Cal",hideButtonIcon:e=!1,attributes:o,buttonPosition:i="bottom-right",buttonColor:a="rgb(0, 0, 0)",buttonTextColor:s="rgb(255, 255, 255)",calOrigin:d,config:c}){let u=null;o!=null&&o.id&&(u=document.getElementById(o.id));let l;u?l=u:(l=document.createElement("cal-floating-button"),l.dataset.calLink=t,l.dataset.calNamespace=this.cal.namespace,l.dataset.calOrigin=d??"",c&&(l.dataset.calConfig=JSON.stringify(c)),o!=null&&o.id&&(l.id=o.id),document.body.appendChild(l));const f=l.dataset;f.buttonText=r,f.hideButtonIcon=""+e,f.buttonPosition=""+i,f.buttonColor=""+a,f.buttonTextColor=""+s}modal({calLink:t,calOrigin:r,config:e={},uid:o}){o=o||0;const i=document.querySelector(`cal-modal-box[uid="${o}"]`);if(i){i.setAttribute("state","started");return}if(typeof e.iframeAttrs=="string"||e.iframeAttrs instanceof Array)throw new Error("iframeAttrs should be an object");e.embedType="modal";const a=this.cal.createIframe({calLink:t,calOrigin:r,queryObject:p.getQueryObject(e)});a.style.borderRadius="8px",a.style.height="100%",a.style.width="100%";const s=document.createElement("template");s.innerHTML=`<cal-modal-box uid="${o}"></cal-modal-box>`,this.cal.modalBox=s.content.children[0],this.cal.modalBox.appendChild(a),this.cal.actionManager.on("__closeIframe",()=>{this.cal.modalBox.setAttribute("state","closed")}),document.body.appendChild(s.content)}on({action:t,callback:r}){w(arguments[0],{required:!0,props:{action:{required:!0,type:"string"},callback:{required:!0,type:Function}}}),this.cal.actionManager.on(t,r)}off({action:t,callback:r}){this.cal.actionManager.off(t,r)}preload({calLink:t}){w(arguments[0],{required:!0,props:{calLink:{type:"string",required:!0}}});const r=document.body.appendChild(document.createElement("iframe")),e=this.cal.getConfig(),o=new URL(`${e.calOrigin}/${t}`);o.searchParams.set("prerender","true"),r.src=o.toString(),r.style.width="0",r.style.height="0",r.style.display="none"}ui(t){w(t,{required:!0,props:{theme:{required:!1,type:"string"},styles:{required:!1,type:Object}}}),this.cal.doInIframe({method:"ui",arg:t})}}h.instance=new p("",h.q);for(const[n,t]of Object.entries(h.ns))t.instance=new p(n,t.q);window.addEventListener("message",n=>{const t=n.data,r=t.fullType,e=x.parseAction(r);if(!e)return;const o=p.actionsManagers[e.ns];if(h.__logQueue=h.__logQueue||[],h.__logQueue.push({...e,data:t.data}),!o)throw new Error("Unhandled Action"+e);o.fire(e.type,t.data)});document.addEventListener("click",n=>{const t=n.target;if(!(t instanceof HTMLElement))return;const r=t.dataset.calLink;if(!r)return;const e=t.dataset.uniqueId=t.dataset.uniqueId||String(Date.now()),o=t.dataset.calNamespace,i=t.dataset.calConfig||"",a=t.dataset.calOrigin||"";let s;try{s=JSON.parse(i)}catch{s={}}let d=h;if(o&&(d=h.ns[o]),!d)throw new Error(`Namespace ${o} isn't defined`);d("modal",{calLink:r,config:s,uid:e,calOrigin:a})}); | ||
`,j="https://app.cal.com";customElements.define("cal-modal-box",g);customElements.define("cal-floating-button",m);customElements.define("cal-inline",z);const h=window.Cal;if(!h||!h.q)throw new Error("Cal is not defined. This shouldn't happen");h.fingerprint="641917e07";h.__css=M;document.head.appendChild(document.createElement("style")).innerHTML=L;function y(...n){console.log(...n)}function w(n,t){function r(o,i){return typeof i=="string"?typeof o==i:o instanceof i}function e(o){return typeof o>"u"}if(t.required&&e(n))throw new Error("Argument is required");for(const[o,i]of Object.entries(t.props||{})){if(i.required&&e(n[o]))throw new Error(`"${o}" is required`);let a=!0;if(i.type&&!e(n[o])&&(i.type instanceof Array?i.type.forEach(s=>{a=a||r(n[o],s)}):a=r(n[o],i.type)),!a)throw new Error(`"${o}" is of wrong type.Expected type "${i.type}"`)}}class p{constructor(t,r){this.iframeDoQueue=[],this.__config={calOrigin:j},this.api=new q(this),this.namespace=t,this.actionManager=new x(t),p.actionsManagers=p.actionsManagers||{},p.actionsManagers[t]=this.actionManager,this.processQueue(r),this.actionManager.on("__dimensionChanged",e=>{const{data:o}=e.detail,i=this.iframe;if(!i)return;const a="px";o.iframeHeight&&(i.style.height=o.iframeHeight+a),this.modalBox&&(i.style.maxHeight=window.innerHeight-100+"px")}),this.actionManager.on("__iframeReady",()=>{this.iframeReady=!0,this.doInIframe({method:"parentKnowsIframeReady"}),this.iframeDoQueue.forEach(e=>{this.doInIframe(e)})}),this.actionManager.on("__routeChanged",()=>{const{top:e,height:o}=this.inlineEl.getBoundingClientRect();e<0&&Math.abs(e/o)>=.25&&this.inlineEl.scrollIntoView({behavior:"smooth"})}),this.actionManager.on("linkReady",()=>{var e,o;(e=this.modalBox)==null||e.setAttribute("state","loaded"),(o=this.inlineEl)==null||o.setAttribute("loading","done")}),this.actionManager.on("linkFailed",e=>{var i,a,s,d;this.iframe&&((i=this.inlineEl)==null||i.setAttribute("data-error-code",e.detail.data.code),(a=this.modalBox)==null||a.setAttribute("data-error-code",e.detail.data.code),(s=this.inlineEl)==null||s.setAttribute("loading","failed"),(d=this.modalBox)==null||d.setAttribute("state","failed"))})}static getQueryObject(t){return t=t||{},{...t,guest:t.guests??void 0}}processInstruction(t){const r=[].slice.call(t);if(typeof r[0]!="string"){r.forEach(i=>{this.processInstruction(i)});return}const[e,...o]=r;this.api[e]||y(`Instruction ${e} not FOUND`);try{this.api[e](...o)}catch(i){y("Instruction couldn't be executed",i)}return r}processQueue(t){t.forEach(r=>{this.processInstruction(r)}),t.splice(0),t.push=r=>{this.processInstruction(r)}}createIframe({calLink:t,queryObject:r={},calOrigin:e}){const o=this.iframe=document.createElement("iframe");o.className="cal-embed",o.name="cal-embed";const i=this.getConfig(),{iframeAttrs:a,...s}=r;a&&a.id&&o.setAttribute("id",a.id);const d=new URLSearchParams;for(const[u,l]of Object.entries(s))l!==void 0&&(l instanceof Array?l.forEach(f=>d.append(u,f)):d.set(u,l));const c=new URL(`${e||i.calOrigin}/${t}`);c.pathname.endsWith("embed")||(c.pathname=`${c.pathname}/embed`),c.searchParams.set("embed",this.namespace),i.debug&&c.searchParams.set("debug",""+i.debug),i.uiDebug&&(o.style.border="1px solid green");for(const[u,l]of d)c.searchParams.append(u,l);return o.src=c.toString(),o}getConfig(){return this.__config}doInIframe(t){if(!this.iframeReady){this.iframeDoQueue.push(t);return}if(!this.iframe)throw new Error("iframe doesn't exist. `createIframe` must be called before `doInIframe`");this.iframe.contentWindow&&this.iframe.contentWindow.postMessage({originator:"CAL",method:t.method,arg:t.arg},"*")}}class q{constructor(t){this.cal=t}init(t,r={}){typeof t!="string"&&(r=t||{});const{calOrigin:e,origin:o,...i}=r;this.cal.__config.calOrigin=e||o||this.cal.__config.calOrigin,this.cal.__config={...this.cal.__config,...i}}inline({calLink:t,elementOrSelector:r,config:e}){if(w(arguments[0],{required:!0,props:{calLink:{required:!0,type:"string"},elementOrSelector:{required:!0,type:["string",HTMLElement]},config:{required:!1,type:Object}}}),e=e||{},typeof e.iframeAttrs=="string"||e.iframeAttrs instanceof Array)throw new Error("iframeAttrs should be an object");e.embedType="inline";const o=this.cal.createIframe({calLink:t,queryObject:p.getQueryObject(e)});o.style.height="100%",o.style.width="100%";const i=r instanceof HTMLElement?r:document.querySelector(r);if(!i)throw new Error("Element not found");i.classList.add("cal-inline-container");const a=document.createElement("template");a.innerHTML='<cal-inline style="max-height:inherit;height:inherit;min-height:inherit;display:flex;position:relative;flex-wrap:wrap;width:100%"></cal-inline><style>.cal-inline-container::-webkit-scrollbar{display:none}.cal-inline-container{scrollbar-width:none}</style>',this.cal.inlineEl=a.content.children[0],this.cal.inlineEl.appendChild(o),i.appendChild(a.content)}floatingButton({calLink:t,buttonText:r="Book my Cal",hideButtonIcon:e=!1,attributes:o,buttonPosition:i="bottom-right",buttonColor:a="rgb(0, 0, 0)",buttonTextColor:s="rgb(255, 255, 255)",calOrigin:d,config:c}){let u=null;o!=null&&o.id&&(u=document.getElementById(o.id));let l;u?l=u:(l=document.createElement("cal-floating-button"),l.dataset.calLink=t,l.dataset.calNamespace=this.cal.namespace,l.dataset.calOrigin=d??"",c&&(l.dataset.calConfig=JSON.stringify(c)),o!=null&&o.id&&(l.id=o.id),document.body.appendChild(l));const f=l.dataset;f.buttonText=r,f.hideButtonIcon=""+e,f.buttonPosition=""+i,f.buttonColor=""+a,f.buttonTextColor=""+s}modal({calLink:t,calOrigin:r,config:e={},uid:o}){o=o||0;const i=document.querySelector(`cal-modal-box[uid="${o}"]`);if(i){i.setAttribute("state","started");return}if(typeof e.iframeAttrs=="string"||e.iframeAttrs instanceof Array)throw new Error("iframeAttrs should be an object");e.embedType="modal";const a=this.cal.createIframe({calLink:t,calOrigin:r,queryObject:p.getQueryObject(e)});a.style.borderRadius="8px",a.style.height="100%",a.style.width="100%";const s=document.createElement("template");s.innerHTML=`<cal-modal-box uid="${o}"></cal-modal-box>`,this.cal.modalBox=s.content.children[0],this.cal.modalBox.appendChild(a),this.cal.actionManager.on("__closeIframe",()=>{this.cal.modalBox.setAttribute("state","closed")}),document.body.appendChild(s.content)}on({action:t,callback:r}){w(arguments[0],{required:!0,props:{action:{required:!0,type:"string"},callback:{required:!0,type:Function}}}),this.cal.actionManager.on(t,r)}off({action:t,callback:r}){this.cal.actionManager.off(t,r)}preload({calLink:t}){w(arguments[0],{required:!0,props:{calLink:{type:"string",required:!0}}});const r=document.body.appendChild(document.createElement("iframe")),e=this.cal.getConfig(),o=new URL(`${e.calOrigin}/${t}`);o.searchParams.set("prerender","true"),r.src=o.toString(),r.style.width="0",r.style.height="0",r.style.display="none"}ui(t){w(t,{required:!0,props:{theme:{required:!1,type:"string"},styles:{required:!1,type:Object}}}),this.cal.doInIframe({method:"ui",arg:t})}}h.instance=new p("",h.q);for(const[n,t]of Object.entries(h.ns))t.instance=new p(n,t.q);window.addEventListener("message",n=>{const t=n.data,r=t.fullType,e=x.parseAction(r);if(!e)return;const o=p.actionsManagers[e.ns];if(h.__logQueue=h.__logQueue||[],h.__logQueue.push({...e,data:t.data}),!o)throw new Error("Unhandled Action"+e);o.fire(e.type,t.data)});document.addEventListener("click",n=>{const t=n.target;if(!(t instanceof HTMLElement))return;const r=t.dataset.calLink;if(!r)return;const e=t.dataset.uniqueId=t.dataset.uniqueId||String(Date.now()),o=t.dataset.calNamespace,i=t.dataset.calConfig||"",a=t.dataset.calOrigin||"";let s;try{s=JSON.parse(i)}catch{s={}}let d=h;if(o&&(d=h.ns[o]),!d)throw new Error(`Namespace ${o} isn't defined`);d("modal",{calLink:r,config:s,uid:e,calOrigin:a})}); | ||
}() |
@@ -1,1 +0,1 @@ | ||
(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const t of document.querySelectorAll('link[rel="modulepreload"]'))i(t);new MutationObserver(t=>{for(const e of t)if(e.type==="childList")for(const r of e.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&i(r)}).observe(document,{childList:!0,subtree:!0});function s(t){const e={};return t.integrity&&(e.integrity=t.integrity),t.referrerPolicy&&(e.referrerPolicy=t.referrerPolicy),t.crossOrigin==="use-credentials"?e.credentials="include":t.crossOrigin==="anonymous"?e.credentials="omit":e.credentials="same-origin",e}function i(t){if(t.ep)return;t.ep=!0;const e=s(t);fetch(t.href,e)}})();const f="https://app.cal.com",p="http://localhost:3000/embed/embed.js";(function(o,n,s){const i=function(e,r){e.q.push(r)},t=o.document;o.Cal=o.Cal||function(){const e=o.Cal,r=arguments;if(e.loaded||(e.ns={},e.q=e.q||[],t.head.appendChild(t.createElement("script")).src=n,e.loaded=!0),r[0]===s){const c=function(){i(c,arguments)},u=r[1];c.q=c.q||[],typeof u=="string"?(e.ns[u]=c)&&i(c,r):i(e,r);return}i(e,r)}})(window,p,"init");const a=window;a.Cal.fingerprint="da968d30f";a.Cal("init",{origin:f});const m=new URL(document.URL).searchParams,l=m.get("embedType"),d=m.get("calLink");if(!d)throw new Error('Missing "calLink" query parameter');if(l==="inline")a.Cal("inline",{elementOrSelector:"#my-embed",calLink:d});else if(l==="floating-popup")a.Cal("floatingButton",{calLink:d,attributes:{id:"my-floating-button"}});else if(l==="element-click"){const o=document.createElement("button");o.setAttribute("data-cal-link",d),o.innerHTML="I am a button that exists on your website",document.body.appendChild(o)}a.addEventListener("message",o=>{const n=o.data;if(n.mode!=="cal:preview")return;const s=window.Cal;if(!s)throw new Error("Cal is not defined yet");if(n.type=="instruction"&&s(n.instruction.name,n.instruction.arg),n.type=="inlineEmbedDimensionUpdate"){const i=document.querySelector("#my-embed");i&&(i.style.width=n.data.width,i.style.height=n.data.height)}});function h(){const o=window.matchMedia("(prefers-color-scheme: dark)");function n(s){s.matches?(document.body.classList.remove("light"),document.body.classList.add("dark")):(document.body.classList.add("light"),document.body.classList.remove("dark"))}o.addEventListener("change",n),n(new MediaQueryListEvent("change",{matches:o.matches}))}h(); | ||
(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const t of document.querySelectorAll('link[rel="modulepreload"]'))i(t);new MutationObserver(t=>{for(const e of t)if(e.type==="childList")for(const r of e.addedNodes)r.tagName==="LINK"&&r.rel==="modulepreload"&&i(r)}).observe(document,{childList:!0,subtree:!0});function s(t){const e={};return t.integrity&&(e.integrity=t.integrity),t.referrerPolicy&&(e.referrerPolicy=t.referrerPolicy),t.crossOrigin==="use-credentials"?e.credentials="include":t.crossOrigin==="anonymous"?e.credentials="omit":e.credentials="same-origin",e}function i(t){if(t.ep)return;t.ep=!0;const e=s(t);fetch(t.href,e)}})();const f="https://app.cal.com",p="http://localhost:3000/embed/embed.js";(function(o,n,s){const i=function(e,r){e.q.push(r)},t=o.document;o.Cal=o.Cal||function(){const e=o.Cal,r=arguments;if(e.loaded||(e.ns={},e.q=e.q||[],t.head.appendChild(t.createElement("script")).src=n,e.loaded=!0),r[0]===s){const c=function(){i(c,arguments)},u=r[1];c.q=c.q||[],typeof u=="string"?(e.ns[u]=c)&&i(c,r):i(e,r);return}i(e,r)}})(window,p,"init");const a=window;a.Cal.fingerprint="641917e07";a.Cal("init",{origin:f});const m=new URL(document.URL).searchParams,l=m.get("embedType"),d=m.get("calLink");if(!d)throw new Error('Missing "calLink" query parameter');if(l==="inline")a.Cal("inline",{elementOrSelector:"#my-embed",calLink:d});else if(l==="floating-popup")a.Cal("floatingButton",{calLink:d,attributes:{id:"my-floating-button"}});else if(l==="element-click"){const o=document.createElement("button");o.setAttribute("data-cal-link",d),o.innerHTML="I am a button that exists on your website",document.body.appendChild(o)}a.addEventListener("message",o=>{const n=o.data;if(n.mode!=="cal:preview")return;const s=window.Cal;if(!s)throw new Error("Cal is not defined yet");if(n.type=="instruction"&&s(n.instruction.name,n.instruction.arg),n.type=="inlineEmbedDimensionUpdate"){const i=document.querySelector("#my-embed");i&&(i.style.width=n.data.width,i.style.height=n.data.height)}});function h(){const o=window.matchMedia("(prefers-color-scheme: dark)");function n(s){s.matches?(document.body.classList.remove("light"),document.body.classList.add("dark")):(document.body.classList.add("light"),document.body.classList.remove("dark"))}o.addEventListener("change",n),n(new MediaQueryListEvent("change",{matches:o.matches}))}h(); |
{ | ||
"name": "@calcom/embed-core", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "This is the vanilla JS core script that embeds Cal Link", | ||
@@ -5,0 +5,0 @@ "main": "./dist/embed/embed.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69894