jspsych-tangram 0.0.13 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/construct/index.browser.js +3873 -4515
  2. package/dist/construct/index.browser.js.map +1 -1
  3. package/dist/construct/index.browser.min.js +13 -13
  4. package/dist/construct/index.browser.min.js.map +1 -1
  5. package/dist/construct/index.cjs +16 -6
  6. package/dist/construct/index.cjs.map +1 -1
  7. package/dist/construct/index.js +16 -6
  8. package/dist/construct/index.js.map +1 -1
  9. package/dist/index.cjs +17 -7
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.js +17 -7
  12. package/dist/index.js.map +1 -1
  13. package/dist/nback/index.browser.js +3900 -4515
  14. package/dist/nback/index.browser.js.map +1 -1
  15. package/dist/nback/index.browser.min.js +12 -12
  16. package/dist/nback/index.browser.min.js.map +1 -1
  17. package/dist/nback/index.cjs +42 -5
  18. package/dist/nback/index.cjs.map +1 -1
  19. package/dist/nback/index.js +42 -5
  20. package/dist/nback/index.js.map +1 -1
  21. package/dist/prep/index.browser.js +3875 -4515
  22. package/dist/prep/index.browser.js.map +1 -1
  23. package/dist/prep/index.browser.min.js +13 -13
  24. package/dist/prep/index.browser.min.js.map +1 -1
  25. package/dist/prep/index.cjs +19 -7
  26. package/dist/prep/index.cjs.map +1 -1
  27. package/dist/prep/index.js +19 -7
  28. package/dist/prep/index.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/core/components/board/GameBoard.tsx +13 -42
  31. package/src/core/components/board/useGameBoard.ts +52 -0
  32. package/src/core/components/index.ts +4 -2
  33. package/src/core/components/pieces/BlueprintRing.tsx +0 -25
  34. package/src/core/components/pieces/useBlueprintRing.ts +39 -0
  35. package/src/plugins/tangram-nback/NBackApp.tsx +1 -1
  36. package/tangram-construct.min.js +13 -13
  37. package/tangram-nback.min.js +12 -12
  38. package/tangram-prep.min.js +13 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jspsych-tangram",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "Tangram tasks for jsPsych: prep and construct.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -718,15 +718,25 @@ export default function GameBoard(props: GameBoardProps) {
718
718
  textAlign: 'center'
719
719
  };
720
720
 
721
- // Timer style (positioned absolutely to not affect centering)
721
+ // Timer style - positioned absolutely to align right edge with semicircle's right edge
722
+ // Independent of instructions content
723
+ const scaleX = svgDimensions.width / viewBox.w;
724
+ const rightEdgeOfSemicircleLogical = viewBox.w / 2 + layout.outerR;
725
+ const distanceFromRightEdgeLogical = viewBox.w - rightEdgeOfSemicircleLogical;
726
+ const distanceFromRightEdgePx = distanceFromRightEdgeLogical * scaleX;
727
+
728
+ // Shift left by 5 monospaced characters (monospace is typically 0.6em wide per char)
729
+ const charWidth = 24 * 0.6; // fontSize * typical monospace char width ratio
730
+ const offsetLeft = charWidth * 5;
731
+
722
732
  const timerStyle: React.CSSProperties = {
723
733
  position: 'absolute',
724
- right: 0,
734
+ right: `${distanceFromRightEdgePx + offsetLeft}px`,
725
735
  fontSize: '24px',
726
736
  fontWeight: 'bold',
727
737
  fontFamily: 'monospace',
728
738
  color: '#333',
729
- minWidth: '80px',
739
+ whiteSpace: 'nowrap',
730
740
  textAlign: 'right'
731
741
  };
732
742
 
@@ -797,42 +807,3 @@ export default function GameBoard(props: GameBoardProps) {
797
807
  </div>
798
808
  );
799
809
  }
800
-
801
- /**
802
- * Hook for managing GameBoard state externally
803
- * Useful for plugins that need direct access to game state
804
- */
805
- export function useGameBoard(config: GameBoardConfig) {
806
- const controller = React.useMemo(() => {
807
- const gameConfig = {
808
- n: config.sectors.length,
809
- layout: config.layout,
810
- target: config.target,
811
- input: config.input,
812
- timeLimitMs: config.timeLimitMs,
813
- maxQuickstashSlots: config.maxQuickstashSlots,
814
- ...(config.maxCompositeSize !== undefined && { maxCompositeSize: config.maxCompositeSize }),
815
- mode: config.mode || "construction",
816
- ...(config.minPiecesPerMacro !== undefined && { minPiecesPerMacro: config.minPiecesPerMacro }),
817
- ...(config.requireAllSlots !== undefined && { requireAllSlots: config.requireAllSlots })
818
- };
819
-
820
- return new BaseGameController(
821
- config.sectors,
822
- config.quickstash,
823
- config.primitives,
824
- gameConfig
825
- );
826
- }, [config]);
827
-
828
- const snapshot = React.useMemo(() =>
829
- controller.snapshot(),
830
- [controller.updateCount]
831
- );
832
-
833
- return {
834
- controller,
835
- snapshot,
836
- isComplete: !!controller.state.endedAt
837
- };
838
- }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Hook for managing GameBoard state externally
3
+ *
4
+ * This hook provides external access to the GameBoard's internal state
5
+ * management, useful for plugins that need to track or control game state
6
+ * directly without rendering the full GameBoard component.
7
+ *
8
+ * REQUIRES: config contains valid GameBoardConfig properties
9
+ * EFFECTS: Creates and manages a BaseGameController instance
10
+ *
11
+ * @param config - GameBoard configuration object
12
+ * @returns Object containing controller, snapshot, and completion status
13
+ */
14
+
15
+ import React from "react";
16
+ import { BaseGameController } from "@/core/engine/state/BaseGameController";
17
+ import type { GameBoardConfig } from "./GameBoard";
18
+
19
+ export function useGameBoard(config: GameBoardConfig) {
20
+ const controller = React.useMemo(() => {
21
+ const gameConfig = {
22
+ n: config.sectors.length,
23
+ layout: config.layout,
24
+ target: config.target,
25
+ input: config.input,
26
+ timeLimitMs: config.timeLimitMs,
27
+ maxQuickstashSlots: config.maxQuickstashSlots,
28
+ ...(config.maxCompositeSize !== undefined && { maxCompositeSize: config.maxCompositeSize }),
29
+ mode: config.mode || "construction",
30
+ ...(config.minPiecesPerMacro !== undefined && { minPiecesPerMacro: config.minPiecesPerMacro }),
31
+ ...(config.requireAllSlots !== undefined && { requireAllSlots: config.requireAllSlots })
32
+ };
33
+
34
+ return new BaseGameController(
35
+ config.sectors,
36
+ config.quickstash,
37
+ config.primitives,
38
+ gameConfig
39
+ );
40
+ }, [config]);
41
+
42
+ const snapshot = React.useMemo(() =>
43
+ controller.snapshot(),
44
+ [controller.updateCount]
45
+ );
46
+
47
+ return {
48
+ controller,
49
+ snapshot,
50
+ isComplete: !!controller.state.endedAt
51
+ };
52
+ }
@@ -6,11 +6,13 @@
6
6
  */
7
7
 
8
8
  // Core game board component
9
- export { default as GameBoard, useGameBoard } from './board/GameBoard';
9
+ export { default as GameBoard } from './board/GameBoard';
10
+ export { useGameBoard } from './board/useGameBoard';
10
11
  export type { GameBoardConfig, GameBoardProps } from './board/GameBoard';
11
12
 
12
13
  // Blueprint ring component for plugin UI
13
- export { default as BlueprintRing, useBlueprintRing } from './pieces/BlueprintRing';
14
+ export { default as BlueprintRing } from './pieces/BlueprintRing';
15
+ export { useBlueprintRing } from './pieces/useBlueprintRing';
14
16
  export type { BlueprintRingProps } from './pieces/BlueprintRing';
15
17
 
16
18
  // Legacy Board components (deprecated - use GameBoard instead)
@@ -268,29 +268,4 @@ export default function BlueprintRing(props: BlueprintRingProps) {
268
268
  })}
269
269
  </g>
270
270
  );
271
- }
272
-
273
- /**
274
- * Hook for managing blueprint ring state
275
- * Useful for components that need more control over blueprint ring behavior
276
- */
277
- export function useBlueprintRing(
278
- primitives: PrimitiveBlueprint[],
279
- quickstash: Blueprint[],
280
- initialView: "primitives" | "quickstash" = "quickstash"
281
- ) {
282
- const [currentView, setCurrentView] = React.useState<"primitives" | "quickstash">(initialView);
283
-
284
- const switchView = React.useCallback(() => {
285
- setCurrentView(prev => prev === "primitives" ? "quickstash" : "primitives");
286
- }, []);
287
-
288
- const blueprints = currentView === "primitives" ? primitives : quickstash;
289
-
290
- return {
291
- currentView,
292
- blueprints,
293
- switchView,
294
- setCurrentView
295
- };
296
271
  }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Hook for managing BlueprintRing state externally
3
+ *
4
+ * This hook manages the state for switching between primitives and quickstash
5
+ * views in the blueprint ring. Useful for components that need more control
6
+ * over blueprint ring behavior.
7
+ *
8
+ * REQUIRES: primitives and quickstash are valid arrays of blueprints
9
+ * EFFECTS: Manages view state and provides toggle functionality
10
+ *
11
+ * @param primitives - Array of primitive piece blueprints
12
+ * @param quickstash - Array of quickstash macro blueprints
13
+ * @param initialView - Initial view to display (defaults to "quickstash")
14
+ * @returns Object with current view, blueprints, and control functions
15
+ */
16
+
17
+ import React from "react";
18
+ import type { Blueprint, PrimitiveBlueprint } from "@/core/domain/types";
19
+
20
+ export function useBlueprintRing(
21
+ primitives: PrimitiveBlueprint[],
22
+ quickstash: Blueprint[],
23
+ initialView: "primitives" | "quickstash" = "quickstash"
24
+ ) {
25
+ const [currentView, setCurrentView] = React.useState<"primitives" | "quickstash">(initialView);
26
+
27
+ const switchView = React.useCallback(() => {
28
+ setCurrentView(prev => prev === "primitives" ? "quickstash" : "primitives");
29
+ }, []);
30
+
31
+ const blueprints = currentView === "primitives" ? primitives : quickstash;
32
+
33
+ return {
34
+ currentView,
35
+ blueprints,
36
+ switchView,
37
+ setCurrentView
38
+ };
39
+ }
@@ -315,7 +315,7 @@ function NBackView({ params }: NBackViewProps) {
315
315
  alignItems: "center",
316
316
  justifyContent: "center",
317
317
  padding: "20px",
318
- background: "#f5f5f5"
318
+ background: "#fff7e0ff"
319
319
  }}>
320
320
  {/* Instructions */}
321
321
  {instructions && (