SLOHERO / PHOTOSHOT RESEARCHENGINEERING RECORD · 01IMPLEMENTATION / EVIDENCE / REPRODUCTION

Photoshot development · 01

Reversible layer masks in a browser editor: separating document state from rendering

From a React–PixiJS adapter to a shared Canvas compositor, with explicit source provenance and a reproducible mask diagnostic.

Source scope: initial eead3ca / later v0.16.0 · 19f45ed. This record does not audit every feature of the current production editor.

Abstract

The target was a browser editor in which image, text and paint layers retain their source data while masks change visibility. An initial PixiJS adapter could display document layers, but rendering primitives did not supply the application’s persistence and masking contract. We trace the installed dependencies, the application-specific adapter and the later shared compositor. A new 100 × 100 pixel diagnostic contrasts destructive erasure with document-level masking: disabling the latter restores source RGBA exactly. Five source-level checks pass. This is an engineering record with a controlled counterexample, not a claim of universal Photoshop compatibility.

1. Objective and acceptance criteria

The intended feature was not simply a canvas showing several images. A layer needed an independent position, size, rotation, opacity and blend mode. A mask needed to hide and restore content without overwriting the source. The same document also needed to survive serialization and produce a composited output. These requirements determine what “working” means for this entry.

We therefore separate three objects: the persistent document, the temporary surface rendered for one layer, and the display object shown by the graphics library. React controls the UI; the layer model owns edit parameters and mask strokes. A screenshot of an attractive composition alone cannot establish that those objects remain consistent.1

2. Initial implementation and the integration obstacle

The initial public commit, eead3ca, imports Application, Sprite and Texture from PixiJS. It creates one sprite per visible layer and transfers document fields into renderer properties. Rotation is converted from degrees to radians, the anchor is centered, and position is offset by half the layer dimensions. This is direct API reuse of an installed library, with separately written adapter code.

The obstacle was the boundary between a graphics object and an editable document. A Sprite does not define our mask history, project schema or export semantics. Moreover, the initial stage renders through PixiJS while document export has its own Canvas composition loop. Source inspection establishes these separate paths; it does not establish a measured preview/export error for every image. We do not turn that architectural risk into an invented historical failure.1

Listing 1 · src/stage.tsx, L1–5 · eead3ca
'use client';
import { useEffect, useRef } from 'react';
import { Application, Sprite, Texture } from 'pixi.js';
import 'pixi.js/advanced-blend-modes';
import { layerSurface, type StudioDoc } from './document';
Listing 2 · src/stage.tsx, L27–33 · eead3ca
      const s = new Sprite(Texture.from(canvas));
      s.anchor.set(0.5);
      s.position.set(l.x + l.width / 2, l.y + l.height / 2);
      s.rotation = (l.rotation * Math.PI) / 180;
      s.alpha = l.opacity;
      s.blendMode = l.blend;
      a.stage.addChild(s);

3. GitHub material and the reuse decision

React and PixiJS supplied established UI and rendering infrastructure. The concrete evidence of PixiJS use is the import and Sprite construction in our own initial commit, rather than the presence of a repository URL in a reference list. The layerSurface call, coordinate mapping and document schema are Photoshot integration code. A whole external photo editor was not transplanted.23

Photopea’s mask documentation supplied a behavioral comparison: content must remain recoverable when the mask is disabled. It is documentation consulted for expected behavior, not evidence that Photopea source code was available or copied. For the later compositor we cite Photoshot’s own exact revision, 19f45ed, instead of attributing its implementation to PixiJS.4

Table 1 | What was reused, consulted and implemented
SourceUse categoryContributionBoundary
ReactInstalled dependencyUI components and stateNo claim of a copied editor
PixiJSInstalled dependency; early stageApplication, Sprite and Texture APIsLater Stage uses Canvas composition
Photopea MasksBehavioral documentationRecoverable visibility editsNo source transplant
PhotoshotApplication-specific codeDocument, adapter, masking and shared compositionExact source revisions linked below

Dependency use, behavioral consultation and application code are separate provenance claims.

4. Implementation: retain the source; compose a temporary surface

For each render, layerSurface creates a Canvas, draws the layer’s source or paint strokes, and applies the mask with destination-in. The mask’s alpha controls how much of that temporary destination survives. The operation then returns to source-over. Mask strokes and source strokes remain distinct fields in the document; disabling the mask causes the surface to be regenerated from the retained source.

In the later Stage, preview calls the shared composite function. Layer order, transforms, blending and adjustments are handled through the document composition path. Preview requests bound the longest edge to 1,600 pixels and cancel stale work using a revision predicate. Sharing that path narrows the number of independent render implementations; the preview-size limit means full-resolution equivalence still requires an appropriately matched test.5

Listing 3 · src/document.ts, L192–196 · 19f45ed
  if (layer.mask?.enabled) {
    ctx.globalCompositeOperation = 'destination-in';
    ctx.drawImage(maskSurface(layer.mask), 0, 0, c.width, c.height);
    ctx.globalCompositeOperation = 'source-over';
  }
Listing 4 · src/stage.tsx, L31–35 · 19f45ed
          const image = await composite(d, false, {
            maxEdge: 1600,
            cancelled: () => !mounted.current || r !== revision.current,
          });
          if (!mounted.current) break;
A shared document-to-pixel pipeline
Fig. 1 | A shared document-to-pixel pipeline. Source-level schematic of the later v0.16.0 composition path. The early PixiJS stage is discussed in Listings 1–2; the arrows here represent data flow, not benchmark timings. Preview and export use the same compositor but may request different resolutions.
SVG

5. Diagnostic method and observed result

For this revision of the article, we executed the unchanged public document engine under Node with @napi-rs/canvas. The input is a 100 × 100 paint layer with blue and orange strokes. A 40-pixel mask stroke hides its center. We compare source, enabled-mask and disabled-mask surfaces, then serialize the document to JSON, validate it and composite it again. The source document is also compared before and after rendering.

The negative control deliberately erases the center of a retained Canvas and then stops applying the erase operation. Merely disabling that operation cannot reconstruct pixels that were already removed. It is a newly constructed diagnostic alternative, not an archived early Photoshot build. At the center, the destructive control remains transparent (alpha 0), whereas disabling the document mask restores alpha 255. The complete disabled-mask RGBA array equals the original source array, and the masked project round trip equals its pre-save render.6

Failure control and successful recovery
Fig. 2 | Failure control and successful recovery. Newly rendered diagnostic outputs. a, Original paint layer. b, Center hidden by the document mask. c, A deliberately destructive control after its erase operation is disabled: missing pixels remain missing. d, Disabling the document mask regenerates the intact source. The checkerboard only indicates transparency. Panel c is not a historical product screenshot.
SVGData
Recovery across a horizontal alpha profile
Fig. 3 | Recovery across a horizontal alpha profile. The line through y = 50 spans 100 pixels. The destructive control retains a transparent gap; the disabled document mask returns alpha 255 throughout. These are pixel values from one controlled input, with no statistical or performance interpretation.
SVGData
Table 2 | Source-level diagnostic checks, rerun for this article
CheckObservationResult
Source document before/afterIdentical JSONPASS
Mask at the centerAlpha 0PASS
Restore stroke at the centerAlpha 255PASS
Mask disabledRGBA equals original sourcePASS
JSON serialize → validate → compositeRGBA equals masked renderPASS

Five deterministic checks on the stated synthetic input. JSON round trip is not an IndexedDB durability test. Browser and Photoshop parity are outside this rerun.

6. Interpretation, scope and next step

The result supports a precise implementation claim: this source revision preserves the source and can regenerate the tested image when its document mask is disabled. It does not show that every image format, GPU/browser combination, transformed mask or blend mode matches Photoshop. The diagnostic uses a native Canvas implementation and does not replace a browser interaction test, a real IndexedDB save/reopen test, or a full-resolution export comparison.

The architectural change is also narrower than replacing one library name with another. We reused React and early PixiJS, wrote the document adapter and mask plumbing, and later routed preview through our own common compositor. Part 2 follows a numerical failure: a plausible brightness/contrast response produced visibly wrong chart values, prompting a measured-response correction rather than a cosmetic UI change.

Code, data and reproducibility

Reproduce and inspect: unchanged source files, exact excerpt provenance and the new diagnostic outputs are available below. The diagnostic harness imports Photoshot’s document engine; it is separate from the production editor.

References and source identity

  1. Photoshot initial document and Stage · eead3ca
  2. React · installed UI dependency
  3. PixiJS · installed early renderer dependency
  4. Photopea · Masks (behavioral reference)
  5. Photoshot Stage and document · 19f45ed
  6. Photoshot mask-render test · 19f45ed