@tldraw/tlschema 4.3.0-canary.fd6b7f2a8adc → 4.3.0-next.085293d79c32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/index.d.ts +90 -34
- package/dist-cjs/index.js +4 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/misc/TLOpacity.js +1 -5
- package/dist-cjs/misc/TLOpacity.js.map +2 -2
- package/dist-cjs/misc/TLRichText.js +5 -1
- package/dist-cjs/misc/TLRichText.js.map +2 -2
- package/dist-cjs/misc/b64Vecs.js +310 -0
- package/dist-cjs/misc/b64Vecs.js.map +7 -0
- package/dist-cjs/shapes/TLArrowShape.js +30 -13
- package/dist-cjs/shapes/TLArrowShape.js.map +2 -2
- package/dist-cjs/shapes/TLDrawShape.js +58 -4
- package/dist-cjs/shapes/TLDrawShape.js.map +2 -2
- package/dist-cjs/shapes/TLEmbedShape.js +17 -0
- package/dist-cjs/shapes/TLEmbedShape.js.map +2 -2
- package/dist-cjs/shapes/TLGeoShape.js +12 -1
- package/dist-cjs/shapes/TLGeoShape.js.map +2 -2
- package/dist-cjs/shapes/TLHighlightShape.js +50 -2
- package/dist-cjs/shapes/TLHighlightShape.js.map +2 -2
- package/dist-cjs/shapes/TLNoteShape.js +12 -1
- package/dist-cjs/shapes/TLNoteShape.js.map +2 -2
- package/dist-cjs/shapes/TLTextShape.js +12 -1
- package/dist-cjs/shapes/TLTextShape.js.map +2 -2
- package/dist-cjs/store-migrations.js +14 -14
- package/dist-cjs/store-migrations.js.map +2 -2
- package/dist-esm/index.d.mts +90 -34
- package/dist-esm/index.mjs +5 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/misc/TLOpacity.mjs +1 -5
- package/dist-esm/misc/TLOpacity.mjs.map +2 -2
- package/dist-esm/misc/TLRichText.mjs +5 -1
- package/dist-esm/misc/TLRichText.mjs.map +2 -2
- package/dist-esm/misc/b64Vecs.mjs +290 -0
- package/dist-esm/misc/b64Vecs.mjs.map +7 -0
- package/dist-esm/shapes/TLArrowShape.mjs +30 -13
- package/dist-esm/shapes/TLArrowShape.mjs.map +2 -2
- package/dist-esm/shapes/TLDrawShape.mjs +58 -4
- package/dist-esm/shapes/TLDrawShape.mjs.map +2 -2
- package/dist-esm/shapes/TLEmbedShape.mjs +17 -0
- package/dist-esm/shapes/TLEmbedShape.mjs.map +2 -2
- package/dist-esm/shapes/TLGeoShape.mjs +12 -1
- package/dist-esm/shapes/TLGeoShape.mjs.map +2 -2
- package/dist-esm/shapes/TLHighlightShape.mjs +50 -2
- package/dist-esm/shapes/TLHighlightShape.mjs.map +2 -2
- package/dist-esm/shapes/TLNoteShape.mjs +12 -1
- package/dist-esm/shapes/TLNoteShape.mjs.map +2 -2
- package/dist-esm/shapes/TLTextShape.mjs +12 -1
- package/dist-esm/shapes/TLTextShape.mjs.map +2 -2
- package/dist-esm/store-migrations.mjs +14 -14
- package/dist-esm/store-migrations.mjs.map +2 -2
- package/package.json +8 -8
- package/src/__tests__/migrationTestUtils.ts +9 -3
- package/src/index.ts +3 -0
- package/src/migrations.test.ts +334 -0
- package/src/misc/TLOpacity.ts +1 -5
- package/src/misc/TLRichText.ts +6 -1
- package/src/misc/b64Vecs.test.ts +480 -0
- package/src/misc/b64Vecs.ts +430 -0
- package/src/shapes/TLArrowShape.ts +36 -13
- package/src/shapes/TLDrawShape.ts +86 -12
- package/src/shapes/TLEmbedShape.ts +17 -0
- package/src/shapes/TLGeoShape.ts +14 -1
- package/src/shapes/TLHighlightShape.ts +60 -0
- package/src/shapes/TLNoteShape.ts +15 -1
- package/src/shapes/TLTextShape.ts +16 -2
- package/src/store-migrations.ts +15 -15
- package/src/assets/TLBookmarkAsset.test.ts +0 -96
- package/src/assets/TLImageAsset.test.ts +0 -213
- package/src/assets/TLVideoAsset.test.ts +0 -105
- package/src/bindings/TLArrowBinding.test.ts +0 -55
- package/src/misc/id-validator.test.ts +0 -50
- package/src/records/TLAsset.test.ts +0 -234
- package/src/records/TLBinding.test.ts +0 -22
- package/src/records/TLCamera.test.ts +0 -19
- package/src/records/TLDocument.test.ts +0 -35
- package/src/records/TLInstance.test.ts +0 -201
- package/src/records/TLPage.test.ts +0 -110
- package/src/records/TLPageState.test.ts +0 -228
- package/src/records/TLPointer.test.ts +0 -63
- package/src/records/TLPresence.test.ts +0 -190
- package/src/records/TLRecord.test.ts +0 -82
- package/src/records/TLShape.test.ts +0 -232
- package/src/shapes/ShapeWithCrop.test.ts +0 -18
- package/src/shapes/TLArrowShape.test.ts +0 -505
- package/src/shapes/TLBaseShape.test.ts +0 -142
- package/src/shapes/TLBookmarkShape.test.ts +0 -122
- package/src/shapes/TLDrawShape.test.ts +0 -177
- package/src/shapes/TLEmbedShape.test.ts +0 -286
- package/src/shapes/TLFrameShape.test.ts +0 -71
- package/src/shapes/TLGeoShape.test.ts +0 -247
- package/src/shapes/TLGroupShape.test.ts +0 -59
- package/src/shapes/TLHighlightShape.test.ts +0 -325
- package/src/shapes/TLImageShape.test.ts +0 -534
- package/src/shapes/TLLineShape.test.ts +0 -269
- package/src/shapes/TLNoteShape.test.ts +0 -1568
- package/src/shapes/TLTextShape.test.ts +0 -407
- package/src/shapes/TLVideoShape.test.ts +0 -112
- package/src/styles/TLColorStyle.test.ts +0 -439
package/dist-cjs/index.d.ts
CHANGED
|
@@ -210,6 +210,7 @@ export declare const arrowShapeVersions: {
|
|
|
210
210
|
readonly AddLabelColor: "com.tldraw.shape.arrow/1";
|
|
211
211
|
readonly AddLabelPosition: "com.tldraw.shape.arrow/3";
|
|
212
212
|
readonly AddRichText: "com.tldraw.shape.arrow/7";
|
|
213
|
+
readonly AddRichTextAttrs: "com.tldraw.shape.arrow/8";
|
|
213
214
|
readonly AddScale: "com.tldraw.shape.arrow/5";
|
|
214
215
|
readonly ExtractBindings: "com.tldraw.shape.arrow/4";
|
|
215
216
|
};
|
|
@@ -299,6 +300,63 @@ export declare const AssetRecordType: RecordType<TLAsset, "props" | "type">;
|
|
|
299
300
|
*/
|
|
300
301
|
export declare const assetValidator: T.Validator<TLAsset>;
|
|
301
302
|
|
|
303
|
+
/**
|
|
304
|
+
* Utilities for encoding and decoding points using base64 and Float16 encoding.
|
|
305
|
+
* Provides functions for converting between VecModel arrays and compact base64 strings,
|
|
306
|
+
* as well as individual point encoding/decoding operations.
|
|
307
|
+
*
|
|
308
|
+
* @public
|
|
309
|
+
*/
|
|
310
|
+
export declare class b64Vecs {
|
|
311
|
+
/* Excluded from this release type: _legacyEncodePoint */
|
|
312
|
+
/* Excluded from this release type: _legacyEncodePoints */
|
|
313
|
+
/* Excluded from this release type: _legacyDecodePoints */
|
|
314
|
+
/**
|
|
315
|
+
* Encode an array of VecModels using delta encoding for improved precision.
|
|
316
|
+
* The first point is stored as Float32 (high precision for absolute position),
|
|
317
|
+
* subsequent points are stored as Float16 deltas from the previous point.
|
|
318
|
+
* This provides full precision for the starting position and excellent precision
|
|
319
|
+
* for deltas between consecutive points (which are typically small values).
|
|
320
|
+
*
|
|
321
|
+
* Format:
|
|
322
|
+
* - First point: 3 Float32 values = 12 bytes = 16 base64 chars
|
|
323
|
+
* - Delta points: 3 Float16 values each = 6 bytes = 8 base64 chars each
|
|
324
|
+
*
|
|
325
|
+
* @param points - An array of VecModel objects to encode
|
|
326
|
+
* @returns A base64-encoded string containing delta-encoded points
|
|
327
|
+
* @public
|
|
328
|
+
*/
|
|
329
|
+
static encodePoints(points: VecModel[]): string;
|
|
330
|
+
/**
|
|
331
|
+
* Decode a delta-encoded base64 string back to an array of absolute VecModels.
|
|
332
|
+
* The first point is stored as Float32 (high precision), subsequent points are
|
|
333
|
+
* Float16 deltas that are accumulated to reconstruct absolute positions.
|
|
334
|
+
*
|
|
335
|
+
* @param base64 - The base64-encoded string containing delta-encoded point data
|
|
336
|
+
* @returns An array of VecModel objects with absolute coordinates
|
|
337
|
+
* @public
|
|
338
|
+
*/
|
|
339
|
+
static decodePoints(base64: string): VecModel[];
|
|
340
|
+
/**
|
|
341
|
+
* Get the first point from a delta-encoded base64 string.
|
|
342
|
+
* The first point is stored as Float32 for full precision.
|
|
343
|
+
*
|
|
344
|
+
* @param b64Points - The delta-encoded base64 string
|
|
345
|
+
* @returns The first point as a VecModel, or null if the string is too short
|
|
346
|
+
* @public
|
|
347
|
+
*/
|
|
348
|
+
static decodeFirstPoint(b64Points: string): null | VecModel;
|
|
349
|
+
/**
|
|
350
|
+
* Get the last point from a delta-encoded base64 string.
|
|
351
|
+
* Requires decoding all points to accumulate deltas.
|
|
352
|
+
*
|
|
353
|
+
* @param b64Points - The delta-encoded base64 string
|
|
354
|
+
* @returns The last point as a VecModel, or null if the string is too short
|
|
355
|
+
* @public
|
|
356
|
+
*/
|
|
357
|
+
static decodeLastPoint(b64Points: string): null | VecModel;
|
|
358
|
+
}
|
|
359
|
+
|
|
302
360
|
/**
|
|
303
361
|
* Validator for binding IDs. Ensures that binding identifiers follow the correct
|
|
304
362
|
* format and type constraints required by the tldraw schema system.
|
|
@@ -426,6 +484,18 @@ export declare const CameraRecordType: RecordType<TLCamera, never>;
|
|
|
426
484
|
*/
|
|
427
485
|
export declare const canvasUiColorTypeValidator: T.Validator<"accent" | "black" | "laser" | "muted-1" | "selection-fill" | "selection-stroke" | "white">;
|
|
428
486
|
|
|
487
|
+
/**
|
|
488
|
+
* Compress legacy draw shape segments by converting VecModel[] points to delta-encoded base64 format.
|
|
489
|
+
* This function is useful for converting old draw shape data to the new compressed format.
|
|
490
|
+
* Uses delta encoding for improved Float16 precision.
|
|
491
|
+
*
|
|
492
|
+
* @public
|
|
493
|
+
*/
|
|
494
|
+
export declare function compressLegacySegments(segments: {
|
|
495
|
+
points: VecModel[];
|
|
496
|
+
type: 'free' | 'straight';
|
|
497
|
+
}[]): TLDrawShapeSegment[];
|
|
498
|
+
|
|
429
499
|
/**
|
|
430
500
|
* Creates a validator for a specific asset record type. This factory function generates
|
|
431
501
|
* a complete validator that validates the entire asset record structure including the
|
|
@@ -1398,22 +1468,7 @@ export declare const DocumentRecordType: RecordType<TLDocument, never>;
|
|
|
1398
1468
|
*/
|
|
1399
1469
|
export declare const drawShapeMigrations: TLPropsMigrations;
|
|
1400
1470
|
|
|
1401
|
-
/**
|
|
1402
|
-
* Validation schema for draw shape properties.
|
|
1403
|
-
*
|
|
1404
|
-
* @public
|
|
1405
|
-
* @example
|
|
1406
|
-
* ```ts
|
|
1407
|
-
* // Validate draw shape properties
|
|
1408
|
-
* const props = {
|
|
1409
|
-
* color: 'red',
|
|
1410
|
-
* fill: 'solid',
|
|
1411
|
-
* segments: [{ type: 'free', points: [] }],
|
|
1412
|
-
* isComplete: true
|
|
1413
|
-
* }
|
|
1414
|
-
* const isValid = drawShapeProps.color.isValid(props.color)
|
|
1415
|
-
* ```
|
|
1416
|
-
*/
|
|
1471
|
+
/** @public */
|
|
1417
1472
|
export declare const drawShapeProps: RecordProps<TLDrawShape>;
|
|
1418
1473
|
|
|
1419
1474
|
/**
|
|
@@ -1537,7 +1592,7 @@ export declare const GeoShapeGeoStyle: EnumStyleProp<"arrow-down" | "arrow-left"
|
|
|
1537
1592
|
/**
|
|
1538
1593
|
* Migration sequence for geo shape properties across different schema versions.
|
|
1539
1594
|
* Handles evolution of geo shapes including URL support, label colors, alignment changes,
|
|
1540
|
-
*
|
|
1595
|
+
* the transition from plain text to rich text, and support for attrs property on richText.
|
|
1541
1596
|
*
|
|
1542
1597
|
* @public
|
|
1543
1598
|
*/
|
|
@@ -1753,20 +1808,7 @@ export declare const groupShapeProps: RecordProps<TLGroupShape>;
|
|
|
1753
1808
|
*/
|
|
1754
1809
|
export declare const highlightShapeMigrations: TLPropsMigrations;
|
|
1755
1810
|
|
|
1756
|
-
/**
|
|
1757
|
-
* Validation schema for highlight shape properties. Defines the runtime validation rules
|
|
1758
|
-
* for all properties of highlight shapes.
|
|
1759
|
-
*
|
|
1760
|
-
* @public
|
|
1761
|
-
* @example
|
|
1762
|
-
* ```ts
|
|
1763
|
-
* import { highlightShapeProps } from '@tldraw/tlschema'
|
|
1764
|
-
*
|
|
1765
|
-
* // Used internally by the validation system
|
|
1766
|
-
* const validator = T.object(highlightShapeProps)
|
|
1767
|
-
* const validatedProps = validator.validate(someHighlightProps)
|
|
1768
|
-
* ```
|
|
1769
|
-
*/
|
|
1811
|
+
/** @public */
|
|
1770
1812
|
export declare const highlightShapeProps: RecordProps<TLHighlightShape>;
|
|
1771
1813
|
|
|
1772
1814
|
/**
|
|
@@ -2215,7 +2257,8 @@ export declare const LineShapeSplineStyle: EnumStyleProp<"cubic" | "line">;
|
|
|
2215
2257
|
* Migration sequence for note shapes. Handles schema evolution over time by defining
|
|
2216
2258
|
* how to upgrade and downgrade note shape data between different versions. Includes
|
|
2217
2259
|
* migrations for URL properties, text alignment changes, vertical alignment addition,
|
|
2218
|
-
* font size adjustments, scaling support, label color,
|
|
2260
|
+
* font size adjustments, scaling support, label color, the transition from plain text to rich text,
|
|
2261
|
+
* and support for attrs property on richText.
|
|
2219
2262
|
*
|
|
2220
2263
|
* @public
|
|
2221
2264
|
*/
|
|
@@ -2412,6 +2455,7 @@ export declare type RecordPropsType<Config extends Record<string, T.Validatable<
|
|
|
2412
2455
|
* ```
|
|
2413
2456
|
*/
|
|
2414
2457
|
export declare const richTextValidator: T.ObjectValidator<{
|
|
2458
|
+
attrs?: any;
|
|
2415
2459
|
content: unknown[];
|
|
2416
2460
|
type: string;
|
|
2417
2461
|
}>;
|
|
@@ -2717,6 +2761,7 @@ export declare type StylePropValue<T extends StyleProp<any>> = T extends StylePr
|
|
|
2717
2761
|
* - RemoveJustify: Replaced 'justify' alignment with 'start'
|
|
2718
2762
|
* - AddTextAlign: Migrated from 'align' to 'textAlign' property
|
|
2719
2763
|
* - AddRichText: Converted plain text to rich text format
|
|
2764
|
+
* - AddRichTextAttrs: Added support for attrs property on richText
|
|
2720
2765
|
*
|
|
2721
2766
|
* @public
|
|
2722
2767
|
*/
|
|
@@ -4161,6 +4206,10 @@ export declare interface TLDrawShapeProps {
|
|
|
4161
4206
|
isPen: boolean;
|
|
4162
4207
|
/** Scale factor applied to the drawing */
|
|
4163
4208
|
scale: number;
|
|
4209
|
+
/** Horizontal scale factor for lazy resize */
|
|
4210
|
+
scaleX: number;
|
|
4211
|
+
/** Vertical scale factor for lazy resize */
|
|
4212
|
+
scaleY: number;
|
|
4164
4213
|
}
|
|
4165
4214
|
|
|
4166
4215
|
/**
|
|
@@ -4171,8 +4220,11 @@ export declare interface TLDrawShapeProps {
|
|
|
4171
4220
|
export declare interface TLDrawShapeSegment {
|
|
4172
4221
|
/** Type of drawing segment - 'free' for freehand curves, 'straight' for line segments */
|
|
4173
4222
|
type: 'free' | 'straight';
|
|
4174
|
-
/**
|
|
4175
|
-
|
|
4223
|
+
/**
|
|
4224
|
+
* Delta-encoded base64 path data.
|
|
4225
|
+
* First point stored as Float32 (12 bytes) for precision, subsequent points as Float16 deltas (6 bytes each).
|
|
4226
|
+
*/
|
|
4227
|
+
path: string;
|
|
4176
4228
|
}
|
|
4177
4229
|
|
|
4178
4230
|
/**
|
|
@@ -4543,6 +4595,10 @@ export declare interface TLHighlightShapeProps {
|
|
|
4543
4595
|
isPen: boolean;
|
|
4544
4596
|
/** Scale factor applied to the highlight shape for display */
|
|
4545
4597
|
scale: number;
|
|
4598
|
+
/** Horizontal scale factor for lazy resize */
|
|
4599
|
+
scaleX: number;
|
|
4600
|
+
/** Vertical scale factor for lazy resize */
|
|
4601
|
+
scaleY: number;
|
|
4546
4602
|
}
|
|
4547
4603
|
|
|
4548
4604
|
/**
|
package/dist-cjs/index.js
CHANGED
|
@@ -62,11 +62,13 @@ __export(index_exports, {
|
|
|
62
62
|
assetIdValidator: () => import_TLBaseAsset.assetIdValidator,
|
|
63
63
|
assetMigrations: () => import_TLAsset.assetMigrations,
|
|
64
64
|
assetValidator: () => import_TLAsset.assetValidator,
|
|
65
|
+
b64Vecs: () => import_b64Vecs.b64Vecs,
|
|
65
66
|
bindingIdValidator: () => import_TLBaseBinding.bindingIdValidator,
|
|
66
67
|
bookmarkShapeMigrations: () => import_TLBookmarkShape.bookmarkShapeMigrations,
|
|
67
68
|
bookmarkShapeProps: () => import_TLBookmarkShape.bookmarkShapeProps,
|
|
68
69
|
boxModelValidator: () => import_geometry_types.boxModelValidator,
|
|
69
70
|
canvasUiColorTypeValidator: () => import_TLColor.canvasUiColorTypeValidator,
|
|
71
|
+
compressLegacySegments: () => import_TLDrawShape.compressLegacySegments,
|
|
70
72
|
createAssetValidator: () => import_TLBaseAsset.createAssetValidator,
|
|
71
73
|
createBindingId: () => import_TLBinding.createBindingId,
|
|
72
74
|
createBindingPropsMigrationIds: () => import_TLBinding.createBindingPropsMigrationIds,
|
|
@@ -176,9 +178,10 @@ var import_TLSizeStyle = require("./styles/TLSizeStyle");
|
|
|
176
178
|
var import_TLTextAlignStyle = require("./styles/TLTextAlignStyle");
|
|
177
179
|
var import_TLVerticalAlignStyle = require("./styles/TLVerticalAlignStyle");
|
|
178
180
|
var import_translations = require("./translations/translations");
|
|
181
|
+
var import_b64Vecs = require("./misc/b64Vecs");
|
|
179
182
|
(0, import_utils.registerTldrawLibraryVersion)(
|
|
180
183
|
"@tldraw/tlschema",
|
|
181
|
-
"4.3.0-
|
|
184
|
+
"4.3.0-next.085293d79c32",
|
|
182
185
|
"cjs"
|
|
183
186
|
);
|
|
184
187
|
//# sourceMappingURL=index.js.map
|
package/dist-cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * @fileoverview\n * Main entry point for the tldraw schema package. Exports the complete type system,\n * data structures, validation, and migrations for tldraw's persisted data.\n *\n * This package provides:\n * - Schema creation utilities (createTLSchema, defaultShapeSchemas, defaultBindingSchemas)\n * - All built-in shape types (TLGeoShape, TLTextShape, TLArrowShape, etc.)\n * - Asset management types and validators (TLImageAsset, TLVideoAsset, TLBookmarkAsset)\n * - Binding system for shape relationships (TLArrowBinding)\n * - Store integration types (TLStore, TLStoreProps, TLStoreSnapshot)\n * - Style properties for consistent styling (DefaultColorStyle, DefaultSizeStyle, etc.)\n * - Validation utilities and type guards\n * - Migration systems for schema evolution\n * - Geometry and utility types\n *\n * @example\n * ```ts\n * import { createTLSchema, defaultShapeSchemas, TLStore } from '@tldraw/tlschema'\n *\n * // Create a schema with default shapes\n * const schema = createTLSchema({\n * shapes: defaultShapeSchemas\n * })\n *\n * // Use with a store\n * const store = new Store({ schema })\n * ```\n *\n * @public\n */\n\nimport { registerTldrawLibraryVersion } from '@tldraw/utils'\nexport { assetIdValidator, createAssetValidator, type TLBaseAsset } from './assets/TLBaseAsset'\nexport { type TLBookmarkAsset } from './assets/TLBookmarkAsset'\nexport { type TLImageAsset } from './assets/TLImageAsset'\nexport { type TLVideoAsset } from './assets/TLVideoAsset'\nexport {\n\tarrowBindingMigrations,\n\tarrowBindingProps,\n\tarrowBindingVersions,\n\tElbowArrowSnap,\n\ttype TLArrowBinding,\n\ttype TLArrowBindingProps,\n} from './bindings/TLArrowBinding'\nexport {\n\tbindingIdValidator,\n\tcreateBindingValidator,\n\ttype TLBaseBinding,\n} from './bindings/TLBaseBinding'\nexport {\n\tcreatePresenceStateDerivation,\n\tgetDefaultUserPresence,\n\ttype TLPresenceStateInfo,\n\ttype TLPresenceUserInfo,\n} from './createPresenceStateDerivation'\nexport {\n\tcreateTLSchema,\n\tdefaultBindingSchemas,\n\tdefaultShapeSchemas,\n\ttype SchemaPropsInfo,\n\ttype TLSchema,\n} from './createTLSchema'\nexport {\n\tboxModelValidator,\n\tvecModelValidator,\n\ttype BoxModel,\n\ttype VecModel,\n} from './misc/geometry-types'\nexport { idValidator } from './misc/id-validator'\nexport {\n\tcanvasUiColorTypeValidator,\n\tTL_CANVAS_UI_COLOR_TYPES,\n\ttype TLCanvasUiColor,\n} from './misc/TLColor'\nexport { TL_CURSOR_TYPES, type TLCursor, type TLCursorType } from './misc/TLCursor'\nexport { TL_HANDLE_TYPES, type TLHandle, type TLHandleType } from './misc/TLHandle'\nexport { opacityValidator, type TLOpacityType } from './misc/TLOpacity'\nexport { richTextValidator, toRichText, type TLRichText } from './misc/TLRichText'\nexport { scribbleValidator, TL_SCRIBBLE_STATES, type TLScribble } from './misc/TLScribble'\nexport {\n\tassetMigrations,\n\tAssetRecordType,\n\tassetValidator,\n\ttype TLAsset,\n\ttype TLAssetId,\n\ttype TLAssetPartial,\n\ttype TLAssetShape,\n} from './records/TLAsset'\nexport {\n\tcreateBindingId,\n\tcreateBindingPropsMigrationIds,\n\tcreateBindingPropsMigrationSequence,\n\tisBinding,\n\tisBindingId,\n\trootBindingMigrations,\n\ttype TLBinding,\n\ttype TLBindingCreate,\n\ttype TLBindingId,\n\ttype TLBindingUpdate,\n\ttype TLDefaultBinding,\n\ttype TLGlobalBindingPropsMap,\n\ttype TLIndexedBindings,\n\ttype TLUnknownBinding,\n} from './records/TLBinding'\nexport { CameraRecordType, type TLCamera, type TLCameraId } from './records/TLCamera'\nexport {\n\tDocumentRecordType,\n\tisDocument,\n\tTLDOCUMENT_ID,\n\ttype TLDocument,\n} from './records/TLDocument'\nexport {\n\tpluckPreservingValues,\n\tTLINSTANCE_ID,\n\ttype TLInstance,\n\ttype TLInstanceId,\n} from './records/TLInstance'\nexport {\n\tisPageId,\n\tpageIdValidator,\n\tPageRecordType,\n\ttype TLPage,\n\ttype TLPageId,\n} from './records/TLPage'\nexport {\n\tInstancePageStateRecordType,\n\ttype TLInstancePageState,\n\ttype TLInstancePageStateId,\n} from './records/TLPageState'\nexport {\n\tPointerRecordType,\n\tTLPOINTER_ID,\n\ttype TLPointer,\n\ttype TLPointerId,\n} from './records/TLPointer'\nexport {\n\tInstancePresenceRecordType,\n\ttype TLInstancePresence,\n\ttype TLInstancePresenceID,\n} from './records/TLPresence'\nexport { type TLRecord } from './records/TLRecord'\nexport {\n\tcreateShapeId,\n\tcreateShapePropsMigrationIds,\n\tcreateShapePropsMigrationSequence,\n\tgetShapePropKeysByStyle,\n\tisShape,\n\tisShapeId,\n\trootShapeMigrations,\n\ttype ExtractShapeByProps,\n\ttype TLCreateShapePartial,\n\ttype TLDefaultShape,\n\ttype TLGlobalShapePropsMap,\n\ttype TLIndexedShapes,\n\ttype TLParentId,\n\ttype TLShape,\n\ttype TLShapeId,\n\ttype TLShapePartial,\n\ttype TLUnknownShape,\n} from './records/TLShape'\nexport {\n\ttype RecordProps,\n\ttype RecordPropsType,\n\ttype TLPropsMigration,\n\ttype TLPropsMigrations,\n} from './recordsWithProps'\nexport { type ShapeWithCrop, type TLShapeCrop } from './shapes/ShapeWithCrop'\nexport {\n\tArrowShapeArrowheadEndStyle,\n\tArrowShapeArrowheadStartStyle,\n\tArrowShapeKindStyle,\n\tarrowShapeMigrations,\n\tarrowShapeProps,\n\tarrowShapeVersions,\n\ttype TLArrowShape,\n\ttype TLArrowShapeArrowheadStyle,\n\ttype TLArrowShapeKind,\n\ttype TLArrowShapeProps,\n} from './shapes/TLArrowShape'\nexport {\n\tcreateShapeValidator,\n\tparentIdValidator,\n\tshapeIdValidator,\n\ttype TLBaseShape,\n} from './shapes/TLBaseShape'\nexport {\n\tbookmarkShapeMigrations,\n\tbookmarkShapeProps,\n\ttype TLBookmarkShape,\n\ttype TLBookmarkShapeProps,\n} from './shapes/TLBookmarkShape'\nexport {\n\tdrawShapeMigrations,\n\tdrawShapeProps,\n\ttype TLDrawShape,\n\ttype TLDrawShapeProps,\n\ttype TLDrawShapeSegment,\n} from './shapes/TLDrawShape'\nexport {\n\tembedShapeMigrations,\n\tembedShapeProps,\n\ttype TLEmbedShape,\n\ttype TLEmbedShapeProps,\n} from './shapes/TLEmbedShape'\nexport {\n\tframeShapeMigrations,\n\tframeShapeProps,\n\ttype TLFrameShape,\n\ttype TLFrameShapeProps,\n} from './shapes/TLFrameShape'\nexport {\n\tGeoShapeGeoStyle,\n\tgeoShapeMigrations,\n\tgeoShapeProps,\n\ttype TLGeoShape,\n\ttype TLGeoShapeGeoStyle,\n\ttype TLGeoShapeProps,\n} from './shapes/TLGeoShape'\nexport {\n\tgroupShapeMigrations,\n\tgroupShapeProps,\n\ttype TLGroupShape,\n\ttype TLGroupShapeProps,\n} from './shapes/TLGroupShape'\nexport {\n\thighlightShapeMigrations,\n\thighlightShapeProps,\n\ttype TLHighlightShape,\n\ttype TLHighlightShapeProps,\n} from './shapes/TLHighlightShape'\nexport {\n\tImageShapeCrop,\n\timageShapeMigrations,\n\timageShapeProps,\n\ttype TLImageShape,\n\ttype TLImageShapeProps,\n} from './shapes/TLImageShape'\nexport {\n\tlineShapeMigrations,\n\tlineShapeProps,\n\tLineShapeSplineStyle,\n\ttype TLLineShape,\n\ttype TLLineShapePoint,\n\ttype TLLineShapeProps,\n\ttype TLLineShapeSplineStyle,\n} from './shapes/TLLineShape'\nexport {\n\tnoteShapeMigrations,\n\tnoteShapeProps,\n\ttype TLNoteShape,\n\ttype TLNoteShapeProps,\n} from './shapes/TLNoteShape'\nexport {\n\ttextShapeMigrations,\n\ttextShapeProps,\n\ttype TLTextShape,\n\ttype TLTextShapeProps,\n} from './shapes/TLTextShape'\nexport {\n\tvideoShapeMigrations,\n\tvideoShapeProps,\n\ttype TLVideoShape,\n\ttype TLVideoShapeProps,\n} from './shapes/TLVideoShape'\nexport { EnumStyleProp, StyleProp, type StylePropValue } from './styles/StyleProp'\nexport {\n\tdefaultColorNames,\n\tDefaultColorStyle,\n\tDefaultColorThemePalette,\n\tDefaultLabelColorStyle,\n\tgetColorValue,\n\tgetDefaultColorTheme,\n\ttype TLDefaultColorStyle,\n\ttype TLDefaultColorTheme,\n\ttype TLDefaultColorThemeColor,\n} from './styles/TLColorStyle'\nexport { DefaultDashStyle, type TLDefaultDashStyle } from './styles/TLDashStyle'\nexport { DefaultFillStyle, type TLDefaultFillStyle } from './styles/TLFillStyle'\nexport {\n\tDefaultFontFamilies,\n\tDefaultFontStyle,\n\ttype TLDefaultFontStyle,\n} from './styles/TLFontStyle'\nexport {\n\tDefaultHorizontalAlignStyle,\n\ttype TLDefaultHorizontalAlignStyle,\n} from './styles/TLHorizontalAlignStyle'\nexport { DefaultSizeStyle, type TLDefaultSizeStyle } from './styles/TLSizeStyle'\nexport { DefaultTextAlignStyle, type TLDefaultTextAlignStyle } from './styles/TLTextAlignStyle'\nexport {\n\tDefaultVerticalAlignStyle,\n\ttype TLDefaultVerticalAlignStyle,\n} from './styles/TLVerticalAlignStyle'\nexport {\n\ttype TLAssetContext,\n\ttype TLAssetStore,\n\ttype TLSerializedStore,\n\ttype TLStore,\n\ttype TLStoreProps,\n\ttype TLStoreSchema,\n\ttype TLStoreSnapshot,\n} from './TLStore'\nexport {\n\tgetDefaultTranslationLocale,\n\tLANGUAGES,\n\ttype TLLanguage,\n} from './translations/translations'\nexport { type SetValue } from './util-types'\n\nregisterTldrawLibraryVersion(\n\t(globalThis as any).TLDRAW_LIBRARY_NAME,\n\t(globalThis as any).TLDRAW_LIBRARY_VERSION,\n\t(globalThis as any).TLDRAW_LIBRARY_MODULES\n)\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgCA,mBAA6C;AAC7C,yBAAyE;AAIzE,4BAOO;AACP,2BAIO;AACP,2CAKO;AACP,4BAMO;AACP,4BAKO;AACP,0BAA4B;AAC5B,qBAIO;AACP,sBAAkE;AAClE,sBAAkE;AAClE,uBAAqD;AACrD,wBAA+D;AAC/D,wBAAuE;AACvE,qBAQO;AACP,uBAeO;AACP,sBAAiE;AACjE,wBAKO;AACP,wBAKO;AACP,oBAMO;AACP,yBAIO;AACP,uBAKO;AACP,wBAIO;AAEP,qBAkBO;AAQP,0BAWO;AACP,yBAKO;AACP,6BAKO;AACP,
|
|
4
|
+
"sourcesContent": ["/**\n * @fileoverview\n * Main entry point for the tldraw schema package. Exports the complete type system,\n * data structures, validation, and migrations for tldraw's persisted data.\n *\n * This package provides:\n * - Schema creation utilities (createTLSchema, defaultShapeSchemas, defaultBindingSchemas)\n * - All built-in shape types (TLGeoShape, TLTextShape, TLArrowShape, etc.)\n * - Asset management types and validators (TLImageAsset, TLVideoAsset, TLBookmarkAsset)\n * - Binding system for shape relationships (TLArrowBinding)\n * - Store integration types (TLStore, TLStoreProps, TLStoreSnapshot)\n * - Style properties for consistent styling (DefaultColorStyle, DefaultSizeStyle, etc.)\n * - Validation utilities and type guards\n * - Migration systems for schema evolution\n * - Geometry and utility types\n *\n * @example\n * ```ts\n * import { createTLSchema, defaultShapeSchemas, TLStore } from '@tldraw/tlschema'\n *\n * // Create a schema with default shapes\n * const schema = createTLSchema({\n * shapes: defaultShapeSchemas\n * })\n *\n * // Use with a store\n * const store = new Store({ schema })\n * ```\n *\n * @public\n */\n\nimport { registerTldrawLibraryVersion } from '@tldraw/utils'\nexport { assetIdValidator, createAssetValidator, type TLBaseAsset } from './assets/TLBaseAsset'\nexport { type TLBookmarkAsset } from './assets/TLBookmarkAsset'\nexport { type TLImageAsset } from './assets/TLImageAsset'\nexport { type TLVideoAsset } from './assets/TLVideoAsset'\nexport {\n\tarrowBindingMigrations,\n\tarrowBindingProps,\n\tarrowBindingVersions,\n\tElbowArrowSnap,\n\ttype TLArrowBinding,\n\ttype TLArrowBindingProps,\n} from './bindings/TLArrowBinding'\nexport {\n\tbindingIdValidator,\n\tcreateBindingValidator,\n\ttype TLBaseBinding,\n} from './bindings/TLBaseBinding'\nexport {\n\tcreatePresenceStateDerivation,\n\tgetDefaultUserPresence,\n\ttype TLPresenceStateInfo,\n\ttype TLPresenceUserInfo,\n} from './createPresenceStateDerivation'\nexport {\n\tcreateTLSchema,\n\tdefaultBindingSchemas,\n\tdefaultShapeSchemas,\n\ttype SchemaPropsInfo,\n\ttype TLSchema,\n} from './createTLSchema'\nexport {\n\tboxModelValidator,\n\tvecModelValidator,\n\ttype BoxModel,\n\ttype VecModel,\n} from './misc/geometry-types'\nexport { idValidator } from './misc/id-validator'\nexport {\n\tcanvasUiColorTypeValidator,\n\tTL_CANVAS_UI_COLOR_TYPES,\n\ttype TLCanvasUiColor,\n} from './misc/TLColor'\nexport { TL_CURSOR_TYPES, type TLCursor, type TLCursorType } from './misc/TLCursor'\nexport { TL_HANDLE_TYPES, type TLHandle, type TLHandleType } from './misc/TLHandle'\nexport { opacityValidator, type TLOpacityType } from './misc/TLOpacity'\nexport { richTextValidator, toRichText, type TLRichText } from './misc/TLRichText'\nexport { scribbleValidator, TL_SCRIBBLE_STATES, type TLScribble } from './misc/TLScribble'\nexport {\n\tassetMigrations,\n\tAssetRecordType,\n\tassetValidator,\n\ttype TLAsset,\n\ttype TLAssetId,\n\ttype TLAssetPartial,\n\ttype TLAssetShape,\n} from './records/TLAsset'\nexport {\n\tcreateBindingId,\n\tcreateBindingPropsMigrationIds,\n\tcreateBindingPropsMigrationSequence,\n\tisBinding,\n\tisBindingId,\n\trootBindingMigrations,\n\ttype TLBinding,\n\ttype TLBindingCreate,\n\ttype TLBindingId,\n\ttype TLBindingUpdate,\n\ttype TLDefaultBinding,\n\ttype TLGlobalBindingPropsMap,\n\ttype TLIndexedBindings,\n\ttype TLUnknownBinding,\n} from './records/TLBinding'\nexport { CameraRecordType, type TLCamera, type TLCameraId } from './records/TLCamera'\nexport {\n\tDocumentRecordType,\n\tisDocument,\n\tTLDOCUMENT_ID,\n\ttype TLDocument,\n} from './records/TLDocument'\nexport {\n\tpluckPreservingValues,\n\tTLINSTANCE_ID,\n\ttype TLInstance,\n\ttype TLInstanceId,\n} from './records/TLInstance'\nexport {\n\tisPageId,\n\tpageIdValidator,\n\tPageRecordType,\n\ttype TLPage,\n\ttype TLPageId,\n} from './records/TLPage'\nexport {\n\tInstancePageStateRecordType,\n\ttype TLInstancePageState,\n\ttype TLInstancePageStateId,\n} from './records/TLPageState'\nexport {\n\tPointerRecordType,\n\tTLPOINTER_ID,\n\ttype TLPointer,\n\ttype TLPointerId,\n} from './records/TLPointer'\nexport {\n\tInstancePresenceRecordType,\n\ttype TLInstancePresence,\n\ttype TLInstancePresenceID,\n} from './records/TLPresence'\nexport { type TLRecord } from './records/TLRecord'\nexport {\n\tcreateShapeId,\n\tcreateShapePropsMigrationIds,\n\tcreateShapePropsMigrationSequence,\n\tgetShapePropKeysByStyle,\n\tisShape,\n\tisShapeId,\n\trootShapeMigrations,\n\ttype ExtractShapeByProps,\n\ttype TLCreateShapePartial,\n\ttype TLDefaultShape,\n\ttype TLGlobalShapePropsMap,\n\ttype TLIndexedShapes,\n\ttype TLParentId,\n\ttype TLShape,\n\ttype TLShapeId,\n\ttype TLShapePartial,\n\ttype TLUnknownShape,\n} from './records/TLShape'\nexport {\n\ttype RecordProps,\n\ttype RecordPropsType,\n\ttype TLPropsMigration,\n\ttype TLPropsMigrations,\n} from './recordsWithProps'\nexport { type ShapeWithCrop, type TLShapeCrop } from './shapes/ShapeWithCrop'\nexport {\n\tArrowShapeArrowheadEndStyle,\n\tArrowShapeArrowheadStartStyle,\n\tArrowShapeKindStyle,\n\tarrowShapeMigrations,\n\tarrowShapeProps,\n\tarrowShapeVersions,\n\ttype TLArrowShape,\n\ttype TLArrowShapeArrowheadStyle,\n\ttype TLArrowShapeKind,\n\ttype TLArrowShapeProps,\n} from './shapes/TLArrowShape'\nexport {\n\tcreateShapeValidator,\n\tparentIdValidator,\n\tshapeIdValidator,\n\ttype TLBaseShape,\n} from './shapes/TLBaseShape'\nexport {\n\tbookmarkShapeMigrations,\n\tbookmarkShapeProps,\n\ttype TLBookmarkShape,\n\ttype TLBookmarkShapeProps,\n} from './shapes/TLBookmarkShape'\nexport {\n\tcompressLegacySegments,\n\tdrawShapeMigrations,\n\tdrawShapeProps,\n\ttype TLDrawShape,\n\ttype TLDrawShapeProps,\n\ttype TLDrawShapeSegment,\n} from './shapes/TLDrawShape'\nexport {\n\tembedShapeMigrations,\n\tembedShapeProps,\n\ttype TLEmbedShape,\n\ttype TLEmbedShapeProps,\n} from './shapes/TLEmbedShape'\nexport {\n\tframeShapeMigrations,\n\tframeShapeProps,\n\ttype TLFrameShape,\n\ttype TLFrameShapeProps,\n} from './shapes/TLFrameShape'\nexport {\n\tGeoShapeGeoStyle,\n\tgeoShapeMigrations,\n\tgeoShapeProps,\n\ttype TLGeoShape,\n\ttype TLGeoShapeGeoStyle,\n\ttype TLGeoShapeProps,\n} from './shapes/TLGeoShape'\nexport {\n\tgroupShapeMigrations,\n\tgroupShapeProps,\n\ttype TLGroupShape,\n\ttype TLGroupShapeProps,\n} from './shapes/TLGroupShape'\nexport {\n\thighlightShapeMigrations,\n\thighlightShapeProps,\n\ttype TLHighlightShape,\n\ttype TLHighlightShapeProps,\n} from './shapes/TLHighlightShape'\nexport {\n\tImageShapeCrop,\n\timageShapeMigrations,\n\timageShapeProps,\n\ttype TLImageShape,\n\ttype TLImageShapeProps,\n} from './shapes/TLImageShape'\nexport {\n\tlineShapeMigrations,\n\tlineShapeProps,\n\tLineShapeSplineStyle,\n\ttype TLLineShape,\n\ttype TLLineShapePoint,\n\ttype TLLineShapeProps,\n\ttype TLLineShapeSplineStyle,\n} from './shapes/TLLineShape'\nexport {\n\tnoteShapeMigrations,\n\tnoteShapeProps,\n\ttype TLNoteShape,\n\ttype TLNoteShapeProps,\n} from './shapes/TLNoteShape'\nexport {\n\ttextShapeMigrations,\n\ttextShapeProps,\n\ttype TLTextShape,\n\ttype TLTextShapeProps,\n} from './shapes/TLTextShape'\nexport {\n\tvideoShapeMigrations,\n\tvideoShapeProps,\n\ttype TLVideoShape,\n\ttype TLVideoShapeProps,\n} from './shapes/TLVideoShape'\nexport { EnumStyleProp, StyleProp, type StylePropValue } from './styles/StyleProp'\nexport {\n\tdefaultColorNames,\n\tDefaultColorStyle,\n\tDefaultColorThemePalette,\n\tDefaultLabelColorStyle,\n\tgetColorValue,\n\tgetDefaultColorTheme,\n\ttype TLDefaultColorStyle,\n\ttype TLDefaultColorTheme,\n\ttype TLDefaultColorThemeColor,\n} from './styles/TLColorStyle'\nexport { DefaultDashStyle, type TLDefaultDashStyle } from './styles/TLDashStyle'\nexport { DefaultFillStyle, type TLDefaultFillStyle } from './styles/TLFillStyle'\nexport {\n\tDefaultFontFamilies,\n\tDefaultFontStyle,\n\ttype TLDefaultFontStyle,\n} from './styles/TLFontStyle'\nexport {\n\tDefaultHorizontalAlignStyle,\n\ttype TLDefaultHorizontalAlignStyle,\n} from './styles/TLHorizontalAlignStyle'\nexport { DefaultSizeStyle, type TLDefaultSizeStyle } from './styles/TLSizeStyle'\nexport { DefaultTextAlignStyle, type TLDefaultTextAlignStyle } from './styles/TLTextAlignStyle'\nexport {\n\tDefaultVerticalAlignStyle,\n\ttype TLDefaultVerticalAlignStyle,\n} from './styles/TLVerticalAlignStyle'\nexport {\n\ttype TLAssetContext,\n\ttype TLAssetStore,\n\ttype TLSerializedStore,\n\ttype TLStore,\n\ttype TLStoreProps,\n\ttype TLStoreSchema,\n\ttype TLStoreSnapshot,\n} from './TLStore'\nexport {\n\tgetDefaultTranslationLocale,\n\tLANGUAGES,\n\ttype TLLanguage,\n} from './translations/translations'\nexport { type SetValue } from './util-types'\n\nregisterTldrawLibraryVersion(\n\t(globalThis as any).TLDRAW_LIBRARY_NAME,\n\t(globalThis as any).TLDRAW_LIBRARY_VERSION,\n\t(globalThis as any).TLDRAW_LIBRARY_MODULES\n)\n\nexport { b64Vecs } from './misc/b64Vecs'\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgCA,mBAA6C;AAC7C,yBAAyE;AAIzE,4BAOO;AACP,2BAIO;AACP,2CAKO;AACP,4BAMO;AACP,4BAKO;AACP,0BAA4B;AAC5B,qBAIO;AACP,sBAAkE;AAClE,sBAAkE;AAClE,uBAAqD;AACrD,wBAA+D;AAC/D,wBAAuE;AACvE,qBAQO;AACP,uBAeO;AACP,sBAAiE;AACjE,wBAKO;AACP,wBAKO;AACP,oBAMO;AACP,yBAIO;AACP,uBAKO;AACP,wBAIO;AAEP,qBAkBO;AAQP,0BAWO;AACP,yBAKO;AACP,6BAKO;AACP,yBAOO;AACP,0BAKO;AACP,0BAKO;AACP,wBAOO;AACP,0BAKO;AACP,8BAKO;AACP,0BAMO;AACP,yBAQO;AACP,yBAKO;AACP,yBAKO;AACP,0BAKO;AACP,uBAA8D;AAC9D,0BAUO;AACP,yBAA0D;AAC1D,yBAA0D;AAC1D,yBAIO;AACP,oCAGO;AACP,yBAA0D;AAC1D,8BAAoE;AACpE,kCAGO;AAUP,0BAIO;AASP,qBAAwB;AAAA,IANxB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -22,9 +22,5 @@ __export(TLOpacity_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(TLOpacity_exports);
|
|
24
24
|
var import_validate = require("@tldraw/validate");
|
|
25
|
-
const opacityValidator = import_validate.T.
|
|
26
|
-
if (n < 0 || n > 1) {
|
|
27
|
-
throw new import_validate.T.ValidationError("Opacity must be between 0 and 1");
|
|
28
|
-
}
|
|
29
|
-
});
|
|
25
|
+
const opacityValidator = import_validate.T.unitInterval;
|
|
30
26
|
//# sourceMappingURL=TLOpacity.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/misc/TLOpacity.ts"],
|
|
4
|
-
"sourcesContent": ["import { T } from '@tldraw/validate'\n\n/**\n * A type representing opacity values in tldraw.\n *\n * Opacity values are numbers between 0 and 1, where 0 is fully transparent\n * and 1 is fully opaque. This type is used throughout the editor to control\n * the transparency of shapes, UI elements, and other visual components.\n *\n * @example\n * ```ts\n * const fullyOpaque: TLOpacityType = 1.0\n * const halfTransparent: TLOpacityType = 0.5\n * const fullyTransparent: TLOpacityType = 0.0\n * const quarterOpaque: TLOpacityType = 0.25\n * ```\n *\n * @public\n */\nexport type TLOpacityType = number\n\n/**\n * A validator for opacity values.\n *\n * This validator ensures that opacity values are numbers between 0 and 1 (inclusive).\n * Values outside this range will cause a validation error. The validator provides\n * runtime type checking for opacity properties throughout the editor.\n *\n * @param n - The number to validate as an opacity value\n * @throws T.ValidationError When the value is not between 0 and 1\n *\n * @example\n * ```ts\n * import { opacityValidator } from '@tldraw/tlschema'\n *\n * // Valid opacity values\n * try {\n * const validOpacity1 = opacityValidator.validate(0.5) // \u2713\n * const validOpacity2 = opacityValidator.validate(1.0) // \u2713\n * const validOpacity3 = opacityValidator.validate(0.0) // \u2713\n * } catch (error) {\n * console.error('Validation failed:', error.message)\n * }\n *\n * // Invalid opacity values\n * try {\n * opacityValidator.validate(-0.1) // \u2717 Throws error\n * opacityValidator.validate(1.5) // \u2717 Throws error\n * } catch (error) {\n * console.error('Invalid opacity:', error.message)\n * }\n * ```\n *\n * @public\n */\nexport const opacityValidator = T.
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAkB;AAuDX,MAAM,mBAAmB,kBAAE
|
|
4
|
+
"sourcesContent": ["import { T } from '@tldraw/validate'\n\n/**\n * A type representing opacity values in tldraw.\n *\n * Opacity values are numbers between 0 and 1, where 0 is fully transparent\n * and 1 is fully opaque. This type is used throughout the editor to control\n * the transparency of shapes, UI elements, and other visual components.\n *\n * @example\n * ```ts\n * const fullyOpaque: TLOpacityType = 1.0\n * const halfTransparent: TLOpacityType = 0.5\n * const fullyTransparent: TLOpacityType = 0.0\n * const quarterOpaque: TLOpacityType = 0.25\n * ```\n *\n * @public\n */\nexport type TLOpacityType = number\n\n/**\n * A validator for opacity values.\n *\n * This validator ensures that opacity values are numbers between 0 and 1 (inclusive).\n * Values outside this range will cause a validation error. The validator provides\n * runtime type checking for opacity properties throughout the editor.\n *\n * @param n - The number to validate as an opacity value\n * @throws T.ValidationError When the value is not between 0 and 1\n *\n * @example\n * ```ts\n * import { opacityValidator } from '@tldraw/tlschema'\n *\n * // Valid opacity values\n * try {\n * const validOpacity1 = opacityValidator.validate(0.5) // \u2713\n * const validOpacity2 = opacityValidator.validate(1.0) // \u2713\n * const validOpacity3 = opacityValidator.validate(0.0) // \u2713\n * } catch (error) {\n * console.error('Validation failed:', error.message)\n * }\n *\n * // Invalid opacity values\n * try {\n * opacityValidator.validate(-0.1) // \u2717 Throws error\n * opacityValidator.validate(1.5) // \u2717 Throws error\n * } catch (error) {\n * console.error('Invalid opacity:', error.message)\n * }\n * ```\n *\n * @public\n */\nexport const opacityValidator = T.unitInterval\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAkB;AAuDX,MAAM,mBAAmB,kBAAE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -23,7 +23,11 @@ __export(TLRichText_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(TLRichText_exports);
|
|
25
25
|
var import_validate = require("@tldraw/validate");
|
|
26
|
-
const richTextValidator = import_validate.T.object({
|
|
26
|
+
const richTextValidator = import_validate.T.object({
|
|
27
|
+
type: import_validate.T.string,
|
|
28
|
+
content: import_validate.T.arrayOf(import_validate.T.unknown),
|
|
29
|
+
attrs: import_validate.T.any.optional()
|
|
30
|
+
});
|
|
27
31
|
function toRichText(text) {
|
|
28
32
|
const lines = text.split("\n");
|
|
29
33
|
const content = lines.map((text2) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/misc/TLRichText.ts"],
|
|
4
|
-
"sourcesContent": ["import { T } from '@tldraw/validate'\n\n/**\n * Validator for TLRichText objects that ensures they have the correct structure\n * for document-based rich text content. Validates a document with a type field\n * and an array of content blocks.\n *\n * @public\n * @example\n * ```ts\n * const richText = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Hello' }] }] }\n * const isValid = richTextValidator.check(richText) // true\n * ```\n */\nexport const richTextValidator = T.object({
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAkB;
|
|
4
|
+
"sourcesContent": ["import { T } from '@tldraw/validate'\n\n/**\n * Validator for TLRichText objects that ensures they have the correct structure\n * for document-based rich text content. Validates a document with a type field\n * and an array of content blocks.\n *\n * @public\n * @example\n * ```ts\n * const richText = { type: 'doc', content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Hello' }] }] }\n * const isValid = richTextValidator.check(richText) // true\n * ```\n */\n\nexport const richTextValidator = T.object({\n\ttype: T.string,\n\tcontent: T.arrayOf(T.unknown),\n\tattrs: T.any.optional(),\n})\n\n/**\n * Type representing rich text content in tldraw. Rich text follows a document-based\n * structure with a root document containing an array of content blocks (paragraphs,\n * text nodes, etc.). This enables formatted text with support for multiple paragraphs,\n * styling, and other rich content.\n *\n * @public\n * @example\n * ```ts\n * const richText: TLRichText = {\n * type: 'doc',\n * content: [\n * {\n * type: 'paragraph',\n * content: [{ type: 'text', text: 'Hello world!' }]\n * }\n * ]\n * }\n * ```\n */\nexport type TLRichText = T.TypeOf<typeof richTextValidator>\n\n/**\n * Converts a plain text string into a TLRichText object. Each line of the input\n * text becomes a separate paragraph in the rich text document. Empty lines are\n * preserved as empty paragraphs to maintain the original text structure.\n *\n * @param text - The plain text string to convert to rich text\n * @returns A TLRichText object with the text content structured as paragraphs\n * @public\n * @example\n * ```ts\n * const richText = toRichText('Hello\\nWorld')\n * // Returns:\n * // {\n * // type: 'doc',\n * // content: [\n * // { type: 'paragraph', content: [{ type: 'text', text: 'Hello' }] },\n * // { type: 'paragraph', content: [{ type: 'text', text: 'World' }] }\n * // ]\n * // }\n *\n * const emptyLine = toRichText('Line 1\\n\\nLine 3')\n * // Creates three paragraphs, with the middle one being empty\n * ```\n */\nexport function toRichText(text: string): TLRichText {\n\tconst lines = text.split('\\n')\n\tconst content = lines.map((text) => {\n\t\tif (!text) {\n\t\t\treturn {\n\t\t\t\ttype: 'paragraph',\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\ttype: 'paragraph',\n\t\t\tcontent: [{ type: 'text', text }],\n\t\t}\n\t})\n\n\treturn {\n\t\ttype: 'doc',\n\t\tcontent,\n\t}\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAkB;AAeX,MAAM,oBAAoB,kBAAE,OAAO;AAAA,EACzC,MAAM,kBAAE;AAAA,EACR,SAAS,kBAAE,QAAQ,kBAAE,OAAO;AAAA,EAC5B,OAAO,kBAAE,IAAI,SAAS;AACvB,CAAC;AAgDM,SAAS,WAAW,MAA0B;AACpD,QAAM,QAAQ,KAAK,MAAM,IAAI;AAC7B,QAAM,UAAU,MAAM,IAAI,CAACA,UAAS;AACnC,QAAI,CAACA,OAAM;AACV,aAAO;AAAA,QACN,MAAM;AAAA,MACP;AAAA,IACD;AAEA,WAAO;AAAA,MACN,MAAM;AAAA,MACN,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAAA,MAAK,CAAC;AAAA,IACjC;AAAA,EACD,CAAC;AAED,SAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,EACD;AACD;",
|
|
6
6
|
"names": ["text"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var b64Vecs_exports = {};
|
|
20
|
+
__export(b64Vecs_exports, {
|
|
21
|
+
b64Vecs: () => b64Vecs,
|
|
22
|
+
fallbackBase64ToUint8Array: () => fallbackBase64ToUint8Array,
|
|
23
|
+
fallbackUint8ArrayToBase64: () => fallbackUint8ArrayToBase64,
|
|
24
|
+
float16BitsToNumber: () => float16BitsToNumber,
|
|
25
|
+
numberToFloat16Bits: () => numberToFloat16Bits
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(b64Vecs_exports);
|
|
28
|
+
var import_utils = require("@tldraw/utils");
|
|
29
|
+
const _POINT_B64_LENGTH = 8;
|
|
30
|
+
const FIRST_POINT_B64_LENGTH = 16;
|
|
31
|
+
const BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
32
|
+
const B64_LOOKUP = new Uint8Array(128);
|
|
33
|
+
for (let i = 0; i < 64; i++) {
|
|
34
|
+
B64_LOOKUP[BASE64_CHARS.charCodeAt(i)] = i;
|
|
35
|
+
}
|
|
36
|
+
const POW2 = new Float64Array(31);
|
|
37
|
+
for (let i = 0; i < 31; i++) {
|
|
38
|
+
POW2[i] = Math.pow(2, i - 15);
|
|
39
|
+
}
|
|
40
|
+
const POW2_SUBNORMAL = Math.pow(2, -14) / 1024;
|
|
41
|
+
const MANTISSA = new Float64Array(1024);
|
|
42
|
+
for (let i = 0; i < 1024; i++) {
|
|
43
|
+
MANTISSA[i] = 1 + i / 1024;
|
|
44
|
+
}
|
|
45
|
+
function nativeGetFloat16(dataView, offset) {
|
|
46
|
+
return dataView.getFloat16(offset, true);
|
|
47
|
+
}
|
|
48
|
+
function fallbackGetFloat16(dataView, offset) {
|
|
49
|
+
return float16BitsToNumber(dataView.getUint16(offset, true));
|
|
50
|
+
}
|
|
51
|
+
const getFloat16 = typeof DataView.prototype.getFloat16 === "function" ? nativeGetFloat16 : fallbackGetFloat16;
|
|
52
|
+
function nativeSetFloat16(dataView, offset, value) {
|
|
53
|
+
;
|
|
54
|
+
dataView.setFloat16(offset, value, true);
|
|
55
|
+
}
|
|
56
|
+
function fallbackSetFloat16(dataView, offset, value) {
|
|
57
|
+
dataView.setUint16(offset, numberToFloat16Bits(value), true);
|
|
58
|
+
}
|
|
59
|
+
const setFloat16 = typeof DataView.prototype.setFloat16 === "function" ? nativeSetFloat16 : fallbackSetFloat16;
|
|
60
|
+
function nativeBase64ToUint8Array(base64) {
|
|
61
|
+
return Uint8Array.fromBase64(base64);
|
|
62
|
+
}
|
|
63
|
+
function fallbackBase64ToUint8Array(base64) {
|
|
64
|
+
const numBytes = Math.floor(base64.length * 3 / 4);
|
|
65
|
+
const bytes = new Uint8Array(numBytes);
|
|
66
|
+
let byteIndex = 0;
|
|
67
|
+
for (let i = 0; i < base64.length; i += 4) {
|
|
68
|
+
const c0 = B64_LOOKUP[base64.charCodeAt(i)];
|
|
69
|
+
const c1 = B64_LOOKUP[base64.charCodeAt(i + 1)];
|
|
70
|
+
const c2 = B64_LOOKUP[base64.charCodeAt(i + 2)];
|
|
71
|
+
const c3 = B64_LOOKUP[base64.charCodeAt(i + 3)];
|
|
72
|
+
const bitmap = c0 << 18 | c1 << 12 | c2 << 6 | c3;
|
|
73
|
+
bytes[byteIndex++] = bitmap >> 16 & 255;
|
|
74
|
+
bytes[byteIndex++] = bitmap >> 8 & 255;
|
|
75
|
+
bytes[byteIndex++] = bitmap & 255;
|
|
76
|
+
}
|
|
77
|
+
return bytes;
|
|
78
|
+
}
|
|
79
|
+
function nativeUint8ArrayToBase64(uint8Array) {
|
|
80
|
+
return uint8Array.toBase64();
|
|
81
|
+
}
|
|
82
|
+
function fallbackUint8ArrayToBase64(uint8Array) {
|
|
83
|
+
(0, import_utils.assert)(uint8Array.length % 3 === 0, "Uint8Array length must be a multiple of 3");
|
|
84
|
+
let result = "";
|
|
85
|
+
for (let i = 0; i < uint8Array.length; i += 3) {
|
|
86
|
+
const byte1 = uint8Array[i];
|
|
87
|
+
const byte2 = uint8Array[i + 1];
|
|
88
|
+
const byte3 = uint8Array[i + 2];
|
|
89
|
+
const bitmap = byte1 << 16 | byte2 << 8 | byte3;
|
|
90
|
+
result += BASE64_CHARS[bitmap >> 18 & 63] + BASE64_CHARS[bitmap >> 12 & 63] + BASE64_CHARS[bitmap >> 6 & 63] + BASE64_CHARS[bitmap & 63];
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
const uint8ArrayToBase64 = typeof Uint8Array.prototype.toBase64 === "function" ? nativeUint8ArrayToBase64 : fallbackUint8ArrayToBase64;
|
|
95
|
+
const base64ToUint8Array = typeof Uint8Array.fromBase64 === "function" ? nativeBase64ToUint8Array : fallbackBase64ToUint8Array;
|
|
96
|
+
function float16BitsToNumber(bits) {
|
|
97
|
+
const sign = bits >> 15;
|
|
98
|
+
const exp = bits >> 10 & 31;
|
|
99
|
+
const frac = bits & 1023;
|
|
100
|
+
if (exp === 0) {
|
|
101
|
+
return sign ? -frac * POW2_SUBNORMAL : frac * POW2_SUBNORMAL;
|
|
102
|
+
}
|
|
103
|
+
if (exp === 31) {
|
|
104
|
+
return frac ? NaN : sign ? -Infinity : Infinity;
|
|
105
|
+
}
|
|
106
|
+
const magnitude = POW2[exp] * MANTISSA[frac];
|
|
107
|
+
return sign ? -magnitude : magnitude;
|
|
108
|
+
}
|
|
109
|
+
function numberToFloat16Bits(value) {
|
|
110
|
+
if (value === 0) return Object.is(value, -0) ? 32768 : 0;
|
|
111
|
+
if (!Number.isFinite(value)) {
|
|
112
|
+
if (Number.isNaN(value)) return 32256;
|
|
113
|
+
return value > 0 ? 31744 : 64512;
|
|
114
|
+
}
|
|
115
|
+
const sign = value < 0 ? 1 : 0;
|
|
116
|
+
value = Math.abs(value);
|
|
117
|
+
const exp = Math.floor(Math.log2(value));
|
|
118
|
+
let expBiased = exp + 15;
|
|
119
|
+
if (expBiased >= 31) {
|
|
120
|
+
return sign << 15 | 31744;
|
|
121
|
+
}
|
|
122
|
+
if (expBiased <= 0) {
|
|
123
|
+
const frac2 = Math.round(value * Math.pow(2, 14) * 1024);
|
|
124
|
+
return sign << 15 | frac2 & 1023;
|
|
125
|
+
}
|
|
126
|
+
const mantissa = value / Math.pow(2, exp) - 1;
|
|
127
|
+
let frac = Math.round(mantissa * 1024);
|
|
128
|
+
if (frac >= 1024) {
|
|
129
|
+
frac = 0;
|
|
130
|
+
expBiased++;
|
|
131
|
+
if (expBiased >= 31) {
|
|
132
|
+
return sign << 15 | 31744;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return sign << 15 | expBiased << 10 | frac;
|
|
136
|
+
}
|
|
137
|
+
class b64Vecs {
|
|
138
|
+
/**
|
|
139
|
+
* Encode a single point (x, y, z) to 8 base64 characters using legacy Float16 encoding.
|
|
140
|
+
* Each coordinate is encoded as a Float16 value, resulting in 6 bytes total.
|
|
141
|
+
*
|
|
142
|
+
* @param x - The x coordinate
|
|
143
|
+
* @param y - The y coordinate
|
|
144
|
+
* @param z - The z coordinate
|
|
145
|
+
* @returns An 8-character base64 string representing the point
|
|
146
|
+
* @internal
|
|
147
|
+
*/
|
|
148
|
+
static _legacyEncodePoint(x, y, z) {
|
|
149
|
+
const buffer = new Uint8Array(6);
|
|
150
|
+
const dataView = new DataView(buffer.buffer);
|
|
151
|
+
setFloat16(dataView, 0, x);
|
|
152
|
+
setFloat16(dataView, 2, y);
|
|
153
|
+
setFloat16(dataView, 4, z);
|
|
154
|
+
return uint8ArrayToBase64(buffer);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Convert an array of VecModels to a base64 string using legacy Float16 encoding.
|
|
158
|
+
* Uses Float16 encoding for each coordinate (x, y, z). If a point's z value is
|
|
159
|
+
* undefined, it defaults to 0.5.
|
|
160
|
+
*
|
|
161
|
+
* @param points - An array of VecModel objects to encode
|
|
162
|
+
* @returns A base64-encoded string containing all points
|
|
163
|
+
* @internal Used only for migrations from legacy format
|
|
164
|
+
*/
|
|
165
|
+
static _legacyEncodePoints(points) {
|
|
166
|
+
if (points.length === 0) return "";
|
|
167
|
+
const buffer = new Uint8Array(points.length * 6);
|
|
168
|
+
const dataView = new DataView(buffer.buffer);
|
|
169
|
+
for (let i = 0; i < points.length; i++) {
|
|
170
|
+
const p = points[i];
|
|
171
|
+
const offset = i * 6;
|
|
172
|
+
setFloat16(dataView, offset, p.x);
|
|
173
|
+
setFloat16(dataView, offset + 2, p.y);
|
|
174
|
+
setFloat16(dataView, offset + 4, p.z ?? 0.5);
|
|
175
|
+
}
|
|
176
|
+
return uint8ArrayToBase64(buffer);
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Convert a legacy base64 string back to an array of VecModels.
|
|
180
|
+
* Decodes Float16-encoded coordinates (x, y, z) from the base64 string.
|
|
181
|
+
*
|
|
182
|
+
* @param base64 - The base64-encoded string containing point data
|
|
183
|
+
* @returns An array of VecModel objects decoded from the string
|
|
184
|
+
* @internal Used only for migrations from legacy format
|
|
185
|
+
*/
|
|
186
|
+
static _legacyDecodePoints(base64) {
|
|
187
|
+
const bytes = base64ToUint8Array(base64);
|
|
188
|
+
const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
189
|
+
const result = [];
|
|
190
|
+
for (let offset = 0; offset < bytes.length; offset += 6) {
|
|
191
|
+
result.push({
|
|
192
|
+
x: getFloat16(dataView, offset),
|
|
193
|
+
y: getFloat16(dataView, offset + 2),
|
|
194
|
+
z: getFloat16(dataView, offset + 4)
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Encode an array of VecModels using delta encoding for improved precision.
|
|
201
|
+
* The first point is stored as Float32 (high precision for absolute position),
|
|
202
|
+
* subsequent points are stored as Float16 deltas from the previous point.
|
|
203
|
+
* This provides full precision for the starting position and excellent precision
|
|
204
|
+
* for deltas between consecutive points (which are typically small values).
|
|
205
|
+
*
|
|
206
|
+
* Format:
|
|
207
|
+
* - First point: 3 Float32 values = 12 bytes = 16 base64 chars
|
|
208
|
+
* - Delta points: 3 Float16 values each = 6 bytes = 8 base64 chars each
|
|
209
|
+
*
|
|
210
|
+
* @param points - An array of VecModel objects to encode
|
|
211
|
+
* @returns A base64-encoded string containing delta-encoded points
|
|
212
|
+
* @public
|
|
213
|
+
*/
|
|
214
|
+
static encodePoints(points) {
|
|
215
|
+
if (points.length === 0) return "";
|
|
216
|
+
const firstPointBytes = 12;
|
|
217
|
+
const deltaBytes = (points.length - 1) * 6;
|
|
218
|
+
const totalBytes = firstPointBytes + deltaBytes;
|
|
219
|
+
const buffer = new Uint8Array(totalBytes);
|
|
220
|
+
const dataView = new DataView(buffer.buffer);
|
|
221
|
+
const first = points[0];
|
|
222
|
+
dataView.setFloat32(0, first.x, true);
|
|
223
|
+
dataView.setFloat32(4, first.y, true);
|
|
224
|
+
dataView.setFloat32(8, first.z ?? 0.5, true);
|
|
225
|
+
let prevX = first.x;
|
|
226
|
+
let prevY = first.y;
|
|
227
|
+
let prevZ = first.z ?? 0.5;
|
|
228
|
+
for (let i = 1; i < points.length; i++) {
|
|
229
|
+
const p = points[i];
|
|
230
|
+
const z = p.z ?? 0.5;
|
|
231
|
+
const offset = firstPointBytes + (i - 1) * 6;
|
|
232
|
+
setFloat16(dataView, offset, p.x - prevX);
|
|
233
|
+
setFloat16(dataView, offset + 2, p.y - prevY);
|
|
234
|
+
setFloat16(dataView, offset + 4, z - prevZ);
|
|
235
|
+
prevX = p.x;
|
|
236
|
+
prevY = p.y;
|
|
237
|
+
prevZ = z;
|
|
238
|
+
}
|
|
239
|
+
return uint8ArrayToBase64(buffer);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Decode a delta-encoded base64 string back to an array of absolute VecModels.
|
|
243
|
+
* The first point is stored as Float32 (high precision), subsequent points are
|
|
244
|
+
* Float16 deltas that are accumulated to reconstruct absolute positions.
|
|
245
|
+
*
|
|
246
|
+
* @param base64 - The base64-encoded string containing delta-encoded point data
|
|
247
|
+
* @returns An array of VecModel objects with absolute coordinates
|
|
248
|
+
* @public
|
|
249
|
+
*/
|
|
250
|
+
static decodePoints(base64) {
|
|
251
|
+
if (base64.length === 0) return [];
|
|
252
|
+
const bytes = base64ToUint8Array(base64);
|
|
253
|
+
const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
254
|
+
const result = [];
|
|
255
|
+
let x = dataView.getFloat32(0, true);
|
|
256
|
+
let y = dataView.getFloat32(4, true);
|
|
257
|
+
let z = dataView.getFloat32(8, true);
|
|
258
|
+
result.push({ x, y, z });
|
|
259
|
+
const firstPointBytes = 12;
|
|
260
|
+
for (let offset = firstPointBytes; offset < bytes.length; offset += 6) {
|
|
261
|
+
x += getFloat16(dataView, offset);
|
|
262
|
+
y += getFloat16(dataView, offset + 2);
|
|
263
|
+
z += getFloat16(dataView, offset + 4);
|
|
264
|
+
result.push({ x, y, z });
|
|
265
|
+
}
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Get the first point from a delta-encoded base64 string.
|
|
270
|
+
* The first point is stored as Float32 for full precision.
|
|
271
|
+
*
|
|
272
|
+
* @param b64Points - The delta-encoded base64 string
|
|
273
|
+
* @returns The first point as a VecModel, or null if the string is too short
|
|
274
|
+
* @public
|
|
275
|
+
*/
|
|
276
|
+
static decodeFirstPoint(b64Points) {
|
|
277
|
+
if (b64Points.length < FIRST_POINT_B64_LENGTH) return null;
|
|
278
|
+
const bytes = base64ToUint8Array(b64Points.slice(0, FIRST_POINT_B64_LENGTH));
|
|
279
|
+
const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
280
|
+
return {
|
|
281
|
+
x: dataView.getFloat32(0, true),
|
|
282
|
+
y: dataView.getFloat32(4, true),
|
|
283
|
+
z: dataView.getFloat32(8, true)
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Get the last point from a delta-encoded base64 string.
|
|
288
|
+
* Requires decoding all points to accumulate deltas.
|
|
289
|
+
*
|
|
290
|
+
* @param b64Points - The delta-encoded base64 string
|
|
291
|
+
* @returns The last point as a VecModel, or null if the string is too short
|
|
292
|
+
* @public
|
|
293
|
+
*/
|
|
294
|
+
static decodeLastPoint(b64Points) {
|
|
295
|
+
if (b64Points.length < FIRST_POINT_B64_LENGTH) return null;
|
|
296
|
+
const bytes = base64ToUint8Array(b64Points);
|
|
297
|
+
const dataView = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
298
|
+
let x = dataView.getFloat32(0, true);
|
|
299
|
+
let y = dataView.getFloat32(4, true);
|
|
300
|
+
let z = dataView.getFloat32(8, true);
|
|
301
|
+
const firstPointBytes = 12;
|
|
302
|
+
for (let offset = firstPointBytes; offset < bytes.length; offset += 6) {
|
|
303
|
+
x += getFloat16(dataView, offset);
|
|
304
|
+
y += getFloat16(dataView, offset + 2);
|
|
305
|
+
z += getFloat16(dataView, offset + 4);
|
|
306
|
+
}
|
|
307
|
+
return { x, y, z };
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
//# sourceMappingURL=b64Vecs.js.map
|