Index of every page on this site: llms.txt
All skills
oahc09 avatar

/cocosair-graphics-and-dom

@ed38648
by oahc09oahc09/cocosairjs3 stars
2
Run it yourself

Draw Graphics/SVG shapes and sprite masks; align a DOM overlay with UI/canvas nodes. Use for overlay placement, input interception, experimental HTML textures or AirUIMesh.

  • 15 files
  • 61.1 KB
  • MIT
  • Updated last month
  • GitHub
Use this Skill: https://skilld.dev/gh/oahc09/cocosairjs/cocosair-graphics-and-dom

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referenceshtml-source.md

≈1.8k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Current HTML source contract (2026-11-15)

This section supersedes conflicting requirements in the retained dated inventory below. Import from cocosair.js, the single browser runtime entry. Dynamic HTML upload requires canvas.requestPaint and WebGL2 texElementSubImage2D. getAirHTMLSourceSupport(canvas, { snapshot: true }) separately requires captureElementImage; geometry and naturalSize are optional capabilities. Missing geometry does not block upload, but updateGeometry rejects with AIR_E_HTML_SOURCE_GEOMETRY_UNSUPPORTED. Old texElementImage2D alone remains unsupported. Capability presence is not proof of healthy context or successful painting.

Elements may be nested under their owning canvas; the nearest canvas must match, and duplicate sources/cross-inner-canvas ownership remain errors. Default size prefers native backing-pixel naturalSize, otherwise CSS offset size times DPR. Explicit resolution is a CSS multiplier; do not multiply native backing size by DPR again. Geometry transforms use CSS pixels and must be updated after layout/projection changes, after paint is ready. Regular primitives.quad UV V runs upward while DOM images start at the top: match geometry UVs; do not also flip UI SpriteFrame uploads.

First paint/resize can reset Texture2D's native allocation. Rebind MeshRenderer material properties in onUpdate, or refresh the existing createAirTextureSprite display. The source borrows the texture and owns paint listeners, captured ElementImage, its geometry and attribute leases. Dispose source before business-owned display/texture/DOM; shared resources retain their original owners. Snapshot freezes image and dimensions and closes once. Synchronous repaint errors enter failed and can be retried, not permanent waiting.

Canvas descendant input controls retain browser keyboard defaults; their keydown does not become a game press. Keyup still retires an earlier held game key without canceling DOM defaults. Direct canvas keys and explicit forwarding keep their contracts. Verify actual focus, typed text and changed GPU glyph pixels; do not treat only dispatched events as success or add a stopPropagation workaround as acceptance.

Actual desktop Chrome 157 supported live/nested/snapshot and DPR1/2 probes. Ordinary Chromium 151 was unsupported; a controlled hidden-capture test proved dynamic independence, not that Chrome naturally lacks capture. No mobile or universal-browser support is inferred. At paused screenshot time render on the native paint boundary, then inspect compositor pixels independently of texture readback. Checkout docs/guides/html-texture.md supplies commands; a copied skills tree does not install browsers or collectors.


Historical HTML source inventory

Derived from src/air/html-source.ts, docs/manual/graphics-and-dom.md, and build/cocosair.module.js (as of 2026-10-10)

Experimental HTML-in-canvas textures

Live HTML-to-texture helpers are experimental APIs exported by the single browser engine entry cocosair.js. There is no separate HTML package entry; importing the main runtime in Node without DOM is unsupported.

Support probe

import { getAirHTMLSourceSupport, createAirHTMLSource } from 'cocosair';

const support = getAirHTMLSourceSupport(canvas);
if (support.supported) { /* create a source */ }

getAirHTMLSourceSupport(canvas) returns { supported, reason }. It is only supported when the canvas exposes requestPaint, captureElementImage, updateElementGeometry, and clearElementGeometry and the WebGL2 context provides texElementSubImage2D; browsers with only the older texElementImage2D are rejected (src/air/html-source.ts:29-37, docs/manual/graphics-and-dom.md:182).

Create

canvas.appendChild(formElement);      // must be a direct child of the canvas
const source = createAirHTMLSource({
    canvas, element: formElement, texture,
    autoUpdate: true,                 // default true; snapshot:true captures one immutable image
    onError: console.error,
});
source.update();                      // request a paint; completion arrives via onUpdate/onError

Guards (src/air/html-source.ts:48-51, :69-72):

  • If unsupported, AIR_E_HTML_SOURCE_UNSUPPORTED throws before any DOM or texture mutation.
  • The element must be a direct child of the canvas (element.parentNode !== canvas throws) and must hold an exclusive lease (one source per element) with a positive resolution.
  • The texture must be a single-mip RGBA8 native Texture2D created for that canvas's WebGL2 device; anything else throws on upload.

The caller owns the texture; its size is driven by the source layout and resolution (docs/manual/graphics-and-dom.md:135). createAirHTMLSource sets the content="drawable" and layoutsubtree canvas attributes plus the element's drawable attribute to satisfy the experimental API surface (src/air/html-source.ts:53-56).

Update cadence

Upload happens only on the browser paint event; the temporary texture binding is restored and engine state caches are untouched (src/air/html-source.ts:60-80, docs/manual/graphics-and-dom.md:139). update() re-arms a pending paint request (an async failure sets status: 'failed'; calling update() retries) (src/air/html-source.ts:84-85). With snapshot: true an immutable ElementImage is captured once and later updates reuse it (src/air/html-source.ts:73, docs/manual/graphics-and-dom.md:135). status is 'waiting' | 'ready' | 'failed' | 'disposed' and the last error stays on error (src/air/html-source.ts:40-42, :84).

Context loss, an element moved out of the canvas, zero size, or an illegal GPU texture are recorded as explicit failures rather than silent success (src/air/html-source.ts:64-72, docs/manual/graphics-and-dom.md:137).

Geometry and dispose

source.updateGeometry({ canvasTransform: { a: 1, d: 1, e: 100, f: 50 } });
source.dispose();   // removes listeners, clears geometry/snapshot; does not free texture or DOM

Uploading pixels does not by itself produce correct interaction: the application converts the native scene projection into the HTML canvasTransform and calls updateElementGeometry (exposed as updateGeometry) so hit-testing, focus, and accessibility geometry stay in sync (src/air/html-source.ts:86, docs/manual/graphics-and-dom.md:139). dispose() removes the paint listener, clears element geometry, closes any snapshot, and restores the canvas content/ layoutsubtree attributes once the last drawable child is gone; it never frees the borrowed texture or DOM element, and throws AIR_E_HTML_SOURCE_DISPOSED on use-after-dispose (src/air/html-source.ts:59, :87-101, docs/manual/graphics-and-dom.md:131).

Verification

Experimental capability must be probed at runtime; a UNSUPPORTED result in a default browser is never rewritten as a feature pass, and system-Chrome evidence does not transfer to ordinary Chromium. See examples/html-texture-experimental/src/main.ts for the live form, repaint, snapshot, and unsupported-branch scene (examples/html-texture-experimental/src/main.ts:1).

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No third-party reports yet.

Signed by skilld at ed38648. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last month
layer
subsystem
All 1 allowed tools
Read Edit Write Bash
Other metadata
compatibility
Cocos AIR source checkout or installed cocosair.js package. Browser rendering requires WebGL 2; source tooling requires Node.js >=18. Use the host-provided tools and user-authorized workspace.
when_to_use
[
  "draw shapes or export curves as SVG",
  "paint gradients, patterns or evenodd holes",
  "mask a sprite or inherit subtree blending",
  "keep a DOM input attached to a UI node",
  "display live HTML or warp textured UI geometry"
]
owns
[
  "graphics-svg",
  "rich-fills",
  "sprite-masks",
  "ui-blend",
  "dom-overlay",
  "html-texture"
]
not_for
[
  "UI widgets and layout -> cocosair-ui-2d",
  "keyboard focus and action routing -> cocosair-input-action",
  "general offscreen render targets -> cocosair-rendering"
]
metadata
{
  "author": "oahc09@gmail.com",
  "version": "1.0.0",
  "last-updated": "2026-10-13",
  "description_zh": "使用 Graphics、SVG、栅格填充、纹理显示、遮罩、混合和 DOM 覆盖层。用于绘图导出、富填充或实验性 HTML 纹理。"
}

README badge

README badge for oahc09/cocosairjs/cocosair-graphics-and-dom