iqc-maker 0.0.0-stage → 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.
package/src/themes.js ADDED
@@ -0,0 +1,237 @@
1
+ 'use strict'
2
+
3
+ const { deepMerge, alpha, mix, lighten, darken, isObject } = require('./utils')
4
+
5
+ function buildTheme(def = {}) {
6
+ const mode = def.mode === 'dark' ? 'dark' : 'light'
7
+ const dark = mode === 'dark'
8
+ const accent = def.accent || (dark ? '#0a84ff' : '#3a8ee6')
9
+ const gradient = def.background || (dark ? ['#000000', '#0b0b0c', '#141416'] : ['#f4f5f7', '#e9ebee', '#dfe2e6'])
10
+ const highlight = def.highlight || (dark ? 'rgba(255,255,255,0.05)' : 'rgba(255,255,255,0.9)')
11
+ const blobs = def.blobs ? [...def.blobs] : [lighten(accent, 0.3), lighten(accent, 0.5), accent, darken(accent, 0.15)]
12
+ if (blobs.length < 5) blobs.unshift(highlight)
13
+
14
+ const ink = dark ? '#ffffff' : '#000000'
15
+ const surface = def.surface || (dark ? '#262628' : '#ffffff')
16
+
17
+ const base = {
18
+ name: def.name || 'custom',
19
+ label: def.label || def.name || 'Custom',
20
+ mode,
21
+ category: def.category || 'custom',
22
+ background: { image: null, gradient, blobs },
23
+ statusBar: {
24
+ text: ink,
25
+ inactive: alpha(ink, 0.3),
26
+ battery: {
27
+ body: alpha(ink, 0.035),
28
+ border: alpha(ink, 0.5),
29
+ cap: alpha(ink, 0.45),
30
+ fill: ink,
31
+ low: dark ? '#ff453a' : '#ff3b30',
32
+ charging: dark ? '#30d158' : '#34c759',
33
+ bolt: '#ffffff',
34
+ boltStroke: 'rgba(0,0,0,0.55)',
35
+ },
36
+ },
37
+ pill: {
38
+ bg: dark ? '#2c2c2e' : '#ffffff',
39
+ underlay: def.underlay || (dark ? alpha(accent, 0.35) : mix(accent, '#ffffff', 0.68)),
40
+ shadow: dark ? 'rgba(0,0,0,0.45)' : alpha(accent, 0.28),
41
+ plusBg: dark ? '#3a3a3c' : '#e7e7e9',
42
+ plusIcon: dark ? '#aeaeb2' : '#7b7b80',
43
+ },
44
+ bubble: {
45
+ bg: surface,
46
+ text: ink,
47
+ time: dark ? '#8e8e93' : '#7d7d82',
48
+ shadow: dark ? 'rgba(0,0,0,0.35)' : 'rgba(0,0,0,0.08)',
49
+ mediaTimeBg: 'rgba(0,0,0,0.38)',
50
+ mediaTimeText: '#ffffff',
51
+ },
52
+ reply: {
53
+ bg: dark ? mix(surface, accent, 0.18) : mix(accent, '#ffffff', 0.9),
54
+ bar: accent,
55
+ name: dark ? lighten(accent, 0.25) : darken(accent, 0.08),
56
+ text: dark ? '#b5b5ba' : '#5b5b60',
57
+ },
58
+ menu: {
59
+ shadow: dark ? 'rgba(0,0,0,0.45)' : alpha(darken(accent, 0.5), 0.08),
60
+ overlay: dark ? 'rgba(28,28,30,0.62)' : 'rgba(0,0,0,0)',
61
+ tintTop: alpha(accent, 0.02),
62
+ tintBottom: alpha(accent, dark ? 0.08 : 0.1),
63
+ sheen: dark ? 'rgba(255,255,255,0.05)' : 'rgba(255,255,255,0.30)',
64
+ glow: dark ? 'rgba(255,255,255,0.06)' : 'rgba(255,255,255,1)',
65
+ spec: dark ? 'rgba(255,255,255,0.06)' : 'rgba(255,255,255,0.22)',
66
+ rimTop: dark ? 'rgba(255,255,255,0.18)' : 'rgba(255,255,255,0.7)',
67
+ rimBottom: dark ? 'rgba(255,255,255,0.05)' : 'rgba(255,255,255,0.22)',
68
+ text: ink,
69
+ icon: ink,
70
+ danger: def.danger || (dark ? '#ff453a' : '#c10b27'),
71
+ divider: dark ? 'rgba(255,255,255,0.15)' : 'rgba(0,0,0,0.15)',
72
+ },
73
+ }
74
+ return def.overrides ? deepMerge(base, def.overrides) : base
75
+ }
76
+
77
+ const L = (name, label, background, blobs, accent, extra = {}) =>
78
+ ({ name, label, mode: 'light', background, blobs, accent, ...extra })
79
+ const D = (name, label, background, blobs, accent, extra = {}) =>
80
+ ({ name, label, mode: 'dark', background, blobs, accent, ...extra })
81
+
82
+ const COLORS = [
83
+ L('blue', 'Blue', ['#e8f4fa', '#d4ebf8', '#bfe0f6'], ['#5dade2', '#85c1e9', '#3498db', '#2e86c1'], '#3a8ee6', { underlay: '#b6dff4' }),
84
+ L('pink', 'Pink', ['#fdeef4', '#fadbe8', '#f7c8dc'], ['#f48fb1', '#f8bbd0', '#ec407a', '#d81b60'], '#e84a8a', { underlay: '#f8cfe0' }),
85
+ L('red', 'Red', ['#fdecec', '#fad4d4', '#f6bcbc'], ['#ef5350', '#f28b82', '#e53935', '#c62828'], '#e53935'),
86
+ L('orange', 'Orange', ['#fff3e6', '#ffe2c4', '#ffd1a3'], ['#ffa726', '#ffcc80', '#fb8c00', '#ef6c00'], '#f57c00'),
87
+ L('yellow', 'Yellow', ['#fffbe6', '#fff3c2', '#ffe999'], ['#ffd54f', '#ffe082', '#fbc02d', '#f9a825'], '#d49b00'),
88
+ L('lime', 'Lime', ['#f7fce8', '#ecf8c8', '#e0f3a6'], ['#c0ca33', '#dce775', '#afb42b', '#9e9d24'], '#8fa31e'),
89
+ L('green', 'Green', ['#eaf7ee', '#d3efdc', '#bce6c9'], ['#66bb6a', '#a5d6a7', '#43a047', '#2e7d32'], '#2e9d4f'),
90
+ L('mint', 'Mint', ['#e9fbf5', '#d0f5e8', '#b6eedb'], ['#4dd0a8', '#99e6cd', '#26b88f', '#1a9c78'], '#1fae86'),
91
+ L('teal', 'Teal', ['#e6f6f6', '#ccecec', '#b2e2e2'], ['#26a69a', '#80cbc4', '#00897b', '#00695c'], '#00897b'),
92
+ L('cyan', 'Cyan', ['#e6fbfd', '#c9f3f9', '#abebf4'], ['#26c6da', '#80deea', '#00acc1', '#00838f'], '#00a5bb'),
93
+ L('navy', 'Navy', ['#e9edf6', '#d3dbed', '#bcc8e3'], ['#5c6bc0', '#9fa8da', '#3949ab', '#1a237e'], '#283593'),
94
+ L('indigo', 'Indigo', ['#eeedfb', '#dcdaf6', '#c9c6f1'], ['#7986cb', '#c5cae9', '#5c6bc0', '#3f51b5'], '#4f5bd5'),
95
+ L('purple', 'Purple', ['#f3ecfa', '#e6d6f5', '#d8c0ef'], ['#ab47bc', '#ce93d8', '#8e24aa', '#6a1b9a'], '#8e44ad'),
96
+ L('lavender', 'Lavender', ['#f5f2fd', '#e9e2fa', '#ddd2f7'], ['#9f8fe6', '#c5b8f2', '#7e6bd6', '#6552c4'], '#7461d1'),
97
+ L('magenta', 'Magenta', ['#fceaf8', '#f8d2f0', '#f3bae8'], ['#e040fb', '#ea80fc', '#d500f9', '#aa00ff'], '#c2185b'),
98
+ L('peach', 'Peach', ['#fff1ea', '#ffe0d1', '#ffcfb8'], ['#ffab91', '#ffccbc', '#ff8a65', '#f4511e'], '#f26b4a'),
99
+ L('brown', 'Brown', ['#f6efe9', '#ecdccf', '#e1c9b5'], ['#a1887f', '#bcaaa4', '#8d6e63', '#6d4c41'], '#795548'),
100
+ L('gray', 'Gray', ['#f4f5f7', '#e7e9ec', '#d9dce1'], ['#9aa0a6', '#c4c7cc', '#80868b', '#5f6368'], '#6b7280'),
101
+ L('white', 'White', ['#ffffff', '#f7f7f8', '#efeff1'], ['#e5e5ea', '#f2f2f7', '#d1d1d6', '#c7c7cc'], '#007aff', { underlay: '#e5e5ea' }),
102
+ L('gold', 'Gold', ['#fbf6e6', '#f4e8c1', '#ecd99a'], ['#d4af37', '#e6c866', '#c19b2e', '#a67c00'], '#b8860b'),
103
+ L('silver', 'Silver', ['#f6f7f9', '#e8ebef', '#dadee4'], ['#b0b8c1', '#d0d5db', '#909aa5', '#717c88'], '#7b8794'),
104
+ L('rosegold', 'Rose Gold', ['#fcefee', '#f6dcd8', '#efc8c1'], ['#e0a899', '#ecc4b9', '#c98b7a', '#b76e5d'], '#b76e79'),
105
+ ]
106
+
107
+ const MONO_DARK = [
108
+ D('black', 'Black', ['#000000', '#0a0a0a', '#121212'], ['#1c1c1e', '#2c2c2e', '#1c1c1e', '#2c2c2e'], '#a1a1a6', { surface: '#1f1f21' }),
109
+ D('dark', 'Dark (iOS)', ['#0b0b0c', '#111113', '#18181b'], ['#1d2a3a', '#232326', '#16324f', '#1c1c1e'], '#0a84ff'),
110
+ D('amoled', 'AMOLED', ['#000000', '#000000', '#000000'], ['#000000', '#000000', '#000000', '#000000'], '#8e8e93', {
111
+ highlight: 'rgba(0,0,0,0)', surface: '#161618', underlay: 'rgba(255,255,255,0.08)',
112
+ }),
113
+ D('graphite', 'Graphite', ['#1a1b1e', '#202125', '#26282c'], ['#3a3c42', '#2f3136', '#45484f', '#33363b'], '#9aa0a6'),
114
+ D('onyx', 'Onyx', ['#050505', '#0d0d0f', '#151518'], ['#2a2a2e', '#1e1e22', '#38383d', '#242428'], '#c7c7cc'),
115
+ ]
116
+
117
+ const EARTH = [
118
+ L('ocean', 'Ocean', ['#e3f4fb', '#c8e8f5', '#a9daf0'], ['#1e88e5', '#4fc3f7', '#0277bd', '#01579b'], '#0277bd', { category: 'earth' }),
119
+ L('sky', 'Sky', ['#f0f8ff', '#dcefff', '#c6e5ff'], ['#90caf9', '#bbdefb', '#64b5f6', '#42a5f5'], '#2196f3', { category: 'earth' }),
120
+ L('sunrise', 'Sunrise', ['#fff6e8', '#ffe6cc', '#ffd6e0'], ['#ffb74d', '#ffe0b2', '#f48fb1', '#ff8a65'], '#f57c4b', { category: 'earth' }),
121
+ L('sunset', 'Sunset', ['#fff0e6', '#ffd9cc', '#f3c6e0'], ['#ff7043', '#ffab91', '#ec407a', '#8e24aa'], '#e8505b', { category: 'earth' }),
122
+ L('beach', 'Beach', ['#fdf8ec', '#f5ecd2', '#d7f0f4'], ['#4dd0e1', '#f3e0a8', '#26c6da', '#e6c27a'], '#00a0b0', { category: 'earth' }),
123
+ L('coral', 'Coral Reef', ['#fff0ee', '#ffdcd6', '#d9f4f2'], ['#ff7f6e', '#ffb3a7', '#26a69a', '#ff5a47'], '#f2604e', { category: 'earth' }),
124
+ L('lagoon', 'Lagoon', ['#e6faf8', '#c7f2ee', '#a6e9e3'], ['#1de9b6', '#64ffda', '#00bfa5', '#00897b'], '#00a99d', { category: 'earth' }),
125
+ L('glacier', 'Glacier', ['#f2fbff', '#e1f5fe', '#cdeefd'], ['#b3e5fc', '#e1f5fe', '#81d4fa', '#4fc3f7'], '#2aa7d9', { category: 'earth' }),
126
+ L('arctic', 'Arctic', ['#f7fbfd', '#ebf3f8', '#dde9f1'], ['#cfd8dc', '#eceff1', '#b0bec5', '#90a4ae'], '#5d8aa8', { category: 'earth' }),
127
+ L('forest', 'Forest', ['#ecf5ec', '#d6e9d4', '#bfdcbc'], ['#558b2f', '#9ccc65', '#33691e', '#1b5e20'], '#2e7d32', { category: 'earth' }),
128
+ L('jungle', 'Jungle', ['#eef8e8', '#d8efcc', '#c0e6ae'], ['#7cb342', '#aed581', '#388e3c', '#00695c'], '#3b8c3a', { category: 'earth' }),
129
+ L('moss', 'Moss', ['#f2f5e9', '#e3eacf', '#d3dfb4'], ['#8a9a5b', '#b5c27f', '#6b7d3a', '#556b2f'], '#5f7a2f', { category: 'earth' }),
130
+ L('matcha', 'Matcha', ['#f3f8ea', '#e4efcf', '#d4e6b3'], ['#9bbf5a', '#c5dc94', '#7ea843', '#5e8a2a'], '#6c9a35', { category: 'earth' }),
131
+ L('meadow', 'Meadow', ['#f4fbe9', '#e5f5cd', '#fff3c2'], ['#9ccc65', '#fff176', '#7cb342', '#ffd54f'], '#689f38', { category: 'earth' }),
132
+ L('spring', 'Spring', ['#f6fcef', '#fce4ec', '#e8f5e9'], ['#a5d6a7', '#f8bbd0', '#81c784', '#f48fb1'], '#43a047', { category: 'earth' }),
133
+ L('sakura', 'Sakura', ['#fff4f7', '#ffe4ec', '#ffd3e0'], ['#f8a5c2', '#ffd1dc', '#f78fb3', '#e66a92'], '#e05a87', { category: 'earth' }),
134
+ L('lavenderfield', 'Lavender Field', ['#f6f2fc', '#e7ddf7', '#eef3e2'], ['#b39ddb', '#d1c4e9', '#9575cd', '#9ccc65'], '#7e57c2', { category: 'earth' }),
135
+ L('sunflower', 'Sunflower', ['#fffbe3', '#fff1b8', '#ffe68c'], ['#ffca28', '#ffe57f', '#ffb300', '#8d6e63'], '#e09b00', { category: 'earth' }),
136
+ L('autumn', 'Autumn', ['#fdf3e7', '#f8e0c4', '#f2cba0'], ['#e67e22', '#f0b27a', '#c0392b', '#a04000'], '#c4561b', { category: 'earth' }),
137
+ L('desert', 'Desert', ['#fbf4e8', '#f3e3c7', '#eacfa3'], ['#d7a86e', '#ecd2a6', '#c18f4f', '#a0703a'], '#b07a3b', { category: 'earth' }),
138
+ L('savanna', 'Savanna', ['#fbf6e3', '#f2e6bd', '#e8d597'], ['#d4b04a', '#e9d48a', '#b8913a', '#8d6e2f'], '#a8862b', { category: 'earth' }),
139
+ L('canyon', 'Canyon', ['#fbeee6', '#f3d6c3', '#eabd9f'], ['#d35400', '#e59866', '#a04000', '#7e3b1c'], '#b5501f', { category: 'earth' }),
140
+ L('earth', 'Earth', ['#f5f0e8', '#e6dccb', '#dde6d0'], ['#8d6e63', '#a5d6a7', '#6d4c41', '#558b2f'], '#6d5a3f', { category: 'earth' }),
141
+ L('clay', 'Clay', ['#f9efea', '#efdbd0', '#e4c6b6'], ['#c97b5a', '#e0ab92', '#b0613e', '#8f4a2c'], '#a65a3a', { category: 'earth' }),
142
+ L('stone', 'Stone', ['#f3f2ef', '#e4e2dd', '#d5d2cb'], ['#a8a29e', '#d6d3d1', '#8c8580', '#6f6964'], '#78716c', { category: 'earth' }),
143
+ L('mocha', 'Mocha', ['#f5eee8', '#e7d8cc', '#d9c2b0'], ['#a47551', '#c9a789', '#8b5e3c', '#6f4a2f'], '#7b5236', { category: 'earth' }),
144
+ L('cherry', 'Cherry', ['#fdebef', '#f9d0d9', '#f4b5c3'], ['#d81b60', '#f06292', '#ad1457', '#880e4f'], '#c2185b', { category: 'earth' }),
145
+ L('grape', 'Grape', ['#f4ebf7', '#e6d2ee', '#d8b9e5'], ['#8e44ad', '#bb8fce', '#6c3483', '#512e5f'], '#7d3c98', { category: 'earth' }),
146
+ L('lemon', 'Lemon', ['#fffde8', '#fff9c4', '#fff59d'], ['#fff176', '#fff9c4', '#ffee58', '#c0ca33'], '#b5a600', { category: 'earth' }),
147
+ L('rainbow', 'Rainbow', ['#fff0f0', '#f0f7ff', '#f3fff0'], ['#ff8a80', '#ffd180', '#80d8ff', '#b388ff'], '#7c4dff', { category: 'earth' }),
148
+ D('aurora', 'Aurora', ['#04121a', '#071d26', '#0b1830'], ['#00e5a0', '#2979ff', '#7c4dff', '#00bfa5'], '#1de9b6', { category: 'earth' }),
149
+ D('galaxy', 'Galaxy', ['#0a0614', '#120a24', '#1a0e33'], ['#7c4dff', '#e040fb', '#3d5afe', '#651fff'], '#b388ff', { category: 'earth' }),
150
+ D('midnight', 'Midnight', ['#050a18', '#0a1228', '#0e1a38'], ['#1a237e', '#283593', '#0d47a1', '#1a2a6c'], '#5c8dff', { category: 'earth' }),
151
+ D('twilight', 'Twilight', ['#120d24', '#1c1436', '#2a1b46'], ['#5e35b1', '#ec407a', '#3949ab', '#8e24aa'], '#b388ff', { category: 'earth' }),
152
+ D('volcano', 'Volcano', ['#120605', '#1c0a07', '#26100a'], ['#ff3d00', '#ff6e40', '#dd2c00', '#bf360c'], '#ff6e40', { category: 'earth' }),
153
+ D('deepsea', 'Deep Sea', ['#020d16', '#041a2a', '#06253b'], ['#006064', '#00838f', '#01579b', '#004d40'], '#26c6da', { category: 'earth' }),
154
+ D('nightforest', 'Night Forest', ['#06110a', '#0a1a10', '#0f2416'], ['#1b5e20', '#2e7d32', '#004d40', '#33691e'], '#66bb6a', { category: 'earth' }),
155
+ D('storm', 'Storm', ['#0d1014', '#141a20', '#1b232b'], ['#37474f', '#546e7a', '#263238', '#455a64'], '#90a4ae', { category: 'earth' }),
156
+ D('eclipse', 'Eclipse', ['#000000', '#0b0704', '#140c06'], ['#ff9100', '#3e2723', '#ff6d00', '#1a1a1a'], '#ffab40', { category: 'earth' }),
157
+ D('nebula', 'Nebula', ['#0d0718', '#170b26', '#200f34'], ['#ff4081', '#7c4dff', '#f50057', '#536dfe'], '#ff80ab', { category: 'earth' }),
158
+ ]
159
+
160
+ function darkVariant(def) {
161
+ const a = def.accent
162
+ return {
163
+ name: 'dark-' + def.name,
164
+ label: 'Dark ' + def.label,
165
+ mode: 'dark',
166
+ category: 'colors-dark',
167
+ accent: lighten(a, 0.12),
168
+ background: [mix(a, '#000000', 0.94), mix(a, '#000000', 0.9), mix(a, '#000000', 0.85)],
169
+ blobs: def.blobs.map(c => alpha(c, 0.32)),
170
+ surface: mix(a, '#1c1c1e', 0.9),
171
+ }
172
+ }
173
+
174
+ const DEFINITIONS = [
175
+ ...COLORS.map(d => ({ ...d, category: 'colors' })),
176
+ ...COLORS.filter(d => !['white', 'gray', 'silver'].includes(d.name)).map(darkVariant),
177
+ ...MONO_DARK.map(d => ({ ...d, category: 'dark' })),
178
+ ...EARTH,
179
+ ]
180
+
181
+ const THEMES = new Map(DEFINITIONS.map(d => [d.name, buildTheme(d)]))
182
+
183
+ const ALIASES = new Map(Object.entries({
184
+ biru: 'blue', 'biru-tua': 'navy', 'biru-muda': 'sky', merah: 'red', jingga: 'orange', oren: 'orange', oranye: 'orange',
185
+ kuning: 'yellow', hijau: 'green', 'hijau-muda': 'mint', tosca: 'teal', toska: 'teal', ungu: 'purple', lembayung: 'lavender',
186
+ 'merah-muda': 'pink', coklat: 'brown', cokelat: 'brown', abu: 'gray', 'abu-abu': 'gray', grey: 'gray', putih: 'white',
187
+ hitam: 'black', item: 'black', gelap: 'dark', emas: 'gold', perak: 'silver', laut: 'ocean', langit: 'sky', pantai: 'beach',
188
+ hutan: 'forest', gurun: 'desert', gunung: 'volcano', senja: 'sunset', fajar: 'sunrise', malam: 'midnight', galaksi: 'galaxy',
189
+ default: 'blue', light: 'white', ios: 'dark', violet: 'purple', rose: 'rosegold',
190
+ }))
191
+
192
+ const normalize = name => String(name || '').trim().toLowerCase().replace(/[\s_]+/g, '-')
193
+
194
+ function resolveName(name) {
195
+ const n = normalize(name)
196
+ if (THEMES.has(n)) return n
197
+ if (ALIASES.has(n)) return ALIASES.get(n)
198
+ const m = n.match(/^(?:dark|gelap)-(.+)$/) || n.match(/^(.+)-(?:dark|gelap)$/)
199
+ if (m) {
200
+ const inner = ALIASES.get(m[1]) || m[1]
201
+ if (THEMES.has('dark-' + inner)) return 'dark-' + inner
202
+ }
203
+ return null
204
+ }
205
+
206
+ function getTheme(theme, overrides) {
207
+ let base
208
+ if (isObject(theme)) {
209
+ base = theme.background && Array.isArray(theme.background) ? buildTheme(theme) : deepMerge(THEMES.get('blue'), theme)
210
+ } else {
211
+ const key = resolveName(theme || 'blue')
212
+ if (!key) throw new RangeError(`[iqc-maker] Tema "${theme}" tidak ditemukan. Lihat listThemes().`)
213
+ base = THEMES.get(key)
214
+ }
215
+ return overrides ? deepMerge(base, overrides) : deepMerge(base)
216
+ }
217
+
218
+ function registerTheme(name, theme) {
219
+ const key = normalize(name)
220
+ if (!key) throw new TypeError('[iqc-maker] Nama tema wajib diisi')
221
+ const built = isObject(theme) && Array.isArray(theme.background) ? buildTheme({ ...theme, name: key }) : deepMerge(getTheme(theme?.extends || 'blue'), theme, { name: key })
222
+ delete built.extends
223
+ THEMES.set(key, built)
224
+ return built
225
+ }
226
+
227
+ function createTheme(base, overrides) {
228
+ return getTheme(base, overrides)
229
+ }
230
+
231
+ function listThemes(filter) {
232
+ const all = [...THEMES.values()].map(t => ({ name: t.name, label: t.label, mode: t.mode, category: t.category }))
233
+ if (!filter) return all
234
+ return all.filter(t => t.category === filter || t.mode === filter)
235
+ }
236
+
237
+ module.exports = { buildTheme, getTheme, createTheme, registerTheme, listThemes, resolveName, THEMES, ALIASES }
package/src/utils.js ADDED
@@ -0,0 +1,60 @@
1
+ 'use strict'
2
+
3
+ const isObject = v => v !== null && typeof v === 'object' && !Array.isArray(v) && !Buffer.isBuffer(v)
4
+
5
+ function deepMerge(target, ...sources) {
6
+ const out = isObject(target) ? { ...target } : {}
7
+ for (const src of sources) {
8
+ if (!isObject(src)) continue
9
+ for (const [k, v] of Object.entries(src)) {
10
+ if (v === undefined) continue
11
+ out[k] = isObject(v) && isObject(out[k]) ? deepMerge(out[k], v) : Array.isArray(v) ? [...v] : v
12
+ }
13
+ }
14
+ return out
15
+ }
16
+
17
+ function parseColor(input) {
18
+ const s = String(input).trim().toLowerCase()
19
+ if (s.startsWith('#')) {
20
+ let h = s.slice(1)
21
+ if (h.length === 3 || h.length === 4) h = [...h].map(c => c + c).join('')
22
+ const n = parseInt(h.slice(0, 6), 16)
23
+ const a = h.length === 8 ? parseInt(h.slice(6, 8), 16) / 255 : 1
24
+ return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255, a }
25
+ }
26
+ const m = s.match(/^rgba?\(([^)]+)\)$/)
27
+ if (m) {
28
+ const [r, g, b, a = 1] = m[1].split(/[\s,/]+/).filter(Boolean).map(Number)
29
+ return { r, g, b, a }
30
+ }
31
+ throw new TypeError(`[iqc-maker] Warna tidak valid: ${input}`)
32
+ }
33
+
34
+ const clamp = (v, min, max) => Math.min(max, Math.max(min, v))
35
+ const hex2 = v => Math.round(clamp(v, 0, 255)).toString(16).padStart(2, '0')
36
+
37
+ function toHex({ r, g, b }) {
38
+ return `#${hex2(r)}${hex2(g)}${hex2(b)}`
39
+ }
40
+
41
+ function alpha(color, a) {
42
+ const c = parseColor(color)
43
+ return `rgba(${c.r},${c.g},${c.b},${+(clamp(a, 0, 1) * c.a).toFixed(3)})`
44
+ }
45
+
46
+ function mix(a, b, t) {
47
+ const x = parseColor(a), y = parseColor(b)
48
+ return toHex({ r: x.r + (y.r - x.r) * t, g: x.g + (y.g - x.g) * t, b: x.b + (y.b - x.b) * t })
49
+ }
50
+
51
+ const lighten = (c, t) => mix(c, '#ffffff', t)
52
+ const darken = (c, t) => mix(c, '#000000', t)
53
+
54
+ function luminance(color) {
55
+ const { r, g, b } = parseColor(color)
56
+ const f = v => { v /= 255; return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4 }
57
+ return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b)
58
+ }
59
+
60
+ module.exports = { isObject, deepMerge, parseColor, toHex, alpha, mix, lighten, darken, luminance, clamp }