@hyext-beyond/hy-ui-native
Version:
A native lib polyfill for huya miniapp
337 lines (336 loc) • 11.3 kB
JavaScript
var _excluded = ["translate", "scale", "rotation", "skewX", "skewY", "originX", "originY", "fontFamily", "fontSize", "fontWeight", "fontStyle", "style", "forwardedRef"],
_excluded2 = ["x", "y"];
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); }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
// @ts-nocheck
// @ts-ignore
import { createElement, StyleSheet } from 'react-native-web';
import { Component } from 'react';
// Kept in separate file, to avoid name collision with Symbol element
function resolve(styleProp, cleanedProps) {
if (styleProp) {
return StyleSheet ? [styleProp, cleanedProps] :
// Compatibility for arrays of styles in plain react web
styleProp[Symbol.iterator] ? Object.assign.apply(Object, [{}].concat(styleProp, [cleanedProps])) : Object.assign({}, styleProp, cleanedProps);
} else {
return cleanedProps;
}
}
/**
* `react-native-svg` supports additional props that aren't defined in the spec.
* This function replaces them in a spec conforming manner.
*
* @param {any} props Properties given to us.
* @returns {any} Cleaned any.
* @private
*/
function prepare(props) {
var translate = props.translate,
scale = props.scale,
rotation = props.rotation,
skewX = props.skewX,
skewY = props.skewY,
originX = props.originX,
originY = props.originY,
fontFamily = props.fontFamily,
fontSize = props.fontSize,
fontWeight = props.fontWeight,
fontStyle = props.fontStyle,
style = props.style,
forwardedRef = props.forwardedRef,
clean = _objectWithoutPropertiesLoose(props, _excluded);
var transform = [];
if (originX != null || originY != null) {
transform.push("translate(" + (originX || 0) + ", " + (originY || 0) + ")");
}
if (translate != null) {
transform.push("translate(" + translate + ")");
}
if (scale != null) {
transform.push("scale(" + scale + ")");
}
// rotation maps to rotate, not to collide with the text rotate attribute (which acts per glyph rather than block)
if (rotation != null) {
transform.push("rotate(" + rotation + ")");
}
if (skewX != null) {
transform.push("skewX(" + skewX + ")");
}
if (skewY != null) {
transform.push("skewY(" + skewY + ")");
}
if (originX != null || originY != null) {
transform.push("translate(" + (-originX || 0) + ", " + (-originY || 0) + ")");
}
if (transform.length) {
clean.transform = transform.join(' ');
}
if (forwardedRef) {
clean.ref = forwardedRef;
}
var styles = {};
if (fontFamily != null) {
styles.fontFamily = fontFamily;
}
if (fontSize != null) {
styles.fontSize = fontSize;
}
if (fontWeight != null) {
styles.fontWeight = fontWeight;
}
if (fontStyle != null) {
styles.fontStyle = fontStyle;
}
clean.style = resolve(style, styles);
return clean;
}
export var Circle = /*#__PURE__*/function (_Component) {
_inheritsLoose(Circle, _Component);
function Circle() {
return _Component.apply(this, arguments) || this;
}
var _proto = Circle.prototype;
_proto.render = function render() {
return createElement('circle', prepare(this.props));
};
return Circle;
}(Component);
export var ClipPath = /*#__PURE__*/function (_Component2) {
_inheritsLoose(ClipPath, _Component2);
function ClipPath() {
return _Component2.apply(this, arguments) || this;
}
var _proto2 = ClipPath.prototype;
_proto2.render = function render() {
return createElement('clipPath', prepare(this.props));
};
return ClipPath;
}(Component);
export var Defs = /*#__PURE__*/function (_Component3) {
_inheritsLoose(Defs, _Component3);
function Defs() {
return _Component3.apply(this, arguments) || this;
}
var _proto3 = Defs.prototype;
_proto3.render = function render() {
return createElement('defs', prepare(this.props));
};
return Defs;
}(Component);
export var Ellipse = /*#__PURE__*/function (_Component4) {
_inheritsLoose(Ellipse, _Component4);
function Ellipse() {
return _Component4.apply(this, arguments) || this;
}
var _proto4 = Ellipse.prototype;
_proto4.render = function render() {
return createElement('ellipse', prepare(this.props));
};
return Ellipse;
}(Component);
export var G = /*#__PURE__*/function (_Component5) {
_inheritsLoose(G, _Component5);
function G() {
return _Component5.apply(this, arguments) || this;
}
var _proto5 = G.prototype;
_proto5.render = function render() {
var _this$props = this.props,
x = _this$props.x,
y = _this$props.y,
rest = _objectWithoutPropertiesLoose(_this$props, _excluded2);
if ((x || y) && !rest.translate) {
rest.translate = (x || 0) + ", " + (y || 0);
}
return createElement('g', prepare(rest));
};
return G;
}(Component);
export var Image = /*#__PURE__*/function (_Component6) {
_inheritsLoose(Image, _Component6);
function Image() {
return _Component6.apply(this, arguments) || this;
}
var _proto6 = Image.prototype;
_proto6.render = function render() {
return createElement('image', prepare(this.props));
};
return Image;
}(Component);
export var Line = /*#__PURE__*/function (_Component7) {
_inheritsLoose(Line, _Component7);
function Line() {
return _Component7.apply(this, arguments) || this;
}
var _proto7 = Line.prototype;
_proto7.render = function render() {
return createElement('line', prepare(this.props));
};
return Line;
}(Component);
export var LinearGradient = /*#__PURE__*/function (_Component8) {
_inheritsLoose(LinearGradient, _Component8);
function LinearGradient() {
return _Component8.apply(this, arguments) || this;
}
var _proto8 = LinearGradient.prototype;
_proto8.render = function render() {
return createElement('linearGradient', prepare(this.props));
};
return LinearGradient;
}(Component);
export var Path = /*#__PURE__*/function (_Component9) {
_inheritsLoose(Path, _Component9);
function Path() {
return _Component9.apply(this, arguments) || this;
}
var _proto9 = Path.prototype;
_proto9.render = function render() {
return createElement('path', prepare(this.props));
};
return Path;
}(Component);
export var Polygon = /*#__PURE__*/function (_Component10) {
_inheritsLoose(Polygon, _Component10);
function Polygon() {
return _Component10.apply(this, arguments) || this;
}
var _proto10 = Polygon.prototype;
_proto10.render = function render() {
return createElement('polygon', prepare(this.props));
};
return Polygon;
}(Component);
export var Polyline = /*#__PURE__*/function (_Component11) {
_inheritsLoose(Polyline, _Component11);
function Polyline() {
return _Component11.apply(this, arguments) || this;
}
var _proto11 = Polyline.prototype;
_proto11.render = function render() {
return createElement('polyline', prepare(this.props));
};
return Polyline;
}(Component);
export var RadialGradient = /*#__PURE__*/function (_Component12) {
_inheritsLoose(RadialGradient, _Component12);
function RadialGradient() {
return _Component12.apply(this, arguments) || this;
}
var _proto12 = RadialGradient.prototype;
_proto12.render = function render() {
return createElement('radialGradient', prepare(this.props));
};
return RadialGradient;
}(Component);
export var Rect = /*#__PURE__*/function (_Component13) {
_inheritsLoose(Rect, _Component13);
function Rect() {
return _Component13.apply(this, arguments) || this;
}
var _proto13 = Rect.prototype;
_proto13.render = function render() {
return createElement('rect', prepare(this.props));
};
return Rect;
}(Component);
export var Stop = /*#__PURE__*/function (_Component14) {
_inheritsLoose(Stop, _Component14);
function Stop() {
return _Component14.apply(this, arguments) || this;
}
var _proto14 = Stop.prototype;
_proto14.render = function render() {
return createElement('stop', prepare(this.props));
};
return Stop;
}(Component);
export var Svg = /*#__PURE__*/function (_Component15) {
_inheritsLoose(Svg, _Component15);
function Svg() {
return _Component15.apply(this, arguments) || this;
}
var _proto15 = Svg.prototype;
_proto15.render = function render() {
return createElement('svg', prepare(this.props));
};
return Svg;
}(Component);
export var Text = /*#__PURE__*/function (_Component16) {
_inheritsLoose(Text, _Component16);
function Text() {
return _Component16.apply(this, arguments) || this;
}
var _proto16 = Text.prototype;
_proto16.render = function render() {
return createElement('text', prepare(this.props));
};
return Text;
}(Component);
export var TSpan = /*#__PURE__*/function (_Component17) {
_inheritsLoose(TSpan, _Component17);
function TSpan() {
return _Component17.apply(this, arguments) || this;
}
var _proto17 = TSpan.prototype;
_proto17.render = function render() {
return createElement('tspan', prepare(this.props));
};
return TSpan;
}(Component);
export var TextPath = /*#__PURE__*/function (_Component18) {
_inheritsLoose(TextPath, _Component18);
function TextPath() {
return _Component18.apply(this, arguments) || this;
}
var _proto18 = TextPath.prototype;
_proto18.render = function render() {
return createElement('textPath', prepare(this.props));
};
return TextPath;
}(Component);
export var Use = /*#__PURE__*/function (_Component19) {
_inheritsLoose(Use, _Component19);
function Use() {
return _Component19.apply(this, arguments) || this;
}
var _proto19 = Use.prototype;
_proto19.render = function render() {
return createElement('use', prepare(this.props));
};
return Use;
}(Component);
export var Mask = /*#__PURE__*/function (_Component20) {
_inheritsLoose(Mask, _Component20);
function Mask() {
return _Component20.apply(this, arguments) || this;
}
var _proto20 = Mask.prototype;
_proto20.render = function render() {
return createElement('mask', prepare(this.props));
};
return Mask;
}(Component);
export var Marker = /*#__PURE__*/function (_Component21) {
_inheritsLoose(Marker, _Component21);
function Marker() {
return _Component21.apply(this, arguments) || this;
}
var _proto21 = Marker.prototype;
_proto21.render = function render() {
return createElement('marker', prepare(this.props));
};
return Marker;
}(Component);
export var Pattern = /*#__PURE__*/function (_Component22) {
_inheritsLoose(Pattern, _Component22);
function Pattern() {
return _Component22.apply(this, arguments) || this;
}
var _proto22 = Pattern.prototype;
_proto22.render = function render() {
return createElement('pattern', prepare(this.props));
};
return Pattern;
}(Component);