快图设计封面工坊版:106套本地模板 + Strapi兼容本地接口 + 模板缩略图修复 + AI生图素材面板接入 + 悬浮AI面板
NodeJS with Webpack / build (push) Canceled after 0s

This commit is contained in:
jinghui committed 2026-10-26 18:11:58 +08:00
commit 838db12446
510 files changed
+27708

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
/*
* @Author: 秦少卫
* @Date: 2023-01-07 01:15:50
* @LastEditors: 秦少卫
* @LastEditTime: 2023-02-08 00:08:40
* @Description: 箭头元素
*/
import { fabric } from 'fabric';
fabric.Arrow = fabric.util.createClass(fabric.Line, {
type: 'arrow',
superType: 'drawing',
initialize(points, options) {
if (!points) {
const { x1, x2, y1, y2 } = options;
points = [x1, y1, x2, y2];
}
options = options || {};
this.callSuper('initialize', points, options);
},
_render(ctx) {
this.callSuper('_render', ctx);
ctx.save();
// 乘或除对应的scaleX(Y),抵消元素放缩造成的影响,使箭头不会变形
ctx.scale(1 / this.scaleX, 1 / this.scaleY);
const xDiff = (this.x2 - this.x1) * this.scaleX;
const yDiff = (this.y2 - this.y1) * this.scaleY;
const angle = Math.atan2(yDiff, xDiff);
ctx.translate(((this.x2 - this.x1) / 2) * this.scaleX, ((this.y2 - this.y1) / 2) * this.scaleY);
ctx.rotate(angle);
ctx.beginPath();
// Move 5px in front of line to start the arrow so it does not have the square line end showing in front (0,0)
ctx.moveTo(0, 0);
ctx.lineTo(-10, 5);
ctx.lineTo(-10, -5);
ctx.closePath();
ctx.lineWidth = this.lineWidth;
ctx.strokeStyle = this.stroke;
ctx.fillStyle = this.fill;
ctx.stroke();
ctx.fill();
ctx.restore();
},
});
fabric.Arrow.fromObject = (options, callback) => {
const { x1, x2, y1, y2 } = options;
return callback(new fabric.Arrow([x1, y1, x2, y2], options));
};
export default fabric.Arrow;
+28
View File
@@ -0,0 +1,28 @@
/*
* @Author: wuchenguang1998
* @Date: 2024-07-28 22:00:00
* @LastEditors: wuchenguang1998
* @LastEditTime: 2024-07-28 23:00:00
* @Description: 矩形元素,圆角属性适配元素放缩影响
*/
import { fabric } from 'fabric';
fabric.Rect = fabric.util.createClass(fabric.Rect, {
type: 'rect',
initialize: function (options) {
options || (options = {});
this.callSuper('initialize', options);
},
_render(ctx) {
const roundValue = this.roundValue || 0;
this.rx = (1 / this.scaleX) * roundValue;
this.ry = (1 / this.scaleY) * roundValue;
this.callSuper('_render', ctx);
},
});
fabric.Rect.fromObject = function (object, callback) {
return fabric.Object._fromObject('Rect', object, callback);
};
export default fabric.Rect;
+118
View File
@@ -0,0 +1,118 @@
/*
* 文本框,修改两端对齐逻辑
*/
import { fabric } from 'fabric';
fabric.Textbox = fabric.util.createClass(fabric.Textbox, {
type: 'textbox',
_renderChars: function (method, ctx, line, left, top, lineIndex) {
// set proper line offset
var lineHeight = this.getHeightOfLine(lineIndex),
isJustify = this.textAlign.indexOf('justify') !== -1,
actualStyle,
nextStyle,
charsToRender = '',
charBox,
boxWidth = 0,
timeToRender,
path = this.path,
shortCut = !isJustify && this.charSpacing === 0 && this.isEmptyStyles(lineIndex) && !path,
isLtr = this.direction === 'ltr',
sign = this.direction === 'ltr' ? 1 : -1,
drawingLeft,
currentDirection = ctx.canvas.getAttribute('dir');
ctx.save();
if (currentDirection !== this.direction) {
ctx.canvas.setAttribute('dir', isLtr ? 'ltr' : 'rtl');
ctx.direction = isLtr ? 'ltr' : 'rtl';
ctx.textAlign = isLtr ? 'left' : 'right';
}
top -= (lineHeight * this._fontSizeFraction) / this.lineHeight;
if (shortCut) {
// render all the line in one pass without checking
// drawingLeft = isLtr ? left : left - this.getLineWidth(lineIndex);
this._renderChar(method, ctx, lineIndex, 0, line.join(''), left, top, lineHeight);
ctx.restore();
return;
}
for (var i = 0, len = line.length - 1; i <= len; i++) {
timeToRender = i === len || this.charSpacing || path;
charsToRender += line[i];
charBox = this.__charBounds[lineIndex][i];
if (boxWidth === 0) {
left += sign * (charBox.kernedWidth - charBox.width);
boxWidth += charBox.width;
} else {
boxWidth += charBox.kernedWidth;
}
if (isJustify && !timeToRender) {
if (this._reSpaceAndTab.test(line[i])) {
timeToRender = true;
}
}
if (!timeToRender) {
// if we have charSpacing, we render char by char
actualStyle = actualStyle || this.getCompleteStyleDeclaration(lineIndex, i);
nextStyle = this.getCompleteStyleDeclaration(lineIndex, i + 1);
timeToRender = fabric.util.hasStyleChanged(actualStyle, nextStyle, false);
}
// if (timeToRender) {
if (path) {
ctx.save();
ctx.translate(charBox.renderLeft, charBox.renderTop);
ctx.rotate(charBox.angle);
this._renderChar(method, ctx, lineIndex, i, charsToRender, -boxWidth / 2, 0, lineHeight);
ctx.restore();
} else {
drawingLeft = left;
this._renderChar(method, ctx, lineIndex, i, charsToRender, drawingLeft, top, lineHeight);
}
charsToRender = '';
actualStyle = nextStyle;
left += sign * boxWidth;
boxWidth = 0;
// }
}
ctx.restore();
},
enlargeSpaces: function () {
var diffSpace, currentLineWidth, numberOfSpaces, accumulatedSpace, line, charBound, spaces;
for (var i = 0, len = this._textLines.length; i < len; i++) {
if (this.textAlign !== 'justify' && (i === len - 1 || this.isEndOfWrapping(i))) {
continue;
}
accumulatedSpace = 0;
line = this._textLines[i];
currentLineWidth = this.getLineWidth(i);
if (
currentLineWidth < this.width &&
(spaces = this.textLines[i].split('')) &&
spaces.length > 1
) {
numberOfSpaces = spaces.length;
diffSpace = (this.width - currentLineWidth) / (numberOfSpaces - 1);
for (var j = 0, jlen = line.length; j <= jlen; j++) {
charBound = this.__charBounds[i][j];
// if (this._reSpaceAndTab.test(line[j])) {
charBound.left += accumulatedSpace;
if (j < jlen - 1) {
charBound.width += diffSpace;
charBound.kernedWidth += diffSpace;
accumulatedSpace += diffSpace;
}
// } else {
// charBound.left += accumulatedSpace;
// }
}
}
}
},
});
fabric.Textbox.fromObject = function (options, callback) {
const { text } = options;
return callback(new fabric.Textbox(text, options));
};
export default fabric.Rect;
+57
View File
@@ -0,0 +1,57 @@
/*
* @Author: wuchenguang1998
* @Date: 2024-05-10 10:46:10
* @LastEditors: wuchenguang1998
* @LastEditTime: 2024-05-10 22:08:51
* @Description: 细尾箭头,支持控制条拖拽不变形
*/
import { fabric } from 'fabric';
fabric.ThinTailArrow = fabric.util.createClass(fabric.Line, {
type: 'thinTailArrow',
superType: 'drawing',
initialize(points, options) {
if (!points) {
const { x1, x2, y1, y2 } = options;
points = [x1, y1, x2, y2];
}
options = options || {};
this.callSuper('initialize', points, options);
},
_render(ctx) {
ctx.save();
// 乘或除对应的scaleX(Y),抵消元素放缩造成的影响,使箭头不会变形
ctx.scale(1 / this.scaleX, 1 / this.scaleY);
const xDiff = (this.x2 - this.x1) * this.scaleX;
const yDiff = (this.y2 - this.y1) * this.scaleY;
ctx.translate(-xDiff / 2, -yDiff / 2);
// 箭头方位角
const angle = Math.atan2(yDiff, xDiff);
ctx.rotate(angle);
// 箭头总长(最小长度是20)
let length = Math.hypot(xDiff, yDiff);
length = length < 20 ? 20 : length;
// 绘制箭头
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(length - 18, -5);
ctx.lineTo(length - 20, -12);
ctx.lineTo(length, 0);
ctx.lineTo(length - 20, 12);
ctx.lineTo(length - 18, 5);
ctx.lineTo(0, 0);
ctx.lineWidth = this.strokeWidth;
ctx.strokeStyle = this.stroke;
ctx.fillStyle = this.fill;
ctx.stroke();
ctx.fill();
ctx.restore();
},
});
fabric.ThinTailArrow.fromObject = (options, callback) => {
const { x1, x2, y1, y2 } = options;
return callback(new fabric.ThinTailArrow([x1, y1, x2, y2], options));
};
export default fabric.ThinTailArrow;