Skip to content

refactor(examples): convert 13 camera examples to ESM helpers (refs #79)#100

Merged
kalwalt merged 1 commit into
devfrom
refactor/79-examples-esm-batch2
Jul 25, 2026
Merged

refactor(examples): convert 13 camera examples to ESM helpers (refs #79)#100
kalwalt merged 1 commit into
devfrom
refactor/79-examples-esm-batch2

Conversation

@kalwalt

@kalwalt kalwalt commented Jul 25, 2026

Copy link
Copy Markdown
Member

Phase 2 of #79 — applies the helper API validated in phase 1 (#98) to the simple and medium tiers: 13 of the remaining 15 camera examples.

Converted

Tier Files
simple boxblur, canny_edge, equalize_hist, gaussblur, scharr, sobel, warp_affine, warp_perspective
medium oflow_lk, pyrdown, sobel_edge, yape, yape06

Each now uses <script type="module"> + import jsfeatNext from '../dist/jsfeatNext.mjs', with loadCamera() / stopCamera() / showCameraError() from demo-utils.mjs and the profiler via profiler.mjs. jQuery and js/compatibility.js are gone from all of them, and the inline grayscale→RGBA loops plus the duplicated render_corners / render_mono_image functions are replaced by the shared renderMonoImage() / renderCorners().

−684 net lines (364 insertions, 1048 deletions) — all boilerplate.

⚠️ A bug caught during conversion

The mechanical pass initially left var ctx, canvasWidth, canvasHeight; in 10 files. That would have shadowed the module-level ctx with undefined and left canvasWidth/canvasHeight undefined — and sample_yape.html passes those straight into jsfeatNext.yape.init(...), while sample_oflow_lk.html uses them for its click bounds-check (clicking would have silently added no tracking points). Fixed by removing the stale declarations and mapping the two variables to the WIDTH/HEIGHT constants (the canvas is 640×480, so they're identical).

Not in this batch — deliberately

sample_orb.html (556 lines) and sample_orb_pinball.html (586) have four render helpers each plus pattern-training logic — a different risk profile. They get their own focused PR to finish #79.

Verification

  • Built a temporary iframe harness that loaded all 15 ESM examples (these 13 + the 2 pilots) and collected errors: every one has a module script, zero jQuery, zero compatibility shim, zero non-camera errors. Harness removed afterwards.
  • Prettier clean.
  • All 13 confirmed working with a real webcam by @kalwalt, including oflow_lk's click-to-add-points and its custom log line.

🤖 Generated with Claude Code

Phase 2 of #79: applies the helper API validated in phase 1 (#98) to the
simple and medium tiers — 13 of the remaining 15 camera examples.

Converted (ESM + de-jQuery in one pass, behaviour unchanged):
- simple: boxblur, canny_edge, equalize_hist, gaussblur, scharr, sobel,
  warp_affine, warp_perspective
- medium: oflow_lk, pyrdown, sobel_edge, yape, yape06

Each now uses `<script type="module">` with `import jsfeatNext from
'../dist/jsfeatNext.mjs'`, `loadCamera()`/`stopCamera()`/`showCameraError()`
from `demo-utils.mjs`, and the profiler via `profiler.mjs`. jQuery and
`js/compatibility.js` are gone from all of them; the inline grayscale->RGBA
expansion loops and the duplicated `render_corners`/`render_mono_image`
functions are replaced by the shared `renderMonoImage()`/`renderCorners()`.

Net -684 lines (364 insertions, 1048 deletions) — all boilerplate.

Note on a bug caught during conversion: the mechanical pass initially left
`var ctx, canvasWidth, canvasHeight;` in 10 files. That would have shadowed
the module-level `ctx` with `undefined` and left `canvasWidth`/`canvasHeight`
undefined — `sample_yape.html` passes those straight into
`jsfeatNext.yape.init(...)`. The stale declarations are removed and the two
variables mapped to the `WIDTH`/`HEIGHT` constants (the canvas is 640x480,
so they are identical).

`sample_orb.html` and `sample_orb_pinball.html` are deliberately NOT in this
batch: at ~556/586 lines with four render helpers each plus pattern-training
logic, they are a different risk profile and get their own focused PR.

Verified with an iframe harness loading all 15 ESM examples (these 13 plus
the two phase-1 pilots): every one has a module script, zero jQuery, zero
compatibility shim, and zero non-camera errors. The harness was removed
afterwards. Prettier clean. All 13 additionally confirmed working with a real
webcam by the maintainer.
@kalwalt kalwalt added this to the 1.0.0 milestone Jul 25, 2026
@kalwalt kalwalt self-assigned this Jul 25, 2026
@kalwalt
kalwalt merged commit f94220a into dev Jul 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant