版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

205 lines
4.4 KiB

  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const HTMLElement_1 = __importDefault(require("../html-element/HTMLElement"));
  7. /**
  8. * HTML Image Element.
  9. *
  10. * Reference:
  11. * https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement.
  12. */
  13. class HTMLImageElement extends HTMLElement_1.default {
  14. constructor() {
  15. super(...arguments);
  16. this.tagName = 'IMG';
  17. this.complete = false;
  18. this.naturalHeight = 0;
  19. this.naturalWidth = 0;
  20. this.crossOrigin = null;
  21. this.decoding = 'auto';
  22. this.loading = 'auto';
  23. this.x = 0;
  24. this.y = 0;
  25. }
  26. /**
  27. * Returns alt.
  28. *
  29. * @returns Alt.
  30. */
  31. get alt() {
  32. return this.getAttributeNS(null, 'alt') || '';
  33. }
  34. /**
  35. * Sets alt.
  36. *
  37. * @param alt Alt.
  38. */
  39. set alt(alt) {
  40. this.setAttributeNS(null, 'alt', alt);
  41. }
  42. /**
  43. * Returns current src.
  44. *
  45. * @returns Current src.
  46. */
  47. get currentSrc() {
  48. return this.src;
  49. }
  50. /**
  51. * Returns height.
  52. *
  53. * @returns Height.
  54. */
  55. get height() {
  56. const height = this.getAttributeNS(null, 'height');
  57. return height !== null ? Number(height) : 0;
  58. }
  59. /**
  60. * Sets height.
  61. *
  62. * @param height Height.
  63. */
  64. set height(height) {
  65. this.setAttributeNS(null, 'height', String(height));
  66. }
  67. /**
  68. * Returns is map.
  69. *
  70. * @returns Is map.
  71. */
  72. get isMap() {
  73. return this.getAttributeNS(null, 'ismap') !== null;
  74. }
  75. /**
  76. * Sets is map.
  77. *
  78. * @param ismap Is map.
  79. */
  80. set isMap(isMap) {
  81. if (!isMap) {
  82. this.removeAttributeNS(null, 'ismap');
  83. }
  84. else {
  85. this.setAttributeNS(null, 'ismap', '');
  86. }
  87. }
  88. /**
  89. * Returns referrer policy.
  90. *
  91. * @returns Referrer policy.
  92. */
  93. get referrerPolicy() {
  94. return this.getAttributeNS(null, 'referrerpolicy') || '';
  95. }
  96. /**
  97. * Sets referrer policy.
  98. *
  99. * @param referrerPolicy Referrer policy.
  100. */
  101. set referrerPolicy(referrerPolicy) {
  102. this.setAttributeNS(null, 'referrerpolicy', referrerPolicy);
  103. }
  104. /**
  105. * Returns sizes.
  106. *
  107. * @returns Sizes.
  108. */
  109. get sizes() {
  110. return this.getAttributeNS(null, 'sizes') || '';
  111. }
  112. /**
  113. * Sets sizes.
  114. *
  115. * @param sizes Sizes.
  116. */
  117. set sizes(sizes) {
  118. this.setAttributeNS(null, 'sizes', sizes);
  119. }
  120. /**
  121. * Returns source.
  122. *
  123. * @returns Source.
  124. */
  125. get src() {
  126. return this.getAttributeNS(null, 'src') || '';
  127. }
  128. /**
  129. * Sets source.
  130. *
  131. * @param source Source.
  132. */
  133. set src(src) {
  134. this.setAttributeNS(null, 'src', src);
  135. }
  136. /**
  137. * Returns srcset.
  138. *
  139. * @returns Source.
  140. */
  141. get srcset() {
  142. return this.getAttributeNS(null, 'srcset') || '';
  143. }
  144. /**
  145. * Sets src set.
  146. *
  147. * @param srcset Src set.
  148. */
  149. set srcset(srcset) {
  150. this.setAttributeNS(null, 'srcset', srcset);
  151. }
  152. /**
  153. * Returns use map.
  154. *
  155. * @returns Use map.
  156. */
  157. get useMap() {
  158. return this.getAttributeNS(null, 'usemap') || '';
  159. }
  160. /**
  161. * Sets is map.
  162. *
  163. * @param useMap Is map.
  164. */
  165. set useMap(useMap) {
  166. this.setAttributeNS(null, 'usemap', useMap);
  167. }
  168. /**
  169. * Returns width.
  170. *
  171. * @returns Width.
  172. */
  173. get width() {
  174. const width = this.getAttributeNS(null, 'width');
  175. return width !== null ? Number(width) : 0;
  176. }
  177. /**
  178. * Sets width.
  179. *
  180. * @param width Width.
  181. */
  182. set width(width) {
  183. this.setAttributeNS(null, 'width', String(width));
  184. }
  185. /**
  186. * The decode() method of the HTMLImageElement interface returns a Promise that resolves when the image is decoded and it is safe to append the image to the DOM.
  187. *
  188. * @returns Promise.
  189. */
  190. decode() {
  191. return Promise.resolve();
  192. }
  193. /**
  194. * Clones a node.
  195. *
  196. * @override
  197. * @param [deep=false] "true" to clone deep.
  198. * @returns Cloned node.
  199. */
  200. cloneNode(deep = false) {
  201. return super.cloneNode(deep);
  202. }
  203. }
  204. exports.default = HTMLImageElement;
  205. //# sourceMappingURL=HTMLImageElement.js.map