@pixel-point/toolcraft 0.0.2
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.md +98 -0
- package/README.md +41 -0
- package/bin/create-toolcraft-app.mjs +8 -0
- package/bin/toolcraft.mjs +8 -0
- package/package.json +24 -0
- package/scripts/prepare-pack.mjs +29 -0
- package/src/cli.mjs +392 -0
- package/src/cli.test.mjs +284 -0
- package/src/copy-recursive.mjs +86 -0
- package/src/generate.mjs +212 -0
- package/src/generate.test.mjs +322 -0
- package/src/import-map.mjs +14 -0
- package/src/package-json.mjs +80 -0
- package/src/package-json.test.mjs +67 -0
- package/src/rewrite-imports.mjs +85 -0
- package/src/rewrite-imports.test.mjs +58 -0
- package/templates/runtime/contracts/component-contracts.test.ts +1165 -0
- package/templates/runtime/contracts/component-contracts.ts +1340 -0
- package/templates/runtime/contracts/decision-contracts.test.ts +206 -0
- package/templates/runtime/contracts/decision-contracts.ts +283 -0
- package/templates/runtime/contracts/index.test.ts +14 -0
- package/templates/runtime/contracts/index.ts +3 -0
- package/templates/runtime/contracts/types.ts +56 -0
- package/templates/runtime/export/export.test.ts +203 -0
- package/templates/runtime/export/export.ts +132 -0
- package/templates/runtime/export/index.ts +1 -0
- package/templates/runtime/index.ts +14 -0
- package/templates/runtime/react/canvas-shell.test.tsx +424 -0
- package/templates/runtime/react/canvas-shell.tsx +408 -0
- package/templates/runtime/react/control-renderers.ts +31 -0
- package/templates/runtime/react/controls-panel.test.tsx +3736 -0
- package/templates/runtime/react/controls-panel.tsx +2327 -0
- package/templates/runtime/react/curve-geometry.test.ts +70 -0
- package/templates/runtime/react/index.ts +15 -0
- package/templates/runtime/react/layer-tree.ts +96 -0
- package/templates/runtime/react/layers-panel.test.tsx +487 -0
- package/templates/runtime/react/layers-panel.tsx +1348 -0
- package/templates/runtime/react/media-file.ts +82 -0
- package/templates/runtime/react/panel-host-config.ts +80 -0
- package/templates/runtime/react/panel-host-geometry.test.ts +66 -0
- package/templates/runtime/react/panel-host-geometry.ts +109 -0
- package/templates/runtime/react/panel-host-types.ts +74 -0
- package/templates/runtime/react/panel-host.test.tsx +102 -0
- package/templates/runtime/react/panel-host.tsx +353 -0
- package/templates/runtime/react/runtime-public-api.test.tsx +132 -0
- package/templates/runtime/react/settings-transfer.test.ts +150 -0
- package/templates/runtime/react/settings-transfer.ts +279 -0
- package/templates/runtime/react/storage-key-migration.ts +48 -0
- package/templates/runtime/react/theme-runtime.tsx +177 -0
- package/templates/runtime/react/timeline-panel.test.tsx +668 -0
- package/templates/runtime/react/timeline-panel.tsx +2953 -0
- package/templates/runtime/react/toolbar-panel.test.tsx +212 -0
- package/templates/runtime/react/toolbar-panel.tsx +205 -0
- package/templates/runtime/react/toolcraft-app.integration.test.tsx +350 -0
- package/templates/runtime/react/toolcraft-app.test.tsx +339 -0
- package/templates/runtime/react/toolcraft-app.tsx +81 -0
- package/templates/runtime/react/toolcraft-root.test.tsx +347 -0
- package/templates/runtime/react/toolcraft-root.tsx +203 -0
- package/templates/runtime/react/use-toolcraft.ts +41 -0
- package/templates/runtime/schema/define-toolcraft.test.ts +1524 -0
- package/templates/runtime/schema/define-toolcraft.ts +1442 -0
- package/templates/runtime/schema/keyframe-capability.test.ts +90 -0
- package/templates/runtime/schema/keyframe-capability.ts +51 -0
- package/templates/runtime/schema/runtime-targets.ts +40 -0
- package/templates/runtime/schema/types.ts +370 -0
- package/templates/runtime/state/canvas-zoom.ts +8 -0
- package/templates/runtime/state/create-template-state.test.ts +242 -0
- package/templates/runtime/state/create-template-state.ts +95 -0
- package/templates/runtime/state/keyframe-evaluation.test.ts +141 -0
- package/templates/runtime/state/keyframe-evaluation.ts +203 -0
- package/templates/runtime/state/persistence.test.ts +217 -0
- package/templates/runtime/state/persistence.ts +511 -0
- package/templates/runtime/state/reducer.test.ts +937 -0
- package/templates/runtime/state/reducer.ts +1212 -0
- package/templates/runtime/state/timeline-readiness.ts +43 -0
- package/templates/runtime/state/types.ts +242 -0
- package/templates/runtime/styles.css +125 -0
- package/templates/runtime/testing/performance.test.ts +1058 -0
- package/templates/runtime/testing/performance.ts +1078 -0
- package/templates/starter/AGENTS.md +186 -0
- package/templates/starter/LICENSE.md +98 -0
- package/templates/starter/NOTICE.md +8 -0
- package/templates/starter/docs/toolcraft/README.md +41 -0
- package/templates/starter/docs/toolcraft/acceptance-testing.md +205 -0
- package/templates/starter/docs/toolcraft/agent-worklog.md +81 -0
- package/templates/starter/docs/toolcraft/assembly-workflow.md +206 -0
- package/templates/starter/docs/toolcraft/component-rules.md +299 -0
- package/templates/starter/docs/toolcraft/custom-controls.md +71 -0
- package/templates/starter/docs/toolcraft/decision-contract.md +71 -0
- package/templates/starter/docs/toolcraft/performance.md +112 -0
- package/templates/starter/docs/toolcraft/renderer-technique.md +48 -0
- package/templates/starter/docs/toolcraft/schema-reference.md +265 -0
- package/templates/starter/docs/toolcraft/workflow.md +87 -0
- package/templates/starter/e2e/app-browser-acceptance.spec.ts +785 -0
- package/templates/starter/e2e/app-controls.spec.ts +41 -0
- package/templates/starter/e2e/app-performance.spec.ts +326 -0
- package/templates/starter/e2e/canvas-handle-helpers.ts +244 -0
- package/templates/starter/e2e/performance-helpers.ts +612 -0
- package/templates/starter/e2e/product-observable-helpers.ts +170 -0
- package/templates/starter/index.html +12 -0
- package/templates/starter/package.json +52 -0
- package/templates/starter/playwright.config.ts +43 -0
- package/templates/starter/scripts/check-ai-skills.mjs +95 -0
- package/templates/starter/scripts/check-toolcraft-docs.mjs +159 -0
- package/templates/starter/scripts/check-toolcraft-integrity.mjs +232 -0
- package/templates/starter/scripts/run-vite-on-free-port.mjs +48 -0
- package/templates/starter/scripts/toolcraft-port.mjs +54 -0
- package/templates/starter/scripts/toolcraft-port.test.mjs +73 -0
- package/templates/starter/src/app/starter-acceptance.test.ts +5959 -0
- package/templates/starter/src/app/starter-acceptance.ts +2646 -0
- package/templates/starter/src/app/starter-performance.test.ts +1390 -0
- package/templates/starter/src/app/starter-performance.ts +12 -0
- package/templates/starter/src/app/starter-schema.test.ts +70 -0
- package/templates/starter/src/app/starter-schema.ts +15 -0
- package/templates/starter/src/main.tsx +18 -0
- package/templates/starter/src/router.tsx +16 -0
- package/templates/starter/src/routes/index.tsx +7 -0
- package/templates/starter/src/routes/root.tsx +19 -0
- package/templates/starter/src/styles.css +120 -0
- package/templates/starter/tsconfig.json +11 -0
- package/templates/starter/vite.config.ts +13 -0
- package/templates/ui/components/composites/accordion.tsx +73 -0
- package/templates/ui/components/composites/alert-dialog.tsx +190 -0
- package/templates/ui/components/composites/alert.tsx +74 -0
- package/templates/ui/components/composites/aspect-ratio.tsx +22 -0
- package/templates/ui/components/composites/avatar.tsx +98 -0
- package/templates/ui/components/composites/badge.tsx +69 -0
- package/templates/ui/components/composites/breadcrumb.tsx +106 -0
- package/templates/ui/components/composites/card.tsx +91 -0
- package/templates/ui/components/composites/combobox.tsx +486 -0
- package/templates/ui/components/composites/command.tsx +296 -0
- package/templates/ui/components/composites/context-menu.tsx +247 -0
- package/templates/ui/components/composites/dialog.tsx +282 -0
- package/templates/ui/components/composites/dropdown-menu.tsx +299 -0
- package/templates/ui/components/composites/empty.tsx +110 -0
- package/templates/ui/components/composites/hover-card.tsx +44 -0
- package/templates/ui/components/composites/index.ts +30 -0
- package/templates/ui/components/composites/menubar.tsx +214 -0
- package/templates/ui/components/composites/navigation-menu.tsx +167 -0
- package/templates/ui/components/composites/pagination.tsx +131 -0
- package/templates/ui/components/composites/progress.tsx +72 -0
- package/templates/ui/components/composites/radio-group.tsx +84 -0
- package/templates/ui/components/composites/resizable.tsx +42 -0
- package/templates/ui/components/composites/sheet.tsx +153 -0
- package/templates/ui/components/composites/sidebar-structural.tsx +310 -0
- package/templates/ui/components/composites/sidebar.tsx +431 -0
- package/templates/ui/components/composites/sonner.tsx +35 -0
- package/templates/ui/components/composites/spinner.tsx +43 -0
- package/templates/ui/components/composites/table.tsx +108 -0
- package/templates/ui/components/composites/tabs.tsx +83 -0
- package/templates/ui/components/control-layout/index.tsx +437 -0
- package/templates/ui/components/controls/actions/actions-control.tsx +139 -0
- package/templates/ui/components/controls/actions/index.ts +9 -0
- package/templates/ui/components/controls/anchor-grid/anchor-grid-control.tsx +107 -0
- package/templates/ui/components/controls/anchor-grid/index.ts +4 -0
- package/templates/ui/components/controls/boolean/boolean-controls.tsx +79 -0
- package/templates/ui/components/controls/boolean/index.ts +4 -0
- package/templates/ui/components/controls/channel-mixer/channel-mixer-control.tsx +95 -0
- package/templates/ui/components/controls/channel-mixer/index.ts +4 -0
- package/templates/ui/components/controls/channel-tabs/channel-tabs.tsx +42 -0
- package/templates/ui/components/controls/channel-tabs/index.ts +6 -0
- package/templates/ui/components/controls/code-textarea/code-textarea-control.tsx +90 -0
- package/templates/ui/components/controls/code-textarea/index.ts +4 -0
- package/templates/ui/components/controls/color/color-control.tsx +571 -0
- package/templates/ui/components/controls/color/color-picker-popover.tsx +104 -0
- package/templates/ui/components/controls/color/index.ts +41 -0
- package/templates/ui/components/controls/color/palette-control-data.ts +436 -0
- package/templates/ui/components/controls/color/palette-control.tsx +535 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-channel-utils.ts +162 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-interactions.ts +190 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-logic.ts +485 -0
- package/templates/ui/components/controls/color/style-guide-color-picker-parts.tsx +710 -0
- package/templates/ui/components/controls/color/style-guide-color-picker.tsx +503 -0
- package/templates/ui/components/controls/control-types.ts +43 -0
- package/templates/ui/components/controls/curves/curve-geometry.ts +355 -0
- package/templates/ui/components/controls/curves/curve-graph.tsx +390 -0
- package/templates/ui/components/controls/curves/curves-control.tsx +445 -0
- package/templates/ui/components/controls/curves/index.ts +6 -0
- package/templates/ui/components/controls/file-drop/file-drop-control.tsx +191 -0
- package/templates/ui/components/controls/file-drop/index.ts +5 -0
- package/templates/ui/components/controls/font-picker/font-catalog.json +15360 -0
- package/templates/ui/components/controls/font-picker/font-catalog.ts +116 -0
- package/templates/ui/components/controls/font-picker/font-picker-control.tsx +1202 -0
- package/templates/ui/components/controls/font-picker/font-preview-loader.ts +336 -0
- package/templates/ui/components/controls/font-picker/index.ts +24 -0
- package/templates/ui/components/controls/font-picker/use-hover-intent.ts +46 -0
- package/templates/ui/components/controls/gradient/gradient-control-utils.ts +190 -0
- package/templates/ui/components/controls/gradient/gradient-control.tsx +612 -0
- package/templates/ui/components/controls/gradient/gradient-stop-list.tsx +400 -0
- package/templates/ui/components/controls/gradient/gradient-toolbar.tsx +152 -0
- package/templates/ui/components/controls/gradient/index.ts +4 -0
- package/templates/ui/components/controls/image-picker/image-picker-control.tsx +139 -0
- package/templates/ui/components/controls/image-picker/index.ts +7 -0
- package/templates/ui/components/controls/index.ts +192 -0
- package/templates/ui/components/controls/range-input/index.ts +4 -0
- package/templates/ui/components/controls/range-input/range-input-control.tsx +173 -0
- package/templates/ui/components/controls/range-slider/index.ts +4 -0
- package/templates/ui/components/controls/range-slider/range-slider-control.tsx +122 -0
- package/templates/ui/components/controls/range-slider/range-slider-value.ts +61 -0
- package/templates/ui/components/controls/segmented/index.ts +8 -0
- package/templates/ui/components/controls/segmented/segmented-control.tsx +94 -0
- package/templates/ui/components/controls/select/index.ts +4 -0
- package/templates/ui/components/controls/select/select-control.tsx +223 -0
- package/templates/ui/components/controls/slider/index.ts +4 -0
- package/templates/ui/components/controls/slider/slider-control.tsx +150 -0
- package/templates/ui/components/controls/slider/slider-value.ts +56 -0
- package/templates/ui/components/controls/text-input/index.ts +4 -0
- package/templates/ui/components/controls/text-input/text-input-control.tsx +158 -0
- package/templates/ui/components/controls/use-measured-element-width.ts +42 -0
- package/templates/ui/components/controls/vector/index.ts +8 -0
- package/templates/ui/components/controls/vector/vector-control.tsx +401 -0
- package/templates/ui/components/panel/index.ts +19 -0
- package/templates/ui/components/panel/panel-actions.tsx +165 -0
- package/templates/ui/components/panel/panel-header.tsx +61 -0
- package/templates/ui/components/panel/panel-icon-button.tsx +96 -0
- package/templates/ui/components/panel/panel-section.tsx +168 -0
- package/templates/ui/components/panel/panel-surface.tsx +206 -0
- package/templates/ui/components/panel/panel.tsx +210 -0
- package/templates/ui/components/primitives/animated-loader.tsx +61 -0
- package/templates/ui/components/primitives/button-group.tsx +134 -0
- package/templates/ui/components/primitives/button.tsx +429 -0
- package/templates/ui/components/primitives/checkbox.tsx +62 -0
- package/templates/ui/components/primitives/editable-slider-value-label.tsx +337 -0
- package/templates/ui/components/primitives/field.tsx +225 -0
- package/templates/ui/components/primitives/index.ts +82 -0
- package/templates/ui/components/primitives/input-group.tsx +298 -0
- package/templates/ui/components/primitives/input.tsx +61 -0
- package/templates/ui/components/primitives/internal/button-loading.tsx +178 -0
- package/templates/ui/components/primitives/label.tsx +16 -0
- package/templates/ui/components/primitives/popover.tsx +126 -0
- package/templates/ui/components/primitives/portal-layer-context.tsx +33 -0
- package/templates/ui/components/primitives/primitive-arrow-icon.tsx +38 -0
- package/templates/ui/components/primitives/scroll-fade-logic.ts +441 -0
- package/templates/ui/components/primitives/scroll-fade-render.tsx +75 -0
- package/templates/ui/components/primitives/scroll-fade-types.ts +41 -0
- package/templates/ui/components/primitives/scroll-fade.tsx +72 -0
- package/templates/ui/components/primitives/select.tsx +408 -0
- package/templates/ui/components/primitives/selection-state.ts +31 -0
- package/templates/ui/components/primitives/separator.tsx +21 -0
- package/templates/ui/components/primitives/slider/index.ts +4 -0
- package/templates/ui/components/primitives/slider/slider-interaction.tsx +96 -0
- package/templates/ui/components/primitives/slider/slider-parts.tsx +303 -0
- package/templates/ui/components/primitives/slider/slider-reset.ts +152 -0
- package/templates/ui/components/primitives/slider/slider-value.ts +114 -0
- package/templates/ui/components/primitives/slider/slider.tsx +511 -0
- package/templates/ui/components/primitives/switch.tsx +35 -0
- package/templates/ui/components/primitives/textarea.tsx +49 -0
- package/templates/ui/components/primitives/toggle-group.tsx +114 -0
- package/templates/ui/components/primitives/toggle.tsx +46 -0
- package/templates/ui/components/primitives/tooltip.tsx +100 -0
- package/templates/ui/hooks/use-mobile.ts +21 -0
- package/templates/ui/index.ts +31 -0
- package/templates/ui/lib/control-outline.ts +3 -0
- package/templates/ui/lib/input-control-style.ts +131 -0
- package/templates/ui/lib/style-guide-color-utils.ts +111 -0
- package/templates/ui/lib/utils.ts +6 -0
- package/templates/ui/styles.css +291 -0
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { defineToolcraft } from "../schema/define-toolcraft";
|
|
6
|
+
import { CanvasShell } from "./canvas-shell";
|
|
7
|
+
import { ToolcraftRoot } from "./toolcraft-root";
|
|
8
|
+
import { useToolcraft } from "./use-toolcraft";
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
cleanup();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
function createSchema() {
|
|
15
|
+
return defineToolcraft({
|
|
16
|
+
canvas: {
|
|
17
|
+
enabled: true,
|
|
18
|
+
size: { width: 300, height: 200, unit: "px" },
|
|
19
|
+
upload: true,
|
|
20
|
+
},
|
|
21
|
+
panels: {},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function createAutoSizedSchema() {
|
|
26
|
+
return defineToolcraft({
|
|
27
|
+
canvas: {
|
|
28
|
+
enabled: true,
|
|
29
|
+
upload: true,
|
|
30
|
+
},
|
|
31
|
+
panels: {},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function CanvasStateProbe() {
|
|
36
|
+
const { state } = useToolcraft();
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<>
|
|
40
|
+
<span data-testid="canvas-offset">
|
|
41
|
+
{state.canvas.offset.x},{state.canvas.offset.y}
|
|
42
|
+
</span>
|
|
43
|
+
<span data-testid="canvas-zoom">{state.canvas.zoom}</span>
|
|
44
|
+
<span data-testid="media-count">{state.mediaAssets.length}</span>
|
|
45
|
+
<span data-testid="media-size">
|
|
46
|
+
{state.mediaAssets[0]?.size.width ?? 0},{state.mediaAssets[0]?.size.height ?? 0}
|
|
47
|
+
</span>
|
|
48
|
+
</>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
describe("CanvasShell", () => {
|
|
53
|
+
function mockCanvasRect(canvas: HTMLElement): void {
|
|
54
|
+
vi.spyOn(canvas, "getBoundingClientRect").mockReturnValue({
|
|
55
|
+
bottom: 600,
|
|
56
|
+
height: 600,
|
|
57
|
+
left: 0,
|
|
58
|
+
right: 800,
|
|
59
|
+
toJSON: () => ({}),
|
|
60
|
+
top: 0,
|
|
61
|
+
width: 800,
|
|
62
|
+
x: 0,
|
|
63
|
+
y: 0,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
it("renders the editable canvas at the schema size", () => {
|
|
68
|
+
const { container } = render(
|
|
69
|
+
<ToolcraftRoot schema={createSchema()}>
|
|
70
|
+
<div style={{ height: 640, position: "relative", width: 640 }}>
|
|
71
|
+
<CanvasShell />
|
|
72
|
+
</div>
|
|
73
|
+
</ToolcraftRoot>,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const editableCanvas = container.querySelector<HTMLElement>(
|
|
77
|
+
"[data-toolcraft-editable-canvas]",
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
expect(editableCanvas?.style.width).toBe("300px");
|
|
81
|
+
expect(editableCanvas?.style.height).toBe("200px");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("does not render a fixed editable canvas when the app has not chosen a size", () => {
|
|
85
|
+
const { container } = render(
|
|
86
|
+
<ToolcraftRoot schema={createAutoSizedSchema()}>
|
|
87
|
+
<div style={{ height: 640, position: "relative", width: 640 }}>
|
|
88
|
+
<CanvasShell />
|
|
89
|
+
</div>
|
|
90
|
+
</ToolcraftRoot>,
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
expect(container.querySelector("[data-toolcraft-editable-canvas]")).toBeNull();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("renders the canvas slot inside the editable canvas when custom app content is provided", () => {
|
|
97
|
+
const { container } = render(
|
|
98
|
+
<ToolcraftRoot schema={createAutoSizedSchema()}>
|
|
99
|
+
<div style={{ height: 640, position: "relative", width: 640 }}>
|
|
100
|
+
<CanvasShell>
|
|
101
|
+
<div data-testid="custom-canvas-renderer" />
|
|
102
|
+
</CanvasShell>
|
|
103
|
+
</div>
|
|
104
|
+
</ToolcraftRoot>,
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
const editableCanvas = container.querySelector<HTMLElement>(
|
|
108
|
+
"[data-toolcraft-editable-canvas]",
|
|
109
|
+
);
|
|
110
|
+
const slot = container.querySelector<HTMLElement>(
|
|
111
|
+
"[data-toolcraft-canvas-slot]",
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
expect(editableCanvas).toBeTruthy();
|
|
115
|
+
expect(slot?.parentElement).toBe(editableCanvas);
|
|
116
|
+
expect(screen.getByTestId("custom-canvas-renderer")).toBeTruthy();
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("does not render decorative canvas background dots", () => {
|
|
120
|
+
const { container } = render(
|
|
121
|
+
<ToolcraftRoot schema={createSchema()}>
|
|
122
|
+
<div style={{ height: 640, position: "relative", width: 640 }}>
|
|
123
|
+
<CanvasShell />
|
|
124
|
+
</div>
|
|
125
|
+
</ToolcraftRoot>,
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
const pattern = container.querySelector<HTMLElement>("[data-toolcraft-canvas-grid]");
|
|
129
|
+
const world = container.querySelector<HTMLElement>("[data-toolcraft-canvas-world]");
|
|
130
|
+
|
|
131
|
+
expect(world).toBeTruthy();
|
|
132
|
+
expect(pattern).toBeNull();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("moves and scales the canvas world without decorative background dots", () => {
|
|
136
|
+
const { container } = render(
|
|
137
|
+
<ToolcraftRoot
|
|
138
|
+
initialState={{
|
|
139
|
+
canvas: {
|
|
140
|
+
offset: { x: 12, y: -8 },
|
|
141
|
+
size: { height: 200, unit: "px", width: 300 },
|
|
142
|
+
zoom: 150,
|
|
143
|
+
},
|
|
144
|
+
}}
|
|
145
|
+
schema={createSchema()}
|
|
146
|
+
>
|
|
147
|
+
<div style={{ height: 640, position: "relative", width: 640 }}>
|
|
148
|
+
<CanvasShell />
|
|
149
|
+
</div>
|
|
150
|
+
</ToolcraftRoot>,
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
const pattern = container.querySelector<HTMLElement>("[data-toolcraft-canvas-grid]");
|
|
154
|
+
const world = container.querySelector<HTMLElement>("[data-toolcraft-canvas-world]");
|
|
155
|
+
|
|
156
|
+
expect(pattern).toBeNull();
|
|
157
|
+
expect(world?.style.transform).toBe("translate(-50%, -50%) translate(12px, -8px) scale(1.5)");
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("keeps minimum zoom world transform without decorative background dots", () => {
|
|
161
|
+
const { container } = render(
|
|
162
|
+
<ToolcraftRoot
|
|
163
|
+
initialState={{
|
|
164
|
+
canvas: {
|
|
165
|
+
offset: { x: 3200, y: -2400 },
|
|
166
|
+
size: { height: 200, unit: "px", width: 300 },
|
|
167
|
+
zoom: 25,
|
|
168
|
+
},
|
|
169
|
+
}}
|
|
170
|
+
schema={createSchema()}
|
|
171
|
+
>
|
|
172
|
+
<div style={{ height: 640, position: "relative", width: 640 }}>
|
|
173
|
+
<CanvasShell />
|
|
174
|
+
</div>
|
|
175
|
+
</ToolcraftRoot>,
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
const pattern = container.querySelector<HTMLElement>("[data-toolcraft-canvas-grid]");
|
|
179
|
+
const world = container.querySelector<HTMLElement>("[data-toolcraft-canvas-world]");
|
|
180
|
+
|
|
181
|
+
expect(pattern).toBeNull();
|
|
182
|
+
expect(world?.style.transform).toBe(
|
|
183
|
+
"translate(-50%, -50%) translate(3200px, -2400px) scale(0.25)",
|
|
184
|
+
);
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
it("updates runtime canvas offset while panning", () => {
|
|
188
|
+
render(
|
|
189
|
+
<ToolcraftRoot schema={createSchema()}>
|
|
190
|
+
<div style={{ height: 640, position: "relative", width: 640 }}>
|
|
191
|
+
<CanvasShell />
|
|
192
|
+
<CanvasStateProbe />
|
|
193
|
+
</div>
|
|
194
|
+
</ToolcraftRoot>,
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
const canvas = screen.getByRole("application", { name: "Canvas viewport" });
|
|
198
|
+
|
|
199
|
+
fireEvent.pointerDown(canvas, { button: 0, clientX: 10, clientY: 20, pointerId: 1 });
|
|
200
|
+
fireEvent.pointerMove(canvas, { clientX: 25, clientY: 45, pointerId: 1 });
|
|
201
|
+
fireEvent.pointerUp(canvas, { pointerId: 1 });
|
|
202
|
+
|
|
203
|
+
expect(screen.getByTestId("canvas-offset").textContent).toBe("15,25");
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("pans the canvas from a two finger wheel gesture", async () => {
|
|
207
|
+
render(
|
|
208
|
+
<ToolcraftRoot schema={createSchema()}>
|
|
209
|
+
<div style={{ height: 640, position: "relative", width: 640 }}>
|
|
210
|
+
<CanvasShell />
|
|
211
|
+
<CanvasStateProbe />
|
|
212
|
+
</div>
|
|
213
|
+
</ToolcraftRoot>,
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
const canvas = screen.getByRole("application", { name: "Canvas viewport" });
|
|
217
|
+
const wheelEvent = new WheelEvent("wheel", {
|
|
218
|
+
bubbles: true,
|
|
219
|
+
cancelable: true,
|
|
220
|
+
deltaX: 8,
|
|
221
|
+
deltaY: -12,
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
expect(canvas.dispatchEvent(wheelEvent)).toBe(false);
|
|
225
|
+
expect(wheelEvent.defaultPrevented).toBe(true);
|
|
226
|
+
await waitFor(() => {
|
|
227
|
+
expect(screen.getByTestId("canvas-offset").textContent).toBe("-8,12");
|
|
228
|
+
});
|
|
229
|
+
expect(screen.getByTestId("canvas-zoom").textContent).toBe("70");
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("zooms the canvas world from a trackpad pinch around the pointer", async () => {
|
|
233
|
+
render(
|
|
234
|
+
<ToolcraftRoot schema={createSchema()}>
|
|
235
|
+
<div style={{ height: 640, position: "relative", width: 640 }}>
|
|
236
|
+
<CanvasShell />
|
|
237
|
+
<CanvasStateProbe />
|
|
238
|
+
</div>
|
|
239
|
+
</ToolcraftRoot>,
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const canvas = screen.getByRole("application", { name: "Canvas viewport" });
|
|
243
|
+
const world = canvas.querySelector("[data-toolcraft-canvas-world]") as HTMLElement;
|
|
244
|
+
mockCanvasRect(canvas);
|
|
245
|
+
|
|
246
|
+
expect(world.style.transform).toBe("translate(-50%, -50%) translate(0px, 0px) scale(0.7)");
|
|
247
|
+
|
|
248
|
+
const wheelEvent = new WheelEvent("wheel", {
|
|
249
|
+
bubbles: true,
|
|
250
|
+
cancelable: true,
|
|
251
|
+
clientX: 600,
|
|
252
|
+
clientY: 300,
|
|
253
|
+
ctrlKey: true,
|
|
254
|
+
deltaY: -100,
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
expect(canvas.dispatchEvent(wheelEvent)).toBe(false);
|
|
258
|
+
expect(wheelEvent.defaultPrevented).toBe(true);
|
|
259
|
+
await waitFor(() => {
|
|
260
|
+
expect(screen.getByTestId("canvas-zoom").textContent).toBe("120");
|
|
261
|
+
});
|
|
262
|
+
expect(world.style.transform).toContain("translate(-142.857142857142");
|
|
263
|
+
expect(world.style.transform).toContain("scale(1.2)");
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it("prevents panel pinch gestures without moving the canvas viewport", async () => {
|
|
267
|
+
render(
|
|
268
|
+
<ToolcraftRoot schema={createSchema()}>
|
|
269
|
+
<div
|
|
270
|
+
data-slot="toolcraft-runtime-app"
|
|
271
|
+
style={{ height: 640, position: "relative", width: 640 }}
|
|
272
|
+
>
|
|
273
|
+
<CanvasShell />
|
|
274
|
+
<button data-testid="panel-overlay" type="button">
|
|
275
|
+
Panel overlay
|
|
276
|
+
</button>
|
|
277
|
+
<CanvasStateProbe />
|
|
278
|
+
</div>
|
|
279
|
+
</ToolcraftRoot>,
|
|
280
|
+
);
|
|
281
|
+
|
|
282
|
+
const canvas = screen.getByRole("application", { name: "Canvas viewport" });
|
|
283
|
+
const overlay = screen.getByTestId("panel-overlay");
|
|
284
|
+
mockCanvasRect(canvas);
|
|
285
|
+
|
|
286
|
+
const wheelEvent = new WheelEvent("wheel", {
|
|
287
|
+
bubbles: true,
|
|
288
|
+
cancelable: true,
|
|
289
|
+
clientX: 600,
|
|
290
|
+
clientY: 300,
|
|
291
|
+
ctrlKey: true,
|
|
292
|
+
deltaY: -100,
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
expect(overlay.dispatchEvent(wheelEvent)).toBe(false);
|
|
296
|
+
expect(wheelEvent.defaultPrevented).toBe(true);
|
|
297
|
+
expect(screen.getByTestId("canvas-zoom").textContent).toBe("70");
|
|
298
|
+
expect(screen.getByTestId("canvas-offset").textContent).toBe("0,0");
|
|
299
|
+
expect(overlay.closest("[data-toolcraft-canvas-world]")).toBeNull();
|
|
300
|
+
|
|
301
|
+
const scrollEvent = new WheelEvent("wheel", {
|
|
302
|
+
bubbles: true,
|
|
303
|
+
cancelable: true,
|
|
304
|
+
deltaY: 80,
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
expect(overlay.dispatchEvent(scrollEvent)).toBe(true);
|
|
308
|
+
expect(scrollEvent.defaultPrevented).toBe(false);
|
|
309
|
+
expect(screen.getByTestId("canvas-zoom").textContent).toBe("70");
|
|
310
|
+
expect(screen.getByTestId("canvas-offset").textContent).toBe("0,0");
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it("prevents browser pinch zoom when canvas zoom is already clamped", () => {
|
|
314
|
+
render(
|
|
315
|
+
<ToolcraftRoot
|
|
316
|
+
initialState={{
|
|
317
|
+
canvas: {
|
|
318
|
+
offset: { x: 0, y: 0 },
|
|
319
|
+
size: { height: 200, unit: "px", width: 300 },
|
|
320
|
+
zoom: 400,
|
|
321
|
+
},
|
|
322
|
+
}}
|
|
323
|
+
schema={createSchema()}
|
|
324
|
+
>
|
|
325
|
+
<div style={{ height: 640, position: "relative", width: 640 }}>
|
|
326
|
+
<CanvasShell />
|
|
327
|
+
<CanvasStateProbe />
|
|
328
|
+
</div>
|
|
329
|
+
</ToolcraftRoot>,
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
const canvas = screen.getByRole("application", { name: "Canvas viewport" });
|
|
333
|
+
mockCanvasRect(canvas);
|
|
334
|
+
|
|
335
|
+
const wheelEvent = new WheelEvent("wheel", {
|
|
336
|
+
bubbles: true,
|
|
337
|
+
cancelable: true,
|
|
338
|
+
clientX: 600,
|
|
339
|
+
clientY: 300,
|
|
340
|
+
ctrlKey: true,
|
|
341
|
+
deltaY: -100,
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
expect(canvas.dispatchEvent(wheelEvent)).toBe(false);
|
|
345
|
+
expect(wheelEvent.defaultPrevented).toBe(true);
|
|
346
|
+
expect(screen.getByTestId("canvas-zoom").textContent).toBe("400");
|
|
347
|
+
expect(screen.getByTestId("canvas-offset").textContent).toBe("0,0");
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it("imports dropped images using editable canvas size", async () => {
|
|
351
|
+
render(
|
|
352
|
+
<ToolcraftRoot schema={createSchema()}>
|
|
353
|
+
<div style={{ height: 640, position: "relative", width: 640 }}>
|
|
354
|
+
<CanvasShell />
|
|
355
|
+
<CanvasStateProbe />
|
|
356
|
+
</div>
|
|
357
|
+
</ToolcraftRoot>,
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
const canvas = screen.getByRole("application", { name: "Canvas viewport" });
|
|
361
|
+
const file = new File(["image"], "material.png", { type: "image/png" });
|
|
362
|
+
|
|
363
|
+
fireEvent.drop(canvas, {
|
|
364
|
+
clientX: 0,
|
|
365
|
+
clientY: 0,
|
|
366
|
+
dataTransfer: {
|
|
367
|
+
files: [file],
|
|
368
|
+
},
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
await waitFor(() => {
|
|
372
|
+
expect(screen.getByTestId("media-count").textContent).toBe("1");
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
expect(screen.getByTestId("media-size").textContent).toBe("300,200");
|
|
376
|
+
expect(screen.getByRole("button", { name: "Select material.png" })).toBeTruthy();
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it("hides media when a parent layer group is hidden", () => {
|
|
380
|
+
render(
|
|
381
|
+
<ToolcraftRoot
|
|
382
|
+
initialState={{
|
|
383
|
+
layers: [
|
|
384
|
+
{
|
|
385
|
+
collapsed: false,
|
|
386
|
+
displayName: "Scene Group",
|
|
387
|
+
id: "group-1",
|
|
388
|
+
kind: "group",
|
|
389
|
+
name: "scene-group",
|
|
390
|
+
visible: false,
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
displayName: "Layer 1",
|
|
394
|
+
id: "layer-1",
|
|
395
|
+
kind: "layer",
|
|
396
|
+
name: "layer-1",
|
|
397
|
+
parentGroupId: "group-1",
|
|
398
|
+
visible: true,
|
|
399
|
+
},
|
|
400
|
+
],
|
|
401
|
+
mediaAssets: [
|
|
402
|
+
{
|
|
403
|
+
dataUrl: "data:image/png;base64,test",
|
|
404
|
+
fileName: "material.png",
|
|
405
|
+
id: "media-1",
|
|
406
|
+
layerId: "layer-1",
|
|
407
|
+
mimeType: "image/png",
|
|
408
|
+
position: { x: 0, y: 0 },
|
|
409
|
+
size: { height: 200, unit: "px", width: 300 },
|
|
410
|
+
},
|
|
411
|
+
],
|
|
412
|
+
selectedLayerId: "layer-1",
|
|
413
|
+
}}
|
|
414
|
+
schema={createSchema()}
|
|
415
|
+
>
|
|
416
|
+
<div style={{ height: 640, position: "relative", width: 640 }}>
|
|
417
|
+
<CanvasShell />
|
|
418
|
+
</div>
|
|
419
|
+
</ToolcraftRoot>,
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
expect(screen.queryByRole("button", { name: "Select material.png" })).toBeNull();
|
|
423
|
+
});
|
|
424
|
+
});
|