jspsych-tangram 0.0.14 → 0.0.16

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 (47) hide show
  1. package/dist/afc/index.browser.js +17751 -0
  2. package/dist/afc/index.browser.js.map +1 -0
  3. package/dist/afc/index.browser.min.js +42 -0
  4. package/dist/afc/index.browser.min.js.map +1 -0
  5. package/dist/afc/index.cjs +443 -0
  6. package/dist/afc/index.cjs.map +1 -0
  7. package/dist/afc/index.d.ts +169 -0
  8. package/dist/afc/index.js +441 -0
  9. package/dist/afc/index.js.map +1 -0
  10. package/dist/construct/index.browser.js +4538 -3890
  11. package/dist/construct/index.browser.js.map +1 -1
  12. package/dist/construct/index.browser.min.js +13 -13
  13. package/dist/construct/index.browser.min.js.map +1 -1
  14. package/dist/construct/index.cjs +4 -8
  15. package/dist/construct/index.cjs.map +1 -1
  16. package/dist/construct/index.js +4 -8
  17. package/dist/construct/index.js.map +1 -1
  18. package/dist/index.cjs +374 -16
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.ts +178 -12
  21. package/dist/index.js +374 -17
  22. package/dist/index.js.map +1 -1
  23. package/dist/nback/index.browser.js +4536 -3919
  24. package/dist/nback/index.browser.js.map +1 -1
  25. package/dist/nback/index.browser.min.js +12 -12
  26. package/dist/nback/index.browser.min.js.map +1 -1
  27. package/dist/nback/index.cjs +6 -41
  28. package/dist/nback/index.cjs.map +1 -1
  29. package/dist/nback/index.js +6 -41
  30. package/dist/nback/index.js.map +1 -1
  31. package/dist/prep/index.browser.js +4538 -3892
  32. package/dist/prep/index.browser.js.map +1 -1
  33. package/dist/prep/index.browser.min.js +13 -13
  34. package/dist/prep/index.browser.min.js.map +1 -1
  35. package/dist/prep/index.cjs +5 -11
  36. package/dist/prep/index.cjs.map +1 -1
  37. package/dist/prep/index.js +5 -11
  38. package/dist/prep/index.js.map +1 -1
  39. package/package.json +9 -3
  40. package/src/index.ts +2 -1
  41. package/src/plugins/tangram-afc/AFCApp.tsx +341 -0
  42. package/src/plugins/tangram-afc/index.ts +140 -0
  43. package/src/plugins/tangram-nback/NBackApp.tsx +2 -2
  44. package/tangram-afc.min.js +42 -0
  45. package/tangram-construct.min.js +13 -13
  46. package/tangram-nback.min.js +12 -12
  47. package/tangram-prep.min.js +13 -13
@@ -0,0 +1,443 @@
1
+ 'use strict';
2
+
3
+ var jspsych = require('jspsych');
4
+ var React = require('react');
5
+ var client = require('react-dom/client');
6
+
7
+ function polysAABB(polys) {
8
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
9
+ for (const poly of polys) {
10
+ for (const p of poly) {
11
+ if (p.x < minX) minX = p.x;
12
+ if (p.y < minY) minY = p.y;
13
+ if (p.x > maxX) maxX = p.x;
14
+ if (p.y > maxY) maxY = p.y;
15
+ }
16
+ }
17
+ const width = Math.max(1, maxX - minX);
18
+ const height = Math.max(1, maxY - minY);
19
+ return { min: { x: minX, y: minY }, max: { x: maxX, y: maxY }, width, height, cx: (minX + maxX) / 2, cy: (minY + maxY) / 2 };
20
+ }
21
+
22
+ const CONFIG = {
23
+ color: {
24
+ bands: {
25
+ silhouette: { fillEven: "#ffffff", stroke: "#b1b1b1" }},
26
+ silhouetteMask: "#374151",
27
+ tangramDecomposition: { stroke: "#fef2cc" },
28
+ primitiveColors: [
29
+ // from seaborn "colorblind" palette, 6 colors, with red omitted
30
+ "#0173b2",
31
+ "#de8f05",
32
+ "#029e73",
33
+ "#cc78bc",
34
+ "#ca9161"
35
+ ]
36
+ },
37
+ opacity: {
38
+ silhouetteMask: 0.25,
39
+ piece: { normal: 1 }
40
+ },
41
+ size: {
42
+ stroke: { bandPx: 5, tangramDecompositionPx: 1 }},
43
+ layout: {
44
+ grid: { stepPx: 20, unitPx: 40 }}};
45
+
46
+ const GRID_PX = CONFIG.layout.grid.stepPx;
47
+ function igcd(a, b) {
48
+ a = Math.round(Math.abs(a));
49
+ b = Math.round(Math.abs(b));
50
+ while (b) [a, b] = [b, a % b];
51
+ return a || 1;
52
+ }
53
+ function inferUnitFromPolys(polys) {
54
+ let g = 0;
55
+ for (const poly of polys) {
56
+ for (let i = 0; i < poly.length; i++) {
57
+ const a = poly[i], b = poly[(i + 1) % poly.length];
58
+ if (!a || !b) continue;
59
+ const dx = Math.round(Math.abs(b.x - a.x));
60
+ const dy = Math.round(Math.abs(b.y - a.y));
61
+ if (dx) g = g ? igcd(g, dx) : dx;
62
+ if (dy) g = g ? igcd(g, dy) : dy;
63
+ }
64
+ }
65
+ return g || 1;
66
+ }
67
+ function placeSilhouetteGridAlignedAsPolys(polys, S, rectCenter) {
68
+ if (!polys || polys.length === 0) return [];
69
+ const a = polysAABB(polys);
70
+ const cx0 = (a.min.x + a.max.x) / 2;
71
+ const cy0 = (a.min.y + a.max.y) / 2;
72
+ const cx = Math.round(rectCenter.cx / GRID_PX) * GRID_PX;
73
+ const cy = Math.round(rectCenter.cy / GRID_PX) * GRID_PX;
74
+ const tx = cx - S * cx0;
75
+ const ty = cy - S * cy0;
76
+ const stx = Math.round(tx / GRID_PX) * GRID_PX;
77
+ const sty = Math.round(ty / GRID_PX) * GRID_PX;
78
+ return polys.map((poly) => poly.map((p) => ({ x: S * p.x + stx, y: S * p.y + sty })));
79
+ }
80
+
81
+ function startAFCTrial(display_element, params, _jsPsych) {
82
+ const root = client.createRoot(display_element);
83
+ root.render(React.createElement(AFCView, { params }));
84
+ return { root, display_element, jsPsych: _jsPsych };
85
+ }
86
+ function AFCView({ params }) {
87
+ const {
88
+ tangramLeft,
89
+ tangramRight,
90
+ instructions,
91
+ buttonTextLeft,
92
+ buttonTextRight,
93
+ showTangramDecomposition,
94
+ usePrimitiveColors,
95
+ primitiveColorIndices,
96
+ onTrialEnd
97
+ } = params;
98
+ const trialStartTime = React.useRef(Date.now());
99
+ const [hasResponded, setHasResponded] = React.useState(false);
100
+ const handleResponse = (choice) => {
101
+ if (hasResponded) return;
102
+ setHasResponded(true);
103
+ const rt = Date.now() - trialStartTime.current;
104
+ if (onTrialEnd) {
105
+ onTrialEnd({
106
+ rt,
107
+ response: choice,
108
+ show_tangram_decomposition: showTangramDecomposition,
109
+ use_primitive_colors: usePrimitiveColors,
110
+ primitive_color_indices: primitiveColorIndices,
111
+ button_text_left: buttonTextLeft,
112
+ button_text_right: buttonTextRight
113
+ });
114
+ }
115
+ };
116
+ return /* @__PURE__ */ React.createElement("div", { style: {
117
+ display: "flex",
118
+ flexDirection: "column",
119
+ alignItems: "center",
120
+ justifyContent: "center",
121
+ padding: "20px",
122
+ background: "#fff7e0ff",
123
+ minHeight: "100vh"
124
+ } }, instructions && /* @__PURE__ */ React.createElement(
125
+ "div",
126
+ {
127
+ style: {
128
+ maxWidth: "800px",
129
+ width: "100%",
130
+ marginBottom: "30px",
131
+ textAlign: "center",
132
+ fontSize: "18px",
133
+ lineHeight: "1.5"
134
+ },
135
+ dangerouslySetInnerHTML: { __html: instructions }
136
+ }
137
+ ), /* @__PURE__ */ React.createElement("div", { style: {
138
+ display: "flex",
139
+ flexDirection: "row",
140
+ gap: "50px",
141
+ justifyContent: "center",
142
+ alignItems: "flex-start",
143
+ flexWrap: "wrap"
144
+ } }, /* @__PURE__ */ React.createElement(
145
+ TangramOption,
146
+ {
147
+ tangram: tangramLeft,
148
+ buttonText: buttonTextLeft,
149
+ onClick: () => handleResponse("left"),
150
+ disabled: hasResponded,
151
+ showDecomposition: showTangramDecomposition,
152
+ usePrimitiveColors,
153
+ primitiveColorIndices
154
+ }
155
+ ), /* @__PURE__ */ React.createElement(
156
+ TangramOption,
157
+ {
158
+ tangram: tangramRight,
159
+ buttonText: buttonTextRight,
160
+ onClick: () => handleResponse("right"),
161
+ disabled: hasResponded,
162
+ showDecomposition: showTangramDecomposition,
163
+ usePrimitiveColors,
164
+ primitiveColorIndices
165
+ }
166
+ )));
167
+ }
168
+ function TangramOption({
169
+ tangram,
170
+ buttonText,
171
+ onClick,
172
+ disabled,
173
+ showDecomposition,
174
+ usePrimitiveColors,
175
+ primitiveColorIndices
176
+ }) {
177
+ if (!tangram) {
178
+ return /* @__PURE__ */ React.createElement("div", { style: { width: 300, height: 300, background: "#eee" } }, "No Tangram Data");
179
+ }
180
+ const CANON = /* @__PURE__ */ new Set([
181
+ "square",
182
+ "smalltriangle",
183
+ "parallelogram",
184
+ "medtriangle",
185
+ "largetriangle"
186
+ ]);
187
+ const filteredTans = tangram.solutionTans.filter((tan) => {
188
+ const tanName = tan.name ?? tan.kind;
189
+ return CANON.has(tanName);
190
+ });
191
+ const mask = filteredTans.map((tan) => {
192
+ const polygon = tan.vertices.map(([x, y]) => ({ x: x ?? 0, y: -(y ?? 0) }));
193
+ return polygon;
194
+ });
195
+ const primitiveDecomposition = filteredTans.map((tan) => ({
196
+ kind: tan.name ?? tan.kind,
197
+ polygon: tan.vertices.map(([x, y]) => ({ x: x ?? 0, y: -(y ?? 0) }))
198
+ }));
199
+ const DISPLAY_SIZE = 300;
200
+ const viewport = {
201
+ w: DISPLAY_SIZE,
202
+ h: DISPLAY_SIZE
203
+ };
204
+ const scaleS = React.useMemo(() => {
205
+ const u = inferUnitFromPolys(mask);
206
+ return u ? CONFIG.layout.grid.unitPx / u : 1;
207
+ }, [mask]);
208
+ const centerPos = {
209
+ cx: viewport.w / 2,
210
+ cy: viewport.h / 2
211
+ };
212
+ const pathD = (poly) => {
213
+ if (!poly || poly.length === 0) return "";
214
+ const moves = poly.map((p, i) => `${i === 0 ? "M" : "L"} ${p.x} ${p.y}`);
215
+ return moves.join(" ") + " Z";
216
+ };
217
+ const renderSilhouette = () => {
218
+ if (showDecomposition) {
219
+ const rawPolys = primitiveDecomposition.map((primInfo) => primInfo.polygon);
220
+ const placedPolys = placeSilhouetteGridAlignedAsPolys(rawPolys, scaleS, centerPos);
221
+ return /* @__PURE__ */ React.createElement("g", { key: "sil-decomposed", pointerEvents: "none" }, placedPolys.map((scaledPoly, i) => {
222
+ const primInfo = primitiveDecomposition[i];
223
+ let fillColor = CONFIG.color.silhouetteMask;
224
+ if (usePrimitiveColors && primInfo?.kind && primitiveColorIndices) {
225
+ const kindToIndex = {
226
+ "square": 0,
227
+ "smalltriangle": 1,
228
+ "parallelogram": 2,
229
+ "medtriangle": 3,
230
+ "largetriangle": 4
231
+ };
232
+ const primitiveIndex = kindToIndex[primInfo.kind];
233
+ if (primitiveIndex !== void 0 && primitiveColorIndices[primitiveIndex] !== void 0) {
234
+ const colorIndex = primitiveColorIndices[primitiveIndex];
235
+ const color = CONFIG.color.primitiveColors[colorIndex];
236
+ if (color) {
237
+ fillColor = color;
238
+ }
239
+ }
240
+ }
241
+ return /* @__PURE__ */ React.createElement(React.Fragment, { key: `prim-${i}` }, /* @__PURE__ */ React.createElement(
242
+ "path",
243
+ {
244
+ d: pathD(scaledPoly),
245
+ fill: fillColor,
246
+ opacity: usePrimitiveColors ? CONFIG.opacity.piece.normal : CONFIG.opacity.silhouetteMask,
247
+ stroke: "none"
248
+ }
249
+ ), /* @__PURE__ */ React.createElement(
250
+ "path",
251
+ {
252
+ d: pathD(scaledPoly),
253
+ fill: "none",
254
+ stroke: CONFIG.color.tangramDecomposition.stroke,
255
+ strokeWidth: CONFIG.size.stroke.tangramDecompositionPx
256
+ }
257
+ ));
258
+ }));
259
+ } else {
260
+ const placedPolys = placeSilhouetteGridAlignedAsPolys(mask, scaleS, centerPos);
261
+ return /* @__PURE__ */ React.createElement("g", { key: "sil-unified", pointerEvents: "none" }, placedPolys.map((scaledPoly, i) => {
262
+ const primInfo = primitiveDecomposition[i];
263
+ let fillColor = CONFIG.color.silhouetteMask;
264
+ if (usePrimitiveColors && primInfo?.kind && primitiveColorIndices) {
265
+ const kindToIndex = {
266
+ "square": 0,
267
+ "smalltriangle": 1,
268
+ "parallelogram": 2,
269
+ "medtriangle": 3,
270
+ "largetriangle": 4
271
+ };
272
+ const primitiveIndex = kindToIndex[primInfo.kind];
273
+ if (primitiveIndex !== void 0 && primitiveColorIndices[primitiveIndex] !== void 0) {
274
+ const colorIndex = primitiveColorIndices[primitiveIndex];
275
+ const color = CONFIG.color.primitiveColors[colorIndex];
276
+ if (color) {
277
+ fillColor = color;
278
+ }
279
+ }
280
+ }
281
+ return /* @__PURE__ */ React.createElement(
282
+ "path",
283
+ {
284
+ key: `sil-${i}`,
285
+ d: pathD(scaledPoly),
286
+ fill: fillColor,
287
+ opacity: usePrimitiveColors ? CONFIG.opacity.piece.normal : CONFIG.opacity.silhouetteMask,
288
+ stroke: "none"
289
+ }
290
+ );
291
+ }));
292
+ }
293
+ };
294
+ return /* @__PURE__ */ React.createElement("div", { style: {
295
+ display: "flex",
296
+ flexDirection: "column",
297
+ alignItems: "center",
298
+ gap: "20px"
299
+ } }, /* @__PURE__ */ React.createElement(
300
+ "svg",
301
+ {
302
+ width: viewport.w,
303
+ height: viewport.h,
304
+ viewBox: `0 0 ${viewport.w} ${viewport.h}`,
305
+ style: {
306
+ display: "block",
307
+ background: CONFIG.color.bands.silhouette.fillEven,
308
+ border: `${CONFIG.size.stroke.bandPx}px solid ${CONFIG.color.bands.silhouette.stroke}`,
309
+ borderRadius: "8px"
310
+ }
311
+ },
312
+ renderSilhouette()
313
+ ), /* @__PURE__ */ React.createElement(
314
+ "button",
315
+ {
316
+ className: "jspsych-btn",
317
+ onClick,
318
+ disabled,
319
+ style: {
320
+ padding: "12px 30px",
321
+ fontSize: "16px",
322
+ cursor: disabled ? "not-allowed" : "pointer",
323
+ opacity: disabled ? 0.5 : 1
324
+ }
325
+ },
326
+ buttonText
327
+ ));
328
+ }
329
+
330
+ const info = {
331
+ name: "tangram-afc",
332
+ version: "1.0.0",
333
+ parameters: {
334
+ /** Left tangram specification to display */
335
+ tangram_left: {
336
+ type: jspsych.ParameterType.COMPLEX,
337
+ default: void 0,
338
+ description: "TangramSpec object defining left target shape to display"
339
+ },
340
+ /** Right tangram specification to display */
341
+ tangram_right: {
342
+ type: jspsych.ParameterType.COMPLEX,
343
+ default: void 0,
344
+ description: "TangramSpec object defining right target shape to display"
345
+ },
346
+ /** HTML content to display above the tangrams as instructions */
347
+ instructions: {
348
+ type: jspsych.ParameterType.STRING,
349
+ default: "",
350
+ description: "HTML content to display above the tangrams as instructions"
351
+ },
352
+ /** Text to display on left response button */
353
+ button_text_left: {
354
+ type: jspsych.ParameterType.STRING,
355
+ default: "Select Left",
356
+ description: "Text to display on left response button"
357
+ },
358
+ /** Text to display on right response button */
359
+ button_text_right: {
360
+ type: jspsych.ParameterType.STRING,
361
+ default: "Select Right",
362
+ description: "Text to display on right response button"
363
+ },
364
+ /** Whether to show tangram decomposed into individual primitives with borders */
365
+ show_tangram_decomposition: {
366
+ type: jspsych.ParameterType.BOOL,
367
+ default: false,
368
+ description: "Whether to show tangram decomposed into individual primitives with borders"
369
+ },
370
+ /** Whether to use distinct colors for each primitive shape type */
371
+ use_primitive_colors: {
372
+ type: jspsych.ParameterType.BOOL,
373
+ default: false,
374
+ description: "Whether each primitive shape type should have its own distinct color in the displayed tangram"
375
+ },
376
+ /** Indices mapping primitives to colors from the color palette */
377
+ primitive_color_indices: {
378
+ type: jspsych.ParameterType.OBJECT,
379
+ default: [0, 1, 2, 3, 4],
380
+ description: "Array of 5 integers indexing into primitiveColors array, mapping [square, smalltriangle, parallelogram, medtriangle, largetriangle] to colors"
381
+ },
382
+ /** Callback fired when trial ends */
383
+ onTrialEnd: {
384
+ type: jspsych.ParameterType.FUNCTION,
385
+ default: void 0,
386
+ description: "Callback when trial completes with full data"
387
+ }
388
+ },
389
+ data: {
390
+ /** Reaction time in milliseconds */
391
+ rt: {
392
+ type: jspsych.ParameterType.INT,
393
+ description: "Milliseconds between trial start and button click"
394
+ },
395
+ /** Response choice */
396
+ response: {
397
+ type: jspsych.ParameterType.STRING,
398
+ description: "Which button was clicked: 'left' or 'right'"
399
+ }
400
+ },
401
+ citations: ""
402
+ };
403
+ class TangramAFCPlugin {
404
+ constructor(jsPsych) {
405
+ this.jsPsych = jsPsych;
406
+ }
407
+ static {
408
+ this.info = info;
409
+ }
410
+ /**
411
+ * Launches the trial by invoking startAFCTrial
412
+ * with the display element, parameters, and jsPsych instance.
413
+ */
414
+ trial(display_element, trial) {
415
+ const wrappedOnTrialEnd = (data) => {
416
+ if (trial.onTrialEnd) {
417
+ trial.onTrialEnd(data);
418
+ }
419
+ const reactContext = display_element.__reactContext;
420
+ if (reactContext?.root) {
421
+ reactContext.root.unmount();
422
+ }
423
+ display_element.innerHTML = "";
424
+ this.jsPsych.finishTrial(data);
425
+ };
426
+ const params = {
427
+ tangramLeft: trial.tangram_left,
428
+ tangramRight: trial.tangram_right,
429
+ instructions: trial.instructions,
430
+ buttonTextLeft: trial.button_text_left,
431
+ buttonTextRight: trial.button_text_right,
432
+ showTangramDecomposition: trial.show_tangram_decomposition,
433
+ usePrimitiveColors: trial.use_primitive_colors,
434
+ primitiveColorIndices: trial.primitive_color_indices,
435
+ onTrialEnd: wrappedOnTrialEnd
436
+ };
437
+ const { root, display_element: element, jsPsych } = startAFCTrial(display_element, params, this.jsPsych);
438
+ element.__reactContext = { root, jsPsych };
439
+ }
440
+ }
441
+
442
+ module.exports = TangramAFCPlugin;
443
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../src/core/engine/geometry/bounds.ts","../../src/core/config/config.ts","../../src/core/engine/geometry/pieces.ts","../../src/plugins/tangram-afc/AFCApp.tsx","../../src/plugins/tangram-afc/index.ts"],"sourcesContent":["import type { Poly, Vec, PrimitiveBlueprint, CompositeBlueprint, Blueprint } from \"@/core/domain/types\";\n\nexport type AABB = { min: Vec; max: Vec; width: number; height: number };\n\n/** AABB of a single polygon (numeric). */\nexport function aabbOf(poly: Poly): { minX: number; minY: number; maxX: number; maxY: number } {\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const p of poly) {\n if (p.x < minX) minX = p.x;\n if (p.y < minY) minY = p.y;\n if (p.x > maxX) maxX = p.x;\n if (p.y > maxY) maxY = p.y;\n }\n return { minX, minY, maxX, maxY };\n}\n\n/** AABB of one or more polygons with width/height and center. */\nexport function polysAABB(polys: Poly[]) {\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const poly of polys) {\n for (const p of poly) {\n if (p.x < minX) minX = p.x;\n if (p.y < minY) minY = p.y;\n if (p.x > maxX) maxX = p.x;\n if (p.y > maxY) maxY = p.y;\n }\n }\n const width = Math.max(1, maxX - minX);\n const height = Math.max(1, maxY - minY);\n return { min: { x: minX, y: minY }, max: { x: maxX, y: maxY }, width, height, cx:(minX+maxX)/2, cy:(minY+maxY)/2 };\n}\n\n/** Bounds of multiple polygons at the origin. */\nexport function boundsOfShapes(shapes: Poly[]): AABB {\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const poly of shapes) {\n for (const p of poly) {\n if (p.x < minX) minX = p.x;\n if (p.y < minY) minY = p.y;\n if (p.x > maxX) maxX = p.x;\n if (p.y > maxY) maxY = p.y;\n }\n }\n const width = Math.max(0, maxX - minX);\n const height = Math.max(0, maxY - minY);\n return { min: { x: minX, y: minY }, max: { x: maxX, y: maxY }, width, height };\n}\n\n/** Bounds of a primitive blueprint (uses its canonical shape). */\nexport function boundsOfPrimitive(bp: PrimitiveBlueprint): AABB {\n return boundsOfShapes(bp.shape);\n}\n\n/**\n * Bounds of a composite blueprint.\n * If `shape` is provided as precomputed union polygons, we use that.\n * Otherwise we bound the parts’ primitives at their offsets (loose but safe).\n */\nexport function boundsOfComposite(\n bp: CompositeBlueprint,\n primitiveLookup: (kind: string) => PrimitiveBlueprint | undefined\n): AABB {\n if (bp.shape && bp.shape.length) return boundsOfShapes(bp.shape);\n\n let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;\n for (const part of bp.parts) {\n const prim = primitiveLookup(part.kind);\n if (!prim) continue;\n const b = boundsOfPrimitive(prim);\n const pMinX = part.offset.x + b.min.x;\n const pMinY = part.offset.y + b.min.y;\n const pMaxX = part.offset.x + b.max.x;\n const pMaxY = part.offset.y + b.max.y;\n if (pMinX < minX) minX = pMinX;\n if (pMinY < minY) minY = pMinY;\n if (pMaxX > maxX) maxX = pMaxX;\n if (pMaxY > maxY) maxY = pMaxY;\n }\n const width = Math.max(0, maxX - minX);\n const height = Math.max(0, maxY - minY);\n return { min: { x: minX, y: minY }, max: { x: maxX, y: maxY }, width, height };\n}\n\n/** Unified bounds helper. */\nexport function boundsOfBlueprint(\n bp: Blueprint,\n primitiveLookup: (kind: string) => PrimitiveBlueprint | undefined\n): AABB {\n if (\"parts\" in bp) return boundsOfComposite(bp, primitiveLookup);\n return boundsOfPrimitive(bp);\n}\n","// src/core/config/config.ts\nexport type Config = {\n color: {\n background: string;\n bands: {\n silhouette: { fillEven: string; fillOdd: string; stroke: string };\n workspace: { fillEven: string; fillOdd: string; stroke: string };\n };\n completion: { fill: string; stroke: string };\n silhouetteMask: string;\n anchors: { invalid: string; valid: string };\n piece: { draggingFill: string; validFill: string; invalidFill: string; invalidStroke: string; selectedStroke: string; allGreenStroke: string; borderStroke: string };\n ui: { light: string; dark: string };\n blueprint: { fill: string; selectedStroke: string; badgeFill: string; labelFill: string };\n tangramDecomposition: { stroke: string };\n primitiveColors: string[];\n };\n opacity: {\n blueprint: number;\n silhouetteMask: number;\n anchors: { invalid: number; valid: number };\n piece: { invalid: number; dragging: number; locked: number; normal: number };\n };\n size: {\n stroke: { bandPx: number; pieceSelectedPx: number; allGreenStrokePx: number; pieceBorderPx: number; tangramDecompositionPx: number };\n anchorRadiusPx: { valid: number; invalid: number };\n badgeFontPx: number;\n centerBadge: { fractionOfOuterR: number; minPx: number; marginPx: number };\n invalidMarker: { sizePx: number; strokePx: number };\n };\n layout: {\n grid: { stepPx: number; unitPx: number };\n paddingPx: number;\n viewportScale: number;\n /** renamed from capacity → constraints */\n constraints: {\n workspaceDiamAnchors: number;\n quickstashDiamAnchors: number;\n primitiveDiamAnchors: number;\n };\n defaults: { maxQuickstashSlots: number };\n };\n game: {\n snapRadiusPx: number;\n showBorders: boolean;\n hideTouchingBorders: boolean;\n silhouettesBelowPieces: boolean;\n };\n};\n\nexport const CONFIG: Config = {\n color: {\n background: \"#fff7e0ff\",\n bands: {\n silhouette: { fillEven: \"#ffffff\", fillOdd: \"#ffffff\", stroke: \"#b1b1b1\" },\n workspace: { fillEven: \"#ffffff\", fillOdd: \"#ffffff\", stroke: \"#b1b1b1\" }\n },\n completion: { fill: \"#ccffcc\", stroke: \"#13da57\" },\n silhouetteMask: \"#374151\",\n anchors: { invalid: \"#7dd3fc\", valid: \"#475569\" },\n // validFill used here for placed composites\n piece: { draggingFill: \"#8e7cc3\", validFill: \"#8e7cc3\", invalidFill: \"#d55c00\", invalidStroke: \"#dc2626\", selectedStroke: \"#674ea7\", allGreenStroke: \"#86efac\", borderStroke: \"#674ea7\" },\n ui: { light: \"#60a5fa\", dark: \"#1d4ed8\" },\n blueprint: { fill: \"#374151\", selectedStroke: \"#111827\", badgeFill: \"#000000\", labelFill: \"#ffffff\" },\n tangramDecomposition: { stroke: \"#fef2cc\" },\n primitiveColors: [ // from seaborn \"colorblind\" palette, 6 colors, with red omitted\n '#0173b2',\n '#de8f05',\n '#029e73',\n '#cc78bc',\n '#ca9161'\n ]\n },\n opacity: {\n blueprint: 0.6,\n silhouetteMask: 0.25,\n //anchors: { valid: 0.80, invalid: 0.50 },\n anchors: { invalid: 0.0, valid: 0.0 },\n piece: { invalid: 1, dragging: 1, locked: 1, normal: 1 },\n },\n size: {\n stroke: { bandPx: 5, pieceSelectedPx: 5, allGreenStrokePx: 10, pieceBorderPx: 2, tangramDecompositionPx: 1 },\n anchorRadiusPx: { valid: 1.0, invalid: 1.0 },\n badgeFontPx: 16,\n centerBadge: { fractionOfOuterR: 0.15, minPx: 20, marginPx: 4 },\n invalidMarker: { sizePx: 10, strokePx: 4 }\n },\n layout: {\n grid: { stepPx: 20, unitPx: 40 },\n paddingPx: 1,\n viewportScale: 0.8,\n constraints: {\n workspaceDiamAnchors: 10, // num anchors req'd to be on diagonal\n quickstashDiamAnchors: 7, // num anchors req'd to be in single quickstash slot\n primitiveDiamAnchors: 5,\n },\n defaults: { maxQuickstashSlots: 1 }\n },\n game: {\n snapRadiusPx: 15,\n showBorders: false,\n hideTouchingBorders: true,\n silhouettesBelowPieces: true\n }\n};","/**\n * Game-specific piece geometry operations\n * Includes: piece positioning, placement, grid snapping, and anchor generation\n *\n * Consolidated from: piece.ts, placement.ts, grid.ts, anchors.ts\n */\n\nimport type { Blueprint, Vec, Poly, Anchor } from \"@/core/domain/types\";\nimport type { CircleLayout, SectorGeom } from \"@/core/domain/layout\";\nimport { polysAABB } from \"./bounds\";\nimport { pointInPolygon, dist2 } from \"./math\";\nimport { CONFIG } from \"@/core/config/config\";\n\nconst GRID_PX = CONFIG.layout.grid.stepPx;\n\n// ===== Piece Positioning (from piece.ts) =====\n\n/** Translate blueprint polys to world coords for a given top-left (TL). */\nexport function piecePolysAt(\n bp: Blueprint,\n bb: { min: { x: number; y: number } },\n tl: { x: number; y: number }\n) {\n const ox = tl.x - bb.min.x;\n const oy = tl.y - bb.min.y;\n const polys = (\"shape\" in bp && bp.shape) ? bp.shape : [];\n return polys.map(poly => poly.map(p => ({ x: p.x + ox, y: p.y + oy })));\n}\n\n/** Build support offsets: each vertex relative to the AABB center. */\nexport function computeSupportOffsets(\n bp: Blueprint,\n bb: { min: { x: number; y: number }; width: number; height: number }\n) {\n const cx = bb.min.x + bb.width / 2;\n const cy = bb.min.y + bb.height / 2;\n\n const polys = (\"shape\" in bp && bp.shape && bp.shape.length)\n ? bp.shape\n : [[\n { x: bb.min.x, y: bb.min.y },\n { x: bb.min.x + bb.width, y: bb.min.y },\n { x: bb.min.x + bb.width, y: bb.min.y + bb.height },\n { x: bb.min.x, y: bb.min.y + bb.height },\n ]];\n\n const offs: Vec[] = [];\n for (const poly of polys) for (const v of poly) offs.push({ x: v.x - cx, y: v.y - cy });\n return offs;\n}\n\n/** Clamp using directional vertex support → exact contact with the ring. */\nexport function clampTopLeftBySupport(\n tlx: number,\n tly: number,\n d: {\n aabb: { width: number; height: number };\n support: { x: number; y: number }[];\n },\n layout: CircleLayout,\n target: \"workspace\" | \"silhouette\",\n pointerInsideCenter: boolean\n) {\n const cx0 = tlx + d.aabb.width / 2;\n const cy0 = tly + d.aabb.height / 2;\n\n const vx = cx0 - layout.cx;\n const vy = cy0 - layout.cy;\n const r = Math.hypot(vx, vy);\n if (r === 0) return { x: tlx, y: tly };\n\n const ux = vx / r, uy = vy / r;\n\n let h_out = -Infinity, h_in = -Infinity;\n for (const o of d.support) {\n const outProj = o.x * ux + o.y * uy;\n if (outProj > h_out) h_out = outProj;\n const inProj = -(o.x * ux + o.y * uy);\n if (inProj > h_in) h_in = inProj;\n }\n\n if (target === \"workspace\") {\n const [rIn, rOut] = layout.bands.workspace;\n const minR = pointerInsideCenter ? 0 : (rIn + h_in);\n const maxR = rOut - h_out;\n const rClamped = Math.min(Math.max(r, minR), maxR);\n if (Math.abs(rClamped - r) < 1e-6) return { x: tlx, y: tly };\n const newCx = layout.cx + rClamped * ux;\n const newCy = layout.cy + rClamped * uy;\n return { x: newCx - d.aabb.width / 2, y: newCy - d.aabb.height / 2 };\n } else {\n const rOut = layout.bands.silhouette[1];\n const maxR = rOut - h_out;\n if (r <= maxR) return { x: tlx, y: tly };\n const newCx = layout.cx + maxR * ux;\n const newCy = layout.cy + maxR * uy;\n return { x: newCx - d.aabb.width / 2, y: newCy - d.aabb.height / 2 };\n }\n}\n\n// ===== Placement (from placement.ts) =====\n\n/** gcd for positive integers */\nfunction igcd(a: number, b: number) {\n a = Math.round(Math.abs(a)); b = Math.round(Math.abs(b));\n while (b) [a, b] = [b, a % b];\n return a || 1;\n}\n\n/** Infer the base lattice unit in raw silhouette coordinates. */\nexport function inferUnitFromPolys(polys: Poly[]): number {\n let g = 0;\n for (const poly of polys) {\n for (let i = 0; i < poly.length; i++) {\n const a = poly[i], b = poly[(i + 1) % poly.length];\n if (!a || !b) continue;\n const dx = Math.round(Math.abs(b.x - a.x));\n const dy = Math.round(Math.abs(b.y - a.y));\n if (dx) g = g ? igcd(g, dx) : dx;\n if (dy) g = g ? igcd(g, dy) : dy;\n }\n }\n return g || 1;\n}\n\n/**\n * Place polys using scale S, re-centered, and translation snapped to GRID_PX; returns polys.\n * The center is snapped to the grid so the lattice points under the silhouette stay invariant.\n */\nexport function placeSilhouetteGridAlignedAsPolys(\n polys: Poly[],\n S: number,\n rectCenter: { cx: number; cy: number }\n): Poly[] {\n if (!polys || polys.length === 0) return [];\n const a = polysAABB(polys);\n const cx0 = (a.min.x + a.max.x) / 2;\n const cy0 = (a.min.y + a.max.y) / 2;\n const cx = Math.round(rectCenter.cx / GRID_PX) * GRID_PX;\n const cy = Math.round(rectCenter.cy / GRID_PX) * GRID_PX;\n const tx = cx - S * cx0;\n const ty = cy - S * cy0;\n const stx = Math.round(tx / GRID_PX) * GRID_PX;\n const sty = Math.round(ty / GRID_PX) * GRID_PX;\n return polys.map(poly => poly.map(p => ({ x: S * p.x + stx, y: S * p.y + sty })));\n}\n\n// ===== Grid Operations (from grid.ts) =====\n\nexport function nearestGridNode(p: Vec): Vec {\n return { x: Math.round(p.x / GRID_PX) * GRID_PX, y: Math.round(p.y / GRID_PX) * GRID_PX };\n}\n\n/** Generate grid nodes inside an AABB. */\nexport function gridNodesInAABB(min: Vec, max: Vec): Vec[] {\n const out: Vec[] = [];\n const x0 = Math.ceil(min.x / GRID_PX) * GRID_PX;\n const y0 = Math.ceil(min.y / GRID_PX) * GRID_PX;\n for (let y = y0; y <= max.y; y += GRID_PX) {\n for (let x = x0; x <= max.x; x += GRID_PX) out.push({ x, y });\n }\n return out;\n}\n\n/** Keep nodes in a band (and optional sector wedge). */\nexport function filterNodesToBandAndSector(\n nodes: Vec[],\n layout: CircleLayout,\n band: \"workspace\" | \"silhouette\",\n sector?: SectorGeom\n): Vec[] {\n const [rIn, rOut] = layout.bands[band];\n const out: Vec[] = [];\n for (const n of nodes) {\n const dx = n.x - layout.cx, dy = n.y - layout.cy;\n const r = Math.hypot(dx, dy);\n if (r < rIn || r > rOut) continue;\n\n if (sector) {\n let theta = Math.atan2(dy, dx);\n if (layout.mode === \"circle\") {\n if (theta < -Math.PI / 2) theta += 2 * Math.PI;\n } else {\n if (theta < Math.PI) theta += 2 * Math.PI;\n }\n if (theta < sector.start || theta >= sector.end) continue;\n }\n out.push(n);\n }\n return out;\n}\n\n/** Keep nodes that lie inside any of the polygons. */\nexport function filterNodesInPolys(\n nodes: Vec[],\n polys: Poly[],\n pointInPolyFn: (pt: Vec, poly: Poly) => boolean = pointInPolygon\n): Vec[] {\n const out: Vec[] = [];\n node: for (const n of nodes) {\n for (const poly of polys) {\n if (pointInPolyFn(n, poly)) { out.push(n); continue node; }\n }\n }\n return out;\n}\n\n// ===== Anchor Operations (from anchors.ts) =====\n\n/**\n * Find the nearest anchor that \"accepts\" a piece signature (kind/compositeSignature).\n * Returns null if none within the optional radius.\n */\nexport function nearestAcceptingAnchor(\n anchors: Anchor[] | undefined,\n point: Vec,\n accepts: { kind?: string; compositeSignature?: string },\n withinPx: number = Infinity\n): { anchor: Anchor; d2: number } | null {\n if (!anchors || !anchors.length) return null;\n\n const { kind, compositeSignature } = accepts;\n const r2 = withinPx === Infinity ? Infinity : withinPx * withinPx;\n\n let best: { anchor: Anchor; d2: number } | null = null;\n for (const a of anchors) {\n const ok = a.accepts.some(acc =>\n (acc.kind === undefined || acc.kind === kind) &&\n (acc.compositeSignature === undefined || acc.compositeSignature === compositeSignature)\n );\n if (!ok) continue;\n\n const d2val = dist2(point, a.position);\n if (d2val <= r2 && (!best || d2val < best.d2)) {\n best = { anchor: a, d2: d2val };\n }\n }\n return best;\n}\n\n/** True if `point` is within `withinPx` of the given anchor. */\nexport function withinAnchor(anchor: Anchor, point: Vec, withinPx: number): boolean {\n const r2 = withinPx * withinPx;\n return dist2(point, anchor.position) <= r2;\n}\n\n// Node-grid helpers for anchor generation\nexport function workspaceNodes(layout: CircleLayout, sector: SectorGeom): Vec[] {\n const pad = 6;\n const min = { x: layout.cx - layout.outerR, y: layout.cy - layout.outerR - pad };\n const max = { x: layout.cx + layout.outerR, y: layout.cy + layout.outerR + pad };\n const nodes = gridNodesInAABB(min, max);\n return filterNodesToBandAndSector(nodes, layout, \"workspace\", sector);\n}\n\nexport function silhouetteNodes(layout: CircleLayout, sector: SectorGeom, fittedMask: Poly[]): Vec[] {\n const pad = 6;\n const min = { x: layout.cx - layout.outerR, y: layout.cy - layout.outerR - pad };\n const max = { x: layout.cx + layout.outerR, y: layout.cy + layout.outerR + pad };\n const nodes = gridNodesInAABB(min, max);\n const banded = filterNodesToBandAndSector(nodes, layout, \"silhouette\", sector);\n return filterNodesInPolys(banded, fittedMask);\n}\n\nexport function silhouetteBandNodes(layout: CircleLayout, sector: SectorGeom): Vec[] {\n const pad = 6;\n const min = { x: layout.cx - layout.outerR, y: layout.cy - layout.outerR - pad };\n const max = { x: layout.cx + layout.outerR, y: layout.cy + layout.outerR + pad };\n const nodes = gridNodesInAABB(min, max);\n return filterNodesToBandAndSector(nodes, layout, \"silhouette\", sector);\n}\n\n/** Generate anchor grid nodes for the inner ring (radius < innerR) */\nexport function innerRingNodes(layout: CircleLayout): Vec[] {\n const pad = 6;\n const min = { x: layout.cx - layout.innerR, y: layout.cy - layout.innerR - pad };\n const max = { x: layout.cx + layout.innerR, y: layout.cy + layout.innerR + pad };\n const nodes = gridNodesInAABB(min, max);\n // Filter to nodes within the inner circle\n const out: Vec[] = [];\n for (const n of nodes) {\n const dx = n.x - layout.cx, dy = n.y - layout.cy;\n const r = Math.hypot(dx, dy);\n if (r < layout.innerR) out.push(n);\n }\n return out;\n}\n\nexport const anchorsDiameterToPx = (anchorsDiag: number, gridPx: number = GRID_PX) =>\n anchorsDiag * Math.SQRT2 * gridPx;\n","/**\n * AFCApp.tsx - React wrapper for tangram alternative forced choice (AFC) trials\n *\n * This component handles the React rendering logic for AFC trials,\n * displaying two tangram silhouettes side-by-side with response buttons.\n */\n\nimport React, { useRef, useState } from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport { JsPsych } from \"jspsych\";\nimport type { Poly, TanKind } from \"../../core/domain/types\";\nimport { placeSilhouetteGridAlignedAsPolys, inferUnitFromPolys } from \"../../core/engine/geometry\";\nimport { CONFIG } from \"../../core/config/config\";\n\nexport interface StartAFCTrialParams {\n tangramLeft: any;\n tangramRight: any;\n instructions?: string;\n buttonTextLeft?: string;\n buttonTextRight?: string;\n showTangramDecomposition?: boolean;\n usePrimitiveColors?: boolean;\n primitiveColorIndices?: number[];\n onTrialEnd?: (data: any) => void;\n}\n\n/**\n * Start an AFC trial by rendering the AFCView component\n */\nexport function startAFCTrial(\n display_element: HTMLElement,\n params: StartAFCTrialParams,\n _jsPsych: JsPsych\n) {\n // Create React root and render AFCView\n const root = createRoot(display_element);\n root.render(React.createElement(AFCView, { params }));\n\n return { root, display_element, jsPsych: _jsPsych };\n}\n\ninterface AFCViewProps {\n params: StartAFCTrialParams;\n}\n\nfunction AFCView({ params }: AFCViewProps) {\n const {\n tangramLeft,\n tangramRight,\n instructions,\n buttonTextLeft,\n buttonTextRight,\n showTangramDecomposition,\n usePrimitiveColors,\n primitiveColorIndices,\n onTrialEnd\n } = params;\n\n // Timing and response tracking\n const trialStartTime = useRef<number>(Date.now());\n const [hasResponded, setHasResponded] = useState(false);\n\n const handleResponse = (choice: \"left\" | \"right\") => {\n if (hasResponded) return;\n\n setHasResponded(true);\n const rt = Date.now() - trialStartTime.current;\n\n if (onTrialEnd) {\n onTrialEnd({\n rt,\n response: choice,\n show_tangram_decomposition: showTangramDecomposition,\n use_primitive_colors: usePrimitiveColors,\n primitive_color_indices: primitiveColorIndices,\n button_text_left: buttonTextLeft,\n button_text_right: buttonTextRight\n });\n }\n };\n\n return (\n <div style={{\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n justifyContent: \"center\",\n padding: \"20px\",\n background: \"#fff7e0ff\",\n minHeight: \"100vh\"\n }}>\n {/* Instructions */}\n {instructions && (\n <div\n style={{\n maxWidth: \"800px\",\n width: \"100%\",\n marginBottom: \"30px\",\n textAlign: \"center\",\n fontSize: \"18px\",\n lineHeight: \"1.5\"\n }}\n dangerouslySetInnerHTML={{ __html: instructions }}\n />\n )}\n\n {/* Container for Tangrams */}\n <div style={{\n display: \"flex\",\n flexDirection: \"row\",\n gap: \"50px\",\n justifyContent: \"center\",\n alignItems: \"flex-start\",\n flexWrap: \"wrap\"\n }}>\n {/* Left Option */}\n <TangramOption\n tangram={tangramLeft}\n buttonText={buttonTextLeft}\n onClick={() => handleResponse(\"left\")}\n disabled={hasResponded}\n showDecomposition={showTangramDecomposition}\n usePrimitiveColors={usePrimitiveColors}\n primitiveColorIndices={primitiveColorIndices}\n />\n\n {/* Right Option */}\n <TangramOption\n tangram={tangramRight}\n buttonText={buttonTextRight}\n onClick={() => handleResponse(\"right\")}\n disabled={hasResponded}\n showDecomposition={showTangramDecomposition}\n usePrimitiveColors={usePrimitiveColors}\n primitiveColorIndices={primitiveColorIndices}\n />\n </div>\n </div>\n );\n}\n\ninterface TangramOptionProps {\n tangram: any;\n buttonText: string;\n onClick: () => void;\n disabled: boolean;\n showDecomposition?: boolean;\n usePrimitiveColors?: boolean;\n primitiveColorIndices?: number[];\n}\n\nfunction TangramOption({\n tangram,\n buttonText,\n onClick,\n disabled,\n showDecomposition,\n usePrimitiveColors,\n primitiveColorIndices\n}: TangramOptionProps) {\n\n if (!tangram) {\n return <div style={{ width: 300, height: 300, background: \"#eee\" }}>No Tangram Data</div>;\n }\n\n // Canonical piece names\n const CANON = new Set([\n \"square\",\n \"smalltriangle\",\n \"parallelogram\",\n \"medtriangle\",\n \"largetriangle\",\n ]);\n\n // Convert TangramSpec to internal format\n const filteredTans = tangram.solutionTans.filter((tan: any) => {\n const tanName = tan.name ?? tan.kind;\n return CANON.has(tanName);\n });\n\n const mask = filteredTans.map((tan: any) => {\n const polygon = tan.vertices.map(([x, y]: number[]) => ({ x: x ?? 0, y: -(y ?? 0) }));\n return polygon;\n });\n\n const primitiveDecomposition = filteredTans.map((tan: any) => ({\n kind: (tan.name ?? tan.kind) as TanKind,\n polygon: tan.vertices.map(([x, y]: number[]) => ({ x: x ?? 0, y: -(y ?? 0) }))\n }));\n\n // Use FIXED viewport size\n const DISPLAY_SIZE = 300;\n const viewport = {\n w: DISPLAY_SIZE,\n h: DISPLAY_SIZE\n };\n\n // Compute scale factor\n const scaleS = React.useMemo(() => {\n const u = inferUnitFromPolys(mask);\n return u ? (CONFIG.layout.grid.unitPx / u) : 1;\n }, [mask]);\n\n const centerPos = {\n cx: viewport.w / 2,\n cy: viewport.h / 2\n };\n\n const pathD = (poly: Poly): string => {\n if (!poly || poly.length === 0) return \"\";\n const moves = poly.map((p, i) => `${i === 0 ? \"M\" : \"L\"} ${p.x} ${p.y}`);\n return moves.join(\" \") + \" Z\";\n };\n\n const renderSilhouette = () => {\n if (showDecomposition) {\n const rawPolys = primitiveDecomposition.map((primInfo: any) => primInfo.polygon);\n const placedPolys = placeSilhouetteGridAlignedAsPolys(rawPolys, scaleS, centerPos);\n\n return (\n <g key=\"sil-decomposed\" pointerEvents=\"none\">\n {placedPolys.map((scaledPoly, i) => {\n const primInfo = primitiveDecomposition[i];\n let fillColor = CONFIG.color.silhouetteMask;\n\n if (usePrimitiveColors && primInfo?.kind && primitiveColorIndices) {\n const kindToIndex: Record<TanKind, number> = {\n 'square': 0,\n 'smalltriangle': 1,\n 'parallelogram': 2,\n 'medtriangle': 3,\n 'largetriangle': 4\n };\n const primitiveIndex = kindToIndex[primInfo.kind as TanKind];\n if (primitiveIndex !== undefined && primitiveColorIndices[primitiveIndex] !== undefined) {\n const colorIndex = primitiveColorIndices[primitiveIndex];\n const color = CONFIG.color.primitiveColors[colorIndex];\n if (color) {\n fillColor = color;\n }\n }\n }\n\n return (\n <React.Fragment key={`prim-${i}`}>\n <path\n d={pathD(scaledPoly)}\n fill={fillColor}\n opacity={usePrimitiveColors ? CONFIG.opacity.piece.normal : CONFIG.opacity.silhouetteMask}\n stroke=\"none\"\n />\n <path\n d={pathD(scaledPoly)}\n fill=\"none\"\n stroke={CONFIG.color.tangramDecomposition.stroke}\n strokeWidth={CONFIG.size.stroke.tangramDecompositionPx}\n />\n </React.Fragment>\n );\n })}\n </g>\n );\n } else {\n const placedPolys = placeSilhouetteGridAlignedAsPolys(mask, scaleS, centerPos);\n\n return (\n <g key=\"sil-unified\" pointerEvents=\"none\">\n {placedPolys.map((scaledPoly, i) => {\n const primInfo = primitiveDecomposition[i];\n let fillColor = CONFIG.color.silhouetteMask;\n\n if (usePrimitiveColors && primInfo?.kind && primitiveColorIndices) {\n const kindToIndex: Record<TanKind, number> = {\n 'square': 0,\n 'smalltriangle': 1,\n 'parallelogram': 2,\n 'medtriangle': 3,\n 'largetriangle': 4\n };\n const primitiveIndex = kindToIndex[primInfo.kind as TanKind];\n if (primitiveIndex !== undefined && primitiveColorIndices[primitiveIndex] !== undefined) {\n const colorIndex = primitiveColorIndices[primitiveIndex];\n const color = CONFIG.color.primitiveColors[colorIndex];\n if (color) {\n fillColor = color;\n }\n }\n }\n\n return (\n <path\n key={`sil-${i}`}\n d={pathD(scaledPoly)}\n fill={fillColor}\n opacity={usePrimitiveColors ? CONFIG.opacity.piece.normal : CONFIG.opacity.silhouetteMask}\n stroke=\"none\"\n />\n );\n })}\n </g>\n );\n }\n };\n\n return (\n <div style={{\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n gap: \"20px\"\n }}>\n <svg\n width={viewport.w}\n height={viewport.h}\n viewBox={`0 0 ${viewport.w} ${viewport.h}`}\n style={{\n display: \"block\",\n background: CONFIG.color.bands.silhouette.fillEven,\n border: `${CONFIG.size.stroke.bandPx}px solid ${CONFIG.color.bands.silhouette.stroke}`,\n borderRadius: \"8px\"\n }}\n >\n {renderSilhouette()}\n </svg>\n\n <button\n className=\"jspsych-btn\"\n onClick={onClick}\n disabled={disabled}\n style={{\n padding: \"12px 30px\",\n fontSize: \"16px\",\n cursor: disabled ? \"not-allowed\" : \"pointer\",\n opacity: disabled ? 0.5 : 1\n }}\n >\n {buttonText}\n </button>\n </div>\n );\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\nimport { startAFCTrial, StartAFCTrialParams } from \"./AFCApp\";\n\nconst info = {\n name: \"tangram-afc\",\n version: \"1.0.0\",\n parameters: {\n /** Left tangram specification to display */\n tangram_left: {\n type: ParameterType.COMPLEX,\n default: undefined,\n description: \"TangramSpec object defining left target shape to display\"\n },\n /** Right tangram specification to display */\n tangram_right: {\n type: ParameterType.COMPLEX,\n default: undefined,\n description: \"TangramSpec object defining right target shape to display\"\n },\n /** HTML content to display above the tangrams as instructions */\n instructions: {\n type: ParameterType.STRING,\n default: \"\",\n description: \"HTML content to display above the tangrams as instructions\"\n },\n /** Text to display on left response button */\n button_text_left: {\n type: ParameterType.STRING,\n default: \"Select Left\",\n description: \"Text to display on left response button\"\n },\n /** Text to display on right response button */\n button_text_right: {\n type: ParameterType.STRING,\n default: \"Select Right\",\n description: \"Text to display on right response button\"\n },\n /** Whether to show tangram decomposed into individual primitives with borders */\n show_tangram_decomposition: {\n type: ParameterType.BOOL,\n default: false,\n description: \"Whether to show tangram decomposed into individual primitives with borders\"\n },\n /** Whether to use distinct colors for each primitive shape type */\n use_primitive_colors: {\n type: ParameterType.BOOL,\n default: false,\n description: \"Whether each primitive shape type should have its own distinct color in the displayed tangram\"\n },\n /** Indices mapping primitives to colors from the color palette */\n primitive_color_indices: {\n type: ParameterType.OBJECT,\n default: [0, 1, 2, 3, 4],\n description: \"Array of 5 integers indexing into primitiveColors array, mapping [square, smalltriangle, parallelogram, medtriangle, largetriangle] to colors\"\n },\n /** Callback fired when trial ends */\n onTrialEnd: {\n type: ParameterType.FUNCTION,\n default: undefined,\n description: \"Callback when trial completes with full data\"\n }\n },\n data: {\n /** Reaction time in milliseconds */\n rt: {\n type: ParameterType.INT,\n description: \"Milliseconds between trial start and button click\"\n },\n /** Response choice */\n response: {\n type: ParameterType.STRING,\n description: \"Which button was clicked: 'left' or 'right'\"\n }\n },\n citations: \"\"\n};\n\ntype Info = typeof info;\n\n/**\n * **tangram-afc**\n *\n * A jsPsych plugin for alternative forced choice (AFC) trials displaying two tangrams\n * side-by-side with response buttons.\n *\n * @author Justin Yang & Sean Paul Anderson\n * @see {@link https://github.com/cogtoolslab/tangram_construction.git/tree/main/experiments/jspsych-tangram-prep}\n */\nclass TangramAFCPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n /**\n * Launches the trial by invoking startAFCTrial\n * with the display element, parameters, and jsPsych instance.\n */\n trial(display_element: HTMLElement, trial: TrialType<Info>) {\n // Wrap onTrialEnd to handle React cleanup and jsPsych trial completion\n const wrappedOnTrialEnd = (data: any) => {\n // Call user-provided callback if exists\n if (trial.onTrialEnd) {\n trial.onTrialEnd(data);\n }\n\n // Clean up React first (before clearing DOM)\n const reactContext = (display_element as any).__reactContext;\n if (reactContext?.root) {\n reactContext.root.unmount();\n }\n\n // Clear display after React cleanup\n display_element.innerHTML = '';\n\n // Finish jsPsych trial with data\n this.jsPsych.finishTrial(data);\n };\n\n // Create parameter object for wrapper\n const params: StartAFCTrialParams = {\n tangramLeft: trial.tangram_left,\n tangramRight: trial.tangram_right,\n instructions: trial.instructions,\n buttonTextLeft: trial.button_text_left,\n buttonTextRight: trial.button_text_right,\n showTangramDecomposition: trial.show_tangram_decomposition,\n usePrimitiveColors: trial.use_primitive_colors,\n primitiveColorIndices: trial.primitive_color_indices,\n onTrialEnd: wrappedOnTrialEnd\n };\n\n // Use React wrapper to start the trial\n const { root, display_element: element, jsPsych } = startAFCTrial(display_element, params, this.jsPsych);\n\n // Store React context for cleanup\n (element as any).__reactContext = { root, jsPsych };\n }\n}\n\nexport default TangramAFCPlugin;\n"],"names":["createRoot","useRef","useState","ParameterType"],"mappings":";;;;;;AAiBO,SAAS,UAAU,KAAA,EAAe;AACvC,EAAA,IAAI,OAAO,QAAA,EAAU,IAAA,GAAO,QAAA,EAAU,IAAA,GAAO,WAAW,IAAA,GAAO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