tokimeki-image-editor 0.1.11 → 0.1.13

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.
@@ -700,6 +700,11 @@ export function isWebGPUInitialized() {
700
700
  */
701
701
  export async function exportWithWebGPU(imageSource, adjustments, transform, cropArea = null, blurAreas = []) {
702
702
  try {
703
+ // Detect mobile devices
704
+ const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
705
+ if (isMobile) {
706
+ console.log('Mobile device detected, WebGPU export may have limited support');
707
+ }
703
708
  // Get adapter and device
704
709
  if (!navigator.gpu) {
705
710
  console.warn('WebGPU not supported for export');
@@ -1144,6 +1149,49 @@ export async function exportWithWebGPU(imageSource, adjustments, transform, crop
1144
1149
  device.queue.submit([commandEncoder.finish()]);
1145
1150
  // Wait for rendering to complete
1146
1151
  await device.queue.onSubmittedWorkDone();
1152
+ // Validate that the canvas has actual content (not all black)
1153
+ // This is important for mobile devices where WebGPU might fail silently
1154
+ try {
1155
+ const ctx2d = document.createElement('canvas').getContext('2d');
1156
+ if (ctx2d) {
1157
+ const testCanvas = document.createElement('canvas');
1158
+ testCanvas.width = Math.min(canvas.width, 100);
1159
+ testCanvas.height = Math.min(canvas.height, 100);
1160
+ const testCtx = testCanvas.getContext('2d');
1161
+ if (testCtx) {
1162
+ // Draw a small portion of the WebGPU canvas to test
1163
+ testCtx.drawImage(canvas, 0, 0, testCanvas.width, testCanvas.height);
1164
+ const imageData = testCtx.getImageData(0, 0, testCanvas.width, testCanvas.height);
1165
+ const data = imageData.data;
1166
+ // Check if at least some pixels are non-zero
1167
+ let hasContent = false;
1168
+ for (let i = 0; i < data.length; i += 4) {
1169
+ // Check RGB values (ignore alpha)
1170
+ if (data[i] > 0 || data[i + 1] > 0 || data[i + 2] > 0) {
1171
+ hasContent = true;
1172
+ break;
1173
+ }
1174
+ }
1175
+ if (!hasContent) {
1176
+ console.warn('WebGPU export produced empty/black canvas, will use Canvas2D fallback');
1177
+ // Cleanup before returning null
1178
+ texture.destroy();
1179
+ intermediate1.destroy();
1180
+ intermediate2.destroy();
1181
+ intermediate3.destroy();
1182
+ intermediate4.destroy();
1183
+ mainUniformBuffer.destroy();
1184
+ blurUniformBuffer.destroy();
1185
+ grainUniformBuffer.destroy();
1186
+ return null;
1187
+ }
1188
+ }
1189
+ }
1190
+ }
1191
+ catch (validationError) {
1192
+ console.warn('Failed to validate WebGPU canvas, assuming it is valid:', validationError);
1193
+ // If validation fails, assume the canvas is valid and continue
1194
+ }
1147
1195
  // Cleanup
1148
1196
  texture.destroy();
1149
1197
  intermediate1.destroy();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokimeki-image-editor",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "A image editor for svelte.",
5
5
  "type": "module",
6
6
  "license": "MIT",