Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Rectangle2d,
ShapeUtil,
TLResizeInfo,
getColorValue,
getDefaultColorTheme,
resizeBox,
} from 'tldraw'
Expand Down Expand Up @@ -65,8 +66,8 @@ export class CardShapeUtil extends ShapeUtil<ICardShape> {
alignItems: 'center',
justifyContent: 'center',
pointerEvents: 'all',
backgroundColor: theme[shape.props.color].semi,
color: theme[shape.props.color].solid,
backgroundColor: getColorValue(theme, shape.props.color, 'semi'),
color: getColorValue(theme, shape.props.color, 'solid'),
}}
>
<h2>Clicks: {count}</h2>
Expand Down
8 changes: 4 additions & 4 deletions apps/examples/src/examples/custom-renderer/CustomRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useLayoutEffect, useRef } from 'react'
import { TLDrawShape, TLGeoShape, getDefaultColorTheme, useEditor } from 'tldraw'
import { TLDrawShape, TLGeoShape, getColorValue, getDefaultColorTheme, useEditor } from 'tldraw'

export function CustomRenderer() {
const editor = useEditor()
Expand Down Expand Up @@ -70,17 +70,17 @@ export function CustomRenderer() {
}
}
}
ctx.strokeStyle = theme[shape.props.color].solid
ctx.strokeStyle = getColorValue(theme, shape.props.color, 'solid')
ctx.lineWidth = 4
ctx.stroke()
if (shape.props.fill !== 'none' && shape.props.isClosed) {
ctx.fillStyle = theme[shape.props.color].semi
ctx.fillStyle = getColorValue(theme, shape.props.color, 'semi')
ctx.fill()
}
} else if (editor.isShapeOfType<TLGeoShape>(shape, 'geo')) {
// Draw a geo shape
const bounds = editor.getShapeGeometry(shape).bounds
ctx.strokeStyle = theme[shape.props.color].solid
ctx.strokeStyle = getColorValue(theme, shape.props.color, 'solid')
ctx.lineWidth = 2
ctx.strokeRect(bounds.minX, bounds.minY, bounds.width, bounds.height)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
BaseBoxShapeUtil,
DefaultColorStyle,
DefaultSizeStyle,
getColorValue,
HTMLContainer,
T,
TLBaseShape,
Expand Down Expand Up @@ -65,7 +66,7 @@ class MyShapeUtil extends BaseBoxShapeUtil<IMyShape> {
style={{
// [3]
fontSize: FONT_SIZES[shape.props.size],
color: theme[shape.props.color].solid,
color: getColorValue(theme, shape.props.color, 'solid'),
}}
>
Select the shape and use the style panel to change the font size and color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
TLResizeInfo,
Vec,
ZERO_INDEX_KEY,
getColorValue,
resizeBox,
structuredClone,
useDefaultColorTheme,
Expand Down Expand Up @@ -189,7 +190,7 @@ export class SpeechBubbleUtil extends ShapeUtil<SpeechBubbleShape> {
<path
d={pathData}
strokeWidth={STROKE_SIZES[size]}
stroke={theme[color].solid}
stroke={getColorValue(theme, color, 'solid')}
fill={'none'}
/>
</svg>
Expand All @@ -203,7 +204,7 @@ export class SpeechBubbleUtil extends ShapeUtil<SpeechBubbleShape> {
align={align}
verticalAlign="start"
text={text}
labelColor={theme[color].solid}
labelColor={getColorValue(theme, color, 'solid')}
isSelected={isSelected}
wrap
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/lib/exports/getSvgJsx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
TLGroupShape,
TLShape,
TLShapeId,
getColorValue,
getDefaultColorTheme,
} from '@tldraw/tlschema'
import { hasOwnProperty, promiseWithResolve, uniqueId } from '@tldraw/utils'
Expand Down Expand Up @@ -373,8 +374,7 @@ function SvgExport({
| { options: { showColors: boolean } }
if (frameShapeUtil?.options.showColors) {
const shape = editor.getShape(singleFrameShapeId)! as TLFrameShape
const color = theme[shape.props.color]
backgroundColor = color.frame.fill
backgroundColor = getColorValue(theme, shape.props.color, 'frameFill')
} else {
backgroundColor = theme.solid
}
Expand Down
7 changes: 4 additions & 3 deletions packages/tldraw/src/lib/shapes/arrow/ArrowShapeUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
clamp,
debugFlags,
exhaustiveSwitchError,
getColorValue,
getDefaultColorTheme,
getFontsFromRichText,
invLerp,
Expand Down Expand Up @@ -785,8 +786,8 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
lineHeight={TEXT_PROPS.lineHeight}
align="middle"
verticalAlign="middle"
labelColor={getColorValue(theme, shape.props.labelColor, 'solid')}
richText={shape.props.richText}
labelColor={theme[shape.props.labelColor].solid}
textWidth={labelPosition.box.w - ARROW_LABEL_PADDING * 2 * shape.props.scale}
isSelected={isSelected}
padding={0}
Expand Down Expand Up @@ -934,8 +935,8 @@ export class ArrowShapeUtil extends ShapeUtil<TLArrowShape> {
font={shape.props.font}
align="middle"
verticalAlign="middle"
labelColor={getColorValue(theme, shape.props.labelColor, 'solid')}
richText={shape.props.richText}
labelColor={theme[shape.props.labelColor].solid}
bounds={getArrowLabelPosition(this.editor, shape)
.box.clone()
.expandBy(-ARROW_LABEL_PADDING * shape.props.scale)}
Expand Down Expand Up @@ -1077,7 +1078,7 @@ const ArrowSvg = track(function ArrowSvg({
</defs>
<g
fill="none"
stroke={theme[shape.props.color].solid}
stroke={getColorValue(theme, shape.props.color, 'solid')}
strokeWidth={strokeWidth}
strokeLinejoin="round"
strokeLinecap="round"
Expand Down
7 changes: 4 additions & 3 deletions packages/tldraw/src/lib/shapes/draw/DrawShapeUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
VecLike,
drawShapeMigrations,
drawShapeProps,
getColorValue,
last,
lerp,
rng,
Expand Down Expand Up @@ -289,7 +290,7 @@ function DrawShapeSvg({ shape, zoomOverride }: { shape: TLDrawShape; zoomOverrid
<path
d={svgInk(allPointsFromSegments, options)}
strokeLinecap="round"
fill={theme[shape.props.color].solid}
fill={getColorValue(theme, shape.props.color, 'solid')}
/>
</>
)
Expand All @@ -313,8 +314,8 @@ function DrawShapeSvg({ shape, zoomOverride }: { shape: TLDrawShape; zoomOverrid
<path
d={solidStrokePath}
strokeLinecap="round"
fill={isDot ? theme[shape.props.color].solid : 'none'}
stroke={theme[shape.props.color].solid}
fill={isDot ? getColorValue(theme, shape.props.color, 'solid') : 'none'}
stroke={getColorValue(theme, shape.props.color, 'solid')}
strokeWidth={sw}
strokeDasharray={isDot ? 'none' : getDrawShapeStrokeDashArray(shape, sw, dotAdjustment)}
strokeDashoffset="0"
Expand Down
27 changes: 13 additions & 14 deletions packages/tldraw/src/lib/shapes/frame/FrameShapeUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
compact,
frameShapeMigrations,
frameShapeProps,
getColorValue,
getDefaultColorTheme,
lerp,
resizeBox,
Expand Down Expand Up @@ -220,13 +221,12 @@ export class FrameShapeUtil extends BaseBoxShapeUtil<TLFrameShape> {
)

const showFrameColors = this.options.showColors

const color = theme[shape.props.color]
const frameFill = showFrameColors ? color.frame.fill : theme.black.frame.fill
const frameStroke = showFrameColors ? color.frame.stroke : theme.black.frame.stroke
const frameHeadingStroke = showFrameColors ? color.frame.headingStroke : theme.background
const frameHeadingFill = showFrameColors ? color.frame.headingFill : theme.background
const frameHeadingText = showFrameColors ? color.frame.text : theme.text
const colorToUse = showFrameColors ? shape.props.color : 'black'
const frameFill = getColorValue(theme, colorToUse, 'frameFill')
const frameStroke = getColorValue(theme, colorToUse, 'frameStroke')
const frameHeadingStroke = getColorValue(theme, colorToUse, 'frameHeadingStroke')
const frameHeadingFill = getColorValue(theme, colorToUse, 'frameHeadingFill')
const frameHeadingText = getColorValue(theme, colorToUse, 'frameText')

return (
<>
Expand Down Expand Up @@ -277,13 +277,12 @@ export class FrameShapeUtil extends BaseBoxShapeUtil<TLFrameShape> {
const text = createTextJsxFromSpans(this.editor, spans, opts)

const showFrameColors = this.options.showColors

const color = theme[shape.props.color]
const frameFill = showFrameColors ? color.frame.fill : theme.black.frame.fill
const frameStroke = showFrameColors ? color.frame.stroke : theme.black.frame.stroke
const frameHeadingStroke = showFrameColors ? color.frame.headingStroke : theme.background
const frameHeadingFill = showFrameColors ? color.frame.headingFill : theme.background
const frameHeadingText = showFrameColors ? color.frame.text : theme.text
const colorToUse = showFrameColors ? shape.props.color : 'black'
const frameFill = getColorValue(theme, colorToUse, 'frameFill')
const frameStroke = getColorValue(theme, colorToUse, 'frameStroke')
const frameHeadingStroke = getColorValue(theme, colorToUse, 'frameHeadingStroke')
const frameHeadingFill = getColorValue(theme, colorToUse, 'frameHeadingFill')
const frameHeadingText = getColorValue(theme, colorToUse, 'frameText')

return (
<>
Expand Down
5 changes: 3 additions & 2 deletions packages/tldraw/src/lib/shapes/geo/GeoShapeUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
exhaustiveSwitchError,
geoShapeMigrations,
geoShapeProps,
getColorValue,
getDefaultColorTheme,
getFontsFromRichText,
isEqual,
Expand Down Expand Up @@ -220,7 +221,7 @@ export class GeoShapeUtil extends BaseBoxShapeUtil<TLGeoShape> {
verticalAlign={verticalAlign}
richText={richText}
isSelected={isOnlySelected}
labelColor={theme[props.labelColor].solid}
labelColor={getColorValue(theme, props.labelColor, 'solid')}
wrap
/>
</HTMLContainer>
Expand Down Expand Up @@ -278,7 +279,7 @@ export class GeoShapeUtil extends BaseBoxShapeUtil<TLGeoShape> {
align={props.align}
verticalAlign={props.verticalAlign}
richText={props.richText}
labelColor={theme[props.labelColor].solid}
labelColor={getColorValue(theme, props.labelColor, 'solid')}
bounds={bounds}
padding={LABEL_PADDING}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TLGeoShape } from '@tldraw/editor'
import { getColorValue, TLGeoShape } from '@tldraw/editor'
import { ShapeFill } from '../../shared/ShapeFill'
import { STROKE_SIZES } from '../../shared/default-shape-constants'
import { useDefaultColorTheme } from '../../shared/useDefaultColorTheme'
Expand Down Expand Up @@ -33,7 +33,7 @@ export function GeoShapeBody({
strokeWidth,
forceSolid,
randomSeed: shape.id,
props: { fill: 'none', stroke: theme[color].solid },
props: { fill: 'none', stroke: getColorValue(theme, color, 'solid') },
})}
</>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TLHighlightShapeProps,
TLResizeInfo,
VecLike,
getColorValue,
highlightShapeMigrations,
highlightShapeProps,
last,
Expand Down Expand Up @@ -289,7 +290,12 @@ function HighlightRenderer({
: getShapeDot(shape.props.segments[0].points[0])

const colorSpace = useColorSpace()
const color = theme[shape.props.color].highlight[colorSpace]

const color = getColorValue(
theme,
shape.props.color,
colorSpace === 'p3' ? 'highlightP3' : 'highlightSrgb'
)

return (
<path
Expand Down
7 changes: 6 additions & 1 deletion packages/tldraw/src/lib/shapes/line/LineShapeUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
WeakCache,
ZERO_INDEX_KEY,
assert,
getColorValue,
getIndexAbove,
getIndexBetween,
getIndices,
Expand Down Expand Up @@ -346,6 +347,10 @@ function LineShapeSvg({
strokeWidth,
forceSolid,
randomSeed: shape.id,
props: { transform: `scale(${scale})`, stroke: theme[color].solid, fill: 'none' },
props: {
transform: `scale(${scale})`,
stroke: getColorValue(theme, color, 'solid'),
fill: 'none',
},
})
}
13 changes: 9 additions & 4 deletions packages/tldraw/src/lib/shapes/note/NoteShapeUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
Vec,
WeakCache,
exhaustiveSwitchError,
getColorValue,
getDefaultColorTheme,
getFontsFromRichText,
isEqual,
Expand Down Expand Up @@ -288,7 +289,7 @@ export class NoteShapeUtil extends ShapeUtil<TLNoteShape> {
style={{
width: nw,
height: nh,
backgroundColor: theme[color].note.fill,
backgroundColor: getColorValue(theme, color, 'noteFill'),
borderBottom: hideShadows
? isDarkMode
? `${2 * scale}px solid rgb(20, 20, 20)`
Expand All @@ -308,7 +309,11 @@ export class NoteShapeUtil extends ShapeUtil<TLNoteShape> {
verticalAlign={verticalAlign}
richText={richText}
isSelected={isSelected}
labelColor={labelColor === 'black' ? theme[color].note.text : theme[labelColor].fill}
labelColor={
labelColor === 'black'
? getColorValue(theme, color, 'noteText')
: getColorValue(theme, labelColor, 'fill')
}
wrap
padding={LABEL_PADDING * scale}
hasCustomTabBehavior
Expand Down Expand Up @@ -343,7 +348,7 @@ export class NoteShapeUtil extends ShapeUtil<TLNoteShape> {
align={shape.props.align}
verticalAlign={shape.props.verticalAlign}
richText={shape.props.richText}
labelColor={theme[shape.props.color].note.text}
labelColor={getColorValue(theme, shape.props.color, 'noteText')}
bounds={bounds}
padding={LABEL_PADDING}
showTextOutline={false}
Expand All @@ -357,7 +362,7 @@ export class NoteShapeUtil extends ShapeUtil<TLNoteShape> {
rx={1}
width={NOTE_SIZE}
height={bounds.h}
fill={theme[shape.props.color].note.fill}
fill={getColorValue(theme, shape.props.color, 'noteFill')}
/>
{textLabel}
</>
Expand Down
11 changes: 6 additions & 5 deletions packages/tldraw/src/lib/shapes/shared/ShapeFill.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
getColorValue,
TLDefaultColorStyle,
TLDefaultColorTheme,
TLDefaultFillStyle,
Expand Down Expand Up @@ -29,13 +30,13 @@ export const ShapeFill = React.memo(function ShapeFill({
return null
}
case 'solid': {
return <path fill={theme[color].semi} d={d} />
return <path fill={getColorValue(theme, color, 'semi')} d={d} />
}
case 'semi': {
return <path fill={theme.solid} d={d} />
return <path fill={getColorValue(theme, color, 'solid')} d={d} />
}
case 'fill': {
return <path fill={theme[color].fill} d={d} />
return <path fill={getColorValue(theme, color, 'fill')} d={d} />
}
case 'pattern': {
return <PatternFill theme={theme} color={color} fill={fill} d={d} scale={scale} />
Expand All @@ -53,13 +54,13 @@ export function PatternFill({ d, color, theme }: ShapeFillProps) {

return (
<>
<path fill={theme[color].pattern} d={d} />
<path fill={getColorValue(theme, color, 'pattern')} d={d} />
<path
fill={
svgExport
? `url(#${getHashPatternZoomName(1, theme.id)})`
: teenyTiny
? theme[color].semi
? getColorValue(theme, color, 'semi')
: `url(#${getHashPatternZoomName(zoomLevel, theme.id)})`
}
d={d}
Expand Down
Loading
Loading