UNPKG

@veltdev/sdk

Version:

Velt is an SDK to add collaborative features to your product within minutes. Example: Comments like Figma, Frame.io, Google docs or sheets, Recording like Loom, Huddles like Slack and much more.

2 lines (1 loc) 4.69 kB
import{D as E,Ha as R,Ja as S,Ka as F,Ma as l,T as b,bb as V,i as g,la as I,m as y,ra as v}from"./chunk-GR3NESUB.js";var Z={schedule(n,t){let e=setTimeout(n,t);return()=>clearTimeout(e)}};function D(n){return n.replace(/[A-Z]/g,t=>`-${t.toLowerCase()}`)}function M(n){return!!n&&n.nodeType===Node.ELEMENT_NODE}var h;function T(n,t){if(!h){let e=Element.prototype;h=e.matches||e.matchesSelector||e.mozMatchesSelector||e.msMatchesSelector||e.oMatchesSelector||e.webkitMatchesSelector}return n.nodeType===Node.ELEMENT_NODE?h.call(n,t):!1}function C(n){let t={};return n.forEach(({propName:e,templateName:s,transform:r})=>{t[D(s)]=[e,r]}),t}function _(n,t){return t.get(l).resolveComponentFactory(n).inputs}function x(n,t){let e=n.childNodes,s=t.map(()=>[]),r=-1;t.some((c,u)=>c==="*"?(r=u,!0):!1);for(let c=0,u=e.length;c<u;++c){let o=e[c],i=O(o,t,r);i!==-1&&s[i].push(o)}return s}function O(n,t,e){let s=e;return M(n)&&t.some((r,c)=>r!=="*"&&T(n,r)?(s=c,!0):!1),s}var N=10,p=class{componentFactory;inputMap=new Map;constructor(t,e){this.componentFactory=e.get(l).resolveComponentFactory(t);for(let s of this.componentFactory.inputs)this.inputMap.set(s.propName,s.templateName)}create(t){return new m(this.componentFactory,t,this.inputMap)}},m=class{componentFactory;injector;inputMap;eventEmitters=new y(1);events=this.eventEmitters.pipe(b(t=>E(...t)));componentRef=null;scheduledDestroyFn=null;initialInputValues=new Map;ngZone;elementZone;appRef;cdScheduler;constructor(t,e,s){this.componentFactory=t,this.injector=e,this.inputMap=s,this.ngZone=this.injector.get(R),this.appRef=this.injector.get(V),this.cdScheduler=e.get(v),this.elementZone=typeof Zone>"u"?null:this.ngZone.run(()=>Zone.current)}connect(t){this.runInZone(()=>{if(this.scheduledDestroyFn!==null){this.scheduledDestroyFn(),this.scheduledDestroyFn=null;return}this.componentRef===null&&this.initializeComponent(t)})}disconnect(){this.runInZone(()=>{this.componentRef===null||this.scheduledDestroyFn!==null||(this.scheduledDestroyFn=Z.schedule(()=>{this.componentRef!==null&&(this.componentRef.destroy(),this.componentRef=null)},N))})}getInputValue(t){return this.runInZone(()=>this.componentRef===null?this.initialInputValues.get(t):this.componentRef.instance[t])}setInputValue(t,e){if(this.componentRef===null){this.initialInputValues.set(t,e);return}this.runInZone(()=>{this.componentRef.setInput(this.inputMap.get(t)??t,e),S(this.componentRef.hostView)&&(F(this.componentRef.changeDetectorRef),this.cdScheduler.notify(6))})}initializeComponent(t){let e=I.create({providers:[],parent:this.injector}),s=x(t,this.componentFactory.ngContentSelectors);this.componentRef=this.componentFactory.create(e,s,t),this.initializeInputs(),this.initializeOutputs(this.componentRef),this.appRef.attachView(this.componentRef.hostView),this.componentRef.hostView.detectChanges()}initializeInputs(){for(let[t,e]of this.initialInputValues)this.setInputValue(t,e);this.initialInputValues.clear()}initializeOutputs(t){let e=this.componentFactory.outputs.map(({propName:s,templateName:r})=>{let c=t.instance[s];return new g(u=>{let o=c.subscribe(i=>u.next({name:r,value:i}));return()=>o.unsubscribe()})});this.eventEmitters.next(e)}runInZone(t){return this.elementZone&&Zone.current!==this.elementZone?this.ngZone.run(t):t()}},f=class extends HTMLElement{ngElementEventsSubscription=null};function L(n,t){let e=_(n,t.injector),s=t.strategyFactory||new p(n,t.injector),r=C(e);class c extends f{injector;static observedAttributes=Object.keys(r);get ngElementStrategy(){if(!this._ngElementStrategy){let o=this._ngElementStrategy=s.create(this.injector||t.injector);e.forEach(({propName:i,transform:a})=>{if(!this.hasOwnProperty(i))return;let d=this[i];delete this[i],o.setInputValue(i,d,a)})}return this._ngElementStrategy}_ngElementStrategy;constructor(o){super(),this.injector=o}attributeChangedCallback(o,i,a,d){let[w,j]=r[o];this.ngElementStrategy.setInputValue(w,a,j)}connectedCallback(){let o=!1;this.ngElementStrategy.events&&(this.subscribeToEvents(),o=!0),this.ngElementStrategy.connect(this),o||this.subscribeToEvents()}disconnectedCallback(){this._ngElementStrategy&&this._ngElementStrategy.disconnect(),this.ngElementEventsSubscription&&(this.ngElementEventsSubscription.unsubscribe(),this.ngElementEventsSubscription=null)}subscribeToEvents(){this.ngElementEventsSubscription=this.ngElementStrategy.events.subscribe(o=>{let i=new CustomEvent(o.name,{detail:o.value});this.dispatchEvent(i)})}}return e.forEach(({propName:u,transform:o})=>{Object.defineProperty(c.prototype,u,{get(){return this.ngElementStrategy.getInputValue(u)},set(i){this.ngElementStrategy.setInputValue(u,i,o)},configurable:!0,enumerable:!0})}),c}export{L as a};