jspsych-tangram 0.0.2 → 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.
- package/dist/construct/index.browser.js +90 -35
- package/dist/construct/index.browser.js.map +1 -1
- package/dist/construct/index.browser.min.js +15 -11
- package/dist/construct/index.browser.min.js.map +1 -1
- package/dist/construct/index.cjs +90 -35
- package/dist/construct/index.cjs.map +1 -1
- package/dist/construct/index.js +90 -35
- package/dist/construct/index.js.map +1 -1
- package/dist/index.cjs +90 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +90 -35
- package/dist/index.js.map +1 -1
- package/dist/prep/index.browser.js +8 -8
- package/dist/prep/index.browser.js.map +1 -1
- package/dist/prep/index.browser.min.js +1 -1
- package/dist/prep/index.browser.min.js.map +1 -1
- package/dist/prep/index.cjs +8 -8
- package/dist/prep/index.cjs.map +1 -1
- package/dist/prep/index.js +8 -8
- package/dist/prep/index.js.map +1 -1
- package/package.json +1 -1
- package/src/core/domain/primitives.ts +8 -8
- package/src/core/domain/types.ts +3 -4
- package/src/core/io/quickstash.ts +3 -3
- package/src/core/io/stims.ts +6 -9
- package/src/core/types/plugin-interfaces.ts +6 -5
- package/src/index.spec.ts +0 -19
- package/src/plugins/tangram-construct/ConstructionApp.tsx +104 -30
- package/tangram-construct.min.js +15 -11
- package/tangram-prep.min.js +1 -1
- package/src/core/io/json-to-tangram-spec.ts +0 -110
|
@@ -20143,11 +20143,11 @@ var TangramConstructPlugin = (function (jspsych) {
|
|
|
20143
20143
|
return pts;
|
|
20144
20144
|
}
|
|
20145
20145
|
const FIRST_EDGES_UNITS = {
|
|
20146
|
-
|
|
20147
|
-
parallelogram: [P(0, 0), P(0.5, 0)],
|
|
20148
|
-
|
|
20149
|
-
|
|
20150
|
-
square: [P(0, 0), P(0.5, 0)]
|
|
20146
|
+
"small-triangle": [P(0, 0), P(0.5, 0.5)],
|
|
20147
|
+
"parallelogram": [P(0, 0), P(0.5, 0)],
|
|
20148
|
+
"large-triangle": [P(0, 0), P(0.5, -0.5)],
|
|
20149
|
+
"med-triangle": [P(0, 0), P(0.5, 0)],
|
|
20150
|
+
"square": [P(0, 0), P(0.5, 0)]
|
|
20151
20151
|
};
|
|
20152
20152
|
const PRIMITIVE_BLUEPRINTS_CACHE = (() => {
|
|
20153
20153
|
const specs = [
|
|
@@ -20160,7 +20160,7 @@ var TangramConstructPlugin = (function (jspsych) {
|
|
|
20160
20160
|
},
|
|
20161
20161
|
{
|
|
20162
20162
|
id: "prim:small",
|
|
20163
|
-
kind: "
|
|
20163
|
+
kind: "small-triangle",
|
|
20164
20164
|
sideLens: [HALFDIAGONAL, HALFDIAGONAL, HALFUNIT, HALFUNIT, HALFUNIT, HALFUNIT],
|
|
20165
20165
|
angles: [180, 45, 180, 90, 180, 45],
|
|
20166
20166
|
color: "#f59e0b"
|
|
@@ -20174,14 +20174,14 @@ var TangramConstructPlugin = (function (jspsych) {
|
|
|
20174
20174
|
},
|
|
20175
20175
|
{
|
|
20176
20176
|
id: "prim:med",
|
|
20177
|
-
kind: "
|
|
20177
|
+
kind: "med-triangle",
|
|
20178
20178
|
sideLens: [HALFUNIT, HALFUNIT, HALFUNIT, HALFUNIT, HALFDIAGONAL, HALFDIAGONAL, HALFDIAGONAL, HALFDIAGONAL],
|
|
20179
20179
|
angles: [180, 180, 180, 45, 180, 90, 180, 45],
|
|
20180
20180
|
color: "#3b82f6"
|
|
20181
20181
|
},
|
|
20182
20182
|
{
|
|
20183
20183
|
id: "prim:large",
|
|
20184
|
-
kind: "
|
|
20184
|
+
kind: "large-triangle",
|
|
20185
20185
|
sideLens: [
|
|
20186
20186
|
HALFDIAGONAL,
|
|
20187
20187
|
HALFDIAGONAL,
|
|
@@ -20251,48 +20251,103 @@ var TangramConstructPlugin = (function (jspsych) {
|
|
|
20251
20251
|
}
|
|
20252
20252
|
|
|
20253
20253
|
function startConstructionTrial(display_element, params, _jsPsych) {
|
|
20254
|
-
const
|
|
20255
|
-
|
|
20256
|
-
|
|
20257
|
-
|
|
20258
|
-
|
|
20259
|
-
|
|
20260
|
-
|
|
20261
|
-
|
|
20262
|
-
|
|
20263
|
-
|
|
20264
|
-
|
|
20254
|
+
const CANON = /* @__PURE__ */ new Set([
|
|
20255
|
+
"square",
|
|
20256
|
+
"small-triangle",
|
|
20257
|
+
"parallelogram",
|
|
20258
|
+
"med-triangle",
|
|
20259
|
+
"large-triangle"
|
|
20260
|
+
]);
|
|
20261
|
+
const SECTOR_IDS = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L"];
|
|
20262
|
+
console.log("[ConstructionApp] Starting tangram conversion...");
|
|
20263
|
+
console.log("[ConstructionApp] Received tangrams:", params.tangrams);
|
|
20264
|
+
console.log("[ConstructionApp] Number of tangrams:", params.tangrams.length);
|
|
20265
|
+
const sectors = params.tangrams.map((tangramSpec, index) => {
|
|
20266
|
+
console.log(`
|
|
20267
|
+
[ConstructionApp] Processing tangram ${index}:`, tangramSpec);
|
|
20268
|
+
console.log(`[ConstructionApp] tangramID: ${tangramSpec.tangramID}`);
|
|
20269
|
+
console.log(`[ConstructionApp] setLabel: ${tangramSpec.setLabel}`);
|
|
20270
|
+
console.log(`[ConstructionApp] solutionTans count: ${tangramSpec.solutionTans?.length}`);
|
|
20271
|
+
console.log(`[ConstructionApp] solutionTans:`, tangramSpec.solutionTans);
|
|
20272
|
+
const filteredTans = tangramSpec.solutionTans.filter((tan) => {
|
|
20273
|
+
const tanName = tan.name ?? tan.kind;
|
|
20274
|
+
const isCanonical = CANON.has(tanName);
|
|
20275
|
+
console.log(`[ConstructionApp] Tan "${tanName}": canonical=${isCanonical}, vertices count=${tan.vertices?.length}`);
|
|
20276
|
+
return isCanonical;
|
|
20277
|
+
});
|
|
20278
|
+
console.log(`[ConstructionApp] Filtered to ${filteredTans.length} canonical pieces`);
|
|
20279
|
+
const mask = filteredTans.map((tan, tanIndex) => {
|
|
20280
|
+
const tanName = tan.name ?? tan.kind;
|
|
20281
|
+
const polygon = tan.vertices.map(([x, y]) => ({ x: x ?? 0, y: -(y ?? 0) }));
|
|
20282
|
+
console.log(`[ConstructionApp] Polygon ${tanIndex} (${tanName}): ${tan.vertices.length} vertices -> ${polygon.length} points`);
|
|
20283
|
+
console.log(`[ConstructionApp] First vertex: [${tan.vertices[0]?.[0]}, ${tan.vertices[0]?.[1]}] -> {x: ${polygon[0]?.x}, y: ${polygon[0]?.y}}`);
|
|
20284
|
+
return polygon;
|
|
20285
|
+
});
|
|
20286
|
+
const sectorId = SECTOR_IDS[index] ?? `S${index}`;
|
|
20287
|
+
console.log(`[ConstructionApp] Assigned sector ID: ${sectorId}`);
|
|
20288
|
+
console.log(`[ConstructionApp] Final mask has ${mask.length} polygons`);
|
|
20289
|
+
const sector = {
|
|
20290
|
+
id: sectorId,
|
|
20291
|
+
silhouette: {
|
|
20292
|
+
id: sectorId,
|
|
20293
|
+
mask
|
|
20294
|
+
}
|
|
20295
|
+
};
|
|
20296
|
+
console.log(`[ConstructionApp] Created sector:`, sector);
|
|
20297
|
+
return sector;
|
|
20298
|
+
});
|
|
20299
|
+
console.log("\n[ConstructionApp] Final sectors array:", sectors);
|
|
20300
|
+
console.log(`[ConstructionApp] Total sectors created: ${sectors.length}`);
|
|
20301
|
+
console.log("\n[ConstructionApp] Processing quickstash macros...");
|
|
20302
|
+
console.log("[ConstructionApp] quickstash_macros:", params.quickstash_macros);
|
|
20303
|
+
console.log("[ConstructionApp] quickstash_macros count:", params.quickstash_macros?.length ?? 0);
|
|
20265
20304
|
let quickstash = [];
|
|
20266
20305
|
if (params.quickstash_macros && params.quickstash_macros.length > 0) {
|
|
20267
20306
|
const firstMacro = params.quickstash_macros[0];
|
|
20307
|
+
console.log("[ConstructionApp] First macro:", firstMacro);
|
|
20268
20308
|
if (firstMacro && "parts" in firstMacro && firstMacro.parts && firstMacro.parts[0] && "anchorOffset" in firstMacro.parts[0]) {
|
|
20309
|
+
console.log("[ConstructionApp] Detected anchor-based composites, converting to pixels...");
|
|
20269
20310
|
const primsByKind = /* @__PURE__ */ new Map();
|
|
20270
20311
|
PRIMITIVE_BLUEPRINTS.forEach((p) => primsByKind.set(p.kind, p));
|
|
20271
20312
|
quickstash = params.quickstash_macros.map(
|
|
20272
20313
|
(anchorComposite) => convertAnchorCompositeToPixels(anchorComposite, primsByKind, CONFIG.layout.grid.stepPx)
|
|
20273
20314
|
// Use current CONFIG grid step
|
|
20274
20315
|
);
|
|
20316
|
+
console.log("[ConstructionApp] Converted to pixel-based blueprints:", quickstash);
|
|
20275
20317
|
} else {
|
|
20318
|
+
console.log("[ConstructionApp] Already pixel-based blueprints");
|
|
20276
20319
|
quickstash = params.quickstash_macros;
|
|
20277
20320
|
}
|
|
20321
|
+
} else {
|
|
20322
|
+
console.log("[ConstructionApp] No quickstash macros provided");
|
|
20278
20323
|
}
|
|
20324
|
+
const gameBoardProps = {
|
|
20325
|
+
sectors,
|
|
20326
|
+
quickstash,
|
|
20327
|
+
primitives: PRIMITIVE_BLUEPRINTS,
|
|
20328
|
+
layout: params.layout || "semicircle",
|
|
20329
|
+
target: params.target || "silhouette",
|
|
20330
|
+
input: params.input || "drag",
|
|
20331
|
+
timeLimitMs: params.time_limit_ms || 0,
|
|
20332
|
+
maxQuickstashSlots: CONFIG.layout.defaults.maxQuickstashSlots,
|
|
20333
|
+
mode: "construction",
|
|
20334
|
+
// Explicit construction mode
|
|
20335
|
+
...params.onInteraction && { onInteraction: params.onInteraction },
|
|
20336
|
+
...params.onTrialEnd && { onTrialEnd: params.onTrialEnd }
|
|
20337
|
+
};
|
|
20338
|
+
console.log("\n[ConstructionApp] Final GameBoard props:");
|
|
20339
|
+
console.log("[ConstructionApp] sectors count:", gameBoardProps.sectors.length);
|
|
20340
|
+
console.log("[ConstructionApp] quickstash count:", gameBoardProps.quickstash.length);
|
|
20341
|
+
console.log("[ConstructionApp] primitives count:", gameBoardProps.primitives.length);
|
|
20342
|
+
console.log("[ConstructionApp] layout:", gameBoardProps.layout);
|
|
20343
|
+
console.log("[ConstructionApp] target:", gameBoardProps.target);
|
|
20344
|
+
console.log("[ConstructionApp] input:", gameBoardProps.input);
|
|
20345
|
+
console.log("[ConstructionApp] timeLimitMs:", gameBoardProps.timeLimitMs);
|
|
20346
|
+
console.log("[ConstructionApp] mode:", gameBoardProps.mode);
|
|
20347
|
+
console.log("[ConstructionApp] Full props:", gameBoardProps);
|
|
20279
20348
|
const root = clientExports.createRoot(display_element);
|
|
20280
|
-
root.render(
|
|
20281
|
-
|
|
20282
|
-
sectors,
|
|
20283
|
-
quickstash,
|
|
20284
|
-
primitives: PRIMITIVE_BLUEPRINTS,
|
|
20285
|
-
layout: params.layout || "semicircle",
|
|
20286
|
-
target: params.target || "silhouette",
|
|
20287
|
-
input: params.input || "drag",
|
|
20288
|
-
timeLimitMs: params.time_limit_ms || 0,
|
|
20289
|
-
maxQuickstashSlots: CONFIG.layout.defaults.maxQuickstashSlots,
|
|
20290
|
-
mode: "construction",
|
|
20291
|
-
// Explicit construction mode
|
|
20292
|
-
...params.onInteraction && { onInteraction: params.onInteraction },
|
|
20293
|
-
...params.onTrialEnd && { onTrialEnd: params.onTrialEnd }
|
|
20294
|
-
})
|
|
20295
|
-
);
|
|
20349
|
+
root.render(React.createElement(GameBoard, gameBoardProps));
|
|
20350
|
+
console.log("[ConstructionApp] GameBoard rendered successfully");
|
|
20296
20351
|
return { root, display_element, jsPsych: _jsPsych };
|
|
20297
20352
|
}
|
|
20298
20353
|
|