Preserve visual units across scaled canvas and container moves
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { CapabilityHandler, ComponentDefinition, Data, FieldChange, Geometry, Json } from './types.ts';
|
||||
import { defineComponent, defineFeature } from './registry.ts';
|
||||
import { presentationUnitsValid, unitScale } from './units.ts';
|
||||
import { equal, fault, validJson } from './values.ts';
|
||||
|
||||
const geometryHandler = (allowed: readonly (keyof Geometry)[], constrain?: (geometry: Geometry) => Geometry): CapabilityHandler => ({ element, input }) => {
|
||||
@@ -18,7 +19,7 @@ export const resizable = (inputOptions: { min?: number; max?: number; aspect?: b
|
||||
if (element.structure !== 'node') throw fault('unsupported_capability', [element.id]);
|
||||
const patch = input.patch as Partial<Geometry>;
|
||||
return geometryHandler(['width', 'height'], geometry => {
|
||||
const min = options.min ?? 1, max = options.max ?? 100000;
|
||||
const units=unitScale(element.data.presentation),min=(options.min??1)*units,max=(options.max??100000)*units;
|
||||
let width = Math.min(max, Math.max(min, geometry.width)), height = Math.min(max, Math.max(min, geometry.height));
|
||||
if (options.aspect) {
|
||||
const ratio = element.geometry.width / element.geometry.height;
|
||||
@@ -41,7 +42,7 @@ export const editable = () => defineFeature('content.edit', {
|
||||
});
|
||||
},
|
||||
});
|
||||
const textData = (data: Data) => validJson(data) && typeof data.title === 'string' && typeof data.text === 'string';
|
||||
const textData = (data: Data) => presentationUnitsValid(data.presentation) && validJson(data) && typeof data.title === 'string' && typeof data.text === 'string';
|
||||
export function builtinComponents(): readonly ComponentDefinition[] {
|
||||
return ['text', 'image', 'script', 'plain-text', 'plain-image', 'icon', 'frame'].map(id => defineComponent({
|
||||
id, dataVersion: 1, structure: 'node', validate: textData,
|
||||
|
||||
Reference in New Issue
Block a user