Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cncserver.binder.bindTo('controller.setup', base.id, () => {
const { settings: { bot } } = cncserver;
console.log(bot);
// Setup the project with the max cavas size in mm.
base.size = new Size(bot.maxAreaMM.width, bot.maxAreaMM.height);
// Setup the actual printable work space as a rectangle.
base.workspace = new Rectangle({
from: [bot.workAreaMM.left, bot.workAreaMM.top],
to: [bot.workAreaMM.right, bot.workAreaMM.bottom],
});
base.project = new Project(base.size);
// Setup layers: temp, working
// Whatever the last layer added was, will be default.
base.layers = {
import: new Layer(),
temp: new Layer(),
preview: new Layer(),
};
const fitSize = (image: HTMLImageElement, size: Size) => {
const iw = image.width
const ih = image.height
const ir = iw / ih
const cw = size.width!
const ch = size.height!
const cr = cw / ch
if (ir < cr) {
const ratio = cw / iw
return new Size(iw * ratio, ih * ratio)
} else {
const ratio = ch / ih
return new Size(iw * ratio, ih * ratio)
}
}
height = containerHeight;
} else {
width = screenWidth - 24 * 2;
height = containerHeight;
}
this.view.viewSize = new paper.Size(width, height);
} else {
leftWidthScale = scaleLinear().domain([480, 1440]).clamp(true).range([65, 230]);
this.view.viewSize = new paper.Size( (screenWidth - 24 * 2) - leftWidthScale(screenWidth), containerHeight );
}
}
constructor(private readonly ps: PaperService) {
super();
this.canvasColorRect = new paper.Path.Rectangle(new paper.Point(0, 0), new paper.Size(0, 0));
this.canvasColorRect.guide = true;
this.updateChildren();
}
componentDidUpdate(prevProps, prevState) {
const {
children, height, width,
cx, cy, dx, dy, x, y, zoom,
} = this.props
PaperRenderer.updateContainer(
children,
this._mountNode,
this,
)
const { view } = this._paper
if (width !== prevProps.width || height !== prevProps.height) {
view.viewSize = new Size(width, height)
}
if (zoom !== prevProps.zoom) {
view.scale(zoom / prevProps.zoom, view.viewToProject(cx, cy))
} else if (x !== prevProps.x || y !== prevProps.y) {
view.translate(dx, dy)
}
}
import * as paper from 'paper';
import {
Color,
Rect2,
Vec2
} from '@app/core';
export interface PaperTextGroup { textItem: paper.TextItem; groupItem: paper.Group; }
export module PaperHelper {
export const COLOR_BLACK = new paper.Color(0, 0, 0, 1);
export const COLOR_WHITE = new paper.Color(1, 1, 1, 1);
export const ZERO_POINT = new paper.Point(0, 0);
export const ZERO_SIZE = new paper.Size(0, 0);
export const ZERO_RECTANGLE = new paper.Rectangle(0, 0, 0, 0);
export const IDENTITY_MATRIX = new paper.Matrix(1, 0, 0, 1, 0, 0);
export function createSinglelineText(rectangle: paper.Rectangle, text: string, fontSize?: number, alignment?: string): PaperTextGroup {
fontSize = fontSize || 10;
alignment = alignment || 'center';
const clip = new paper.Path.Rectangle(rectangle);
let y = rectangle.center.y + fontSize * 1.2 * 0.25;
let x = rectangle.center.x;
if (alignment === 'left') {
x = rectangle.left;
} else if (alignment === 'right') {
export function vec2Size(vec: Vec2): paper.Size {
return new paper.Size(vec.x, vec.y);
}
private updateCanvasColorShape() {
this.canvasColorRect = new paper.Path.Rectangle(
new paper.Point(0, 0),
new paper.Size(this.vectorLayer.width, this.vectorLayer.height),
);
this.canvasColorRect.guide = true;
this.canvasColorRect.fillColor = parseAndroidColor(this.vectorLayer.canvasColor) || 'white';
this.updateChildren();
}