@autumnsgrove/groveengine 0.8.6 → 0.9.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/dist/components/admin/GutterManager.svelte +213 -101
- package/dist/components/admin/MarkdownEditor.svelte +6 -3
- package/dist/components/custom/GutterItem.svelte +8 -2
- package/dist/components/quota/UpgradePrompt.svelte +1 -0
- package/dist/config/domain-blocklist.d.ts +59 -0
- package/dist/config/domain-blocklist.js +731 -0
- package/dist/config/index.d.ts +3 -1
- package/dist/config/index.js +2 -1
- package/dist/config/offensive-blocklist.d.ts +44 -0
- package/dist/config/offensive-blocklist.js +751 -0
- package/dist/config/terrarium.d.ts +109 -0
- package/dist/config/terrarium.js +125 -0
- package/dist/styles/tokens.css +90 -0
- package/dist/types/dom-to-image-more.d.ts +39 -0
- package/dist/ui/components/chrome/Footer.svelte +137 -0
- package/dist/ui/components/chrome/Footer.svelte.d.ts +11 -0
- package/dist/ui/components/chrome/FooterMinimal.svelte +75 -0
- package/dist/ui/components/chrome/FooterMinimal.svelte.d.ts +10 -0
- package/dist/ui/components/chrome/Header.svelte +113 -0
- package/dist/ui/components/chrome/Header.svelte.d.ts +11 -0
- package/dist/ui/components/chrome/HeaderMinimal.svelte +68 -0
- package/dist/ui/components/chrome/HeaderMinimal.svelte.d.ts +9 -0
- package/dist/ui/components/chrome/MobileMenu.svelte +145 -0
- package/dist/ui/components/chrome/MobileMenu.svelte.d.ts +9 -0
- package/dist/ui/components/chrome/ThemeToggle.svelte +34 -0
- package/dist/ui/components/chrome/ThemeToggle.svelte.d.ts +3 -0
- package/dist/ui/components/chrome/defaults.d.ts +6 -0
- package/dist/ui/components/chrome/defaults.js +65 -0
- package/dist/ui/components/chrome/index.d.ts +13 -0
- package/dist/ui/components/chrome/index.js +14 -0
- package/dist/ui/components/chrome/types.d.ts +19 -0
- package/dist/ui/components/chrome/types.js +8 -0
- package/dist/ui/components/content/RoadmapPreview.svelte +2 -1
- package/dist/ui/components/forms/ContentSearch.svelte +406 -0
- package/dist/ui/components/forms/ContentSearch.svelte.d.ts +71 -0
- package/dist/ui/components/forms/filterUtils.d.ts +138 -0
- package/dist/ui/components/forms/filterUtils.js +240 -0
- package/dist/ui/components/forms/index.d.ts +2 -0
- package/dist/ui/components/forms/index.js +5 -1
- package/dist/ui/components/gallery/ImageGallery.svelte +3 -0
- package/dist/ui/components/gallery/Lightbox.svelte +3 -0
- package/dist/ui/components/gallery/ZoomableImage.svelte +1 -0
- package/dist/ui/components/icons/index.d.ts +2 -1
- package/dist/ui/components/icons/index.js +14 -3
- package/dist/ui/components/icons/lucide.d.ts +213 -0
- package/dist/ui/components/icons/lucide.js +224 -0
- package/dist/ui/components/terrarium/AssetPalette.svelte +207 -0
- package/dist/ui/components/terrarium/AssetPalette.svelte.d.ts +7 -0
- package/dist/ui/components/terrarium/Canvas.svelte +231 -0
- package/dist/ui/components/terrarium/Canvas.svelte.d.ts +14 -0
- package/dist/ui/components/terrarium/ExportDialog.svelte +307 -0
- package/dist/ui/components/terrarium/ExportDialog.svelte.d.ts +18 -0
- package/dist/ui/components/terrarium/PaletteItem.svelte +169 -0
- package/dist/ui/components/terrarium/PaletteItem.svelte.d.ts +9 -0
- package/dist/ui/components/terrarium/PlacedAsset.svelte +222 -0
- package/dist/ui/components/terrarium/PlacedAsset.svelte.d.ts +11 -0
- package/dist/ui/components/terrarium/Terrarium.svelte +266 -0
- package/dist/ui/components/terrarium/Terrarium.svelte.d.ts +3 -0
- package/dist/ui/components/terrarium/Toolbar.svelte +299 -0
- package/dist/ui/components/terrarium/Toolbar.svelte.d.ts +24 -0
- package/dist/ui/components/terrarium/index.d.ts +31 -0
- package/dist/ui/components/terrarium/index.js +33 -0
- package/dist/ui/components/terrarium/terrariumState.svelte.d.ts +45 -0
- package/dist/ui/components/terrarium/terrariumState.svelte.js +291 -0
- package/dist/ui/components/terrarium/types.d.ts +139 -0
- package/dist/ui/components/terrarium/types.js +43 -0
- package/dist/ui/components/terrarium/utils/export.d.ts +48 -0
- package/dist/ui/components/terrarium/utils/export.js +148 -0
- package/dist/ui/components/ui/CollapsibleSection.svelte +2 -0
- package/dist/ui/components/ui/GlassConfirmDialog.svelte +9 -0
- package/dist/ui/components/ui/GlassOverlay.svelte +2 -1
- package/dist/ui/components/ui/Input.svelte +9 -1
- package/dist/ui/components/ui/Input.svelte.d.ts +2 -0
- package/dist/ui/components/ui/Textarea.svelte +9 -1
- package/dist/ui/components/ui/Textarea.svelte.d.ts +2 -0
- package/dist/ui/stores/index.d.ts +6 -0
- package/dist/ui/stores/index.js +6 -0
- package/dist/ui/stores/season.d.ts +14 -0
- package/dist/ui/stores/season.js +65 -0
- package/package.json +27 -4
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Grove — A place to Be
|
|
3
|
+
Copyright (c) 2025 Autumn Brown
|
|
4
|
+
Licensed under AGPL-3.0
|
|
5
|
+
-->
|
|
6
|
+
<script lang="ts">
|
|
7
|
+
import type { PlacedAsset, Point } from './types';
|
|
8
|
+
import type { Component as SvelteComponent } from 'svelte';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
asset: PlacedAsset;
|
|
12
|
+
isSelected?: boolean;
|
|
13
|
+
animationsEnabled?: boolean;
|
|
14
|
+
onSelect?: () => void;
|
|
15
|
+
onMove?: (position: Point) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let {
|
|
19
|
+
asset,
|
|
20
|
+
isSelected = false,
|
|
21
|
+
animationsEnabled = true,
|
|
22
|
+
onSelect,
|
|
23
|
+
onMove
|
|
24
|
+
}: Props = $props();
|
|
25
|
+
|
|
26
|
+
let component: SvelteComponent | null = $state(null);
|
|
27
|
+
let containerElement: HTMLDivElement | null = $state(null);
|
|
28
|
+
let isDragging = $state(false);
|
|
29
|
+
let dragStart: Point = $state({ x: 0, y: 0 });
|
|
30
|
+
let positionStart: Point = $state({ x: 0, y: 0 });
|
|
31
|
+
|
|
32
|
+
// Dynamically import the nature component
|
|
33
|
+
$effect(() => {
|
|
34
|
+
const loadComponent = async () => {
|
|
35
|
+
try {
|
|
36
|
+
// Map component name to path
|
|
37
|
+
const category = asset.category;
|
|
38
|
+
const componentPath = `/src/lib/ui/components/nature/${category}/${asset.componentName}.svelte`;
|
|
39
|
+
|
|
40
|
+
// Dynamic import - this will work with Vite's glob imports
|
|
41
|
+
const modules = import.meta.glob('/src/lib/ui/components/nature/**/*.svelte');
|
|
42
|
+
const loader = modules[componentPath];
|
|
43
|
+
|
|
44
|
+
if (!loader) {
|
|
45
|
+
console.error(`Component not found: ${componentPath}`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const module = await loader() as { default: SvelteComponent };
|
|
50
|
+
component = module.default;
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(`Failed to load component ${asset.componentName}:`, error);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
loadComponent();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Calculate transform style
|
|
60
|
+
const transformStyle = $derived(
|
|
61
|
+
`translate(${asset.position.x}px, ${asset.position.y}px) scale(${asset.scale}) rotate(${asset.rotation}deg)`
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// Component props including animation state
|
|
65
|
+
const componentProps = $derived({
|
|
66
|
+
...asset.props,
|
|
67
|
+
animate: animationsEnabled && asset.animationEnabled
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
function handleMouseDown(event: MouseEvent) {
|
|
71
|
+
if (event.button !== 0) return; // Only left click
|
|
72
|
+
|
|
73
|
+
event.stopPropagation();
|
|
74
|
+
|
|
75
|
+
// Select this asset
|
|
76
|
+
onSelect?.();
|
|
77
|
+
|
|
78
|
+
// Start dragging
|
|
79
|
+
isDragging = true;
|
|
80
|
+
dragStart = { x: event.clientX, y: event.clientY };
|
|
81
|
+
positionStart = { ...asset.position };
|
|
82
|
+
|
|
83
|
+
if (containerElement) {
|
|
84
|
+
containerElement.style.cursor = 'grabbing';
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function handleMouseMove(event: MouseEvent) {
|
|
89
|
+
if (!isDragging) return;
|
|
90
|
+
|
|
91
|
+
const dx = event.clientX - dragStart.x;
|
|
92
|
+
const dy = event.clientY - dragStart.y;
|
|
93
|
+
|
|
94
|
+
const newPosition = {
|
|
95
|
+
x: positionStart.x + dx,
|
|
96
|
+
y: positionStart.y + dy
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
onMove?.(newPosition);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function handleMouseUp() {
|
|
103
|
+
if (isDragging) {
|
|
104
|
+
isDragging = false;
|
|
105
|
+
if (containerElement) {
|
|
106
|
+
containerElement.style.cursor = isSelected ? 'grab' : 'pointer';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function handleTouchStart(event: TouchEvent) {
|
|
112
|
+
if (event.touches.length !== 1) return;
|
|
113
|
+
|
|
114
|
+
event.stopPropagation();
|
|
115
|
+
|
|
116
|
+
// Select this asset
|
|
117
|
+
onSelect?.();
|
|
118
|
+
|
|
119
|
+
// Start dragging
|
|
120
|
+
const touch = event.touches[0];
|
|
121
|
+
isDragging = true;
|
|
122
|
+
dragStart = { x: touch.clientX, y: touch.clientY };
|
|
123
|
+
positionStart = { ...asset.position };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function handleTouchMove(event: TouchEvent) {
|
|
127
|
+
if (!isDragging || event.touches.length !== 1) return;
|
|
128
|
+
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
|
|
131
|
+
const touch = event.touches[0];
|
|
132
|
+
const dx = touch.clientX - dragStart.x;
|
|
133
|
+
const dy = touch.clientY - dragStart.y;
|
|
134
|
+
|
|
135
|
+
const newPosition = {
|
|
136
|
+
x: positionStart.x + dx,
|
|
137
|
+
y: positionStart.y + dy
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
onMove?.(newPosition);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function handleTouchEnd() {
|
|
144
|
+
if (isDragging) {
|
|
145
|
+
isDragging = false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Set up global event listeners for dragging
|
|
150
|
+
$effect(() => {
|
|
151
|
+
const handleGlobalMouseMove = (e: MouseEvent) => handleMouseMove(e);
|
|
152
|
+
const handleGlobalMouseUp = () => handleMouseUp();
|
|
153
|
+
|
|
154
|
+
if (isDragging) {
|
|
155
|
+
window.addEventListener('mousemove', handleGlobalMouseMove);
|
|
156
|
+
window.addEventListener('mouseup', handleGlobalMouseUp);
|
|
157
|
+
|
|
158
|
+
return () => {
|
|
159
|
+
window.removeEventListener('mousemove', handleGlobalMouseMove);
|
|
160
|
+
window.removeEventListener('mouseup', handleGlobalMouseUp);
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
</script>
|
|
165
|
+
|
|
166
|
+
<div
|
|
167
|
+
bind:this={containerElement}
|
|
168
|
+
class="absolute top-0 left-0 transition-none {isSelected ? 'selected' : ''}"
|
|
169
|
+
class:cursor-grab={isSelected && !isDragging}
|
|
170
|
+
class:cursor-grabbing={isDragging}
|
|
171
|
+
class:cursor-pointer={!isSelected && !isDragging}
|
|
172
|
+
style="
|
|
173
|
+
transform: {transformStyle};
|
|
174
|
+
transform-origin: center center;
|
|
175
|
+
z-index: {asset.zIndex};
|
|
176
|
+
"
|
|
177
|
+
role="button"
|
|
178
|
+
tabindex="0"
|
|
179
|
+
aria-label="{asset.componentName} at position {asset.position.x}, {asset.position.y}"
|
|
180
|
+
aria-pressed={isSelected}
|
|
181
|
+
onmousedown={handleMouseDown}
|
|
182
|
+
ontouchstart={handleTouchStart}
|
|
183
|
+
ontouchmove={handleTouchMove}
|
|
184
|
+
ontouchend={handleTouchEnd}
|
|
185
|
+
>
|
|
186
|
+
<!-- Selection border with glass effect -->
|
|
187
|
+
{#if isSelected}
|
|
188
|
+
<div
|
|
189
|
+
class="absolute inset-0 -m-2 pointer-events-none rounded-lg border-2 border-blue-400 bg-blue-50/10 backdrop-blur-sm shadow-lg"
|
|
190
|
+
style="z-index: -1;"
|
|
191
|
+
/>
|
|
192
|
+
{/if}
|
|
193
|
+
|
|
194
|
+
<!-- Render the nature component -->
|
|
195
|
+
{#if component}
|
|
196
|
+
<svelte:component this={component} {...componentProps} />
|
|
197
|
+
{:else}
|
|
198
|
+
<!-- Loading placeholder -->
|
|
199
|
+
<div class="w-16 h-16 flex items-center justify-center bg-white/20 backdrop-blur-sm rounded-lg border border-white/30">
|
|
200
|
+
<div class="text-xs text-gray-500">Loading...</div>
|
|
201
|
+
</div>
|
|
202
|
+
{/if}
|
|
203
|
+
</div>
|
|
204
|
+
|
|
205
|
+
<style>
|
|
206
|
+
.selected {
|
|
207
|
+
/* Ensure selected assets are interactive */
|
|
208
|
+
pointer-events: auto;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/* Prevent text selection during drag */
|
|
212
|
+
div {
|
|
213
|
+
-moz-user-select: none;
|
|
214
|
+
user-select: none;
|
|
215
|
+
-webkit-user-select: none;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/* Smooth hover effect for non-selected assets */
|
|
219
|
+
div:not(.selected):hover {
|
|
220
|
+
filter: brightness(1.05);
|
|
221
|
+
}
|
|
222
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PlacedAsset, Point } from './types';
|
|
2
|
+
interface Props {
|
|
3
|
+
asset: PlacedAsset;
|
|
4
|
+
isSelected?: boolean;
|
|
5
|
+
animationsEnabled?: boolean;
|
|
6
|
+
onSelect?: () => void;
|
|
7
|
+
onMove?: (position: Point) => void;
|
|
8
|
+
}
|
|
9
|
+
declare const PlacedAsset: import("svelte").Component<Props, {}, "">;
|
|
10
|
+
type PlacedAsset = ReturnType<typeof PlacedAsset>;
|
|
11
|
+
export default PlacedAsset;
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Grove — A place to Be
|
|
3
|
+
Copyright (c) 2025 Autumn Brown
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU Affero General Public License as published
|
|
7
|
+
by the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU Affero General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
-->
|
|
18
|
+
|
|
19
|
+
<script lang="ts">
|
|
20
|
+
import { createTerrariumState } from './terrariumState.svelte';
|
|
21
|
+
import Canvas from './Canvas.svelte';
|
|
22
|
+
import AssetPalette from './AssetPalette.svelte';
|
|
23
|
+
import Toolbar from './Toolbar.svelte';
|
|
24
|
+
import ExportDialog from './ExportDialog.svelte';
|
|
25
|
+
import { exportSceneAsPNG } from './utils/export';
|
|
26
|
+
import { TERRARIUM_CONFIG } from '../../../config/terrarium';
|
|
27
|
+
import type { AssetCategory, TerrariumScene } from './types';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Terrarium - Main Container Component
|
|
31
|
+
*
|
|
32
|
+
* The primary container that orchestrates the entire Terrarium creative canvas.
|
|
33
|
+
* Manages state, coordinates child components, handles keyboard shortcuts,
|
|
34
|
+
* and manages persistence with localStorage.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
const STORAGE_KEY = 'terrarium-scene';
|
|
38
|
+
|
|
39
|
+
const terrarium = createTerrariumState();
|
|
40
|
+
let showExportDialog = $state(false);
|
|
41
|
+
let canvasElement: HTMLDivElement | null = $state(null);
|
|
42
|
+
|
|
43
|
+
function handleAssetSelect(name: string, category: AssetCategory) {
|
|
44
|
+
if (!terrarium.canAddAsset) {
|
|
45
|
+
// Complexity budget exceeded - UI should show visual feedback
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const centerX = terrarium.scene.canvas.width / 2;
|
|
50
|
+
const centerY = terrarium.scene.canvas.height / 2;
|
|
51
|
+
|
|
52
|
+
terrarium.addAsset(name, category, { x: centerX, y: centerY });
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function handleToggleAnimations() {
|
|
56
|
+
terrarium.toggleAnimations();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function handleToggleGrid() {
|
|
60
|
+
terrarium.toggleGrid();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function handleSetGridSize(size: 16 | 32 | 64) {
|
|
64
|
+
terrarium.setGridSize(size);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function handleDelete() {
|
|
68
|
+
if (terrarium.selectedAssetId) {
|
|
69
|
+
terrarium.deleteAsset(terrarium.selectedAssetId);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function handleDuplicate() {
|
|
74
|
+
if (terrarium.selectedAssetId) {
|
|
75
|
+
terrarium.duplicateAsset(terrarium.selectedAssetId);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function handleExport() {
|
|
80
|
+
showExportDialog = true;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function handleSave(): boolean {
|
|
84
|
+
try {
|
|
85
|
+
const sceneJson = JSON.stringify(terrarium.scene);
|
|
86
|
+
|
|
87
|
+
// Proactive size validation before attempting to save
|
|
88
|
+
if (sceneJson.length > TERRARIUM_CONFIG.scene.maxSizeBytes) {
|
|
89
|
+
// Scene too large - warn user before attempting save
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
localStorage.setItem(STORAGE_KEY, sceneJson);
|
|
94
|
+
return true;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
if (error instanceof DOMException && error.name === 'QuotaExceededError') {
|
|
97
|
+
// Storage quota exceeded - handled silently, UI should show feedback
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function handleRename(name: string) {
|
|
104
|
+
const trimmed = name.trim();
|
|
105
|
+
if (trimmed.length > 0 && trimmed.length <= TERRARIUM_CONFIG.scene.maxNameLength) {
|
|
106
|
+
terrarium.scene.name = trimmed;
|
|
107
|
+
terrarium.scene.updatedAt = new Date().toISOString();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function handleExportPNG(options: { scale: number; includeBackground: boolean }) {
|
|
112
|
+
if (!canvasElement) {
|
|
113
|
+
throw new Error('Canvas element not found');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
await exportSceneAsPNG(canvasElement, terrarium.scene.name, {
|
|
117
|
+
scale: options.scale,
|
|
118
|
+
backgroundColor: options.includeBackground ? terrarium.scene.canvas.background : 'transparent',
|
|
119
|
+
pauseAnimations: true
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function handleCloseExportDialog() {
|
|
124
|
+
showExportDialog = false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function handleKeyDown(event: KeyboardEvent) {
|
|
128
|
+
const target = event.target as HTMLElement;
|
|
129
|
+
const isInputField =
|
|
130
|
+
target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.isContentEditable;
|
|
131
|
+
|
|
132
|
+
if (isInputField && event.key !== 'Escape') {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const isMac = navigator.platform.toUpperCase().indexOf('MAC') >= 0;
|
|
137
|
+
const cmdOrCtrl = isMac ? event.metaKey : event.ctrlKey;
|
|
138
|
+
|
|
139
|
+
if (event.key === 'Delete' || event.key === 'Backspace') {
|
|
140
|
+
if (!isInputField && terrarium.selectedAssetId) {
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
handleDelete();
|
|
143
|
+
}
|
|
144
|
+
} else if (cmdOrCtrl && event.key === 'd') {
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
if (terrarium.selectedAssetId) {
|
|
147
|
+
handleDuplicate();
|
|
148
|
+
}
|
|
149
|
+
} else if (event.key === 'Escape') {
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
terrarium.selectAsset(null);
|
|
152
|
+
showExportDialog = false;
|
|
153
|
+
} else if (event.key === 'g' && !cmdOrCtrl) {
|
|
154
|
+
if (!isInputField) {
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
handleToggleGrid();
|
|
157
|
+
}
|
|
158
|
+
} else if (event.key === 'a' && !cmdOrCtrl) {
|
|
159
|
+
if (!isInputField) {
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
handleToggleAnimations();
|
|
162
|
+
}
|
|
163
|
+
} else if (cmdOrCtrl && event.key === 's') {
|
|
164
|
+
event.preventDefault();
|
|
165
|
+
handleSave();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function isValidScene(scene: unknown): scene is TerrariumScene {
|
|
170
|
+
if (typeof scene !== 'object' || scene === null) return false;
|
|
171
|
+
const s = scene as Record<string, unknown>;
|
|
172
|
+
return (
|
|
173
|
+
typeof s.id === 'string' &&
|
|
174
|
+
typeof s.name === 'string' &&
|
|
175
|
+
typeof s.canvas === 'object' &&
|
|
176
|
+
Array.isArray(s.assets)
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function loadSceneFromStorage() {
|
|
181
|
+
try {
|
|
182
|
+
const storedScene = localStorage.getItem(STORAGE_KEY);
|
|
183
|
+
if (storedScene) {
|
|
184
|
+
const parsedScene = JSON.parse(storedScene);
|
|
185
|
+
if (isValidScene(parsedScene)) {
|
|
186
|
+
terrarium.setScene(parsedScene);
|
|
187
|
+
} else {
|
|
188
|
+
// Invalid scene format - clear and use default
|
|
189
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
} catch {
|
|
193
|
+
// Clear corrupted data silently
|
|
194
|
+
try {
|
|
195
|
+
localStorage.removeItem(STORAGE_KEY);
|
|
196
|
+
} catch {
|
|
197
|
+
// Ignore cleanup errors
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
$effect(() => {
|
|
203
|
+
loadSceneFromStorage();
|
|
204
|
+
});
|
|
205
|
+
</script>
|
|
206
|
+
|
|
207
|
+
<svelte:window onkeydown={handleKeyDown} />
|
|
208
|
+
|
|
209
|
+
<div class="terrarium-container flex h-screen w-screen overflow-hidden">
|
|
210
|
+
<!-- Left Sidebar: Asset Palette -->
|
|
211
|
+
<div class="flex-shrink-0" style="width: 280px;">
|
|
212
|
+
<AssetPalette onAssetSelect={handleAssetSelect} />
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
<!-- Main Content Area -->
|
|
216
|
+
<div class="flex flex-col flex-1 min-w-0">
|
|
217
|
+
<!-- Top Toolbar -->
|
|
218
|
+
<Toolbar
|
|
219
|
+
bind:sceneName={terrarium.scene.name}
|
|
220
|
+
animationsEnabled={terrarium.animationsEnabled}
|
|
221
|
+
gridEnabled={terrarium.scene.canvas.gridEnabled}
|
|
222
|
+
gridSize={terrarium.scene.canvas.gridSize}
|
|
223
|
+
hasSelection={terrarium.selectedAssetId !== null}
|
|
224
|
+
onToggleAnimations={handleToggleAnimations}
|
|
225
|
+
onToggleGrid={handleToggleGrid}
|
|
226
|
+
onSetGridSize={handleSetGridSize}
|
|
227
|
+
onDelete={handleDelete}
|
|
228
|
+
onDuplicate={handleDuplicate}
|
|
229
|
+
onExport={handleExport}
|
|
230
|
+
onSave={handleSave}
|
|
231
|
+
onRename={handleRename}
|
|
232
|
+
/>
|
|
233
|
+
|
|
234
|
+
<!-- Canvas Area -->
|
|
235
|
+
<div bind:this={canvasElement} class="flex-1 min-h-0 overflow-hidden">
|
|
236
|
+
<Canvas
|
|
237
|
+
scene={terrarium.scene}
|
|
238
|
+
selectedAssetId={terrarium.selectedAssetId}
|
|
239
|
+
animationsEnabled={terrarium.animationsEnabled}
|
|
240
|
+
panOffset={terrarium.panOffset}
|
|
241
|
+
onAssetSelect={(id) => terrarium.selectAsset(id)}
|
|
242
|
+
onAssetMove={(id, position) => terrarium.updateAsset(id, { position })}
|
|
243
|
+
onCanvasClick={() => terrarium.selectAsset(null)}
|
|
244
|
+
onPan={(offset) => terrarium.setPanOffset(offset)}
|
|
245
|
+
/>
|
|
246
|
+
</div>
|
|
247
|
+
</div>
|
|
248
|
+
|
|
249
|
+
<!-- Export Dialog (Modal Overlay) -->
|
|
250
|
+
<ExportDialog
|
|
251
|
+
bind:open={showExportDialog}
|
|
252
|
+
sceneName={terrarium.scene.name}
|
|
253
|
+
onClose={handleCloseExportDialog}
|
|
254
|
+
onExport={handleExportPNG}
|
|
255
|
+
/>
|
|
256
|
+
</div>
|
|
257
|
+
|
|
258
|
+
<style>
|
|
259
|
+
.terrarium-container {
|
|
260
|
+
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
:global(.dark) .terrarium-container {
|
|
264
|
+
background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
|
|
265
|
+
}
|
|
266
|
+
</style>
|