@kelet-ai/feedback-ui 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,32 +1,38 @@
1
- import Ae, { 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 De } 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,968 +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(Re) {
228
- return Re !== "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 = Ae, 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
- }, ke = () => {
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
- }, Pe = Ee(
434
+ return { ...slotProps, ...overrideProps };
435
+ };
436
+ const VoteFeedbackContext = createContext(
359
437
  null
360
- ), te = () => {
361
- const n = ae(Pe);
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 = ke(), O = e || k, R = W(async () => {
376
- h("upvote");
377
- const c = {
378
- 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,
379
478
  vote: "upvote",
380
- ...o && { extra_metadata: o },
381
- ...u && { trigger_name: u }
479
+ ...extra_metadata && { extra_metadata },
480
+ ...trigger_name && { trigger_name }
382
481
  };
383
482
  try {
384
- w(!0), await O(c);
483
+ setIsSubmitting(true);
484
+ await handler(data);
385
485
  } finally {
386
- w(!1);
486
+ setIsSubmitting(false);
387
487
  }
388
- }, [O, d, o, u]), I = W(async () => {
389
- if (h("downvote"), O) {
390
- const c = {
391
- 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,
392
494
  vote: "downvote",
393
- ...o && { extra_metadata: o },
394
- ...u && { trigger_name: u }
495
+ ...extra_metadata && { extra_metadata },
496
+ ...trigger_name && { trigger_name }
395
497
  };
396
498
  try {
397
- w(!0), await O(c);
499
+ setIsSubmitting(true);
500
+ await handler(data);
398
501
  } finally {
399
- w(!1);
502
+ setIsSubmitting(false);
400
503
  }
401
504
  }
402
- p(!0), setTimeout(() => {
403
- g.current?.focus();
404
- const c = document.createElement("div");
405
- 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);
406
515
  }, 0);
407
- }, [O, d, o, u]), L = W(
408
- (c) => {
409
- m(c.target.value);
516
+ }, [handler, tx_id, extra_metadata, trigger_name]);
517
+ const handleTextareaChange = useCallback(
518
+ (e) => {
519
+ setFeedbackText(e.target.value);
410
520
  },
411
521
  []
412
- ), i = W(async () => {
413
- const c = y.trim().length > 0;
414
- if (c) {
415
- const b = {
416
- 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,
417
528
  vote: "downvote",
418
- explanation: y,
419
- ...o && { extra_metadata: o },
420
- ...u && { trigger_name: u }
529
+ explanation: feedbackText,
530
+ ...extra_metadata && { extra_metadata },
531
+ ...trigger_name && { trigger_name }
421
532
  };
422
533
  try {
423
- w(!0), await O(b);
534
+ setIsSubmitting(true);
535
+ await handler(data);
424
536
  } finally {
425
- w(!1);
537
+ setIsSubmitting(false);
426
538
  }
427
539
  }
428
- if (p(!1), m(t), C.current?.focus(), c) {
429
- const b = document.createElement("div");
430
- 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);
431
550
  }
432
- }, [O, y, t, d, o, u]), l = W(
433
- (c) => {
434
- if (c.key === "Escape")
435
- p(!1), m(t), C.current?.focus();
436
- else if ((c.metaKey || c.ctrlKey) && c.key === "Enter")
437
- 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((_) => {
438
561
  });
439
- else if (c.key === "Tab" && f) {
440
- const b = document.getElementById(P);
441
- if (b) {
442
- 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(
443
566
  'button, textarea, input, select, a[href], [tabindex]:not([tabindex="-1"])'
444
- ), x = D[0], M = D[D.length - 1];
445
- 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
+ }
446
577
  }
447
578
  }
448
579
  },
449
- [i, f, P, t]
450
- ), s = {
451
- onFeedback: O,
452
- showPopover: f,
453
- setShowPopover: p,
454
- feedbackText: y,
455
- setFeedbackText: m,
456
- isSubmitting: A,
457
- setIsSubmitting: w,
458
- vote: E,
459
- handleUpvote: R,
460
- handleDownvote: I,
461
- handleTextareaChange: L,
462
- handleSubmit: i,
463
- handleKeyDown: l,
464
- textareaRef: g,
465
- triggerRef: C,
466
- popoverId: P,
467
- triggerId: v,
468
- tx_id: d,
469
- extra_metadata: o,
470
- 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
471
603
  };
472
- return /* @__PURE__ */ F.jsx(Pe.Provider, { value: s, children: n });
473
- }, Me = ({
474
- asChild: n,
475
- children: e,
476
- onClick: t,
477
- ...r
604
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(VoteFeedbackContext.Provider, { value: contextValue, children });
605
+ };
606
+ const UpvoteButton = ({
607
+ asChild,
608
+ children,
609
+ onClick,
610
+ ...props
478
611
  }) => {
479
- const { handleUpvote: o, isSubmitting: u, vote: d } = te(), f = W(
480
- (m) => {
481
- o(), t?.(m);
612
+ const { handleUpvote, isSubmitting, vote } = useVoteFeedbackContext();
613
+ const handleClick = useCallback(
614
+ (e) => {
615
+ handleUpvote();
616
+ onClick?.(e);
482
617
  },
483
- [o, t]
484
- ), p = {
485
- ...r,
486
- onClick: f,
487
- disabled: u || r.disabled,
488
- "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",
489
625
  type: "button"
490
- }, y = d === "upvote";
491
- if (n) {
492
- const m = typeof e == "function" ? e({ isSelected: y }) : e;
493
- if (Z(m))
494
- return Q(
495
- m,
496
- 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)
497
634
  );
635
+ }
498
636
  }
499
- return /* @__PURE__ */ F.jsx("button", { ...p, children: typeof e == "function" ? e({ isSelected: y }) : e });
500
- }, $e = ({
501
- asChild: n,
502
- children: e,
503
- onClick: t,
504
- ...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
505
644
  }) => {
506
645
  const {
507
- handleDownvote: o,
508
- showPopover: u,
509
- isSubmitting: d,
510
- popoverId: f,
511
- triggerId: p,
512
- triggerRef: y,
513
- vote: m
514
- } = te(), A = W(
515
- (h) => {
516
- 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);
517
658
  },
518
- [o, t]
519
- ), w = {
520
- ...r,
521
- ref: y,
522
- onClick: A,
523
- disabled: d || r.disabled,
524
- "aria-label": r["aria-label"] || "Downvote feedback",
525
- "aria-expanded": u,
526
- "aria-controls": f,
527
- 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,
528
670
  type: "button"
529
- }, E = m === "downvote";
530
- if (n) {
531
- const h = typeof e == "function" ? e({ isSelected: E }) : e;
532
- if (Z(h))
533
- return Q(h, ee(w, h.props));
534
- if (h)
535
- 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
+ }
536
680
  }
537
- return /* @__PURE__ */ F.jsx("button", { ...w, children: typeof e == "function" ? e({ isSelected: E }) : e });
538
- }, qe = ({ asChild: n, children: e, ...t }) => {
539
- const { showPopover: r, handleKeyDown: o, popoverId: u, triggerId: d } = te();
540
- 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) {
541
686
  return null;
542
- const f = {
543
- ...t,
687
+ }
688
+ const slotProps = {
689
+ ...props,
544
690
  role: "dialog",
545
- "aria-labelledby": d,
546
- "aria-modal": !0,
547
- "aria-describedby": `${u}-description`,
548
- id: u,
549
- onKeyDown: o,
691
+ "aria-labelledby": triggerId,
692
+ "aria-modal": true,
693
+ "aria-describedby": `${popoverId}-description`,
694
+ id: popoverId,
695
+ onKeyDown: handleKeyDown,
550
696
  tabIndex: -1
551
697
  };
552
- return n && Z(e) ? /* @__PURE__ */ F.jsxs(F.Fragment, { children: [
553
- Q(
554
- e,
555
- ee(f, e.props)
556
- ),
557
- /* @__PURE__ */ F.jsx("div", { id: `${u}-description`, className: "sr-only", children: "Provide additional feedback for your downvote" })
558
- ] }) : /* @__PURE__ */ F.jsxs("div", { ...f, children: [
559
- /* @__PURE__ */ F.jsx("div", { id: `${u}-description`, className: "sr-only", children: "Provide additional feedback for your downvote" }),
560
- 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
561
710
  ] });
562
- }, We = ({ asChild: n, value: e, onChange: t, ...r }) => {
711
+ };
712
+ const Textarea = ({ asChild, value, onChange, ...props }) => {
563
713
  const {
564
- feedbackText: o,
565
- handleTextareaChange: u,
566
- textareaRef: d,
567
- handleKeyDown: f,
568
- popoverId: p
569
- } = te(), y = {
570
- ...r,
571
- ref: d,
572
- value: e !== void 0 ? e : o,
573
- onChange: t || u,
574
- onKeyDown: f,
575
- placeholder: r.placeholder || "What did we miss?",
576
- "aria-label": r["aria-label"] || "Additional feedback",
577
- "aria-describedby": `${p}-help`,
578
- 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
579
730
  };
580
- return n && Z(r.children) ? Q(
581
- r.children,
582
- ee(y, r.children.props)
583
- ) : /* @__PURE__ */ F.jsx("textarea", { ...y });
584
- }, Ye = ({
585
- asChild: n,
586
- children: e,
587
- onClick: t,
588
- ...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
589
744
  }) => {
590
- const { handleSubmit: o, isSubmitting: u, feedbackText: d } = te(), f = W(
591
- (A) => {
592
- o(), t?.(A);
745
+ const { handleSubmit, isSubmitting, feedbackText } = useVoteFeedbackContext();
746
+ const handleClick = useCallback(
747
+ (e) => {
748
+ handleSubmit();
749
+ onClick?.(e);
593
750
  },
594
- [o, t]
595
- ), p = d.trim().length > 0, y = p ? "Submit feedback" : "Close without feedback", m = {
596
- ...r,
597
- onClick: f,
598
- 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,
599
759
  type: "button",
600
- "aria-label": r["aria-label"] || y,
601
- "aria-describedby": p ? void 0 : "submit-help"
760
+ "aria-label": props["aria-label"] || buttonText,
761
+ "aria-describedby": hasText ? void 0 : "submit-help"
602
762
  };
603
- return n && Z(e) ? /* @__PURE__ */ F.jsxs(F.Fragment, { children: [
604
- Q(
605
- e,
606
- ee(m, e.props)
607
- ),
608
- !p && /* @__PURE__ */ F.jsx("span", { id: "submit-help", className: "sr-only", children: "This will close the dialog without submitting feedback" })
609
- ] }) : /* @__PURE__ */ F.jsxs("button", { ...m, children: [
610
- e,
611
- !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" })
612
775
  ] });
613
- }, mt = {
614
- Root: Le,
615
- UpvoteButton: Me,
616
- DownvoteButton: $e,
617
- Popover: qe,
618
- Textarea: We,
619
- SubmitButton: Ye
620
776
  };
621
- var ie = { exports: {} }, ze = ie.exports, he;
622
- function Ke() {
623
- return he || (he = 1, function(n, e) {
624
- (function(t, r) {
625
- var o = r(t);
626
- n.exports = o;
627
- })(ze, function(t) {
628
- var r = ["N", "E", "A", "D"];
629
- function o(i, l) {
630
- 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, {
631
802
  constructor: {
632
- value: i,
633
- enumerable: !1,
634
- writable: !0,
635
- configurable: !0
803
+ value: ctor,
804
+ enumerable: false,
805
+ writable: true,
806
+ configurable: true
636
807
  }
637
808
  });
638
809
  }
639
- function u(i, l) {
810
+ function Diff2(kind, path) {
640
811
  Object.defineProperty(this, "kind", {
641
- value: i,
642
- enumerable: !0
643
- }), l && l.length && Object.defineProperty(this, "path", {
644
- value: l,
645
- enumerable: !0
812
+ value: kind,
813
+ enumerable: true
646
814
  });
815
+ if (path && path.length) {
816
+ Object.defineProperty(this, "path", {
817
+ value: path,
818
+ enumerable: true
819
+ });
820
+ }
647
821
  }
648
- function d(i, l, s) {
649
- d.super_.call(this, "E", i), Object.defineProperty(this, "lhs", {
650
- value: l,
651
- enumerable: !0
652
- }), Object.defineProperty(this, "rhs", {
653
- value: s,
654
- 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
655
831
  });
656
832
  }
657
- o(d, u);
658
- function f(i, l) {
659
- f.super_.call(this, "N", i), Object.defineProperty(this, "rhs", {
660
- value: l,
661
- 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
662
839
  });
663
840
  }
664
- o(f, u);
665
- function p(i, l) {
666
- p.super_.call(this, "D", i), Object.defineProperty(this, "lhs", {
667
- value: l,
668
- 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
669
847
  });
670
848
  }
671
- o(p, u);
672
- function y(i, l, s) {
673
- y.super_.call(this, "A", i), Object.defineProperty(this, "index", {
674
- value: l,
675
- enumerable: !0
676
- }), Object.defineProperty(this, "item", {
677
- value: s,
678
- 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
679
859
  });
680
860
  }
681
- o(y, u);
682
- function m(i, l, s) {
683
- var c = i.slice(l + 1 || i.length);
684
- 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;
685
867
  }
686
- function A(i) {
687
- var l = typeof i;
688
- 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";
689
885
  }
690
- function w(i) {
691
- var l = 0;
692
- if (i.length === 0)
693
- return l;
694
- for (var s = 0; s < i.length; s++) {
695
- var c = i.charCodeAt(s);
696
- l = (l << 5) - l + c, l = l & l;
886
+ function hashThisString(string) {
887
+ var hash = 0;
888
+ if (string.length === 0) {
889
+ return hash;
697
890
  }
698
- 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;
699
897
  }
700
- function E(i) {
701
- var l = 0, s = A(i);
702
- if (s === "array") {
703
- i.forEach(function(M) {
704
- 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);
705
904
  });
706
- var c = "[type: array, hash: " + l + "]";
707
- return l + w(c);
905
+ var arrayString = "[type: array, hash: " + accum + "]";
906
+ return accum + hashThisString(arrayString);
708
907
  }
709
- if (s === "object") {
710
- for (var b in i)
711
- if (i.hasOwnProperty(b)) {
712
- var D = "[ type: object, key: " + b + ", value hash: " + E(i[b]) + "]";
713
- 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);
714
913
  }
715
- return l;
914
+ }
915
+ return accum;
716
916
  }
717
- var x = "[ type: " + s + " ; value: " + i + "]";
718
- return l + w(x);
917
+ var stringToHash = "[ type: " + type + " ; value: " + object + "]";
918
+ return accum + hashThisString(stringToHash);
719
919
  }
720
- function h(i, l, s, c, b, D, x, M) {
721
- s = s || [], b = b || [], x = x || [];
722
- var N = b.slice(0);
723
- if (typeof D < "u" && D !== null) {
724
- if (c) {
725
- 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)) {
726
928
  return;
727
- if (typeof c == "object") {
728
- if (c.prefilter && c.prefilter(N, D))
929
+ } else if (typeof prefilter === "object") {
930
+ if (prefilter.prefilter && prefilter.prefilter(currentPath, key)) {
729
931
  return;
730
- if (c.normalize) {
731
- var H = c.normalize(N, D, i, l);
732
- 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
+ }
733
939
  }
734
940
  }
735
941
  }
736
- N.push(D);
942
+ currentPath.push(key);
737
943
  }
738
- A(i) === "regexp" && A(l) === "regexp" && (i = i.toString(), l = l.toString());
739
- 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);
740
- if (!q && $)
741
- s.push(new f(N, l));
742
- else if (!$ && q)
743
- s.push(new p(N, i));
744
- else if (A(i) !== A(l))
745
- s.push(new d(N, i, l));
746
- else if (A(i) === "date" && i - l !== 0)
747
- s.push(new d(N, i, l));
748
- else if (J === "object" && i !== null && l !== null) {
749
- for (a = x.length - 1; a > -1; --a)
750
- if (x[a].lhs === i) {
751
- 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;
752
965
  break;
753
966
  }
754
- if (S)
755
- i !== l && s.push(new d(N, i, l));
756
- else {
757
- if (x.push({ lhs: i, rhs: l }), Array.isArray(i)) {
758
- for (M && (i.sort(function(j, Y) {
759
- return E(j) - E(Y);
760
- }), l.sort(function(j, Y) {
761
- return E(j) - E(Y);
762
- })), a = l.length - 1, T = i.length - 1; a > T; )
763
- s.push(new y(N, a, new f(void 0, l[a--])));
764
- for (; T > a; )
765
- s.push(new y(N, T, new p(void 0, i[T--])));
766
- for (; a >= 0; --a)
767
- 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
+ }
768
990
  } else {
769
- var B = Object.keys(i), K = Object.keys(l);
770
- for (a = 0; a < B.length; ++a)
771
- _ = 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);
772
- for (a = 0; a < K.length; ++a)
773
- _ = 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
+ }
774
1009
  }
775
- 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));
776
1017
  }
777
- } else i !== l && (J === "number" && isNaN(i) && isNaN(l) || s.push(new d(N, i, l)));
1018
+ }
778
1019
  }
779
- function g(i, l, s, c, b) {
780
- var D = [];
781
- if (h(i, l, D, c, null, null, null, b), s)
782
- for (var x = 0; x < D.length; ++x)
783
- s(D[x]);
784
- 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;
785
1029
  }
786
- function C(i, l, s, c, b, D, x) {
787
- 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);
788
1032
  }
789
- function P(i, l, s, c) {
790
- var b = c ? function(x) {
791
- x && c.push(x);
792
- } : void 0, D = g(i, l, b, s);
793
- 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;
794
1041
  }
795
- function v(i, l, s, c) {
796
- var b = c ? function(x) {
797
- x && c.push(x);
798
- } : void 0, D = g(i, l, b, s, !0);
799
- 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;
800
1050
  }
801
- function k(i, l, s) {
802
- if (s.path && s.path.length) {
803
- var c = i[l], b, D = s.path.length - 1;
804
- for (b = 0; b < D; b++)
805
- c = c[s.path[b]];
806
- 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) {
807
1058
  case "A":
808
- k(c[s.path[b]], s.index, s.item);
1059
+ applyArrayChange(it[change.path[i]], change.index, change.item);
809
1060
  break;
810
1061
  case "D":
811
- delete c[s.path[b]];
1062
+ delete it[change.path[i]];
812
1063
  break;
813
1064
  case "E":
814
1065
  case "N":
815
- c[s.path[b]] = s.rhs;
1066
+ it[change.path[i]] = change.rhs;
816
1067
  break;
817
1068
  }
818
- } else
819
- switch (s.kind) {
1069
+ } else {
1070
+ switch (change.kind) {
820
1071
  case "A":
821
- k(i[l], s.index, s.item);
1072
+ applyArrayChange(arr[index], change.index, change.item);
822
1073
  break;
823
1074
  case "D":
824
- i = m(i, l);
1075
+ arr = arrayRemove(arr, index);
825
1076
  break;
826
1077
  case "E":
827
1078
  case "N":
828
- i[l] = s.rhs;
1079
+ arr[index] = change.rhs;
829
1080
  break;
830
1081
  }
831
- return i;
1082
+ }
1083
+ return arr;
832
1084
  }
833
- function O(i, l, s) {
834
- if (typeof s > "u" && l && ~r.indexOf(l.kind) && (s = l), i && s && s.kind) {
835
- for (var c = i, b = -1, D = s.path ? s.path.length - 1 : 0; ++b < D; )
836
- 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]];
837
- 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) {
838
1098
  case "A":
839
- 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);
840
1103
  break;
841
1104
  case "D":
842
- delete c[s.path[b]];
1105
+ delete it[change.path[i]];
843
1106
  break;
844
1107
  case "E":
845
1108
  case "N":
846
- c[s.path[b]] = s.rhs;
1109
+ it[change.path[i]] = change.rhs;
847
1110
  break;
848
1111
  }
849
1112
  }
850
1113
  }
851
- function R(i, l, s) {
852
- if (s.path && s.path.length) {
853
- var c = i[l], b, D = s.path.length - 1;
854
- for (b = 0; b < D; b++)
855
- c = c[s.path[b]];
856
- 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) {
857
1121
  case "A":
858
- R(c[s.path[b]], s.index, s.item);
1122
+ revertArrayChange(it[change.path[i]], change.index, change.item);
859
1123
  break;
860
1124
  case "D":
861
- c[s.path[b]] = s.lhs;
1125
+ it[change.path[i]] = change.lhs;
862
1126
  break;
863
1127
  case "E":
864
- c[s.path[b]] = s.lhs;
1128
+ it[change.path[i]] = change.lhs;
865
1129
  break;
866
1130
  case "N":
867
- delete c[s.path[b]];
1131
+ delete it[change.path[i]];
868
1132
  break;
869
1133
  }
870
- } else
871
- switch (s.kind) {
1134
+ } else {
1135
+ switch (change.kind) {
872
1136
  case "A":
873
- R(i[l], s.index, s.item);
1137
+ revertArrayChange(arr[index], change.index, change.item);
874
1138
  break;
875
1139
  case "D":
876
- i[l] = s.lhs;
1140
+ arr[index] = change.lhs;
877
1141
  break;
878
1142
  case "E":
879
- i[l] = s.lhs;
1143
+ arr[index] = change.lhs;
880
1144
  break;
881
1145
  case "N":
882
- i = m(i, l);
1146
+ arr = arrayRemove(arr, index);
883
1147
  break;
884
1148
  }
885
- return i;
1149
+ }
1150
+ return arr;
886
1151
  }
887
- function I(i, l, s) {
888
- if (i && l && s && s.kind) {
889
- var c = i, b, D;
890
- for (D = s.path.length - 1, b = 0; b < D; b++)
891
- typeof c[s.path[b]] > "u" && (c[s.path[b]] = {}), c = c[s.path[b]];
892
- 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) {
893
1163
  case "A":
894
- R(c[s.path[b]], s.index, s.item);
1164
+ revertArrayChange(it[change.path[i]], change.index, change.item);
895
1165
  break;
896
1166
  case "D":
897
- c[s.path[b]] = s.lhs;
1167
+ it[change.path[i]] = change.lhs;
898
1168
  break;
899
1169
  case "E":
900
- c[s.path[b]] = s.lhs;
1170
+ it[change.path[i]] = change.lhs;
901
1171
  break;
902
1172
  case "N":
903
- delete c[s.path[b]];
1173
+ delete it[change.path[i]];
904
1174
  break;
905
1175
  }
906
1176
  }
907
1177
  }
908
- function L(i, l, s) {
909
- if (i && l) {
910
- var c = function(b) {
911
- (!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
+ }
912
1184
  };
913
- g(i, l, c);
1185
+ observableDiff(target, source, onChange);
914
1186
  }
915
1187
  }
916
- return Object.defineProperties(P, {
1188
+ Object.defineProperties(accumulateDiff, {
917
1189
  diff: {
918
- value: P,
919
- enumerable: !0
1190
+ value: accumulateDiff,
1191
+ enumerable: true
920
1192
  },
921
1193
  orderIndependentDiff: {
922
- value: v,
923
- enumerable: !0
1194
+ value: accumulateOrderIndependentDiff,
1195
+ enumerable: true
924
1196
  },
925
1197
  observableDiff: {
926
- value: g,
927
- enumerable: !0
1198
+ value: observableDiff,
1199
+ enumerable: true
928
1200
  },
929
1201
  orderIndependentObservableDiff: {
930
- value: C,
931
- enumerable: !0
1202
+ value: orderIndependentDeepDiff,
1203
+ enumerable: true
932
1204
  },
933
1205
  orderIndepHash: {
934
- value: E,
935
- enumerable: !0
1206
+ value: getOrderIndependentHash,
1207
+ enumerable: true
936
1208
  },
937
1209
  applyDiff: {
938
- value: L,
939
- enumerable: !0
1210
+ value: applyDiff,
1211
+ enumerable: true
940
1212
  },
941
1213
  applyChange: {
942
- value: O,
943
- enumerable: !0
1214
+ value: applyChange,
1215
+ enumerable: true
944
1216
  },
945
1217
  revertChange: {
946
- value: I,
947
- enumerable: !0
1218
+ value: revertChange,
1219
+ enumerable: true
948
1220
  },
949
1221
  isConflict: {
950
1222
  value: function() {
951
- return typeof $conflict < "u";
1223
+ return typeof $conflict !== "undefined";
952
1224
  },
953
- enumerable: !0
1225
+ enumerable: true
954
1226
  }
955
- }), P.DeepDiff = P, t && (t.DeepDiff = P), P;
1227
+ });
1228
+ accumulateDiff.DeepDiff = accumulateDiff;
1229
+ if (root) {
1230
+ root.DeepDiff = accumulateDiff;
1231
+ }
1232
+ return accumulateDiff;
956
1233
  });
957
- }(ie)), ie.exports;
1234
+ })(deepDiff$1);
1235
+ return deepDiff$1.exports;
958
1236
  }
959
- var xe = Ke(), oe = { exports: {} };
960
- const z = new Uint32Array(65536), Ue = (n, e) => {
961
- const t = n.length, r = e.length, o = 1 << t - 1;
962
- let u = -1, d = 0, f = t, p = t;
963
- for (; p--; )
964
- z[n.charCodeAt(p)] |= 1 << p;
965
- for (p = 0; p < r; p++) {
966
- let y = z[e.charCodeAt(p)];
967
- const m = y | d;
968
- 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
+ }
969
1315
  }
970
- for (p = t; p--; )
971
- z[n.charCodeAt(p)] = 0;
972
- return f;
973
- }, He = (n, e) => {
974
- const t = e.length, r = n.length, o = [], u = [], d = Math.ceil(t / 32), f = Math.ceil(r / 32);
975
- for (let h = 0; h < d; h++)
976
- u[h] = -1, o[h] = 0;
977
- let p = 0;
978
- for (; p < f - 1; p++) {
979
- let h = 0, g = -1;
980
- const C = p * 32, P = Math.min(32, r) + C;
981
- for (let v = C; v < P; v++)
982
- z[n.charCodeAt(v)] |= 1 << v;
983
- for (let v = 0; v < t; v++) {
984
- 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;
985
- let i = h | ~(L | g), l = g & L;
986
- 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;
987
1339
  }
988
- for (let v = C; v < P; v++)
989
- z[n.charCodeAt(v)] = 0;
1340
+ ph = ph << 1 | pb;
1341
+ mh = mh << 1 | mb;
1342
+ pv = mh | ~(xv | ph);
1343
+ mv = ph & xv;
990
1344
  }
991
- let y = 0, m = -1;
992
- const A = p * 32, w = Math.min(32, r - A) + A;
993
- for (let h = A; h < w; h++)
994
- z[n.charCodeAt(h)] |= 1 << h;
995
- let E = r;
996
- for (let h = 0; h < t; h++) {
997
- 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;
998
- let O = y | ~(k | m), R = m & k;
999
- 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;
1000
1347
  }
1001
- for (let h = A; h < w; h++)
1002
- z[n.charCodeAt(h)] = 0;
1003
- return E;
1004
- }, Te = (n, e) => {
1005
- if (n.length < e.length) {
1006
- const t = e;
1007
- 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;
1008
1358
  }
1009
- return e.length === 0 ? n.length : n.length <= 32 ? Ue(n, e) : He(n, e);
1010
- }, Je = (n, e) => {
1011
- let t = 1 / 0, r = 0;
1012
- for (let o = 0; o < e.length; o++) {
1013
- const u = Te(n, e[o]);
1014
- u < t && (t = u, r = o);
1359
+ if (a.length <= 32) {
1360
+ return myers_32(a, b);
1015
1361
  }
1016
- return e[r];
1017
- }, 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({
1018
1377
  __proto__: null,
1019
- closest: Je,
1020
- distance: Te
1021
- }, Symbol.toStringTag, { value: "Module" })), Ve = /* @__PURE__ */ Se(Be);
1022
- var me;
1023
- function Ge() {
1024
- 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) {
1025
1387
  (function() {
1026
- var t;
1388
+ var collator;
1027
1389
  try {
1028
- t = typeof Intl < "u" && typeof Intl.Collator < "u" ? Intl.Collator("generic", { sensitivity: "base" }) : null;
1029
- } catch {
1390
+ collator = typeof Intl !== "undefined" && typeof Intl.Collator !== "undefined" ? Intl.Collator("generic", { sensitivity: "base" }) : null;
1391
+ } catch (err) {
1030
1392
  console.log("Collator could not be initialized and wouldn't be used");
1031
1393
  }
1032
- var r = Ve, o = [], u = [], d = {
1394
+ var levenshtein2 = require$$0;
1395
+ var prevRow = [], str2Char = [];
1396
+ var Levenshtein = {
1033
1397
  /**
1034
1398
  * Calculate levenshtein distance of the two strings.
1035
1399
  *
@@ -1039,484 +1403,724 @@ function Ge() {
1039
1403
  * @param [options.useCollator] Use `Intl.Collator` for locale-sensitive string comparison.
1040
1404
  * @return Integer the levenshtein distance (0 and above).
1041
1405
  */
1042
- get: function(f, p, y) {
1043
- var m = y && t && y.useCollator;
1044
- if (m) {
1045
- var A = f.length, w = p.length;
1046
- if (A === 0) return w;
1047
- if (w === 0) return A;
1048
- var E, h, g, C, P;
1049
- for (g = 0; g < w; ++g)
1050
- o[g] = g, u[g] = p.charCodeAt(g);
1051
- o[w] = w;
1052
- var v;
1053
- for (g = 0; g < A; ++g) {
1054
- for (h = g + 1, C = 0; C < w; ++C)
1055
- 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;
1056
- 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;
1057
1436
  }
1058
- return h;
1437
+ return nextCol;
1059
1438
  }
1060
- return r.distance(f, p);
1439
+ return levenshtein2.distance(str1, str2);
1061
1440
  }
1062
1441
  };
1063
- 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
+ }
1064
1449
  })();
1065
- }(oe, oe.exports)), oe.exports;
1450
+ })(levenshtein$1, levenshtein$1.exports);
1451
+ return levenshtein$1.exports;
1066
1452
  }
1067
- var Xe = Ge();
1068
- const Ze = /* @__PURE__ */ _e(Xe);
1069
- class Qe {
1070
- diff(e, t, r = {}) {
1071
- let o;
1072
- typeof r == "function" ? (o = r, r = {}) : "callback" in r && (o = r.callback);
1073
- 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));
1074
- 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);
1075
1469
  }
1076
- diffWithOptionsObj(e, t, r, o) {
1077
- var u;
1078
- const d = (v) => {
1079
- 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) {
1080
1475
  setTimeout(function() {
1081
- o(v);
1476
+ callback(value);
1082
1477
  }, 0);
1083
- return;
1084
- } else
1085
- return v;
1086
- }, f = t.length, p = e.length;
1087
- let y = 1, m = f + p;
1088
- r.maxEditLength != null && (m = Math.min(m, r.maxEditLength));
1089
- const A = (u = r.timeout) !== null && u !== void 0 ? u : 1 / 0, w = Date.now() + A, E = [{ oldPos: -1, lastComponent: void 0 }];
1090
- let h = this.extractCommon(E[0], t, e, 0, r);
1091
- if (E[0].oldPos + 1 >= p && h + 1 >= f)
1092
- return d(this.buildValues(E[0].lastComponent, t, e));
1093
- let g = -1 / 0, C = 1 / 0;
1094
- const P = () => {
1095
- for (let v = Math.max(g, -y); v <= Math.min(C, y); v += 2) {
1096
- let k;
1097
- const O = E[v - 1], R = E[v + 1];
1098
- O && (E[v - 1] = void 0);
1099
- let I = !1;
1100
- if (R) {
1101
- const i = R.oldPos - v;
1102
- 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;
1103
1503
  }
1104
- const L = O && O.oldPos + 1 < p;
1105
- if (!I && !L) {
1106
- 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;
1107
1512
  continue;
1108
1513
  }
1109
- 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)
1110
- return d(this.buildValues(k.lastComponent, t, e)) || !0;
1111
- 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
+ }
1112
1531
  }
1113
- y++;
1532
+ editLength++;
1114
1533
  };
1115
- if (o)
1116
- (function v() {
1534
+ if (callback) {
1535
+ (function exec() {
1117
1536
  setTimeout(function() {
1118
- if (y > m || Date.now() > w)
1119
- return o(void 0);
1120
- P() || v();
1537
+ if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) {
1538
+ return callback(void 0);
1539
+ }
1540
+ if (!execEditLength()) {
1541
+ exec();
1542
+ }
1121
1543
  }, 0);
1122
1544
  })();
1123
- else
1124
- for (; y <= m && Date.now() <= w; ) {
1125
- const v = P();
1126
- if (v)
1127
- return v;
1545
+ } else {
1546
+ while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) {
1547
+ const ret = execEditLength();
1548
+ if (ret) {
1549
+ return ret;
1550
+ }
1128
1551
  }
1552
+ }
1129
1553
  }
1130
- addToPath(e, t, r, o, u) {
1131
- const d = e.lastComponent;
1132
- return d && !u.oneChangePerToken && d.added === t && d.removed === r ? {
1133
- oldPos: e.oldPos + o,
1134
- lastComponent: { count: d.count + 1, added: t, removed: r, previousComponent: d.previousComponent }
1135
- } : {
1136
- oldPos: e.oldPos + o,
1137
- lastComponent: { count: 1, added: t, removed: r, previousComponent: d }
1138
- };
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
+ }
1139
1567
  }
1140
- extractCommon(e, t, r, o, u) {
1141
- const d = t.length, f = r.length;
1142
- let p = e.oldPos, y = p - o, m = 0;
1143
- for (; y + 1 < d && p + 1 < f && this.equals(r[p + 1], t[y + 1], u); )
1144
- y++, p++, m++, u.oneChangePerToken && (e.lastComponent = { count: 1, previousComponent: e.lastComponent, added: !1, removed: !1 });
1145
- 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;
1146
1584
  }
1147
- equals(e, t, r) {
1148
- 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
+ }
1149
1591
  }
1150
- removeEmpty(e) {
1151
- const t = [];
1152
- for (let r = 0; r < e.length; r++)
1153
- e[r] && t.push(e[r]);
1154
- 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;
1155
1600
  }
1156
1601
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
1157
- castInput(e, t) {
1158
- return e;
1602
+ castInput(value, options) {
1603
+ return value;
1159
1604
  }
1160
1605
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
1161
- tokenize(e, t) {
1162
- return Array.from(e);
1606
+ tokenize(value, options) {
1607
+ return Array.from(value);
1163
1608
  }
1164
- join(e) {
1165
- return e.join("");
1609
+ join(chars) {
1610
+ return chars.join("");
1166
1611
  }
1167
- postProcess(e, t) {
1168
- return e;
1612
+ postProcess(changeObjects, options) {
1613
+ return changeObjects;
1169
1614
  }
1170
1615
  get useLongestToken() {
1171
- return !1;
1616
+ return false;
1172
1617
  }
1173
- buildValues(e, t, r) {
1174
- const o = [];
1175
- let u;
1176
- for (; e; )
1177
- o.push(e), u = e.previousComponent, delete e.previousComponent, e = u;
1178
- o.reverse();
1179
- const d = o.length;
1180
- let f = 0, p = 0, y = 0;
1181
- for (; f < d; f++) {
1182
- const m = o[f];
1183
- if (m.removed)
1184
- m.value = this.join(r.slice(y, y + m.count)), y += m.count;
1185
- else {
1186
- if (!m.added && this.useLongestToken) {
1187
- let A = t.slice(p, p + m.count);
1188
- A = A.map(function(w, E) {
1189
- const h = r[y + E];
1190
- return h.length > w.length ? h : w;
1191
- }), m.value = this.join(A);
1192
- } else
1193
- m.value = this.join(t.slice(p, p + m.count));
1194
- 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;
1195
1650
  }
1196
1651
  }
1197
- return o;
1652
+ return components;
1198
1653
  }
1199
1654
  }
1200
- class et extends Qe {
1655
+ class LineDiff extends Diff {
1201
1656
  constructor() {
1202
- super(...arguments), this.tokenize = nt;
1657
+ super(...arguments);
1658
+ this.tokenize = tokenize;
1203
1659
  }
1204
- equals(e, t, r) {
1205
- return r.ignoreWhitespace ? ((!r.newlineIsToken || !e.includes(`
1206
- `)) && (e = e.trim()), (!r.newlineIsToken || !t.includes(`
1207
- `)) && (t = t.trim())) : r.ignoreNewlineAtEof && !r.newlineIsToken && (e.endsWith(`
1208
- `) && (e = e.slice(0, -1)), t.endsWith(`
1209
- `) && (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);
1210
1677
  }
1211
1678
  }
1212
- const tt = new et();
1213
- function ve(n, e, t) {
1214
- return tt.diff(n, e, t);
1679
+ const lineDiff = new LineDiff();
1680
+ function diffLines(oldStr, newStr, options) {
1681
+ return lineDiff.diff(oldStr, newStr, options);
1215
1682
  }
1216
- function nt(n, e) {
1217
- e.stripTrailingCr && (n = n.replace(/\r\n/g, `
1218
- `));
1219
- const t = [], r = n.split(/(\n|\r\n)/);
1220
- r[r.length - 1] || r.pop();
1221
- for (let o = 0; o < r.length; o++) {
1222
- const u = r[o];
1223
- 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();
1224
1690
  }
1225
- 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;
1226
1700
  }
1227
- function be(n, e, t, r, o, u, d) {
1228
- let f;
1229
- d ? typeof d == "function" ? f = { callback: d } : f = d : f = {}, typeof f.context > "u" && (f.context = 4);
1230
- const p = f.context;
1231
- 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) {
1232
1715
  throw new Error("newlineIsToken may not be used with patch-generation functions, only with diffing functions");
1233
- if (f.callback) {
1234
- const { callback: m } = f;
1235
- ve(t, r, Object.assign(Object.assign({}, f), { callback: (A) => {
1236
- const w = y(A);
1237
- 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);
1238
1724
  } }));
1239
- } else
1240
- return y(ve(t, r, f));
1241
- function y(m) {
1242
- if (!m)
1725
+ }
1726
+ function diffLinesResultToPatch(diff) {
1727
+ if (!diff) {
1243
1728
  return;
1244
- m.push({ value: "", lines: [] });
1245
- function A(v) {
1246
- return v.map(function(k) {
1247
- return " " + k;
1729
+ }
1730
+ diff.push({ value: "", lines: [] });
1731
+ function contextLines(lines) {
1732
+ return lines.map(function(entry) {
1733
+ return " " + entry;
1248
1734
  });
1249
1735
  }
1250
- const w = [];
1251
- let E = 0, h = 0, g = [], C = 1, P = 1;
1252
- for (let v = 0; v < m.length; v++) {
1253
- const k = m[v], O = k.lines || ot(k.value);
1254
- if (k.lines = O, k.added || k.removed) {
1255
- if (!E) {
1256
- const R = m[v - 1];
1257
- 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;
1258
1759
  }
1259
- for (const R of O)
1260
- g.push((k.added ? "+" : "-") + R);
1261
- k.added ? P += O.length : C += O.length;
1262
1760
  } else {
1263
- if (E)
1264
- if (O.length <= p * 2 && v < m.length - 2)
1265
- for (const R of A(O))
1266
- g.push(R);
1267
- else {
1268
- const R = Math.min(O.length, p);
1269
- for (const L of A(O.slice(0, R)))
1270
- g.push(L);
1271
- const I = {
1272
- oldStart: E,
1273
- oldLines: C - E + R,
1274
- newStart: h,
1275
- newLines: P - h + R,
1276
- 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
1277
1777
  };
1278
- w.push(I), E = 0, h = 0, g = [];
1778
+ hunks.push(hunk);
1779
+ oldRangeStart = 0;
1780
+ newRangeStart = 0;
1781
+ curRange = [];
1279
1782
  }
1280
- 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
+ }
1281
1796
  }
1282
1797
  }
1283
- for (const v of w)
1284
- for (let k = 0; k < v.lines.length; k++)
1285
- v.lines[k].endsWith(`
1286
- `) ? v.lines[k] = v.lines[k].slice(0, -1) : (v.lines.splice(k + 1, 0, "\"), k++);
1287
1798
  return {
1288
- oldFileName: n,
1289
- newFileName: e,
1290
- oldHeader: o,
1291
- newHeader: u,
1292
- hunks: w
1799
+ oldFileName,
1800
+ newFileName,
1801
+ oldHeader,
1802
+ newHeader,
1803
+ hunks
1293
1804
  };
1294
1805
  }
1295
1806
  }
1296
- function ue(n) {
1297
- if (Array.isArray(n))
1298
- return n.map(ue).join(`
1299
- `);
1300
- const e = [];
1301
- 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));
1302
- for (let t = 0; t < n.hunks.length; t++) {
1303
- const r = n.hunks[t];
1304
- r.oldLines === 0 && (r.oldStart -= 1), r.newLines === 0 && (r.newStart -= 1), e.push("@@ -" + r.oldStart + "," + r.oldLines + " +" + r.newStart + "," + r.newLines + " @@");
1305
- for (const o of r.lines)
1306
- 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
+ }
1307
1830
  }
1308
- return e.join(`
1309
- `) + `
1310
- `;
1831
+ return ret.join("\n") + "\n";
1311
1832
  }
1312
- function rt(n, e, t, r, o, u, d) {
1313
- if (typeof d == "function" && (d = { callback: d }), d?.callback) {
1314
- const { callback: f } = d;
1315
- be(n, e, t, r, o, u, Object.assign(Object.assign({}, d), { callback: (p) => {
1316
- f(p ? ue(p) : void 0);
1317
- } }));
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);
1318
1843
  } else {
1319
- const f = be(n, e, t, r, o, u, d);
1320
- 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
+ } }));
1321
1852
  }
1322
1853
  }
1323
- function ot(n) {
1324
- const e = n.endsWith(`
1325
- `), t = n.split(`
1326
- `).map((r) => r + `
1327
- `);
1328
- 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;
1329
1863
  }
1330
- function it(n, e, t = "git", r = 3) {
1331
- switch (t) {
1864
+ function formatDiff(oldValue, newValue, diffType = "git", context = 3) {
1865
+ switch (diffType) {
1332
1866
  case "git":
1333
- return ye(n, e, r);
1867
+ return formatGitDiff(oldValue, newValue, context);
1334
1868
  case "object":
1335
- return st(n, e);
1869
+ return formatObjectDiff(oldValue, newValue);
1336
1870
  case "json":
1337
- return at(n, e);
1871
+ return formatJsonDiff(oldValue, newValue);
1338
1872
  default:
1339
- return ye(n, e, r);
1873
+ return formatGitDiff(oldValue, newValue, context);
1340
1874
  }
1341
1875
  }
1342
- function ye(n, e, t = 3) {
1343
- const r = ge(n), o = ge(e);
1344
- return rt(
1876
+ function formatGitDiff(oldValue, newValue, context = 3) {
1877
+ const oldStr = stringify(oldValue);
1878
+ const newStr = stringify(newValue);
1879
+ const patch = createTwoFilesPatch(
1345
1880
  /* oldFilename */
1346
1881
  "",
1347
1882
  /* newFilename */
1348
1883
  "",
1349
- r,
1350
- o,
1884
+ oldStr,
1885
+ newStr,
1351
1886
  /* oldHeader */
1352
1887
  "",
1353
1888
  /* newHeader */
1354
1889
  "",
1355
- { context: t }
1356
- ).split(`
1357
- `).slice(2).join(`
1358
- `);
1890
+ { context }
1891
+ );
1892
+ return patch.split("\n").slice(2).join("\n");
1359
1893
  }
1360
- function st(n, e) {
1361
- const t = xe.diff(n, e) || [];
1362
- 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);
1363
1897
  }
1364
- function at(n, e) {
1898
+ function formatJsonDiff(oldValue, newValue) {
1365
1899
  return JSON.stringify(
1366
1900
  {
1367
- before: n,
1368
- after: e
1901
+ before: oldValue,
1902
+ after: newValue
1369
1903
  },
1370
1904
  null,
1371
1905
  2
1372
1906
  );
1373
1907
  }
1374
- function lt(n, e) {
1375
- return typeof n == "string" && typeof e == "string" ? Ce(n, e) : typeof n == "number" && typeof e == "number" ? Oe(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
+ }
1376
1916
  }
1377
- function Ce(n, e) {
1378
- if (n === e) return 0;
1379
- if (n.length === 0 || e.length === 0) return 1;
1380
- const t = Ze.get(n, e), r = Math.max(n.length, e.length);
1381
- 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;
1382
1924
  }
1383
- function Oe(n, e) {
1384
- if (n === e) return 0;
1385
- if (n === 0) return 1;
1386
- const t = Math.abs(e - n), r = Math.max(Math.abs(n), Math.abs(e));
1387
- 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);
1388
1931
  }
1389
- function ut(n, e) {
1390
- if (n === e) return 0;
1391
- const t = xe.diff(n, e) || [];
1392
- if (t.length === 0) return 0;
1393
- const r = we(n), o = we(e), u = Math.max(r, o);
1394
- if (u === 0) return 0;
1395
- let d = 0;
1396
- for (const f of t)
1397
- 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) {
1398
1943
  case "N":
1399
- d += 1;
1944
+ changeWeight += 1;
1400
1945
  break;
1401
1946
  case "D":
1402
- d += 1;
1947
+ changeWeight += 1;
1403
1948
  break;
1404
1949
  case "E":
1405
- if (typeof f.lhs == "string" && typeof f.rhs == "string") {
1406
- const p = Ce(
1407
- f.lhs,
1408
- f.rhs
1950
+ if (typeof difference.lhs === "string" && typeof difference.rhs === "string") {
1951
+ const stringChangeRatio = calculateStringDiffPercentage(
1952
+ difference.lhs,
1953
+ difference.rhs
1409
1954
  );
1410
- d += p;
1411
- } else if (typeof f.lhs == "number" && typeof f.rhs == "number") {
1412
- const p = Oe(
1413
- f.lhs,
1414
- 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
1415
1960
  );
1416
- d += p;
1417
- } else
1418
- d += 1;
1961
+ changeWeight += numberChangeRatio;
1962
+ } else {
1963
+ changeWeight += 1;
1964
+ }
1419
1965
  break;
1420
1966
  case "A":
1421
- d += 0.5;
1967
+ changeWeight += 0.5;
1422
1968
  break;
1423
1969
  }
1424
- return Math.min(d / u, 1);
1970
+ }
1971
+ return Math.min(changeWeight / totalProps, 1);
1425
1972
  }
1426
- function we(n) {
1427
- if (n == null) return 0;
1428
- if (typeof n != "object") return 1;
1429
- if (Array.isArray(n)) return n.length;
1430
- let e = 0;
1431
- for (const t in n)
1432
- Object.prototype.hasOwnProperty.call(n, t) && (e += 1);
1433
- 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;
1434
1984
  }
1435
- function ge(n) {
1985
+ function stringify(value) {
1436
1986
  try {
1437
1987
  return JSON.stringify(
1438
- n,
1439
- (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
+ },
1440
1996
  2
1441
1997
  );
1442
- } catch {
1443
- return String(n);
1998
+ } catch (_) {
1999
+ return String(value);
1444
2000
  }
1445
2001
  }
1446
- function ct(n, e, t) {
1447
- const r = ke(), 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(
1448
- (C, P, v) => {
1449
- const k = lt(C, P), O = it(C, P, d);
1450
- let R;
1451
- t?.vote ? typeof t.vote == "function" ? R = t.vote(C, P, k) : R = t.vote : R = k > 0.5 ? "downvote" : "upvote";
1452
- const I = typeof e == "function" ? e(P) : e;
1453
- o({
1454
- tx_id: I,
1455
- vote: R,
1456
- explanation: `State change with diff percentage: ${(k * 100).toFixed(1)}%`,
1457
- 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,
1458
2034
  source: "IMPLICIT",
1459
- extra_metadata: t?.metadata,
1460
- trigger_name: v
2035
+ extra_metadata: options?.metadata,
2036
+ trigger_name: triggerName
1461
2037
  });
1462
2038
  },
1463
- [t, e, d, o]
1464
- ), g = W(
1465
- (C) => {
1466
- const P = C || p;
1467
- if (w.current && E.current && E.current !== P) {
1468
- clearTimeout(w.current);
1469
- const v = m.current;
1470
- h(
1471
- v,
1472
- n,
1473
- E.current
1474
- ), 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;
1475
2054
  }
1476
- E.current = P;
2055
+ currentTriggerNameRef.current = newTriggerName;
1477
2056
  },
1478
- [n, p, h]
2057
+ [currentState, defaultTriggerName, sendFeedback]
1479
2058
  );
1480
- return De(() => {
1481
- if (A.current) {
1482
- 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;
1483
2064
  return;
1484
2065
  }
1485
- const C = y.current;
1486
- 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(() => {
1487
- const v = m.current, k = n;
1488
- h(
1489
- v,
1490
- k,
1491
- E.current || p
1492
- ), m.current = k, w.current = null;
1493
- }, u)), () => {
1494
- 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
+ }
1495
2092
  };
1496
2093
  }, [
1497
- n,
1498
- e,
1499
- t,
1500
- o,
1501
- d,
1502
- u,
1503
- f,
1504
- p,
1505
- h
1506
- ]), {
1507
- 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
1508
2106
  };
1509
2107
  }
1510
- function vt(n, e, t) {
1511
- const [r, o] = X(n), { notifyChange: u } = ct(r, e, t), d = W(
1512
- (f, p) => {
1513
- 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
+ });
1514
2118
  },
1515
- [u]
2119
+ [notifyChange]
1516
2120
  );
1517
- return [r, d];
2121
+ return [state, setState];
1518
2122
  }
1519
- let ft = () => {
2123
+ let _loadOtelApi = () => {
1520
2124
  try {
1521
2125
  return require("@opentelemetry/api");
1522
2126
  } catch {
@@ -1525,21 +2129,23 @@ let ft = () => {
1525
2129
  );
1526
2130
  }
1527
2131
  };
1528
- function bt() {
1529
- const { trace: n, context: e } = ft();
2132
+ function getOtelTraceId() {
2133
+ const { trace, context } = _loadOtelApi();
1530
2134
  try {
1531
- const t = n.getSpanContext(e.active());
1532
- if (t?.traceId)
1533
- return t.traceId;
1534
- const r = n.getSpan(e.active());
1535
- if (r) {
1536
- const o = r.spanContext();
1537
- if (o.traceId)
1538
- 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
+ }
1539
2145
  }
1540
- } catch (t) {
2146
+ } catch (error) {
1541
2147
  throw new Error(
1542
- `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"}`
1543
2149
  );
1544
2150
  }
1545
2151
  throw new Error(
@@ -1547,11 +2153,12 @@ function bt() {
1547
2153
  );
1548
2154
  }
1549
2155
  export {
1550
- se as KeletContext,
1551
- ht as KeletProvider,
1552
- mt as VoteFeedback,
1553
- bt as getOtelTraceId,
1554
- ke as useDefaultFeedbackHandler,
1555
- vt as useFeedbackState,
1556
- pt as useKelet
2156
+ KeletContext,
2157
+ KeletProvider,
2158
+ VoteFeedback,
2159
+ getOtelTraceId,
2160
+ useDefaultFeedbackHandler,
2161
+ useFeedbackState,
2162
+ useKelet
1557
2163
  };
2164
+ //# sourceMappingURL=feedback-ui.es.js.map