2023-04-25 11:01:25 +00:00
|
|
|
## API Report File for "@tldraw/utils"
|
|
|
|
|
|
|
|
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
|
|
|
// @internal
|
|
|
|
export function annotateError(error: unknown, annotations: Partial<ErrorAnnotations>): void;
|
|
|
|
|
|
|
|
// @internal (undocumented)
|
|
|
|
export const assert: (value: unknown, message?: string) => asserts value;
|
|
|
|
|
|
|
|
// @internal (undocumented)
|
|
|
|
export const assertExists: <T>(value: T, message?: string | undefined) => NonNullable<T>;
|
|
|
|
|
|
|
|
// @internal (undocumented)
|
|
|
|
export function compact<T>(arr: T[]): NonNullable<T>[];
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function debounce<T extends unknown[], U>(callback: (...args: T) => PromiseLike<U> | U, wait: number): {
|
|
|
|
(...args: T): Promise<U>;
|
|
|
|
cancel(): void;
|
|
|
|
};
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function dedupe<T>(input: T[], equals?: (a: any, b: any) => boolean): T[];
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function deepCopy<T = unknown>(obj: T): T;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
export type ErrorResult<E> = {
|
|
|
|
readonly ok: false;
|
|
|
|
readonly error: E;
|
|
|
|
};
|
|
|
|
|
|
|
|
// @internal (undocumented)
|
|
|
|
export function exhaustiveSwitchError(value: never, property?: string): never;
|
|
|
|
|
2023-06-16 10:33:47 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export type Expand<T> = T extends infer O ? {
|
|
|
|
[K in keyof O]: O[K];
|
|
|
|
} : never;
|
|
|
|
|
2023-07-19 10:50:40 +00:00
|
|
|
// @public
|
|
|
|
export class FileHelpers {
|
|
|
|
// @internal (undocumented)
|
|
|
|
static base64ToFile(dataURL: string): Promise<ArrayBuffer>;
|
|
|
|
static fileToBase64(file: Blob): Promise<string>;
|
|
|
|
}
|
|
|
|
|
derived presence state (#1204)
This PR adds
- A new `TLInstancePresence` record type, to collect info about the
presence state in a particular instance of the editor. This will
eventually be used to sync presence data instead of sending
instance-only state across the wire.
- **Record Scopes**
`RecordType` now has a `scope` property which can be one of three
things:
- `document`: the record belongs to the document and should be synced
and persisted freely. Currently: `TLDocument`, `TLPage`, `TLShape`, and
`TLAsset`
- `instance`: the record belongs to a single instance of the store and
should not be synced at all. It should not be persisted directly in most
cases, but rather compiled into a kind of 'instance configuration' to
store alongside the local document data so that when reopening the
associated document it can remember some of the previous instance state.
Currently: `TLInstance`, `TLInstancePageState`, `TLCamera`, `TLUser`,
`TLUserDocument`, `TLUserPresence`
- `presence`: the record belongs to a single instance of the store and
should not be persisted, but may be synced using the special presence
sync protocol. Currently just `TLInstancePresence`
This sets us up for the following changes, which are gonna be pretty
high-impact in terms of integrating tldraw into existing systems:
- Removing `instanceId` as a config option. Each instance gets a
randomly generated ID.
- We'd replace it with an `instanceConfig` option that has stuff like
selectedIds, camera positions, and so on. Then it's up to library users
to get and reinstate the instance config at persistence boundaries.
- Removing `userId` as config option, and removing the `TLUser` type
altogether.
- We might need to revisit when doing auth-enabled features like locking
shapes, but I suspect that will be separate.
2023-04-27 18:03:19 +00:00
|
|
|
// @internal
|
|
|
|
export function filterEntries<Key extends string, Value>(object: {
|
|
|
|
[K in Key]: Value;
|
|
|
|
}, predicate: (key: Key, value: Value) => boolean): {
|
|
|
|
[K in Key]: Value;
|
|
|
|
};
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// @internal (undocumented)
|
|
|
|
export function getErrorAnnotations(error: Error): ErrorAnnotations;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function getFirstFromIterable<T = unknown>(set: Map<any, T> | Set<T>): T;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function getHashForObject(obj: any): string;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function getHashForString(string: string): string;
|
|
|
|
|
|
|
|
// @internal (undocumented)
|
|
|
|
export function getOwnProperty<K extends string, V>(obj: Partial<Record<K, V>>, key: K): undefined | V;
|
|
|
|
|
|
|
|
// @internal (undocumented)
|
|
|
|
export function getOwnProperty(obj: object, key: string): unknown;
|
|
|
|
|
|
|
|
// @internal (undocumented)
|
|
|
|
export function hasOwnProperty(obj: object, key: string): boolean;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function isDefined<T>(value: T): value is typeof value extends undefined ? never : T;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function isNonNull<T>(value: T): value is typeof value extends null ? never : T;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function isNonNullish<T>(value: T): value is typeof value extends undefined ? never : typeof value extends null ? never : T;
|
|
|
|
|
tldraw zero - package shuffle (#1710)
This PR moves code between our packages so that:
- @tldraw/editor is a “core” library with the engine and canvas but no
shapes, tools, or other things
- @tldraw/tldraw contains everything particular to the experience we’ve
built for tldraw
At first look, this might seem like a step away from customization and
configuration, however I believe it greatly increases the configuration
potential of the @tldraw/editor while also providing a more accurate
reflection of what configuration options actually exist for
@tldraw/tldraw.
## Library changes
@tldraw/editor re-exports its dependencies and @tldraw/tldraw re-exports
@tldraw/editor.
- users of @tldraw/editor WITHOUT @tldraw/tldraw should almost always
only import things from @tldraw/editor.
- users of @tldraw/tldraw should almost always only import things from
@tldraw/tldraw.
- @tldraw/polyfills is merged into @tldraw/editor
- @tldraw/indices is merged into @tldraw/editor
- @tldraw/primitives is merged mostly into @tldraw/editor, partially
into @tldraw/tldraw
- @tldraw/file-format is merged into @tldraw/tldraw
- @tldraw/ui is merged into @tldraw/tldraw
Many (many) utils and other code is moved from the editor to tldraw. For
example, embeds now are entirely an feature of @tldraw/tldraw. The only
big chunk of code left in core is related to arrow handling.
## API Changes
The editor can now be used without tldraw's assets. We load them in
@tldraw/tldraw instead, so feel free to use whatever fonts or images or
whatever that you like with the editor.
All tools and shapes (except for the `Group` shape) are moved to
@tldraw/tldraw. This includes the `select` tool.
You should use the editor with at least one tool, however, so you now
also need to send in an `initialState` prop to the Editor /
<TldrawEditor> component indicating which state the editor should begin
in.
The `components` prop now also accepts `SelectionForeground`.
The complex selection component that we use for tldraw is moved to
@tldraw/tldraw. The default component is quite basic but can easily be
replaced via the `components` prop. We pass down our tldraw-flavored
SelectionFg via `components`.
Likewise with the `Scribble` component: the `DefaultScribble` no longer
uses our freehand tech and is a simple path instead. We pass down the
tldraw-flavored scribble via `components`.
The `ExternalContentManager` (`Editor.externalContentManager`) is
removed and replaced with a mapping of types to handlers.
- Register new content handlers with
`Editor.registerExternalContentHandler`.
- Register new asset creation handlers (for files and URLs) with
`Editor.registerExternalAssetHandler`
### Change Type
- [x] `major` — Breaking change
### Test Plan
- [x] Unit Tests
- [x] End to end tests
### Release Notes
- [@tldraw/editor] lots, wip
- [@tldraw/ui] gone, merged to tldraw/tldraw
- [@tldraw/polyfills] gone, merged to tldraw/editor
- [@tldraw/primitives] gone, merged to tldraw/editor / tldraw/tldraw
- [@tldraw/indices] gone, merged to tldraw/editor
- [@tldraw/file-format] gone, merged to tldraw/tldraw
---------
Co-authored-by: alex <alex@dytry.ch>
2023-07-17 21:22:34 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export function isValidUrl(url: string): boolean;
|
|
|
|
|
2023-06-28 14:24:05 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export type JsonArray = JsonValue[];
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
export type JsonObject = {
|
|
|
|
[key: string]: JsonValue | undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
export type JsonPrimitive = boolean | null | number | string;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
export type JsonValue = JsonArray | JsonObject | JsonPrimitive;
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// @internal (undocumented)
|
|
|
|
export function last<T>(arr: readonly T[]): T | undefined;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function lerp(a: number, b: number, t: number): number;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
export function lns(str: string): string;
|
|
|
|
|
2023-06-12 14:04:14 +00:00
|
|
|
// @internal
|
|
|
|
export function mapObjectMapValues<Key extends string, ValueBefore, ValueAfter>(object: {
|
|
|
|
readonly [K in Key]: ValueBefore;
|
|
|
|
}, mapper: (key: Key, value: ValueBefore) => ValueAfter): {
|
|
|
|
[K in Key]: ValueAfter;
|
|
|
|
};
|
|
|
|
|
2023-07-19 10:50:40 +00:00
|
|
|
// @public
|
|
|
|
export class MediaHelpers {
|
|
|
|
static getImageSizeFromSrc(dataURL: string): Promise<{
|
|
|
|
w: number;
|
|
|
|
h: number;
|
|
|
|
}>;
|
|
|
|
static getVideoSizeFromSrc(src: string): Promise<{
|
|
|
|
w: number;
|
|
|
|
h: number;
|
|
|
|
}>;
|
|
|
|
}
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// @internal (undocumented)
|
|
|
|
export function minBy<T>(arr: readonly T[], fn: (item: T) => number): T | undefined;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function modulate(value: number, rangeA: number[], rangeB: number[], clamp?: boolean): number;
|
|
|
|
|
2023-06-12 14:04:14 +00:00
|
|
|
// @internal
|
|
|
|
export function noop(): void;
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// @internal
|
|
|
|
export function objectMapEntries<Key extends string, Value>(object: {
|
|
|
|
[K in Key]: Value;
|
|
|
|
}): Array<[Key, Value]>;
|
|
|
|
|
2023-05-24 11:25:41 +00:00
|
|
|
// @internal
|
|
|
|
export function objectMapFromEntries<Key extends string, Value>(entries: ReadonlyArray<readonly [Key, Value]>): {
|
|
|
|
[K in Key]: Value;
|
|
|
|
};
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// @internal
|
|
|
|
export function objectMapKeys<Key extends string>(object: {
|
|
|
|
readonly [K in Key]: unknown;
|
|
|
|
}): Array<Key>;
|
|
|
|
|
|
|
|
// @internal
|
|
|
|
export function objectMapValues<Key extends string, Value>(object: {
|
|
|
|
[K in Key]: Value;
|
|
|
|
}): Array<Value>;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
export type OkResult<T> = {
|
|
|
|
readonly ok: true;
|
|
|
|
readonly value: T;
|
|
|
|
};
|
|
|
|
|
|
|
|
// @internal
|
|
|
|
export function omitFromStackTrace<Args extends Array<unknown>, Return>(fn: (...args: Args) => Return): (...args: Args) => Return;
|
|
|
|
|
|
|
|
// @internal
|
|
|
|
export function partition<T>(arr: T[], predicate: (item: T) => boolean): [T[], T[]];
|
|
|
|
|
2023-07-19 10:50:40 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export class PngHelpers {
|
|
|
|
// (undocumented)
|
|
|
|
static findChunk(view: DataView, type: string): {
|
|
|
|
dataOffset: number;
|
|
|
|
size: number;
|
|
|
|
start: number;
|
|
|
|
};
|
|
|
|
// (undocumented)
|
|
|
|
static getChunkType(view: DataView, offset: number): string;
|
|
|
|
// (undocumented)
|
|
|
|
static isPng(view: DataView, offset: number): boolean;
|
|
|
|
// (undocumented)
|
|
|
|
static parsePhys(view: DataView, offset: number): {
|
|
|
|
ppux: number;
|
|
|
|
ppuy: number;
|
|
|
|
unit: number;
|
|
|
|
};
|
|
|
|
// (undocumented)
|
|
|
|
static readChunks(view: DataView, offset?: number): Record<string, {
|
|
|
|
dataOffset: number;
|
|
|
|
size: number;
|
|
|
|
start: number;
|
|
|
|
}>;
|
|
|
|
// (undocumented)
|
|
|
|
static setPhysChunk(view: DataView, dpr?: number, options?: BlobPropertyBag): Blob;
|
|
|
|
}
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// @internal (undocumented)
|
|
|
|
export function promiseWithResolve<T>(): Promise<T> & {
|
|
|
|
resolve: (value: T) => void;
|
|
|
|
reject: (reason?: any) => void;
|
|
|
|
};
|
|
|
|
|
2023-05-12 09:43:51 +00:00
|
|
|
// @internal
|
|
|
|
export function rafThrottle(fn: () => void): () => void;
|
|
|
|
|
2023-06-09 11:43:01 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export type RecursivePartial<T> = {
|
|
|
|
[P in keyof T]?: RecursivePartial<T[P]>;
|
|
|
|
};
|
|
|
|
|
2023-06-12 14:04:14 +00:00
|
|
|
// @internal (undocumented)
|
2023-06-16 10:33:47 +00:00
|
|
|
type Required_2<T, K extends keyof T> = Expand<Omit<T, K> & _Required<Pick<T, K>>>;
|
2023-06-12 14:04:14 +00:00
|
|
|
export { Required_2 as Required }
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export type Result<T, E> = ErrorResult<E> | OkResult<T>;
|
|
|
|
|
|
|
|
// @public (undocumented)
|
|
|
|
export const Result: {
|
|
|
|
ok<T>(value: T): OkResult<T>;
|
|
|
|
err<E>(error: E): ErrorResult<E>;
|
|
|
|
};
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function rng(seed?: string): () => number;
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function rotateArray<T>(arr: T[], offset: number): T[];
|
|
|
|
|
2023-05-22 08:18:01 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
export function sortById<T extends {
|
|
|
|
id: any;
|
|
|
|
}>(a: T, b: T): -1 | 1;
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// @public (undocumented)
|
|
|
|
const structuredClone_2: <T>(i: T) => T;
|
|
|
|
export { structuredClone_2 as structuredClone }
|
|
|
|
|
|
|
|
// @public
|
|
|
|
export function throttle<T extends (...args: any) => any>(func: T, limit: number): (...args: Parameters<T>) => ReturnType<T>;
|
|
|
|
|
2023-05-12 09:43:51 +00:00
|
|
|
// @internal
|
|
|
|
export function throttledRaf(fn: () => void): void;
|
|
|
|
|
2023-04-25 11:01:25 +00:00
|
|
|
// (No @packageDocumentation comment for this package)
|
|
|
|
|
|
|
|
```
|