@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.
Files changed (257) hide show
  1. package/LICENSE.md +98 -0
  2. package/README.md +41 -0
  3. package/bin/create-toolcraft-app.mjs +8 -0
  4. package/bin/toolcraft.mjs +8 -0
  5. package/package.json +24 -0
  6. package/scripts/prepare-pack.mjs +29 -0
  7. package/src/cli.mjs +392 -0
  8. package/src/cli.test.mjs +284 -0
  9. package/src/copy-recursive.mjs +86 -0
  10. package/src/generate.mjs +212 -0
  11. package/src/generate.test.mjs +322 -0
  12. package/src/import-map.mjs +14 -0
  13. package/src/package-json.mjs +80 -0
  14. package/src/package-json.test.mjs +67 -0
  15. package/src/rewrite-imports.mjs +85 -0
  16. package/src/rewrite-imports.test.mjs +58 -0
  17. package/templates/runtime/contracts/component-contracts.test.ts +1165 -0
  18. package/templates/runtime/contracts/component-contracts.ts +1340 -0
  19. package/templates/runtime/contracts/decision-contracts.test.ts +206 -0
  20. package/templates/runtime/contracts/decision-contracts.ts +283 -0
  21. package/templates/runtime/contracts/index.test.ts +14 -0
  22. package/templates/runtime/contracts/index.ts +3 -0
  23. package/templates/runtime/contracts/types.ts +56 -0
  24. package/templates/runtime/export/export.test.ts +203 -0
  25. package/templates/runtime/export/export.ts +132 -0
  26. package/templates/runtime/export/index.ts +1 -0
  27. package/templates/runtime/index.ts +14 -0
  28. package/templates/runtime/react/canvas-shell.test.tsx +424 -0
  29. package/templates/runtime/react/canvas-shell.tsx +408 -0
  30. package/templates/runtime/react/control-renderers.ts +31 -0
  31. package/templates/runtime/react/controls-panel.test.tsx +3736 -0
  32. package/templates/runtime/react/controls-panel.tsx +2327 -0
  33. package/templates/runtime/react/curve-geometry.test.ts +70 -0
  34. package/templates/runtime/react/index.ts +15 -0
  35. package/templates/runtime/react/layer-tree.ts +96 -0
  36. package/templates/runtime/react/layers-panel.test.tsx +487 -0
  37. package/templates/runtime/react/layers-panel.tsx +1348 -0
  38. package/templates/runtime/react/media-file.ts +82 -0
  39. package/templates/runtime/react/panel-host-config.ts +80 -0
  40. package/templates/runtime/react/panel-host-geometry.test.ts +66 -0
  41. package/templates/runtime/react/panel-host-geometry.ts +109 -0
  42. package/templates/runtime/react/panel-host-types.ts +74 -0
  43. package/templates/runtime/react/panel-host.test.tsx +102 -0
  44. package/templates/runtime/react/panel-host.tsx +353 -0
  45. package/templates/runtime/react/runtime-public-api.test.tsx +132 -0
  46. package/templates/runtime/react/settings-transfer.test.ts +150 -0
  47. package/templates/runtime/react/settings-transfer.ts +279 -0
  48. package/templates/runtime/react/storage-key-migration.ts +48 -0
  49. package/templates/runtime/react/theme-runtime.tsx +177 -0
  50. package/templates/runtime/react/timeline-panel.test.tsx +668 -0
  51. package/templates/runtime/react/timeline-panel.tsx +2953 -0
  52. package/templates/runtime/react/toolbar-panel.test.tsx +212 -0
  53. package/templates/runtime/react/toolbar-panel.tsx +205 -0
  54. package/templates/runtime/react/toolcraft-app.integration.test.tsx +350 -0
  55. package/templates/runtime/react/toolcraft-app.test.tsx +339 -0
  56. package/templates/runtime/react/toolcraft-app.tsx +81 -0
  57. package/templates/runtime/react/toolcraft-root.test.tsx +347 -0
  58. package/templates/runtime/react/toolcraft-root.tsx +203 -0
  59. package/templates/runtime/react/use-toolcraft.ts +41 -0
  60. package/templates/runtime/schema/define-toolcraft.test.ts +1524 -0
  61. package/templates/runtime/schema/define-toolcraft.ts +1442 -0
  62. package/templates/runtime/schema/keyframe-capability.test.ts +90 -0
  63. package/templates/runtime/schema/keyframe-capability.ts +51 -0
  64. package/templates/runtime/schema/runtime-targets.ts +40 -0
  65. package/templates/runtime/schema/types.ts +370 -0
  66. package/templates/runtime/state/canvas-zoom.ts +8 -0
  67. package/templates/runtime/state/create-template-state.test.ts +242 -0
  68. package/templates/runtime/state/create-template-state.ts +95 -0
  69. package/templates/runtime/state/keyframe-evaluation.test.ts +141 -0
  70. package/templates/runtime/state/keyframe-evaluation.ts +203 -0
  71. package/templates/runtime/state/persistence.test.ts +217 -0
  72. package/templates/runtime/state/persistence.ts +511 -0
  73. package/templates/runtime/state/reducer.test.ts +937 -0
  74. package/templates/runtime/state/reducer.ts +1212 -0
  75. package/templates/runtime/state/timeline-readiness.ts +43 -0
  76. package/templates/runtime/state/types.ts +242 -0
  77. package/templates/runtime/styles.css +125 -0
  78. package/templates/runtime/testing/performance.test.ts +1058 -0
  79. package/templates/runtime/testing/performance.ts +1078 -0
  80. package/templates/starter/AGENTS.md +186 -0
  81. package/templates/starter/LICENSE.md +98 -0
  82. package/templates/starter/NOTICE.md +8 -0
  83. package/templates/starter/docs/toolcraft/README.md +41 -0
  84. package/templates/starter/docs/toolcraft/acceptance-testing.md +205 -0
  85. package/templates/starter/docs/toolcraft/agent-worklog.md +81 -0
  86. package/templates/starter/docs/toolcraft/assembly-workflow.md +206 -0
  87. package/templates/starter/docs/toolcraft/component-rules.md +299 -0
  88. package/templates/starter/docs/toolcraft/custom-controls.md +71 -0
  89. package/templates/starter/docs/toolcraft/decision-contract.md +71 -0
  90. package/templates/starter/docs/toolcraft/performance.md +112 -0
  91. package/templates/starter/docs/toolcraft/renderer-technique.md +48 -0
  92. package/templates/starter/docs/toolcraft/schema-reference.md +265 -0
  93. package/templates/starter/docs/toolcraft/workflow.md +87 -0
  94. package/templates/starter/e2e/app-browser-acceptance.spec.ts +785 -0
  95. package/templates/starter/e2e/app-controls.spec.ts +41 -0
  96. package/templates/starter/e2e/app-performance.spec.ts +326 -0
  97. package/templates/starter/e2e/canvas-handle-helpers.ts +244 -0
  98. package/templates/starter/e2e/performance-helpers.ts +612 -0
  99. package/templates/starter/e2e/product-observable-helpers.ts +170 -0
  100. package/templates/starter/index.html +12 -0
  101. package/templates/starter/package.json +52 -0
  102. package/templates/starter/playwright.config.ts +43 -0
  103. package/templates/starter/scripts/check-ai-skills.mjs +95 -0
  104. package/templates/starter/scripts/check-toolcraft-docs.mjs +159 -0
  105. package/templates/starter/scripts/check-toolcraft-integrity.mjs +232 -0
  106. package/templates/starter/scripts/run-vite-on-free-port.mjs +48 -0
  107. package/templates/starter/scripts/toolcraft-port.mjs +54 -0
  108. package/templates/starter/scripts/toolcraft-port.test.mjs +73 -0
  109. package/templates/starter/src/app/starter-acceptance.test.ts +5959 -0
  110. package/templates/starter/src/app/starter-acceptance.ts +2646 -0
  111. package/templates/starter/src/app/starter-performance.test.ts +1390 -0
  112. package/templates/starter/src/app/starter-performance.ts +12 -0
  113. package/templates/starter/src/app/starter-schema.test.ts +70 -0
  114. package/templates/starter/src/app/starter-schema.ts +15 -0
  115. package/templates/starter/src/main.tsx +18 -0
  116. package/templates/starter/src/router.tsx +16 -0
  117. package/templates/starter/src/routes/index.tsx +7 -0
  118. package/templates/starter/src/routes/root.tsx +19 -0
  119. package/templates/starter/src/styles.css +120 -0
  120. package/templates/starter/tsconfig.json +11 -0
  121. package/templates/starter/vite.config.ts +13 -0
  122. package/templates/ui/components/composites/accordion.tsx +73 -0
  123. package/templates/ui/components/composites/alert-dialog.tsx +190 -0
  124. package/templates/ui/components/composites/alert.tsx +74 -0
  125. package/templates/ui/components/composites/aspect-ratio.tsx +22 -0
  126. package/templates/ui/components/composites/avatar.tsx +98 -0
  127. package/templates/ui/components/composites/badge.tsx +69 -0
  128. package/templates/ui/components/composites/breadcrumb.tsx +106 -0
  129. package/templates/ui/components/composites/card.tsx +91 -0
  130. package/templates/ui/components/composites/combobox.tsx +486 -0
  131. package/templates/ui/components/composites/command.tsx +296 -0
  132. package/templates/ui/components/composites/context-menu.tsx +247 -0
  133. package/templates/ui/components/composites/dialog.tsx +282 -0
  134. package/templates/ui/components/composites/dropdown-menu.tsx +299 -0
  135. package/templates/ui/components/composites/empty.tsx +110 -0
  136. package/templates/ui/components/composites/hover-card.tsx +44 -0
  137. package/templates/ui/components/composites/index.ts +30 -0
  138. package/templates/ui/components/composites/menubar.tsx +214 -0
  139. package/templates/ui/components/composites/navigation-menu.tsx +167 -0
  140. package/templates/ui/components/composites/pagination.tsx +131 -0
  141. package/templates/ui/components/composites/progress.tsx +72 -0
  142. package/templates/ui/components/composites/radio-group.tsx +84 -0
  143. package/templates/ui/components/composites/resizable.tsx +42 -0
  144. package/templates/ui/components/composites/sheet.tsx +153 -0
  145. package/templates/ui/components/composites/sidebar-structural.tsx +310 -0
  146. package/templates/ui/components/composites/sidebar.tsx +431 -0
  147. package/templates/ui/components/composites/sonner.tsx +35 -0
  148. package/templates/ui/components/composites/spinner.tsx +43 -0
  149. package/templates/ui/components/composites/table.tsx +108 -0
  150. package/templates/ui/components/composites/tabs.tsx +83 -0
  151. package/templates/ui/components/control-layout/index.tsx +437 -0
  152. package/templates/ui/components/controls/actions/actions-control.tsx +139 -0
  153. package/templates/ui/components/controls/actions/index.ts +9 -0
  154. package/templates/ui/components/controls/anchor-grid/anchor-grid-control.tsx +107 -0
  155. package/templates/ui/components/controls/anchor-grid/index.ts +4 -0
  156. package/templates/ui/components/controls/boolean/boolean-controls.tsx +79 -0
  157. package/templates/ui/components/controls/boolean/index.ts +4 -0
  158. package/templates/ui/components/controls/channel-mixer/channel-mixer-control.tsx +95 -0
  159. package/templates/ui/components/controls/channel-mixer/index.ts +4 -0
  160. package/templates/ui/components/controls/channel-tabs/channel-tabs.tsx +42 -0
  161. package/templates/ui/components/controls/channel-tabs/index.ts +6 -0
  162. package/templates/ui/components/controls/code-textarea/code-textarea-control.tsx +90 -0
  163. package/templates/ui/components/controls/code-textarea/index.ts +4 -0
  164. package/templates/ui/components/controls/color/color-control.tsx +571 -0
  165. package/templates/ui/components/controls/color/color-picker-popover.tsx +104 -0
  166. package/templates/ui/components/controls/color/index.ts +41 -0
  167. package/templates/ui/components/controls/color/palette-control-data.ts +436 -0
  168. package/templates/ui/components/controls/color/palette-control.tsx +535 -0
  169. package/templates/ui/components/controls/color/style-guide-color-picker-channel-utils.ts +162 -0
  170. package/templates/ui/components/controls/color/style-guide-color-picker-interactions.ts +190 -0
  171. package/templates/ui/components/controls/color/style-guide-color-picker-logic.ts +485 -0
  172. package/templates/ui/components/controls/color/style-guide-color-picker-parts.tsx +710 -0
  173. package/templates/ui/components/controls/color/style-guide-color-picker.tsx +503 -0
  174. package/templates/ui/components/controls/control-types.ts +43 -0
  175. package/templates/ui/components/controls/curves/curve-geometry.ts +355 -0
  176. package/templates/ui/components/controls/curves/curve-graph.tsx +390 -0
  177. package/templates/ui/components/controls/curves/curves-control.tsx +445 -0
  178. package/templates/ui/components/controls/curves/index.ts +6 -0
  179. package/templates/ui/components/controls/file-drop/file-drop-control.tsx +191 -0
  180. package/templates/ui/components/controls/file-drop/index.ts +5 -0
  181. package/templates/ui/components/controls/font-picker/font-catalog.json +15360 -0
  182. package/templates/ui/components/controls/font-picker/font-catalog.ts +116 -0
  183. package/templates/ui/components/controls/font-picker/font-picker-control.tsx +1202 -0
  184. package/templates/ui/components/controls/font-picker/font-preview-loader.ts +336 -0
  185. package/templates/ui/components/controls/font-picker/index.ts +24 -0
  186. package/templates/ui/components/controls/font-picker/use-hover-intent.ts +46 -0
  187. package/templates/ui/components/controls/gradient/gradient-control-utils.ts +190 -0
  188. package/templates/ui/components/controls/gradient/gradient-control.tsx +612 -0
  189. package/templates/ui/components/controls/gradient/gradient-stop-list.tsx +400 -0
  190. package/templates/ui/components/controls/gradient/gradient-toolbar.tsx +152 -0
  191. package/templates/ui/components/controls/gradient/index.ts +4 -0
  192. package/templates/ui/components/controls/image-picker/image-picker-control.tsx +139 -0
  193. package/templates/ui/components/controls/image-picker/index.ts +7 -0
  194. package/templates/ui/components/controls/index.ts +192 -0
  195. package/templates/ui/components/controls/range-input/index.ts +4 -0
  196. package/templates/ui/components/controls/range-input/range-input-control.tsx +173 -0
  197. package/templates/ui/components/controls/range-slider/index.ts +4 -0
  198. package/templates/ui/components/controls/range-slider/range-slider-control.tsx +122 -0
  199. package/templates/ui/components/controls/range-slider/range-slider-value.ts +61 -0
  200. package/templates/ui/components/controls/segmented/index.ts +8 -0
  201. package/templates/ui/components/controls/segmented/segmented-control.tsx +94 -0
  202. package/templates/ui/components/controls/select/index.ts +4 -0
  203. package/templates/ui/components/controls/select/select-control.tsx +223 -0
  204. package/templates/ui/components/controls/slider/index.ts +4 -0
  205. package/templates/ui/components/controls/slider/slider-control.tsx +150 -0
  206. package/templates/ui/components/controls/slider/slider-value.ts +56 -0
  207. package/templates/ui/components/controls/text-input/index.ts +4 -0
  208. package/templates/ui/components/controls/text-input/text-input-control.tsx +158 -0
  209. package/templates/ui/components/controls/use-measured-element-width.ts +42 -0
  210. package/templates/ui/components/controls/vector/index.ts +8 -0
  211. package/templates/ui/components/controls/vector/vector-control.tsx +401 -0
  212. package/templates/ui/components/panel/index.ts +19 -0
  213. package/templates/ui/components/panel/panel-actions.tsx +165 -0
  214. package/templates/ui/components/panel/panel-header.tsx +61 -0
  215. package/templates/ui/components/panel/panel-icon-button.tsx +96 -0
  216. package/templates/ui/components/panel/panel-section.tsx +168 -0
  217. package/templates/ui/components/panel/panel-surface.tsx +206 -0
  218. package/templates/ui/components/panel/panel.tsx +210 -0
  219. package/templates/ui/components/primitives/animated-loader.tsx +61 -0
  220. package/templates/ui/components/primitives/button-group.tsx +134 -0
  221. package/templates/ui/components/primitives/button.tsx +429 -0
  222. package/templates/ui/components/primitives/checkbox.tsx +62 -0
  223. package/templates/ui/components/primitives/editable-slider-value-label.tsx +337 -0
  224. package/templates/ui/components/primitives/field.tsx +225 -0
  225. package/templates/ui/components/primitives/index.ts +82 -0
  226. package/templates/ui/components/primitives/input-group.tsx +298 -0
  227. package/templates/ui/components/primitives/input.tsx +61 -0
  228. package/templates/ui/components/primitives/internal/button-loading.tsx +178 -0
  229. package/templates/ui/components/primitives/label.tsx +16 -0
  230. package/templates/ui/components/primitives/popover.tsx +126 -0
  231. package/templates/ui/components/primitives/portal-layer-context.tsx +33 -0
  232. package/templates/ui/components/primitives/primitive-arrow-icon.tsx +38 -0
  233. package/templates/ui/components/primitives/scroll-fade-logic.ts +441 -0
  234. package/templates/ui/components/primitives/scroll-fade-render.tsx +75 -0
  235. package/templates/ui/components/primitives/scroll-fade-types.ts +41 -0
  236. package/templates/ui/components/primitives/scroll-fade.tsx +72 -0
  237. package/templates/ui/components/primitives/select.tsx +408 -0
  238. package/templates/ui/components/primitives/selection-state.ts +31 -0
  239. package/templates/ui/components/primitives/separator.tsx +21 -0
  240. package/templates/ui/components/primitives/slider/index.ts +4 -0
  241. package/templates/ui/components/primitives/slider/slider-interaction.tsx +96 -0
  242. package/templates/ui/components/primitives/slider/slider-parts.tsx +303 -0
  243. package/templates/ui/components/primitives/slider/slider-reset.ts +152 -0
  244. package/templates/ui/components/primitives/slider/slider-value.ts +114 -0
  245. package/templates/ui/components/primitives/slider/slider.tsx +511 -0
  246. package/templates/ui/components/primitives/switch.tsx +35 -0
  247. package/templates/ui/components/primitives/textarea.tsx +49 -0
  248. package/templates/ui/components/primitives/toggle-group.tsx +114 -0
  249. package/templates/ui/components/primitives/toggle.tsx +46 -0
  250. package/templates/ui/components/primitives/tooltip.tsx +100 -0
  251. package/templates/ui/hooks/use-mobile.ts +21 -0
  252. package/templates/ui/index.ts +31 -0
  253. package/templates/ui/lib/control-outline.ts +3 -0
  254. package/templates/ui/lib/input-control-style.ts +131 -0
  255. package/templates/ui/lib/style-guide-color-utils.ts +111 -0
  256. package/templates/ui/lib/utils.ts +6 -0
  257. package/templates/ui/styles.css +291 -0
@@ -0,0 +1,668 @@
1
+ import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
2
+ import * as React from "react";
3
+ import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
4
+
5
+ import { defineToolcraft } from "../schema/define-toolcraft";
6
+ import type { ToolcraftTimelinePanelSchema } from "../schema/types";
7
+ import type { ToolcraftInitialState } from "../state/types";
8
+ import { ToolcraftRoot } from "./toolcraft-root";
9
+ import { TimelinePanel } from "./timeline-panel";
10
+ import { useToolcraft } from "./use-toolcraft";
11
+
12
+ beforeAll(() => {
13
+ Object.defineProperty(window, "matchMedia", {
14
+ value: (query: string) => ({
15
+ addEventListener: () => undefined,
16
+ addListener: () => undefined,
17
+ dispatchEvent: () => false,
18
+ matches: query === "(prefers-reduced-motion: reduce)",
19
+ media: query,
20
+ onchange: null,
21
+ removeEventListener: () => undefined,
22
+ removeListener: () => undefined,
23
+ }),
24
+ writable: true,
25
+ });
26
+ });
27
+
28
+ afterEach(() => {
29
+ cleanup();
30
+ vi.restoreAllMocks();
31
+ });
32
+
33
+ function createSchema(timeline: ToolcraftTimelinePanelSchema = true) {
34
+ return defineToolcraft({
35
+ canvas: { enabled: true },
36
+ panels: {
37
+ timeline,
38
+ },
39
+ });
40
+ }
41
+
42
+ function StateProbe() {
43
+ const { state } = useToolcraft();
44
+
45
+ return (
46
+ <>
47
+ <span data-testid="timeline-playing">{String(state.timeline.isPlaying)}</span>
48
+ <span data-testid="timeline-looping">{String(state.timeline.isLooping)}</span>
49
+ <span data-testid="timeline-time">{String(state.timeline.currentTimeSeconds)}</span>
50
+ <span data-testid="timeline-expanded">{String(state.timeline.expanded)}</span>
51
+ </>
52
+ );
53
+ }
54
+
55
+ function renderTimelinePanel(
56
+ props: Partial<React.ComponentProps<typeof TimelinePanel>> = {},
57
+ initialState?: ToolcraftInitialState,
58
+ timeline?: ToolcraftTimelinePanelSchema,
59
+ ) {
60
+ return render(
61
+ <ToolcraftRoot initialState={initialState} schema={createSchema(timeline)}>
62
+ <TimelinePanel framed={false} {...props} />
63
+ <StateProbe />
64
+ </ToolcraftRoot>,
65
+ );
66
+ }
67
+
68
+ function renderUploadDependentTimelinePanel(
69
+ initialState?: ToolcraftInitialState,
70
+ ) {
71
+ const schema = defineToolcraft({
72
+ canvas: {
73
+ enabled: true,
74
+ sizing: { mode: "intrinsic-media" },
75
+ upload: true,
76
+ },
77
+ panels: {
78
+ timeline: { mode: "playback" },
79
+ },
80
+ });
81
+
82
+ return render(
83
+ <ToolcraftRoot initialState={initialState} schema={schema}>
84
+ <TimelinePanel framed={false} />
85
+ <StateProbe />
86
+ </ToolcraftRoot>,
87
+ );
88
+ }
89
+
90
+ describe("TimelinePanel", () => {
91
+ it("stays collapsed by default in the runtime contract", () => {
92
+ renderTimelinePanel();
93
+
94
+ expect(screen.getByTestId("timeline-expanded").textContent).toBe("false");
95
+ expect(screen.getByText("Dur:")).toBeTruthy();
96
+ expect(screen.queryByText("Duration:")).toBeNull();
97
+ expect(screen.queryByText("Add your first keyframe from the properties panel.")).toBeNull();
98
+ });
99
+
100
+ it("renders timeline state and dispatches playback commands", () => {
101
+ renderTimelinePanel();
102
+
103
+ expect(screen.getByText("8s")).toBeTruthy();
104
+ expect(screen.getByText("Dur:")).toBeTruthy();
105
+ expect(screen.queryByText("Duration:")).toBeNull();
106
+ expect(screen.getByTestId("timeline-playing").textContent).toBe("true");
107
+ expect(screen.getByTestId("timeline-looping").textContent).toBe("true");
108
+ expect(screen.getByTestId("timeline-expanded").textContent).toBe("false");
109
+
110
+ fireEvent.click(screen.getByRole("button", { name: "Pause playback" }));
111
+ expect(screen.getByTestId("timeline-playing").textContent).toBe("false");
112
+
113
+ fireEvent.click(screen.getByRole("button", { name: "Disable loop" }));
114
+ expect(screen.getByTestId("timeline-looping").textContent).toBe("false");
115
+ });
116
+
117
+ it("replays from the beginning when play is pressed at the non-looping end", () => {
118
+ renderTimelinePanel(
119
+ {},
120
+ {
121
+ timeline: {
122
+ currentTimeSeconds: 8,
123
+ isLooping: false,
124
+ isPlaying: false,
125
+ },
126
+ },
127
+ { mode: "playback" },
128
+ );
129
+
130
+ expect(screen.getByTestId("timeline-time").textContent).toBe("8");
131
+
132
+ fireEvent.click(screen.getByRole("button", { name: "Play playback" }));
133
+
134
+ expect(screen.getByTestId("timeline-time").textContent).toBe("0");
135
+ expect(screen.getByTestId("timeline-playing").textContent).toBe("true");
136
+ });
137
+
138
+ it("persists expanded state in the shared runtime timeline", () => {
139
+ renderTimelinePanel();
140
+
141
+ fireEvent.click(screen.getByRole("button", { name: "Expand timeline panel" }));
142
+
143
+ expect(screen.getByTestId("timeline-expanded").textContent).toBe("true");
144
+ expect(screen.getByText("Duration:")).toBeTruthy();
145
+ expect(screen.getByText("Add your first keyframe from the properties panel.")).toBeTruthy();
146
+ expect(screen.queryByText("Dur:")).toBeNull();
147
+ });
148
+
149
+ it("renders playback-only timelines without an expanded keyframe editor", () => {
150
+ const { container } = renderTimelinePanel(
151
+ {},
152
+ {
153
+ timeline: {
154
+ expanded: true,
155
+ keyframeGroups: [
156
+ {
157
+ controlId: "selectedLayer.opacity",
158
+ keyframes: [
159
+ {
160
+ controlId: "selectedLayer.opacity",
161
+ controlLabel: "Opacity",
162
+ id: "selectedLayer.opacity::4",
163
+ timeSeconds: 4,
164
+ valueLabel: "75%",
165
+ },
166
+ ],
167
+ label: "Opacity",
168
+ },
169
+ ],
170
+ },
171
+ },
172
+ { mode: "playback" },
173
+ );
174
+
175
+ expect(screen.getByText("Dur:")).toBeTruthy();
176
+ expect(screen.queryByRole("button", { name: "Expand timeline panel" })).toBeNull();
177
+ expect(screen.queryByText("Duration:")).toBeNull();
178
+ expect(screen.queryByText("Opacity")).toBeNull();
179
+ expect(screen.queryByText("Add your first keyframe from the properties panel.")).toBeNull();
180
+ expect(screen.getByRole("button", { name: "Pause playback" })).toBeTruthy();
181
+ expect(
182
+ container.querySelector('[data-slot="timeline-panel"] > [data-panel-id="timeline"]')
183
+ ?.className,
184
+ ).toContain("pr-3");
185
+ });
186
+
187
+ it("keeps upload-dependent playback inert until source media exists", () => {
188
+ renderUploadDependentTimelinePanel({
189
+ timeline: {
190
+ currentTimeSeconds: 4,
191
+ isPlaying: true,
192
+ },
193
+ });
194
+
195
+ const playButton = screen.getByRole("button", { name: "Play playback" });
196
+
197
+ expect((playButton as HTMLButtonElement).disabled).toBe(true);
198
+ expect(screen.getByTestId("timeline-playing").textContent).toBe("false");
199
+ expect(screen.getByTestId("timeline-time").textContent).toBe("0");
200
+
201
+ fireEvent.click(playButton);
202
+
203
+ expect(screen.getByTestId("timeline-playing").textContent).toBe("false");
204
+ expect(screen.getByTestId("timeline-time").textContent).toBe("0");
205
+ });
206
+
207
+ it("keeps upload-dependent playback available when source media exists", () => {
208
+ renderUploadDependentTimelinePanel({
209
+ mediaAssets: [
210
+ {
211
+ dataUrl: "data:image/png;base64,AAAA",
212
+ fileName: "source.png",
213
+ id: "media-1",
214
+ layerId: "layer-1",
215
+ mimeType: "image/png",
216
+ position: { x: 0, y: 0 },
217
+ size: { height: 320, unit: "px", width: 512 },
218
+ },
219
+ ],
220
+ });
221
+
222
+ expect(
223
+ (screen.getByRole("button", { name: "Pause playback" }) as HTMLButtonElement)
224
+ .disabled,
225
+ ).toBe(false);
226
+ expect(screen.getByTestId("timeline-playing").textContent).toBe("true");
227
+ });
228
+
229
+ it("delegates the whole timeline window size to motion during expand and collapse", () => {
230
+ const { container } = renderTimelinePanel({ panelPlacement: "floating" });
231
+ const timelinePanel = container.querySelector<HTMLElement>('[data-slot="timeline-panel"]');
232
+
233
+ expect(timelinePanel?.style.width).toBe("256px");
234
+ expect(timelinePanel?.style.height).toBe("36px");
235
+
236
+ fireEvent.click(screen.getByRole("button", { name: "Expand timeline panel" }));
237
+
238
+ expect(timelinePanel?.getAttribute("data-expanded-height")).toBe("110");
239
+
240
+ fireEvent.click(screen.getByRole("button", { name: "Collapse timeline panel" }));
241
+
242
+ expect(timelinePanel?.getAttribute("data-expanded-height")).toBeNull();
243
+ });
244
+
245
+ it("points the expand toggle down when collapsed and up when expanded", () => {
246
+ const { container } = renderTimelinePanel();
247
+
248
+ const getArrowIcon = () => container.querySelector('[data-slot="primitive-arrow-icon"]');
249
+
250
+ expect(getArrowIcon()?.classList.contains("rotate-180")).toBe(false);
251
+
252
+ fireEvent.click(screen.getByRole("button", { name: "Expand timeline panel" }));
253
+
254
+ expect(getArrowIcon()?.classList.contains("rotate-180")).toBe(true);
255
+ });
256
+
257
+ it("uses the shared panel host when floating", () => {
258
+ const { container } = renderTimelinePanel({ panelPlacement: "floating" });
259
+
260
+ expect(container.querySelector('[data-panel-type="timeline"]')).toBeTruthy();
261
+ expect(container.querySelector('[data-snap-edges="top bottom"]')).toBeTruthy();
262
+ });
263
+
264
+ it("moves the expanded floating timeline from the stable host position before narrowing", async () => {
265
+ vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(function (
266
+ this: HTMLElement,
267
+ ) {
268
+ if (this.matches('[data-slot="toolcraft-runtime-app"]')) {
269
+ return {
270
+ bottom: 720,
271
+ height: 720,
272
+ left: 0,
273
+ right: 960,
274
+ toJSON: () => ({}),
275
+ top: 0,
276
+ width: 960,
277
+ x: 0,
278
+ y: 0,
279
+ };
280
+ }
281
+
282
+ if (this.matches('[data-panel-type="controls"]')) {
283
+ return {
284
+ bottom: 560,
285
+ height: 560,
286
+ left: 10,
287
+ right: 40,
288
+ toJSON: () => ({}),
289
+ top: 10,
290
+ width: 30,
291
+ x: 10,
292
+ y: 10,
293
+ };
294
+ }
295
+
296
+ if (this.matches('[data-panel-type="layers"]')) {
297
+ return {
298
+ bottom: 560,
299
+ height: 560,
300
+ left: 760,
301
+ right: 950,
302
+ toJSON: () => ({}),
303
+ top: 10,
304
+ width: 190,
305
+ x: 760,
306
+ y: 10,
307
+ };
308
+ }
309
+
310
+ if (
311
+ this.matches('[data-slot="toolcraft-runtime-panel-host"]') &&
312
+ this.matches('[data-panel-type="timeline"]')
313
+ ) {
314
+ return {
315
+ bottom: 128,
316
+ height: 118,
317
+ left: 136,
318
+ right: 824,
319
+ toJSON: () => ({}),
320
+ top: 10,
321
+ width: 688,
322
+ x: 136,
323
+ y: 10,
324
+ };
325
+ }
326
+
327
+ if (this.matches('[data-slot="timeline-panel"]')) {
328
+ return {
329
+ bottom: 128,
330
+ height: 118,
331
+ left: 99,
332
+ right: 787,
333
+ toJSON: () => ({}),
334
+ top: 10,
335
+ width: 688,
336
+ x: 99,
337
+ y: 10,
338
+ };
339
+ }
340
+
341
+ return {
342
+ bottom: 0,
343
+ height: 0,
344
+ left: 0,
345
+ right: 0,
346
+ toJSON: () => ({}),
347
+ top: 0,
348
+ width: 0,
349
+ x: 0,
350
+ y: 0,
351
+ };
352
+ });
353
+
354
+ const { container } = render(
355
+ <ToolcraftRoot
356
+ initialState={{ timeline: { expanded: true } }}
357
+ schema={createSchema()}
358
+ >
359
+ <div data-slot="toolcraft-runtime-app">
360
+ <div data-panel-type="controls" />
361
+ <div data-panel-type="layers" />
362
+ <TimelinePanel framed={false} panelPlacement="floating" />
363
+ </div>
364
+ </ToolcraftRoot>,
365
+ );
366
+
367
+ const timelinePanel = container.querySelector<HTMLElement>('[data-slot="timeline-panel"]');
368
+
369
+ await waitFor(() => {
370
+ expect(timelinePanel?.getAttribute("data-responsive-offset-x")).toBe("-74");
371
+ expect(timelinePanel?.getAttribute("data-responsive-width")).toBeNull();
372
+ });
373
+ });
374
+
375
+ it("narrows expanded floating timeline after it reaches both side panels", async () => {
376
+ vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(function (
377
+ this: HTMLElement,
378
+ ) {
379
+ if (this.matches('[data-slot="toolcraft-runtime-app"]')) {
380
+ return {
381
+ bottom: 720,
382
+ height: 720,
383
+ left: 0,
384
+ right: 960,
385
+ toJSON: () => ({}),
386
+ top: 0,
387
+ width: 960,
388
+ x: 0,
389
+ y: 0,
390
+ };
391
+ }
392
+
393
+ if (this.matches('[data-panel-type="layers"]')) {
394
+ return {
395
+ bottom: 560,
396
+ height: 560,
397
+ left: 10,
398
+ right: 250,
399
+ toJSON: () => ({}),
400
+ top: 10,
401
+ width: 240,
402
+ x: 10,
403
+ y: 10,
404
+ };
405
+ }
406
+
407
+ if (this.matches('[data-panel-type="controls"]')) {
408
+ return {
409
+ bottom: 560,
410
+ height: 560,
411
+ left: 650,
412
+ right: 950,
413
+ toJSON: () => ({}),
414
+ top: 10,
415
+ width: 300,
416
+ x: 650,
417
+ y: 10,
418
+ };
419
+ }
420
+
421
+ if (this.matches('[data-slot="timeline-panel"]')) {
422
+ return {
423
+ bottom: 128,
424
+ height: 118,
425
+ left: 136,
426
+ right: 824,
427
+ toJSON: () => ({}),
428
+ top: 10,
429
+ width: 688,
430
+ x: 136,
431
+ y: 10,
432
+ };
433
+ }
434
+
435
+ return {
436
+ bottom: 0,
437
+ height: 0,
438
+ left: 0,
439
+ right: 0,
440
+ toJSON: () => ({}),
441
+ top: 0,
442
+ width: 0,
443
+ x: 0,
444
+ y: 0,
445
+ };
446
+ });
447
+
448
+ const { container } = render(
449
+ <ToolcraftRoot
450
+ initialState={{ timeline: { expanded: true } }}
451
+ schema={createSchema()}
452
+ >
453
+ <div data-slot="toolcraft-runtime-app">
454
+ <div data-panel-type="layers" />
455
+ <div data-panel-type="controls" />
456
+ <TimelinePanel framed={false} panelPlacement="floating" />
457
+ </div>
458
+ </ToolcraftRoot>,
459
+ );
460
+
461
+ const timelinePanel = container.querySelector<HTMLElement>('[data-slot="timeline-panel"]');
462
+
463
+ await waitFor(() => {
464
+ expect(timelinePanel?.getAttribute("data-responsive-offset-x")).toBe("-30");
465
+ expect(timelinePanel?.getAttribute("data-responsive-width")).toBe("380");
466
+ });
467
+ });
468
+
469
+ it("keeps the expanded floating timeline inside the side-panel corridor immediately after resize", async () => {
470
+ let isNarrow = false;
471
+
472
+ vi.spyOn(HTMLElement.prototype, "getBoundingClientRect").mockImplementation(function (
473
+ this: HTMLElement,
474
+ ) {
475
+ if (this.matches('[data-slot="toolcraft-runtime-app"]')) {
476
+ return {
477
+ bottom: 720,
478
+ height: 720,
479
+ left: 0,
480
+ right: isNarrow ? 1024 : 1440,
481
+ toJSON: () => ({}),
482
+ top: 0,
483
+ width: isNarrow ? 1024 : 1440,
484
+ x: 0,
485
+ y: 0,
486
+ };
487
+ }
488
+
489
+ if (this.matches('[data-panel-type="layers"]')) {
490
+ return {
491
+ bottom: 560,
492
+ height: 560,
493
+ left: 10,
494
+ right: 250,
495
+ toJSON: () => ({}),
496
+ top: 10,
497
+ width: 240,
498
+ x: 10,
499
+ y: 10,
500
+ };
501
+ }
502
+
503
+ if (this.matches('[data-panel-type="controls"]')) {
504
+ return {
505
+ bottom: 560,
506
+ height: 560,
507
+ left: isNarrow ? 714 : 1130,
508
+ right: isNarrow ? 1014 : 1430,
509
+ toJSON: () => ({}),
510
+ top: 10,
511
+ width: 300,
512
+ x: isNarrow ? 714 : 1130,
513
+ y: 10,
514
+ };
515
+ }
516
+
517
+ if (
518
+ this.matches('[data-slot="toolcraft-runtime-panel-host"]') &&
519
+ this.matches('[data-panel-type="timeline"]')
520
+ ) {
521
+ return {
522
+ bottom: 128,
523
+ height: 118,
524
+ left: isNarrow ? 384 : 592,
525
+ right: isNarrow ? 640 : 848,
526
+ toJSON: () => ({}),
527
+ top: 10,
528
+ width: 256,
529
+ x: isNarrow ? 384 : 592,
530
+ y: 10,
531
+ };
532
+ }
533
+
534
+ if (this.matches('[data-slot="timeline-panel"]')) {
535
+ return {
536
+ bottom: 128,
537
+ height: 118,
538
+ left: isNarrow ? 384 : 592,
539
+ right: isNarrow ? 640 : 848,
540
+ toJSON: () => ({}),
541
+ top: 10,
542
+ width: 256,
543
+ x: isNarrow ? 384 : 592,
544
+ y: 10,
545
+ };
546
+ }
547
+
548
+ return {
549
+ bottom: 0,
550
+ height: 0,
551
+ left: 0,
552
+ right: 0,
553
+ toJSON: () => ({}),
554
+ top: 0,
555
+ width: 0,
556
+ x: 0,
557
+ y: 0,
558
+ };
559
+ });
560
+
561
+ const { container } = render(
562
+ <ToolcraftRoot
563
+ initialState={{ timeline: { expanded: true } }}
564
+ schema={createSchema()}
565
+ >
566
+ <div data-slot="toolcraft-runtime-app">
567
+ <div data-panel-type="layers" />
568
+ <div data-panel-type="controls" />
569
+ <TimelinePanel framed={false} panelPlacement="floating" />
570
+ </div>
571
+ </ToolcraftRoot>,
572
+ );
573
+
574
+ const timelinePanel = container.querySelector<HTMLElement>('[data-slot="timeline-panel"]');
575
+
576
+ await waitFor(() => {
577
+ expect(timelinePanel?.getAttribute("data-responsive-width")).toBeNull();
578
+ expect(timelinePanel?.getAttribute("data-responsive-offset-x")).toBeNull();
579
+ });
580
+
581
+ isNarrow = true;
582
+ fireEvent(window, new Event("resize"));
583
+
584
+ await waitFor(() => {
585
+ expect(timelinePanel?.getAttribute("data-responsive-width")).toBe("444");
586
+ expect(timelinePanel?.getAttribute("data-responsive-offset-x")).toBe("-30");
587
+ });
588
+ });
589
+
590
+ it("keeps the selected keyframe row highlighted", () => {
591
+ const selectedKeyframeId = "selectedLayer.opacity::4";
592
+ const { container } = renderTimelinePanel(
593
+ {},
594
+ {
595
+ timeline: {
596
+ expanded: true,
597
+ keyframeGroups: [
598
+ {
599
+ controlId: "selectedLayer.opacity",
600
+ keyframes: [
601
+ {
602
+ controlId: "selectedLayer.opacity",
603
+ controlLabel: "Opacity",
604
+ id: selectedKeyframeId,
605
+ timeSeconds: 4,
606
+ valueLabel: "75%",
607
+ },
608
+ ],
609
+ label: "Opacity",
610
+ },
611
+ ],
612
+ selectedKeyframeId,
613
+ },
614
+ },
615
+ );
616
+
617
+ expect(container.querySelector('[data-slot="timeline-keyframe-row"]')?.className).toContain(
618
+ "bg-[color:color-mix(in_oklab,var(--foreground)_3%,transparent)]",
619
+ );
620
+ });
621
+
622
+ it("pauses playback when dragging a keyframe", () => {
623
+ const keyframeId = "selectedLayer.opacity::4";
624
+ const { container } = renderTimelinePanel(
625
+ {},
626
+ {
627
+ timeline: {
628
+ expanded: true,
629
+ isPlaying: true,
630
+ keyframeGroups: [
631
+ {
632
+ controlId: "selectedLayer.opacity",
633
+ keyframes: [
634
+ {
635
+ controlId: "selectedLayer.opacity",
636
+ controlLabel: "Opacity",
637
+ id: keyframeId,
638
+ timeSeconds: 4,
639
+ valueLabel: "75%",
640
+ },
641
+ ],
642
+ label: "Opacity",
643
+ },
644
+ ],
645
+ },
646
+ },
647
+ );
648
+ const track = container.querySelector<HTMLElement>('[data-slot="timeline-keyframe-track"]');
649
+ const keyframeButton = screen.getByRole("button", { name: "Opacity keyframe at 4.00s" });
650
+
651
+ expect(track).toBeTruthy();
652
+ expect(screen.getByTestId("timeline-playing").textContent).toBe("true");
653
+
654
+ fireEvent.pointerDown(keyframeButton, {
655
+ button: 0,
656
+ clientX: 100,
657
+ clientY: 12,
658
+ pointerId: 1,
659
+ });
660
+ fireEvent.pointerMove(keyframeButton, {
661
+ clientX: 100,
662
+ clientY: 400,
663
+ pointerId: 1,
664
+ });
665
+
666
+ expect(screen.getByTestId("timeline-playing").textContent).toBe("false");
667
+ });
668
+ });