@file-viewer/renderer-data 2.1.13 → 2.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/psd.js +18 -8
  2. package/package.json +2 -2
package/dist/psd.js CHANGED
@@ -81,15 +81,15 @@ const toCanvas = (documentRef, source) => {
81
81
  }
82
82
  return undefined;
83
83
  };
84
- const flattenLayers = (documentRef, layers, depth = 0, path = '') => {
84
+ const buildLayerTree = (documentRef, layers, depth = 0, path = '') => {
85
85
  if (!Array.isArray(layers)) {
86
86
  return [];
87
87
  }
88
- return layers.flatMap((layer, index) => {
88
+ return layers.map((layer, index) => {
89
89
  const name = String(layer.name || `Layer ${index + 1}`);
90
90
  const id = `${path}${index}`;
91
91
  const canvas = toCanvas(documentRef, layer.canvas || layer.imageData);
92
- const item = {
92
+ return {
93
93
  id,
94
94
  name,
95
95
  depth,
@@ -98,11 +98,17 @@ const flattenLayers = (documentRef, layers, depth = 0, path = '') => {
98
98
  width: Math.max(0, Number(layer.right || 0) - Number(layer.left || 0)),
99
99
  height: Math.max(0, Number(layer.bottom || 0) - Number(layer.top || 0)),
100
100
  hidden: Boolean(layer.hidden),
101
- canvas
101
+ canvas,
102
+ children: buildLayerTree(documentRef, layer.children, depth + 1, `${id}.`)
102
103
  };
103
- return [item, ...flattenLayers(documentRef, layer.children, depth + 1, `${id}.`)];
104
104
  });
105
105
  };
106
+ const flattenLayerTreeForDrawing = (layers) => {
107
+ return layers.flatMap(layer => [layer, ...flattenLayerTreeForDrawing(layer.children)]);
108
+ };
109
+ const flattenLayerTreeForPanel = (layers) => {
110
+ return layers.slice().reverse().flatMap(layer => [layer, ...flattenLayerTreeForPanel(layer.children)]);
111
+ };
106
112
  const clampZoom = (value) => {
107
113
  return Math.min(4, Math.max(0.1, Number(value.toFixed(2))));
108
114
  };
@@ -112,7 +118,9 @@ export default async function renderPsdAsset(buffer, target, context) {
112
118
  const { readPsd } = await import('ag-psd');
113
119
  const psd = readPsd(buffer, { useImageData: true });
114
120
  const compositeCanvas = toCanvas(documentRef, psd.canvas || psd.imageData);
115
- const layers = flattenLayers(documentRef, psd.children);
121
+ const layerTree = buildLayerTree(documentRef, psd.children);
122
+ const layers = flattenLayerTreeForDrawing(layerTree);
123
+ const panelLayers = flattenLayerTreeForPanel(layerTree);
116
124
  const drawableLayers = layers.filter(layer => layer.canvas);
117
125
  const selected = new Set(drawableLayers.filter(layer => !layer.hidden).map(layer => layer.id));
118
126
  let zoom = 1;
@@ -163,7 +171,7 @@ export default async function renderPsdAsset(buffer, target, context) {
163
171
  context.drawImage(compositeCanvas, 0, 0);
164
172
  return;
165
173
  }
166
- visibleLayerCanvases.slice().reverse().forEach(layer => {
174
+ visibleLayerCanvases.forEach(layer => {
167
175
  if (layer.canvas) {
168
176
  context.drawImage(layer.canvas, layer.left, layer.top);
169
177
  }
@@ -172,8 +180,10 @@ export default async function renderPsdAsset(buffer, target, context) {
172
180
  if (!layers.length) {
173
181
  list.appendChild(createElement(documentRef, 'li', 'psd-empty', t('psd.layers.empty')));
174
182
  }
175
- layers.forEach(layer => {
183
+ panelLayers.forEach(layer => {
176
184
  const item = createElement(documentRef, 'li', 'psd-layer');
185
+ item.dataset.layerId = layer.id;
186
+ item.dataset.layerName = layer.name;
177
187
  item.style.paddingLeft = `${8 + layer.depth * 14}px`;
178
188
  const checkbox = createElement(documentRef, 'input');
179
189
  checkbox.type = 'checkbox';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-data",
3
- "version": "2.1.13",
3
+ "version": "2.1.15",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Standalone data asset renderer plugin for Flyfish File Viewer with PSD, SQLite, Parquet, Avro, WASM, font, AI/EPS, and WebArchive previews.",
@@ -57,7 +57,7 @@
57
57
  "LICENSE"
58
58
  ],
59
59
  "dependencies": {
60
- "@file-viewer/core": "^2.1.13",
60
+ "@file-viewer/core": "^2.1.15",
61
61
  "ag-psd": "^30.1.1",
62
62
  "avsc": "^5.7.9",
63
63
  "hyparquet": "^1.26.0",