UNPKG

@hyext-beyond/hy-ui-native

Version:

A native lib polyfill for huya miniapp

73 lines 3.3 kB
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } import React from 'react'; export var Canvas = /*#__PURE__*/function (_React$Component) { _inheritsLoose(Canvas, _React$Component); function Canvas() { return _React$Component.apply(this, arguments) || this; } var _proto = Canvas.prototype; _proto.getContext = function getContext() { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return Promise.resolve(this._c.getContext.apply(this._c, args)); }; _proto.toDataURL = function toDataURL() { for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { args[_key2] = arguments[_key2]; } return Promise.resolve(this._c.toDataURL.apply(this._c, args)); }; _proto._init = function _init() { var canvas = this._c; if (canvas) { this.width = 300; this.height = 150; } }; _proto.componentDidMount = function componentDidMount() { this._init(); }; _proto.render = function render() { var _this = this; return /*#__PURE__*/React.createElement("canvas", { ref: function ref(c) { _this._c = c; } }); }; _createClass(Canvas, [{ key: "width", get: function get() { var _this$_c; return ((_this$_c = this._c) == null ? void 0 : _this$_c.width) || 0; }, set: function set(v) { var c = this._c; if (c != null) { c.width = v; c.style.width = v + 'px'; } } }, { key: "height", get: function get() { var _this$_c2; return ((_this$_c2 = this._c) == null ? void 0 : _this$_c2.height) || 0; }, set: function set(v) { var c = this._c; if (c != null) { c.height = v; c.style.height = v + 'px'; } } }]); return Canvas; }(React.Component); export default Canvas;