chunk.NKWA7PWD.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import {
  2. n as n2
  3. } from "./chunk.EPTJRW4G.js";
  4. import {
  5. getIconLibrary,
  6. unwatchIcon,
  7. watchIcon
  8. } from "./chunk.5ITCQEWZ.js";
  9. import {
  10. requestIcon
  11. } from "./chunk.ARRH633M.js";
  12. import {
  13. event,
  14. watch
  15. } from "./chunk.XX234VRK.js";
  16. import {
  17. i
  18. } from "./chunk.VIWFLAGR.js";
  19. import {
  20. T,
  21. e,
  22. h,
  23. n,
  24. r,
  25. r2
  26. } from "./chunk.5PIDMFOE.js";
  27. import {
  28. __decorateClass
  29. } from "./chunk.IHGPZX35.js";
  30. // node_modules/lit-html/directives/unsafe-svg.js
  31. var t = class extends n2 {
  32. };
  33. t.directiveName = "unsafeSVG", t.resultType = 2;
  34. var o = i(t);
  35. // _uyihdawu1:/Users/claviska/Projects/shoelace/src/components/icon/icon.scss
  36. var icon_default = ":host {\n position: relative;\n box-sizing: border-box;\n}\n:host *, :host *:before, :host *:after {\n box-sizing: inherit;\n}\n\n[hidden] {\n display: none !important;\n}\n\n:host {\n display: inline-block;\n width: 1em;\n height: 1em;\n contain: strict;\n box-sizing: content-box !important;\n}\n\n.icon,\nsvg {\n display: block;\n height: 100%;\n width: 100%;\n}";
  37. // src/components/icon/icon.ts
  38. var parser = new DOMParser();
  39. var SlIcon = class extends h {
  40. constructor() {
  41. super(...arguments);
  42. this.svg = "";
  43. this.library = "default";
  44. }
  45. connectedCallback() {
  46. super.connectedCallback();
  47. watchIcon(this);
  48. }
  49. firstUpdated() {
  50. this.setIcon();
  51. }
  52. disconnectedCallback() {
  53. super.disconnectedCallback();
  54. unwatchIcon(this);
  55. }
  56. getLabel() {
  57. let label = "";
  58. if (this.label) {
  59. label = this.label;
  60. } else if (this.name) {
  61. label = this.name.replace(/-/g, " ");
  62. } else if (this.src) {
  63. label = this.src.replace(/.*\//, "").replace(/-/g, " ").replace(/\.svg/i, "");
  64. }
  65. return label;
  66. }
  67. getUrl() {
  68. const library = getIconLibrary(this.library);
  69. if (this.name && library) {
  70. return library.resolver(this.name);
  71. } else {
  72. return this.src;
  73. }
  74. }
  75. redraw() {
  76. this.setIcon();
  77. }
  78. async setIcon() {
  79. const library = getIconLibrary(this.library);
  80. const url = this.getUrl();
  81. if (url) {
  82. try {
  83. const file = await requestIcon(url);
  84. if (url !== this.getUrl()) {
  85. return;
  86. } else if (file.ok) {
  87. const doc = parser.parseFromString(file.svg, "text/html");
  88. const svgEl = doc.body.querySelector("svg");
  89. if (svgEl) {
  90. if (library && library.mutator) {
  91. library.mutator(svgEl);
  92. }
  93. this.svg = svgEl.outerHTML;
  94. this.slLoad.emit();
  95. } else {
  96. this.svg = "";
  97. this.slError.emit({ detail: { status: file.status } });
  98. }
  99. } else {
  100. this.svg = "";
  101. this.slError.emit({ detail: { status: file.status } });
  102. }
  103. } catch (e2) {
  104. this.slError.emit({ detail: { status: -1 } });
  105. }
  106. } else if (this.svg) {
  107. this.svg = "";
  108. }
  109. }
  110. handleChange() {
  111. this.setIcon();
  112. }
  113. render() {
  114. return T` <div part="base" class="icon" role="img" aria-label=${this.getLabel()}>${o(this.svg)}</div>`;
  115. }
  116. };
  117. SlIcon.styles = r(icon_default);
  118. __decorateClass([
  119. r2()
  120. ], SlIcon.prototype, "svg", 2);
  121. __decorateClass([
  122. e()
  123. ], SlIcon.prototype, "name", 2);
  124. __decorateClass([
  125. e()
  126. ], SlIcon.prototype, "src", 2);
  127. __decorateClass([
  128. e()
  129. ], SlIcon.prototype, "label", 2);
  130. __decorateClass([
  131. e()
  132. ], SlIcon.prototype, "library", 2);
  133. __decorateClass([
  134. event("sl-load")
  135. ], SlIcon.prototype, "slLoad", 2);
  136. __decorateClass([
  137. event("sl-error")
  138. ], SlIcon.prototype, "slError", 2);
  139. __decorateClass([
  140. watch("name"),
  141. watch("src"),
  142. watch("library")
  143. ], SlIcon.prototype, "setIcon", 1);
  144. SlIcon = __decorateClass([
  145. n("sl-icon")
  146. ], SlIcon);
  147. var icon_default2 = SlIcon;
  148. export {
  149. icon_default2 as icon_default
  150. };
  151. /**
  152. * @license
  153. * Copyright 2017 Google LLC
  154. * SPDX-License-Identifier: BSD-3-Clause
  155. */