lido-standalone 0.0.0-beta-19-dev → 0.0.0-beta-20-dev

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.
Files changed (37) hide show
  1. package/dist/cjs/{index-52f24ddb.js → index-9a2514de.js} +3 -1
  2. package/dist/cjs/index-9a2514de.js.map +1 -0
  3. package/dist/cjs/index.cjs.js +1 -1
  4. package/dist/cjs/lido-standalone.cjs.entry.js +114 -65
  5. package/dist/cjs/lido-standalone.cjs.entry.js.map +1 -1
  6. package/dist/cjs/lido-standalone.cjs.js +2 -2
  7. package/dist/cjs/loader.cjs.js +2 -2
  8. package/dist/collection/components/lido-standalone/lido-standalone.js +148 -63
  9. package/dist/collection/components/lido-standalone/lido-standalone.js.map +1 -1
  10. package/dist/components/lido-standalone.js +117 -65
  11. package/dist/components/lido-standalone.js.map +1 -1
  12. package/dist/esm/{index-5da3b4be.js → index-32cd7d72.js} +3 -2
  13. package/dist/esm/index-32cd7d72.js.map +1 -0
  14. package/dist/esm/index.js +1 -1
  15. package/dist/esm/lido-standalone.entry.js +114 -65
  16. package/dist/esm/lido-standalone.entry.js.map +1 -1
  17. package/dist/esm/lido-standalone.js +3 -3
  18. package/dist/esm/loader.js +3 -3
  19. package/dist/lido-standalone/index.esm.js +1 -1
  20. package/dist/lido-standalone/lido-standalone.esm.js +1 -1
  21. package/dist/lido-standalone/lido-standalone.esm.js.map +1 -1
  22. package/dist/lido-standalone/p-1469ddb8.js +3 -0
  23. package/dist/lido-standalone/p-1469ddb8.js.map +1 -0
  24. package/dist/lido-standalone/p-862a6695.entry.js +2 -0
  25. package/dist/lido-standalone/p-862a6695.entry.js.map +1 -0
  26. package/dist/types/components/lido-standalone/lido-standalone.d.ts +13 -3
  27. package/dist/types/components.d.ts +16 -0
  28. package/package.json +1 -1
  29. package/src/components/lido-standalone/lido-standalone.tsx +142 -77
  30. package/src/components/lido-standalone/readme.md +2 -0
  31. package/src/components.d.ts +16 -0
  32. package/dist/cjs/index-52f24ddb.js.map +0 -1
  33. package/dist/esm/index-5da3b4be.js.map +0 -1
  34. package/dist/lido-standalone/p-1bb50e6d.entry.js +0 -2
  35. package/dist/lido-standalone/p-1bb50e6d.entry.js.map +0 -1
  36. package/dist/lido-standalone/p-3a3323c8.js +0 -3
  37. package/dist/lido-standalone/p-3a3323c8.js.map +0 -1
@@ -21,7 +21,9 @@ export class LidoStandalone {
21
21
  this.initialIndex = 0;
22
22
  this.canplay = false;
23
23
  this.height = '75vh';
24
+ this.language = undefined;
24
25
  this.xmlData = undefined;
26
+ this.zipUrl = undefined;
25
27
  this.codeFolderPath = undefined;
26
28
  this.commonAudioPath = undefined;
27
29
  this.scriptsInjected = false;
@@ -36,6 +38,10 @@ export class LidoStandalone {
36
38
  onXmlPathChange() {
37
39
  this.fetchXmlData();
38
40
  }
41
+ // Re-apply inline XML whenever the host prop changes.
42
+ onXmlDataChange() {
43
+ this.fetchXmlData();
44
+ }
39
45
  componentWillLoad() {
40
46
  // 1) Attempt to inject the Lido scripts from baseUrl
41
47
  this.injectLidoScripts();
@@ -57,7 +63,11 @@ export class LidoStandalone {
57
63
  const cleanBase = this.baseUrl.replace(/\/+$/, '');
58
64
  const scriptCheckUrl = `${cleanBase}/code/lido-player.esm.js`;
59
65
  const fileExists = this.doesFileExistSync(scriptCheckUrl);
66
+ // --------------- CASE: NO codeFolderPath PROVIDED ---------------
67
+ // Try loading version from default /code_versions folder
68
+ // --------------- SINGLE CASE: codeFolderPath PROVIDED ---------------
60
69
  if (fileExists) {
70
+ console.log("Using code from zip....");
61
71
  // If it exists, inject them
62
72
  const scriptEsm = document.createElement('script');
63
73
  scriptEsm.type = 'module';
@@ -70,79 +80,117 @@ export class LidoStandalone {
70
80
  document.head.appendChild(scriptNoModule);
71
81
  this.scriptsInjected = true;
72
82
  console.debug('Lido scripts injected from:', this.baseUrl);
83
+ return;
73
84
  }
74
- else if (this.codeFolderPath) {
85
+ if (this.codeFolderPath) {
75
86
  const cleanBase = this.baseUrl.replace(/\/+$/, "");
76
- const cfgUrl = `${cleanBase}/config.json`;
77
87
  try {
78
- const res = await fetch(cfgUrl);
79
- if (!res.ok) {
80
- console.warn("config.json not found. Skipping versioning and continuing...");
81
- throw new Error("config.json fetch failed");
82
- }
83
- else {
84
- const cfg = await res.json();
85
- const version = cfg.codeVersion;
86
- if (!version) {
87
- console.warn("config.json missing codeVersion. Skipping versioning. Falling back to npm package lido-player...");
88
- throw new Error("codeVersion missing in config.json");
89
- }
90
- else {
91
- // --- Version exists: try to load versioned folder ---
92
- const codePath = this.codeFolderPath.replace(/\/+$/, "");
93
- const versionFolder = `${codePath}/${version}`;
94
- const esmUrl = `${versionFolder}/lido-player.esm.js`;
95
- const noModuleUrl = `${versionFolder}/lido-player.js`;
96
- // Check if versioned ESM exists
97
- const headCheck = await fetch(esmUrl, { method: "HEAD" });
98
- if (!headCheck.ok) {
99
- console.warn(`Version folder found but lido-player.esm.js missing: ${esmUrl}`);
88
+ const lessonCfgUrl = `${cleanBase}/config.json`;
89
+ try {
90
+ // 1️⃣ Load lesson config.json safely
91
+ let lessonCfg = {};
92
+ let lessonVersion = null;
93
+ try {
94
+ const lessonResp = await fetch(lessonCfgUrl);
95
+ if (!lessonResp.ok)
96
+ throw new Error("Lesson config.json missing");
97
+ // Check for empty file (0 bytes)
98
+ const text = await lessonResp.text();
99
+ if (text.trim().length > 0) {
100
+ lessonCfg = JSON.parse(text);
100
101
  }
101
102
  else {
102
- // --- Load versioned scripts (SUCCESS CASE) ---
103
- const scriptEsm = document.createElement("script");
104
- scriptEsm.type = "module";
105
- scriptEsm.src = esmUrl;
106
- document.head.appendChild(scriptEsm);
107
- const scriptNoModule = document.createElement("script");
108
- scriptNoModule.setAttribute("nomodule", "");
109
- scriptNoModule.src = noModuleUrl;
110
- document.head.appendChild(scriptNoModule);
111
- this.scriptsInjected = true;
112
- console.debug("Loaded version from config.json:", versionFolder);
113
- return; // return when version successfully loaded
103
+ console.warn("Lesson config.json is EMPTY → falling back to latest version");
114
104
  }
105
+ lessonVersion = lessonCfg.code_version;
106
+ console.log(`%c USING THE VERSION FOLDER--> ${lessonVersion} `, "color: #3bffe8ff; background:#d32f2f; font-size: 15px; font-weight: bold; padding: 6px 10px; border-radius: 4px;");
107
+ }
108
+ catch (parseErr) {
109
+ console.warn("Lesson config.json invalid or unreadable → fallback to latest version");
110
+ lessonVersion = null;
111
+ }
112
+ // Normalize invalid versions
113
+ if (!lessonVersion || typeof lessonVersion !== "string" || lessonVersion.trim() === "") {
114
+ console.warn("Lesson has NO valid codeVersion → using latest version in code-folder-path");
115
+ lessonVersion = null;
115
116
  }
117
+ // 2️⃣ Load version list from code-folder-path/config.json
118
+ const codeCfgUrl = `${this.codeFolderPath.replace(/\/+$/, '')}/config.json`;
119
+ const codeResp = await fetch(codeCfgUrl);
120
+ if (!codeResp.ok)
121
+ throw new Error("Code-folder config.json missing");
122
+ const codeCfg = await codeResp.json();
123
+ const availableVersions = codeCfg.versions || [];
124
+ if (!availableVersions.length) {
125
+ throw new Error("No versions listed in code-folder config.json");
126
+ }
127
+ // 3️⃣ Compute selected version
128
+ let selectedVersion = null;
129
+ if (lessonVersion) {
130
+ selectedVersion = availableVersions.find(v => v.includes(lessonVersion));
131
+ }
132
+ // Fallback: use latest version
133
+ if (!selectedVersion) {
134
+ selectedVersion = availableVersions[availableVersions.length - 1];
135
+ console.log(`%c USING THE LATEST VERSION FOLDER-> ${selectedVersion} `, "color: #3bffe8ff; background:#d32f2f; font-size: 15px; font-weight: bold; padding: 6px 10px; border-radius: 4px;");
136
+ }
137
+ // 4️⃣ Inject scripts
138
+ const versionDir = `${this.codeFolderPath}/${selectedVersion}`;
139
+ const esmUrl = `${versionDir}/lido-player.esm.js`;
140
+ const noModuleUrl = `${versionDir}/lido-player.js`;
141
+ // Check if version folder exists
142
+ const headCheck = await fetch(esmUrl, { method: "HEAD" });
143
+ if (!headCheck.ok)
144
+ throw new Error(`Versioned script missing: ${esmUrl}`);
145
+ // Inject main module file
146
+ const scriptEsm = document.createElement("script");
147
+ scriptEsm.type = "module";
148
+ scriptEsm.src = esmUrl;
149
+ document.head.appendChild(scriptEsm);
150
+ // Inject fallback nomodule script
151
+ const scriptNoModule = document.createElement("script");
152
+ scriptNoModule.setAttribute("nomodule", "");
153
+ scriptNoModule.src = noModuleUrl;
154
+ document.head.appendChild(scriptNoModule);
155
+ this.scriptsInjected = true;
156
+ console.debug("Loaded Lido version from:", versionDir);
157
+ }
158
+ catch (err) {
159
+ console.warn("Failed to load versioned scripts, falling back to npm:", err);
160
+ this.fallbackNpmImport();
116
161
  }
117
162
  }
118
- catch (e) {
119
- console.error("Failed to read config.json. Skipping versioning...", e);
163
+ catch (err) {
164
+ console.warn("Failed loading scripts → fallback to npm:", err);
120
165
  this.fallbackNpmImport();
121
166
  }
122
- // If we reach this point, version loading FAILED → continue to final else
123
- }
124
- else {
125
- // Otherwise, fallback to the npm package
126
- console.warn(`Could not find remote scripts at "${scriptCheckUrl}". Falling back to npm package "lido-player"...`);
127
- this.fallbackNpmImport();
167
+ return;
128
168
  }
169
+ this.fallbackNpmImport();
129
170
  }
130
171
  /**
131
- * Synchronously checks if a file exists via HTTP HEAD request.
132
- * Returns true if status is 2xx, false otherwise.
133
- */
172
+ * Checks if a file truly exists (not a dev-server fallback).
173
+ * Ensures:
174
+ * - HTTP HEAD returns 2xx
175
+ * - responseURL matches the requested URL
176
+ */
134
177
  doesFileExistSync(url) {
135
- let exists = false;
136
178
  try {
137
179
  const xhr = new XMLHttpRequest();
138
- xhr.open('HEAD', url, false); // false = synchronous
139
- xhr.send(null);
140
- exists = xhr.status >= 200 && xhr.status < 300;
180
+ xhr.open("HEAD", url, false); // synchronous
181
+ xhr.send();
182
+ const statusOk = xhr.status >= 200 && xhr.status < 300;
183
+ if (!statusOk)
184
+ return false;
185
+ // Detect fallback HTML responses (common when folder/file is missing)
186
+ const contentType = xhr.getResponseHeader("Content-Type") || "";
187
+ const isHtmlFallback = contentType.includes("text/html");
188
+ return !isHtmlFallback;
141
189
  }
142
190
  catch (err) {
143
- console.warn('Synchronous HEAD request failed for:', url, err);
191
+ console.warn("File existence check failed for:", url, err);
192
+ return false;
144
193
  }
145
- return exists;
146
194
  }
147
195
  /**
148
196
  * Fallback approach: dynamically import the "lido-player/loader" module,
@@ -169,15 +217,13 @@ export class LidoStandalone {
169
217
  return;
170
218
  }
171
219
  // If xmlPath is not explicitly provided, default to `index.xml` in baseUrl
172
- if (!this.xmlPath) {
173
- if (this.baseUrl) {
174
- const cleanBase = this.baseUrl.replace(/\/+$/, '');
175
- this.xmlPath = `${cleanBase}/index.xml`;
176
- this.xmlBaseUrl = this.baseUrl;
177
- }
178
- else {
179
- return;
180
- }
220
+ if (this.baseUrl) {
221
+ const cleanBase = this.baseUrl.replace(/\/+$/, '');
222
+ this.xmlPath = `${cleanBase}/index.xml`;
223
+ this.xmlBaseUrl = this.baseUrl;
224
+ }
225
+ else {
226
+ return;
181
227
  }
182
228
  try {
183
229
  const xhr = new XMLHttpRequest();
@@ -205,7 +251,8 @@ export class LidoStandalone {
205
251
  *
206
252
  * This ensures the custom elements are defined before usage.
207
253
  */
208
- return h("lido-home", { key: '4e0aae8e3dae8ebc2b78fbbe97b9cbd3e08b6ff1', "common-audio-path": this.commonAudioPath, "initial-index": this.initialIndex, canplay: this.canplay, height: this.height, "xml-data": this.localXmlData, "base-url": this.xmlBaseUrl, "code-folder-path": this.codeFolderPath });
254
+ const lang = this.language || 'en';
255
+ return h("lido-home", { key: '52fd8d3879919dbba73d4c687f2d540f0e4e601f', "common-audio-path": this.commonAudioPath, "initial-index": this.initialIndex, canplay: this.canplay, height: this.height, lang: lang, "xml-data": this.localXmlData, "base-url": this.xmlBaseUrl, "code-folder-path": this.codeFolderPath, "zip-url": this.zipUrl });
209
256
  }
210
257
  static get is() { return "lido-standalone"; }
211
258
  static get originalStyleUrls() {
@@ -309,6 +356,23 @@ export class LidoStandalone {
309
356
  "reflect": false,
310
357
  "defaultValue": "'75vh'"
311
358
  },
359
+ "language": {
360
+ "type": "string",
361
+ "mutable": false,
362
+ "complexType": {
363
+ "original": "string",
364
+ "resolved": "string",
365
+ "references": {}
366
+ },
367
+ "required": false,
368
+ "optional": true,
369
+ "docs": {
370
+ "tags": [],
371
+ "text": "The language prop to pass to <lido-home>."
372
+ },
373
+ "attribute": "language",
374
+ "reflect": false
375
+ },
312
376
  "xmlData": {
313
377
  "type": "string",
314
378
  "mutable": false,
@@ -326,6 +390,23 @@ export class LidoStandalone {
326
390
  "attribute": "xml-data",
327
391
  "reflect": false
328
392
  },
393
+ "zipUrl": {
394
+ "type": "string",
395
+ "mutable": false,
396
+ "complexType": {
397
+ "original": "string",
398
+ "resolved": "string",
399
+ "references": {}
400
+ },
401
+ "required": false,
402
+ "optional": true,
403
+ "docs": {
404
+ "tags": [],
405
+ "text": "To pass zip file directly to <lido-home> as its attribute."
406
+ },
407
+ "attribute": "zip-url",
408
+ "reflect": false
409
+ },
329
410
  "codeFolderPath": {
330
411
  "type": "string",
331
412
  "mutable": false,
@@ -369,6 +450,7 @@ export class LidoStandalone {
369
450
  "xmlBaseUrl": {}
370
451
  };
371
452
  }
453
+ static get elementRef() { return "hostElement"; }
372
454
  static get watchers() {
373
455
  return [{
374
456
  "propName": "baseUrl",
@@ -376,6 +458,9 @@ export class LidoStandalone {
376
458
  }, {
377
459
  "propName": "xmlPath",
378
460
  "methodName": "onXmlPathChange"
461
+ }, {
462
+ "propName": "xmlData",
463
+ "methodName": "onXmlDataChange"
379
464
  }];
380
465
  }
381
466
  }
@@ -1 +1 @@
1
- {"version":3,"file":"lido-standalone.js","sourceRoot":"","sources":["../../../src/components/lido-standalone/lido-standalone.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,eAAe,CAAC;AAEjE;;;;;;;;;;;;;;GAcG;AAMH,MAAM,OAAO,cAAc;;uBAUC,EAAE;;4BASG,CAAC;uBAGL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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGF","sourcesContent":["import { Component, Prop, State, Watch, h } from '@stencil/core';\n\n/**\n * <lido-standalone> usage example:\n *\n * <lido-standalone\n * base-url=\"https://example.com/path/to/folder/lido-game\"\n * xml-path=\"https://example.com/path/to/folder/lido-game/assets/xmlData.xml\"\n * initial-index=\"2\"\n * canplay=\"true\"\n * height=\"75vh\"\n * ></lido-standalone>\n *\n * This attempts to load the external Lido scripts at runtime (from `baseUrl`).\n * If they aren't found, it falls back to loading the Lido npm package\n * and calls defineCustomElements(...) to register <lido-home>.\n */\n@Component({\n tag: 'lido-standalone',\n styleUrl: 'lido-standalone.css',\n shadow: false,\n})\nexport class LidoStandalone {\n /**\n * The public URL where the unzipped Lido code is hosted, e.g.\n * \"https://example.com/path/to/lido-game\".\n *\n * Inside that folder, we expect:\n * - code/lido-player.esm.js\n * - code/lido-player.js\n * - assets/ (optional)\n */\n @Prop() baseUrl: string = '';\n\n /**\n * If provided, we'll fetch this XML path once and pass the loaded string\n * to <lido-home>'s `xml-data` attribute.\n */\n @Prop() xmlPath?: string;\n\n /** The initial index to pass down to <lido-home>. Defaults to 0. */\n @Prop() initialIndex: number = 0;\n\n /** Whether the <lido-home> can play. Defaults to false. */\n @Prop() canplay: boolean = false;\n\n /** The height prop to pass to <lido-home>. Defaults to \"75vh\". */\n @Prop() height: string = '75vh';\n\n /**\n * Optional prop for directly providing XML data instead of fetching.\n */\n @Prop() xmlData?: string;\n\n /**\n * If provided(in index.html) → tries versioned script loading from config.json.\n * If no version is found → automatically falls back to default player loading.\n * If not provided → version management is skipped entirely and falls back to default player loading.\n */\n @Prop() codeFolderPath?: string;\n\n @Prop() commonAudioPath?: string;\n\n /** Whether scripts are already injected (remote or fallback). */\n @State() scriptsInjected: boolean = false;\n\n /** Stores the fetched or provided XML data. */\n @State() localXmlData?: string;\n\n /** This might be used by <lido-home> if referencing assets. */\n @State() xmlBaseUrl?: string;\n\n // Re-inject scripts if the baseUrl changes\n @Watch('baseUrl')\n onBaseUrlChange() {\n this.injectLidoScripts();\n }\n\n // Re-fetch XML if the xmlPath changes\n @Watch('xmlPath')\n onXmlPathChange() {\n this.fetchXmlData();\n }\n\n componentWillLoad() {\n // 1) Attempt to inject the Lido scripts from baseUrl\n this.injectLidoScripts();\n // 2) Fetch the XML (or use the xmlData if provided)\n this.fetchXmlData();\n }\n\n private async injectLidoScripts() {\n console.log('injectLidoScripts() called. baseUrl=', this.baseUrl);\n\n // If no baseUrl is provided OR we already injected scripts, just go to fallback\n if (!this.baseUrl) {\n console.warn('lido-standalone: No baseUrl provided. Using npm fallback...');\n this.fallbackNpmImport();\n return;\n }\n if (this.scriptsInjected) {\n return;\n }\n\n // Synchronously check if remote ESM script exists at baseUrl/code/lido-player.esm.js\n const cleanBase = this.baseUrl.replace(/\\/+$/, '');\n const scriptCheckUrl = `${cleanBase}/code/lido-player.esm.js`;\n const fileExists = this.doesFileExistSync(scriptCheckUrl);\n\n if (fileExists) {\n // If it exists, inject them\n const scriptEsm = document.createElement('script');\n scriptEsm.type = 'module';\n scriptEsm.src = scriptCheckUrl;\n document.head.appendChild(scriptEsm);\n\n // (Optional) NoModule script for older browsers\n const scriptNoModule = document.createElement('script');\n scriptNoModule.setAttribute('nomodule', '');\n scriptNoModule.src = `${cleanBase}/code/lido-player.js`;\n document.head.appendChild(scriptNoModule);\n\n this.scriptsInjected = true;\n console.debug('Lido scripts injected from:', this.baseUrl);\n }\n\n else if (this.codeFolderPath) {\n const cleanBase = this.baseUrl.replace(/\\/+$/, \"\");\n const cfgUrl = `${cleanBase}/config.json`;\n\n try {\n const res = await fetch(cfgUrl);\n\n if (!res.ok) {\n console.warn(\"config.json not found. Skipping versioning and continuing...\");\n throw new Error(\"config.json fetch failed\");\n } \n else {\n const cfg = await res.json();\n const version = cfg.codeVersion;\n\n if (!version) {\n console.warn(\"config.json missing codeVersion. Skipping versioning. Falling back to npm package lido-player...\");\n throw new Error(\"codeVersion missing in config.json\");\n } else {\n // --- Version exists: try to load versioned folder ---\n const codePath = this.codeFolderPath.replace(/\\/+$/, \"\");\n const versionFolder = `${codePath}/${version}`;\n\n const esmUrl = `${versionFolder}/lido-player.esm.js`;\n const noModuleUrl = `${versionFolder}/lido-player.js`;\n\n // Check if versioned ESM exists\n const headCheck = await fetch(esmUrl, { method: \"HEAD\" });\n\n if (!headCheck.ok) {\n console.warn(`Version folder found but lido-player.esm.js missing: ${esmUrl}`);\n } else {\n // --- Load versioned scripts (SUCCESS CASE) ---\n const scriptEsm = document.createElement(\"script\");\n scriptEsm.type = \"module\";\n scriptEsm.src = esmUrl;\n document.head.appendChild(scriptEsm);\n\n const scriptNoModule = document.createElement(\"script\");\n scriptNoModule.setAttribute(\"nomodule\", \"\");\n scriptNoModule.src = noModuleUrl;\n document.head.appendChild(scriptNoModule);\n\n this.scriptsInjected = true;\n console.debug(\"Loaded version from config.json:\", versionFolder);\n return; // return when version successfully loaded\n }\n }\n }\n } catch (e) {\n console.error(\"Failed to read config.json. Skipping versioning...\", e);\n this.fallbackNpmImport();\n }\n // If we reach this point, version loading FAILED → continue to final else\n }\n\n else {\n // Otherwise, fallback to the npm package\n console.warn(`Could not find remote scripts at \"${scriptCheckUrl}\". Falling back to npm package \"lido-player\"...`);\n this.fallbackNpmImport();\n }\n }\n\n /**\n * Synchronously checks if a file exists via HTTP HEAD request.\n * Returns true if status is 2xx, false otherwise.\n */\n private doesFileExistSync(url: string): boolean {\n let exists = false;\n try {\n const xhr = new XMLHttpRequest();\n xhr.open('HEAD', url, false); // false = synchronous\n xhr.send(null);\n exists = xhr.status >= 200 && xhr.status < 300;\n } catch (err) {\n console.warn('Synchronous HEAD request failed for:', url, err);\n }\n return exists;\n }\n\n /**\n * Fallback approach: dynamically import the \"lido-player/loader\" module,\n * then call defineCustomElements(window) to register the <lido-home> component.\n * This is asynchronous by nature.\n */\n private fallbackNpmImport() {\n import('lido-player/loader')\n .then(({ defineCustomElements }) => {\n // Register custom elements on 'window'\n defineCustomElements(window);\n // Mark scripts as loaded so we can proceed\n this.scriptsInjected = true;\n console.debug('Lido scripts loaded via npm fallback (defineCustomElements).');\n })\n .catch(err => {\n console.error('Failed to load from npm package \"lido-player\":', err);\n });\n }\n\n private fetchXmlData() {\n // If the user provided raw XML data, just store it\n if (this.xmlData) {\n this.localXmlData = this.xmlData;\n return;\n }\n\n // If xmlPath is not explicitly provided, default to `index.xml` in baseUrl\n if (!this.xmlPath) {\n if (this.baseUrl) {\n const cleanBase = this.baseUrl.replace(/\\/+$/, '');\n this.xmlPath = `${cleanBase}/index.xml`;\n this.xmlBaseUrl = this.baseUrl;\n } else {\n return;\n }\n }\n\n try {\n const xhr = new XMLHttpRequest();\n xhr.open('GET', this.xmlPath, false); // false = synchronous\n xhr.send(null);\n\n if (xhr.status >= 200 && xhr.status < 300) {\n this.localXmlData = xhr.responseText;\n } else {\n console.warn(`Failed to fetch XML from ${this.xmlPath}:`, xhr.status);\n }\n } catch (err) {\n console.warn(`Error fetching XML from ${this.xmlPath}:`, err);\n }\n }\n\n render() {\n /**\n * If you want to hide <lido-home> until the fallback is fully loaded,\n * you could do something like:\n *\n * if (!this.scriptsInjected) {\n * return <div>Loading Lido...</div>;\n * }\n *\n * This ensures the custom elements are defined before usage.\n */\n\n return <lido-home common-audio-path={this.commonAudioPath} initial-index={this.initialIndex} canplay={this.canplay} height={this.height} xml-data={this.localXmlData} base-url={this.xmlBaseUrl} code-folder-path={this.codeFolderPath}></lido-home>;\n }\n\n \n}\n\n\n"]}
1
+ {"version":3,"file":"lido-standalone.js","sourceRoot":"","sources":["../../../src/components/lido-standalone/lido-standalone.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK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AM,GAAG,GAAG,EAAE,CAAC;gBAC1C,IAAI,CAAC,YAAY,GAAG,GAAG,CAAC,YAAY,CAAC;YACvC,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,IAAI,CAAC,4BAA4B,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;YACxE,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,IAAI,CAAC,2BAA2B,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,CAAC,CAAC;QAChE,CAAC;IACH,CAAC;IAED,MAAM;QACJ;;;;;;;;;WASG;QAEH,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC;QACnC,OAAO,uFAA+B,IAAI,CAAC,eAAe,mBAAiB,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,cAAY,IAAI,CAAC,YAAY,cAAY,IAAI,CAAC,UAAU,sBAAoB,IAAI,CAAC,cAAc,aAAW,IAAI,CAAC,MAAM,GAAc,CAAC;IAC1R,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAGF","sourcesContent":["import { Component, Element, Prop, State, Watch, h } from '@stencil/core';\n\n/**\n * <lido-standalone> usage example:\n *\n * <lido-standalone\n * base-url=\"https://example.com/path/to/folder/lido-game\"\n * xml-path=\"https://example.com/path/to/folder/lido-game/assets/xmlData.xml\"\n * initial-index=\"2\"\n * canplay=\"true\"\n * height=\"75vh\"\n * ></lido-standalone>\n *\n * This attempts to load the external Lido scripts at runtime (from `baseUrl`).\n * If they aren't found, it falls back to loading the Lido npm package\n * and calls defineCustomElements(...) to register <lido-home>.\n */\n@Component({\n tag: 'lido-standalone',\n styleUrl: 'lido-standalone.css',\n shadow: false,\n})\nexport class LidoStandalone {\n @Element() hostElement!: HTMLElement;\n\n /**\n * The public URL where the unzipped Lido code is hosted, e.g.\n * \"https://example.com/path/to/lido-game\".\n *\n * Inside that folder, we expect:\n * - code/lido-player.esm.js\n * - code/lido-player.js\n * - assets/ (optional)\n */\n @Prop() baseUrl: string = '';\n\n /**\n * If provided, we'll fetch this XML path once and pass the loaded string\n * to <lido-home>'s `xml-data` attribute.\n */\n @Prop() xmlPath?: string;\n\n /** The initial index to pass down to <lido-home>. Defaults to 0. */\n @Prop() initialIndex: number = 0;\n\n /** Whether the <lido-home> can play. Defaults to false. */\n @Prop() canplay: boolean = false;\n\n /** The height prop to pass to <lido-home>. Defaults to \"75vh\". */\n @Prop() height: string = '75vh';\n\n /** The language prop to pass to <lido-home>. */\n @Prop() language?: string;\n\n /**\n * Optional prop for directly providing XML data instead of fetching.\n */\n @Prop() xmlData?: string;\n\n /**\n * To pass zip file directly to <lido-home> as its attribute.\n */\n @Prop() zipUrl?: string;\n\n /**\n * If provided(in index.html) → tries versioned script loading from config.json.\n * If no version is found → automatically falls back to default player loading.\n * If not provided → version management is skipped entirely and falls back to default player loading.\n */\n @Prop() codeFolderPath?: string;\n\n @Prop() commonAudioPath?: string;\n\n /** Whether scripts are already injected (remote or fallback). */\n @State() scriptsInjected: boolean = false;\n\n /** Stores the fetched or provided XML data. */\n @State() localXmlData?: string;\n\n /** This might be used by <lido-home> if referencing assets. */\n @State() xmlBaseUrl?: string;\n\n // Re-inject scripts if the baseUrl changes\n @Watch('baseUrl')\n onBaseUrlChange() {\n this.injectLidoScripts();\n }\n\n // Re-fetch XML if the xmlPath changes\n @Watch('xmlPath')\n onXmlPathChange() {\n this.fetchXmlData();\n }\n\n // Re-apply inline XML whenever the host prop changes.\n @Watch('xmlData')\n onXmlDataChange() {\n this.fetchXmlData();\n }\n\n componentWillLoad() {\n // 1) Attempt to inject the Lido scripts from baseUrl\n this.injectLidoScripts();\n // 2) Fetch the XML (or use the xmlData if provided)\n this.fetchXmlData();\n }\n\n private async injectLidoScripts() {\n console.log('injectLidoScripts() called. baseUrl=', this.baseUrl);\n\n // If no baseUrl is provided OR we already injected scripts, just go to fallback\n if (!this.baseUrl) {\n console.warn('lido-standalone: No baseUrl provided. Using npm fallback...');\n this.fallbackNpmImport();\n return;\n }\n if (this.scriptsInjected) {\n return;\n }\n\n // Synchronously check if remote ESM script exists at baseUrl/code/lido-player.esm.js\n const cleanBase = this.baseUrl.replace(/\\/+$/, '');\n const scriptCheckUrl = `${cleanBase}/code/lido-player.esm.js`;\n const fileExists = this.doesFileExistSync(scriptCheckUrl);\n\n // --------------- CASE: NO codeFolderPath PROVIDED ---------------\n // Try loading version from default /code_versions folder\n // --------------- SINGLE CASE: codeFolderPath PROVIDED ---------------\n\n if (fileExists) {\n console.log(\"Using code from zip....\")\n // If it exists, inject them\n const scriptEsm = document.createElement('script');\n scriptEsm.type = 'module';\n scriptEsm.src = scriptCheckUrl;\n document.head.appendChild(scriptEsm);\n // (Optional) NoModule script for older browsers\n const scriptNoModule = document.createElement('script');\n scriptNoModule.setAttribute('nomodule', '');\n scriptNoModule.src = `${cleanBase}/code/lido-player.js`;\n document.head.appendChild(scriptNoModule);\n this.scriptsInjected = true;\n console.debug('Lido scripts injected from:', this.baseUrl);\n return;\n }\n \n if (this.codeFolderPath) {\n const cleanBase = this.baseUrl.replace(/\\/+$/, \"\");\n try {\n const lessonCfgUrl = `${cleanBase}/config.json`;\n try {\n // 1️⃣ Load lesson config.json safely\n let lessonCfg: any = {};\n let lessonVersion: string | null = null;\n\n try {\n const lessonResp = await fetch(lessonCfgUrl);\n if (!lessonResp.ok) throw new Error(\"Lesson config.json missing\");\n\n // Check for empty file (0 bytes)\n const text = await lessonResp.text();\n if (text.trim().length > 0) {\n lessonCfg = JSON.parse(text);\n } else {\n console.warn(\"Lesson config.json is EMPTY → falling back to latest version\");\n }\n\n lessonVersion = lessonCfg.code_version;\n console.log(`%c USING THE VERSION FOLDER--> ${lessonVersion} `,\"color: #3bffe8ff; background:#d32f2f; font-size: 15px; font-weight: bold; padding: 6px 10px; border-radius: 4px;\");\n\n } catch (parseErr) {\n console.warn(\"Lesson config.json invalid or unreadable → fallback to latest version\");\n lessonVersion = null;\n }\n\n // Normalize invalid versions\n if (!lessonVersion || typeof lessonVersion !== \"string\" || lessonVersion.trim() === \"\") {\n console.warn(\"Lesson has NO valid codeVersion → using latest version in code-folder-path\");\n lessonVersion = null;\n }\n\n // 2️⃣ Load version list from code-folder-path/config.json\n const codeCfgUrl = `${this.codeFolderPath.replace(/\\/+$/, '')}/config.json`;\n const codeResp = await fetch(codeCfgUrl);\n if (!codeResp.ok) throw new Error(\"Code-folder config.json missing\");\n\n const codeCfg = await codeResp.json();\n const availableVersions: string[] = codeCfg.versions || [];\n\n if (!availableVersions.length) {\n throw new Error(\"No versions listed in code-folder config.json\");\n }\n\n // 3️⃣ Compute selected version\n let selectedVersion: string | undefined = null;\n\n if (lessonVersion) {\n selectedVersion = availableVersions.find(v => v.includes(lessonVersion));\n }\n\n // Fallback: use latest version\n if (!selectedVersion) {\n selectedVersion = availableVersions[availableVersions.length - 1];\n console.log(`%c USING THE LATEST VERSION FOLDER-> ${selectedVersion} `,\"color: #3bffe8ff; background:#d32f2f; font-size: 15px; font-weight: bold; padding: 6px 10px; border-radius: 4px;\");\n }\n\n // 4️⃣ Inject scripts\n const versionDir = `${this.codeFolderPath}/${selectedVersion}`;\n const esmUrl = `${versionDir}/lido-player.esm.js`;\n const noModuleUrl = `${versionDir}/lido-player.js`;\n\n // Check if version folder exists\n const headCheck = await fetch(esmUrl, { method: \"HEAD\" });\n if (!headCheck.ok) throw new Error(`Versioned script missing: ${esmUrl}`);\n\n // Inject main module file\n const scriptEsm = document.createElement(\"script\");\n scriptEsm.type = \"module\";\n scriptEsm.src = esmUrl;\n document.head.appendChild(scriptEsm);\n\n // Inject fallback nomodule script\n const scriptNoModule = document.createElement(\"script\");\n scriptNoModule.setAttribute(\"nomodule\", \"\");\n scriptNoModule.src = noModuleUrl;\n document.head.appendChild(scriptNoModule);\n\n this.scriptsInjected = true;\n console.debug(\"Loaded Lido version from:\", versionDir);\n\n }catch (err) {\n console.warn(\"Failed to load versioned scripts, falling back to npm:\", err);\n this.fallbackNpmImport();\n } \n } catch (err) {\n console.warn(\"Failed loading scripts → fallback to npm:\", err);\n this.fallbackNpmImport();\n }\n return;\n }\n this.fallbackNpmImport();\n }\n\n /**\n * Checks if a file truly exists (not a dev-server fallback).\n * Ensures:\n * - HTTP HEAD returns 2xx\n * - responseURL matches the requested URL\n */\nprivate doesFileExistSync(url: string): boolean {\n try {\n const xhr = new XMLHttpRequest();\n xhr.open(\"HEAD\", url, false); // synchronous\n xhr.send();\n\n const statusOk = xhr.status >= 200 && xhr.status < 300;\n\n if (!statusOk) return false;\n\n // Detect fallback HTML responses (common when folder/file is missing)\n const contentType = xhr.getResponseHeader(\"Content-Type\") || \"\";\n\n const isHtmlFallback = contentType.includes(\"text/html\");\n\n return !isHtmlFallback;\n } catch (err) {\n console.warn(\"File existence check failed for:\", url, err);\n return false;\n }\n}\n\n\n /**\n * Fallback approach: dynamically import the \"lido-player/loader\" module,\n * then call defineCustomElements(window) to register the <lido-home> component.\n * This is asynchronous by nature.\n */\n private fallbackNpmImport() {\n import('lido-player/loader')\n .then(({ defineCustomElements }) => {\n // Register custom elements on 'window'\n defineCustomElements(window);\n // Mark scripts as loaded so we can proceed\n this.scriptsInjected = true;\n console.debug('Lido scripts loaded via npm fallback (defineCustomElements).');\n })\n .catch(err => {\n console.error('Failed to load from npm package \"lido-player\":', err);\n });\n }\n\n private fetchXmlData() {\n // If the user provided raw XML data, just store it\n if (this.xmlData) {\n this.localXmlData = this.xmlData;\n return;\n }\n\n // If xmlPath is not explicitly provided, default to `index.xml` in baseUrl\n if (this.baseUrl) {\n const cleanBase = this.baseUrl.replace(/\\/+$/, '');\n this.xmlPath = `${cleanBase}/index.xml`;\n this.xmlBaseUrl = this.baseUrl;\n } else {\n return;\n }\n\n try {\n const xhr = new XMLHttpRequest();\n xhr.open('GET', this.xmlPath, false); // false = synchronous\n xhr.send(null);\n\n if (xhr.status >= 200 && xhr.status < 300) {\n this.localXmlData = xhr.responseText;\n } else {\n console.warn(`Failed to fetch XML from ${this.xmlPath}:`, xhr.status);\n }\n } catch (err) {\n console.warn(`Error fetching XML from ${this.xmlPath}:`, err);\n }\n }\n\n render() {\n /**\n * If you want to hide <lido-home> until the fallback is fully loaded,\n * you could do something like:\n *\n * if (!this.scriptsInjected) {\n * return <div>Loading Lido...</div>;\n * }\n *\n * This ensures the custom elements are defined before usage.\n */\n\n const lang = this.language || 'en';\n return <lido-home common-audio-path={this.commonAudioPath} initial-index={this.initialIndex} canplay={this.canplay} height={this.height} lang={lang} xml-data={this.localXmlData} base-url={this.xmlBaseUrl} code-folder-path={this.codeFolderPath} zip-url={this.zipUrl}></lido-home>;\n }\n\n \n}\n\n\n"]}