playhtml 0.1.8 → 0.1.9

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/README.md CHANGED
@@ -48,6 +48,8 @@ A full list can be found in `types.ts` under `TagType`.
48
48
 
49
49
  ### `can-move`
50
50
 
51
+ https://github.com/spencerc99/playhtml/assets/14796580/9c2b9bf6-142c-41e2-8c8f-93a3b121a73e
52
+
51
53
  Creates a movable object using 2D `translate` on the element. Dragging the element around will move it
52
54
 
53
55
  **troubleshooting**
@@ -61,6 +63,8 @@ Creates a rotatable object using a `rotate` `transform` on the element. Dragging
61
63
 
62
64
  ### `can-toggle`
63
65
 
66
+ <blockquote class="twitter-tweet"><p lang="en" dir="ltr">today i installed some lamps on the demos-and-chill website<br><br>then <a href="https://twitter.com/_jzhao?ref_src=twsrc%5Etfw">@_jzhao</a> and i fought on whether to keep them on or not. <a href="https://t.co/sCspTwmRpS">pic.twitter.com/sCspTwmRpS</a></p>&mdash; spencer chang ☀️ (spencerchang.me @ bsky) (@spencerc99) <a href="https://twitter.com/spencerc99/status/1681048824884895744?ref_src=twsrc%5Etfw">July 17, 2023</a></blockquote> <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
67
+
64
68
  Creates an object that can be switched on and off. Clicking the element will toggle the `clicked` class on the element.
65
69
 
66
70
  ### `can-grow`
@@ -69,6 +73,8 @@ Creates an object that can be resized using a `scale` `transform`. Clicking the
69
73
 
70
74
  ### `can-post`
71
75
 
76
+ ![image](https://github.com/spencerc99/playhtml/assets/14796580/6de3fcab-2372-4080-b46f-cd768f1ed44e)
77
+
72
78
  Creates a communal forum from a `form` element. The form will sync any new submissions including all the `input` elements in the form, using their `name` property as the key and their value as the value. New messages will be currently prepended to the element with the `guestbookMessages` ID. TODO: make this generic and take user input
73
79
 
74
80
  ---
@@ -6093,23 +6093,25 @@ const qs = {
6093
6093
  },
6094
6094
  [tt.CanGrow]: {
6095
6095
  // TODO: turn this into a function so you can accept arbitrary user input?
6096
- defaultData: { scale: 1, maxScale: 2 },
6097
- defaultLocalData: { isHovering: !1 },
6096
+ defaultData: { scale: 1 },
6097
+ defaultLocalData: { maxScale: 2, isHovering: !1 },
6098
6098
  updateElement: ({ element: e, data: t }) => {
6099
6099
  e.style.transform = `scale(${t.scale})`;
6100
6100
  },
6101
- onClick: (e, { data: t, element: n, setData: s }) => {
6101
+ onClick: (e, { data: t, element: n, setData: s, localData: r }) => {
6102
+ let { scale: i } = t;
6102
6103
  if (e.altKey) {
6103
6104
  if (t.scale <= 0.5)
6104
6105
  return;
6105
- t.scale -= 0.1;
6106
+ i -= 0.1;
6106
6107
  } else {
6107
- if (n.style.cursor = Ws, t.scale >= t.maxScale)
6108
+ if (n.style.cursor = Ws, t.scale >= r.maxScale)
6108
6109
  return;
6109
- t.scale += 0.1;
6110
+ i += 0.1;
6110
6111
  }
6111
- s(t);
6112
+ s({ ...t, scale: i });
6112
6113
  },
6114
+ // TODO: this still needs to use te document as a whole
6113
6115
  onMouseEnter: xe,
6114
6116
  onKeyDown: xe,
6115
6117
  onKeyUp: xe
@@ -6118,22 +6120,20 @@ const qs = {
6118
6120
  defaultData: [],
6119
6121
  defaultLocalData: { addedEntries: /* @__PURE__ */ new Set() },
6120
6122
  updateElement: ({
6121
- element: e,
6122
- data: t,
6123
- localData: { addedEntries: n },
6124
- setLocalData: s,
6125
- setData: r
6123
+ data: e,
6124
+ localData: { addedEntries: t },
6125
+ setLocalData: n
6126
6126
  }) => {
6127
- const i = t.filter(
6128
- (c) => !n.has(c.id)
6129
- ), o = Ps("guestbookMessages");
6130
- i.forEach((c) => {
6131
- const l = document.createElement("div");
6132
- l.classList.add("guestbook-entry");
6133
- const a = new Date(c.timestamp), h = a.toTimeString().split(" ")[0], u = a.toDateString() === (/* @__PURE__ */ new Date()).toDateString();
6134
- l.innerHTML = `
6135
- <span class="guestbook-entry-timestamp">${u ? "" : a.toDateString() + " "}${h}</span><span class="guestbook-entry-name">${c.name}</span> <span class="guestbook-entry-message">${c.message}</span>`, o.prepend(l), n.add(c.id);
6136
- }), s({ addedEntries: n });
6127
+ const s = e.filter(
6128
+ (i) => !t.has(i.id)
6129
+ ), r = Ps("guestbookMessages");
6130
+ s.forEach((i) => {
6131
+ const o = document.createElement("div");
6132
+ o.classList.add("guestbook-entry");
6133
+ const c = new Date(i.timestamp), l = c.toTimeString().split(" ")[0], a = c.toDateString() === (/* @__PURE__ */ new Date()).toDateString();
6134
+ o.innerHTML = `
6135
+ <span class="guestbook-entry-timestamp">${a ? "" : c.toDateString() + " "}${l}</span><span class="guestbook-entry-name">${i.name}</span> <span class="guestbook-entry-message">${i.message}</span>`, r.prepend(o), t.add(i.id);
6136
+ }), n({ addedEntries: t });
6137
6137
  },
6138
6138
  onSubmit: (e, { data: t, setData: n }) => {
6139
6139
  e.preventDefault(), e.stopImmediatePropagation();
@@ -3,5 +3,5 @@
3
3
  `?o.insert.slice(0,-1):o.insert;(typeof c!="string"||c.length>0)&&tn(s,this,r,c,o.attributes||{})}else o.retain!==void 0?Is(s,this,r,o.retain,o.attributes||{}):o.delete!==void 0&&Ls(s,r,o.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,s){const r=[],i=new Map,o=this.doc;let c="",l=this._start;function a(){if(c.length>0){const u={};let d=!1;i.forEach((g,m)=>{d=!0,u[m]=g});const f={insert:c};d&&(f.attributes=u),r.push(f),c=""}}const h=()=>{for(;l!==null;){if(Bt(l,t)||n!==void 0&&Bt(l,n))switch(l.content.constructor){case $:{const u=i.get("ychange");t!==void 0&&!Bt(l,t)?(u===void 0||u.user!==l.id.client||u.type!=="removed")&&(a(),i.set("ychange",s?s("removed",l.id):{type:"removed"})):n!==void 0&&!Bt(l,n)?(u===void 0||u.user!==l.id.client||u.type!=="added")&&(a(),i.set("ychange",s?s("added",l.id):{type:"added"})):u!==void 0&&(a(),i.delete("ychange")),c+=l.content.str;break}case G:case ut:{a();const u={insert:l.content.getContent()[0]};if(i.size>0){const d={};u.attributes=d,i.forEach((f,g)=>{d[g]=f})}r.push(u);break}case E:Bt(l,t)&&(a(),Et(i,l.content));break}l=l.right}a()};return t||n?_(o,u=>{t&&Je(u,t),n&&Je(u,n),h()},"cleanup"):h(),r}insert(t,n,s){if(n.length<=0)return;const r=this.doc;r!==null?_(r,i=>{const o=de(i,this,t);s||(s={},o.currentAttributes.forEach((c,l)=>{s[l]=c})),tn(i,this,o,n,s)}):this._pending.push(()=>this.insert(t,n,s))}insertEmbed(t,n,s={}){const r=this.doc;r!==null?_(r,i=>{const o=de(i,this,t);tn(i,this,o,n,s)}):this._pending.push(()=>this.insertEmbed(t,n,s))}delete(t,n){if(n===0)return;const s=this.doc;s!==null?_(s,r=>{Ls(r,de(r,this,t),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,s){if(n===0)return;const r=this.doc;r!==null?_(r,i=>{const o=de(i,this,t);o.right!==null&&Is(i,this,o,n,s)}):this._pending.push(()=>this.format(t,n,s))}removeAttribute(t){this.doc!==null?_(this.doc,n=>{he(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?_(this.doc,s=>{Qe(s,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return Ze(this,t)}getAttributes(){return _s(this)}_write(t){t.writeTypeRef(Eo)}}const oo=e=>new It;class en{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===Ht||n.constructor===ht)&&n._start!==null)t=n._start;else for(;t!==null;)if(t.right!==null){t=t.right;break}else t.parent===this._root?t=null:t=t.parent._item;while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}}class ht extends x{constructor(){super(),this._prelimContent=[]}get firstChild(){const t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new ht}clone(){const t=new ht;return t.insert(0,this.toArray().map(n=>n instanceof x?n.clone():n)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new en(this,t)}querySelector(t){t=t.toUpperCase();const s=new en(this,r=>r.nodeName&&r.nodeName.toUpperCase()===t).next();return s.done?null:s.value}querySelectorAll(t){return t=t.toUpperCase(),q(new en(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){le(this,t,new ao(this,n,t))}toString(){return ps(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},s){const r=t.createDocumentFragment();return s!==void 0&&s._createAssociation(r,this),Ft(this,i=>{r.insertBefore(i.toDOM(t,n,s),null)}),r}insert(t,n){this.doc!==null?_(this.doc,s=>{ys(s,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)_(this.doc,s=>{const r=t&&t instanceof x?t._item:t;ae(s,this,r,n)});else{const s=this._prelimContent,r=t===null?0:s.findIndex(i=>i===t)+1;if(r===0&&t!==null)throw ot("Reference item not found");s.splice(r,0,...n)}}delete(t,n=1){this.doc!==null?_(this.doc,s=>{bs(s,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return gs(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return ws(this,t)}slice(t=0,n=this.length){return fs(this,t,n)}forEach(t){Ft(this,t)}_write(t){t.writeTypeRef(Ao)}}const co=e=>new ht;class Ht extends ht{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((s,r)=>{this.setAttribute(r,s)}),this._prelimAttrs=null}_copy(){return new Ht(this.nodeName)}clone(){const t=new Ht(this.nodeName),n=this.getAttributes();return yr(n,(s,r)=>{typeof s=="string"&&t.setAttribute(r,s)}),t.insert(0,this.toArray().map(s=>s instanceof x?s.clone():s)),t}toString(){const t=this.getAttributes(),n=[],s=[];for(const c in t)s.push(c);s.sort();const r=s.length;for(let c=0;c<r;c++){const l=s[c];n.push(l+'="'+t[l]+'"')}const i=this.nodeName.toLocaleLowerCase(),o=n.length>0?" "+n.join(" "):"";return`<${i}${o}>${super.toString()}</${i}>`}removeAttribute(t){this.doc!==null?_(this.doc,n=>{he(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?_(this.doc,s=>{Qe(s,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return Ze(this,t)}hasAttribute(t){return ks(this,t)}getAttributes(){return _s(this)}toDOM(t=document,n={},s){const r=t.createElement(this.nodeName),i=this.getAttributes();for(const o in i){const c=i[o];typeof c=="string"&&r.setAttribute(o,c)}return Ft(this,o=>{r.appendChild(o.toDOM(t,n,s))}),s!==void 0&&s._createAssociation(r,this),r}_write(t){t.writeTypeRef(Io),t.writeKey(this.nodeName)}}const lo=e=>new Ht(e.readKey());class ao extends oe{constructor(t,n,s){super(t,s),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(r=>{r===null?this.childListChanged=!0:this.attributesChanged.add(r)})}}class fe extends at{constructor(t){super(),this.hookName=t}_copy(){return new fe(this.hookName)}clone(){const t=new fe(this.hookName);return this.forEach((n,s)=>{t.set(s,n)}),t}toDOM(t=document,n={},s){const r=n[this.hookName];let i;return r!==void 0?i=r.createDom(this):i=document.createElement(this.hookName),i.setAttribute("data-yjs-hook",this.hookName),s!==void 0&&s._createAssociation(i,this),i}_write(t){t.writeTypeRef(Lo),t.writeKey(this.hookName)}}const ho=e=>new fe(e.readKey());class ge extends It{get nextSibling(){const t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){const t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new ge}clone(){const t=new ge;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,s){const r=t.createTextNode(this.toString());return s!==void 0&&s._createAssociation(r,this),r}toString(){return this.toDelta().map(t=>{const n=[];for(const r in t.attributes){const i=[];for(const o in t.attributes[r])i.push({key:o,value:t.attributes[r][o]});i.sort((o,c)=>o.key<c.key?-1:1),n.push({nodeName:r,attrs:i})}n.sort((r,i)=>r.nodeName<i.nodeName?-1:1);let s="";for(let r=0;r<n.length;r++){const i=n[r];s+=`<${i.nodeName}`;for(let o=0;o<i.attrs.length;o++){const c=i.attrs[o];s+=` ${c.key}="${c.value}"`}s+=">"}s+=t.insert;for(let r=n.length-1;r>=0;r--)s+=`</${n[r].nodeName}>`;return s}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(xo)}}const uo=e=>new ge;class nn{constructor(t,n){this.id=t,this.length=n}get deleted(){throw V()}mergeWith(t){return!1}write(t,n,s){throw V()}integrate(t,n){throw V()}}const fo=0;class R extends nn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),rs(t.doc.store,this)}write(t,n){t.writeInfo(fo),t.writeLen(this.length-n)}getMissing(t,n){return null}}class $t{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new $t(this.content)}splice(t){throw V()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}}const go=e=>new $t(e.readBuf());class jt{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new jt(this.len)}splice(t){const n=new jt(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){ee(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}}const po=e=>new jt(e.readLen()),xs=(e,t)=>new kt({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});class Kt{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;const n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new Kt(xs(this.doc.guid,this.opts))}splice(t){throw V()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}}const wo=e=>new Kt(xs(e.readString(),e.readAny()));class ut{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new ut(this.embed)}splice(t){throw V()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}}const mo=e=>new ut(e.readJSON());class E{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new E(this.key,this.value)}splice(t){throw V()}mergeWith(t){return!1}integrate(t,n){const s=n.parent;s._searchMarker=null,s._hasFormatting=!0}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}}const yo=e=>new E(e.readKey(),e.readJSON());class pe{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new pe(this.arr)}splice(t){const n=new pe(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const s=this.arr.length;t.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];t.writeString(i===void 0?"undefined":JSON.stringify(i))}}getRef(){return 2}}const bo=e=>{const t=e.readLen(),n=[];for(let s=0;s<t;s++){const r=e.readString();r==="undefined"?n.push(void 0):n.push(JSON.parse(r))}return new pe(n)};class dt{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new dt(this.arr)}splice(t){const n=new dt(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){const s=this.arr.length;t.writeLen(s-n);for(let r=n;r<s;r++){const i=this.arr[r];t.writeAny(i)}}getRef(){return 8}}const _o=e=>{const t=e.readLen(),n=[];for(let s=0;s<t;s++)n.push(e.readAny());return new dt(n)};class ${constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new $(this.str)}splice(t){const n=new $(this.str.slice(t));this.str=this.str.slice(0,t);const s=this.str.charCodeAt(t-1);return s>=55296&&s<=56319&&(this.str=this.str.slice(0,t-1)+"�",n.str="�"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}}const ko=e=>new $(e.readString()),So=[Pi,eo,oo,lo,co,ho,uo],Do=0,Co=1,Eo=2,Io=3,Ao=4,Lo=5,xo=6;class G{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new G(this.type._copy())}splice(t){throw V()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(s=>{s.deleted?t._mergeStructs.push(s):s.delete(t)}),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach(s=>{for(;s!==null;)s.gc(t,!0),s=s.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}}const Mo=e=>new G(So[e.readTypeRef()](e)),we=(e,t,n)=>{const{client:s,clock:r}=t.id,i=new I(y(s,r+n),t,y(s,r+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&i.markDeleted(),t.keep&&(i.keep=!0),t.redone!==null&&(i.redone=y(t.redone.client,t.redone.clock+n)),t.right=i,i.right!==null&&(i.right.left=i),e._mergeStructs.push(i),i.parentSub!==null&&i.right===null&&i.parent._map.set(i.parentSub,i),t.length=n,i};class I extends nn{constructor(t,n,s,r,i,o,c,l){super(t,l.getLength()),this.origin=s,this.left=n,this.right=r,this.rightOrigin=i,this.parent=o,this.parentSub=c,this.redone=null,this.content=l,this.info=this.content.isCountable()?Cn:0}set marker(t){(this.info&Ee)>0!==t&&(this.info^=Ee)}get marker(){return(this.info&Ee)>0}get keep(){return(this.info&Dn)>0}set keep(t){this.keep!==t&&(this.info^=Dn)}get countable(){return(this.info&Cn)>0}get deleted(){return(this.info&Ce)>0}set deleted(t){this.deleted!==t&&(this.info^=Ce)}markDeleted(){this.info|=Ce}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=L(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=L(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Dt&&this.id.client!==this.parent.client&&this.parent.clock>=L(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=is(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=P(t,this.rightOrigin),this.rightOrigin=this.right.id),(this.left&&this.left.constructor===R||this.right&&this.right.constructor===R)&&(this.parent=null),!this.parent)this.left&&this.left.constructor===I&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===I&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Dt){const s=Xe(n,this.parent);s.constructor===R?this.parent=null:this.parent=s.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=is(t,t.doc.store,y(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let s=this.left,r;if(s!==null)r=s.right;else if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start;const i=new Set,o=new Set;for(;r!==null&&r!==this.right;){if(o.add(r),i.add(r),ne(this.origin,r.origin)){if(r.id.client<this.id.client)s=r,i.clear();else if(ne(this.rightOrigin,r.rightOrigin))break}else if(r.origin!==null&&o.has(Xe(t.doc.store,r.origin)))i.has(Xe(t.doc.store,r.origin))||(s=r,i.clear());else break;r=r.right}this.left=s}if(this.left!==null){const s=this.left.right;this.right=s,this.left.right=this}else{let s;if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start,this.parent._start=this;this.right=s}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),rs(t.doc.store,this),this.content.integrate(t,this),ls(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new R(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:y(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&ne(t.origin,this.lastId)&&this.right===t&&ne(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){const n=this.parent._searchMarker;return n&&n.forEach(s=>{s.p===t&&(s.p=this,!this.deleted&&this.countable&&(s.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){const n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),ee(t.deleteSet,this.id.client,this.id.clock,this.length),ls(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw F();this.content.gc(t),n?Ni(t,this,new R(this.id,this.length)):this.content=new jt(this.length)}write(t,n){const s=n>0?y(this.id.client,this.id.clock+n-1):this.origin,r=this.rightOrigin,i=this.parentSub,o=this.content.getRef()&Wt|(s===null?0:O)|(r===null?0:X)|(i===null?0:Ut);if(t.writeInfo(o),s!==null&&t.writeLeftID(s),r!==null&&t.writeRightID(r),s===null&&r===null){const c=this.parent;if(c._item!==void 0){const l=c._item;if(l===null){const a=Ri(c);t.writeParentInfo(!0),t.writeString(a)}else t.writeParentInfo(!1),t.writeLeftID(l.id)}else c.constructor===String?(t.writeParentInfo(!0),t.writeString(c)):c.constructor===Dt?(t.writeParentInfo(!1),t.writeLeftID(c)):F();i!==null&&t.writeString(i)}this.content.write(t,n)}}const Ms=(e,t)=>Uo[t&Wt](e),Uo=[()=>{F()},po,bo,go,ko,mo,yo,Mo,_o,wo,()=>{F()}],To=10;class N extends nn{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){F()}write(t,n){t.writeInfo(To),p(t.restEncoder,this.length-n)}getMissing(t,n){return null}}const Us=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Ts="__ $YJS$ __";Us[Ts]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Us[Ts]=!0;const vs=0,sn=1,Os=2,rn=(e,t)=>{p(e,vs);const n=vi(t);C(e,n)},Rs=(e,t,n)=>{p(e,sn),C(e,Ke(t,n))},vo=(e,t,n)=>Rs(t,n,U(e)),Ns=(e,t,n)=>{try{qn(t,U(e),n)}catch(s){console.error("Caught error while handling a Yjs update",s)}},Oo=(e,t)=>{p(e,Os),C(e,t)},Ro=Ns,No=(e,t,n,s)=>{const r=w(e);switch(r){case vs:vo(e,t,n);break;case sn:Ns(e,n,s);break;case Os:Ro(e,n,s);break;default:throw new Error("Unknown message type")}return r},Bo=0,Vo=(e,t,n)=>{switch(w(e)){case Bo:n(t,Z(e))}},on=3e4;class Fo extends te{constructor(t){super(),this.doc=t,this.clientID=t.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{const n=ct();this.getLocalState()!==null&&on/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const s=[];this.meta.forEach((r,i)=>{i!==this.clientID&&on<=n-r.lastUpdated&&this.states.has(i)&&s.push(i)}),s.length>0&&cn(this,s,"timeout")},J(on/10)),t.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(t){const n=this.clientID,s=this.meta.get(n),r=s===void 0?0:s.clock+1,i=this.states.get(n);t===null?this.states.delete(n):this.states.set(n,t),this.meta.set(n,{clock:r,lastUpdated:ct()});const o=[],c=[],l=[],a=[];t===null?a.push(n):i==null?t!=null&&o.push(n):(c.push(n),Mt(i,t)||l.push(n)),(o.length>0||l.length>0||a.length>0)&&this.emit("change",[{added:o,updated:l,removed:a},"local"]),this.emit("update",[{added:o,updated:c,removed:a},"local"])}setLocalStateField(t,n){const s=this.getLocalState();s!==null&&this.setLocalState({...s,[t]:n})}getStates(){return this.states}}const cn=(e,t,n)=>{const s=[];for(let r=0;r<t.length;r++){const i=t[r];if(e.states.has(i)){if(e.states.delete(i),i===e.clientID){const o=e.meta.get(i);e.meta.set(i,{clock:o.clock+1,lastUpdated:ct()})}s.push(i)}}s.length>0&&(e.emit("change",[{added:[],updated:[],removed:s},n]),e.emit("update",[{added:[],updated:[],removed:s},n]))},Jt=(e,t,n=e.states)=>{const s=t.length,r=M();p(r,s);for(let i=0;i<s;i++){const o=t[i],c=n.get(o)||null,l=e.meta.get(o).clock;p(r,o),p(r,l),it(r,JSON.stringify(c))}return S(r)},Ho=(e,t,n)=>{const s=Q(t),r=ct(),i=[],o=[],c=[],l=[],a=w(s);for(let h=0;h<a;h++){const u=w(s);let d=w(s);const f=JSON.parse(Z(s)),g=e.meta.get(u),m=e.states.get(u),v=g===void 0?0:g.clock;(v<d||v===d&&f===null&&e.states.has(u))&&(f===null?u===e.clientID&&e.getLocalState()!=null?d++:e.states.delete(u):e.states.set(u,f),e.meta.set(u,{clock:d,lastUpdated:r}),g===void 0&&f!==null?i.push(u):g!==void 0&&f===null?l.push(u):f!==null&&(Mt(f,m)||c.push(u),o.push(u)))}(i.length>0||c.length>0||l.length>0)&&e.emit("change",[{added:i,updated:c,removed:l},n]),(i.length>0||o.length>0||l.length>0)&&e.emit("update",[{added:i,updated:o,removed:l},n])},$o=e=>br(e,(t,n)=>`${encodeURIComponent(n)}=${encodeURIComponent(t)}`).join("&");var ft=0,Bs=3,At=1,jo=2;function Ko(e,t){if(!e)throw new Error(t)}var Xt=[];Xt[ft]=(e,t,n,s,r)=>{p(e,ft);const i=No(t,e,n.doc,n);s&&i===sn&&!n.synced&&(n.synced=!0)},Xt[Bs]=(e,t,n,s,r)=>{p(e,At),C(e,Jt(n.awareness,Array.from(n.awareness.getStates().keys())))},Xt[At]=(e,t,n,s,r)=>{Ho(n.awareness,U(t),n)},Xt[jo]=(e,t,n,s,r)=>{Vo(t,n.doc,(i,o)=>Jo(n,o))};var Vs=3e4;function Jo(e,t){console.warn(`Permission denied to access ${e.url}.
4
4
  ${t}`)}function Fs(e,t,n){const s=Q(t),r=M(),i=w(s),o=e.messageHandlers[i];return o?o(r,s,e,n,i):console.error("Unable to compute message"),r}function Hs(e){if(e.shouldConnect&&e.ws===null){const t=new e._WS(e.url);t.binaryType="arraybuffer",e.ws=t,e.wsconnecting=!0,e.wsconnected=!1,e.synced=!1,t.onmessage=n=>{if(n.data==="ping"){t.send("pong");return}e.wsLastMessageReceived=ct();const s=Fs(e,new Uint8Array(n.data),!0);Ae(s)>1&&t.send(S(s))},t.onerror=n=>{e.emit("connection-error",[n,e])},t.onclose=n=>{e.emit("connection-close",[n,e]),e.ws=null,e.wsconnecting=!1,e.wsconnected?(e.wsconnected=!1,e.synced=!1,cn(e.awareness,Array.from(e.awareness.getStates().keys()).filter(s=>s!==e.doc.clientID),e),e.emit("status",[{status:"disconnected"}])):e.wsUnsuccessfulReconnects++,setTimeout(Hs,De(Lr(2,e.wsUnsuccessfulReconnects)*100,e.maxBackoffTime),e)},t.onopen=()=>{e.wsLastMessageReceived=ct(),e.wsconnecting=!1,e.wsconnected=!0,e.wsUnsuccessfulReconnects=0,e.emit("status",[{status:"connected"}]);const n=M();if(p(n,ft),rn(n,e.doc),t.send(S(n)),e.awareness.getLocalState()!==null){const s=M();p(s,At),C(s,Jt(e.awareness,[e.doc.clientID])),t.send(S(s))}},e.emit("status",[{status:"connecting"}])}}function ln(e,t){const n=e.ws;e.wsconnected&&n&&n.readyState===n.OPEN&&n.send(t),e.bcconnected&&yt(e.bcChannel,t,e)}var Xo=class extends te{constructor(t,n,s,{connect:r=!0,awareness:i=new Fo(s),params:o={},WebSocketPolyfill:c=WebSocket,resyncInterval:l=-1,maxBackoffTime:a=2500,disableBc:h=!1}={}){super();b(this,"maxBackoffTime");b(this,"bcChannel");b(this,"url");b(this,"roomname");b(this,"doc");b(this,"_WS");b(this,"awareness");b(this,"wsconnected");b(this,"wsconnecting");b(this,"bcconnected");b(this,"disableBc");b(this,"wsUnsuccessfulReconnects");b(this,"messageHandlers");b(this,"_synced");b(this,"ws");b(this,"wsLastMessageReceived");b(this,"shouldConnect");b(this,"_resyncInterval");b(this,"_bcSubscriber");b(this,"_updateHandler");b(this,"_awarenessUpdateHandler");b(this,"_unloadHandler");b(this,"_checkInterval");for(;t[t.length-1]==="/";)t=t.slice(0,t.length-1);const u=$o(o);this.maxBackoffTime=a,this.bcChannel=t+"/"+n,this.url=t+"/"+n+(u.length===0?"":"?"+u),this.roomname=n,this.doc=s,this._WS=c,this.awareness=i,this.wsconnected=!1,this.wsconnecting=!1,this.bcconnected=!1,this.disableBc=h,this.wsUnsuccessfulReconnects=0,this.messageHandlers=Xt.slice(),this._synced=!1,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=r,this._resyncInterval=0,l>0&&(this._resyncInterval=setInterval(()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const d=M();p(d,ft),rn(d,s),this.ws.send(S(d))}},l)),this._bcSubscriber=(d,f)=>{if(f!==this){const g=Fs(this,new Uint8Array(d),!1);Ae(g)>1&&yt(this.bcChannel,S(g),this)}},this._updateHandler=(d,f)=>{if(f!==this){const g=M();p(g,ft),Oo(g,d),ln(this,S(g))}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:d,updated:f,removed:g},m)=>{const v=d.concat(f).concat(g),D=M();p(D,At),C(D,Jt(i,v)),ln(this,S(D))},this._unloadHandler=()=>{cn(this.awareness,[s.clientID],"window unload")},typeof window<"u"?window.addEventListener("unload",this._unloadHandler):typeof process<"u"&&process.on("exit",this._unloadHandler),i.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval(()=>{this.wsconnected&&Vs<ct()-this.wsLastMessageReceived&&(Ko(this.ws!==null,"ws must not be null"),this.ws.close())},Vs/10),r&&this.connect()}get synced(){return this._synced}set synced(t){this._synced!==t&&(this._synced=t,this.emit("synced",[t]),this.emit("sync",[t]))}destroy(){this._resyncInterval!==0&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),typeof window<"u"?window.removeEventListener("unload",this._unloadHandler):typeof process<"u"&&process.off("exit",this._unloadHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy()}connectBc(){if(this.disableBc)return;this.bcconnected||(ti(this.bcChannel,this._bcSubscriber),this.bcconnected=!0);const t=M();p(t,ft),rn(t,this.doc),yt(this.bcChannel,S(t),this);const n=M();p(n,ft),Rs(n,this.doc),yt(this.bcChannel,S(n),this);const s=M();p(s,Bs),yt(this.bcChannel,S(s),this);const r=M();p(r,At),C(r,Jt(this.awareness,[this.doc.clientID])),yt(this.bcChannel,S(r),this)}disconnectBc(){const t=M();p(t,At),C(t,Jt(this.awareness,[this.doc.clientID],new Map)),ln(this,S(t)),this.bcconnected&&(ei(this.bcChannel,this._bcSubscriber),this.bcconnected=!1)}disconnect(){this.shouldConnect=!1,this.disconnectBc(),this.ws!==null&&this.ws.close()}connect(){this.shouldConnect=!0,!this.wsconnected&&this.ws===null&&(Hs(this),this.connectBc())}};function $s(){if(crypto.randomUUID)return crypto.randomUUID();let e=new Date().getTime(),t=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){let s=Math.random()*16;return e>0?(s=(e+s)%16|0,e=Math.floor(e/16)):(s=(t+s)%16|0,t=Math.floor(t/16)),(n==="x"?s:s&3|8).toString(16)})}var Yo=class extends Xo{constructor(e,t,n,s={}){const r=`${e.startsWith("localhost:")||e.startsWith("127.0.0.1:")?"ws":"wss"}://${e}/party`;s.params===void 0?s.params={_pk:$s()}:s.params._pk=$s(),super(r,t,n,s)}};const gt=e=>bt((t,n)=>{e.onerror=s=>n(new Error(s.target.error)),e.onsuccess=s=>t(s.target.result)}),zo=(e,t)=>bt((n,s)=>{const r=indexedDB.open(e);r.onupgradeneeded=i=>t(i.target.result),r.onerror=i=>s(ot(i.target.error)),r.onsuccess=i=>{const o=i.target.result;o.onversionchange=()=>{o.close()},typeof addEventListener<"u"&&addEventListener("unload",()=>o.close()),n(o)}}),Go=e=>gt(indexedDB.deleteDatabase(e)),Wo=(e,t)=>t.forEach(n=>e.createObjectStore.apply(e,n)),Yt=(e,t,n="readwrite")=>{const s=e.transaction(t,n);return t.map(r=>sc(s,r))},js=(e,t)=>gt(e.count(t)),qo=(e,t)=>gt(e.get(t)),Ks=(e,t)=>gt(e.delete(t)),Qo=(e,t,n)=>gt(e.put(t,n)),an=(e,t)=>gt(e.add(t)),Zo=(e,t,n)=>gt(e.getAll(t,n)),Po=(e,t,n)=>{let s=null;return nc(e,t,r=>(s=r,!1),n).then(()=>s)},tc=(e,t=null)=>Po(e,t,"prev"),ec=(e,t)=>bt((n,s)=>{e.onerror=s,e.onsuccess=async r=>{const i=r.target.result;if(i===null||await t(i)===!1)return n();i.continue()}}),nc=(e,t,n,s="next")=>ec(e.openKeyCursor(t,s),r=>n(r.key)),sc=(e,t)=>e.objectStore(t),rc=(e,t)=>IDBKeyRange.upperBound(e,t),ic=(e,t)=>IDBKeyRange.lowerBound(e,t),hn="custom",Js="updates",Xs=500,Ys=(e,t=()=>{},n=()=>{})=>{const[s]=Yt(e.db,[Js]);return Zo(s,ic(e._dbref,!1)).then(r=>{e._destroyed||(t(s),_(e.doc,()=>{r.forEach(i=>qn(e.doc,i))},e,!1),n(s))}).then(()=>tc(s).then(r=>{e._dbref=r+1})).then(()=>js(s).then(r=>{e._dbsize=r})).then(()=>s)},oc=(e,t=!0)=>Ys(e).then(n=>{(t||e._dbsize>=Xs)&&an(n,Ke(e.doc)).then(()=>Ks(n,rc(e._dbref,!0))).then(()=>js(n).then(s=>{e._dbsize=s}))});class cc extends te{constructor(t,n){super(),this.doc=n,this.name=t,this._dbref=0,this._dbsize=0,this._destroyed=!1,this.db=null,this.synced=!1,this._db=zo(t,s=>Wo(s,[["updates",{autoIncrement:!0}],["custom"]])),this.whenSynced=bt(s=>this.on("synced",()=>s(this))),this._db.then(s=>{this.db=s,Ys(this,o=>an(o,Ke(n)),()=>{if(this._destroyed)return this;this.synced=!0,this.emit("synced",[this])})}),this._storeTimeout=1e3,this._storeTimeoutId=null,this._storeUpdate=(s,r)=>{if(this.db&&r!==this){const[i]=Yt(this.db,[Js]);an(i,s),++this._dbsize>=Xs&&(this._storeTimeoutId!==null&&clearTimeout(this._storeTimeoutId),this._storeTimeoutId=setTimeout(()=>{oc(this,!1),this._storeTimeoutId=null},this._storeTimeout))}},n.on("update",this._storeUpdate),this.destroy=this.destroy.bind(this),n.on("destroy",this.destroy)}destroy(){return this._storeTimeoutId&&clearTimeout(this._storeTimeoutId),this.doc.off("update",this._storeUpdate),this.doc.off("destroy",this.destroy),this._destroyed=!0,this._db.then(t=>{t.close()})}clearData(){return this.destroy().then(()=>{Go(this.name)})}get(t){return this._db.then(n=>{const[s]=Yt(n,[hn],"readonly");return qo(s,t)})}set(t,n){return this._db.then(s=>{const[r]=Yt(s,[hn]);return Qo(r,n,t)})}del(t){return this._db.then(n=>{const[s]=Yt(n,[hn]);return Ks(s,t)})}}const Cc="";var pt=(e=>(e.CanMove="can-move",e.CanSpin="can-spin",e.CanGrow="can-grow",e.CanToggle="can-toggle",e.CanPost="can-post",e))(pt||{});const lc=(e,t=300)=>{let n;return function(...s){clearTimeout(n),n=setTimeout(()=>e.apply(this,s),t)}},ac={ctrlKey:"Control",altKey:"Alt",shiftKey:"Shift",metaKey:"Meta"},zs=`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='44' height='53' viewport='0 0 100 100' style='fill:black;font-size:26px;'><text y='40%'>🚿</text></svg>")
5
5
  16 0,
6
- auto`,hc=`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='48' viewport='0 0 100 100' style='fill:black;font-size:24px;'><text y='50%'>✂️</text></svg>") 16 0,auto`;function un(e,{data:t,element:n,localData:s,setLocalData:r}){if(s.isHovering=!0,e.altKey){if(t.scale<=.5){n.style.cursor="not-allowed";return}n.style.cursor=hc}else{if(t.scale>=t.maxScale){n.style.cursor="not-allowed";return}n.style.cursor=zs}r(s)}const Gs={[pt.CanMove]:{defaultData:{x:0,y:0},defaultLocalData:{startMouseX:0,startMouseY:0},updateElement:({element:e,data:t})=>{e.style.transform=`translate(${t.x}px, ${t.y}px)`},onDragStart:(e,{setLocalData:t})=>{t({startMouseX:e.clientX,startMouseY:e.clientY})},onDrag:(e,{data:t,localData:n,setData:s,setLocalData:r})=>{r({startMouseX:e.pageX,startMouseY:e.pageY}),s({x:t.x+e.pageX-n.startMouseX,y:t.y+e.pageY-n.startMouseY})},resetShortcut:"shiftKey"},[pt.CanSpin]:{defaultData:{rotation:0},defaultLocalData:{startMouseX:0},updateElement:({element:e,data:t})=>{e.style.transform=`rotate(${t.rotation}deg)`},onDragStart:(e,{setLocalData:t})=>{t({startMouseX:e.clientX})},onDrag:(e,{data:t,localData:n,setData:s,setLocalData:r})=>{let i=Math.abs(e.pageX-n.startMouseX)*2,o=t.rotation;e.pageX>n.startMouseX?o+=i:e.pageX<n.startMouseX&&(o-=i),s({rotation:o}),r({startMouseX:e.pageX})},resetShortcut:"shiftKey"},[pt.CanToggle]:{defaultData:!1,updateElement:({element:e,data:t})=>{e.classList.toggle("clicked",t)},onClick:(e,{data:t,setData:n})=>{n(!t)},resetShortcut:"shiftKey"},[pt.CanGrow]:{defaultData:{scale:1,maxScale:2},defaultLocalData:{isHovering:!1},updateElement:({element:e,data:t})=>{e.style.transform=`scale(${t.scale})`},onClick:(e,{data:t,element:n,setData:s})=>{if(e.altKey){if(t.scale<=.5)return;t.scale-=.1}else{if(n.style.cursor=zs,t.scale>=t.maxScale)return;t.scale+=.1}s(t)},onMouseEnter:un,onKeyDown:un,onKeyUp:un},[pt.CanPost]:{defaultData:[],defaultLocalData:{addedEntries:new Set},updateElement:({element:e,data:t,localData:{addedEntries:n},setLocalData:s,setData:r})=>{const i=t.filter(c=>!n.has(c.id)),o=fn("guestbookMessages");i.forEach(c=>{const l=document.createElement("div");l.classList.add("guestbook-entry");const a=new Date(c.timestamp),h=a.toTimeString().split(" ")[0],u=a.toDateString()===new Date().toDateString();l.innerHTML=`
7
- <span class="guestbook-entry-timestamp">${u?"":a.toDateString()+" "}${h}</span><span class="guestbook-entry-name">${c.name}</span> <span class="guestbook-entry-message">${c.message}</span>`,o.prepend(l),n.add(c.id)}),s({addedEntries:n})},onSubmit:(e,{data:t,setData:n})=>{e.preventDefault(),e.stopImmediatePropagation();const s=new FormData(e.target),r=Object.fromEntries(s.entries()),i=Date.now(),o={name:"someone",message:"something",...r,timestamp:i,id:`${i}-${r.name}`};n([...t,o])}}};class uc{constructor({element:t,onChange:n,defaultData:s,defaultLocalData:r,data:i,updateElement:o,onClick:c,onDrag:l,onDragStart:a,onMouseEnter:h,onKeyDown:u,onKeyUp:d,onSubmit:f,resetShortcut:g,debounceMs:m}){b(this,"defaultData");b(this,"localData");b(this,"element");b(this,"_data");b(this,"onChange");b(this,"debouncedOnChange");b(this,"resetShortcut");b(this,"updateElement");this.element=t,this.defaultData=s,this.localData=r,this.onChange=n,this.resetShortcut=g,this.debouncedOnChange=lc(this.onChange,m),this.updateElement=o;const v=i===void 0?s:i;this._data=v,this.__data=v,c&&t.addEventListener("click",D=>{c(D,this.getEventHandlerData())}),l&&t.addEventListener("mousedown",D=>{a&&a(D,this.getEventHandlerData());const tr=gn=>{gn.preventDefault(),l(gn,this.getEventHandlerData())},er=gn=>{document.removeEventListener("mousemove",tr),document.removeEventListener("mouseup",er)};document.addEventListener("mousemove",tr),document.addEventListener("mouseup",er)}),h&&t.addEventListener("mouseenter",D=>{h(D,this.getEventHandlerData())}),u&&t.addEventListener("keydown",D=>{u(D,this.getEventHandlerData())}),d&&t.addEventListener("keyup",D=>{d(D,this.getEventHandlerData())}),f&&t.addEventListener("submit",D=>(D.preventDefault(),f(D,this.getEventHandlerData()),!1)),g&&(t.title||(t.title=`Hold down the ${ac[g]} key while clicking to reset.`),t.addEventListener("click",D=>{switch(g){case"ctrlKey":if(!D.ctrlKey)return;break;case"altKey":if(!D.altKey)return;break;case"shiftKey":if(!D.shiftKey)return;break;case"metaKey":if(!D.metaKey)return;break;default:return}this.reset(),D.preventDefault(),D.stopPropagation()}))}get data(){return this._data}setLocalData(t){this.localData=t}set __data(t){this._data=t,this.updateElement(this.getEventHandlerData())}getEventHandlerData(){return{element:this.element,data:this.data,localData:this.localData,setData:t=>this.setData(t),setLocalData:t=>this.setLocalData(t)}}setData(t){this.onChange(t)}setDataDebounced(t){this.debouncedOnChange(t)}reset(){this.setData(this.defaultData)}}const dc="playhtml.spencerc99.partykit.dev",dn=new kt,Ws=window.location.href,qs=new Yo(dc,Ws,dn,{connect:!1});new cc(Ws,dn),qs.connect();const W=dn.getMap("playhtml-global");function me(e){return e.id}function fn(e){return document.getElementById(e)}qs.on("sync",e=>{e||console.error("Issue connecting to yjs..."),Ps()});function Qs(e){return e instanceof HTMLElement}function Zs(e,t){const n=Gs[t],s=W.get(t),r=me(e),i={...n,data:s.get(r)||n.defaultData,element:e,onChange:o=>{s.get(r)!==o&&s.set(r,o)}};return new uc(i)}function Ps(){const e=new Map;console.log("EXISTING DATA",W.toJSON());for(const t of Object.values(pt)){const n=Array.from(document.querySelectorAll(`[${t}]`)).filter(Qs);if(!n.length||!Gs[t])continue;W.get(t)||W.set(t,new at);const r=W.get(t);for(const i of n){if(e.has(me(i)))continue;const o=Zs(i,t);e.set(me(i),o),i.classList.add("__playhtml-element"),i.classList.add(`__playhtml-${t}`)}r.observe(i=>{i.changes.keys.forEach((o,c)=>{if(o.action==="add"){const l=fn(c);if(!Qs(l)){console.log(`Element ${c} not an HTML element. Ignoring.`);return}if(e.has(c)){console.log(`Element ${c} already registered. Ignoring.`);return}const a=Zs(l,t);e.set(me(l),a)}else if(o.action==="update"){const l=e.get(c);l.__data=r.get(c)}else o.action==="delete"?e.delete(c):console.log(`Unhandled action: ${o.action}`)})})}W.observe(t=>{t.changes.keys.forEach((n,s)=>{n.action==="add"&&W.set(s,W.get(s))})})}T.getElementFromId=fn,T.globalData=W,T.setupElements=Ps,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
6
+ auto`,hc=`url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='48' viewport='0 0 100 100' style='fill:black;font-size:24px;'><text y='50%'>✂️</text></svg>") 16 0,auto`;function un(e,{data:t,element:n,localData:s,setLocalData:r}){if(s.isHovering=!0,e.altKey){if(t.scale<=.5){n.style.cursor="not-allowed";return}n.style.cursor=hc}else{if(t.scale>=t.maxScale){n.style.cursor="not-allowed";return}n.style.cursor=zs}r(s)}const Gs={[pt.CanMove]:{defaultData:{x:0,y:0},defaultLocalData:{startMouseX:0,startMouseY:0},updateElement:({element:e,data:t})=>{e.style.transform=`translate(${t.x}px, ${t.y}px)`},onDragStart:(e,{setLocalData:t})=>{t({startMouseX:e.clientX,startMouseY:e.clientY})},onDrag:(e,{data:t,localData:n,setData:s,setLocalData:r})=>{r({startMouseX:e.pageX,startMouseY:e.pageY}),s({x:t.x+e.pageX-n.startMouseX,y:t.y+e.pageY-n.startMouseY})},resetShortcut:"shiftKey"},[pt.CanSpin]:{defaultData:{rotation:0},defaultLocalData:{startMouseX:0},updateElement:({element:e,data:t})=>{e.style.transform=`rotate(${t.rotation}deg)`},onDragStart:(e,{setLocalData:t})=>{t({startMouseX:e.clientX})},onDrag:(e,{data:t,localData:n,setData:s,setLocalData:r})=>{let i=Math.abs(e.pageX-n.startMouseX)*2,o=t.rotation;e.pageX>n.startMouseX?o+=i:e.pageX<n.startMouseX&&(o-=i),s({rotation:o}),r({startMouseX:e.pageX})},resetShortcut:"shiftKey"},[pt.CanToggle]:{defaultData:!1,updateElement:({element:e,data:t})=>{e.classList.toggle("clicked",t)},onClick:(e,{data:t,setData:n})=>{n(!t)},resetShortcut:"shiftKey"},[pt.CanGrow]:{defaultData:{scale:1},defaultLocalData:{maxScale:2,isHovering:!1},updateElement:({element:e,data:t})=>{e.style.transform=`scale(${t.scale})`},onClick:(e,{data:t,element:n,setData:s,localData:r})=>{let{scale:i}=t;if(e.altKey){if(t.scale<=.5)return;i-=.1}else{if(n.style.cursor=zs,t.scale>=r.maxScale)return;i+=.1}s({...t,scale:i})},onMouseEnter:un,onKeyDown:un,onKeyUp:un},[pt.CanPost]:{defaultData:[],defaultLocalData:{addedEntries:new Set},updateElement:({data:e,localData:{addedEntries:t},setLocalData:n})=>{const s=e.filter(i=>!t.has(i.id)),r=fn("guestbookMessages");s.forEach(i=>{const o=document.createElement("div");o.classList.add("guestbook-entry");const c=new Date(i.timestamp),l=c.toTimeString().split(" ")[0],a=c.toDateString()===new Date().toDateString();o.innerHTML=`
7
+ <span class="guestbook-entry-timestamp">${a?"":c.toDateString()+" "}${l}</span><span class="guestbook-entry-name">${i.name}</span> <span class="guestbook-entry-message">${i.message}</span>`,r.prepend(o),t.add(i.id)}),n({addedEntries:t})},onSubmit:(e,{data:t,setData:n})=>{e.preventDefault(),e.stopImmediatePropagation();const s=new FormData(e.target),r=Object.fromEntries(s.entries()),i=Date.now(),o={name:"someone",message:"something",...r,timestamp:i,id:`${i}-${r.name}`};n([...t,o])}}};class uc{constructor({element:t,onChange:n,defaultData:s,defaultLocalData:r,data:i,updateElement:o,onClick:c,onDrag:l,onDragStart:a,onMouseEnter:h,onKeyDown:u,onKeyUp:d,onSubmit:f,resetShortcut:g,debounceMs:m}){b(this,"defaultData");b(this,"localData");b(this,"element");b(this,"_data");b(this,"onChange");b(this,"debouncedOnChange");b(this,"resetShortcut");b(this,"updateElement");this.element=t,this.defaultData=s,this.localData=r,this.onChange=n,this.resetShortcut=g,this.debouncedOnChange=lc(this.onChange,m),this.updateElement=o;const v=i===void 0?s:i;this._data=v,this.__data=v,c&&t.addEventListener("click",D=>{c(D,this.getEventHandlerData())}),l&&t.addEventListener("mousedown",D=>{a&&a(D,this.getEventHandlerData());const tr=gn=>{gn.preventDefault(),l(gn,this.getEventHandlerData())},er=gn=>{document.removeEventListener("mousemove",tr),document.removeEventListener("mouseup",er)};document.addEventListener("mousemove",tr),document.addEventListener("mouseup",er)}),h&&t.addEventListener("mouseenter",D=>{h(D,this.getEventHandlerData())}),u&&t.addEventListener("keydown",D=>{u(D,this.getEventHandlerData())}),d&&t.addEventListener("keyup",D=>{d(D,this.getEventHandlerData())}),f&&t.addEventListener("submit",D=>(D.preventDefault(),f(D,this.getEventHandlerData()),!1)),g&&(t.title||(t.title=`Hold down the ${ac[g]} key while clicking to reset.`),t.addEventListener("click",D=>{switch(g){case"ctrlKey":if(!D.ctrlKey)return;break;case"altKey":if(!D.altKey)return;break;case"shiftKey":if(!D.shiftKey)return;break;case"metaKey":if(!D.metaKey)return;break;default:return}this.reset(),D.preventDefault(),D.stopPropagation()}))}get data(){return this._data}setLocalData(t){this.localData=t}set __data(t){this._data=t,this.updateElement(this.getEventHandlerData())}getEventHandlerData(){return{element:this.element,data:this.data,localData:this.localData,setData:t=>this.setData(t),setLocalData:t=>this.setLocalData(t)}}setData(t){this.onChange(t)}setDataDebounced(t){this.debouncedOnChange(t)}reset(){this.setData(this.defaultData)}}const dc="playhtml.spencerc99.partykit.dev",dn=new kt,Ws=window.location.href,qs=new Yo(dc,Ws,dn,{connect:!1});new cc(Ws,dn),qs.connect();const W=dn.getMap("playhtml-global");function me(e){return e.id}function fn(e){return document.getElementById(e)}qs.on("sync",e=>{e||console.error("Issue connecting to yjs..."),Ps()});function Qs(e){return e instanceof HTMLElement}function Zs(e,t){const n=Gs[t],s=W.get(t),r=me(e),i={...n,data:s.get(r)||n.defaultData,element:e,onChange:o=>{s.get(r)!==o&&s.set(r,o)}};return new uc(i)}function Ps(){const e=new Map;console.log("EXISTING DATA",W.toJSON());for(const t of Object.values(pt)){const n=Array.from(document.querySelectorAll(`[${t}]`)).filter(Qs);if(!n.length||!Gs[t])continue;W.get(t)||W.set(t,new at);const r=W.get(t);for(const i of n){if(e.has(me(i)))continue;const o=Zs(i,t);e.set(me(i),o),i.classList.add("__playhtml-element"),i.classList.add(`__playhtml-${t}`)}r.observe(i=>{i.changes.keys.forEach((o,c)=>{if(o.action==="add"){const l=fn(c);if(!Qs(l)){console.log(`Element ${c} not an HTML element. Ignoring.`);return}if(e.has(c)){console.log(`Element ${c} already registered. Ignoring.`);return}const a=Zs(l,t);e.set(me(l),a)}else if(o.action==="update"){const l=e.get(c);l.__data=r.get(c)}else o.action==="delete"?e.delete(c):console.log(`Unhandled action: ${o.action}`)})})}W.observe(t=>{t.changes.keys.forEach((n,s)=>{n.action==="add"&&W.set(s,W.get(s))})})}T.getElementFromId=fn,T.globalData=W,T.setupElements=Ps,Object.defineProperty(T,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playhtml",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/playhtml.umd.js",