Files
open-kimi-ppt-skill/editor/neo-ppt/assets/penpal-legacy-Dgg3M9hr.js
T

1 line
9.7 KiB
JavaScript

System.register(["./vue-legacy-BnJhYd-u.js","./common-utils-legacy-BUVwbO7W.js"],function(e,t){var s,n,a,r,i,o,l,d,c,h,u,p,m,g,f,v,M,w,y,I,E,S,N,A,T,O,C,R,L,k,D,P,_,b,W,j,F,Y,$,H,U,V,K,x,z,G,J,X,q,B,Q,Z,ee,te,se,ne,ae,re,ie;return{setters:[function(e){s=e.c,n=e.l,a=e.u},function(e){r=e.o}],execute:function(){I=class extends Error{constructor(e,t){super(t),r(this,"code",void 0),this.name="PenpalError",this.code=e}},e("n",E=I),S=e=>({name:e.name,message:e.message,stack:e.stack,penpalCode:e instanceof E?e.code:void 0}),N=({name:e,message:t,stack:s,penpalCode:n})=>{const a=n?new E(n,t):new Error(t);return a.name=e,a.stack=s,a},A=Symbol("Reply"),i=new WeakMap,T=class{constructor(e,t){r(this,"value",void 0),r(this,"transferables",void 0),a(this,i,A),this.value=e,this.transferables=t?.transferables}},O="penpal",C=e=>"object"==typeof e&&null!==e,R=e=>"function"==typeof e,L=e=>C(e)&&e.namespace===O,k=e=>"SYN"===e.type,D=e=>"ACK1"===e.type,P=e=>"ACK2"===e.type,_=e=>"CALL"===e.type,b=e=>"REPLY"===e.type,W=e=>"DESTROY"===e.type,j=(e,t=[])=>{const s=[];for(const n of Object.keys(e)){const a=e[n];R(a)?s.push([...t,n]):C(a)&&s.push(...j(a,[...t,n]))}return s},F=(e,t)=>{const s=e.reduce((e,t)=>C(e)?e[t]:void 0,t);return R(s)?s:void 0},Y=e=>e.join("."),$=(e,t,s)=>({namespace:O,channel:e,type:"REPLY",callId:t,isError:!0,...s instanceof Error?{value:S(s),isSerializedErrorInstance:!0}:{value:s}}),H=(e,t,s,n)=>{let a=!1;const r=async r=>{if(a)return;if(!_(r))return;n?.(`Received ${Y(r.methodPath)}() call`,r);const{methodPath:i,args:o,id:l}=r;let d,c;try{const e=F(i,t);if(!e)throw new E("METHOD_NOT_FOUND",`Method \`${Y(i)}\` is not found.`);let n=await e(...o);n instanceof T&&(c=n.transferables,n=await n.value),d={namespace:O,channel:s,type:"REPLY",callId:l,value:n}}catch(h){d=$(s,l,h)}if(!a)try{n?.(`Sending ${Y(i)}() reply`,d),e.sendMessage(d,c)}catch(h){throw"DataCloneError"===h.name&&(d=$(s,l,h),n?.(`Sending ${Y(i)}() reply`,d),e.sendMessage(d)),h}};return e.addMessageHandler(r),()=>{a=!0,e.removeMessageHandler(r)}},U=crypto.randomUUID?.bind(crypto)??(()=>new Array(4).fill(0).map(()=>Math.floor(Math.random()*Number.MAX_SAFE_INTEGER).toString(16)).join("-")),V=Symbol("CallOptions"),o=new WeakMap,K=class{constructor(e){r(this,"transferables",void 0),r(this,"timeout",void 0),a(this,o,V),this.transferables=e?.transferables,this.timeout=e?.timeout}},x=new Set(["apply","call","bind"]),z=(e,t,s=[])=>new Proxy(s.length?()=>{}:Object.create(null),{get(n,a){if("then"!==a)return s.length&&x.has(a)?Reflect.get(n,a):z(e,t,[...s,a])},apply:(t,n,a)=>e(s,a)}),G=e=>new E("CONNECTION_DESTROYED",`Method call ${Y(e)}() failed due to destroyed connection`),J=(e,t,s)=>{let n=!1;const a=new Map,r=e=>{if(!b(e))return;const{callId:t,value:n,isError:r,isSerializedErrorInstance:i}=e,o=a.get(t);o&&(a.delete(t),s?.(`Received ${Y(o.methodPath)}() call`,e),r?o.reject(i?N(n):n):o.resolve(n))};return e.addMessageHandler(r),{remoteProxy:z((r,i)=>{if(n)throw G(r);const o=U(),l=i[i.length-1],d=l instanceof K,{timeout:c,transferables:h}=d?l:{},u=d?i.slice(0,-1):i;return new Promise((n,i)=>{const l=void 0!==c?window.setTimeout(()=>{a.delete(o),i(new E("METHOD_CALL_TIMEOUT",`Method call ${Y(r)}() timed out after ${c}ms`))},c):void 0;a.set(o,{methodPath:r,resolve:n,reject:i,timeoutId:l});try{const n={namespace:O,channel:t,type:"CALL",id:o,methodPath:r,args:u};s?.(`Sending ${Y(r)}() call`,n),e.sendMessage(n,h)}catch(d){i(new E("TRANSMISSION_FAILED",d.message))}})},s),destroy:()=>{n=!0,e.removeMessageHandler(r);for(const{methodPath:e,reject:t,timeoutId:s}of a.values())clearTimeout(s),t(G(e));a.clear()}}},X=()=>{let e,t;return{promise:new Promise((s,n)=>{e=s,t=n}),resolve:e,reject:t}},q="deprecated-penpal",B=e=>C(e)&&"penpal"in e,Q=e=>e.split("."),Z=e=>e.join("."),ee=e=>{try{return JSON.stringify(e)}catch(t){return String(e)}},te=e=>new E("TRANSMISSION_FAILED",`Unexpected message to translate: ${ee(e)}`),se=e=>{if("syn"===e.penpal)return{namespace:O,channel:void 0,type:"SYN",participantId:q};if("ack"===e.penpal)return{namespace:O,channel:void 0,type:"ACK2"};if("call"===e.penpal)return{namespace:O,channel:void 0,type:"CALL",id:e.id,methodPath:Q(e.methodName),args:e.args};if("reply"===e.penpal)return"fulfilled"===e.resolution?{namespace:O,channel:void 0,type:"REPLY",callId:e.id,value:e.returnValue}:{namespace:O,channel:void 0,type:"REPLY",callId:e.id,isError:!0,...e.returnValueIsError?{value:e.returnValue,isSerializedErrorInstance:!0}:{value:e.returnValue}};throw te(e)},ne=e=>{if(D(e))return{penpal:"synAck",methodNames:e.methodPaths.map(Z)};if(_(e))return{penpal:"call",id:e.id,methodName:Z(e.methodPath),args:e.args};if(b(e))return e.isError?{penpal:"reply",id:e.callId,resolution:"rejected",...e.isSerializedErrorInstance?{returnValue:e.value,returnValueIsError:!0}:{returnValue:e.value}}:{penpal:"reply",id:e.callId,resolution:"fulfilled",returnValue:e.value};throw te(e)},ae=({messenger:e,methods:t,timeout:s,channel:n,log:a})=>{const r=U();let i;const o=[];let l=!1;const d=j(t),{promise:c,resolve:h,reject:u}=X(),p=void 0!==s?setTimeout(()=>{u(new E("CONNECTION_TIMEOUT",`Connection timed out after ${s}ms`))},s):void 0,m=()=>{for(const e of o)e()},g=()=>{if(l)return;o.push(H(e,t,n,a));const{remoteProxy:s,destroy:r}=J(e,n,a);o.push(r),clearTimeout(p),l=!0,h({remoteProxy:s,destroy:m})},f=()=>{const t={namespace:O,type:"SYN",channel:n,participantId:r};a?.("Sending handshake SYN",t);try{e.sendMessage(t)}catch(s){u(new E("TRANSMISSION_FAILED",s.message))}},v=t=>{k(t)&&(t=>{if(a?.("Received handshake SYN",t),t.participantId===i&&i!==q)return;if(i=t.participantId,f(),!(r>i||i===q))return;const s={namespace:O,channel:n,type:"ACK1",methodPaths:d};a?.("Sending handshake ACK1",s);try{e.sendMessage(s)}catch(o){return void u(new E("TRANSMISSION_FAILED",o.message))}})(t),D(t)&&(t=>{a?.("Received handshake ACK1",t);const s={namespace:O,channel:n,type:"ACK2"};a?.("Sending handshake ACK2",s);try{e.sendMessage(s)}catch(r){return void u(new E("TRANSMISSION_FAILED",r.message))}g()})(t),P(t)&&(e=>{a?.("Received handshake ACK2",e),g()})(t)};return e.addMessageHandler(v),o.push(()=>e.removeMessageHandler(v)),f(),c},re=e=>{let t,s=!1;return(...n)=>(s||(s=!0,t=e(...n)),t)},ie=new WeakSet,e("i",({messenger:e,methods:t={},timeout:s,channel:n,log:a})=>{if(!e)throw new E("INVALID_ARGUMENT","messenger must be defined");if(ie.has(e))throw new E("INVALID_ARGUMENT","A messenger can only be used for a single connection");ie.add(e);const r=[e.destroy],i=re(t=>{if(t){const t={namespace:O,channel:n,type:"DESTROY"};try{e.sendMessage(t)}catch(s){}}for(const e of r)e();a?.("Connection destroyed")}),o=e=>L(e)&&e.channel===n;return{promise:(async()=>{try{e.initialize({log:a,validateReceivedMessage:o}),e.addMessageHandler(e=>{W(e)&&i(!1)});const{remoteProxy:l,destroy:d}=await ae({messenger:e,methods:t,timeout:s,channel:n,log:a});return r.push(d),l}catch(l){throw i(!0),l}})(),destroy:()=>{i(!0)}}}),e("r",(l=new WeakMap,d=new WeakMap,c=new WeakMap,h=new WeakMap,u=new WeakMap,p=new WeakMap,m=new WeakMap,g=new WeakMap,f=new WeakMap,v=new WeakMap,M=new WeakMap,w=new WeakMap,y=new WeakMap,class{constructor({remoteWindow:e,allowedOrigins:t}){if(a(this,l,void 0),a(this,d,void 0),a(this,c,void 0),a(this,h,void 0),a(this,u,void 0),a(this,p,new Set),a(this,m,void 0),a(this,g,!1),r(this,"initialize",({log:e,validateReceivedMessage:t})=>{s(c,this,e),s(h,this,t),window.addEventListener("message",n(w,this))}),r(this,"sendMessage",(e,t)=>{if(k(e)){const s=n(v,this).call(this,e);return void n(l,this).postMessage(e,{targetOrigin:s,transfer:t})}if(D(e)||n(g,this)){const s=n(g,this)?ne(e):e,a=n(v,this).call(this,e);return void n(l,this).postMessage(s,{targetOrigin:a,transfer:t})}if(P(e)){const{port1:a,port2:r}=new MessageChannel;s(m,this,a),a.addEventListener("message",n(y,this)),a.start();const i=[r,...t||[]],o=n(v,this).call(this,e);return void n(l,this).postMessage(e,{targetOrigin:o,transfer:i})}if(!n(m,this))throw new E("TRANSMISSION_FAILED","Cannot send message because the MessagePort is not connected");n(m,this).postMessage(e,{transfer:t})}),r(this,"addMessageHandler",e=>{n(p,this).add(e)}),r(this,"removeMessageHandler",e=>{n(p,this).delete(e)}),r(this,"destroy",()=>{window.removeEventListener("message",n(w,this)),n(M,this).call(this),n(p,this).clear()}),a(this,f,e=>n(d,this).some(t=>t instanceof RegExp?t.test(e):t===e||"*"===t)),a(this,v,e=>{if(k(e))return"*";if(!n(u,this))throw new E("TRANSMISSION_FAILED","Cannot send message because the remote origin is not established");return"null"===n(u,this)&&n(d,this).includes("*")?"*":n(u,this)}),a(this,M,()=>{n(m,this)?.removeEventListener("message",n(y,this)),n(m,this)?.close(),s(m,this,void 0)}),a(this,w,({source:e,origin:t,ports:a,data:r})=>{if(e===n(l,this)){if(B(r)){n(c,this)?.call(this,"Please upgrade the child window to the latest version of Penpal."),s(g,this,!0);try{r=se(r)}catch(i){return void n(c,this)?.call(this,`Failed to translate deprecated message: ${i.message}`)}}if(n(h,this)?.call(this,r))if(n(f,this).call(this,t)){if(k(r)&&(n(M,this).call(this),s(u,this,t)),P(r)&&!n(g,this)){if(s(m,this,a[0]),!n(m,this))return void n(c,this)?.call(this,"Ignoring ACK2 because it did not include a MessagePort");n(m,this).addEventListener("message",n(y,this)),n(m,this).start()}for(const e of n(p,this))e(r)}else n(c,this)?.call(this,`Received a message from origin \`${t}\` which did not match allowed origins \`[${n(d,this).join(", ")}]\``)}}),a(this,y,({data:e})=>{if(n(h,this)?.call(this,e))for(const t of n(p,this))t(e)}),!e)throw new E("INVALID_ARGUMENT","remoteWindow must be defined");s(l,this,e),s(d,this,t?.length?t:[window.origin])}})),e("t",{ConnectionDestroyed:"CONNECTION_DESTROYED",ConnectionTimeout:"CONNECTION_TIMEOUT",InvalidArgument:"INVALID_ARGUMENT",MethodCallTimeout:"METHOD_CALL_TIMEOUT",MethodNotFound:"METHOD_NOT_FOUND",TransmissionFailed:"TRANSMISSION_FAILED"})}}});