@flare-engine/shapes 0.2.1 → 0.3.1
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/LICENSE
CHANGED
|
@@ -1,21 +1,201 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Grzegorz Otto
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ Procedural 2D shape primitives for [react-native-skia](https://shopify.github.io
|
|
|
4
4
|
|
|
5
5
|
## Why
|
|
6
6
|
|
|
7
|
-
Mobile and indie game prototypes don't need sprite sheets to start. Compose ships, enemies, pickups, and UI shapes from primitives, ship a playable build, and replace shapes with art only after the mechanics lock — exactly the workflow Unity Shapes2D and Defold prototyping threads document.
|
|
7
|
+
Mobile and indie game prototypes don't need sprite sheets to start. Compose ships, enemies, pickups, and UI shapes from primitives, ship a playable build, and replace shapes with art only after the mechanics lock — exactly the workflow Unity Shapes2D and Defold prototyping threads document. Shape-first prototyping keeps the iteration loop tight: a project can reach a playable state immediately and swap in sprite art only after mechanics lock.
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
@@ -12,23 +12,32 @@ Mobile and indie game prototypes don't need sprite sheets to start. Compose ship
|
|
|
12
12
|
bun add @flare-engine/shapes @shopify/react-native-skia
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
`@shopify/react-native-skia` is an **optional, type-only peer** — `src/draw.ts` imports it via `import type` only (for the injected `Skia` / `canvas` / `paint` handles), so it never enters the runtime bundle. Skip it entirely on web/CanvasKit; add it only where you actually render on native Skia.
|
|
16
|
+
|
|
15
17
|
## Usage
|
|
16
18
|
|
|
17
19
|
```ts
|
|
20
|
+
import type { Skia as SkiaModule, SkCanvas, SkPaint } from '@shopify/react-native-skia';
|
|
18
21
|
import { drawShape, type ShapeSpec } from '@flare-engine/shapes';
|
|
19
22
|
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
kind: '
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
// `Skia` from react-native-skia is a value; the handle type is `typeof Skia`
|
|
24
|
+
// (mirrors `type Skia = typeof SkiaModule` inside src/draw.ts).
|
|
25
|
+
type Skia = typeof SkiaModule;
|
|
26
|
+
|
|
27
|
+
function demo(skia: Skia, canvas: SkCanvas, paint: SkPaint): void {
|
|
28
|
+
// Compose any entity from primitives.
|
|
29
|
+
const shape: ShapeSpec = { kind: 'circle', r: 24, fill: 0xff8844cc };
|
|
30
|
+
drawShape(skia, canvas, paint, shape, /* x */ 100, /* y */ 200, /* rot */ 0);
|
|
31
|
+
|
|
32
|
+
// Need a custom shape? Use the SVG escape hatch:
|
|
33
|
+
const star: ShapeSpec = {
|
|
34
|
+
kind: 'path',
|
|
35
|
+
d: 'M 128 0 L 168 80 L 256 93 L 192 155 L 207 244 L 128 202 L 49 244 L 64 155 L 0 93 L 88 80 Z',
|
|
36
|
+
boundsR: 256,
|
|
37
|
+
fill: 0xffc9a24a,
|
|
38
|
+
};
|
|
39
|
+
drawShape(skia, canvas, paint, star, 0, 0, 0);
|
|
40
|
+
}
|
|
32
41
|
```
|
|
33
42
|
|
|
34
43
|
## Primitives
|
|
@@ -77,7 +86,9 @@ const amulet: readonly ShapeSpec[] = [
|
|
|
77
86
|
## Bounds
|
|
78
87
|
|
|
79
88
|
```ts
|
|
80
|
-
import { shapeBoundsRadius, singleShapeRadius } from '@flare-engine/shapes';
|
|
89
|
+
import { shapeBoundsRadius, singleShapeRadius, type ShapeSpec } from '@flare-engine/shapes';
|
|
90
|
+
|
|
91
|
+
declare const playerShip: ShapeSpec;
|
|
81
92
|
|
|
82
93
|
// For atlas tile sizing — max half-extent across a composition.
|
|
83
94
|
const tileRadius = shapeBoundsRadius([playerShip]);
|
|
@@ -101,7 +112,9 @@ Three ways, in order of friction:
|
|
|
101
112
|
3. Add a bounds branch in `singleShapeRadius` (`src/bounds.ts`)
|
|
102
113
|
4. Add tests in `tests/draw.test.ts` and `tests/bounds.test.ts`
|
|
103
114
|
|
|
104
|
-
Tsc
|
|
115
|
+
Tsc catches a missing step 3: `singleShapeRadius` returns `number`, so an unhandled kind fails to
|
|
116
|
+
compile. It does **not** catch a missing step 2 — `drawShape` returns `void` and its switch has no
|
|
117
|
+
`default`, so a new kind without a draw branch compiles and silently draws nothing.
|
|
105
118
|
|
|
106
119
|
## Glow tags
|
|
107
120
|
|
|
@@ -114,4 +127,4 @@ Two visual halos for free, set `glow: 'friendly' | 'hazard'` on any primitive:
|
|
|
114
127
|
|
|
115
128
|
## License
|
|
116
129
|
|
|
117
|
-
|
|
130
|
+
Apache-2.0
|
package/dist/index.d.mts
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.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","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"}
|