@texonom/nutils 1.4.7 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -1,2 +1,746 @@
1
- var ee=Object.defineProperty,te=Object.defineProperties;var oe=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var ne=Object.prototype.hasOwnProperty,ce=Object.prototype.propertyIsEnumerable;var V=(e,t,c)=>t in e?ee(e,t,{enumerable:!0,configurable:!0,writable:!0,value:c}):e[t]=c,y=(e,t)=>{for(var c in t||(t={}))ne.call(t,c)&&V(e,c,t[c]);if(N)for(var c of N(t))ce.call(t,c)&&V(e,c,t[c]);return e},M=(e,t)=>te(e,oe(t));var U=(e,t,c)=>new Promise((n,o)=>{var r=s=>{try{i(c.next(s))}catch(u){o(u)}},l=s=>{try{i(c.throw(s))}catch(u){o(u)}},i=s=>s.done?n(s.value):Promise.resolve(s.value).then(r,l);i((c=c.apply(e,t)).next())});var T=e=>{var t;return e?Array.isArray(e)?(t=e==null?void 0:e.reduce((c,n)=>c+(n[0]!=="\u204D"&&n[0]!=="\u2023"?n[0]:""),""))!=null?t:"":e:""};function S(e,t){var o,r,l,i,s,u,a;let c=e.collection_id||((r=(o=e.format)==null?void 0:o.collection_pointer)==null?void 0:r.id);if(c)return c;let n=(l=e==null?void 0:e.view_ids)==null?void 0:l[0];if(n){let f=(s=(i=t.collection_view)==null?void 0:i[n])==null?void 0:s.value;if(f)return(a=(u=f.format)==null?void 0:u.collection_pointer)==null?void 0:a.id}return null}function w(e,t){var c,n;if((c=e.properties)!=null&&c.title)return T(e.properties.title);if(e.type==="collection_view_page"||e.type==="collection_view"){let o=S(e,t);if(o){let r=(n=t.collection[o])==null?void 0:n.value;if(r)return T(r.name)}}return""}function j(e,t){var c,n,o;if((c=e.format)!=null&&c.page_icon)return(n=e.format)==null?void 0:n.page_icon;if(e.type==="collection_view_page"||e.type==="collection_view"){let r=S(e,t);if(r){let l=(o=t.collection[r])==null?void 0:o.value;if(l)return l.icon}}return null}function Be(e){var c;let t=(c=e.block[Object.keys(e.block)[0]])==null?void 0:c.value;return t?w(t,e):null}function Q(e,t,c){var n;try{if(!t.properties||!Object.keys(c.collection))return null;let o=(n=c.collection[t.parent_id])==null?void 0:n.value;if(o){let r=e.toLowerCase(),l=Object.keys(o.schema).find(u=>{var a,f;return((f=(a=o.schema[u])==null?void 0:a.name)==null?void 0:f.toLowerCase())===r});if(!l)return null;let{type:i}=o.schema[l],s=T(t.properties[l]);switch(i){case"created_time":return t.created_time;case"multi_select":return s.split(",");case"date":{let a=t.properties[l][0][1][0][1];if(a.type=="datetime")return new Date(`${a.start_date} ${a.start_time}`).getTime();if(a.type=="date")return new Date(a.start_date).getTime();if(a.type=="datetimerange"){let{start_date:f,start_time:g,end_date:B,end_time:h}=a,p=new Date(`${f} ${g}`).getTime(),k=new Date(`${B} ${h}`).getTime();return[p,k]}else{let f=new Date(a.start_date).getTime(),g=new Date(a.end_date).getTime();return[f,g]}}case"checkbox":return s=="Yes";case"last_edited_time":return t.last_edited_time;default:return s}}}catch(o){}return null}var re=e=>{if(e&&Array.isArray(e)){if(e[0]==="d")return e[1];for(let t of e){let c=re(t);if(c)return c}}return null};var H=(e,t,{inclusive:c=!1}={})=>{var o,r;let n=e;for(;n!=null;){if(c&&(n==null?void 0:n.type)==="page")return n;let l=n.parent_id,i=n.parent_table;if(!l)break;if(i==="collection")n=(o=t.collection[l])==null?void 0:o.value;else if(n=(r=t.block[l])==null?void 0:r.value,(n==null?void 0:n.type)==="page")return n}return null},Ce=(e,t,{inclusive:c=!1}={})=>{var o,r,l,i;let n=e;for(;n!=null;){if(c&&(n==null?void 0:n.type)==="page")return n;let s=n.parent_id,u=n.parent_table;if(!s)break;if(u==="collection")return(o=t.collection[s])==null?void 0:o.value;if(u==="space")return(l=(r=t.space)==null?void 0:r[s])==null?void 0:l.value;if(n=(i=t.block[s])==null?void 0:i.value,(n==null?void 0:n.type)==="page")return n}return null};var ie={header:0,sub_header:1,sub_sub_header:2},X=(e,t)=>{var o;let c=((o=e.content)!=null?o:[]).map(r=>{var i,s;let l=(i=t.block[r])==null?void 0:i.value;if(l){let{type:u}=l;if(u==="header"||u==="sub_header"||u==="sub_sub_header")return{id:r,type:u,text:T((s=l.properties)==null?void 0:s.title),indentLevel:ie[u]}}return null}).filter(Boolean),n=[{actual:-1,effective:-1}];for(let r of c){let{indentLevel:l}=r,i=l;do{let s=n[n.length-1],{actual:u,effective:a}=s;if(i>u)r.indentLevel=a+1,n.push({actual:i,effective:r.indentLevel});else if(i===u){r.indentLevel=a;break}else n.pop()}while(!0)}return c};var W=(e,t,c=!1)=>{let n=t||Object.keys(e.block)[0],o=new Set;function r(l){var g,B;if(o.has(l))return;o.add(l);let i=(g=e.block[l])==null?void 0:g.value;if(!i)return;let{content:s,type:u,properties:a,format:f}=i;if(a)for(let h of Object.keys(a)){let p=a[h];p.map(k=>{var I,v;let b=(v=(I=k==null?void 0:k[0])==null?void 0:I[1])==null?void 0:v[0];(b==null?void 0:b[0])==="p"&&b[1]&&r(b[1])}),p.map(k=>{var I;let b=(I=k==null?void 0:k[1])==null?void 0:I[0];((b==null?void 0:b[0])==="p"||(b==null?void 0:b[0])==="eoi")&&b[1]&&r(b[1])})}if(f){let h=(B=f.transclusion_reference_pointer)==null?void 0:B.id;h&&r(h)}if(!(!s||!Array.isArray(s))&&!(l!==n&&!c&&(u==="page"||u==="collection_view_page")))for(let h of s)r(h)}return r(n),Array.from(o)},Ue=(e,t)=>{var l;let c=t||Object.keys(e.block)[0],n=new Set,o=(l=e.block[c])==null?void 0:l.value;o!=null&&o.created_by_id&&n.add(o==null?void 0:o.created_by_id),o!=null&&o.last_edited_by_id&&n.add(o==null?void 0:o.last_edited_by_id);let{properties:r}=o;if(r)for(let i of Object.keys(r))r[i].map(u=>{var f;let a=(f=u==null?void 0:u[1])==null?void 0:f[0];(a==null?void 0:a[0])==="u"&&a[1]&&n.add(a[1])});return Array.from(n)};var J=(e="")=>`${e.substr(0,8)}-${e.substr(8,4)}-${e.substr(12,4)}-${e.substr(16,4)}-${e.substr(20)}`;var le=/\b([a-f0-9]{32})\b/,se=/\b([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\b/,Ae=(e="",{uuid:t=!0}={})=>{if(!e)return null;e=e.split("?")[0];let c=e.match(le);if(c)return t?J(c[1]):c[1];let n=e.match(se);return n?t?n[1]:n[1].replace(/-/g,""):null};var Y=e=>e.replace(/-/g,"");function A(e,t,c=[]){var n,o;if(t.parent_id){c.push(t.parent_id);let r=t.parent_table;if((o=(n=e[r])==null?void 0:n[t.parent_id])!=null&&o.value)return A(e,e[r][t.parent_id].value,c)}return c}function Me(a,f,g,B){return U(this,arguments,function*(e,t,c,n,{startRecordMap:o,fetchOption:r={timeout:1e5},maxPage:l,debug:i,concurrency:s=100,collectionConcurrency:u=100}={}){var O;let h={},p=o||(yield t(e,{fetchOption:r})),k=JSON.parse(JSON.stringify(p));i&&console.time("Total fetch time");let b=1;for(;;){i&&console.debug(`Iteration ${b}`),i&&console.debug("block length ",Object.keys(p.block).length),i&&console.time("getPageContentBlockIds");let E=Object.keys(k.block),C=Object.keys(E.reduce((m,d)=>{let x=W(p,d,!0);for(let R of x)p.block[R]||(m[R]=!0);return m},{}));for(let{value:m}of Object.values(k.block))m&&!p.block[m.parent_id]&&m.parent_table==="block"&&C.push(m.parent_id);if(i&&console.timeEnd("getPageContentBlockIds"),i&&console.time("getBlocks"),k=(yield c(C,r)).recordMap,i&&console.timeEnd("getBlocks"),!(k!=null&&k.block))break;i&&console.time("mapBlocks");let D=Object.values(p.block).map(m=>{var d;return(d=m.value)==null?void 0:d.id}).filter(Boolean);p.block=y(y({},p.block),k.block),i&&console.timeEnd("mapBlocks"),i&&console.time("fetchCollections"),yield n(D,p,void 0,{fetchOption:r,concurrency:s,collectionConcurrency:u}),i&&console.timeEnd("fetchCollections"),i&&console.debug("collection query length "+Object.keys(p.collection_query).length),i&&console.debug("new block length ",Object.keys(k.block).length);let _=Object.values(p.block).map(m=>{var d;return(d=m.value)==null?void 0:d.type}).filter(m=>m==="page").length;if(i&&console.debug("page length ",_),Number.isInteger(l)&&_>=l)break;i&&console.debug(`memory usage ${process.memoryUsage().rss/1024/1024}MB`),b+=1,i&&console.debug()}i&&console.timeEnd("Total fetch time"),i&&console.time("get page map"),i&&console.debug("Total block length ",Object.keys(p.block).length);let I=Object.keys(p.block),v=[];for(let E of I)((O=p.block[E].value)==null?void 0:O.type)==="page"&&(v.push(ae(E,p,c).then(C=>h[E]=C)),yield me(1));yield Promise.all(v),i&&console.timeEnd("get page map"),i&&console.debug("Total page length ",Object.keys(h).length),i&&console.time("get page tree");let P={id:e,title:w(p.block[e].value,p),blocks:1,pages:1,children:[],type:"page"};return F(p,P),i&&console.timeEnd("get page tree"),{pageMap:h,pageTree:P,recordMap:p}})}function F(e,t){var r,l,i,s;let c=[t],n=t;for(;n.parent;)c.push(n.parent),n=n.parent;let o=(r=e.block[t.id])==null?void 0:r.value;if(!o)return console.warn(`No block value for ${t.id}`),delete t.parent,t;if((l=o.content)!=null&&l.length){for(let u of c)u.blocks+=o.content.length;for(let u of o.content){let a=(i=e.block[u])==null?void 0:i.value;if(a&&(t.children.push(F(e,{id:u,title:w(a,e),blocks:1,pages:0,children:[],type:a.type,parent:t})),a.type==="page"))for(let f of c)f.pages++}}else if((o==null?void 0:o.type)==="collection_view"){if(!((s=e.collection_query[o.collection_id])==null?void 0:s[o.view_ids[0]]))return console.warn(`No collection query for ${t.id}`),delete t.parent,t;let a={};for(let g of Object.values(e.collection_query[o.collection_id]))if(g.collection_group_results.blockIds)for(let B of g.collection_group_results.blockIds)a[B]=!0;let f=Object.keys(a);for(let g of c)g.pages+=f.length;for(let g of c)g.blocks+=f.length;for(let g of f)t.children.push(F(e,{id:g,title:w(e.block[g].value,e),blocks:f.length,pages:f.length,children:[],type:o.type,parent:t}))}return delete t.parent,t}function ae(e,t,c){return U(this,null,function*(){var a,f,g,B,h,p,k,b,I,v,P,O,E,C,D;let n=W(t,e),o={[e]:{value:t.block[e].value,role:"reader"}},r={},l={},i={},s=[];for(let _ of n){let m=(a=t.block[_])==null?void 0:a.value;if(!m){s.push(_);continue}if(o[_]={value:m,role:"reader"},m.type==="collection_view"||m.type==="collection_view_page"){t.collection[m.collection_id]&&(r[m.collection_id]=t.collection[m.collection_id]),t.collection_query[m.collection_id]&&(i[m.collection_id]=t.collection_query[m.collection_id]);for(let d of m.view_ids)if(t.collection_view[d]){l[d]=t.collection_view[d];let x=(B=(g=(f=t.collection_query[m==null?void 0:m.collection_id])==null?void 0:f[d])==null?void 0:g.collection_group_results)==null?void 0:B.blockIds;if(x!=null&&x.length)for(let R of x){let $=(h=t.block[R])==null?void 0:h.value;$?o[R]={value:$,role:"reader"}:s.push(R)}}}}let u=A(t,t.block[e].value);for(let _ of u){let m=(p=t.block[_])==null?void 0:p.value;m&&(o[_]={value:m,role:"reader"});let d=(k=t.collection[_])==null?void 0:k.value;d&&(r[_]={value:d})}for(let _ of Object.keys(o)){let m=o[_].value,d=m;if((m==null?void 0:m.type)==="alias")for(;;){let x=(I=(b=d==null?void 0:d.format)==null?void 0:b.alias_pointer)==null?void 0:I.id;if(!x)break;d=(v=t.block[x])==null?void 0:v.value,d?o[x]={value:d,role:"reader"}:s.push(x)}}if(s.length){let _=(yield c(s).catch(()=>({recordMap:{block:null}}))).recordMap;if(_!=null&&_.block){o=y(y({},o),_.block);for(let m in _.block)t.block[m]=_.block[m]}else console.warn(`fetching ${s.length} fail for ${e}`)}n=W(t,e);for(let _ of n){let m=(P=t.block[_])==null?void 0:P.value;if(m&&(o[_]={value:m,role:"reader"},m.type==="collection_view"||m.type==="collection_view_page")){t.collection[m.collection_id]&&(r[m.collection_id]=t.collection[m.collection_id]),t.collection_query[m.collection_id]&&(i[m.collection_id]=t.collection_query[m.collection_id]);for(let d of m.view_ids)if(t.collection_view[d]){l[d]=t.collection_view[d];let x=(C=(E=(O=t.collection_query[m==null?void 0:m.collection_id])==null?void 0:O[d])==null?void 0:E.collection_group_results)==null?void 0:C.blockIds;if(x!=null&&x.length)for(let R of x){let $=(D=t.block[R])==null?void 0:D.value;$&&(o[R]={value:$,role:"reader"})}}}}return{block:o,collection:r,collection_view:l,collection_query:i,signed_urls:{},notion_user:{}}})}var me=e=>U(null,null,function*(){return new Promise(t=>setTimeout(t,e))});var L=e=>(e||"").replace(/( |\/)/g,"-").replace(/[^a-zA-Z0-9-\u4e00-\u9FFF\uAC00-\uD7AF\u3130-\u318F\u3041-\u3096\u30A1-\u30FC\u3000-\u303F]/g,"").replace(/--+/g,"-").replace(/^-+|-+$/g,"").trim().toLowerCase();var et=(e,t,{uuid:c=!0}={})=>{var r,l;if(!e||!t)return null;let n=Y(e),o=(r=t.block[e])==null?void 0:r.value;if(o){let i=Q("slug",o,t)||L(w(o,t));if(i)return c?`${i}-${n}`:i}else{let i=(l=t.collection[e])==null?void 0:l.value;if(i){let s=L(T(i.name));if(s)return c?`${s}-${n}`:s}}return n};var rt=(e,t)=>{var r;let c=e.block,n=[],o=t;do{let l=(r=c[o])==null?void 0:r.value;if(!l)break;let i=w(l,e),s=j(l,e);if(!(i||s))break;n.push({block:l,active:o===t,pageId:o,title:i,icon:s});let u=H(l,e),a=u==null?void 0:u.id;if(!a)break;o=a}while(!0);return n.reverse(),n};import Z from"is-url-superb";var ut=(e,{mapImageUrl:t})=>{let n=Object.keys(e.block).flatMap(o=>{var i,s,u,a,f,g,B,h,p,k,b;let r=(i=e.block[o])==null?void 0:i.value,l=[];if(r){if(r.type==="image"){let P=((s=e.signed_urls)==null?void 0:s[r.id])||((f=(a=(u=r.properties)==null?void 0:u.source)==null?void 0:a[0])==null?void 0:f[0]);P.includes("file.notion.so")&&(P=(h=(B=(g=r.properties)==null?void 0:g.source)==null?void 0:B[0])==null?void 0:h[0]),P&&l.push({block:r,url:P})}if((p=r.format)!=null&&p.page_cover){let v=r.format.page_cover;l.push({block:r,url:v})}if((k=r.format)!=null&&k.bookmark_cover){let v=r.format.bookmark_cover;l.push({block:r,url:v})}if((b=r.format)!=null&&b.bookmark_icon){let v=r.format.bookmark_icon;l.push({block:r,url:v})}let I=j(r,e);I&&Z(I)&&l.push({block:r,url:I})}return l}).filter(Boolean).map(({block:o,url:r})=>t(r,o)).filter(Boolean);return Array.from(new Set(n))};import ue from"mem";import fe from"normalize-url";var pe=ue(e=>{if(!e)return"";try{if(e.startsWith("https://www.notion.so/image/")){let t=new URL(e),c=decodeURIComponent(t.pathname.substring(7)),n=pe(c);t.pathname=`/image/${encodeURIComponent(n)}`,e=t.toString()}return fe(e,{stripProtocol:!0,stripWWW:!0,stripHash:!0,stripTextFragment:!0,removeQueryParameters:!0})}catch(t){return""}});function kt(e,t){return{block:y(y({},e.block),t.block),collection:y(y({},e.collection),t.collection),collection_view:y(y({},e.collection_view),t.collection_view),notion_user:y(y({},e.notion_user),t.notion_user),collection_query:y(y({},e.collection_query),t.collection_query),signed_urls:y(y({},e.signed_urls),t.signed_urls),preview_images:y(y({},e.preview_images),t.preview_images)}}var G=(e,{month:t="short"}={})=>{let c=new Date(e),n=c.toLocaleString("en-US",{month:t});return`${c.getUTCFullYear()} ${n} ${c.getUTCDate()} ${c.getUTCHours()}:${c.getUTCMinutes()}`};var xt=e=>{let t=`${e.start_time||""} ${e.start_date} ${e.time_zone||""}`;return G(t)};function de(e,t,{wordsPerMinute:c=275,imageReadTimeInSeconds:n=12}={}){let o=z(e,t),r=o.numWords/c,i=(o.numImages>10?o.numImages/2*(n+3)+(o.numImages-10)*3:o.numImages/2*(2*n+(1-o.numImages)))/60,s=r+i;return M(y({},o),{totalWordsReadTimeInMinutes:r,totalImageReadTimeInMinutes:i,totalReadTimeInMinutes:s})}function Bt(e,t,c){let n=de(e,t,c);return ge(n.totalReadTimeInMinutes)}function z(e,t){var n,o,r,l;let c={numWords:0,numImages:0};if(!e)return c;for(let i of e.content||[]){let s=(n=t.block[i])==null?void 0:n.value,u=!1;if(s){switch(s.type){case"quote":case"alias":case"header":case"sub_header":case"sub_sub_header":{let a=w(s,t);c.numWords+=q(a);break}case"callout":case"toggle":case"to_do":case"bulleted_list":case"numbered_list":case"text":{let a=w(s,t);c.numWords+=q(a),u=!0;break}case"embed":case"tweet":case"maps":case"pdf":case"figma":case"typeform":case"codepen":case"excalidraw":case"gist":case"video":case"drive":case"audio":case"file":case"image":c.numImages+=1;break;case"bookmark":c.numImages+=.25;break;case"code":c.numImages+=2;break;case"table":case"collection_view":c.numImages+=2;break;case"column":case"column_list":case"transclusion_container":u=!0;break;case"table_of_contents":{let a=e;if(!a)continue;let f=X(a,t);for(let g of f)c.numWords+=q(g.text);break}case"transclusion_reference":{let a=(r=(o=s==null?void 0:s.format)==null?void 0:o.transclusion_reference_pointer)==null?void 0:r.id;if(!a)continue;let f=(l=t.block[a])==null?void 0:l.value;f&&K(c,z(f,t));break}default:break}u&&K(c,z(s,t))}}return c}function K(e,t){e.numWords+=t.numWords,e.numImages+=t.numImages}function q(e){return e?(e.match(/\w+/g)||[]).length:0}function ge(e){return e<.5?"less than a minute":e<1.5?"1 minute":`${Math.ceil(e)} minutes`}var Tt=(e,t)=>{if(!e)return null;if(e.startsWith("data:")||e.startsWith("https://images.unsplash.com"))return e;try{let o=new URL(e);if(o.pathname.startsWith("/secure.notion-static.com")&&o.hostname.endsWith(".amazonaws.com")&&o.searchParams.has("X-Amz-Credential")&&o.searchParams.has("X-Amz-Signature")&&o.searchParams.has("X-Amz-Algorithm"))return e}catch(o){}e.startsWith("/images")&&(e=`https://www.notion.so${e}`),e=`https://www.notion.so${e.startsWith("/image")?e:`/image/${encodeURIComponent(e)}`}`;let c=new URL(e),n=t.parent_table==="space"?"block":t.parent_table;return(n==="collection"||n==="team")&&(n="block"),c.searchParams.set("table",n),c.searchParams.set("id",t.id),c.searchParams.set("cache","v2"),e=c.toString(),e};var Ct=e=>t=>(t=(t||"").replace(/-/g,""),e&&t===e?"/":`/${t}`);export{Tt as defaultMapImageUrl,Ct as defaultMapPageUrl,de as estimatePageReadTime,Bt as estimatePageReadTimeAsHumanizedString,A as findAncestors,G as formatDate,xt as formatNotionDateTime,Me as getAllInSpace,S as getBlockCollectionId,j as getBlockIcon,Ce as getBlockParent,H as getBlockParentPage,w as getBlockTitle,et as getCanonicalPageId,re as getDateValue,rt as getPageBreadcrumbs,W as getPageContentBlockIds,Ue as getPageContentUserIds,ut as getPageImageUrls,Q as getPageProperty,ae as getPageSync,X as getPageTableOfContents,Be as getPageTitle,T as getTextContent,J as idToUuid,Z as isUrl,kt as mergeRecordMaps,L as normalizeTitle,pe as normalizeUrl,Ae as parsePageId,F as recursivePageTree,Y as uuidToId};
2
- //# sourceMappingURL=index.js.map
1
+ var J = Object.defineProperty, Y = Object.defineProperties;
2
+ var x = Object.getOwnPropertyDescriptors;
3
+ var R = Object.getOwnPropertySymbols;
4
+ var Z = Object.prototype.hasOwnProperty, G = Object.prototype.propertyIsEnumerable;
5
+ var F = (e, t, c) => t in e ? J(e, t, { enumerable: !0, configurable: !0, writable: !0, value: c }) : e[t] = c, d = (e, t) => {
6
+ for (var c in t || (t = {}))
7
+ Z.call(t, c) && F(e, c, t[c]);
8
+ if (R)
9
+ for (var c of R(t))
10
+ G.call(t, c) && F(e, c, t[c]);
11
+ return e;
12
+ }, E = (e, t) => Y(e, x(t));
13
+ var L = (e, t, c) => new Promise((o, n) => {
14
+ var s = (a) => {
15
+ try {
16
+ l(c.next(a));
17
+ } catch (f) {
18
+ n(f);
19
+ }
20
+ }, i = (a) => {
21
+ try {
22
+ l(c.throw(a));
23
+ } catch (f) {
24
+ n(f);
25
+ }
26
+ }, l = (a) => a.done ? o(a.value) : Promise.resolve(a.value).then(s, i);
27
+ l((c = c.apply(e, t)).next());
28
+ });
29
+ import K from "is-url-superb";
30
+ import { default as qe } from "is-url-superb";
31
+ import M from "mem";
32
+ import ee from "normalize-url";
33
+ const S = (e) => {
34
+ var t;
35
+ return e ? Array.isArray(e) ? (t = e == null ? void 0 : e.reduce((c, o) => c + (o[0] !== "⁍" && o[0] !== "‣" ? o[0] : ""), "")) != null ? t : "" : e : "";
36
+ };
37
+ function V(e, t) {
38
+ var n, s, i, l, a, f, r;
39
+ const c = e.collection_id || ((s = (n = e.format) == null ? void 0 : n.collection_pointer) == null ? void 0 : s.id);
40
+ if (c) return c;
41
+ const o = (i = e == null ? void 0 : e.view_ids) == null ? void 0 : i[0];
42
+ if (o) {
43
+ const m = (a = (l = t.collection_view) == null ? void 0 : l[o]) == null ? void 0 : a.value;
44
+ if (m)
45
+ return (r = (f = m.format) == null ? void 0 : f.collection_pointer) == null ? void 0 : r.id;
46
+ }
47
+ return null;
48
+ }
49
+ function C(e, t) {
50
+ var c, o;
51
+ if ((c = e.properties) != null && c.title) return S(e.properties.title);
52
+ if (e.type === "collection_view_page" || e.type === "collection_view") {
53
+ const n = V(e, t);
54
+ if (n) {
55
+ const s = (o = t.collection[n]) == null ? void 0 : o.value;
56
+ if (s) return S(s.name);
57
+ }
58
+ }
59
+ return "";
60
+ }
61
+ function H(e, t) {
62
+ var c, o, n;
63
+ if ((c = e.format) != null && c.page_icon) return (o = e.format) == null ? void 0 : o.page_icon;
64
+ if (e.type === "collection_view_page" || e.type === "collection_view") {
65
+ const s = V(e, t);
66
+ if (s) {
67
+ const i = (n = t.collection[s]) == null ? void 0 : n.value;
68
+ if (i) return i.icon;
69
+ }
70
+ }
71
+ return null;
72
+ }
73
+ function ve(e) {
74
+ var c;
75
+ const t = (c = e.block[Object.keys(e.block)[0]]) == null ? void 0 : c.value;
76
+ return t ? C(t, e) : null;
77
+ }
78
+ function te(e, t, c) {
79
+ var o;
80
+ try {
81
+ if (!t.properties || !Object.keys(c.collection))
82
+ return null;
83
+ const n = (o = c.collection[t.parent_id]) == null ? void 0 : o.value;
84
+ if (n) {
85
+ const s = e.toLowerCase(), i = Object.keys(n.schema).find(
86
+ (f) => {
87
+ var r, m;
88
+ return ((m = (r = n.schema[f]) == null ? void 0 : r.name) == null ? void 0 : m.toLowerCase()) === s;
89
+ }
90
+ );
91
+ if (!i) return null;
92
+ const { type: l } = n.schema[i], a = S(t.properties[i]);
93
+ switch (l) {
94
+ case "created_time":
95
+ return t.created_time;
96
+ case "multi_select":
97
+ return a.split(",");
98
+ case "date": {
99
+ const r = t.properties[i][0][1][0][1];
100
+ if (r.type == "datetime")
101
+ return (/* @__PURE__ */ new Date(`${r.start_date} ${r.start_time}`)).getTime();
102
+ if (r.type == "date")
103
+ return new Date(r.start_date).getTime();
104
+ if (r.type == "datetimerange") {
105
+ const { start_date: m, start_time: b, end_date: $, end_time: v } = r, _ = (/* @__PURE__ */ new Date(`${m} ${b}`)).getTime(), k = (/* @__PURE__ */ new Date(`${$} ${v}`)).getTime();
106
+ return [_, k];
107
+ } else {
108
+ const m = new Date(r.start_date).getTime(), b = new Date(r.end_date).getTime();
109
+ return [m, b];
110
+ }
111
+ }
112
+ case "checkbox":
113
+ return a == "Yes";
114
+ case "last_edited_time":
115
+ return t.last_edited_time;
116
+ default:
117
+ return a;
118
+ }
119
+ }
120
+ } catch (n) {
121
+ }
122
+ return null;
123
+ }
124
+ const ne = (e) => {
125
+ if (e && Array.isArray(e)) {
126
+ if (e[0] === "d") return e[1];
127
+ for (const t of e) {
128
+ const c = ne(t);
129
+ if (c) return c;
130
+ }
131
+ }
132
+ return null;
133
+ }, oe = (e, t, {
134
+ inclusive: c = !1
135
+ } = {}) => {
136
+ var n, s;
137
+ let o = e;
138
+ for (; o != null; ) {
139
+ if (c && (o == null ? void 0 : o.type) === "page") return o;
140
+ const i = o.parent_id, l = o.parent_table;
141
+ if (!i) break;
142
+ if (l === "collection")
143
+ o = (n = t.collection[i]) == null ? void 0 : n.value;
144
+ else if (o = (s = t.block[i]) == null ? void 0 : s.value, (o == null ? void 0 : o.type) === "page") return o;
145
+ }
146
+ return null;
147
+ }, ye = (e, t, {
148
+ inclusive: c = !1
149
+ } = {}) => {
150
+ var n, s, i, l;
151
+ let o = e;
152
+ for (; o != null; ) {
153
+ if (c && (o == null ? void 0 : o.type) === "page") return o;
154
+ const a = o.parent_id, f = o.parent_table;
155
+ if (!a) break;
156
+ if (f === "collection")
157
+ return (n = t.collection[a]) == null ? void 0 : n.value;
158
+ if (f === "space")
159
+ return (i = (s = t.space) == null ? void 0 : s[a]) == null ? void 0 : i.value;
160
+ if (o = (l = t.block[a]) == null ? void 0 : l.value, (o == null ? void 0 : o.type) === "page") return o;
161
+ }
162
+ return null;
163
+ }, ce = {
164
+ header: 0,
165
+ sub_header: 1,
166
+ sub_sub_header: 2
167
+ }, se = (e, t) => {
168
+ var n;
169
+ const c = ((n = e.content) != null ? n : []).map((s) => {
170
+ var l, a;
171
+ const i = (l = t.block[s]) == null ? void 0 : l.value;
172
+ if (i) {
173
+ const { type: f } = i;
174
+ if (f === "header" || f === "sub_header" || f === "sub_sub_header")
175
+ return {
176
+ id: s,
177
+ type: f,
178
+ text: S((a = i.properties) == null ? void 0 : a.title),
179
+ indentLevel: ce[f]
180
+ };
181
+ }
182
+ return null;
183
+ }).filter(Boolean), o = [
184
+ {
185
+ actual: -1,
186
+ effective: -1
187
+ }
188
+ ];
189
+ for (const s of c) {
190
+ const { indentLevel: i } = s, l = i;
191
+ do {
192
+ const a = o[o.length - 1], { actual: f, effective: r } = a;
193
+ if (l > f)
194
+ s.indentLevel = r + 1, o.push({
195
+ actual: l,
196
+ effective: s.indentLevel
197
+ });
198
+ else if (l === f) {
199
+ s.indentLevel = r;
200
+ break;
201
+ } else
202
+ o.pop();
203
+ } while (!0);
204
+ }
205
+ return c;
206
+ }, D = (e, t, c = !1) => {
207
+ const o = t || Object.keys(e.block)[0], n = /* @__PURE__ */ new Set();
208
+ function s(i) {
209
+ var b, $;
210
+ if (n.has(i)) return;
211
+ n.add(i);
212
+ const l = (b = e.block[i]) == null ? void 0 : b.value;
213
+ if (!l) return;
214
+ const { content: a, type: f, properties: r, format: m } = l;
215
+ if (r)
216
+ for (const v of Object.keys(r)) {
217
+ const _ = r[v];
218
+ _.map((k) => {
219
+ var I, w;
220
+ const h = (w = (I = k == null ? void 0 : k[0]) == null ? void 0 : I[1]) == null ? void 0 : w[0];
221
+ (h == null ? void 0 : h[0]) === "p" && h[1] && s(h[1]);
222
+ }), _.map((k) => {
223
+ var I;
224
+ const h = (I = k == null ? void 0 : k[1]) == null ? void 0 : I[0];
225
+ ((h == null ? void 0 : h[0]) === "p" || (h == null ? void 0 : h[0]) === "eoi") && h[1] && s(h[1]);
226
+ });
227
+ }
228
+ if (m) {
229
+ const v = ($ = m.transclusion_reference_pointer) == null ? void 0 : $.id;
230
+ v && s(v);
231
+ }
232
+ if (!(!a || !Array.isArray(a)) && !(i !== o && !c && (f === "page" || f === "collection_view_page")))
233
+ for (const v of a) s(v);
234
+ }
235
+ return s(o), Array.from(n);
236
+ }, we = (e, t) => {
237
+ var i;
238
+ const c = t || Object.keys(e.block)[0], o = /* @__PURE__ */ new Set(), n = (i = e.block[c]) == null ? void 0 : i.value;
239
+ n != null && n.created_by_id && o.add(n == null ? void 0 : n.created_by_id), n != null && n.last_edited_by_id && o.add(n == null ? void 0 : n.last_edited_by_id);
240
+ const { properties: s } = n;
241
+ if (s)
242
+ for (const l of Object.keys(s))
243
+ s[l].map((f) => {
244
+ var m;
245
+ const r = (m = f == null ? void 0 : f[1]) == null ? void 0 : m[0];
246
+ (r == null ? void 0 : r[0]) === "u" && r[1] && o.add(r[1]);
247
+ });
248
+ return Array.from(o);
249
+ }, le = (e = "") => `${e.substr(0, 8)}-${e.substr(8, 4)}-${e.substr(12, 4)}-${e.substr(16, 4)}-${e.substr(20)}`, ie = /\b([a-f0-9]{32})\b/, ae = /\b([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\b/, Ie = (e = "", { uuid: t = !0 } = {}) => {
250
+ if (!e) return null;
251
+ e = e.split("?")[0];
252
+ const c = e.match(ie);
253
+ if (c) return t ? le(c[1]) : c[1];
254
+ const o = e.match(ae);
255
+ return o ? t ? o[1] : o[1].replace(/-/g, "") : null;
256
+ }, re = (e) => e.replace(/-/g, "");
257
+ function X(e, t, c = []) {
258
+ var o, n;
259
+ if (t.parent_id) {
260
+ c.push(t.parent_id);
261
+ const s = t.parent_table;
262
+ if ((n = (o = e[s]) == null ? void 0 : o[t.parent_id]) != null && n.value)
263
+ return X(e, e[s][t.parent_id].value, c);
264
+ }
265
+ return c;
266
+ }
267
+ function $e(r, m, b, $) {
268
+ return L(this, arguments, function* (e, t, c, o, {
269
+ startRecordMap: n,
270
+ fetchOption: s = { timeout: 1e5 },
271
+ maxPage: i,
272
+ debug: l,
273
+ concurrency: a = 100,
274
+ collectionConcurrency: f = 100
275
+ } = {}) {
276
+ var O;
277
+ const v = {}, _ = n || (yield t(e, { fetchOption: s }));
278
+ let k = JSON.parse(JSON.stringify(_));
279
+ l && console.time("Total fetch time");
280
+ let h = 1;
281
+ for (; ; ) {
282
+ l && console.debug(`Iteration ${h}`), l && console.debug("block length ", Object.keys(_.block).length), l && console.time("getPageContentBlockIds");
283
+ const T = Object.keys(k.block), B = Object.keys(
284
+ T.reduce((u, g) => {
285
+ const y = D(_, g, !0);
286
+ for (const U of y) _.block[U] || (u[U] = !0);
287
+ return u;
288
+ }, {})
289
+ );
290
+ for (const { value: u } of Object.values(k.block))
291
+ u && !_.block[u.parent_id] && u.parent_table === "block" && B.push(u.parent_id);
292
+ if (l && console.timeEnd("getPageContentBlockIds"), l && console.time("getBlocks"), k = (yield c(B, s)).recordMap, l && console.timeEnd("getBlocks"), !(k != null && k.block)) break;
293
+ l && console.time("mapBlocks");
294
+ const W = Object.values(_.block).map((u) => {
295
+ var g;
296
+ return (g = u.value) == null ? void 0 : g.id;
297
+ }).filter(Boolean);
298
+ _.block = d(d({}, _.block), k.block), l && console.timeEnd("mapBlocks"), l && console.time("fetchCollections"), yield o(W, _, void 0, { fetchOption: s, concurrency: a, collectionConcurrency: f }), l && console.timeEnd("fetchCollections"), l && console.debug("collection query length " + Object.keys(_.collection_query).length), l && console.debug("new block length ", Object.keys(k.block).length);
299
+ const p = Object.values(_.block).map((u) => {
300
+ var g;
301
+ return (g = u.value) == null ? void 0 : g.type;
302
+ }).filter((u) => u === "page").length;
303
+ if (l && console.debug("page length ", p), Number.isInteger(i) && p >= i) break;
304
+ l && console.debug(`memory usage ${process.memoryUsage().rss / 1024 / 1024}MB`), h += 1, l && console.debug();
305
+ }
306
+ l && console.timeEnd("Total fetch time"), l && console.time("get page map"), l && console.debug("Total block length ", Object.keys(_.block).length);
307
+ const I = Object.keys(_.block), w = [];
308
+ for (const T of I)
309
+ ((O = _.block[T].value) == null ? void 0 : O.type) === "page" && (w.push(ue(T, _, c).then((B) => v[T] = B)), yield fe(1));
310
+ yield Promise.all(w), l && console.timeEnd("get page map"), l && console.debug("Total page length ", Object.keys(v).length), l && console.time("get page tree");
311
+ const P = {
312
+ id: e,
313
+ title: C(_.block[e].value, _),
314
+ blocks: 1,
315
+ pages: 1,
316
+ children: [],
317
+ type: "page"
318
+ };
319
+ return A(_, P), l && console.timeEnd("get page tree"), { pageMap: v, pageTree: P, recordMap: _ };
320
+ });
321
+ }
322
+ function A(e, t) {
323
+ var s, i, l, a;
324
+ const c = [t];
325
+ let o = t;
326
+ for (; o.parent; )
327
+ c.push(o.parent), o = o.parent;
328
+ const n = (s = e.block[t.id]) == null ? void 0 : s.value;
329
+ if (!n)
330
+ return console.warn(`No block value for ${t.id}`), delete t.parent, t;
331
+ if ((i = n.content) != null && i.length) {
332
+ for (const f of c) f.blocks += n.content.length;
333
+ for (const f of n.content) {
334
+ const r = (l = e.block[f]) == null ? void 0 : l.value;
335
+ if (r && (t.children.push(
336
+ A(e, {
337
+ id: f,
338
+ title: C(r, e),
339
+ blocks: 1,
340
+ pages: 0,
341
+ children: [],
342
+ type: r.type,
343
+ parent: t
344
+ })
345
+ ), r.type === "page"))
346
+ for (const m of c) m.pages++;
347
+ }
348
+ } else if ((n == null ? void 0 : n.type) === "collection_view") {
349
+ if (!((a = e.collection_query[n.collection_id]) == null ? void 0 : a[n.view_ids[0]]))
350
+ return console.warn(`No collection query for ${t.id}`), delete t.parent, t;
351
+ const r = {};
352
+ for (const b of Object.values(e.collection_query[n.collection_id]))
353
+ if (b.collection_group_results.blockIds)
354
+ for (const $ of b.collection_group_results.blockIds) r[$] = !0;
355
+ const m = Object.keys(r);
356
+ for (const b of c) b.pages += m.length;
357
+ for (const b of c) b.blocks += m.length;
358
+ for (const b of m)
359
+ t.children.push(
360
+ A(e, {
361
+ id: b,
362
+ title: C(e.block[b].value, e),
363
+ blocks: m.length,
364
+ pages: m.length,
365
+ children: [],
366
+ type: n.type,
367
+ parent: t
368
+ })
369
+ );
370
+ }
371
+ return delete t.parent, t;
372
+ }
373
+ function ue(e, t, c) {
374
+ return L(this, null, function* () {
375
+ var r, m, b, $, v, _, k, h, I, w, P, O, T, B, W;
376
+ let o = D(t, e), n = { [e]: { value: t.block[e].value, role: "reader" } };
377
+ const s = {}, i = {}, l = {}, a = [];
378
+ for (const p of o) {
379
+ const u = (r = t.block[p]) == null ? void 0 : r.value;
380
+ if (!u) {
381
+ a.push(p);
382
+ continue;
383
+ }
384
+ if (n[p] = { value: u, role: "reader" }, u.type === "collection_view" || u.type === "collection_view_page") {
385
+ t.collection[u.collection_id] && (s[u.collection_id] = t.collection[u.collection_id]), t.collection_query[u.collection_id] && (l[u.collection_id] = t.collection_query[u.collection_id]);
386
+ for (const g of u.view_ids)
387
+ if (t.collection_view[g]) {
388
+ i[g] = t.collection_view[g];
389
+ const y = ($ = (b = (m = t.collection_query[u == null ? void 0 : u.collection_id]) == null ? void 0 : m[g]) == null ? void 0 : b.collection_group_results) == null ? void 0 : $.blockIds;
390
+ if (y != null && y.length)
391
+ for (const U of y) {
392
+ const j = (v = t.block[U]) == null ? void 0 : v.value;
393
+ j ? n[U] = { value: j, role: "reader" } : a.push(U);
394
+ }
395
+ }
396
+ }
397
+ }
398
+ const f = X(t, t.block[e].value);
399
+ for (const p of f) {
400
+ const u = (_ = t.block[p]) == null ? void 0 : _.value;
401
+ u && (n[p] = { value: u, role: "reader" });
402
+ const g = (k = t.collection[p]) == null ? void 0 : k.value;
403
+ g && (s[p] = { value: g });
404
+ }
405
+ for (const p of Object.keys(n)) {
406
+ const u = n[p].value;
407
+ let g = u;
408
+ if ((u == null ? void 0 : u.type) === "alias")
409
+ for (; ; ) {
410
+ const y = (I = (h = g == null ? void 0 : g.format) == null ? void 0 : h.alias_pointer) == null ? void 0 : I.id;
411
+ if (!y) break;
412
+ g = (w = t.block[y]) == null ? void 0 : w.value, g ? n[y] = { value: g, role: "reader" } : a.push(y);
413
+ }
414
+ }
415
+ if (a.length) {
416
+ const p = (yield c(a).catch(() => ({ recordMap: { block: null } }))).recordMap;
417
+ if (p != null && p.block) {
418
+ n = d(d({}, n), p.block);
419
+ for (const u in p.block) t.block[u] = p.block[u];
420
+ } else
421
+ console.warn(`fetching ${a.length} fail for ${e}`);
422
+ }
423
+ o = D(t, e);
424
+ for (const p of o) {
425
+ const u = (P = t.block[p]) == null ? void 0 : P.value;
426
+ if (u && (n[p] = { value: u, role: "reader" }, u.type === "collection_view" || u.type === "collection_view_page")) {
427
+ t.collection[u.collection_id] && (s[u.collection_id] = t.collection[u.collection_id]), t.collection_query[u.collection_id] && (l[u.collection_id] = t.collection_query[u.collection_id]);
428
+ for (const g of u.view_ids)
429
+ if (t.collection_view[g]) {
430
+ i[g] = t.collection_view[g];
431
+ const y = (B = (T = (O = t.collection_query[u == null ? void 0 : u.collection_id]) == null ? void 0 : O[g]) == null ? void 0 : T.collection_group_results) == null ? void 0 : B.blockIds;
432
+ if (y != null && y.length)
433
+ for (const U of y) {
434
+ const j = (W = t.block[U]) == null ? void 0 : W.value;
435
+ j && (n[U] = { value: j, role: "reader" });
436
+ }
437
+ }
438
+ }
439
+ }
440
+ return {
441
+ block: n,
442
+ collection: s,
443
+ collection_view: i,
444
+ collection_query: l,
445
+ signed_urls: {},
446
+ notion_user: {}
447
+ };
448
+ });
449
+ }
450
+ const fe = (e) => L(null, null, function* () {
451
+ return new Promise((t) => setTimeout(t, e));
452
+ }), N = (e) => (e || "").replace(/( |\/)/g, "-").replace(/[^a-zA-Z0-9-\u4e00-\u9FFF\uAC00-\uD7AF\u3130-\u318F\u3041-\u3096\u30A1-\u30FC\u3000-\u303F]/g, "").replace(/--+/g, "-").replace(/^-+|-+$/g, "").trim().toLowerCase(), Pe = (e, t, { uuid: c = !0 } = {}) => {
453
+ var s, i;
454
+ if (!e || !t) return null;
455
+ const o = re(e), n = (s = t.block[e]) == null ? void 0 : s.value;
456
+ if (n) {
457
+ const l = te("slug", n, t) || N(C(n, t));
458
+ if (l)
459
+ return c ? `${l}-${o}` : l;
460
+ } else {
461
+ const l = (i = t.collection[e]) == null ? void 0 : i.value;
462
+ if (l) {
463
+ const a = N(S(l.name));
464
+ if (a)
465
+ return c ? `${a}-${o}` : a;
466
+ }
467
+ }
468
+ return o;
469
+ }, Ue = (e, t) => {
470
+ var s;
471
+ const c = e.block, o = [];
472
+ let n = t;
473
+ do {
474
+ const i = (s = c[n]) == null ? void 0 : s.value;
475
+ if (!i) break;
476
+ const l = C(i, e), a = H(i, e);
477
+ if (!(l || a)) break;
478
+ o.push({
479
+ block: i,
480
+ active: n === t,
481
+ pageId: n,
482
+ title: l,
483
+ icon: a
484
+ });
485
+ const f = oe(i, e), r = f == null ? void 0 : f.id;
486
+ if (!r) break;
487
+ n = r;
488
+ } while (!0);
489
+ return o.reverse(), o;
490
+ }, Te = (e, {
491
+ mapImageUrl: t
492
+ }) => {
493
+ const o = Object.keys(e.block).flatMap((n) => {
494
+ var l, a, f, r, m, b, $, v, _, k, h;
495
+ const s = (l = e.block[n]) == null ? void 0 : l.value, i = [];
496
+ if (s) {
497
+ if (s.type === "image") {
498
+ let P = ((a = e.signed_urls) == null ? void 0 : a[s.id]) || ((m = (r = (f = s.properties) == null ? void 0 : f.source) == null ? void 0 : r[0]) == null ? void 0 : m[0]);
499
+ P.includes("file.notion.so") && (P = (v = ($ = (b = s.properties) == null ? void 0 : b.source) == null ? void 0 : $[0]) == null ? void 0 : v[0]), P && i.push({
500
+ block: s,
501
+ url: P
502
+ });
503
+ }
504
+ if ((_ = s.format) != null && _.page_cover) {
505
+ const w = s.format.page_cover;
506
+ i.push({
507
+ block: s,
508
+ url: w
509
+ });
510
+ }
511
+ if ((k = s.format) != null && k.bookmark_cover) {
512
+ const w = s.format.bookmark_cover;
513
+ i.push({
514
+ block: s,
515
+ url: w
516
+ });
517
+ }
518
+ if ((h = s.format) != null && h.bookmark_icon) {
519
+ const w = s.format.bookmark_icon;
520
+ i.push({
521
+ block: s,
522
+ url: w
523
+ });
524
+ }
525
+ const I = H(s, e);
526
+ I && K(I) && i.push({
527
+ block: s,
528
+ url: I
529
+ });
530
+ }
531
+ return i;
532
+ }).filter(Boolean).map(({ block: n, url: s }) => t(s, n)).filter(Boolean);
533
+ return Array.from(new Set(o));
534
+ }, me = M((e) => {
535
+ if (!e) return "";
536
+ try {
537
+ if (e.startsWith("https://www.notion.so/image/")) {
538
+ const t = new URL(e), c = decodeURIComponent(t.pathname.substring(7)), o = me(c);
539
+ t.pathname = `/image/${encodeURIComponent(o)}`, e = t.toString();
540
+ }
541
+ return ee(e, {
542
+ stripProtocol: !0,
543
+ stripWWW: !0,
544
+ stripHash: !0,
545
+ stripTextFragment: !0,
546
+ removeQueryParameters: !0
547
+ });
548
+ } catch (t) {
549
+ return "";
550
+ }
551
+ });
552
+ function Ce(e, t) {
553
+ return {
554
+ block: d(d({}, e.block), t.block),
555
+ collection: d(d({}, e.collection), t.collection),
556
+ collection_view: d(d({}, e.collection_view), t.collection_view),
557
+ notion_user: d(d({}, e.notion_user), t.notion_user),
558
+ collection_query: d(d({}, e.collection_query), t.collection_query),
559
+ signed_urls: d(d({}, e.signed_urls), t.signed_urls),
560
+ preview_images: d(d({}, e.preview_images), t.preview_images)
561
+ };
562
+ }
563
+ const _e = (e, { month: t = "short" } = {}) => {
564
+ const c = new Date(e), o = c.toLocaleString("en-US", { month: t });
565
+ return `${c.getUTCFullYear()} ${o} ${c.getUTCDate()} ${c.getUTCHours()}:${c.getUTCMinutes()}`;
566
+ }, Be = (e) => {
567
+ const t = `${e.start_time || ""} ${e.start_date} ${e.time_zone || ""}`;
568
+ return _e(t);
569
+ };
570
+ function ge(e, t, { wordsPerMinute: c = 275, imageReadTimeInSeconds: o = 12 } = {}) {
571
+ const n = z(e, t), s = n.numWords / c, l = (n.numImages > 10 ? n.numImages / 2 * (o + 3) + (n.numImages - 10) * 3 : n.numImages / 2 * (2 * o + (1 - n.numImages))) / 60, a = s + l;
572
+ return E(d({}, n), {
573
+ totalWordsReadTimeInMinutes: s,
574
+ totalImageReadTimeInMinutes: l,
575
+ totalReadTimeInMinutes: a
576
+ });
577
+ }
578
+ function Oe(e, t, c) {
579
+ const o = ge(e, t, c);
580
+ return be(o.totalReadTimeInMinutes);
581
+ }
582
+ function z(e, t) {
583
+ var o, n, s, i;
584
+ const c = {
585
+ numWords: 0,
586
+ numImages: 0
587
+ };
588
+ if (!e) return c;
589
+ for (const l of e.content || []) {
590
+ const a = (o = t.block[l]) == null ? void 0 : o.value;
591
+ let f = !1;
592
+ if (a) {
593
+ switch (a.type) {
594
+ case "quote":
595
+ // fallthrough
596
+ case "alias":
597
+ // fallthrough
598
+ case "header":
599
+ // fallthrough
600
+ case "sub_header":
601
+ // fallthrough
602
+ case "sub_sub_header": {
603
+ const r = C(a, t);
604
+ c.numWords += q(r);
605
+ break;
606
+ }
607
+ case "callout":
608
+ // fallthrough
609
+ case "toggle":
610
+ // fallthrough
611
+ case "to_do":
612
+ // fallthrough
613
+ case "bulleted_list":
614
+ // fallthrough
615
+ case "numbered_list":
616
+ // fallthrough
617
+ case "text": {
618
+ const r = C(a, t);
619
+ c.numWords += q(r), f = !0;
620
+ break;
621
+ }
622
+ case "embed":
623
+ // fallthrough
624
+ case "tweet":
625
+ // fallthrough
626
+ case "maps":
627
+ // fallthrough
628
+ case "pdf":
629
+ // fallthrough
630
+ case "figma":
631
+ // fallthrough
632
+ case "typeform":
633
+ // fallthrough
634
+ case "codepen":
635
+ // fallthrough
636
+ case "excalidraw":
637
+ // fallthrough
638
+ case "gist":
639
+ // fallthrough
640
+ case "video":
641
+ // fallthrough
642
+ case "drive":
643
+ // fallthrough
644
+ case "audio":
645
+ // fallthrough
646
+ case "file":
647
+ // fallthrough
648
+ case "image":
649
+ c.numImages += 1;
650
+ break;
651
+ case "bookmark":
652
+ c.numImages += 0.25;
653
+ break;
654
+ case "code":
655
+ c.numImages += 2;
656
+ break;
657
+ case "table":
658
+ // fallthrough
659
+ case "collection_view":
660
+ c.numImages += 2;
661
+ break;
662
+ case "column":
663
+ // fallthrough
664
+ case "column_list":
665
+ // fallthrough
666
+ case "transclusion_container":
667
+ f = !0;
668
+ break;
669
+ case "table_of_contents": {
670
+ const r = e;
671
+ if (!r) continue;
672
+ const m = se(r, t);
673
+ for (const b of m) c.numWords += q(b.text);
674
+ break;
675
+ }
676
+ case "transclusion_reference": {
677
+ const r = (s = (n = a == null ? void 0 : a.format) == null ? void 0 : n.transclusion_reference_pointer) == null ? void 0 : s.id;
678
+ if (!r) continue;
679
+ const m = (i = t.block[r]) == null ? void 0 : i.value;
680
+ m && Q(c, z(m, t));
681
+ break;
682
+ }
683
+ }
684
+ f && Q(c, z(a, t));
685
+ }
686
+ }
687
+ return c;
688
+ }
689
+ function Q(e, t) {
690
+ e.numWords += t.numWords, e.numImages += t.numImages;
691
+ }
692
+ function q(e) {
693
+ return e ? (e.match(/\w+/g) || []).length : 0;
694
+ }
695
+ function be(e) {
696
+ return e < 0.5 ? "less than a minute" : e < 1.5 ? "1 minute" : `${Math.ceil(e)} minutes`;
697
+ }
698
+ const je = (e, t) => {
699
+ if (!e) return null;
700
+ if (e.startsWith("data:") || e.startsWith("https://images.unsplash.com")) return e;
701
+ try {
702
+ const n = new URL(e);
703
+ if (n.pathname.startsWith("/secure.notion-static.com") && n.hostname.endsWith(".amazonaws.com") && n.searchParams.has("X-Amz-Credential") && n.searchParams.has("X-Amz-Signature") && n.searchParams.has("X-Amz-Algorithm"))
704
+ return e;
705
+ } catch (n) {
706
+ }
707
+ e.startsWith("/images") && (e = `https://www.notion.so${e}`), e = `https://www.notion.so${e.startsWith("/image") ? e : `/image/${encodeURIComponent(e)}`}`;
708
+ const c = new URL(e);
709
+ let o = t.parent_table === "space" ? "block" : t.parent_table;
710
+ return (o === "collection" || o === "team") && (o = "block"), c.searchParams.set("table", o), c.searchParams.set("id", t.id), c.searchParams.set("cache", "v2"), e = c.toString(), e;
711
+ }, Se = (e) => (t) => (t = (t || "").replace(/-/g, ""), e && t === e ? "/" : `/${t}`);
712
+ export {
713
+ je as defaultMapImageUrl,
714
+ Se as defaultMapPageUrl,
715
+ ge as estimatePageReadTime,
716
+ Oe as estimatePageReadTimeAsHumanizedString,
717
+ X as findAncestors,
718
+ _e as formatDate,
719
+ Be as formatNotionDateTime,
720
+ $e as getAllInSpace,
721
+ V as getBlockCollectionId,
722
+ H as getBlockIcon,
723
+ ye as getBlockParent,
724
+ oe as getBlockParentPage,
725
+ C as getBlockTitle,
726
+ Pe as getCanonicalPageId,
727
+ ne as getDateValue,
728
+ Ue as getPageBreadcrumbs,
729
+ D as getPageContentBlockIds,
730
+ we as getPageContentUserIds,
731
+ Te as getPageImageUrls,
732
+ te as getPageProperty,
733
+ ue as getPageSync,
734
+ se as getPageTableOfContents,
735
+ ve as getPageTitle,
736
+ S as getTextContent,
737
+ le as idToUuid,
738
+ qe as isUrl,
739
+ Ce as mergeRecordMaps,
740
+ N as normalizeTitle,
741
+ me as normalizeUrl,
742
+ Ie as parsePageId,
743
+ A as recursivePageTree,
744
+ re as uuidToId
745
+ };
746
+ //# sourceMappingURL=index.js.map