import{s as x,f as h,E as L,G as j,w as E,a3 as S,V as A,y as m,ad as N,ae as U,z as g,P as b,Q as n,T as W,D as z,dG as B,dH as D,aH as P}from"./index-DT8qTvyx.js";var T=function(p){x(a,p);function a(){var e=p!==null&&p.apply(this,arguments)||this;return e.IFrameRef=h.createRef(),e.state={width:e.props.width||"100%",height:e.props.height||"100%"},e}return a.prototype.componentDidMount=function(){window.addEventListener("message",this.onMessage)},a.prototype.componentDidUpdate=function(e){var r=this.props.data;r!==e.data?this.postMessage("update",r):(this.props.width!==e.width||this.props.height!==e.height)&&this.setState({width:this.props.width||"100%",height:this.props.height||"100%"})},a.prototype.componentWillUnmount=function(){window.removeEventListener("message",this.onMessage)},a.prototype.validateURL=function(e){return e&&typeof e=="string"&&/^data:([a-zA-Z0-9]+\/[a-zA-Z0-9]+);base64,.*/.test(e)?!0:!(e&&typeof e=="string"&&!/^(\.\/|\.\.\/|\/|(blob\:)?https?\:\/\/|\/\/)/.test(e))},a.prototype.onMessage=function(e){var r,s,t;return L(this,void 0,void 0,function(){var i,u,v,_,w,d,C,o,f,y,c;return j(this,function(l){switch(l.label){case 0:return i=this.props,u=i.events,v=i.onEvent,_=i.onAction,w=i.data,typeof((r=e==null?void 0:e.data)===null||r===void 0?void 0:r.type)!="string"?[2]:(d=P(e.data.type.split(":"),2),C=d[0],o=d[1],C!=="amis"||!o?[2]:o==="resize"&&e.data.data?(this.setState({width:e.data.data.width||"100%",height:e.data.data.height||"100%"}),[3,4]):[3,1]);case 1:return f=v==null?void 0:v[o],f&&(!((s=f.actions)===null||s===void 0)&&s.length)?(y=B(o,{env:(t=this.props)===null||t===void 0?void 0:t.env,nativeEvent:e,data:S(w,e.data.data),scoped:this.context}),[4,D(f.actions,this,y)]):[3,3];case 2:if(l.sent(),y.prevented)return[2];l.label=3;case 3:u&&(c=u[o],c&&_(e,c,S(w,e.data.data))),l.label=4;case 4:return[2]}})})},a.prototype.onLoad=function(){var e=this.props,r=e.src,s=e.data;r&&this.postMessage("init",s)},a.prototype.reload=function(e,r){if(r)return this.receive(r);var s=this.props,t=s.src,i=s.data;t&&(this.IFrameRef.current.src=E(t,i,"| raw"))},a.prototype.receive=function(e){var r=this.props,s=r.src,t=r.data,i=S(t,e);this.postMessage("receive",i),A(s,s,t,i)&&(this.IFrameRef.current.src=E(s,i,"| raw"))},a.prototype.postMessage=function(e,r){var s,t;(t=(s=this.IFrameRef.current)===null||s===void 0?void 0:s.contentWindow)===null||t===void 0||t.postMessage({type:"amis:".concat(e),data:JSON.parse(JSON.stringify(r))},"*")},a.prototype.render=function(){var e=this.state,r=e.width,s=e.height,t=this.props,i=t.className,u=t.src,v=t.name,_=t.frameBorder,w=t.data,d=t.style,C=t.allow,o=t.sandbox,f=t.referrerpolicy,y=t.translate,c=t.id,l=t.wrapperCustomStyle,I=t.env,M=t.themeCss;t.baseControlClassName;var O=t.classnames,R={};r!==void 0&&(R.width=r),s!==void 0&&(R.height=s),d=m(m({},R),d);var F=u?E(u,w,"| raw"):void 0;return this.validateURL(F)?(location.protocol==="https:"&&F&&F.startsWith("http://")&&I.notify("error",y("Iframe.invalidProtocol")),h.createElement(h.Fragment,null,h.createElement("iframe",{name:v,className:O("IFrame",i,N(m(m({},this.props),{name:"baseControlClassName",id:c,themeCss:M})),N(m(m({},this.props),{name:"wrapperCustomStyle",id:c,themeCss:l}))),frameBorder:_,style:d,ref:this.IFrameRef,onLoad:this.onLoad,src:F,allow:C,referrerPolicy:f,sandbox:o}),h.createElement(U,m({},this.props,{config:{wrapperCustomStyle:l,id:c,themeCss:M,classNames:[{key:"baseControlClassName"}]},env:I})))):h.createElement("p",null,y("Iframe.invalid"))},a.propsList=["src","className"],a.defaultProps={className:"",frameBorder:0},g([b,n("design:type",Function),n("design:paramtypes",[MessageEvent]),n("design:returntype",Promise)],a.prototype,"onMessage",null),g([b,n("design:type",Function),n("design:paramtypes",[]),n("design:returntype",void 0)],a.prototype,"onLoad",null),g([b,n("design:type",Function),n("design:paramtypes",[Object,Object]),n("design:returntype",void 0)],a.prototype,"reload",null),g([b,n("design:type",Function),n("design:paramtypes",[Object]),n("design:returntype",void 0)],a.prototype,"receive",null),g([b,n("design:type",Function),n("design:paramtypes",[String,Object]),n("design:returntype",void 0)],a.prototype,"postMessage",null),a}(h.Component),H=function(p){x(a,p);function a(e,r){var s=p.call(this,e)||this,t=r;return t.registerComponent(s),s}return a.prototype.componentWillUnmount=function(){var e=this.context;e.unRegisterComponent(this),p.prototype.componentWillUnmount.call(this)},a.contextType=W,a=g([z({type:"iframe"}),n("design:paramtypes",[Object,Object])],a),a}(T);export{H as IFrameRenderer,T as default};
