chunk.XOWK4TWJ.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import {
  2. requestInclude
  3. } from "./chunk.DTM5B7PO.js";
  4. import {
  5. event,
  6. watch
  7. } from "./chunk.XX234VRK.js";
  8. import {
  9. T,
  10. e,
  11. h,
  12. n,
  13. r
  14. } from "./chunk.5PIDMFOE.js";
  15. import {
  16. __decorateClass
  17. } from "./chunk.IHGPZX35.js";
  18. // _uyihdawu1:/Users/claviska/Projects/shoelace/src/components/include/include.scss
  19. var include_default = ":host {\n display: block;\n}";
  20. // src/components/include/include.ts
  21. var SlInclude = class extends h {
  22. constructor() {
  23. super(...arguments);
  24. this.mode = "cors";
  25. this.allowScripts = false;
  26. }
  27. connectedCallback() {
  28. super.connectedCallback();
  29. this.loadSource();
  30. }
  31. executeScript(script) {
  32. const newScript = document.createElement("script");
  33. [...script.attributes].map((attr) => newScript.setAttribute(attr.name, attr.value));
  34. newScript.textContent = script.textContent;
  35. script.parentNode.replaceChild(newScript, script);
  36. }
  37. async loadSource() {
  38. try {
  39. const src = this.src;
  40. const file = await requestInclude(src, this.mode);
  41. if (src !== this.src) {
  42. return;
  43. }
  44. if (!file) {
  45. return;
  46. }
  47. if (!file.ok) {
  48. this.slError.emit({ detail: { status: file.status } });
  49. return;
  50. }
  51. this.innerHTML = file.html;
  52. if (this.allowScripts) {
  53. [...this.querySelectorAll("script")].map((script) => this.executeScript(script));
  54. }
  55. this.slLoad.emit();
  56. } catch (e2) {
  57. this.slError.emit({ detail: { status: -1 } });
  58. }
  59. }
  60. render() {
  61. return T`<slot></slot>`;
  62. }
  63. };
  64. SlInclude.styles = r(include_default);
  65. __decorateClass([
  66. e()
  67. ], SlInclude.prototype, "src", 2);
  68. __decorateClass([
  69. e()
  70. ], SlInclude.prototype, "mode", 2);
  71. __decorateClass([
  72. e({ attribute: "allow-scripts", type: Boolean })
  73. ], SlInclude.prototype, "allowScripts", 2);
  74. __decorateClass([
  75. event("sl-load")
  76. ], SlInclude.prototype, "slLoad", 2);
  77. __decorateClass([
  78. event("sl-error")
  79. ], SlInclude.prototype, "slError", 2);
  80. __decorateClass([
  81. watch("src")
  82. ], SlInclude.prototype, "loadSource", 1);
  83. SlInclude = __decorateClass([
  84. n("sl-include")
  85. ], SlInclude);
  86. var include_default2 = SlInclude;
  87. export {
  88. include_default2 as include_default
  89. };