(()=>{"use strict";var e={97735:(e,t,n)=>{var r=n(18674),a=n(3531),o=n(30827),i=n(20593),s=n(16820);let f=null;async function p(e){return globalThis.crypto&&globalThis.crypto.subtle&&"function"==typeof globalThis.crypto.subtle.digest?new Uint8Array(await globalThis.crypto.subtle.digest("SHA-256",e)):(0,o.b)(e)}async function l({docBuffer:e,storageDocId:t,rootDocBuffer:n}){let o;if(c(n))return console.warn("[worker]: Empty root doc buffer"),{};let i=(0,a.U5)(await p(n));f&&f.hash===i?o=f.doc:(o=new s.Doc,(0,s.applyUpdate)(o,n),f={doc:o,hash:i});let l=null;for(let[e,n]of o.getMap("spaces"))if(n instanceof s.Doc&&t===n.guid){l=e;break}if(null===l)return{};let u=new s.Doc;c(e)||(0,s.applyUpdate)(u,e);let g=null;if(o.getMap("meta").get("pages")?.forEach(e=>{e.get("id")===l&&(g=!e.get("trash"))}),!g)return{deletedDoc:[l]};{let e=u.getMap("blocks");if(0===e.size)return{};let t="",n=[];for(let a of e.values()){let e=a.get("sys:flavour")?.toString(),o=a.get("sys:id")?.toString();if(e&&o){if("affine:page"===e&&(t=a.get("prop:title").toString(),n.push(r.y.from(`${l}:${o}`,{docId:l,flavour:e,blockId:o,content:t}))),"affine:paragraph"===e||"affine:list"===e||"affine:code"===e){let t=a.get("prop:text");if(!t)continue;let i=t.toDelta().map(e=>e.attributes&&e.attributes.reference&&e.attributes.reference.pageId?e.attributes.reference.pageId:null).filter(e=>!!e);n.push(r.y.from(`${l}:${o}`,{docId:l,flavour:e,blockId:o,content:t.toString(),ref:i}))}if("affine:embed-linked-doc"===e||"affine:embed-synced-doc"===e){let t=a.get("prop:pageId");"string"==typeof t&&n.push(r.y.from(`${l}:${o}`,{docId:l,flavour:e,blockId:o,ref:t}))}if("affine:attachment"===e||"affine:image"===e){let t=a.get("prop:sourceId");"string"==typeof t&&n.push(r.y.from(`${l}:${o}`,{docId:l,flavour:e,blockId:o,blob:[t]}))}if("affine:surface"===e){let t=[],i=a.get("prop:elements");if(!(i instanceof s.Map&&"$blocksuite:internal:native$"===i.get("type")))continue;let f=i.get("value");if(!(f instanceof s.Map))continue;for(let e of f.values()){if(!(e instanceof s.Map))continue;let n=e.get("text");n&&t.push(n.toString())}n.push(r.y.from(`${l}:${o}`,{docId:l,flavour:e,blockId:o,content:t}))}if("affine:database"===e){let t=[],i=a.get("prop:columns");if(!(i instanceof s.Array))continue;for(let e of i){if(!(e instanceof s.Map))continue;"string"==typeof e.get("name")&&t.push(e.get("name"));let n=e.get("data");if(!(n instanceof s.Map))continue;let r=n.get("options");if(r instanceof s.Array)for(let e of r){if(!(e instanceof s.Map))continue;let n=e.get("value");"string"==typeof n&&t.push(n)}}n.push(r.y.from(`${l}:${o}`,{docId:l,flavour:e,blockId:o,content:t}))}}}return{addedDoc:[{id:l,doc:r.y.from(l,{title:t}),blocks:n}]}}}function c(e){return 0===e.byteLength||2===e.byteLength&&0===e[0]&&0===e[1]}globalThis.onmessage=async e=>{let t=e.data;if("init"===t.type){postMessage({type:"init",msgId:t.msgId});return}if("run"===t.type){let{input:e}=t;try{let n;n="rootDoc"===e.type?function({allIndexedDocs:e,rootDocBuffer:t}){let n=new s.Doc;(0,s.applyUpdate)(n,t);let r=n.getMap("meta").get("pages");if(!r)return{};let a=[];for(let e of r){let t=e.get("id");"string"==typeof t&&(e.get("trash")||a.push(t))}let o=(0,i.A)(e,a);return{reindexDoc:[...(0,i.A)(a,e),...o].map(e=>({docId:e,storageDocId:n.getMap("spaces").get(e)?.guid??e}))}}(e):await l(e),postMessage({type:"done",msgId:t.msgId,output:n})}catch(e){postMessage({type:"failed",msgId:t.msgId,error:e instanceof Error?e.message:e+""})}}}}},t={};function n(r){var a=t[r];if(void 0!==a)return a.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.m=e,n.x=()=>{var e=n.O(void 0,[4922,861,9574,8674],()=>n(97735));return n.O(e)},(()=>{var e=[];n.O=(t,r,a,o)=>{if(r){o=o||0;for(var i=e.length;i>0&&e[i-1][2]>o;i--)e[i]=e[i-1];e[i]=[r,a,o];return}for(var s=1/0,i=0;i=o)&&Object.keys(n.O).every(e=>n.O[e](r[p]))?r.splice(p--,1):(f=!1,o{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.f={},n.e=e=>Promise.all(Object.keys(n.f).reduce((t,r)=>(n.f[r](e,t),t),[])),n.u=e=>4922===e?"js/chunk.npm-async-lodash-es.27a23701.js":861===e?"js/chunk.npm-async-lib0.9b0cd4f1.js":9574===e?"js/chunk.npm-async-yjs.5ef92592.js":"js/"+e+".65285e27.js",n.miniCssF=e=>{},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.p="/",(()=>{var e={3941:1};n.f.i=(t,r)=>{e[t]||importScripts(n.p+n.u(t))};var t=globalThis.webpackChunk_affine_web=globalThis.webpackChunk_affine_web||[],r=t.push.bind(t);t.push=t=>{var[a,o,i]=t;for(var s in o)n.o(o,s)&&(n.m[s]=o[s]);for(i&&i(n);a.length;)e[a.pop()]=1;r(t)}})(),(()=>{var e=n.x;n.x=()=>Promise.all([4922,861,9574,8674].map(n.e,n)).then(e)})(),n.x()})(); //# sourceMappingURL=worker.9c2f0192.js.map