fireworks-engine 1.0.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.
@@ -0,0 +1,160 @@
1
+ import { resolveSizeScale, resolveTimeScale } from './mathResolvers.js';
2
+
3
+ export function isPlainRecord(value) {
4
+ return !!value && typeof value === 'object' && !Array.isArray(value);
5
+ }
6
+
7
+ export function normalizeGroupedPublicOptions(options = {}) {
8
+ if (!isPlainRecord(options)) {
9
+ return {};
10
+ }
11
+
12
+ const canvas = isPlainRecord(options.canvas) ? options.canvas : {};
13
+ const runtime = isPlainRecord(options.runtime) ? options.runtime : {};
14
+ const performance = isPlainRecord(options.performance) ? options.performance : {};
15
+ const rocket = isPlainRecord(options.rocket) ? options.rocket : {};
16
+ const rocketTailEmbers = isPlainRecord(options.rocketTailEmbers) ? options.rocketTailEmbers : {};
17
+ const burstForms = isPlainRecord(options.burstForms) ? options.burstForms : {};
18
+ const burstSparks = isPlainRecord(options.burstSparks) ? options.burstSparks : {};
19
+ const burstCenterFlash = isPlainRecord(options.burstCenterFlash) ? options.burstCenterFlash : {};
20
+ const burstTwinkleCloud = isPlainRecord(options.burstTwinkleCloud) ? options.burstTwinkleCloud : {};
21
+
22
+ const sizeScale = resolveSizeScale(options.sizeScale, 1);
23
+ const timeScale = resolveTimeScale(options.timeScale, 1);
24
+ const simple = options.simple === true;
25
+
26
+ return {
27
+ mode: options.mode,
28
+ bursts: options.bursts,
29
+ duration: options.duration,
30
+ rocketCount: options.rocketCount,
31
+ rocketDelay: options.rocketDelay,
32
+ totalDuration: options.totalDuration,
33
+ timeScale,
34
+ sizeScale,
35
+ simple,
36
+ onStart: options.onStart,
37
+ onStop: options.onStop,
38
+ onFinish: options.onFinish,
39
+ canvas: { ...canvas },
40
+ runtime: { ...runtime },
41
+ performance: { ...performance },
42
+ rocket: { ...rocket },
43
+ rocketTailEmbers: { ...rocketTailEmbers },
44
+ burstForms: { ...burstForms },
45
+ burstSparks: { ...burstSparks },
46
+ burstCenterFlash: { ...burstCenterFlash },
47
+ burstTwinkleCloud: { ...burstTwinkleCloud },
48
+ };
49
+ }
50
+
51
+ export function resolveBurstEntityToggle(value) {
52
+ return typeof value === 'boolean' ? value : null;
53
+ }
54
+
55
+ const BURST_FORM_SINGLE_SHAPES = ['circle', 'square', 'rectangle', 'glyph'];
56
+ const BURST_FORM_MIX_SHAPES = ['circle', 'square', 'rectangle'];
57
+
58
+ function appendUnique(list, value) {
59
+ if (!list.includes(value)) {
60
+ list.push(value);
61
+ }
62
+ }
63
+
64
+ function resolveBurstFormShapeTokenSet(shape) {
65
+ if (typeof shape !== 'string') {
66
+ return [];
67
+ }
68
+
69
+ const trimmed = shape.trim();
70
+ if (!trimmed) {
71
+ return [];
72
+ }
73
+
74
+ if (trimmed === 'mix') {
75
+ return [...BURST_FORM_MIX_SHAPES];
76
+ }
77
+
78
+ const resolved = [];
79
+ const tokens = trimmed.split('|');
80
+
81
+ for (let index = 0; index < tokens.length; index += 1) {
82
+ const token = tokens[index].trim();
83
+ if (!token) {
84
+ continue;
85
+ }
86
+
87
+ if (token === 'mix') {
88
+ for (let mixIndex = 0; mixIndex < BURST_FORM_MIX_SHAPES.length; mixIndex += 1) {
89
+ appendUnique(resolved, BURST_FORM_MIX_SHAPES[mixIndex]);
90
+ }
91
+ continue;
92
+ }
93
+
94
+ if (BURST_FORM_SINGLE_SHAPES.includes(token)) {
95
+ appendUnique(resolved, token);
96
+ }
97
+ }
98
+
99
+ return resolved;
100
+ }
101
+
102
+ export function resolveBurstFormShape(value) {
103
+ if (typeof value === 'string') {
104
+ const trimmed = value.trim();
105
+ if (trimmed === 'mix' || BURST_FORM_SINGLE_SHAPES.includes(trimmed)) {
106
+ return trimmed;
107
+ }
108
+
109
+ const resolvedSet = resolveBurstFormShapeTokenSet(trimmed);
110
+ if (resolvedSet.length > 0) {
111
+ return resolvedSet.join('|');
112
+ }
113
+ }
114
+
115
+ return 'circle';
116
+ }
117
+
118
+ export function resolveBurstFormShapeSet(shape) {
119
+ const resolvedSet = resolveBurstFormShapeTokenSet(shape);
120
+ return resolvedSet.length > 0 ? resolvedSet : ['circle'];
121
+ }
122
+
123
+ const BURST_FORM_GLYPH_LIMIT = 8;
124
+
125
+ export function normalizeBurstFormGlyph(glyph, fallback = '★') {
126
+ if (typeof glyph !== 'string') {
127
+ return fallback;
128
+ }
129
+
130
+ const trimmed = glyph.trim();
131
+ if (!trimmed) {
132
+ return fallback;
133
+ }
134
+
135
+ const normalized = Array.from(trimmed).slice(0, BURST_FORM_GLYPH_LIMIT).join('');
136
+ return normalized || fallback;
137
+ }
138
+
139
+ export function resolveBurstColorMode(value) {
140
+ if (value === 'rgb' || value === 'single') {
141
+ return value;
142
+ }
143
+ return 'palette';
144
+ }
145
+
146
+ export function resolveBurstFlashColorMode(value) {
147
+ if (value === 'palette' || value === 'rgb' || value === 'single') {
148
+ return value;
149
+ }
150
+
151
+ return 'single';
152
+ }
153
+
154
+ export function resolveBurstSparkShape(value) {
155
+ if (value === 'spindle' || value === 'fade') {
156
+ return value;
157
+ }
158
+
159
+ return 'uniform';
160
+ }