@tldraw/tlschema
Version:
A tiny little drawing app (schema).
83 lines (82 loc) • 2.96 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var TLDrawShape_exports = {};
__export(TLDrawShape_exports, {
DrawShapeSegment: () => DrawShapeSegment,
drawShapeMigrations: () => drawShapeMigrations,
drawShapeProps: () => drawShapeProps,
drawShapeVersions: () => Versions
});
module.exports = __toCommonJS(TLDrawShape_exports);
var import_validate = require("@tldraw/validate");
var import_geometry_types = require("../misc/geometry-types");
var import_TLShape = require("../records/TLShape");
var import_TLColorStyle = require("../styles/TLColorStyle");
var import_TLDashStyle = require("../styles/TLDashStyle");
var import_TLFillStyle = require("../styles/TLFillStyle");
var import_TLSizeStyle = require("../styles/TLSizeStyle");
const DrawShapeSegment = import_validate.T.object({
type: import_validate.T.literalEnum("free", "straight"),
points: import_validate.T.arrayOf(import_geometry_types.vecModelValidator)
});
const drawShapeProps = {
color: import_TLColorStyle.DefaultColorStyle,
fill: import_TLFillStyle.DefaultFillStyle,
dash: import_TLDashStyle.DefaultDashStyle,
size: import_TLSizeStyle.DefaultSizeStyle,
segments: import_validate.T.arrayOf(DrawShapeSegment),
isComplete: import_validate.T.boolean,
isClosed: import_validate.T.boolean,
isPen: import_validate.T.boolean,
scale: import_validate.T.nonZeroNumber
};
const Versions = (0, import_TLShape.createShapePropsMigrationIds)("draw", {
AddInPen: 1,
AddScale: 2
});
const drawShapeMigrations = (0, import_TLShape.createShapePropsMigrationSequence)({
sequence: [
{
id: Versions.AddInPen,
up: (props) => {
const { points } = props.segments[0];
if (points.length === 0) {
props.isPen = false;
return;
}
let isPen = !(points[0].z === 0 || points[0].z === 0.5);
if (points[1]) {
isPen = isPen && !(points[1].z === 0 || points[1].z === 0.5);
}
props.isPen = isPen;
},
down: "retired"
},
{
id: Versions.AddScale,
up: (props) => {
props.scale = 1;
},
down: (props) => {
delete props.scale;
}
}
]
});
//# sourceMappingURL=TLDrawShape.js.map