@shopify/react-native-skia
Version:
High-performance React Native Graphics using Skia
43 lines • 2.27 kB
JavaScript
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
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); }
import { BaseHostObject } from "./Host";
import { JsiSkRect } from "./JsiSkRect";
export class JsiSkRRect extends BaseHostObject {
static fromValue(CanvasKit, rect) {
if (rect instanceof JsiSkRect) {
return rect.ref;
}
if ("topLeft" in rect && "topRight" in rect && "bottomRight" in rect && "bottomLeft" in rect) {
return Float32Array.of(rect.rect.x, rect.rect.y, rect.rect.x + rect.rect.width, rect.rect.y + rect.rect.height, rect.topLeft.x, rect.topLeft.y, rect.topRight.x, rect.topRight.y, rect.bottomRight.x, rect.bottomRight.y, rect.bottomLeft.x, rect.bottomLeft.y);
}
return CanvasKit.RRectXY(JsiSkRect.fromValue(CanvasKit, rect.rect), rect.rx, rect.ry);
}
constructor(CanvasKit, rect, rx, ry) {
// based on https://github.com/google/skia/blob/main/src/core/SkRRect.cpp#L51
if (rx === Infinity || ry === Infinity) {
rx = ry = 0;
}
if (rect.width < rx + rx || rect.height < ry + ry) {
// At most one of these two divides will be by zero, and neither numerator is zero.
const scale = Math.min(rect.width / (rx + rx), rect.height / (ry + ry));
rx *= scale;
ry *= scale;
}
const ref = CanvasKit.RRectXY(JsiSkRect.fromValue(CanvasKit, rect), rx, ry);
super(CanvasKit, ref, "RRect");
_defineProperty(this, "dispose", () => {
// Float32Array
});
}
get rx() {
return this.ref[4];
}
get ry() {
return this.ref[5];
}
get rect() {
return new JsiSkRect(this.CanvasKit, Float32Array.of(this.ref[0], this.ref[1], this.ref[2], this.ref[3]));
}
}
//# sourceMappingURL=JsiSkRRect.js.map