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.

referencescontracts.md

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

Derived from the cocosair-graphics-and-dom skill and its canonical docs/source pointers; reorganized on 2026-10-11. Source annotations below identify repository inputs, not files guaranteed to ship to npm consumers.

Contracts

  • The UI host is a contract, not boilerplate. Graphics, AirUIMesh and createAirTextureSprite output are 2D renderers, so they draw only under a Canvas whose cameraComponent is an ortho camera whose visibility contains the node's Layers.Enum.UI_2D bit (src/air/ui-kit.ts:38, :44-51, :61, :65); createUICanvas(scene, name, options) builds that whole host and cocosair-ui-2d owns it. A bare new Node() + addComponent(Camera) yields a perfectly uniform canvas with no error, and Layers.UI_2D is undefined - the bit is Layers.Enum.UI_2D.
  • AirGraphicsCommand[] is plain drawing data with Y-up local coordinates; a command is moveTo/lineTo/bezierCurveTo/quadraticCurveTo/arc/rect/roundRect/ellipse/circle/close/fill/stroke (src/air/graphics-commands.ts:5-15). Colors must match #rrggbb and opacity stays in [0,1], else validation throws AIR_E_GRAPHICS_COMMAND before any replay (:26-31, :32-70).
  • drawAirGraphics(graphics, commands, clear = true) replays only solid nonzero fills on the native Graphics; it throws on any gradient, pattern or evenodd fill, pointing you at rasterizeAirGraphics (src/air/graphics-commands.ts:74-88, :76). arc's last boolean keeps native direction (true = counter-clockwise); stroke accepts butt|round|square caps and miter|round|bevel joins (docs/manual/graphics-and-dom.md:54).
  • airGraphicsCommandsToSvg(commands, bounds) serializes the same data into <svg>, flipping Y exactly once via the scale(1 -1) group and viewBox (src/air/graphics-commands.ts:156). It preserves original curves and does not reconstruct them from a subdivided Graphics.impl (docs/manual/graphics-and-dom.md:56); SVG supports solid/linear/radial fills plus local patterns with opacity and evenodd holes (:58).
  • Pattern paint is { kind: 'pattern', image, width, height, textureSpace, transform }; transform is a direct affine pattern -> chosen space, never pre-inverted or premultiplied by texture size (src/air/graphics-commands.ts:22). textureSpace: 'global' makes airGraphicsCommandsToSvg throw and requires rasterizeAirGraphics to receive options.worldTransform (the local-to-world matrix [a,b,c,d,tx,ty]) (src/air/graphics-commands.ts:106, src/air/graphics-raster.ts:28-30). SVG pattern export needs local coordinates plus an explicit sourceURL that is a data:image or http(s) value (src/air/graphics-commands.ts:107).
  • rasterizeAirGraphics(commands, { bounds, resolution = 1, worldTransform? }) uses Canvas2D and a native Texture2D; it is a raster result, not a GPU vector filler. resolution sets pixels per logical unit and each edge is capped at 8192, else AIR_E_GRAPHICS_RESOLUTION (src/air/graphics-raster.ts:26-27). The -resolution device transform plus top-first getImageData rows match native Sprite UV, so there is no extra upload flip (:32, :77-80). Call update(commands?, options?) explicitly on any command/resolution/bounds/global-pattern-transform change; it is not an automatic per-frame loop (:23, docs/manual/graphics-and-dom.md:82).
  • createAirTextureSprite(parent, texture, { name?, size?, anchor? }) borrows the TextureBase and owns the created Node/SpriteFrame; default size is the texture size and default anchor [0.5, 0.5], set on UITransform not the shared texture (src/air/texture-sprite.ts:14-25). refresh() rebuilds the frame rect/originalSize after the texture resizes; dispose() destroys the owned node/frame but not the borrowed texture (:28-47).
  • attachAirSpriteMask(sprite, maskTexture, options) samples a second texture in normalized sprite UVs and handles trimmed/rotated atlas frames via an inverse affine (src/air/effects/sprite-mask.ts:68-74). channel is alpha|red (default alpha), mode is soft|threshold (default soft; soft attenuates output alpha, threshold discards fragments at threshold, default 0.1), plus inverted (:10-15, :21-23). It masks ONE Sprite, never an arbitrary subtree, and refuses a Sprite that already has a customMaterial (docs/manual/graphics-and-dom.md:103, src/air/effects/sprite-mask.ts:24). Detach the binding before disposing the mask texture (:78-82).
  • createAirUIBlendScope(root, mode = 'normal') is an opt-in controller: it rewrites the private _srcBlendFactor/_dstBlendFactor and pushes normal|add|multiply through a MaterialInstance overridePipelineStates, covering native UIRenderer including ParticleSystem2D (src/air/ui-blend.ts:5-28). It adds no implicit Node.blendMode. Call update() after hierarchy/component/particle/material changes; set(node, null) restores inheritance and explicit child overrides win (:36-53). dispose() and moving a node out of the subtree restore only the factors the controller still owns (:29-35, :54).
  • createAirDOMOverlay({ canvas, host?, className? }) owns one independent fixed root and never mutates game.container; .attach(element, node, camera, { width?, height?, anchor? }) borrows the element and .dispose() restores its original parent, order and inline style (src/air/dom-overlay.ts:24-44, :68-77). update() (from the app's own frame callback, not a second clock) projects the node's world matrix plus the canvas CSS-vs-backing size into one CSS matrix(); this affine mapping is intended for planar orthographic UI, and perspective or tilted planes cannot be represented accurately (:50-67, docs/manual/graphics-and-dom.md:37).
  • AirUIMesh is a native UIRenderer component (@requireComponent(UITransform)) that shares Sprite materials, stencil masks and batch buffers. setGeometry({ positions, uvs, indices }) requires 3..1024 XY vertices, one [0,1] UV pair per vertex, and 1..1365 triangles (indices.length in 3..4095, multiple of 3) or it throws AIR_E_UI_MESH_GEOMETRY (src/air/ui-mesh.ts:21-31, :106). dispose() clears the renderer and releases its frame/texture leases without destroying the node or shared assets (:111-115).
  • HTML live textures are experimental APIs in the main cocosair.js entry (bundle build/cocosair.module.js): getAirHTMLSourceSupport(canvas) probes the API, and createAirHTMLSource({ canvas, element, texture, ... }) throws AIR_E_HTML_SOURCE_UNSUPPORTED before any DOM/texture mutation when the browser lacks it. The element must be a direct child of the canvas and hold an exclusive lease, and the texture must be a single-mip RGBA8 native Texture2D for that WebGL2 device (src/air/html-source.ts:39-51, :69-72).

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