1 | function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
2 |
|
3 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var EventEmitter = require('wolfy87-eventemitter');
|
11 |
|
12 | var CAPITALIZED_ATTRS_MAP = {
|
13 | fillStyle: 'FillStyle',
|
14 | fontSize: 'FontSize',
|
15 | globalAlpha: 'GlobalAlpha',
|
16 | opacity: 'GlobalAlpha',
|
17 | lineCap: 'LineCap',
|
18 | lineJoin: 'LineJoin',
|
19 | lineWidth: 'LineWidth',
|
20 | miterLimit: 'MiterLimit',
|
21 | strokeStyle: 'StrokeStyle',
|
22 | textAlign: 'TextAlign',
|
23 | textBaseline: 'TextBaseline'
|
24 | };
|
25 |
|
26 | var Renderer =
|
27 |
|
28 | function (_EventEmitter) {
|
29 | _inheritsLoose(Renderer, _EventEmitter);
|
30 |
|
31 | function Renderer(myCtx) {
|
32 | var _this;
|
33 |
|
34 | _this = _EventEmitter.call(this) || this;
|
35 |
|
36 | var self = _assertThisInitialized(_assertThisInitialized(_this));
|
37 |
|
38 | self.ctx = myCtx;
|
39 | self.style = {};
|
40 |
|
41 | self._initContext(myCtx);
|
42 |
|
43 | return _this;
|
44 | }
|
45 |
|
46 | var _proto = Renderer.prototype;
|
47 |
|
48 | _proto.getContext = function getContext(type) {
|
49 | if (type === '2d') {
|
50 | return this.ctx;
|
51 | }
|
52 | };
|
53 |
|
54 | _proto._initContext = function _initContext(myCtx) {
|
55 | Object.keys(CAPITALIZED_ATTRS_MAP).map(function (key) {
|
56 | Object.defineProperty(myCtx, key, {
|
57 | set: function set(value) {
|
58 | var name = 'set' + CAPITALIZED_ATTRS_MAP[key];
|
59 | myCtx[name](value);
|
60 | }
|
61 | });
|
62 | return key;
|
63 | });
|
64 | };
|
65 |
|
66 | return Renderer;
|
67 | }(EventEmitter);
|
68 |
|
69 | module.exports = Renderer; |
\ | No newline at end of file |