mirror of
https://gitee.com/onvia/ccc-tnt-psd2ui
synced 2025-10-16 20:16:28 +00:00
两个版本的插件
This commit is contained in:
10
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/psd/LayerType.js
Normal file
10
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/psd/LayerType.js
Normal file
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LayerType = void 0;
|
||||
var LayerType;
|
||||
(function (LayerType) {
|
||||
LayerType[LayerType["Doc"] = 0] = "Doc";
|
||||
LayerType[LayerType["Group"] = 1] = "Group";
|
||||
LayerType[LayerType["Text"] = 2] = "Text";
|
||||
LayerType[LayerType["Image"] = 3] = "Image";
|
||||
})(LayerType = exports.LayerType || (exports.LayerType = {}));
|
39
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/psd/PsdDocument.js
Normal file
39
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/psd/PsdDocument.js
Normal file
@@ -0,0 +1,39 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PsdDocument = void 0;
|
||||
const Rect_1 = require("../values/Rect");
|
||||
const Size_1 = require("../values/Size");
|
||||
const PsdGroup_1 = require("./PsdGroup");
|
||||
class PsdDocument extends PsdGroup_1.PsdGroup {
|
||||
constructor(source) {
|
||||
super(source, null, null);
|
||||
/** 当前文档所有的图片 */
|
||||
this.images = new Map();
|
||||
this.objectMap = new Map();
|
||||
this.objectArray = [];
|
||||
this.size = new Size_1.Size(source.width, source.height);
|
||||
this.rect = new Rect_1.Rect(0, this.size.width, 0, this.size.height);
|
||||
}
|
||||
pushObject(uiObject) {
|
||||
let idx = this.objectArray.length;
|
||||
uiObject.idx = idx;
|
||||
this.objectMap.set(uiObject.uuid, idx);
|
||||
this.objectArray.push(uiObject);
|
||||
return idx;
|
||||
}
|
||||
getObjectIdx(uuid) {
|
||||
let idx = this.objectMap.get(uuid);
|
||||
return idx;
|
||||
}
|
||||
getObject(uuid) {
|
||||
let idx = this.objectMap.get(uuid);
|
||||
if (idx < this.objectArray.length) {
|
||||
return this.objectArray[idx];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
onCtor() {
|
||||
super.onCtor();
|
||||
}
|
||||
}
|
||||
exports.PsdDocument = PsdDocument;
|
44
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/psd/PsdGroup.js
Normal file
44
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/psd/PsdGroup.js
Normal file
@@ -0,0 +1,44 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PsdGroup = void 0;
|
||||
const Rect_1 = require("../values/Rect");
|
||||
const PsdLayer_1 = require("./PsdLayer");
|
||||
class PsdGroup extends PsdLayer_1.PsdLayer {
|
||||
constructor(source, parent, rootDoc) {
|
||||
super(source, parent, rootDoc);
|
||||
this.children = [];
|
||||
if (rootDoc) {
|
||||
this.rect = new Rect_1.Rect(0, rootDoc.size.width, 0, rootDoc.size.height);
|
||||
}
|
||||
}
|
||||
parseSource() {
|
||||
var _a;
|
||||
super.parseSource();
|
||||
if (!((_a = this.attr) === null || _a === void 0 ? void 0 : _a.comps.full)) {
|
||||
this.resize();
|
||||
this.computeBasePosition();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
resize() {
|
||||
let left = Number.MAX_SAFE_INTEGER;
|
||||
let right = Number.MIN_SAFE_INTEGER;
|
||||
let top = Number.MAX_SAFE_INTEGER;
|
||||
let bottom = Number.MIN_SAFE_INTEGER;
|
||||
for (let i = 0; i < this.children.length; i++) {
|
||||
const element = this.children[i];
|
||||
let _rect = element.rect;
|
||||
left = Math.min(_rect.left, left);
|
||||
right = Math.max(_rect.right, right);
|
||||
top = Math.min(_rect.top, top);
|
||||
bottom = Math.max(_rect.bottom, bottom);
|
||||
}
|
||||
this.rect.left = left;
|
||||
this.rect.right = right;
|
||||
this.rect.top = top;
|
||||
this.rect.bottom = bottom;
|
||||
}
|
||||
onCtor() {
|
||||
}
|
||||
}
|
||||
exports.PsdGroup = PsdGroup;
|
75
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/psd/PsdImage.js
Normal file
75
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/psd/PsdImage.js
Normal file
@@ -0,0 +1,75 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PsdImage = void 0;
|
||||
const PsdLayer_1 = require("./PsdLayer");
|
||||
const Utils_1 = require("../utils/Utils");
|
||||
const Texture9Utils_1 = require("../utils/Texture9Utils");
|
||||
const Size_1 = require("../values/Size");
|
||||
const FileUtils_1 = require("../utils/FileUtils");
|
||||
const Vec3_1 = require("../values/Vec3");
|
||||
class PsdImage extends PsdLayer_1.PsdLayer {
|
||||
constructor(source, parent, rootDoc) {
|
||||
var _a;
|
||||
super(source, parent, rootDoc);
|
||||
this.textureUuid = Utils_1.utils.uuid();
|
||||
// img name
|
||||
this.imgName = ((_a = this.attr.comps.img) === null || _a === void 0 ? void 0 : _a.name) || this.name;
|
||||
// .9
|
||||
if (this.attr.comps['.9']) {
|
||||
let s9 = this.attr.comps['.9'];
|
||||
this.s9 = Texture9Utils_1.Texture9Utils.safeBorder(s9);
|
||||
let newCanvas = Texture9Utils_1.Texture9Utils.split(this.source.canvas, s9);
|
||||
this.source.canvas = newCanvas;
|
||||
}
|
||||
let canvas = this.source.canvas;
|
||||
this.imgBuffer = canvas.toBuffer('image/png');
|
||||
this.md5 = FileUtils_1.fileUtils.getMD5(this.imgBuffer);
|
||||
this.textureSize = new Size_1.Size(canvas.width, canvas.height);
|
||||
this.scale = new Vec3_1.Vec3((this.isFilpX() ? -1 : 1) * this.scale.x, (this.isFilpY() ? -1 : 1) * this.scale.y, 1);
|
||||
}
|
||||
onCtor() {
|
||||
}
|
||||
isIgnore() {
|
||||
//
|
||||
if (this.attr.comps.ignore || this.attr.comps.ignoreimg) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/** 是否是镜像图片 */
|
||||
isBind() {
|
||||
var _a, _b;
|
||||
return typeof ((_a = this.attr.comps.flip) === null || _a === void 0 ? void 0 : _a.bind) !== 'undefined'
|
||||
|| typeof ((_b = this.attr.comps.img) === null || _b === void 0 ? void 0 : _b.bind) !== 'undefined';
|
||||
}
|
||||
/** 是否是 x 方向镜像图片 */
|
||||
isFilpX() {
|
||||
var _a;
|
||||
return typeof ((_a = this.attr.comps.flipX) === null || _a === void 0 ? void 0 : _a.bind) !== 'undefined';
|
||||
}
|
||||
/** 是否是 y 方向镜像图片 */
|
||||
isFilpY() {
|
||||
var _a;
|
||||
return typeof ((_a = this.attr.comps.flipY) === null || _a === void 0 ? void 0 : _a.bind) !== 'undefined';
|
||||
}
|
||||
// 根据锚点计算坐标
|
||||
updatePositionWithAR() {
|
||||
if (!this.parent) {
|
||||
return;
|
||||
}
|
||||
let parent = this.parent;
|
||||
while (parent) {
|
||||
this.position.x -= parent.position.x;
|
||||
this.position.y -= parent.position.y;
|
||||
parent = parent.parent;
|
||||
}
|
||||
// this.position.x = this.position.x - this.parent.size.width * this.parent.anchorPoint.x + this.size.width * this.anchorPoint.x;
|
||||
// this.position.y = this.position.y - this.parent.size.height * this.parent.anchorPoint.y + this.size.height * this.anchorPoint.y;
|
||||
// 如果是镜像图片,则特殊处理
|
||||
let arX = (this.isFilpX() ? (1 - this.anchorPoint.x) : this.anchorPoint.x);
|
||||
let arY = (this.isFilpY() ? (1 - this.anchorPoint.y) : this.anchorPoint.y);
|
||||
this.position.x = this.position.x - this.rootDoc.size.width * this.rootDoc.anchorPoint.x + this.size.width * arX;
|
||||
this.position.y = this.position.y - this.rootDoc.size.height * this.rootDoc.anchorPoint.y + this.size.height * arY;
|
||||
}
|
||||
}
|
||||
exports.PsdImage = PsdImage;
|
185
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/psd/PsdLayer.js
Normal file
185
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/psd/PsdLayer.js
Normal file
@@ -0,0 +1,185 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PsdLayer = void 0;
|
||||
const Size_1 = require("../values/Size");
|
||||
const Vec2_1 = require("../values/Vec2");
|
||||
const Utils_1 = require("../utils/Utils");
|
||||
const Rect_1 = require("../values/Rect");
|
||||
const Color_1 = require("../values/Color");
|
||||
const Vec3_1 = require("../values/Vec3");
|
||||
class PsdLayer {
|
||||
constructor(source, parent, rootDoc) {
|
||||
var _a, _b, _c, _d;
|
||||
this.uuid = Utils_1.utils.uuid();
|
||||
this.source = source;
|
||||
this.parent = parent;
|
||||
this.rootDoc = rootDoc;
|
||||
this.name = source.name;
|
||||
this.position = new Vec2_1.Vec2();
|
||||
this.size = new Size_1.Size();
|
||||
this.rect = new Rect_1.Rect(source);
|
||||
// this.anchorPoint = new Vec2();
|
||||
this.anchorPoint = new Vec2_1.Vec2(0.5, 0.5);
|
||||
this.hidden = false;
|
||||
this.opacity = 255;
|
||||
this.color = new Color_1.Color(255, 255, 255, 255);
|
||||
console.log(`PsdLayer->解析到图层 `, this.name);
|
||||
this.attr = this.parseNameRule(this.name);
|
||||
// // 更新名字
|
||||
this.name = ((_a = this.attr) === null || _a === void 0 ? void 0 : _a.name) || this.name;
|
||||
// 使用配置的缩放系数
|
||||
let _scale = (_b = this.attr) === null || _b === void 0 ? void 0 : _b.comps.scale;
|
||||
this.scale = new Vec3_1.Vec3((_c = _scale === null || _scale === void 0 ? void 0 : _scale.x) !== null && _c !== void 0 ? _c : 1, (_d = _scale === null || _scale === void 0 ? void 0 : _scale.y) !== null && _d !== void 0 ? _d : 1, 1);
|
||||
}
|
||||
parseNameRule(name) {
|
||||
var _a, _b;
|
||||
if (!name) {
|
||||
return;
|
||||
}
|
||||
name = name.trim();
|
||||
let fragments = name.split("@");
|
||||
if (fragments.length === 0) {
|
||||
console.error(`PsdLayer-> 名字解析错误`);
|
||||
return;
|
||||
}
|
||||
let obj = {
|
||||
name: (_b = (_a = fragments[0]) === null || _a === void 0 ? void 0 : _a.replace(/\.|>|\/|\ /g, "_")) !== null && _b !== void 0 ? _b : "unknow",
|
||||
comps: {},
|
||||
};
|
||||
for (let i = 1; i < fragments.length; i++) {
|
||||
const fragment = fragments[i].trim();
|
||||
let attr = {};
|
||||
let startIdx = fragment.indexOf("{");
|
||||
let comp = fragment;
|
||||
if (startIdx != -1) {
|
||||
let endIdx = fragment.indexOf("}");
|
||||
if (endIdx == -1) {
|
||||
console.log(`PsdLayer->${name} 属性 解析错误`);
|
||||
continue;
|
||||
}
|
||||
let attrStr = fragment.substring(startIdx + 1, endIdx);
|
||||
comp = fragment.substr(0, startIdx);
|
||||
attrStr = attrStr.trim();
|
||||
let attrs = attrStr.split(",");
|
||||
attrs.forEach((str) => {
|
||||
str = str.trim();
|
||||
let strs = str.split(":");
|
||||
if (!strs.length) {
|
||||
console.log(`PsdLayer->${name} 属性 解析错误`);
|
||||
return;
|
||||
}
|
||||
strs.map((v) => {
|
||||
return v.trim();
|
||||
});
|
||||
attr[strs[0]] = Utils_1.utils.isNumber(strs[1]) ? parseFloat(strs[1]) : strs[1];
|
||||
});
|
||||
}
|
||||
comp = comp.trim();
|
||||
comp = comp.replace(":", ""); // 防呆,删除 key 中的冒号,
|
||||
obj.comps[comp] = attr;
|
||||
}
|
||||
// 获取别名的值
|
||||
obj.comps.ignore = obj.comps.ignore || obj.comps.ig;
|
||||
obj.comps.ignorenode = obj.comps.ignorenode || obj.comps.ignode;
|
||||
obj.comps.ignoreimg = obj.comps.ignoreimg || obj.comps.igimg;
|
||||
obj.comps.Btn = obj.comps.Btn || obj.comps.btn;
|
||||
obj.comps.ProgressBar = obj.comps.ProgressBar || obj.comps.progressBar;
|
||||
obj.comps.Toggle = obj.comps.Toggle || obj.comps.toggle;
|
||||
// obj.comps.position = obj.comps.position || obj.comps.pos;
|
||||
// 将mirror filpX filpY 进行合并
|
||||
if (obj.comps.flip || obj.comps.flipX || obj.comps.flipY) {
|
||||
obj.comps.flip = Object.assign({}, obj.comps.flip, obj.comps.flipX, obj.comps.flipY);
|
||||
if (obj.comps.flipX) {
|
||||
obj.comps.flip.x = 1;
|
||||
}
|
||||
if (obj.comps.flipY) {
|
||||
obj.comps.flip.y = 1;
|
||||
}
|
||||
// x,y 都缺省时,默认 x 方向镜像
|
||||
if (typeof obj.comps.flip.bind !== 'undefined') {
|
||||
if (!obj.comps.flip.y) {
|
||||
obj.comps.flip.x = 1;
|
||||
}
|
||||
// 只有作为镜像图片使用的时候才反向赋值
|
||||
// 反向赋值,防止使用的时候值错误
|
||||
if (obj.comps.flip.x) {
|
||||
obj.comps.flipX = Object.assign({}, obj.comps.flipX, obj.comps.flip);
|
||||
}
|
||||
if (obj.comps.flip.y) {
|
||||
obj.comps.flipY = Object.assign({}, obj.comps.flipY, obj.comps.flip);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 检查冲突
|
||||
if (obj.comps.full && obj.comps.size) {
|
||||
console.warn(`PsdLayer->${obj.name} 同时存在 @full 和 @size`);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
/** 解析数据 */
|
||||
parseSource() {
|
||||
var _a, _b;
|
||||
let _source = this.source;
|
||||
// psd文档
|
||||
if (!this.parent) {
|
||||
return false;
|
||||
}
|
||||
this.hidden = _source.hidden;
|
||||
this.opacity = Math.round(_source.opacity * 255);
|
||||
// 获取锚点
|
||||
let ar = this.attr.comps.ar;
|
||||
if (ar) {
|
||||
this.anchorPoint.x = (_a = ar.x) !== null && _a !== void 0 ? _a : this.anchorPoint.x;
|
||||
this.anchorPoint.y = (_b = ar.y) !== null && _b !== void 0 ? _b : this.anchorPoint.y;
|
||||
}
|
||||
this.computeBasePosition();
|
||||
return true;
|
||||
}
|
||||
/** 解析 effect */
|
||||
parseEffects() {
|
||||
// 颜色叠加 暂时搞不定
|
||||
// if(this.source.effects?.solidFill){
|
||||
// let solidFills = this.source.effects?.solidFill;
|
||||
// for (let i = 0; i < solidFills.length; i++) {
|
||||
// const solidFill = solidFills[i];
|
||||
// if(solidFill.enabled){
|
||||
// let color = solidFill.color;
|
||||
// this.color = new Color(color.r,color.g,color.b,solidFill.opacity * 255);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
// 计算初始坐标 左下角 0,0 为锚点
|
||||
computeBasePosition() {
|
||||
if (!this.rootDoc) {
|
||||
return;
|
||||
}
|
||||
let _rect = this.rect;
|
||||
let width = (_rect.right - _rect.left);
|
||||
let height = (_rect.bottom - _rect.top);
|
||||
this.size.width = width;
|
||||
this.size.height = height;
|
||||
// 位置 左下角为锚点
|
||||
let x = _rect.left;
|
||||
let y = (this.rootDoc.size.height - _rect.bottom);
|
||||
this.position.x = x;
|
||||
this.position.y = y;
|
||||
}
|
||||
// 根据锚点计算坐标
|
||||
updatePositionWithAR() {
|
||||
if (!this.parent) {
|
||||
return;
|
||||
}
|
||||
let parent = this.parent;
|
||||
while (parent) {
|
||||
this.position.x -= parent.position.x;
|
||||
this.position.y -= parent.position.y;
|
||||
parent = parent.parent;
|
||||
}
|
||||
// this.position.x = this.position.x - this.parent.size.width * this.parent.anchorPoint.x + this.size.width * this.anchorPoint.x;
|
||||
// this.position.y = this.position.y - this.parent.size.height * this.parent.anchorPoint.y + this.size.height * this.anchorPoint.y;
|
||||
this.position.x = this.position.x - this.rootDoc.size.width * this.rootDoc.anchorPoint.x + this.size.width * this.anchorPoint.x;
|
||||
this.position.y = this.position.y - this.rootDoc.size.height * this.rootDoc.anchorPoint.y + this.size.height * this.anchorPoint.y;
|
||||
}
|
||||
}
|
||||
exports.PsdLayer = PsdLayer;
|
57
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/psd/PsdText.js
Normal file
57
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/psd/PsdText.js
Normal file
@@ -0,0 +1,57 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.PsdText = void 0;
|
||||
const config_1 = require("../config");
|
||||
const Color_1 = require("../values/Color");
|
||||
const PsdLayer_1 = require("./PsdLayer");
|
||||
class PsdText extends PsdLayer_1.PsdLayer {
|
||||
parseSource() {
|
||||
super.parseSource();
|
||||
let textSource = this.source.text;
|
||||
let style = textSource.style;
|
||||
if (style) {
|
||||
let fillColor = style.fillColor;
|
||||
if (fillColor) {
|
||||
this.color = new Color_1.Color(fillColor.r, fillColor.g, fillColor.b, fillColor.a * 255);
|
||||
}
|
||||
}
|
||||
this.text = textSource.text;
|
||||
this.fontSize = style.fontSize;
|
||||
this.offsetY = config_1.config.textOffsetY[this.fontSize] || config_1.config.textOffsetY["default"] || 0;
|
||||
this.parseSolidFill();
|
||||
this.parseStroke();
|
||||
return true;
|
||||
}
|
||||
onCtor() {
|
||||
}
|
||||
/** 描边 */
|
||||
parseStroke() {
|
||||
var _a, _b;
|
||||
if ((_a = this.source.effects) === null || _a === void 0 ? void 0 : _a.stroke) {
|
||||
let stroke = (_b = this.source.effects) === null || _b === void 0 ? void 0 : _b.stroke[0];
|
||||
// 外描边
|
||||
if ((stroke === null || stroke === void 0 ? void 0 : stroke.enabled) && (stroke === null || stroke === void 0 ? void 0 : stroke.position) === "outside") {
|
||||
let color = stroke.color;
|
||||
this.outline = {
|
||||
width: stroke.size.value,
|
||||
color: new Color_1.Color(color.r, color.g, color.b, stroke.opacity * 255)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
/** 解析 颜色叠加 */
|
||||
parseSolidFill() {
|
||||
var _a, _b;
|
||||
if ((_a = this.source.effects) === null || _a === void 0 ? void 0 : _a.solidFill) {
|
||||
let solidFills = (_b = this.source.effects) === null || _b === void 0 ? void 0 : _b.solidFill;
|
||||
for (let i = 0; i < solidFills.length; i++) {
|
||||
const solidFill = solidFills[i];
|
||||
if (solidFill.enabled) {
|
||||
let color = solidFill.color;
|
||||
this.color = new Color_1.Color(color.r, color.g, color.b, solidFill.opacity * 255);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.PsdText = PsdText;
|
Reference in New Issue
Block a user