diff --git a/components/label/usePaperStore.ts b/components/label/usePaperStore.ts index 3192f3d..b158c07 100644 --- a/components/label/usePaperStore.ts +++ b/components/label/usePaperStore.ts @@ -80,6 +80,7 @@ const replacePaperWorkingPolygonShape = ( } syncPaperCompoundPolygonChildrenData(nextShape, phase) + syncPaperObjectStrokeScaling(nextShape) currentShape?.remove() if (!nextShape.parent && originalParent && "insertChild" in originalParent) { @@ -146,6 +147,7 @@ const createPaperPathFromGeometryContour = ({ ) path.strokeColor = clonePaperColor(strokeColor) path.strokeWidth = strokeWidth + path.strokeScaling = false path.fillColor = clonePaperColor(fillColor) path.visible = visible path.opacity = opacity @@ -215,6 +217,7 @@ const createPaperPolygonShapeFromGeometry = ({ compoundPath.data = safeClone(baseData) compoundPath.strokeColor = clonePaperColor(strokeColor) compoundPath.strokeWidth = strokeWidth + compoundPath.strokeScaling = false compoundPath.fillColor = clonePaperColor(fillColor) compoundPath.visible = visible compoundPath.opacity = opacity @@ -899,6 +902,40 @@ const isPaperObjectType = (type: unknown) => typeof type === "string" && PAPER_OBJECT_TYPES.includes(type as (typeof PAPER_OBJECT_TYPES)[number]) +const syncPaperObjectStrokeScaling = ( + item: paper.Item | null | undefined +) => { + if (!(item instanceof paper.Path || item instanceof paper.CompoundPath)) { + return + } + if (!isPaperObjectType(item.data?.type)) { + return + } + + item.strokeScaling = false + + if (item instanceof paper.CompoundPath) { + ;(item.children as paper.Path[]).forEach((child) => { + child.strokeScaling = false + }) + } +} + +const syncAllPaperObjectStrokeScaling = () => { + const group = usePaperStore.getState().group + if (!group) return + + group + .getItems({ + match: (item: paper.Item) => + (item instanceof paper.Path || item instanceof paper.CompoundPath) && + isPaperObjectType(item.data?.type), + }) + .forEach((item) => { + syncPaperObjectStrokeScaling(item) + }) +} + export const ensureEditablePaperPathSelected = (objectId: number) => { const objectPaths = usePaperStore .getState() @@ -6887,6 +6924,8 @@ export const usePaperStore = create((set) => ({ } item.scale(1 / newScale) }) + + syncAllPaperObjectStrokeScaling() } }, getAll: () => {