snow-cms 1.2.0 → 1.3.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/dist/index-browser.es.js +2 -2
- package/dist/index-browser.es2.js +1 -1
- package/dist/index.css +3 -3
- package/dist/index.es.js +3 -43
- package/dist/index.es2.js +2 -1
- package/dist/index.es3.js +1 -3
- package/dist/index.es4.js +1 -1
- package/dist/index.js +32 -30
- package/dist/index2.css +1 -0
- package/dist/index2.js +43 -0
- package/dist/index3.js +1 -0
- package/dist/index4.js +3 -0
- package/dist/index5.js +1 -0
- package/dist/index6.js +1 -0
- package/package.json +15 -15
- package/dist/index.es5.js +0 -1
- package/dist/index.es6.js +0 -3
- package/dist/index.es7.js +0 -2
- package/dist/index.es8.js +0 -1
- package/dist/index.es9.js +0 -1
package/dist/index3.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{P as Y,c as Z,I as ee,S as te,s as re,a as ne,p as se,E as ie}from"./index2.js";import{c as T,g as oe}from"./index.js";var _,F;function ae(){if(F)return _;F=1;var s="Expected a function",r=NaN,o="[object Symbol]",v=/^\s+|\s+$/g,u=/^[-+]0x[0-9a-f]+$/i,b=/^0b[01]+$/i,I=/^0o[0-7]+$/i,n=parseInt,g=typeof T=="object"&&T&&T.Object===Object&&T,c=typeof self=="object"&&self&&self.Object===Object&&self,h=g||c||Function("return this")(),M=Object.prototype,z=M.toString,A=Math.max,B=Math.min,O=function(){return h.Date.now()};function G(e,i,d){var p,y,w,m,a,l,L=0,P=!1,E=!1,C=!0;if(typeof e!="function")throw new TypeError(s);i=N(i)||0,S(d)&&(P=!!d.leading,E="maxWait"in d,w=E?A(N(d.maxWait)||0,i):w,C="trailing"in d?!!d.trailing:C);function R(t){var f=p,k=y;return p=y=void 0,L=t,m=e.apply(k,f),m}function V(t){return L=t,a=setTimeout(j,i),P?R(t):m}function X(t){var f=t-l,k=t-L,q=i-f;return E?B(q,w-k):q}function D(t){var f=t-l,k=t-L;return l===void 0||f>=i||f<0||E&&k>=w}function j(){var t=O();if(D(t))return W(t);a=setTimeout(j,X(t))}function W(t){return a=void 0,C&&p?R(t):(p=y=void 0,m)}function J(){a!==void 0&&clearTimeout(a),L=0,p=l=y=a=void 0}function Q(){return a===void 0?m:W(O())}function U(){var t=O(),f=D(t);if(p=arguments,y=this,l=t,f){if(a===void 0)return V(l);if(E)return a=setTimeout(j,i),R(l)}return a===void 0&&(a=setTimeout(j,i)),m}return U.cancel=J,U.flush=Q,U}function S(e){var i=typeof e;return!!e&&(i=="object"||i=="function")}function H(e){return!!e&&typeof e=="object"}function K(e){return typeof e=="symbol"||H(e)&&z.call(e)==o}function N(e){if(typeof e=="number")return e;if(K(e))return r;if(S(e)){var i=typeof e.valueOf=="function"?e.valueOf():e;e=S(i)?i+"":i}if(typeof e!="string")return e===0?e:+e;e=e.replace(v,"");var d=b.test(e);return d||I.test(e)?n(e.slice(2),d?2:8):u.test(e)?r:+e}return _=G,_}var ue=ae();const de=oe(ue);class x{constructor(){this.beforeMountedListeners=[],this.mountedListeners=[],this.updatedListeners=[],this.markdownUpdatedListeners=[],this.blurListeners=[],this.focusListeners=[],this.destroyListeners=[],this.beforeMount=r=>(this.beforeMountedListeners.push(r),this),this.mounted=r=>(this.mountedListeners.push(r),this),this.updated=r=>(this.updatedListeners.push(r),this)}get listeners(){return{beforeMount:this.beforeMountedListeners,mounted:this.mountedListeners,updated:this.updatedListeners,markdownUpdated:this.markdownUpdatedListeners,blur:this.blurListeners,focus:this.focusListeners,destroy:this.destroyListeners}}markdownUpdated(r){return this.markdownUpdatedListeners.push(r),this}blur(r){return this.blurListeners.push(r),this}focus(r){return this.focusListeners.push(r),this}destroy(r){return this.destroyListeners.push(r),this}}const $=Z(new x,"listener"),fe=new Y("MILKDOWN_LISTENER"),ce=s=>(s.inject($,new x),async()=>{await s.wait(ee);const r=s.get($),{listeners:o}=r;o.beforeMount.forEach(n=>n(s)),await s.wait(te);const v=s.get(re);let u=null,b=null;const I=new ne({key:fe,view:()=>({destroy:()=>{o.destroy.forEach(n=>n(s))}}),props:{handleDOMEvents:{focus:()=>(o.focus.forEach(n=>n(s)),!1),blur:()=>(o.blur.forEach(n=>n(s)),!1)}},state:{init:(n,g)=>{u=g.doc,b=v(g.doc)},apply:n=>!n.docChanged||n.getMeta("addToHistory")===!1?void 0:de(()=>{const{doc:c}=n;if(o.updated.length>0&&u&&!u.eq(c)&&o.updated.forEach(h=>{h(s,c,u)}),o.markdownUpdated.length>0&&u&&!u.eq(c)){const h=v(c);o.markdownUpdated.forEach(M=>{M(s,h,b)}),b=h}u=c},200)()}});s.update(se,n=>n.concat(I)),await s.wait(ie),o.mounted.forEach(n=>n(s))});ce.meta={package:"@milkdown/plugin-listener",displayName:"Listener"};export{x as ListenerManager,fe as key,ce as listener,$ as listenerCtx};
|
package/dist/index4.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{$nodeAttr as I,$useKeymap as C,$nodeSchema as b,$command as g,$node as ot,$ctx as st,$markAttr as J,$markSchema as Q,$inputRule as M,$prose as q,$remark as T}from"./index6.js";import{F as N,b as X,R as re,d as ae,e as Kt,N as Dt,l as _t,f as Pt,v as K,g as tt,h,r as lt,t as ne,m as Y,i as R,T as oe,j as it,k as $,n as dt,w as se,o as le,q as Et,u as ct,P as W,a as F,D as rt,x as at,y as $t,A as qt}from"./index2.js";import"./index.js";function Wt(t,e){return function(r,a){let{$from:n,$to:s,node:l}=r.selection;if(l&&l.isBlock||n.depth<2||!n.sameParent(s))return!1;let i=n.node(-1);if(i.type!=t)return!1;if(n.parent.content.size==0&&n.node(-1).childCount==n.indexAfter(-1)){if(n.depth==3||n.node(-3).type!=t||n.index(-2)!=n.node(-2).childCount-1)return!1;if(a){let u=N.empty,m=n.index(-1)?1:n.index(-2)?2:3;for(let A=n.depth-m;A>=n.depth-3;A--)u=N.from(n.node(A).copy(u));let f=n.indexAfter(-1)<n.node(-2).childCount?1:n.indexAfter(-2)<n.node(-3).childCount?2:3;u=u.append(N.from(t.createAndFill()));let y=n.before(n.depth-(m-1)),k=r.tr.replace(y,n.after(-f),new X(u,4-m,0)),w=-1;k.doc.nodesBetween(y,k.doc.content.size,(A,te)=>{if(w>-1)return!1;A.isTextblock&&A.content.size==0&&(w=te+1)}),w>-1&&k.setSelection(ae.near(k.doc.resolve(w))),a(k.scrollIntoView())}return!0}let d=s.pos==n.end()?i.contentMatchAt(0).defaultType:null,c=r.tr.delete(n.pos,s.pos),p=d?[null,{type:d}]:void 0;return Kt(c.doc,n.pos,2,p)?(a&&a(c.split(n.pos,2,p).scrollIntoView()),!0):!1}}function pt(t){return function(e,r){let{$from:a,$to:n}=e.selection,s=a.blockRange(n,l=>l.childCount>0&&l.firstChild.type==t);return s?r?a.node(s.depth-1).type==t?Ft(e,r,t,s):Vt(e,r,s):!0:!1}}function Ft(t,e,r,a){let n=t.tr,s=a.end,l=a.$to.end(a.depth);s<l&&(n.step(new re(s-1,l,s,l,new X(N.from(r.create(null,a.parent.copy())),1,0),1,!0)),a=new Dt(n.doc.resolve(a.$from.pos),n.doc.resolve(l),a.depth));const i=_t(a);if(i==null)return!1;n.lift(a,i);let d=n.doc.resolve(n.mapping.map(s,-1)-1);return Pt(n.doc,d.pos)&&d.nodeBefore.type==d.nodeAfter.type&&n.join(d.pos),e(n.scrollIntoView()),!0}function Vt(t,e,r){let a=t.tr,n=r.parent;for(let f=r.end,y=r.endIndex-1,k=r.startIndex;y>k;y--)f-=n.child(y).nodeSize,a.delete(f-1,f+1);let s=a.doc.resolve(r.start),l=s.nodeAfter;if(a.mapping.map(r.end)!=r.start+s.nodeAfter.nodeSize)return!1;let i=r.startIndex==0,d=r.endIndex==n.childCount,c=s.node(-1),p=s.index(-1);if(!c.canReplace(p+(i?0:1),p+1,l.content.append(d?N.empty:N.from(n))))return!1;let u=s.pos,m=u+l.nodeSize;return a.step(new re(u-(i?1:0),m+(d?1:0),u+1,m-1,new X((i?N.empty:N.from(n.copy(N.empty))).append(d?N.empty:N.from(n.copy(N.empty))),i?0:1,d?0:1),i?0:1)),e(a.scrollIntoView()),!0}function zt(t){return function(e,r){let{$from:a,$to:n}=e.selection,s=a.blockRange(n,c=>c.childCount>0&&c.firstChild.type==t);if(!s)return!1;let l=s.startIndex;if(l==0)return!1;let i=s.parent,d=i.child(l-1);if(d.type!=t)return!1;if(r){let c=d.lastChild&&d.lastChild.type==i.type,p=N.from(c?t.create():null),u=new X(N.from(t.create(null,N.from(i.type.create(null,p)))),c?3:1,0),m=s.start,f=s.end;r(e.tr.step(new re(m-(c?3:1),f,m,f,u,1,!0)).scrollIntoView())}return!0}}function Ut(t){const e=new Map;if(!t||!t.type)throw new Error("mdast-util-definitions expected node");return K(t,"definition",function(a){const n=nt(a.identifier);n&&!e.get(n)&&e.set(n,a)}),r;function r(a){const n=nt(a);return e.get(n)}}function nt(t){return String(t||"").toUpperCase()}function jt(){return function(t){const e=Ut(t);K(t,function(r,a,n){if(r.type==="definition"&&n!==void 0&&typeof a=="number")return n.children.splice(a,1),[tt,a];if(r.type==="imageReference"||r.type==="linkReference"){const s=e(r.identifier);if(s&&n&&typeof a=="number")return n.children[a]=r.type==="imageReference"?{type:"image",url:s.url,title:s.title,alt:r.alt}:{type:"link",url:s.url,title:s.title,children:r.children},[tt,a]}})}}function ut(t,e){var r;if(!(e.childCount>=1&&((r=e.lastChild)==null?void 0:r.type.name)==="hardbreak")){t.next(e.content);return}const n=[];e.content.forEach((s,l,i)=>{i!==e.childCount-1&&n.push(s)}),t.next(N.fromArray(n))}function o(t,e){return Object.assign(t,{meta:{package:"@milkdown/preset-commonmark",...e}}),t}const ie=J("emphasis");o(ie,{displayName:"Attr<emphasis>",group:"Emphasis"});const D=Q("emphasis",t=>({attrs:{marker:{default:t.get(lt).emphasis||"*",validate:"string"}},parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style",getAttrs:e=>e==="italic"}],toDOM:e=>["em",t.get(ie.key)(e)],parseMarkdown:{match:e=>e.type==="emphasis",runner:(e,r,a)=>{e.openMark(a,{marker:r.marker}),e.next(r.children),e.closeMark(a)}},toMarkdown:{match:e=>e.type.name==="emphasis",runner:(e,r)=>{e.withMark(r,"emphasis",void 0,{marker:r.attrs.marker})}}}));o(D.mark,{displayName:"MarkSchema<emphasis>",group:"Emphasis"});o(D.ctx,{displayName:"MarkSchemaCtx<emphasis>",group:"Emphasis"});const de=g("ToggleEmphasis",t=>()=>ne(D.type(t)));o(de,{displayName:"Command<toggleEmphasisCommand>",group:"Emphasis"});const mt=M(t=>Y(/(?:^|[^*])\*([^*]+)\*$/,D.type(t),{getAttr:()=>({marker:"*"}),updateCaptured:({fullMatch:e,start:r})=>e.startsWith("*")?{}:{fullMatch:e.slice(1),start:r+1}}));o(mt,{displayName:"InputRule<emphasis>|Star",group:"Emphasis"});const gt=M(t=>Y(/(?:^|[^_])_([^_]+)_$/,D.type(t),{getAttr:()=>({marker:"_"}),updateCaptured:({fullMatch:e,start:r})=>e.startsWith("_")?{}:{fullMatch:e.slice(1),start:r+1}}));o(gt,{displayName:"InputRule<emphasis>|Underscore",group:"Emphasis"});const ce=C("emphasisKeymap",{ToggleEmphasis:{shortcuts:"Mod-i",command:t=>{const e=t.get(h);return()=>e.call(de.key)}}});o(ce.ctx,{displayName:"KeymapCtx<emphasis>",group:"Emphasis"});o(ce.shortcuts,{displayName:"Keymap<emphasis>",group:"Emphasis"});const pe=J("strong");o(pe,{displayName:"Attr<strong>",group:"Strong"});const V=Q("strong",t=>({attrs:{marker:{default:t.get(lt).strong||"*",validate:"string"}},parseDOM:[{tag:"b",getAttrs:e=>e.style.fontWeight!="normal"&&null},{tag:"strong"},{style:"font-style",getAttrs:e=>e==="bold"},{style:"font-weight=400",clearMark:e=>e.type.name=="strong"},{style:"font-weight",getAttrs:e=>/^(bold(er)?|[5-9]\d{2,})$/.test(e)&&null}],toDOM:e=>["strong",t.get(pe.key)(e)],parseMarkdown:{match:e=>e.type==="strong",runner:(e,r,a)=>{e.openMark(a,{marker:r.marker}),e.next(r.children),e.closeMark(a)}},toMarkdown:{match:e=>e.type.name==="strong",runner:(e,r)=>{e.withMark(r,"strong",void 0,{marker:r.attrs.marker})}}}));o(V.mark,{displayName:"MarkSchema<strong>",group:"Strong"});o(V.ctx,{displayName:"MarkSchemaCtx<strong>",group:"Strong"});const ue=g("ToggleStrong",t=>()=>ne(V.type(t)));o(ue,{displayName:"Command<toggleStrongCommand>",group:"Strong"});const yt=M(t=>Y(/(?:\*\*|__)([^*_]+)(?:\*\*|__)$/,V.type(t),{getAttr:e=>({marker:e[0].startsWith("*")?"*":"_"})}));o(yt,{displayName:"InputRule<strong>",group:"Strong"});const me=C("strongKeymap",{ToggleBold:{shortcuts:["Mod-b"],command:t=>{const e=t.get(h);return()=>e.call(ue.key)}}});o(me.ctx,{displayName:"KeymapCtx<strong>",group:"Strong"});o(me.shortcuts,{displayName:"Keymap<strong>",group:"Strong"});const ge=J("inlineCode");o(ge,{displayName:"Attr<inlineCode>",group:"InlineCode"});const x=Q("inlineCode",t=>({priority:100,code:!0,parseDOM:[{tag:"code"}],toDOM:e=>["code",t.get(ge.key)(e)],parseMarkdown:{match:e=>e.type==="inlineCode",runner:(e,r,a)=>{e.openMark(a),e.addText(r.value),e.closeMark(a)}},toMarkdown:{match:e=>e.type.name==="inlineCode",runner:(e,r,a)=>{e.withMark(r,"inlineCode",a.text||"")}}}));o(x.mark,{displayName:"MarkSchema<inlineCode>",group:"InlineCode"});o(x.ctx,{displayName:"MarkSchemaCtx<inlineCode>",group:"InlineCode"});const ye=g("ToggleInlineCode",t=>()=>(e,r)=>{const{selection:a,tr:n}=e;if(a.empty)return!1;const{from:s,to:l}=a;return e.doc.rangeHasMark(s,l,x.type(t))?(r==null||r(n.removeMark(s,l,x.type(t))),!0):(Object.keys(e.schema.marks).filter(c=>c!==x.type.name).map(c=>e.schema.marks[c]).forEach(c=>{n.removeMark(s,l,c)}),r==null||r(n.addMark(s,l,x.type(t).create())),!0)});o(ye,{displayName:"Command<toggleInlineCodeCommand>",group:"InlineCode"});const ht=M(t=>Y(/(?:`)([^`]+)(?:`)$/,x.type(t)));o(ht,{displayName:"InputRule<inlineCodeInputRule>",group:"InlineCode"});const he=C("inlineCodeKeymap",{ToggleInlineCode:{shortcuts:"Mod-e",command:t=>{const e=t.get(h);return()=>e.call(ye.key)}}});o(he.ctx,{displayName:"KeymapCtx<inlineCode>",group:"InlineCode"});o(he.shortcuts,{displayName:"Keymap<inlineCode>",group:"InlineCode"});const fe=J("link");o(fe,{displayName:"Attr<link>",group:"Link"});const O=Q("link",t=>({attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},parseDOM:[{tag:"a[href]",getAttrs:e=>{if(!(e instanceof HTMLElement))throw R(e);return{href:e.getAttribute("href"),title:e.getAttribute("title")}}}],toDOM:e=>["a",{...t.get(fe.key)(e),...e.attrs}],parseMarkdown:{match:e=>e.type==="link",runner:(e,r,a)=>{const n=r.url,s=r.title;e.openMark(a,{href:n,title:s}),e.next(r.children),e.closeMark(a)}},toMarkdown:{match:e=>e.type.name==="link",runner:(e,r)=>{e.withMark(r,"link",void 0,{title:r.attrs.title,url:r.attrs.href})}}}));o(O.mark,{displayName:"MarkSchema<link>",group:"Link"});const ft=g("ToggleLink",t=>(e={})=>ne(O.type(t),e));o(ft,{displayName:"Command<toggleLinkCommand>",group:"Link"});const kt=g("UpdateLink",t=>(e={})=>(r,a)=>{if(!a)return!1;let n,s=-1;const{selection:l}=r,{from:i,to:d}=l;if(r.doc.nodesBetween(i,i===d?d+1:d,(y,k)=>{if(O.type(t).isInSet(y.marks))return n=y,s=k,!1}),!n)return!1;const c=n.marks.find(({type:y})=>y===O.type(t));if(!c)return!1;const p=s,u=s+n.nodeSize,{tr:m}=r,f=O.type(t).create({...c.attrs,...e});return f?(a(m.removeMark(p,u,c).addMark(p,u,f).setSelection(new oe(m.selection.$anchor)).scrollIntoView()),!0):!1});o(kt,{displayName:"Command<updateLinkCommand>",group:"Link"});const Nt=ot("doc",()=>({content:"block+",parseMarkdown:{match:({type:t})=>t==="root",runner:(t,e,r)=>{t.injectRoot(e,r)}},toMarkdown:{match:t=>t.type.name==="doc",runner:(t,e)=>{t.openNode("root"),t.next(e.content)}}}));o(Nt,{displayName:"NodeSchema<doc>",group:"Doc"});function Gt(t){return K(t,e=>{var r,a;if(((r=e.children)==null?void 0:r.length)!==1)return;const n=(a=e.children)==null?void 0:a[0];if(!n||n.type!=="html")return;const{value:s}=n;["<br />","<br>","<br/>"].includes(s)&&e.children.splice(0,1)})}const Z=T("remark-preserve-empty-line",()=>()=>Gt);o(Z.plugin,{displayName:"Remark<remarkPreserveEmptyLine>",group:"Remark"});o(Z.options,{displayName:"RemarkConfig<remarkPreserveEmptyLine>",group:"Remark"});const ke=I("paragraph");o(ke,{displayName:"Attr<paragraph>",group:"Paragraph"});const B=b("paragraph",t=>({content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM:e=>["p",t.get(ke.key)(e),0],parseMarkdown:{match:e=>e.type==="paragraph",runner:(e,r,a)=>{e.openNode(a),r.children?e.next(r.children):e.addText(r.value||""),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="paragraph",runner:(e,r)=>{var a;const s=(a=t.get(it).state)==null?void 0:a.doc.lastChild;e.openNode("paragraph"),(!r.content||r.content.size===0)&&r!==s&&Jt(t)?e.addNode("html",void 0,"<br />"):ut(e,r),e.closeNode()}}}));function Jt(t){let e=!1;try{t.get(Z.id),e=!0}catch{e=!1}return e}o(B.node,{displayName:"NodeSchema<paragraph>",group:"Paragraph"});o(B.ctx,{displayName:"NodeSchemaCtx<paragraph>",group:"Paragraph"});const Ne=g("TurnIntoText",t=>()=>$(B.type(t)));o(Ne,{displayName:"Command<turnIntoTextCommand>",group:"Paragraph"});const Ie=C("paragraphKeymap",{TurnIntoText:{shortcuts:"Mod-Alt-0",command:t=>{const e=t.get(h);return()=>e.call(Ne.key)}}});o(Ie.ctx,{displayName:"KeymapCtx<paragraph>",group:"Paragraph"});o(Ie.shortcuts,{displayName:"Keymap<paragraph>",group:"Paragraph"});const Qt=Array(6).fill(0).map((t,e)=>e+1);function Xt(t){return t.textContent.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/\s+/g,"-")}const ee=st(Xt,"headingIdGenerator");o(ee,{displayName:"Ctx<HeadingIdGenerator>",group:"Heading"});const Ce=I("heading");o(Ce,{displayName:"Attr<heading>",group:"Heading"});const H=b("heading",t=>{const e=t.get(ee.key);return{content:"inline*",group:"block",defining:!0,attrs:{id:{default:"",validate:"string"},level:{default:1,validate:"number"}},parseDOM:Qt.map(r=>({tag:`h${r}`,getAttrs:a=>{if(!(a instanceof HTMLElement))throw R(a);return{level:r,id:a.id}}})),toDOM:r=>[`h${r.attrs.level}`,{...t.get(Ce.key)(r),id:r.attrs.id||e(r)},0],parseMarkdown:{match:({type:r})=>r==="heading",runner:(r,a,n)=>{const s=a.depth;r.openNode(n,{level:s}),r.next(a.children),r.closeNode()}},toMarkdown:{match:r=>r.type.name==="heading",runner:(r,a)=>{r.openNode("heading",void 0,{depth:a.attrs.level}),ut(r,a),r.closeNode()}}}});o(H.node,{displayName:"NodeSchema<heading>",group:"Heading"});o(H.ctx,{displayName:"NodeSchemaCtx<heading>",group:"Heading"});const It=M(t=>dt(/^(?<hashes>#+)\s$/,H.type(t),e=>{var r,a;const n=((a=(r=e.groups)==null?void 0:r.hashes)==null?void 0:a.length)||0,s=t.get(it),{$from:l}=s.state.selection,i=l.node();if(i.type.name==="heading"){let d=Number(i.attrs.level)+Number(n);return d>6&&(d=6),{level:d}}return{level:n}}));o(It,{displayName:"InputRule<wrapInHeadingInputRule>",group:"Heading"});const v=g("WrapInHeading",t=>e=>(e??(e=1),e<1?$(B.type(t)):$(H.type(t),{level:e})));o(v,{displayName:"Command<wrapInHeadingCommand>",group:"Heading"});const be=g("DowngradeHeading",t=>()=>(e,r,a)=>{const{$from:n}=e.selection,s=n.node();if(s.type!==H.type(t)||!e.selection.empty||n.parentOffset!==0)return!1;const l=s.attrs.level-1;return l?(r==null||r(e.tr.setNodeMarkup(e.selection.$from.before(),void 0,{...s.attrs,level:l})),!0):$(B.type(t))(e,r,a)});o(be,{displayName:"Command<downgradeHeadingCommand>",group:"Heading"});const Me=C("headingKeymap",{TurnIntoH1:{shortcuts:"Mod-Alt-1",command:t=>{const e=t.get(h);return()=>e.call(v.key,1)}},TurnIntoH2:{shortcuts:"Mod-Alt-2",command:t=>{const e=t.get(h);return()=>e.call(v.key,2)}},TurnIntoH3:{shortcuts:"Mod-Alt-3",command:t=>{const e=t.get(h);return()=>e.call(v.key,3)}},TurnIntoH4:{shortcuts:"Mod-Alt-4",command:t=>{const e=t.get(h);return()=>e.call(v.key,4)}},TurnIntoH5:{shortcuts:"Mod-Alt-5",command:t=>{const e=t.get(h);return()=>e.call(v.key,5)}},TurnIntoH6:{shortcuts:"Mod-Alt-6",command:t=>{const e=t.get(h);return()=>e.call(v.key,6)}},DowngradeHeading:{shortcuts:["Delete","Backspace"],command:t=>{const e=t.get(h);return()=>e.call(be.key)}}});o(Me.ctx,{displayName:"KeymapCtx<heading>",group:"Heading"});o(Me.shortcuts,{displayName:"Keymap<heading>",group:"Heading"});const Le=I("blockquote");o(Le,{displayName:"Attr<blockquote>",group:"Blockquote"});const z=b("blockquote",t=>({content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM:e=>["blockquote",t.get(Le.key)(e),0],parseMarkdown:{match:({type:e})=>e==="blockquote",runner:(e,r,a)=>{e.openNode(a).next(r.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="blockquote",runner:(e,r)=>{e.openNode("blockquote").next(r.content).closeNode()}}}));o(z.node,{displayName:"NodeSchema<blockquote>",group:"Blockquote"});o(z.ctx,{displayName:"NodeSchemaCtx<blockquote>",group:"Blockquote"});const Ct=M(t=>se(/^\s*>\s$/,z.type(t)));o(Ct,{displayName:"InputRule<wrapInBlockquoteInputRule>",group:"Blockquote"});const ve=g("WrapInBlockquote",t=>()=>le(z.type(t)));o(ve,{displayName:"Command<wrapInBlockquoteCommand>",group:"Blockquote"});const xe=C("blockquoteKeymap",{WrapInBlockquote:{shortcuts:"Mod-Shift-b",command:t=>{const e=t.get(h);return()=>e.call(ve.key)}}});o(xe.ctx,{displayName:"KeymapCtx<blockquote>",group:"Blockquote"});o(xe.shortcuts,{displayName:"Keymap<blockquote>",group:"Blockquote"});const we=I("codeBlock",()=>({pre:{},code:{}}));o(we,{displayName:"Attr<codeBlock>",group:"CodeBlock"});const U=b("code_block",t=>({content:"text*",group:"block",marks:"",defining:!0,code:!0,attrs:{language:{default:"",validate:"string"}},parseDOM:[{tag:"pre",preserveWhitespace:"full",getAttrs:e=>{if(!(e instanceof HTMLElement))throw R(e);return{language:e.dataset.language}}}],toDOM:e=>{const r=t.get(we.key)(e);return["pre",{...r.pre,"data-language":e.attrs.language},["code",r.code,0]]},parseMarkdown:{match:({type:e})=>e==="code",runner:(e,r,a)=>{const n=r.lang,s=r.value;e.openNode(a,{language:n}),s&&e.addText(s),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="code_block",runner:(e,r)=>{var a;e.addNode("code",void 0,((a=r.content.firstChild)==null?void 0:a.text)||"",{lang:r.attrs.language})}}}));o(U.node,{displayName:"NodeSchema<codeBlock>",group:"CodeBlock"});o(U.ctx,{displayName:"NodeSchemaCtx<codeBlock>",group:"CodeBlock"});const bt=M(t=>dt(/^```(?<language>[a-z]*)?[\s\n]$/,U.type(t),e=>{var r;return{language:((r=e.groups)==null?void 0:r.language)??""}}));o(bt,{displayName:"InputRule<createCodeBlockInputRule>",group:"CodeBlock"});const Ae=g("CreateCodeBlock",t=>(e="")=>$(U.type(t),{language:e}));o(Ae,{displayName:"Command<createCodeBlockCommand>",group:"CodeBlock"});const Yt=g("UpdateCodeBlockLanguage",()=>({pos:t,language:e}={pos:-1,language:""})=>(r,a)=>t>=0?(a==null||a(r.tr.setNodeAttribute(t,"language",e)),!0):!1);o(Yt,{displayName:"Command<updateCodeBlockLanguageCommand>",group:"CodeBlock"});const Se=C("codeBlockKeymap",{CreateCodeBlock:{shortcuts:"Mod-Alt-c",command:t=>{const e=t.get(h);return()=>e.call(Ae.key)}}});o(Se.ctx,{displayName:"KeymapCtx<codeBlock>",group:"CodeBlock"});o(Se.shortcuts,{displayName:"Keymap<codeBlock>",group:"CodeBlock"});const Re=I("image");o(Re,{displayName:"Attr<image>",group:"Image"});const _=b("image",t=>({inline:!0,group:"inline",selectable:!0,draggable:!0,marks:"",atom:!0,defining:!0,isolating:!0,attrs:{src:{default:"",validate:"string"},alt:{default:"",validate:"string"},title:{default:"",validate:"string"}},parseDOM:[{tag:"img[src]",getAttrs:e=>{if(!(e instanceof HTMLElement))throw R(e);return{src:e.getAttribute("src")||"",alt:e.getAttribute("alt")||"",title:e.getAttribute("title")||e.getAttribute("alt")||""}}}],toDOM:e=>["img",{...t.get(Re.key)(e),...e.attrs}],parseMarkdown:{match:({type:e})=>e==="image",runner:(e,r,a)=>{const n=r.url,s=r.alt,l=r.title;e.addNode(a,{src:n,alt:s,title:l})}},toMarkdown:{match:e=>e.type.name==="image",runner:(e,r)=>{e.addNode("image",void 0,void 0,{title:r.attrs.title,url:r.attrs.src,alt:r.attrs.alt})}}}));o(_.node,{displayName:"NodeSchema<image>",group:"Image"});o(_.ctx,{displayName:"NodeSchemaCtx<image>",group:"Image"});const Mt=g("InsertImage",t=>(e={})=>(r,a)=>{if(!a)return!0;const{src:n="",alt:s="",title:l=""}=e,i=_.type(t).create({src:n,alt:s,title:l});return i&&a(r.tr.replaceSelectionWith(i).scrollIntoView()),!0});o(Mt,{displayName:"Command<insertImageCommand>",group:"Image"});const Lt=g("UpdateImage",t=>(e={})=>(r,a)=>{const n=Et(r.selection,_.type(t));if(!n)return!1;const{node:s,pos:l}=n,i={...s.attrs},{src:d,alt:c,title:p}=e;return d!==void 0&&(i.src=d),c!==void 0&&(i.alt=c),p!==void 0&&(i.title=p),a==null||a(r.tr.setNodeMarkup(l,void 0,i).scrollIntoView()),!0});o(Lt,{displayName:"Command<updateImageCommand>",group:"Image"});const Zt=M(t=>new ct(/!\[(?<alt>.*?)]\((?<filename>.*?)\s*(?="|\))"?(?<title>[^"]+)?"?\)/,(e,r,a,n)=>{const[s,l,i="",d]=r;return s?e.tr.replaceWith(a,n,_.type(t).create({src:i,alt:l,title:d})):null}));o(Zt,{displayName:"InputRule<insertImageInputRule>",group:"Image"});const G=I("hardbreak",t=>({"data-type":"hardbreak","data-is-inline":t.attrs.isInline}));o(G,{displayName:"Attr<hardbreak>",group:"Hardbreak"});const S=b("hardbreak",t=>({inline:!0,group:"inline",attrs:{isInline:{default:!1,validate:"boolean"}},selectable:!1,parseDOM:[{tag:"br"},{tag:'span[data-type="hardbreak"]',getAttrs:()=>({isInline:!0})}],toDOM:e=>e.attrs.isInline?["span",t.get(G.key)(e)," "]:["br",t.get(G.key)(e)],parseMarkdown:{match:({type:e})=>e==="break",runner:(e,r,a)=>{var n;e.addNode(a,{isInline:!!((n=r.data)!=null&&n.isInline)})}},leafText:()=>`
|
|
2
|
+
`,toMarkdown:{match:e=>e.type.name==="hardbreak",runner:(e,r)=>{r.attrs.isInline?e.addNode("text",void 0,`
|
|
3
|
+
`):e.addNode("break")}}}));o(S.node,{displayName:"NodeSchema<hardbreak>",group:"Hardbreak"});o(S.ctx,{displayName:"NodeSchemaCtx<hardbreak>",group:"Hardbreak"});const Be=g("InsertHardbreak",t=>()=>(e,r)=>{var a;const{selection:n,tr:s}=e;if(!(n instanceof oe))return!1;if(n.empty){const l=n.$from.node();if(l.childCount>0&&((a=l.lastChild)==null?void 0:a.type.name)==="hardbreak")return r==null||r(s.replaceRangeWith(n.to-1,n.to,e.schema.node("paragraph")).setSelection(ae.near(s.doc.resolve(n.to))).scrollIntoView()),!0}return r==null||r(s.setMeta("hardbreak",!0).replaceSelectionWith(S.type(t).create()).scrollIntoView()),!0});o(Be,{displayName:"Command<insertHardbreakCommand>",group:"Hardbreak"});const He=C("hardbreakKeymap",{InsertHardbreak:{shortcuts:"Shift-Enter",command:t=>{const e=t.get(h);return()=>e.call(Be.key)}}});o(He.ctx,{displayName:"KeymapCtx<hardbreak>",group:"Hardbreak"});o(He.shortcuts,{displayName:"Keymap<hardbreak>",group:"Hardbreak"});const Oe=I("hr");o(Oe,{displayName:"Attr<hr>",group:"Hr"});const j=b("hr",t=>({group:"block",parseDOM:[{tag:"hr"}],toDOM:e=>["hr",t.get(Oe.key)(e)],parseMarkdown:{match:({type:e})=>e==="thematicBreak",runner:(e,r,a)=>{e.addNode(a)}},toMarkdown:{match:e=>e.type.name==="hr",runner:e=>{e.addNode("thematicBreak")}}}));o(j.node,{displayName:"NodeSchema<hr>",group:"Hr"});o(j.ctx,{displayName:"NodeSchemaCtx<hr>",group:"Hr"});const vt=M(t=>new ct(/^(?:---|___\s|\*\*\*\s)$/,(e,r,a,n)=>{const{tr:s}=e;return r[0]&&s.replaceWith(a-1,n,j.type(t).create()),s}));o(vt,{displayName:"InputRule<insertHrInputRule>",group:"Hr"});const xt=g("InsertHr",t=>()=>(e,r)=>{if(!r)return!0;const a=B.node.type(t).create(),{tr:n,selection:s}=e,{from:l}=s,i=j.type(t).create();if(!i)return!0;const d=n.replaceSelectionWith(i).insert(l,a),c=ae.findFrom(d.doc.resolve(l),1,!0);return c&&r(d.setSelection(c).scrollIntoView()),!0});o(xt,{displayName:"Command<insertHrCommand>",group:"Hr"});const Te=I("bulletList");o(Te,{displayName:"Attr<bulletList>",group:"BulletList"});const P=b("bullet_list",t=>({content:"listItem+",group:"block",attrs:{spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ul",getAttrs:e=>{if(!(e instanceof HTMLElement))throw R(e);return{spread:e.dataset.spread==="true"}}}],toDOM:e=>["ul",{...t.get(Te.key)(e),"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:r})=>e==="list"&&!r,runner:(e,r,a)=>{const n=r.spread!=null?`${r.spread}`:"false";e.openNode(a,{spread:n}).next(r.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="bullet_list",runner:(e,r)=>{e.openNode("list",void 0,{ordered:!1,spread:r.attrs.spread}).next(r.content).closeNode()}}}));o(P.node,{displayName:"NodeSchema<bulletList>",group:"BulletList"});o(P.ctx,{displayName:"NodeSchemaCtx<bulletList>",group:"BulletList"});const wt=M(t=>se(/^\s*([-+*])\s$/,P.type(t)));o(wt,{displayName:"InputRule<wrapInBulletListInputRule>",group:"BulletList"});const Ke=g("WrapInBulletList",t=>()=>le(P.type(t)));o(Ke,{displayName:"Command<wrapInBulletListCommand>",group:"BulletList"});const De=C("bulletListKeymap",{WrapInBulletList:{shortcuts:"Mod-Alt-8",command:t=>{const e=t.get(h);return()=>e.call(Ke.key)}}});o(De.ctx,{displayName:"KeymapCtx<bulletListKeymap>",group:"BulletList"});o(De.shortcuts,{displayName:"Keymap<bulletListKeymap>",group:"BulletList"});const _e=I("orderedList");o(_e,{displayName:"Attr<orderedList>",group:"OrderedList"});const E=b("ordered_list",t=>({content:"listItem+",group:"block",attrs:{order:{default:1,validate:"number"},spread:{default:!1,validate:"boolean"}},parseDOM:[{tag:"ol",getAttrs:e=>{if(!(e instanceof HTMLElement))throw R(e);return{spread:e.dataset.spread,order:e.hasAttribute("start")?Number(e.getAttribute("start")):1}}}],toDOM:e=>["ol",{...t.get(_e.key)(e),...e.attrs.order===1?{}:e.attrs.order,"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e,ordered:r})=>e==="list"&&!!r,runner:(e,r,a)=>{const n=r.spread!=null?`${r.spread}`:"true";e.openNode(a,{spread:n}).next(r.children).closeNode()}},toMarkdown:{match:e=>e.type.name==="ordered_list",runner:(e,r)=>{e.openNode("list",void 0,{ordered:!0,start:1,spread:r.attrs.spread==="true"}),e.next(r.content),e.closeNode()}}}));o(E.node,{displayName:"NodeSchema<orderedList>",group:"OrderedList"});o(E.ctx,{displayName:"NodeSchemaCtx<orderedList>",group:"OrderedList"});const At=M(t=>se(/^\s*(\d+)\.\s$/,E.type(t),e=>({order:Number(e[1])}),(e,r)=>r.childCount+r.attrs.order===Number(e[1])));o(At,{displayName:"InputRule<wrapInOrderedListInputRule>",group:"OrderedList"});const Pe=g("WrapInOrderedList",t=>()=>le(E.type(t)));o(Pe,{displayName:"Command<wrapInOrderedListCommand>",group:"OrderedList"});const Ee=C("orderedListKeymap",{WrapInOrderedList:{shortcuts:"Mod-Alt-7",command:t=>{const e=t.get(h);return()=>e.call(Pe.key)}}});o(Ee.ctx,{displayName:"KeymapCtx<orderedList>",group:"OrderedList"});o(Ee.shortcuts,{displayName:"Keymap<orderedList>",group:"OrderedList"});const $e=I("listItem");o($e,{displayName:"Attr<listItem>",group:"ListItem"});const L=b("list_item",t=>({group:"listItem",content:"paragraph block*",attrs:{label:{default:"•",validate:"string"},listType:{default:"bullet",validate:"string"},spread:{default:!0,validate:"boolean"}},defining:!0,parseDOM:[{tag:"li",getAttrs:e=>{if(!(e instanceof HTMLElement))throw R(e);return{label:e.dataset.label,listType:e.dataset.listType,spread:e.dataset.spread==="true"}}}],toDOM:e=>["li",{...t.get($e.key)(e),"data-label":e.attrs.label,"data-list-type":e.attrs.listType,"data-spread":e.attrs.spread},0],parseMarkdown:{match:({type:e})=>e==="listItem",runner:(e,r,a)=>{const n=r.label!=null?`${r.label}.`:"•",s=r.label!=null?"ordered":"bullet",l=r.spread!=null?`${r.spread}`:"true";e.openNode(a,{label:n,listType:s,spread:l}),e.next(r.children),e.closeNode()}},toMarkdown:{match:e=>e.type.name==="list_item",runner:(e,r)=>{e.openNode("listItem",void 0,{spread:r.attrs.spread}),e.next(r.content),e.closeNode()}}}));o(L.node,{displayName:"NodeSchema<listItem>",group:"ListItem"});o(L.ctx,{displayName:"NodeSchemaCtx<listItem>",group:"ListItem"});const qe=g("SinkListItem",t=>()=>zt(L.type(t)));o(qe,{displayName:"Command<sinkListItemCommand>",group:"ListItem"});const We=g("LiftListItem",t=>()=>pt(L.type(t)));o(We,{displayName:"Command<liftListItemCommand>",group:"ListItem"});const Fe=g("SplitListItem",t=>()=>Wt(L.type(t)));o(Fe,{displayName:"Command<splitListItemCommand>",group:"ListItem"});function er(t){return(e,r,a)=>{const{selection:n}=e;if(!(n instanceof oe))return!1;const{empty:s,$from:l}=n;if(!s||l.parentOffset!==0)return!1;const i=l.node(-1);return i.type!==L.type(t)||i.firstChild!==l.node()||l.node(-2).childCount>1?!1:pt(L.type(t))(e,r,a)}}const Ve=g("LiftFirstListItem",t=>()=>er(t));o(Ve,{displayName:"Command<liftFirstListItemCommand>",group:"ListItem"});const ze=C("listItemKeymap",{NextListItem:{shortcuts:"Enter",command:t=>{const e=t.get(h);return()=>e.call(Fe.key)}},SinkListItem:{shortcuts:["Tab","Mod-]"],command:t=>{const e=t.get(h);return()=>e.call(qe.key)}},LiftListItem:{shortcuts:["Shift-Tab","Mod-["],command:t=>{const e=t.get(h);return()=>e.call(We.key)}},LiftFirstListItem:{shortcuts:["Backspace","Delete"],command:t=>{const e=t.get(h);return()=>e.call(Ve.key)}}});o(ze.ctx,{displayName:"KeymapCtx<listItem>",group:"ListItem"});o(ze.shortcuts,{displayName:"Keymap<listItem>",group:"ListItem"});const St=ot("text",()=>({group:"inline",parseMarkdown:{match:({type:t})=>t==="text",runner:(t,e)=>{t.addText(e.value)}},toMarkdown:{match:t=>t.type.name==="text",runner:(t,e)=>{t.addNode("text",void 0,e.text)}}}));o(St,{displayName:"NodeSchema<text>",group:"Text"});const Ue=I("html");o(Ue,{displayName:"Attr<html>",group:"Html"});const je=b("html",t=>({atom:!0,group:"inline",inline:!0,attrs:{value:{default:"",validate:"string"}},toDOM:e=>{const r=document.createElement("span"),a={...t.get(Ue.key)(e),"data-value":e.attrs.value,"data-type":"html"};return r.textContent=e.attrs.value,["span",a,e.attrs.value]},parseDOM:[{tag:'span[data-type="html"]',getAttrs:e=>({value:e.dataset.value??""})}],parseMarkdown:{match:({type:e})=>e==="html",runner:(e,r,a)=>{e.addNode(a,{value:r.value})}},toMarkdown:{match:e=>e.type.name==="html",runner:(e,r)=>{e.addNode("html",void 0,r.attrs.value)}}}));o(je.node,{displayName:"NodeSchema<html>",group:"Html"});o(je.ctx,{displayName:"NodeSchemaCtx<html>",group:"Html"});const tr=[Nt,ke,B,ee,Ce,H,G,S,Le,z,we,U,Oe,j,Re,_,Te,P,_e,E,$e,L,ie,D,pe,V,ge,x,fe,O,Ue,je,St].flat(),rr=[Ct,wt,At,bt,vt,It].flat(),ar=[mt,gt,ht,yt],nr=[Ne,ve,v,be,Ae,Be,xt,Mt,Lt,Pe,Ke,qe,Fe,We,Ve,de,ye,ue,ft,kt],or=[xe,Se,He,Me,ze,Ee,De,Ie,ce,he,me].flat(),Ge=T("remarkAddOrderInList",()=>()=>t=>{K(t,"list",e=>{if(e.ordered){const r=e.start??1;e.children.forEach((a,n)=>{a.label=n+r})}})});o(Ge.plugin,{displayName:"Remark<remarkAddOrderInListPlugin>",group:"Remark"});o(Ge.options,{displayName:"RemarkConfig<remarkAddOrderInListPlugin>",group:"Remark"});const Je=T("remarkLineBreak",()=>()=>t=>{const e=/[\t ]*(?:\r?\n|\r)/g;K(t,"text",(r,a,n)=>{if(!r.value||typeof r.value!="string")return;const s=[];let l=0;e.lastIndex=0;let i=e.exec(r.value);for(;i;){const c=i.index;l!==c&&s.push({type:"text",value:r.value.slice(l,c)}),s.push({type:"break",data:{isInline:!0}}),l=c+i[0].length,i=e.exec(r.value)}if(s.length>0&&n&&typeof a=="number")return l<r.value.length&&s.push({type:"text",value:r.value.slice(l)}),n.children.splice(a,1,...s),a+s.length})});o(Je.plugin,{displayName:"Remark<remarkLineBreak>",group:"Remark"});o(Je.options,{displayName:"RemarkConfig<remarkLineBreak>",group:"Remark"});const Qe=T("remarkInlineLink",()=>jt);o(Qe.plugin,{displayName:"Remark<remarkInlineLinkPlugin>",group:"Remark"});o(Qe.options,{displayName:"RemarkConfig<remarkInlineLinkPlugin>",group:"Remark"});const sr=t=>!!t.children,lr=t=>t.type==="html";function ir(t,e){return r(t,0,null)[0];function r(a,n,s){if(sr(a)){const l=[];for(let i=0,d=a.children.length;i<d;i++){const c=a.children[i];if(c){const p=r(c,i,a);if(p)for(let u=0,m=p.length;u<m;u++){const f=p[u];f&&l.push(f)}}}a.children=l}return e(a,n,s)}}const Xe=T("remarkHTMLTransformer",()=>()=>t=>{ir(t,(e,r,a)=>lr(e)?((a==null?void 0:a.type)==="root"&&(e.children=[{...e}],delete e.value,e.type="paragraph"),[e]):[e])});o(Xe.plugin,{displayName:"Remark<remarkHtmlTransformer>",group:"Remark"});o(Xe.options,{displayName:"RemarkConfig<remarkHtmlTransformer>",group:"Remark"});const Ye=T("remarkMarker",()=>()=>(t,e)=>{const r=a=>e.value.charAt(a.position.start.offset);K(t,a=>["strong","emphasis"].includes(a.type),a=>{a.marker=r(a)})});o(Ye.plugin,{displayName:"Remark<remarkMarker>",group:"Remark"});o(Ye.options,{displayName:"RemarkConfig<remarkMarker>",group:"Remark"});const Rt=q(()=>{let t=!1;const e=new W("MILKDOWN_INLINE_NODES_CURSOR"),r=new F({key:e,state:{init(){return!1},apply(a){if(!a.selection.empty)return!1;const n=a.selection.$from,s=n.nodeBefore,l=n.nodeAfter;return!!(s&&l&&s.isInline&&!s.isText&&l.isInline&&!l.isText)}},props:{handleDOMEvents:{compositionend:(a,n)=>t?(t=!1,requestAnimationFrame(()=>{if(r.getState(a.state)){const l=a.state.selection.from;n.preventDefault(),a.dispatch(a.state.tr.insertText(n.data||"",l))}}),!0):!1,compositionstart:a=>(r.getState(a.state)&&(t=!0),!1),beforeinput:(a,n)=>{if(r.getState(a.state)&&n instanceof InputEvent&&n.data&&!t){const l=a.state.selection.from;return n.preventDefault(),a.dispatch(a.state.tr.insertText(n.data||"",l)),!0}return!1}},decorations(a){if(r.getState(a)){const l=a.selection.$from.pos,i=document.createElement("span"),d=rt.widget(l,i,{side:-1}),c=document.createElement("span"),p=rt.widget(l,c);return setTimeout(()=>{i.contentEditable="true",c.contentEditable="true"}),at.create(a.doc,[d,p])}return at.empty}}});return r});o(Rt,{displayName:"Prose<inlineNodesCursorPlugin>",group:"Prose"});const Bt=q(t=>new F({key:new W("MILKDOWN_HARDBREAK_MARKS"),appendTransaction:(e,r,a)=>{if(!e.length)return;const[n]=e;if(!n)return;const[s]=n.steps;if(n.getMeta("hardbreak")){if(!(s instanceof $t))return;const{from:d}=s;return a.tr.setNodeMarkup(d,S.type(t),void 0,[])}if(s instanceof qt){let d=a.tr;const{from:c,to:p}=s;return a.doc.nodesBetween(c,p,(u,m)=>{u.type===S.type(t)&&(d=d.setNodeMarkup(m,S.type(t),void 0,[]))}),d}}}));o(Bt,{displayName:"Prose<hardbreakClearMarkPlugin>",group:"Prose"});const Ze=st(["table","code_block"],"hardbreakFilterNodes");o(Ze,{displayName:"Ctx<hardbreakFilterNodes>",group:"Prose"});const Ht=q(t=>{const e=t.get(Ze.key);return new F({key:new W("MILKDOWN_HARDBREAK_FILTER"),filterTransaction:(r,a)=>{const n=r.getMeta("hardbreak"),[s]=r.steps;if(n&&s){const{from:l}=s,i=a.doc.resolve(l);let d=i.depth,c=!0;for(;d>0;)e.includes(i.node(d).type.name)&&(c=!1),d--;return c}return!0}})});o(Ht,{displayName:"Prose<hardbreakFilterPlugin>",group:"Prose"});const Ot=q(t=>{const e=new W("MILKDOWN_HEADING_ID"),r=a=>{if(a.composing)return;const n=t.get(ee.key),s=a.state.tr.setMeta("addToHistory",!1);let l=!1;const i={};a.state.doc.descendants((d,c)=>{if(d.type===H.type(t)){if(d.textContent.trim().length===0)return;const p=d.attrs;let u=n(d);i[u]?(i[u]+=1,u+=`-#${i[u]}`):i[u]=1,p.id!==u&&(l=!0,s.setMeta(e,!0).setNodeMarkup(c,void 0,{...p,id:u}))}}),l&&a.dispatch(s)};return new F({key:e,view:a=>(r(a),{update:(n,s)=>{n.state.doc.eq(s.doc)||r(n)}})})});o(Ot,{displayName:"Prose<syncHeadingIdPlugin>",group:"Prose"});const Tt=q(t=>{const e=r=>{if(r.composing||!r.editable)return;const a=E.type(t),n=P.type(t),s=L.type(t),l=r.state,i=(p,u)=>{let m=!1;const f=`${u+1}.`;return p.label!==f&&(p.label=f,m=!0),m};let d=l.tr,c=!1;l.doc.descendants((p,u,m,f)=>{if(p.type===n){const y=p.maybeChild(0);(y==null?void 0:y.type)===s&&y.attrs.listType==="ordered"&&(c=!0,d.setNodeMarkup(u,a,{spread:"true"}),p.descendants((k,w,A,te)=>{if(k.type===s){const et={...k.attrs};i(et,te)&&(d=d.setNodeMarkup(w,void 0,et))}return!1}))}else if(p.type===s&&(m==null?void 0:m.type)===a){const y={...p.attrs};let k=!1;y.listType!=="ordered"&&(y.listType="ordered",k=!0),(m==null?void 0:m.maybeChild(0))&&(k=i(y,f)),k&&(d=d.setNodeMarkup(u,void 0,y),c=!0)}}),c&&r.dispatch(d.setMeta("addToHistory",!1))};return new F({key:new W("MILKDOWN_KEEP_LIST_ORDER"),view:r=>(e(r),{update:a=>{e(a)}})})});o(Tt,{displayName:"Prose<syncListOrderPlugin>",group:"Prose"});const dr=[Bt,Ze,Ht,Rt,Ge,Qe,Je,Xe,Ye,Z,Ot,Tt].flat(),gr=[tr,rr,ar,nr,or,dr].flat();export{Le as blockquoteAttr,xe as blockquoteKeymap,z as blockquoteSchema,Te as bulletListAttr,De as bulletListKeymap,P as bulletListSchema,we as codeBlockAttr,Se as codeBlockKeymap,U as codeBlockSchema,nr as commands,gr as commonmark,Ae as createCodeBlockCommand,bt as createCodeBlockInputRule,Nt as docSchema,be as downgradeHeadingCommand,ie as emphasisAttr,ce as emphasisKeymap,D as emphasisSchema,mt as emphasisStarInputRule,gt as emphasisUnderscoreInputRule,G as hardbreakAttr,Bt as hardbreakClearMarkPlugin,Ze as hardbreakFilterNodes,Ht as hardbreakFilterPlugin,He as hardbreakKeymap,S as hardbreakSchema,Ce as headingAttr,ee as headingIdGenerator,Me as headingKeymap,H as headingSchema,Oe as hrAttr,j as hrSchema,Ue as htmlAttr,je as htmlSchema,Re as imageAttr,_ as imageSchema,ge as inlineCodeAttr,ht as inlineCodeInputRule,he as inlineCodeKeymap,x as inlineCodeSchema,Rt as inlineNodesCursorPlugin,rr as inputRules,Be as insertHardbreakCommand,xt as insertHrCommand,vt as insertHrInputRule,Mt as insertImageCommand,Zt as insertImageInputRule,or as keymap,Ve as liftFirstListItemCommand,We as liftListItemCommand,fe as linkAttr,O as linkSchema,$e as listItemAttr,ze as listItemKeymap,L as listItemSchema,ar as markInputRules,_e as orderedListAttr,Ee as orderedListKeymap,E as orderedListSchema,ke as paragraphAttr,Ie as paragraphKeymap,B as paragraphSchema,dr as plugins,Ge as remarkAddOrderInListPlugin,Xe as remarkHtmlTransformer,Qe as remarkInlineLinkPlugin,Je as remarkLineBreak,Ye as remarkMarker,Z as remarkPreserveEmptyLinePlugin,tr as schema,qe as sinkListItemCommand,Fe as splitListItemCommand,pe as strongAttr,yt as strongInputRule,me as strongKeymap,V as strongSchema,Ot as syncHeadingIdPlugin,Tt as syncListOrderPlugin,St as textSchema,de as toggleEmphasisCommand,ye as toggleInlineCodeCommand,ft as toggleLinkCommand,ue as toggleStrongCommand,Ne as turnIntoTextCommand,Yt as updateCodeBlockLanguageCommand,Lt as updateImageCommand,kt as updateLinkCommand,ve as wrapInBlockquoteCommand,Ct as wrapInBlockquoteInputRule,Ke as wrapInBulletListCommand,wt as wrapInBulletListInputRule,v as wrapInHeadingCommand,It as wrapInHeadingInputRule,Pe as wrapInOrderedListCommand,At as wrapInOrderedListInputRule};
|
package/dist/index5.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{z as e}from"./index2.js";import"./index.js";function i(r){var n,o,t="";if(typeof r=="string"||typeof r=="number")t+=r;else if(typeof r=="object")if(Array.isArray(r)){var s=r.length;for(n=0;n<s;n++)r[n]&&(o=i(r[n]))&&(t&&(t+=" "),t+=o)}else for(o in r)r[o]&&(t&&(t+=" "),t+=o);return t}function a(){for(var r,n,o=0,t="",s=arguments.length;o<s;o++)(r=arguments[o])&&(n=i(r))&&(t&&(t+=" "),t+=n);return t}function l(r){r.update(e,n=>{const o=n.attributes;return{...n,attributes:t=>{const s=typeof o=="function"?o(t):o;return{...s,class:a("prose dark:prose-invert",(s==null?void 0:s.class)||"","milkdown-theme-nord")}}}})}export{l as nord};
|
package/dist/index6.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{c as I,B as w,C as g,G as M,H as k,J as O,K as D,h as d,j as f,L as H,s as L,M as b,b as j,O as N,p,Q as U,U as E,V as K,W as m,X as C,I as B,Y as R,Z as P,_ as T,$ as V,a0 as $,a1 as v,a2 as A,a3 as F,a4 as G}from"./index2.js";import"./index.js";let J=t=>crypto.getRandomValues(new Uint8Array(t)),Q=(t,s,r)=>{let n=(2<<Math.log2(t.length-1))-1,e=-~(1.6*n*s/t.length);return(a=s)=>{let o="";for(;;){let i=r(e),u=e|0;for(;u--;)if(o+=t[i[u]&n]||"",o.length>=a)return o}}},W=(t,s=21)=>Q(t,s|0,J);const X=W("abcedfghicklmn",10);function y(t,s,r){const n=D(r||X());let e=!1;const a=o=>(o.record(n),o.update(s,i=>i.concat(n)),async()=>{const u=await t(o,a,()=>{o.done(n),e=!0});return e||o.done(n),()=>{if(o.update(s,c=>c.filter(l=>l!==n)),o.clearTimer(n),u){const c=u();c&&"then"in c&&c.catch(console.error)}}});return a.timer=n,a}function ee(t,s){const r=E(t),n=e=>async()=>{n.key=r,await e.wait(K);const a=s(e);return e.get(d).create(r,a),n.run=o=>e.get(d).call(t,o),()=>{e.get(d).remove(r)}};return n}function te(t,s,r){const n=E(t);return y(async(e,a)=>{await e.wait(K);const o=await s(e);return e.get(d).create(n,o),a.run=i=>e.get(d).call(t,i),a.key=n,()=>{e.get(d).remove(n)}},F,r)}function ne(t){const s=r=>async()=>{await r.wait(m);const n=t(r);return r.update(C,e=>[...e,n]),s.inputRule=n,()=>{r.update(C,e=>e.filter(a=>a!==n))}};return s}function re(t,s){return y(async(r,n)=>{await r.wait(m);const e=await t(r);return r.update(C,a=>[...a,e]),n.inputRule=e,()=>{r.update(C,a=>a.filter(o=>o!==e))}},T,s)}function Y(t,s){const r=n=>async()=>{const e=s(n);return n.update(k,a=>[...a.filter(o=>o[0]!==t),[t,e]]),r.id=t,r.schema=e,()=>{n.update(k,a=>a.filter(([o])=>o!==t))}};return r.type=n=>{const e=n.get(g).marks[t];if(!e)throw O(t);return e},r}function ae(t,s,r){const n=y(async(e,a,o)=>{const i=await s(e);return e.update(k,u=>[...u.filter(c=>c[0]!==t),[t,i]]),a.id=t,a.schema=i,o(),()=>{e.update(k,u=>u.filter(([c])=>c!==t))}},P,r);return n.type=e=>{const a=e.get(g).marks[t];if(!a)throw O(t);return a},n}function Z(t,s){const r=n=>async()=>{const e=s(n);return n.update(w,a=>[...a.filter(o=>o[0]!==t),[t,e]]),r.id=t,r.schema=e,()=>{n.update(w,a=>a.filter(([o])=>o!==t))}};return r.type=n=>{const e=n.get(g).nodes[t];if(!e)throw M(t);return e},r}function se(t,s,r){const n=y(async(e,a,o)=>{const i=await s(e);return e.update(w,u=>[...u.filter(c=>c[0]!==t),[t,i]]),a.id=t,a.schema=i,o(),()=>{e.update(w,u=>u.filter(([c])=>c!==t))}},P,r);return n.type=e=>{const a=e.get(g).nodes[t];if(!a)throw M(t);return a},n}function oe(t){let s;const r=n=>async()=>(await n.wait(m),s=t(n),n.update(p,e=>[...e,s]),()=>{n.update(p,e=>e.filter(a=>a!==s))});return r.plugin=()=>s,r.key=()=>s.spec.key,r}function ie(t,s){let r;const n=y(async e=>(await e.wait(m),r=await t(e),e.update(p,a=>[...a,r]),()=>{e.update(p,a=>a.filter(o=>o!==r))}),T,s);return n.plugin=()=>r,n.key=()=>r.spec.key,n}function _(t){const s=r=>async()=>{await r.wait(m);const n=t(r),e=V(n);return r.update(p,a=>[...a,e]),s.keymap=n,()=>{r.update(p,a=>a.filter(o=>o!==e))}};return s}function ce(t,s){return y(async(r,n)=>{await r.wait(m);const e=await t(r),a=V(e);return r.update(p,o=>[...o,a]),n.keymap=e,()=>{r.update(p,o=>o.filter(i=>i!==a))}},T,s)}function ue(t,s){const r=n=>async()=>{await n.wait(m);const e=s(n);return t.type(n)instanceof $?n.update(v,a=>[...a,[t.id,e]]):n.update(A,a=>[...a,[t.id,e]]),r.view=e,r.type=t,()=>{t.type(n)instanceof $?n.update(v,a=>a.filter(o=>o[0]!==t.id)):n.update(A,a=>a.filter(o=>o[0]!==t.id))}};return r}function le(t,s,r){return y(async(n,e)=>{await n.wait(m);const a=await s(n);return t.type(n)instanceof $?n.update(v,o=>[...o,[t.id,a]]):n.update(A,o=>[...o,[t.id,a]]),e.view=a,e.type=t,()=>{t.type(n)instanceof $?n.update(v,o=>o.filter(i=>i[0]!==t.id)):n.update(A,o=>o.filter(i=>i[0]!==t.id))}},G,r)}function h(t,s){const r=I(t,s),n=e=>(e.inject(r),()=>()=>{e.remove(r)});return n.key=r,n}function pe(t,s){const r=h(s,t),n=Z(t,a=>a.get(r.key)(a)),e=[r,n];return e.id=n.id,e.node=n,e.type=a=>n.type(a),e.schema=n.schema,e.ctx=r,e.key=r.key,e.extendSchema=a=>o=>()=>{const i=o.get(r.key),c=a(i)(o);o.update(w,l=>[...l.filter(S=>S[0]!==t),[t,c]]),e.schema=c},e}function me(t,s){const r=h(s,t),n=Y(t,a=>a.get(r.key)(a)),e=[r,n];return e.id=n.id,e.mark=n,e.type=n.type,e.schema=n.schema,e.ctx=r,e.key=r.key,e.extendSchema=a=>o=>()=>{const i=o.get(r.key),c=a(i)(o);o.update(k,l=>[...l.filter(S=>S[0]!==t),[t,c]]),e.schema=c},e}function de(t,s){const r=Object.fromEntries(Object.entries(s).map(([o,{shortcuts:i}])=>[o,i])),n=h(r,`${t}Keymap`),e=_(o=>{const i=o.get(n.key),u=Object.entries(s).flatMap(([c,{command:l}])=>[i[c]].flat().map(z=>[z,l(o)]));return Object.fromEntries(u)}),a=[n,e];return a.ctx=n,a.shortcuts=e,a.key=n.key,a.keymap=e.keymap,a}const fe=(t,s=()=>({}))=>h(s,`${t}Attr`),ye=(t,s=()=>({}))=>h(s,`${t}Attr`);function ge(t,s,r){const n=h(r??{},t),e=o=>async()=>{await o.wait(B);const u={plugin:s(o),options:o.get(n.key)};return o.update(R,c=>[...c,u]),()=>{o.update(R,c=>c.filter(l=>l!==u))}},a=[n,e];return a.id=t,a.plugin=e,a.options=n,a}function he(t,s){return r=>r.get(d).call(t,s)}function we(){return t=>{const s=t.get(f),{tr:r}=s.state,n=Object.assign(Object.create(r),r).setTime(Date.now());return s.dispatch(n)}}function ke(){return t=>{const s=document.createElement("div"),r=t.get(g),n=t.get(f),e=H.fromSchema(r).serializeFragment(n.state.doc.content);return s.appendChild(e),s.innerHTML}}function Se(){return t=>{const s=t.get(f);return t.get(L)(s.state.doc)}}function Ce(t){return s=>{const r=s.get(f),e=s.get(b)(t);if(!e)return;const a=r.state.selection.content();return r.dispatch(r.state.tr.replaceSelection(new j(e.content,a.openStart,a.openEnd)).scrollIntoView())}}function $e(){return t=>{const s=t.get(f),r=[];return s.state.doc.descendants(e=>{e.type.name==="heading"&&e.attrs.level&&r.push({text:e.textContent,level:e.attrs.level,id:e.attrs.id})}),r}}function ve(t,s=!1){return r=>{const n=r.get(f),a=r.get(b)(t);if(!a)return;if(!s){const{state:l}=n;return n.dispatch(l.tr.replace(0,l.doc.content.size,new j(a.content,0,0)))}const o=r.get(g),i=r.get(N),u=r.get(p),c=U.create({schema:o,doc:a,plugins:u,...i});n.updateState(c)}}function Ae(t,s){return r=>{const n=r.get(f),{tr:e}=n.state,a=e.doc.nodeAt(t);if(!a)return;const o=s(a.attrs);return n.dispatch(e.setNodeMarkup(t,void 0,o))}}const Te=(...t)=>{const s=t.length;let r=s;for(;r--;)if(typeof t[r]!="function")throw new TypeError("Expected a function");return(...n)=>{let e=0,a=s?t[e](...n):n[0];for(;++e<s;)a=t[e](a);return a}};export{ee as $command,te as $commandAsync,h as $ctx,ne as $inputRule,re as $inputRuleAsync,Y as $mark,ae as $markAsync,ye as $markAttr,me as $markSchema,Z as $node,se as $nodeAsync,fe as $nodeAttr,pe as $nodeSchema,oe as $prose,ie as $proseAsync,ge as $remark,_ as $shortcut,ce as $shortcutAsync,de as $useKeymap,ue as $view,le as $viewAsync,y as addTimer,he as callCommand,we as forceUpdate,ke as getHTML,Se as getMarkdown,Ce as insert,X as nanoid,$e as outline,Te as pipe,ve as replaceAll,Ae as setAttr};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "snow-cms",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "A configurable CMS built with Svelte.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Sammy-T",
|
|
@@ -16,30 +16,30 @@
|
|
|
16
16
|
"dist/**.css"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@picocss/pico": "^2.
|
|
19
|
+
"@picocss/pico": "^2.1.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@milkdown/core": "^7.
|
|
23
|
-
"@milkdown/ctx": "^7.
|
|
24
|
-
"@milkdown/plugin-listener": "^7.
|
|
25
|
-
"@milkdown/preset-commonmark": "^7.
|
|
26
|
-
"@milkdown/prose": "^7.
|
|
27
|
-
"@milkdown/theme-nord": "^7.
|
|
28
|
-
"@milkdown/transformer": "^7.
|
|
29
|
-
"@milkdown/utils": "^7.
|
|
30
|
-
"@octokit/core": "^6.1.
|
|
22
|
+
"@milkdown/core": "^7.9.0",
|
|
23
|
+
"@milkdown/ctx": "^7.9.0",
|
|
24
|
+
"@milkdown/plugin-listener": "^7.9.0",
|
|
25
|
+
"@milkdown/preset-commonmark": "^7.9.0",
|
|
26
|
+
"@milkdown/prose": "^7.9.0",
|
|
27
|
+
"@milkdown/theme-nord": "^7.9.0",
|
|
28
|
+
"@milkdown/transformer": "^7.9.0",
|
|
29
|
+
"@milkdown/utils": "^7.9.0",
|
|
30
|
+
"@octokit/core": "^6.1.5",
|
|
31
31
|
"@sveltejs/vite-plugin-svelte": "^5.0.3",
|
|
32
|
-
"browser-fs-access": "^0.
|
|
32
|
+
"browser-fs-access": "^0.37.0",
|
|
33
33
|
"dayjs": "^1.11.13",
|
|
34
|
-
"dotenv": "^16.
|
|
34
|
+
"dotenv": "^16.5.0",
|
|
35
35
|
"events": "^3.3.0",
|
|
36
36
|
"js-yaml": "^4.1.0",
|
|
37
37
|
"npm-run-all": "^4.1.5",
|
|
38
38
|
"pouchdb-adapter-idb": "^9.0.0",
|
|
39
39
|
"pouchdb-core": "^9.0.0",
|
|
40
40
|
"pouchdb-find": "^9.0.0",
|
|
41
|
-
"svelte": "^5.
|
|
42
|
-
"vite": "^6.
|
|
41
|
+
"svelte": "^5.28.2",
|
|
42
|
+
"vite": "^6.3.4"
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"dev": "run-p build:watch:cms serve:site",
|
package/dist/index.es5.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{J,X as h,q as m,u as O,Z as $,x as b,y as K,O as l,L as f,z as L,r as N,B as j,S as E,C as V,N as d,E as X,G as R,Y as T,K as p,U as k,M as q,V as M,W as C,_ as S,$ as U,a0 as A,a1 as v,a2 as x,a3 as D,a4 as H}from"./index.es.js";import"./index.js";let I=a=>crypto.getRandomValues(new Uint8Array(a)),Q=(a,s,n)=>{let t=(2<<Math.log2(a.length-1))-1,e=-~(1.6*t*s/a.length);return(r=s)=>{let c="";for(;;){let i=n(e),o=e|0;for(;o--;)if(c+=a[i[o]&t]||"",c.length>=r)return c}}},W=(a,s=21)=>Q(a,s|0,I);const B=W("abcedfghicklmn",10);function y(a,s,n){const t=K(n||B());let e=!1;const r=c=>(c.record(t),c.update(s,i=>i.concat(t)),async()=>{const i=await a(c,r,()=>{c.done(t),e=!0});return e||c.done(t),()=>{c.update(s,o=>o.filter(u=>u!==t)),c.clearTimer(t),i==null||i()}});return r.timer=t,r}function P(a,s){const n=R(a),t=e=>async()=>{t.key=n,await e.wait(T);const r=s(e);return e.get(l).create(n,r),t.run=c=>e.get(l).call(a,c),()=>{e.get(l).remove(n)}};return t}function tt(a,s,n){const t=R(a);return y(async(e,r)=>{await e.wait(T);const c=await s(e);return e.get(l).create(t,c),r.run=i=>e.get(l).call(a,i),r.key=t,()=>{e.get(l).remove(t)}},D,n)}function et(a){const s=n=>async()=>{await n.wait(p);const t=a(n);return n.update(k,e=>[...e,t]),s.inputRule=t,()=>{n.update(k,e=>e.filter(r=>r!==t))}};return s}function at(a,s){return y(async(n,t)=>{await n.wait(p);const e=await a(n);return n.update(k,r=>[...r,e]),t.inputRule=e,()=>{n.update(k,r=>r.filter(c=>c!==e))}},S,s)}function F(a,s){const n=t=>async()=>{const e=s(t);return t.update($,r=>[...r.filter(c=>c[0]!==a),[a,e]]),n.id=a,n.schema=e,()=>{t.update($,r=>r.filter(([c])=>c!==a))}};return n.type=t=>{const e=t.get(m).marks[a];if(!e)throw b(a);return e},n}function nt(a,s,n){const t=y(async(e,r,c)=>{const i=await s(e);return e.update($,o=>[...o.filter(u=>u[0]!==a),[a,i]]),r.id=a,r.schema=i,c(),()=>{e.update($,o=>o.filter(([u])=>u!==a))}},C,n);return t.type=e=>{const r=e.get(m).marks[a];if(!r)throw b(a);return r},t}function G(a,s){const n=t=>async()=>{const e=s(t);return t.update(h,r=>[...r.filter(c=>c[0]!==a),[a,e]]),n.id=a,n.schema=e,()=>{t.update(h,r=>r.filter(([c])=>c!==a))}};return n.type=t=>{const e=t.get(m).nodes[a];if(!e)throw O(a);return e},n}function rt(a,s,n){const t=y(async(e,r,c)=>{const i=await s(e);return e.update(h,o=>[...o.filter(u=>u[0]!==a),[a,i]]),r.id=a,r.schema=i,c(),()=>{e.update(h,o=>o.filter(([u])=>u!==a))}},C,n);return t.type=e=>{const r=e.get(m).nodes[a];if(!r)throw O(a);return r},t}function st(a){let s;const n=t=>async()=>(await t.wait(p),s=a(t),t.update(d,e=>[...e,s]),()=>{t.update(d,e=>e.filter(r=>r!==s))});return n.plugin=()=>s,n.key=()=>s.spec.key,n}function ct(a,s){let n;const t=y(async e=>(await e.wait(p),n=await a(e),e.update(d,r=>[...r,n]),()=>{e.update(d,r=>r.filter(c=>c!==n))}),S,s);return t.plugin=()=>n,t.key=()=>n.spec.key,t}function Y(a){const s=n=>async()=>{await n.wait(p);const t=a(n),e=U(t);return n.update(d,r=>[...r,e]),s.keymap=t,()=>{n.update(d,r=>r.filter(c=>c!==e))}};return s}function it(a,s){return y(async(n,t)=>{await n.wait(p);const e=await a(n),r=U(e);return n.update(d,c=>[...c,r]),t.keymap=e,()=>{n.update(d,c=>c.filter(i=>i!==r))}},S,s)}function ot(a,s){const n=t=>async()=>{await t.wait(p);const e=s(t);return a.type(t)instanceof A?t.update(v,r=>[...r,[a.id,e]]):t.update(x,r=>[...r,[a.id,e]]),n.view=e,n.type=a,()=>{a.type(t)instanceof A?t.update(v,r=>r.filter(c=>c[0]!==a.id)):t.update(x,r=>r.filter(c=>c[0]!==a.id))}};return n}function ut(a,s,n){return y(async(t,e)=>{await t.wait(p);const r=await s(t);return a.type(t)instanceof A?t.update(v,c=>[...c,[a.id,r]]):t.update(x,c=>[...c,[a.id,r]]),e.view=r,e.type=a,()=>{a.type(t)instanceof A?t.update(v,c=>c.filter(i=>i[0]!==a.id)):t.update(x,c=>c.filter(i=>i[0]!==a.id))}},H,n)}function g(a,s){const n=J(a,s),t=e=>(e.inject(n),()=>()=>{e.remove(n)});return t.key=n,t}function dt(a,s){const n=g(s,a),t=G(a,r=>r.get(n.key)(r)),e=[n,t];return e.id=t.id,e.node=t,e.type=r=>t.type(r),e.schema=t.schema,e.ctx=n,e.key=n.key,e.extendSchema=r=>c=>()=>{const i=c.get(n.key),o=r(i)(c);c.update(h,u=>[...u.filter(w=>w[0]!==a),[a,o]]),e.schema=o},e}function pt(a,s){const n=g(s,a),t=F(a,r=>r.get(n.key)(r)),e=[n,t];return e.id=t.id,e.mark=t,e.type=t.type,e.schema=t.schema,e.ctx=n,e.key=n.key,e.extendSchema=r=>c=>()=>{const i=c.get(n.key),o=r(i)(c);c.update($,u=>[...u.filter(w=>w[0]!==a),[a,o]]),e.schema=o},e}function lt(a,s){const n=Object.fromEntries(Object.entries(s).map(([c,{shortcuts:i}])=>[c,i])),t=g(n,`${a}Keymap`),e=Y(c=>{const i=c.get(t.key),o=Object.entries(s).flatMap(([u,{command:w}])=>[i[u]].flat().map(z=>[z,w(c)]));return Object.fromEntries(o)}),r=[t,e];return r.ctx=t,r.shortcuts=e,r.key=t.key,r.keymap=e.keymap,r}const ft=(a,s=()=>({}))=>g(s,`${a}Attr`),yt=(a,s=()=>({}))=>g(s,`${a}Attr`);function mt(a,s,n){const t=g(n??{},a),e=c=>async()=>{await c.wait(q);const i={plugin:s(c),options:c.get(t.key)};return c.update(M,o=>[...o,i]),()=>{c.update(M,o=>o.filter(u=>u!==i))}},r=[t,e];return r.id=a,r.plugin=e,r.options=t,r}function gt(a,s){return n=>n.get(l).call(a,s)}function wt(){return a=>{const s=a.get(f),{tr:n}=s.state,t=Object.assign(Object.create(n),n).setTime(Date.now());return s.dispatch(t)}}function ht(){return a=>{const s=document.createElement("div"),n=a.get(m),t=a.get(f),e=L.fromSchema(n).serializeFragment(t.state.doc.content);return s.appendChild(e),s.innerHTML}}function $t(){return a=>{const s=a.get(f);return a.get(N)(s.state.doc)}}function kt(a){return s=>{const n=s.get(f),t=s.get(j)(a);if(!t)return;const e=n.state.selection.content();return n.dispatch(n.state.tr.replaceSelection(new E(t.content,e.openStart,e.openEnd)).scrollIntoView())}}function At(){return a=>{const s=a.get(f),n=[];return s.state.doc.descendants(t=>{t.type.name==="heading"&&t.attrs.level&&n.push({text:t.textContent,level:t.attrs.level,id:t.attrs.id})}),n}}function vt(a,s=!1){return n=>{const t=n.get(f),e=n.get(j)(a);if(!e)return;if(!s){const{state:u}=t;return t.dispatch(u.tr.replace(0,u.doc.content.size,new E(e.content,0,0)))}const r=n.get(m),c=n.get(V),i=n.get(d),o=X.create({schema:r,doc:e,plugins:i,...c});t.updateState(o)}}function xt(a,s){return n=>{const t=n.get(f),{tr:e}=t.state,r=e.doc.nodeAt(a);if(!r)return;const c=s(r.attrs);return t.dispatch(e.setNodeMarkup(a,void 0,c))}}const St=(...a)=>{const s=a.length;let n=s;for(;n--;)if(typeof a[n]!="function")throw new TypeError("Expected a function");return(...t)=>{let e=0,r=s?a[e](...t):t[0];for(;++e<s;)r=a[e](r);return r}};export{P as $command,tt as $commandAsync,g as $ctx,et as $inputRule,at as $inputRuleAsync,F as $mark,nt as $markAsync,yt as $markAttr,pt as $markSchema,G as $node,rt as $nodeAsync,ft as $nodeAttr,dt as $nodeSchema,st as $prose,ct as $proseAsync,mt as $remark,Y as $shortcut,it as $shortcutAsync,lt as $useKeymap,ot as $view,ut as $viewAsync,y as addTimer,gt as callCommand,wt as forceUpdate,ht as getHTML,$t as getMarkdown,kt as insert,B as nanoid,At as outline,St as pipe,vt as replaceAll,xt as setAttr};
|
package/dist/index.es6.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{i as P,t as b,c as Z,a as H,b as $,r as fe,f as ce}from"./index.es8.js";import{c as _,B as ee,p as G,g as z,M as C,i as w,n as W,s as te,a as d,E as x,N as I,b as oe,I as N,r as he,d as A,R as J,e as le,f as de,U as ie,Q as _e,h as ve,j as O,u as K,v as me,k as ge,l as ye,o as pe,m as we,q as De}from"./index-browser.es2.js";import{m as Ee,f as ke}from"./index.es9.js";import"./index.js";function Ce(n){return te(`"use strict";
|
|
2
|
-
return `+n+";",{})}function xe(n){var e=["return function(doc) {",' "use strict";'," var emitted = false;"," var emit = function (a, b) {"," emitted = true;"," };"," var view = "+n+";"," view(doc);"," if (emitted) {"," return true;"," }","};"].join(`
|
|
3
|
-
`);return te(e,{})}function Ae(n,e){if(n.selector&&n.filter&&n.filter!=="_selector"){var t=typeof n.filter=="string"?n.filter:"function";return e(new Error('selector invalid for filter "'+t+'"'))}e()}function Le(n){n.view&&!n.filter&&(n.filter="_view"),n.selector&&!n.filter&&(n.filter="_selector"),n.filter&&typeof n.filter=="string"&&(n.filter==="_view"?n.view=W(n.view):n.filter=W(n.filter))}function Oe(n,e){return e.filter&&typeof e.filter=="string"&&!e.doc_ids&&!w(n.db)}function Re(n,e){var t=e.complete;if(e.filter==="_view"){if(!e.view||typeof e.view!="string"){var i=_(ee,"`view` filter parameter not found or invalid.");return t(i)}var r=G(e.view);n.db.get("_design/"+r[0],function(s,f){if(n.isCancelled)return t(null,{status:"cancelled"});if(s)return t(z(s));var u=f&&f.views&&f.views[r[1]]&&f.views[r[1]].map;if(!u)return t(_(C,f.views?"missing json key: "+r[1]:"missing json key: views"));e.filter=xe(u),n.doChanges(e)})}else if(e.selector)e.filter=function(s){return Ee(s,e.selector)},n.doChanges(e);else{var a=G(e.filter);n.db.get("_design/"+a[0],function(s,f){if(n.isCancelled)return t(null,{status:"cancelled"});if(s)return t(z(s));var u=f&&f.filters&&f.filters[a[1]];if(!u)return t(_(C,f&&f.filters?"missing json key: "+a[1]:"missing json key: filters"));e.filter=Ce(u),n.doChanges(e)})}}function Te(n){n._changesFilterPlugin={validate:Ae,normalize:Le,shouldFilter:Oe,filter:Re}}function Se(n,e,t,i){try{n.emit("change",e,t,i)}catch(r){A("error",'Error in .on("change", function):',r)}}function Fe(n,e,t){var i=[{rev:n._rev}];t.style==="all_docs"&&(i=Z(e.rev_tree).map(function(a){return{rev:a.rev}}));var r={id:e.id,changes:i,doc:n};return $(e,n._rev)&&(r.deleted=!0),t.conflicts&&(r.doc._conflicts=H(e),r.doc._conflicts.length||delete r.doc._conflicts),r}class Pe extends x{constructor(e,t,i){super(),this.db=e,t=t?O(t):{};var r=t.complete=pe((f,u)=>{f?we(this,"error")>0&&this.emit("error",f):this.emit("complete",u),this.removeAllListeners(),e.removeListener("destroyed",a)});i&&(this.on("complete",function(f){i(null,f)}),this.on("error",i));const a=()=>{this.cancel()};e.once("destroyed",a),t.onChange=(f,u,o)=>{this.isCancelled||Se(this,f,u,o)};var s=new Promise(function(f,u){t.complete=function(o,c){o?u(o):f(c)}});this.once("cancel",function(){e.removeListener("destroyed",a),t.complete(null,{status:"cancelled"})}),this.then=s.then.bind(s),this.catch=s.catch.bind(s),this.then(function(f){r(null,f)},r),e.taskqueue.isReady?this.validateChanges(t):e.taskqueue.addTask(f=>{f?t.complete(f):this.isCancelled?this.emit("cancel"):this.validateChanges(t)})}cancel(){this.isCancelled=!0,this.db.taskqueue.isReady&&this.emit("cancel")}validateChanges(e){var t=e.complete;h._changesFilterPlugin?h._changesFilterPlugin.validate(e,i=>{if(i)return t(i);this.doChanges(e)}):this.doChanges(e)}doChanges(e){var t=e.complete;if(e=O(e),"live"in e&&!("continuous"in e)&&(e.continuous=e.live),e.processChange=Fe,e.since==="latest"&&(e.since="now"),e.since||(e.since=0),e.since==="now"){this.db.info().then(r=>{if(this.isCancelled){t(null,{status:"cancelled"});return}e.since=r.update_seq,this.doChanges(e)},t);return}if(h._changesFilterPlugin){if(h._changesFilterPlugin.normalize(e),h._changesFilterPlugin.shouldFilter(this,e))return h._changesFilterPlugin.filter(this,e)}else["doc_ids","filter","selector","view"].forEach(function(r){r in e&&A("warn",'The "'+r+'" option was passed in to changes/replicate, but pouchdb-changes-filter plugin is not installed, so it was ignored. Please install the plugin to enable filtering.')});"descending"in e||(e.descending=!1),e.limit=e.limit===0?1:e.limit,e.complete=t;var i=this.db._changes(e);if(i&&typeof i.cancel=="function"){const r=this.cancel;this.cancel=(...a)=>{i.cancel(),r.apply(this,a)}}}}function q(n,e){return function(t,i){t||i[0]&&i[0].error?(t=t||i[0],t.docId=e,n(t)):n(null,i.length?i[0]:i)}}function Ie(n){for(var e=0;e<n.length;e++){var t=n[e];if(t._deleted)delete t._attachments;else if(t._attachments)for(var i=Object.keys(t._attachments),r=0;r<i.length;r++){var a=i[r];t._attachments[a]=ye(t._attachments[a],["data","digest","content_type","length","revpos","stub"])}}}function Ne(n,e){if(n._id===e._id){const t=n._revisions?n._revisions.start:0,i=e._revisions?e._revisions.start:0;return t-i}return n._id<e._id?-1:1}function qe(n){var e={},t=[];return b(n,function(i,r,a,s){var f=r+"-"+a;return i&&(e[f]=0),s!==void 0&&t.push({from:s,to:f}),f}),t.reverse(),t.forEach(function(i){e[i.from]===void 0?e[i.from]=1+e[i.to]:e[i.from]=Math.min(e[i.from],1+e[i.to])}),e}function je(n){var e="limit"in n?n.keys.slice(n.skip,n.limit+n.skip):n.skip>0?n.keys.slice(n.skip):n.keys;n.keys=e,n.skip=0,delete n.limit,n.descending&&(e.reverse(),n.descending=!1)}function ne(n){var e=n._compactionQueue[0],t=e.opts,i=e.callback;n.get("_local/compaction").catch(function(){return!1}).then(function(r){r&&r.last_seq&&(t.last_seq=r.last_seq),n._compact(t,function(a,s){a?i(a):i(null,s),ge(function(){n._compactionQueue.shift(),n._compactionQueue.length&&ne(n)})})})}function Qe(n,e,t){return n.get("_local/purges").then(function(i){const r=i.purgeSeq+1;return i.purges.push({docId:e,rev:t,purgeSeq:r}),i.purges.length>self.purged_infos_limit&&i.purges.splice(0,i.purges.length-self.purged_infos_limit),i.purgeSeq=r,i}).catch(function(i){if(i.status!==404)throw i;return{_id:"_local/purges",purges:[{docId:e,rev:t,purgeSeq:0}],purgeSeq:0}}).then(function(i){return n.put(i)})}function be(n){return n.charAt(0)==="_"?n+" is not a valid attachment name, attachment names cannot start with '_'":!1}function j(n){return n===null||typeof n!="object"||Array.isArray(n)}const Be=/^\d+-[^-]*$/;function Q(n){return typeof n=="string"&&Be.test(n)}class re extends x{_setup(){this.post=d("post",function(e,t,i){if(typeof t=="function"&&(i=t,t={}),j(e))return i(_(I));this.bulkDocs({docs:[e]},t,q(i,e._id))}).bind(this),this.put=d("put",function(e,t,i){if(typeof t=="function"&&(i=t,t={}),j(e))return i(_(I));if(oe(e._id),"_rev"in e&&!Q(e._rev))return i(_(N));if(P(e._id)&&typeof this._putLocal=="function")return e._deleted?this._removeLocal(e,i):this._putLocal(e,i);const r=s=>{typeof this._put=="function"&&t.new_edits!==!1?this._put(e,t,s):this.bulkDocs({docs:[e]},t,q(s,e._id))};t.force&&e._rev?(a(),r(function(s){var f=s?null:{ok:!0,id:e._id,rev:e._rev};i(s,f)})):r(i);function a(){var s=e._rev.split("-"),f=s[1],u=parseInt(s[0],10),o=u+1,c=he();e._revisions={start:o,ids:[c,f]},e._rev=o+"-"+c,t.new_edits=!1}}).bind(this),this.putAttachment=d("putAttachment",function(e,t,i,r,a){var s=this;typeof a=="function"&&(a=r,r=i,i=null),typeof a>"u"&&(a=r,r=i,i=null),a||A("warn","Attachment",t,"on document",e,"is missing content_type");function f(u){var o="_rev"in u?parseInt(u._rev,10):0;return u._attachments=u._attachments||{},u._attachments[t]={content_type:a,data:r,revpos:++o},s.put(u)}return s.get(e).then(function(u){if(u._rev!==i)throw _(J);return f(u)},function(u){if(u.reason===C.message)return f({_id:e});throw u})}).bind(this),this.removeAttachment=d("removeAttachment",function(e,t,i,r){this.get(e,(a,s)=>{if(a){r(a);return}if(s._rev!==i){r(_(J));return}if(!s._attachments)return r();delete s._attachments[t],Object.keys(s._attachments).length===0&&delete s._attachments,this.put(s,r)})}).bind(this),this.remove=d("remove",function(e,t,i,r){var a;typeof t=="string"?(a={_id:e,_rev:t},typeof i=="function"&&(r=i,i={})):(a=e,typeof t=="function"?(r=t,i={}):(r=i,i=t)),i=i||{},i.was_delete=!0;var s={_id:a._id,_rev:a._rev||i.rev};if(s._deleted=!0,P(s._id)&&typeof this._removeLocal=="function")return this._removeLocal(a,r);this.bulkDocs({docs:[s]},i,q(r,s._id))}).bind(this),this.revsDiff=d("revsDiff",function(e,t,i){typeof t=="function"&&(i=t,t={});var r=Object.keys(e);if(!r.length)return i(null,{});var a=0,s=new Map;function f(o,c){s.has(o)||s.set(o,{missing:[]}),s.get(o).missing.push(c)}function u(o,c){var l=e[o].slice(0);b(c,function(v,y,g,L,R){var D=y+"-"+g,m=l.indexOf(D);m!==-1&&(l.splice(m,1),R.status!=="available"&&f(o,D))}),l.forEach(function(v){f(o,v)})}r.forEach(function(o){this._getRevisionTree(o,function(c,l){if(c&&c.status===404&&c.message==="missing")s.set(o,{missing:e[o]});else{if(c)return i(c);u(o,l)}if(++a===r.length){var v={};return s.forEach(function(y,g){v[g]=y}),i(null,v)}})},this)}).bind(this),this.bulkGet=d("bulkGet",function(e,t){le(this,e,t)}).bind(this),this.compactDocument=d("compactDocument",function(e,t,i){this._getRevisionTree(e,(r,a)=>{if(r)return i(r);var s=qe(a),f=[],u=[];Object.keys(s).forEach(function(o){s[o]>t&&f.push(o)}),b(a,function(o,c,l,v,y){var g=c+"-"+l;y.status==="available"&&f.indexOf(g)!==-1&&u.push(g)}),this._doCompaction(e,u,i)})}).bind(this),this.compact=d("compact",function(e,t){typeof e=="function"&&(t=e,e={}),e=e||{},this._compactionQueue=this._compactionQueue||[],this._compactionQueue.push({opts:e,callback:t}),this._compactionQueue.length===1&&ne(this)}).bind(this),this.get=d("get",function(e,t,i){if(typeof t=="function"&&(i=t,t={}),t=t||{},typeof e!="string")return i(_(de));if(P(e)&&typeof this._getLocal=="function")return this._getLocal(e,i);var r=[];const a=()=>{var u=[],o=r.length;if(!o)return i(null,u);r.forEach(c=>{this.get(e,{rev:c,revs:t.revs,latest:t.latest,attachments:t.attachments,binary:t.binary},function(l,v){if(l)u.push({missing:c});else{for(var y,g=0,L=u.length;g<L;g++)if(u[g].ok&&u[g].ok._rev===v._rev){y=!0;break}y||u.push({ok:v})}o--,o||i(null,u)})})};if(t.open_revs){if(t.open_revs==="all")this._getRevisionTree(e,function(u,o){if(u)return i(u);r=Z(o).map(function(c){return c.rev}),a()});else if(Array.isArray(t.open_revs)){r=t.open_revs;for(var s=0;s<r.length;s++){var f=r[s];if(!Q(f))return i(_(N))}a()}else return i(_(ie,"function_clause"));return}return this._get(e,t,(u,o)=>{if(u)return u.docId=e,i(u);var c=o.doc,l=o.metadata,v=o.ctx;if(t.conflicts){var y=H(l);y.length&&(c._conflicts=y)}if($(l,c._rev)&&(c._deleted=!0),t.revs||t.revs_info){for(var g=c._rev.split("-"),L=parseInt(g[0],10),R=g[1],D=fe(l.rev_tree),m=null,T=0;T<D.length;T++){var B=D[T];const p=B.ids.findIndex(k=>k.id===R);var ae=p===L-1;(ae||!m&&p!==-1)&&(m=B)}if(!m)return u=new Error("invalid rev tree"),u.docId=e,i(u);const E=c._rev.split("-")[1],F=m.ids.findIndex(p=>p.id===E)+1;var ue=m.ids.length-F;if(m.ids.splice(F,ue),m.ids.reverse(),t.revs&&(c._revisions={start:m.pos+m.ids.length-1,ids:m.ids.map(function(p){return p.id})}),t.revs_info){var M=m.pos+m.ids.length;c._revs_info=m.ids.map(function(p){return M--,{rev:M+"-"+p.id,status:p.opts.status}})}}if(t.attachments&&c._attachments){var S=c._attachments,U=Object.keys(S).length;if(U===0)return i(null,c);Object.keys(S).forEach(E=>{this._getAttachment(c._id,E,S[E],{binary:t.binary,metadata:l,ctx:v},function(F,p){var k=c._attachments[E];k.data=p,delete k.stub,delete k.length,--U||i(null,c)})})}else{if(c._attachments)for(var V in c._attachments)Object.prototype.hasOwnProperty.call(c._attachments,V)&&(c._attachments[V].stub=!0);i(null,c)}})}).bind(this),this.getAttachment=d("getAttachment",function(e,t,i,r){i instanceof Function&&(r=i,i={}),this._get(e,i,(a,s)=>{if(a)return r(a);if(s.doc._attachments&&s.doc._attachments[t])i.ctx=s.ctx,i.binary=!0,i.metadata=s.metadata,this._getAttachment(e,t,s.doc._attachments[t],i,r);else return r(_(C))})}).bind(this),this.allDocs=d("allDocs",function(e,t){if(typeof e=="function"&&(t=e,e={}),e.skip=typeof e.skip<"u"?e.skip:0,e.start_key&&(e.startkey=e.start_key),e.end_key&&(e.endkey=e.end_key),"keys"in e){if(!Array.isArray(e.keys))return t(new TypeError("options.keys must be an array"));var i=["startkey","endkey","key"].filter(function(r){return r in e})[0];if(i){t(_(_e,"Query parameter `"+i+"` is not compatible with multi-get"));return}if(!w(this)&&(je(e),e.keys.length===0))return this._allDocs({limit:0},t)}return this._allDocs(e,t)}).bind(this),this.close=d("close",function(e){return this._closed=!0,this.emit("closed"),this._close(e)}).bind(this),this.info=d("info",function(e){this._info((t,i)=>{if(t)return e(t);i.db_name=i.db_name||this.name,i.auto_compaction=!!(this.auto_compaction&&!w(this)),i.adapter=this.adapter,e(null,i)})}).bind(this),this.id=d("id",function(e){return this._id(e)}).bind(this),this.bulkDocs=d("bulkDocs",function(e,t,i){if(typeof t=="function"&&(i=t,t={}),t=t||{},Array.isArray(e)&&(e={docs:e}),!e||!e.docs||!Array.isArray(e.docs))return i(_(ve));for(var r=0;r<e.docs.length;++r){const u=e.docs[r];if(j(u))return i(_(I));if("_rev"in u&&!Q(u._rev))return i(_(N))}var a;if(e.docs.forEach(function(u){u._attachments&&Object.keys(u._attachments).forEach(function(o){a=a||be(o),u._attachments[o].content_type||A("warn","Attachment",o,"on document",u._id,"is missing content_type")})}),a)return i(_(ee,a));"new_edits"in t||("new_edits"in e?t.new_edits=e.new_edits:t.new_edits=!0);var s=this;!t.new_edits&&!w(s)&&e.docs.sort(Ne),Ie(e.docs);var f=e.docs.map(function(u){return u._id});this._bulkDocs(e,t,function(u,o){if(u)return i(u);if(t.new_edits||(o=o.filter(function(v){return v.error})),!w(s))for(var c=0,l=o.length;c<l;c++)o[c].id=o[c].id||f[c];i(null,o)})}).bind(this),this.registerDependentDatabase=d("registerDependentDatabase",function(e,t){var i=O(this.__opts);this.__opts.view_adapter&&(i.adapter=this.__opts.view_adapter);var r=new this.constructor(e,i);function a(s){return s.dependentDbs=s.dependentDbs||{},s.dependentDbs[e]?!1:(s.dependentDbs[e]=!0,s)}K(this,"_local/_pouch_dependentDbs",a).then(function(){t(null,{db:r})}).catch(t)}).bind(this),this.destroy=d("destroy",function(e,t){typeof e=="function"&&(t=e,e={});var i="use_prefix"in this?this.use_prefix:!0;const r=()=>{this._destroy(e,(a,s)=>{if(a)return t(a);this._destroyed=!0,this.emit("destroyed"),t(null,s||{ok:!0})})};if(w(this))return r();this.get("_local/_pouch_dependentDbs",(a,s)=>{if(a)return a.status!==404?t(a):r();var f=s.dependentDbs,u=this.constructor,o=Object.keys(f).map(c=>{var l=i?c.replace(new RegExp("^"+u.prefix),""):c;return new u(l,this.__opts).destroy()});Promise.all(o).then(r,t)})}).bind(this)}_compact(e,t){var i={return_docs:!1,last_seq:e.last_seq||0,since:e.last_seq||0},r=[],a,s=0;const f=c=>{this.activeTasks.update(a,{completed_items:++s}),r.push(this.compactDocument(c.id,0))},u=c=>{this.activeTasks.remove(a,c),t(c)},o=c=>{var l=c.last_seq;Promise.all(r).then(()=>K(this,"_local/compaction",v=>!v.last_seq||v.last_seq<l?(v.last_seq=l,v):!1)).then(()=>{this.activeTasks.remove(a),t(null,{ok:!0})}).catch(u)};this.info().then(c=>{a=this.activeTasks.add({name:"database_compaction",total_items:c.update_seq-i.last_seq}),this.changes(i).on("change",f).on("complete",o).on("error",u)})}changes(e,t){return typeof e=="function"&&(t=e,e={}),e=e||{},e.return_docs="return_docs"in e?e.return_docs:!e.live,new Pe(this,e,t)}type(){return typeof this._type=="function"?this._type():this.adapter}}re.prototype.purge=d("_purge",function(n,e,t){if(typeof this._purge>"u")return t(_(ie,"Purge is not implemented in the "+this.adapter+" adapter."));var i=this;i._getRevisionTree(n,(r,a)=>{if(r)return t(r);if(!a)return t(_(C));let s;try{s=ce(a,e)}catch(f){return t(f.message||f)}i._purge(n,s,(f,u)=>{if(f)return t(f);Qe(i,n,e).then(function(){return t(null,u)})})})});class Me{constructor(){this.isReady=!1,this.failed=!1,this.queue=[]}execute(){var e;if(this.failed)for(;e=this.queue.shift();)e(this.failed);else for(;e=this.queue.shift();)e()}fail(e){this.failed=e,this.execute()}ready(e){this.isReady=!0,this.db=e,this.execute()}addTask(e){this.queue.push(e),this.failed&&this.execute()}}function Ue(n,e){var t=n.match(/([a-z-]*):\/\/(.*)/);if(t)return{name:/https?/.test(t[1])?t[1]+"://"+t[2]:t[2],adapter:t[1]};var i=h.adapters,r=h.preferredAdapters,a=h.prefix,s=e.adapter;if(!s)for(var f=0;f<r.length;++f){if(s=r[f],s==="idb"&&"websql"in i&&De()&&localStorage["_pouch__websqldb_"+a+n]){A("log",'PouchDB is downgrading "'+n+'" to WebSQL to avoid data loss, because it was already opened with WebSQL.');continue}break}var u=i[s],o=u&&"use_prefix"in u?u.use_prefix:!0;return{name:o?a+n:n,adapter:s}}function Ve(n,e){n.prototype=Object.create(e.prototype,{constructor:{value:n}})}function se(n,e){let t=function(...i){if(!(this instanceof t))return new t(...i);e.apply(this,i)};return Ve(t,n),t}function Ge(n){function e(i){n.removeListener("closed",t),i||n.constructor.emit("destroyed",n.name)}function t(){n.removeListener("destroyed",e),n.constructor.emit("unref",n)}n.once("destroyed",e),n.once("closed",t),n.constructor.emit("ref",n)}class Y extends re{constructor(e,t){super(),this._setup(e,t)}_setup(e,t){if(super._setup(),t=t||{},e&&typeof e=="object"&&(t=e,e=t.name,delete t.name),t.deterministic_revs===void 0&&(t.deterministic_revs=!0),this.__opts=t=O(t),this.auto_compaction=t.auto_compaction,this.purged_infos_limit=t.purged_infos_limit||1e3,this.prefix=h.prefix,typeof e!="string")throw new Error("Missing/invalid DB name");var i=(t.prefix||"")+e,r=Ue(i,t);if(t.name=r.name,t.adapter=t.adapter||r.adapter,this.name=e,this._adapter=t.adapter,h.emit("debug",["adapter","Picked adapter: ",t.adapter]),!h.adapters[t.adapter]||!h.adapters[t.adapter].valid())throw new Error("Invalid Adapter: "+t.adapter);if(t.view_adapter&&(!h.adapters[t.view_adapter]||!h.adapters[t.view_adapter].valid()))throw new Error("Invalid View Adapter: "+t.view_adapter);this.taskqueue=new Me,this.adapter=t.adapter,h.adapters[t.adapter].call(this,t,a=>{if(a)return this.taskqueue.fail(a);Ge(this),this.emit("created",this),h.emit("created",this.name),this.taskqueue.ready(this)})}}const h=se(Y,function(n,e){Y.prototype._setup.call(this,n,e)});class ze{constructor(){this.tasks={}}list(){return Object.values(this.tasks)}add(e){const t=me();return this.tasks[t]={id:t,name:e.name,total_items:e.total_items,created_at:new Date().toJSON()},t}get(e){return this.tasks[e]}remove(e,t){return delete this.tasks[e],this.tasks}update(e,t){const i=this.tasks[e];if(typeof i<"u"){const r={id:i.id,name:i.name,created_at:i.created_at,total_items:t.total_items||i.total_items,completed_items:t.completed_items||i.completed_items,updated_at:new Date().toJSON()};this.tasks[e]=r}return this.tasks}}h.adapters={};h.preferredAdapters=[];h.prefix="_pouch_";var X=new x;function We(n){Object.keys(x.prototype).forEach(function(t){typeof x.prototype[t]=="function"&&(n[t]=X[t].bind(X))});var e=n._destructionListeners=new Map;n.on("ref",function(i){e.has(i.name)||e.set(i.name,[]),e.get(i.name).push(i)}),n.on("unref",function(i){if(e.has(i.name)){var r=e.get(i.name),a=r.indexOf(i);a<0||(r.splice(a,1),r.length>1?e.set(i.name,r):e.delete(i.name))}}),n.on("destroyed",function(i){if(e.has(i)){var r=e.get(i);e.delete(i),r.forEach(function(a){a.emit("destroyed",!0)})}})}We(h);h.adapter=function(n,e,t){e.valid()&&(h.adapters[n]=e,t&&h.preferredAdapters.push(n))};h.plugin=function(n){if(typeof n=="function")n(h);else{if(typeof n!="object"||Object.keys(n).length===0)throw new Error('Invalid plugin: got "'+n+'", expected an object or a function');Object.keys(n).forEach(function(e){h.prototype[e]=n[e]})}return this.__defaults&&(h.__defaults=Object.assign({},this.__defaults)),h};h.defaults=function(n){let e=se(h,function(t,i){i=i||{},t&&typeof t=="object"&&(i=t,t=i.name,delete i.name),i=Object.assign({},e.__defaults,i),h.call(this,t,i)});return e.preferredAdapters=h.preferredAdapters.slice(),Object.keys(h).forEach(function(t){t in e||(e[t]=h[t])}),e.__defaults=Object.assign({},this.__defaults,n),e};h.fetch=function(n,e){return ke(n,e)};h.prototype.activeTasks=h.activeTasks=new ze;var Je="9.0.0";h.plugin(Te);h.version=Je;export{h as default};
|
package/dist/index.es7.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{g as Qe}from"./index.js";import{t as je,w as Ae,r as ze,b as Ue,c as W,D as we,I as Ye,x as Xe,y as Te,z as Pe,A as Ze,C as $e,F as ke,G as et,R as _e,M as ae,H as tt,J as rt,k as Ke,d as Oe,K as nt,L as at,O as Re,j as it,P as ot,l as st,q as ut,S as ct}from"./index-browser.es2.js";import{i as ge,m as Le,d as ft,w as le,b as ie,l as vt,t as lt,a as dt,e as _t}from"./index.es8.js";var de={},Ce;function gt(){if(Ce)return de;Ce=1,de.stringify=function(r){var t=[];t.push({obj:r});for(var a="",c,o,d,g,m,S,A,C,D,R,q;c=t.pop();)if(o=c.obj,d=c.prefix||"",g=c.val||"",a+=d,g)a+=g;else if(typeof o!="object")a+=typeof o>"u"?null:JSON.stringify(o);else if(o===null)a+="null";else if(Array.isArray(o)){for(t.push({val:"]"}),m=o.length-1;m>=0;m--)S=m===0?"":",",t.push({obj:o[m],prefix:S});t.push({val:"["})}else{A=[];for(C in o)o.hasOwnProperty(C)&&A.push(C);for(t.push({val:"}"}),m=A.length-1;m>=0;m--)D=A[m],R=o[D],q=m>0?",":"",q+=JSON.stringify(D)+":",t.push({obj:R,prefix:q});t.push({val:"{"})}return a};function e(n,r,t){var a=t[t.length-1];n===a.element&&(t.pop(),a=t[t.length-1]);var c=a.element,o=a.index;if(Array.isArray(c))c.push(n);else if(o===r.length-2){var d=r.pop();c[d]=n}else r.push(n)}return de.parse=function(n){for(var r=[],t=[],a=0,c,o,d,g,m,S,A,C,D;;){if(c=n[a++],c==="}"||c==="]"||typeof c>"u"){if(r.length===1)return r.pop();e(r.pop(),r,t);continue}switch(c){case" ":case" ":case`
|
|
2
|
-
`:case":":case",":break;case"n":a+=3,e(null,r,t);break;case"t":a+=3,e(!0,r,t);break;case"f":a+=4,e(!1,r,t);break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":case"-":for(o="",a--;;)if(d=n[a++],/[\d\.\-e\+]/.test(d))o+=d;else{a--;break}e(parseFloat(o),r,t);break;case'"':for(g="",m=void 0,S=0;A=n[a++],A!=='"'||m==="\\"&&S%2===1;)g+=A,m=A,m==="\\"?S++:S=0;e(JSON.parse('"'+g+'"'),r,t);break;case"[":C={element:[],index:r.length},r.push(C.element),t.push(C);break;case"{":D={element:{},index:r.length},r.push(D.element),t.push(D);break;default:throw new Error("unexpectedly reached end of input: "+c)}}},de}var ht=gt();const Me=Qe(ht);function mt(e){try{return JSON.parse(e)}catch{return Me.parse(e)}}function pt(e){try{return JSON.stringify(e)}catch{return Me.stringify(e)}}function yt(e,n,r){return new Promise(function(t){var a=je([""]);let c;{const o=r;c=e.objectStore(n).put(a,o)}c.onsuccess=function(){var o=navigator.userAgent.match(/Chrome\/(\d+)/),d=navigator.userAgent.match(/Edge\//);t(d||!o||parseInt(o[1],10)>=43)},c.onerror=e.onabort=function(o){o.preventDefault(),o.stopPropagation(),t(!1)}}).catch(function(){return!1})}function Ie(e){return e.reduce(function(n,r){return n[r]=!0,n},{})}var St=Ie(["_id","_rev","_access","_attachments","_deleted","_revisions","_revs_info","_conflicts","_deleted_conflicts","_local_seq","_rev_tree","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats","_removed"]),Dt=Ie(["_access","_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]);function Be(e){if(!/^\d+-/.test(e))return W(Ye);var n=e.indexOf("-"),r=e.substring(0,n),t=e.substring(n+1);return{prefix:parseInt(r,10),id:t}}function xt(e,n){for(var r=e.start-e.ids.length+1,t=e.ids,a=[t[0],n,[]],c=1,o=t.length;c<o;c++)a=[t[c],{status:"missing"},[a]];return[{pos:r,ids:a}]}function Ne(e,n,r){r||(r={deterministic_revs:!0});var t,a,c,o={status:"available"};if(e._deleted&&(o.deleted=!0),n)if(e._id||(e._id=Ae()),a=ze(e,r.deterministic_revs),e._rev){if(c=Be(e._rev),c.error)return c;e._rev_tree=[{pos:c.prefix,ids:[c.id,{status:"missing"},[[a,o,[]]]]}],t=c.prefix+1}else e._rev_tree=[{pos:1,ids:[a,o,[]]}],t=1;else if(e._revisions&&(e._rev_tree=xt(e._revisions,o),t=e._revisions.start,a=e._revisions.ids[0]),!e._rev_tree){if(c=Be(e._rev),c.error)return c;t=c.prefix,a=c.id,e._rev_tree=[{pos:t,ids:[a,o,[]]}]}Ue(e._id),e._rev=t+"-"+a;var d={metadata:{},data:{}};for(var g in e)if(Object.prototype.hasOwnProperty.call(e,g)){var m=g[0]==="_";if(m&&!St[g]){var S=W(we,g);throw S.message=we.message+": "+g,S}else m&&!Dt[g]?d.metadata[g.slice(1)]=e[g]:d.data[g]=e[g]}return d}function qt(e){try{return Ze(e)}catch{var n=W($e,"Attachment is not a valid base64 string");return{error:n}}}function bt(e,n,r){var t=qt(e.data);if(t.error)return r(t.error);e.length=t.length,n==="blob"?e.data=Xe(t,e.content_type):n==="base64"?e.data=Te(t):e.data=t,Pe(t,function(a){e.digest="md5-"+a,r()})}function At(e,n,r){Pe(e.data,function(t){e.digest="md5-"+t,e.length=e.data.size||e.data.length||0,n==="binary"?ke(e.data,function(a){e.data=a,r()}):n==="base64"?et(e.data,function(a){e.data=a,r()}):r()})}function Rt(e,n,r){if(e.stub)return r();typeof e.data=="string"?bt(e,n,r):At(e,n,r)}function wt(e,n,r){if(!e.length)return r();var t=0,a;e.forEach(function(o){var d=o.data&&o.data._attachments?Object.keys(o.data._attachments):[],g=0;if(!d.length)return c();function m(A){a=A,g++,g===d.length&&c()}for(var S in o.data._attachments)Object.prototype.hasOwnProperty.call(o.data._attachments,S)&&Rt(o.data._attachments[S],n,m)});function c(){t++,e.length===t&&(a?r(a):r())}}function Ot(e,n,r,t,a,c,o,d){if(ft(n.rev_tree,r.metadata.rev)&&!d)return t[a]=r,c();var g=n.winningRev||le(n),m="deleted"in n?n.deleted:ie(n,g),S="deleted"in r.metadata?r.metadata.deleted:ie(r.metadata),A=/^1-/.test(r.metadata.rev);if(m&&!S&&d&&A){var C=r.data;C._rev=g,C._id=r.metadata.id,r=Ne(C,d)}var D=Le(n.rev_tree,r.metadata.rev_tree[0],e),R=d&&(m&&S&&D.conflicts!=="new_leaf"||!m&&D.conflicts!=="new_leaf"||m&&!S&&D.conflicts==="new_branch");if(R){var q=W(_e);return t[a]=q,c()}var s=r.metadata.rev;r.metadata.rev_tree=D.tree,r.stemmedRevs=D.stemmedRevs||[],n.rev_map&&(r.metadata.rev_map=n.rev_map);var i=le(r.metadata),u=ie(r.metadata,i),v=m===u?0:m<u?-1:1,l;s===i?l=u:l=ie(r.metadata,s),o(r,i,u,l,!0,v,a,c)}function Ct(e){return e.metadata.rev_tree[0].ids[1].status==="missing"}function Bt(e,n,r,t,a,c,o,d,g){e=e||1e3;function m(q,s,i){var u=le(q.metadata),v=ie(q.metadata,u);if("was_delete"in d&&v)return c[s]=W(ae,"deleted"),i();var l=S&&Ct(q);if(l){var f=W(_e);return c[s]=f,i()}var _=v?0:1;o(q,u,v,v,!1,_,s,i)}var S=d.new_edits,A=new Map,C=0,D=n.length;function R(){++C===D&&g&&g()}n.forEach(function(q,s){if(q._id&&ge(q._id)){var i=q._deleted?"_removeLocal":"_putLocal";r[i](q,{ctx:a},function(v,l){c[s]=v||l,R()});return}var u=q.metadata.id;A.has(u)?(D--,A.get(u).push([q,s])):A.set(u,[[q,s]])}),A.forEach(function(q,s){var i=0;function u(){++i<q.length?v():R()}function v(){var l=q[i],f=l[0],_=l[1];if(t.has(s))Ot(e,t.get(s),f,c,_,u,o,S);else{var p=Le([],f.metadata.rev_tree[0],e);f.metadata.rev_tree=p.tree,f.stemmedRevs=p.stemmedRevs||[],m(f,_,u)}}v()})}var Et=5,V="document-store",Q="by-sequence",Y="attach-store",oe="attach-seq-store",U="meta-store",$="local-store",pe="detect-blob-support";function k(e){return function(n){var r="unknown_error";n.target&&n.target.error&&(r=n.target.error.name||n.target.error.message),e(W(Re,r,n.type))}}function De(e,n,r){return{data:pt(e),winningRev:n,deletedOrLocal:r?"1":"0",seq:e.seq,id:e.id}}function se(e){if(!e)return null;var n=mt(e.data);return n.winningRev=e.winningRev,n.deleted=e.deletedOrLocal==="1",n.seq=e.seq,n}function he(e){if(!e)return e;var n=e._doc_id_rev.lastIndexOf(":");return e._id=e._doc_id_rev.substring(0,n-1),e._rev=e._doc_id_rev.substring(n+1),delete e._doc_id_rev,e}function Ge(e,n,r,t){r?t(e?typeof e!="string"?e:nt(e,n):je([""],{type:n})):e?typeof e!="string"?at(e,function(a){t(Te(a))}):t(e):t("")}function Ve(e,n,r,t){var a=Object.keys(e._attachments||{});if(!a.length)return t&&t();var c=0;function o(){++c===a.length&&t&&t()}function d(g,m){var S=g._attachments[m],A=S.digest,C=r.objectStore(Y).get(A);C.onsuccess=function(D){S.body=D.target.result.body,o()}}a.forEach(function(g){n.attachments&&n.include_docs?d(e,g):(e._attachments[g].stub=!0,o())})}function xe(e,n){return Promise.all(e.map(function(r){if(r.doc&&r.doc._attachments){var t=Object.keys(r.doc._attachments);return Promise.all(t.map(function(a){var c=r.doc._attachments[a];if("body"in c){var o=c.body,d=c.content_type;return new Promise(function(g){Ge(o,d,n,function(m){r.doc._attachments[a]=Object.assign(st(c,["digest","content_type"]),{data:m}),g()})})}}))}}))}function Fe(e,n,r){var t=[],a=r.objectStore(Q),c=r.objectStore(Y),o=r.objectStore(oe),d=e.length;function g(){d--,d||m()}function m(){t.length&&t.forEach(function(S){var A=o.index("digestSeq").count(IDBKeyRange.bound(S+"::",S+"::",!1,!1));A.onsuccess=function(C){var D=C.target.result;D||c.delete(S)}})}e.forEach(function(S){var A=a.index("_doc_id_rev"),C=n+"::"+S;A.getKey(C).onsuccess=function(D){var R=D.target.result;if(typeof R!="number")return g();a.delete(R);var q=o.index("seq").openCursor(IDBKeyRange.only(R));q.onsuccess=function(s){var i=s.target.result;if(i){var u=i.value.digestSeq.split("::")[0];t.push(u),o.delete(i.primaryKey),i.continue()}else g()}}})}function X(e,n,r){try{return{txn:e.transaction(n,r)}}catch(t){return{error:t}}}var ve=new rt;function jt(e,n,r,t,a,c){for(var o=n.docs,d,g,m,S,A,C,D,R,q=0,s=o.length;q<s;q++){var i=o[q];i._id&&ge(i._id)||(i=o[q]=Ne(i,r.new_edits,e),i.error&&!D&&(D=i))}if(D)return c(D);var u=!1,v=0,l=new Array(o.length),f=new Map,_=!1,p=t._meta.blobSupport?"blob":"base64";wt(o,p,function(x){if(x)return c(x);y()});function y(){var x=[V,Q,Y,$,oe,U],E=X(a,x,"readwrite");if(E.error)return c(E.error);d=E.txn,d.onabort=k(c),d.ontimeout=k(c),d.oncomplete=B,g=d.objectStore(V),m=d.objectStore(Q),S=d.objectStore(Y),A=d.objectStore(oe),C=d.objectStore(U),C.get(U).onsuccess=function(K){R=K.target.result,O()},j(function(K){if(K)return _=!0,c(K);M()})}function h(){u=!0,O()}function w(){Bt(e.revs_limit,o,t,f,d,l,T,r,h)}function O(){!R||!u||(R.docCount+=v,C.put(R))}function M(){if(!o.length)return;var x=0;function E(){++x===o.length&&w()}function K(L){var H=se(L.target.result);H&&f.set(H.id,H),E()}for(var F=0,G=o.length;F<G;F++){var N=o[F];if(N._id&&ge(N._id)){E();continue}var I=g.get(N.metadata.id);I.onsuccess=K}}function B(){_||(ve.notify(t._meta.name),c(null,l))}function b(x,E){var K=S.get(x);K.onsuccess=function(F){if(F.target.result)E();else{var G=W(ct,"unknown stub attachment with digest "+x);G.status=412,E(G)}}}function j(x){var E=[];if(o.forEach(function(N){N.data&&N.data._attachments&&Object.keys(N.data._attachments).forEach(function(I){var L=N.data._attachments[I];L.stub&&E.push(L.digest)})}),!E.length)return x();var K=0,F;function G(){++K===E.length&&x(F)}E.forEach(function(N){b(N,function(I){I&&!F&&(F=I),G()})})}function T(x,E,K,F,G,N,I,L){x.metadata.winningRev=E,x.metadata.deleted=K;var H=x.data;H._id=x.metadata.id,H._rev=x.metadata.rev,F&&(H._deleted=!0);var te=H._attachments&&Object.keys(H._attachments).length;if(te)return J(x,E,K,G,I,L);v+=N,O(),P(x,E,K,G,I,L)}function P(x,E,K,F,G,N){var I=x.data,L=x.metadata;I._doc_id_rev=L.id+"::"+L.rev,delete I._id,delete I._rev;function H(Z){var ee=x.stemmedRevs||[];F&&t.auto_compaction&&(ee=ee.concat(_t(x.metadata))),ee&&ee.length&&Fe(ee,x.metadata.id,d),L.seq=Z.target.result;var fe=De(L,E,K),me=g.put(fe);me.onsuccess=ue}function te(Z){Z.preventDefault(),Z.stopPropagation();var ee=m.index("_doc_id_rev"),fe=ee.getKey(I._doc_id_rev);fe.onsuccess=function(me){var He=m.put(I,me.target.result);He.onsuccess=H}}function ue(){l[G]={ok:!0,id:L.id,rev:L.rev},f.set(x.metadata.id,x.metadata),z(x,L.seq,N)}var ne=m.put(I);ne.onsuccess=H,ne.onerror=te}function J(x,E,K,F,G,N){var I=x.data,L=0,H=Object.keys(I._attachments);function te(){L===H.length&&P(x,E,K,F,G,N)}function ue(){L++,te()}H.forEach(function(ne){var Z=x.data._attachments[ne];if(Z.stub)L++,te();else{var ee=Z.data;delete Z.data,Z.revpos=parseInt(E,10);var fe=Z.digest;re(fe,ee,ue)}})}function z(x,E,K){var F=0,G=Object.keys(x.data._attachments||{});if(!G.length)return K();function N(){++F===G.length&&K()}function I(H){var te=x.data._attachments[H].digest,ue=A.put({seq:E,digestSeq:te+"::"+E});ue.onsuccess=N,ue.onerror=function(ne){ne.preventDefault(),ne.stopPropagation(),N()}}for(var L=0;L<G.length;L++)I(G[L])}function re(x,E,K){var F=S.count(x);F.onsuccess=function(G){var N=G.target.result;if(N)return K();var I={digest:x,body:E},L=S.put(I);L.onsuccess=K}}}function Je(e,n,r,t,a){t===-1&&(t=1e3);var c=typeof e.getAll=="function"&&typeof e.getAllKeys=="function"&&t>1&&!r,o,d,g;function m(D){d=D.target.result,o&&a(o,d,g)}function S(D){o=D.target.result,d&&a(o,d,g)}function A(){if(!o.length)return a();var D=o[o.length-1],R;if(n&&n.upper)try{R=IDBKeyRange.bound(D,n.upper,!0,n.upperOpen)}catch(q){if(q.name==="DataError"&&q.code===0)return a()}else R=IDBKeyRange.lowerBound(D,!0);n=R,o=null,d=null,e.getAll(n,t).onsuccess=m,e.getAllKeys(n,t).onsuccess=S}function C(D){var R=D.target.result;if(!R)return a();a([R.key],[R.value],R)}c?(g={continue:A},e.getAll(n,t).onsuccess=m,e.getAllKeys(n,t).onsuccess=S):r?e.openCursor(n,"prev").onsuccess=C:e.openCursor(n).onsuccess=C}function Tt(e,n,r){if(typeof e.getAll=="function"){e.getAll(n).onsuccess=r;return}var t=[];function a(c){var o=c.target.result;o?(t.push(o.value),o.continue()):r({target:{result:t}})}e.openCursor(n).onsuccess=a}function Pt(e,n,r){var t=new Array(e.length),a=0;e.forEach(function(c,o){n.get(c).onsuccess=function(d){d.target.result?t[o]=d.target.result:t[o]={key:c,error:"not_found"},a++,a===e.length&&r(e,t,{})}})}function Kt(e,n,r,t,a){try{if(e&&n)return a?IDBKeyRange.bound(n,e,!r,!1):IDBKeyRange.bound(e,n,!1,!r);if(e)return a?IDBKeyRange.upperBound(e):IDBKeyRange.lowerBound(e);if(n)return a?IDBKeyRange.lowerBound(n,!r):IDBKeyRange.upperBound(n,!r);if(t)return IDBKeyRange.only(t)}catch(c){return{error:c}}return null}function Lt(e,n,r){var t="startkey"in e?e.startkey:!1,a="endkey"in e?e.endkey:!1,c="key"in e?e.key:!1,o="keys"in e?e.keys:!1,d=e.skip||0,g=typeof e.limit=="number"?e.limit:-1,m=e.inclusive_end!==!1,S,A;if(!o&&(S=Kt(t,a,m,c,e.descending),A=S&&S.error,A&&!(A.name==="DataError"&&A.code===0)))return r(W(Re,A.name,A.message));var C=[V,Q,U];e.attachments&&C.push(Y);var D=X(n,C,"readonly");if(D.error)return r(D.error);var R=D.txn;R.oncomplete=M,R.onabort=k(r);var q=R.objectStore(V),s=R.objectStore(Q),i=R.objectStore(U),u=s.index("_doc_id_rev"),v=[],l,f;i.get(U).onsuccess=function(B){l=B.target.result.docCount},e.update_seq&&(s.openKeyCursor(null,"prev").onsuccess=B=>{var b=B.target.result;b&&b.key&&(f=b.key)});function _(B,b,j){var T=B.id+"::"+j;u.get(T).onsuccess=function(J){if(b.doc=he(J.target.result)||{},e.conflicts){var z=dt(B);z.length&&(b.doc._conflicts=z)}Ve(b.doc,e,R)}}function p(B,b){var j={id:b.id,key:b.id,value:{rev:B}},T=b.deleted;T?o&&(v.push(j),j.value.deleted=!0,j.doc=null):d--<=0&&(v.push(j),e.include_docs&&_(b,j,B))}function y(B){for(var b=0,j=B.length;b<j&&v.length!==g;b++){var T=B[b];if(T.error&&o){v.push(T);continue}var P=se(T),J=P.winningRev;p(J,P)}}function h(B,b,j){j&&(y(b),v.length<g&&j.continue())}function w(B){var b=B.target.result;e.descending&&(b=b.reverse()),y(b)}function O(){var B={total_rows:l,offset:e.skip,rows:v};e.update_seq&&f!==void 0&&(B.update_seq=f),r(null,B)}function M(){e.attachments?xe(v,e.binary).then(O):O()}if(!(A||g===0)){if(o)return Pt(o,q,h);if(g===-1)return Tt(q,S,w);Je(q,S,e.descending,g+d,h)}}function Mt(e,n){var r=e.objectStore(V).index("deletedOrLocal");r.count(IDBKeyRange.only("0")).onsuccess=function(t){n(t.target.result)}}var qe=!1,be=[];function It(e,n,r,t){try{e(n,r)}catch(a){t.emit("error",a)}}function Ee(){qe||!be.length||(qe=!0,be.shift()())}function Nt(e,n,r){be.push(function(){e(function(c,o){It(n,c,o,r),qe=!1,Ke(function(){Ee()})})}),Ee()}function Gt(e,n,r,t){if(e=it(e),e.continuous){var a=r+":"+Ae();return ve.addListener(r,a,n,e),ve.notify(r),{cancel:function(){ve.removeListener(r,a)}}}var c=e.doc_ids&&new Set(e.doc_ids);e.since=e.since||0;var o=e.since,d="limit"in e?e.limit:-1;d===0&&(d=1);var g=[],m=0,S=ot(e),A=new Map,C,D,R,q;function s(y,h,w){if(!w||!y.length)return;var O=new Array(y.length),M=new Array(y.length);function B(T,P){var J=e.processChange(P,T,e);o=J.seq=T.seq;var z=S(J);return typeof z=="object"?Promise.reject(z):z?(m++,e.return_docs&&g.push(J),e.attachments&&e.include_docs?new Promise(function(re){Ve(P,e,C,function(){xe([J],e.binary).then(function(){re(J)})})}):Promise.resolve(J)):Promise.resolve()}function b(){for(var T=[],P=0,J=O.length;P<J&&m!==d;P++){var z=O[P];if(z){var re=M[P];T.push(B(re,z))}}Promise.all(T).then(function(x){for(var E=0,K=x.length;E<K;E++)x[E]&&e.onChange(x[E])}).catch(e.complete),m!==d&&w.continue()}var j=0;h.forEach(function(T,P){var J=he(T),z=y[P];u(J,z,function(re,x){M[P]=re,O[P]=x,++j===y.length&&b()})})}function i(y,h,w,O){if(w.seq!==h)return O();if(w.winningRev===y._rev)return O(w,y);var M=y._id+"::"+w.winningRev,B=q.get(M);B.onsuccess=function(b){O(w,he(b.target.result))}}function u(y,h,w){if(c&&!c.has(y._id))return w();var O=A.get(y._id);if(O)return i(y,h,O,w);R.get(y._id).onsuccess=function(M){O=se(M.target.result),A.set(y._id,O),i(y,h,O,w)}}function v(){e.complete(null,{results:g,last_seq:o})}function l(){!e.continuous&&e.attachments?xe(g).then(v):v()}var f=[V,Q];e.attachments&&f.push(Y);var _=X(t,f,"readonly");if(_.error)return e.complete(_.error);C=_.txn,C.onabort=k(e.complete),C.oncomplete=l,D=C.objectStore(Q),R=C.objectStore(V),q=D.index("_doc_id_rev");var p=e.since&&!e.descending?IDBKeyRange.lowerBound(e.since,!0):null;Je(D,p,e.descending,d,s)}var ce=new Map,ye,Se=new Map;function We(e,n){var r=this;Nt(function(t){Vt(r,e,t)},n,r.constructor)}function Vt(e,n,r){var t=n.name,a=null,c=null;e._meta=null;function o(s){return function(i,u){i&&i instanceof Error&&!i.reason&&c&&(i.reason=c),s(i,u)}}function d(s){var i=s.createObjectStore(V,{keyPath:"id"});s.createObjectStore(Q,{autoIncrement:!0}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0}),s.createObjectStore(Y,{keyPath:"digest"}),s.createObjectStore(U,{keyPath:"id",autoIncrement:!1}),s.createObjectStore(pe),i.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),s.createObjectStore($,{keyPath:"_id"});var u=s.createObjectStore(oe,{autoIncrement:!0});u.createIndex("seq","seq"),u.createIndex("digestSeq","digestSeq",{unique:!0})}function g(s,i){var u=s.objectStore(V);u.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),u.openCursor().onsuccess=function(v){var l=v.target.result;if(l){var f=l.value,_=ie(f);f.deletedOrLocal=_?"1":"0",u.put(f),l.continue()}else i()}}function m(s){s.createObjectStore($,{keyPath:"_id"}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0})}function S(s,i){var u=s.objectStore($),v=s.objectStore(V),l=s.objectStore(Q),f=v.openCursor();f.onsuccess=function(_){var p=_.target.result;if(p){var y=p.value,h=y.id,w=ge(h),O=le(y);if(w){var M=h+"::"+O,B=h+"::",b=h+"::~",j=l.index("_doc_id_rev"),T=IDBKeyRange.bound(B,b,!1,!1),P=j.openCursor(T);P.onsuccess=function(J){if(P=J.target.result,!P)v.delete(p.primaryKey),p.continue();else{var z=P.value;z._doc_id_rev===M&&u.put(z),l.delete(P.primaryKey),P.continue()}}}else p.continue()}else i&&i()}}function A(s){var i=s.createObjectStore(oe,{autoIncrement:!0});i.createIndex("seq","seq"),i.createIndex("digestSeq","digestSeq",{unique:!0})}function C(s,i){var u=s.objectStore(Q),v=s.objectStore(Y),l=s.objectStore(oe),f=v.count();f.onsuccess=function(_){var p=_.target.result;if(!p)return i();u.openCursor().onsuccess=function(y){var h=y.target.result;if(!h)return i();for(var w=h.value,O=h.primaryKey,M=Object.keys(w._attachments||{}),B={},b=0;b<M.length;b++){var j=w._attachments[M[b]];B[j.digest]=!0}var T=Object.keys(B);for(b=0;b<T.length;b++){var P=T[b];l.put({seq:O,digestSeq:P+"::"+O})}h.continue()}}}function D(s){function i(f){return f.data?se(f):(f.deleted=f.deletedOrLocal==="1",f)}var u=s.objectStore(Q),v=s.objectStore(V),l=v.openCursor();l.onsuccess=function(f){var _=f.target.result;if(!_)return;var p=i(_.value);p.winningRev=p.winningRev||le(p);function y(){var w=p.id+"::",O=p.id+"::",M=u.index("_doc_id_rev").openCursor(IDBKeyRange.bound(w,O)),B=0;M.onsuccess=function(b){var j=b.target.result;if(!j)return p.seq=B,h();var T=j.primaryKey;T>B&&(B=T),j.continue()}}function h(){var w=De(p,p.winningRev,p.deleted),O=v.put(w);O.onsuccess=function(){_.continue()}}if(p.seq)return h();y()}}e._remote=!1,e.type=function(){return"idb"},e._id=tt(function(s){s(null,e._meta.instanceId)}),e._bulkDocs=function(i,u,v){jt(n,i,u,e,a,o(v))},e._get=function(i,u,v){var l,f,_,p=u.ctx;if(!p){var y=X(a,[V,Q,Y],"readonly");if(y.error)return v(y.error);p=y.txn}function h(){v(_,{doc:l,metadata:f,ctx:p})}p.objectStore(V).get(i).onsuccess=function(w){if(f=se(w.target.result),!f)return _=W(ae,"missing"),h();var O;if(u.rev)O=u.latest?vt(u.rev,f):u.rev;else{O=f.winningRev;var M=ie(f);if(M)return _=W(ae,"deleted"),h()}var B=p.objectStore(Q),b=f.id+"::"+O;B.index("_doc_id_rev").get(b).onsuccess=function(j){if(l=j.target.result,l&&(l=he(l)),!l)return _=W(ae,"missing"),h();h()}}},e._getAttachment=function(s,i,u,v,l){var f;if(v.ctx)f=v.ctx;else{var _=X(a,[V,Q,Y],"readonly");if(_.error)return l(_.error);f=_.txn}var p=u.digest,y=u.content_type;f.objectStore(Y).get(p).onsuccess=function(h){var w=h.target.result.body;Ge(w,y,v.binary,function(O){l(null,O)})}},e._info=function(i){var u,v,l=X(a,[U,Q],"readonly");if(l.error)return i(l.error);var f=l.txn;f.objectStore(U).get(U).onsuccess=function(_){v=_.target.result.docCount},f.objectStore(Q).openKeyCursor(null,"prev").onsuccess=function(_){var p=_.target.result;u=p?p.key:0},f.oncomplete=function(){i(null,{doc_count:v,update_seq:u,idb_attachment_format:e._meta.blobSupport?"binary":"base64"})}},e._allDocs=function(i,u){Lt(i,a,o(u))},e._changes=function(i){return Gt(i,e,t,a)},e._close=function(s){a.close(),ce.delete(t),s()},e._getRevisionTree=function(s,i){var u=X(a,[V],"readonly");if(u.error)return i(u.error);var v=u.txn,l=v.objectStore(V).get(s);l.onsuccess=function(f){var _=se(f.target.result);_?i(null,_.rev_tree):i(W(ae))}},e._doCompaction=function(s,i,u){var v=[V,Q,Y,oe],l=X(a,v,"readwrite");if(l.error)return u(l.error);var f=l.txn,_=f.objectStore(V);_.get(s).onsuccess=function(p){var y=se(p.target.result);lt(y.rev_tree,function(O,M,B,b,j){var T=M+"-"+B;i.indexOf(T)!==-1&&(j.status="missing")}),Fe(i,s,f);var h=y.winningRev,w=y.deleted;f.objectStore(V).put(De(y,h,w))},f.onabort=k(u),f.oncomplete=function(){u()}},e._getLocal=function(s,i){var u=X(a,[$],"readonly");if(u.error)return i(u.error);var v=u.txn,l=v.objectStore($).get(s);l.onerror=k(i),l.onsuccess=function(f){var _=f.target.result;_?(delete _._doc_id_rev,i(null,_)):i(W(ae))}},e._putLocal=function(s,i,u){typeof i=="function"&&(u=i,i={}),delete s._revisions;var v=s._rev,l=s._id;v?s._rev="0-"+(parseInt(v.split("-")[1],10)+1):s._rev="0-1";var f=i.ctx,_;if(!f){var p=X(a,[$],"readwrite");if(p.error)return u(p.error);f=p.txn,f.onerror=k(u),f.oncomplete=function(){_&&u(null,_)}}var y=f.objectStore($),h;v?(h=y.get(l),h.onsuccess=function(w){var O=w.target.result;if(!O||O._rev!==v)u(W(_e));else{var M=y.put(s);M.onsuccess=function(){_={ok:!0,id:s._id,rev:s._rev},i.ctx&&u(null,_)}}}):(h=y.add(s),h.onerror=function(w){u(W(_e)),w.preventDefault(),w.stopPropagation()},h.onsuccess=function(){_={ok:!0,id:s._id,rev:s._rev},i.ctx&&u(null,_)})},e._removeLocal=function(s,i,u){typeof i=="function"&&(u=i,i={});var v=i.ctx;if(!v){var l=X(a,[$],"readwrite");if(l.error)return u(l.error);v=l.txn,v.oncomplete=function(){f&&u(null,f)}}var f,_=s._id,p=v.objectStore($),y=p.get(_);y.onerror=k(u),y.onsuccess=function(h){var w=h.target.result;!w||w._rev!==s._rev?u(W(ae)):(p.delete(_),f={ok:!0,id:_,rev:"0-0"},i.ctx&&u(null,f))}},e._destroy=function(s,i){ve.removeAllListeners(t);var u=Se.get(t);u&&u.result&&(u.result.close(),ce.delete(t));var v=indexedDB.deleteDatabase(t);v.onsuccess=function(){Se.delete(t),ut()&&t in localStorage&&delete localStorage[t],i(null,{ok:!0})},v.onerror=k(i)};var R=ce.get(t);if(R)return a=R.idb,e._meta=R.global,Ke(function(){r(null,e)});var q=indexedDB.open(t,Et);Se.set(t,q),q.onupgradeneeded=function(s){var i=s.target.result;if(s.oldVersion<1)return d(i);var u=s.currentTarget.transaction;s.oldVersion<3&&m(i),s.oldVersion<4&&A(i);var v=[g,S,C,D],l=s.oldVersion;function f(){var _=v[l-1];l++,_&&_(u,f)}f()},q.onsuccess=function(s){a=s.target.result,a.onversionchange=function(){a.close(),ce.delete(t)},a.onabort=function(h){Oe("error","Database has a global failure",h.target.error),c=h.target.error,a.close(),ce.delete(t)};var i=a.transaction([U,pe,V],"readwrite"),u=!1,v,l,f,_;function p(){typeof f>"u"||!u||(e._meta={name:t,instanceId:_,blobSupport:f},ce.set(t,{idb:a,global:e._meta}),r(null,e))}function y(){if(!(typeof l>"u"||typeof v>"u")){var h=t+"_id";h in v?_=v[h]:v[h]=_=Ae(),v.docCount=l,i.objectStore(U).put(v)}}i.objectStore(U).get(U).onsuccess=function(h){v=h.target.result||{id:U},y()},Mt(i,function(h){l=h,y()}),ye||(ye=yt(i,pe,"key")),ye.then(function(h){f=h,p()}),i.oncomplete=function(){u=!0,p()},i.onabort=k(r)},q.onerror=function(s){var i=s.target.error&&s.target.error.message;i?i.indexOf("stored database is a higher version")!==-1&&(i=new Error('This DB was created with the newer "indexeddb" adapter, but you are trying to open it with the older "idb" adapter')):i="Failed to open indexedDB, are you in private browsing mode?",Oe("error",i),r(W(Re,i))}}We.valid=function(){try{return typeof indexedDB<"u"&&typeof IDBKeyRange<"u"}catch{return!1}};function Ht(e){e.adapter("idb",We,!0)}export{Ht as default};
|
package/dist/index.es8.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import"./index-browser.es2.js";function V(t){for(var e,i,r,s=t.rev_tree.slice(),n;n=s.pop();){var o=n.ids,v=o[2],a=n.pos;if(v.length){for(var l=0,f=v.length;l<f;l++)s.push({pos:a+1,ids:v[l]});continue}var u=!!o[1].deleted,c=o[0];(!e||(r!==u?r:i!==a?i<a:e<c))&&(e=c,i=a,r=u)}return i+"-"+e}function x(t,e){for(var i=t.slice(),r;r=i.pop();)for(var s=r.pos,n=r.ids,o=n[2],v=e(o.length===0,s,n[0],r.ctx,n[1]),a=0,l=o.length;a<l;a++)i.push({pos:s+1,ids:o[a],ctx:v})}function P(t,e){return t.pos-e.pos}function q(t){var e=[];x(t,function(s,n,o,v,a){s&&e.push({rev:n+"-"+o,pos:n,opts:a})}),e.sort(P).reverse();for(var i=0,r=e.length;i<r;i++)delete e[i].pos;return e}function M(t){for(var e=V(t),i=q(t.rev_tree),r=[],s=0,n=i.length;s<n;s++){var o=i[s];o.rev!==e&&!o.opts.deleted&&r.push(o.rev)}return r}function U(t){var e=[];return x(t.rev_tree,function(i,r,s,n,o){o.status==="available"&&!i&&(e.push(r+"-"+s),o.status="missing")}),e}function W(t,e){let i=[];const r=t.slice();let s;for(;s=r.pop();){const{pos:n,ids:o}=s,v=`${n}-${o[0]}`,a=o[2];if(i.push(v),v===e){if(a.length!==0)throw new Error("The requested revision is not a leaf");return i.reverse()}(a.length===0||a.length>1)&&(i=[]);for(let l=0,f=a.length;l<f;l++)r.push({pos:n+1,ids:a[l]})}if(i.length===0)throw new Error("The requested revision does not exist");return i.reverse()}function L(t){for(var e=[],i=t.slice(),r;r=i.pop();){var s=r.pos,n=r.ids,o=n[0],v=n[1],a=n[2],l=a.length===0,f=r.history?r.history.slice():[];f.push({id:o,opts:v}),l&&e.push({pos:s+1-f.length,ids:f});for(var u=0,c=a.length;u<c;u++)i.push({pos:s+1,ids:a[u],history:f})}return e.reverse()}function $(t,e){return t.pos-e.pos}function y(t,e,i){for(var r=0,s=t.length,n;r<s;)n=r+s>>>1,i(t[n],e)<0?r=n+1:s=n;return r}function B(t,e,i){var r=y(t,e,i);t.splice(r,0,e)}function _(t,e){for(var i,r,s=e,n=t.length;s<n;s++){var o=t[s],v=[o.id,o.opts,[]];r?(r[2].push(v),r=v):i=r=v}return i}function D(t,e){return t[0]<e[0]?-1:1}function I(t,e){for(var i=[{tree1:t,tree2:e}],r=!1;i.length>0;){var s=i.pop(),n=s.tree1,o=s.tree2;(n[1].status||o[1].status)&&(n[1].status=n[1].status==="available"||o[1].status==="available"?"available":"missing");for(var v=0;v<o[2].length;v++){if(!n[2][0]){r="new_leaf",n[2][0]=o[2][v];continue}for(var a=!1,l=0;l<n[2].length;l++)n[2][l][0]===o[2][v][0]&&(i.push({tree1:n[2][l],tree2:o[2][v]}),a=!0);a||(r="new_branch",B(n[2],o[2][v],D))}}return{conflicts:r,tree:t}}function R(t,e,i){var r=[],s=!1,n=!1,o;if(!t.length)return{tree:[e],conflicts:"new_leaf"};for(var v=0,a=t.length;v<a;v++){var l=t[v];if(l.pos===e.pos&&l.ids[0]===e.ids[0])o=I(l.ids,e.ids),r.push({pos:l.pos,ids:o.tree}),s=s||o.conflicts,n=!0;else if(i!==!0){var f=l.pos<e.pos?l:e,u=l.pos<e.pos?e:l,c=u.pos-f.pos,g=[],d=[];for(d.push({ids:f.ids,diff:c,parent:null,parentIdx:null});d.length>0;){var p=d.pop();if(p.diff===0){p.ids[0]===u.ids[0]&&g.push(p);continue}for(var h=p.ids[2],w=0,E=h.length;w<E;w++)d.push({ids:h[w],diff:p.diff-1,parent:p.ids,parentIdx:w})}var T=g[0];T?(o=I(T.ids,u.ids),T.parent[2][T.parentIdx]=o.tree,r.push({pos:f.pos,ids:f.ids}),s=s||o.conflicts,n=!0):r.push(l)}else r.push(l)}return n||r.push(e),r.sort($),{tree:r,conflicts:s||"internal_node"}}function O(t,e){for(var i=L(t),r,s,n=0,o=i.length;n<o;n++){var v=i[n],a=v.ids,l;if(a.length>e){r||(r={});var f=a.length-e;l={pos:v.pos+f,ids:_(a,f)};for(var u=0;u<f;u++){var c=v.pos+u+"-"+a[u].id;r[c]=!0}}else l={pos:v.pos,ids:_(a,0)};s?s=R(s,l,!0).tree:s=[l]}return r&&x(s,function(g,d,p){delete r[d+"-"+p]}),{tree:s,revs:r?Object.keys(r):[]}}function z(t,e,i){var r=R(t,e),s=O(r.tree,i);return{tree:s.tree,stemmedRevs:s.revs,conflicts:r.conflicts}}function A(t,e){for(var i=t.slice(),r=e.split("-"),s=parseInt(r[0],10),n=r[1],o;o=i.pop();){if(o.pos===s&&o.ids[0]===n)return!0;for(var v=o.ids[2],a=0,l=v.length;a<l;a++)i.push({pos:o.pos+1,ids:v[a]})}return!1}function k(t){return t.ids}function F(t,e){e||(e=V(t));for(var i=e.substring(e.indexOf("-")+1),r=t.rev_tree.map(k),s;s=r.pop();){if(s[0]===i)return!!s[1].deleted;r=r.concat(s[2])}}function G(t){return typeof t=="string"&&t.startsWith("_local/")}function H(t,e){for(var i=e.rev_tree.slice(),r;r=i.pop();){var s=r.pos,n=r.ids,o=n[0],v=n[1],a=n[2],l=a.length===0,f=r.history?r.history.slice():[];if(f.push({id:o,pos:s,opts:v}),l)for(var u=0,c=f.length;u<c;u++){var g=f[u],d=g.pos+"-"+g.id;if(d===t)return s+"-"+o}for(var p=0,h=a.length;p<h;p++)i.push({pos:s+1,ids:a[p],history:f})}throw new Error("Unable to resolve latest revision for id "+e.id+", rev "+t)}export{M as a,F as b,q as c,A as d,U as e,W as f,G as i,H as l,z as m,L as r,x as t,V as w};
|
package/dist/index.es9.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as q}from"./index-browser.es2.js";var sn=fetch,$n=Headers;function J(r,n,t){for(var e="",f=t-r.length;e.length<f;)e+=n;return e}function H(r,n,t){var e=J(r,n,t);return e+r}var S=-324,x=3,A="";function s(r,n){if(r===n)return 0;r=y(r),n=y(n);var t=m(r),e=m(n);if(t-e!==0)return t-e;switch(typeof r){case"number":return r-n;case"boolean":return r<n?-1:1;case"string":return U(r,n)}return Array.isArray(r)?R(r,n):W(r,n)}function y(r){switch(typeof r){case"undefined":return null;case"number":return r===1/0||r===-1/0||isNaN(r)?null:r;case"object":var n=r;if(Array.isArray(r)){var t=r.length;r=new Array(t);for(var e=0;e<t;e++)r[e]=y(n[e])}else{if(r instanceof Date)return r.toJSON();if(r!==null){r={};for(var f in n)if(Object.prototype.hasOwnProperty.call(n,f)){var u=n[f];typeof u<"u"&&(r[f]=y(u))}}}}return r}function B(r){if(r!==null)switch(typeof r){case"boolean":return r?1:0;case"number":return X(r);case"string":return r.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"");case"object":var n=Array.isArray(r),t=n?r:Object.keys(r),e=-1,f=t.length,u="";if(n)for(;++e<f;)u+=j(t[e]);else for(;++e<f;){var i=t[e];u+=j(i)+j(r[i])}return u}return""}function j(r){var n="\0";return r=y(r),m(r)+A+B(r)+n}function P(r,n){var t=n,e,f=r[n]==="1";if(f)e=0,n++;else{var u=r[n]==="0";n++;var i="",a=r.substring(n,n+x),o=parseInt(a,10)+S;for(u&&(o=-o),n+=x;;){var c=r[n];if(c==="\0")break;i+=c,n++}i=i.split("."),i.length===1?e=parseInt(i,10):e=parseFloat(i[0]+"."+i[1]),u&&(e=e-10),o!==0&&(e=parseFloat(e+"e"+o))}return{num:e,length:n-t}}function Q(r,n){var t=r.pop();if(n.length){var e=n[n.length-1];t===e.element&&(n.pop(),e=n[n.length-1]);var f=e.element,u=e.index;if(Array.isArray(f))f.push(t);else if(u===r.length-2){var i=r.pop();f[i]=t}else r.push(t)}}function gn(r){for(var n=[],t=[],e=0;;){var f=r[e++];if(f==="\0"){if(n.length===1)return n.pop();Q(n,t);continue}switch(f){case"1":n.push(null);break;case"2":n.push(r[e]==="1"),e++;break;case"3":var u=P(r,e);n.push(u.num),e+=u.length;break;case"4":for(var i="";;){var a=r[e];if(a==="\0")break;i+=a,e++}i=i.replace(/\u0001\u0001/g,"\0").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),n.push(i);break;case"5":var o={element:[],index:n.length};n.push(o.element),t.push(o);break;case"6":var c={element:{},index:n.length};n.push(c.element),t.push(c);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+f)}}}function R(r,n){for(var t=Math.min(r.length,n.length),e=0;e<t;e++){var f=s(r[e],n[e]);if(f!==0)return f}return r.length===n.length?0:r.length>n.length?1:-1}function U(r,n){return r===n?0:r>n?1:-1}function W(r,n){for(var t=Object.keys(r),e=Object.keys(n),f=Math.min(t.length,e.length),u=0;u<f;u++){var i=s(t[u],e[u]);if(i!==0||(i=s(r[t[u]],n[e[u]]),i!==0))return i}return t.length===e.length?0:t.length>e.length?1:-1}function m(r){var n=["boolean","number","string","object"],t=n.indexOf(typeof r);if(~t)return r===null?1:Array.isArray(r)?5:t<3?t+2:t+3;if(Array.isArray(r))return 5}function X(r){if(r===0)return"1";var n=r.toExponential().split(/e\+?/),t=parseInt(n[1],10),e=r<0,f=e?"0":"2",u=(e?-t:t)-S,i=H(u.toString(),"0",x);f+=A+i;var a=Math.abs(parseFloat(n[0]));e&&(a=10-a);var o=a.toFixed(20);return o=o.replace(/\.?0+$/,""),f+=A+o,f}function I(r,n){for(var t=r,e=0,f=n.length;e<f;e++){var u=n[e];if(t=t[u],!t)break}return t}function vn(r,n,t){for(var e=0,f=n.length;e<f-1;e++){var u=n[e];r=r[u]=r[u]||{}}r[n[f-1]]=t}function Y(r,n){return r<n?-1:r>n?1:0}function E(r){for(var n=[],t="",e=0,f=r.length;e<f;e++){var u=r[e];e>0&&r[e-1]==="\\"&&(u==="$"||u===".")?t=t.substring(0,t.length-1)+u:u==="."?(n.push(t),t=""):t+=u}return n.push(t),n}var Z=["$or","$nor","$not"];function G(r){return Z.indexOf(r)>-1}function L(r){return Object.keys(r)[0]}function k(r){return r[L(r)]}function b(r){var n={},t={$or:!0,$nor:!0};return r.forEach(function(e){Object.keys(e).forEach(function(f){var u=e[f];if(typeof u!="object"&&(u={$eq:u}),G(f))if(u instanceof Array){if(t[f]){t[f]=!1,n[f]=u;return}var i=[];n[f].forEach(function(o){Object.keys(u).forEach(function(c){var v=u[c],p=Math.max(Object.keys(o).length,Object.keys(v).length),w=b([o,v]);Object.keys(w).length<=p||i.push(w)})}),n[f]=i}else n[f]=b([u]);else{var a=n[f]=n[f]||{};Object.keys(u).forEach(function(o){var c=u[o];if(o==="$gt"||o==="$gte")return K(o,c,a);if(o==="$lt"||o==="$lte")return D(o,c,a);if(o==="$ne")return F(c,a);if(o==="$eq")return d(c,a);if(o==="$regex")return M(c,a);a[o]=c})}})}),n}function K(r,n,t){typeof t.$eq<"u"||(typeof t.$gte<"u"?r==="$gte"?n>t.$gte&&(t.$gte=n):n>=t.$gte&&(delete t.$gte,t.$gt=n):typeof t.$gt<"u"?r==="$gte"?n>t.$gt&&(delete t.$gt,t.$gte=n):n>t.$gt&&(t.$gt=n):t[r]=n)}function D(r,n,t){typeof t.$eq<"u"||(typeof t.$lte<"u"?r==="$lte"?n<t.$lte&&(t.$lte=n):n<=t.$lte&&(delete t.$lte,t.$lt=n):typeof t.$lt<"u"?r==="$lte"?n<t.$lt&&(delete t.$lt,t.$lte=n):n<t.$lt&&(t.$lt=n):t[r]=n)}function F(r,n){"$ne"in n?n.$ne.push(r):n.$ne=[r]}function d(r,n){delete n.$gt,delete n.$gte,delete n.$lt,delete n.$lte,delete n.$ne,n.$eq=r}function M(r,n){"$regex"in n?n.$regex.push(r):n.$regex=[r]}function T(r){for(var n in r){if(Array.isArray(r))for(var t in r)r[t].$and&&(r[t]=b(r[t].$and));var e=r[n];typeof e=="object"&&T(e)}return r}function _(r,n){for(var t in r){t==="$and"&&(n=!0);var e=r[t];typeof e=="object"&&(n=_(e,n))}return n}function V(r){var n=q(r);_(n,!1)&&(n=T(n),"$and"in n&&(n=b(n.$and))),["$or","$nor"].forEach(function(i){i in n&&n[i].forEach(function(a){for(var o=Object.keys(a),c=0;c<o.length;c++){var v=o[c],p=a[v];(typeof p!="object"||p===null)&&(a[v]={$eq:p})}})}),"$not"in n&&(n.$not=b([n.$not]));for(var t=Object.keys(n),e=0;e<t.length;e++){var f=t[e],u=n[f];(typeof u!="object"||u===null)&&(u={$eq:u}),n[f]=u}return O(n),n}function O(r){Object.keys(r).forEach(function(n){var t=r[n];Array.isArray(t)?t.forEach(function(e){e&&typeof e=="object"&&O(e)}):n==="$ne"?r.$ne=[t]:n==="$regex"?r.$regex=[t]:t&&typeof t=="object"&&O(t)})}function nn(r){function n(t){return r.map(function(e){var f=L(e),u=E(f),i=I(t,u);return i})}return function(t,e){var f=n(t.doc),u=n(e.doc),i=s(f,u);return i!==0?i:Y(t.doc._id,e.doc._id)}}function rn(r,n,t){if(r=r.filter(function(i){return g(i.doc,n.selector,t)}),n.sort){var e=nn(n.sort);r=r.sort(e),typeof n.sort[0]!="string"&&k(n.sort[0])==="desc"&&(r=r.reverse())}if("limit"in n||"skip"in n){var f=n.skip||0,u=("limit"in n?n.limit:r.length)+f;r=r.slice(f,u)}return r}function g(r,n,t){return t.every(function(e){var f=n[e],u=E(e),i=I(r,u);return G(e)?en(e,f,r):h(f,r,u,i)})}function h(r,n,t,e){return r?typeof r=="object"?Object.keys(r).every(function(f){var u=r[f];if(f.indexOf("$")===0)return C(f,n,u,t,e);var i=E(f);if(e===void 0&&typeof u!="object"&&i.length>0)return!1;var a=I(e,i);return typeof u=="object"?h(u,n,t,a):C("$eq",n,u,i,a)}):r===e:!0}function en(r,n,t){return r==="$or"?n.some(function(e){return g(t,e,Object.keys(e))}):r==="$not"?!g(t,n,Object.keys(n)):!n.find(function(e){return g(t,e,Object.keys(e))})}function C(r,n,t,e,f){if(!z[r])throw new Error('unknown operator "'+r+'" - should be one of $eq, $lte, $lt, $gt, $gte, $exists, $ne, $in, $nin, $size, $mod, $regex, $elemMatch, $type, $allMatch or $all');return z[r](n,t,e,f)}function l(r){return typeof r<"u"&&r!==null}function $(r){return typeof r<"u"}function tn(r,n){if(typeof r!="number"||parseInt(r,10)!==r)return!1;var t=n[0],e=n[1];return r%t===e}function N(r,n){return n.some(function(t){return r instanceof Array?r.some(function(e){return s(t,e)===0}):s(t,r)===0})}function fn(r,n){return n.every(function(t){return r.some(function(e){return s(t,e)===0})})}function un(r,n){return r.length===n}function on(r,n){var t=new RegExp(n);return t.test(r)}function an(r,n){switch(n){case"null":return r===null;case"boolean":return typeof r=="boolean";case"number":return typeof r=="number";case"string":return typeof r=="string";case"array":return r instanceof Array;case"object":return{}.toString.call(r)==="[object Object]"}}var z={$elemMatch:function(r,n,t,e){return!Array.isArray(e)||e.length===0?!1:typeof e[0]=="object"&&e[0]!==null?e.some(function(f){return g(f,n,Object.keys(n))}):e.some(function(f){return h(n,r,t,f)})},$allMatch:function(r,n,t,e){return!Array.isArray(e)||e.length===0?!1:typeof e[0]=="object"&&e[0]!==null?e.every(function(f){return g(f,n,Object.keys(n))}):e.every(function(f){return h(n,r,t,f)})},$eq:function(r,n,t,e){return $(e)&&s(e,n)===0},$gte:function(r,n,t,e){return $(e)&&s(e,n)>=0},$gt:function(r,n,t,e){return $(e)&&s(e,n)>0},$lte:function(r,n,t,e){return $(e)&&s(e,n)<=0},$lt:function(r,n,t,e){return $(e)&&s(e,n)<0},$exists:function(r,n,t,e){return n?$(e):!$(e)},$mod:function(r,n,t,e){return l(e)&&tn(e,n)},$ne:function(r,n,t,e){return n.every(function(f){return s(e,f)!==0})},$in:function(r,n,t,e){return l(e)&&N(e,n)},$nin:function(r,n,t,e){return l(e)&&!N(e,n)},$size:function(r,n,t,e){return l(e)&&Array.isArray(e)&&un(e,n)},$all:function(r,n,t,e){return Array.isArray(e)&&fn(e,n)},$regex:function(r,n,t,e){return l(e)&&typeof e=="string"&&n.every(function(f){return on(e,f)})},$type:function(r,n,t,e){return an(e,n)}};function pn(r,n){if(typeof n!="object")throw new Error("Selector error: expected a JSON object");n=V(n);var t={doc:r},e=rn([t],{selector:n},Object.keys(n));return e&&e.length===1}export{V as a,rn as b,s as c,Y as d,E as e,sn as f,k as g,$n as h,I as i,L as j,pn as m,y as n,gn as p,vn as s,j as t};
|