@commentkit/comment-kit 0.7.7 → 1.0.0-beta.0

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.
Files changed (109) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +108 -762
  3. package/SECURITY.md +19 -14
  4. package/dist/npm/THIRD_PARTY_NOTICES.txt +73 -0
  5. package/dist/npm/chunks/anchor-DT-Ynhh1.js +270 -0
  6. package/dist/npm/chunks/client-D1vrh_5G.js +590 -0
  7. package/dist/{shared/capture-colors-D0uLr-vZ.js → npm/chunks/colors-CX-IPjvb.js} +2 -0
  8. package/dist/npm/chunks/html2canvas-_mjSRP3G.js +4011 -0
  9. package/dist/npm/chunks/mount-Ce1MZrcm.js +2485 -0
  10. package/dist/{shared/pusher-CnhQgAvF.js → npm/chunks/pusher-DRKlokR8.js} +224 -222
  11. package/dist/npm/chunks/realtime-5SvAvTUU.js +23 -0
  12. package/dist/npm/chunks/rolldown-runtime-VHNaYcLd.js +13 -0
  13. package/dist/npm/chunks/src-DJjfvVsa.js +330 -0
  14. package/dist/npm/element.js +24 -0
  15. package/dist/npm/headless.js +3 -0
  16. package/dist/npm/index.js +3 -0
  17. package/dist/npm/react.js +17 -0
  18. package/dist/npm/svelte.js +8 -0
  19. package/dist/npm/types/adapters/react.d.ts +9 -0
  20. package/dist/npm/types/adapters/svelte.d.ts +9 -0
  21. package/dist/npm/types/adapters/vue.d.ts +46 -0
  22. package/dist/npm/types/anchor/index.d.ts +49 -0
  23. package/dist/npm/types/core/api.d.ts +29 -0
  24. package/dist/npm/types/core/auth.d.ts +48 -0
  25. package/dist/npm/types/core/client.d.ts +100 -0
  26. package/dist/npm/types/core/store.d.ts +7 -0
  27. package/dist/npm/types/core/types.d.ts +278 -0
  28. package/dist/npm/types/element.d.ts +10 -0
  29. package/dist/npm/types/headless.d.ts +7 -0
  30. package/dist/npm/types/index.d.ts +30 -0
  31. package/dist/npm/vue.js +32 -0
  32. package/package.json +65 -173
  33. package/dist/THIRD_PARTY_NOTICES.txt +0 -284
  34. package/dist/angular.es.js +0 -321
  35. package/dist/comment-kit.es.js +0 -218
  36. package/dist/demo.es.js +0 -483
  37. package/dist/headless.es.js +0 -4
  38. package/dist/preact.es.js +0 -117
  39. package/dist/qwik.es.js +0 -1
  40. package/dist/qwik.qwik.mjs +0 -114
  41. package/dist/react.es.js +0 -98
  42. package/dist/shared/ShadowRootContext-DD6a0QaI.js +0 -11
  43. package/dist/shared/annotation-icons-Dh-bmNYK.js +0 -172
  44. package/dist/shared/annotation-toolbar-zeiCmKIr.js +0 -1086
  45. package/dist/shared/attachment-refresh-DAacLaRu.js +0 -94
  46. package/dist/shared/bridge-CJoGYngu.js +0 -177
  47. package/dist/shared/button-D4GHW6oZ.js +0 -474
  48. package/dist/shared/button-group-BVR7iT-S.js +0 -91
  49. package/dist/shared/capture-privacy-CiOrcAlt.js +0 -101
  50. package/dist/shared/comment-drawing-canvas-Btc12IsS.js +0 -124
  51. package/dist/shared/comment-icon-D8JTCEJ7.js +0 -607
  52. package/dist/shared/comment-image-lightbox--QpbcAtH.js +0 -190
  53. package/dist/shared/comment-images-content-C_r4SHM-.js +0 -214
  54. package/dist/shared/comment-kit-core-CmLUFujd.js +0 -3682
  55. package/dist/shared/comment-kit-ui-BHwYuSIi.js +0 -19391
  56. package/dist/shared/comment-screenshot-annotator-zJZyO-XM.js +0 -151
  57. package/dist/shared/comment-screenshot-overlay-CoKTYB0J.js +0 -205
  58. package/dist/shared/comment-shortcut-groups-CfEmkitU.js +0 -153
  59. package/dist/shared/createReactComponent-BZHeRbD0.js +0 -45
  60. package/dist/shared/dev-export-panel-Cnt6oCZU.js +0 -207
  61. package/dist/shared/dev-grab-B85jo9AS.js +0 -197
  62. package/dist/shared/dist-D9A5k-N4.js +0 -617
  63. package/dist/shared/dom-Bhf4WFtY.js +0 -223
  64. package/dist/shared/element-selector-Cng84xC7.js +0 -902
  65. package/dist/shared/error-boundary-D3PD74vI.js +0 -21
  66. package/dist/shared/errors-Bu5ajEmB.js +0 -22
  67. package/dist/shared/icons-nzMOLzrm.js +0 -266
  68. package/dist/shared/input-UPtAj0M6.js +0 -111
  69. package/dist/shared/mount-ui-Dz7FB_Ak.js +0 -208
  70. package/dist/shared/realtime-recovery-BjlV-ewc.js +0 -162
  71. package/dist/shared/realtime-yGLX4wMK.js +0 -334
  72. package/dist/shared/request-activity-DQrAUwfA.js +0 -11
  73. package/dist/shared/screenshot-B5-hwpmt.js +0 -199
  74. package/dist/shared/separator-UhJb0Row.js +0 -3955
  75. package/dist/shared/shadow-root-B58ZI2yz.js +0 -133
  76. package/dist/shared/styles-CnYsLS2f.js +0 -2
  77. package/dist/shared/text-B4HHZNaa.js +0 -23
  78. package/dist/shared/token-session-D92MYbNu.js +0 -25
  79. package/dist/shared/useLabelableId-8n0QmH8N.js +0 -154
  80. package/dist/shared/useRender-Uxk1OPK-.js +0 -5
  81. package/dist/shared/useValueChanged-DKq5cMot.js +0 -92
  82. package/dist/shared/validation-3wbbbuX0.js +0 -70
  83. package/dist/shared/websocket-manager-KhH4hL0Q.js +0 -381
  84. package/dist/solid.es.js +0 -98
  85. package/dist/svelte.es.js +0 -130
  86. package/dist/types/adapters/bridge.d.ts +0 -122
  87. package/dist/types/angular/index.d.ts +0 -145
  88. package/dist/types/core/agent-context.d.ts +0 -17
  89. package/dist/types/core/api-client.d.ts +0 -155
  90. package/dist/types/core/comment-kit-core.d.ts +0 -254
  91. package/dist/types/core/local-demo.d.ts +0 -60
  92. package/dist/types/core/types.d.ts +0 -770
  93. package/dist/types/core/websocket-manager.d.ts +0 -125
  94. package/dist/types/core/write-access.d.ts +0 -11
  95. package/dist/types/demo.d.ts +0 -17
  96. package/dist/types/headless.d.ts +0 -8
  97. package/dist/types/index.d.ts +0 -87
  98. package/dist/types/preact/index.d.ts +0 -25
  99. package/dist/types/qwik/index.d.ts +0 -73
  100. package/dist/types/react/client.d.ts +0 -31
  101. package/dist/types/react/index.d.ts +0 -4
  102. package/dist/types/solid/index.d.ts +0 -37
  103. package/dist/types/svelte/index.d.ts +0 -55
  104. package/dist/types/utils/dom.d.ts +0 -59
  105. package/dist/types/utils/event-emitter.d.ts +0 -11
  106. package/dist/types/vue/index.d.ts +0 -87
  107. package/dist/vue.es.js +0 -148
  108. package/docs/api-reference.md +0 -405
  109. package/docs/local-demo.md +0 -60
@@ -1,154 +0,0 @@
1
- import { F as e, L as t, P as n, R as r, f as i, z as a } from "./button-D4GHW6oZ.js";
2
- import { n as o } from "./useValueChanged-DKq5cMot.js";
3
- import * as s from "react";
4
- var c = "data-valid", l = "data-invalid", u = {
5
- badInput: !1,
6
- customError: !1,
7
- patternMismatch: !1,
8
- rangeOverflow: !1,
9
- rangeUnderflow: !1,
10
- stepMismatch: !1,
11
- tooLong: !1,
12
- tooShort: !1,
13
- typeMismatch: !1,
14
- valid: null,
15
- valueMissing: !1
16
- }, d = {
17
- valid: null,
18
- touched: !1,
19
- dirty: !1,
20
- filled: !1,
21
- focused: !1
22
- }, f = {
23
- disabled: !1,
24
- ...d
25
- }, p = { valid(e) {
26
- return e === null ? null : e ? { [c]: "" } : { [l]: "" };
27
- } }, m = {
28
- invalid: void 0,
29
- name: void 0,
30
- validityData: {
31
- state: u,
32
- errors: [],
33
- error: "",
34
- value: "",
35
- initialValue: null
36
- },
37
- setValidityData: r,
38
- disabled: void 0,
39
- setTouched: r,
40
- setDirty: r,
41
- setFilled: r,
42
- setFocused: r,
43
- focusOwnerRef: { current: void 0 },
44
- validationMode: "onSubmit",
45
- shouldValidateOnChange: () => !1,
46
- state: f,
47
- registerFieldControl: r,
48
- validation: {
49
- getValidationProps: (e, n = t) => n,
50
- inputRef: { current: null },
51
- registeredInputs: /* @__PURE__ */ new Map(),
52
- registerInput: r,
53
- getInputControl: () => null,
54
- commit: async () => {},
55
- change: r
56
- }
57
- }, h = /*#__PURE__*/ s.createContext(m);
58
- function g(e = !0) {
59
- let t = s.useContext(h);
60
- if (t.setValidityData === r && !e) throw Error(n(28));
61
- return t;
62
- }
63
- function _(t, n, r) {
64
- let { setFocused: a, focusOwnerRef: o } = g(), s = i((e) => {
65
- (e ? !t : o.current === s) && (o.current = e && s, r?.(e), a(e));
66
- });
67
- return e(() => {
68
- let e = n.current;
69
- return e?.getRootNode()?.activeElement === e && s(!0), () => s(!1);
70
- }, [
71
- t,
72
- n,
73
- s
74
- ]), s;
75
- }
76
- function v(t, n, r, i, o = !0, s) {
77
- let { registerFieldControl: c } = g(), l = a(() => Symbol());
78
- e(() => {
79
- let e = l.current;
80
- o ? c(e, {
81
- controlRef: t,
82
- getValue: i,
83
- id: n,
84
- name: s,
85
- value: r
86
- }) : c(e, void 0);
87
- }, [
88
- t,
89
- o,
90
- i,
91
- n,
92
- s,
93
- c,
94
- l,
95
- r
96
- ]), e(() => {
97
- let e = l.current;
98
- return () => {
99
- c(e, void 0);
100
- };
101
- }, [c, l]);
102
- }
103
- var y = /*#__PURE__*/ s.createContext({
104
- elementRef: { current: null },
105
- formRef: { current: { fields: /* @__PURE__ */ new Map() } },
106
- errors: {},
107
- clearErrors: r,
108
- validationMode: "onSubmit",
109
- submitCountRef: { current: 0 }
110
- });
111
- function b() {
112
- return s.useContext(y);
113
- }
114
- var x = /*#__PURE__*/ s.createContext({
115
- controlId: void 0,
116
- registerControlId: r,
117
- resetControlId: r,
118
- labelId: void 0,
119
- setLabelId: r,
120
- messageIds: [],
121
- setMessageIds: r,
122
- getDescriptionProps: (e) => e
123
- });
124
- function S() {
125
- return s.useContext(x);
126
- }
127
- function C(t = {}) {
128
- let { id: n, enabled: c = !0 } = t, { controlId: l, registerControlId: u, resetControlId: d } = S(), f = o(), p = a(() => Symbol()), m = s.useRef(!1), h = s.useRef(!1), g = i(() => {
129
- m.current && u !== r && (m.current = !1, u(p.current, void 0));
130
- });
131
- return e(() => {
132
- if (!c || u === r) {
133
- g();
134
- return;
135
- }
136
- let e;
137
- if (n !== void 0) h.current = !0, e = n;
138
- else if (h.current) e = f;
139
- else {
140
- d();
141
- return;
142
- }
143
- e === void 0 ? g() : (m.current = !0, u(p.current, e));
144
- }, [
145
- n,
146
- c,
147
- u,
148
- d,
149
- f,
150
- p,
151
- g
152
- ]), e(() => g, [g]), (c ? l : void 0) ?? n ?? f;
153
- }
154
- export { _ as a, g as c, v as i, d as l, S as n, m as o, b as r, h as s, C as t, p as u };
@@ -1,5 +0,0 @@
1
- import { l as e } from "./button-D4GHW6oZ.js";
2
- function t(t) {
3
- return e(t.defaultTagName ?? "div", t, t);
4
- }
5
- export { t };
@@ -1,92 +0,0 @@
1
- import { F as e, I as t, L as n, f as r, p as i, z as a } from "./button-D4GHW6oZ.js";
2
- import * as o from "react";
3
- function s(e) {
4
- o.useEffect(e, t);
5
- }
6
- var c = 0, l = class e {
7
- static create() {
8
- return new e();
9
- }
10
- currentId = c;
11
- start(e, t) {
12
- this.clear(), this.currentId = setTimeout(() => {
13
- this.currentId = c, t();
14
- }, e);
15
- }
16
- isStarted() {
17
- return this.currentId !== c;
18
- }
19
- clear = () => {
20
- this.currentId !== c && (clearTimeout(this.currentId), this.currentId = c);
21
- };
22
- disposeEffect = () => this.clear;
23
- };
24
- function u() {
25
- let e = a(l.create).current;
26
- return s(e.disposeEffect), e;
27
- }
28
- function d(e, t, r, i) {
29
- let a = !1, o = !1, s = i ?? n;
30
- return {
31
- reason: e,
32
- event: t ?? new Event("base-ui"),
33
- cancel() {
34
- a = !0;
35
- },
36
- allowPropagation() {
37
- o = !0;
38
- },
39
- get isCanceled() {
40
- return a;
41
- },
42
- get isPropagationAllowed() {
43
- return o;
44
- },
45
- trigger: r,
46
- ...s
47
- };
48
- }
49
- function f(e, t, r) {
50
- let i = r ?? n;
51
- return {
52
- reason: e,
53
- event: t ?? new Event("base-ui"),
54
- ...i
55
- };
56
- }
57
- var p = "none", m = "trigger-press", h = "trigger-hover", g = "trigger-focus", _ = "outside-press", v = "item-press", y = "close-press", b = "clear-press", x = "chip-remove-press", S = "track-press", C = "input-change", w = "input-clear", T = "input-press", E = "focus-out", D = "escape-key", O = "list-navigation", k = "keyboard", A = "pointer", j = "drag", M = "cancel-open", N = "sibling-open", P = "disabled", F = "missing", I = "initial", L = "imperative-action", R = "window-resize";
58
- function z() {
59
- let [, e] = o.useState({});
60
- return o.useCallback(() => {
61
- e({});
62
- }, []);
63
- }
64
- var B = 0;
65
- function V(e, t = "mui") {
66
- let n = o.useRef(void 0), r = z(), i = e ?? n.current;
67
- return o.useEffect(() => {
68
- n.current ?? (B += 1, n.current = `${t}-${B}`, e ?? r());
69
- }, [
70
- e,
71
- t,
72
- r
73
- ]), i;
74
- }
75
- var H = i.useId;
76
- function U(e, t) {
77
- if (H !== void 0) {
78
- let n = H();
79
- return e ?? (t ? `${t}-${n}` : n);
80
- }
81
- return V(e, t);
82
- }
83
- function W(e) {
84
- return U(e, "base-ui");
85
- }
86
- function G(t, n) {
87
- let i = o.useRef(t), a = r(n);
88
- e(() => {
89
- i.current !== t && a(i.current), i.current = t;
90
- }, [t, a]);
91
- }
92
- export { R as A, _ as C, g as D, S as E, s as F, f as M, l as N, h as O, u as P, p as S, N as T, T as _, M as a, O as b, y as c, D as d, E as f, w as g, C as h, z as i, d as j, m as k, P as l, I as m, W as n, x as o, L as p, U as r, b as s, G as t, j as u, v, A as w, F as x, k as y };
@@ -1,70 +0,0 @@
1
- function e(e) {
2
- for (let t = 0; t < e.length; t++) {
3
- let n = e.charCodeAt(t);
4
- if (n < 32 || n === 127) return !0;
5
- }
6
- return !1;
7
- }
8
- function t(e) {
9
- for (let t = 0; t < e.length; t++) {
10
- let n = e.charCodeAt(t);
11
- if (n < 32 && n !== 9 && n !== 10 && n !== 13 || n === 127) return !0;
12
- }
13
- return !1;
14
- }
15
- function n(e) {
16
- return typeof e == "object" && !!e && !Array.isArray(e);
17
- }
18
- function r(e) {
19
- return typeof e == "number" && Number.isFinite(e);
20
- }
21
- function i(e) {
22
- return r(e) && e >= 0 && e <= 100;
23
- }
24
- function a(t, n) {
25
- return typeof t == "string" && t.trim().length > 0 && t.length <= n && !e(t);
26
- }
27
- function o(t, n) {
28
- return t === void 0 || typeof t == "string" && t.length <= n && !e(t);
29
- }
30
- function s(e, n) {
31
- return typeof e == "string" && e.trim().length > 0 && e.length <= n && !t(e);
32
- }
33
- function c(e, t = 254) {
34
- if (!a(e, t)) return !1;
35
- let n = e.trim();
36
- if (n !== e) return !1;
37
- let r = n.indexOf("@");
38
- return r > 0 && r === n.lastIndexOf("@") && r < n.length - 1 && !/\s/.test(n);
39
- }
40
- var l = /* @__PURE__ */ new Set(/* @__PURE__ */ "exe.dll.bat.cmd.com.msi.scr.pif.cpl.sh.bash.zsh.ps1.py.rb.pl.php.jar.js.mjs.cjs.html.htm.xhtml.svg.swf.wasm".split("."));
41
- function u(e) {
42
- let t = e.lastIndexOf("."), n = t >= 0 ? e.slice(t + 1).toLowerCase() : "";
43
- return l.has(n);
44
- }
45
- function d(t) {
46
- if (typeof t != "string" || !t || t.trim() !== t || e(t)) return !1;
47
- try {
48
- let e = new URL(t, "https://commentkit.dev");
49
- return ["http:", "https:"].includes(e.protocol) && !e.username && !e.password;
50
- } catch {
51
- return !1;
52
- }
53
- }
54
- function f(t) {
55
- return typeof t == "string" && t.length <= 100 && /^(?:#[\da-f]{3,8}|[a-z]+|(?:rgba?|hsla?|hwb|lab|lch|oklab|oklch)\([\d\s.,%/+-]+\)|color\((?:srgb|display-p3)[\d\s.,%/+-]+\))$/i.test(t) && !e(t);
56
- }
57
- function p(t, n = !1) {
58
- if (typeof t != "string" || !t || t.trim() !== t || e(t)) return !1;
59
- if (n && /^data:image\/(?:png|jpeg|gif|webp|avif);base64,[A-Za-z0-9+/]+={0,2}$/i.test(t)) return !0;
60
- try {
61
- return [
62
- "http:",
63
- "https:",
64
- "blob:"
65
- ].includes(new URL(t, "https://commentkit.dev").protocol);
66
- } catch {
67
- return !1;
68
- }
69
- }
70
- export { i as a, f as c, o as d, a as f, r as i, s as l, e as n, n as o, c as p, t as r, p as s, u as t, d as u };
@@ -1,381 +0,0 @@
1
- import { d as e, f as t, i as n, l as r, o as i, p as a } from "./validation-3wbbbuX0.js";
2
- import { s as o } from "./comment-kit-core-CmLUFujd.js";
3
- import { i as s } from "./text-B4HHZNaa.js";
4
- var c = Object.create, l = Object.defineProperty, u = Object.getOwnPropertyDescriptor, d = Object.getOwnPropertyNames, f = Object.getPrototypeOf, p = Object.prototype.hasOwnProperty, m = (e, t) => () => (t || (e((t = { exports: {} }).exports, t, t.exports), e = null), t.exports), h = (e, t) => {
5
- let n = {};
6
- for (var r in e) l(n, r, {
7
- get: e[r],
8
- enumerable: !0
9
- });
10
- return t || l(n, Symbol.toStringTag, { value: "Module" }), n;
11
- }, g = (e, t, n, r) => {
12
- if (t && typeof t == "object" || typeof t == "function") for (var i = d(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !p.call(e, s) && s !== n && l(e, s, {
13
- get: ((e) => t[e]).bind(null, s),
14
- enumerable: !(r = u(t, s)) || r.enumerable
15
- });
16
- return e;
17
- }, _ = (e, t, n) => (n = e == null ? {} : c(f(e)), g(t || !e || !e.__esModule || !p.call(e, "default") ? l(n, "default", {
18
- value: e,
19
- enumerable: !0
20
- }) : n, e));
21
- function v(e, t) {
22
- let n = { ...e };
23
- for (let e of t) n[e] === null && delete n[e];
24
- return n;
25
- }
26
- function y(e) {
27
- return i(e) ? v(e, ["avatar", "organizationId"]) : e;
28
- }
29
- function b(e) {
30
- return i(e) ? v(e, [
31
- "thumbnail",
32
- "filename",
33
- "mimeType"
34
- ]) : e;
35
- }
36
- function x(e) {
37
- if (!i(e)) return e;
38
- let t = v(e, ["replyTo"]);
39
- return t.author = y(t.author), Array.isArray(t.attachments) && (t.attachments = t.attachments.map(b)), t;
40
- }
41
- function S(e) {
42
- if (!i(e)) return e;
43
- let t = v(e, [
44
- "description",
45
- "textSelection",
46
- "drawingData",
47
- "environment",
48
- "branch",
49
- "deviceInfo",
50
- "resolvedAt",
51
- "completedAt"
52
- ]);
53
- return t.author = y(t.author), "user" in t && (t.user = y(t.user)), i(t.position) && (t.position = v(t.position, ["element", "xpath"])), i(t.page) && t.page.title === null && (t.page = {
54
- ...t.page,
55
- title: ""
56
- }), Array.isArray(t.assignees) && (t.assignees = t.assignees.map(y)), Array.isArray(t.replies) && (t.replies = t.replies.map(x)), Array.isArray(t.attachments) && (t.attachments = t.attachments.map(b)), t;
57
- }
58
- var C = null;
59
- function w() {
60
- return C ||= import("./pusher-CnhQgAvF.js").then((e) => /* @__PURE__ */ _(e.default, 1)).then((e) => e.default ?? e), C;
61
- }
62
- var T = o.ID, E = o.NAME, D = o.EMAIL, O = o.PAGE, k = o.COLOR, A = o.DRAWING_PATH_DATA, j = o.DRAWING_TEXT, M = o.ONLINE_USERS, N = {
63
- id: "unknown",
64
- name: "Unknown",
65
- email: "unknown@example.invalid"
66
- }, P = /* @__PURE__ */ new Set([
67
- "client-cursor_move",
68
- "client-cursor_leave",
69
- "client-drawing_stroke"
70
- ]), F = /* @__PURE__ */ new Set([
71
- "path",
72
- "line",
73
- "rectangle",
74
- "circle",
75
- "text"
76
- ]);
77
- function I(e) {
78
- return t(e, T);
79
- }
80
- function L(n) {
81
- return i(n) ? I(n.id) && t(n.name, E) && a(n.email) && e(n.avatar, O) : !1;
82
- }
83
- function R(e) {
84
- return i(e) ? I(e.id) && r(e.content, o.CONTENT) && I(e.userId) && i(e.position) && n(e.position.x) && n(e.position.y) && L(e.author) : !1;
85
- }
86
- function z(e) {
87
- return i(e) ? I(e.id) && r(e.content, o.CONTENT) && L(e.author) : !1;
88
- }
89
- function B(e) {
90
- return i(e) ? n(e.x) && e.x >= 0 && e.x <= 100 && n(e.y) && e.y >= 0 && e.y <= 100 && t(e.page, O) : !1;
91
- }
92
- function V(r) {
93
- return !i(r) || !t(r.type, 20) || !F.has(r.type) || !t(r.stroke, k) || !n(r.strokeWidth) || r.strokeWidth <= 0 || r.strokeWidth > 100 || !t(r.fill, k) ? !1 : e(r.d, A) && e(r.text, j) && (r.x === void 0 || n(r.x)) && (r.y === void 0 || n(r.y)) && (r.width === void 0 || n(r.width)) && (r.height === void 0 || n(r.height));
94
- }
95
- function H(e) {
96
- return {
97
- id: e.id.slice(0, T),
98
- name: e.name.slice(0, E),
99
- email: e.email.slice(0, D),
100
- ...e.avatar ? { avatar: e.avatar.slice(0, O) } : {},
101
- ...e.organizationId ? { organizationId: e.organizationId.slice(0, T) } : {}
102
- };
103
- }
104
- function U(e) {
105
- if (!t(e, O)) return "";
106
- let n = s(e);
107
- return n.length <= O ? n : "";
108
- }
109
- function W(e) {
110
- let t = e.toLowerCase().replace(/^\[|\]$/g, "");
111
- return t === "localhost" || t === "127.0.0.1" || t === "::1";
112
- }
113
- function G(e) {
114
- return t(e, 253) && (e === "localhost" || /^[A-Za-z0-9](?:[A-Za-z0-9.-]*[A-Za-z0-9])?$/.test(e));
115
- }
116
- function K() {
117
- return { ...N };
118
- }
119
- function q(e) {
120
- let n = String(e.projectId).trim();
121
- if (!I(n) || !/^[\w.-]+$/.test(n)) throw Error("Invalid WebSocket projectId");
122
- let r;
123
- try {
124
- r = new URL(e.authEndpoint);
125
- } catch {
126
- throw Error("Invalid WebSocket auth endpoint");
127
- }
128
- if (r.protocol !== "https:" && !(r.protocol === "http:" && W(r.hostname))) throw Error("Invalid WebSocket auth endpoint");
129
- if (!t(e.key, 256)) throw Error("Invalid WebSocket key");
130
- if (!G(e.wsHost)) throw Error("Invalid WebSocket host");
131
- if (!t(e.apiKey, 512)) throw Error("Invalid WebSocket API key");
132
- if (e.userEmail && !a(e.userEmail)) throw Error("Invalid WebSocket user email");
133
- if (e.userInfo && !L(e.userInfo)) throw Error("Invalid WebSocket user info");
134
- return {
135
- ...e,
136
- projectId: n,
137
- authEndpoint: r.toString(),
138
- userInfo: e.userInfo ? H(e.userInfo) : void 0
139
- };
140
- }
141
- var J = class e {
142
- static {
143
- this.MAX_LISTENERS_PER_EVENT = 100;
144
- }
145
- constructor(e) {
146
- this.listeners = /* @__PURE__ */ new Map(), this.pusher = null, this.presenceChannel = null, this.onlineUsers = /* @__PURE__ */ new Map(), this.lastCursorUpdate = 0, this.cursorThrottle = 50, this.reconnectAttempts = 0, this.connecting = null, this.destroyed = !1, this.authorizationGeneration = 0, this.config = q(e);
147
- }
148
- on(t, n) {
149
- let r = this.listeners.get(t);
150
- return r || (r = /* @__PURE__ */ new Set(), this.listeners.set(t, r)), r.size >= e.MAX_LISTENERS_PER_EVENT && console.warn(`[CommentKit WS] Max listeners (${e.MAX_LISTENERS_PER_EVENT}) reached for '${t}' — possible memory leak`), r.add(n), () => {
151
- let e = this.listeners.get(t);
152
- e?.delete(n), e?.size === 0 && this.listeners.delete(t);
153
- };
154
- }
155
- emit(e, t) {
156
- let n = this.listeners.get(e);
157
- if (n) for (let r of Array.from(n)) try {
158
- r(t);
159
- } catch (t) {
160
- console.error(`[CommentKit WS] Error in '${e}' listener:`, t);
161
- }
162
- }
163
- async connect() {
164
- if (!(this.pusher || this.destroyed)) return this.connecting ||= this.openConnection().finally(() => {
165
- this.connecting = null;
166
- }), this.connecting;
167
- }
168
- async openConnection() {
169
- if (this.pusher || this.destroyed) return;
170
- let e = await w();
171
- if (this.destroyed) return;
172
- let t = { "X-API-Key": this.config.apiKey };
173
- this.config.userEmail && (t["X-User-Email"] = this.config.userEmail), this.pusher = new e(this.config.key, {
174
- cluster: "",
175
- wsHost: this.config.wsHost,
176
- wsPort: this.config.wsPort ?? 443,
177
- wssPort: this.config.wsPort ?? 443,
178
- forceTLS: this.config.forceTLS ?? !0,
179
- enabledTransports: ["ws"],
180
- disableStats: !0,
181
- channelAuthorization: this.config.authorizeChannel ? { customHandler: this.createChannelAuthorizer(this.config.authorizeChannel) } : {
182
- transport: "ajax",
183
- endpoint: this.config.authEndpoint,
184
- headers: t,
185
- params: this.config.userInfo ? {
186
- user_id: this.config.userInfo.id,
187
- user_name: this.config.userInfo.name,
188
- user_email: this.config.userInfo.email
189
- } : {}
190
- }
191
- }), this.pusher.connection.bind("connected", () => {
192
- this.reconnectAttempts = 0, this.emit("connected", void 0);
193
- }), this.pusher.connection.bind("disconnected", () => {
194
- this.emit("disconnected", {
195
- code: 1e3,
196
- reason: "Disconnected"
197
- });
198
- }), this.pusher.connection.bind("connecting", () => {
199
- this.reconnectAttempts > 0 && this.emit("reconnecting", {
200
- attempt: this.reconnectAttempts,
201
- maxAttempts: 5
202
- });
203
- }), this.pusher.connection.bind("unavailable", () => {
204
- this.reconnectAttempts++, this.emit("error", /* @__PURE__ */ Error("WebSocket connection unavailable"));
205
- }), this.pusher.connection.bind("failed", () => {
206
- this.emit("error", /* @__PURE__ */ Error("WebSocket connection failed"));
207
- }), this.pusher.connection.bind("error", (e) => {
208
- if (this.destroyed) return;
209
- let t = (i(e) && i(e.data) ? e.data : null)?.code;
210
- (t === 4004 || t === 4200) && (this.authorizationGeneration++, this.pusher?.disconnect()), this.onlineUsers.clear(), this.emit("presence:update", { users: [] }), this.emit("error", /* @__PURE__ */ Error(t === 4004 ? "Realtime connection capacity reached. Try reconnecting later." : "Realtime connection unavailable. Try reconnecting."));
211
- }), this.subscribeToChannel();
212
- }
213
- createChannelAuthorizer(e) {
214
- return (t, n) => {
215
- let r = this.authorizationGeneration, i = () => !this.destroyed && r === this.authorizationGeneration && this.pusher?.connection.socket_id === t.socketId;
216
- Promise.resolve().then(() => e(t.socketId, t.channelName)).then((e) => {
217
- i() && n(null, e);
218
- }, (e) => {
219
- i() && n(e instanceof Error ? e : /* @__PURE__ */ Error("Channel authorization failed"), null);
220
- });
221
- };
222
- }
223
- reconnect() {
224
- if (this.destroyed) return;
225
- if (!this.pusher) {
226
- this.connect();
227
- return;
228
- }
229
- let e = this.pusher;
230
- this.authorizationGeneration++, this.reconnectAttempts++, this.onlineUsers.clear(), this.emit("presence:update", { users: [] }), e.disconnect(), !this.destroyed && this.pusher === e && e.connect();
231
- }
232
- disconnect() {
233
- this.authorizationGeneration++, this.presenceChannel &&= (this.pusher?.unsubscribe(`presence-project.${this.config.projectId}`), null), this.pusher &&= (this.pusher.disconnect(), null), this.onlineUsers.clear();
234
- }
235
- isConnected() {
236
- return this.pusher?.connection.state === "connected";
237
- }
238
- getOnlineUsers() {
239
- return Array.from(this.onlineUsers.values());
240
- }
241
- subscribeToChannel() {
242
- if (!this.pusher) return;
243
- let e = `presence-project.${this.config.projectId}`;
244
- this.presenceChannel = this.pusher.subscribe(e), this.presenceChannel.bind("pusher:subscription_succeeded", (e) => {
245
- this.onlineUsers.clear(), e.each((e) => {
246
- if (this.onlineUsers.size >= M) return;
247
- let t = this.memberToUser(e);
248
- t && this.onlineUsers.set(t.id, t);
249
- }), this.emit("presence:update", { users: this.getOnlineUsers() }), this.emit("subscribed", void 0);
250
- }), this.presenceChannel.bind("pusher:member_added", (e) => {
251
- let t = this.memberToUser(e);
252
- if (t) {
253
- if (!this.onlineUsers.has(t.id) && this.onlineUsers.size >= M) return;
254
- this.onlineUsers.set(t.id, t), this.emit("user:joined", t), this.emit("presence:update", { users: this.getOnlineUsers() });
255
- }
256
- }), this.presenceChannel.bind("pusher:member_removed", (e) => {
257
- if (!I(e.id)) return;
258
- let t = e.id;
259
- this.onlineUsers.delete(t), this.emit("user:left", { userId: t }), this.emit("presence:update", { users: this.getOnlineUsers() });
260
- }), this.presenceChannel.bind("pusher:subscription_error", (e) => {
261
- console.error("[CommentKit WS] Channel subscription error:", e);
262
- let n = t(e.type, 80) ? e.type : "unknown";
263
- this.emit("error", /* @__PURE__ */ Error(`Channel subscription failed: ${n}`));
264
- });
265
- let n = (e, t) => {
266
- this.presenceChannel?.bind(e, t), this.presenceChannel?.bind(`.${e}`, t);
267
- }, r = (e, t) => {
268
- n(e, (e) => {
269
- if (a(e, t)) return;
270
- let n = S(e);
271
- R(n) && this.emit(t, n);
272
- });
273
- }, a = (e, t) => !i(e) || e.refresh !== !0 || !I(e.commentId) ? !1 : (this.emit("comment:refresh", {
274
- commentId: e.commentId.trim(),
275
- event: t
276
- }), !0);
277
- r("comment_created", "comment:created"), r("comment_updated", "comment:updated"), n("comment_deleted", (e) => {
278
- let t = e;
279
- i(t) && I(t.id) && this.emit("comment:deleted", { id: t.id });
280
- }), r("comment_resolved", "comment:resolved"), r("comment_completed", "comment:completed"), n("reply_added", (e) => {
281
- if (a(e, "comment:updated")) return;
282
- let t = e;
283
- if (i(t) && I(t.commentId)) {
284
- let e = x(t.reply);
285
- z(e) && this.emit("reply:added", {
286
- commentId: t.commentId,
287
- reply: e
288
- });
289
- }
290
- }), n("reaction_added", (e) => {
291
- let n = e;
292
- i(n) && I(n.commentId) && t(n.emoji, 32) && I(n.userId) && this.emit("reaction:added", {
293
- commentId: n.commentId,
294
- ...I(n.replyId) ? { replyId: n.replyId } : {},
295
- emoji: n.emoji,
296
- userId: n.userId
297
- });
298
- }), n("reaction_removed", (e) => {
299
- let n = e;
300
- i(n) && I(n.commentId) && t(n.emoji, 32) && I(n.userId) && this.emit("reaction:removed", {
301
- commentId: n.commentId,
302
- ...I(n.replyId) ? { replyId: n.replyId } : {},
303
- emoji: n.emoji,
304
- userId: n.userId
305
- });
306
- }), this.presenceChannel.bind("client-cursor_move", (e, t) => {
307
- let n = this.authenticatedClientEventUser(e, t);
308
- if (n && B(e)) {
309
- let t = U(e.page);
310
- t && this.emit("cursor:move", {
311
- x: e.x,
312
- y: e.y,
313
- page: t,
314
- user: n
315
- });
316
- }
317
- }), this.presenceChannel.bind("client-cursor_leave", (e, t) => {
318
- let n = this.authenticatedClientEventUser(e, t);
319
- n && this.emit("cursor:leave", { userId: n.id });
320
- }), this.presenceChannel.bind("client-drawing_stroke", (e, t) => {
321
- let n = this.authenticatedClientEventUser(e, t);
322
- n && i(e) && V(e.path) && this.emit("drawing:stroke", {
323
- userId: n.id,
324
- path: e.path
325
- });
326
- });
327
- }
328
- authenticatedClientEventUser(e, t) {
329
- if (!I(t?.user_id) || !i(e)) return null;
330
- let n = t.user_id.trim();
331
- if ("userId" in e && e.userId !== n) return null;
332
- if ("user" in e) {
333
- let t = e.user;
334
- if (!i(t) || t.id !== n) return null;
335
- }
336
- return this.onlineUsers.get(n) ?? null;
337
- }
338
- memberToUser(e) {
339
- if (!I(e.id)) return null;
340
- let t = e.info;
341
- if (!t) return null;
342
- let n = t.email == null || t.email === "" ? `${String(e.id)}@presence.invalid` : t.email, r = y({
343
- id: String(e.id),
344
- name: t.name || "Anonymous",
345
- email: n,
346
- avatar: t.avatar
347
- });
348
- return L(r) ? H(r) : null;
349
- }
350
- sendCursorMove(e, t, n) {
351
- if (!Number.isFinite(e) || !Number.isFinite(t)) return;
352
- let r = U(n);
353
- if (!r) return;
354
- let i = Math.max(0, Math.min(100, e)), a = Math.max(0, Math.min(100, t)), o = Date.now();
355
- o - this.lastCursorUpdate < this.cursorThrottle || (this.lastCursorUpdate = o, this.triggerClientEvent("client-cursor_move", {
356
- x: i,
357
- y: a,
358
- page: r,
359
- user: this.config.userInfo || K()
360
- }));
361
- }
362
- sendCursorLeave() {
363
- this.triggerClientEvent("client-cursor_leave", { userId: this.config.userInfo?.id || "unknown" });
364
- }
365
- sendDrawingStroke(e) {
366
- V(e) && this.triggerClientEvent("client-drawing_stroke", {
367
- userId: this.config.userInfo?.id || "unknown",
368
- path: e
369
- });
370
- }
371
- requestPresence() {}
372
- triggerClientEvent(e, t) {
373
- if (P.has(e) && this.presenceChannel) try {
374
- this.presenceChannel.trigger(e, t);
375
- } catch {}
376
- }
377
- destroy() {
378
- this.destroyed = !0, this.disconnect(), this.listeners.clear();
379
- }
380
- };
381
- export { m as a, y as i, S as n, h as o, x as r, J as t };