import{r as t,d as i,B as e,h as n,H as o,e as l}from"./p-f8363b1b.js";import{a as s}from"./p-baa91ba7.js";import{F as r,g as a,a as u,_ as d,b as h,C as c,r as v,S as p}from"./p-98d7792a.js";import{m as f,c as m,t as g}from"./p-3b9b3ee7.js";import{l as w}from"./p-82ae0260.js";import{h as y,m as b}from"./p-47accef4.js";import{e as x}from"./p-eaddf196.js";import{i as j}from"./p-cebc952c.js";import"./p-d2ac57a0.js";import"./p-f44f0a67.js";import"./p-80de33dc.js";import"./p-bf71b10e.js";
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class $ extends r{constructor(t,i){super(T(t),`Firebase Storage: ${i} (${T(t)})`),this.customData={serverResponse:null},this._baseMessage=this.message,Object.setPrototypeOf(this,$.prototype)}_codeEquals(t){return T(t)===this.code}get serverResponse(){return this.customData.serverResponse}set serverResponse(t){this.customData.serverResponse=t,this.message=this.customData.serverResponse?`${this._baseMessage}\n${this.customData.serverResponse}`:this._baseMessage}}function T(t){return"storage/"+t}function k(){return new $("unknown","An unknown error occurred, please check the error payload for server response.")}function R(t){return new $("invalid-argument",t)}function C(){return new $("app-deleted","The Firebase app was deleted.")}function E(t,i){return new $("invalid-format","String does not match format '"+t+"': "+i)}function S(t){throw new $("internal-error","Internal error: "+t)}
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */class P{constructor(t,i){this.bucket=t,this.path_=i}get path(){return this.path_}get isRoot(){return 0===this.path.length}fullServerUrl(){const t=encodeURIComponent;return"/b/"+t(this.bucket)+"/o/"+t(this.path)}bucketOnlyServerUrl(){return"/b/"+encodeURIComponent(this.bucket)+"/o"}static makeFromBucketSpec(t,i){let e;try{e=P.makeFromUrl(t,i)}catch(i){return new P(t,"")}if(""===e.path)return e;throw new $("invalid-default-bucket","Invalid default bucket '"+t+"'.")}static makeFromUrl(t,i){let e=null;const n="([A-Za-z0-9.\\-_]+)",o=new RegExp("^gs://"+n+"(/(.*))?$","i");function l(t){t.path_=decodeURIComponent(t.path)}const s=i.replace(/[.]/g,"\\."),r=[{regex:o,indices:{bucket:1,path:3},postModify:function(t){"/"===t.path.charAt(t.path.length-1)&&(t.path_=t.path_.slice(0,-1))}},{regex:new RegExp(`^https?://${s}/v[A-Za-z0-9_]+/b/${n}/o(/([^?#]*).*)?$`,"i"),indices:{bucket:1,path:3},postModify:l},{regex:new RegExp(`^https?://${"firebasestorage.googleapis.com"===i?"(?:storage.googleapis.com|storage.cloud.google.com)":i}/${n}/([^?#]*)`,"i"),indices:{bucket:1,path:2},postModify:l}];for(let i=0;i<r.length;i++){const n=r[i],o=n.regex.exec(t);if(o){let t=o[n.indices.path];t||(t=""),e=new P(o[n.indices.bucket],t),n.postModify(e);break}}if(null==e)throw function(t){return new $("invalid-url","Invalid URL '"+t+"'.")}(t);return e}}class U{constructor(t){this.promise_=Promise.reject(t)}getPromise(){return this.promise_}cancel(t=!1){}}
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function I(t){return"string"==typeof t||t instanceof String}function O(t){return M()&&t instanceof Blob}function M(){return"undefined"!=typeof Blob}function H(t,i,e,n){if(n<i)throw R(`Invalid value for '${t}'. Expected ${i} or greater.`);if(n>e)throw R(`Invalid value for '${t}'. Expected ${e} or less.`)}
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function F(t,i,e){let n=i;return null==e&&(n=`https://${i}`),`${e}://${n}/v0${t}`}function A(t){const i=encodeURIComponent;let e="?";for(const n in t)t.hasOwnProperty(n)&&(e=e+(i(n)+"=")+i(t[n])+"&");return e=e.slice(0,-1),e}
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */var D;!function(t){t[t.NO_ERROR=0]="NO_ERROR",t[t.NETWORK_ERROR=1]="NETWORK_ERROR",t[t.ABORT=2]="ABORT"}(D||(D={}));
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
class _{constructor(t,i,e,n,o,l,s,r,a,u,d){this.url_=t,this.method_=i,this.headers_=e,this.body_=n,this.successCodes_=o,this.additionalRetryCodes_=l,this.callback_=s,this.errorCallback_=r,this.timeout_=a,this.progressCallback_=u,this.connectionFactory_=d,this.pendingConnection_=null,this.backoffId_=null,this.canceled_=!1,this.appDelete_=!1,this.promise_=new Promise(((t,i)=>{this.resolve_=t,this.reject_=i,this.start_()}))}start_(){const t=(t,i)=>{const e=this.resolve_,n=this.reject_,o=i.connection;if(i.wasSuccessCode)try{const t=this.callback_(o,o.getResponse());void 0!==t?e(t):e()}catch(t){n(t)}else if(null!==o){const t=k();t.serverResponse=o.getErrorText(),n(this.errorCallback_?this.errorCallback_(o,t):t)}else n(i.canceled?this.appDelete_?C():new $("canceled","User canceled the upload/download."):new $("retry-limit-exceeded","Max retry time for operation exceeded, please try again."))};this.canceled_?t(0,new B(!1,null,!0)):this.backoffId_=function(t,i,e){let n=1,o=null,l=null,s=!1,r=0;function a(){return 2===r}let u=!1;function d(...t){u||(u=!0,i.apply(null,t))}function h(i){o=setTimeout((()=>{o=null,t(v,a())}),i)}function c(){l&&clearTimeout(l)}function v(t,...i){if(u)return void c();if(t)return c(),void d.call(null,t,...i);if(a()||s)return c(),void d.call(null,t,...i);let e;n<64&&(n*=2),1===r?(r=2,e=0):e=1e3*(n+Math.random()),h(e)}let p=!1;function f(t){p||(p=!0,c(),u||(null!==o?(t||(r=2),clearTimeout(o),h(0)):t||(r=1)))}return h(0),l=setTimeout((()=>{s=!0,f(!0)}),e),f}(((t,i)=>{if(i)return void t(!1,new B(!1,null,!0));const e=this.connectionFactory_();this.pendingConnection_=e;const n=t=>{null!==this.progressCallback_&&this.progressCallback_(t.loaded,t.lengthComputable?t.total:-1)};null!==this.progressCallback_&&e.addUploadProgressListener(n),e.send(this.url_,this.method_,this.body_,this.headers_).then((()=>{null!==this.progressCallback_&&e.removeUploadProgressListener(n),this.pendingConnection_=null;const i=e.getErrorCode()===D.NO_ERROR,o=e.getStatus();if(!i||this.isRetryStatusCode_(o)){const i=e.getErrorCode()===D.ABORT;return void t(!1,new B(!1,null,i))}const l=-1!==this.successCodes_.indexOf(o);t(!0,new B(l,e))}))}),t,this.timeout_)}getPromise(){return this.promise_}cancel(t){this.canceled_=!0,this.appDelete_=t||!1,null!==this.backoffId_&&(0,this.backoffId_)(!1),null!==this.pendingConnection_&&this.pendingConnection_.abort()}isRetryStatusCode_(t){const i=t>=500&&t<600,e=-1!==[408,429].indexOf(t),n=-1!==this.additionalRetryCodes_.indexOf(t);return i||e||n}}class B{constructor(t,i,e){this.wasSuccessCode=t,this.connection=i,this.canceled=!!e}}
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function L(){return"undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof WebKitBlobBuilder?WebKitBlobBuilder:void 0}function N(...t){const i=L();if(void 0!==i){const e=new i;for(let i=0;i<t.length;i++)e.append(t[i]);return e.getBlob()}if(M())return new Blob(t);throw new $("unsupported-environment","This browser doesn't seem to support creating Blobs")}class z{constructor(t,i){this.data=t,this.contentType=i||null}}function J(t){const i=[];for(let e=0;e<t.length;e++){let n=t.charCodeAt(e);n<=127?i.push(n):n<=2047?i.push(192|n>>6,128|63&n):55296==(64512&n)?e<t.length-1&&56320==(64512&t.charCodeAt(e+1))?(n=65536|(1023&n)<<10|1023&t.charCodeAt(++e),i.push(240|n>>18,128|n>>12&63,128|n>>6&63,128|63&n)):i.push(239,191,189):56320==(64512&n)?i.push(239,191,189):i.push(224|n>>12,128|n>>6&63,128|63&n)}return new Uint8Array(i)}function q(t,i){switch(t){case"base64":{const e=-1!==i.indexOf("-"),n=-1!==i.indexOf("_");if(e||n)throw E(t,"Invalid character '"+(e?"-":"_")+"' found: is it base64url encoded?");break}case"base64url":{const e=-1!==i.indexOf("+"),n=-1!==i.indexOf("/");if(e||n)throw E(t,"Invalid character '"+(e?"+":"/")+"' found: is it base64 encoded?");i=i.replace(/-/g,"+").replace(/_/g,"/");break}}let e;try{e=atob(i)}catch(i){throw E(t,"Invalid character found")}const n=new Uint8Array(e.length);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t);return n}class K{constructor(t){this.base64=!1,this.contentType=null;const i=t.match(/^data:([^,]+)?,/);if(null===i)throw E("data_url","Must be formatted 'data:[<mediatype>][;base64],<data>");const e=i[1]||null;var n,o;
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */null!=e&&(this.base64=(n=e).length>=(o=";base64").length&&n.substring(n.length-o.length)===o,this.contentType=this.base64?e.substring(0,e.length-";base64".length):e),this.rest=t.substring(t.indexOf(",")+1)}}class W{constructor(t,i){let e=0,n="";O(t)?(this.data_=t,e=t.size,n=t.type):t instanceof ArrayBuffer?(i?this.data_=new Uint8Array(t):(this.data_=new Uint8Array(t.byteLength),this.data_.set(new Uint8Array(t))),e=this.data_.length):t instanceof Uint8Array&&(i?this.data_=t:(this.data_=new Uint8Array(t.length),this.data_.set(t)),e=t.length),this.size_=e,this.type_=n}size(){return this.size_}type(){return this.type_}slice(t,i){if(O(this.data_)){const l=(n=t,o=i,(e=this.data_).webkitSlice?e.webkitSlice(n,o):e.mozSlice?e.mozSlice(n,o):e.slice?e.slice(n,o):null);return null===l?null:new W(l)}var e,n,o;
/**
 * @license
 * Copyright 2021 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */{const e=new Uint8Array(this.data_.buffer,t,i-t);return new W(e,!0)}}static getBlob(...t){if(M()){const i=t.map((t=>t instanceof W?t.data_:t));return new W(N.apply(null,i))}{const i=t.map((t=>I(t)?function(t,i){switch(t){case"raw":return new z(J(i));case"base64":case"base64url":return new z(q(t,i));case"data_url":return new z(function(t){const i=new K(t);return i.base64?q("base64",i.rest):function(t){let i;try{i=decodeURIComponent(t)}catch(t){throw E("data_url","Malformed data URL.")}return J(i)}(i.rest)}(i),new K(i).contentType)}throw k()}("raw",t).data:t.data_));let e=0;i.forEach((t=>{e+=t.byteLength}));const n=new Uint8Array(e);let o=0;return i.forEach((t=>{for(let i=0;i<t.length;i++)n[o++]=t[i]})),new W(n,!0)}}uploadData(){return this.data_}}
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function X(t){let i;try{i=JSON.parse(t)}catch(t){return null}return"object"!=typeof(e=i)||Array.isArray(e)?null:i;var e}
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function Z(t){const i=t.lastIndexOf("/",t.length-2);return-1===i?t:t.slice(i+1)}
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function G(t,i){return i}class Q{constructor(t,i,e,n){this.server=t,this.local=i||t,this.writable=!!e,this.xform=n||G}}let V=null;function Y(){if(V)return V;const t=[];t.push(new Q("bucket")),t.push(new Q("generation")),t.push(new Q("metageneration")),t.push(new Q("name","fullPath",!0));const i=new Q("name");i.xform=function(t,i){return function(t){return!I(t)||t.length<2?t:Z(t)}(i)},t.push(i);const e=new Q("size");return e.xform=function(t,i){return void 0!==i?Number(i):i},t.push(e),t.push(new Q("timeCreated")),t.push(new Q("updated")),t.push(new Q("md5Hash",null,!0)),t.push(new Q("cacheControl",null,!0)),t.push(new Q("contentDisposition",null,!0)),t.push(new Q("contentEncoding",null,!0)),t.push(new Q("contentLanguage",null,!0)),t.push(new Q("contentType",null,!0)),t.push(new Q("metadata","customMetadata",!0)),V=t,V}function tt(t,i,e){const n=X(i);return null===n?null:function(t,i,e){const n={type:"file"},o=e.length;for(let t=0;t<o;t++){const o=e[t];n[o.local]=o.xform(n,i[o.server])}return function(t,i){Object.defineProperty(t,"ref",{get:function(){const e=new P(t.bucket,t.fullPath);return i._makeStorageReference(e)}})}(n,t),n}(t,n,e)}class it{constructor(t,i,e,n){this.url=t,this.method=i,this.handler=e,this.timeout=n,this.urlParams={},this.headers={},this.body=null,this.errorHandler=null,this.progressCallback=null,this.successCodes=[200],this.additionalRetryCodes=[]}}
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */function et(t){if(!t)throw k()}function nt(t){return function(i,e){let n;return n=401===i.getStatus()?i.getErrorText().includes("Firebase App Check token is invalid")?new $("unauthorized-app","This app does not have permission to access Firebase Storage on this project."):new $("unauthenticated","User is not authenticated, please authenticate using Firebase Authentication and try again."):402===i.getStatus()?new $("quota-exceeded","Quota for bucket '"+t.bucket+"' exceeded, please view quota on https://firebase.google.com/pricing/."):403===i.getStatus()?new $("unauthorized","User does not have permission to access '"+t.path+"'."):e,n.serverResponse=e.serverResponse,n}}class ot extends class{constructor(){this.sent_=!1,this.xhr_=new XMLHttpRequest,this.initXhr(),this.errorCode_=D.NO_ERROR,this.sendPromise_=new Promise((t=>{this.xhr_.addEventListener("abort",(()=>{this.errorCode_=D.ABORT,t()})),this.xhr_.addEventListener("error",(()=>{this.errorCode_=D.NETWORK_ERROR,t()})),this.xhr_.addEventListener("load",(()=>{t()}))}))}send(t,i,e,n){if(this.sent_)throw S("cannot .send() more than once");if(this.sent_=!0,this.xhr_.open(i,t,!0),void 0!==n)for(const t in n)n.hasOwnProperty(t)&&this.xhr_.setRequestHeader(t,n[t].toString());return void 0!==e?this.xhr_.send(e):this.xhr_.send(),this.sendPromise_}getErrorCode(){if(!this.sent_)throw S("cannot .getErrorCode() before sending");return this.errorCode_}getStatus(){if(!this.sent_)throw S("cannot .getStatus() before sending");try{return this.xhr_.status}catch(t){return-1}}getResponse(){if(!this.sent_)throw S("cannot .getResponse() before sending");return this.xhr_.response}getErrorText(){if(!this.sent_)throw S("cannot .getErrorText() before sending");return this.xhr_.statusText}abort(){this.xhr_.abort()}getResponseHeader(t){return this.xhr_.getResponseHeader(t)}addUploadProgressListener(t){null!=this.xhr_.upload&&this.xhr_.upload.addEventListener("progress",t)}removeUploadProgressListener(t){null!=this.xhr_.upload&&this.xhr_.upload.removeEventListener("progress",t)}}{initXhr(){this.xhr_.responseType="text"}}function lt(){return new ot}
/**
 * @license
 * Copyright 2019 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */class st{constructor(t,i){this._service=t,this._location=i instanceof P?i:P.makeFromUrl(i,t.host)}toString(){return"gs://"+this._location.bucket+"/"+this._location.path}_newRef(t,i){return new st(t,i)}get root(){const t=new P(this._location.bucket,"");return this._newRef(this._service,t)}get bucket(){return this._location.bucket}get fullPath(){return this._location.path}get name(){return Z(this._location.path)}get storage(){return this._service}get parent(){const t=function(t){if(0===t.length)return null;const i=t.lastIndexOf("/");return-1===i?"":t.slice(0,i)}(this._location.path);if(null===t)return null;const i=new P(this._location.bucket,t);return new st(this._service,i)}_throwIfRoot(t){if(""===this._location.path)throw function(t){return new $("invalid-root-operation","The operation '"+t+"' cannot be performed on a root reference, create a non-root reference using child, such as .child('file.png').")}(t)}}function rt(t){t._throwIfRoot("getDownloadURL");const i=function(t,i,e){const n=F(i.fullServerUrl(),t.host,t._protocol),o=t.maxOperationRetryTime,l=new it(n,"GET",function(t,i){return function(e,n){const o=tt(t,n,i);return et(null!==o),function(t,i,e,n){const o=X(i);if(null===o)return null;if(!I(o.downloadTokens))return null;const l=o.downloadTokens;if(0===l.length)return null;const s=encodeURIComponent;return l.split(",").map((i=>{const o=t.fullPath;return F("/b/"+s(t.bucket)+"/o/"+s(o),e,n)+A({alt:"media",token:i})}))[0]}(o,n,t.host,t._protocol)}}(t,e),o);return l.errorHandler=function(t){const i=nt(t);return function(e,n){let o=i(e,n);return 404===e.getStatus()&&(o=new $("object-not-found","Object '"+t.path+"' does not exist.")),o.serverResponse=n.serverResponse,o}}(i),l}(t.storage,t._location,Y());return t.storage.makeRequestWithTokens(i,lt).then((t=>{if(null===t)throw new $("no-download-url","The given file does not have any download URLs.");return t}))}function at(t,i){if(t instanceof ht){const e=t;if(null==e._bucket)throw new $("no-default-bucket","No default bucket found. Did you set the 'storageBucket' property when initializing the app?");const n=new st(e,e._bucket);return null!=i?at(n,i):n}return void 0!==i?function(t,i){const e=function(t,i){const e=i.split("/").filter((t=>t.length>0)).join("/");return 0===t.length?e:t+"/"+e}(t._location.path,i),n=new P(t._location.bucket,e);return new st(t.storage,n)}
/**
 * @license
 * Copyright 2017 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */(t,i):t}function ut(t,i){if(i&&/^[A-Za-z]+:\/\//.test(i)){if(t instanceof ht)return new st(t,i);throw R("To use ref(service, url), the first argument must be a Storage instance.")}return at(t,i)}function dt(t,i){const e=null==i?void 0:i.storageBucket;return null==e?null:P.makeFromBucketSpec(e,t)}class ht{constructor(t,i,e,n,o){this.app=t,this._authProvider=i,this._appCheckProvider=e,this._url=n,this._firebaseVersion=o,this._bucket=null,this._host="firebasestorage.googleapis.com",this._protocol="https",this._appId=null,this._deleted=!1,this._maxOperationRetryTime=12e4,this._maxUploadRetryTime=6e5,this._requests=new Set,this._bucket=null!=n?P.makeFromBucketSpec(n,this._host):dt(this._host,this.app.options)}get host(){return this._host}set host(t){this._host=t,this._bucket=null!=this._url?P.makeFromBucketSpec(this._url,t):dt(t,this.app.options)}get maxUploadRetryTime(){return this._maxUploadRetryTime}set maxUploadRetryTime(t){H("time",0,Number.POSITIVE_INFINITY,t),this._maxUploadRetryTime=t}get maxOperationRetryTime(){return this._maxOperationRetryTime}set maxOperationRetryTime(t){H("time",0,Number.POSITIVE_INFINITY,t),this._maxOperationRetryTime=t}async _getAuthToken(){if(this._overrideAuthToken)return this._overrideAuthToken;const t=this._authProvider.getImmediate({optional:!0});if(t){const i=await t.getToken();if(null!==i)return i.accessToken}return null}async _getAppCheckToken(){const t=this._appCheckProvider.getImmediate({optional:!0});return t?(await t.getToken()).token:null}_delete(){return this._deleted||(this._deleted=!0,this._requests.forEach((t=>t.cancel())),this._requests.clear()),Promise.resolve()}_makeStorageReference(t){return new st(this,t)}_makeRequest(t,i,e,n){if(this._deleted)return new U(C());{const o=function(t,i,e,n,o,l){const s=A(t.urlParams),r=t.url+s,a=Object.assign({},t.headers);return function(t,i){i&&(t["X-Firebase-GMPID"]=i)}(a,i),function(t,i){null!==i&&i.length>0&&(t.Authorization="Firebase "+i)}(a,e),function(t,i){t["X-Firebase-Storage-Version"]="webjs/"+(null!=i?i:"AppManager")}(a,l),function(t,i){null!==i&&(t["X-Firebase-AppCheck"]=i)}(a,n),new _(r,t.method,a,t.body,t.successCodes,t.additionalRetryCodes,t.handler,t.errorHandler,t.timeout,t.progressCallback,o)}(t,this._appId,e,n,i,this._firebaseVersion);return this._requests.add(o),o.getPromise().then((()=>this._requests.delete(o)),(()=>this._requests.delete(o))),o}}async makeRequestWithTokens(t,i){const[e,n]=await Promise.all([this._getAuthToken(),this._getAppCheckToken()]);return this._makeRequest(t,i,e,n).getPromise()}}const ct="@firebase/storage";function vt(t,i,e){return function(t,i,e){t._throwIfRoot("uploadBytes");const n=function(t,i,e,n,o){const l=i.bucketOnlyServerUrl(),s={"X-Goog-Upload-Protocol":"multipart"},r=function(){let t="";for(let i=0;i<2;i++)t+=Math.random().toString().slice(2);return t}();s["Content-Type"]="multipart/related; boundary="+r;const a=function(t,i,e){const n=Object.assign({},e);return n.fullPath=t.path,n.size=i.size(),n.contentType||(n.contentType=function(t,i){return i&&i.type()||"application/octet-stream"}(0,i)),n}(i,n,o),u=function(t,i){const e={},n=i.length;for(let o=0;o<n;o++){const n=i[o];n.writable&&(e[n.server]=t[n.local])}return JSON.stringify(e)}(a,e),d=W.getBlob("--"+r+"\r\nContent-Type: application/json; charset=utf-8\r\n\r\n"+u+"\r\n--"+r+"\r\nContent-Type: "+a.contentType+"\r\n\r\n",n,"\r\n--"+r+"--");if(null===d)throw new $("cannot-slice-blob","Cannot slice blob for upload. Please retry the upload.");const h={name:a.fullPath},c=F(l,t.host,t._protocol),v=t.maxUploadRetryTime,p=new it(c,"POST",function(t,i){return function(e,n){const o=tt(t,n,i);return et(null!==o),o}}(t,e),v);return p.urlParams=h,p.headers=s,p.body=d.uploadData(),p.errorHandler=nt(i),p}(t.storage,t._location,Y(),new W(i,!0),e);return t.storage.makeRequestWithTokens(n,lt).then((i=>({metadata:i,ref:t})))}(t=u(t),i,e)}async function pt(t,i=!1){var e,n,o,l,s;const r=t;for(const a of Object.keys(t)){const u=t[a];if(u)try{if("Object"===(null===(e=null==u?void 0:u.constructor)||void 0===e?void 0:e.name))r[a]=await pt(u);else if("DocumentReference"===(null===(n=null==u?void 0:u.constructor)||void 0===n?void 0:n.name))i?r[a]={id:u.id}:delete r[a];else if("Timestamp"===(null===(o=null==u?void 0:u.constructor)||void 0===o?void 0:o.name))r[a]=u.toDate();else if("Array"===(null===(l=null==u?void 0:u.constructor)||void 0===l?void 0:l.name)){const t=[];for(const i of r[a])t.push(await pt(i));r[a]=t}else"object"==typeof u&&"Date"!==(null===(s=null==u?void 0:u.constructor)||void 0===s?void 0:s.name)&&(r[a]=await pt(JSON.parse(JSON.stringify(u))))}catch(t){delete r[a]}}return JSON.parse(JSON.stringify(r))}h(new c("storage",(function(t,{instanceIdentifier:i}){const e=t.getProvider("app").getImmediate(),n=t.getProvider("auth-internal"),o=t.getProvider("app-check-internal");return new ht(e,n,o,i,p)}),"PUBLIC").setMultipleInstances(!0)),v(ct,"0.9.5",""),v(ct,"0.9.5","esm2017");const ft=async t=>{var i;let e=t;try{if("function"==typeof(null==t?void 0:t.get)){const n=await t.get();e={id:null==n?void 0:n.id,...(null===(i=null==n?void 0:n.data)||void 0===i?void 0:i.call(n))||{}}}}catch(t){console.log("Error getting doc")}return e};class mt{constructor({api:t,readOnly:i,block:e}){this.settings=[],this.api=t,this.readOnly=i,this.block=e,this.data={},this.codeEditorEl=null}setCaretAtEnd(t){const i=document.getSelection();t=t.firstChild,i.rangeCount&&["Start","End"].forEach((e=>i.getRangeAt(0)["set"+e](t,t.length)))}renderSettings(){this.settingsEl=document.createElement("div");for(const t of this.settings){let i=document.createElement("div");i.classList.add("cdx-settings-button",`cdx-settings-button-${t.name}`),i.innerHTML="function"==typeof(null==t?void 0:t.innerHTML)?t.innerHTML():t.innerHTML,"function"==typeof(null==t?void 0:t.onClick)&&i.addEventListener("click",t.onClick),this.settingsEl.appendChild(i)}return this.settingsEl}static get isReadOnlySupported(){return!0}static get displayInToolbox(){return!0}static get enableLineBreaks(){return!0}static get toolbox(){return{icon:'<svg xmlns="http://www.w3.org/2000/svg" class="ionicon" viewBox="0 0 512 512"><title>Scan</title><path d="M342 444h46a56 56 0 0056-56v-46M444 170v-46a56 56 0 00-56-56h-46M170 444h-46a56 56 0 01-56-56v-46M68 170v-46a56 56 0 0156-56h46" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="44"/></svg>',title:"Frame Holder"}}render(){const t=document.createElement("div");return t.style.padding="15px",t.style.borderRadius="10px",t.style.border="2px dashed var(--ion-color-medium, #cccccc)",t.style.color="var(--ion-color-medium, #cccccc)",t.style.fontStyle="italic",t.textContent="Frame Holder",t}save(t){return{}}static get DEFAULT_PLACEHOLDER(){return"Frame Holder"}static get sanitize(){return{}}}const gt=class{constructor(e){t(this,e),this.fireenjinTrigger=i(this,"fireenjinTrigger",7),this.fireenjinFetch=i(this,"fireenjinFetch",7),this.fireenjinSubmit=i(this,"fireenjinSubmit",7),this.templateChange=i(this,"templateChange",7),this.enableClicks=!1,this.name="editor",this.zoom=1,this.resize=!1,this.allowFullscreen=!1,this.disableFrame=!1,this.toastPosition="top",this.isPreviewing=!1,this.sizes=[50,50],this.fetch=!1,this.controls=[],this.tools={},this.tags=[],this.helpers={formatUSD:t=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2}).format(t||0)},this.hooks={},this.currentPartials=[],this.currentHelpers=[]}onKeydown(t){let i=String.fromCharCode(t.which).toLowerCase();(t.ctrlKey||t.metaKey)&&"s"===i&&this.save()}async onCodeChange(t){var i,e,n,o,l,s,r,a,u,d;"head"===(null===(i=null==t?void 0:t.target)||void 0===i?void 0:i.name)?this.template.head=(null===(e=null==t?void 0:t.target)||void 0===e?void 0:e.value)||"":"sampleData"===(null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.name)?this.template.sampleData="string"==typeof(null===(o=null==t?void 0:t.target)||void 0===o?void 0:o.value)&&JSON.stringify(null===(l=null==t?void 0:t.target)||void 0===l?void 0:l.value)||(null===(s=null==t?void 0:t.target)||void 0===s?void 0:s.value)||{}:"routes"===(null===(r=null==t?void 0:t.target)||void 0===r?void 0:r.name)&&(this.template.routes="string"==typeof(null===(a=null==t?void 0:t.target)||void 0===a?void 0:a.value)&&JSON.stringify(null===(u=null==t?void 0:t.target)||void 0===u?void 0:u.value)||(null===(d=null==t?void 0:t.target)||void 0===d?void 0:d.value)||{}),await this.generatePreview()}async onEditorChange(){const t={...this.template||{},editor:await this.editorJs.save()};this.template=t,await this.generatePreview(),this.templateChange.emit({template:t})}async onChange(t){var i,e,n,o,l,s,r,a;if("frameId"===(null===(i=null==t?void 0:t.target)||void 0===i?void 0:i.name))this.template={...this.template,frame:(this.partials||[]).find((i=>{var e;return(null==i?void 0:i.id)===(null===(e=null==t?void 0:t.target)||void 0===e?void 0:e.value)}))||null};else if("headerId"===(null===(e=null==t?void 0:t.target)||void 0===e?void 0:e.name))this.template={...this.template,header:(this.partials||[]).find((i=>{var e;return(null==i?void 0:i.id)===(null===(e=null==t?void 0:t.target)||void 0===e?void 0:e.value)}))};else if("footerId"===(null===(n=null==t?void 0:t.target)||void 0===n?void 0:n.name))this.template={...this.template,footer:(this.partials||[]).find((i=>{var e;return(null==i?void 0:i.id)===(null===(e=null==t?void 0:t.target)||void 0===e?void 0:e.value)}))};else if(["type","subject","tags","name","text","amp","description"].includes(null===(o=null==t?void 0:t.target)||void 0===o?void 0:o.name))this.template[null===(l=null==t?void 0:t.target)||void 0===l?void 0:l.name]=null===(s=null==t?void 0:t.target)||void 0===s?void 0:s.value;else{this.template={...this.template,[null===(r=null==t?void 0:t.target)||void 0===r?void 0:r.name]:null===(a=null==t?void 0:t.target)||void 0===a?void 0:a.value};const i=t.target.closest("ion-card ion-list");i&&this.setProgress(i)}this.templateChange.emit({template:this.template}),await this.generatePreview()}async onSuccess(t){var i,e,n,o,l,s,r,a,u,d,h,c,v,p,f,m;const g=this.endpoint||"addTemplate",w=this.endpoint||"editTemplate";if((null===(i=null==t?void 0:t.detail)||void 0===i?void 0:i.endpoint)===("string"==typeof this.fetch&&this.fetch||this.endpoint||"findTemplate")){const i=(null===(o=null===(n=null===(e=null==t?void 0:t.detail)||void 0===e?void 0:e.data)||void 0===n?void 0:n.template)||void 0===o?void 0:o.sampleData)||this.templateData||(null===(l=this.template)||void 0===l?void 0:l.sampleData)||{},a="string"==typeof i?JSON.parse(i):i,u={...(null===(r=null===(s=null==t?void 0:t.detail)||void 0===s?void 0:s.data)||void 0===r?void 0:r.template)||{},sampleData:a};this.template=u,this.templateChange.emit({template:u}),this.afterTemplateUpdate()}else[g,w].includes(null===(a=null==t?void 0:t.detail)||void 0===a?void 0:a.endpoint)?(await this.presentToast(),this.fetch&&this.fetchData(),(null===(u=this.modalEl)||void 0===u?void 0:u.dismiss)&&this.modalEl.dismiss()):"generatePdf"===(null===(d=null==t?void 0:t.detail)||void 0===d?void 0:d.endpoint)&&(null===window||void 0===window?void 0:window.open)&&(null===(v=null===(c=null===(h=t.detail)||void 0===h?void 0:h.data)||void 0===c?void 0:c.generatePdf)||void 0===v?void 0:v.url)&&window.open(null===(m=null===(f=null===(p=t.detail)||void 0===p?void 0:p.data)||void 0===f?void 0:f.generatePdf)||void 0===m?void 0:m.url,"_blank").focus()}async onTrigger(t){var i,e,n,o,l,s,r,a,u,d,h,c,v,p,f,m;"save"===(null===(i=null==t?void 0:t.detail)||void 0===i?void 0:i.name)?this.save():"export"===(null===(e=null==t?void 0:t.detail)||void 0===e?void 0:e.name)?(await this.exportHTML(),await this.generatePdf()):"send"===(null===(n=null==t?void 0:t.detail)||void 0===n?void 0:n.name)?this.openSendEmailModal(null===(o=null==t?void 0:t.detail)||void 0===o?void 0:o.payload):"preview"===(null===(l=null==t?void 0:t.detail)||void 0===l?void 0:l.name)?this.togglePreview(!!this.isPreviewing):"more"===(null===(s=null==t?void 0:t.detail)||void 0===s?void 0:s.name)?this.openTemplateInfoModal():"closeModal"===(null===(r=null==t?void 0:t.detail)||void 0===r?void 0:r.name)&&(null===(a=this.modalEl)||void 0===a?void 0:a.dismiss)?null===(h=null===(u=null===document||void 0===document?void 0:document.querySelectorAll)||void 0===u?void 0:(d=u.call(document,"ion-modal")).forEach)||void 0===h||h.call(d,(t=>{var i;return null===(i=null==t?void 0:t.dismiss)||void 0===i?void 0:i.call(t)})):"sampleData"===(null===(c=null==t?void 0:t.detail)||void 0===c?void 0:c.name)?this.openSampleDataModal():"code"===(null===(v=null==t?void 0:t.detail)||void 0===v?void 0:v.name)?this.openCodeModal():"layout"===(null===(p=null==t?void 0:t.detail)||void 0===p?void 0:p.name)?this.openLayoutModal():"routes"===(null===(f=null==t?void 0:t.detail)||void 0===f?void 0:f.name)?this.openRoutesModal():"head"===(null===(m=null==t?void 0:t.detail)||void 0===m?void 0:m.name)&&this.openHeadModal()}async togglePreview(t){this.generatePreview(),this.isPreviewing=null!=t?t:!this.isPreviewing}async save(t){var i,e,n,o,l,s,r,a,u,d,h,c,v,p,f,m,g,w,y,b,x,j,$,T,k;const R="string"==typeof this.endpoint&&this.endpoint||"addTemplate",C="string"==typeof this.endpoint&&this.endpoint||"editTemplate",E=(null==t?void 0:t.sampleData)||(null===(i=this.template)||void 0===i?void 0:i.sampleData)||null,S="string"==typeof E?JSON.parse(E):E,P=await pt({editor:await(null===(n=null===(e=this.editorJs)||void 0===e?void 0:e.save)||void 0===n?void 0:n.call(e))||{time:(new Date).getTime(),blocks:[],version:"2.8.1"},amp:(null==t?void 0:t.amp)||(null===(o=this.template)||void 0===o?void 0:o.amp)||null,attachments:(null==t?void 0:t.attachments)||(null===(l=this.template)||void 0===l?void 0:l.attachments)||[],description:(null==t?void 0:t.description)||(null===(s=this.template)||void 0===s?void 0:s.description)||null,footerId:(null==t?void 0:t.footerId)||(null===(a=null===(r=this.template)||void 0===r?void 0:r.footer)||void 0===a?void 0:a.id)||null,headerId:(null==t?void 0:t.headerId)||(null===(d=null===(u=this.template)||void 0===u?void 0:u.header)||void 0===d?void 0:d.id)||null,head:(null==t?void 0:t.head)||(null===(h=this.template)||void 0===h?void 0:h.head)||null,frameId:(null==t?void 0:t.frameId)||(null===(v=null===(c=this.template)||void 0===c?void 0:c.frame)||void 0===v?void 0:v.id)||null,name:(null==t?void 0:t.name)||(null===(p=this.template)||void 0===p?void 0:p.name)||null,routes:(null==t?void 0:t.routes)||(null===(f=this.template)||void 0===f?void 0:f.routes)||null,sampleData:S,subject:(null==t?void 0:t.subject)||(null===(m=this.template)||void 0===m?void 0:m.subject)||null,tags:(null==t?void 0:t.tags)||(null===(g=this.template)||void 0===g?void 0:g.tags)||[],text:(null==t?void 0:t.text)||(null===(w=this.template)||void 0===w?void 0:w.text)||null,type:(null==t?void 0:t.type)||(null===(y=this.template)||void 0===y?void 0:y.type)||null});return(null===(b=this.template)||void 0===b?void 0:b.partial)&&(P.partial=null!==($=null!==(x=null==t?void 0:t.partial)&&void 0!==x?x:null===(j=this.template)||void 0===j?void 0:j.partial)&&void 0!==$?$:"on"===(null===(T=this.template)||void 0===T?void 0:T.partial)),this.fireenjinSubmit.emit(this.templateId?{endpoint:C,name:this.name,id:this.templateId||(null===(k=this.template)||void 0===k?void 0:k.id),data:P}:{endpoint:R,name:this.name,params:{data:P}}),P}async openTemplateInfoModal(){var t;return this.modalEl=await f.create({component:"fireenjin-mx-modal-template-settings",cssClass:"fireenjin-mx-modal-template-settings-wrapper",componentProps:{tags:this.tags||[],types:this.types,template:this.template,templateId:this.templateId||(null===(t=this.template)||void 0===t?void 0:t.id),helpers:this.helpers||null,partials:this.partials||null,frames:this.frames||null}}),await this.modalEl.present(),this.modalEl}async openSendEmailModal(t){var i,e,n;return this.modalEl=await f.create({component:"fireenjin-mx-modal-send-email",cssClass:"fireenjin-mx-modal-send-email-wrapper",componentProps:{to:(null==t?void 0:t.to)||[],text:null==t?void 0:t.text,html:(null==t?void 0:t.html)||await this.exportHTML(),templateId:(null==t?void 0:t.templateId)||this.templateId||(null===(i=this.template)||void 0===i?void 0:i.id),template:(null==t?void 0:t.template)||this.template,hideTemplateSelect:null===(e=null==t?void 0:t.hideTemplateSelect)||void 0===e||e,subject:(null==t?void 0:t.subject)||(null===(n=this.template)||void 0===n?void 0:n.subject)||null,from:(null==t?void 0:t.from)||this.mailFrom||null,replyTo:(null==t?void 0:t.replyTo)||this.mailReplyTo||null,helpers:this.helpers||null,partials:this.partials||null,frames:this.frames||null,templates:(null==t?void 0:t.templates)||this.templates||null}}),await this.modalEl.present(),this.modalEl}async openRoutesModal(){var t;const i="string"==typeof this.endpoint&&this.endpoint||"addTemplate",e="string"==typeof this.endpoint&&this.endpoint||"editTemplate";return this.modalEl=await f.create({component:"fireenjin-mx-modal-code-editor",cssClass:"fireenjin-mx-modal-code-editor-wrapper",componentProps:{pageTitle:"Routes",name:"routes",language:"json",value:JSON.stringify((null===(t=this.template)||void 0===t?void 0:t.routes)||{}),endpoint:this.templateId?e:i,documentId:this.templateId}}),await this.modalEl.present(),this.modalEl}async openLayoutModal(){var t;const i={tags:this.tags||[],types:this.types,template:this.template,templates:this.templates||null,templateId:this.templateId||(null===(t=this.template)||void 0===t?void 0:t.id),helpers:this.helpers||null,partials:this.partials||null,frames:this.frames||null};return this.modalEl=await f.create({component:"fireenjin-mx-modal-layout",cssClass:"fireenjin-mx-modal-layout-wrapper",componentProps:i}),await this.modalEl.present(),this.modalEl}async openCodeModal(){return this.modalEl=await f.create({component:"fireenjin-mx-modal-code-editor",cssClass:"fireenjin-mx-modal-code-editor-wrapper",componentProps:{name:"code",pageTitle:"Code",language:"html",value:await this.exportHTML()}}),await this.modalEl.present(),this.modalEl}async openHeadModal(){var t;const i="string"==typeof this.endpoint&&this.endpoint||"addTemplate",e="string"==typeof this.endpoint&&this.endpoint||"editTemplate";return this.modalEl=await f.create({component:"fireenjin-mx-modal-code-editor",cssClass:"fireenjin-mx-modal-code-editor-wrapper",componentProps:{pageTitle:"Edit Head",name:"head",language:"html",value:(null===(t=this.template)||void 0===t?void 0:t.head)||"",endpoint:this.templateId?e:i,documentId:this.templateId}}),await this.modalEl.present(),this.modalEl}async openSampleDataModal(){var t;const i="string"==typeof this.endpoint&&this.endpoint||"addTemplate",e="string"==typeof this.endpoint&&this.endpoint||"editTemplate",n=this.templateData||(null===(t=this.template)||void 0===t?void 0:t.sampleData)||{};return this.modalEl=await f.create({component:"fireenjin-mx-modal-code-editor",cssClass:"fireenjin-mx-modal-code-editor-wrapper",componentProps:{name:"sampleData",language:"json",value:"string"==typeof n?n:JSON.stringify(n,null,4),endpoint:this.templateId?e:i,documentId:this.templateId}}),await this.modalEl.present(),this.modalEl}async generatePdf(){var t;this.fireenjinSubmit.emit({endpoint:"generatePdf",params:{data:{templateId:this.templateId,payload:this.templateData||(null===(t=this.template)||void 0===t?void 0:t.sampleData)||{}}}})}async openControls(){return this.actionEl=await m.create({header:this.controlsHeader,buttons:[{text:"Toggle Preview",icon:this.isPreviewing?"eye-off":"eye",handler:()=>{this.fireenjinTrigger.emit({name:"preview",payload:{isPreviewing:!this.isPreviewing}})}},{text:"Save",icon:"save",handler:()=>{this.fireenjinTrigger.emit({name:"save"})}},{text:"Edit Info",icon:"create",handler:()=>{this.fireenjinTrigger.emit({name:"more"})}},{text:"Edit Layout",icon:"layers",handler:()=>{this.fireenjinTrigger.emit({name:"layout"})}},{text:"Edit Sample Data",icon:"document-text",handler:()=>{this.fireenjinTrigger.emit({name:"sampleData"})}},{text:"Edit Head",icon:"search-circle",handler:()=>{this.fireenjinTrigger.emit({name:"editHead"})}},{text:"Edit Routes",icon:"globe",handler:()=>{this.fireenjinTrigger.emit({name:"routes"})}},{text:"View Code",icon:"code-slash",handler:()=>{this.fireenjinTrigger.emit({name:"code"})}},{text:"Send as Email",icon:"mail",handler:()=>{this.fireenjinTrigger.emit({name:"send"})}},{text:"Export",icon:"exit",handler:()=>{this.fireenjinTrigger.emit({name:"export"})}},...this.controls]}),await this.actionEl.present(),this.actionEl}async fetchData(t){const i=(null==t?void 0:t.templateId)||this.templateId;i&&this.fireenjinFetch.emit({endpoint:"string"==typeof this.fetch&&this.fetch||"string"==typeof this.endpoint&&this.endpoint||"findTemplate",name:this.name,params:{id:i}})}async unsetPartials(){for(const t of this.currentPartials)w.unregisterPartial(t);this.currentPartials=[],this.partials=[]}async setTemplates(t){var i,e;if(this.templates=t||this.templates||null,null===(i=this.templates)||void 0===i?void 0:i.length)try{this.partials=this.templates.filter((t=>(null==t?void 0:t.partial)||["frame","component"].includes(null==t?void 0:t.type))),(null===(e=this.partials)||void 0===e?void 0:e.length)&&this.setPartials(),this.frames=this.templates.filter((t=>"frame"===(null==t?void 0:t.type)))}catch(t){console.log("Error setting templates.")}}async setPartials(t){try{w.registerPartial(null,"")}catch(t){}try{(null==t?void 0:t.length)&&this.partials!==t&&(this.partials=t);for(const t of this.partials)try{this.currentPartials.includes(null==t?void 0:t.id)&&w.unregisterPartial(null==t?void 0:t.id),w.registerPartial(null==t?void 0:t.id,(null==t?void 0:t.html)||""),this.currentPartials.includes(null==t?void 0:t.id)||(this.currentPartials=[...this.currentPartials,null==t?void 0:t.id])}catch(i){console.log(`Error setting partial ${null==t?void 0:t.id}.`)}}catch(t){console.log("Error setting partials.")}}async setHelpers(t){try{(null==t?void 0:t.length)&&this.helpers!==t&&(this.helpers=t);for(const[t,i]of Object.entries(this.helpers))try{this.currentHelpers.includes(t)&&w.unregisterHelper(t),w.registerHelper(t,i),this.currentHelpers.includes(t)||(this.currentHelpers=[...this.currentHelpers,t])}catch(i){console.log(`Error setting helper ${t}.`)}}catch(t){console.log("Error setting helpers.")}}sanitizeHtml(t){let i=t;return i=i.replace(/&/g,"&amp;"),i=i.replace(/</g,"&lt;"),i=i.replace(/>/g,"&gt;"),i}async getIfDoc(t){var i;let e=t;try{if(null==t?void 0:t.get){const n=await t.get();e={id:null==n?void 0:n.id,...(null===(i=null==n?void 0:n.data)||void 0===i?void 0:i.call(n))||{}}}}catch(t){console.log("Error getting doc")}return e}async exportHTML({data:t,excludeFrame:i,mjml:e,disableRender:n,disableHandlebarsCompile:o,excludeFooter:l,excludeHeader:s,url:r}={}){var a,u,d,h,c,v,p,f,m;let g="";try{i?g=await this.editorEl.exportHTML():(this.template.editor=await this.editorEl.exportJSON(),g=await async function(t){var i,e,n;const o=null==t?void 0:t.template,l=await ft((null==t?void 0:t.frame)||(null==o?void 0:o.frame)),s=(null===(i=null==t?void 0:t.hydrate)||void 0===i?void 0:i.head)||(null==l?void 0:l.head)||(null==o?void 0:o.head)||"",r=await ft((null==l?void 0:l.header)||(null==o?void 0:o.header)||""),a=await ft((null==l?void 0:l.footer)||(null==o?void 0:o.footer)||""),u=await async function(t,{parserConfig:i,customParsers:e,embedMarkup:n}={}){return new x(i||null,e||{button:t=>`<ion-button shape="${t.shape?t.shape:"square"}" color="${t.color?t.color:"primary"}" class="${"center"===t.align?"enjin-align-center":"right"===t.align?"enjin-align-right":"enjin-align-left"}" href="${t.href?t.href:"#"}">${t.text}</ion-button>`,component:t=>`<div class="editor-component">{{> ${t.templateId}}}</div>`,tasklist:t=>{const i=(null==t?void 0:t.color)?t.color:"success",e=(null==t?void 0:t.progress)?t.progress:0,n=["<ion-list>"];for(const e of(null==t?void 0:t.items)?t.items:[])n.push(`<ion-item><ion-checkbox slot="start" color="${i}" ${e.checked?'checked="true"':""}></ion-checkbox><ion-label>${e.text}</ion-label></ion-item>`);return n.push(`<ion-progress-bar color="${i}" value="${e}"></ion-progress-bar>`,"</ion-list>"),n.join("")},code:t=>t.html,FrameHolder:()=>"{{#if @partial-block}} {{> @partial-block }} {{/if}}"},n||null).parse(t)}(null==o?void 0:o.editor,{parserConfig:null==t?void 0:t.parserConfig,customParsers:null==t?void 0:t.customParsers,embedMarkup:null==t?void 0:t.embedMarkup});let d=[!(null==t?void 0:t.excludeHeader)&&(null==r?void 0:r.html)||"",(null==l?void 0:l.id)?`{{#> ${null==l?void 0:l.id} }}${u}{{/${null==l?void 0:l.id}}}`:u,!(null==t?void 0:t.excludeFooter)&&(null==a?void 0:a.html)||""].join("");try{(null===(e=null==t?void 0:t.handlebars)||void 0===e?void 0:e.compile)&&(d=t.handlebars.compile(d)((null==t?void 0:t.data)||(null==o?void 0:o.sampleData)||{}))}catch(t){console.log("Error rendering handlebars: ",t)}try{(null==t?void 0:t.mjml)&&(d=null===(n=b(d,"object"==typeof(null==t?void 0:t.mjml)&&t.mjml||{}))||void 0===n?void 0:n.html)}catch(t){console.log("Error rendering MJML",t)}try{(null==t?void 0:t.disableRender)||(d=await async function(t,i={}){if(!t)throw Error("HTML is required");const e=await y.renderToString(t,i.hydrateOptions?i.hydrateOptions:{prettyHtml:!0,removeScripts:!0});let n=(null==i?void 0:i.head)&&(null==e?void 0:e.html)?e.html.replace('<meta charset="utf-8">',`<meta charset="utf-8">\n    ${(null==i?void 0:i.head)||""}\n    `):(null==e?void 0:e.html)||"";if(i.replace)for(const t of Object.keys(i.replace))n=n.replace(new RegExp(t,"g"),i.replace[t]);return n=n.replace(new RegExp("{{&gt;","g"),"{{>").replace(new RegExp("{{#&gt;","g"),"{{#>"),i.partial&&n.includes("</body>")?/<body[^>]*>((.|[\n\r])*)<\/body>/im.exec(n)[1]:n}(d,{...(null==t?void 0:t.hydrate)||{},head:s}))}catch(t){console.log("Error rendering components",t)}return d}({mjml:e||"email"===(null===(a=this.template)||void 0===a?void 0:a.type)&&{fonts:this.fonts},excludeFooter:null!=l?l:(null===(u=this.template)||void 0===u?void 0:u.partial)||"component"===(null===(d=this.template)||void 0===d?void 0:d.type),excludeHeader:null!=s?s:(null===(h=this.template)||void 0===h?void 0:h.partial)||"component"===(null===(c=this.template)||void 0===c?void 0:c.type),data:t||this.templateData||(null===(v=this.template)||void 0===v?void 0:v.sampleData),handlebars:!(null!=o?o:(null===(p=this.template)||void 0===p?void 0:p.partial)||["component","frame"].includes(null===(f=this.template)||void 0===f?void 0:f.type))&&(null==w?void 0:w.compile)&&w,parserConfig:this.parserConfig,customParsers:this.customParsers||"email"===(null===(m=this.template)||void 0===m?void 0:m.type)&&{header:t=>`<mj-text><h${t.level}>${t.text}</h${t.level}></mj-text>`,list:t=>{const i="ordered"===t.style?"ol":"ul";return`<mj-text><${i}>${t.items.reduce(((t,i)=>t+`<li>${i}</li>`),"")}</${i}></mj-text>`},raw:t=>`<mj-raw>${t.html}</mj-raw>`,quote:t=>`<mj-text align="${(null==t?void 0:t.alignment)||"left"}"><blockquote style="text-align: ${(null==t?void 0:t.alignment)||"left"}"><p>${t.text}</p><cite>${t.caption}</cite></blockquote></mj-text>`,image:(t,i)=>{var e;const n=`${t.stretched?"img-fullwidth":""} ${t.withBorder?"img-border":""} ${t.withBackground?"img-bg":""}`,o=i.image.imgClass||"";let l;return l=t.url?t.url:"absolute"===i.image.path?t.file.url:i.image.path.replace(/<(.+)>/,((i,e)=>t.file[e])),(null==t?void 0:t.stretched)&&"figure"===i.image.use?`<mj-hero mode="fluid-height"  padding="100px 0px" background-url="${l}"><mj-text padding="20px" color="${(null===(e=null==i?void 0:i.img)||void 0===e?void 0:e.figColor)||"#ffffff"}" font-family="Helvetica" align="center" font-size="45px" line-height="45px" font-weight="900" css-class="${i.image.figCapClass||""}">${(null==t?void 0:t.caption)||""}</mj-text></mj-hero>`:`<mj-image css-class="${n} ${o}" src="${l}" alt="${(null==t?void 0:t.caption)||""}" fluid-on-mobile="${(null==t?void 0:t.stretched)?"true":"false"}" />`},paragraph:t=>{var i;return`<mj-text color="${(null==t?void 0:t.color)&&(null===(i=this.colors)||void 0===i?void 0:i[null==t?void 0:t.color])||"#000000"}" align="${(null==t?void 0:t.alignment)||"left"}">${(null==t?void 0:t.text)||""}</mj-text>`},table:t=>`<mj-table>${t.content.map((t=>`<tr>${t.reduce(((t,i)=>t+`<td>${i}</td>`),"")}</tr>`)).join("")}</mj-table>`,button:t=>{var i,e;const n=null===(i=this.colors)||void 0===i?void 0:i[null==t?void 0:t.color],o=null===(e=this.colors)||void 0===e?void 0:e["solid"===(null==t?void 0:t.fill)?`${null==t?void 0:t.color}-contrast`:t.color];return`<mj-button ${(null==t?void 0:t.expand)?'width="100%"':""} align="${(null==t?void 0:t.align)||"left"}" background-color="${"solid"===(null==t?void 0:t.fill)&&(null==t?void 0:t.color)&&n||"transparent"}" ${(null==t?void 0:t.color)&&o&&`color="${o}"`||""} href="${(null==t?void 0:t.href)||"#"}" ${"round"===(null==t?void 0:t.shape)?'border-radius="64px"':""} ${"outline"===t.fill?`border="2px solid ${n}"`:""}>${(null==t?void 0:t.text)||""}</mj-button>`},component:t=>`<mj-text><div class="editor-component">{{> ${t.templateId}}}</div></mj-text>`,code:t=>null==t?void 0:t.html,...this.customEmailParsers||{}},template:this.template,disableRender:null==n||n,url:r||this.url}))}catch(t){console.log("Error exoprting HTML",t)}return g}async generatePreview({templateData:t,mjml:i,disableRender:e,excludeFrame:n,excludeHeader:o,excludeFooter:l,disableHandlebarsCompile:s}={}){var r;if(!(null===(r=this.editorEl)||void 0===r?void 0:r.exportHTML))return;t&&(this.templateData=t);const a=await this.exportHTML({excludeFrame:n,mjml:i,disableRender:e,excludeFooter:l,excludeHeader:o,disableHandlebarsCompile:s});return this.template.html=a,this.previewTemplate={html:a,id:"preview"},a}setProgress(t){var i;let e=0;const n=Array.from(t.querySelectorAll("ion-item")),o=t.querySelector("ion-progress-bar");for(const t of n)e+=(null===(i=null==t?void 0:t.querySelector("ion-checkbox"))||void 0===i?void 0:i.checked)?1:0;const l=e/n.length,s=isFinite(l)&&l>0?l:0;o.value=s}async presentToast(){(await g.create({message:"The template has been saved successfully!",duration:2e3,position:this.toastPosition||"top"})).present()}getExtension(t){var i=t.split(/[\\/]/).pop(),e=i.lastIndexOf(".");return""===i||e<1?"":i.slice(e+1)}async afterTemplateUpdate(){var t,i,e,n;if("function"==typeof(null===(t=this.hooks)||void 0===t?void 0:t.afterTemplateUpdate))return this.hooks.afterTemplateUpdate(this.template);if(this.templateId=(null===(i=this.template)||void 0===i?void 0:i.id)||this.templateId,null===(e=this.template)||void 0===e?void 0:e.editor)try{this.editorJs.blocks.render((null===(n=this.template)||void 0===n?void 0:n.editor)||{}),this.generatePreview()}catch(t){setTimeout((async()=>{var t;this.editorJs.blocks.render((null===(t=this.template)||void 0===t?void 0:t.editor)||{}),this.generatePreview()}),1e3)}}async onPhotoUpload(t){var i,e;const n=(o=this.storage,l=`${(new Date).toISOString()}.${this.getExtension(null===(i=null==t?void 0:t.file)||void 0===i?void 0:i.name)}`,ut(o=u(o),l));var o,l;const s=await vt(n,t.file),r=await(a=s.ref,rt(a=u(a)));var a;return"function"==typeof(null===(e=this.hooks)||void 0===e?void 0:e.onPhotoUpload)&&this.hooks.onPhotoUpload(r,this.template),{success:!0,file:{url:r}}}async componentDidLoad(){var t,i,n,o,l;(null==e?void 0:e.isBrowser)&&(this.storage=function(t=a(),i){return t=u(t),d(t,"storage").getImmediate({identifier:i})}(this.app),this.fetch&&this.fetchData(),(null===(t=this.templates)||void 0===t?void 0:t.length)?this.setTemplates():(this.helpers&&(null===(i=Object.keys(this.helpers))||void 0===i?void 0:i.length)&&this.setHelpers(),(null===(n=this.partials)||void 0===n?void 0:n.length)&&this.setPartials()),(null===(o=this.editorEl)||void 0===o?void 0:o.getInstance)?this.editorJs=await this.editorEl.getInstance():setTimeout((async()=>{this.editorJs=await this.editorEl.getInstance()}),2e3),(null===(l=this.template)||void 0===l?void 0:l.id)&&this.afterTemplateUpdate())}render(){var t,i,l;"function"==typeof(null===(t=this.hooks)||void 0===t?void 0:t.onRender)&&this.hooks.onRender(this.template);const s=this.partials||(null===(l=null===(i=this.templates)||void 0===i?void 0:i.filter)||void 0===l?void 0:l.call(i,(t=>null==t?void 0:t.partial)))||[];return n(o,{class:{"is-previewing":!!this.isPreviewing}},(null==e?void 0:e.isBrowser)&&n("fireenjin-editor",{partials:s,ref:t=>this.editorEl=t,uploadCallback:t=>this.onPhotoUpload(t),tools:{FrameHolder:mt,...this.tools||{}}}),n("fireenjin-render-template",{ref:t=>this.previewEl=t,id:"preview",name:this.name,enableClicks:this.enableClicks,disableFrame:this.disableFrame,allowFullscreen:this.allowFullscreen,resize:this.resize,zoom:this.zoom,partials:s,template:this.previewTemplate}))}get appTemplateEl(){return l(this)}static get watchers(){return{templates:["setTemplates"],partials:["setPartials"],helpers:["setHelpers"]}}};s([j.debounce(1e3)],gt.prototype,"generatePreview",null),gt.style="fireenjin-mx-editor,fireenjin-mx-editor fireenjin-editor{display:block;opacity:1;transition:all ease 0.4s;position:relative;width:100%;height:100%}fireenjin-mx-editor.is-previewing fireenjin-editor{opacity:0;pointer-events:none}fireenjin-mx-editor #preview{transition:all ease 0.4;opacity:0;position:absolute !important;top:0;left:0;right:0;display:block;width:100%;height:100%;pointer-events:none;border:1px solid #CCCCCC}fireenjin-mx-editor.is-previewing #preview{opacity:1;pointer-events:all}";export{gt as fireenjin_mx_editor}