canvas-editor-engine 1.1.46 → 1.1.47

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.
@@ -11,33 +11,36 @@ class ProjectFileSerializer {
11
11
  ;
12
12
  load() {
13
13
  const rowProjects = JSON.parse(this.file);
14
- const imageDataProcessor = (state) => {
15
- const data = Object.values(state.imageData.data);
16
- // const tempCanvas = document.createElement('canvas');
17
- // const tempCtx = tempCanvas.getContext('2d');
18
- // const tempImageData = tempCtx.getImageData(0, 0, _imageData.width, _imageData.height);
19
- const tempImageData = new ImageData(state.size.width, state.size.height);
14
+ const imageDataProcessor = (temp) => {
15
+ let data;
16
+ let size;
17
+ if (temp?.current) {
18
+ data = Object.values(temp?.current.imageData.data);
19
+ size = temp?.current.size;
20
+ }
21
+ else if (temp?.state) {
22
+ data = Object.values(temp?.state.tempImageData.data);
23
+ size = temp?.state.size;
24
+ }
25
+ const tempImageData = new ImageData(size.width, size.height);
20
26
  data.forEach((colorAtom, index) => {
21
27
  tempImageData.data[index] = colorAtom;
22
28
  });
23
29
  return tempImageData;
24
30
  };
25
- const test = imageDataProcessor(rowProjects[0].state.current);
26
- console.log('test', test);
27
- // const projects = rowProjects.map((project) => {
28
- // project.state.current.imageData = imageDataProcessor(project.state.current.imageData);
29
- // project.state.history = project.state.history.map((historyLine) => {
30
- // historyLine.stateValue.tempImageData = imageDataProcessor(historyLine.stateValue.tempImageData);
31
- // return historyLine;
32
- // });
33
- // project.state.cache = project.state.cache.map((historyLine) => {
34
- // historyLine.stateValue.tempImageData = imageDataProcessor(historyLine.stateValue.tempImageData);
35
- // return historyLine;
36
- // });
37
- // return project;
38
- // });
39
- // return projects;
40
- return [{}];
31
+ const projects = rowProjects.map((project) => {
32
+ project.state.current.imageData = imageDataProcessor({ current: project.state.current });
33
+ project.state.history = project.state.history.map((historyLine) => {
34
+ historyLine.stateValue.tempImageData = imageDataProcessor({ state: historyLine.stateValue });
35
+ return historyLine;
36
+ });
37
+ project.state.cache = project.state.cache.map((historyLine) => {
38
+ historyLine.stateValue.tempImageData = imageDataProcessor({ state: historyLine.stateValue });
39
+ return historyLine;
40
+ });
41
+ return project;
42
+ });
43
+ return projects;
41
44
  }
42
45
  saveProjects(projects) {
43
46
  this.file.save(JSON.stringify(projects));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "canvas-editor-engine",
3
- "version": "1.1.46",
3
+ "version": "1.1.47",
4
4
  "description": "CanvasEditorEngine library, use: [typescript] [canvas]",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",