jspsych-tangram 0.0.10 → 0.0.11

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.
@@ -22,16 +22,49 @@ function polysAABB(polys) {
22
22
  const CONFIG = {
23
23
  color: {
24
24
  bands: {
25
- silhouette: { fillEven: "#fff2ccff", stroke: "#b1b1b1" }},
25
+ silhouette: { fillEven: "#fff2ccff", fillOdd: "#fff2ccff", stroke: "#b1b1b1" },
26
+ workspace: { fillEven: "#fff2ccff", fillOdd: "#fff2ccff", stroke: "#b1b1b1" }
27
+ },
28
+ completion: { fill: "#ccfff2", stroke: "#13da57" },
26
29
  silhouetteMask: "#374151",
30
+ anchors: { invalid: "#7dd3fc", valid: "#475569" },
31
+ piece: { draggingFill: "#8e7cc3ff", validFill: "#8e7cc3ff", invalidFill: "#ef4444", invalidStroke: "#dc2626", selectedStroke: "#674ea7", allGreenStroke: "#86efac", borderStroke: "#674ea7" },
32
+ ui: { light: "#60a5fa", dark: "#1d4ed8" },
33
+ blueprint: { fill: "#374151", selectedStroke: "#111827", badgeFill: "#000000", labelFill: "#ffffff" },
27
34
  tangramDecomposition: { stroke: "#fef2cc" }
28
35
  },
29
36
  opacity: {
30
- silhouetteMask: 0.25},
37
+ blueprint: 0.4,
38
+ silhouetteMask: 0.25,
39
+ //anchors: { valid: 0.80, invalid: 0.50 },
40
+ anchors: { invalid: 0, valid: 0 },
41
+ piece: { invalid: 0.35, dragging: 0.75, locked: 1, normal: 1 }
42
+ },
31
43
  size: {
32
- stroke: { bandPx: 5, tangramDecompositionPx: 1 }},
44
+ stroke: { bandPx: 5, pieceSelectedPx: 3, allGreenStrokePx: 10, pieceBorderPx: 2, tangramDecompositionPx: 1 },
45
+ anchorRadiusPx: { valid: 1, invalid: 1 },
46
+ badgeFontPx: 16,
47
+ centerBadge: { fractionOfOuterR: 0.15, minPx: 20, marginPx: 4 }
48
+ },
33
49
  layout: {
34
- grid: { stepPx: 20, unitPx: 40 }}};
50
+ grid: { stepPx: 20, unitPx: 40 },
51
+ paddingPx: 1,
52
+ viewportScale: 0.8,
53
+ constraints: {
54
+ workspaceDiamAnchors: 10,
55
+ // num anchors req'd to be on diagonal
56
+ quickstashDiamAnchors: 7,
57
+ // num anchors req'd to be in single quickstash slot
58
+ primitiveDiamAnchors: 5
59
+ },
60
+ defaults: { maxQuickstashSlots: 1 }
61
+ },
62
+ game: {
63
+ snapRadiusPx: 15,
64
+ showBorders: false,
65
+ hideTouchingBorders: true
66
+ }
67
+ };
35
68
 
36
69
  const GRID_PX = CONFIG.layout.grid.stepPx;
37
70
  function igcd(a, b) {
@@ -225,9 +258,8 @@ function NBackView({ params }) {
225
258
  display: "flex",
226
259
  flexDirection: "column",
227
260
  alignItems: "center",
228
- justifyContent: "flex-start",
229
- minHeight: "100vh",
230
- padding: "40px 20px",
261
+ justifyContent: "center",
262
+ padding: "20px",
231
263
  background: "#f5f5f5"
232
264
  } }, instructions && /* @__PURE__ */ React.createElement(
233
265
  "div",
@@ -1 +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-nback/NBackApp.tsx","../../src/plugins/tangram-nback/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 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 };\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 };\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 };\n};\n\nexport const CONFIG: Config = {\n color: {\n bands: {\n silhouette: { fillEven: \"#fff2ccff\", fillOdd: \"#fff2ccff\", stroke: \"#b1b1b1\" },\n workspace: { fillEven: \"#fff2ccff\", fillOdd: \"#fff2ccff\", stroke: \"#b1b1b1\" }\n },\n completion: { fill: \"#ccfff2\", stroke: \"#13da57\" },\n silhouetteMask: \"#374151\",\n anchors: { invalid: \"#7dd3fc\", valid: \"#475569\" },\n piece: { draggingFill: \"#8e7cc3ff\", validFill: \"#8e7cc3ff\", invalidFill: \"#ef4444\", 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 },\n opacity: {\n blueprint: 0.4,\n silhouetteMask: 0.25,\n //anchors: { valid: 0.80, invalid: 0.50 },\n anchors: { invalid: 0.0, valid: 0.0 },\n piece: { invalid: 0.35, dragging: 0.75, locked: 1, normal: 1 },\n },\n size: {\n stroke: { bandPx: 5, pieceSelectedPx: 3, 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 },\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 }\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 * NBackApp.tsx - React wrapper for tangram n-back matching trials\n *\n * This component handles the React rendering logic for n-back trials,\n * displaying a single tangram silhouette with a response button.\n */\n\nimport React, { useRef, useEffect, 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 StartNBackTrialParams {\n tangram: any;\n isMatch?: boolean;\n show_tangram_decomposition?: boolean;\n instructions?: string;\n button_text?: string;\n duration: number;\n onTrialEnd?: (data: any) => void;\n}\n\n/**\n * Start an n-back trial by rendering the NBackView component\n */\nexport function startNBackTrial(\n display_element: HTMLElement,\n params: StartNBackTrialParams,\n _jsPsych: JsPsych\n) {\n // Create React root and render NBackView\n const root = createRoot(display_element);\n root.render(React.createElement(NBackView, { params }));\n\n return { root, display_element, jsPsych: _jsPsych };\n}\n\ninterface NBackViewProps {\n params: StartNBackTrialParams;\n}\n\nfunction NBackView({ params }: NBackViewProps) {\n const {\n tangram,\n isMatch,\n show_tangram_decomposition,\n instructions,\n button_text,\n duration,\n onTrialEnd\n } = params;\n\n // Timing and response tracking\n const trialStartTime = useRef<number>(Date.now());\n const buttonEnabledRef = useRef<boolean>(true);\n const timeoutIdRef = useRef<NodeJS.Timeout | null>(null);\n const hasRespondedRef = useRef<boolean>(false);\n const responseDataRef = useRef<any>(null);\n const [buttonDisabled, setButtonDisabled] = useState(false);\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 for n-back display (constant across all tangrams)\n const DISPLAY_SIZE = 400;\n const viewport = {\n w: DISPLAY_SIZE,\n h: DISPLAY_SIZE\n };\n\n // Compute scale factor to keep tangram pieces at constant physical size\n // This matches the approach in TangramConstructPlugin/GameBoard\n const scaleS = React.useMemo(() => {\n const u = inferUnitFromPolys(mask);\n return u ? (CONFIG.layout.grid.unitPx / u) : 1;\n }, [mask]);\n\n // For n-back display, we want tangrams centered in viewport\n // Don't use computeCircleLayout's positioning - just center manually\n const centerPos = {\n cx: viewport.w / 2,\n cy: viewport.h / 2\n };\n\n // Helper to convert polygon to SVG path\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 // End trial with data\n const endTrial = (data: {\n responded_match: boolean;\n rt: number;\n responded_after_duration: boolean;\n rt_after_duration: number;\n }) => {\n // Clear timeout if it exists\n if (timeoutIdRef.current) {\n clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n // Compute accuracy\n const accuracy = isMatch !== undefined\n ? (isMatch === data.responded_match ? 1 : 0)\n : NaN;\n\n const trialData = {\n ...data,\n accuracy,\n tangram_id: tangram.tangramID,\n is_match: isMatch\n };\n\n if (onTrialEnd) {\n onTrialEnd(trialData);\n }\n };\n\n // Handle button click\n const handleButtonClick = () => {\n if (!buttonEnabledRef.current) {\n // Late response after duration expired\n const rt_late = Date.now() - trialStartTime.current;\n hasRespondedRef.current = true;\n responseDataRef.current = {\n responded_match: true,\n rt: NaN,\n responded_after_duration: true,\n rt_after_duration: rt_late\n };\n endTrial(responseDataRef.current);\n } else {\n // Response before duration expired - disable button but continue showing trial\n const rt = Date.now() - trialStartTime.current;\n buttonEnabledRef.current = false;\n setButtonDisabled(true);\n hasRespondedRef.current = true;\n responseDataRef.current = {\n responded_match: true,\n rt,\n responded_after_duration: false,\n rt_after_duration: NaN\n };\n // Don't end trial yet - wait for duration timeout\n }\n };\n\n // Set up duration timeout\n useEffect(() => {\n timeoutIdRef.current = setTimeout(() => {\n buttonEnabledRef.current = false;\n\n // End trial with appropriate data\n if (hasRespondedRef.current && responseDataRef.current) {\n // User already responded - use saved response data\n endTrial(responseDataRef.current);\n } else {\n // No response - end with no-response data\n endTrial({\n responded_match: false,\n rt: NaN,\n responded_after_duration: false,\n rt_after_duration: NaN\n });\n }\n }, duration);\n\n return () => {\n if (timeoutIdRef.current) {\n clearTimeout(timeoutIdRef.current);\n }\n };\n }, []);\n\n // Render silhouette\n const renderSilhouette = () => {\n if (show_tangram_decomposition) {\n // Render decomposed primitives with borders\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 <React.Fragment key={`prim-${i}`}>\n {/* Fill path */}\n <path\n d={pathD(scaledPoly)}\n fill={CONFIG.color.silhouetteMask}\n opacity={CONFIG.opacity.silhouetteMask}\n stroke=\"none\"\n />\n\n {/* Full perimeter border */}\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 </g>\n );\n } else {\n // Render unified silhouette\n const placedPolys = placeSilhouetteGridAlignedAsPolys(mask, scaleS, centerPos);\n\n return (\n <g key=\"sil-unified\" pointerEvents=\"none\">\n {placedPolys.map((scaledPoly, i) => (\n <path\n key={`sil-${i}`}\n d={pathD(scaledPoly)}\n fill={CONFIG.color.silhouetteMask}\n opacity={CONFIG.opacity.silhouetteMask}\n stroke=\"none\"\n />\n ))}\n </g>\n );\n }\n };\n\n return (\n <div style={{\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n justifyContent: \"flex-start\",\n minHeight: \"100vh\",\n padding: \"40px 20px\",\n background: \"#f5f5f5\"\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 SVG and button */}\n <div style={{\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n gap: \"30px\"\n }}>\n {/* SVG with tangram silhouette */}\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 {/* Response button */}\n <button\n className=\"jspsych-btn\"\n onClick={handleButtonClick}\n disabled={buttonDisabled}\n style={{\n padding: \"12px 30px\",\n fontSize: \"16px\",\n cursor: buttonDisabled ? \"not-allowed\" : \"pointer\",\n opacity: buttonDisabled ? 0.5 : 1\n }}\n >\n {button_text}\n </button>\n </div>\n </div>\n );\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\nimport { startNBackTrial, StartNBackTrialParams } from \"./NBackApp\";\n\nconst info = {\n name: \"tangram-nback\",\n version: \"1.0.0\",\n parameters: {\n /** Single tangram specification to display */\n tangram: {\n type: ParameterType.COMPLEX,\n default: undefined,\n description: \"TangramSpec object defining target shape to display\"\n },\n /** Whether this trial is a match (for computing accuracy) */\n isMatch: {\n type: ParameterType.BOOL,\n default: undefined,\n description: \"Whether this tangram matches the previous one (optional)\"\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 /** HTML content to display above the tangram as instructions */\n instructions: {\n type: ParameterType.STRING,\n default: \"\",\n description: \"HTML content to display above the tangram as instructions\"\n },\n /** Text to display on response button */\n button_text: {\n type: ParameterType.STRING,\n default: \"Same as previous!\",\n description: \"Text to display on response button\"\n },\n /** Duration to display tangram and accept responses (milliseconds) */\n duration: {\n type: ParameterType.INT,\n default: 3000,\n description: \"Duration in milliseconds to display tangram and accept responses\"\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 /** Whether participant clicked the response button before duration expired */\n responded_match: {\n type: ParameterType.BOOL,\n description: \"True if participant clicked response button, false otherwise\"\n },\n /** Reaction time in milliseconds (NaN if no response or response after duration) */\n rt: {\n type: ParameterType.INT,\n description: \"Milliseconds between trial start and button click (NaN if no response or late response)\"\n },\n /** Accuracy: 1 if correct, 0 if incorrect, NaN if isMatch not provided */\n accuracy: {\n type: ParameterType.FLOAT,\n description: \"1 if response matches isMatch parameter, 0 otherwise (NaN if isMatch not provided)\"\n },\n /** Whether response occurred after duration expired */\n responded_after_duration: {\n type: ParameterType.BOOL,\n description: \"True if button clicked after duration expired, false otherwise\"\n },\n /** Time of late response (NaN if no late response) */\n rt_after_duration: {\n type: ParameterType.INT,\n description: \"Milliseconds between trial start and late button click (NaN if no late response)\"\n }\n },\n citations: \"\"\n};\n\ntype Info = typeof info;\n\n/**\n * **tangram-nback**\n *\n * A jsPsych plugin for n-back matching trials displaying a single tangram\n * with a response button.\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 TangramNBackPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n /**\n * Launches the trial by invoking startNBackTrial\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: StartNBackTrialParams = {\n tangram: trial.tangram,\n isMatch: trial.isMatch,\n show_tangram_decomposition: trial.show_tangram_decomposition,\n instructions: trial.instructions,\n button_text: trial.button_text,\n duration: trial.duration,\n onTrialEnd: wrappedOnTrialEnd\n };\n\n // Use React wrapper to start the trial\n const { root, display_element: element, jsPsych } = startNBackTrial(display_element, params, this.jsPsych);\n\n // Store React context for cleanup\n (element as any).__reactContext = { root, jsPsych };\n }\n}\n\nexport default TangramNBackPlugin;\n"],"names":["createRoot","useRef","useState","useEffect","ParameterType"],"mappings":";;;;;;AAiBO,SAAS,UAAU,KAAA,EAAe;AACvC,EAAA,IAAI,OAAO,QAAA,EAAU,IAAA,GAAO,QAAA,EAAU,IAAA,GAAO,WAAW,IAAA,GAAO,CAAA,QAAA;AAC/D,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,KAAA,MAAW,KAAK,IAAA,EAAM;AACpB,MAAA,IAAI,CAAA,CAAE,CAAA,GAAI,IAAA,EAAM,IAAA,GAAO,CAAA,CAAE,CAAA;AACzB,MAAA,IAAI,CAAA,CAAE,CAAA,GAAI,IAAA,EAAM,IAAA,GAAO,CAAA,CAAE,CAAA;AACzB,MAAA,IAAI,CAAA,CAAE,CAAA,GAAI,IAAA,EAAM,IAAA,GAAO,CAAA,CAAE,CAAA;AACzB,MAAA,IAAI,CAAA,CAAE,CAAA,GAAI,IAAA,EAAM,IAAA,GAAO,CAAA,CAAE,CAAA;AAAA,IAC3B;AAAA,EACF;AACA,EAAA,MAAM,KAAA,GAAS,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,OAAO,IAAI,CAAA;AACtC,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,OAAO,IAAI,CAAA;AACtC,EAAA,OAAO,EAAE,GAAA,EAAK,EAAE,CAAA,EAAG,IAAA,EAAM,GAAG,IAAA,EAAK,EAAG,GAAA,EAAK,EAAE,CAAA,EAAG,IAAA,EAAM,GAAG,IAAA,EAAK,EAA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AAA;AAAA,MACf,4BAA4B,KAAA,CAAM,0BAAA;AAAA,MAClC,cAAc,KAAA,CAAM,YAAA;AAAA,MACpB,aAAa,KAAA,CAAM,WAAA;AAAA,MACnB,UAAU,KAAA,CAAM,QAAA;AAAA,MAChB,UAAA,EAAY;AAAA,KACd;AAGA,IAAA,MAAM,EAAE,IAAA,EAAM,eAAA,EAAiB,OAAA,EAAS,OAAA,KAAY,eAAA,CAAgB,eAAA,EAAiB,MAAA,EAAQ,IAAA,CAAK,OAAO,CAAA;AAGzG,IAAC,OAAA,CAAgB,cAAA,GAAiB,EAAE,IAAA,EAAM,OAAA,EAAQ;AAAA,EACpD;AACF;;;;"}
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-nback/NBackApp.tsx","../../src/plugins/tangram-nback/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 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 };\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 };\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 };\n};\n\nexport const CONFIG: Config = {\n color: {\n bands: {\n silhouette: { fillEven: \"#fff2ccff\", fillOdd: \"#fff2ccff\", stroke: \"#b1b1b1\" },\n workspace: { fillEven: \"#fff2ccff\", fillOdd: \"#fff2ccff\", stroke: \"#b1b1b1\" }\n },\n completion: { fill: \"#ccfff2\", stroke: \"#13da57\" },\n silhouetteMask: \"#374151\",\n anchors: { invalid: \"#7dd3fc\", valid: \"#475569\" },\n piece: { draggingFill: \"#8e7cc3ff\", validFill: \"#8e7cc3ff\", invalidFill: \"#ef4444\", 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 },\n opacity: {\n blueprint: 0.4,\n silhouetteMask: 0.25,\n //anchors: { valid: 0.80, invalid: 0.50 },\n anchors: { invalid: 0.0, valid: 0.0 },\n piece: { invalid: 0.35, dragging: 0.75, locked: 1, normal: 1 },\n },\n size: {\n stroke: { bandPx: 5, pieceSelectedPx: 3, 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 },\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 }\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 * NBackApp.tsx - React wrapper for tangram n-back matching trials\n *\n * This component handles the React rendering logic for n-back trials,\n * displaying a single tangram silhouette with a response button.\n */\n\nimport React, { useRef, useEffect, 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 StartNBackTrialParams {\n tangram: any;\n isMatch?: boolean;\n show_tangram_decomposition?: boolean;\n instructions?: string;\n button_text?: string;\n duration: number;\n onTrialEnd?: (data: any) => void;\n}\n\n/**\n * Start an n-back trial by rendering the NBackView component\n */\nexport function startNBackTrial(\n display_element: HTMLElement,\n params: StartNBackTrialParams,\n _jsPsych: JsPsych\n) {\n // Create React root and render NBackView\n const root = createRoot(display_element);\n root.render(React.createElement(NBackView, { params }));\n\n return { root, display_element, jsPsych: _jsPsych };\n}\n\ninterface NBackViewProps {\n params: StartNBackTrialParams;\n}\n\nfunction NBackView({ params }: NBackViewProps) {\n const {\n tangram,\n isMatch,\n show_tangram_decomposition,\n instructions,\n button_text,\n duration,\n onTrialEnd\n } = params;\n\n // Timing and response tracking\n const trialStartTime = useRef<number>(Date.now());\n const buttonEnabledRef = useRef<boolean>(true);\n const timeoutIdRef = useRef<NodeJS.Timeout | null>(null);\n const hasRespondedRef = useRef<boolean>(false);\n const responseDataRef = useRef<any>(null);\n const [buttonDisabled, setButtonDisabled] = useState(false);\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 for n-back display (constant across all tangrams)\n const DISPLAY_SIZE = 400;\n const viewport = {\n w: DISPLAY_SIZE,\n h: DISPLAY_SIZE\n };\n\n // Compute scale factor to keep tangram pieces at constant physical size\n // This matches the approach in TangramConstructPlugin/GameBoard\n const scaleS = React.useMemo(() => {\n const u = inferUnitFromPolys(mask);\n return u ? (CONFIG.layout.grid.unitPx / u) : 1;\n }, [mask]);\n\n // For n-back display, we want tangrams centered in viewport\n // Don't use computeCircleLayout's positioning - just center manually\n const centerPos = {\n cx: viewport.w / 2,\n cy: viewport.h / 2\n };\n\n // Helper to convert polygon to SVG path\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 // End trial with data\n const endTrial = (data: {\n responded_match: boolean;\n rt: number;\n responded_after_duration: boolean;\n rt_after_duration: number;\n }) => {\n // Clear timeout if it exists\n if (timeoutIdRef.current) {\n clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n // Compute accuracy\n const accuracy = isMatch !== undefined\n ? (isMatch === data.responded_match ? 1 : 0)\n : NaN;\n\n const trialData = {\n ...data,\n accuracy,\n tangram_id: tangram.tangramID,\n is_match: isMatch\n };\n\n if (onTrialEnd) {\n onTrialEnd(trialData);\n }\n };\n\n // Handle button click\n const handleButtonClick = () => {\n if (!buttonEnabledRef.current) {\n // Late response after duration expired\n const rt_late = Date.now() - trialStartTime.current;\n hasRespondedRef.current = true;\n responseDataRef.current = {\n responded_match: true,\n rt: NaN,\n responded_after_duration: true,\n rt_after_duration: rt_late\n };\n endTrial(responseDataRef.current);\n } else {\n // Response before duration expired - disable button but continue showing trial\n const rt = Date.now() - trialStartTime.current;\n buttonEnabledRef.current = false;\n setButtonDisabled(true);\n hasRespondedRef.current = true;\n responseDataRef.current = {\n responded_match: true,\n rt,\n responded_after_duration: false,\n rt_after_duration: NaN\n };\n // Don't end trial yet - wait for duration timeout\n }\n };\n\n // Set up duration timeout\n useEffect(() => {\n timeoutIdRef.current = setTimeout(() => {\n buttonEnabledRef.current = false;\n\n // End trial with appropriate data\n if (hasRespondedRef.current && responseDataRef.current) {\n // User already responded - use saved response data\n endTrial(responseDataRef.current);\n } else {\n // No response - end with no-response data\n endTrial({\n responded_match: false,\n rt: NaN,\n responded_after_duration: false,\n rt_after_duration: NaN\n });\n }\n }, duration);\n\n return () => {\n if (timeoutIdRef.current) {\n clearTimeout(timeoutIdRef.current);\n }\n };\n }, []);\n\n // Render silhouette\n const renderSilhouette = () => {\n if (show_tangram_decomposition) {\n // Render decomposed primitives with borders\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 <React.Fragment key={`prim-${i}`}>\n {/* Fill path */}\n <path\n d={pathD(scaledPoly)}\n fill={CONFIG.color.silhouetteMask}\n opacity={CONFIG.opacity.silhouetteMask}\n stroke=\"none\"\n />\n\n {/* Full perimeter border */}\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 </g>\n );\n } else {\n // Render unified silhouette\n const placedPolys = placeSilhouetteGridAlignedAsPolys(mask, scaleS, centerPos);\n\n return (\n <g key=\"sil-unified\" pointerEvents=\"none\">\n {placedPolys.map((scaledPoly, i) => (\n <path\n key={`sil-${i}`}\n d={pathD(scaledPoly)}\n fill={CONFIG.color.silhouetteMask}\n opacity={CONFIG.opacity.silhouetteMask}\n stroke=\"none\"\n />\n ))}\n </g>\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: \"#f5f5f5\"\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 SVG and button */}\n <div style={{\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n gap: \"30px\"\n }}>\n {/* SVG with tangram silhouette */}\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 {/* Response button */}\n <button\n className=\"jspsych-btn\"\n onClick={handleButtonClick}\n disabled={buttonDisabled}\n style={{\n padding: \"12px 30px\",\n fontSize: \"16px\",\n cursor: buttonDisabled ? \"not-allowed\" : \"pointer\",\n opacity: buttonDisabled ? 0.5 : 1\n }}\n >\n {button_text}\n </button>\n </div>\n </div>\n );\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\nimport { startNBackTrial, StartNBackTrialParams } from \"./NBackApp\";\n\nconst info = {\n name: \"tangram-nback\",\n version: \"1.0.0\",\n parameters: {\n /** Single tangram specification to display */\n tangram: {\n type: ParameterType.COMPLEX,\n default: undefined,\n description: \"TangramSpec object defining target shape to display\"\n },\n /** Whether this trial is a match (for computing accuracy) */\n isMatch: {\n type: ParameterType.BOOL,\n default: undefined,\n description: \"Whether this tangram matches the previous one (optional)\"\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 /** HTML content to display above the tangram as instructions */\n instructions: {\n type: ParameterType.STRING,\n default: \"\",\n description: \"HTML content to display above the tangram as instructions\"\n },\n /** Text to display on response button */\n button_text: {\n type: ParameterType.STRING,\n default: \"Same as previous!\",\n description: \"Text to display on response button\"\n },\n /** Duration to display tangram and accept responses (milliseconds) */\n duration: {\n type: ParameterType.INT,\n default: 3000,\n description: \"Duration in milliseconds to display tangram and accept responses\"\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 /** Whether participant clicked the response button before duration expired */\n responded_match: {\n type: ParameterType.BOOL,\n description: \"True if participant clicked response button, false otherwise\"\n },\n /** Reaction time in milliseconds (NaN if no response or response after duration) */\n rt: {\n type: ParameterType.INT,\n description: \"Milliseconds between trial start and button click (NaN if no response or late response)\"\n },\n /** Accuracy: 1 if correct, 0 if incorrect, NaN if isMatch not provided */\n accuracy: {\n type: ParameterType.FLOAT,\n description: \"1 if response matches isMatch parameter, 0 otherwise (NaN if isMatch not provided)\"\n },\n /** Whether response occurred after duration expired */\n responded_after_duration: {\n type: ParameterType.BOOL,\n description: \"True if button clicked after duration expired, false otherwise\"\n },\n /** Time of late response (NaN if no late response) */\n rt_after_duration: {\n type: ParameterType.INT,\n description: \"Milliseconds between trial start and late button click (NaN if no late response)\"\n }\n },\n citations: \"\"\n};\n\ntype Info = typeof info;\n\n/**\n * **tangram-nback**\n *\n * A jsPsych plugin for n-back matching trials displaying a single tangram\n * with a response button.\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 TangramNBackPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n /**\n * Launches the trial by invoking startNBackTrial\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: StartNBackTrialParams = {\n tangram: trial.tangram,\n isMatch: trial.isMatch,\n show_tangram_decomposition: trial.show_tangram_decomposition,\n instructions: trial.instructions,\n button_text: trial.button_text,\n duration: trial.duration,\n onTrialEnd: wrappedOnTrialEnd\n };\n\n // Use React wrapper to start the trial\n const { root, display_element: element, jsPsych } = startNBackTrial(display_element, params, this.jsPsych);\n\n // Store React context for cleanup\n (element as any).__reactContext = { root, j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,CAAA,cAAA,GAAiB,EAAE,IAAA,EAAM,OAAQ,EAAA,CAAA;AAAA,GACpD;AACF;;;;"}
@@ -20,16 +20,49 @@ function polysAABB(polys) {
20
20
  const CONFIG = {
21
21
  color: {
22
22
  bands: {
23
- silhouette: { fillEven: "#fff2ccff", stroke: "#b1b1b1" }},
23
+ silhouette: { fillEven: "#fff2ccff", fillOdd: "#fff2ccff", stroke: "#b1b1b1" },
24
+ workspace: { fillEven: "#fff2ccff", fillOdd: "#fff2ccff", stroke: "#b1b1b1" }
25
+ },
26
+ completion: { fill: "#ccfff2", stroke: "#13da57" },
24
27
  silhouetteMask: "#374151",
28
+ anchors: { invalid: "#7dd3fc", valid: "#475569" },
29
+ piece: { draggingFill: "#8e7cc3ff", validFill: "#8e7cc3ff", invalidFill: "#ef4444", invalidStroke: "#dc2626", selectedStroke: "#674ea7", allGreenStroke: "#86efac", borderStroke: "#674ea7" },
30
+ ui: { light: "#60a5fa", dark: "#1d4ed8" },
31
+ blueprint: { fill: "#374151", selectedStroke: "#111827", badgeFill: "#000000", labelFill: "#ffffff" },
25
32
  tangramDecomposition: { stroke: "#fef2cc" }
26
33
  },
27
34
  opacity: {
28
- silhouetteMask: 0.25},
35
+ blueprint: 0.4,
36
+ silhouetteMask: 0.25,
37
+ //anchors: { valid: 0.80, invalid: 0.50 },
38
+ anchors: { invalid: 0, valid: 0 },
39
+ piece: { invalid: 0.35, dragging: 0.75, locked: 1, normal: 1 }
40
+ },
29
41
  size: {
30
- stroke: { bandPx: 5, tangramDecompositionPx: 1 }},
42
+ stroke: { bandPx: 5, pieceSelectedPx: 3, allGreenStrokePx: 10, pieceBorderPx: 2, tangramDecompositionPx: 1 },
43
+ anchorRadiusPx: { valid: 1, invalid: 1 },
44
+ badgeFontPx: 16,
45
+ centerBadge: { fractionOfOuterR: 0.15, minPx: 20, marginPx: 4 }
46
+ },
31
47
  layout: {
32
- grid: { stepPx: 20, unitPx: 40 }}};
48
+ grid: { stepPx: 20, unitPx: 40 },
49
+ paddingPx: 1,
50
+ viewportScale: 0.8,
51
+ constraints: {
52
+ workspaceDiamAnchors: 10,
53
+ // num anchors req'd to be on diagonal
54
+ quickstashDiamAnchors: 7,
55
+ // num anchors req'd to be in single quickstash slot
56
+ primitiveDiamAnchors: 5
57
+ },
58
+ defaults: { maxQuickstashSlots: 1 }
59
+ },
60
+ game: {
61
+ snapRadiusPx: 15,
62
+ showBorders: false,
63
+ hideTouchingBorders: true
64
+ }
65
+ };
33
66
 
34
67
  const GRID_PX = CONFIG.layout.grid.stepPx;
35
68
  function igcd(a, b) {
@@ -223,9 +256,8 @@ function NBackView({ params }) {
223
256
  display: "flex",
224
257
  flexDirection: "column",
225
258
  alignItems: "center",
226
- justifyContent: "flex-start",
227
- minHeight: "100vh",
228
- padding: "40px 20px",
259
+ justifyContent: "center",
260
+ padding: "20px",
229
261
  background: "#f5f5f5"
230
262
  } }, instructions && /* @__PURE__ */ React.createElement(
231
263
  "div",
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/core/engine/geometry/bounds.ts","../../src/core/config/config.ts","../../src/core/engine/geometry/pieces.ts","../../src/plugins/tangram-nback/NBackApp.tsx","../../src/plugins/tangram-nback/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 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 };\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 };\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 };\n};\n\nexport const CONFIG: Config = {\n color: {\n bands: {\n silhouette: { fillEven: \"#fff2ccff\", fillOdd: \"#fff2ccff\", stroke: \"#b1b1b1\" },\n workspace: { fillEven: \"#fff2ccff\", fillOdd: \"#fff2ccff\", stroke: \"#b1b1b1\" }\n },\n completion: { fill: \"#ccfff2\", stroke: \"#13da57\" },\n silhouetteMask: \"#374151\",\n anchors: { invalid: \"#7dd3fc\", valid: \"#475569\" },\n piece: { draggingFill: \"#8e7cc3ff\", validFill: \"#8e7cc3ff\", invalidFill: \"#ef4444\", 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 },\n opacity: {\n blueprint: 0.4,\n silhouetteMask: 0.25,\n //anchors: { valid: 0.80, invalid: 0.50 },\n anchors: { invalid: 0.0, valid: 0.0 },\n piece: { invalid: 0.35, dragging: 0.75, locked: 1, normal: 1 },\n },\n size: {\n stroke: { bandPx: 5, pieceSelectedPx: 3, 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 },\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 }\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 * NBackApp.tsx - React wrapper for tangram n-back matching trials\n *\n * This component handles the React rendering logic for n-back trials,\n * displaying a single tangram silhouette with a response button.\n */\n\nimport React, { useRef, useEffect, 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 StartNBackTrialParams {\n tangram: any;\n isMatch?: boolean;\n show_tangram_decomposition?: boolean;\n instructions?: string;\n button_text?: string;\n duration: number;\n onTrialEnd?: (data: any) => void;\n}\n\n/**\n * Start an n-back trial by rendering the NBackView component\n */\nexport function startNBackTrial(\n display_element: HTMLElement,\n params: StartNBackTrialParams,\n _jsPsych: JsPsych\n) {\n // Create React root and render NBackView\n const root = createRoot(display_element);\n root.render(React.createElement(NBackView, { params }));\n\n return { root, display_element, jsPsych: _jsPsych };\n}\n\ninterface NBackViewProps {\n params: StartNBackTrialParams;\n}\n\nfunction NBackView({ params }: NBackViewProps) {\n const {\n tangram,\n isMatch,\n show_tangram_decomposition,\n instructions,\n button_text,\n duration,\n onTrialEnd\n } = params;\n\n // Timing and response tracking\n const trialStartTime = useRef<number>(Date.now());\n const buttonEnabledRef = useRef<boolean>(true);\n const timeoutIdRef = useRef<NodeJS.Timeout | null>(null);\n const hasRespondedRef = useRef<boolean>(false);\n const responseDataRef = useRef<any>(null);\n const [buttonDisabled, setButtonDisabled] = useState(false);\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 for n-back display (constant across all tangrams)\n const DISPLAY_SIZE = 400;\n const viewport = {\n w: DISPLAY_SIZE,\n h: DISPLAY_SIZE\n };\n\n // Compute scale factor to keep tangram pieces at constant physical size\n // This matches the approach in TangramConstructPlugin/GameBoard\n const scaleS = React.useMemo(() => {\n const u = inferUnitFromPolys(mask);\n return u ? (CONFIG.layout.grid.unitPx / u) : 1;\n }, [mask]);\n\n // For n-back display, we want tangrams centered in viewport\n // Don't use computeCircleLayout's positioning - just center manually\n const centerPos = {\n cx: viewport.w / 2,\n cy: viewport.h / 2\n };\n\n // Helper to convert polygon to SVG path\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 // End trial with data\n const endTrial = (data: {\n responded_match: boolean;\n rt: number;\n responded_after_duration: boolean;\n rt_after_duration: number;\n }) => {\n // Clear timeout if it exists\n if (timeoutIdRef.current) {\n clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n // Compute accuracy\n const accuracy = isMatch !== undefined\n ? (isMatch === data.responded_match ? 1 : 0)\n : NaN;\n\n const trialData = {\n ...data,\n accuracy,\n tangram_id: tangram.tangramID,\n is_match: isMatch\n };\n\n if (onTrialEnd) {\n onTrialEnd(trialData);\n }\n };\n\n // Handle button click\n const handleButtonClick = () => {\n if (!buttonEnabledRef.current) {\n // Late response after duration expired\n const rt_late = Date.now() - trialStartTime.current;\n hasRespondedRef.current = true;\n responseDataRef.current = {\n responded_match: true,\n rt: NaN,\n responded_after_duration: true,\n rt_after_duration: rt_late\n };\n endTrial(responseDataRef.current);\n } else {\n // Response before duration expired - disable button but continue showing trial\n const rt = Date.now() - trialStartTime.current;\n buttonEnabledRef.current = false;\n setButtonDisabled(true);\n hasRespondedRef.current = true;\n responseDataRef.current = {\n responded_match: true,\n rt,\n responded_after_duration: false,\n rt_after_duration: NaN\n };\n // Don't end trial yet - wait for duration timeout\n }\n };\n\n // Set up duration timeout\n useEffect(() => {\n timeoutIdRef.current = setTimeout(() => {\n buttonEnabledRef.current = false;\n\n // End trial with appropriate data\n if (hasRespondedRef.current && responseDataRef.current) {\n // User already responded - use saved response data\n endTrial(responseDataRef.current);\n } else {\n // No response - end with no-response data\n endTrial({\n responded_match: false,\n rt: NaN,\n responded_after_duration: false,\n rt_after_duration: NaN\n });\n }\n }, duration);\n\n return () => {\n if (timeoutIdRef.current) {\n clearTimeout(timeoutIdRef.current);\n }\n };\n }, []);\n\n // Render silhouette\n const renderSilhouette = () => {\n if (show_tangram_decomposition) {\n // Render decomposed primitives with borders\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 <React.Fragment key={`prim-${i}`}>\n {/* Fill path */}\n <path\n d={pathD(scaledPoly)}\n fill={CONFIG.color.silhouetteMask}\n opacity={CONFIG.opacity.silhouetteMask}\n stroke=\"none\"\n />\n\n {/* Full perimeter border */}\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 </g>\n );\n } else {\n // Render unified silhouette\n const placedPolys = placeSilhouetteGridAlignedAsPolys(mask, scaleS, centerPos);\n\n return (\n <g key=\"sil-unified\" pointerEvents=\"none\">\n {placedPolys.map((scaledPoly, i) => (\n <path\n key={`sil-${i}`}\n d={pathD(scaledPoly)}\n fill={CONFIG.color.silhouetteMask}\n opacity={CONFIG.opacity.silhouetteMask}\n stroke=\"none\"\n />\n ))}\n </g>\n );\n }\n };\n\n return (\n <div style={{\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n justifyContent: \"flex-start\",\n minHeight: \"100vh\",\n padding: \"40px 20px\",\n background: \"#f5f5f5\"\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 SVG and button */}\n <div style={{\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n gap: \"30px\"\n }}>\n {/* SVG with tangram silhouette */}\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 {/* Response button */}\n <button\n className=\"jspsych-btn\"\n onClick={handleButtonClick}\n disabled={buttonDisabled}\n style={{\n padding: \"12px 30px\",\n fontSize: \"16px\",\n cursor: buttonDisabled ? \"not-allowed\" : \"pointer\",\n opacity: buttonDisabled ? 0.5 : 1\n }}\n >\n {button_text}\n </button>\n </div>\n </div>\n );\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\nimport { startNBackTrial, StartNBackTrialParams } from \"./NBackApp\";\n\nconst info = {\n name: \"tangram-nback\",\n version: \"1.0.0\",\n parameters: {\n /** Single tangram specification to display */\n tangram: {\n type: ParameterType.COMPLEX,\n default: undefined,\n description: \"TangramSpec object defining target shape to display\"\n },\n /** Whether this trial is a match (for computing accuracy) */\n isMatch: {\n type: ParameterType.BOOL,\n default: undefined,\n description: \"Whether this tangram matches the previous one (optional)\"\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 /** HTML content to display above the tangram as instructions */\n instructions: {\n type: ParameterType.STRING,\n default: \"\",\n description: \"HTML content to display above the tangram as instructions\"\n },\n /** Text to display on response button */\n button_text: {\n type: ParameterType.STRING,\n default: \"Same as previous!\",\n description: \"Text to display on response button\"\n },\n /** Duration to display tangram and accept responses (milliseconds) */\n duration: {\n type: ParameterType.INT,\n default: 3000,\n description: \"Duration in milliseconds to display tangram and accept responses\"\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 /** Whether participant clicked the response button before duration expired */\n responded_match: {\n type: ParameterType.BOOL,\n description: \"True if participant clicked response button, false otherwise\"\n },\n /** Reaction time in milliseconds (NaN if no response or response after duration) */\n rt: {\n type: ParameterType.INT,\n description: \"Milliseconds between trial start and button click (NaN if no response or late response)\"\n },\n /** Accuracy: 1 if correct, 0 if incorrect, NaN if isMatch not provided */\n accuracy: {\n type: ParameterType.FLOAT,\n description: \"1 if response matches isMatch parameter, 0 otherwise (NaN if isMatch not provided)\"\n },\n /** Whether response occurred after duration expired */\n responded_after_duration: {\n type: ParameterType.BOOL,\n description: \"True if button clicked after duration expired, false otherwise\"\n },\n /** Time of late response (NaN if no late response) */\n rt_after_duration: {\n type: ParameterType.INT,\n description: \"Milliseconds between trial start and late button click (NaN if no late response)\"\n }\n },\n citations: \"\"\n};\n\ntype Info = typeof info;\n\n/**\n * **tangram-nback**\n *\n * A jsPsych plugin for n-back matching trials displaying a single tangram\n * with a response button.\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 TangramNBackPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n /**\n * Launches the trial by invoking startNBackTrial\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: StartNBackTrialParams = {\n tangram: trial.tangram,\n isMatch: trial.isMatch,\n show_tangram_decomposition: trial.show_tangram_decomposition,\n instructions: trial.instructions,\n button_text: trial.button_text,\n duration: trial.duration,\n onTrialEnd: wrappedOnTrialEnd\n };\n\n // Use React wrapper to start the trial\n const { root, display_element: element, jsPsych } = startNBackTrial(display_element, params, this.jsPsych);\n\n // Store React context for cleanup\n (element as any).__reactContext = { root, jsPsych };\n }\n}\n\nexport default TangramNBackPlugin;\n"],"names":[],"mappings":";;;;AAiBO,SAAS,UAAU,KAAA,EAAe;AACvC,EAAA,IAAI,OAAO,QAAA,EAAU,IAAA,GAAO,QAAA,EAAU,IAAA,GAAO,WAAW,IAAA,GAAO,CAAA,QAAA;AAC/D,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,KAAA,MAAW,KAAK,IAAA,EAAM;AACpB,MAAA,IAAI,CAAA,CAAE,CAAA,GAAI,IAAA,EAAM,IAAA,GAAO,CAAA,CAAE,CAAA;AACzB,MAAA,IAAI,CAAA,CAAE,CAAA,GAAI,IAAA,EAAM,IAAA,GAAO,CAAA,CAAE,CAAA;AACzB,MAAA,IAAI,CAAA,CAAE,CAAA,GAAI,IAAA,EAAM,IAAA,GAAO,CAAA,CAAE,CAAA;AACzB,MAAA,IAAI,CAAA,CAAE,CAAA,GAAI,IAAA,EAAM,IAAA,GAAO,CAAA,CAAE,CAAA;AAAA,IAC3B;AAAA,EACF;AACA,EAAA,MAAM,KAAA,GAAS,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,OAAO,IAAI,CAAA;AACtC,EAAA,MAAM,MAAA,GAAS,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,OAAO,IAAI,CAAA;AACtC,EAAA,OAAO,EAAE,GAAA,EAAK,EAAE,CAAA,EAAG,IAAA,EAAM,GAAG,IAAA,EAAK,EAAG,GAAA,EAAK,EAAE,CAAA,EAAG,IAAA,EAAM,GAAG,IAAA,EAAK,EAAG,KAAA,EAAO,MAAA,EAAQ,EAAA,EAAA,CAAI,IAAA,GAAK,QAA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A,CAAM,WAAA;AAAA,MACnB,UAAU,KAAA,CAAM,QAAA;AAAA,MAChB,UAAA,EAAY;AAAA,KACd;AAGA,IAAA,MAAM,EAAE,IAAA,EAAM,eAAA,EAAiB,OAAA,EAAS,OAAA,KAAY,eAAA,CAAgB,eAAA,EAAiB,MAAA,EAAQ,IAAA,CAAK,OAAO,CAAA;AAGzG,IAAC,OAAA,CAAgB,cAAA,GAAiB,EAAE,IAAA,EAAM,OAAA,EAAQ;AAAA,EACpD;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/core/engine/geometry/bounds.ts","../../src/core/config/config.ts","../../src/core/engine/geometry/pieces.ts","../../src/plugins/tangram-nback/NBackApp.tsx","../../src/plugins/tangram-nback/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 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 };\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 };\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 };\n};\n\nexport const CONFIG: Config = {\n color: {\n bands: {\n silhouette: { fillEven: \"#fff2ccff\", fillOdd: \"#fff2ccff\", stroke: \"#b1b1b1\" },\n workspace: { fillEven: \"#fff2ccff\", fillOdd: \"#fff2ccff\", stroke: \"#b1b1b1\" }\n },\n completion: { fill: \"#ccfff2\", stroke: \"#13da57\" },\n silhouetteMask: \"#374151\",\n anchors: { invalid: \"#7dd3fc\", valid: \"#475569\" },\n piece: { draggingFill: \"#8e7cc3ff\", validFill: \"#8e7cc3ff\", invalidFill: \"#ef4444\", 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 },\n opacity: {\n blueprint: 0.4,\n silhouetteMask: 0.25,\n //anchors: { valid: 0.80, invalid: 0.50 },\n anchors: { invalid: 0.0, valid: 0.0 },\n piece: { invalid: 0.35, dragging: 0.75, locked: 1, normal: 1 },\n },\n size: {\n stroke: { bandPx: 5, pieceSelectedPx: 3, 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 },\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 }\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 * NBackApp.tsx - React wrapper for tangram n-back matching trials\n *\n * This component handles the React rendering logic for n-back trials,\n * displaying a single tangram silhouette with a response button.\n */\n\nimport React, { useRef, useEffect, 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 StartNBackTrialParams {\n tangram: any;\n isMatch?: boolean;\n show_tangram_decomposition?: boolean;\n instructions?: string;\n button_text?: string;\n duration: number;\n onTrialEnd?: (data: any) => void;\n}\n\n/**\n * Start an n-back trial by rendering the NBackView component\n */\nexport function startNBackTrial(\n display_element: HTMLElement,\n params: StartNBackTrialParams,\n _jsPsych: JsPsych\n) {\n // Create React root and render NBackView\n const root = createRoot(display_element);\n root.render(React.createElement(NBackView, { params }));\n\n return { root, display_element, jsPsych: _jsPsych };\n}\n\ninterface NBackViewProps {\n params: StartNBackTrialParams;\n}\n\nfunction NBackView({ params }: NBackViewProps) {\n const {\n tangram,\n isMatch,\n show_tangram_decomposition,\n instructions,\n button_text,\n duration,\n onTrialEnd\n } = params;\n\n // Timing and response tracking\n const trialStartTime = useRef<number>(Date.now());\n const buttonEnabledRef = useRef<boolean>(true);\n const timeoutIdRef = useRef<NodeJS.Timeout | null>(null);\n const hasRespondedRef = useRef<boolean>(false);\n const responseDataRef = useRef<any>(null);\n const [buttonDisabled, setButtonDisabled] = useState(false);\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 for n-back display (constant across all tangrams)\n const DISPLAY_SIZE = 400;\n const viewport = {\n w: DISPLAY_SIZE,\n h: DISPLAY_SIZE\n };\n\n // Compute scale factor to keep tangram pieces at constant physical size\n // This matches the approach in TangramConstructPlugin/GameBoard\n const scaleS = React.useMemo(() => {\n const u = inferUnitFromPolys(mask);\n return u ? (CONFIG.layout.grid.unitPx / u) : 1;\n }, [mask]);\n\n // For n-back display, we want tangrams centered in viewport\n // Don't use computeCircleLayout's positioning - just center manually\n const centerPos = {\n cx: viewport.w / 2,\n cy: viewport.h / 2\n };\n\n // Helper to convert polygon to SVG path\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 // End trial with data\n const endTrial = (data: {\n responded_match: boolean;\n rt: number;\n responded_after_duration: boolean;\n rt_after_duration: number;\n }) => {\n // Clear timeout if it exists\n if (timeoutIdRef.current) {\n clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n // Compute accuracy\n const accuracy = isMatch !== undefined\n ? (isMatch === data.responded_match ? 1 : 0)\n : NaN;\n\n const trialData = {\n ...data,\n accuracy,\n tangram_id: tangram.tangramID,\n is_match: isMatch\n };\n\n if (onTrialEnd) {\n onTrialEnd(trialData);\n }\n };\n\n // Handle button click\n const handleButtonClick = () => {\n if (!buttonEnabledRef.current) {\n // Late response after duration expired\n const rt_late = Date.now() - trialStartTime.current;\n hasRespondedRef.current = true;\n responseDataRef.current = {\n responded_match: true,\n rt: NaN,\n responded_after_duration: true,\n rt_after_duration: rt_late\n };\n endTrial(responseDataRef.current);\n } else {\n // Response before duration expired - disable button but continue showing trial\n const rt = Date.now() - trialStartTime.current;\n buttonEnabledRef.current = false;\n setButtonDisabled(true);\n hasRespondedRef.current = true;\n responseDataRef.current = {\n responded_match: true,\n rt,\n responded_after_duration: false,\n rt_after_duration: NaN\n };\n // Don't end trial yet - wait for duration timeout\n }\n };\n\n // Set up duration timeout\n useEffect(() => {\n timeoutIdRef.current = setTimeout(() => {\n buttonEnabledRef.current = false;\n\n // End trial with appropriate data\n if (hasRespondedRef.current && responseDataRef.current) {\n // User already responded - use saved response data\n endTrial(responseDataRef.current);\n } else {\n // No response - end with no-response data\n endTrial({\n responded_match: false,\n rt: NaN,\n responded_after_duration: false,\n rt_after_duration: NaN\n });\n }\n }, duration);\n\n return () => {\n if (timeoutIdRef.current) {\n clearTimeout(timeoutIdRef.current);\n }\n };\n }, []);\n\n // Render silhouette\n const renderSilhouette = () => {\n if (show_tangram_decomposition) {\n // Render decomposed primitives with borders\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 <React.Fragment key={`prim-${i}`}>\n {/* Fill path */}\n <path\n d={pathD(scaledPoly)}\n fill={CONFIG.color.silhouetteMask}\n opacity={CONFIG.opacity.silhouetteMask}\n stroke=\"none\"\n />\n\n {/* Full perimeter border */}\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 </g>\n );\n } else {\n // Render unified silhouette\n const placedPolys = placeSilhouetteGridAlignedAsPolys(mask, scaleS, centerPos);\n\n return (\n <g key=\"sil-unified\" pointerEvents=\"none\">\n {placedPolys.map((scaledPoly, i) => (\n <path\n key={`sil-${i}`}\n d={pathD(scaledPoly)}\n fill={CONFIG.color.silhouetteMask}\n opacity={CONFIG.opacity.silhouetteMask}\n stroke=\"none\"\n />\n ))}\n </g>\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: \"#f5f5f5\"\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 SVG and button */}\n <div style={{\n display: \"flex\",\n flexDirection: \"column\",\n alignItems: \"center\",\n gap: \"30px\"\n }}>\n {/* SVG with tangram silhouette */}\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 {/* Response button */}\n <button\n className=\"jspsych-btn\"\n onClick={handleButtonClick}\n disabled={buttonDisabled}\n style={{\n padding: \"12px 30px\",\n fontSize: \"16px\",\n cursor: buttonDisabled ? \"not-allowed\" : \"pointer\",\n opacity: buttonDisabled ? 0.5 : 1\n }}\n >\n {button_text}\n </button>\n </div>\n </div>\n );\n}\n","import { JsPsych, JsPsychPlugin, ParameterType, TrialType } from \"jspsych\";\nimport { startNBackTrial, StartNBackTrialParams } from \"./NBackApp\";\n\nconst info = {\n name: \"tangram-nback\",\n version: \"1.0.0\",\n parameters: {\n /** Single tangram specification to display */\n tangram: {\n type: ParameterType.COMPLEX,\n default: undefined,\n description: \"TangramSpec object defining target shape to display\"\n },\n /** Whether this trial is a match (for computing accuracy) */\n isMatch: {\n type: ParameterType.BOOL,\n default: undefined,\n description: \"Whether this tangram matches the previous one (optional)\"\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 /** HTML content to display above the tangram as instructions */\n instructions: {\n type: ParameterType.STRING,\n default: \"\",\n description: \"HTML content to display above the tangram as instructions\"\n },\n /** Text to display on response button */\n button_text: {\n type: ParameterType.STRING,\n default: \"Same as previous!\",\n description: \"Text to display on response button\"\n },\n /** Duration to display tangram and accept responses (milliseconds) */\n duration: {\n type: ParameterType.INT,\n default: 3000,\n description: \"Duration in milliseconds to display tangram and accept responses\"\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 /** Whether participant clicked the response button before duration expired */\n responded_match: {\n type: ParameterType.BOOL,\n description: \"True if participant clicked response button, false otherwise\"\n },\n /** Reaction time in milliseconds (NaN if no response or response after duration) */\n rt: {\n type: ParameterType.INT,\n description: \"Milliseconds between trial start and button click (NaN if no response or late response)\"\n },\n /** Accuracy: 1 if correct, 0 if incorrect, NaN if isMatch not provided */\n accuracy: {\n type: ParameterType.FLOAT,\n description: \"1 if response matches isMatch parameter, 0 otherwise (NaN if isMatch not provided)\"\n },\n /** Whether response occurred after duration expired */\n responded_after_duration: {\n type: ParameterType.BOOL,\n description: \"True if button clicked after duration expired, false otherwise\"\n },\n /** Time of late response (NaN if no late response) */\n rt_after_duration: {\n type: ParameterType.INT,\n description: \"Milliseconds between trial start and late button click (NaN if no late response)\"\n }\n },\n citations: \"\"\n};\n\ntype Info = typeof info;\n\n/**\n * **tangram-nback**\n *\n * A jsPsych plugin for n-back matching trials displaying a single tangram\n * with a response button.\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 TangramNBackPlugin implements JsPsychPlugin<Info> {\n static info = info;\n\n constructor(private jsPsych: JsPsych) {}\n\n /**\n * Launches the trial by invoking startNBackTrial\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: StartNBackTrialParams = {\n tangram: trial.tangram,\n isMatch: trial.isMatch,\n show_tangram_decomposition: trial.show_tangram_decomposition,\n instructions: trial.instructions,\n button_text: trial.button_text,\n duration: trial.duration,\n onTrialEnd: wrappedOnTrialEnd\n };\n\n // Use React wrapper to start the trial\n const { root, display_element: element, jsPsych } = startNBackTrial(display_element, params, this.jsPsych);\n\n // Store React context for cleanup\n (element as any).__reactContext = { root, jsPsych };\n }\n}\n\nexport default TangramNBackPlugin;\n"],"names":[],"mappings":";;;;AAiBO,SAAS,UAAU,KAAe,EAAA;AACvC,EAAA,IAA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