obi-sdk 0.6.0 → 0.6.4

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.
@@ -0,0 +1,185 @@
1
+ import { O as ObiWidget, s as setGlobalContext, t as trackEvent, c as captureException, w as withSentryAsyncHandler, a as withSentryHandler } from "./chunks/obi-widget-c52bfca4.js";
2
+ import "./chunks/types-e0297e7b.js";
3
+ if (!customElements.get("obi-widget")) {
4
+ customElements.define("obi-widget", ObiWidget);
5
+ }
6
+ const RETRY_CONFIG = {
7
+ maxAttempts: 3,
8
+ baseDelay: 200,
9
+ // ms
10
+ maxDelay: 2e3
11
+ // ms
12
+ };
13
+ function delay(ms) {
14
+ return new Promise((resolve) => setTimeout(resolve, ms));
15
+ }
16
+ function getRetryDelay(attempt) {
17
+ const exponentialDelay = RETRY_CONFIG.baseDelay * Math.pow(2, attempt);
18
+ return Math.min(exponentialDelay, RETRY_CONFIG.maxDelay);
19
+ }
20
+ async function retryOperation(operation, operationName, maxAttempts = RETRY_CONFIG.maxAttempts) {
21
+ let lastError = null;
22
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
23
+ try {
24
+ trackEvent(`${operationName}_attempt`, { attempt: attempt + 1 }, "init");
25
+ return await operation();
26
+ } catch (error) {
27
+ lastError = error;
28
+ console.warn(`[obi-sdk] ${operationName} failed (attempt ${attempt + 1}/${maxAttempts}):`, error);
29
+ trackEvent(`${operationName}_failed`, {
30
+ error: error instanceof Error ? error.message : String(error),
31
+ attempt: attempt + 1,
32
+ maxAttempts
33
+ }, "init");
34
+ if (attempt < maxAttempts - 1) {
35
+ const delayMs = getRetryDelay(attempt);
36
+ await delay(delayMs);
37
+ }
38
+ }
39
+ }
40
+ const finalError = new Error(`${operationName} failed after ${maxAttempts} attempts: ${lastError?.message}`);
41
+ captureException(finalError, {
42
+ componentName: "init",
43
+ handlerName: "retryOperation",
44
+ operationName,
45
+ maxAttempts,
46
+ lastErrorMessage: lastError?.message
47
+ });
48
+ throw finalError;
49
+ }
50
+ const mountSDK = withSentryHandler(function() {
51
+ const w = window;
52
+ let q = [];
53
+ if (typeof w.ObiSDK === "function" || typeof w.ObiSDK === "object") {
54
+ q = w.ObiSDK.q || [];
55
+ }
56
+ if (w.obiWidgetConfig) {
57
+ setGlobalContext({
58
+ apiKey: w.obiWidgetConfig.apiKey,
59
+ userId: w.obiWidgetConfig.user?.id,
60
+ userEmail: w.obiWidgetConfig.user?.email,
61
+ userMetadata: w.obiWidgetConfig.user?.metadata
62
+ });
63
+ }
64
+ w.ObiSDK = function(command, config) {
65
+ try {
66
+ if (command === "update" && config) {
67
+ w.obiWidgetConfig = {
68
+ ...w.obiWidgetConfig,
69
+ ...config
70
+ };
71
+ if (config.user) {
72
+ setGlobalContext({
73
+ userId: config.user.id,
74
+ userEmail: config.user.email,
75
+ userMetadata: config.user.metadata
76
+ });
77
+ }
78
+ const widgets = document.querySelectorAll("obi-widget");
79
+ widgets.forEach((widget) => {
80
+ widget.dispatchEvent(
81
+ new CustomEvent("obi-config-updated", {
82
+ detail: config,
83
+ bubbles: true,
84
+ composed: true
85
+ })
86
+ );
87
+ });
88
+ trackEvent("SDK_config_updated", {
89
+ hasUser: !!config.user,
90
+ configKeys: Object.keys(config)
91
+ }, "init");
92
+ }
93
+ } catch (error) {
94
+ captureException(error, {
95
+ componentName: "init",
96
+ handlerName: "ObiSDK.update",
97
+ command
98
+ });
99
+ throw error;
100
+ }
101
+ };
102
+ w.ObiSDK.q = q;
103
+ }, "mountSDK", "init");
104
+ const mountWidget = withSentryAsyncHandler(async function() {
105
+ return retryOperation(async () => {
106
+ if (document.querySelector("obi-widget")) {
107
+ trackEvent("widget_already_exists", {}, "init");
108
+ return;
109
+ }
110
+ if (!document.body) {
111
+ throw new Error("document.body not available");
112
+ }
113
+ const widget = document.createElement("obi-widget");
114
+ document.body.appendChild(widget);
115
+ console.log("[obi-sdk] widget mounted");
116
+ trackEvent("widget_mounted", {}, "init");
117
+ }, "widget mounting");
118
+ }, "mountWidget", "init");
119
+ const processQueue = withSentryHandler(function() {
120
+ const w = window;
121
+ if (w.ObiSDK && Array.isArray(w.ObiSDK.q)) {
122
+ const queueLength = w.ObiSDK.q.length;
123
+ trackEvent("queue_processing", { queueLength }, "init");
124
+ (w.ObiSDK.q || []).forEach((args) => {
125
+ w.ObiSDK(...args);
126
+ });
127
+ w.ObiSDK.q = [];
128
+ if (queueLength > 0) {
129
+ trackEvent("queue_processed", { queueLength }, "init");
130
+ }
131
+ }
132
+ }, "processQueue", "init");
133
+ const loadFonts = withSentryAsyncHandler(async function() {
134
+ await loadFont("https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Syne:wght@400..800&display=swap");
135
+ await loadFont("https://fonts.cdnfonts.com/css/satoshi");
136
+ }, "loadFonts", "init");
137
+ const loadFont = withSentryAsyncHandler(async function(fontUrl) {
138
+ return retryOperation(async () => {
139
+ if (!document.head) {
140
+ throw new Error("document.head not available");
141
+ }
142
+ const link = document.createElement("link");
143
+ link.href = fontUrl;
144
+ link.rel = "stylesheet";
145
+ document.head.appendChild(link);
146
+ trackEvent("font_loaded", { fontUrl }, "init");
147
+ }, "font loading");
148
+ }, "loadFont", "init");
149
+ const safeInitialize = withSentryAsyncHandler(async function() {
150
+ trackEvent("SDK_initialization_started", {}, "init");
151
+ await new Promise((resolve) => setTimeout(resolve, 500));
152
+ mountSDK();
153
+ await loadFonts();
154
+ await mountWidget();
155
+ processQueue();
156
+ trackEvent("SDK_initialization_completed", {}, "init");
157
+ }, "safeInitialize", "init");
158
+ const initializeObiWidget = withSentryAsyncHandler(async function() {
159
+ if (document.readyState === "loading") {
160
+ trackEvent("DOM_not_ready", {}, "init");
161
+ document.addEventListener("DOMContentLoaded", async () => {
162
+ try {
163
+ await safeInitialize();
164
+ } catch (error) {
165
+ captureException(error, { componentName: "init", handlerName: "DOMContentLoaded" });
166
+ console.error("[obi-sdk] initialization failed:", error);
167
+ }
168
+ });
169
+ } else {
170
+ trackEvent("DOM_ready", {}, "init");
171
+ await safeInitialize();
172
+ }
173
+ }, "initializeObiWidget", "init");
174
+ try {
175
+ setGlobalContext({ componentName: "init" });
176
+ trackEvent("SDK_script_loaded", {}, "init");
177
+ initializeObiWidget();
178
+ } catch (error) {
179
+ captureException(error, { componentName: "init", handlerName: "top-level" });
180
+ console.error("[obi-sdk] initialization failed:", error);
181
+ }
182
+ export {
183
+ ObiWidget
184
+ };
185
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/core/init.ts"],"sourcesContent":["import { ObiWidget } from \"../ui/components/obi-widget\"\nimport { \n captureException, \n setGlobalContext, \n trackEvent, \n withSentryAsyncHandler,\n withSentryHandler \n} from \"../sentry\"\n\nif (!customElements.get(\"obi-widget\")) {\n customElements.define(\"obi-widget\", ObiWidget)\n}\n\n// Retry configuration\nconst RETRY_CONFIG = {\n maxAttempts: 3,\n baseDelay: 200, // ms\n maxDelay: 2000, // ms\n}\n\nfunction delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n\nfunction getRetryDelay(attempt: number): number {\n const exponentialDelay = RETRY_CONFIG.baseDelay * Math.pow(2, attempt)\n return Math.min(exponentialDelay, RETRY_CONFIG.maxDelay)\n}\n\nasync function retryOperation<T>(\n operation: () => Promise<T> | T,\n operationName: string,\n maxAttempts: number = RETRY_CONFIG.maxAttempts\n): Promise<T> {\n let lastError: Error | null = null\n\n for (let attempt = 0; attempt < maxAttempts; attempt++) {\n try {\n trackEvent(`${operationName}_attempt`, { attempt: attempt + 1 }, 'init');\n return await operation()\n } catch (error) {\n lastError = error as Error\n console.warn(`[obi-sdk] ${operationName} failed (attempt ${attempt + 1}/${maxAttempts}):`, error)\n \n trackEvent(`${operationName}_failed`, {\n error: error instanceof Error ? error.message : String(error),\n attempt: attempt + 1,\n maxAttempts\n }, 'init');\n\n if (attempt < maxAttempts - 1) {\n const delayMs = getRetryDelay(attempt)\n await delay(delayMs)\n }\n }\n }\n\n const finalError = new Error(`${operationName} failed after ${maxAttempts} attempts: ${lastError?.message}`)\n captureException(finalError, { \n componentName: 'init', \n handlerName: 'retryOperation',\n operationName,\n maxAttempts,\n lastErrorMessage: lastError?.message \n });\n throw finalError;\n}\n\nconst mountSDK = withSentryHandler(function(): void {\n const w = window as any\n \n // The \"q\" here is a queue of commands that are sent to the SDK before it is initialized, typically\n // from the loader. We need to save it here so that we can restore it after the SDK is initialized.\n let q: any[] = []\n if (typeof w.ObiSDK === \"function\" || typeof w.ObiSDK === \"object\") {\n q = w.ObiSDK.q || []\n }\n\n // Set up global context from config if available\n if (w.obiWidgetConfig) {\n setGlobalContext({\n apiKey: w.obiWidgetConfig.apiKey,\n userId: w.obiWidgetConfig.user?.id,\n userEmail: w.obiWidgetConfig.user?.email,\n userMetadata: w.obiWidgetConfig.user?.metadata\n });\n }\n\n // The loader will have already set the ObiSDK value, but it's function is designed to just add\n // the command to the queue. We need to override it here so that we can handle the commands.\n w.ObiSDK = function (command: string, config?: any) {\n try {\n if (command === \"update\" && config) {\n w.obiWidgetConfig = {\n ...w.obiWidgetConfig,\n ...config,\n }\n \n // Update Sentry context when config changes\n if (config.user) {\n setGlobalContext({\n userId: config.user.id,\n userEmail: config.user.email,\n userMetadata: config.user.metadata\n });\n }\n \n // Notify all mounted obi-widget elements about the configuration update.\n const widgets = document.querySelectorAll(\"obi-widget\")\n widgets.forEach((widget) => {\n widget.dispatchEvent(\n new CustomEvent(\"obi-config-updated\", {\n detail: config,\n bubbles: true,\n composed: true,\n })\n )\n })\n \n trackEvent('SDK_config_updated', { \n hasUser: !!config.user,\n configKeys: Object.keys(config) \n }, 'init');\n }\n } catch (error) {\n captureException(error, { \n componentName: 'init', \n handlerName: 'ObiSDK.update',\n command \n });\n throw error;\n }\n }\n\n // Restore the queue, so it can be processed in the `processQueue` function.\n w.ObiSDK.q = q\n}, 'mountSDK', 'init');\n\nconst mountWidget = withSentryAsyncHandler(async function(): Promise<void> {\n return retryOperation(async () => {\n if (document.querySelector(\"obi-widget\")) {\n trackEvent('widget_already_exists', {}, 'init');\n return\n }\n\n if (!document.body) {\n throw new Error(\"document.body not available\")\n }\n\n const widget = document.createElement(\"obi-widget\")\n document.body.appendChild(widget)\n console.log(\"[obi-sdk] widget mounted\")\n trackEvent('widget_mounted', {}, 'init');\n }, \"widget mounting\")\n}, 'mountWidget', 'init');\n\n// Optionally process a queue if you want to support it\nconst processQueue = withSentryHandler(function() {\n const w = window as any\n if (w.ObiSDK && Array.isArray(w.ObiSDK.q)) {\n const queueLength = w.ObiSDK.q.length;\n trackEvent('queue_processing', { queueLength }, 'init');\n \n (w.ObiSDK.q || []).forEach((args: any[]) => {\n w.ObiSDK(...args)\n })\n w.ObiSDK.q = []\n \n if (queueLength > 0) {\n trackEvent('queue_processed', { queueLength }, 'init');\n }\n }\n}, 'processQueue', 'init');\n\nconst loadFonts = withSentryAsyncHandler(async function() {\n await loadFont(\"https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Syne:wght@400..800&display=swap\")\n await loadFont(\"https://fonts.cdnfonts.com/css/satoshi\")\n}, 'loadFonts', 'init');\n\nconst loadFont = withSentryAsyncHandler(async function(fontUrl: string) {\n return retryOperation(async () => {\n if (!document.head) {\n throw new Error(\"document.head not available\")\n }\n\n const link = document.createElement(\"link\")\n link.href = fontUrl\n link.rel = \"stylesheet\"\n\n document.head.appendChild(link)\n trackEvent('font_loaded', { fontUrl }, 'init');\n }, \"font loading\")\n}, 'loadFont', 'init');\n\nconst safeInitialize = withSentryAsyncHandler(async function(): Promise<void> {\n // Track initialization start\n trackEvent('SDK_initialization_started', {}, 'init');\n \n // Wait for a moment to ensure any write to localStorage from the obi loader is complete.\n await new Promise(resolve => setTimeout(resolve, 500))\n \n mountSDK()\n await loadFonts()\n await mountWidget()\n processQueue()\n \n trackEvent('SDK_initialization_completed', {}, 'init');\n}, 'safeInitialize', 'init');\n\nexport const initializeObiWidget = withSentryAsyncHandler(async function() {\n if (document.readyState === \"loading\") {\n trackEvent('DOM_not_ready', {}, 'init');\n document.addEventListener(\"DOMContentLoaded\", async () => {\n try {\n await safeInitialize()\n } catch (error) {\n captureException(error, { componentName: 'init', handlerName: 'DOMContentLoaded' })\n console.error(\"[obi-sdk] initialization failed:\", error)\n }\n })\n } else {\n trackEvent('DOM_ready', {}, 'init');\n await safeInitialize()\n }\n}, 'initializeObiWidget', 'init');\n\ntry {\n // Set initial context\n setGlobalContext({ componentName: 'init' });\n trackEvent('SDK_script_loaded', {}, 'init');\n \n initializeObiWidget()\n} catch (error) {\n captureException(error, { componentName: 'init', handlerName: 'top-level' })\n console.error(\"[obi-sdk] initialization failed:\", error)\n}\n"],"names":[],"mappings":"AASA,SAAA,KAAA,WAAA,KAAA,kBAAA,KAAA,YAAA,KAAA,kBAAA,KAAA,wBAAA,KAAA,yBAAA;AAAA,OAAA;AAAA,IAAI,CAAC,eAAe,IAAI,YAAY,GAAG;AACtB,iBAAA,OAAO,cAAc,SAAS;AAC/C;AAGA,MAAM,eAAe;AAAA,EACnB,aAAa;AAAA,EACb,WAAW;AAAA;AAAA,EACX,UAAU;AAAA;AACZ;AAEA,SAAS,MAAM,IAA2B;AACxC,SAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AACzD;AAEA,SAAS,cAAc,SAAyB;AAC9C,QAAM,mBAAmB,aAAa,YAAY,KAAK,IAAI,GAAG,OAAO;AACrE,SAAO,KAAK,IAAI,kBAAkB,aAAa,QAAQ;AACzD;AAEA,eAAe,eACb,WACA,eACA,cAAsB,aAAa,aACvB;AACZ,MAAI,YAA0B;AAE9B,WAAS,UAAU,GAAG,UAAU,aAAa,WAAW;AAClD,QAAA;AACS,iBAAA,GAAG,aAAa,YAAY,EAAE,SAAS,UAAU,KAAK,MAAM;AACvE,aAAO,MAAM,UAAU;AAAA,aAChB,OAAO;AACF,kBAAA;AACJ,cAAA,KAA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MAAM;AAEhC,IAAI;AAEe,mBAAA,EAAE,eAAe,OAAA,CAAQ;AAC/B,aAAA,qBAAqB,IAAI,MAAM;AAEtB;AACtB,SAAS,OAAO;AACd,mBAAiB,OAAO,EAAE,eAAe,QAAQ,aAAa,aAAa;AACnE,UAAA,MAAM,oCAAoC,KAAK;AACzD;"}
@@ -0,0 +1,110 @@
1
+ import { S as SDKState } from "./chunks/types-e0297e7b.js";
2
+ import { i, n, b as i$1, x } from "./chunks/obi-widget-c52bfca4.js";
3
+ import { A, C, e, f, D, N, d, O, S } from "./chunks/obi-widget-c52bfca4.js";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __decorateClass = (decorators, target, key, kind) => {
7
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
8
+ for (var i2 = decorators.length - 1, decorator; i2 >= 0; i2--)
9
+ if (decorator = decorators[i2])
10
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
11
+ if (kind && result)
12
+ __defProp(target, key, result);
13
+ return result;
14
+ };
15
+ class ObiStatusWidget extends i$1 {
16
+ constructor() {
17
+ super(...arguments);
18
+ this.state = SDKState.READY;
19
+ }
20
+ render() {
21
+ return x`
22
+ <div class="status-container">
23
+ <div class="status-indicator ${this.state}"></div>
24
+ <div class="status-text">${this.getStatusText()}</div>
25
+ </div>
26
+ `;
27
+ }
28
+ getStatusText() {
29
+ switch (this.state) {
30
+ case SDKState.READY:
31
+ return "Ready";
32
+ case SDKState.ERROR:
33
+ return "Error";
34
+ default:
35
+ return "Unknown";
36
+ }
37
+ }
38
+ }
39
+ ObiStatusWidget.styles = i`
40
+ :host {
41
+ display: inline-block;
42
+ font-family: Arial, sans-serif;
43
+ }
44
+
45
+ .status-container {
46
+ display: flex;
47
+ align-items: center;
48
+ padding: 8px 12px;
49
+ border-radius: 16px;
50
+ background-color: #f3f4f6;
51
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
52
+ }
53
+
54
+ .status-indicator {
55
+ width: 10px;
56
+ height: 10px;
57
+ border-radius: 50%;
58
+ margin-right: 8px;
59
+ }
60
+
61
+ .ready {
62
+ background-color: #10b981;
63
+ }
64
+
65
+ .active {
66
+ background-color: #3b82f6;
67
+ }
68
+
69
+ .error {
70
+ background-color: #ef4444;
71
+ }
72
+
73
+ .status-text {
74
+ font-size: 14px;
75
+ font-weight: 500;
76
+ color: #1f2937;
77
+ }
78
+ `;
79
+ __decorateClass([
80
+ n({ type: String })
81
+ ], ObiStatusWidget.prototype, "state", 2);
82
+ if (!customElements.get("obi-status-widget")) {
83
+ customElements.define("obi-status-widget", ObiStatusWidget);
84
+ }
85
+ const statusWidget = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, ObiStatusWidget }, Symbol.toStringTag, { value: "Module" }));
86
+ function defineCustomElements() {
87
+ Promise.resolve().then(() => statusWidget);
88
+ import("./chunks/index-d50e99a5.js");
89
+ import("./chunks/obi-widget-c52bfca4.js").then((n2) => n2.l);
90
+ import("./chunks/obi-widget-c52bfca4.js").then((n2) => n2.m);
91
+ import("./chunks/obi-widget-c52bfca4.js").then((n2) => n2.g);
92
+ import("./chunks/obi-widget-c52bfca4.js").then((n2) => n2.h);
93
+ import("./chunks/obi-widget-c52bfca4.js").then((n2) => n2.o);
94
+ import("./chunks/obi-widget-c52bfca4.js").then((n2) => n2.j);
95
+ import("./chunks/obi-widget-c52bfca4.js").then((n2) => n2.k);
96
+ }
97
+ export {
98
+ A as AudioEqualizer,
99
+ C as Course,
100
+ e as CourseList,
101
+ f as CourseModal,
102
+ D as DotLoader,
103
+ N as NavIcon,
104
+ d as NavigationBar,
105
+ ObiStatusWidget,
106
+ O as ObiWidget,
107
+ S as SearchingLoader,
108
+ defineCustomElements
109
+ };
110
+ //# sourceMappingURL=ui.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui.js","sources":["../../src/ui/components/status-widget.ts","../../src/ui/components/index.ts"],"sourcesContent":["import { SDKState } from \"@obi/obi-session\"\nimport { LitElement, html, css } from \"lit\"\nimport { property } from \"lit/decorators.js\"\n\nexport class ObiStatusWidget extends LitElement {\n @property({ type: String })\n state: SDKState = SDKState.READY\n\n static styles = css`\n :host {\n display: inline-block;\n font-family: Arial, sans-serif;\n }\n\n .status-container {\n display: flex;\n align-items: center;\n padding: 8px 12px;\n border-radius: 16px;\n background-color: #f3f4f6;\n box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);\n }\n\n .status-indicator {\n width: 10px;\n height: 10px;\n border-radius: 50%;\n margin-right: 8px;\n }\n\n .ready {\n background-color: #10b981;\n }\n\n .active {\n background-color: #3b82f6;\n }\n\n .error {\n background-color: #ef4444;\n }\n\n .status-text {\n font-size: 14px;\n font-weight: 500;\n color: #1f2937;\n }\n `\n\n render() {\n return html`\n <div class=\"status-container\">\n <div class=\"status-indicator ${this.state}\"></div>\n <div class=\"status-text\">${this.getStatusText()}</div>\n </div>\n `\n }\n\n private getStatusText(): string {\n switch (this.state) {\n case SDKState.READY:\n return \"Ready\"\n case SDKState.ERROR:\n return \"Error\"\n default:\n return \"Unknown\"\n }\n }\n}\n\nif (!customElements.get(\"obi-status-widget\")) {\n customElements.define(\"obi-status-widget\", ObiStatusWidget)\n}\n","export * from \"./status-widget\"\nexport * from \"./obi-widget\"\nexport * from \"./audio-equalizer\"\nexport * from \"./dot-loader\"\nexport * from \"./nav-icon\"\nexport * from \"./navigation-bar\"\nexport * from \"./searching-loader\"\nexport * from \"./courses/courses\"\nexport * from \"./courses/course-modal\"\n\n// Function to define all custom elements at once for development\nexport function defineCustomElements() {\n // Import all components to ensure they're registered\n // This is primarily useful for development\n import(\"./status-widget\")\n import(\"./obi-widget\")\n import(\"./audio-equalizer\")\n import(\"./dot-loader\")\n import(\"./nav-icon\")\n import(\"./navigation-bar\")\n import(\"./searching-loader\")\n import(\"./courses/courses\")\n import(\"./courses/course-modal\")\n}\n"],"names":["LitElement","html","css","property","n"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