@markupai/sidebar-adapter 1.3.3 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,41 +1,55 @@
1
- var ne = /* @__PURE__ */ (function(e) {
1
+ var oe = /* @__PURE__ */ (function(e) {
2
2
  return e.TEXT_PLAIN = "text/plain", e.TEXT_MARKDOWN = "text/markdown", e.TEXT_HTML = "text/html", e.APPLICATION_DITA_XML = "application/dita+xml", e;
3
- })({}), ae = [
3
+ })({}), se = [
4
4
  "text/plain",
5
5
  "text/markdown",
6
6
  "text/html",
7
7
  "application/dita+xml"
8
- ], oe = {
8
+ ], le = {
9
9
  integrationName: "unknown",
10
10
  integrationVersion: "unknown",
11
11
  integrationId: "markupai-sidebar-app",
12
12
  hideBanner: !1,
13
13
  dialogClosingScript: void 0,
14
14
  useCheckPreviewDialog: !1,
15
- supportCheckSelection: !0
16
- }, se = (e) => typeof e != "object" || e === null ? !1 : Array.isArray(e.fields), le = (e) => {
15
+ supportCheckSelection: !0,
16
+ multiAgent: !1,
17
+ multiDocument: !1
18
+ }, ce = (e) => typeof e != "object" || e === null ? !1 : Array.isArray(e.fields), de = (e) => {
17
19
  if (typeof e != "object" || e === null) return !1;
18
20
  const t = e;
19
21
  return typeof t.id != "string" || t.id.length === 0 || typeof t.label != "string" ? !1 : t.type === "boolean" ? typeof t.default == "boolean" : t.type === "enum" ? typeof t.default != "string" || !Array.isArray(t.options) || t.options.length === 0 ? !1 : t.options.every((i) => {
20
22
  if (typeof i != "object" || i === null) return !1;
21
- const r = i;
22
- return typeof r.value == "string" && typeof r.label == "string";
23
+ const n = i;
24
+ return typeof n.value == "string" && typeof n.label == "string";
23
25
  }) : !1;
24
- }, T = class O extends Error {
26
+ }, O = class T extends Error {
25
27
  name = "TextLookupError";
26
28
  constructor(t) {
27
- super(t), Object.setPrototypeOf(this, O.prototype);
29
+ super(t), Object.setPrototypeOf(this, T.prototype);
28
30
  }
29
31
  };
30
- function ce(e) {
31
- return e instanceof T;
32
+ function ge(e) {
33
+ return e instanceof O;
32
34
  }
33
- var P = { TextLookupError: (e) => new T(e) };
34
- function N(e) {
35
- const t = e.message ?? "", i = e.name, r = typeof i == "string" && i in P ? P[i] : void 0;
36
- return r ? r(t, e) : Object.assign(new Error(t), i ? { name: i } : {});
35
+ var P = { TextLookupError: (e) => new O(e) };
36
+ function U(e) {
37
+ const t = e.message ?? "", i = e.name, n = typeof i == "string" && i in P ? P[i] : void 0;
38
+ return n ? n(t, e) : Object.assign(new Error(t), i ? { name: i } : {});
37
39
  }
38
- var B = class extends Promise {
40
+ var D = ":", x = /^[a-z][a-z0-9-]*$/;
41
+ function pe(e) {
42
+ const t = e.indexOf(D);
43
+ return t <= 0 || t === e.length - 1 ? !1 : x.test(e.slice(0, t));
44
+ }
45
+ function ue(e, t) {
46
+ const i = e.trim().toLowerCase(), n = t.trim();
47
+ if (!x.test(i)) throw new Error(`Invalid document reference prefix ${JSON.stringify(e)}: expected a lowercase name like "word".`);
48
+ if (n.length === 0) throw new Error("Invalid document reference: the document id is empty.");
49
+ const r = `${i}${D}`;
50
+ return n.startsWith(r) ? n : `${r}${n}`;
51
+ }
52
+ var H = class extends Promise {
39
53
  static get [Symbol.species]() {
40
54
  return Promise;
41
55
  }
@@ -44,19 +58,19 @@ var B = class extends Promise {
44
58
  constructor(e = () => {
45
59
  }) {
46
60
  let t, i;
47
- super((r, a) => {
48
- t = r, i = a, e(r, a);
61
+ super((n, r) => {
62
+ t = n, i = r, e(n, r);
49
63
  }), this.resolve = t, this.reject = i;
50
64
  }
51
- }, U = { timeout: 1e4 };
52
- function H(e) {
65
+ }, $ = { timeout: 1e4 };
66
+ function j(e) {
53
67
  const t = JSON.stringify(e, Object.getOwnPropertyNames(e)), i = JSON.parse(t);
54
68
  return i.message === void 0 || i.message === "" ? JSON.stringify({
55
69
  message: e instanceof Error ? e.message : String(e),
56
70
  name: e instanceof Error ? e.name : void 0
57
71
  }) : t;
58
72
  }
59
- var D = class {
73
+ var L = class {
60
74
  promisesByID = {};
61
75
  receiversByName = {};
62
76
  currentID = 0;
@@ -64,7 +78,7 @@ var D = class {
64
78
  postMessage;
65
79
  constructor(e, t) {
66
80
  this.postMessage = e, this.config = {
67
- ...U,
81
+ ...$,
68
82
  ...t
69
83
  };
70
84
  }
@@ -78,23 +92,23 @@ var D = class {
78
92
  return this.callWithOptions(e, {}, ...t);
79
93
  }
80
94
  callWithOptions(e, t, ...i) {
81
- const r = this.currentID++, a = new B(), n = t.timeout ?? this.config.timeout, o = setTimeout(() => {
82
- if (r in this.promisesByID) {
83
- const l = /* @__PURE__ */ new Error(`IPC call timeout: "${e}" did not respond within ${String(n)}ms`);
84
- a.reject(l), Reflect.deleteProperty(this.promisesByID, r);
95
+ const n = this.currentID++, r = new H(), a = t.timeout ?? this.config.timeout, o = setTimeout(() => {
96
+ if (n in this.promisesByID) {
97
+ const l = /* @__PURE__ */ new Error(`IPC call timeout: "${e}" did not respond within ${String(a)}ms`);
98
+ r.reject(l), Reflect.deleteProperty(this.promisesByID, n);
85
99
  }
86
- }, n);
87
- this.promisesByID[r] = {
88
- promise: a,
100
+ }, a);
101
+ this.promisesByID[n] = {
102
+ promise: r,
89
103
  timeoutId: o
90
104
  };
91
105
  const s = {
92
106
  type: "call",
93
- id: r,
107
+ id: n,
94
108
  name: e,
95
109
  data: i
96
110
  };
97
- return this.postMessage(s), a;
111
+ return this.postMessage(s), r;
98
112
  }
99
113
  receive(e, t) {
100
114
  this.receiversByName[e] = t;
@@ -117,11 +131,11 @@ var D = class {
117
131
  }
118
132
  }
119
133
  async handleCall(e) {
120
- const { id: t, name: i, data: r } = e;
134
+ const { id: t, name: i, data: n } = e;
121
135
  if (!(i in this.receiversByName)) {
122
- const n = /* @__PURE__ */ new Error(`No receiver registered for: ${i}`), o = JSON.stringify({
123
- message: n.message,
124
- name: n.name
136
+ const a = /* @__PURE__ */ new Error(`No receiver registered for: ${i}`), o = JSON.stringify({
137
+ message: a.message,
138
+ name: a.name
125
139
  });
126
140
  this.postMessage({
127
141
  type: "error",
@@ -131,22 +145,22 @@ var D = class {
131
145
  });
132
146
  return;
133
147
  }
134
- const a = this.receiversByName[i];
148
+ const r = this.receiversByName[i];
135
149
  try {
136
- if (!Array.isArray(r)) throw new TypeError(`IPC: Expected array of arguments but got ${typeof r}`);
137
- const n = await a(...r), o = {
150
+ if (!Array.isArray(n)) throw new TypeError(`IPC: Expected array of arguments but got ${typeof n}`);
151
+ const a = await r(...n), o = {
138
152
  type: "response",
139
153
  id: t,
140
154
  name: i,
141
- data: n
155
+ data: a
142
156
  };
143
157
  this.postMessage(o);
144
- } catch (n) {
158
+ } catch (a) {
145
159
  const o = {
146
160
  type: "error",
147
161
  id: t,
148
162
  name: i,
149
- errorJSON: H(n)
163
+ errorJSON: j(a)
150
164
  };
151
165
  this.postMessage(o);
152
166
  }
@@ -154,20 +168,20 @@ var D = class {
154
168
  handleResponse(e) {
155
169
  const { id: t } = e;
156
170
  if (t in this.promisesByID) {
157
- const { promise: i, timeoutId: r } = this.promisesByID[t];
158
- clearTimeout(r), i.resolve(e.data), Reflect.deleteProperty(this.promisesByID, t);
171
+ const { promise: i, timeoutId: n } = this.promisesByID[t];
172
+ clearTimeout(n), i.resolve(e.data), Reflect.deleteProperty(this.promisesByID, t);
159
173
  }
160
174
  }
161
175
  handleError(e) {
162
176
  const { id: t, errorJSON: i } = e;
163
177
  if (t in this.promisesByID) {
164
- const { promise: r, timeoutId: a } = this.promisesByID[t];
165
- clearTimeout(a);
178
+ const { promise: n, timeoutId: r } = this.promisesByID[t];
179
+ clearTimeout(r);
166
180
  try {
167
- const n = N(JSON.parse(i));
168
- r.reject(n);
181
+ const a = U(JSON.parse(i));
182
+ n.reject(a);
169
183
  } catch {
170
- r.reject(/* @__PURE__ */ new Error("Failed to parse error from IPC"));
184
+ n.reject(/* @__PURE__ */ new Error("Failed to parse error from IPC"));
171
185
  }
172
186
  Reflect.deleteProperty(this.promisesByID, t);
173
187
  }
@@ -177,13 +191,13 @@ var D = class {
177
191
  clearTimeout(t), e.reject(/* @__PURE__ */ new Error("IPC destroyed"));
178
192
  this.promisesByID = {}, this.receiversByName = {};
179
193
  }
180
- }, j = class {
194
+ }, F = class {
181
195
  ipc;
182
196
  sidebar;
183
197
  targetOrigin;
184
198
  constructor(e, t, i = "*") {
185
- this.sidebar = e || {}, this.targetOrigin = i, this.ipc = new D((r) => {
186
- window.parent.postMessage(r, this.targetOrigin);
199
+ this.sidebar = e || {}, this.targetOrigin = i, this.ipc = new L((n) => {
200
+ window.parent.postMessage(n, this.targetOrigin);
187
201
  }, t), window.addEventListener("message", this.handleMessage), this.registerReceivers();
188
202
  }
189
203
  handleMessage = (e) => {
@@ -199,8 +213,8 @@ var D = class {
199
213
  }
200
214
  if (this.sidebar.activateAgenticIssue) {
201
215
  const e = this.sidebar.activateAgenticIssue;
202
- this.ipc.receive("activateAgenticIssue", async (t) => {
203
- await e(t);
216
+ this.ipc.receive("activateAgenticIssue", async (t, i) => {
217
+ await e(t, typeof i == "string" ? i : null);
204
218
  });
205
219
  }
206
220
  if (this.sidebar.invalidateAgenticIssue) {
@@ -231,6 +245,12 @@ var D = class {
231
245
  const e = this.sidebar.getIntegrationSettings;
232
246
  this.ipc.receive("getIntegrationSettings", async () => await e());
233
247
  }
248
+ if (this.sidebar.onActiveDocumentChanged) {
249
+ const e = this.sidebar.onActiveDocumentChanged;
250
+ this.ipc.receive("onActiveDocumentChanged", async (t) => {
251
+ await e(t);
252
+ });
253
+ }
234
254
  }
235
255
  async getInitConfig() {
236
256
  return await this.ipc.call("getInitConfig");
@@ -241,14 +261,14 @@ var D = class {
241
261
  async getSelectedContent(e) {
242
262
  return this.ipc.callWithOptions("getSelectedContent", e ?? {});
243
263
  }
244
- async replaceContent(e, t) {
245
- await this.ipc.call("replaceContent", e, t);
264
+ async replaceContent(e, t, i = null) {
265
+ await this.ipc.call("replaceContent", e, t, i);
246
266
  }
247
- async selectContent(e) {
248
- await this.ipc.call("selectContent", e);
267
+ async selectContent(e, t = null) {
268
+ await this.ipc.call("selectContent", e, t);
249
269
  }
250
- async showDialog(e, t, i, r) {
251
- await this.ipc.call("showDialog", e, t, i, r);
270
+ async showDialog(e, t, i, n) {
271
+ await this.ipc.call("showDialog", e, t, i, n);
252
272
  }
253
273
  async closeDialog() {
254
274
  await this.ipc.call("closeDialog");
@@ -256,11 +276,11 @@ var D = class {
256
276
  async replaceMultipleContents(e) {
257
277
  await this.ipc.call("replaceMultipleContents", e);
258
278
  }
259
- async onAgenticAgentResults(e, t) {
260
- await this.ipc.call("onAgenticAgentResults", e, t);
279
+ async onAgenticAgentResults(e, t, i = null) {
280
+ await this.ipc.call("onAgenticAgentResults", e, t, i);
261
281
  }
262
- async onAgenticStreamComplete() {
263
- await this.ipc.call("onAgenticStreamComplete");
282
+ async onAgenticStreamComplete(e = null) {
283
+ await this.ipc.call("onAgenticStreamComplete", e);
264
284
  }
265
285
  async onAgenticIssueStatusChanged(e, t, i) {
266
286
  await this.ipc.call("onAgenticIssueStatusChanged", e, t, i);
@@ -293,10 +313,10 @@ var D = class {
293
313
  destroy() {
294
314
  window.removeEventListener("message", this.handleMessage), this.ipc.destroy();
295
315
  }
296
- }, de = class {
316
+ }, he = class {
297
317
  ipcAdapter;
298
318
  constructor(e, t, i) {
299
- this.ipcAdapter = new j(e, t, i);
319
+ this.ipcAdapter = new F(e, t, i);
300
320
  }
301
321
  destroy() {
302
322
  this.ipcAdapter.destroy();
@@ -310,14 +330,14 @@ var D = class {
310
330
  async getSelectedContent(e) {
311
331
  return await this.ipcAdapter.getSelectedContent(e);
312
332
  }
313
- async replaceContent(e, t) {
314
- await this.ipcAdapter.replaceContent(e, t);
333
+ async replaceContent(e, t, i = null) {
334
+ await this.ipcAdapter.replaceContent(e, t, i);
315
335
  }
316
- async selectContent(e) {
317
- await this.ipcAdapter.selectContent(e);
336
+ async selectContent(e, t = null) {
337
+ await this.ipcAdapter.selectContent(e, t);
318
338
  }
319
- async showDialog(e, t, i, r) {
320
- await this.ipcAdapter.showDialog(e, t, i, r);
339
+ async showDialog(e, t, i, n) {
340
+ await this.ipcAdapter.showDialog(e, t, i, n);
321
341
  }
322
342
  async closeDialog() {
323
343
  await this.ipcAdapter.closeDialog();
@@ -325,11 +345,11 @@ var D = class {
325
345
  async replaceMultipleContents(e) {
326
346
  await this.ipcAdapter.replaceMultipleContents(e);
327
347
  }
328
- onAgenticAgentResults(e, t) {
329
- return this.ipcAdapter.onAgenticAgentResults(e, t);
348
+ onAgenticAgentResults(e, t, i = null) {
349
+ return this.ipcAdapter.onAgenticAgentResults(e, t, i);
330
350
  }
331
- onAgenticStreamComplete() {
332
- return this.ipcAdapter.onAgenticStreamComplete();
351
+ onAgenticStreamComplete(e = null) {
352
+ return this.ipcAdapter.onAgenticStreamComplete(e);
333
353
  }
334
354
  onAgenticIssueStatusChanged(e, t, i) {
335
355
  return this.ipcAdapter.onAgenticIssueStatusChanged(e, t, i);
@@ -352,47 +372,47 @@ var D = class {
352
372
  getTargetOrigin() {
353
373
  return this.ipcAdapter.getTargetOrigin();
354
374
  }
355
- }, F = class {
375
+ }, z = class {
356
376
  ipc;
357
377
  plugin;
358
378
  iframe;
359
379
  window;
360
380
  targetOrigin;
361
- constructor(e, t, i, r, a = "*") {
362
- this.plugin = e, this.iframe = t, this.window = i ?? window, this.targetOrigin = a, this.ipc = new D((n) => {
363
- this.iframe.contentWindow?.postMessage(n, this.targetOrigin);
364
- }, r), this.window.addEventListener("message", this.handleMessage, !1), this.registerReceivers();
381
+ constructor(e, t, i, n, r = "*") {
382
+ this.plugin = e, this.iframe = t, this.window = i ?? window, this.targetOrigin = r, this.ipc = new L((a) => {
383
+ this.iframe.contentWindow?.postMessage(a, this.targetOrigin);
384
+ }, n), this.window.addEventListener("message", this.handleMessage, !1), this.registerReceivers();
365
385
  }
366
386
  handleMessage = (e) => {
367
387
  const t = this.window.location.origin, i = this.targetOrigin;
368
388
  e.origin !== t && (i !== "*" && e.origin !== i || e.data && typeof e.data == "object" && this.ipc.handleMessage(e.data));
369
389
  };
370
390
  registerReceivers() {
371
- if (this.ipc.receive("getInitConfig", async () => await this.plugin.getInitConfig()), this.ipc.receive("getContent", async () => await this.plugin.getContent()), this.ipc.receive("getSelectedContent", async () => await this.plugin.getSelectedContent()), this.ipc.receive("replaceContent", async (e, t) => {
372
- await this.plugin.replaceContent(e, t);
373
- }), this.ipc.receive("selectContent", async (e) => {
374
- await this.plugin.selectContent(e);
375
- }), this.ipc.receive("showDialog", async (e, t, i, r) => {
391
+ if (this.ipc.receive("getInitConfig", async () => await this.plugin.getInitConfig()), this.ipc.receive("getContent", async () => await this.plugin.getContent()), this.ipc.receive("getSelectedContent", async () => await this.plugin.getSelectedContent()), this.ipc.receive("replaceContent", async (e, t, i) => {
392
+ await this.plugin.replaceContent(e, t, typeof i == "string" ? i : null);
393
+ }), this.ipc.receive("selectContent", async (e, t) => {
394
+ await this.plugin.selectContent(e, typeof t == "string" ? t : null);
395
+ }), this.ipc.receive("showDialog", async (e, t, i, n) => {
376
396
  if (!this.plugin.showDialog) throw new Error("SidebarIPCAdapter: host does not implement showDialog");
377
- await this.plugin.showDialog(e, t, i, r);
397
+ await this.plugin.showDialog(e, t, i, n);
378
398
  }), this.ipc.receive("closeDialog", async () => {
379
399
  if (!this.plugin.closeDialog) throw new Error("SidebarIPCAdapter: host does not implement closeDialog");
380
400
  await this.plugin.closeDialog();
381
401
  }), this.ipc.receive("replaceMultipleContents", async (e) => {
382
402
  await this.plugin.replaceMultipleContents(e);
383
- }), this.ipc.receive("onAgenticAgentResults", async (e, t) => {
403
+ }), this.ipc.receive("onAgenticAgentResults", async (e, t, i) => {
384
404
  if (!Array.isArray(t))
385
405
  return;
386
- const i = this.plugin.onAgenticAgentResults;
387
- i && await i(e, t);
388
- }), this.ipc.receive("onAgenticStreamComplete", async () => {
389
- const e = this.plugin.onAgenticStreamComplete;
390
- e && await e();
406
+ const n = this.plugin.onAgenticAgentResults;
407
+ n && await n(e, t, typeof i == "string" ? i : null);
408
+ }), this.ipc.receive("onAgenticStreamComplete", async (e) => {
409
+ const t = this.plugin.onAgenticStreamComplete;
410
+ t && await t(typeof e == "string" ? e : null);
391
411
  }), this.ipc.receive("onAgenticIssueStatusChanged", async (e, t, i) => {
392
- const r = this.plugin.onAgenticIssueStatusChanged;
393
- if (r && !(t !== "active" && t !== "resolved" && t !== "dismissed" || i !== "user" && i !== "host"))
412
+ const n = this.plugin.onAgenticIssueStatusChanged;
413
+ if (n && !(t !== "active" && t !== "resolved" && t !== "dismissed" || i !== "user" && i !== "host"))
394
414
  try {
395
- await r(e, t, i);
415
+ await n(e, t, i);
396
416
  } catch {
397
417
  }
398
418
  }), this.plugin.openAuthUrl) {
@@ -414,8 +434,8 @@ var D = class {
414
434
  });
415
435
  }
416
436
  }
417
- async activateAgenticIssue(e) {
418
- await this.ipc.call("activateAgenticIssue", e);
437
+ async activateAgenticIssue(e, t = null) {
438
+ await this.ipc.call("activateAgenticIssue", e, t);
419
439
  }
420
440
  async invalidateAgenticIssue(e) {
421
441
  await this.ipc.call("invalidateAgenticIssue", e);
@@ -435,16 +455,19 @@ var D = class {
435
455
  async getIntegrationSettings() {
436
456
  return await this.ipc.call("getIntegrationSettings");
437
457
  }
458
+ async notifyActiveDocumentChanged(e) {
459
+ await this.ipc.call("onActiveDocumentChanged", e);
460
+ }
438
461
  configure(e) {
439
462
  this.ipc.configure(e);
440
463
  }
441
464
  destroy() {
442
465
  this.window.removeEventListener("message", this.handleMessage), this.ipc.destroy();
443
466
  }
444
- }, $ = class {
467
+ }, W = class {
445
468
  ipcAdapter;
446
469
  constructor(e, t, i) {
447
- this.ipcAdapter = new F(e, t, i?.win, i?.config, i?.targetOrigin);
470
+ this.ipcAdapter = new z(e, t, i?.win, i?.config, i?.targetOrigin);
448
471
  }
449
472
  destroy() {
450
473
  this.ipcAdapter.destroy();
@@ -452,8 +475,8 @@ var D = class {
452
475
  async notifyPluginStatus(e, t) {
453
476
  await this.ipcAdapter.notifyPluginStatus(e, t);
454
477
  }
455
- async activateAgenticIssue(e) {
456
- await this.ipcAdapter.activateAgenticIssue(e);
478
+ async activateAgenticIssue(e, t = null) {
479
+ await this.ipcAdapter.activateAgenticIssue(e, t);
457
480
  }
458
481
  async invalidateAgenticIssue(e) {
459
482
  await this.ipcAdapter.invalidateAgenticIssue(e);
@@ -470,10 +493,13 @@ var D = class {
470
493
  async getIntegrationSettings() {
471
494
  return await this.ipcAdapter.getIntegrationSettings();
472
495
  }
496
+ async notifyActiveDocumentChanged(e) {
497
+ await this.ipcAdapter.notifyActiveDocumentChanged(e);
498
+ }
473
499
  configure(e) {
474
500
  this.ipcAdapter.configure(e);
475
501
  }
476
- }, W = `
502
+ }, G = `
477
503
  <div class="sidebar-load-overlay-card">
478
504
  <div class="sidebar-load-overlay-title">Sidebar failed to load</div>
479
505
  <div class="sidebar-load-overlay-description">Check your connection or try again.</div>
@@ -494,16 +520,16 @@ var D = class {
494
520
  <span>Retry</span>
495
521
  </button>
496
522
  </div>
497
- `, z = () => {
523
+ `, J = () => {
498
524
  const e = document.createElement("div");
499
- e.className = "sidebar-load-overlay", e.style.display = "none", e.innerHTML = W;
525
+ e.className = "sidebar-load-overlay", e.style.display = "none", e.innerHTML = G;
500
526
  const t = e.querySelector(".sidebar-load-overlay-button");
501
527
  if (!t) throw new Error("Missing retry button in load overlay template.");
502
528
  return {
503
529
  overlay: e,
504
530
  button: t
505
531
  };
506
- }, E = "markupai-sidebar-load-overlay-styles", G = `
532
+ }, E = "markupai-sidebar-load-overlay-styles", Y = `
507
533
  :root {
508
534
  --background: #f5f5f4;
509
535
  --foreground: #333332;
@@ -595,37 +621,37 @@ var D = class {
595
621
  box-shadow: 0 0 0 2px
596
622
  color-mix(in srgb, var(--accent, #ef4640) 60%, transparent);
597
623
  }
598
- `, J = (e) => {
624
+ `, V = (e) => {
599
625
  const t = e ?? document;
600
626
  if (t.getElementById(E)) return;
601
627
  const i = t.createElement("style");
602
- i.id = E, i.textContent = G, t.head.appendChild(i);
603
- }, Y = 8e3, V = 12e3, K = (e, t, i = {}) => {
604
- J(e.ownerDocument);
605
- const { sidebarUrl: r, targetOrigin: a, timeoutMs: n = Y, retryIntervalMs: o = V, messageListenWindow: s } = i, l = s ?? (typeof globalThis.window < "u" ? globalThis.window : globalThis), p = () => r ?? t.src, _ = () => {
606
- if (a) return a;
628
+ i.id = E, i.textContent = Y, t.head.appendChild(i);
629
+ }, X = 8e3, K = 12e3, q = (e, t, i = {}) => {
630
+ V(e.ownerDocument);
631
+ const { sidebarUrl: n, targetOrigin: r, timeoutMs: a = X, retryIntervalMs: o = K, messageListenWindow: s } = i, l = s ?? (typeof globalThis.window < "u" ? globalThis.window : globalThis), p = () => n ?? t.src, N = () => {
632
+ if (r) return r;
607
633
  try {
608
634
  return new URL(p()).origin;
609
635
  } catch {
610
636
  return "*";
611
637
  }
612
- }, { overlay: m, button: I } = z();
613
- e.appendChild(m);
638
+ }, { overlay: y, button: v } = J();
639
+ e.appendChild(y);
614
640
  let u = !1, h, d;
615
641
  const g = (c) => {
616
- m.style.display = c ? "flex" : "none";
642
+ y.style.display = c ? "flex" : "none";
617
643
  };
618
644
  g(!1);
619
645
  const f = () => {
620
646
  h && (globalThis.clearTimeout(h), h = void 0);
621
- }, v = () => {
647
+ }, I = () => {
622
648
  f(), h = globalThis.setTimeout(() => {
623
649
  u || g(!0);
624
- }, n);
650
+ }, a);
625
651
  }, A = (c) => {
626
- const y = c?.preserveOverlay ?? !0;
627
- u = !1, y || g(!1), t.src = p(), v();
628
- }, k = () => {
652
+ const m = c?.preserveOverlay ?? !0;
653
+ u = !1, m || g(!1), t.src = p(), I();
654
+ }, B = () => {
629
655
  d || o <= 0 || (d = globalThis.setInterval(() => {
630
656
  u || A({ preserveOverlay: !0 });
631
657
  }, o));
@@ -633,48 +659,48 @@ var D = class {
633
659
  d && (globalThis.clearInterval(d), d = void 0);
634
660
  }, b = (c) => {
635
661
  if (!t.contentWindow || c.source !== t.contentWindow) return;
636
- const y = _();
637
- y !== "*" && c.origin !== y || (u = !0, f(), C(), g(!1));
662
+ const m = N();
663
+ m !== "*" && c.origin !== m || (u = !0, f(), C(), g(!1));
638
664
  }, w = () => {
639
665
  f(), g(!0);
640
666
  }, S = () => {
641
667
  A();
642
668
  };
643
- return I.addEventListener("click", S), t.addEventListener("error", w), l.addEventListener("message", b), v(), k(), () => {
644
- f(), C(), t.removeEventListener("error", w), l.removeEventListener("message", b), I.removeEventListener("click", S), m.remove();
669
+ return v.addEventListener("click", S), t.addEventListener("error", w), l.addEventListener("message", b), I(), B(), () => {
670
+ f(), C(), t.removeEventListener("error", w), l.removeEventListener("message", b), v.removeEventListener("click", S), y.remove();
645
671
  };
646
- }, X = "Markup AI Sidebar", q = "clipboard-read; clipboard-write", ge = "markupai.sidebarNextGen.overrideUrl", pe = "https://sidebar.markup.ai/";
647
- function ue(e) {
672
+ }, Z = "Markup AI Sidebar", Q = "clipboard-read; clipboard-write", fe = "markupai.sidebarNextGen.overrideUrl", me = "https://sidebar.markup.ai/";
673
+ function ye(e) {
648
674
  try {
649
675
  return "localStorage" in globalThis && globalThis.localStorage.getItem("markupai.sidebarNextGen.overrideUrl")?.trim() || e;
650
676
  } catch {
651
677
  return e;
652
678
  }
653
679
  }
654
- var Z = "markupai.sidebarNextGen.authOverride";
655
- function he(e, t) {
680
+ var ee = "markupai.sidebarNextGen.authOverride";
681
+ function ve(e, t) {
656
682
  if (!t) return e;
657
683
  try {
658
684
  if (!("localStorage" in globalThis)) return e;
659
- const i = globalThis.localStorage.getItem(Z)?.trim();
685
+ const i = globalThis.localStorage.getItem(ee)?.trim();
660
686
  if (!i) return e;
661
- const r = JSON.parse(i);
662
- return r !== null && typeof r == "object" && "type" in r && (r.type === "mediation" || r.type === "popup") ? r : e;
687
+ const n = JSON.parse(i);
688
+ return n !== null && typeof n == "object" && "type" in n && (n.type === "mediation" || n.type === "popup") ? n : e;
663
689
  } catch {
664
690
  return e;
665
691
  }
666
692
  }
667
- function fe(e, t) {
693
+ function Ie(e, t) {
668
694
  try {
669
695
  return new URL(e).origin;
670
696
  } catch (i) {
671
697
  return t?.onInvalidUrl?.(e, i), "*";
672
698
  }
673
699
  }
674
- function ye(e, t = "Expected SidebarAdapter from createSidebarHost") {
700
+ function Ae(e, t = "Expected SidebarAdapter from createSidebarHost") {
675
701
  if (e.adapter === null) throw new Error(t);
676
702
  }
677
- function Q(e) {
703
+ function te(e) {
678
704
  const { iframe: t, iframeMount: i } = e;
679
705
  if (t !== void 0 && i !== void 0) throw new Error("createSidebarHost: pass only one of `iframe` or `iframeMount`");
680
706
  if (t !== void 0) return {
@@ -682,20 +708,20 @@ function Q(e) {
682
708
  removeMountedIframe: null
683
709
  };
684
710
  if (i === void 0) throw new Error("createSidebarHost: pass either `iframe` or `iframeMount`");
685
- const { container: r, src: a, allow: n = q } = i, o = document.createElement("iframe");
686
- return o.title = X, o.src = a, n && o.setAttribute("allow", n), r.appendChild(o), {
711
+ const { container: n, src: r, allow: a = Q } = i, o = document.createElement("iframe");
712
+ return o.title = Z, o.src = r, a && o.setAttribute("allow", a), n.appendChild(o), {
687
713
  iframe: o,
688
714
  removeMountedIframe: () => {
689
715
  o.remove();
690
716
  }
691
717
  };
692
718
  }
693
- function me(e) {
694
- const { plugin: t, loadOverlayContainer: i, loadOverlayOptions: r, adapterOptions: a } = e, { iframe: n, removeMountedIframe: o } = Q(e), s = i !== void 0 ? K(i, n, r ?? {}) : null;
719
+ function Ce(e) {
720
+ const { plugin: t, loadOverlayContainer: i, loadOverlayOptions: n, adapterOptions: r } = e, { iframe: a, removeMountedIframe: o } = te(e), s = i !== void 0 ? q(i, a, n ?? {}) : null;
695
721
  if (t !== void 0) {
696
- const l = new $(t, n, a);
722
+ const l = new W(t, a, r);
697
723
  return {
698
- iframe: n,
724
+ iframe: a,
699
725
  adapter: l,
700
726
  destroy: () => {
701
727
  s?.(), l.destroy(), o?.();
@@ -703,21 +729,21 @@ function me(e) {
703
729
  };
704
730
  }
705
731
  return {
706
- iframe: n,
732
+ iframe: a,
707
733
  adapter: null,
708
734
  destroy: () => {
709
735
  s?.(), o?.();
710
736
  }
711
737
  };
712
738
  }
713
- var x = "sidebarContainer", R = "markupai-sidebar-host-shell-styles";
714
- function L(e) {
739
+ var M = "sidebarContainer", R = "markupai-sidebar-host-shell-styles";
740
+ function _(e) {
715
741
  if (typeof CSS < "u" && typeof CSS.escape == "function") return CSS.escape(e);
716
- if (!/^[a-zA-Z_][\w-]*$/.test(e)) throw new Error(`sidebar host shell: containerId must match /^[a-zA-Z_][\\w-]*$/ when CSS.escape is unavailable (got ${JSON.stringify(e)})`);
742
+ if (!/^[a-zA-Z_][\w-]*$/.test(e)) throw new Error(String.raw`sidebar host shell: containerId must match /^[a-zA-Z_][\w-]*$/ when CSS.escape is unavailable (got ${JSON.stringify(e)})`);
717
743
  return e;
718
744
  }
719
- function M(e = x) {
720
- const t = L(e);
745
+ function k(e = M) {
746
+ const t = _(e);
721
747
  return `
722
748
  html {
723
749
  height: 100%;
@@ -742,84 +768,86 @@ body {
742
768
  }
743
769
  `.trim();
744
770
  }
745
- var Ie = M();
746
- function ee(e) {
771
+ var be = k();
772
+ function ie(e) {
747
773
  return e instanceof Document ? e : e.ownerDocument;
748
774
  }
749
- function te(e, t, i) {
775
+ function ne(e, t, i) {
750
776
  if (!t || e.getElementById(R)) return;
751
- const r = e.createElement("style");
752
- r.id = R, r.textContent = M(i), e.head.appendChild(r);
777
+ const n = e.createElement("style");
778
+ n.id = R, n.textContent = k(i), e.head.appendChild(n);
753
779
  }
754
- function ve(e) {
755
- const { root: t = typeof document < "u" ? document : void 0, containerId: i = x, includeDefaultStyles: r = !0 } = e ?? {};
780
+ function we(e) {
781
+ const { root: t = typeof document < "u" ? document : void 0, containerId: i = M, includeDefaultStyles: n = !0 } = e ?? {};
756
782
  if (t === void 0) throw new Error("ensureSidebarHostShell: no document — pass `root` in non-browser environments");
757
- const a = ee(t);
758
- te(a, r, i);
759
- const n = t instanceof Document ? a.getElementById(i) : t.querySelector(`#${L(i)}`);
760
- if (n instanceof HTMLElement && (t instanceof Document || t.contains(n))) return n;
783
+ const r = ie(t);
784
+ ne(r, n, i);
785
+ const a = t instanceof Document ? r.getElementById(i) : t.querySelector(`#${_(i)}`);
786
+ if (a instanceof HTMLElement && (t instanceof Document || t.contains(a))) return a;
761
787
  if (!(t instanceof Document)) {
762
- const s = a.createElement("div");
788
+ const s = r.createElement("div");
763
789
  return s.id = i, t.appendChild(s), s;
764
790
  }
765
- const o = a.createElement("div");
766
- return o.id = i, a.body.appendChild(o), o;
791
+ const o = r.createElement("div");
792
+ return o.id = i, r.body.appendChild(o), o;
767
793
  }
768
- function ie() {
794
+ function re() {
769
795
  return ' <meta name="viewport" content="width=device-width, initial-scale=1.0" />';
770
796
  }
771
- function Ae(e) {
772
- const { title: t = "Markup AI Sidebar", headInnerHtml: i = "", includePluginHostHead: r = !1, bodyScriptsHtml: a, htmlLang: n = "en", htmlAttrs: o = `lang="${n}" style="height:100%"`, bodyAttrs: s = 'style="height:100%;margin:0"' } = e, l = [r ? ie() : "", i].filter((p) => p.trim().length > 0).join(`
797
+ function Se(e) {
798
+ const { title: t = "Markup AI Sidebar", headInnerHtml: i = "", includePluginHostHead: n = !1, bodyScriptsHtml: r, htmlLang: a = "en", htmlAttrs: o = `lang="${a}" style="height:100%"`, bodyAttrs: s = 'style="height:100%;margin:0"' } = e, l = [n ? re() : "", i].filter((p) => p.trim().length > 0).join(`
773
799
  `);
774
800
  return `<!DOCTYPE html>
775
801
  <html ${o}>
776
802
  <head>
777
803
  <base target="_top" />
778
804
  <meta charset="UTF-8" />
779
- <title>${re(t)}</title>${l ? `
805
+ <title>${ae(t)}</title>${l ? `
780
806
  ${l}` : ""}
781
807
  </head>
782
808
  <body ${s}>
783
- ${a}
809
+ ${r}
784
810
  </body>
785
811
  </html>
786
812
  `;
787
813
  }
788
- function re(e) {
814
+ function ae(e) {
789
815
  return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
790
816
  }
791
817
  export {
792
- Z as AUTH_CONFIG_OVERRIDE_STORAGE_KEY,
793
- U as DEFAULT_IPC_CONFIG,
794
- oe as DEFAULT_SIDEBAR_CONFIG,
795
- B as DeferredPromise,
796
- D as IPCCore,
797
- ne as MimeType,
798
- de as PluginAdapter,
799
- j as PluginIPCAdapter,
800
- pe as SIDEBAR_DEFAULT_PRODUCTION_BASE_URL,
801
- x as SIDEBAR_HOST_CONTAINER_ID,
802
- Ie as SIDEBAR_HOST_SHELL_CSS,
803
- q as SIDEBAR_IFRAME_DEFAULT_ALLOW,
804
- X as SIDEBAR_IFRAME_DEFAULT_TITLE,
805
- ge as SIDEBAR_URL_OVERRIDE_STORAGE_KEY,
806
- $ as SidebarAdapter,
807
- F as SidebarIPCAdapter,
808
- ae as TEXT_MIME_TYPES,
809
- T as TextLookupError,
810
- ye as assertSidebarHostAdapter,
811
- Ae as buildSidebarHostHtmlDocument,
812
- M as buildSidebarHostShellCss,
813
- ie as buildSidebarPluginHostHeadInnerHtml,
814
- me as createSidebarHost,
815
- ve as ensureSidebarHostShell,
816
- he as getAuthConfigWithOverride,
817
- ue as getSidebarBaseUrlWithOverride,
818
+ ee as AUTH_CONFIG_OVERRIDE_STORAGE_KEY,
819
+ $ as DEFAULT_IPC_CONFIG,
820
+ le as DEFAULT_SIDEBAR_CONFIG,
821
+ H as DeferredPromise,
822
+ L as IPCCore,
823
+ oe as MimeType,
824
+ he as PluginAdapter,
825
+ F as PluginIPCAdapter,
826
+ me as SIDEBAR_DEFAULT_PRODUCTION_BASE_URL,
827
+ M as SIDEBAR_HOST_CONTAINER_ID,
828
+ be as SIDEBAR_HOST_SHELL_CSS,
829
+ Q as SIDEBAR_IFRAME_DEFAULT_ALLOW,
830
+ Z as SIDEBAR_IFRAME_DEFAULT_TITLE,
831
+ fe as SIDEBAR_URL_OVERRIDE_STORAGE_KEY,
832
+ W as SidebarAdapter,
833
+ z as SidebarIPCAdapter,
834
+ se as TEXT_MIME_TYPES,
835
+ O as TextLookupError,
836
+ Ae as assertSidebarHostAdapter,
837
+ ue as buildDocumentReference,
838
+ Se as buildSidebarHostHtmlDocument,
839
+ k as buildSidebarHostShellCss,
840
+ re as buildSidebarPluginHostHeadInnerHtml,
841
+ Ce as createSidebarHost,
842
+ we as ensureSidebarHostShell,
843
+ ve as getAuthConfigWithOverride,
844
+ ye as getSidebarBaseUrlWithOverride,
818
845
  P as ipcErrorReconstructors,
819
- le as isIntegrationSettingField,
820
- se as isIntegrationSettingsSchema,
821
- ce as isTextLookupError,
822
- N as reconstructError,
823
- K as setupSidebarLoadOverlay,
824
- fe as sidebarPostMessageTargetOrigin
846
+ pe as isDocumentReference,
847
+ de as isIntegrationSettingField,
848
+ ce as isIntegrationSettingsSchema,
849
+ ge as isTextLookupError,
850
+ U as reconstructError,
851
+ q as setupSidebarLoadOverlay,
852
+ Ie as sidebarPostMessageTargetOrigin
825
853
  };