angular-t9n
Version:
A translation tool for Angular i18n
2 lines (1 loc) • 3.3 kB
JavaScript
import{F as g,K as W,S as E,W as O,a as k,b as y,d as S,e as d,f as w,g as j,h as p,x}from"./chunk-KWXDDR2S.js";var T={url:"",deserializer:i=>JSON.parse(i.data),serializer:i=>JSON.stringify(i)},C="WebSocketSubject.error must be called with an object with an error code, and an optional reason: { code: number, reason: string }",l=class i extends w{constructor(t,e){if(super(),this._socket=null,t instanceof S)this.destination=e,this.source=t;else{let o=this._config=Object.assign({},T);if(this._output=new d,typeof t=="string")o.url=t;else for(let c in t)t.hasOwnProperty(c)&&(o[c]=t[c]);if(!o.WebSocketCtor&&WebSocket)o.WebSocketCtor=WebSocket;else if(!o.WebSocketCtor)throw new Error("no WebSocket constructor can be found");this.destination=new p}}lift(t){let e=new i(this._config,this.destination);return e.operator=t,e.source=this,e}_resetState(){this._socket=null,this.source||(this.destination=new p),this._output=new d}multiplex(t,e,o){let c=this;return new S(s=>{try{c.next(t())}catch(a){s.error(a)}let r=c.subscribe({next:a=>{try{o(a)&&s.next(a)}catch(n){s.error(n)}},error:a=>s.error(a),complete:()=>s.complete()});return()=>{try{c.next(e())}catch(a){s.error(a)}r.unsubscribe()}})}_connectSocket(){let{WebSocketCtor:t,protocol:e,url:o,binaryType:c}=this._config,s=this._output,r=null;try{r=e?new t(o,e):new t(o),this._socket=r,c&&(this._socket.binaryType=c)}catch(n){s.error(n);return}let a=new k(()=>{this._socket=null,r&&r.readyState===1&&r.close()});r.onopen=n=>{let{_socket:u}=this;if(!u){r.close(),this._resetState();return}let{openObserver:m}=this._config;m&&m.next(n);let b=this.destination;this.destination=y.create(h=>{if(r.readyState===1)try{let{serializer:f}=this._config;r.send(f(h))}catch(f){this.destination.error(f)}},h=>{let{closingObserver:f}=this._config;f&&f.next(void 0),h&&h.code?r.close(h.code,h.reason):s.error(new TypeError(C)),this._resetState()},()=>{let{closingObserver:h}=this._config;h&&h.next(void 0),r.close(),this._resetState()}),b&&b instanceof p&&a.add(b.subscribe(this.destination))},r.onerror=n=>{this._resetState(),s.error(n)},r.onclose=n=>{r===this._socket&&this._resetState();let{closeObserver:u}=this._config;u&&u.next(n),n.wasClean?s.complete():s.error(n)},r.onmessage=n=>{try{let{deserializer:u}=this._config;s.next(u(n))}catch(u){s.error(u)}}}_subscribe(t){let{source:e}=this;return e?e.subscribe(t):(this._socket||this._connectSocket(),this._output.subscribe(t),t.add(()=>{let{_socket:o}=this;this._output.observers.length===0&&(o&&(o.readyState===1||o.readyState===0)&&o.close(),this._resetState())}),t)}unsubscribe(){let{_socket:t}=this;t&&(t.readyState===1||t.readyState===0)&&t.close(),this._resetState(),super.unsubscribe()}};function _(i){return new l(i)}var v={production:!0,translationServer:"",translationSocket:`ws://${location.host}`};var $=(()=>{class i{constructor(){this._projectSubject=new j(null),this.project=this._projectSubject.pipe(g((e,o)=>JSON.stringify(e)===JSON.stringify(o))),this.projectChange=this.project.pipe(x(e=>!!e)),_(v.translationSocket).pipe(E({error:()=>this._projectSubject.next(null)}),W({delay:1e3})).subscribe(e=>this._projectSubject.next(e))}static{this.\u0275fac=function(o){return new(o||i)}}static{this.\u0275prov=O({token:i,factory:i.\u0275fac,providedIn:"root"})}}return i})();export{v as a,$ as b};