@flare-engine/shapes 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -21
- package/NOTICE +2 -0
- package/README.md +29 -16
- package/dist/index.d.mts +92 -99
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +92 -99
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +363 -382
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +355 -348
- package/dist/index.mjs.map +1 -1
- package/package.json +21 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { SkCanvas, SkPaint, Skia } from "@shopify/react-native-skia";
|
|
2
|
+
//#region src/types.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* Shape primitive vocabulary. 12 named atomic shapes + 1 SVG escape hatch.
|
|
5
5
|
*
|
|
@@ -18,63 +18,63 @@ import { Skia as Skia$1, SkCanvas, SkPaint } from '@shopify/react-native-skia';
|
|
|
18
18
|
* `draw.ts` to feed Skia paints.
|
|
19
19
|
*/
|
|
20
20
|
interface BaseSpec {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
readonly fill?: number;
|
|
22
|
+
readonly stroke?: number;
|
|
23
|
+
readonly strokeWidth?: number;
|
|
24
|
+
/** Local offset applied when composing multiple shapes per entity. */
|
|
25
|
+
readonly ox?: number;
|
|
26
|
+
readonly oy?: number;
|
|
27
|
+
/** Local rotation in radians, composed with the entity rotation. */
|
|
28
|
+
readonly rot?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Optional glow tag. When present, `drawShape` emits the corresponding glow
|
|
31
|
+
* ring behind the body geometry.
|
|
32
|
+
*
|
|
33
|
+
* 'friendly' — safe-green rim (player ship, weapon/upgrade pickups)
|
|
34
|
+
* 'hazard' — orange double-stroke (danger cues, enemy bullets)
|
|
35
|
+
*/
|
|
36
|
+
readonly glow?: 'friendly' | 'hazard';
|
|
37
37
|
}
|
|
38
38
|
interface CircleSpec extends BaseSpec {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
readonly kind: 'circle';
|
|
40
|
+
readonly r: number;
|
|
41
41
|
}
|
|
42
42
|
interface RectSpec extends BaseSpec {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
readonly kind: 'rect';
|
|
44
|
+
readonly w: number;
|
|
45
|
+
readonly h: number;
|
|
46
46
|
}
|
|
47
47
|
interface TriangleSpec extends BaseSpec {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
readonly kind: 'triangle';
|
|
49
|
+
readonly size: number;
|
|
50
50
|
}
|
|
51
51
|
interface NgonSpec extends BaseSpec {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
readonly kind: 'ngon';
|
|
53
|
+
readonly n: number;
|
|
54
|
+
readonly r: number;
|
|
55
55
|
}
|
|
56
56
|
interface StarSpec extends BaseSpec {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
readonly kind: 'star';
|
|
58
|
+
readonly points: number;
|
|
59
|
+
readonly rOuter: number;
|
|
60
|
+
readonly rInner: number;
|
|
61
61
|
}
|
|
62
62
|
interface RingSpec extends BaseSpec {
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
readonly kind: 'ring';
|
|
64
|
+
readonly r: number;
|
|
65
65
|
}
|
|
66
66
|
interface PolylineSpec extends BaseSpec {
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
readonly kind: 'polyline';
|
|
68
|
+
readonly points: readonly number[];
|
|
69
69
|
}
|
|
70
70
|
interface GradientRectSpec extends BaseSpec {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
71
|
+
readonly kind: 'gradient-rect';
|
|
72
|
+
readonly w: number;
|
|
73
|
+
readonly h: number;
|
|
74
|
+
readonly colorA: number;
|
|
75
|
+
readonly colorB: number;
|
|
76
|
+
/** 0 = horizontal, 1 = vertical. */
|
|
77
|
+
readonly axis: 0 | 1;
|
|
78
78
|
}
|
|
79
79
|
/**
|
|
80
80
|
* Sector or arc. Angles in radians, 0 = +X axis, increasing CCW.
|
|
@@ -85,12 +85,12 @@ interface GradientRectSpec extends BaseSpec {
|
|
|
85
85
|
* - 1/8-moon: startAngle: -Math.PI/8, endAngle: Math.PI/8, sector: true
|
|
86
86
|
*/
|
|
87
87
|
interface ArcSpec extends BaseSpec {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
readonly kind: 'arc';
|
|
89
|
+
readonly r: number;
|
|
90
|
+
readonly startAngle: number;
|
|
91
|
+
readonly endAngle: number;
|
|
92
|
+
/** Closed wedge (true) or open arc stroke (false). Default false. */
|
|
93
|
+
readonly sector?: boolean;
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* Annulus (ring with thickness). When `startAngle`+`endAngle` are set,
|
|
@@ -101,12 +101,12 @@ interface ArcSpec extends BaseSpec {
|
|
|
101
101
|
* the ring colour.
|
|
102
102
|
*/
|
|
103
103
|
interface AnnulusSpec extends BaseSpec {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
readonly kind: 'annulus';
|
|
105
|
+
readonly rOuter: number;
|
|
106
|
+
readonly rInner: number;
|
|
107
|
+
/** If set together with `endAngle`, renders a partial annulus. */
|
|
108
|
+
readonly startAngle?: number;
|
|
109
|
+
readonly endAngle?: number;
|
|
110
110
|
}
|
|
111
111
|
/**
|
|
112
112
|
* Trapezoid (4-sided, parallel top and bottom edges). Apex up — `topW` is
|
|
@@ -114,10 +114,10 @@ interface AnnulusSpec extends BaseSpec {
|
|
|
114
114
|
* to flip apex-down.
|
|
115
115
|
*/
|
|
116
116
|
interface TrapezoidSpec extends BaseSpec {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
117
|
+
readonly kind: 'trapezoid';
|
|
118
|
+
readonly topW: number;
|
|
119
|
+
readonly botW: number;
|
|
120
|
+
readonly h: number;
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
123
|
* SVG path escape hatch. `d` is the standard SVG path-data string (M, L, C,
|
|
@@ -128,56 +128,37 @@ interface TrapezoidSpec extends BaseSpec {
|
|
|
128
128
|
* silently skipped (does not throw).
|
|
129
129
|
*/
|
|
130
130
|
interface PathSpec extends BaseSpec {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
131
|
+
readonly kind: 'path';
|
|
132
|
+
readonly d: string;
|
|
133
|
+
/**
|
|
134
|
+
* Bounding-radius hint for atlas tile sizing. Required because parsing
|
|
135
|
+
* `d` to compute bounds is non-trivial outside Skia. Treat as "max
|
|
136
|
+
* distance from origin to any point on the path".
|
|
137
|
+
*/
|
|
138
|
+
readonly boundsR: number;
|
|
139
139
|
}
|
|
140
140
|
/** Used exclusively as `ShipSpec.engine`. Not part of the flat `ShapeSpec` union. */
|
|
141
141
|
interface SquareSpec extends BaseSpec {
|
|
142
|
-
|
|
143
|
-
|
|
142
|
+
readonly kind: 'square';
|
|
143
|
+
readonly size: number;
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
146
|
-
* Composite ship spec
|
|
146
|
+
* Composite ship spec — a 3-element rule:
|
|
147
147
|
* hull + N rect weapons + 1 square engine.
|
|
148
148
|
*
|
|
149
|
-
*
|
|
150
|
-
* of `ShipSpec
|
|
151
|
-
*
|
|
149
|
+
* A higher-level `ShipDef` (hull-preset references) may eventually replace
|
|
150
|
+
* direct use of `ShipSpec`; for now this remains the rendering composite
|
|
151
|
+
* consumed by `drawShip`.
|
|
152
152
|
*/
|
|
153
153
|
interface ShipSpec extends BaseSpec {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
readonly kind: 'ship';
|
|
155
|
+
readonly hull: ShapeSpec;
|
|
156
|
+
readonly weapons: readonly RectSpec[];
|
|
157
|
+
readonly engine: SquareSpec;
|
|
158
158
|
}
|
|
159
159
|
type ShapeSpec = CircleSpec | RectSpec | TriangleSpec | NgonSpec | StarSpec | RingSpec | PolylineSpec | GradientRectSpec | ArcSpec | AnnulusSpec | TrapezoidSpec | PathSpec | ShipSpec;
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
* Shape drawing dispatcher — consumes a `ShapeSpec` and emits Skia draw
|
|
163
|
-
* calls on a canvas. All shapes draw relative to (x + ox, y + oy), rotated
|
|
164
|
-
* by (rot + spec.rot).
|
|
165
|
-
*
|
|
166
|
-
* The dispatcher is allocation-free per call except where Skia itself
|
|
167
|
-
* allocates path objects. Glow ring is emitted before the shape body so it
|
|
168
|
-
* renders behind the geometry.
|
|
169
|
-
*/
|
|
170
|
-
|
|
171
|
-
type Skia = typeof Skia$1;
|
|
172
|
-
/** ARGB for safe #6FA66B at α ≈ 0.25 (0x40 / 255). */
|
|
173
|
-
declare function friendlyGlowArgb(): number;
|
|
174
|
-
/** ARGB for hazardOrange #E84B2A at α ≈ 0.6 (0x99 / 255). */
|
|
175
|
-
declare function hazardGlowArgb(): number;
|
|
176
|
-
declare function applyFriendlyGlow(_Skia: Skia, canvas: SkCanvas, paint: SkPaint, cx: number, cy: number, r: number): void;
|
|
177
|
-
declare function applyHazardGlow(_Skia: Skia, canvas: SkCanvas, paint: SkPaint, cx: number, cy: number, r: number): void;
|
|
178
|
-
declare function argbTo(out: Float32Array, argb: number): void;
|
|
179
|
-
declare function drawShape(Skia: Skia, canvas: SkCanvas, paint: SkPaint, spec: ShapeSpec, x: number, y: number, rot: number): void;
|
|
180
|
-
|
|
160
|
+
//#endregion
|
|
161
|
+
//#region src/bounds.d.ts
|
|
181
162
|
/**
|
|
182
163
|
* Approximate bounding radius for a single primitive. Used to size glow
|
|
183
164
|
* rings and atlas tiles. Returned values are deliberately a touch generous
|
|
@@ -190,5 +171,17 @@ declare function singleShapeRadius(spec: ShapeSpec): number;
|
|
|
190
171
|
* shapes (including their `ox`/`oy` offsets and stroke widths).
|
|
191
172
|
*/
|
|
192
173
|
declare function shapeBoundsRadius(specs: readonly ShapeSpec[]): number;
|
|
193
|
-
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/draw.d.ts
|
|
176
|
+
type Skia$1 = typeof Skia;
|
|
177
|
+
/** ARGB for safe #6FA66B at α ≈ 0.25 (0x40 / 255). */
|
|
178
|
+
declare function friendlyGlowArgb(): number;
|
|
179
|
+
/** ARGB for hazardOrange #E84B2A at α ≈ 0.6 (0x99 / 255). */
|
|
180
|
+
declare function hazardGlowArgb(): number;
|
|
181
|
+
declare function applyFriendlyGlow(_Skia: Skia$1, canvas: SkCanvas, paint: SkPaint, cx: number, cy: number, r: number): void;
|
|
182
|
+
declare function applyHazardGlow(_Skia: Skia$1, canvas: SkCanvas, paint: SkPaint, cx: number, cy: number, r: number): void;
|
|
183
|
+
declare function argbTo(out: Float32Array, argb: number): void;
|
|
184
|
+
declare function drawShape(Skia: Skia$1, canvas: SkCanvas, paint: SkPaint, spec: ShapeSpec, x: number, y: number, rot: number): void;
|
|
185
|
+
//#endregion
|
|
194
186
|
export { type AnnulusSpec, type ArcSpec, type BaseSpec, type CircleSpec, type GradientRectSpec, type NgonSpec, type PathSpec, type PolylineSpec, type RectSpec, type RingSpec, type ShapeSpec, type ShipSpec, type SquareSpec, type StarSpec, type TrapezoidSpec, type TriangleSpec, applyFriendlyGlow, applyHazardGlow, argbTo, drawShape, friendlyGlowArgb, hazardGlowArgb, shapeBoundsRadius, singleShapeRadius };
|
|
187
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/bounds.ts","../src/draw.ts"],"mappings":";;;;;;;;;;;;;;;;;;;UAkBiB;WACN;WACA;WACA;;WAEA;WACA;;WAEA;;;;;;;;WAQA;;UAGM,mBAAmB;WACzB;WACA;;UAGM,iBAAiB;WACvB;WACA;WACA;;UAGM,qBAAqB;WAC3B;WACA;;UAGM,iBAAiB;WACvB;WACA;WACA;;UAGM,iBAAiB;WACvB;WACA;WACA;WACA;;UAGM,iBAAiB;WACvB;WACA;;UAGM,qBAAqB;WAC3B;WACA;;UAGM,yBAAyB;WAC/B;WACA;WACA;WACA;WACA;;WAEA;;;;;;;;;;UAWM,gBAAgB;WACtB;WACA;WACA;WACA;;WAEA;;;;;;;;;;UAWM,oBAAoB;WAC1B;WACA;WACA;;WAEA;WACA;;;;;;;UAQM,sBAAsB;WAC5B;WACA;WACA;WACA;;;;;;;;;;UAWM,iBAAiB;WACvB;WACA;;;;;;WAMA;;;UAIM,mBAAmB;WACzB;WACA;;;;;;;;;;UAWM,iBAAiB;WACvB;WACA,MAAM;WACN,kBAAkB;WAClB,QAAQ;;KAGP,YACR,aACA,WACA,eACA,WACA,WACA,WACA,eACA,mBACA,UACA,cACA,gBACA,WACA;;;;;;;;iBClLY,kBAAkB,MAAM;;;;;;iBAqDxB,kBAAkB,gBAAgB;;;KChC7C,gBAAc;;iBAKH;;iBAKA;iBAIA,kBACd,OAAO,QACP,QAAQ,UACR,OAAO,SACP,YACA,YACA;iBAMc,gBACd,OAAO,QACP,QAAQ,UACR,OAAO,SACP,YACA,YACA;iBAYc,OAAO,KAAK,cAAc;iBAsB1B,UACd,MAAM,QACN,QAAQ,UACR,OAAO,SACP,MAAM,WACN,WACA,WACA"}
|