SVGPreserveAspectRatio.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. "use strict";
  2. const conversions = require("webidl-conversions");
  3. const utils = require("./utils.js");
  4. const implSymbol = utils.implSymbol;
  5. const ctorRegistrySymbol = utils.ctorRegistrySymbol;
  6. const interfaceName = "SVGPreserveAspectRatio";
  7. exports.is = value => {
  8. return utils.isObject(value) && Object.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
  9. };
  10. exports.isImpl = value => {
  11. return utils.isObject(value) && value instanceof Impl.implementation;
  12. };
  13. exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
  14. if (exports.is(value)) {
  15. return utils.implForWrapper(value);
  16. }
  17. throw new globalObject.TypeError(`${context} is not of type 'SVGPreserveAspectRatio'.`);
  18. };
  19. function makeWrapper(globalObject, newTarget) {
  20. let proto;
  21. if (newTarget !== undefined) {
  22. proto = newTarget.prototype;
  23. }
  24. if (!utils.isObject(proto)) {
  25. proto = globalObject[ctorRegistrySymbol]["SVGPreserveAspectRatio"].prototype;
  26. }
  27. return Object.create(proto);
  28. }
  29. exports.create = (globalObject, constructorArgs, privateData) => {
  30. const wrapper = makeWrapper(globalObject);
  31. return exports.setup(wrapper, globalObject, constructorArgs, privateData);
  32. };
  33. exports.createImpl = (globalObject, constructorArgs, privateData) => {
  34. const wrapper = exports.create(globalObject, constructorArgs, privateData);
  35. return utils.implForWrapper(wrapper);
  36. };
  37. exports._internalSetup = (wrapper, globalObject) => {};
  38. exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
  39. privateData.wrapper = wrapper;
  40. exports._internalSetup(wrapper, globalObject);
  41. Object.defineProperty(wrapper, implSymbol, {
  42. value: new Impl.implementation(globalObject, constructorArgs, privateData),
  43. configurable: true
  44. });
  45. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  46. if (Impl.init) {
  47. Impl.init(wrapper[implSymbol]);
  48. }
  49. return wrapper;
  50. };
  51. exports.new = (globalObject, newTarget) => {
  52. const wrapper = makeWrapper(globalObject, newTarget);
  53. exports._internalSetup(wrapper, globalObject);
  54. Object.defineProperty(wrapper, implSymbol, {
  55. value: Object.create(Impl.implementation.prototype),
  56. configurable: true
  57. });
  58. wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
  59. if (Impl.init) {
  60. Impl.init(wrapper[implSymbol]);
  61. }
  62. return wrapper[implSymbol];
  63. };
  64. const exposed = new Set(["Window"]);
  65. exports.install = (globalObject, globalNames) => {
  66. if (!globalNames.some(globalName => exposed.has(globalName))) {
  67. return;
  68. }
  69. const ctorRegistry = utils.initCtorRegistry(globalObject);
  70. class SVGPreserveAspectRatio {
  71. constructor() {
  72. throw new globalObject.TypeError("Illegal constructor");
  73. }
  74. get align() {
  75. const esValue = this !== null && this !== undefined ? this : globalObject;
  76. if (!exports.is(esValue)) {
  77. throw new globalObject.TypeError(
  78. "'get align' called on an object that is not a valid instance of SVGPreserveAspectRatio."
  79. );
  80. }
  81. return esValue[implSymbol]["align"];
  82. }
  83. set align(V) {
  84. const esValue = this !== null && this !== undefined ? this : globalObject;
  85. if (!exports.is(esValue)) {
  86. throw new globalObject.TypeError(
  87. "'set align' called on an object that is not a valid instance of SVGPreserveAspectRatio."
  88. );
  89. }
  90. V = conversions["unsigned short"](V, {
  91. context: "Failed to set the 'align' property on 'SVGPreserveAspectRatio': The provided value",
  92. globals: globalObject
  93. });
  94. esValue[implSymbol]["align"] = V;
  95. }
  96. get meetOrSlice() {
  97. const esValue = this !== null && this !== undefined ? this : globalObject;
  98. if (!exports.is(esValue)) {
  99. throw new globalObject.TypeError(
  100. "'get meetOrSlice' called on an object that is not a valid instance of SVGPreserveAspectRatio."
  101. );
  102. }
  103. return esValue[implSymbol]["meetOrSlice"];
  104. }
  105. set meetOrSlice(V) {
  106. const esValue = this !== null && this !== undefined ? this : globalObject;
  107. if (!exports.is(esValue)) {
  108. throw new globalObject.TypeError(
  109. "'set meetOrSlice' called on an object that is not a valid instance of SVGPreserveAspectRatio."
  110. );
  111. }
  112. V = conversions["unsigned short"](V, {
  113. context: "Failed to set the 'meetOrSlice' property on 'SVGPreserveAspectRatio': The provided value",
  114. globals: globalObject
  115. });
  116. esValue[implSymbol]["meetOrSlice"] = V;
  117. }
  118. }
  119. Object.defineProperties(SVGPreserveAspectRatio.prototype, {
  120. align: { enumerable: true },
  121. meetOrSlice: { enumerable: true },
  122. [Symbol.toStringTag]: { value: "SVGPreserveAspectRatio", configurable: true },
  123. SVG_PRESERVEASPECTRATIO_UNKNOWN: { value: 0, enumerable: true },
  124. SVG_PRESERVEASPECTRATIO_NONE: { value: 1, enumerable: true },
  125. SVG_PRESERVEASPECTRATIO_XMINYMIN: { value: 2, enumerable: true },
  126. SVG_PRESERVEASPECTRATIO_XMIDYMIN: { value: 3, enumerable: true },
  127. SVG_PRESERVEASPECTRATIO_XMAXYMIN: { value: 4, enumerable: true },
  128. SVG_PRESERVEASPECTRATIO_XMINYMID: { value: 5, enumerable: true },
  129. SVG_PRESERVEASPECTRATIO_XMIDYMID: { value: 6, enumerable: true },
  130. SVG_PRESERVEASPECTRATIO_XMAXYMID: { value: 7, enumerable: true },
  131. SVG_PRESERVEASPECTRATIO_XMINYMAX: { value: 8, enumerable: true },
  132. SVG_PRESERVEASPECTRATIO_XMIDYMAX: { value: 9, enumerable: true },
  133. SVG_PRESERVEASPECTRATIO_XMAXYMAX: { value: 10, enumerable: true },
  134. SVG_MEETORSLICE_UNKNOWN: { value: 0, enumerable: true },
  135. SVG_MEETORSLICE_MEET: { value: 1, enumerable: true },
  136. SVG_MEETORSLICE_SLICE: { value: 2, enumerable: true }
  137. });
  138. Object.defineProperties(SVGPreserveAspectRatio, {
  139. SVG_PRESERVEASPECTRATIO_UNKNOWN: { value: 0, enumerable: true },
  140. SVG_PRESERVEASPECTRATIO_NONE: { value: 1, enumerable: true },
  141. SVG_PRESERVEASPECTRATIO_XMINYMIN: { value: 2, enumerable: true },
  142. SVG_PRESERVEASPECTRATIO_XMIDYMIN: { value: 3, enumerable: true },
  143. SVG_PRESERVEASPECTRATIO_XMAXYMIN: { value: 4, enumerable: true },
  144. SVG_PRESERVEASPECTRATIO_XMINYMID: { value: 5, enumerable: true },
  145. SVG_PRESERVEASPECTRATIO_XMIDYMID: { value: 6, enumerable: true },
  146. SVG_PRESERVEASPECTRATIO_XMAXYMID: { value: 7, enumerable: true },
  147. SVG_PRESERVEASPECTRATIO_XMINYMAX: { value: 8, enumerable: true },
  148. SVG_PRESERVEASPECTRATIO_XMIDYMAX: { value: 9, enumerable: true },
  149. SVG_PRESERVEASPECTRATIO_XMAXYMAX: { value: 10, enumerable: true },
  150. SVG_MEETORSLICE_UNKNOWN: { value: 0, enumerable: true },
  151. SVG_MEETORSLICE_MEET: { value: 1, enumerable: true },
  152. SVG_MEETORSLICE_SLICE: { value: 2, enumerable: true }
  153. });
  154. ctorRegistry[interfaceName] = SVGPreserveAspectRatio;
  155. Object.defineProperty(globalObject, interfaceName, {
  156. configurable: true,
  157. writable: true,
  158. value: SVGPreserveAspectRatio
  159. });
  160. };
  161. const Impl = require("../../jsdom/living/svg/SVGPreserveAspectRatio-impl.js");