Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
psd-parse
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
psd-parse
Commits
4a712d00
Commit
4a712d00
authored
Sep 27, 2019
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文件名使用hash字符串
节点增加uuid字段
parent
f112f438
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
3 additions
and
1 deletion
+3
-1
generator.cjs.js
samples/zeroing-demo/generator.cjs.js
+1
-0
generator.cjs.js.map
samples/zeroing-demo/generator.cjs.js.map
+1
-1
zeroing.js
src/zeroing.js
+1
-0
No files found.
samples/zeroing-demo/generator.cjs.js
View file @
4a712d00
...
@@ -79,6 +79,7 @@ async function execute(psdFile, options) {
...
@@ -79,6 +79,7 @@ async function execute(psdFile, options) {
let
viewRoot
=
{
let
viewRoot
=
{
name
:
path
.
basename
(
psdFile
,
'.psd'
),
name
:
path
.
basename
(
psdFile
,
'.psd'
),
type
:
'node'
,
type
:
'node'
,
uuid
:
generateUUID
(),
};
};
const
assets
=
[];
const
assets
=
[];
...
...
samples/zeroing-demo/generator.cjs.js.map
View file @
4a712d00
{
"version"
:
3
,
"file"
:
"generator.cjs.js"
,
"sources"
:
[
"../../src/psd-tree.js"
,
"../../src/utils.js"
,
"../../src/zeroing.js"
,
"generator.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = require('psd');
\n\n
export async function getTree(psdFilePath) {\n
\t
const psd = await PSD.open(psdFilePath);
\n\t
const root = {};
\n\t
walk(psd.tree(), root);
\n\n\t
return root;
\n
}
\n\n
function walk(psNode, dataNode) {\n
\t
const {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};
\n\t
const {left, top, width, height, name, layer: {opacity, visible}} = psNode;
\n\t
const x = left - pLeft;
\n\t
const y = top - pTop;
\n\n\t
Object.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});
\n\t
if (psNode.children() && psNode.children().length > 0){\n
\t\t
dataNode.children = [];
\n\t
}
\n\n\t
let children = psNode.children();
\n\t
for (let i = children.length - 1; i >= 0; i--) {\n
\t\t
const childPsNode = children[i];
\n\n\t\t
const childDataNode = {};
\n\t\t
dataNode.children.push(childDataNode);
\n\t\t
walk(childPsNode, childDataNode)
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
export async function walkNode(node, callback, includeSelf = false) {\n
\t
if (includeSelf) {\n
\t\t
await callback(node, null);
\n\t
}
\n\t
if (node.children && node.children.length > 0) {\n
\t\t
for (let childNode of node.children) {\n
\t\t\t
await callback(childNode, node);
\n\t\t\t
const result = await walkNode(childNode, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
export async function walkObject(obj, callback) {\n
\t
if(typeof obj ===
\"
object
\"
){\n
\t\t
for (let key of Object.keys(obj)) {\n
\t\t\t
const value = obj[key];
\n\t\t\t
await callback(key, value, obj);
\n\t\t\t
const result = await walkObject(value, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-09-26.
\n
*
\n
* 导出zeroing的视图
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import
{
walkNode
}
from
\"
./utils
\"
;
\n
import path from 'path'
\n
import Color from 'color'
\n
import generateUUID from 'uuid/v4'
\n
import fs from
\"
fs-extra
\"
;
\n
import hash from 'object-hash';
\n\n
export async function execute(psdFile, options) {\n
\t
const
{
\n\t\timagesPath,\n\t
}
= options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile, '.psd'),
\n\t\t
type: 'node',
\n\t
};
\n\n\t
const assets = [];
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {name, x, y, width, height, alpha, visible, origin: {layer: {typeTool, solidColor}}} = node;
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
let viewNode = {\n
\t\t\t
name,
\n\t\t\t
properties,
\n\t\t\t
uuid: generateUUID(),
\n\t\t
};
\n\t\t
if (x !== 0) {\n
\t\t\t
properties.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
properties.y = y;
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
const fonts = fontInfo.fonts();
\n\t\t\t
const styles = fontInfo.styles();
\n\t\t\t
const
{
RunLengthArray
}
= fontInfo.engineData.EngineDict.StyleRun;
\n\n\t\t\t
properties.text = fontInfo.textValue;
\n\t\t\t
properties.textflow = {\n
\t\t\t\t
fonts, styles, RunLengthArray,
\n\t\t\t
};
\n\t\t\t
viewNode.type = 'label';
\n\t\t
} else if (solidColor) {\n
\t\t\t
const {r, g, b} = solidColor();
\n\t\t\t
let color = Color({r, g, b});
\n\n\t\t\t
viewNode.type = 'rect';
\n\t\t\t
properties.fillColor = '#' + color.rgbNumber().toString(16);
\n\t\t
} else {\n
\t\t\t
if (node.hasOwnProperty('children')) {\n
\t\t\t\t
viewNode.type = 'node';
\n\t\t\t
} else {\n
\t\t\t\t
viewNode.type = 'image';
\n\n\t\t\t\t
const uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
properties.source = 'asset|' + uuid;
\n\n\t\t\t\t
const imageFilePath = path.join(imagesPath, uuid + ext);
\n\t\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t\t
let png = node.origin.toPng();
\n\t\t\t\t
let buffer = await savePng(png, imageFilePath);
\n\t\t\t\t
//await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t\t
const hashFileName = hash(buffer);
\n\t\t\t\t
const hashFilePath = path.join(imagesPath, hashFileName + ext);
\n\t\t\t\t
await fs.rename(imageFilePath, hashFilePath);
\n\n\t\t\t\t
assets.push(
{
\n\t\t\t\t\tname,\n\t\t\t\t\text,\n\t\t\t\t\tuuid,\n\t\t\t\t});\n\t\t\t}\n\t\t
}
\n\n\t\t
let viewParent = parent.view || viewRoot;
\n\t\t
if (!viewParent.hasOwnProperty('children')) {\n
\t\t\t
viewParent.children = [];
\n\t\t
}
\n\t\t
viewParent.children.push(viewNode);
\n\n\t\t
node.view = viewNode;
\n\t
});
\n\n\t
return {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
}
\n
}
\n\n
function savePng(png, output) {\n
\t
return new Promise((resolve, reject) => {\n
\t\t
let buffer, buffers = [];
\n\t\t
png.pack()
\n\t\t\t
.on('error', reject)
\n\t\t\t
.on('data', (data) => buffers.push(data))
\n\t\t\t
.on('end', () => {\n
\t\t\t\t
buffer = Buffer.concat(buffers)
\n\t\t\t
})
\n\t\t\t
.pipe(fs.createWriteStream(output))
\n\t\t\t
.on('finish', () =>
{
\n\t\t\t\tresolve(buffer);\n\t\t\t});\n\t});\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
import
{
toZeroing
}
from
\"
../../src/index
\"
;
\n\n
(async function generate() {\n
\t
const imagesPath = 'zeroing-demo/images_' + Date.now();
\n\n\t
const {view, assets} = await toZeroing('psd/test.psd',
{
\n\t\timagesPath,\n\t});\n\n\tconsole.log(assets);\n\tconsole.log(view);\n})();\n"],"names":["toZeroing"],"mappings":";;;;;;;;;;;AAAA;;;;A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"../../src/psd-tree.js"
,
"../../src/utils.js"
,
"../../src/zeroing.js"
,
"generator.js"
],
"sourcesContent"
:
[
"/**
\n
* Created by rockyl on 2019-08-09.
\n
*/
\n\n
const PSD = require('psd');
\n\n
export async function getTree(psdFilePath) {\n
\t
const psd = await PSD.open(psdFilePath);
\n\t
const root = {};
\n\t
walk(psd.tree(), root);
\n\n\t
return root;
\n
}
\n\n
function walk(psNode, dataNode) {\n
\t
const {left: pLeft = 0, top: pTop = 0,} = psNode.parent || {};
\n\t
const {left, top, width, height, name, layer: {opacity, visible}} = psNode;
\n\t
const x = left - pLeft;
\n\t
const y = top - pTop;
\n\n\t
Object.assign(dataNode, {x, y, width, height, alpha: opacity / 255, visible, name, origin: psNode, label: `${name} > [${x}, ${y}, ${width}, ${height}]`});
\n\t
if (psNode.children() && psNode.children().length > 0){\n
\t\t
dataNode.children = [];
\n\t
}
\n\n\t
let children = psNode.children();
\n\t
for (let i = children.length - 1; i >= 0; i--) {\n
\t\t
const childPsNode = children[i];
\n\n\t\t
const childDataNode = {};
\n\t\t
dataNode.children.push(childDataNode);
\n\t\t
walk(childPsNode, childDataNode)
\n\t
}
\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
export async function walkNode(node, callback, includeSelf = false) {\n
\t
if (includeSelf) {\n
\t\t
await callback(node, null);
\n\t
}
\n\t
if (node.children && node.children.length > 0) {\n
\t\t
for (let childNode of node.children) {\n
\t\t\t
await callback(childNode, node);
\n\t\t\t
const result = await walkNode(childNode, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n\n
export async function walkObject(obj, callback) {\n
\t
if(typeof obj ===
\"
object
\"
){\n
\t\t
for (let key of Object.keys(obj)) {\n
\t\t\t
const value = obj[key];
\n\t\t\t
await callback(key, value, obj);
\n\t\t\t
const result = await walkObject(value, callback);
\n\t\t\t
if (result === true)
{
\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-09-26.
\n
*
\n
* 导出zeroing的视图
\n
*/
\n\n
import
{
getTree
}
from
\"
./psd-tree
\"
;
\n
import
{
walkNode
}
from
\"
./utils
\"
;
\n
import path from 'path'
\n
import Color from 'color'
\n
import generateUUID from 'uuid/v4'
\n
import fs from
\"
fs-extra
\"
;
\n
import hash from 'object-hash';
\n\n
export async function execute(psdFile, options) {\n
\t
const
{
\n\t\timagesPath,\n\t
}
= options;
\n\n\t
const tree = await getTree(psdFile);
\n\n\t
let viewRoot = {\n
\t\t
name: path.basename(psdFile, '.psd'),
\n\t\t
type: 'node',
\n\t\t
uuid: generateUUID(),
\n\t
};
\n\n\t
const assets = [];
\n\n\t
await walkNode(tree, async function (node, parent) {\n
\t\t
const {name, x, y, width, height, alpha, visible, origin: {layer: {typeTool, solidColor}}} = node;
\n\t\t
let properties = {\n
\t\t\t
width, height, alpha, visible,
\n\t\t
};
\n\t\t
let viewNode = {\n
\t\t\t
name,
\n\t\t\t
properties,
\n\t\t\t
uuid: generateUUID(),
\n\t\t
};
\n\t\t
if (x !== 0) {\n
\t\t\t
properties.x = x;
\n\t\t
}
\n\t\t
if (y !== 0) {\n
\t\t\t
properties.y = y;
\n\t\t
}
\n\n\t\t
if (typeTool) {\n
\t\t\t
let fontInfo = typeTool();
\n\t\t\t
const fonts = fontInfo.fonts();
\n\t\t\t
const styles = fontInfo.styles();
\n\t\t\t
const
{
RunLengthArray
}
= fontInfo.engineData.EngineDict.StyleRun;
\n\n\t\t\t
properties.text = fontInfo.textValue;
\n\t\t\t
properties.textflow = {\n
\t\t\t\t
fonts, styles, RunLengthArray,
\n\t\t\t
};
\n\t\t\t
viewNode.type = 'label';
\n\t\t
} else if (solidColor) {\n
\t\t\t
const {r, g, b} = solidColor();
\n\t\t\t
let color = Color({r, g, b});
\n\n\t\t\t
viewNode.type = 'rect';
\n\t\t\t
properties.fillColor = '#' + color.rgbNumber().toString(16);
\n\t\t
} else {\n
\t\t\t
if (node.hasOwnProperty('children')) {\n
\t\t\t\t
viewNode.type = 'node';
\n\t\t\t
} else {\n
\t\t\t\t
viewNode.type = 'image';
\n\n\t\t\t\t
const uuid = generateUUID();
\n\t\t\t\t
const ext = '.png';
\n\n\t\t\t\t
properties.source = 'asset|' + uuid;
\n\n\t\t\t\t
const imageFilePath = path.join(imagesPath, uuid + ext);
\n\t\t\t\t
await fs.ensureDir(path.dirname(imageFilePath));
\n\t\t\t\t
let png = node.origin.toPng();
\n\t\t\t\t
let buffer = await savePng(png, imageFilePath);
\n\t\t\t\t
//await node.origin.saveAsPng(imageFilePath);
\n\n\t\t\t\t
const hashFileName = hash(buffer);
\n\t\t\t\t
const hashFilePath = path.join(imagesPath, hashFileName + ext);
\n\t\t\t\t
await fs.rename(imageFilePath, hashFilePath);
\n\n\t\t\t\t
assets.push(
{
\n\t\t\t\t\tname,\n\t\t\t\t\text,\n\t\t\t\t\tuuid,\n\t\t\t\t});\n\t\t\t}\n\t\t
}
\n\n\t\t
let viewParent = parent.view || viewRoot;
\n\t\t
if (!viewParent.hasOwnProperty('children')) {\n
\t\t\t
viewParent.children = [];
\n\t\t
}
\n\t\t
viewParent.children.push(viewNode);
\n\n\t\t
node.view = viewNode;
\n\t
});
\n\n\t
return {\n
\t\t
view: viewRoot,
\n\t\t
assets,
\n\t
}
\n
}
\n\n
function savePng(png, output) {\n
\t
return new Promise((resolve, reject) => {\n
\t\t
let buffer, buffers = [];
\n\t\t
png.pack()
\n\t\t\t
.on('error', reject)
\n\t\t\t
.on('data', (data) => buffers.push(data))
\n\t\t\t
.on('end', () => {\n
\t\t\t\t
buffer = Buffer.concat(buffers)
\n\t\t\t
})
\n\t\t\t
.pipe(fs.createWriteStream(output))
\n\t\t\t
.on('finish', () =>
{
\n\t\t\t\tresolve(buffer);\n\t\t\t});\n\t});\n
}
\n
"
,
"/**
\n
* Created by rockyl on 2019-08-10.
\n
*/
\n\n
import
{
toZeroing
}
from
\"
../../src/index
\"
;
\n\n
(async function generate() {\n
\t
const imagesPath = 'zeroing-demo/images_' + Date.now();
\n\n\t
const {view, assets} = await toZeroing('psd/test.psd',
{
\n\t\timagesPath,\n\t});\n\n\tconsole.log(assets);\n\tconsole.log(view);\n})();\n"],"names":["toZeroing"],"mappings":";;;;;;;;;;;AAAA;;;;AAIA,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;;AAE3B,AAAO,eAAe,OAAO,CAAC,WAAW,EAAE;CAC1C,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;CACxC,MAAM,IAAI,GAAG,EAAE,CAAC;CAChB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC;;CAEvB,OAAO,IAAI,CAAC;CACZ;;AAED,SAAS,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE;CAC/B,MAAM,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,IAAI,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC;CAC9D,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC;CAC3E,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;CACvB,MAAM,CAAC,GAAG,GAAG,GAAG,IAAI,CAAC;;CAErB,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,EA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AC,GAAG,MAAMA,OAAS,CAAC,cAAc,EAAE;EACtD,UAAU;EACV,CAAC,CAAC;;CAEH,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;CACpB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;CAClB,GAAG,CAAC"
}
\ No newline at end of file
\ No newline at end of file
src/zeroing.js
View file @
4a712d00
...
@@ -86,6 +86,7 @@ export async function execute(psdFile, options) {
...
@@ -86,6 +86,7 @@ export async function execute(psdFile, options) {
name
,
name
,
ext
,
ext
,
uuid
,
uuid
,
hash
:
hashFileName
,
});
});
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment