UNPKG

@meursyphus/flitter

Version:

Flitter: A high-performance JavaScript rendering engine and framework inspired by Flutter. Features declarative programming, SVG and Canvas support, and optimized for complex data visualizations, interactive charts, and graphic editors in web applications

1,793 lines (1,767 loc) 544 kB
var __defProp = Object.defineProperty; var __defProps = Object.defineProperties; var __getOwnPropDescs = Object.getOwnPropertyDescriptors; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __typeError = (msg) => { throw TypeError(msg); }; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); var __objRest = (source, exclude) => { var target = {}; for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop]; if (source != null && __getOwnPropSymbols) for (var prop of __getOwnPropSymbols(source)) { if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop]; } return target; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method); // src/framework/renderer/canvas/layer.ts var Layer = class { constructor() { __publicField(this, "attached", false); __publicField(this, "owner"); } attach(owner) { this.attached = true; this.owner = owner; } }; var _paintBounds; var PictureLayer = class extends Layer { constructor(paintBounds) { super(); __privateAdd(this, _paintBounds); __publicField(this, "picture"); __privateSet(this, _paintBounds, paintBounds); } addToScene(builder) { builder.addPicture({ x: __privateGet(this, _paintBounds).left, y: __privateGet(this, _paintBounds).top, picture: this.picture }); } }; _paintBounds = new WeakMap(); var ContainerLayer = class extends Layer { constructor() { super(...arguments); __publicField(this, "children", []); } addToScene(builder) { this.visitChildren((layer) => { layer.addToScene(builder); }); } visitChildren(visitor) { for (const child of this.children) { visitor(child); } } removeAllChildren() { this.children = []; } buildScene(builder) { this.addToScene(builder); } append(child) { this.children.push(child); child.attach(this.owner); } }; var OffsetLayer = class extends ContainerLayer { constructor() { super(...arguments); __publicField(this, "offset"); } }; var _pictures; var SceneBuilder = class { constructor() { __privateAdd(this, _pictures, []); } render(ctx) { for (const { x, y, picture } of __privateGet(this, _pictures)) { ctx.drawImage( picture.toImage(), x, y, picture.size.width, picture.size.height ); } } addPicture(props) { __privateGet(this, _pictures).push(props); } }; _pictures = new WeakMap(); var _source; var Picture = class { constructor(source) { __privateAdd(this, _source); __privateSet(this, _source, source); } toImage() { return __privateGet(this, _source); } get size() { return { width: __privateGet(this, _source).width / window.devicePixelRatio, height: __privateGet(this, _source).height / window.devicePixelRatio }; } }; _source = new WeakMap(); var _source2; var PictureRecorder = class { /** * * @implements: This recorder is currently under implementation and does not actually record but directly reflects on the canvas context. Temporarily, it requires the paintSize immediately. The recorder is intended to manage the drawing order for implementing z-index. Once implemented, it will function as a recorder by not directly drawing on the canvas context but recording the operations. */ constructor(paintBounds) { __privateAdd(this, _source2); __privateSet(this, _source2, document.createElement("canvas")); const dpr = window.devicePixelRatio; __privateGet(this, _source2).width = paintBounds.width * dpr; __privateGet(this, _source2).height = paintBounds.height * dpr; } /** * @implements: This function is still incomplete. So It needs paintSize temporarily. Once completed, it will intercept the CanvasRenderingContext2D API * to record in the recorder. The recorder will log according to the vertical layering order. * When endRecording is called, the recorded content will be returned as a Picture. */ createCanvasContext() { const ctx = __privateGet(this, _source2).getContext("2d"); ctx.scale(window.devicePixelRatio, window.devicePixelRatio); return ctx; } endRecording() { const picture = new Picture(__privateGet(this, _source2)); __privateSet(this, _source2, null); return picture; } }; _source2 = new WeakMap(); // src/framework/BuildOwner.ts var BuildOwner = class { constructor({ onNeedVisualUpdate }) { __publicField(this, "onNeedVisualUpdate"); __publicField(this, "dirtyElements", []); __publicField(this, "globalKeyRegistry", /* @__PURE__ */ new WeakMap()); this.onNeedVisualUpdate = () => onNeedVisualUpdate(); } scheduleFor(elememt) { this.dirtyElements.push(elememt); this.requestVisualUpdate(); } requestVisualUpdate() { this.onNeedVisualUpdate(); } flushBuild() { const dirtyElements = this.dirtyElements; this.dirtyElements = []; dirtyElements.sort((a, b) => a.depth - b.depth).forEach((elememt) => { if (!elememt.dirty) return; elememt.rebuild(); }); } registerGlobalKey(key, elememt) { key.buildOwner = this; this.globalKeyRegistry.set(key, elememt); } findByGlobalKey(key) { const result = this.globalKeyRegistry.get(key); return result; } }; var BuildOwner_default = BuildOwner; // src/type/_types/_data.ts var Data = class { equals(_other) { throw new Error("equals not implemented"); } }; var data_default = Data; // src/type/_types/_calculable.ts var Calculable = class extends data_default { constructor() { super(...arguments); __publicField(this, "isCalculable", true); } plus(_other) { throw Error("plus is not implemented"); } minus(other) { return this.plus(other.multiply(-1)); } multiply(_value) { throw Error("multiply is not implemented"); } }; var calculable_default = Calculable; // src/type/_types/_offset.ts var _Offset = class _Offset extends calculable_default { constructor({ x, y }) { super(); __publicField(this, "x"); __publicField(this, "y"); this.x = x; this.y = y; } static raw({ x, y }) { return new _Offset({ x, y }); } static zero() { return _Offset.raw({ x: 0, y: 0 }); } plus({ x, y }) { if (x === 0 && y === 0) { return this; } return _Offset.raw({ x: this.x + x, y: this.y + y }); } multiply(value) { return _Offset.raw({ x: this.x * value, y: this.y * value }); } equals(other) { return this.x === other.x && this.y === other.y; } minus(other) { return super.minus(other); } }; __publicField(_Offset, "Constants", { zero: Object.freeze(_Offset.raw({ x: 0, y: 0 })) }); var Offset = _Offset; var offset_default = Offset; // src/type/_types/_rect.ts var Rect = class _Rect { constructor(left, top, right, bottom) { this.left = left; this.top = top; this.right = right; this.bottom = bottom; } get width() { return this.right - this.left; } get height() { return this.bottom - this.top; } get shortestSide() { return Math.min(Math.abs(this.width), Math.abs(this.height)); } get longestSide() { return Math.max(Math.abs(this.width), Math.abs(this.height)); } get topLeft() { return new offset_default({ x: this.left, y: this.top }); } get topCenter() { return new offset_default({ x: this.left + this.width / 2, y: this.top }); } get topRight() { return new offset_default({ x: this.right, y: this.top }); } get center() { return new offset_default({ x: this.left + this.width / 2, y: this.top + this.height / 2 }); } static fromLTRB({ left, top, right, bottom }) { return new _Rect(left, top, right, bottom); } static fromLTWH({ left, top, width, height }) { return _Rect.fromLTRB({ left, top, right: left + width, bottom: top + height }); } static fromCircle({ center, radius }) { return _Rect.fromCenter({ center, width: 2 * radius, height: 2 * radius }); } static fromCenter({ center, width, height }) { return _Rect.fromLTRB({ left: center.x - width / 2, top: center.y - height / 2, right: center.x + width / 2, bottom: center.y + height / 2 }); } static fromPoints(a, b) { return _Rect.fromLTRB({ left: Math.min(a.x, b.x), top: Math.min(a.y, b.y), right: Math.max(a.x, b.x), bottom: Math.max(a.y, b.y) }); } inflate(delta) { return _Rect.fromLTRB({ left: this.left - delta, top: this.top - delta, right: this.right + delta, bottom: this.bottom + delta }); } deflate(delta) { return this.inflate(-delta); } }; var rect_default = Rect; // src/type/_types/_alignment.ts var _Alignment = class _Alignment extends calculable_default { constructor({ x, y }) { super(); __publicField(this, "x"); // -1 ~ 1 __publicField(this, "y"); this.x = x; this.y = y; } // -1 ~ 1 plus(other) { return new _Alignment({ x: this.x + other.x, y: this.y + other.y }); } multiply(value) { return new _Alignment({ x: this.x * value, y: this.y * value }); } equals(other) { if (other === this) return true; return this.x === other.x && this.y === other.y; } /** * @deprecated The method should not be used */ equal(other) { return this.equals(other); } add(target) { return new _Alignment({ x: this.x + target.x, y: this.y + target.y }); } alongOffset(other) { const centerX = other.x / 2; const centerY = other.y / 2; return offset_default.raw({ x: centerX + this.x * centerX, y: centerY + this.y * centerY }); } alongSize(other) { const centerX = other.width / 2; const centerY = other.height / 2; return offset_default.raw({ x: centerX + this.x * centerX, y: centerY + this.y * centerY }); } withRect(rect) { const halfWidth = rect.width / 2; const halfHeight = rect.height / 2; return offset_default.raw({ x: rect.left + halfWidth + this.x * halfWidth, y: rect.top + halfHeight + this.y * halfHeight }); } /// Returns a rect of the given size, aligned within given rect as specified /// by this alignment. /// /// For example, a 100×100 size inscribed on a 200×200 rect using /// [Alignment.topLeft] would be the 100×100 rect at the top left of inscribe(size, rect) { const halfWidthDelta = (rect.width - size.width) / 2; const halfHeightDelta = (rect.height - size.height) / 2; return rect_default.fromLTWH({ left: rect.left + halfWidthDelta + this.x * halfWidthDelta, top: rect.top + halfHeightDelta + this.y * halfHeightDelta, width: size.width, height: size.height }); } static lerp({ start, end, t }) { if (start == null && end == null) { return; } if (start == null) { return new _Alignment({ x: lerpDouble(0, end.x, t), y: lerpDouble(0, end.y, t) }); } if (end == null) { return new _Alignment({ x: lerpDouble(start.x, 0, t), y: lerpDouble(start.y, 0, t) }); } return new _Alignment({ x: lerpDouble(start.x, end.x, t), y: lerpDouble(start.y, end.y, t) }); } getOffset({ target, current }) { return new offset_default({ x: (1 + this.x) * (current.width - target.width) / 2, y: (1 + this.y) * (current.height - target.height) / 2 }); } static of({ x, y }) { return new _Alignment({ x, y }); } resolve(_) { return this; } }; __publicField(_Alignment, "topLeft", _Alignment.of({ x: -1, y: -1 })); __publicField(_Alignment, "topCenter", _Alignment.of({ x: 0, y: -1 })); __publicField(_Alignment, "topRight", _Alignment.of({ x: 1, y: -1 })); __publicField(_Alignment, "centerLeft", _Alignment.of({ x: -1, y: 0 })); __publicField(_Alignment, "center", _Alignment.of({ x: 0, y: 0 })); __publicField(_Alignment, "centerRight", _Alignment.of({ x: 1, y: 0 })); __publicField(_Alignment, "bottomLeft", _Alignment.of({ x: -1, y: 1 })); __publicField(_Alignment, "bottomCenter", _Alignment.of({ x: 0, y: 1 })); __publicField(_Alignment, "bottomRight", _Alignment.of({ x: 1, y: 1 })); var Alignment = _Alignment; var alignment_default = Alignment; function lerpDouble(a, b, t) { if (t > 1 || t < 0) throw new Error("value must be between 0 and 1: " + t.toString()); return a + (b - a) * t; } // src/utils/assert.ts function assert(condition, message) { if (!condition) { throw new Error(message || "Assertion failed"); } } // src/utils/lerp.ts function lerp(a, b, t) { return a + (b - a) * t; } var lerp_default = lerp; // src/utils/getTextSize.ts var OFFSET = 20; var SCALE = 100; var defaultWidthMapStr = "007LLmW'55;N0500LLLLLLLLLL00NNNLzWW\\\\WQb\\0FWLg\\bWb\\WQ\\WrWWQ000CL5LLFLL0LL**F*gLLLL5F0LF\\FFF5.5N"; var DEFAULT_FONT_SIZE = 12; var DEFAULT_FONT_FAMILY = "sans-serif"; var DEFAULT_FONT = `${DEFAULT_FONT_SIZE}px ${DEFAULT_FONT_FAMILY}`; function getTextWidthMap(mapStr) { const map = {}; if (typeof JSON === "undefined") { return map; } for (let i = 0; i < mapStr.length; i++) { const char = String.fromCharCode(i + 32); const size = (mapStr.charCodeAt(i) - OFFSET) / SCALE; map[char] = size; } return map; } var DEFAULT_TEXT_WIDTH_MAP = getTextWidthMap(defaultWidthMapStr); var _ctx; function getCtxOrNull() { if (typeof window === "undefined") { return null; } if (_ctx == null) { _ctx = document.createElement("canvas").getContext("2d"); } return _ctx; } function getTextWidth({ text, font }) { const ctx = getCtxOrNull(); if (ctx != null) { ctx.font = font; const width2 = Math.ceil(ctx.measureText(text).width); return width2; } const res = /(\d+)px/.exec(font); const fontSize = res && +res[1] || DEFAULT_FONT_SIZE; let width = 0; if (font.indexOf("mono") >= 0) { width = fontSize * text.length; } else { for (let i = 0; i < text.length; i++) { const preCalcWidth = DEFAULT_TEXT_WIDTH_MAP[text[i]]; width += preCalcWidth == null ? fontSize : preCalcWidth * fontSize; } } return Math.ceil(width); } // src/utils/classToFunction.ts function classToFunction(Clazz) { return (...args) => new Clazz(...args); } var classToFunction_default = classToFunction; // src/utils/createUniqueId.ts var id = 1; function createUniqueId() { return (id++).toString(); } // src/utils/environment.ts var browser = typeof window !== "undefined"; // src/utils/index.ts var _Utils = class _Utils { static sum(values) { return values.reduce(_Utils.sumReducer, 0); } static repeat(value, count) { return Array.from({ length: count }, () => value); } static clampDouble(value, min, max) { return Math.min(max, Math.max(min, value)); } static arrayEqual(a, b) { if (a.length !== b.length) return false; return a.every((value, i) => value === b[i]); } static lerp(a, b, t) { assert(t >= 0 && t <= 1); if (typeof a === "number") { return lerp_default(a, b, t); } assert(b == null ? void 0 : b.isCalculable, "b is not a Calculable"); return a.plus(b.minus(a).multiply(t)); } }; __publicField(_Utils, "sumReducer", (acc, value) => acc + value); __publicField(_Utils, "maxReducer", (acc, value) => Math.max(acc, value)); __publicField(_Utils, "minReducer", (acc, value) => Math.min(acc, value)); var Utils = _Utils; // src/type/_types/_size.ts var _Size = class _Size { constructor({ width, height }) { __publicField(this, "width"); __publicField(this, "height"); this.width = width; this.height = height; } equal(other) { if (this === other) return true; return this.width === other.width && this.height === other.height; } static maximum() { return new _Size({ width: Infinity, height: Infinity }); } get isFinite() { return Number.isFinite(this.width) && Number.isFinite(this.height); } get shortest() { return Math.min(this.width, this.height); } get longest() { return Math.max(this.width, this.height); } minus(other) { return new offset_default({ x: this.width - other.width, y: this.height - other.height }); } }; __publicField(_Size, "zero", new _Size({ width: 0, height: 0 })); //depricated because javascript is vernerable for unexpected mutating variable __publicField(_Size, "infinite", new _Size({ width: Infinity, height: Infinity })); var Size = _Size; var size_default = Size; // src/type/_types/_constraints.ts var Constraints = class _Constraints extends data_default { constructor({ maxHeight = Infinity, maxWidth = Infinity, minHeight = 0, minWidth = 0 } = {}) { super(); __publicField(this, "minWidth"); __publicField(this, "maxWidth"); __publicField(this, "minHeight"); __publicField(this, "maxHeight"); this.minWidth = minWidth; this.maxWidth = maxWidth; this.minHeight = minHeight; this.maxHeight = maxHeight; } static lerp(a, b, t) { _Constraints.validateInterpolation(a, b); return new _Constraints({ minWidth: _Constraints.interpolateDimension(a.minWidth, b.minWidth, t), maxWidth: _Constraints.interpolateDimension(a.maxWidth, b.maxWidth, t), minHeight: _Constraints.interpolateDimension(a.minHeight, b.minHeight, t), maxHeight: _Constraints.interpolateDimension(a.maxHeight, b.maxHeight, t) }); } static validateInterpolation(a, b) { const dimensions = ["minWidth", "maxWidth", "minHeight", "maxHeight"]; dimensions.forEach((dimension) => { assert( Number.isFinite(a[dimension]) && Number.isFinite(b[dimension]) || a[dimension] === Infinity && b[dimension] === Infinity, "Cannot interpolate between finite constraints and unbounded constraints." ); }); } static interpolateDimension(aValue, bValue, t) { return Number.isFinite(aValue) ? Utils.lerp(aValue, bValue, t) : Infinity; } static expand({ width = Infinity, height = Infinity } = {}) { return new _Constraints({ maxHeight: height, minHeight: height, maxWidth: width, minWidth: width }); } static zero() { return new _Constraints({ minHeight: 0, maxHeight: 0, minWidth: 0, maxWidth: 0 }); } static loose(size) { return new _Constraints({ minHeight: 0, maxHeight: size.height, minWidth: 0, maxWidth: size.width }); } static tight({ width, height }) { return _Constraints.tightFor({ width, height }); } static tightFor({ width, height }) { return new _Constraints({ maxHeight: height != null ? height : Infinity, minHeight: height != null ? height : 0, maxWidth: width != null ? width : Infinity, minWidth: width != null ? width : 0 }); } enforce(parent) { const minWidth = parent.constrainWidth(this.minWidth); const maxWidth = parent.constrainWidth(this.maxWidth); const minHeight = parent.constrainHeight(this.minHeight); const maxHeight = parent.constrainHeight(this.maxHeight); if (minWidth === maxWidth && minHeight === maxHeight && this.maxWidth === maxWidth && this.maxHeight === maxHeight) { return this; } return new _Constraints({ minWidth, maxWidth, minHeight, maxHeight }); } loosen() { return new _Constraints(__spreadProps(__spreadValues({}, this), { minHeight: 0, minWidth: 0 })); } constrain({ width, height }) { return new size_default({ width: this.constrainWidth(width), height: this.constrainHeight(height) }); } normalize() { if (this.minWidth <= this.maxWidth && this.minHeight <= this.maxHeight) { return this; } return new _Constraints({ maxHeight: Math.max(this.maxHeight, this.minHeight), minHeight: Math.min(this.minHeight, this.maxHeight), maxWidth: Math.max(this.maxWidth, this.minWidth), minWidth: Math.min(this.minWidth, this.maxWidth) }); } getMax(key) { return key === "width" ? this.maxWidth : this.maxHeight; } getMin(key) { return key === "width" ? this.minWidth : this.minHeight; } get hasTightWidth() { return this.maxWidth === this.minWidth; } get hasTightHeight() { return this.maxHeight === this.minHeight; } get isTight() { return this.hasTightWidth && this.hasBoundedHeight; } get hasBoundedWidth() { return this.maxWidth !== Infinity; } get hasBoundedHeight() { return this.maxHeight !== Infinity; } get isUnbounded() { return !this.hasBoundedHeight && !this.hasBoundedWidth; } get hasInfiniteWidth() { return this.minWidth >= Infinity; } get hasInfiniteHeight() { return this.minHeight >= Infinity; } copyWith({ maxHeight, maxWidth, minHeight, minWidth }) { return new _Constraints({ minHeight: minHeight != null ? minHeight : this.minHeight, maxHeight: maxHeight != null ? maxHeight : this.maxHeight, minWidth: minWidth != null ? minWidth : this.minWidth, maxWidth: maxWidth != null ? maxWidth : this.maxWidth }); } // Return new box constraints that are smaller by the given dimensions. deflate(edge) { const horizontal = edge.horizontal; const vertical = edge.vertical; const deflatedMinWidth = Math.max(0, this.minWidth - horizontal); const deflatedMinHeight = Math.max(0, this.minHeight - vertical); return new _Constraints({ minWidth: deflatedMinWidth, maxWidth: Math.max(deflatedMinWidth, this.maxWidth - horizontal), minHeight: deflatedMinHeight, maxHeight: Math.max(deflatedMinHeight, this.maxHeight - vertical) }); } constrainWidth(width = Infinity) { return this.clampDouble(width, this.minWidth, this.maxWidth); } constrainHeight(height = Infinity) { return this.clampDouble(height, this.minHeight, this.maxHeight); } tighten({ width, height }) { return new _Constraints({ minWidth: width == null ? this.minWidth : this.clampDouble(width, this.minWidth, this.maxWidth), maxWidth: width == null ? this.maxWidth : this.clampDouble(width, this.minWidth, this.maxWidth), minHeight: height == null ? this.minHeight : this.clampDouble(height, this.minHeight, this.maxHeight), maxHeight: height == null ? this.maxHeight : this.clampDouble(height, this.minHeight, this.maxHeight) }); } widthConstraints() { return new _Constraints({ minWidth: this.minWidth, maxWidth: this.maxWidth }); } heightConstraints() { return new _Constraints({ minHeight: this.minHeight, maxHeight: this.maxHeight }); } get smallest() { return new size_default({ width: this.constrainWidth(0), height: this.constrainHeight(0) }); } get biggest() { return new size_default({ width: this.constrainWidth(), height: this.constrainHeight() }); } /** * @deprecated The method should not be used */ equal(other) { return this.equals(other); } equals(other) { if (this === other) return true; return this.maxWidth === other.maxWidth && this.minWidth === other.minWidth && this.maxHeight === other.maxHeight && this.minHeight === other.minHeight; } clampDouble(value, min, max) { return Math.min(max, Math.max(min, value)); } }; var constraints_default = Constraints; // src/type/_types/edge-insets.ts var EdgeInsetsGeometry = class _EdgeInsetsGeometry extends calculable_default { constructor({ top, bottom, left, right }) { super(); __publicField(this, "top"); __publicField(this, "bottom"); __publicField(this, "left"); __publicField(this, "right"); this.top = top; this.bottom = bottom; this.left = left; this.right = right; } plus(other) { return new _EdgeInsetsGeometry({ top: this.top + other.top, bottom: this.bottom + other.bottom, left: this.left + other.left, right: this.right + other.right }); } multiply(value) { return new _EdgeInsetsGeometry({ top: this.top * value, bottom: this.bottom * value, left: this.left * value, right: this.right * value }); } equals(other) { if (this === other) return; return this.top === other.top && this.bottom === other.bottom && this.left === other.left && this.right === other.right; } /** * @deprecated The method should not be used * Instead use elquals */ eqaul(other) { return this.equals(other); } get horizontal() { return this.left + this.right; } get vertical() { return this.top + this.bottom; } deflateRect(rect) { return rect_default.fromLTRB({ left: rect.left + this.left, top: rect.top + this.top, bottom: rect.bottom - this.bottom, right: rect.right - this.right }); } add(outer) { return new _EdgeInsetsGeometry({ left: this.left + outer.left, right: this.right + outer.right, bottom: this.bottom + outer.bottom, top: this.top + outer.top }); } }; var EdgeInsets = class _EdgeInsets extends EdgeInsetsGeometry { static all(value) { return new _EdgeInsets({ top: value, bottom: value, left: value, right: value }); } static symmetric({ horizontal = 0, vertical = 0 }) { return new _EdgeInsets({ top: vertical, bottom: vertical, left: horizontal, right: horizontal }); } static only({ top = 0, bottom = 0, left = 0, right = 0 }) { return new _EdgeInsets({ top, bottom, left, right }); } static fromLTRB({ left, right, top, bottom }) { return new _EdgeInsets({ left, right, bottom, top }); } }; var edge_insets_default = EdgeInsets; // src/type/_types/_gap.ts var Gap = class _Gap { constructor({ x = 0, y = 0 }) { __publicField(this, "x"); __publicField(this, "y"); this.x = x; this.y = y; } static only({ x = 0, y = 0 }) { return new _Gap({ x, y }); } static all(value) { return new _Gap({ x: value, y: value }); } }; var gap_default = Gap; // src/type/_types/border-radius-geometry.ts var BorderRadiusGeometry = class extends calculable_default { constructor({ topLeft, topRight, bottomLeft, bottomRight }) { super(); __publicField(this, "topLeft"); __publicField(this, "topRight"); __publicField(this, "bottomLeft"); __publicField(this, "bottomRight"); this.bottomLeft = bottomLeft; this.bottomRight = bottomRight; this.topLeft = topLeft; this.topRight = topRight; } static lerp(a, b, t) { const result = Utils.lerp(a, b, t); return result; } equals(other) { if (this === other) return true; return this.topLeft.equals(other.topLeft) && this.topRight.equals(other.topRight) && this.bottomLeft.equals(other.bottomLeft) && this.bottomRight.equals(other.bottomRight); } /** * @deprecated The method should not be used */ equal(other) { return this.equals(other); } toRRect(_rect) { throw new Error("Not implemented"); } }; var border_radius_geometry_default = BorderRadiusGeometry; // src/type/_types/_path.ts var Path = class _Path { constructor() { __publicField(this, "_d", ""); } getD() { return this._d; } moveTo(point) { return this._moveTo(point, false); } relativeMoveTo(point) { return this._moveTo(point, true); } lineTo(point) { return this._lineTo(point, false); } relativeLineTo(point) { return this._lineTo(point, true); } quadraticBezierTo(props) { return this._quadraticBezierTo(props, false); } relativeQuadraticBezierTo(props) { return this._quadraticBezierTo(props, true); } cubicTo(props) { return this._cubicTo(props, false); } relativeCubicTo(props) { return this._cubicTo(props, true); } arcToPoint(props) { return this._arcToPoint(props, false); } relativeArcToPoint(props) { return this._arcToPoint(props, true); } addRect(rect) { return this.moveTo({ x: rect.left, y: rect.top }).lineTo({ x: rect.right, y: rect.top }).lineTo({ x: rect.right, y: rect.bottom }).lineTo({ x: rect.left, y: rect.bottom }).close(); } addRRect(rRect, { clockwise = true } = {}) { if (rRect.width == 0 || rRect.height == 0) { return this; } const { left, right, top, bottom, tlRadiusX, tlRadiusY, trRadiusX, trRadiusY, blRadiusX, blRadiusY, brRadiusX, brRadiusY } = rRect; const common = { rotation: 0, largeArc: false, clockwise }; const points = [ { x: left, y: top + tlRadiusY }, { x: left + tlRadiusX, y: top }, { x: right - trRadiusX, y: top }, { x: right, y: top + trRadiusY }, { x: right, y: bottom - brRadiusY }, { x: right - brRadiusX, y: bottom }, { x: left + blRadiusX, y: bottom }, { x: left, y: bottom - blRadiusY } ]; const radiuses = [ { x: tlRadiusX, y: tlRadiusY }, { x: trRadiusX, y: trRadiusY }, { x: brRadiusX, y: brRadiusY }, { x: blRadiusX, y: blRadiusY } ]; if (!clockwise) { points.reverse(); radiuses.reverse(); } return this.moveTo(points[0]).arcToPoint(__spreadProps(__spreadValues({}, common), { radius: radiuses[0], endPoint: points[1] })).lineTo(points[2]).arcToPoint(__spreadProps(__spreadValues({}, common), { radius: radiuses[1], endPoint: points[3] })).lineTo(points[4]).arcToPoint(__spreadProps(__spreadValues({}, common), { radius: radiuses[2], endPoint: points[5] })).lineTo(points[6]).arcToPoint(__spreadProps(__spreadValues({}, common), { radius: radiuses[3], endPoint: points[7] })).close(); } addDRRect({ inner, outer }) { return new _Path().addRRect(outer).addRRect(inner, { clockwise: false }); } addOval(rect) { const common = { rotation: 0, radius: { x: rect.width / 2, y: rect.height / 2 }, largeArc: false, clockwise: true }; const point1 = { x: rect.left, y: (rect.top + rect.bottom) / 2 }; const point2 = { x: rect.right, y: (rect.top + rect.bottom) / 2 }; return this.moveTo(point1).arcToPoint(__spreadProps(__spreadValues({}, common), { endPoint: point2 })).arcToPoint(__spreadProps(__spreadValues({}, common), { endPoint: point1 })).close(); } addPolygons(points) { if (points.length < 3) throw Error("polygons need at least 3 points"); this.moveTo(points[0]); points.slice(1).forEach((point) => this.lineTo(point)); return this.close(); } close() { this._d += "Z"; return this; } _quadraticBezierTo({ controlPoint, endPoint }, relative) { this._d += `${relative ? "q" : "Q"}${controlPoint.x} ${controlPoint.y} ${endPoint.x} ${endPoint.y}`; return this; } _lineTo({ x, y }, relative) { this._d += `${relative ? "l" : "L"}${x} ${y}`; return this; } _moveTo({ x, y }, relative) { this._d += `${relative ? "m" : "M"}${x} ${y}`; return this; } _cubicTo({ startControlPoint, endControlPoint, endPoint }, relative) { this._d += `${relative ? "c" : "C"}${startControlPoint.x} ${startControlPoint.y} ${endControlPoint.x} ${endControlPoint.y} ${endPoint.x} ${endPoint.y}`; return this; } _arcToPoint({ endPoint, radius, rotation, largeArc, clockwise }, relative) { this._d += `${relative ? "a" : "A"}${radius.x} ${radius.y} ${rotation} ${largeArc ? 1 : 0} ${clockwise ? 1 : 0} ${endPoint.x} ${endPoint.y}`; return this; } toCanvasPath() { return new Path2D(this._d); } }; var path_default = Path; // src/type/_types/_radius.ts var _Radius = class _Radius extends calculable_default { constructor(x, y) { super(); __publicField(this, "x"); __publicField(this, "y"); this.x = x; this.y = y; } static circular(r) { return _Radius.elliptical({ x: r, y: r }); } static elliptical({ x, y }) { return new _Radius(x, y); } plus(other) { return new _Radius(this.x + other.x, this.y + other.y); } multiply(value) { return new _Radius(this.x * value, this.y * value); } equals(other) { if (this === other) return true; return this.x === other.x && this.y === other.y; } /** * @deprecated The method should not be used */ equal(other) { return this.equals(other); } clamp({ minimum, maximum }) { minimum != null ? minimum : minimum = _Radius.circular(-Infinity); maximum != null ? maximum : maximum = _Radius.circular(Infinity); return _Radius.elliptical({ x: Utils.clampDouble(this.x, minimum.x, maximum.x), y: Utils.clampDouble(this.y, minimum.y, maximum.y) }); } clampValues({ maximumX = Infinity, maximumY = Infinity, minimumX = -Infinity, minimumY = -Infinity }) { return _Radius.elliptical({ x: Utils.clampDouble(this.x, minimumX, maximumX), y: Utils.clampDouble(this.y, minimumY, maximumY) }); } }; __publicField(_Radius, "zero", _Radius.circular(0)); var Radius = _Radius; var radius_default = Radius; // src/type/_types/r-rect.ts var RRect = class _RRect { constructor(top, left, bottom, right, tlRadiusX, tlRadiusY, blRadiusX, blRadiusY, trRadiusX, trRadiusY, brRadiusX, brRadiusY) { this.top = top; this.left = left; this.bottom = bottom; this.right = right; this.tlRadiusX = tlRadiusX; this.tlRadiusY = tlRadiusY; this.blRadiusX = blRadiusX; this.blRadiusY = blRadiusY; this.trRadiusX = trRadiusX; this.trRadiusY = trRadiusY; this.brRadiusX = brRadiusX; this.brRadiusY = brRadiusY; } get width() { return this.right - this.left; } get height() { return this.bottom - this.top; } static fromLTRBXY({ left, top, right, bottom, radiusX, radiusY }) { return this.raw({ top, left, right, bottom, tlRadiusX: radiusX, tlRadiusY: radiusY, trRadiusX: radiusX, trRadiusY: radiusY, blRadiusX: radiusX, blRadiusY: radiusY, brRadiusX: radiusX, brRadiusY: radiusY }); } static fromLTRBR({ left, radius, top, right, bottom }) { return this.fromLTRBXY({ left, top, right, bottom, radiusX: radius.x, radiusY: radius.y }); } static fromRectXY({ radiusX, radiusY, rect }) { return this.raw({ top: rect.top, left: rect.left, right: rect.right, bottom: rect.bottom, tlRadiusX: radiusX, tlRadiusY: radiusY, trRadiusX: radiusX, trRadiusY: radiusY, blRadiusX: radiusX, blRadiusY: radiusY, brRadiusX: radiusX, brRadiusY: radiusY }); } static fromRecAndRadius({ radius, rect }) { return this.fromRectXY({ radiusX: radius.x, radiusY: radius.y, rect }); } static fromLTRBAndCorners({ left, right, bottom, top, topLeft = radius_default.zero, topRight = radius_default.zero, bottomLeft = radius_default.zero, bottomRight = radius_default.zero }) { return this.raw({ left, right, bottom, top, tlRadiusX: topLeft.x, tlRadiusY: topLeft.y, trRadiusX: topRight.x, trRadiusY: topRight.y, blRadiusX: bottomLeft.x, blRadiusY: bottomLeft.y, brRadiusX: bottomRight.x, brRadiusY: bottomRight.y }); } static fromRectAndCorners({ rect, topLeft = radius_default.zero, topRight = radius_default.zero, bottomLeft = radius_default.zero, bottomRight = radius_default.zero }) { return this.fromLTRBAndCorners({ left: rect.left, right: rect.right, bottom: rect.bottom, top: rect.top, topLeft, topRight, bottomLeft, bottomRight }); } static raw({ top, left, bottom, right, tlRadiusX, tlRadiusY, blRadiusX, blRadiusY, trRadiusX, trRadiusY, brRadiusX, brRadiusY }) { return new _RRect( top, left, bottom, right, tlRadiusX, tlRadiusY, blRadiusX, blRadiusY, trRadiusX, trRadiusY, brRadiusX, brRadiusY ); } inflate(delta) { return _RRect.raw({ left: this.left - delta, top: this.top - delta, right: this.right + delta, bottom: this.bottom + delta, tlRadiusX: Math.max(0, this.tlRadiusX + delta), trRadiusX: Math.max(0, this.trRadiusX + delta), blRadiusX: Math.max(0, this.blRadiusX + delta), brRadiusX: Math.max(0, this.brRadiusX + delta), tlRadiusY: Math.max(0, this.tlRadiusY + delta), trRadiusY: Math.max(0, this.trRadiusY + delta), blRadiusY: Math.max(0, this.blRadiusY + delta), brRadiusY: Math.max(0, this.brRadiusY + delta) }); } deflate(delta) { return this.inflate(-delta); } }; var r_rect_default = RRect; // src/type/_types/text-direction.ts var TextDirection = /* @__PURE__ */ ((TextDirection2) => { TextDirection2[TextDirection2["rtl"] = 1] = "rtl"; TextDirection2[TextDirection2["ltr"] = 2] = "ltr"; return TextDirection2; })(TextDirection || {}); var text_direction_default = TextDirection; // src/type/_types/_etc.ts var MainAxisSize = /* @__PURE__ */ ((MainAxisSize2) => { MainAxisSize2[MainAxisSize2["min"] = 1] = "min"; MainAxisSize2[MainAxisSize2["max"] = 2] = "max"; return MainAxisSize2; })(MainAxisSize || {}); var VerticalDirection = /* @__PURE__ */ ((VerticalDirection2) => { VerticalDirection2[VerticalDirection2["up"] = 1] = "up"; VerticalDirection2[VerticalDirection2["down"] = 2] = "down"; return VerticalDirection2; })(VerticalDirection || {}); var MainAxisAlignment = /* @__PURE__ */ ((MainAxisAlignment2) => { MainAxisAlignment2[MainAxisAlignment2["start"] = 1] = "start"; MainAxisAlignment2[MainAxisAlignment2["end"] = 2] = "end"; MainAxisAlignment2[MainAxisAlignment2["center"] = 3] = "center"; MainAxisAlignment2[MainAxisAlignment2["spaceBetween"] = 4] = "spaceBetween"; MainAxisAlignment2[MainAxisAlignment2["spaceAround"] = 5] = "spaceAround"; MainAxisAlignment2[MainAxisAlignment2["spaceEvenly"] = 6] = "spaceEvenly"; return MainAxisAlignment2; })(MainAxisAlignment || {}); var CrossAxisAlignment = /* @__PURE__ */ ((CrossAxisAlignment2) => { CrossAxisAlignment2[CrossAxisAlignment2["start"] = 1] = "start"; CrossAxisAlignment2[CrossAxisAlignment2["end"] = 2] = "end"; CrossAxisAlignment2[CrossAxisAlignment2["center"] = 3] = "center"; CrossAxisAlignment2[CrossAxisAlignment2["stretch"] = 4] = "stretch"; return CrossAxisAlignment2; })(CrossAxisAlignment || {}); var Axis = /* @__PURE__ */ ((Axis2) => { Axis2[Axis2["horizontal"] = 1] = "horizontal"; Axis2[Axis2["vertical"] = 2] = "vertical"; return Axis2; })(Axis || {}); // src/type/_types/_matrix3.ts var Matrix3 = class _Matrix3 { constructor(...args) { __publicField(this, "_m3storage"); this._m3storage = args; } get storage() { return this._m3storage; } static zero() { return new _Matrix3(0, 0, 0, 0, 0, 0, 0, 0, 0); } }; var matrix3_default = Matrix3; // src/type/_types/_vector4.ts var Vector4 = class _Vector4 { constructor(arg0, arg1, arg2, arg3) { __publicField(this, "type", "v4"); __publicField(this, "_v4storage"); this._v4storage = [arg0, arg1, arg2, arg3]; } get storage() { return this._v4storage; } static zero() { return new _Vector4(0, 0, 0, 0); } set xy(arg) { const argStorage = arg._v2storage; this._v4storage[0] = argStorage[0]; this._v4storage[1] = argStorage[1]; } set xz(arg) { const argStorage = arg._v2storage; this._v4storage[0] = argStorage[0]; this._v4storage[2] = argStorage[1]; } set xw(arg) { const argStorage = arg._v2storage; this._v4storage[0] = argStorage[0]; this._v4storage[3] = argStorage[1]; } set yx(arg) { const argStorage = arg._v2storage; this._v4storage[1] = argStorage[0]; this._v4storage[0] = argStorage[1]; } set yz(arg) { const argStorage = arg._v2storage; this._v4storage[1] = argStorage[0]; this._v4storage[2] = argStorage[1]; } set yw(arg) { const argStorage = arg._v2storage; this._v4storage[1] = argStorage[0]; this._v4storage[3] = argStorage[1]; } set zx(arg) { const argStorage = arg._v2storage; this._v4storage[2] = argStorage[0]; this._v4storage[0] = argStorage[1]; } set zy(arg) { const argStorage = arg._v2storage; this._v4storage[2] = argStorage[0]; this._v4storage[1] = argStorage[1]; } set zw(arg) { const argStorage = arg._v2storage; this._v4storage[2] = argStorage[0]; this._v4storage[3] = argStorage[1]; } set wx(arg) { const argStorage = arg._v2storage; this._v4storage[3] = argStorage[0]; this._v4storage[0] = argStorage[1]; } set wy(arg) { const argStorage = arg._v2storage; this._v4storage[3] = argStorage[0]; this._v4storage[1] = argStorage[1]; } set wz(arg) { const argStorage = arg._v2storage; this._v4storage[3] = argStorage[0]; this._v4storage[2] = argStorage[1]; } set xyz(arg) { const argStorage = arg._v3storage; this._v4storage[0] = argStorage[0]; this._v4storage[1] = argStorage[1]; this._v4storage[2] = argStorage[2]; } set xyw(arg) { const argStorage = arg._v3storage; this._v4storage[0] = argStorage[0]; this._v4storage[1] = argStorage[1]; this._v4storage[3] = argStorage[2]; } set xzy(arg) { const argStorage = arg._v3storage; this._v4storage[0] = argStorage[0]; this._v4storage[2] = argStorage[1]; this._v4storage[1] = argStorage[2]; } set xzw(arg) { const argStorage = arg._v3storage; this._v4storage[0] = argStorage[0]; this._v4storage[2] = argStorage[1]; this._v4storage[3] = argStorage[2]; } set xwy(arg) { const argStorage = arg._v3storage; this._v4storage[0] = argStorage[0]; this._v4storage[3] = argStorage[1]; this._v4storage[1] = argStorage[2]; } set xwz(arg) { const argStorage = arg._v3storage; this._v4storage[0] = argStorage[0]; this._v4storage[3] = argStorage[1]; this._v4storage[2] = argStorage[2]; } set yxz(arg) { const argStorage = arg._v3storage; this._v4storage[1] = argStorage[0]; this._v4storage[0] = argStorage[1]; this._v4storage[2] = argStorage[2]; } set yxw(arg) { const argStorage = arg._v3storage; this._v4storage[1] = argStorage[0]; this._v4storage[0] = argStorage[1]; this._v4storage[3] = argStorage[2]; } set yzx(arg) { const argStorage = arg._v3storage; this._v4storage[1] = argStorage[0]; this._v4storage[2] = argStorage[1]; this._v4storage[0] = argStorage[2]; } set yzw(arg) { const argStorage = arg._v3storage; this._v4storage[1] = argStorage[0]; this._v4storage[2] = argStorage[1]; this._v4storage[3] = argStorage[2]; } set ywx(arg) { const argStorage = arg._v3storage; this._v4storage[1] = argStorage[0]; this._v4storage[3] = argStorage[1]; this._v4storage[0] = argStorage[2]; } set ywz(arg) { const argStorage = arg._v3storage; this._v4storage[1] = argStorage[0]; this._v4storage[3] = argStorage[1]; this._v4storage[2] = argStorage[2]; } set zxy(arg) { const argStorage = arg._v3storage; this._v4storage[2] = argStorage[0]; this._v4storage[0] = argStorage[1]; this._v4storage[1] = argStorage[2]; } set zxw(arg) { const argStorage = arg._v3storage; this._v4storage[2] = argStorage[0]; this._v4storage[0] = argStorage[1]; this._v4storage[3] = argStorage[2]; } set zyx(arg) { const argStorage = arg._v3storage; this._v4storage[2] = argStorage[0]; this._v4storage[1] = argStorage[1]; this._v4storage[0] = argStorage[2]; } set zyw(arg) { const argStorage = arg._v3storage; this._v4storage[2] = argStorage[0]; this._v4storage[1] = argStorage[1]; this._v4storage[3] = argStorage[2]; } set zwx(arg) { const argStorage = arg._v3storage; this._v4storage[2] = argStorage[0]; this._v4storage[3] = argStorage[1]; this._v4storage[0] = argStorage[2]; } set zwy(arg) { const argStorage = arg._v3storage; this._v4storage[2] = argStorage[0]; this._v4storage[3] = argStorage[1]; this._v4storage[1] = argStorage[2]; } set wxy(arg) { const argStorage = arg._v3storage; this._v4storage[3] = argStorage[0]; this._v4storage[0] = argStorage[1]; this._v4storage[1] = argStorage[2]; } set wxz(arg) { const argStorage = arg._v3storage; this._v4storage[3] = argStorage[0]; this._v4storage[0] = argStorage[1]; this._v4storage[2] = argStorage[2]; } set wyx(arg) { const argStorage = arg._v3storage; this._v4storage[3] = argStorage[0]; this._v4storage[1] = argStorage[1]; this._v4storage[0] = argStorage[2]; } set wyz(arg) { const argStorage = arg._v3storage; this._v4storage[3] = argStorage[0]; this._v4storage[1] = argStorage[1]; this._v4storage[2] = argStorage[2]; } set wzx(arg) { const argStorage = arg._v3storage; this._v4storage[3] = argStorage[0]; this._v4storage[2] = argStorage[1]; this._v4storage[0] = argStorage[2]; } set wzy(arg) { const argStorage = arg._v3storage; this._v4storage[3] = argStorage[0]; this._v4storage[2] = argStorage[1]; this._v4storage[1] = argStorage[2]; } set xyzw(arg) { const argStorage = arg._v4storage; this._v4storage[0] = argStorage[0]; this._v4storage[1] = argStorage[1]; this._v4storage[2] = argStorage[2]; this._v4storage[3] = argStorage[3]; } set xywz(arg) { const argStorage = arg._v4storage; this._v4storage[0] = argStorage[0]; this._v4storage[1] = argStorage[1]; this._v4storage[3] = argStorage[2]; this._v4storage[2] = argStorage[3]; } set xzyw(arg) { const argStorage = arg._v4storage; this._v4storage[0] = argStorage[0]; this._v4storage[2] = argStorage[1]; this._v4storage[1] = argStorage[2]; this._v4storage[3] = argStorage[3]; } set xzwy(arg) { const argStorage = arg._v4storage; this._v4storage[0] = argStorage[0]; this._v4storage[2] = argStorage[1]; this._v4storage[3] = argStorage[2]; this._v4storage[1] = argStorage[3]; } set xwyz(arg) { const argStorage = arg._v4storage; this._v4storage[0] = argStorage[0]; this._v4storage[3] = argStorage[1]; this._v4storage[1] = argStorage[2]; this._v4storage[2] = argStorage[3]; } set xwzy(arg) { const argStorage = arg._v4storage; this._v4storage[0] = argStorage[0]; this._v4storage[3] = argStorage[1]; this._v4storage[2] = argStorage[2]; this._v4storage[1] = argStorage[3]; } set yxzw(arg) { const argStorage = arg._v4storage; this._v4storage[1] = argStorage[0]; this._v4storage[0] = argStorage[1]; this._v4storage[2] = argStorage[2]; this._v4storage[3] = argStorage[3]; } set yxwz(arg) { const argStorage = arg._v4storage; this._v4storage[1] = argStorage[0]; this._v4storage[0] = argStorage[1]; this._v4storage[3] = argStorage[2]; this._v4storage[2] = argStorage[3]; } set yzxw(arg) { const argStorage = arg._v4storage; this._v4storage[1] = argStorage[0]; this._v4storage[2] = argStorage[1]; this._v4storage[0] = argStorage[2]; this._v4storage[3] = argStorage[3]; } set yzwx(arg) { const argStorage = arg._v4storage; this._v4storage[1] = argStorage[0]; this._v4storage[2] = argStorage[1]; this._v4storage[3] = argStorage[2]; this._v4storage[0] = argStorage[3]; } set ywxz(arg) { const argStorage = arg._v4storage; this._v4storage[1] = argStorage[0]; this._v4storage[3] = argStorage[1]; this._v4storage[0] = argStorage[2]; this._v4storage[2] = argStorage[3]; } set ywzx(arg) { const argStorage = arg._v4storage; this._v4storage[1] = argStorage[0]; this._v4storage[3] = argS