canvas-renderer.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  18. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  19. return new (P || (P = Promise))(function (resolve, reject) {
  20. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  21. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  22. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  23. step((generator = generator.apply(thisArg, _arguments || [])).next());
  24. });
  25. };
  26. var __generator = (this && this.__generator) || function (thisArg, body) {
  27. var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
  28. return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
  29. function verb(n) { return function (v) { return step([n, v]); }; }
  30. function step(op) {
  31. if (f) throw new TypeError("Generator is already executing.");
  32. while (_) try {
  33. if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
  34. if (y = 0, t) op = [op[0] & 2, t.value];
  35. switch (op[0]) {
  36. case 0: case 1: t = op; break;
  37. case 4: _.label++; return { value: op[1], done: false };
  38. case 5: _.label++; y = op[1]; op = [0]; continue;
  39. case 7: op = _.ops.pop(); _.trys.pop(); continue;
  40. default:
  41. if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
  42. if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
  43. if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
  44. if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
  45. if (t[2]) _.ops.pop();
  46. _.trys.pop(); continue;
  47. }
  48. op = body.call(thisArg, _);
  49. } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
  50. if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
  51. }
  52. };
  53. Object.defineProperty(exports, "__esModule", { value: true });
  54. exports.CanvasRenderer = void 0;
  55. var stacking_context_1 = require("../stacking-context");
  56. var color_1 = require("../../css/types/color");
  57. var path_1 = require("../path");
  58. var bound_curves_1 = require("../bound-curves");
  59. var bezier_curve_1 = require("../bezier-curve");
  60. var vector_1 = require("../vector");
  61. var image_1 = require("../../css/types/image");
  62. var border_1 = require("../border");
  63. var background_1 = require("../background");
  64. var parser_1 = require("../../css/syntax/parser");
  65. var text_1 = require("../../css/layout/text");
  66. var image_element_container_1 = require("../../dom/replaced-elements/image-element-container");
  67. var box_sizing_1 = require("../box-sizing");
  68. var canvas_element_container_1 = require("../../dom/replaced-elements/canvas-element-container");
  69. var svg_element_container_1 = require("../../dom/replaced-elements/svg-element-container");
  70. var effects_1 = require("../effects");
  71. var bitwise_1 = require("../../core/bitwise");
  72. var gradient_1 = require("../../css/types/functions/gradient");
  73. var length_percentage_1 = require("../../css/types/length-percentage");
  74. var font_metrics_1 = require("../font-metrics");
  75. var bounds_1 = require("../../css/layout/bounds");
  76. var line_height_1 = require("../../css/property-descriptors/line-height");
  77. var input_element_container_1 = require("../../dom/replaced-elements/input-element-container");
  78. var textarea_element_container_1 = require("../../dom/elements/textarea-element-container");
  79. var select_element_container_1 = require("../../dom/elements/select-element-container");
  80. var iframe_element_container_1 = require("../../dom/replaced-elements/iframe-element-container");
  81. var renderer_1 = require("../renderer");
  82. var text_segmentation_1 = require("text-segmentation");
  83. var MASK_OFFSET = 10000;
  84. var CanvasRenderer = /** @class */ (function (_super) {
  85. __extends(CanvasRenderer, _super);
  86. function CanvasRenderer(context, options) {
  87. var _this = _super.call(this, context, options) || this;
  88. _this._activeEffects = [];
  89. _this.canvas = options.canvas ? options.canvas : document.createElement('canvas');
  90. _this.ctx = _this.canvas.getContext('2d');
  91. if (!options.canvas) {
  92. _this.canvas.width = Math.floor(options.width * options.scale);
  93. _this.canvas.height = Math.floor(options.height * options.scale);
  94. _this.canvas.style.width = options.width + "px";
  95. _this.canvas.style.height = options.height + "px";
  96. }
  97. _this.fontMetrics = new font_metrics_1.FontMetrics(document);
  98. _this.ctx.scale(_this.options.scale, _this.options.scale);
  99. _this.ctx.translate(-options.x, -options.y);
  100. _this.ctx.textBaseline = 'bottom';
  101. _this._activeEffects = [];
  102. _this.context.logger.debug("Canvas renderer initialized (" + options.width + "x" + options.height + ") with scale " + options.scale);
  103. return _this;
  104. }
  105. CanvasRenderer.prototype.applyEffects = function (effects) {
  106. var _this = this;
  107. while (this._activeEffects.length) {
  108. this.popEffect();
  109. }
  110. effects.forEach(function (effect) { return _this.applyEffect(effect); });
  111. };
  112. CanvasRenderer.prototype.applyEffect = function (effect) {
  113. this.ctx.save();
  114. if (effects_1.isOpacityEffect(effect)) {
  115. this.ctx.globalAlpha = effect.opacity;
  116. }
  117. if (effects_1.isTransformEffect(effect)) {
  118. this.ctx.translate(effect.offsetX, effect.offsetY);
  119. this.ctx.transform(effect.matrix[0], effect.matrix[1], effect.matrix[2], effect.matrix[3], effect.matrix[4], effect.matrix[5]);
  120. this.ctx.translate(-effect.offsetX, -effect.offsetY);
  121. }
  122. if (effects_1.isClipEffect(effect)) {
  123. this.path(effect.path);
  124. this.ctx.clip();
  125. }
  126. this._activeEffects.push(effect);
  127. };
  128. CanvasRenderer.prototype.popEffect = function () {
  129. this._activeEffects.pop();
  130. this.ctx.restore();
  131. };
  132. CanvasRenderer.prototype.renderStack = function (stack) {
  133. return __awaiter(this, void 0, void 0, function () {
  134. var styles;
  135. return __generator(this, function (_a) {
  136. switch (_a.label) {
  137. case 0:
  138. styles = stack.element.container.styles;
  139. if (!styles.isVisible()) return [3 /*break*/, 2];
  140. return [4 /*yield*/, this.renderStackContent(stack)];
  141. case 1:
  142. _a.sent();
  143. _a.label = 2;
  144. case 2: return [2 /*return*/];
  145. }
  146. });
  147. });
  148. };
  149. CanvasRenderer.prototype.renderNode = function (paint) {
  150. return __awaiter(this, void 0, void 0, function () {
  151. return __generator(this, function (_a) {
  152. switch (_a.label) {
  153. case 0:
  154. if (bitwise_1.contains(paint.container.flags, 16 /* DEBUG_RENDER */)) {
  155. debugger;
  156. }
  157. if (!paint.container.styles.isVisible()) return [3 /*break*/, 3];
  158. return [4 /*yield*/, this.renderNodeBackgroundAndBorders(paint)];
  159. case 1:
  160. _a.sent();
  161. return [4 /*yield*/, this.renderNodeContent(paint)];
  162. case 2:
  163. _a.sent();
  164. _a.label = 3;
  165. case 3: return [2 /*return*/];
  166. }
  167. });
  168. });
  169. };
  170. CanvasRenderer.prototype.renderTextWithLetterSpacing = function (text, letterSpacing, baseline) {
  171. var _this = this;
  172. if (letterSpacing === 0) {
  173. this.ctx.fillText(text.text, text.bounds.left, text.bounds.top + baseline);
  174. }
  175. else {
  176. var letters = text_segmentation_1.splitGraphemes(text.text);
  177. letters.reduce(function (left, letter) {
  178. _this.ctx.fillText(letter, left, text.bounds.top + baseline);
  179. return left + _this.ctx.measureText(letter).width;
  180. }, text.bounds.left);
  181. }
  182. };
  183. CanvasRenderer.prototype.createFontStyle = function (styles) {
  184. var fontVariant = styles.fontVariant
  185. .filter(function (variant) { return variant === 'normal' || variant === 'small-caps'; })
  186. .join('');
  187. var fontFamily = styles.fontFamily.join(', ');
  188. var fontSize = parser_1.isDimensionToken(styles.fontSize)
  189. ? "" + styles.fontSize.number + styles.fontSize.unit
  190. : styles.fontSize.number + "px";
  191. return [
  192. [styles.fontStyle, fontVariant, styles.fontWeight, fontSize, fontFamily].join(' '),
  193. fontFamily,
  194. fontSize
  195. ];
  196. };
  197. CanvasRenderer.prototype.renderTextNode = function (text, styles) {
  198. return __awaiter(this, void 0, void 0, function () {
  199. var _a, font, fontFamily, fontSize, _b, baseline, middle, paintOrder;
  200. var _this = this;
  201. return __generator(this, function (_c) {
  202. _a = this.createFontStyle(styles), font = _a[0], fontFamily = _a[1], fontSize = _a[2];
  203. this.ctx.font = font;
  204. this.ctx.direction = styles.direction === 1 /* RTL */ ? 'rtl' : 'ltr';
  205. this.ctx.textAlign = 'left';
  206. this.ctx.textBaseline = 'alphabetic';
  207. _b = this.fontMetrics.getMetrics(fontFamily, fontSize), baseline = _b.baseline, middle = _b.middle;
  208. paintOrder = styles.paintOrder;
  209. text.textBounds.forEach(function (text) {
  210. paintOrder.forEach(function (paintOrderLayer) {
  211. switch (paintOrderLayer) {
  212. case 0 /* FILL */:
  213. _this.ctx.fillStyle = color_1.asString(styles.color);
  214. _this.renderTextWithLetterSpacing(text, styles.letterSpacing, baseline);
  215. var textShadows = styles.textShadow;
  216. if (textShadows.length && text.text.trim().length) {
  217. textShadows
  218. .slice(0)
  219. .reverse()
  220. .forEach(function (textShadow) {
  221. _this.ctx.shadowColor = color_1.asString(textShadow.color);
  222. _this.ctx.shadowOffsetX = textShadow.offsetX.number * _this.options.scale;
  223. _this.ctx.shadowOffsetY = textShadow.offsetY.number * _this.options.scale;
  224. _this.ctx.shadowBlur = textShadow.blur.number;
  225. _this.renderTextWithLetterSpacing(text, styles.letterSpacing, baseline);
  226. });
  227. _this.ctx.shadowColor = '';
  228. _this.ctx.shadowOffsetX = 0;
  229. _this.ctx.shadowOffsetY = 0;
  230. _this.ctx.shadowBlur = 0;
  231. }
  232. if (styles.textDecorationLine.length) {
  233. _this.ctx.fillStyle = color_1.asString(styles.textDecorationColor || styles.color);
  234. styles.textDecorationLine.forEach(function (textDecorationLine) {
  235. switch (textDecorationLine) {
  236. case 1 /* UNDERLINE */:
  237. // Draws a line at the baseline of the font
  238. // TODO As some browsers display the line as more than 1px if the font-size is big,
  239. // need to take that into account both in position and size
  240. _this.ctx.fillRect(text.bounds.left, Math.round(text.bounds.top + baseline), text.bounds.width, 1);
  241. break;
  242. case 2 /* OVERLINE */:
  243. _this.ctx.fillRect(text.bounds.left, Math.round(text.bounds.top), text.bounds.width, 1);
  244. break;
  245. case 3 /* LINE_THROUGH */:
  246. // TODO try and find exact position for line-through
  247. _this.ctx.fillRect(text.bounds.left, Math.ceil(text.bounds.top + middle), text.bounds.width, 1);
  248. break;
  249. }
  250. });
  251. }
  252. break;
  253. case 1 /* STROKE */:
  254. if (styles.webkitTextStrokeWidth && text.text.trim().length) {
  255. _this.ctx.strokeStyle = color_1.asString(styles.webkitTextStrokeColor);
  256. _this.ctx.lineWidth = styles.webkitTextStrokeWidth;
  257. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  258. _this.ctx.lineJoin = !!window.chrome ? 'miter' : 'round';
  259. _this.ctx.strokeText(text.text, text.bounds.left, text.bounds.top + baseline);
  260. }
  261. _this.ctx.strokeStyle = '';
  262. _this.ctx.lineWidth = 0;
  263. _this.ctx.lineJoin = 'miter';
  264. break;
  265. }
  266. });
  267. });
  268. return [2 /*return*/];
  269. });
  270. });
  271. };
  272. CanvasRenderer.prototype.renderReplacedElement = function (container, curves, image) {
  273. if (image && container.intrinsicWidth > 0 && container.intrinsicHeight > 0) {
  274. var box = box_sizing_1.contentBox(container);
  275. var path = bound_curves_1.calculatePaddingBoxPath(curves);
  276. this.path(path);
  277. this.ctx.save();
  278. this.ctx.clip();
  279. this.ctx.drawImage(image, 0, 0, container.intrinsicWidth, container.intrinsicHeight, box.left, box.top, box.width, box.height);
  280. this.ctx.restore();
  281. }
  282. };
  283. CanvasRenderer.prototype.renderNodeContent = function (paint) {
  284. return __awaiter(this, void 0, void 0, function () {
  285. var container, curves, styles, _i, _a, child, image, e_1, image, e_2, iframeRenderer, canvas, size, _b, fontFamily, fontSize, baseline, bounds, x, textBounds, img, image, url, e_3, fontFamily, bounds;
  286. return __generator(this, function (_c) {
  287. switch (_c.label) {
  288. case 0:
  289. this.applyEffects(paint.getEffects(4 /* CONTENT */));
  290. container = paint.container;
  291. curves = paint.curves;
  292. styles = container.styles;
  293. _i = 0, _a = container.textNodes;
  294. _c.label = 1;
  295. case 1:
  296. if (!(_i < _a.length)) return [3 /*break*/, 4];
  297. child = _a[_i];
  298. return [4 /*yield*/, this.renderTextNode(child, styles)];
  299. case 2:
  300. _c.sent();
  301. _c.label = 3;
  302. case 3:
  303. _i++;
  304. return [3 /*break*/, 1];
  305. case 4:
  306. if (!(container instanceof image_element_container_1.ImageElementContainer)) return [3 /*break*/, 8];
  307. _c.label = 5;
  308. case 5:
  309. _c.trys.push([5, 7, , 8]);
  310. return [4 /*yield*/, this.context.cache.match(container.src)];
  311. case 6:
  312. image = _c.sent();
  313. this.renderReplacedElement(container, curves, image);
  314. return [3 /*break*/, 8];
  315. case 7:
  316. e_1 = _c.sent();
  317. this.context.logger.error("Error loading image " + container.src);
  318. return [3 /*break*/, 8];
  319. case 8:
  320. if (container instanceof canvas_element_container_1.CanvasElementContainer) {
  321. this.renderReplacedElement(container, curves, container.canvas);
  322. }
  323. if (!(container instanceof svg_element_container_1.SVGElementContainer)) return [3 /*break*/, 12];
  324. _c.label = 9;
  325. case 9:
  326. _c.trys.push([9, 11, , 12]);
  327. return [4 /*yield*/, this.context.cache.match(container.svg)];
  328. case 10:
  329. image = _c.sent();
  330. this.renderReplacedElement(container, curves, image);
  331. return [3 /*break*/, 12];
  332. case 11:
  333. e_2 = _c.sent();
  334. this.context.logger.error("Error loading svg " + container.svg.substring(0, 255));
  335. return [3 /*break*/, 12];
  336. case 12:
  337. if (!(container instanceof iframe_element_container_1.IFrameElementContainer && container.tree)) return [3 /*break*/, 14];
  338. iframeRenderer = new CanvasRenderer(this.context, {
  339. scale: this.options.scale,
  340. backgroundColor: container.backgroundColor,
  341. x: 0,
  342. y: 0,
  343. width: container.width,
  344. height: container.height
  345. });
  346. return [4 /*yield*/, iframeRenderer.render(container.tree)];
  347. case 13:
  348. canvas = _c.sent();
  349. if (container.width && container.height) {
  350. this.ctx.drawImage(canvas, 0, 0, container.width, container.height, container.bounds.left, container.bounds.top, container.bounds.width, container.bounds.height);
  351. }
  352. _c.label = 14;
  353. case 14:
  354. if (container instanceof input_element_container_1.InputElementContainer) {
  355. size = Math.min(container.bounds.width, container.bounds.height);
  356. if (container.type === input_element_container_1.CHECKBOX) {
  357. if (container.checked) {
  358. this.ctx.save();
  359. this.path([
  360. new vector_1.Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79),
  361. new vector_1.Vector(container.bounds.left + size * 0.16, container.bounds.top + size * 0.5549),
  362. new vector_1.Vector(container.bounds.left + size * 0.27347, container.bounds.top + size * 0.44071),
  363. new vector_1.Vector(container.bounds.left + size * 0.39694, container.bounds.top + size * 0.5649),
  364. new vector_1.Vector(container.bounds.left + size * 0.72983, container.bounds.top + size * 0.23),
  365. new vector_1.Vector(container.bounds.left + size * 0.84, container.bounds.top + size * 0.34085),
  366. new vector_1.Vector(container.bounds.left + size * 0.39363, container.bounds.top + size * 0.79)
  367. ]);
  368. this.ctx.fillStyle = color_1.asString(input_element_container_1.INPUT_COLOR);
  369. this.ctx.fill();
  370. this.ctx.restore();
  371. }
  372. }
  373. else if (container.type === input_element_container_1.RADIO) {
  374. if (container.checked) {
  375. this.ctx.save();
  376. this.ctx.beginPath();
  377. this.ctx.arc(container.bounds.left + size / 2, container.bounds.top + size / 2, size / 4, 0, Math.PI * 2, true);
  378. this.ctx.fillStyle = color_1.asString(input_element_container_1.INPUT_COLOR);
  379. this.ctx.fill();
  380. this.ctx.restore();
  381. }
  382. }
  383. }
  384. if (isTextInputElement(container) && container.value.length) {
  385. _b = this.createFontStyle(styles), fontFamily = _b[0], fontSize = _b[1];
  386. baseline = this.fontMetrics.getMetrics(fontFamily, fontSize).baseline;
  387. this.ctx.font = fontFamily;
  388. this.ctx.fillStyle = color_1.asString(styles.color);
  389. this.ctx.textBaseline = 'alphabetic';
  390. this.ctx.textAlign = canvasTextAlign(container.styles.textAlign);
  391. bounds = box_sizing_1.contentBox(container);
  392. x = 0;
  393. switch (container.styles.textAlign) {
  394. case 1 /* CENTER */:
  395. x += bounds.width / 2;
  396. break;
  397. case 2 /* RIGHT */:
  398. x += bounds.width;
  399. break;
  400. }
  401. textBounds = bounds.add(x, 0, 0, -bounds.height / 2 + 1);
  402. this.ctx.save();
  403. this.path([
  404. new vector_1.Vector(bounds.left, bounds.top),
  405. new vector_1.Vector(bounds.left + bounds.width, bounds.top),
  406. new vector_1.Vector(bounds.left + bounds.width, bounds.top + bounds.height),
  407. new vector_1.Vector(bounds.left, bounds.top + bounds.height)
  408. ]);
  409. this.ctx.clip();
  410. this.renderTextWithLetterSpacing(new text_1.TextBounds(container.value, textBounds), styles.letterSpacing, baseline);
  411. this.ctx.restore();
  412. this.ctx.textBaseline = 'alphabetic';
  413. this.ctx.textAlign = 'left';
  414. }
  415. if (!bitwise_1.contains(container.styles.display, 2048 /* LIST_ITEM */)) return [3 /*break*/, 20];
  416. if (!(container.styles.listStyleImage !== null)) return [3 /*break*/, 19];
  417. img = container.styles.listStyleImage;
  418. if (!(img.type === 0 /* URL */)) return [3 /*break*/, 18];
  419. image = void 0;
  420. url = img.url;
  421. _c.label = 15;
  422. case 15:
  423. _c.trys.push([15, 17, , 18]);
  424. return [4 /*yield*/, this.context.cache.match(url)];
  425. case 16:
  426. image = _c.sent();
  427. this.ctx.drawImage(image, container.bounds.left - (image.width + 10), container.bounds.top);
  428. return [3 /*break*/, 18];
  429. case 17:
  430. e_3 = _c.sent();
  431. this.context.logger.error("Error loading list-style-image " + url);
  432. return [3 /*break*/, 18];
  433. case 18: return [3 /*break*/, 20];
  434. case 19:
  435. if (paint.listValue && container.styles.listStyleType !== -1 /* NONE */) {
  436. fontFamily = this.createFontStyle(styles)[0];
  437. this.ctx.font = fontFamily;
  438. this.ctx.fillStyle = color_1.asString(styles.color);
  439. this.ctx.textBaseline = 'middle';
  440. this.ctx.textAlign = 'right';
  441. bounds = new bounds_1.Bounds(container.bounds.left, container.bounds.top + length_percentage_1.getAbsoluteValue(container.styles.paddingTop, container.bounds.width), container.bounds.width, line_height_1.computeLineHeight(styles.lineHeight, styles.fontSize.number) / 2 + 1);
  442. this.renderTextWithLetterSpacing(new text_1.TextBounds(paint.listValue, bounds), styles.letterSpacing, line_height_1.computeLineHeight(styles.lineHeight, styles.fontSize.number) / 2 + 2);
  443. this.ctx.textBaseline = 'bottom';
  444. this.ctx.textAlign = 'left';
  445. }
  446. _c.label = 20;
  447. case 20: return [2 /*return*/];
  448. }
  449. });
  450. });
  451. };
  452. CanvasRenderer.prototype.renderStackContent = function (stack) {
  453. return __awaiter(this, void 0, void 0, function () {
  454. var _i, _a, child, _b, _c, child, _d, _e, child, _f, _g, child, _h, _j, child, _k, _l, child, _m, _o, child;
  455. return __generator(this, function (_p) {
  456. switch (_p.label) {
  457. case 0:
  458. if (bitwise_1.contains(stack.element.container.flags, 16 /* DEBUG_RENDER */)) {
  459. debugger;
  460. }
  461. // https://www.w3.org/TR/css-position-3/#painting-order
  462. // 1. the background and borders of the element forming the stacking context.
  463. return [4 /*yield*/, this.renderNodeBackgroundAndBorders(stack.element)];
  464. case 1:
  465. // https://www.w3.org/TR/css-position-3/#painting-order
  466. // 1. the background and borders of the element forming the stacking context.
  467. _p.sent();
  468. _i = 0, _a = stack.negativeZIndex;
  469. _p.label = 2;
  470. case 2:
  471. if (!(_i < _a.length)) return [3 /*break*/, 5];
  472. child = _a[_i];
  473. return [4 /*yield*/, this.renderStack(child)];
  474. case 3:
  475. _p.sent();
  476. _p.label = 4;
  477. case 4:
  478. _i++;
  479. return [3 /*break*/, 2];
  480. case 5:
  481. // 3. For all its in-flow, non-positioned, block-level descendants in tree order:
  482. return [4 /*yield*/, this.renderNodeContent(stack.element)];
  483. case 6:
  484. // 3. For all its in-flow, non-positioned, block-level descendants in tree order:
  485. _p.sent();
  486. _b = 0, _c = stack.nonInlineLevel;
  487. _p.label = 7;
  488. case 7:
  489. if (!(_b < _c.length)) return [3 /*break*/, 10];
  490. child = _c[_b];
  491. return [4 /*yield*/, this.renderNode(child)];
  492. case 8:
  493. _p.sent();
  494. _p.label = 9;
  495. case 9:
  496. _b++;
  497. return [3 /*break*/, 7];
  498. case 10:
  499. _d = 0, _e = stack.nonPositionedFloats;
  500. _p.label = 11;
  501. case 11:
  502. if (!(_d < _e.length)) return [3 /*break*/, 14];
  503. child = _e[_d];
  504. return [4 /*yield*/, this.renderStack(child)];
  505. case 12:
  506. _p.sent();
  507. _p.label = 13;
  508. case 13:
  509. _d++;
  510. return [3 /*break*/, 11];
  511. case 14:
  512. _f = 0, _g = stack.nonPositionedInlineLevel;
  513. _p.label = 15;
  514. case 15:
  515. if (!(_f < _g.length)) return [3 /*break*/, 18];
  516. child = _g[_f];
  517. return [4 /*yield*/, this.renderStack(child)];
  518. case 16:
  519. _p.sent();
  520. _p.label = 17;
  521. case 17:
  522. _f++;
  523. return [3 /*break*/, 15];
  524. case 18:
  525. _h = 0, _j = stack.inlineLevel;
  526. _p.label = 19;
  527. case 19:
  528. if (!(_h < _j.length)) return [3 /*break*/, 22];
  529. child = _j[_h];
  530. return [4 /*yield*/, this.renderNode(child)];
  531. case 20:
  532. _p.sent();
  533. _p.label = 21;
  534. case 21:
  535. _h++;
  536. return [3 /*break*/, 19];
  537. case 22:
  538. _k = 0, _l = stack.zeroOrAutoZIndexOrTransformedOrOpacity;
  539. _p.label = 23;
  540. case 23:
  541. if (!(_k < _l.length)) return [3 /*break*/, 26];
  542. child = _l[_k];
  543. return [4 /*yield*/, this.renderStack(child)];
  544. case 24:
  545. _p.sent();
  546. _p.label = 25;
  547. case 25:
  548. _k++;
  549. return [3 /*break*/, 23];
  550. case 26:
  551. _m = 0, _o = stack.positiveZIndex;
  552. _p.label = 27;
  553. case 27:
  554. if (!(_m < _o.length)) return [3 /*break*/, 30];
  555. child = _o[_m];
  556. return [4 /*yield*/, this.renderStack(child)];
  557. case 28:
  558. _p.sent();
  559. _p.label = 29;
  560. case 29:
  561. _m++;
  562. return [3 /*break*/, 27];
  563. case 30: return [2 /*return*/];
  564. }
  565. });
  566. });
  567. };
  568. CanvasRenderer.prototype.mask = function (paths) {
  569. this.ctx.beginPath();
  570. this.ctx.moveTo(0, 0);
  571. this.ctx.lineTo(this.canvas.width, 0);
  572. this.ctx.lineTo(this.canvas.width, this.canvas.height);
  573. this.ctx.lineTo(0, this.canvas.height);
  574. this.ctx.lineTo(0, 0);
  575. this.formatPath(paths.slice(0).reverse());
  576. this.ctx.closePath();
  577. };
  578. CanvasRenderer.prototype.path = function (paths) {
  579. this.ctx.beginPath();
  580. this.formatPath(paths);
  581. this.ctx.closePath();
  582. };
  583. CanvasRenderer.prototype.formatPath = function (paths) {
  584. var _this = this;
  585. paths.forEach(function (point, index) {
  586. var start = bezier_curve_1.isBezierCurve(point) ? point.start : point;
  587. if (index === 0) {
  588. _this.ctx.moveTo(start.x, start.y);
  589. }
  590. else {
  591. _this.ctx.lineTo(start.x, start.y);
  592. }
  593. if (bezier_curve_1.isBezierCurve(point)) {
  594. _this.ctx.bezierCurveTo(point.startControl.x, point.startControl.y, point.endControl.x, point.endControl.y, point.end.x, point.end.y);
  595. }
  596. });
  597. };
  598. CanvasRenderer.prototype.renderRepeat = function (path, pattern, offsetX, offsetY) {
  599. this.path(path);
  600. this.ctx.fillStyle = pattern;
  601. this.ctx.translate(offsetX, offsetY);
  602. this.ctx.fill();
  603. this.ctx.translate(-offsetX, -offsetY);
  604. };
  605. CanvasRenderer.prototype.resizeImage = function (image, width, height) {
  606. var _a;
  607. if (image.width === width && image.height === height) {
  608. return image;
  609. }
  610. var ownerDocument = (_a = this.canvas.ownerDocument) !== null && _a !== void 0 ? _a : document;
  611. var canvas = ownerDocument.createElement('canvas');
  612. canvas.width = Math.max(1, width);
  613. canvas.height = Math.max(1, height);
  614. var ctx = canvas.getContext('2d');
  615. ctx.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height);
  616. return canvas;
  617. };
  618. CanvasRenderer.prototype.renderBackgroundImage = function (container) {
  619. return __awaiter(this, void 0, void 0, function () {
  620. var index, _loop_1, this_1, _i, _a, backgroundImage;
  621. return __generator(this, function (_b) {
  622. switch (_b.label) {
  623. case 0:
  624. index = container.styles.backgroundImage.length - 1;
  625. _loop_1 = function (backgroundImage) {
  626. var image, url, e_4, _c, path, x, y, width, height, pattern, _d, path, x, y, width, height, _e, lineLength, x0, x1, y0, y1, canvas, ctx, gradient_2, pattern, _f, path, left, top_1, width, height, position, x, y, _g, rx, ry, radialGradient_1, midX, midY, f, invF;
  627. return __generator(this, function (_h) {
  628. switch (_h.label) {
  629. case 0:
  630. if (!(backgroundImage.type === 0 /* URL */)) return [3 /*break*/, 5];
  631. image = void 0;
  632. url = backgroundImage.url;
  633. _h.label = 1;
  634. case 1:
  635. _h.trys.push([1, 3, , 4]);
  636. return [4 /*yield*/, this_1.context.cache.match(url)];
  637. case 2:
  638. image = _h.sent();
  639. return [3 /*break*/, 4];
  640. case 3:
  641. e_4 = _h.sent();
  642. this_1.context.logger.error("Error loading background-image " + url);
  643. return [3 /*break*/, 4];
  644. case 4:
  645. if (image) {
  646. _c = background_1.calculateBackgroundRendering(container, index, [
  647. image.width,
  648. image.height,
  649. image.width / image.height
  650. ]), path = _c[0], x = _c[1], y = _c[2], width = _c[3], height = _c[4];
  651. pattern = this_1.ctx.createPattern(this_1.resizeImage(image, width, height), 'repeat');
  652. this_1.renderRepeat(path, pattern, x, y);
  653. }
  654. return [3 /*break*/, 6];
  655. case 5:
  656. if (image_1.isLinearGradient(backgroundImage)) {
  657. _d = background_1.calculateBackgroundRendering(container, index, [null, null, null]), path = _d[0], x = _d[1], y = _d[2], width = _d[3], height = _d[4];
  658. _e = gradient_1.calculateGradientDirection(backgroundImage.angle, width, height), lineLength = _e[0], x0 = _e[1], x1 = _e[2], y0 = _e[3], y1 = _e[4];
  659. canvas = document.createElement('canvas');
  660. canvas.width = width;
  661. canvas.height = height;
  662. ctx = canvas.getContext('2d');
  663. gradient_2 = ctx.createLinearGradient(x0, y0, x1, y1);
  664. gradient_1.processColorStops(backgroundImage.stops, lineLength).forEach(function (colorStop) {
  665. return gradient_2.addColorStop(colorStop.stop, color_1.asString(colorStop.color));
  666. });
  667. ctx.fillStyle = gradient_2;
  668. ctx.fillRect(0, 0, width, height);
  669. if (width > 0 && height > 0) {
  670. pattern = this_1.ctx.createPattern(canvas, 'repeat');
  671. this_1.renderRepeat(path, pattern, x, y);
  672. }
  673. }
  674. else if (image_1.isRadialGradient(backgroundImage)) {
  675. _f = background_1.calculateBackgroundRendering(container, index, [
  676. null,
  677. null,
  678. null
  679. ]), path = _f[0], left = _f[1], top_1 = _f[2], width = _f[3], height = _f[4];
  680. position = backgroundImage.position.length === 0 ? [length_percentage_1.FIFTY_PERCENT] : backgroundImage.position;
  681. x = length_percentage_1.getAbsoluteValue(position[0], width);
  682. y = length_percentage_1.getAbsoluteValue(position[position.length - 1], height);
  683. _g = gradient_1.calculateRadius(backgroundImage, x, y, width, height), rx = _g[0], ry = _g[1];
  684. if (rx > 0 && ry > 0) {
  685. radialGradient_1 = this_1.ctx.createRadialGradient(left + x, top_1 + y, 0, left + x, top_1 + y, rx);
  686. gradient_1.processColorStops(backgroundImage.stops, rx * 2).forEach(function (colorStop) {
  687. return radialGradient_1.addColorStop(colorStop.stop, color_1.asString(colorStop.color));
  688. });
  689. this_1.path(path);
  690. this_1.ctx.fillStyle = radialGradient_1;
  691. if (rx !== ry) {
  692. midX = container.bounds.left + 0.5 * container.bounds.width;
  693. midY = container.bounds.top + 0.5 * container.bounds.height;
  694. f = ry / rx;
  695. invF = 1 / f;
  696. this_1.ctx.save();
  697. this_1.ctx.translate(midX, midY);
  698. this_1.ctx.transform(1, 0, 0, f, 0, 0);
  699. this_1.ctx.translate(-midX, -midY);
  700. this_1.ctx.fillRect(left, invF * (top_1 - midY) + midY, width, height * invF);
  701. this_1.ctx.restore();
  702. }
  703. else {
  704. this_1.ctx.fill();
  705. }
  706. }
  707. }
  708. _h.label = 6;
  709. case 6:
  710. index--;
  711. return [2 /*return*/];
  712. }
  713. });
  714. };
  715. this_1 = this;
  716. _i = 0, _a = container.styles.backgroundImage.slice(0).reverse();
  717. _b.label = 1;
  718. case 1:
  719. if (!(_i < _a.length)) return [3 /*break*/, 4];
  720. backgroundImage = _a[_i];
  721. return [5 /*yield**/, _loop_1(backgroundImage)];
  722. case 2:
  723. _b.sent();
  724. _b.label = 3;
  725. case 3:
  726. _i++;
  727. return [3 /*break*/, 1];
  728. case 4: return [2 /*return*/];
  729. }
  730. });
  731. });
  732. };
  733. CanvasRenderer.prototype.renderSolidBorder = function (color, side, curvePoints) {
  734. return __awaiter(this, void 0, void 0, function () {
  735. return __generator(this, function (_a) {
  736. this.path(border_1.parsePathForBorder(curvePoints, side));
  737. this.ctx.fillStyle = color_1.asString(color);
  738. this.ctx.fill();
  739. return [2 /*return*/];
  740. });
  741. });
  742. };
  743. CanvasRenderer.prototype.renderDoubleBorder = function (color, width, side, curvePoints) {
  744. return __awaiter(this, void 0, void 0, function () {
  745. var outerPaths, innerPaths;
  746. return __generator(this, function (_a) {
  747. switch (_a.label) {
  748. case 0:
  749. if (!(width < 3)) return [3 /*break*/, 2];
  750. return [4 /*yield*/, this.renderSolidBorder(color, side, curvePoints)];
  751. case 1:
  752. _a.sent();
  753. return [2 /*return*/];
  754. case 2:
  755. outerPaths = border_1.parsePathForBorderDoubleOuter(curvePoints, side);
  756. this.path(outerPaths);
  757. this.ctx.fillStyle = color_1.asString(color);
  758. this.ctx.fill();
  759. innerPaths = border_1.parsePathForBorderDoubleInner(curvePoints, side);
  760. this.path(innerPaths);
  761. this.ctx.fill();
  762. return [2 /*return*/];
  763. }
  764. });
  765. });
  766. };
  767. CanvasRenderer.prototype.renderNodeBackgroundAndBorders = function (paint) {
  768. return __awaiter(this, void 0, void 0, function () {
  769. var styles, hasBackground, borders, backgroundPaintingArea, side, _i, borders_1, border;
  770. var _this = this;
  771. return __generator(this, function (_a) {
  772. switch (_a.label) {
  773. case 0:
  774. this.applyEffects(paint.getEffects(2 /* BACKGROUND_BORDERS */));
  775. styles = paint.container.styles;
  776. hasBackground = !color_1.isTransparent(styles.backgroundColor) || styles.backgroundImage.length;
  777. borders = [
  778. { style: styles.borderTopStyle, color: styles.borderTopColor, width: styles.borderTopWidth },
  779. { style: styles.borderRightStyle, color: styles.borderRightColor, width: styles.borderRightWidth },
  780. { style: styles.borderBottomStyle, color: styles.borderBottomColor, width: styles.borderBottomWidth },
  781. { style: styles.borderLeftStyle, color: styles.borderLeftColor, width: styles.borderLeftWidth }
  782. ];
  783. backgroundPaintingArea = calculateBackgroundCurvedPaintingArea(background_1.getBackgroundValueForIndex(styles.backgroundClip, 0), paint.curves);
  784. if (!(hasBackground || styles.boxShadow.length)) return [3 /*break*/, 2];
  785. this.ctx.save();
  786. this.path(backgroundPaintingArea);
  787. this.ctx.clip();
  788. if (!color_1.isTransparent(styles.backgroundColor)) {
  789. this.ctx.fillStyle = color_1.asString(styles.backgroundColor);
  790. this.ctx.fill();
  791. }
  792. return [4 /*yield*/, this.renderBackgroundImage(paint.container)];
  793. case 1:
  794. _a.sent();
  795. this.ctx.restore();
  796. styles.boxShadow
  797. .slice(0)
  798. .reverse()
  799. .forEach(function (shadow) {
  800. _this.ctx.save();
  801. var borderBoxArea = bound_curves_1.calculateBorderBoxPath(paint.curves);
  802. var maskOffset = shadow.inset ? 0 : MASK_OFFSET;
  803. var shadowPaintingArea = path_1.transformPath(borderBoxArea, -maskOffset + (shadow.inset ? 1 : -1) * shadow.spread.number, (shadow.inset ? 1 : -1) * shadow.spread.number, shadow.spread.number * (shadow.inset ? -2 : 2), shadow.spread.number * (shadow.inset ? -2 : 2));
  804. if (shadow.inset) {
  805. _this.path(borderBoxArea);
  806. _this.ctx.clip();
  807. _this.mask(shadowPaintingArea);
  808. }
  809. else {
  810. _this.mask(borderBoxArea);
  811. _this.ctx.clip();
  812. _this.path(shadowPaintingArea);
  813. }
  814. _this.ctx.shadowOffsetX = shadow.offsetX.number + maskOffset;
  815. _this.ctx.shadowOffsetY = shadow.offsetY.number;
  816. _this.ctx.shadowColor = color_1.asString(shadow.color);
  817. _this.ctx.shadowBlur = shadow.blur.number;
  818. _this.ctx.fillStyle = shadow.inset ? color_1.asString(shadow.color) : 'rgba(0,0,0,1)';
  819. _this.ctx.fill();
  820. _this.ctx.restore();
  821. });
  822. _a.label = 2;
  823. case 2:
  824. side = 0;
  825. _i = 0, borders_1 = borders;
  826. _a.label = 3;
  827. case 3:
  828. if (!(_i < borders_1.length)) return [3 /*break*/, 13];
  829. border = borders_1[_i];
  830. if (!(border.style !== 0 /* NONE */ && !color_1.isTransparent(border.color) && border.width > 0)) return [3 /*break*/, 11];
  831. if (!(border.style === 2 /* DASHED */)) return [3 /*break*/, 5];
  832. return [4 /*yield*/, this.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 2 /* DASHED */)];
  833. case 4:
  834. _a.sent();
  835. return [3 /*break*/, 11];
  836. case 5:
  837. if (!(border.style === 3 /* DOTTED */)) return [3 /*break*/, 7];
  838. return [4 /*yield*/, this.renderDashedDottedBorder(border.color, border.width, side, paint.curves, 3 /* DOTTED */)];
  839. case 6:
  840. _a.sent();
  841. return [3 /*break*/, 11];
  842. case 7:
  843. if (!(border.style === 4 /* DOUBLE */)) return [3 /*break*/, 9];
  844. return [4 /*yield*/, this.renderDoubleBorder(border.color, border.width, side, paint.curves)];
  845. case 8:
  846. _a.sent();
  847. return [3 /*break*/, 11];
  848. case 9: return [4 /*yield*/, this.renderSolidBorder(border.color, side, paint.curves)];
  849. case 10:
  850. _a.sent();
  851. _a.label = 11;
  852. case 11:
  853. side++;
  854. _a.label = 12;
  855. case 12:
  856. _i++;
  857. return [3 /*break*/, 3];
  858. case 13: return [2 /*return*/];
  859. }
  860. });
  861. });
  862. };
  863. CanvasRenderer.prototype.renderDashedDottedBorder = function (color, width, side, curvePoints, style) {
  864. return __awaiter(this, void 0, void 0, function () {
  865. var strokePaths, boxPaths, startX, startY, endX, endY, length, dashLength, spaceLength, useLineDash, multiplier, numberOfDashes, minSpace, maxSpace, path1, path2, path1, path2;
  866. return __generator(this, function (_a) {
  867. this.ctx.save();
  868. strokePaths = border_1.parsePathForBorderStroke(curvePoints, side);
  869. boxPaths = border_1.parsePathForBorder(curvePoints, side);
  870. if (style === 2 /* DASHED */) {
  871. this.path(boxPaths);
  872. this.ctx.clip();
  873. }
  874. if (bezier_curve_1.isBezierCurve(boxPaths[0])) {
  875. startX = boxPaths[0].start.x;
  876. startY = boxPaths[0].start.y;
  877. }
  878. else {
  879. startX = boxPaths[0].x;
  880. startY = boxPaths[0].y;
  881. }
  882. if (bezier_curve_1.isBezierCurve(boxPaths[1])) {
  883. endX = boxPaths[1].end.x;
  884. endY = boxPaths[1].end.y;
  885. }
  886. else {
  887. endX = boxPaths[1].x;
  888. endY = boxPaths[1].y;
  889. }
  890. if (side === 0 || side === 2) {
  891. length = Math.abs(startX - endX);
  892. }
  893. else {
  894. length = Math.abs(startY - endY);
  895. }
  896. this.ctx.beginPath();
  897. if (style === 3 /* DOTTED */) {
  898. this.formatPath(strokePaths);
  899. }
  900. else {
  901. this.formatPath(boxPaths.slice(0, 2));
  902. }
  903. dashLength = width < 3 ? width * 3 : width * 2;
  904. spaceLength = width < 3 ? width * 2 : width;
  905. if (style === 3 /* DOTTED */) {
  906. dashLength = width;
  907. spaceLength = width;
  908. }
  909. useLineDash = true;
  910. if (length <= dashLength * 2) {
  911. useLineDash = false;
  912. }
  913. else if (length <= dashLength * 2 + spaceLength) {
  914. multiplier = length / (2 * dashLength + spaceLength);
  915. dashLength *= multiplier;
  916. spaceLength *= multiplier;
  917. }
  918. else {
  919. numberOfDashes = Math.floor((length + spaceLength) / (dashLength + spaceLength));
  920. minSpace = (length - numberOfDashes * dashLength) / (numberOfDashes - 1);
  921. maxSpace = (length - (numberOfDashes + 1) * dashLength) / numberOfDashes;
  922. spaceLength =
  923. maxSpace <= 0 || Math.abs(spaceLength - minSpace) < Math.abs(spaceLength - maxSpace)
  924. ? minSpace
  925. : maxSpace;
  926. }
  927. if (useLineDash) {
  928. if (style === 3 /* DOTTED */) {
  929. this.ctx.setLineDash([0, dashLength + spaceLength]);
  930. }
  931. else {
  932. this.ctx.setLineDash([dashLength, spaceLength]);
  933. }
  934. }
  935. if (style === 3 /* DOTTED */) {
  936. this.ctx.lineCap = 'round';
  937. this.ctx.lineWidth = width;
  938. }
  939. else {
  940. this.ctx.lineWidth = width * 2 + 1.1;
  941. }
  942. this.ctx.strokeStyle = color_1.asString(color);
  943. this.ctx.stroke();
  944. this.ctx.setLineDash([]);
  945. // dashed round edge gap
  946. if (style === 2 /* DASHED */) {
  947. if (bezier_curve_1.isBezierCurve(boxPaths[0])) {
  948. path1 = boxPaths[3];
  949. path2 = boxPaths[0];
  950. this.ctx.beginPath();
  951. this.formatPath([new vector_1.Vector(path1.end.x, path1.end.y), new vector_1.Vector(path2.start.x, path2.start.y)]);
  952. this.ctx.stroke();
  953. }
  954. if (bezier_curve_1.isBezierCurve(boxPaths[1])) {
  955. path1 = boxPaths[1];
  956. path2 = boxPaths[2];
  957. this.ctx.beginPath();
  958. this.formatPath([new vector_1.Vector(path1.end.x, path1.end.y), new vector_1.Vector(path2.start.x, path2.start.y)]);
  959. this.ctx.stroke();
  960. }
  961. }
  962. this.ctx.restore();
  963. return [2 /*return*/];
  964. });
  965. });
  966. };
  967. CanvasRenderer.prototype.render = function (element) {
  968. return __awaiter(this, void 0, void 0, function () {
  969. var stack;
  970. return __generator(this, function (_a) {
  971. switch (_a.label) {
  972. case 0:
  973. if (this.options.backgroundColor) {
  974. this.ctx.fillStyle = color_1.asString(this.options.backgroundColor);
  975. this.ctx.fillRect(this.options.x, this.options.y, this.options.width, this.options.height);
  976. }
  977. stack = stacking_context_1.parseStackingContexts(element);
  978. return [4 /*yield*/, this.renderStack(stack)];
  979. case 1:
  980. _a.sent();
  981. this.applyEffects([]);
  982. return [2 /*return*/, this.canvas];
  983. }
  984. });
  985. });
  986. };
  987. return CanvasRenderer;
  988. }(renderer_1.Renderer));
  989. exports.CanvasRenderer = CanvasRenderer;
  990. var isTextInputElement = function (container) {
  991. if (container instanceof textarea_element_container_1.TextareaElementContainer) {
  992. return true;
  993. }
  994. else if (container instanceof select_element_container_1.SelectElementContainer) {
  995. return true;
  996. }
  997. else if (container instanceof input_element_container_1.InputElementContainer && container.type !== input_element_container_1.RADIO && container.type !== input_element_container_1.CHECKBOX) {
  998. return true;
  999. }
  1000. return false;
  1001. };
  1002. var calculateBackgroundCurvedPaintingArea = function (clip, curves) {
  1003. switch (clip) {
  1004. case 0 /* BORDER_BOX */:
  1005. return bound_curves_1.calculateBorderBoxPath(curves);
  1006. case 2 /* CONTENT_BOX */:
  1007. return bound_curves_1.calculateContentBoxPath(curves);
  1008. case 1 /* PADDING_BOX */:
  1009. default:
  1010. return bound_curves_1.calculatePaddingBoxPath(curves);
  1011. }
  1012. };
  1013. var canvasTextAlign = function (textAlign) {
  1014. switch (textAlign) {
  1015. case 1 /* CENTER */:
  1016. return 'center';
  1017. case 2 /* RIGHT */:
  1018. return 'right';
  1019. case 0 /* LEFT */:
  1020. default:
  1021. return 'left';
  1022. }
  1023. };
  1024. //# sourceMappingURL=canvas-renderer.js.map