@kelet-ai/feedback-ui 0.4.2 → 0.6.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.
@@ -1,32 +1,38 @@
1
- import De, { createContext as Ee, useContext as ae, useCallback as W, isValidElement as Z, cloneElement as Q, useState as X, useRef as U, useId as ce, useEffect as ke } from "react";
2
- function _e(n) {
3
- return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
1
+ import require$$0$1, { createContext, useContext, useCallback, isValidElement, cloneElement, useState, useRef, useId, useEffect } from "react";
2
+ function getDefaultExportFromCjs(x) {
3
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
4
4
  }
5
- function Se(n) {
5
+ function getAugmentedNamespace(n) {
6
6
  if (Object.prototype.hasOwnProperty.call(n, "__esModule")) return n;
7
- var e = n.default;
8
- if (typeof e == "function") {
9
- var t = function r() {
10
- var o = !1;
7
+ var f = n.default;
8
+ if (typeof f == "function") {
9
+ var a = function a2() {
10
+ var isInstance = false;
11
11
  try {
12
- o = this instanceof r;
12
+ isInstance = this instanceof a2;
13
13
  } catch {
14
14
  }
15
- return o ? Reflect.construct(e, arguments, this.constructor) : e.apply(this, arguments);
15
+ if (isInstance) {
16
+ return Reflect.construct(f, arguments, this.constructor);
17
+ }
18
+ return f.apply(this, arguments);
16
19
  };
17
- t.prototype = e.prototype;
18
- } else t = {};
19
- return Object.defineProperty(t, "__esModule", { value: !0 }), Object.keys(n).forEach(function(r) {
20
- var o = Object.getOwnPropertyDescriptor(n, r);
21
- Object.defineProperty(t, r, o.get ? o : {
22
- enumerable: !0,
20
+ a.prototype = f.prototype;
21
+ } else a = {};
22
+ Object.defineProperty(a, "__esModule", { value: true });
23
+ Object.keys(n).forEach(function(k) {
24
+ var d = Object.getOwnPropertyDescriptor(n, k);
25
+ Object.defineProperty(a, k, d.get ? d : {
26
+ enumerable: true,
23
27
  get: function() {
24
- return n[r];
28
+ return n[k];
25
29
  }
26
30
  });
27
- }), t;
31
+ });
32
+ return a;
28
33
  }
29
- var re = { exports: {} }, V = {};
34
+ var jsxRuntime = { exports: {} };
35
+ var reactJsxRuntime_production = {};
30
36
  /**
31
37
  * @license React
32
38
  * react-jsx-runtime.production.js
@@ -36,29 +42,35 @@ var re = { exports: {} }, V = {};
36
42
  * This source code is licensed under the MIT license found in the
37
43
  * LICENSE file in the root directory of this source tree.
38
44
  */
39
- var fe;
40
- function je() {
41
- if (fe) return V;
42
- fe = 1;
43
- var n = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
44
- function t(r, o, u) {
45
- var d = null;
46
- if (u !== void 0 && (d = "" + u), o.key !== void 0 && (d = "" + o.key), "key" in o) {
47
- u = {};
48
- for (var f in o)
49
- f !== "key" && (u[f] = o[f]);
50
- } else u = o;
51
- return o = u.ref, {
52
- $$typeof: n,
53
- type: r,
54
- key: d,
55
- ref: o !== void 0 ? o : null,
56
- props: u
45
+ var hasRequiredReactJsxRuntime_production;
46
+ function requireReactJsxRuntime_production() {
47
+ if (hasRequiredReactJsxRuntime_production) return reactJsxRuntime_production;
48
+ hasRequiredReactJsxRuntime_production = 1;
49
+ var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
50
+ function jsxProd(type, config, maybeKey) {
51
+ var key = null;
52
+ void 0 !== maybeKey && (key = "" + maybeKey);
53
+ void 0 !== config.key && (key = "" + config.key);
54
+ if ("key" in config) {
55
+ maybeKey = {};
56
+ for (var propName in config)
57
+ "key" !== propName && (maybeKey[propName] = config[propName]);
58
+ } else maybeKey = config;
59
+ config = maybeKey.ref;
60
+ return {
61
+ $$typeof: REACT_ELEMENT_TYPE,
62
+ type,
63
+ key,
64
+ ref: void 0 !== config ? config : null,
65
+ props: maybeKey
57
66
  };
58
67
  }
59
- return V.Fragment = e, V.jsx = t, V.jsxs = t, V;
68
+ reactJsxRuntime_production.Fragment = REACT_FRAGMENT_TYPE;
69
+ reactJsxRuntime_production.jsx = jsxProd;
70
+ reactJsxRuntime_production.jsxs = jsxProd;
71
+ return reactJsxRuntime_production;
60
72
  }
61
- var G = {};
73
+ var reactJsxRuntime_development = {};
62
74
  /**
63
75
  * @license React
64
76
  * react-jsx-runtime.development.js
@@ -68,972 +80,1320 @@ var G = {};
68
80
  * This source code is licensed under the MIT license found in the
69
81
  * LICENSE file in the root directory of this source tree.
70
82
  */
71
- var de;
72
- function Ne() {
73
- return de || (de = 1, process.env.NODE_ENV !== "production" && function() {
74
- function n(a) {
75
- if (a == null) return null;
76
- if (typeof a == "function")
77
- return a.$$typeof === s ? null : a.displayName || a.name || null;
78
- if (typeof a == "string") return a;
79
- switch (a) {
80
- case g:
83
+ var hasRequiredReactJsxRuntime_development;
84
+ function requireReactJsxRuntime_development() {
85
+ if (hasRequiredReactJsxRuntime_development) return reactJsxRuntime_development;
86
+ hasRequiredReactJsxRuntime_development = 1;
87
+ "production" !== process.env.NODE_ENV && function() {
88
+ function getComponentNameFromType(type) {
89
+ if (null == type) return null;
90
+ if ("function" === typeof type)
91
+ return type.$$typeof === REACT_CLIENT_REFERENCE ? null : type.displayName || type.name || null;
92
+ if ("string" === typeof type) return type;
93
+ switch (type) {
94
+ case REACT_FRAGMENT_TYPE:
81
95
  return "Fragment";
82
- case P:
96
+ case REACT_PROFILER_TYPE:
83
97
  return "Profiler";
84
- case C:
98
+ case REACT_STRICT_MODE_TYPE:
85
99
  return "StrictMode";
86
- case R:
100
+ case REACT_SUSPENSE_TYPE:
87
101
  return "Suspense";
88
- case I:
102
+ case REACT_SUSPENSE_LIST_TYPE:
89
103
  return "SuspenseList";
90
- case l:
104
+ case REACT_ACTIVITY_TYPE:
91
105
  return "Activity";
92
106
  }
93
- if (typeof a == "object")
94
- switch (typeof a.tag == "number" && console.error(
107
+ if ("object" === typeof type)
108
+ switch ("number" === typeof type.tag && console.error(
95
109
  "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
96
- ), a.$$typeof) {
97
- case h:
110
+ ), type.$$typeof) {
111
+ case REACT_PORTAL_TYPE:
98
112
  return "Portal";
99
- case k:
100
- return (a.displayName || "Context") + ".Provider";
101
- case v:
102
- return (a._context.displayName || "Context") + ".Consumer";
103
- case O:
104
- var T = a.render;
105
- return a = a.displayName, a || (a = T.displayName || T.name || "", a = a !== "" ? "ForwardRef(" + a + ")" : "ForwardRef"), a;
106
- case L:
107
- return T = a.displayName || null, T !== null ? T : n(a.type) || "Memo";
108
- case i:
109
- T = a._payload, a = a._init;
113
+ case REACT_CONTEXT_TYPE:
114
+ return (type.displayName || "Context") + ".Provider";
115
+ case REACT_CONSUMER_TYPE:
116
+ return (type._context.displayName || "Context") + ".Consumer";
117
+ case REACT_FORWARD_REF_TYPE:
118
+ var innerType = type.render;
119
+ type = type.displayName;
120
+ type || (type = innerType.displayName || innerType.name || "", type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef");
121
+ return type;
122
+ case REACT_MEMO_TYPE:
123
+ return innerType = type.displayName || null, null !== innerType ? innerType : getComponentNameFromType(type.type) || "Memo";
124
+ case REACT_LAZY_TYPE:
125
+ innerType = type._payload;
126
+ type = type._init;
110
127
  try {
111
- return n(a(T));
112
- } catch {
128
+ return getComponentNameFromType(type(innerType));
129
+ } catch (x) {
113
130
  }
114
131
  }
115
132
  return null;
116
133
  }
117
- function e(a) {
118
- return "" + a;
134
+ function testStringCoercion(value) {
135
+ return "" + value;
119
136
  }
120
- function t(a) {
137
+ function checkKeyStringCoercion(value) {
121
138
  try {
122
- e(a);
123
- var T = !1;
124
- } catch {
125
- T = !0;
139
+ testStringCoercion(value);
140
+ var JSCompiler_inline_result = false;
141
+ } catch (e) {
142
+ JSCompiler_inline_result = true;
126
143
  }
127
- if (T) {
128
- T = console;
129
- var _ = T.error, S = typeof Symbol == "function" && Symbol.toStringTag && a[Symbol.toStringTag] || a.constructor.name || "Object";
130
- return _.call(
131
- T,
144
+ if (JSCompiler_inline_result) {
145
+ JSCompiler_inline_result = console;
146
+ var JSCompiler_temp_const = JSCompiler_inline_result.error;
147
+ var JSCompiler_inline_result$jscomp$0 = "function" === typeof Symbol && Symbol.toStringTag && value[Symbol.toStringTag] || value.constructor.name || "Object";
148
+ JSCompiler_temp_const.call(
149
+ JSCompiler_inline_result,
132
150
  "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
133
- S
134
- ), e(a);
151
+ JSCompiler_inline_result$jscomp$0
152
+ );
153
+ return testStringCoercion(value);
135
154
  }
136
155
  }
137
- function r(a) {
138
- if (a === g) return "<>";
139
- if (typeof a == "object" && a !== null && a.$$typeof === i)
156
+ function getTaskName(type) {
157
+ if (type === REACT_FRAGMENT_TYPE) return "<>";
158
+ if ("object" === typeof type && null !== type && type.$$typeof === REACT_LAZY_TYPE)
140
159
  return "<...>";
141
160
  try {
142
- var T = n(a);
143
- return T ? "<" + T + ">" : "<...>";
144
- } catch {
161
+ var name = getComponentNameFromType(type);
162
+ return name ? "<" + name + ">" : "<...>";
163
+ } catch (x) {
145
164
  return "<...>";
146
165
  }
147
166
  }
148
- function o() {
149
- var a = c.A;
150
- return a === null ? null : a.getOwner();
167
+ function getOwner() {
168
+ var dispatcher = ReactSharedInternals.A;
169
+ return null === dispatcher ? null : dispatcher.getOwner();
151
170
  }
152
- function u() {
171
+ function UnknownOwner() {
153
172
  return Error("react-stack-top-frame");
154
173
  }
155
- function d(a) {
156
- if (b.call(a, "key")) {
157
- var T = Object.getOwnPropertyDescriptor(a, "key").get;
158
- if (T && T.isReactWarning) return !1;
174
+ function hasValidKey(config) {
175
+ if (hasOwnProperty.call(config, "key")) {
176
+ var getter = Object.getOwnPropertyDescriptor(config, "key").get;
177
+ if (getter && getter.isReactWarning) return false;
159
178
  }
160
- return a.key !== void 0;
179
+ return void 0 !== config.key;
161
180
  }
162
- function f(a, T) {
163
- function _() {
164
- M || (M = !0, console.error(
181
+ function defineKeyPropWarningGetter(props, displayName) {
182
+ function warnAboutAccessingKey() {
183
+ specialPropKeyWarningShown || (specialPropKeyWarningShown = true, console.error(
165
184
  "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
166
- T
185
+ displayName
167
186
  ));
168
187
  }
169
- _.isReactWarning = !0, Object.defineProperty(a, "key", {
170
- get: _,
171
- configurable: !0
188
+ warnAboutAccessingKey.isReactWarning = true;
189
+ Object.defineProperty(props, "key", {
190
+ get: warnAboutAccessingKey,
191
+ configurable: true
172
192
  });
173
193
  }
174
- function p() {
175
- var a = n(this.type);
176
- return N[a] || (N[a] = !0, console.error(
194
+ function elementRefGetterWithDeprecationWarning() {
195
+ var componentName = getComponentNameFromType(this.type);
196
+ didWarnAboutElementRef[componentName] || (didWarnAboutElementRef[componentName] = true, console.error(
177
197
  "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
178
- )), a = this.props.ref, a !== void 0 ? a : null;
198
+ ));
199
+ componentName = this.props.ref;
200
+ return void 0 !== componentName ? componentName : null;
179
201
  }
180
- function y(a, T, _, S, q, $, B, K) {
181
- return _ = $.ref, a = {
182
- $$typeof: E,
183
- type: a,
184
- key: T,
185
- props: $,
186
- _owner: q
187
- }, (_ !== void 0 ? _ : null) !== null ? Object.defineProperty(a, "ref", {
188
- enumerable: !1,
189
- get: p
190
- }) : Object.defineProperty(a, "ref", { enumerable: !1, value: null }), a._store = {}, Object.defineProperty(a._store, "validated", {
191
- configurable: !1,
192
- enumerable: !1,
193
- writable: !0,
202
+ function ReactElement(type, key, self2, source, owner, props, debugStack, debugTask) {
203
+ self2 = props.ref;
204
+ type = {
205
+ $$typeof: REACT_ELEMENT_TYPE,
206
+ type,
207
+ key,
208
+ props,
209
+ _owner: owner
210
+ };
211
+ null !== (void 0 !== self2 ? self2 : null) ? Object.defineProperty(type, "ref", {
212
+ enumerable: false,
213
+ get: elementRefGetterWithDeprecationWarning
214
+ }) : Object.defineProperty(type, "ref", { enumerable: false, value: null });
215
+ type._store = {};
216
+ Object.defineProperty(type._store, "validated", {
217
+ configurable: false,
218
+ enumerable: false,
219
+ writable: true,
194
220
  value: 0
195
- }), Object.defineProperty(a, "_debugInfo", {
196
- configurable: !1,
197
- enumerable: !1,
198
- writable: !0,
221
+ });
222
+ Object.defineProperty(type, "_debugInfo", {
223
+ configurable: false,
224
+ enumerable: false,
225
+ writable: true,
199
226
  value: null
200
- }), Object.defineProperty(a, "_debugStack", {
201
- configurable: !1,
202
- enumerable: !1,
203
- writable: !0,
204
- value: B
205
- }), Object.defineProperty(a, "_debugTask", {
206
- configurable: !1,
207
- enumerable: !1,
208
- writable: !0,
209
- value: K
210
- }), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a;
227
+ });
228
+ Object.defineProperty(type, "_debugStack", {
229
+ configurable: false,
230
+ enumerable: false,
231
+ writable: true,
232
+ value: debugStack
233
+ });
234
+ Object.defineProperty(type, "_debugTask", {
235
+ configurable: false,
236
+ enumerable: false,
237
+ writable: true,
238
+ value: debugTask
239
+ });
240
+ Object.freeze && (Object.freeze(type.props), Object.freeze(type));
241
+ return type;
211
242
  }
212
- function m(a, T, _, S, q, $, B, K) {
213
- var j = T.children;
214
- if (j !== void 0)
215
- if (S)
216
- if (D(j)) {
217
- for (S = 0; S < j.length; S++)
218
- A(j[S]);
219
- Object.freeze && Object.freeze(j);
243
+ function jsxDEVImpl(type, config, maybeKey, isStaticChildren, source, self2, debugStack, debugTask) {
244
+ var children = config.children;
245
+ if (void 0 !== children)
246
+ if (isStaticChildren)
247
+ if (isArrayImpl(children)) {
248
+ for (isStaticChildren = 0; isStaticChildren < children.length; isStaticChildren++)
249
+ validateChildKeys(children[isStaticChildren]);
250
+ Object.freeze && Object.freeze(children);
220
251
  } else
221
252
  console.error(
222
253
  "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
223
254
  );
224
- else A(j);
225
- if (b.call(T, "key")) {
226
- j = n(a);
227
- var Y = Object.keys(T).filter(function(Ae) {
228
- return Ae !== "key";
255
+ else validateChildKeys(children);
256
+ if (hasOwnProperty.call(config, "key")) {
257
+ children = getComponentNameFromType(type);
258
+ var keys = Object.keys(config).filter(function(k) {
259
+ return "key" !== k;
229
260
  });
230
- S = 0 < Y.length ? "{key: someKey, " + Y.join(": ..., ") + ": ...}" : "{key: someKey}", ne[j + S] || (Y = 0 < Y.length ? "{" + Y.join(": ..., ") + ": ...}" : "{}", console.error(
231
- `A props object containing a "key" prop is being spread into JSX:
232
- let props = %s;
233
- <%s {...props} />
234
- React keys must be passed directly to JSX without using spread:
235
- let props = %s;
236
- <%s key={someKey} {...props} />`,
237
- S,
238
- j,
239
- Y,
240
- j
241
- ), ne[j + S] = !0);
261
+ isStaticChildren = 0 < keys.length ? "{key: someKey, " + keys.join(": ..., ") + ": ...}" : "{key: someKey}";
262
+ didWarnAboutKeySpread[children + isStaticChildren] || (keys = 0 < keys.length ? "{" + keys.join(": ..., ") + ": ...}" : "{}", console.error(
263
+ 'A props object containing a "key" prop is being spread into JSX:\n let props = %s;\n <%s {...props} />\nReact keys must be passed directly to JSX without using spread:\n let props = %s;\n <%s key={someKey} {...props} />',
264
+ isStaticChildren,
265
+ children,
266
+ keys,
267
+ children
268
+ ), didWarnAboutKeySpread[children + isStaticChildren] = true);
242
269
  }
243
- if (j = null, _ !== void 0 && (t(_), j = "" + _), d(T) && (t(T.key), j = "" + T.key), "key" in T) {
244
- _ = {};
245
- for (var le in T)
246
- le !== "key" && (_[le] = T[le]);
247
- } else _ = T;
248
- return j && f(
249
- _,
250
- typeof a == "function" ? a.displayName || a.name || "Unknown" : a
251
- ), y(
252
- a,
253
- j,
254
- $,
255
- q,
256
- o(),
257
- _,
258
- B,
259
- K
270
+ children = null;
271
+ void 0 !== maybeKey && (checkKeyStringCoercion(maybeKey), children = "" + maybeKey);
272
+ hasValidKey(config) && (checkKeyStringCoercion(config.key), children = "" + config.key);
273
+ if ("key" in config) {
274
+ maybeKey = {};
275
+ for (var propName in config)
276
+ "key" !== propName && (maybeKey[propName] = config[propName]);
277
+ } else maybeKey = config;
278
+ children && defineKeyPropWarningGetter(
279
+ maybeKey,
280
+ "function" === typeof type ? type.displayName || type.name || "Unknown" : type
281
+ );
282
+ return ReactElement(
283
+ type,
284
+ children,
285
+ self2,
286
+ source,
287
+ getOwner(),
288
+ maybeKey,
289
+ debugStack,
290
+ debugTask
260
291
  );
261
292
  }
262
- function A(a) {
263
- typeof a == "object" && a !== null && a.$$typeof === E && a._store && (a._store.validated = 1);
293
+ function validateChildKeys(node) {
294
+ "object" === typeof node && null !== node && node.$$typeof === REACT_ELEMENT_TYPE && node._store && (node._store.validated = 1);
264
295
  }
265
- var w = De, E = Symbol.for("react.transitional.element"), h = Symbol.for("react.portal"), g = Symbol.for("react.fragment"), C = Symbol.for("react.strict_mode"), P = Symbol.for("react.profiler"), v = Symbol.for("react.consumer"), k = Symbol.for("react.context"), O = Symbol.for("react.forward_ref"), R = Symbol.for("react.suspense"), I = Symbol.for("react.suspense_list"), L = Symbol.for("react.memo"), i = Symbol.for("react.lazy"), l = Symbol.for("react.activity"), s = Symbol.for("react.client.reference"), c = w.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, b = Object.prototype.hasOwnProperty, D = Array.isArray, x = console.createTask ? console.createTask : function() {
296
+ var React = require$$0$1, REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_PORTAL_TYPE = Symbol.for("react.portal"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"), REACT_STRICT_MODE_TYPE = Symbol.for("react.strict_mode"), REACT_PROFILER_TYPE = Symbol.for("react.profiler");
297
+ var REACT_CONSUMER_TYPE = Symbol.for("react.consumer"), REACT_CONTEXT_TYPE = Symbol.for("react.context"), REACT_FORWARD_REF_TYPE = Symbol.for("react.forward_ref"), REACT_SUSPENSE_TYPE = Symbol.for("react.suspense"), REACT_SUSPENSE_LIST_TYPE = Symbol.for("react.suspense_list"), REACT_MEMO_TYPE = Symbol.for("react.memo"), REACT_LAZY_TYPE = Symbol.for("react.lazy"), REACT_ACTIVITY_TYPE = Symbol.for("react.activity"), REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"), ReactSharedInternals = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, hasOwnProperty = Object.prototype.hasOwnProperty, isArrayImpl = Array.isArray, createTask = console.createTask ? console.createTask : function() {
266
298
  return null;
267
299
  };
268
- w = {
269
- react_stack_bottom_frame: function(a) {
270
- return a();
300
+ React = {
301
+ react_stack_bottom_frame: function(callStackForError) {
302
+ return callStackForError();
271
303
  }
272
304
  };
273
- var M, N = {}, H = w.react_stack_bottom_frame.bind(
274
- w,
275
- u
276
- )(), J = x(r(u)), ne = {};
277
- G.Fragment = g, G.jsx = function(a, T, _, S, q) {
278
- var $ = 1e4 > c.recentlyCreatedOwnerStacks++;
279
- return m(
280
- a,
281
- T,
282
- _,
283
- !1,
284
- S,
285
- q,
286
- $ ? Error("react-stack-top-frame") : H,
287
- $ ? x(r(a)) : J
305
+ var specialPropKeyWarningShown;
306
+ var didWarnAboutElementRef = {};
307
+ var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(
308
+ React,
309
+ UnknownOwner
310
+ )();
311
+ var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
312
+ var didWarnAboutKeySpread = {};
313
+ reactJsxRuntime_development.Fragment = REACT_FRAGMENT_TYPE;
314
+ reactJsxRuntime_development.jsx = function(type, config, maybeKey, source, self2) {
315
+ var trackActualOwner = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
316
+ return jsxDEVImpl(
317
+ type,
318
+ config,
319
+ maybeKey,
320
+ false,
321
+ source,
322
+ self2,
323
+ trackActualOwner ? Error("react-stack-top-frame") : unknownOwnerDebugStack,
324
+ trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
288
325
  );
289
- }, G.jsxs = function(a, T, _, S, q) {
290
- var $ = 1e4 > c.recentlyCreatedOwnerStacks++;
291
- return m(
292
- a,
293
- T,
294
- _,
295
- !0,
296
- S,
297
- q,
298
- $ ? Error("react-stack-top-frame") : H,
299
- $ ? x(r(a)) : J
326
+ };
327
+ reactJsxRuntime_development.jsxs = function(type, config, maybeKey, source, self2) {
328
+ var trackActualOwner = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
329
+ return jsxDEVImpl(
330
+ type,
331
+ config,
332
+ maybeKey,
333
+ true,
334
+ source,
335
+ self2,
336
+ trackActualOwner ? Error("react-stack-top-frame") : unknownOwnerDebugStack,
337
+ trackActualOwner ? createTask(getTaskName(type)) : unknownOwnerDebugTask
300
338
  );
301
339
  };
302
- }()), G;
340
+ }();
341
+ return reactJsxRuntime_development;
303
342
  }
304
- var pe;
305
- function Ie() {
306
- return pe || (pe = 1, process.env.NODE_ENV === "production" ? re.exports = je() : re.exports = Ne()), re.exports;
343
+ var hasRequiredJsxRuntime;
344
+ function requireJsxRuntime() {
345
+ if (hasRequiredJsxRuntime) return jsxRuntime.exports;
346
+ hasRequiredJsxRuntime = 1;
347
+ if (process.env.NODE_ENV === "production") {
348
+ jsxRuntime.exports = requireReactJsxRuntime_production();
349
+ } else {
350
+ jsxRuntime.exports = requireReactJsxRuntime_development();
351
+ }
352
+ return jsxRuntime.exports;
307
353
  }
308
- var F = Ie();
309
- const se = Ee(null), Fe = "https://api.kelet.ai/api", pt = () => {
310
- const n = ae(se);
311
- if (!n)
354
+ var jsxRuntimeExports = requireJsxRuntime();
355
+ const KeletContext = createContext(null);
356
+ const KeletBaseUrl = "https://api.kelet.ai/api";
357
+ const useKelet = () => {
358
+ const context = useContext(KeletContext);
359
+ if (!context) {
312
360
  throw new Error("useKelet must be used within a KeletProvider");
313
- return n;
314
- }, Pe = () => {
315
- const n = ae(se);
316
- return n ? n.feedback : async () => {
317
- };
318
- }, ht = ({ apiKey: n, project: e, children: t }) => {
319
- const r = ae(se), o = n || r?.api_key;
320
- if (!o)
361
+ }
362
+ return context;
363
+ };
364
+ const useDefaultFeedbackHandler = () => {
365
+ const context = useContext(KeletContext);
366
+ if (!context) {
367
+ return async () => {
368
+ };
369
+ } else {
370
+ return context.feedback;
371
+ }
372
+ };
373
+ const KeletProvider = ({ apiKey, project, children }) => {
374
+ const parentContext = useContext(KeletContext);
375
+ const resolvedApiKey = apiKey || parentContext?.api_key;
376
+ if (!resolvedApiKey) {
321
377
  throw new Error(
322
378
  "apiKey is required either directly or from a parent KeletProvider"
323
379
  );
324
- const d = {
325
- api_key: o,
326
- project: e,
327
- feedback: async (f) => {
328
- const p = `${Fe}/projects/${e}/feedback`, y = {
329
- tx_id: f.tx_id,
330
- source: f.source || "EXPLICIT",
331
- vote: f.vote,
332
- explanation: f.explanation,
333
- correction: f.correction,
334
- selection: f.selection
335
- // Include trigger_name if needed in the future
336
- }, m = await fetch(p, {
337
- method: "POST",
338
- headers: {
339
- "Content-Type": "application/json",
340
- Authorization: `Bearer ${o}`
341
- },
342
- body: JSON.stringify(y)
343
- });
344
- if (!m.ok)
345
- throw new Error(`Failed to submit feedback: ${m.statusText}`);
380
+ }
381
+ const feedback = async (data) => {
382
+ const url = `${KeletBaseUrl}/projects/${project}/feedback`;
383
+ const req = {
384
+ tx_id: data.tx_id,
385
+ source: data.source || "EXPLICIT",
386
+ vote: data.vote,
387
+ explanation: data.explanation,
388
+ correction: data.correction,
389
+ selection: data.selection
390
+ // Include trigger_name if needed in the future
391
+ };
392
+ const response = await fetch(url, {
393
+ method: "POST",
394
+ headers: {
395
+ "Content-Type": "application/json",
396
+ Authorization: `Bearer ${resolvedApiKey}`
397
+ },
398
+ body: JSON.stringify(req)
399
+ });
400
+ if (!response.ok) {
401
+ throw new Error(`Failed to submit feedback: ${response.statusText}`);
346
402
  }
347
403
  };
348
- return /* @__PURE__ */ F.jsx(se.Provider, { value: d, children: t });
349
- }, ee = (n, e) => {
350
- const t = { ...e };
351
- for (const r in e) {
352
- const o = n[r], u = e[r];
353
- /^on[A-Z]/.test(r) ? o && u ? t[r] = (...f) => {
354
- u(...f), o(...f);
355
- } : o && (t[r] = o) : r === "style" ? t[r] = { ...o, ...u } : r === "className" ? t[r] = [o, u].filter(Boolean).join(" ") : t[r] = u !== void 0 ? u : o;
404
+ const value = {
405
+ api_key: resolvedApiKey,
406
+ project,
407
+ feedback
408
+ };
409
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(KeletContext.Provider, { value, children });
410
+ };
411
+ const mergeProps = (slotProps, childProps) => {
412
+ const overrideProps = { ...childProps };
413
+ for (const propName in childProps) {
414
+ const slotPropValue = slotProps[propName];
415
+ const childPropValue = childProps[propName];
416
+ const isHandler = /^on[A-Z]/.test(propName);
417
+ if (isHandler) {
418
+ if (slotPropValue && childPropValue) {
419
+ overrideProps[propName] = (...args) => {
420
+ childPropValue(...args);
421
+ slotPropValue(...args);
422
+ };
423
+ } else if (slotPropValue) {
424
+ overrideProps[propName] = slotPropValue;
425
+ }
426
+ } else if (propName === "style") {
427
+ overrideProps[propName] = { ...slotPropValue, ...childPropValue };
428
+ } else if (propName === "className") {
429
+ overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
430
+ } else {
431
+ overrideProps[propName] = childPropValue !== void 0 ? childPropValue : slotPropValue;
432
+ }
356
433
  }
357
- return { ...n, ...t };
358
- }, xe = Ee(
434
+ return { ...slotProps, ...overrideProps };
435
+ };
436
+ const VoteFeedbackContext = createContext(
359
437
  null
360
- ), te = () => {
361
- const n = ae(xe);
362
- if (!n)
438
+ );
439
+ const useVoteFeedbackContext = () => {
440
+ const context = useContext(VoteFeedbackContext);
441
+ if (!context) {
363
442
  throw new Error(
364
443
  "VoteFeedback components must be used within VoteFeedback.Root"
365
444
  );
366
- return n;
367
- }, Le = ({
368
- children: n,
369
- onFeedback: e,
370
- defaultText: t = "",
371
- tx_id: r,
372
- extra_metadata: o,
373
- trigger_name: u
445
+ }
446
+ return context;
447
+ };
448
+ const VoteFeedbackRoot = ({
449
+ children,
450
+ onFeedback,
451
+ defaultText = "",
452
+ tx_id: txIdProp,
453
+ extra_metadata,
454
+ trigger_name
374
455
  }) => {
375
- const d = typeof r == "function" ? r() : r, [f, p] = X(!1), [y, m] = X(t), [A, w] = X(!1), [E, h] = X(null), g = U(null), C = U(null), P = ce(), v = ce(), k = Pe(), O = e || k;
376
- ke(() => {
377
- p(!1), m(t), w(!1), h(null), setTimeout(() => C.current?.focus(), 0);
378
- }, [d, t]);
379
- const R = W(async () => {
380
- h("upvote");
381
- const c = {
382
- tx_id: d,
456
+ const tx_id = typeof txIdProp === "function" ? txIdProp() : txIdProp;
457
+ const [showPopover, setShowPopover] = useState(false);
458
+ const [feedbackText, setFeedbackText] = useState(defaultText);
459
+ const [isSubmitting, setIsSubmitting] = useState(false);
460
+ const [vote, setVote] = useState(null);
461
+ const textareaRef = useRef(null);
462
+ const triggerRef = useRef(null);
463
+ const popoverId = useId();
464
+ const triggerId = useId();
465
+ const defaultHandler = useDefaultFeedbackHandler();
466
+ const handler = onFeedback || defaultHandler;
467
+ useEffect(() => {
468
+ setShowPopover(false);
469
+ setFeedbackText(defaultText);
470
+ setIsSubmitting(false);
471
+ setVote(null);
472
+ setTimeout(() => triggerRef.current?.focus(), 0);
473
+ }, [tx_id, defaultText]);
474
+ const handleUpvote = useCallback(async () => {
475
+ setVote("upvote");
476
+ const data = {
477
+ tx_id,
383
478
  vote: "upvote",
384
- ...o && { extra_metadata: o },
385
- ...u && { trigger_name: u }
479
+ ...extra_metadata && { extra_metadata },
480
+ ...trigger_name && { trigger_name }
386
481
  };
387
482
  try {
388
- w(!0), await O(c);
483
+ setIsSubmitting(true);
484
+ await handler(data);
389
485
  } finally {
390
- w(!1);
486
+ setIsSubmitting(false);
391
487
  }
392
- }, [O, d, o, u]), I = W(async () => {
393
- if (h("downvote"), O) {
394
- const c = {
395
- tx_id: d,
488
+ }, [handler, tx_id, extra_metadata, trigger_name]);
489
+ const handleDownvote = useCallback(async () => {
490
+ setVote("downvote");
491
+ if (handler) {
492
+ const data = {
493
+ tx_id,
396
494
  vote: "downvote",
397
- ...o && { extra_metadata: o },
398
- ...u && { trigger_name: u }
495
+ ...extra_metadata && { extra_metadata },
496
+ ...trigger_name && { trigger_name }
399
497
  };
400
498
  try {
401
- w(!0), await O(c);
499
+ setIsSubmitting(true);
500
+ await handler(data);
402
501
  } finally {
403
- w(!1);
502
+ setIsSubmitting(false);
404
503
  }
405
504
  }
406
- p(!0), setTimeout(() => {
407
- g.current?.focus();
408
- const c = document.createElement("div");
409
- c.setAttribute("aria-live", "polite"), c.setAttribute("aria-atomic", "true"), c.className = "sr-only", c.textContent = "Feedback dialog opened. You can provide additional details about your downvote.", document.body.appendChild(c), setTimeout(() => document.body.removeChild(c), 1e3);
505
+ setShowPopover(true);
506
+ setTimeout(() => {
507
+ textareaRef.current?.focus();
508
+ const announcement = document.createElement("div");
509
+ announcement.setAttribute("aria-live", "polite");
510
+ announcement.setAttribute("aria-atomic", "true");
511
+ announcement.className = "sr-only";
512
+ announcement.textContent = "Feedback dialog opened. You can provide additional details about your downvote.";
513
+ document.body.appendChild(announcement);
514
+ setTimeout(() => document.body.removeChild(announcement), 1e3);
410
515
  }, 0);
411
- }, [O, d, o, u]), L = W(
412
- (c) => {
413
- m(c.target.value);
516
+ }, [handler, tx_id, extra_metadata, trigger_name]);
517
+ const handleTextareaChange = useCallback(
518
+ (e) => {
519
+ setFeedbackText(e.target.value);
414
520
  },
415
521
  []
416
- ), i = W(async () => {
417
- const c = y.trim().length > 0;
418
- if (c) {
419
- const b = {
420
- tx_id: d,
522
+ );
523
+ const handleSubmit = useCallback(async () => {
524
+ const hasText = feedbackText.trim().length > 0;
525
+ if (hasText) {
526
+ const data = {
527
+ tx_id,
421
528
  vote: "downvote",
422
- explanation: y,
423
- ...o && { extra_metadata: o },
424
- ...u && { trigger_name: u }
529
+ explanation: feedbackText,
530
+ ...extra_metadata && { extra_metadata },
531
+ ...trigger_name && { trigger_name }
425
532
  };
426
533
  try {
427
- w(!0), await O(b);
534
+ setIsSubmitting(true);
535
+ await handler(data);
428
536
  } finally {
429
- w(!1);
537
+ setIsSubmitting(false);
430
538
  }
431
539
  }
432
- if (p(!1), m(t), C.current?.focus(), c) {
433
- const b = document.createElement("div");
434
- b.setAttribute("aria-live", "polite"), b.className = "sr-only", b.textContent = "Feedback submitted successfully.", document.body.appendChild(b), setTimeout(() => document.body.removeChild(b), 1e3);
540
+ setShowPopover(false);
541
+ setFeedbackText(defaultText);
542
+ triggerRef.current?.focus();
543
+ if (hasText) {
544
+ const announcement = document.createElement("div");
545
+ announcement.setAttribute("aria-live", "polite");
546
+ announcement.className = "sr-only";
547
+ announcement.textContent = "Feedback submitted successfully.";
548
+ document.body.appendChild(announcement);
549
+ setTimeout(() => document.body.removeChild(announcement), 1e3);
435
550
  }
436
- }, [O, y, t, d, o, u]), l = W(
437
- (c) => {
438
- if (c.key === "Escape")
439
- p(!1), m(t), C.current?.focus();
440
- else if ((c.metaKey || c.ctrlKey) && c.key === "Enter")
441
- c.preventDefault(), i().then((b) => {
551
+ }, [handler, feedbackText, defaultText, tx_id, extra_metadata, trigger_name]);
552
+ const handleKeyDown = useCallback(
553
+ (e) => {
554
+ if (e.key === "Escape") {
555
+ setShowPopover(false);
556
+ setFeedbackText(defaultText);
557
+ triggerRef.current?.focus();
558
+ } else if ((e.metaKey || e.ctrlKey) && e.key === "Enter") {
559
+ e.preventDefault();
560
+ handleSubmit().then((_) => {
442
561
  });
443
- else if (c.key === "Tab" && f) {
444
- const b = document.getElementById(P);
445
- if (b) {
446
- const D = b.querySelectorAll(
562
+ } else if (e.key === "Tab" && showPopover) {
563
+ const popoverElement = document.getElementById(popoverId);
564
+ if (popoverElement) {
565
+ const focusableElements = popoverElement.querySelectorAll(
447
566
  'button, textarea, input, select, a[href], [tabindex]:not([tabindex="-1"])'
448
- ), x = D[0], M = D[D.length - 1];
449
- c.shiftKey && document.activeElement === x ? (c.preventDefault(), M?.focus()) : !c.shiftKey && document.activeElement === M && (c.preventDefault(), x?.focus());
567
+ );
568
+ const firstElement = focusableElements[0];
569
+ const lastElement = focusableElements[focusableElements.length - 1];
570
+ if (e.shiftKey && document.activeElement === firstElement) {
571
+ e.preventDefault();
572
+ lastElement?.focus();
573
+ } else if (!e.shiftKey && document.activeElement === lastElement) {
574
+ e.preventDefault();
575
+ firstElement?.focus();
576
+ }
450
577
  }
451
578
  }
452
579
  },
453
- [i, f, P, t]
454
- ), s = {
455
- onFeedback: O,
456
- showPopover: f,
457
- setShowPopover: p,
458
- feedbackText: y,
459
- setFeedbackText: m,
460
- isSubmitting: A,
461
- setIsSubmitting: w,
462
- vote: E,
463
- handleUpvote: R,
464
- handleDownvote: I,
465
- handleTextareaChange: L,
466
- handleSubmit: i,
467
- handleKeyDown: l,
468
- textareaRef: g,
469
- triggerRef: C,
470
- popoverId: P,
471
- triggerId: v,
472
- tx_id: d,
473
- extra_metadata: o,
474
- trigger_name: u
580
+ [handleSubmit, showPopover, popoverId, defaultText]
581
+ );
582
+ const contextValue = {
583
+ onFeedback: handler,
584
+ showPopover,
585
+ setShowPopover,
586
+ feedbackText,
587
+ setFeedbackText,
588
+ isSubmitting,
589
+ setIsSubmitting,
590
+ vote,
591
+ handleUpvote,
592
+ handleDownvote,
593
+ handleTextareaChange,
594
+ handleSubmit,
595
+ handleKeyDown,
596
+ textareaRef,
597
+ triggerRef,
598
+ popoverId,
599
+ triggerId,
600
+ tx_id,
601
+ extra_metadata,
602
+ trigger_name
475
603
  };
476
- return /* @__PURE__ */ F.jsx(xe.Provider, { value: s, children: n });
477
- }, Me = ({
478
- asChild: n,
479
- children: e,
480
- onClick: t,
481
- ...r
604
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(VoteFeedbackContext.Provider, { value: contextValue, children });
605
+ };
606
+ const UpvoteButton = ({
607
+ asChild,
608
+ children,
609
+ onClick,
610
+ ...props
482
611
  }) => {
483
- const { handleUpvote: o, isSubmitting: u, vote: d } = te(), f = W(
484
- (m) => {
485
- o(), t?.(m);
612
+ const { handleUpvote, isSubmitting, vote } = useVoteFeedbackContext();
613
+ const handleClick = useCallback(
614
+ (e) => {
615
+ handleUpvote();
616
+ onClick?.(e);
486
617
  },
487
- [o, t]
488
- ), p = {
489
- ...r,
490
- onClick: f,
491
- disabled: u || r.disabled,
492
- "aria-label": r["aria-label"] || "Upvote feedback",
618
+ [handleUpvote, onClick]
619
+ );
620
+ const slotProps = {
621
+ ...props,
622
+ onClick: handleClick,
623
+ disabled: isSubmitting || props.disabled,
624
+ "aria-label": props["aria-label"] || "Upvote feedback",
493
625
  type: "button"
494
- }, y = d === "upvote";
495
- if (n) {
496
- const m = typeof e == "function" ? e({ isSelected: y }) : e;
497
- if (Z(m))
498
- return Q(
499
- m,
500
- ee(p, m.props)
626
+ };
627
+ const isSelected = vote === "upvote";
628
+ if (asChild) {
629
+ const child = typeof children === "function" ? children({ isSelected }) : children;
630
+ if (isValidElement(child)) {
631
+ return cloneElement(
632
+ child,
633
+ mergeProps(slotProps, child.props)
501
634
  );
635
+ }
502
636
  }
503
- return /* @__PURE__ */ F.jsx("button", { ...p, children: typeof e == "function" ? e({ isSelected: y }) : e });
504
- }, $e = ({
505
- asChild: n,
506
- children: e,
507
- onClick: t,
508
- ...r
637
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("button", { ...slotProps, children: typeof children === "function" ? children({ isSelected }) : children });
638
+ };
639
+ const DownvoteButton = ({
640
+ asChild,
641
+ children,
642
+ onClick,
643
+ ...props
509
644
  }) => {
510
645
  const {
511
- handleDownvote: o,
512
- showPopover: u,
513
- isSubmitting: d,
514
- popoverId: f,
515
- triggerId: p,
516
- triggerRef: y,
517
- vote: m
518
- } = te(), A = W(
519
- (h) => {
520
- o(), t?.(h);
646
+ handleDownvote,
647
+ showPopover,
648
+ isSubmitting,
649
+ popoverId,
650
+ triggerId,
651
+ triggerRef,
652
+ vote
653
+ } = useVoteFeedbackContext();
654
+ const handleClick = useCallback(
655
+ (e) => {
656
+ handleDownvote();
657
+ onClick?.(e);
521
658
  },
522
- [o, t]
523
- ), w = {
524
- ...r,
525
- ref: y,
526
- onClick: A,
527
- disabled: d || r.disabled,
528
- "aria-label": r["aria-label"] || "Downvote feedback",
529
- "aria-expanded": u,
530
- "aria-controls": f,
531
- id: p,
659
+ [handleDownvote, onClick]
660
+ );
661
+ const slotProps = {
662
+ ...props,
663
+ ref: triggerRef,
664
+ onClick: handleClick,
665
+ disabled: isSubmitting || props.disabled,
666
+ "aria-label": props["aria-label"] || "Downvote feedback",
667
+ "aria-expanded": showPopover,
668
+ "aria-controls": popoverId,
669
+ id: triggerId,
532
670
  type: "button"
533
- }, E = m === "downvote";
534
- if (n) {
535
- const h = typeof e == "function" ? e({ isSelected: E }) : e;
536
- if (Z(h))
537
- return Q(h, ee(w, h.props));
538
- if (h)
539
- return h;
671
+ };
672
+ const isSelected = vote === "downvote";
673
+ if (asChild) {
674
+ const child = typeof children === "function" ? children({ isSelected }) : children;
675
+ if (isValidElement(child)) {
676
+ return cloneElement(child, mergeProps(slotProps, child.props));
677
+ } else if (child) {
678
+ return child;
679
+ }
540
680
  }
541
- return /* @__PURE__ */ F.jsx("button", { ...w, children: typeof e == "function" ? e({ isSelected: E }) : e });
542
- }, qe = ({ asChild: n, children: e, ...t }) => {
543
- const { showPopover: r, handleKeyDown: o, popoverId: u, triggerId: d } = te();
544
- if (!r)
681
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("button", { ...slotProps, children: typeof children === "function" ? children({ isSelected }) : children });
682
+ };
683
+ const Popover = ({ asChild, children, ...props }) => {
684
+ const { showPopover, handleKeyDown, popoverId, triggerId } = useVoteFeedbackContext();
685
+ if (!showPopover) {
545
686
  return null;
546
- const f = {
547
- ...t,
687
+ }
688
+ const slotProps = {
689
+ ...props,
548
690
  role: "dialog",
549
- "aria-labelledby": d,
550
- "aria-modal": !0,
551
- "aria-describedby": `${u}-description`,
552
- id: u,
553
- onKeyDown: o,
691
+ "aria-labelledby": triggerId,
692
+ "aria-modal": true,
693
+ "aria-describedby": `${popoverId}-description`,
694
+ id: popoverId,
695
+ onKeyDown: handleKeyDown,
554
696
  tabIndex: -1
555
697
  };
556
- return n && Z(e) ? /* @__PURE__ */ F.jsxs(F.Fragment, { children: [
557
- Q(
558
- e,
559
- ee(f, e.props)
560
- ),
561
- /* @__PURE__ */ F.jsx("div", { id: `${u}-description`, className: "sr-only", children: "Provide additional feedback for your downvote" })
562
- ] }) : /* @__PURE__ */ F.jsxs("div", { ...f, children: [
563
- /* @__PURE__ */ F.jsx("div", { id: `${u}-description`, className: "sr-only", children: "Provide additional feedback for your downvote" }),
564
- e
698
+ if (asChild && isValidElement(children)) {
699
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
700
+ cloneElement(
701
+ children,
702
+ mergeProps(slotProps, children.props)
703
+ ),
704
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { id: `${popoverId}-description`, className: "sr-only", children: "Provide additional feedback for your downvote" })
705
+ ] });
706
+ }
707
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { ...slotProps, children: [
708
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { id: `${popoverId}-description`, className: "sr-only", children: "Provide additional feedback for your downvote" }),
709
+ children
565
710
  ] });
566
- }, We = ({ asChild: n, value: e, onChange: t, ...r }) => {
711
+ };
712
+ const Textarea = ({ asChild, value, onChange, ...props }) => {
567
713
  const {
568
- feedbackText: o,
569
- handleTextareaChange: u,
570
- textareaRef: d,
571
- handleKeyDown: f,
572
- popoverId: p
573
- } = te(), y = {
574
- ...r,
575
- ref: d,
576
- value: e !== void 0 ? e : o,
577
- onChange: t || u,
578
- onKeyDown: f,
579
- placeholder: r.placeholder || "What did we miss?",
580
- "aria-label": r["aria-label"] || "Additional feedback",
581
- "aria-describedby": `${p}-help`,
582
- rows: r.rows || 3
714
+ feedbackText,
715
+ handleTextareaChange,
716
+ textareaRef,
717
+ handleKeyDown,
718
+ popoverId
719
+ } = useVoteFeedbackContext();
720
+ const slotProps = {
721
+ ...props,
722
+ ref: textareaRef,
723
+ value: value !== void 0 ? value : feedbackText,
724
+ onChange: onChange || handleTextareaChange,
725
+ onKeyDown: handleKeyDown,
726
+ placeholder: props.placeholder || "What did we miss?",
727
+ "aria-label": props["aria-label"] || "Additional feedback",
728
+ "aria-describedby": `${popoverId}-help`,
729
+ rows: props.rows || 3
583
730
  };
584
- return n && Z(r.children) ? Q(
585
- r.children,
586
- ee(y, r.children.props)
587
- ) : /* @__PURE__ */ F.jsx("textarea", { ...y });
588
- }, Ye = ({
589
- asChild: n,
590
- children: e,
591
- onClick: t,
592
- ...r
731
+ if (asChild && isValidElement(props.children)) {
732
+ return cloneElement(
733
+ props.children,
734
+ mergeProps(slotProps, props.children.props)
735
+ );
736
+ }
737
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("textarea", { ...slotProps });
738
+ };
739
+ const SubmitButton = ({
740
+ asChild,
741
+ children,
742
+ onClick,
743
+ ...props
593
744
  }) => {
594
- const { handleSubmit: o, isSubmitting: u, feedbackText: d } = te(), f = W(
595
- (A) => {
596
- o(), t?.(A);
745
+ const { handleSubmit, isSubmitting, feedbackText } = useVoteFeedbackContext();
746
+ const handleClick = useCallback(
747
+ (e) => {
748
+ handleSubmit();
749
+ onClick?.(e);
597
750
  },
598
- [o, t]
599
- ), p = d.trim().length > 0, y = p ? "Submit feedback" : "Close without feedback", m = {
600
- ...r,
601
- onClick: f,
602
- disabled: u || r.disabled,
751
+ [handleSubmit, onClick]
752
+ );
753
+ const hasText = feedbackText.trim().length > 0;
754
+ const buttonText = hasText ? "Submit feedback" : "Close without feedback";
755
+ const slotProps = {
756
+ ...props,
757
+ onClick: handleClick,
758
+ disabled: isSubmitting || props.disabled,
603
759
  type: "button",
604
- "aria-label": r["aria-label"] || y,
605
- "aria-describedby": p ? void 0 : "submit-help"
760
+ "aria-label": props["aria-label"] || buttonText,
761
+ "aria-describedby": hasText ? void 0 : "submit-help"
606
762
  };
607
- return n && Z(e) ? /* @__PURE__ */ F.jsxs(F.Fragment, { children: [
608
- Q(
609
- e,
610
- ee(m, e.props)
611
- ),
612
- !p && /* @__PURE__ */ F.jsx("span", { id: "submit-help", className: "sr-only", children: "This will close the dialog without submitting feedback" })
613
- ] }) : /* @__PURE__ */ F.jsxs("button", { ...m, children: [
614
- e,
615
- !p && /* @__PURE__ */ F.jsx("span", { id: "submit-help", className: "sr-only", children: "This will close the dialog without submitting feedback" })
763
+ if (asChild && isValidElement(children)) {
764
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
765
+ cloneElement(
766
+ children,
767
+ mergeProps(slotProps, children.props)
768
+ ),
769
+ !hasText && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { id: "submit-help", className: "sr-only", children: "This will close the dialog without submitting feedback" })
770
+ ] });
771
+ }
772
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("button", { ...slotProps, children: [
773
+ children,
774
+ !hasText && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { id: "submit-help", className: "sr-only", children: "This will close the dialog without submitting feedback" })
616
775
  ] });
617
- }, mt = {
618
- Root: Le,
619
- UpvoteButton: Me,
620
- DownvoteButton: $e,
621
- Popover: qe,
622
- Textarea: We,
623
- SubmitButton: Ye
624
776
  };
625
- var ie = { exports: {} }, ze = ie.exports, he;
626
- function Ke() {
627
- return he || (he = 1, function(n, e) {
628
- (function(t, r) {
629
- var o = r(t);
630
- n.exports = o;
631
- })(ze, function(t) {
632
- var r = ["N", "E", "A", "D"];
633
- function o(i, l) {
634
- i.super_ = l, i.prototype = Object.create(l.prototype, {
777
+ const VoteFeedback = {
778
+ Root: VoteFeedbackRoot,
779
+ UpvoteButton,
780
+ DownvoteButton,
781
+ Popover,
782
+ Textarea,
783
+ SubmitButton
784
+ };
785
+ var deepDiff$1 = { exports: {} };
786
+ var deepDiff = deepDiff$1.exports;
787
+ var hasRequiredDeepDiff;
788
+ function requireDeepDiff() {
789
+ if (hasRequiredDeepDiff) return deepDiff$1.exports;
790
+ hasRequiredDeepDiff = 1;
791
+ (function(module, exports) {
792
+ (function(root, factory) {
793
+ var deepDiff2 = factory(root);
794
+ {
795
+ module.exports = deepDiff2;
796
+ }
797
+ })(deepDiff, function(root) {
798
+ var validKinds = ["N", "E", "A", "D"];
799
+ function inherits(ctor, superCtor) {
800
+ ctor.super_ = superCtor;
801
+ ctor.prototype = Object.create(superCtor.prototype, {
635
802
  constructor: {
636
- value: i,
637
- enumerable: !1,
638
- writable: !0,
639
- configurable: !0
803
+ value: ctor,
804
+ enumerable: false,
805
+ writable: true,
806
+ configurable: true
640
807
  }
641
808
  });
642
809
  }
643
- function u(i, l) {
810
+ function Diff2(kind, path) {
644
811
  Object.defineProperty(this, "kind", {
645
- value: i,
646
- enumerable: !0
647
- }), l && l.length && Object.defineProperty(this, "path", {
648
- value: l,
649
- enumerable: !0
812
+ value: kind,
813
+ enumerable: true
650
814
  });
815
+ if (path && path.length) {
816
+ Object.defineProperty(this, "path", {
817
+ value: path,
818
+ enumerable: true
819
+ });
820
+ }
651
821
  }
652
- function d(i, l, s) {
653
- d.super_.call(this, "E", i), Object.defineProperty(this, "lhs", {
654
- value: l,
655
- enumerable: !0
656
- }), Object.defineProperty(this, "rhs", {
657
- value: s,
658
- enumerable: !0
822
+ function DiffEdit(path, origin, value) {
823
+ DiffEdit.super_.call(this, "E", path);
824
+ Object.defineProperty(this, "lhs", {
825
+ value: origin,
826
+ enumerable: true
827
+ });
828
+ Object.defineProperty(this, "rhs", {
829
+ value,
830
+ enumerable: true
659
831
  });
660
832
  }
661
- o(d, u);
662
- function f(i, l) {
663
- f.super_.call(this, "N", i), Object.defineProperty(this, "rhs", {
664
- value: l,
665
- enumerable: !0
833
+ inherits(DiffEdit, Diff2);
834
+ function DiffNew(path, value) {
835
+ DiffNew.super_.call(this, "N", path);
836
+ Object.defineProperty(this, "rhs", {
837
+ value,
838
+ enumerable: true
666
839
  });
667
840
  }
668
- o(f, u);
669
- function p(i, l) {
670
- p.super_.call(this, "D", i), Object.defineProperty(this, "lhs", {
671
- value: l,
672
- enumerable: !0
841
+ inherits(DiffNew, Diff2);
842
+ function DiffDeleted(path, value) {
843
+ DiffDeleted.super_.call(this, "D", path);
844
+ Object.defineProperty(this, "lhs", {
845
+ value,
846
+ enumerable: true
673
847
  });
674
848
  }
675
- o(p, u);
676
- function y(i, l, s) {
677
- y.super_.call(this, "A", i), Object.defineProperty(this, "index", {
678
- value: l,
679
- enumerable: !0
680
- }), Object.defineProperty(this, "item", {
681
- value: s,
682
- enumerable: !0
849
+ inherits(DiffDeleted, Diff2);
850
+ function DiffArray(path, index, item) {
851
+ DiffArray.super_.call(this, "A", path);
852
+ Object.defineProperty(this, "index", {
853
+ value: index,
854
+ enumerable: true
855
+ });
856
+ Object.defineProperty(this, "item", {
857
+ value: item,
858
+ enumerable: true
683
859
  });
684
860
  }
685
- o(y, u);
686
- function m(i, l, s) {
687
- var c = i.slice(l + 1 || i.length);
688
- return i.length = l < 0 ? i.length + l : l, i.push.apply(i, c), i;
861
+ inherits(DiffArray, Diff2);
862
+ function arrayRemove(arr, from, to) {
863
+ var rest = arr.slice(from + 1 || arr.length);
864
+ arr.length = from < 0 ? arr.length + from : from;
865
+ arr.push.apply(arr, rest);
866
+ return arr;
689
867
  }
690
- function A(i) {
691
- var l = typeof i;
692
- return l !== "object" ? l : i === Math ? "math" : i === null ? "null" : Array.isArray(i) ? "array" : Object.prototype.toString.call(i) === "[object Date]" ? "date" : typeof i.toString == "function" && /^\/.*\//.test(i.toString()) ? "regexp" : "object";
868
+ function realTypeOf(subject) {
869
+ var type = typeof subject;
870
+ if (type !== "object") {
871
+ return type;
872
+ }
873
+ if (subject === Math) {
874
+ return "math";
875
+ } else if (subject === null) {
876
+ return "null";
877
+ } else if (Array.isArray(subject)) {
878
+ return "array";
879
+ } else if (Object.prototype.toString.call(subject) === "[object Date]") {
880
+ return "date";
881
+ } else if (typeof subject.toString === "function" && /^\/.*\//.test(subject.toString())) {
882
+ return "regexp";
883
+ }
884
+ return "object";
693
885
  }
694
- function w(i) {
695
- var l = 0;
696
- if (i.length === 0)
697
- return l;
698
- for (var s = 0; s < i.length; s++) {
699
- var c = i.charCodeAt(s);
700
- l = (l << 5) - l + c, l = l & l;
886
+ function hashThisString(string) {
887
+ var hash = 0;
888
+ if (string.length === 0) {
889
+ return hash;
701
890
  }
702
- return l;
891
+ for (var i = 0; i < string.length; i++) {
892
+ var char = string.charCodeAt(i);
893
+ hash = (hash << 5) - hash + char;
894
+ hash = hash & hash;
895
+ }
896
+ return hash;
703
897
  }
704
- function E(i) {
705
- var l = 0, s = A(i);
706
- if (s === "array") {
707
- i.forEach(function(M) {
708
- l += E(M);
898
+ function getOrderIndependentHash(object) {
899
+ var accum = 0;
900
+ var type = realTypeOf(object);
901
+ if (type === "array") {
902
+ object.forEach(function(item) {
903
+ accum += getOrderIndependentHash(item);
709
904
  });
710
- var c = "[type: array, hash: " + l + "]";
711
- return l + w(c);
905
+ var arrayString = "[type: array, hash: " + accum + "]";
906
+ return accum + hashThisString(arrayString);
712
907
  }
713
- if (s === "object") {
714
- for (var b in i)
715
- if (i.hasOwnProperty(b)) {
716
- var D = "[ type: object, key: " + b + ", value hash: " + E(i[b]) + "]";
717
- l += w(D);
908
+ if (type === "object") {
909
+ for (var key in object) {
910
+ if (object.hasOwnProperty(key)) {
911
+ var keyValueString = "[ type: object, key: " + key + ", value hash: " + getOrderIndependentHash(object[key]) + "]";
912
+ accum += hashThisString(keyValueString);
718
913
  }
719
- return l;
914
+ }
915
+ return accum;
720
916
  }
721
- var x = "[ type: " + s + " ; value: " + i + "]";
722
- return l + w(x);
917
+ var stringToHash = "[ type: " + type + " ; value: " + object + "]";
918
+ return accum + hashThisString(stringToHash);
723
919
  }
724
- function h(i, l, s, c, b, D, x, M) {
725
- s = s || [], b = b || [], x = x || [];
726
- var N = b.slice(0);
727
- if (typeof D < "u" && D !== null) {
728
- if (c) {
729
- if (typeof c == "function" && c(N, D))
920
+ function deepDiff2(lhs, rhs, changes, prefilter, path, key, stack, orderIndependent) {
921
+ changes = changes || [];
922
+ path = path || [];
923
+ stack = stack || [];
924
+ var currentPath = path.slice(0);
925
+ if (typeof key !== "undefined" && key !== null) {
926
+ if (prefilter) {
927
+ if (typeof prefilter === "function" && prefilter(currentPath, key)) {
730
928
  return;
731
- if (typeof c == "object") {
732
- if (c.prefilter && c.prefilter(N, D))
929
+ } else if (typeof prefilter === "object") {
930
+ if (prefilter.prefilter && prefilter.prefilter(currentPath, key)) {
733
931
  return;
734
- if (c.normalize) {
735
- var H = c.normalize(N, D, i, l);
736
- H && (i = H[0], l = H[1]);
932
+ }
933
+ if (prefilter.normalize) {
934
+ var alt = prefilter.normalize(currentPath, key, lhs, rhs);
935
+ if (alt) {
936
+ lhs = alt[0];
937
+ rhs = alt[1];
938
+ }
737
939
  }
738
940
  }
739
941
  }
740
- N.push(D);
942
+ currentPath.push(key);
741
943
  }
742
- A(i) === "regexp" && A(l) === "regexp" && (i = i.toString(), l = l.toString());
743
- var J = typeof i, ne = typeof l, a, T, _, S, q = J !== "undefined" || x && x.length > 0 && x[x.length - 1].lhs && Object.getOwnPropertyDescriptor(x[x.length - 1].lhs, D), $ = ne !== "undefined" || x && x.length > 0 && x[x.length - 1].rhs && Object.getOwnPropertyDescriptor(x[x.length - 1].rhs, D);
744
- if (!q && $)
745
- s.push(new f(N, l));
746
- else if (!$ && q)
747
- s.push(new p(N, i));
748
- else if (A(i) !== A(l))
749
- s.push(new d(N, i, l));
750
- else if (A(i) === "date" && i - l !== 0)
751
- s.push(new d(N, i, l));
752
- else if (J === "object" && i !== null && l !== null) {
753
- for (a = x.length - 1; a > -1; --a)
754
- if (x[a].lhs === i) {
755
- S = !0;
944
+ if (realTypeOf(lhs) === "regexp" && realTypeOf(rhs) === "regexp") {
945
+ lhs = lhs.toString();
946
+ rhs = rhs.toString();
947
+ }
948
+ var ltype = typeof lhs;
949
+ var rtype = typeof rhs;
950
+ var i, j, k, other;
951
+ var ldefined = ltype !== "undefined" || stack && stack.length > 0 && stack[stack.length - 1].lhs && Object.getOwnPropertyDescriptor(stack[stack.length - 1].lhs, key);
952
+ var rdefined = rtype !== "undefined" || stack && stack.length > 0 && stack[stack.length - 1].rhs && Object.getOwnPropertyDescriptor(stack[stack.length - 1].rhs, key);
953
+ if (!ldefined && rdefined) {
954
+ changes.push(new DiffNew(currentPath, rhs));
955
+ } else if (!rdefined && ldefined) {
956
+ changes.push(new DiffDeleted(currentPath, lhs));
957
+ } else if (realTypeOf(lhs) !== realTypeOf(rhs)) {
958
+ changes.push(new DiffEdit(currentPath, lhs, rhs));
959
+ } else if (realTypeOf(lhs) === "date" && lhs - rhs !== 0) {
960
+ changes.push(new DiffEdit(currentPath, lhs, rhs));
961
+ } else if (ltype === "object" && lhs !== null && rhs !== null) {
962
+ for (i = stack.length - 1; i > -1; --i) {
963
+ if (stack[i].lhs === lhs) {
964
+ other = true;
756
965
  break;
757
966
  }
758
- if (S)
759
- i !== l && s.push(new d(N, i, l));
760
- else {
761
- if (x.push({ lhs: i, rhs: l }), Array.isArray(i)) {
762
- for (M && (i.sort(function(j, Y) {
763
- return E(j) - E(Y);
764
- }), l.sort(function(j, Y) {
765
- return E(j) - E(Y);
766
- })), a = l.length - 1, T = i.length - 1; a > T; )
767
- s.push(new y(N, a, new f(void 0, l[a--])));
768
- for (; T > a; )
769
- s.push(new y(N, T, new p(void 0, i[T--])));
770
- for (; a >= 0; --a)
771
- h(i[a], l[a], s, c, N, a, x, M);
967
+ }
968
+ if (!other) {
969
+ stack.push({ lhs, rhs });
970
+ if (Array.isArray(lhs)) {
971
+ if (orderIndependent) {
972
+ lhs.sort(function(a, b) {
973
+ return getOrderIndependentHash(a) - getOrderIndependentHash(b);
974
+ });
975
+ rhs.sort(function(a, b) {
976
+ return getOrderIndependentHash(a) - getOrderIndependentHash(b);
977
+ });
978
+ }
979
+ i = rhs.length - 1;
980
+ j = lhs.length - 1;
981
+ while (i > j) {
982
+ changes.push(new DiffArray(currentPath, i, new DiffNew(void 0, rhs[i--])));
983
+ }
984
+ while (j > i) {
985
+ changes.push(new DiffArray(currentPath, j, new DiffDeleted(void 0, lhs[j--])));
986
+ }
987
+ for (; i >= 0; --i) {
988
+ deepDiff2(lhs[i], rhs[i], changes, prefilter, currentPath, i, stack, orderIndependent);
989
+ }
772
990
  } else {
773
- var B = Object.keys(i), K = Object.keys(l);
774
- for (a = 0; a < B.length; ++a)
775
- _ = B[a], S = K.indexOf(_), S >= 0 ? (h(i[_], l[_], s, c, N, _, x, M), K[S] = null) : h(i[_], void 0, s, c, N, _, x, M);
776
- for (a = 0; a < K.length; ++a)
777
- _ = K[a], _ && h(void 0, l[_], s, c, N, _, x, M);
991
+ var akeys = Object.keys(lhs);
992
+ var pkeys = Object.keys(rhs);
993
+ for (i = 0; i < akeys.length; ++i) {
994
+ k = akeys[i];
995
+ other = pkeys.indexOf(k);
996
+ if (other >= 0) {
997
+ deepDiff2(lhs[k], rhs[k], changes, prefilter, currentPath, k, stack, orderIndependent);
998
+ pkeys[other] = null;
999
+ } else {
1000
+ deepDiff2(lhs[k], void 0, changes, prefilter, currentPath, k, stack, orderIndependent);
1001
+ }
1002
+ }
1003
+ for (i = 0; i < pkeys.length; ++i) {
1004
+ k = pkeys[i];
1005
+ if (k) {
1006
+ deepDiff2(void 0, rhs[k], changes, prefilter, currentPath, k, stack, orderIndependent);
1007
+ }
1008
+ }
778
1009
  }
779
- x.length = x.length - 1;
1010
+ stack.length = stack.length - 1;
1011
+ } else if (lhs !== rhs) {
1012
+ changes.push(new DiffEdit(currentPath, lhs, rhs));
1013
+ }
1014
+ } else if (lhs !== rhs) {
1015
+ if (!(ltype === "number" && isNaN(lhs) && isNaN(rhs))) {
1016
+ changes.push(new DiffEdit(currentPath, lhs, rhs));
780
1017
  }
781
- } else i !== l && (J === "number" && isNaN(i) && isNaN(l) || s.push(new d(N, i, l)));
1018
+ }
782
1019
  }
783
- function g(i, l, s, c, b) {
784
- var D = [];
785
- if (h(i, l, D, c, null, null, null, b), s)
786
- for (var x = 0; x < D.length; ++x)
787
- s(D[x]);
788
- return D;
1020
+ function observableDiff(lhs, rhs, observer, prefilter, orderIndependent) {
1021
+ var changes = [];
1022
+ deepDiff2(lhs, rhs, changes, prefilter, null, null, null, orderIndependent);
1023
+ if (observer) {
1024
+ for (var i = 0; i < changes.length; ++i) {
1025
+ observer(changes[i]);
1026
+ }
1027
+ }
1028
+ return changes;
789
1029
  }
790
- function C(i, l, s, c, b, D, x) {
791
- return h(i, l, s, c, b, D, x, !0);
1030
+ function orderIndependentDeepDiff(lhs, rhs, changes, prefilter, path, key, stack) {
1031
+ return deepDiff2(lhs, rhs, changes, prefilter, path, key, stack, true);
792
1032
  }
793
- function P(i, l, s, c) {
794
- var b = c ? function(x) {
795
- x && c.push(x);
796
- } : void 0, D = g(i, l, b, s);
797
- return c || (D.length ? D : void 0);
1033
+ function accumulateDiff(lhs, rhs, prefilter, accum) {
1034
+ var observer = accum ? function(difference) {
1035
+ if (difference) {
1036
+ accum.push(difference);
1037
+ }
1038
+ } : void 0;
1039
+ var changes = observableDiff(lhs, rhs, observer, prefilter);
1040
+ return accum ? accum : changes.length ? changes : void 0;
798
1041
  }
799
- function v(i, l, s, c) {
800
- var b = c ? function(x) {
801
- x && c.push(x);
802
- } : void 0, D = g(i, l, b, s, !0);
803
- return c || (D.length ? D : void 0);
1042
+ function accumulateOrderIndependentDiff(lhs, rhs, prefilter, accum) {
1043
+ var observer = accum ? function(difference) {
1044
+ if (difference) {
1045
+ accum.push(difference);
1046
+ }
1047
+ } : void 0;
1048
+ var changes = observableDiff(lhs, rhs, observer, prefilter, true);
1049
+ return accum ? accum : changes.length ? changes : void 0;
804
1050
  }
805
- function k(i, l, s) {
806
- if (s.path && s.path.length) {
807
- var c = i[l], b, D = s.path.length - 1;
808
- for (b = 0; b < D; b++)
809
- c = c[s.path[b]];
810
- switch (s.kind) {
1051
+ function applyArrayChange(arr, index, change) {
1052
+ if (change.path && change.path.length) {
1053
+ var it = arr[index], i, u = change.path.length - 1;
1054
+ for (i = 0; i < u; i++) {
1055
+ it = it[change.path[i]];
1056
+ }
1057
+ switch (change.kind) {
811
1058
  case "A":
812
- k(c[s.path[b]], s.index, s.item);
1059
+ applyArrayChange(it[change.path[i]], change.index, change.item);
813
1060
  break;
814
1061
  case "D":
815
- delete c[s.path[b]];
1062
+ delete it[change.path[i]];
816
1063
  break;
817
1064
  case "E":
818
1065
  case "N":
819
- c[s.path[b]] = s.rhs;
1066
+ it[change.path[i]] = change.rhs;
820
1067
  break;
821
1068
  }
822
- } else
823
- switch (s.kind) {
1069
+ } else {
1070
+ switch (change.kind) {
824
1071
  case "A":
825
- k(i[l], s.index, s.item);
1072
+ applyArrayChange(arr[index], change.index, change.item);
826
1073
  break;
827
1074
  case "D":
828
- i = m(i, l);
1075
+ arr = arrayRemove(arr, index);
829
1076
  break;
830
1077
  case "E":
831
1078
  case "N":
832
- i[l] = s.rhs;
1079
+ arr[index] = change.rhs;
833
1080
  break;
834
1081
  }
835
- return i;
1082
+ }
1083
+ return arr;
836
1084
  }
837
- function O(i, l, s) {
838
- if (typeof s > "u" && l && ~r.indexOf(l.kind) && (s = l), i && s && s.kind) {
839
- for (var c = i, b = -1, D = s.path ? s.path.length - 1 : 0; ++b < D; )
840
- typeof c[s.path[b]] > "u" && (c[s.path[b]] = typeof s.path[b + 1] < "u" && typeof s.path[b + 1] == "number" ? [] : {}), c = c[s.path[b]];
841
- switch (s.kind) {
1085
+ function applyChange(target, source, change) {
1086
+ if (typeof change === "undefined" && source && ~validKinds.indexOf(source.kind)) {
1087
+ change = source;
1088
+ }
1089
+ if (target && change && change.kind) {
1090
+ var it = target, i = -1, last = change.path ? change.path.length - 1 : 0;
1091
+ while (++i < last) {
1092
+ if (typeof it[change.path[i]] === "undefined") {
1093
+ it[change.path[i]] = typeof change.path[i + 1] !== "undefined" && typeof change.path[i + 1] === "number" ? [] : {};
1094
+ }
1095
+ it = it[change.path[i]];
1096
+ }
1097
+ switch (change.kind) {
842
1098
  case "A":
843
- s.path && typeof c[s.path[b]] > "u" && (c[s.path[b]] = []), k(s.path ? c[s.path[b]] : c, s.index, s.item);
1099
+ if (change.path && typeof it[change.path[i]] === "undefined") {
1100
+ it[change.path[i]] = [];
1101
+ }
1102
+ applyArrayChange(change.path ? it[change.path[i]] : it, change.index, change.item);
844
1103
  break;
845
1104
  case "D":
846
- delete c[s.path[b]];
1105
+ delete it[change.path[i]];
847
1106
  break;
848
1107
  case "E":
849
1108
  case "N":
850
- c[s.path[b]] = s.rhs;
1109
+ it[change.path[i]] = change.rhs;
851
1110
  break;
852
1111
  }
853
1112
  }
854
1113
  }
855
- function R(i, l, s) {
856
- if (s.path && s.path.length) {
857
- var c = i[l], b, D = s.path.length - 1;
858
- for (b = 0; b < D; b++)
859
- c = c[s.path[b]];
860
- switch (s.kind) {
1114
+ function revertArrayChange(arr, index, change) {
1115
+ if (change.path && change.path.length) {
1116
+ var it = arr[index], i, u = change.path.length - 1;
1117
+ for (i = 0; i < u; i++) {
1118
+ it = it[change.path[i]];
1119
+ }
1120
+ switch (change.kind) {
861
1121
  case "A":
862
- R(c[s.path[b]], s.index, s.item);
1122
+ revertArrayChange(it[change.path[i]], change.index, change.item);
863
1123
  break;
864
1124
  case "D":
865
- c[s.path[b]] = s.lhs;
1125
+ it[change.path[i]] = change.lhs;
866
1126
  break;
867
1127
  case "E":
868
- c[s.path[b]] = s.lhs;
1128
+ it[change.path[i]] = change.lhs;
869
1129
  break;
870
1130
  case "N":
871
- delete c[s.path[b]];
1131
+ delete it[change.path[i]];
872
1132
  break;
873
1133
  }
874
- } else
875
- switch (s.kind) {
1134
+ } else {
1135
+ switch (change.kind) {
876
1136
  case "A":
877
- R(i[l], s.index, s.item);
1137
+ revertArrayChange(arr[index], change.index, change.item);
878
1138
  break;
879
1139
  case "D":
880
- i[l] = s.lhs;
1140
+ arr[index] = change.lhs;
881
1141
  break;
882
1142
  case "E":
883
- i[l] = s.lhs;
1143
+ arr[index] = change.lhs;
884
1144
  break;
885
1145
  case "N":
886
- i = m(i, l);
1146
+ arr = arrayRemove(arr, index);
887
1147
  break;
888
1148
  }
889
- return i;
1149
+ }
1150
+ return arr;
890
1151
  }
891
- function I(i, l, s) {
892
- if (i && l && s && s.kind) {
893
- var c = i, b, D;
894
- for (D = s.path.length - 1, b = 0; b < D; b++)
895
- typeof c[s.path[b]] > "u" && (c[s.path[b]] = {}), c = c[s.path[b]];
896
- switch (s.kind) {
1152
+ function revertChange(target, source, change) {
1153
+ if (target && source && change && change.kind) {
1154
+ var it = target, i, u;
1155
+ u = change.path.length - 1;
1156
+ for (i = 0; i < u; i++) {
1157
+ if (typeof it[change.path[i]] === "undefined") {
1158
+ it[change.path[i]] = {};
1159
+ }
1160
+ it = it[change.path[i]];
1161
+ }
1162
+ switch (change.kind) {
897
1163
  case "A":
898
- R(c[s.path[b]], s.index, s.item);
1164
+ revertArrayChange(it[change.path[i]], change.index, change.item);
899
1165
  break;
900
1166
  case "D":
901
- c[s.path[b]] = s.lhs;
1167
+ it[change.path[i]] = change.lhs;
902
1168
  break;
903
1169
  case "E":
904
- c[s.path[b]] = s.lhs;
1170
+ it[change.path[i]] = change.lhs;
905
1171
  break;
906
1172
  case "N":
907
- delete c[s.path[b]];
1173
+ delete it[change.path[i]];
908
1174
  break;
909
1175
  }
910
1176
  }
911
1177
  }
912
- function L(i, l, s) {
913
- if (i && l) {
914
- var c = function(b) {
915
- (!s || s(i, l, b)) && O(i, l, b);
1178
+ function applyDiff(target, source, filter) {
1179
+ if (target && source) {
1180
+ var onChange = function(change) {
1181
+ if (!filter || filter(target, source, change)) {
1182
+ applyChange(target, source, change);
1183
+ }
916
1184
  };
917
- g(i, l, c);
1185
+ observableDiff(target, source, onChange);
918
1186
  }
919
1187
  }
920
- return Object.defineProperties(P, {
1188
+ Object.defineProperties(accumulateDiff, {
921
1189
  diff: {
922
- value: P,
923
- enumerable: !0
1190
+ value: accumulateDiff,
1191
+ enumerable: true
924
1192
  },
925
1193
  orderIndependentDiff: {
926
- value: v,
927
- enumerable: !0
1194
+ value: accumulateOrderIndependentDiff,
1195
+ enumerable: true
928
1196
  },
929
1197
  observableDiff: {
930
- value: g,
931
- enumerable: !0
1198
+ value: observableDiff,
1199
+ enumerable: true
932
1200
  },
933
1201
  orderIndependentObservableDiff: {
934
- value: C,
935
- enumerable: !0
1202
+ value: orderIndependentDeepDiff,
1203
+ enumerable: true
936
1204
  },
937
1205
  orderIndepHash: {
938
- value: E,
939
- enumerable: !0
1206
+ value: getOrderIndependentHash,
1207
+ enumerable: true
940
1208
  },
941
1209
  applyDiff: {
942
- value: L,
943
- enumerable: !0
1210
+ value: applyDiff,
1211
+ enumerable: true
944
1212
  },
945
1213
  applyChange: {
946
- value: O,
947
- enumerable: !0
1214
+ value: applyChange,
1215
+ enumerable: true
948
1216
  },
949
1217
  revertChange: {
950
- value: I,
951
- enumerable: !0
1218
+ value: revertChange,
1219
+ enumerable: true
952
1220
  },
953
1221
  isConflict: {
954
1222
  value: function() {
955
- return typeof $conflict < "u";
1223
+ return typeof $conflict !== "undefined";
956
1224
  },
957
- enumerable: !0
1225
+ enumerable: true
958
1226
  }
959
- }), P.DeepDiff = P, t && (t.DeepDiff = P), P;
1227
+ });
1228
+ accumulateDiff.DeepDiff = accumulateDiff;
1229
+ if (root) {
1230
+ root.DeepDiff = accumulateDiff;
1231
+ }
1232
+ return accumulateDiff;
960
1233
  });
961
- }(ie)), ie.exports;
1234
+ })(deepDiff$1);
1235
+ return deepDiff$1.exports;
962
1236
  }
963
- var Te = Ke(), oe = { exports: {} };
964
- const z = new Uint32Array(65536), Ue = (n, e) => {
965
- const t = n.length, r = e.length, o = 1 << t - 1;
966
- let u = -1, d = 0, f = t, p = t;
967
- for (; p--; )
968
- z[n.charCodeAt(p)] |= 1 << p;
969
- for (p = 0; p < r; p++) {
970
- let y = z[e.charCodeAt(p)];
971
- const m = y | d;
972
- y |= (y & u) + u ^ u, d |= ~(y | u), u &= y, d & o && f++, u & o && f--, d = d << 1 | 1, u = u << 1 | ~(m | d), d &= m;
1237
+ var deepDiffExports = requireDeepDiff();
1238
+ var levenshtein$1 = { exports: {} };
1239
+ const peq = new Uint32Array(65536);
1240
+ const myers_32 = (a, b) => {
1241
+ const n = a.length;
1242
+ const m = b.length;
1243
+ const lst = 1 << n - 1;
1244
+ let pv = -1;
1245
+ let mv = 0;
1246
+ let sc = n;
1247
+ let i = n;
1248
+ while (i--) {
1249
+ peq[a.charCodeAt(i)] |= 1 << i;
1250
+ }
1251
+ for (i = 0; i < m; i++) {
1252
+ let eq = peq[b.charCodeAt(i)];
1253
+ const xv = eq | mv;
1254
+ eq |= (eq & pv) + pv ^ pv;
1255
+ mv |= ~(eq | pv);
1256
+ pv &= eq;
1257
+ if (mv & lst) {
1258
+ sc++;
1259
+ }
1260
+ if (pv & lst) {
1261
+ sc--;
1262
+ }
1263
+ mv = mv << 1 | 1;
1264
+ pv = pv << 1 | ~(xv | mv);
1265
+ mv &= xv;
1266
+ }
1267
+ i = n;
1268
+ while (i--) {
1269
+ peq[a.charCodeAt(i)] = 0;
1270
+ }
1271
+ return sc;
1272
+ };
1273
+ const myers_x = (b, a) => {
1274
+ const n = a.length;
1275
+ const m = b.length;
1276
+ const mhc = [];
1277
+ const phc = [];
1278
+ const hsize = Math.ceil(n / 32);
1279
+ const vsize = Math.ceil(m / 32);
1280
+ for (let i = 0; i < hsize; i++) {
1281
+ phc[i] = -1;
1282
+ mhc[i] = 0;
1283
+ }
1284
+ let j = 0;
1285
+ for (; j < vsize - 1; j++) {
1286
+ let mv2 = 0;
1287
+ let pv2 = -1;
1288
+ const start2 = j * 32;
1289
+ const vlen2 = Math.min(32, m) + start2;
1290
+ for (let k = start2; k < vlen2; k++) {
1291
+ peq[b.charCodeAt(k)] |= 1 << k;
1292
+ }
1293
+ for (let i = 0; i < n; i++) {
1294
+ const eq = peq[a.charCodeAt(i)];
1295
+ const pb = phc[i / 32 | 0] >>> i & 1;
1296
+ const mb = mhc[i / 32 | 0] >>> i & 1;
1297
+ const xv = eq | mv2;
1298
+ const xh = ((eq | mb) & pv2) + pv2 ^ pv2 | eq | mb;
1299
+ let ph = mv2 | ~(xh | pv2);
1300
+ let mh = pv2 & xh;
1301
+ if (ph >>> 31 ^ pb) {
1302
+ phc[i / 32 | 0] ^= 1 << i;
1303
+ }
1304
+ if (mh >>> 31 ^ mb) {
1305
+ mhc[i / 32 | 0] ^= 1 << i;
1306
+ }
1307
+ ph = ph << 1 | pb;
1308
+ mh = mh << 1 | mb;
1309
+ pv2 = mh | ~(xv | ph);
1310
+ mv2 = ph & xv;
1311
+ }
1312
+ for (let k = start2; k < vlen2; k++) {
1313
+ peq[b.charCodeAt(k)] = 0;
1314
+ }
973
1315
  }
974
- for (p = t; p--; )
975
- z[n.charCodeAt(p)] = 0;
976
- return f;
977
- }, He = (n, e) => {
978
- const t = e.length, r = n.length, o = [], u = [], d = Math.ceil(t / 32), f = Math.ceil(r / 32);
979
- for (let h = 0; h < d; h++)
980
- u[h] = -1, o[h] = 0;
981
- let p = 0;
982
- for (; p < f - 1; p++) {
983
- let h = 0, g = -1;
984
- const C = p * 32, P = Math.min(32, r) + C;
985
- for (let v = C; v < P; v++)
986
- z[n.charCodeAt(v)] |= 1 << v;
987
- for (let v = 0; v < t; v++) {
988
- const k = z[e.charCodeAt(v)], O = u[v / 32 | 0] >>> v & 1, R = o[v / 32 | 0] >>> v & 1, I = k | h, L = ((k | R) & g) + g ^ g | k | R;
989
- let i = h | ~(L | g), l = g & L;
990
- i >>> 31 ^ O && (u[v / 32 | 0] ^= 1 << v), l >>> 31 ^ R && (o[v / 32 | 0] ^= 1 << v), i = i << 1 | O, l = l << 1 | R, g = l | ~(I | i), h = i & I;
1316
+ let mv = 0;
1317
+ let pv = -1;
1318
+ const start = j * 32;
1319
+ const vlen = Math.min(32, m - start) + start;
1320
+ for (let k = start; k < vlen; k++) {
1321
+ peq[b.charCodeAt(k)] |= 1 << k;
1322
+ }
1323
+ let score = m;
1324
+ for (let i = 0; i < n; i++) {
1325
+ const eq = peq[a.charCodeAt(i)];
1326
+ const pb = phc[i / 32 | 0] >>> i & 1;
1327
+ const mb = mhc[i / 32 | 0] >>> i & 1;
1328
+ const xv = eq | mv;
1329
+ const xh = ((eq | mb) & pv) + pv ^ pv | eq | mb;
1330
+ let ph = mv | ~(xh | pv);
1331
+ let mh = pv & xh;
1332
+ score += ph >>> m - 1 & 1;
1333
+ score -= mh >>> m - 1 & 1;
1334
+ if (ph >>> 31 ^ pb) {
1335
+ phc[i / 32 | 0] ^= 1 << i;
1336
+ }
1337
+ if (mh >>> 31 ^ mb) {
1338
+ mhc[i / 32 | 0] ^= 1 << i;
991
1339
  }
992
- for (let v = C; v < P; v++)
993
- z[n.charCodeAt(v)] = 0;
1340
+ ph = ph << 1 | pb;
1341
+ mh = mh << 1 | mb;
1342
+ pv = mh | ~(xv | ph);
1343
+ mv = ph & xv;
994
1344
  }
995
- let y = 0, m = -1;
996
- const A = p * 32, w = Math.min(32, r - A) + A;
997
- for (let h = A; h < w; h++)
998
- z[n.charCodeAt(h)] |= 1 << h;
999
- let E = r;
1000
- for (let h = 0; h < t; h++) {
1001
- const g = z[e.charCodeAt(h)], C = u[h / 32 | 0] >>> h & 1, P = o[h / 32 | 0] >>> h & 1, v = g | y, k = ((g | P) & m) + m ^ m | g | P;
1002
- let O = y | ~(k | m), R = m & k;
1003
- E += O >>> r - 1 & 1, E -= R >>> r - 1 & 1, O >>> 31 ^ C && (u[h / 32 | 0] ^= 1 << h), R >>> 31 ^ P && (o[h / 32 | 0] ^= 1 << h), O = O << 1 | C, R = R << 1 | P, m = R | ~(v | O), y = O & v;
1345
+ for (let k = start; k < vlen; k++) {
1346
+ peq[b.charCodeAt(k)] = 0;
1004
1347
  }
1005
- for (let h = A; h < w; h++)
1006
- z[n.charCodeAt(h)] = 0;
1007
- return E;
1008
- }, Ce = (n, e) => {
1009
- if (n.length < e.length) {
1010
- const t = e;
1011
- e = n, n = t;
1348
+ return score;
1349
+ };
1350
+ const distance = (a, b) => {
1351
+ if (a.length < b.length) {
1352
+ const tmp = b;
1353
+ b = a;
1354
+ a = tmp;
1355
+ }
1356
+ if (b.length === 0) {
1357
+ return a.length;
1012
1358
  }
1013
- return e.length === 0 ? n.length : n.length <= 32 ? Ue(n, e) : He(n, e);
1014
- }, Je = (n, e) => {
1015
- let t = 1 / 0, r = 0;
1016
- for (let o = 0; o < e.length; o++) {
1017
- const u = Ce(n, e[o]);
1018
- u < t && (t = u, r = o);
1359
+ if (a.length <= 32) {
1360
+ return myers_32(a, b);
1019
1361
  }
1020
- return e[r];
1021
- }, Be = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1362
+ return myers_x(a, b);
1363
+ };
1364
+ const closest = (str, arr) => {
1365
+ let min_distance = Infinity;
1366
+ let min_index = 0;
1367
+ for (let i = 0; i < arr.length; i++) {
1368
+ const dist = distance(str, arr[i]);
1369
+ if (dist < min_distance) {
1370
+ min_distance = dist;
1371
+ min_index = i;
1372
+ }
1373
+ }
1374
+ return arr[min_index];
1375
+ };
1376
+ const mod = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1022
1377
  __proto__: null,
1023
- closest: Je,
1024
- distance: Ce
1025
- }, Symbol.toStringTag, { value: "Module" })), Ve = /* @__PURE__ */ Se(Be);
1026
- var me;
1027
- function Ge() {
1028
- return me || (me = 1, function(n, e) {
1378
+ closest,
1379
+ distance
1380
+ }, Symbol.toStringTag, { value: "Module" }));
1381
+ const require$$0 = /* @__PURE__ */ getAugmentedNamespace(mod);
1382
+ var hasRequiredLevenshtein;
1383
+ function requireLevenshtein() {
1384
+ if (hasRequiredLevenshtein) return levenshtein$1.exports;
1385
+ hasRequiredLevenshtein = 1;
1386
+ (function(module, exports) {
1029
1387
  (function() {
1030
- var t;
1388
+ var collator;
1031
1389
  try {
1032
- t = typeof Intl < "u" && typeof Intl.Collator < "u" ? Intl.Collator("generic", { sensitivity: "base" }) : null;
1033
- } catch {
1390
+ collator = typeof Intl !== "undefined" && typeof Intl.Collator !== "undefined" ? Intl.Collator("generic", { sensitivity: "base" }) : null;
1391
+ } catch (err) {
1034
1392
  console.log("Collator could not be initialized and wouldn't be used");
1035
1393
  }
1036
- var r = Ve, o = [], u = [], d = {
1394
+ var levenshtein2 = require$$0;
1395
+ var prevRow = [], str2Char = [];
1396
+ var Levenshtein = {
1037
1397
  /**
1038
1398
  * Calculate levenshtein distance of the two strings.
1039
1399
  *
@@ -1043,484 +1403,724 @@ function Ge() {
1043
1403
  * @param [options.useCollator] Use `Intl.Collator` for locale-sensitive string comparison.
1044
1404
  * @return Integer the levenshtein distance (0 and above).
1045
1405
  */
1046
- get: function(f, p, y) {
1047
- var m = y && t && y.useCollator;
1048
- if (m) {
1049
- var A = f.length, w = p.length;
1050
- if (A === 0) return w;
1051
- if (w === 0) return A;
1052
- var E, h, g, C, P;
1053
- for (g = 0; g < w; ++g)
1054
- o[g] = g, u[g] = p.charCodeAt(g);
1055
- o[w] = w;
1056
- var v;
1057
- for (g = 0; g < A; ++g) {
1058
- for (h = g + 1, C = 0; C < w; ++C)
1059
- E = h, v = t.compare(f.charAt(g), String.fromCharCode(u[C])) === 0, h = o[C] + (v ? 0 : 1), P = E + 1, h > P && (h = P), P = o[C + 1] + 1, h > P && (h = P), o[C] = E;
1060
- o[C] = h;
1406
+ get: function(str1, str2, options) {
1407
+ var useCollator = options && collator && options.useCollator;
1408
+ if (useCollator) {
1409
+ var str1Len = str1.length, str2Len = str2.length;
1410
+ if (str1Len === 0) return str2Len;
1411
+ if (str2Len === 0) return str1Len;
1412
+ var curCol, nextCol, i, j, tmp;
1413
+ for (i = 0; i < str2Len; ++i) {
1414
+ prevRow[i] = i;
1415
+ str2Char[i] = str2.charCodeAt(i);
1416
+ }
1417
+ prevRow[str2Len] = str2Len;
1418
+ var strCmp;
1419
+ for (i = 0; i < str1Len; ++i) {
1420
+ nextCol = i + 1;
1421
+ for (j = 0; j < str2Len; ++j) {
1422
+ curCol = nextCol;
1423
+ strCmp = 0 === collator.compare(str1.charAt(i), String.fromCharCode(str2Char[j]));
1424
+ nextCol = prevRow[j] + (strCmp ? 0 : 1);
1425
+ tmp = curCol + 1;
1426
+ if (nextCol > tmp) {
1427
+ nextCol = tmp;
1428
+ }
1429
+ tmp = prevRow[j + 1] + 1;
1430
+ if (nextCol > tmp) {
1431
+ nextCol = tmp;
1432
+ }
1433
+ prevRow[j] = curCol;
1434
+ }
1435
+ prevRow[j] = nextCol;
1061
1436
  }
1062
- return h;
1437
+ return nextCol;
1063
1438
  }
1064
- return r.distance(f, p);
1439
+ return levenshtein2.distance(str1, str2);
1065
1440
  }
1066
1441
  };
1067
- n !== null && n.exports === e ? n.exports = d : typeof self < "u" && typeof self.postMessage == "function" && typeof self.importScripts == "function" ? self.Levenshtein = d : typeof window < "u" && window !== null && (window.Levenshtein = d);
1442
+ if (module !== null && true && module.exports === exports) {
1443
+ module.exports = Levenshtein;
1444
+ } else if (typeof self !== "undefined" && typeof self.postMessage === "function" && typeof self.importScripts === "function") {
1445
+ self.Levenshtein = Levenshtein;
1446
+ } else if (typeof window !== "undefined" && window !== null) {
1447
+ window.Levenshtein = Levenshtein;
1448
+ }
1068
1449
  })();
1069
- }(oe, oe.exports)), oe.exports;
1450
+ })(levenshtein$1, levenshtein$1.exports);
1451
+ return levenshtein$1.exports;
1070
1452
  }
1071
- var Xe = Ge();
1072
- const Ze = /* @__PURE__ */ _e(Xe);
1073
- class Qe {
1074
- diff(e, t, r = {}) {
1075
- let o;
1076
- typeof r == "function" ? (o = r, r = {}) : "callback" in r && (o = r.callback);
1077
- const u = this.castInput(e, r), d = this.castInput(t, r), f = this.removeEmpty(this.tokenize(u, r)), p = this.removeEmpty(this.tokenize(d, r));
1078
- return this.diffWithOptionsObj(f, p, r, o);
1453
+ var levenshteinExports = requireLevenshtein();
1454
+ const levenshtein = /* @__PURE__ */ getDefaultExportFromCjs(levenshteinExports);
1455
+ class Diff {
1456
+ diff(oldStr, newStr, options = {}) {
1457
+ let callback;
1458
+ if (typeof options === "function") {
1459
+ callback = options;
1460
+ options = {};
1461
+ } else if ("callback" in options) {
1462
+ callback = options.callback;
1463
+ }
1464
+ const oldString = this.castInput(oldStr, options);
1465
+ const newString = this.castInput(newStr, options);
1466
+ const oldTokens = this.removeEmpty(this.tokenize(oldString, options));
1467
+ const newTokens = this.removeEmpty(this.tokenize(newString, options));
1468
+ return this.diffWithOptionsObj(oldTokens, newTokens, options, callback);
1079
1469
  }
1080
- diffWithOptionsObj(e, t, r, o) {
1081
- var u;
1082
- const d = (v) => {
1083
- if (v = this.postProcess(v, r), o) {
1470
+ diffWithOptionsObj(oldTokens, newTokens, options, callback) {
1471
+ var _a;
1472
+ const done = (value) => {
1473
+ value = this.postProcess(value, options);
1474
+ if (callback) {
1084
1475
  setTimeout(function() {
1085
- o(v);
1476
+ callback(value);
1086
1477
  }, 0);
1087
- return;
1088
- } else
1089
- return v;
1090
- }, f = t.length, p = e.length;
1091
- let y = 1, m = f + p;
1092
- r.maxEditLength != null && (m = Math.min(m, r.maxEditLength));
1093
- const A = (u = r.timeout) !== null && u !== void 0 ? u : 1 / 0, w = Date.now() + A, E = [{ oldPos: -1, lastComponent: void 0 }];
1094
- let h = this.extractCommon(E[0], t, e, 0, r);
1095
- if (E[0].oldPos + 1 >= p && h + 1 >= f)
1096
- return d(this.buildValues(E[0].lastComponent, t, e));
1097
- let g = -1 / 0, C = 1 / 0;
1098
- const P = () => {
1099
- for (let v = Math.max(g, -y); v <= Math.min(C, y); v += 2) {
1100
- let k;
1101
- const O = E[v - 1], R = E[v + 1];
1102
- O && (E[v - 1] = void 0);
1103
- let I = !1;
1104
- if (R) {
1105
- const i = R.oldPos - v;
1106
- I = R && 0 <= i && i < f;
1478
+ return void 0;
1479
+ } else {
1480
+ return value;
1481
+ }
1482
+ };
1483
+ const newLen = newTokens.length, oldLen = oldTokens.length;
1484
+ let editLength = 1;
1485
+ let maxEditLength = newLen + oldLen;
1486
+ if (options.maxEditLength != null) {
1487
+ maxEditLength = Math.min(maxEditLength, options.maxEditLength);
1488
+ }
1489
+ const maxExecutionTime = (_a = options.timeout) !== null && _a !== void 0 ? _a : Infinity;
1490
+ const abortAfterTimestamp = Date.now() + maxExecutionTime;
1491
+ const bestPath = [{ oldPos: -1, lastComponent: void 0 }];
1492
+ let newPos = this.extractCommon(bestPath[0], newTokens, oldTokens, 0, options);
1493
+ if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
1494
+ return done(this.buildValues(bestPath[0].lastComponent, newTokens, oldTokens));
1495
+ }
1496
+ let minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity;
1497
+ const execEditLength = () => {
1498
+ for (let diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) {
1499
+ let basePath;
1500
+ const removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1];
1501
+ if (removePath) {
1502
+ bestPath[diagonalPath - 1] = void 0;
1107
1503
  }
1108
- const L = O && O.oldPos + 1 < p;
1109
- if (!I && !L) {
1110
- E[v] = void 0;
1504
+ let canAdd = false;
1505
+ if (addPath) {
1506
+ const addPathNewPos = addPath.oldPos - diagonalPath;
1507
+ canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen;
1508
+ }
1509
+ const canRemove = removePath && removePath.oldPos + 1 < oldLen;
1510
+ if (!canAdd && !canRemove) {
1511
+ bestPath[diagonalPath] = void 0;
1111
1512
  continue;
1112
1513
  }
1113
- if (!L || I && O.oldPos < R.oldPos ? k = this.addToPath(R, !0, !1, 0, r) : k = this.addToPath(O, !1, !0, 1, r), h = this.extractCommon(k, t, e, v, r), k.oldPos + 1 >= p && h + 1 >= f)
1114
- return d(this.buildValues(k.lastComponent, t, e)) || !0;
1115
- E[v] = k, k.oldPos + 1 >= p && (C = Math.min(C, v - 1)), h + 1 >= f && (g = Math.max(g, v + 1));
1514
+ if (!canRemove || canAdd && removePath.oldPos < addPath.oldPos) {
1515
+ basePath = this.addToPath(addPath, true, false, 0, options);
1516
+ } else {
1517
+ basePath = this.addToPath(removePath, false, true, 1, options);
1518
+ }
1519
+ newPos = this.extractCommon(basePath, newTokens, oldTokens, diagonalPath, options);
1520
+ if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) {
1521
+ return done(this.buildValues(basePath.lastComponent, newTokens, oldTokens)) || true;
1522
+ } else {
1523
+ bestPath[diagonalPath] = basePath;
1524
+ if (basePath.oldPos + 1 >= oldLen) {
1525
+ maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1);
1526
+ }
1527
+ if (newPos + 1 >= newLen) {
1528
+ minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1);
1529
+ }
1530
+ }
1116
1531
  }
1117
- y++;
1532
+ editLength++;
1118
1533
  };
1119
- if (o)
1120
- (function v() {
1534
+ if (callback) {
1535
+ (function exec() {
1121
1536
  setTimeout(function() {
1122
- if (y > m || Date.now() > w)
1123
- return o(void 0);
1124
- P() || v();
1537
+ if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
1538
+ return callback(void 0);
1539
+ }
1540
+ if (!execEditLength()) {
1541
+ exec();
1542
+ }
1125
1543
  }, 0);
1126
1544
  })();
1127
- else
1128
- for (; y <= m && Date.now() <= w; ) {
1129
- const v = P();
1130
- if (v)
1131
- return v;
1545
+ } else {
1546
+ while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
1547
+ const ret = execEditLength();
1548
+ if (ret) {
1549
+ return ret;
1550
+ }
1132
1551
  }
1552
+ }
1133
1553
  }
1134
- addToPath(e, t, r, o, u) {
1135
- const d = e.lastComponent;
1136
- return d && !u.oneChangePerToken && d.added === t && d.removed === r ? {
1137
- oldPos: e.oldPos + o,
1138
- lastComponent: { count: d.count + 1, added: t, removed: r, previousComponent: d.previousComponent }
1139
- } : {
1140
- oldPos: e.oldPos + o,
1141
- lastComponent: { count: 1, added: t, removed: r, previousComponent: d }
1142
- };
1554
+ addToPath(path, added, removed, oldPosInc, options) {
1555
+ const last = path.lastComponent;
1556
+ if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
1557
+ return {
1558
+ oldPos: path.oldPos + oldPosInc,
1559
+ lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
1560
+ };
1561
+ } else {
1562
+ return {
1563
+ oldPos: path.oldPos + oldPosInc,
1564
+ lastComponent: { count: 1, added, removed, previousComponent: last }
1565
+ };
1566
+ }
1143
1567
  }
1144
- extractCommon(e, t, r, o, u) {
1145
- const d = t.length, f = r.length;
1146
- let p = e.oldPos, y = p - o, m = 0;
1147
- for (; y + 1 < d && p + 1 < f && this.equals(r[p + 1], t[y + 1], u); )
1148
- y++, p++, m++, u.oneChangePerToken && (e.lastComponent = { count: 1, previousComponent: e.lastComponent, added: !1, removed: !1 });
1149
- return m && !u.oneChangePerToken && (e.lastComponent = { count: m, previousComponent: e.lastComponent, added: !1, removed: !1 }), e.oldPos = p, y;
1568
+ extractCommon(basePath, newTokens, oldTokens, diagonalPath, options) {
1569
+ const newLen = newTokens.length, oldLen = oldTokens.length;
1570
+ let oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0;
1571
+ while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(oldTokens[oldPos + 1], newTokens[newPos + 1], options)) {
1572
+ newPos++;
1573
+ oldPos++;
1574
+ commonCount++;
1575
+ if (options.oneChangePerToken) {
1576
+ basePath.lastComponent = { count: 1, previousComponent: basePath.lastComponent, added: false, removed: false };
1577
+ }
1578
+ }
1579
+ if (commonCount && !options.oneChangePerToken) {
1580
+ basePath.lastComponent = { count: commonCount, previousComponent: basePath.lastComponent, added: false, removed: false };
1581
+ }
1582
+ basePath.oldPos = oldPos;
1583
+ return newPos;
1150
1584
  }
1151
- equals(e, t, r) {
1152
- return r.comparator ? r.comparator(e, t) : e === t || !!r.ignoreCase && e.toLowerCase() === t.toLowerCase();
1585
+ equals(left, right, options) {
1586
+ if (options.comparator) {
1587
+ return options.comparator(left, right);
1588
+ } else {
1589
+ return left === right || !!options.ignoreCase && left.toLowerCase() === right.toLowerCase();
1590
+ }
1153
1591
  }
1154
- removeEmpty(e) {
1155
- const t = [];
1156
- for (let r = 0; r < e.length; r++)
1157
- e[r] && t.push(e[r]);
1158
- return t;
1592
+ removeEmpty(array) {
1593
+ const ret = [];
1594
+ for (let i = 0; i < array.length; i++) {
1595
+ if (array[i]) {
1596
+ ret.push(array[i]);
1597
+ }
1598
+ }
1599
+ return ret;
1159
1600
  }
1160
1601
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
1161
- castInput(e, t) {
1162
- return e;
1602
+ castInput(value, options) {
1603
+ return value;
1163
1604
  }
1164
1605
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
1165
- tokenize(e, t) {
1166
- return Array.from(e);
1606
+ tokenize(value, options) {
1607
+ return Array.from(value);
1167
1608
  }
1168
- join(e) {
1169
- return e.join("");
1609
+ join(chars) {
1610
+ return chars.join("");
1170
1611
  }
1171
- postProcess(e, t) {
1172
- return e;
1612
+ postProcess(changeObjects, options) {
1613
+ return changeObjects;
1173
1614
  }
1174
1615
  get useLongestToken() {
1175
- return !1;
1616
+ return false;
1176
1617
  }
1177
- buildValues(e, t, r) {
1178
- const o = [];
1179
- let u;
1180
- for (; e; )
1181
- o.push(e), u = e.previousComponent, delete e.previousComponent, e = u;
1182
- o.reverse();
1183
- const d = o.length;
1184
- let f = 0, p = 0, y = 0;
1185
- for (; f < d; f++) {
1186
- const m = o[f];
1187
- if (m.removed)
1188
- m.value = this.join(r.slice(y, y + m.count)), y += m.count;
1189
- else {
1190
- if (!m.added && this.useLongestToken) {
1191
- let A = t.slice(p, p + m.count);
1192
- A = A.map(function(w, E) {
1193
- const h = r[y + E];
1194
- return h.length > w.length ? h : w;
1195
- }), m.value = this.join(A);
1196
- } else
1197
- m.value = this.join(t.slice(p, p + m.count));
1198
- p += m.count, m.added || (y += m.count);
1618
+ buildValues(lastComponent, newTokens, oldTokens) {
1619
+ const components = [];
1620
+ let nextComponent;
1621
+ while (lastComponent) {
1622
+ components.push(lastComponent);
1623
+ nextComponent = lastComponent.previousComponent;
1624
+ delete lastComponent.previousComponent;
1625
+ lastComponent = nextComponent;
1626
+ }
1627
+ components.reverse();
1628
+ const componentLen = components.length;
1629
+ let componentPos = 0, newPos = 0, oldPos = 0;
1630
+ for (; componentPos < componentLen; componentPos++) {
1631
+ const component = components[componentPos];
1632
+ if (!component.removed) {
1633
+ if (!component.added && this.useLongestToken) {
1634
+ let value = newTokens.slice(newPos, newPos + component.count);
1635
+ value = value.map(function(value2, i) {
1636
+ const oldValue = oldTokens[oldPos + i];
1637
+ return oldValue.length > value2.length ? oldValue : value2;
1638
+ });
1639
+ component.value = this.join(value);
1640
+ } else {
1641
+ component.value = this.join(newTokens.slice(newPos, newPos + component.count));
1642
+ }
1643
+ newPos += component.count;
1644
+ if (!component.added) {
1645
+ oldPos += component.count;
1646
+ }
1647
+ } else {
1648
+ component.value = this.join(oldTokens.slice(oldPos, oldPos + component.count));
1649
+ oldPos += component.count;
1199
1650
  }
1200
1651
  }
1201
- return o;
1652
+ return components;
1202
1653
  }
1203
1654
  }
1204
- class et extends Qe {
1655
+ class LineDiff extends Diff {
1205
1656
  constructor() {
1206
- super(...arguments), this.tokenize = nt;
1657
+ super(...arguments);
1658
+ this.tokenize = tokenize;
1207
1659
  }
1208
- equals(e, t, r) {
1209
- return r.ignoreWhitespace ? ((!r.newlineIsToken || !e.includes(`
1210
- `)) && (e = e.trim()), (!r.newlineIsToken || !t.includes(`
1211
- `)) && (t = t.trim())) : r.ignoreNewlineAtEof && !r.newlineIsToken && (e.endsWith(`
1212
- `) && (e = e.slice(0, -1)), t.endsWith(`
1213
- `) && (t = t.slice(0, -1))), super.equals(e, t, r);
1660
+ equals(left, right, options) {
1661
+ if (options.ignoreWhitespace) {
1662
+ if (!options.newlineIsToken || !left.includes("\n")) {
1663
+ left = left.trim();
1664
+ }
1665
+ if (!options.newlineIsToken || !right.includes("\n")) {
1666
+ right = right.trim();
1667
+ }
1668
+ } else if (options.ignoreNewlineAtEof && !options.newlineIsToken) {
1669
+ if (left.endsWith("\n")) {
1670
+ left = left.slice(0, -1);
1671
+ }
1672
+ if (right.endsWith("\n")) {
1673
+ right = right.slice(0, -1);
1674
+ }
1675
+ }
1676
+ return super.equals(left, right, options);
1214
1677
  }
1215
1678
  }
1216
- const tt = new et();
1217
- function ve(n, e, t) {
1218
- return tt.diff(n, e, t);
1679
+ const lineDiff = new LineDiff();
1680
+ function diffLines(oldStr, newStr, options) {
1681
+ return lineDiff.diff(oldStr, newStr, options);
1219
1682
  }
1220
- function nt(n, e) {
1221
- e.stripTrailingCr && (n = n.replace(/\r\n/g, `
1222
- `));
1223
- const t = [], r = n.split(/(\n|\r\n)/);
1224
- r[r.length - 1] || r.pop();
1225
- for (let o = 0; o < r.length; o++) {
1226
- const u = r[o];
1227
- o % 2 && !e.newlineIsToken ? t[t.length - 1] += u : t.push(u);
1683
+ function tokenize(value, options) {
1684
+ if (options.stripTrailingCr) {
1685
+ value = value.replace(/\r\n/g, "\n");
1686
+ }
1687
+ const retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/);
1688
+ if (!linesAndNewlines[linesAndNewlines.length - 1]) {
1689
+ linesAndNewlines.pop();
1228
1690
  }
1229
- return t;
1691
+ for (let i = 0; i < linesAndNewlines.length; i++) {
1692
+ const line = linesAndNewlines[i];
1693
+ if (i % 2 && !options.newlineIsToken) {
1694
+ retLines[retLines.length - 1] += line;
1695
+ } else {
1696
+ retLines.push(line);
1697
+ }
1698
+ }
1699
+ return retLines;
1230
1700
  }
1231
- function be(n, e, t, r, o, u, d) {
1232
- let f;
1233
- d ? typeof d == "function" ? f = { callback: d } : f = d : f = {}, typeof f.context > "u" && (f.context = 4);
1234
- const p = f.context;
1235
- if (f.newlineIsToken)
1701
+ function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
1702
+ let optionsObj;
1703
+ if (!options) {
1704
+ optionsObj = {};
1705
+ } else if (typeof options === "function") {
1706
+ optionsObj = { callback: options };
1707
+ } else {
1708
+ optionsObj = options;
1709
+ }
1710
+ if (typeof optionsObj.context === "undefined") {
1711
+ optionsObj.context = 4;
1712
+ }
1713
+ const context = optionsObj.context;
1714
+ if (optionsObj.newlineIsToken) {
1236
1715
  throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");
1237
- if (f.callback) {
1238
- const { callback: m } = f;
1239
- ve(t, r, Object.assign(Object.assign({}, f), { callback: (A) => {
1240
- const w = y(A);
1241
- m(w);
1716
+ }
1717
+ if (!optionsObj.callback) {
1718
+ return diffLinesResultToPatch(diffLines(oldStr, newStr, optionsObj));
1719
+ } else {
1720
+ const { callback } = optionsObj;
1721
+ diffLines(oldStr, newStr, Object.assign(Object.assign({}, optionsObj), { callback: (diff) => {
1722
+ const patch = diffLinesResultToPatch(diff);
1723
+ callback(patch);
1242
1724
  } }));
1243
- } else
1244
- return y(ve(t, r, f));
1245
- function y(m) {
1246
- if (!m)
1725
+ }
1726
+ function diffLinesResultToPatch(diff) {
1727
+ if (!diff) {
1247
1728
  return;
1248
- m.push({ value: "", lines: [] });
1249
- function A(v) {
1250
- return v.map(function(k) {
1251
- return " " + k;
1729
+ }
1730
+ diff.push({ value: "", lines: [] });
1731
+ function contextLines(lines) {
1732
+ return lines.map(function(entry) {
1733
+ return " " + entry;
1252
1734
  });
1253
1735
  }
1254
- const w = [];
1255
- let E = 0, h = 0, g = [], C = 1, P = 1;
1256
- for (let v = 0; v < m.length; v++) {
1257
- const k = m[v], O = k.lines || ot(k.value);
1258
- if (k.lines = O, k.added || k.removed) {
1259
- if (!E) {
1260
- const R = m[v - 1];
1261
- E = C, h = P, R && (g = p > 0 ? A(R.lines.slice(-p)) : [], E -= g.length, h -= g.length);
1736
+ const hunks = [];
1737
+ let oldRangeStart = 0, newRangeStart = 0, curRange = [], oldLine = 1, newLine = 1;
1738
+ for (let i = 0; i < diff.length; i++) {
1739
+ const current = diff[i], lines = current.lines || splitLines(current.value);
1740
+ current.lines = lines;
1741
+ if (current.added || current.removed) {
1742
+ if (!oldRangeStart) {
1743
+ const prev = diff[i - 1];
1744
+ oldRangeStart = oldLine;
1745
+ newRangeStart = newLine;
1746
+ if (prev) {
1747
+ curRange = context > 0 ? contextLines(prev.lines.slice(-context)) : [];
1748
+ oldRangeStart -= curRange.length;
1749
+ newRangeStart -= curRange.length;
1750
+ }
1751
+ }
1752
+ for (const line of lines) {
1753
+ curRange.push((current.added ? "+" : "-") + line);
1754
+ }
1755
+ if (current.added) {
1756
+ newLine += lines.length;
1757
+ } else {
1758
+ oldLine += lines.length;
1262
1759
  }
1263
- for (const R of O)
1264
- g.push((k.added ? "+" : "-") + R);
1265
- k.added ? P += O.length : C += O.length;
1266
1760
  } else {
1267
- if (E)
1268
- if (O.length <= p * 2 && v < m.length - 2)
1269
- for (const R of A(O))
1270
- g.push(R);
1271
- else {
1272
- const R = Math.min(O.length, p);
1273
- for (const L of A(O.slice(0, R)))
1274
- g.push(L);
1275
- const I = {
1276
- oldStart: E,
1277
- oldLines: C - E + R,
1278
- newStart: h,
1279
- newLines: P - h + R,
1280
- lines: g
1761
+ if (oldRangeStart) {
1762
+ if (lines.length <= context * 2 && i < diff.length - 2) {
1763
+ for (const line of contextLines(lines)) {
1764
+ curRange.push(line);
1765
+ }
1766
+ } else {
1767
+ const contextSize = Math.min(lines.length, context);
1768
+ for (const line of contextLines(lines.slice(0, contextSize))) {
1769
+ curRange.push(line);
1770
+ }
1771
+ const hunk = {
1772
+ oldStart: oldRangeStart,
1773
+ oldLines: oldLine - oldRangeStart + contextSize,
1774
+ newStart: newRangeStart,
1775
+ newLines: newLine - newRangeStart + contextSize,
1776
+ lines: curRange
1281
1777
  };
1282
- w.push(I), E = 0, h = 0, g = [];
1778
+ hunks.push(hunk);
1779
+ oldRangeStart = 0;
1780
+ newRangeStart = 0;
1781
+ curRange = [];
1283
1782
  }
1284
- C += O.length, P += O.length;
1783
+ }
1784
+ oldLine += lines.length;
1785
+ newLine += lines.length;
1786
+ }
1787
+ }
1788
+ for (const hunk of hunks) {
1789
+ for (let i = 0; i < hunk.lines.length; i++) {
1790
+ if (hunk.lines[i].endsWith("\n")) {
1791
+ hunk.lines[i] = hunk.lines[i].slice(0, -1);
1792
+ } else {
1793
+ hunk.lines.splice(i + 1, 0, "\");
1794
+ i++;
1795
+ }
1285
1796
  }
1286
1797
  }
1287
- for (const v of w)
1288
- for (let k = 0; k < v.lines.length; k++)
1289
- v.lines[k].endsWith(`
1290
- `) ? v.lines[k] = v.lines[k].slice(0, -1) : (v.lines.splice(k + 1, 0, "\"), k++);
1291
1798
  return {
1292
- oldFileName: n,
1293
- newFileName: e,
1294
- oldHeader: o,
1295
- newHeader: u,
1296
- hunks: w
1799
+ oldFileName,
1800
+ newFileName,
1801
+ oldHeader,
1802
+ newHeader,
1803
+ hunks
1297
1804
  };
1298
1805
  }
1299
1806
  }
1300
- function ue(n) {
1301
- if (Array.isArray(n))
1302
- return n.map(ue).join(`
1303
- `);
1304
- const e = [];
1305
- n.oldFileName == n.newFileName && e.push("Index: " + n.oldFileName), e.push("==================================================================="), e.push("--- " + n.oldFileName + (typeof n.oldHeader > "u" ? "" : " " + n.oldHeader)), e.push("+++ " + n.newFileName + (typeof n.newHeader > "u" ? "" : " " + n.newHeader));
1306
- for (let t = 0; t < n.hunks.length; t++) {
1307
- const r = n.hunks[t];
1308
- r.oldLines === 0 && (r.oldStart -= 1), r.newLines === 0 && (r.newStart -= 1), e.push("@@ -" + r.oldStart + "," + r.oldLines + " +" + r.newStart + "," + r.newLines + " @@");
1309
- for (const o of r.lines)
1310
- e.push(o);
1807
+ function formatPatch(patch) {
1808
+ if (Array.isArray(patch)) {
1809
+ return patch.map(formatPatch).join("\n");
1810
+ }
1811
+ const ret = [];
1812
+ if (patch.oldFileName == patch.newFileName) {
1813
+ ret.push("Index: " + patch.oldFileName);
1814
+ }
1815
+ ret.push("===================================================================");
1816
+ ret.push("--- " + patch.oldFileName + (typeof patch.oldHeader === "undefined" ? "" : " " + patch.oldHeader));
1817
+ ret.push("+++ " + patch.newFileName + (typeof patch.newHeader === "undefined" ? "" : " " + patch.newHeader));
1818
+ for (let i = 0; i < patch.hunks.length; i++) {
1819
+ const hunk = patch.hunks[i];
1820
+ if (hunk.oldLines === 0) {
1821
+ hunk.oldStart -= 1;
1822
+ }
1823
+ if (hunk.newLines === 0) {
1824
+ hunk.newStart -= 1;
1825
+ }
1826
+ ret.push("@@ -" + hunk.oldStart + "," + hunk.oldLines + " +" + hunk.newStart + "," + hunk.newLines + " @@");
1827
+ for (const line of hunk.lines) {
1828
+ ret.push(line);
1829
+ }
1311
1830
  }
1312
- return e.join(`
1313
- `) + `
1314
- `;
1831
+ return ret.join("\n") + "\n";
1315
1832
  }
1316
- function rt(n, e, t, r, o, u, d) {
1317
- if (typeof d == "function" && (d = { callback: d }), d?.callback) {
1318
- const { callback: f } = d;
1319
- be(n, e, t, r, o, u, Object.assign(Object.assign({}, d), { callback: (p) => {
1320
- f(p ? ue(p) : void 0);
1321
- } }));
1833
+ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
1834
+ if (typeof options === "function") {
1835
+ options = { callback: options };
1836
+ }
1837
+ if (!(options === null || options === void 0 ? void 0 : options.callback)) {
1838
+ const patchObj = structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options);
1839
+ if (!patchObj) {
1840
+ return;
1841
+ }
1842
+ return formatPatch(patchObj);
1322
1843
  } else {
1323
- const f = be(n, e, t, r, o, u, d);
1324
- return f ? ue(f) : void 0;
1844
+ const { callback } = options;
1845
+ structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, Object.assign(Object.assign({}, options), { callback: (patchObj) => {
1846
+ if (!patchObj) {
1847
+ callback(void 0);
1848
+ } else {
1849
+ callback(formatPatch(patchObj));
1850
+ }
1851
+ } }));
1325
1852
  }
1326
1853
  }
1327
- function ot(n) {
1328
- const e = n.endsWith(`
1329
- `), t = n.split(`
1330
- `).map((r) => r + `
1331
- `);
1332
- return e ? t.pop() : t.push(t.pop().slice(0, -1)), t;
1854
+ function splitLines(text) {
1855
+ const hasTrailingNl = text.endsWith("\n");
1856
+ const result = text.split("\n").map((line) => line + "\n");
1857
+ if (hasTrailingNl) {
1858
+ result.pop();
1859
+ } else {
1860
+ result.push(result.pop().slice(0, -1));
1861
+ }
1862
+ return result;
1333
1863
  }
1334
- function it(n, e, t = "git", r = 3) {
1335
- switch (t) {
1864
+ function formatDiff(oldValue, newValue, diffType = "git", context = 3) {
1865
+ switch (diffType) {
1336
1866
  case "git":
1337
- return ye(n, e, r);
1867
+ return formatGitDiff(oldValue, newValue, context);
1338
1868
  case "object":
1339
- return st(n, e);
1869
+ return formatObjectDiff(oldValue, newValue);
1340
1870
  case "json":
1341
- return at(n, e);
1871
+ return formatJsonDiff(oldValue, newValue);
1342
1872
  default:
1343
- return ye(n, e, r);
1873
+ return formatGitDiff(oldValue, newValue, context);
1344
1874
  }
1345
1875
  }
1346
- function ye(n, e, t = 3) {
1347
- const r = ge(n), o = ge(e);
1348
- return rt(
1876
+ function formatGitDiff(oldValue, newValue, context = 3) {
1877
+ const oldStr = stringify(oldValue);
1878
+ const newStr = stringify(newValue);
1879
+ const patch = createTwoFilesPatch(
1349
1880
  /* oldFilename */
1350
1881
  "",
1351
1882
  /* newFilename */
1352
1883
  "",
1353
- r,
1354
- o,
1884
+ oldStr,
1885
+ newStr,
1355
1886
  /* oldHeader */
1356
1887
  "",
1357
1888
  /* newHeader */
1358
1889
  "",
1359
- { context: t }
1360
- ).split(`
1361
- `).slice(2).join(`
1362
- `);
1890
+ { context }
1891
+ );
1892
+ return patch.split("\n").slice(2).join("\n");
1363
1893
  }
1364
- function st(n, e) {
1365
- const t = Te.diff(n, e) || [];
1366
- return JSON.stringify(t, null, 2);
1894
+ function formatObjectDiff(oldValue, newValue) {
1895
+ const differences = deepDiffExports.diff(oldValue, newValue) || [];
1896
+ return JSON.stringify(differences, null, 2);
1367
1897
  }
1368
- function at(n, e) {
1898
+ function formatJsonDiff(oldValue, newValue) {
1369
1899
  return JSON.stringify(
1370
1900
  {
1371
- before: n,
1372
- after: e
1901
+ before: oldValue,
1902
+ after: newValue
1373
1903
  },
1374
1904
  null,
1375
1905
  2
1376
1906
  );
1377
1907
  }
1378
- function lt(n, e) {
1379
- return typeof n == "string" && typeof e == "string" ? Oe(n, e) : typeof n == "number" && typeof e == "number" ? Re(n, e) : ut(n, e);
1908
+ function calculateDiffPercentage(oldValue, newValue) {
1909
+ if (typeof oldValue === "string" && typeof newValue === "string") {
1910
+ return calculateStringDiffPercentage(oldValue, newValue);
1911
+ } else if (typeof oldValue === "number" && typeof newValue === "number") {
1912
+ return calculateNumberDiffPercentage(oldValue, newValue);
1913
+ } else {
1914
+ return calculateObjectDiffPercentage(oldValue, newValue);
1915
+ }
1380
1916
  }
1381
- function Oe(n, e) {
1382
- if (n === e) return 0;
1383
- if (n.length === 0 || e.length === 0) return 1;
1384
- const t = Ze.get(n, e), r = Math.max(n.length, e.length);
1385
- return t / r;
1917
+ function calculateStringDiffPercentage(oldStr, newStr) {
1918
+ if (oldStr === newStr) return 0;
1919
+ if (oldStr.length === 0) return 1;
1920
+ if (newStr.length === 0) return 1;
1921
+ const distance2 = levenshtein.get(oldStr, newStr);
1922
+ const maxLength = Math.max(oldStr.length, newStr.length);
1923
+ return distance2 / maxLength;
1386
1924
  }
1387
- function Re(n, e) {
1388
- if (n === e) return 0;
1389
- if (n === 0) return 1;
1390
- const t = Math.abs(e - n), r = Math.max(Math.abs(n), Math.abs(e));
1391
- return Math.min(t / r, 1);
1925
+ function calculateNumberDiffPercentage(oldNum, newNum) {
1926
+ if (oldNum === newNum) return 0;
1927
+ if (oldNum === 0) return 1;
1928
+ const change = Math.abs(newNum - oldNum);
1929
+ const base = Math.max(Math.abs(oldNum), Math.abs(newNum));
1930
+ return Math.min(change / base, 1);
1392
1931
  }
1393
- function ut(n, e) {
1394
- if (n === e) return 0;
1395
- const t = Te.diff(n, e) || [];
1396
- if (t.length === 0) return 0;
1397
- const r = we(n), o = we(e), u = Math.max(r, o);
1398
- if (u === 0) return 0;
1399
- let d = 0;
1400
- for (const f of t)
1401
- switch (f.kind) {
1932
+ function calculateObjectDiffPercentage(oldObj, newObj) {
1933
+ if (oldObj === newObj) return 0;
1934
+ const differences = deepDiffExports.diff(oldObj, newObj) || [];
1935
+ if (differences.length === 0) return 0;
1936
+ const oldProps = countObjectProperties(oldObj);
1937
+ const newProps = countObjectProperties(newObj);
1938
+ const totalProps = Math.max(oldProps, newProps);
1939
+ if (totalProps === 0) return 0;
1940
+ let changeWeight = 0;
1941
+ for (const difference of differences) {
1942
+ switch (difference.kind) {
1402
1943
  case "N":
1403
- d += 1;
1944
+ changeWeight += 1;
1404
1945
  break;
1405
1946
  case "D":
1406
- d += 1;
1947
+ changeWeight += 1;
1407
1948
  break;
1408
1949
  case "E":
1409
- if (typeof f.lhs == "string" && typeof f.rhs == "string") {
1410
- const p = Oe(
1411
- f.lhs,
1412
- f.rhs
1950
+ if (typeof difference.lhs === "string" && typeof difference.rhs === "string") {
1951
+ const stringChangeRatio = calculateStringDiffPercentage(
1952
+ difference.lhs,
1953
+ difference.rhs
1413
1954
  );
1414
- d += p;
1415
- } else if (typeof f.lhs == "number" && typeof f.rhs == "number") {
1416
- const p = Re(
1417
- f.lhs,
1418
- f.rhs
1955
+ changeWeight += stringChangeRatio;
1956
+ } else if (typeof difference.lhs === "number" && typeof difference.rhs === "number") {
1957
+ const numberChangeRatio = calculateNumberDiffPercentage(
1958
+ difference.lhs,
1959
+ difference.rhs
1419
1960
  );
1420
- d += p;
1421
- } else
1422
- d += 1;
1961
+ changeWeight += numberChangeRatio;
1962
+ } else {
1963
+ changeWeight += 1;
1964
+ }
1423
1965
  break;
1424
1966
  case "A":
1425
- d += 0.5;
1967
+ changeWeight += 0.5;
1426
1968
  break;
1427
1969
  }
1428
- return Math.min(d / u, 1);
1970
+ }
1971
+ return Math.min(changeWeight / totalProps, 1);
1429
1972
  }
1430
- function we(n) {
1431
- if (n == null) return 0;
1432
- if (typeof n != "object") return 1;
1433
- if (Array.isArray(n)) return n.length;
1434
- let e = 0;
1435
- for (const t in n)
1436
- Object.prototype.hasOwnProperty.call(n, t) && (e += 1);
1437
- return e;
1973
+ function countObjectProperties(obj) {
1974
+ if (obj === null || obj === void 0) return 0;
1975
+ if (typeof obj !== "object") return 1;
1976
+ if (Array.isArray(obj)) return obj.length;
1977
+ let count = 0;
1978
+ for (const key in obj) {
1979
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
1980
+ count += 1;
1981
+ }
1982
+ }
1983
+ return count;
1438
1984
  }
1439
- function ge(n) {
1985
+ function stringify(value) {
1440
1986
  try {
1441
1987
  return JSON.stringify(
1442
- n,
1443
- (e, t) => typeof t == "function" ? "[Function]" : t === void 0 ? "[undefined]" : t === 1 / 0 ? "[Infinity]" : Number.isNaN(t) ? "[NaN]" : t,
1988
+ value,
1989
+ (_key, val) => {
1990
+ if (typeof val === "function") return "[Function]";
1991
+ if (val === void 0) return "[undefined]";
1992
+ if (val === Infinity) return "[Infinity]";
1993
+ if (Number.isNaN(val)) return "[NaN]";
1994
+ return val;
1995
+ },
1444
1996
  2
1445
1997
  );
1446
- } catch {
1447
- return String(n);
1998
+ } catch (_) {
1999
+ return String(value);
1448
2000
  }
1449
2001
  }
1450
- function ct(n, e, t) {
1451
- const r = Pe(), o = t?.onFeedback || r, u = t?.debounceMs ?? 1500, d = t?.diffType ?? "git", f = t?.compareWith, p = t?.default_trigger_name ?? "auto_state_change", y = U(n), m = U(n), A = U(!0), w = U(null), E = U(void 0), h = W(
1452
- (C, P, v) => {
1453
- const k = lt(C, P), O = it(C, P, d);
1454
- let R;
1455
- t?.vote ? typeof t.vote == "function" ? R = t.vote(C, P, k) : R = t.vote : R = k > 0.5 ? "downvote" : "upvote";
1456
- const I = typeof e == "function" ? e(P) : e;
1457
- o({
1458
- tx_id: I,
1459
- vote: R,
1460
- explanation: `State change with diff percentage: ${(k * 100).toFixed(1)}%`,
1461
- correction: O,
2002
+ function useStateChangeTracking(currentState, tx_id, options) {
2003
+ const defaultFeedbackHandler = useDefaultFeedbackHandler();
2004
+ const feedbackHandler = options?.onFeedback || defaultFeedbackHandler;
2005
+ const debounceMs = options?.debounceMs ?? 1500;
2006
+ const diffType = options?.diffType ?? "git";
2007
+ const compareWith = options?.compareWith;
2008
+ const defaultTriggerName = options?.default_trigger_name ?? "auto_state_change";
2009
+ const prevStateRef = useRef(currentState);
2010
+ const changeStartStateRef = useRef(currentState);
2011
+ const isFirstRenderRef = useRef(true);
2012
+ const timeoutRef = useRef(null);
2013
+ const currentTriggerNameRef = useRef(void 0);
2014
+ const sendFeedback = useCallback(
2015
+ (startState, endState, triggerName) => {
2016
+ const diffPercentage = calculateDiffPercentage(startState, endState);
2017
+ const diffString = formatDiff(startState, endState, diffType);
2018
+ let vote;
2019
+ if (options?.vote) {
2020
+ if (typeof options.vote === "function") {
2021
+ vote = options.vote(startState, endState, diffPercentage);
2022
+ } else {
2023
+ vote = options.vote;
2024
+ }
2025
+ } else {
2026
+ vote = diffPercentage > 0.5 ? "downvote" : "upvote";
2027
+ }
2028
+ const idString = typeof tx_id === "function" ? tx_id(endState) : tx_id;
2029
+ feedbackHandler({
2030
+ tx_id: idString,
2031
+ vote,
2032
+ explanation: `State change with diff percentage: ${(diffPercentage * 100).toFixed(1)}%`,
2033
+ correction: diffString,
1462
2034
  source: "IMPLICIT",
1463
- extra_metadata: t?.metadata,
1464
- trigger_name: v
2035
+ extra_metadata: options?.metadata,
2036
+ trigger_name: triggerName
1465
2037
  });
1466
2038
  },
1467
- [t, e, d, o]
1468
- ), g = W(
1469
- (C) => {
1470
- const P = C || p;
1471
- if (w.current && E.current && E.current !== P) {
1472
- clearTimeout(w.current);
1473
- const v = m.current;
1474
- h(
1475
- v,
1476
- n,
1477
- E.current
1478
- ), w.current = null;
2039
+ [options, tx_id, diffType, feedbackHandler]
2040
+ );
2041
+ const notifyChange = useCallback(
2042
+ (trigger_name) => {
2043
+ const newTriggerName = trigger_name || defaultTriggerName;
2044
+ if (timeoutRef.current && currentTriggerNameRef.current && currentTriggerNameRef.current !== newTriggerName) {
2045
+ clearTimeout(timeoutRef.current);
2046
+ const startState = changeStartStateRef.current;
2047
+ const currentStateBeforeChange = currentState;
2048
+ sendFeedback(
2049
+ startState,
2050
+ currentStateBeforeChange,
2051
+ currentTriggerNameRef.current
2052
+ );
2053
+ timeoutRef.current = null;
1479
2054
  }
1480
- E.current = P;
2055
+ currentTriggerNameRef.current = newTriggerName;
1481
2056
  },
1482
- [n, p, h]
2057
+ [currentState, defaultTriggerName, sendFeedback]
1483
2058
  );
1484
- return ke(() => {
1485
- if (A.current) {
1486
- A.current = !1, y.current = n, m.current = n;
2059
+ useEffect(() => {
2060
+ if (isFirstRenderRef.current) {
2061
+ isFirstRenderRef.current = false;
2062
+ prevStateRef.current = currentState;
2063
+ changeStartStateRef.current = currentState;
1487
2064
  return;
1488
2065
  }
1489
- const C = y.current;
1490
- return (f ? f(C, n) : JSON.stringify(C) === JSON.stringify(n)) || (w.current || (m.current = C), w.current && clearTimeout(w.current), y.current = n, w.current = setTimeout(() => {
1491
- const v = m.current, k = n;
1492
- h(
1493
- v,
1494
- k,
1495
- E.current || p
1496
- ), m.current = k, w.current = null;
1497
- }, u)), () => {
1498
- w.current && clearTimeout(w.current);
2066
+ const prevState = prevStateRef.current;
2067
+ const isEqual = compareWith ? compareWith(prevState, currentState) : JSON.stringify(prevState) === JSON.stringify(currentState);
2068
+ if (!isEqual) {
2069
+ if (!timeoutRef.current) {
2070
+ changeStartStateRef.current = prevState;
2071
+ }
2072
+ if (timeoutRef.current) {
2073
+ clearTimeout(timeoutRef.current);
2074
+ }
2075
+ prevStateRef.current = currentState;
2076
+ timeoutRef.current = setTimeout(() => {
2077
+ const startState = changeStartStateRef.current;
2078
+ const finalState = currentState;
2079
+ sendFeedback(
2080
+ startState,
2081
+ finalState,
2082
+ currentTriggerNameRef.current || defaultTriggerName
2083
+ );
2084
+ changeStartStateRef.current = finalState;
2085
+ timeoutRef.current = null;
2086
+ }, debounceMs);
2087
+ }
2088
+ return () => {
2089
+ if (timeoutRef.current) {
2090
+ clearTimeout(timeoutRef.current);
2091
+ }
1499
2092
  };
1500
2093
  }, [
1501
- n,
1502
- e,
1503
- t,
1504
- o,
1505
- d,
1506
- u,
1507
- f,
1508
- p,
1509
- h
1510
- ]), {
1511
- notifyChange: g
2094
+ currentState,
2095
+ tx_id,
2096
+ options,
2097
+ feedbackHandler,
2098
+ diffType,
2099
+ debounceMs,
2100
+ compareWith,
2101
+ defaultTriggerName,
2102
+ sendFeedback
2103
+ ]);
2104
+ return {
2105
+ notifyChange
1512
2106
  };
1513
2107
  }
1514
- function vt(n, e, t) {
1515
- const [r, o] = X(n), { notifyChange: u } = ct(r, e, t), d = W(
1516
- (f, p) => {
1517
- u(p), o((y) => typeof f == "function" ? f(y) : f);
2108
+ function useFeedbackState(initialState, tx_id, options) {
2109
+ const [state, setStateInternal] = useState(initialState);
2110
+ const { notifyChange } = useStateChangeTracking(state, tx_id, options);
2111
+ const setState = useCallback(
2112
+ (value, trigger_name) => {
2113
+ notifyChange(trigger_name);
2114
+ setStateInternal((prevState) => {
2115
+ const newState = typeof value === "function" ? value(prevState) : value;
2116
+ return newState;
2117
+ });
1518
2118
  },
1519
- [u]
2119
+ [notifyChange]
1520
2120
  );
1521
- return [r, d];
2121
+ return [state, setState];
1522
2122
  }
1523
- let ft = () => {
2123
+ let _loadOtelApi = () => {
1524
2124
  try {
1525
2125
  return require("@opentelemetry/api");
1526
2126
  } catch {
@@ -1529,21 +2129,23 @@ let ft = () => {
1529
2129
  );
1530
2130
  }
1531
2131
  };
1532
- function bt() {
1533
- const { trace: n, context: e } = ft();
2132
+ function getOtelTraceId() {
2133
+ const { trace, context } = _loadOtelApi();
1534
2134
  try {
1535
- const t = n.getSpanContext(e.active());
1536
- if (t?.traceId)
1537
- return t.traceId;
1538
- const r = n.getSpan(e.active());
1539
- if (r) {
1540
- const o = r.spanContext();
1541
- if (o.traceId)
1542
- return o.traceId;
2135
+ const spanContext = trace.getSpanContext(context.active());
2136
+ if (spanContext?.traceId) {
2137
+ return spanContext.traceId;
2138
+ }
2139
+ const activeSpan = trace.getSpan(context.active());
2140
+ if (activeSpan) {
2141
+ const spanCtx = activeSpan.spanContext();
2142
+ if (spanCtx.traceId) {
2143
+ return spanCtx.traceId;
2144
+ }
1543
2145
  }
1544
- } catch (t) {
2146
+ } catch (error) {
1545
2147
  throw new Error(
1546
- `Failed to extract OpenTelemetry trace ID: ${t instanceof Error ? t.message : "Unknown error"}`
2148
+ `Failed to extract OpenTelemetry trace ID: ${error instanceof Error ? error.message : "Unknown error"}`
1547
2149
  );
1548
2150
  }
1549
2151
  throw new Error(
@@ -1551,11 +2153,12 @@ function bt() {
1551
2153
  );
1552
2154
  }
1553
2155
  export {
1554
- se as KeletContext,
1555
- ht as KeletProvider,
1556
- mt as VoteFeedback,
1557
- bt as getOtelTraceId,
1558
- Pe as useDefaultFeedbackHandler,
1559
- vt as useFeedbackState,
1560
- pt as useKelet
2156
+ KeletContext,
2157
+ KeletProvider,
2158
+ VoteFeedback,
2159
+ getOtelTraceId,
2160
+ useDefaultFeedbackHandler,
2161
+ useFeedbackState,
2162
+ useKelet
1561
2163
  };
2164
+ //# sourceMappingURL=feedback-ui.es.js.map