pixelkiln 0.27.0 → 0.28.0

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.
package/dist/cli.js CHANGED
@@ -8490,6 +8490,7 @@ function createGalleryEditHandler(opts) {
8490
8490
  }
8491
8491
 
8492
8492
  // src/gallery/snapshot.ts
8493
+ var PROJECT_FILE_TYPE = "application/octet-stream";
8493
8494
  function galleryMediaId(absolutePath) {
8494
8495
  return createHash3("sha256").update(path22.resolve(absolutePath)).digest("hex").slice(0, 24);
8495
8496
  }
@@ -8639,12 +8640,20 @@ async function buildGallerySnapshot(opts) {
8639
8640
  const companion = await readHandEditCompanion(editPath);
8640
8641
  if (companion) {
8641
8642
  const projectPath = handEditProjectPath(editPath);
8643
+ const project = companion.project && existsSync17(projectPath) ? await fileInfo(projectPath) : null;
8644
+ let projectUrl = null;
8645
+ if (project) {
8646
+ const id = galleryMediaId(projectPath);
8647
+ media.set(id, { path: projectPath, contentType: PROJECT_FILE_TYPE });
8648
+ projectUrl = `${galleryMediaRoute(id)}?v=${project.bytes}-${Date.parse(project.modifiedAt).toString(36)}`;
8649
+ }
8642
8650
  editMeta = {
8643
8651
  editor: companion.editor,
8644
8652
  savedAt: companion.savedAt,
8645
8653
  basedOn: companion.basedOn,
8646
8654
  changedSince: editSha !== null && editSha !== companion.sha256,
8647
- project: companion.project && existsSync17(projectPath) ? portableOutputPath(projectPath, root) : null
8655
+ project: project ? portableOutputPath(projectPath, root) : null,
8656
+ projectUrl
8648
8657
  };
8649
8658
  }
8650
8659
  const regenerated = companion ? generated?.sha256 !== void 0 && generated.sha256 !== null && companion.basedOn !== generated.sha256 : Boolean(generated?.modifiedAt && edit.modifiedAt && generated.modifiedAt > edit.modifiedAt && generated.exists);
@@ -9741,30 +9750,42 @@ function openEditorSheet(item) {
9741
9750
  stage.append(frame, loading);
9742
9751
  panel.append(bar, stage);
9743
9752
  host.append(scrim, panel);
9744
- SHEET = { item, frame, loading, status, msg, save, saveClose, dirty: false, opened: false, ready: null, pending: null, requests: 0, source: src };
9753
+ SHEET = { item, frame, loading, status, msg, save, saveClose, dirty: false, opened: false, ready: null, pending: null, requests: 0, source: src, sentProject: false };
9745
9754
  sheetStatus('cool', 'loading');
9746
9755
  sheetButtons();
9747
9756
  close.focus({ preventScroll: true });
9748
9757
  }
9758
+ // The edit file is what the editor gets; when a browser save kept the layered
9759
+ // project beside it, that goes along too and the editor restores the layers,
9760
+ // falling back to the flattened PNG if the file cannot be read.
9749
9761
  async function sendOpen() {
9750
9762
  const { item, source } = SHEET;
9751
9763
  const style = snap.styles.find((s) => s.id === item.styleId && s.project === item.project);
9752
- let png;
9764
+ const projectUrl = source === item.edit && item.editMeta && item.editMeta.projectUrl && SHEET.ready.version >= 2 ? item.editMeta.projectUrl : null;
9765
+ let png, pxo = null;
9753
9766
  try {
9754
9767
  const res = await fetch(source.url, { cache: 'no-store' });
9755
9768
  if (!res.ok) throw new Error(await res.text());
9756
9769
  png = await res.arrayBuffer();
9770
+ if (projectUrl) {
9771
+ const p = await fetch(projectUrl, { cache: 'no-store' });
9772
+ if (p.ok) pxo = await p.arrayBuffer();
9773
+ }
9757
9774
  } catch (err) {
9758
9775
  if (SHEET) { SHEET.msg.textContent = 'Could not load the image: ' + err.message; sheetStatus('bad', 'failed'); }
9759
9776
  return;
9760
9777
  }
9761
9778
  if (!SHEET) return;
9762
9779
  const request = 'open-' + (++SHEET.requests);
9763
- SHEET.frame.contentWindow.postMessage({
9780
+ SHEET.sentProject = !!pxo;
9781
+ const message = {
9764
9782
  type: 'pixelkiln:open', request,
9765
9783
  asset: { key: item.styleId + '/' + item.assetId, id: item.id, name: item.assetId, width: item.width, height: item.height },
9766
9784
  png, palette: style ? style.palette : [],
9767
- }, location.origin, [png]);
9785
+ };
9786
+ const transfer = [png];
9787
+ if (pxo) { message.pxo = pxo; transfer.push(pxo); }
9788
+ SHEET.frame.contentWindow.postMessage(message, location.origin, transfer);
9768
9789
  sheetStatus('cool', 'opening');
9769
9790
  }
9770
9791
  function requestEditorSave(close) {
@@ -9790,7 +9811,9 @@ async function onEditorMessage(m) {
9790
9811
  case 'pixelkiln:opened':
9791
9812
  SHEET.opened = true;
9792
9813
  SHEET.loading.remove();
9793
- sheetStatus('ok', SHEET.item.edit && SHEET.item.edit.exists ? 'editing the edit file' : 'editing a copy of the generated art');
9814
+ if (m.source === 'pxo') sheetStatus('ok', 'editing the edit file with its ' + (m.layers === 1 ? 'layer' : m.layers + ' layers') + ' restored');
9815
+ else if (SHEET.sentProject) sheetStatus('warn', 'editing the flattened edit file; its layer file could not be opened');
9816
+ else sheetStatus('ok', SHEET.item.edit && SHEET.item.edit.exists ? 'editing the edit file' : 'editing a copy of the generated art');
9794
9817
  sheetButtons();
9795
9818
  break;
9796
9819
  case 'pixelkiln:dirty':
@@ -11762,8 +11785,8 @@ var pin_default = {
11762
11785
  pixelorama: "v1.2.2",
11763
11786
  godot: "4.7.2",
11764
11787
  extensionsApi: 9,
11765
- protocol: 1,
11766
- release: "editor-pixelorama-v1.2.2-pk.6",
11788
+ protocol: 2,
11789
+ release: "editor-pixelorama-v1.2.2-pk.10",
11767
11790
  files: {
11768
11791
  "index.apple-touch-icon.png": {
11769
11792
  sha256: "ee5434873e0fed91e9a888c3ea5a8b79beac25999308be7a6eb41bf4ce640d27",
@@ -11778,7 +11801,7 @@ var pin_default = {
11778
11801
  bytes: 7298
11779
11802
  },
11780
11803
  "index.html": {
11781
- sha256: "43299b159b780809044fc0a484906bb93a280116c22cc87388ee2ab8263ac1f3",
11804
+ sha256: "ad777659ca39a22872437d44595b749c1637f83994d5f82d50dca861f2186b9c",
11782
11805
  bytes: 5442
11783
11806
  },
11784
11807
  "index.icon.png": {
@@ -11790,8 +11813,8 @@ var pin_default = {
11790
11813
  bytes: 279815
11791
11814
  },
11792
11815
  "index.pck": {
11793
- sha256: "ee10aa3d6e09a1ff2a334d0de7df1ae57f32ce00698948892a46443c2c67ae7a",
11794
- bytes: 6426700
11816
+ sha256: "546a3f9851df0854c9f6052f29f1e559de79deb53b936d44a72c3475234c26ff",
11817
+ bytes: 6427868
11795
11818
  },
11796
11819
  "index.png": {
11797
11820
  sha256: "6e3ca3eb4a99e4c07bdd89ebc873b440ec0ffd66ce1955160da9e7ed80d538d7",