@tldraw/editor 4.6.0-next.5a871ec02ff3 → 4.6.0-next.d15997ff5a4b
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 +124 -6
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/TldrawEditor.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCanvas.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js +1 -1
- package/dist-cjs/lib/components/default-components/DefaultCollaboratorHint.js.map +2 -2
- package/dist-cjs/lib/components/default-components/DefaultErrorFallback.js.map +2 -2
- package/dist-cjs/lib/config/createTLStore.js +1 -1
- package/dist-cjs/lib/config/createTLStore.js.map +2 -2
- package/dist-cjs/lib/config/createTLUser.js.map +1 -1
- package/dist-cjs/lib/config/defaultShapes.js.map +2 -2
- package/dist-cjs/lib/editor/Editor.js +463 -354
- package/dist-cjs/lib/editor/Editor.js.map +2 -2
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js +25 -64
- package/dist-cjs/lib/editor/managers/ClickManager/ClickManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js +1 -1
- package/dist-cjs/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js +14 -53
- package/dist-cjs/lib/editor/managers/FocusManager/FocusManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js +71 -112
- package/dist-cjs/lib/editor/managers/InputsManager/InputsManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js +21 -56
- package/dist-cjs/lib/editor/managers/SnapManager/BoundsSnaps.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js +11 -52
- package/dist-cjs/lib/editor/managers/SnapManager/HandleSnaps.js.map +2 -2
- package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js +19 -56
- package/dist-cjs/lib/editor/managers/SnapManager/SnapManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js +4 -4
- package/dist-cjs/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js +102 -30
- package/dist-cjs/lib/editor/managers/TextManager/TextManager.js.map +2 -2
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js +16 -55
- package/dist-cjs/lib/editor/managers/TickManager/TickManager.js.map +1 -1
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js +57 -68
- package/dist-cjs/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.js.map +2 -2
- package/dist-cjs/lib/editor/shapes/ShapeUtil.js.map +1 -1
- package/dist-cjs/lib/exports/ExportDelay.js +12 -53
- package/dist-cjs/lib/exports/ExportDelay.js.map +1 -1
- package/dist-cjs/lib/exports/FontEmbedder.js +14 -57
- package/dist-cjs/lib/exports/FontEmbedder.js.map +1 -1
- package/dist-cjs/lib/exports/StyleEmbedder.js +1 -1
- package/dist-cjs/lib/exports/StyleEmbedder.js.map +2 -2
- package/dist-cjs/lib/exports/getSvgJsx.js.map +2 -2
- package/dist-cjs/lib/hooks/useEditorComponents.js.map +2 -2
- package/dist-cjs/lib/hooks/useLocalStore.js.map +2 -2
- package/dist-cjs/lib/options.js +3 -0
- package/dist-cjs/lib/options.js.map +2 -2
- package/dist-cjs/lib/primitives/Box.js +26 -26
- package/dist-cjs/lib/primitives/Box.js.map +2 -2
- package/dist-cjs/lib/primitives/Vec.js +1 -1
- package/dist-cjs/lib/primitives/Vec.js.map +1 -1
- package/dist-cjs/lib/primitives/geometry/Arc2d.js +2 -2
- package/dist-cjs/lib/primitives/geometry/Arc2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Circle2d.js +2 -2
- package/dist-cjs/lib/primitives/geometry/Circle2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/CubicSpline2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/CubicSpline2d.js.map +1 -1
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js +3 -3
- package/dist-cjs/lib/primitives/geometry/Ellipse2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js +10 -9
- package/dist-cjs/lib/primitives/geometry/Geometry2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Polyline2d.js +2 -2
- package/dist-cjs/lib/primitives/geometry/Polyline2d.js.map +2 -2
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js +1 -1
- package/dist-cjs/lib/primitives/geometry/Stadium2d.js.map +2 -2
- package/dist-cjs/lib/utils/SharedStylesMap.js +1 -1
- package/dist-cjs/lib/utils/SharedStylesMap.js.map +1 -1
- package/dist-cjs/lib/utils/getSvgPathFromPoints.js.map +2 -2
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js +3 -2
- package/dist-cjs/lib/utils/sync/TLLocalSyncClient.js.map +2 -2
- package/dist-cjs/version.js +3 -3
- package/dist-cjs/version.js.map +1 -1
- package/dist-esm/index.d.mts +124 -6
- package/dist-esm/index.mjs +4 -2
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/TldrawEditor.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultCanvas.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs +1 -1
- package/dist-esm/lib/components/default-components/DefaultCollaboratorHint.mjs.map +2 -2
- package/dist-esm/lib/components/default-components/DefaultErrorFallback.mjs.map +2 -2
- package/dist-esm/lib/config/createTLStore.mjs +1 -1
- package/dist-esm/lib/config/createTLStore.mjs.map +2 -2
- package/dist-esm/lib/config/createTLUser.mjs.map +1 -1
- package/dist-esm/lib/config/defaultShapes.mjs.map +2 -2
- package/dist-esm/lib/editor/Editor.mjs +465 -357
- package/dist-esm/lib/editor/Editor.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs +25 -64
- package/dist-esm/lib/editor/managers/ClickManager/ClickManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs +1 -1
- package/dist-esm/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs +14 -53
- package/dist-esm/lib/editor/managers/FocusManager/FocusManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs +71 -112
- package/dist-esm/lib/editor/managers/InputsManager/InputsManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs +21 -56
- package/dist-esm/lib/editor/managers/SnapManager/BoundsSnaps.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs +11 -52
- package/dist-esm/lib/editor/managers/SnapManager/HandleSnaps.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs +19 -56
- package/dist-esm/lib/editor/managers/SnapManager/SnapManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs +4 -4
- package/dist-esm/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs +102 -30
- package/dist-esm/lib/editor/managers/TextManager/TextManager.mjs.map +2 -2
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs +16 -55
- package/dist-esm/lib/editor/managers/TickManager/TickManager.mjs.map +1 -1
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs +57 -68
- package/dist-esm/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.mjs.map +2 -2
- package/dist-esm/lib/editor/shapes/ShapeUtil.mjs.map +1 -1
- package/dist-esm/lib/exports/ExportDelay.mjs +12 -53
- package/dist-esm/lib/exports/ExportDelay.mjs.map +1 -1
- package/dist-esm/lib/exports/FontEmbedder.mjs +14 -57
- package/dist-esm/lib/exports/FontEmbedder.mjs.map +1 -1
- package/dist-esm/lib/exports/StyleEmbedder.mjs +1 -1
- package/dist-esm/lib/exports/StyleEmbedder.mjs.map +2 -2
- package/dist-esm/lib/exports/getSvgJsx.mjs.map +2 -2
- package/dist-esm/lib/hooks/useEditorComponents.mjs.map +2 -2
- package/dist-esm/lib/hooks/useLocalStore.mjs.map +2 -2
- package/dist-esm/lib/options.mjs +3 -0
- package/dist-esm/lib/options.mjs.map +2 -2
- package/dist-esm/lib/primitives/Box.mjs +26 -26
- package/dist-esm/lib/primitives/Box.mjs.map +2 -2
- package/dist-esm/lib/primitives/Vec.mjs +1 -1
- package/dist-esm/lib/primitives/Vec.mjs.map +1 -1
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/Arc2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/Circle2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/CubicSpline2d.mjs +1 -1
- package/dist-esm/lib/primitives/geometry/CubicSpline2d.mjs.map +1 -1
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs +3 -3
- package/dist-esm/lib/primitives/geometry/Ellipse2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs +10 -9
- package/dist-esm/lib/primitives/geometry/Geometry2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Polyline2d.mjs +2 -2
- package/dist-esm/lib/primitives/geometry/Polyline2d.mjs.map +2 -2
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs +1 -1
- package/dist-esm/lib/primitives/geometry/Stadium2d.mjs.map +2 -2
- package/dist-esm/lib/utils/SharedStylesMap.mjs +1 -1
- package/dist-esm/lib/utils/SharedStylesMap.mjs.map +1 -1
- package/dist-esm/lib/utils/getSvgPathFromPoints.mjs.map +2 -2
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs +3 -2
- package/dist-esm/lib/utils/sync/TLLocalSyncClient.mjs.map +2 -2
- package/dist-esm/version.mjs +3 -3
- package/dist-esm/version.mjs.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +15 -7
- package/src/lib/TldrawEditor.tsx +1 -1
- package/src/lib/components/default-components/DefaultCanvas.tsx +1 -1
- package/src/lib/components/default-components/DefaultCollaboratorHint.tsx +1 -1
- package/src/lib/components/default-components/DefaultErrorFallback.tsx +1 -0
- package/src/lib/config/TLEditorSnapshot.test.ts +1 -1
- package/src/lib/config/createTLStore.ts +1 -1
- package/src/lib/config/createTLUser.ts +3 -3
- package/src/lib/config/defaultShapes.ts +1 -1
- package/src/lib/editor/Editor.ts +9 -8
- package/src/lib/editor/managers/ClickManager/ClickManager.ts +1 -1
- package/src/lib/editor/managers/EdgeScrollManager/EdgeScrollManager.ts +1 -1
- package/src/lib/editor/managers/InputsManager/InputsManager.ts +30 -30
- package/src/lib/editor/managers/SnapManager/BoundsSnaps.ts +1 -1
- package/src/lib/editor/managers/SnapManager/HandleSnaps.ts +1 -1
- package/src/lib/editor/managers/SpatialIndexManager/SpatialIndexManager.ts +5 -5
- package/src/lib/editor/managers/TextManager/TextManager.test.ts +18 -4
- package/src/lib/editor/managers/TextManager/TextManager.ts +140 -34
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.test.ts +1 -1
- package/src/lib/editor/managers/UserPreferencesManager/UserPreferencesManager.ts +1 -1
- package/src/lib/editor/shapes/ShapeUtil.ts +2 -2
- package/src/lib/exports/StyleEmbedder.ts +1 -1
- package/src/lib/exports/getSvgJsx.tsx +1 -1
- package/src/lib/hooks/useEditorComponents.tsx +1 -1
- package/src/lib/hooks/useLocalStore.ts +1 -1
- package/src/lib/options.ts +108 -0
- package/src/lib/primitives/Box.ts +26 -26
- package/src/lib/primitives/Vec.ts +1 -1
- package/src/lib/primitives/geometry/Arc2d.ts +2 -2
- package/src/lib/primitives/geometry/Circle2d.ts +2 -2
- package/src/lib/primitives/geometry/CubicSpline2d.ts +1 -1
- package/src/lib/primitives/geometry/Ellipse2d.ts +3 -3
- package/src/lib/primitives/geometry/Geometry2d.ts +10 -9
- package/src/lib/primitives/geometry/Polyline2d.ts +2 -2
- package/src/lib/primitives/geometry/Stadium2d.ts +1 -1
- package/src/lib/utils/SharedStylesMap.ts +1 -1
- package/src/lib/utils/getSvgPathFromPoints.ts +1 -1
- package/src/lib/utils/sync/TLLocalSyncClient.test.ts +1 -1
- package/src/lib/utils/sync/TLLocalSyncClient.ts +2 -1
- package/src/version.ts +3 -3
|
@@ -21,6 +21,23 @@ const textAlignmentsForLtr = {
|
|
|
21
21
|
'end-legacy': 'right',
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
interface PoolItem {
|
|
25
|
+
el: HTMLDivElement
|
|
26
|
+
html: string
|
|
27
|
+
appliedStyleKeys: string[]
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @public */
|
|
31
|
+
export interface BatchMeasurementRequest {
|
|
32
|
+
html: string
|
|
33
|
+
opts: TLMeasureTextOpts
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** @public */
|
|
37
|
+
export type TLMeasuredTextSize = BoxModel & {
|
|
38
|
+
scrollWidth: number
|
|
39
|
+
}
|
|
40
|
+
|
|
24
41
|
/** @public */
|
|
25
42
|
export interface TLMeasureTextOpts {
|
|
26
43
|
fontStyle: string
|
|
@@ -73,53 +90,66 @@ const initialDefaultStyles = Object.freeze({
|
|
|
73
90
|
/** @public */
|
|
74
91
|
export class TextManager {
|
|
75
92
|
private elm: HTMLDivElement
|
|
93
|
+
private poolElms: PoolItem[] = []
|
|
76
94
|
|
|
77
95
|
constructor(public editor: Editor) {
|
|
78
|
-
|
|
96
|
+
this.elm = this.createMeasurementEl()
|
|
97
|
+
this.editor.getContainer().appendChild(this.elm)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private createMeasurementEl(): HTMLDivElement {
|
|
101
|
+
const elm = this.editor.getContainerDocument().createElement('div')
|
|
79
102
|
elm.classList.add('tl-text')
|
|
80
103
|
elm.classList.add('tl-text-measure')
|
|
81
104
|
elm.setAttribute('dir', 'auto')
|
|
82
105
|
elm.tabIndex = -1
|
|
83
|
-
this.editor.getContainer().appendChild(elm)
|
|
84
|
-
|
|
85
|
-
this.elm = elm
|
|
86
|
-
|
|
87
106
|
for (const key of objectMapKeys(initialDefaultStyles)) {
|
|
88
107
|
elm.style.setProperty(key, initialDefaultStyles[key])
|
|
89
108
|
}
|
|
109
|
+
|
|
110
|
+
return elm
|
|
90
111
|
}
|
|
91
112
|
|
|
92
|
-
private
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
stylesToReinstate[key] = oldValue
|
|
99
|
-
this.elm.style.setProperty(key, styles[key])
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return () => {
|
|
103
|
-
for (const key of objectMapKeys(stylesToReinstate)) {
|
|
104
|
-
this.elm.style.setProperty(key, stylesToReinstate[key])
|
|
113
|
+
private resetElementStyles(el: HTMLElement, appliedStyleKeys: string[]) {
|
|
114
|
+
for (const key of appliedStyleKeys) {
|
|
115
|
+
if (key in initialDefaultStyles) {
|
|
116
|
+
el.style.setProperty(key, initialDefaultStyles[key as keyof typeof initialDefaultStyles])
|
|
117
|
+
} else {
|
|
118
|
+
el.style.removeProperty(key)
|
|
105
119
|
}
|
|
106
120
|
}
|
|
107
121
|
}
|
|
108
122
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
123
|
+
private setElementStyles(el: HTMLElement, styles: Record<string, string | undefined | null>) {
|
|
124
|
+
type StyleValue = string | null
|
|
125
|
+
type RestoreEntry = [prop: string, value: StyleValue]
|
|
112
126
|
|
|
113
|
-
|
|
114
|
-
const div = this.editor.getContainerDocument().createElement('div')
|
|
115
|
-
div.textContent = normalizeTextForDom(textToMeasure)
|
|
116
|
-
return this.measureHtml(div.innerHTML, opts)
|
|
117
|
-
}
|
|
127
|
+
const restore: RestoreEntry[] = []
|
|
118
128
|
|
|
119
|
-
|
|
120
|
-
|
|
129
|
+
for (const [key, nextValue] of Object.entries(styles)) {
|
|
130
|
+
const oldValue = el.style.getPropertyValue(key)
|
|
121
131
|
|
|
122
|
-
|
|
132
|
+
if (typeof nextValue === 'string') {
|
|
133
|
+
if (oldValue === nextValue) continue
|
|
134
|
+
restore.push([key, oldValue || null])
|
|
135
|
+
el.style.setProperty(key, nextValue)
|
|
136
|
+
} else {
|
|
137
|
+
if (!oldValue) continue
|
|
138
|
+
restore.push([key, oldValue])
|
|
139
|
+
el.style.removeProperty(key)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return () => {
|
|
144
|
+
for (const [key, value] of restore) {
|
|
145
|
+
if (value === null || value === '') el.style.removeProperty(key)
|
|
146
|
+
else el.style.setProperty(key, value)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private getMeasureStyles(opts: TLMeasureTextOpts): Record<string, string | undefined> {
|
|
152
|
+
return {
|
|
123
153
|
'font-family': opts.fontFamily,
|
|
124
154
|
'font-style': opts.fontStyle,
|
|
125
155
|
'font-weight': opts.fontWeight,
|
|
@@ -128,11 +158,87 @@ export class TextManager {
|
|
|
128
158
|
padding: opts.padding,
|
|
129
159
|
'max-width': opts.maxWidth ? opts.maxWidth + 'px' : undefined,
|
|
130
160
|
'min-width': opts.minWidth ? opts.minWidth + 'px' : undefined,
|
|
131
|
-
'overflow-wrap': opts.disableOverflowWrapBreaking ? 'normal' :
|
|
161
|
+
'overflow-wrap': opts.disableOverflowWrapBreaking ? 'normal' : 'break-word',
|
|
132
162
|
...opts.otherStyles,
|
|
133
163
|
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
dispose() {
|
|
167
|
+
this.elm.remove()
|
|
168
|
+
for (const { el } of this.poolElms) {
|
|
169
|
+
el.remove()
|
|
170
|
+
}
|
|
171
|
+
this.poolElms.length = 0
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
private ensurePoolSize(size: number) {
|
|
175
|
+
if (this.poolElms.length >= size) return
|
|
176
|
+
|
|
177
|
+
const fragment = this.editor.getContainerDocument().createDocumentFragment()
|
|
178
|
+
while (this.poolElms.length < size) {
|
|
179
|
+
const el = this.createMeasurementEl()
|
|
180
|
+
this.poolElms.push({ el, html: '', appliedStyleKeys: [] })
|
|
181
|
+
fragment.appendChild(el)
|
|
182
|
+
}
|
|
183
|
+
this.editor.getContainer().appendChild(fragment)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private getPoolItem(index: number): PoolItem {
|
|
187
|
+
this.ensurePoolSize(index + 1)
|
|
188
|
+
return this.poolElms[index]
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
measureHtmlBatch(requests: BatchMeasurementRequest[]): TLMeasuredTextSize[] {
|
|
192
|
+
if (requests.length === 0) return []
|
|
193
|
+
|
|
194
|
+
while (this.poolElms.length > requests.length) {
|
|
195
|
+
const { el } = this.poolElms.pop()!
|
|
196
|
+
el.remove()
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
for (let i = 0; i < requests.length; i++) {
|
|
200
|
+
const { html, opts } = requests[i]
|
|
201
|
+
const poolItem = this.getPoolItem(i)
|
|
202
|
+
|
|
203
|
+
const { el } = poolItem
|
|
204
|
+
this.resetElementStyles(el, poolItem.appliedStyleKeys)
|
|
205
|
+
const styles = this.getMeasureStyles(opts)
|
|
206
|
+
this.setElementStyles(el, styles)
|
|
207
|
+
poolItem.appliedStyleKeys = Object.keys(styles)
|
|
208
|
+
// Skip innerHTML parsing if the content hasn't changed
|
|
209
|
+
if (poolItem.html !== html) {
|
|
210
|
+
el.innerHTML = html
|
|
211
|
+
poolItem.html = html
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const results: TLMeasuredTextSize[] = []
|
|
216
|
+
for (let i = 0; i < requests.length; i++) {
|
|
217
|
+
const el = this.getPoolItem(i).el
|
|
218
|
+
const scrollWidth = requests[i].opts.measureScrollWidth ? el.scrollWidth : 0
|
|
219
|
+
const rect = el.getBoundingClientRect()
|
|
220
|
+
results.push({
|
|
221
|
+
x: 0,
|
|
222
|
+
y: 0,
|
|
223
|
+
w: rect.width,
|
|
224
|
+
h: rect.height,
|
|
225
|
+
scrollWidth,
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return results
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
measureText(textToMeasure: string, opts: TLMeasureTextOpts): TLMeasuredTextSize {
|
|
233
|
+
const div = this.editor.getContainerDocument().createElement('div')
|
|
234
|
+
div.textContent = normalizeTextForDom(textToMeasure)
|
|
235
|
+
return this.measureHtml(div.innerHTML, opts)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
measureHtml(html: string, opts: TLMeasureTextOpts): TLMeasuredTextSize {
|
|
239
|
+
const { elm } = this
|
|
134
240
|
|
|
135
|
-
const restoreStyles = this.setElementStyles(
|
|
241
|
+
const restoreStyles = this.setElementStyles(elm, this.getMeasureStyles(opts))
|
|
136
242
|
|
|
137
243
|
try {
|
|
138
244
|
elm.innerHTML = html
|
|
@@ -280,11 +386,11 @@ export class TextManager {
|
|
|
280
386
|
width: `${elementWidth}px`,
|
|
281
387
|
height: 'min-content',
|
|
282
388
|
'text-align': textAlignmentsForLtr[opts.textAlign],
|
|
283
|
-
'overflow-wrap': shouldTruncateToFirstLine ? 'anywhere' :
|
|
284
|
-
'word-break': shouldTruncateToFirstLine ? 'break-all' :
|
|
389
|
+
'overflow-wrap': shouldTruncateToFirstLine ? 'anywhere' : 'break-word',
|
|
390
|
+
'word-break': shouldTruncateToFirstLine ? 'break-all' : 'normal',
|
|
285
391
|
...opts.otherStyles,
|
|
286
392
|
}
|
|
287
|
-
const restoreStyles = this.setElementStyles(newStyles)
|
|
393
|
+
const restoreStyles = this.setElementStyles(elm, newStyles)
|
|
288
394
|
|
|
289
395
|
try {
|
|
290
396
|
const normalizedText = normalizeTextForDom(textToMeasure)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { atom } from '@tldraw/state'
|
|
2
2
|
import { Mocked, vi } from 'vitest'
|
|
3
|
-
import { TLUserPreferences, defaultUserPreferences } from '../../../config/TLUserPreferences'
|
|
4
3
|
import { TLUser } from '../../../config/createTLUser'
|
|
4
|
+
import { TLUserPreferences, defaultUserPreferences } from '../../../config/TLUserPreferences'
|
|
5
5
|
import { UserPreferencesManager } from './UserPreferencesManager'
|
|
6
6
|
|
|
7
7
|
// Mock window.matchMedia
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { atom, computed } from '@tldraw/state'
|
|
2
|
-
import { TLUserPreferences, defaultUserPreferences } from '../../../config/TLUserPreferences'
|
|
3
2
|
import { TLUser } from '../../../config/createTLUser'
|
|
3
|
+
import { TLUserPreferences, defaultUserPreferences } from '../../../config/TLUserPreferences'
|
|
4
4
|
import { getGlobalWindow } from '../../../utils/dom'
|
|
5
5
|
|
|
6
6
|
/** @public */
|
|
@@ -15,15 +15,15 @@ import {
|
|
|
15
15
|
import { IndexKey } from '@tldraw/utils'
|
|
16
16
|
import { ReactElement } from 'react'
|
|
17
17
|
import { Box, SelectionHandle } from '../../primitives/Box'
|
|
18
|
-
import { Vec } from '../../primitives/Vec'
|
|
19
18
|
import { Geometry2d } from '../../primitives/geometry/Geometry2d'
|
|
19
|
+
import { Vec } from '../../primitives/Vec'
|
|
20
20
|
import type { Editor } from '../Editor'
|
|
21
21
|
import { TLFontFace } from '../managers/FontManager/FontManager'
|
|
22
22
|
import { BoundsSnapGeometry } from '../managers/SnapManager/BoundsSnaps'
|
|
23
23
|
import { HandleSnapGeometry } from '../managers/SnapManager/HandleSnaps'
|
|
24
|
-
import { SvgExportContext } from '../types/SvgExportContext'
|
|
25
24
|
import { TLClickEventInfo } from '../types/event-types'
|
|
26
25
|
import { TLResizeHandle } from '../types/selection-types'
|
|
26
|
+
import { SvgExportContext } from '../types/SvgExportContext'
|
|
27
27
|
|
|
28
28
|
/** @public */
|
|
29
29
|
export interface TLShapeUtilConstructor<T extends TLShape, U extends ShapeUtil<T> = ShapeUtil<T>> {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { assertExists, getOwnProperty, objectMapValues, uniqueId } from '@tldraw/utils'
|
|
2
|
-
import { FontEmbedder } from './FontEmbedder'
|
|
3
2
|
import { ReadonlyStyles, Styles, cssRules } from './cssRules'
|
|
4
3
|
import {
|
|
5
4
|
elementStyle,
|
|
@@ -9,6 +8,7 @@ import {
|
|
|
9
8
|
isElement,
|
|
10
9
|
} from './domUtils'
|
|
11
10
|
import { resourceToDataUrl } from './fetchCache'
|
|
11
|
+
import { FontEmbedder } from './FontEmbedder'
|
|
12
12
|
import { parseCssValueUrls, shouldIncludeCssProperty } from './parseCss'
|
|
13
13
|
|
|
14
14
|
const NO_STYLES = {} as const
|
|
@@ -23,12 +23,12 @@ import { InnerShape, InnerShapeBackground } from '../components/Shape'
|
|
|
23
23
|
import type { Editor, TLRenderingShape } from '../editor/Editor'
|
|
24
24
|
import { TLFontFace } from '../editor/managers/FontManager/FontManager'
|
|
25
25
|
import { ShapeUtil } from '../editor/shapes/ShapeUtil'
|
|
26
|
+
import { TLImageExportOptions } from '../editor/types/misc-types'
|
|
26
27
|
import {
|
|
27
28
|
SvgExportContext,
|
|
28
29
|
SvgExportContextProvider,
|
|
29
30
|
SvgExportDef,
|
|
30
31
|
} from '../editor/types/SvgExportContext'
|
|
31
|
-
import { TLImageExportOptions } from '../editor/types/misc-types'
|
|
32
32
|
import { useEditor } from '../hooks/useEditor'
|
|
33
33
|
import { useEvent } from '../hooks/useEvent'
|
|
34
34
|
import { suffixSafeId, useUniqueSafeId } from '../hooks/useSafeId'
|
|
@@ -19,8 +19,8 @@ import { DefaultShapeWrapper } from '../components/default-components/DefaultSha
|
|
|
19
19
|
import { DefaultSnapIndicator } from '../components/default-components/DefaultSnapIndictor'
|
|
20
20
|
import { DefaultSpinner } from '../components/default-components/DefaultSpinner'
|
|
21
21
|
import { DefaultSvgDefs } from '../components/default-components/DefaultSvgDefs'
|
|
22
|
-
import type { TLEditorComponents } from './EditorComponentsContext'
|
|
23
22
|
import { EditorComponentsContext } from './EditorComponentsContext'
|
|
23
|
+
import type { TLEditorComponents } from './EditorComponentsContext'
|
|
24
24
|
import { useShallowObjectIdentity } from './useIdentity'
|
|
25
25
|
|
|
26
26
|
export { useEditorComponents } from './EditorComponentsContext'
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { TLAsset, TLAssetStore, TLStoreSnapshot } from '@tldraw/tlschema'
|
|
2
2
|
import { WeakCache } from '@tldraw/utils'
|
|
3
3
|
import { useEffect } from 'react'
|
|
4
|
-
import { TLEditorSnapshot } from '../config/TLEditorSnapshot'
|
|
5
4
|
import { TLStoreOptions, createTLStore } from '../config/createTLStore'
|
|
5
|
+
import { TLEditorSnapshot } from '../config/TLEditorSnapshot'
|
|
6
6
|
import { TLStoreWithStatus } from '../utils/sync/StoreWithStatus'
|
|
7
7
|
import { TLLocalSyncClient } from '../utils/sync/TLLocalSyncClient'
|
|
8
8
|
import { useShallowObjectIdentity } from './useIdentity'
|
package/src/lib/options.ts
CHANGED
|
@@ -1,10 +1,50 @@
|
|
|
1
|
+
import { Awaitable } from '@tldraw/utils'
|
|
1
2
|
import { ComponentType, Fragment } from 'react'
|
|
2
3
|
import { DEFAULT_CAMERA_OPTIONS } from './constants'
|
|
4
|
+
import type { Editor } from './editor/Editor'
|
|
5
|
+
import { TLContent } from './editor/types/clipboard-types'
|
|
6
|
+
import { TLExternalContent } from './editor/types/external-content'
|
|
3
7
|
import { TLCameraOptions } from './editor/types/misc-types'
|
|
4
8
|
import { VecLike } from './primitives/Vec'
|
|
5
9
|
import { TLDeepLinkOptions } from './utils/deepLinks'
|
|
6
10
|
import { TLTextOptions } from './utils/richText'
|
|
7
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Identifies how a clipboard write was triggered (copy vs cut, keyboard vs menu).
|
|
14
|
+
*
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
export interface TLClipboardWriteInfo {
|
|
18
|
+
readonly operation: 'copy' | 'cut'
|
|
19
|
+
readonly source: 'native' | 'menu'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Raw clipboard paste payload, before tldraw parses clipboard contents into {@link TLExternalContent}.
|
|
24
|
+
*
|
|
25
|
+
* - `native-event`: from the `paste` event — `clipboardData` is available synchronously (unlike async
|
|
26
|
+
* `navigator.clipboard.read()`).
|
|
27
|
+
* - `clipboard-read`: from an explicit `navigator.clipboard.read()` call — only `ClipboardItem[]`
|
|
28
|
+
* exists
|
|
29
|
+
* (no `DataTransfer`).
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
export type TLClipboardPasteRawInfo =
|
|
34
|
+
| {
|
|
35
|
+
readonly editor: Editor
|
|
36
|
+
readonly source: 'native-event'
|
|
37
|
+
readonly event: ClipboardEvent
|
|
38
|
+
readonly clipboardData: DataTransfer | null
|
|
39
|
+
readonly point: VecLike | undefined
|
|
40
|
+
}
|
|
41
|
+
| {
|
|
42
|
+
readonly editor: Editor
|
|
43
|
+
readonly source: 'clipboard-read'
|
|
44
|
+
readonly clipboardItems: readonly ClipboardItem[]
|
|
45
|
+
readonly point: VecLike | undefined
|
|
46
|
+
}
|
|
47
|
+
|
|
8
48
|
/**
|
|
9
49
|
* Options for configuring tldraw. For defaults, see {@link defaultTldrawOptions}.
|
|
10
50
|
*
|
|
@@ -156,6 +196,71 @@ export interface TldrawOptions {
|
|
|
156
196
|
* viewport's page dimensions regardless of overview zoom changes.
|
|
157
197
|
*/
|
|
158
198
|
readonly quickZoomPreservesScreenBounds: boolean
|
|
199
|
+
/**
|
|
200
|
+
* Called before content is written to the clipboard during a copy or cut operation.
|
|
201
|
+
* Receives the serialized content (shapes, bindings, assets) and can filter or transform
|
|
202
|
+
* it before it reaches the clipboard.
|
|
203
|
+
*
|
|
204
|
+
* Return a modified `TLContent` object to change what is copied or cut. Return `false` to
|
|
205
|
+
* cancel the clipboard write (for cut, the selected shapes are not removed). Return `void`
|
|
206
|
+
* (or `undefined`) to pass through unchanged. You may return a `Promise` of those values if
|
|
207
|
+
* the hook is async.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```tsx
|
|
211
|
+
* // Filter out "locked" shapes from copy
|
|
212
|
+
* onBeforeCopyToClipboard({ content, operation }) {
|
|
213
|
+
* return {
|
|
214
|
+
* ...content,
|
|
215
|
+
* shapes: content.shapes.filter(s => !s.meta.locked),
|
|
216
|
+
* rootShapeIds: content.rootShapeIds.filter(id =>
|
|
217
|
+
* content.shapes.find(s => s.id === id && !s.meta.locked)
|
|
218
|
+
* ),
|
|
219
|
+
* }
|
|
220
|
+
* }
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
onBeforeCopyToClipboard?(
|
|
224
|
+
info: { editor: Editor; content: TLContent } & TLClipboardWriteInfo
|
|
225
|
+
): Awaitable<TLContent | false | void>
|
|
226
|
+
/**
|
|
227
|
+
* Called before pasted content is processed and shapes are created. Receives the parsed
|
|
228
|
+
* external content from the clipboard and can filter, transform, or cancel it.
|
|
229
|
+
*
|
|
230
|
+
* Return `false` to cancel the paste. Return a modified content object to transform it.
|
|
231
|
+
* Return `void` (or `undefined`) to pass through unchanged. You may return a `Promise` of
|
|
232
|
+
* those values if the hook is async.
|
|
233
|
+
*
|
|
234
|
+
* This only fires for clipboard paste operations (keyboard shortcuts and menu actions),
|
|
235
|
+
* not for file drops or programmatic `putExternalContent` calls.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```tsx
|
|
239
|
+
* // Block pasting of image files
|
|
240
|
+
* onBeforePasteFromClipboard({ content }) {
|
|
241
|
+
* if (content.type === 'files') {
|
|
242
|
+
* const nonImages = content.files.filter(f => !f.type.startsWith('image/'))
|
|
243
|
+
* if (nonImages.length === 0) return false
|
|
244
|
+
* return { ...content, files: nonImages }
|
|
245
|
+
* }
|
|
246
|
+
* }
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
onBeforePasteFromClipboard?(info: {
|
|
250
|
+
editor: Editor
|
|
251
|
+
content: TLExternalContent<unknown>
|
|
252
|
+
source: 'native-event' | 'clipboard-read'
|
|
253
|
+
point?: VecLike
|
|
254
|
+
}): Awaitable<TLExternalContent<unknown> | false | void>
|
|
255
|
+
/**
|
|
256
|
+
* Called first for keyboard and menu paste, **before** tldraw handles or parses clipboard data
|
|
257
|
+
* (and before {@link TldrawOptions.onBeforePasteFromClipboard}).
|
|
258
|
+
*
|
|
259
|
+
* Return `false` to cancel tldraw's default paste handling for this gesture (same convention as
|
|
260
|
+
* {@link TldrawOptions.onBeforePasteFromClipboard}). Use this when you handle paste yourself from
|
|
261
|
+
* raw clipboard data, or to block the gesture entirely. Return `void` (or `undefined`) to continue.
|
|
262
|
+
*/
|
|
263
|
+
onClipboardPasteRaw?(info: TLClipboardPasteRawInfo): false | void
|
|
159
264
|
/**
|
|
160
265
|
* Called when content is dropped on the canvas. Provides the page position
|
|
161
266
|
* where the drop occurred and the underlying drag event object.
|
|
@@ -227,5 +332,8 @@ export const defaultTldrawOptions = {
|
|
|
227
332
|
text: {},
|
|
228
333
|
deepLinks: undefined,
|
|
229
334
|
quickZoomPreservesScreenBounds: true,
|
|
335
|
+
onBeforeCopyToClipboard: undefined,
|
|
336
|
+
onBeforePasteFromClipboard: undefined,
|
|
337
|
+
onClipboardPasteRaw: undefined,
|
|
230
338
|
experimental__onDropOnCanvas: undefined,
|
|
231
339
|
} as const satisfies TldrawOptions
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BoxModel } from '@tldraw/tlschema'
|
|
2
|
-
import { Vec, VecLike } from './Vec'
|
|
3
2
|
import { approximatelyLte, PI, PI2, toPrecision } from './utils'
|
|
3
|
+
import { Vec, VecLike } from './Vec'
|
|
4
4
|
|
|
5
5
|
/** @public */
|
|
6
6
|
export type BoxLike = BoxModel | Box
|
|
@@ -36,114 +36,114 @@ export class Box {
|
|
|
36
36
|
w = 0
|
|
37
37
|
h = 0
|
|
38
38
|
|
|
39
|
-
// eslint-disable-next-line no-
|
|
39
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
40
40
|
get point() {
|
|
41
41
|
return new Vec(this.x, this.y)
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
// eslint-disable-next-line no-
|
|
44
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
45
45
|
set point(val: Vec) {
|
|
46
46
|
this.x = val.x
|
|
47
47
|
this.y = val.y
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
// eslint-disable-next-line no-
|
|
50
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
51
51
|
get minX() {
|
|
52
52
|
return this.x
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
// eslint-disable-next-line no-
|
|
55
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
56
56
|
set minX(n: number) {
|
|
57
57
|
this.x = n
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
// eslint-disable-next-line no-
|
|
60
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
61
61
|
get left() {
|
|
62
62
|
return this.x
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
// eslint-disable-next-line no-
|
|
65
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
66
66
|
get midX() {
|
|
67
67
|
return this.x + this.w / 2
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
// eslint-disable-next-line no-
|
|
70
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
71
71
|
get maxX() {
|
|
72
72
|
return this.x + this.w
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
// eslint-disable-next-line no-
|
|
75
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
76
76
|
get right() {
|
|
77
77
|
return this.x + this.w
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
// eslint-disable-next-line no-
|
|
80
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
81
81
|
get minY() {
|
|
82
82
|
return this.y
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
// eslint-disable-next-line no-
|
|
85
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
86
86
|
set minY(n: number) {
|
|
87
87
|
this.y = n
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
// eslint-disable-next-line no-
|
|
90
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
91
91
|
get top() {
|
|
92
92
|
return this.y
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
// eslint-disable-next-line no-
|
|
95
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
96
96
|
get midY() {
|
|
97
97
|
return this.y + this.h / 2
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
// eslint-disable-next-line no-
|
|
100
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
101
101
|
get maxY() {
|
|
102
102
|
return this.y + this.h
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
// eslint-disable-next-line no-
|
|
105
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
106
106
|
get bottom() {
|
|
107
107
|
return this.y + this.h
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
// eslint-disable-next-line no-
|
|
110
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
111
111
|
get width() {
|
|
112
112
|
return this.w
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
// eslint-disable-next-line no-
|
|
115
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
116
116
|
set width(n: number) {
|
|
117
117
|
this.w = n
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
// eslint-disable-next-line no-
|
|
120
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
121
121
|
get height() {
|
|
122
122
|
return this.h
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
// eslint-disable-next-line no-
|
|
125
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
126
126
|
set height(n: number) {
|
|
127
127
|
this.h = n
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
// eslint-disable-next-line no-
|
|
130
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
131
131
|
get aspectRatio() {
|
|
132
132
|
return this.width / this.height
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
// eslint-disable-next-line no-
|
|
135
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
136
136
|
get center() {
|
|
137
137
|
return new Vec(this.x + this.w / 2, this.y + this.h / 2)
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
// eslint-disable-next-line no-
|
|
140
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
141
141
|
set center(v: Vec) {
|
|
142
142
|
this.x = v.x - this.w / 2
|
|
143
143
|
this.y = v.y - this.h / 2
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
// eslint-disable-next-line no-
|
|
146
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
147
147
|
get corners() {
|
|
148
148
|
return [
|
|
149
149
|
new Vec(this.x, this.y),
|
|
@@ -153,7 +153,7 @@ export class Box {
|
|
|
153
153
|
]
|
|
154
154
|
}
|
|
155
155
|
|
|
156
|
-
// eslint-disable-next-line no-
|
|
156
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
157
157
|
get cornersAndCenter() {
|
|
158
158
|
return [
|
|
159
159
|
new Vec(this.x, this.y),
|
|
@@ -164,7 +164,7 @@ export class Box {
|
|
|
164
164
|
]
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
// eslint-disable-next-line no-
|
|
167
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
168
168
|
get sides(): Array<[Vec, Vec]> {
|
|
169
169
|
const { corners } = this
|
|
170
170
|
return [
|
|
@@ -175,7 +175,7 @@ export class Box {
|
|
|
175
175
|
]
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
// eslint-disable-next-line no-
|
|
178
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
179
179
|
get size(): Vec {
|
|
180
180
|
return new Vec(this.w, this.h)
|
|
181
181
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Vec, VecLike } from '../Vec'
|
|
2
1
|
import { intersectLineSegmentCircle } from '../intersect'
|
|
3
2
|
import { getArcMeasure, getPointInArcT, getPointOnCircle } from '../utils'
|
|
4
|
-
import {
|
|
3
|
+
import { Vec, VecLike } from '../Vec'
|
|
5
4
|
import { getVerticesCountForArcLength } from './geometry-constants'
|
|
5
|
+
import { Geometry2d, Geometry2dOptions } from './Geometry2d'
|
|
6
6
|
|
|
7
7
|
/** @public */
|
|
8
8
|
export class Arc2d extends Geometry2d {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Box } from '../Box'
|
|
2
|
-
import { Vec, VecLike } from '../Vec'
|
|
3
2
|
import { intersectLineSegmentCircle } from '../intersect'
|
|
4
3
|
import { PI2, getPointOnCircle } from '../utils'
|
|
5
|
-
import {
|
|
4
|
+
import { Vec, VecLike } from '../Vec'
|
|
6
5
|
import { getVerticesCountForArcLength } from './geometry-constants'
|
|
6
|
+
import { Geometry2d, Geometry2dOptions } from './Geometry2d'
|
|
7
7
|
|
|
8
8
|
/** @public */
|
|
9
9
|
export class Circle2d extends Geometry2d {
|
|
@@ -15,7 +15,7 @@ export class CubicSpline2d extends Geometry2d {
|
|
|
15
15
|
|
|
16
16
|
private _segments?: CubicBezier2d[]
|
|
17
17
|
|
|
18
|
-
// eslint-disable-next-line no-
|
|
18
|
+
// eslint-disable-next-line tldraw/no-setter-getter
|
|
19
19
|
get segments() {
|
|
20
20
|
if (!this._segments) {
|
|
21
21
|
this._segments = []
|