playhtml 2.1.6 → 2.1.8

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/CHANGELOG.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  The format is based on Keep a Changelog and this project adheres to Semantic Versioning.
4
4
 
5
- ## 2.1.3 - 2024-04-17
5
+ ## 2.1.6 - 2024-04-17
6
6
 
7
7
  - fix bug with native image dragging conflicting with playhtml draggable elements.
8
8
 
package/README.md CHANGED
@@ -225,7 +225,7 @@ Creates a rotatable element using a `rotate` `transform` on the element. Draggin
225
225
 
226
226
  ## Help & Community
227
227
 
228
- Join our [Discord community](https://discord.gg/h7sABTv8) to get help and show off what you've built!
228
+ Join our [Discord community](https://discord.gg/SKbsSf4ptU) to get help and show off what you've built!
229
229
 
230
230
  ## Data Policy
231
231
 
package/dist/main.d.ts CHANGED
@@ -94,9 +94,13 @@ export declare interface InitOptions<T = any> {
94
94
  */
95
95
  includeSearch?: boolean;
96
96
  };
97
+ /**
98
+ * Runs if playhtml fails to connect. Useful to show error messages and debugging.
99
+ */
100
+ onError?: () => void;
97
101
  }
98
102
 
99
- declare function initPlayHTML({ host, extraCapabilities, events, defaultRoomOptions, room: inputRoom, }?: InitOptions): Promise<YPartyKitProvider | undefined>;
103
+ declare function initPlayHTML({ host, extraCapabilities, events, defaultRoomOptions, room: inputRoom, onError, }?: InitOptions): Promise<YPartyKitProvider | undefined>;
100
104
 
101
105
  export declare const playhtml: PlayHTMLComponents;
102
106
 
@@ -127,7 +127,7 @@ let fi = class {
127
127
  this.cpos = 0, this.cbuf = new Uint8Array(100), this.bufs = [];
128
128
  }
129
129
  };
130
- const $ = () => new fi(), pn = (e) => {
130
+ const N = () => new fi(), pn = (e) => {
131
131
  let t = e.cpos;
132
132
  for (let n = 0; n < e.bufs.length; n++)
133
133
  t += e.bufs[n].length;
@@ -726,7 +726,7 @@ const Zt = () => new qt(), Ao = (e) => {
726
726
  for (let n = 0; n < e.bufs.length; n++)
727
727
  t += e.bufs[n].length;
728
728
  return t;
729
- }, N = (e) => {
729
+ }, B = (e) => {
730
730
  const t = new Uint8Array(Ao(e));
731
731
  let n = 0;
732
732
  for (let s = 0; s < e.bufs.length; s++) {
@@ -843,7 +843,7 @@ class ge {
843
843
  this.s === t ? this.count++ : (ts(this), this.count = 1, this.s = t);
844
844
  }
845
845
  toUint8Array() {
846
- return ts(this), N(this.encoder);
846
+ return ts(this), B(this.encoder);
847
847
  }
848
848
  }
849
849
  const es = (e) => {
@@ -863,7 +863,7 @@ class je {
863
863
  this.diff === t - this.s ? (this.s = t, this.count++) : (es(this), this.count = 1, this.diff = t - this.s, this.s = t);
864
864
  }
865
865
  toUint8Array() {
866
- return es(this), N(this.encoder);
866
+ return es(this), B(this.encoder);
867
867
  }
868
868
  }
869
869
  class Ro {
@@ -878,7 +878,7 @@ class Ro {
878
878
  }
879
879
  toUint8Array() {
880
880
  const t = new qt();
881
- return this.sarr.push(this.s), this.s = "", lt(t, this.sarr.join("")), Me(t, this.lensE.toUint8Array()), N(t);
881
+ return this.sarr.push(this.s), this.s = "", lt(t, this.sarr.join("")), Me(t, this.lensE.toUint8Array()), B(t);
882
882
  }
883
883
  }
884
884
  const $o = crypto.getRandomValues.bind(crypto), Ns = () => $o(new Uint32Array(1))[0], No = [1e7] + -1e3 + -4e3 + -8e3 + -1e11, Bo = () => No.replace(
@@ -1527,7 +1527,7 @@ class Ws {
1527
1527
  this.restEncoder = Zt();
1528
1528
  }
1529
1529
  toUint8Array() {
1530
- return N(this.restEncoder);
1530
+ return B(this.restEncoder);
1531
1531
  }
1532
1532
  resetDsCurVal() {
1533
1533
  }
@@ -1626,7 +1626,7 @@ class Ps {
1626
1626
  this.restEncoder = Zt(), this.dsCurrVal = 0;
1627
1627
  }
1628
1628
  toUint8Array() {
1629
- return N(this.restEncoder);
1629
+ return B(this.restEncoder);
1630
1630
  }
1631
1631
  resetDsCurVal() {
1632
1632
  this.dsCurrVal = 0;
@@ -1651,7 +1651,7 @@ class ht extends Ps {
1651
1651
  }
1652
1652
  toUint8Array() {
1653
1653
  const t = Zt();
1654
- return m(t, 0), L(t, this.keyClockEncoder.toUint8Array()), L(t, this.clientEncoder.toUint8Array()), L(t, this.leftClockEncoder.toUint8Array()), L(t, this.rightClockEncoder.toUint8Array()), L(t, N(this.infoEncoder)), L(t, this.stringEncoder.toUint8Array()), L(t, N(this.parentInfoEncoder)), L(t, this.typeRefEncoder.toUint8Array()), L(t, this.lenEncoder.toUint8Array()), Me(t, N(this.restEncoder)), N(t);
1654
+ return m(t, 0), L(t, this.keyClockEncoder.toUint8Array()), L(t, this.clientEncoder.toUint8Array()), L(t, this.leftClockEncoder.toUint8Array()), L(t, this.rightClockEncoder.toUint8Array()), L(t, B(this.infoEncoder)), L(t, this.stringEncoder.toUint8Array()), L(t, B(this.parentInfoEncoder)), L(t, this.typeRefEncoder.toUint8Array()), L(t, this.lenEncoder.toUint8Array()), Me(t, B(this.restEncoder)), B(t);
1655
1655
  }
1656
1656
  /**
1657
1657
  * @param {ID} id
@@ -2342,7 +2342,7 @@ const Dc = (e) => Se(e, Js, te), Ec = (e, t) => {
2342
2342
  const a = Cn(c);
2343
2343
  return Ot(i, a), i.toUint8Array();
2344
2344
  }, ir = (e) => {
2345
- e.written > 0 && (e.clientStructs.push({ written: e.written, restEncoder: N(e.encoder.restEncoder) }), e.encoder.restEncoder = Zt(), e.written = 0);
2345
+ e.written > 0 && (e.clientStructs.push({ written: e.written, restEncoder: B(e.encoder.restEncoder) }), e.encoder.restEncoder = Zt(), e.written = 0);
2346
2346
  }, et = (e, t, n) => {
2347
2347
  e.written > 0 && e.currClient !== t.id.client && ir(e), e.written === 0 && (e.currClient = t.id.client, e.encoder.writeClient(t.id.client), m(e.encoder.restEncoder, t.id.clock + n)), t.write(e.encoder, n), e.written++;
2348
2348
  }, Mn = (e) => {
@@ -5904,7 +5904,7 @@ const Rn = (e, t, n) => {
5904
5904
  );
5905
5905
  m(r, o), m(r, l), lt(r, JSON.stringify(c));
5906
5906
  }
5907
- return N(r);
5907
+ return B(r);
5908
5908
  }, yl = (e, t, n) => {
5909
5909
  const s = wt(t), r = ye(), i = [], o = [], c = [], l = [], a = w(s);
5910
5910
  for (let h = 0; h < a; h++) {
@@ -6001,7 +6001,7 @@ function Al(e, t) {
6001
6001
  ${t}`);
6002
6002
  }
6003
6003
  function Mr(e, t, n) {
6004
- const s = _i(t), r = $(), i = Ls(s), o = e.messageHandlers[i];
6004
+ const s = _i(t), r = N(), i = Ls(s), o = e.messageHandlers[i];
6005
6005
  return /** @type {any} */ o ? o(r, s, e, n, i) : console.error("Unable to compute message"), r;
6006
6006
  }
6007
6007
  function xr(e) {
@@ -6044,9 +6044,9 @@ function xr(e) {
6044
6044
  status: "connected"
6045
6045
  }
6046
6046
  ]);
6047
- const n = $();
6047
+ const n = N();
6048
6048
  if (v(n, it), hn(n, e.doc), Nt(U(n), t), e.awareness.getLocalState() !== null) {
6049
- const s = $();
6049
+ const s = N();
6050
6050
  v(s, At), Dt(
6051
6051
  s,
6052
6052
  Ft(e.awareness, [
@@ -6110,7 +6110,7 @@ var Ll = typeof WebSocket > "u" ? null : WebSocket, Il = class extends Ni {
6110
6110
  this.maxBackoffTime = a, this.bcChannel = t + "/" + n, this.url = t + "/" + n + (d.length === 0 ? "" : "?" + d), 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 = se.slice(), this._synced = !1, this.ws = null, this.wsLastMessageReceived = 0, this.shouldConnect = r, this._resyncInterval = 0, l > 0 && (this._resyncInterval = /** @type {any} */
6111
6111
  setInterval(() => {
6112
6112
  if (this.ws && this.ws.readyState === WebSocket.OPEN) {
6113
- const u = $();
6113
+ const u = N();
6114
6114
  v(u, it), hn(u, s), Nt(U(u), this.ws);
6115
6115
  }
6116
6116
  }, l)), this._bcSubscriber = (u, f) => {
@@ -6120,11 +6120,11 @@ var Ll = typeof WebSocket > "u" ? null : WebSocket, Il = class extends Ni {
6120
6120
  }
6121
6121
  }, this._updateHandler = (u, f) => {
6122
6122
  if (f !== this) {
6123
- const g = $();
6123
+ const g = N();
6124
6124
  v(g, it), Sl(g, u), We(this, U(g));
6125
6125
  }
6126
6126
  }, this.doc.on("update", this._updateHandler), this._awarenessUpdateHandler = ({ added: u, updated: f, removed: g }, p) => {
6127
- const _ = u.concat(f).concat(g), Y = $();
6127
+ const _ = u.concat(f).concat(g), Y = N();
6128
6128
  v(Y, At), Dt(
6129
6129
  Y,
6130
6130
  Ft(i, _)
@@ -6156,17 +6156,17 @@ var Ll = typeof WebSocket > "u" ? null : WebSocket, Il = class extends Ni {
6156
6156
  if (this.disableBc)
6157
6157
  return;
6158
6158
  this.bcconnected || (Ri(this.bcChannel, this._bcSubscriber), this.bcconnected = !0);
6159
- const t = $();
6159
+ const t = N();
6160
6160
  v(t, it), hn(t, this.doc), St(this.bcChannel, U(t), this);
6161
- const n = $();
6161
+ const n = N();
6162
6162
  v(n, it), Lr(n, this.doc), St(this.bcChannel, U(n), this);
6163
- const s = $();
6163
+ const s = N();
6164
6164
  v(s, vr), St(
6165
6165
  this.bcChannel,
6166
6166
  U(s),
6167
6167
  this
6168
6168
  );
6169
- const r = $();
6169
+ const r = N();
6170
6170
  v(r, At), Dt(
6171
6171
  r,
6172
6172
  Ft(this.awareness, [
@@ -6179,7 +6179,7 @@ var Ll = typeof WebSocket > "u" ? null : WebSocket, Il = class extends Ni {
6179
6179
  );
6180
6180
  }
6181
6181
  disconnectBc() {
6182
- const t = $();
6182
+ const t = N();
6183
6183
  v(t, At), Dt(
6184
6184
  t,
6185
6185
  Ft(
@@ -6366,19 +6366,14 @@ class Yl extends vs {
6366
6366
  });
6367
6367
  }
6368
6368
  }
6369
- const Xl = {
6370
- ctrlKey: "Control",
6371
- altKey: "Alt",
6372
- shiftKey: "Shift",
6373
- metaKey: "Meta"
6374
- }, Jl = "can-duplicate-to";
6369
+ const Xl = "can-duplicate-to";
6375
6370
  var Re = /* @__PURE__ */ ((e) => (e.CanPlay = "can-play", e.CanMove = "can-move", e.CanSpin = "can-spin", e.CanGrow = "can-grow", e.CanToggle = "can-toggle", e.CanDuplicate = "can-duplicate", e.CanHover = "can-hover", e.CanResize = "can-resize", e.CanMirror = "can-mirror", e))(Re || {});
6376
- function Wl(e) {
6371
+ function Jl(e) {
6377
6372
  return e.id;
6378
6373
  }
6379
6374
  const Nr = `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>")
6380
6375
  16 0,
6381
- auto`, Pl = `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`;
6376
+ auto`, Wl = `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`;
6382
6377
  function ps(e, { getData: t, getElement: n, getLocalData: s, setLocalData: r }) {
6383
6378
  const i = t(), o = s(), c = n();
6384
6379
  if (o.isHovering = !0, e.altKey) {
@@ -6386,7 +6381,7 @@ function ps(e, { getData: t, getElement: n, getLocalData: s, setLocalData: r })
6386
6381
  c.style.cursor = "not-allowed";
6387
6382
  return;
6388
6383
  }
6389
- c.style.cursor = Pl;
6384
+ c.style.cursor = Wl;
6390
6385
  } else {
6391
6386
  if (i.scale >= i.maxScale) {
6392
6387
  c.style.cursor = "not-allowed";
@@ -6403,7 +6398,7 @@ function he(e) {
6403
6398
  }
6404
6399
  return { clientX: e.clientX, clientY: e.clientY };
6405
6400
  }
6406
- const Gl = {
6401
+ const Pl = {
6407
6402
  [
6408
6403
  "can-move"
6409
6404
  /* CanMove */
@@ -6521,7 +6516,7 @@ const Gl = {
6521
6516
  );
6522
6517
  return;
6523
6518
  }
6524
- const l = s.getAttribute(Jl);
6519
+ const l = s.getAttribute(Xl);
6525
6520
  function a(d) {
6526
6521
  if (l) {
6527
6522
  const u = document.getElementById(l) || document.querySelector(l);
@@ -6568,8 +6563,8 @@ const Gl = {
6568
6563
  defaultData: (e) => Gt(e),
6569
6564
  onMount: ({ getElement: e, setData: t, getData: n }) => {
6570
6565
  const s = e();
6571
- ql(s, (r) => {
6572
- const i = n(), o = Ql(i, r);
6566
+ Gl(s, (r) => {
6567
+ const i = n(), o = Zl(i, r);
6573
6568
  t(o);
6574
6569
  });
6575
6570
  },
@@ -6592,7 +6587,7 @@ function Le(e, t) {
6592
6587
  return !1;
6593
6588
  return !0;
6594
6589
  }
6595
- function ql(e, t, n) {
6590
+ function Gl(e, t, n) {
6596
6591
  const s = { childList: !0, attributes: !0, subtree: !0, characterData: !0, ...n }, r = (o) => {
6597
6592
  const c = o.filter((l) => {
6598
6593
  if (s.childList && l.type === "childList")
@@ -6609,32 +6604,32 @@ function ql(e, t, n) {
6609
6604
  }, i = new MutationObserver(r);
6610
6605
  return i.observe(e, s), i;
6611
6606
  }
6612
- function Zl(e) {
6607
+ function ql(e) {
6613
6608
  return JSON.parse(JSON.stringify(e));
6614
6609
  }
6615
- function Ql(e, t) {
6616
- let n = Zl(e);
6610
+ function Zl(e, t) {
6611
+ let n = ql(e);
6617
6612
  return t.forEach((s) => {
6618
6613
  switch (s.type) {
6619
6614
  case "attributes":
6620
- ta(n, s);
6615
+ Ql(n, s);
6621
6616
  break;
6622
6617
  case "childList":
6623
- ea(n, s);
6618
+ ta(n, s);
6624
6619
  break;
6625
6620
  case "characterData":
6626
- na(n, s);
6621
+ ea(n, s);
6627
6622
  break;
6628
6623
  }
6629
6624
  }), n;
6630
6625
  }
6631
- function ta(e, t) {
6626
+ function Ql(e, t) {
6632
6627
  if (t.target instanceof HTMLElement) {
6633
6628
  const n = t.attributeName, s = t.target.getAttribute(n);
6634
6629
  s !== null ? e.attributes[n] = s : delete e.attributes[n];
6635
6630
  }
6636
6631
  }
6637
- function ea(e, t) {
6632
+ function ta(e, t) {
6638
6633
  t.addedNodes.length && t.addedNodes.forEach((n) => {
6639
6634
  if (!(n instanceof HTMLElement))
6640
6635
  return;
@@ -6649,7 +6644,7 @@ function ea(e, t) {
6649
6644
  r !== -1 && e.children.splice(r, 1);
6650
6645
  });
6651
6646
  }
6652
- function na(e, t) {
6647
+ function ea(e, t) {
6653
6648
  t.target === e && (e.textContent = t.target.textContent);
6654
6649
  }
6655
6650
  function Gt(e) {
@@ -6666,9 +6661,9 @@ function Gt(e) {
6666
6661
  }), t;
6667
6662
  }
6668
6663
  function Br(e, t) {
6669
- sa(e, t), t.children.length === 0 && e.textContent !== t.textContent ? e.textContent = t.textContent : t.children.length > 0 && ra(e, t);
6664
+ na(e, t), t.children.length === 0 && e.textContent !== t.textContent ? e.textContent = t.textContent : t.children.length > 0 && sa(e, t);
6670
6665
  }
6671
- function sa(e, t) {
6666
+ function na(e, t) {
6672
6667
  if (t) {
6673
6668
  for (const [n, s] of Object.entries(t.attributes))
6674
6669
  e.getAttribute(n) !== s && e.setAttribute(n, s);
@@ -6677,7 +6672,7 @@ function sa(e, t) {
6677
6672
  });
6678
6673
  }
6679
6674
  }
6680
- function ra(e, t) {
6675
+ function sa(e, t) {
6681
6676
  const n = /* @__PURE__ */ new Set();
6682
6677
  t.children.forEach((s) => {
6683
6678
  let r = Array.from(e.children).find(
@@ -6694,7 +6689,7 @@ const ws = (e, t = 300) => {
6694
6689
  clearTimeout(n), n = setTimeout(() => e.apply(this, s), t);
6695
6690
  };
6696
6691
  };
6697
- class ia {
6692
+ class ra {
6698
6693
  constructor(t) {
6699
6694
  y(this, "defaultData");
6700
6695
  y(this, "localData");
@@ -6754,25 +6749,25 @@ class ia {
6754
6749
  (f = this.onClick) == null || f.call(this, u, this.getEventHandlerData());
6755
6750
  }), this.onClick = o, c && !this.onDrag && (t.addEventListener("touchstart", (u) => {
6756
6751
  var p;
6757
- u.preventDefault(), (p = this.onDragStart) == null || p.call(this, u, this.getEventHandlerData());
6752
+ u.preventDefault(), t.classList.add("cursordown"), (p = this.onDragStart) == null || p.call(this, u, this.getEventHandlerData());
6758
6753
  const f = (_) => {
6759
6754
  var Y;
6760
6755
  _.preventDefault(), (Y = this.onDrag) == null || Y.call(this, _, this.getEventHandlerData());
6761
6756
  }, g = (_) => {
6762
- document.removeEventListener("touchmove", f), document.removeEventListener("touchend", g);
6757
+ t.classList.remove("cursordown"), document.removeEventListener("touchmove", f), document.removeEventListener("touchend", g);
6763
6758
  };
6764
6759
  document.addEventListener("touchmove", f), document.addEventListener("touchend", g);
6765
6760
  }), t.addEventListener("mousedown", (u) => {
6766
6761
  var p;
6767
- u.preventDefault(), (p = this.onDragStart) == null || p.call(this, u, this.getEventHandlerData());
6762
+ u.preventDefault(), (p = this.onDragStart) == null || p.call(this, u, this.getEventHandlerData()), t.classList.add("cursordown");
6768
6763
  const f = (_) => {
6769
6764
  var Y;
6770
6765
  _.preventDefault(), (Y = this.onDrag) == null || Y.call(this, _, this.getEventHandlerData());
6771
6766
  }, g = (_) => {
6772
- document.removeEventListener("mousemove", f), document.removeEventListener("mouseup", g);
6767
+ t.classList.remove("cursordown"), document.removeEventListener("mousemove", f), document.removeEventListener("mouseup", g);
6773
6768
  };
6774
6769
  document.addEventListener("mousemove", f), document.addEventListener("mouseup", g);
6775
- })), this.onDrag = c, this.onDragStart = l, a && !this.resetShortcut && (t.title || (t.title = `Hold down the ${Xl[a]} key while clicking to reset.`), t.reset = this.reset, t.addEventListener("click", (u) => {
6770
+ })), this.onDrag = c, this.onDragStart = l, a && !this.resetShortcut && (t.reset = this.reset, t.addEventListener("click", (u) => {
6776
6771
  switch (this.resetShortcut) {
6777
6772
  case "ctrlKey":
6778
6773
  if (!u.ctrlKey)
@@ -6864,25 +6859,25 @@ class ia {
6864
6859
  this.setData(this.defaultData);
6865
6860
  }
6866
6861
  }
6867
- async function oa(e, t) {
6862
+ async function ia(e, t) {
6868
6863
  const n = new TextEncoder().encode(`${e}-${t.outerHTML}}`), s = await crypto.subtle.digest("SHA-1", n);
6869
6864
  return Array.from(new Uint8Array(s)).map((o) => o.toString(16).padStart(2, "0")).join("");
6870
6865
  }
6871
- const ca = "playhtml.spencerc99.partykit.dev", dn = new mt();
6872
- function la(e) {
6866
+ const oa = "playhtml.spencerc99.partykit.dev", dn = new mt();
6867
+ function ca(e) {
6873
6868
  const t = window.location.pathname.replace(/\.[^/.]+$/, "");
6874
6869
  return e ? t + window.location.search : t;
6875
6870
  }
6876
- let B, W = dn.getMap("playhtml-global"), R = /* @__PURE__ */ new Map(), gt = /* @__PURE__ */ new Map();
6871
+ let R, W = dn.getMap("playhtml-global"), $ = /* @__PURE__ */ new Map(), gt = /* @__PURE__ */ new Map();
6877
6872
  const ms = /* @__PURE__ */ new Map();
6878
- let aa = 0, re = Gl;
6873
+ let la = 0, re = Pl;
6879
6874
  function Vr() {
6880
6875
  return [Re.CanPlay, ...Object.keys(re)];
6881
6876
  }
6882
- function ha(e) {
6883
- B.ws && B.ws.send(JSON.stringify(e));
6877
+ function aa(e) {
6878
+ R.ws && R.ws.send(JSON.stringify(e));
6884
6879
  }
6885
- function ua(e) {
6880
+ function ha(e) {
6886
6881
  if (e.data instanceof Blob)
6887
6882
  return;
6888
6883
  let t;
@@ -6897,19 +6892,20 @@ function ua(e) {
6897
6892
  i.onEvent(s);
6898
6893
  }
6899
6894
  let Lt = !1, fn = !0;
6900
- async function da({
6895
+ async function ua({
6901
6896
  // TODO: if it is a localhost url, need to make some deterministic way to connect to the same room.
6902
- host: e = ca,
6897
+ host: e = oa,
6903
6898
  extraCapabilities: t,
6904
6899
  events: n,
6905
6900
  defaultRoomOptions: s = {},
6906
- room: r = la(s.includeSearch)
6901
+ room: r = ca(s.includeSearch),
6902
+ onError: i
6907
6903
  } = {}) {
6908
6904
  if (!fn) {
6909
6905
  console.error("playhtml already set up!");
6910
6906
  return;
6911
6907
  }
6912
- const i = encodeURIComponent(window.location.hostname + "-" + r), o = e;
6908
+ const o = encodeURIComponent(window.location.hostname + "-" + r), c = e;
6913
6909
  if (console.log(
6914
6910
  `࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂
6915
6911
  ࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
@@ -6917,21 +6913,23 @@ async function da({
6917
6913
  ࿂࿂࿂࿂ https://playhtml.fun ࿂࿂࿂࿂
6918
6914
  ࿂࿂࿂࿂ ࿂ ࿂ ࿂ ࿂ ࿂࿂࿂࿂
6919
6915
  ࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂࿂`
6920
- ), B = new Ml(o, i, dn), new Yl(i, dn), t)
6921
- for (const [l, a] of Object.entries(t))
6922
- re[l] = a;
6916
+ ), R = new Ml(c, o, dn), R.on("error", () => {
6917
+ i == null || i();
6918
+ }), new Yl(o, dn), t)
6919
+ for (const [a, h] of Object.entries(t))
6920
+ re[a] = h;
6923
6921
  if (n)
6924
- for (const [l, a] of Object.entries(n))
6925
- zr(l, a);
6926
- const c = document.createElement("link");
6927
- return c.rel = "stylesheet", c.href = "https://unpkg.com/playhtml@latest/dist/style.css", document.head.appendChild(c), await new Promise((l) => {
6928
- Lt && l(!0), B.on("sync", (a) => {
6929
- a ? a && B.ws.addEventListener("message", ua) : console.error("Issue connecting to yjs..."), !Lt && (Lt = !0, console.log("[PLAYHTML]: Setting up elements... Time to have some fun 🛝"), jr(), l(!0));
6922
+ for (const [a, h] of Object.entries(n))
6923
+ zr(a, h);
6924
+ const l = document.createElement("link");
6925
+ return l.rel = "stylesheet", l.href = "https://unpkg.com/playhtml@latest/dist/style.css", document.head.appendChild(l), await new Promise((a) => {
6926
+ Lt && a(!0), R.on("sync", (h) => {
6927
+ h ? h && R.ws.addEventListener("message", ha) : console.error("Issue connecting to yjs..."), !Lt && (Lt = !0, console.log("[PLAYHTML]: Setting up elements... Time to have some fun 🛝"), jr(), a(!0));
6930
6928
  });
6931
- }), B;
6929
+ }), R;
6932
6930
  }
6933
- function fa(e, t) {
6934
- const n = B.awareness.getLocalState();
6931
+ function da(e, t) {
6932
+ const n = R.awareness.getLocalState();
6935
6933
  return ((n == null ? void 0 : n[e]) ?? {})[t];
6936
6934
  }
6937
6935
  function Nn(e) {
@@ -6951,31 +6949,31 @@ function Fr(e, t) {
6951
6949
  }
6952
6950
  return !1;
6953
6951
  }
6954
- function ga(e, t, n, s) {
6952
+ function fa(e, t, n, s) {
6955
6953
  const r = W.get(t);
6956
6954
  return {
6957
6955
  ...n,
6958
6956
  // TODO: when adding save-state if no save state, then just use defaultData
6959
6957
  data: r.get(s) ?? (n.defaultData instanceof Function ? n.defaultData(e) : n.defaultData),
6960
- awareness: fa(t, s) ?? n.myDefaultAwareness !== void 0 ? [n.myDefaultAwareness] : void 0,
6958
+ awareness: da(t, s) ?? n.myDefaultAwareness !== void 0 ? [n.myDefaultAwareness] : void 0,
6961
6959
  element: e,
6962
6960
  onChange: (o) => {
6963
6961
  Fr(r.get(s), o) || r.set(s, o);
6964
6962
  },
6965
6963
  onAwarenessChange: (o) => {
6966
6964
  var l;
6967
- const c = ((l = B.awareness.getLocalState()) == null ? void 0 : l[t]) || {};
6968
- c[s] !== o && (c[s] = o, B.awareness.setLocalStateField(t, c));
6965
+ const c = ((l = R.awareness.getLocalState()) == null ? void 0 : l[t]) || {};
6966
+ c[s] !== o && (c[s] = o, R.awareness.setLocalStateField(t, c));
6969
6967
  },
6970
6968
  triggerAwarenessUpdate: () => {
6971
6969
  Hr();
6972
6970
  }
6973
6971
  };
6974
6972
  }
6975
- function pa(e) {
6973
+ function ga(e) {
6976
6974
  return e.defaultData !== void 0 && (typeof e.defaultData == "object" || typeof e.defaultData == "function") && e.updateElement !== void 0;
6977
6975
  }
6978
- function wa(e, t) {
6976
+ function pa(e, t) {
6979
6977
  if (e === Re.CanPlay) {
6980
6978
  const n = t;
6981
6979
  return {
@@ -7002,10 +7000,10 @@ function Hr() {
7002
7000
  const o = e.get(n);
7003
7001
  o.has(s) || o.set(s, /* @__PURE__ */ new Map()), o.get(s).set(r, i);
7004
7002
  }
7005
- B.awareness.getStates().forEach((n, s) => {
7003
+ R.awareness.getStates().forEach((n, s) => {
7006
7004
  var r;
7007
7005
  for (const [i, o] of Object.entries(n)) {
7008
- const c = R.get(i);
7006
+ const c = $.get(i);
7009
7007
  if (c)
7010
7008
  for (const [l, a] of c) {
7011
7009
  if (!(l in o))
@@ -7020,7 +7018,7 @@ function Hr() {
7020
7018
  }
7021
7019
  }
7022
7020
  for (const [i, o] of e) {
7023
- const c = R.get(i);
7021
+ const c = $.get(i);
7024
7022
  if (c)
7025
7023
  for (const [l, a] of c) {
7026
7024
  const h = (r = o.get(l)) == null ? void 0 : r.values();
@@ -7046,31 +7044,31 @@ function jr() {
7046
7044
  e.changes.keys.forEach((t, n) => {
7047
7045
  t.action === "add" && W.set(n, W.get(n));
7048
7046
  });
7049
- }), B.awareness.on("change", () => Hr()), fn = !1);
7047
+ }), R.awareness.on("change", () => Hr()), fn = !1);
7050
7048
  }
7051
7049
  }
7052
- const ma = {
7053
- init: da,
7050
+ const wa = {
7051
+ init: ua,
7054
7052
  setupPlayElements: jr,
7055
- setupPlayElement: Sa,
7056
- removePlayElement: _a,
7053
+ setupPlayElement: ba,
7054
+ removePlayElement: Sa,
7057
7055
  setupPlayElementForTag: $e,
7058
7056
  globalData: W,
7059
- elementHandlers: R,
7057
+ elementHandlers: $,
7060
7058
  eventHandlers: gt,
7061
- dispatchPlayEvent: ka,
7059
+ dispatchPlayEvent: _a,
7062
7060
  registerPlayEventListener: zr,
7063
- removePlayEventListener: Da
7061
+ removePlayEventListener: ka
7064
7062
  };
7065
- window.playhtml = ma;
7066
- function ya(e) {
7067
- if (R.has(e) || !Lt)
7063
+ window.playhtml = wa;
7064
+ function ma(e) {
7065
+ if ($.has(e) || !Lt)
7068
7066
  return;
7069
- R.has(e) || R.set(e, /* @__PURE__ */ new Map()), e !== Re.CanPlay && re[e], W.get(e) || W.set(e, new ut());
7067
+ $.has(e) || $.set(e, /* @__PURE__ */ new Map()), e !== Re.CanPlay && re[e], W.get(e) || W.set(e, new ut());
7070
7068
  const t = W.get(e);
7071
7069
  t.observe((n) => {
7072
7070
  n.changes.keys.forEach((s, r) => {
7073
- const i = R.get(e);
7071
+ const i = $.get(e);
7074
7072
  if (s.action === "add") {
7075
7073
  const o = document.getElementById(r);
7076
7074
  if (!Nn(o)) {
@@ -7086,13 +7084,13 @@ function ya(e) {
7086
7084
  });
7087
7085
  });
7088
7086
  }
7089
- function ba(e, t) {
7087
+ function ya(e, t) {
7090
7088
  var n, s;
7091
7089
  return ((s = (n = re[t]) == null ? void 0 : n.isValidElementForTag) == null ? void 0 : s.call(n, e)) ?? !0;
7092
7090
  }
7093
7091
  async function $e(e, t) {
7094
7092
  var c;
7095
- if (!ba(e, t) || !Lt)
7093
+ if (!ya(e, t) || !Lt)
7096
7094
  return;
7097
7095
  if (!e.id) {
7098
7096
  const l = e.getAttribute("selector-id");
@@ -7100,27 +7098,27 @@ async function $e(e, t) {
7100
7098
  const a = ms.get(l) ?? 0;
7101
7099
  e.id = btoa(`${t}-${l}-${a}`), ms.set(l, a + 1);
7102
7100
  } else
7103
- e.id = await oa(t, e);
7101
+ e.id = await ia(t, e);
7104
7102
  }
7105
- const n = Wl(e);
7103
+ const n = Jl(e);
7106
7104
  if (!n) {
7107
7105
  console.error(
7108
7106
  `Element ${e} does not have an acceptable ID. Please add an ID to the element to register it as a playhtml element.`
7109
7107
  );
7110
7108
  return;
7111
7109
  }
7112
- ya(t);
7113
- const s = R.get(t), r = wa(
7110
+ ma(t);
7111
+ const s = $.get(t), r = pa(
7114
7112
  t,
7115
7113
  e
7116
7114
  );
7117
- if (!pa(r)) {
7115
+ if (!ga(r)) {
7118
7116
  console.error(
7119
7117
  `Element ${n} does not have proper info to initial a playhtml element. Please refer to https://github.com/spencerc99/playhtml#can-play for troubleshooting help.`
7120
7118
  );
7121
7119
  return;
7122
7120
  }
7123
- const i = W.get(t), o = ga(
7121
+ const i = W.get(t), o = fa(
7124
7122
  e,
7125
7123
  t,
7126
7124
  r,
@@ -7130,17 +7128,17 @@ async function $e(e, t) {
7130
7128
  s.get(n).reinitializeElementData(o);
7131
7129
  return;
7132
7130
  } else
7133
- s.set(n, new ia(o));
7131
+ s.set(n, new ra(o));
7134
7132
  i.get(n) === void 0 && r.defaultData !== void 0 && i.set(
7135
7133
  n,
7136
7134
  r.defaultData instanceof Function ? r.defaultData(e) : r.defaultData
7137
7135
  ), (c = o.triggerAwarenessUpdate) == null || c.call(o), e.classList.add("__playhtml-element"), e.classList.add(`__playhtml-${t}`), e.style.setProperty("--jiggle-delay", `${Math.random() * 1}s;}`);
7138
7136
  }
7139
- function Sa(e, { ignoreIfAlreadySetup: t } = {}) {
7140
- if (!(t && Object.keys(R || {}).some(
7137
+ function ba(e, { ignoreIfAlreadySetup: t } = {}) {
7138
+ if (!(t && Object.keys($ || {}).some(
7141
7139
  (n) => {
7142
7140
  var s;
7143
- return (s = R.get(n)) == null ? void 0 : s.has(e.id);
7141
+ return (s = $.get(n)) == null ? void 0 : s.has(e.id);
7144
7142
  }
7145
7143
  ))) {
7146
7144
  if (!Nn(e)) {
@@ -7152,29 +7150,29 @@ function Sa(e, { ignoreIfAlreadySetup: t } = {}) {
7152
7150
  );
7153
7151
  }
7154
7152
  }
7155
- function _a(e) {
7153
+ function Sa(e) {
7156
7154
  if (!(!e || !e.id))
7157
- for (const t of Object.keys(R)) {
7158
- const n = R.get(t);
7155
+ for (const t of Object.keys($)) {
7156
+ const n = $.get(t);
7159
7157
  n.has(e.id) && n.delete(e.id);
7160
7158
  }
7161
7159
  }
7162
- function ka(e) {
7160
+ function _a(e) {
7163
7161
  const { type: t } = e;
7164
7162
  if (!gt.has(t)) {
7165
7163
  console.error(`[playhtml] event "${t}" not registered.`);
7166
7164
  return;
7167
7165
  }
7168
- ha(e);
7166
+ aa(e);
7169
7167
  }
7170
7168
  function zr(e, t) {
7171
- const n = String(aa++);
7169
+ const n = String(la++);
7172
7170
  return gt.set(e, [
7173
7171
  ...gt.get(e) ?? [],
7174
7172
  { type: e, ...t, id: n }
7175
7173
  ]), n;
7176
7174
  }
7177
- function Da(e, t) {
7175
+ function ka(e, t) {
7178
7176
  const n = gt.get(e);
7179
7177
  if (!n)
7180
7178
  return;
@@ -7182,5 +7180,5 @@ function Da(e, t) {
7182
7180
  s !== -1 && (n.splice(s, 1), n.length === 0 && gt.delete(e));
7183
7181
  }
7184
7182
  export {
7185
- ma as playhtml
7183
+ wa as playhtml
7186
7184
  };
package/dist/style.css CHANGED
@@ -1 +1 @@
1
- @charset "UTF-8";.__playhtml-can-move{cursor:pointer;transition:transform .15s;will-change:transform}.__playhtml-can-spin,.__playhtml-can-grow{cursor:pointer;transition:transform .25s;will-change:transform}.__playhtml-can-toggle,.__playhtml-can-draw{cursor:pointer}.__playhtml-can-draw .__playhtml-draw-container{position:relative;width:100%;height:100%;cursor:none}.__playhtml-can-draw .__playhtml-draw-container canvas{position:absolute;top:0;left:0;cursor:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewport='0 0 100 100' style='overflow: visible; fill:black;font-size:20px;'><text y='-30%' x='-50%' style='transform:rotate(180deg)'>🖍️</text></svg>") 16 0,auto}body .__playhtml-element.editing:nth-child(2n){animation-name:jiggle1;animation-iteration-count:infinite;transform-origin:50% 10%;animation-duration:.25s;animation-delay:var(--jiggle-delay)}body .__playhtml-element.editing:nth-child(2n-1){animation-name:jiggle2;animation-iteration-count:infinite;animation-direction:alternate;transform-origin:30% 5%;animation-duration:.45s;animation-delay:var(--jiggle-delay)}@keyframes jiggle1{0%{transform:rotate(-1deg);animation-timing-function:ease-in}50%{transform:rotate(1.5deg);animation-timing-function:ease-out}}@keyframes jiggle2{0%{transform:rotate(1deg);animation-timing-function:ease-in}50%{transform:rotate(-1.5deg);animation-timing-function:ease-out}}
1
+ @charset "UTF-8";.__playhtml-can-move{cursor:grab;transition:transform .15s;will-change:transform}.__playhtml-can-move.cursordown{cursor:grabbing}.__playhtml-can-spin{cursor:grab;transition:transform .25s;will-change:transform}.__playhtml-can-spin.cursordown{cursor:grabbing}.__playhtml-can-grow{cursor:pointer;transition:transform .25s;will-change:transform}.__playhtml-can-toggle,.__playhtml-can-draw{cursor:pointer}.__playhtml-can-draw .__playhtml-draw-container{position:relative;width:100%;height:100%;cursor:none}.__playhtml-can-draw .__playhtml-draw-container canvas{position:absolute;top:0;left:0;cursor:url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewport='0 0 100 100' style='overflow: visible; fill:black;font-size:20px;'><text y='-30%' x='-50%' style='transform:rotate(180deg)'>🖍️</text></svg>") 16 0,auto}body .__playhtml-element.editing:nth-child(2n){animation-name:jiggle1;animation-iteration-count:infinite;transform-origin:50% 10%;animation-duration:.25s;animation-delay:var(--jiggle-delay)}body .__playhtml-element.editing:nth-child(2n-1){animation-name:jiggle2;animation-iteration-count:infinite;animation-direction:alternate;transform-origin:30% 5%;animation-duration:.45s;animation-delay:var(--jiggle-delay)}@keyframes jiggle1{0%{transform:rotate(-1deg);animation-timing-function:ease-in}50%{transform:rotate(1.5deg);animation-timing-function:ease-out}}@keyframes jiggle2{0%{transform:rotate(1deg);animation-timing-function:ease-in}50%{transform:rotate(-1.5deg);animation-timing-function:ease-out}}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "playhtml",
3
3
  "title": "playhtml",
4
4
  "description": "Create interactive, collaborative html elements with a single attribute",
5
- "version": "2.1.6",
5
+ "version": "2.1.8",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "keywords": [