@markupai/sidebar-adapter 0.0.23

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 ADDED
@@ -0,0 +1,937 @@
1
+ var k = /* @__PURE__ */ ((r) => (r.TEXT_PLAIN = "text/plain", r.TEXT_MARKDOWN = "text/markdown", r.TEXT_HTML = "text/html", r.APPLICATION_DITA_XML = "application/dita+xml", r))(k || {});
2
+ const re = [
3
+ "text/plain",
4
+ "text/markdown",
5
+ "text/html",
6
+ "application/dita+xml"
7
+ /* APPLICATION_DITA_XML */
8
+ ], ie = {
9
+ integrationName: "unknown",
10
+ integrationVersion: "unknown",
11
+ integrationId: "markupai-sidebar-app",
12
+ hideBanner: !1,
13
+ dialogClosingScript: void 0,
14
+ useCheckPreviewDialog: !1,
15
+ supportCheckSelection: !0
16
+ };
17
+ class v extends Error {
18
+ name = "TextLookupError";
19
+ constructor(e) {
20
+ super(e), Object.setPrototypeOf(this, v.prototype);
21
+ }
22
+ }
23
+ function ne(r) {
24
+ return r instanceof v;
25
+ }
26
+ const C = {
27
+ TextLookupError: (r) => new v(r)
28
+ };
29
+ function B(r) {
30
+ const e = r.message ?? "", t = r.name, i = typeof t == "string" && t in C ? C[t] : void 0;
31
+ return i ? i(e, r) : Object.assign(new Error(e), t ? { name: t } : {});
32
+ }
33
+ const O = () => {
34
+ };
35
+ class P {
36
+ _promise;
37
+ [Symbol.toStringTag] = "Promise";
38
+ /**
39
+ * Resolves the underlying promise with a specified value.
40
+ *
41
+ * @param value - The value to resolve the promise with.
42
+ */
43
+ resolve = O;
44
+ /**
45
+ * Rejects the underlying promise with a specified reason.
46
+ *
47
+ * @param reason - The reason for rejecting the promise.
48
+ */
49
+ reject = O;
50
+ /**
51
+ * Creates a new instance of DeferredPromise.
52
+ */
53
+ constructor() {
54
+ this._promise = new Promise((e, t) => {
55
+ this.resolve = e, this.reject = t;
56
+ });
57
+ }
58
+ /**
59
+ * Attaches callbacks for the resolution and/or rejection of the promise.
60
+ *
61
+ * @param onFulfilled - The callback to execute when the promise is resolved.
62
+ * @param onRejected - The callback to execute when the promise is rejected.
63
+ * @returns - A new promise resolved or rejected by the onFulfilled or
64
+ * onRejected callback.
65
+ */
66
+ then(e, t) {
67
+ return this._promise.then(e, t);
68
+ }
69
+ /**
70
+ * Attaches a callback for the rejection of the promise.
71
+ *
72
+ * @param onRejected - The callback to execute when the promise is rejected.
73
+ * @returns - A new promise resolved by the onRejected callback.
74
+ */
75
+ catch(e) {
76
+ return this._promise.catch(e);
77
+ }
78
+ /**
79
+ * Attaches a callback that is executed when the promise is settled, whether
80
+ * fulfilled or rejected.
81
+ *
82
+ * @param onFinally - The callback to execute when the promise is settled.
83
+ * @returns - A new promise resolved by the onFinally callback.
84
+ */
85
+ finally(e) {
86
+ return this._promise.finally(e);
87
+ }
88
+ }
89
+ const N = {
90
+ timeout: 1e4
91
+ };
92
+ class D {
93
+ promisesByID = {};
94
+ receiversByName = {};
95
+ currentID = 0;
96
+ config;
97
+ postMessage;
98
+ constructor(e, t) {
99
+ this.postMessage = e, this.config = { ...N, ...t };
100
+ }
101
+ /**
102
+ * Update IPC configuration
103
+ */
104
+ configure(e) {
105
+ this.config = { ...this.config, ...e };
106
+ }
107
+ /**
108
+ * Makes a call to the other side. Returns a promise that resolves when
109
+ * the other side responds.
110
+ *
111
+ * @param name - The name of the receiver on the other side
112
+ * @param data - Parameters to send to the receiver
113
+ * @returns Promise that resolves with the receiver's response
114
+ */
115
+ call(e, ...t) {
116
+ return this.callWithOptions(e, {}, ...t);
117
+ }
118
+ /**
119
+ * Makes a call with per-call overrides (e.g. timeout).
120
+ *
121
+ * @param name - The name of the receiver on the other side
122
+ * @param options - Per-call overrides (e.g. timeout in ms)
123
+ * @param data - Parameters to send to the receiver
124
+ * @returns Promise that resolves with the receiver's response
125
+ */
126
+ callWithOptions(e, t, ...i) {
127
+ const n = this.currentID++, s = new P(), o = t.timeout ?? this.config.timeout, a = setTimeout(() => {
128
+ if (n in this.promisesByID) {
129
+ const l = new Error(
130
+ `IPC call timeout: "${e}" did not respond within ${String(o)}ms`
131
+ );
132
+ s.reject(l), Reflect.deleteProperty(this.promisesByID, n);
133
+ }
134
+ }, o);
135
+ this.promisesByID[n] = { promise: s, timeoutId: a };
136
+ const c = {
137
+ type: "call",
138
+ id: n,
139
+ name: e,
140
+ data: i
141
+ };
142
+ return this.postMessage(c), s;
143
+ }
144
+ /**
145
+ * Registers a function to receive calls with a particular name.
146
+ * The return value will be sent back to the caller.
147
+ *
148
+ * @param name - The name of the receiver
149
+ * @param fn - The function that will receive calls
150
+ */
151
+ receive(e, t) {
152
+ this.receiversByName[e] = t;
153
+ }
154
+ /**
155
+ * Unregisters a receiver for a given call name
156
+ *
157
+ * @param name - The name of the receiver to unregister
158
+ */
159
+ ignore(e) {
160
+ delete this.receiversByName[e];
161
+ }
162
+ /**
163
+ * Handles incoming messages from the other side
164
+ * @param message - The IPC message to handle
165
+ */
166
+ async handleMessage(e) {
167
+ switch (e.type) {
168
+ case "call":
169
+ await this.handleCall(e);
170
+ break;
171
+ case "response":
172
+ this.handleResponse(e);
173
+ break;
174
+ case "error":
175
+ this.handleError(e);
176
+ break;
177
+ }
178
+ }
179
+ /**
180
+ * Handles incoming call messages
181
+ */
182
+ async handleCall(e) {
183
+ const { id: t, name: i, data: n } = e;
184
+ if (i in this.receiversByName) {
185
+ const s = this.receiversByName[i];
186
+ try {
187
+ if (!Array.isArray(n))
188
+ throw new Error(`IPC: Expected array of arguments but got ${typeof n}`);
189
+ const o = await s(...n), a = {
190
+ type: "response",
191
+ id: t,
192
+ name: i,
193
+ data: o
194
+ };
195
+ this.postMessage(a);
196
+ } catch (o) {
197
+ let a = JSON.stringify(o, Object.getOwnPropertyNames(o));
198
+ const c = JSON.parse(a);
199
+ (c.message === void 0 || c.message === "") && (a = JSON.stringify({
200
+ message: o instanceof Error ? o.message : String(o),
201
+ name: o instanceof Error ? o.name : void 0
202
+ }));
203
+ const l = {
204
+ type: "error",
205
+ id: t,
206
+ name: i,
207
+ errorJSON: a
208
+ };
209
+ this.postMessage(l);
210
+ }
211
+ } else {
212
+ const s = new Error(`No receiver registered for: ${i}`), o = JSON.stringify({
213
+ message: s.message,
214
+ name: s.name
215
+ }), a = {
216
+ type: "error",
217
+ id: t,
218
+ name: i,
219
+ errorJSON: o
220
+ };
221
+ this.postMessage(a);
222
+ }
223
+ }
224
+ /**
225
+ * Handles incoming response messages
226
+ */
227
+ handleResponse(e) {
228
+ const { id: t } = e;
229
+ if (t in this.promisesByID) {
230
+ const { promise: i, timeoutId: n } = this.promisesByID[t];
231
+ clearTimeout(n), i.resolve(e.data), Reflect.deleteProperty(this.promisesByID, t);
232
+ }
233
+ }
234
+ /**
235
+ * Handles incoming error messages
236
+ */
237
+ handleError(e) {
238
+ const { id: t, errorJSON: i } = e;
239
+ if (t in this.promisesByID) {
240
+ const { promise: n, timeoutId: s } = this.promisesByID[t];
241
+ clearTimeout(s);
242
+ try {
243
+ const o = JSON.parse(i), a = B(o);
244
+ n.reject(a);
245
+ } catch {
246
+ n.reject(new Error("Failed to parse error from IPC"));
247
+ }
248
+ Reflect.deleteProperty(this.promisesByID, t);
249
+ }
250
+ }
251
+ /**
252
+ * Cleanup all pending promises and receivers
253
+ */
254
+ destroy() {
255
+ for (const { promise: e, timeoutId: t } of Object.values(this.promisesByID))
256
+ clearTimeout(t), e.reject(new Error("IPC destroyed"));
257
+ this.promisesByID = {}, this.receiversByName = {};
258
+ }
259
+ }
260
+ class H {
261
+ ipc;
262
+ sidebar;
263
+ targetOrigin;
264
+ constructor(e, t, i = "*") {
265
+ this.sidebar = e || {}, this.targetOrigin = i, this.ipc = new D((n) => {
266
+ window.parent.postMessage(n, this.targetOrigin);
267
+ }, t), window.addEventListener("message", this.handleMessage), this.registerReceivers();
268
+ }
269
+ handleMessage = (e) => {
270
+ const t = globalThis.window.location.origin, i = this.targetOrigin;
271
+ e.origin !== t && (i !== "*" && e.origin !== i || e.data && typeof e.data == "object" && this.ipc.handleMessage(e.data));
272
+ };
273
+ registerReceivers() {
274
+ if (this.sidebar.onPluginStatusChange) {
275
+ const e = this.sidebar.onPluginStatusChange;
276
+ this.ipc.receive("onPluginStatusChange", async (t) => {
277
+ await e(t);
278
+ });
279
+ }
280
+ if (this.sidebar.activateAgenticIssue) {
281
+ const e = this.sidebar.activateAgenticIssue;
282
+ this.ipc.receive("activateAgenticIssue", async (t) => {
283
+ await e(t);
284
+ });
285
+ }
286
+ }
287
+ // ============================================
288
+ // Methods to call plugin functions
289
+ // ============================================
290
+ /**
291
+ * Request initialization configuration from the editor
292
+ */
293
+ async getInitConfig() {
294
+ return await this.ipc.call("getInitConfig");
295
+ }
296
+ /**
297
+ * Request content from the editor in whatever format the integration supports
298
+ * @param options - Optional per-call overrides (e.g. timeout in ms; overrides default IPC timeout)
299
+ */
300
+ async getContent(e) {
301
+ return this.ipc.callWithOptions("getContent", e ?? {});
302
+ }
303
+ /**
304
+ * Request selected content from the editor in whatever format the integration supports
305
+ * @param options - Optional per-call overrides (e.g. timeout in ms; overrides default IPC timeout)
306
+ */
307
+ async getSelectedContent(e) {
308
+ return this.ipc.callWithOptions("getSelectedContent", e ?? {});
309
+ }
310
+ /**
311
+ * Replace content in the editor
312
+ */
313
+ async replaceContent(e, t, i) {
314
+ await this.ipc.call("replaceContent", e, t, i);
315
+ }
316
+ /**
317
+ * Select content in the editor
318
+ */
319
+ async selectContent(e, t) {
320
+ await this.ipc.call("selectContent", e, t);
321
+ }
322
+ /**
323
+ * Show a dialog in the editor
324
+ */
325
+ async showDialog(e, t, i, n) {
326
+ await this.ipc.call("showDialog", e, t, i, n);
327
+ }
328
+ /**
329
+ * Close the dialog in the editor
330
+ */
331
+ async closeDialog() {
332
+ await this.ipc.call("closeDialog");
333
+ }
334
+ /**
335
+ * Replace multiple contents in the editor
336
+ */
337
+ async replaceMultipleContents(e) {
338
+ await this.ipc.call("replaceMultipleContents", e);
339
+ }
340
+ /**
341
+ * Notify plugin that one agent's results are available (streaming).
342
+ */
343
+ async onAgenticAgentResults(e, t) {
344
+ await this.ipc.call("onAgenticAgentResults", e, t);
345
+ }
346
+ /**
347
+ * Notify plugin that the agentic stream has finished.
348
+ */
349
+ async onAgenticStreamComplete() {
350
+ await this.ipc.call("onAgenticStreamComplete");
351
+ }
352
+ /**
353
+ * Update IPC configuration
354
+ */
355
+ configure(e) {
356
+ this.ipc.configure(e);
357
+ }
358
+ /**
359
+ * Set or update the target origin for postMessage communication
360
+ */
361
+ setTargetOrigin(e) {
362
+ if (!e || typeof e != "string")
363
+ throw new Error("Invalid targetOrigin: must be a non-empty string");
364
+ try {
365
+ const t = new URL(e);
366
+ if (!["http:", "https:"].includes(t.protocol) || !t.host)
367
+ throw new Error(
368
+ "Invalid targetOrigin: protocol must be http or https and must have a host"
369
+ );
370
+ } catch {
371
+ throw new Error("Invalid targetOrigin: must be a valid origin (e.g., https://example.com)");
372
+ }
373
+ this.targetOrigin = e;
374
+ }
375
+ /**
376
+ * Get the current target origin
377
+ */
378
+ getTargetOrigin() {
379
+ return this.targetOrigin;
380
+ }
381
+ /**
382
+ * Cleanup and destroy the adapter
383
+ */
384
+ destroy() {
385
+ window.removeEventListener("message", this.handleMessage), this.ipc.destroy();
386
+ }
387
+ }
388
+ class oe {
389
+ ipcAdapter;
390
+ constructor(e, t, i) {
391
+ this.ipcAdapter = new H(e, t, i);
392
+ }
393
+ /**
394
+ * Cleanup and destroy the adapter
395
+ */
396
+ destroy() {
397
+ this.ipcAdapter.destroy();
398
+ }
399
+ /**
400
+ * Request initialization configuration from the editor
401
+ */
402
+ async getInitConfig() {
403
+ return await this.ipcAdapter.getInitConfig();
404
+ }
405
+ /**
406
+ * Request content from the editor in whatever format the integration supports
407
+ * @param options - Optional per-call overrides (e.g. timeout in ms; overrides default IPC timeout)
408
+ */
409
+ async getContent(e) {
410
+ return await this.ipcAdapter.getContent(e);
411
+ }
412
+ /**
413
+ * Request selected content from the editor in whatever format the integration supports
414
+ * @param options - Optional per-call overrides (e.g. timeout in ms; overrides default IPC timeout)
415
+ */
416
+ async getSelectedContent(e) {
417
+ return await this.ipcAdapter.getSelectedContent(e);
418
+ }
419
+ /**
420
+ * Replace content in the editor
421
+ */
422
+ async replaceContent(e, t, i) {
423
+ await this.ipcAdapter.replaceContent(e, t, i);
424
+ }
425
+ /**
426
+ * Select content in the editor
427
+ */
428
+ async selectContent(e, t) {
429
+ await this.ipcAdapter.selectContent(e, t);
430
+ }
431
+ /**
432
+ * Show a dialog in the editor
433
+ */
434
+ async showDialog(e, t, i, n) {
435
+ await this.ipcAdapter.showDialog(e, t, i, n);
436
+ }
437
+ /**
438
+ * Close the dialog in the editor
439
+ */
440
+ async closeDialog() {
441
+ await this.ipcAdapter.closeDialog();
442
+ }
443
+ /**
444
+ * Replace multiple contents in the editor
445
+ */
446
+ async replaceMultipleContents(e) {
447
+ await this.ipcAdapter.replaceMultipleContents(e);
448
+ }
449
+ /**
450
+ * Notify plugin that one agent's results are available (streaming).
451
+ */
452
+ onAgenticAgentResults(e, t) {
453
+ return this.ipcAdapter.onAgenticAgentResults(e, t);
454
+ }
455
+ /**
456
+ * Notify plugin that the agentic stream has finished.
457
+ */
458
+ onAgenticStreamComplete() {
459
+ return this.ipcAdapter.onAgenticStreamComplete();
460
+ }
461
+ /**
462
+ * Update IPC configuration
463
+ */
464
+ configure(e) {
465
+ this.ipcAdapter.configure(e);
466
+ }
467
+ /**
468
+ * Set or update the target origin for postMessage communication
469
+ */
470
+ setTargetOrigin(e) {
471
+ this.ipcAdapter.setTargetOrigin(e);
472
+ }
473
+ /**
474
+ * Get the current target origin
475
+ */
476
+ getTargetOrigin() {
477
+ return this.ipcAdapter.getTargetOrigin();
478
+ }
479
+ }
480
+ class j {
481
+ ipc;
482
+ plugin;
483
+ iframe;
484
+ window;
485
+ targetOrigin;
486
+ constructor(e, t, i, n, s = "*") {
487
+ this.plugin = e, this.iframe = t, this.window = i ?? window, this.targetOrigin = s, this.ipc = new D((o) => {
488
+ this.iframe.contentWindow?.postMessage(o, this.targetOrigin);
489
+ }, n), this.window.addEventListener("message", this.handleMessage, !1), this.registerReceivers();
490
+ }
491
+ handleMessage = (e) => {
492
+ const t = this.window.location.origin, i = this.targetOrigin;
493
+ e.origin !== t && (i !== "*" && e.origin !== i || e.data && typeof e.data == "object" && this.ipc.handleMessage(e.data));
494
+ };
495
+ registerReceivers() {
496
+ 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) => {
497
+ await this.plugin.replaceContent(e, t, i);
498
+ }), this.ipc.receive("selectContent", async (e, t) => {
499
+ await this.plugin.selectContent(e, t);
500
+ }), this.ipc.receive("showDialog", async (e, t, i, n) => {
501
+ await this.plugin.showDialog(e, t, i, n);
502
+ }), this.ipc.receive("closeDialog", async () => {
503
+ await this.plugin.closeDialog();
504
+ }), this.ipc.receive("replaceMultipleContents", async (e) => {
505
+ await this.plugin.replaceMultipleContents(e);
506
+ }), this.ipc.receive("onAgenticAgentResults", async (e, t) => {
507
+ if (!Array.isArray(t))
508
+ return;
509
+ const i = this.plugin.onAgenticAgentResults;
510
+ i && await i(e, t);
511
+ }), this.ipc.receive("onAgenticStreamComplete", async () => {
512
+ const e = this.plugin.onAgenticStreamComplete;
513
+ e && await e();
514
+ });
515
+ }
516
+ // ============================================
517
+ // Methods to call sidebar functions (Plugin → Sidebar)
518
+ // ============================================
519
+ /**
520
+ * Request sidebar to activate (expand and scroll to) the card for the given issue.
521
+ */
522
+ async activateAgenticIssue(e) {
523
+ await this.ipc.call("activateAgenticIssue", e);
524
+ }
525
+ /**
526
+ * Notify sidebar of plugin status changes
527
+ * Example method demonstrating Plugin → Sidebar communication
528
+ */
529
+ async notifyPluginStatus(e) {
530
+ await this.ipc.call("onPluginStatusChange", e);
531
+ }
532
+ /**
533
+ * Update IPC configuration
534
+ */
535
+ configure(e) {
536
+ this.ipc.configure(e);
537
+ }
538
+ /**
539
+ * Cleanup and destroy the adapter
540
+ */
541
+ destroy() {
542
+ this.window.removeEventListener("message", this.handleMessage), this.ipc.destroy();
543
+ }
544
+ }
545
+ class U {
546
+ ipcAdapter;
547
+ constructor(e, t, i) {
548
+ this.ipcAdapter = new j(
549
+ e,
550
+ t,
551
+ i?.win,
552
+ i?.config,
553
+ i?.targetOrigin
554
+ );
555
+ }
556
+ /**
557
+ * Cleanup and destroy the adapter
558
+ */
559
+ destroy() {
560
+ this.ipcAdapter.destroy();
561
+ }
562
+ /**
563
+ * Notify sidebar of plugin status changes
564
+ * Example method demonstrating Plugin → Sidebar communication
565
+ */
566
+ async notifyPluginStatus(e) {
567
+ await this.ipcAdapter.notifyPluginStatus(e);
568
+ }
569
+ /**
570
+ * Request sidebar to activate (expand and scroll to) the card for the given issue.
571
+ */
572
+ async activateAgenticIssue(e) {
573
+ await this.ipcAdapter.activateAgenticIssue(e);
574
+ }
575
+ /**
576
+ * Update IPC configuration
577
+ */
578
+ configure(e) {
579
+ this.ipcAdapter.configure(e);
580
+ }
581
+ }
582
+ const $ = `
583
+ <div class="sidebar-load-overlay-card">
584
+ <div class="sidebar-load-overlay-title">Sidebar failed to load</div>
585
+ <div class="sidebar-load-overlay-description">Check your connection or try again.</div>
586
+ <button type="button" class="sidebar-load-overlay-button">
587
+ <svg
588
+ class="sidebar-load-overlay-button-icon"
589
+ viewBox="0 0 24 24"
590
+ fill="none"
591
+ stroke="currentColor"
592
+ stroke-width="1.5"
593
+ stroke-linecap="round"
594
+ stroke-linejoin="round"
595
+ aria-hidden="true"
596
+ focusable="false"
597
+ >
598
+ <path d="M20 12a8 8 0 1 1-2.34-5.66M20 4v6h-6" />
599
+ </svg>
600
+ <span>Retry</span>
601
+ </button>
602
+ </div>
603
+ `, F = () => {
604
+ const r = document.createElement("div");
605
+ r.className = "sidebar-load-overlay", r.style.display = "none", r.innerHTML = $;
606
+ const e = r.querySelector(".sidebar-load-overlay-button");
607
+ if (!e)
608
+ throw new Error("Missing retry button in load overlay template.");
609
+ return { overlay: r, button: e };
610
+ }, T = "markupai-sidebar-load-overlay-styles", W = `
611
+ :root {
612
+ --background: #f5f5f4;
613
+ --foreground: #333332;
614
+ --muted-foreground: #78716c;
615
+ --accent: #ef4640;
616
+ --accent-foreground: #fafaf9;
617
+ --border: #d6d3d1;
618
+ --card: #fafaf9;
619
+ --card-foreground: #1c1917;
620
+ --overlay: color-mix(in srgb, var(--background) 90%, transparent);
621
+ --overlay-foreground: var(--foreground);
622
+ }
623
+
624
+ .sidebar-load-overlay {
625
+ position: absolute;
626
+ inset: 0;
627
+ z-index: 10;
628
+ display: flex;
629
+ align-items: center;
630
+ justify-content: center;
631
+ padding: 0 24px;
632
+ text-align: center;
633
+ font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
634
+ sans-serif;
635
+ line-height: 1.4;
636
+ -webkit-font-smoothing: antialiased;
637
+ background: var(--overlay, rgba(245, 245, 244, 0.9));
638
+ color: var(--overlay-foreground, #333332);
639
+ }
640
+
641
+ .sidebar-load-overlay-card {
642
+ display: flex;
643
+ max-width: 260px;
644
+ flex-direction: column;
645
+ gap: 12px;
646
+ border-radius: 12px;
647
+ border: 1px solid var(--border, #d6d3d1);
648
+ background: var(--card, #fafaf9);
649
+ color: var(--card-foreground, #1c1917);
650
+ padding: 20px 16px;
651
+ box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
652
+ }
653
+
654
+ .sidebar-load-overlay-title {
655
+ font-size: 13px;
656
+ font-weight: 600;
657
+ line-height: 1.4;
658
+ }
659
+
660
+ .sidebar-load-overlay-description {
661
+ font-size: 12px;
662
+ line-height: 1.4;
663
+ color: var(--muted-foreground, #78716c);
664
+ }
665
+
666
+ .sidebar-load-overlay-button {
667
+ border-radius: 8px;
668
+ border: 1px solid var(--accent, #ef4640);
669
+ background: var(--accent, #ef4640);
670
+ color: var(--accent-foreground, #fafaf9);
671
+ cursor: pointer;
672
+ padding: 8px 12px;
673
+ font-size: 12px;
674
+ font-weight: 600;
675
+ line-height: 1.2;
676
+ font-family: inherit;
677
+ display: inline-flex;
678
+ align-items: center;
679
+ justify-content: center;
680
+ gap: 6px;
681
+ transition:
682
+ background 0.15s ease,
683
+ border-color 0.15s ease,
684
+ color 0.15s ease;
685
+ }
686
+
687
+ .sidebar-load-overlay-button-icon {
688
+ height: 14px;
689
+ width: 14px;
690
+ }
691
+
692
+ .sidebar-load-overlay-button:hover {
693
+ background: color-mix(in srgb, var(--accent, #ef4640) 85%, #000);
694
+ border-color: color-mix(in srgb, var(--accent, #ef4640) 85%, #000);
695
+ }
696
+
697
+ .sidebar-load-overlay-button:focus-visible {
698
+ outline: none;
699
+ box-shadow: 0 0 0 2px
700
+ color-mix(in srgb, var(--accent, #ef4640) 60%, transparent);
701
+ }
702
+ `, J = () => {
703
+ if (document.getElementById(T)) return;
704
+ const r = document.createElement("style");
705
+ r.id = T, r.textContent = W, document.head.appendChild(r);
706
+ }, z = 8e3, Y = 12e3, X = (r, e, t = {}) => {
707
+ J();
708
+ const {
709
+ sidebarUrl: i,
710
+ targetOrigin: n,
711
+ timeoutMs: s = z,
712
+ retryIntervalMs: o = Y
713
+ } = t, a = () => i ?? e.src, c = () => {
714
+ if (n) return n;
715
+ try {
716
+ return new URL(a()).origin;
717
+ } catch {
718
+ return "*";
719
+ }
720
+ }, { overlay: l, button: u } = F();
721
+ r.appendChild(l);
722
+ let h = !1, f, g;
723
+ const p = (d) => {
724
+ l.style.display = d ? "flex" : "none";
725
+ };
726
+ p(!1);
727
+ const m = () => {
728
+ f && (globalThis.clearTimeout(f), f = void 0);
729
+ }, b = () => {
730
+ m(), f = globalThis.setTimeout(() => {
731
+ h || p(!0);
732
+ }, s);
733
+ }, w = (d) => {
734
+ const y = d?.preserveOverlay ?? !0;
735
+ h = !1, y || p(!1), e.src = a(), b();
736
+ }, R = () => {
737
+ g || o <= 0 || (g = globalThis.setInterval(() => {
738
+ h || w({ preserveOverlay: !0 });
739
+ }, o));
740
+ }, S = () => {
741
+ g && (globalThis.clearInterval(g), g = void 0);
742
+ }, E = (d) => {
743
+ if (!e.contentWindow || d.source !== e.contentWindow) return;
744
+ const y = c();
745
+ y !== "*" && d.origin !== y || (h = !0, m(), S(), p(!1));
746
+ }, A = () => {
747
+ m(), p(!0);
748
+ }, I = () => {
749
+ w();
750
+ };
751
+ return u.addEventListener("click", I), e.addEventListener("error", A), globalThis.addEventListener("message", E), b(), R(), () => {
752
+ m(), S(), e.removeEventListener("error", A), globalThis.removeEventListener("message", E), u.removeEventListener("click", I), l.remove();
753
+ };
754
+ }, G = "Markup AI Sidebar", V = "clipboard-read; clipboard-write", q = "markupai.sidebarNextGen.overrideUrl", se = "https://sidebar.markup.ai/";
755
+ function ae(r) {
756
+ try {
757
+ return typeof globalThis.localStorage > "u" ? r : globalThis.localStorage.getItem(q)?.trim() || r;
758
+ } catch {
759
+ return r;
760
+ }
761
+ }
762
+ function ce(r, e) {
763
+ try {
764
+ return new URL(r).origin;
765
+ } catch (t) {
766
+ return e?.onInvalidUrl?.(r, t), "*";
767
+ }
768
+ }
769
+ function le(r, e = "Expected SidebarAdapter from createSidebarHost") {
770
+ if (r.adapter === null)
771
+ throw new Error(e);
772
+ }
773
+ function K(r) {
774
+ const { iframe: e, iframeMount: t } = r;
775
+ if (e !== void 0 && t !== void 0)
776
+ throw new Error("createSidebarHost: pass only one of `iframe` or `iframeMount`");
777
+ if (e !== void 0)
778
+ return { iframe: e, removeMountedIframe: null };
779
+ if (t === void 0)
780
+ throw new Error("createSidebarHost: pass either `iframe` or `iframeMount`");
781
+ const { container: i, src: n, allow: s = V } = t, o = document.createElement("iframe");
782
+ return o.title = G, o.src = n, s && o.setAttribute("allow", s), i.appendChild(o), {
783
+ iframe: o,
784
+ removeMountedIframe: () => {
785
+ o.remove();
786
+ }
787
+ };
788
+ }
789
+ function de(r) {
790
+ const { plugin: e, loadOverlayContainer: t, loadOverlayOptions: i, adapterOptions: n } = r, { iframe: s, removeMountedIframe: o } = K(r), a = t !== void 0 ? X(t, s, i ?? {}) : null;
791
+ if (e !== void 0) {
792
+ const c = new U(e, s, n);
793
+ return {
794
+ iframe: s,
795
+ adapter: c,
796
+ destroy: () => {
797
+ a?.(), c.destroy(), o?.();
798
+ }
799
+ };
800
+ }
801
+ return {
802
+ iframe: s,
803
+ adapter: null,
804
+ destroy: () => {
805
+ a?.(), o?.();
806
+ }
807
+ };
808
+ }
809
+ const M = "sidebarContainer", x = "markupai-sidebar-host-shell-styles";
810
+ function L(r) {
811
+ if (typeof CSS < "u" && typeof CSS.escape == "function")
812
+ return CSS.escape(r);
813
+ if (!/^[a-zA-Z_][\w-]*$/.test(r))
814
+ throw new Error(
815
+ `sidebar host shell: containerId must match /^[a-zA-Z_][\\w-]*$/ when CSS.escape is unavailable (got ${JSON.stringify(r)})`
816
+ );
817
+ return r;
818
+ }
819
+ function _(r = M) {
820
+ const e = L(r);
821
+ return `
822
+ html {
823
+ height: 100%;
824
+ }
825
+ body {
826
+ height: 100%;
827
+ margin: 0;
828
+ }
829
+ #${e} {
830
+ height: 100%;
831
+ box-sizing: border-box;
832
+ position: relative;
833
+ }
834
+ #${e} iframe {
835
+ width: 100%;
836
+ height: 100%;
837
+ border: 0;
838
+ background: #fff;
839
+ padding: 0;
840
+ margin: 0;
841
+ display: block;
842
+ }
843
+ `.trim();
844
+ }
845
+ const ge = _();
846
+ function Z(r) {
847
+ return r instanceof Document ? r : r.ownerDocument;
848
+ }
849
+ function Q(r, e, t) {
850
+ if (!e || r.getElementById(x)) return;
851
+ const i = r.createElement("style");
852
+ i.id = x, i.textContent = _(t), r.head.appendChild(i);
853
+ }
854
+ function pe(r) {
855
+ const {
856
+ root: e = typeof document < "u" ? document : void 0,
857
+ containerId: t = M,
858
+ includeDefaultStyles: i = !0
859
+ } = r ?? {};
860
+ if (e === void 0)
861
+ throw new Error(
862
+ "ensureSidebarHostShell: no document — pass `root` in non-browser environments"
863
+ );
864
+ const n = Z(e);
865
+ Q(n, i, t);
866
+ const s = e instanceof Document ? n.getElementById(t) : e.querySelector(`#${L(t)}`);
867
+ if (s instanceof HTMLElement && (e instanceof Document || e.contains(s)))
868
+ return s;
869
+ if (!(e instanceof Document)) {
870
+ const a = n.createElement("div");
871
+ return a.id = t, e.appendChild(a), a;
872
+ }
873
+ const o = n.createElement("div");
874
+ return o.id = t, n.body.appendChild(o), o;
875
+ }
876
+ function ee() {
877
+ return ' <meta name="viewport" content="width=device-width, initial-scale=1.0" />';
878
+ }
879
+ function ue(r) {
880
+ const {
881
+ title: e = "Markup AI Sidebar",
882
+ headInnerHtml: t = "",
883
+ includePluginHostHead: i = !1,
884
+ bodyScriptsHtml: n,
885
+ htmlLang: s = "en",
886
+ htmlAttrs: o = `lang="${s}" style="height:100%"`,
887
+ bodyAttrs: a = 'style="height:100%;margin:0"'
888
+ } = r, l = [i ? ee() : "", t].filter((u) => u.trim().length > 0).join(`
889
+ `);
890
+ return `<!DOCTYPE html>
891
+ <html ${o}>
892
+ <head>
893
+ <base target="_top" />
894
+ <meta charset="UTF-8" />
895
+ <title>${te(e)}</title>${l ? `
896
+ ${l}` : ""}
897
+ </head>
898
+ <body ${a}>
899
+ ${n}
900
+ </body>
901
+ </html>
902
+ `;
903
+ }
904
+ function te(r) {
905
+ return r.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
906
+ }
907
+ export {
908
+ N as DEFAULT_IPC_CONFIG,
909
+ ie as DEFAULT_SIDEBAR_CONFIG,
910
+ P as DeferredPromise,
911
+ D as IPCCore,
912
+ k as MimeType,
913
+ oe as PluginAdapter,
914
+ H as PluginIPCAdapter,
915
+ se as SIDEBAR_DEFAULT_PRODUCTION_BASE_URL,
916
+ M as SIDEBAR_HOST_CONTAINER_ID,
917
+ ge as SIDEBAR_HOST_SHELL_CSS,
918
+ V as SIDEBAR_IFRAME_DEFAULT_ALLOW,
919
+ G as SIDEBAR_IFRAME_DEFAULT_TITLE,
920
+ q as SIDEBAR_URL_OVERRIDE_STORAGE_KEY,
921
+ U as SidebarAdapter,
922
+ j as SidebarIPCAdapter,
923
+ re as TEXT_MIME_TYPES,
924
+ v as TextLookupError,
925
+ le as assertSidebarHostAdapter,
926
+ ue as buildSidebarHostHtmlDocument,
927
+ _ as buildSidebarHostShellCss,
928
+ ee as buildSidebarPluginHostHeadInnerHtml,
929
+ de as createSidebarHost,
930
+ pe as ensureSidebarHostShell,
931
+ ae as getSidebarBaseUrlWithOverride,
932
+ C as ipcErrorReconstructors,
933
+ ne as isTextLookupError,
934
+ B as reconstructError,
935
+ X as setupSidebarLoadOverlay,
936
+ ce as sidebarPostMessageTargetOrigin
937
+ };