jspsych-tangram 0.0.1 → 0.0.3

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.
@@ -3432,11 +3432,11 @@ function constructFromSpec(sideLens, angles, firstEdgeUnits) {
3432
3432
  return pts;
3433
3433
  }
3434
3434
  const FIRST_EDGES_UNITS = {
3435
- small_triangle: [P(0, 0), P(0.5, 0.5)],
3436
- parallelogram: [P(0, 0), P(0.5, 0)],
3437
- large_triangle: [P(0, 0), P(0.5, -0.5)],
3438
- med_triangle: [P(0, 0), P(0.5, 0)],
3439
- square: [P(0, 0), P(0.5, 0)]
3435
+ "small-triangle": [P(0, 0), P(0.5, 0.5)],
3436
+ "parallelogram": [P(0, 0), P(0.5, 0)],
3437
+ "large-triangle": [P(0, 0), P(0.5, -0.5)],
3438
+ "med-triangle": [P(0, 0), P(0.5, 0)],
3439
+ "square": [P(0, 0), P(0.5, 0)]
3440
3440
  };
3441
3441
  const PRIMITIVE_BLUEPRINTS_CACHE = (() => {
3442
3442
  const specs = [
@@ -3449,7 +3449,7 @@ const PRIMITIVE_BLUEPRINTS_CACHE = (() => {
3449
3449
  },
3450
3450
  {
3451
3451
  id: "prim:small",
3452
- kind: "small_triangle",
3452
+ kind: "small-triangle",
3453
3453
  sideLens: [HALFDIAGONAL, HALFDIAGONAL, HALFUNIT, HALFUNIT, HALFUNIT, HALFUNIT],
3454
3454
  angles: [180, 45, 180, 90, 180, 45],
3455
3455
  color: "#f59e0b"
@@ -3463,14 +3463,14 @@ const PRIMITIVE_BLUEPRINTS_CACHE = (() => {
3463
3463
  },
3464
3464
  {
3465
3465
  id: "prim:med",
3466
- kind: "med_triangle",
3466
+ kind: "med-triangle",
3467
3467
  sideLens: [HALFUNIT, HALFUNIT, HALFUNIT, HALFUNIT, HALFDIAGONAL, HALFDIAGONAL, HALFDIAGONAL, HALFDIAGONAL],
3468
3468
  angles: [180, 180, 180, 45, 180, 90, 180, 45],
3469
3469
  color: "#3b82f6"
3470
3470
  },
3471
3471
  {
3472
3472
  id: "prim:large",
3473
- kind: "large_triangle",
3473
+ kind: "large-triangle",
3474
3474
  sideLens: [
3475
3475
  HALFDIAGONAL,
3476
3476
  HALFDIAGONAL,
@@ -3540,48 +3540,103 @@ function convertAnchorCompositeToPixels(anchorComposite, primsByKind, gridStepPx
3540
3540
  }
3541
3541
 
3542
3542
  function startConstructionTrial(display_element, params, _jsPsych) {
3543
- const sectors = params.tangrams.map((tangramSpec) => ({
3544
- id: tangramSpec.id,
3545
- silhouette: {
3546
- id: tangramSpec.id,
3547
- mask: tangramSpec.silhouette.mask.map(
3548
- (polygonArray) => polygonArray.map(([x, y]) => ({ x: x ?? 0, y: -(y ?? 0) }))
3549
- // Convert to SVG coords (flip Y)
3550
- ),
3551
- requiredCount: tangramSpec.silhouette.requiredCount
3552
- }
3553
- }));
3543
+ const CANON = /* @__PURE__ */ new Set([
3544
+ "square",
3545
+ "small-triangle",
3546
+ "parallelogram",
3547
+ "med-triangle",
3548
+ "large-triangle"
3549
+ ]);
3550
+ const SECTOR_IDS = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"];
3551
+ console.log("[ConstructionApp] Starting tangram conversion...");
3552
+ console.log("[ConstructionApp] Received tangrams:", params.tangrams);
3553
+ console.log("[ConstructionApp] Number of tangrams:", params.tangrams.length);
3554
+ const sectors = params.tangrams.map((tangramSpec, index) => {
3555
+ console.log(`
3556
+ [ConstructionApp] Processing tangram ${index}:`, tangramSpec);
3557
+ console.log(`[ConstructionApp] tangramID: ${tangramSpec.tangramID}`);
3558
+ console.log(`[ConstructionApp] setLabel: ${tangramSpec.setLabel}`);
3559
+ console.log(`[ConstructionApp] solutionTans count: ${tangramSpec.solutionTans?.length}`);
3560
+ console.log(`[ConstructionApp] solutionTans:`, tangramSpec.solutionTans);
3561
+ const filteredTans = tangramSpec.solutionTans.filter((tan) => {
3562
+ const tanName = tan.name ?? tan.kind;
3563
+ const isCanonical = CANON.has(tanName);
3564
+ console.log(`[ConstructionApp] Tan "${tanName}": canonical=${isCanonical}, vertices count=${tan.vertices?.length}`);
3565
+ return isCanonical;
3566
+ });
3567
+ console.log(`[ConstructionApp] Filtered to ${filteredTans.length} canonical pieces`);
3568
+ const mask = filteredTans.map((tan, tanIndex) => {
3569
+ const tanName = tan.name ?? tan.kind;
3570
+ const polygon = tan.vertices.map(([x, y]) => ({ x: x ?? 0, y: -(y ?? 0) }));
3571
+ console.log(`[ConstructionApp] Polygon ${tanIndex} (${tanName}): ${tan.vertices.length} vertices -> ${polygon.length} points`);
3572
+ console.log(`[ConstructionApp] First vertex: [${tan.vertices[0]?.[0]}, ${tan.vertices[0]?.[1]}] -> {x: ${polygon[0]?.x}, y: ${polygon[0]?.y}}`);
3573
+ return polygon;
3574
+ });
3575
+ const sectorId = SECTOR_IDS[index] ?? `S${index}`;
3576
+ console.log(`[ConstructionApp] Assigned sector ID: ${sectorId}`);
3577
+ console.log(`[ConstructionApp] Final mask has ${mask.length} polygons`);
3578
+ const sector = {
3579
+ id: sectorId,
3580
+ silhouette: {
3581
+ id: sectorId,
3582
+ mask
3583
+ }
3584
+ };
3585
+ console.log(`[ConstructionApp] Created sector:`, sector);
3586
+ return sector;
3587
+ });
3588
+ console.log("\n[ConstructionApp] Final sectors array:", sectors);
3589
+ console.log(`[ConstructionApp] Total sectors created: ${sectors.length}`);
3590
+ console.log("\n[ConstructionApp] Processing quickstash macros...");
3591
+ console.log("[ConstructionApp] quickstash_macros:", params.quickstash_macros);
3592
+ console.log("[ConstructionApp] quickstash_macros count:", params.quickstash_macros?.length ?? 0);
3554
3593
  let quickstash = [];
3555
3594
  if (params.quickstash_macros && params.quickstash_macros.length > 0) {
3556
3595
  const firstMacro = params.quickstash_macros[0];
3596
+ console.log("[ConstructionApp] First macro:", firstMacro);
3557
3597
  if (firstMacro && "parts" in firstMacro && firstMacro.parts && firstMacro.parts[0] && "anchorOffset" in firstMacro.parts[0]) {
3598
+ console.log("[ConstructionApp] Detected anchor-based composites, converting to pixels...");
3558
3599
  const primsByKind = /* @__PURE__ */ new Map();
3559
3600
  PRIMITIVE_BLUEPRINTS.forEach((p) => primsByKind.set(p.kind, p));
3560
3601
  quickstash = params.quickstash_macros.map(
3561
3602
  (anchorComposite) => convertAnchorCompositeToPixels(anchorComposite, primsByKind, CONFIG.layout.grid.stepPx)
3562
3603
  // Use current CONFIG grid step
3563
3604
  );
3605
+ console.log("[ConstructionApp] Converted to pixel-based blueprints:", quickstash);
3564
3606
  } else {
3607
+ console.log("[ConstructionApp] Already pixel-based blueprints");
3565
3608
  quickstash = params.quickstash_macros;
3566
3609
  }
3610
+ } else {
3611
+ console.log("[ConstructionApp] No quickstash macros provided");
3567
3612
  }
3613
+ const gameBoardProps = {
3614
+ sectors,
3615
+ quickstash,
3616
+ primitives: PRIMITIVE_BLUEPRINTS,
3617
+ layout: params.layout || "semicircle",
3618
+ target: params.target || "silhouette",
3619
+ input: params.input || "drag",
3620
+ timeLimitMs: params.time_limit_ms || 0,
3621
+ maxQuickstashSlots: CONFIG.layout.defaults.maxQuickstashSlots,
3622
+ mode: "construction",
3623
+ // Explicit construction mode
3624
+ ...params.onInteraction && { onInteraction: params.onInteraction },
3625
+ ...params.onTrialEnd && { onTrialEnd: params.onTrialEnd }
3626
+ };
3627
+ console.log("\n[ConstructionApp] Final GameBoard props:");
3628
+ console.log("[ConstructionApp] sectors count:", gameBoardProps.sectors.length);
3629
+ console.log("[ConstructionApp] quickstash count:", gameBoardProps.quickstash.length);
3630
+ console.log("[ConstructionApp] primitives count:", gameBoardProps.primitives.length);
3631
+ console.log("[ConstructionApp] layout:", gameBoardProps.layout);
3632
+ console.log("[ConstructionApp] target:", gameBoardProps.target);
3633
+ console.log("[ConstructionApp] input:", gameBoardProps.input);
3634
+ console.log("[ConstructionApp] timeLimitMs:", gameBoardProps.timeLimitMs);
3635
+ console.log("[ConstructionApp] mode:", gameBoardProps.mode);
3636
+ console.log("[ConstructionApp] Full props:", gameBoardProps);
3568
3637
  const root = createRoot(display_element);
3569
- root.render(
3570
- React.createElement(GameBoard, {
3571
- sectors,
3572
- quickstash,
3573
- primitives: PRIMITIVE_BLUEPRINTS,
3574
- layout: params.layout || "semicircle",
3575
- target: params.target || "silhouette",
3576
- input: params.input || "drag",
3577
- timeLimitMs: params.time_limit_ms || 0,
3578
- maxQuickstashSlots: CONFIG.layout.defaults.maxQuickstashSlots,
3579
- mode: "construction",
3580
- // Explicit construction mode
3581
- ...params.onInteraction && { onInteraction: params.onInteraction },
3582
- ...params.onTrialEnd && { onTrialEnd: params.onTrialEnd }
3583
- })
3584
- );
3638
+ root.render(React.createElement(GameBoard, gameBoardProps));
3639
+ console.log("[ConstructionApp] GameBoard rendered successfully");
3585
3640
  return { root, display_element, jsPsych: _jsPsych };
3586
3641
  }
3587
3642