Derived from the cocosair-ui-2d 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
createUICanvas(scene, name = 'UICanvas', options = {})returns the Canvas rootNode, not aCanvascomponent (src/air/ui-kit.ts:37,:66). Defaults:layer = Layers.Enum.UI_2D(:38),designWidth = 1280(:39),designHeight = 720(:40). It addsUITransformsized to the design box with anchor(0.5, 0.5)(:44-46),Canvas(:47), and aWidgetfully aligned to all four edges withalignMode = ON_WINDOW_RESIZE(:48-51).- The UI camera is a child node
name + '/Camera', ORTHO,clearFlags = SOLID_COLOR,clearColor = new Color(24, 30, 44, 255),visibility = layer,near = 1,far = 2000, and the helper assignscanvas.cameraComponent = camerabefore returning (src/air/ui-kit.ts:54-66).Canvas.cameraComponentis a real setter that triggers_onResizeCamera()on change (src/cocos/2d/framework/canvas.ts:96-102); without it the batcher draws nothing. - Layer naming has two live conventions. The AIR helpers use
Layers.Enum.UI_2D(bit 25,src/cocos/scene-graph/layers.ts:41), whileexamples/ui-components/main.js:49andexamples/ui-layout/main.js:36useLayers.Enum.UI_3D(bit 23,src/cocos/scene-graph/layers.ts:39). Either works as long as the node's layer bit is included in the UI camera'svisibility; the invariant is node layer == camera visibility layer, not a specific constant (docs/manual/2d-ui.md:56). spriteNode(parent, name = 'Sprite', options)creates aUITransform+Spritechild withsizeMode = CUSTOM(src/air/ui-kit.ts:81-93).sizeModemust beCUSTOMbefore assigning aspriteFrame, or the node resizes to the texture (docs/manual/2d-ui.md:62-66). RuntimeSpriteFrames come fromdocument.createElement('canvas') -> ImageAsset -> Texture2D -> SpriteFrame;builtinResMgr.get('default-spriteframe')GPU-uploads fail in this build, so the examples generate frames instead (examples/ui-components/main.js:93).labelNode(parent, text, name = 'Label', options)setsfontSize = 28by default andlineHeight = Math.round(fontSize * 1.25)(src/air/ui-kit.ts:117,:124),color = options.color ?? Color.WHITE(:125), and only writesoverflow/enableWrapTextwhen supplied (:126-127).enableWrapTextmust be a boolean if present, else it throwsObject.assign(new Error('[AIR_E_LABEL_WRAP] enableWrapText must be boolean'), { code: 'AIR_E_LABEL_WRAP' })(src/air/ui-kit.ts:112-113).- The
Labelfont surface is system + BMFont only.Label extends UIRenderer(src/cocos/2d/components/label.ts:180),Label.CacheModeis{ NONE, BITMAP, CHAR }(:143,:149,:157,:164), andLabel.Overflowis{ NONE, CLAMP, SHRINK, RESIZE_HEIGHT }(:108,:114-133). Outlining and shadow are separate componentsLabelOutline(src/cocos/2d/components/label-outline.ts:46) andLabelShadow(src/cocos/2d/components/label-shadow.ts:43), not Label properties. - Every component in scope is on the single
export { ... }block ofbuild/cocosair.module.js(currently :161574).Canvas,Widget,Button,ScrollView,ProgressBar,Slider,Toggle,EditBox,PageView,SafeAreaandBlockInputEventsare exported both bare and as... as XComponent.Layoutships only asLayout$1 as Layout(src/cocos/ui/layout.ts:214), andRichTextships only asRichText as RichTextComponentwith no bareRichText(src/cocos/2d/components/rich-text.ts:157);LabelAtlasis exported bare (src/cocos/2d/assets/label-atlas.ts:35). - 2D sorting:
Sorting2D extends Componentrequires aUIRenderer(@requireComponent(UIRenderer),src/cocos/sorting/sorting-2d.ts:50-51), andsortingLayer/sortingOrderwriteuiRenderer.priority = SortingLayers.getSortingPriority(layerIndex, order)(:115-126,src/cocos/sorting/sorting-layers.ts:64-66). Out of the boxSortingLayers.Enumhas onlydefault: 0; more layers arrive from settings throughSortingLayers.init()(src/cocos/sorting/sorting-layers.ts:36-41).Intersection2Dis a static 2D geometry intersection utility (src/cocos/physics-2d/builtin/intersection-2d.ts:301), not part of the sort pipeline despite being grouped with it on the export list.