()
| 556 | } |
| 557 | |
| 558 | async function loadPalettes() { |
| 559 | try { |
| 560 | const [pRes, iRes] = await Promise.all([fetch('palette/palettes.json'), fetch('palette/palette-info.json')]); |
| 561 | const palettes = await pRes.json(); |
| 562 | const info = await iRes.json(); |
| 563 | |
| 564 | // Map info and sort: wplace first, then others alphabetically |
| 565 | allPalettes = palettes.map(p => ({ ...p, info: info[p.id] || {} })); |
| 566 | allPalettes.sort((a, b) => { |
| 567 | if (a.id === 'wplace') return -1; |
| 568 | if (b.id === 'wplace') return 1; |
| 569 | return (a.displayName || a.id).localeCompare(b.displayName || b.id); |
| 570 | }); |
| 571 | |
| 572 | // Load bead palettes |
| 573 | try { |
| 574 | const beadPkgRes = await fetch('palette/bead-palettes/package.json'); |
| 575 | if (beadPkgRes.ok) { |
| 576 | const beadPkg = await beadPkgRes.json(); |
| 577 | if (beadPkg.contributes && beadPkg.contributes.palettes) { |
| 578 | const beadPalettes = []; |
| 579 | for (const bp of beadPkg.contributes.palettes) { |
| 580 | try { |
| 581 | const res = await fetch(`palette/bead-palettes/${bp.path.replace('./', '')}`); |
| 582 | if (res.ok) { |
| 583 | const data = await res.json(); |
| 584 | beadPalettes.push({ |
| 585 | id: bp.id, |
| 586 | displayName: bp.id, |
| 587 | colors: data.colors, |
| 588 | meta: data.meta || null, |
| 589 | info: { author: data.meta?.brand || '', description: t('palette.fuseBeadDesc') }, |
| 590 | }); |
| 591 | } |
| 592 | } catch (e) { |
| 593 | console.warn(`Failed to load bead palette: ${bp.id}`, e); |
| 594 | } |
| 595 | } |
| 596 | allPalettes = [...beadPalettes, ...allPalettes]; |
| 597 | } |
| 598 | } |
| 599 | } catch (e) { |
| 600 | console.warn('Failed to load bead palette package', e); |
| 601 | } |
| 602 | |
| 603 | palettesLoaded = true; |
| 604 | } catch (e) { console.error(e); } |
| 605 | loadCustomPalettes(); |
| 606 | } |
| 607 | |
| 608 | loadPalettes(); |
| 609 |
no test coverage detected