@astronox/core 0.5.4 → 0.5.6

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 (29) hide show
  1. package/README.md +13 -0
  2. package/package.json +1 -1
  3. package/src/components/content/AnnotatedText/AnnotatedText.astro +38 -0
  4. package/src/components/content/AnnotatedText/AnnotatedText.css +19 -0
  5. package/src/components/content/AnnotatedText/MarkedText.astro +11 -0
  6. package/src/components/content/InlineDefinition/InlineDefinition.astro +11 -2
  7. package/src/components/data-display/TextPair/TextPair.astro +13 -2
  8. package/src/components/feedback/Tooltip/Tooltip.astro +18 -3
  9. package/src/components/feedback/Tooltip/Tooltip.css +9 -0
  10. package/src/components/index.ts +1 -0
  11. package/src/display/annotatedText.ts +14 -0
  12. package/src/display/contracts.ts +4 -3
  13. package/src/display/index.ts +1 -0
  14. package/src/patterns/MagneticFieldPuzzle/MagneticFieldPuzzle.css +0 -79
  15. package/src/patterns/MagneticFieldPuzzle/magneticFieldPuzzleController.ts +14 -148
  16. package/src/patterns/PuzzleGrid/movement.css +80 -0
  17. package/src/patterns/PuzzleGrid/movement.ts +149 -0
  18. package/src/patterns/PuzzleGrid/selectionDismissal.ts +4 -2
  19. package/src/patterns/SlidingPuzzle/SlidingPuzzle.astro +181 -0
  20. package/src/patterns/SlidingPuzzle/SlidingPuzzle.css +177 -0
  21. package/src/patterns/SlidingPuzzle/contracts.ts +57 -0
  22. package/src/patterns/SlidingPuzzle/simulation.ts +106 -0
  23. package/src/patterns/SlidingPuzzle/slidingPuzzleController.ts +703 -0
  24. package/src/patterns/Table/TableBody.astro +7 -1
  25. package/src/patterns/Table/TableCell.astro +3 -1
  26. package/src/patterns/Table/TableCellValue.astro +10 -1
  27. package/src/patterns/index.ts +4 -0
  28. package/src/primitives/text/TextBlock/TextBlock.astro +54 -4
  29. package/src/styles/style.css +4 -0
@@ -11,7 +11,8 @@ type Props = {
11
11
  };
12
12
 
13
13
  const { cell, rowHref, truncate = false, wrap = false }: Props = Astro.props;
14
- const tooltip = cell?.tooltip?.trim();
14
+ const tooltip =
15
+ typeof cell?.tooltip === 'string' ? cell.tooltip.trim() : cell?.tooltip;
15
16
  const layout =
16
17
  cell?.kind === 'text' || cell?.kind === 'link' ? cell.layout : undefined;
17
18
 
@@ -37,6 +38,7 @@ const rootAttributes = cell
37
38
  <div {...rootAttributes}>
38
39
  <TableCellValue
39
40
  cell={cell}
41
+ interactive={false}
40
42
  rowHref={rowHref}
41
43
  truncate={truncate}
42
44
  wrap={wrap}
@@ -10,12 +10,19 @@ import Button from '../../components/actions/Button/Button.astro';
10
10
 
11
11
  type Props = {
12
12
  cell: TableCell;
13
+ interactive?: boolean;
13
14
  rowHref?: string;
14
15
  truncate?: boolean;
15
16
  wrap: boolean;
16
17
  };
17
18
 
18
- const { cell, rowHref, truncate = false, wrap }: Props = Astro.props;
19
+ const {
20
+ cell,
21
+ interactive = true,
22
+ rowHref,
23
+ truncate = false,
24
+ wrap,
25
+ }: Props = Astro.props;
19
26
 
20
27
  const formatValue = (value: DisplayTextValue): string => String(value);
21
28
  ---
@@ -28,6 +35,7 @@ const formatValue = (value: DisplayTextValue): string => String(value);
28
35
  primarySize={cell.primarySize}
29
36
  primaryWeight={cell.primaryWeight ?? 'regular'}
30
37
  secondary={cell.description}
38
+ interactiveSecondary={interactive}
31
39
  secondaryWeight={cell.secondaryWeight}
32
40
  layout={cell.layout}
33
41
  truncate={truncate}
@@ -48,6 +56,7 @@ const formatValue = (value: DisplayTextValue): string => String(value);
48
56
  primarySize={cell.primarySize}
49
57
  primaryWeight={cell.primaryWeight}
50
58
  secondary={cell.description}
59
+ interactiveSecondary={false}
51
60
  secondaryWeight={cell.secondaryWeight}
52
61
  layout={cell.layout}
53
62
  truncate={truncate}
@@ -10,6 +10,10 @@ export { default as Modal } from './Modal/Modal.astro';
10
10
  export { default as ModalClose } from './Modal/ModalClose.astro';
11
11
  export { default as ModalOpen } from './Modal/ModalOpen.astro';
12
12
  export { default as PuzzleGrid } from './PuzzleGrid/PuzzleGrid.astro';
13
+ export { default as SlidingPuzzle } from './SlidingPuzzle/SlidingPuzzle.astro';
14
+ export * from './SlidingPuzzle/contracts';
15
+ export * from './SlidingPuzzle/simulation';
16
+ export * from './SlidingPuzzle/slidingPuzzleController';
13
17
  export { default as SpriteProjectilePreview } from './SpriteProjectilePreview/SpriteProjectilePreview.astro';
14
18
  export { default as StageFlow } from './StageFlow/StageFlow.astro';
15
19
  export { default as Table } from './Table/Table.astro';
@@ -1,11 +1,13 @@
1
1
  ---
2
2
  import type { HTMLAttributes } from 'astro/types';
3
3
  import type { Tone } from '../../../theme/contracts';
4
+ import type { DisplayAnnotatedText } from '../../../display/annotatedText';
5
+ import AnnotatedText from '../../../components/content/AnnotatedText/AnnotatedText.astro';
4
6
 
5
7
  type Props = HTMLAttributes<'p'> & {
6
8
  'data-tone'?: Tone;
7
9
  preserveBreaks?: boolean;
8
- text: string;
10
+ text: string | DisplayAnnotatedText;
9
11
  };
10
12
 
11
13
  const {
@@ -15,7 +17,49 @@ const {
15
17
  text,
16
18
  ...attrs
17
19
  }: Props = Astro.props;
18
- const paragraphs = preserveBreaks ? text.split(/\r?\n(?:[ \t]*\r?\n)+/) : [];
20
+ function splitParagraphs(
21
+ content: DisplayAnnotatedText,
22
+ ): DisplayAnnotatedText[] {
23
+ const text = content.map((span) => span.text).join('');
24
+ const result: DisplayAnnotatedText[] = [];
25
+ let spanIndex = 0;
26
+ let spanStart = 0;
27
+
28
+ // Slice the original annotations using offsets in the complete text. Paragraph
29
+ // separators may cross span boundaries, including between CR and LF.
30
+ const slice = (start: number, end: number): DisplayAnnotatedText => {
31
+ const spans: Array<DisplayAnnotatedText[number]> = [];
32
+ while (spanIndex < content.length && spanStart < end) {
33
+ const span = content[spanIndex]!;
34
+ const spanEnd = spanStart + span.text.length;
35
+ const from = Math.max(start, spanStart);
36
+ const to = Math.min(end, spanEnd);
37
+ if (from < to) {
38
+ spans.push({
39
+ ...span,
40
+ text: span.text.slice(from - spanStart, to - spanStart),
41
+ });
42
+ }
43
+ if (spanEnd > end) break;
44
+ spanStart = spanEnd;
45
+ spanIndex += 1;
46
+ }
47
+ return spans;
48
+ };
49
+
50
+ let start = 0;
51
+ for (const separator of text.matchAll(/\r?\n(?:[ \t]*\r?\n)+/g)) {
52
+ result.push(slice(start, separator.index));
53
+ start = separator.index + separator[0].length;
54
+ }
55
+ result.push(slice(start, text.length));
56
+ return result;
57
+ }
58
+ const paragraphs = !preserveBreaks
59
+ ? []
60
+ : typeof text === 'string'
61
+ ? text.split(/\r?\n(?:[ \t]*\r?\n)+/)
62
+ : splitParagraphs(text);
19
63
  ---
20
64
 
21
65
  {
@@ -28,7 +72,13 @@ const paragraphs = preserveBreaks ? text.split(/\r?\n(?:[ \t]*\r?\n)+/) : [];
28
72
  data-tone={dataTone}
29
73
  >
30
74
  {paragraphs.map((paragraph) => (
31
- <p class="text-block__paragraph">{paragraph}</p>
75
+ <p class="text-block__paragraph">
76
+ {typeof paragraph === 'string' ? (
77
+ paragraph
78
+ ) : (
79
+ <AnnotatedText content={paragraph} />
80
+ )}
81
+ </p>
32
82
  ))}
33
83
  </div>
34
84
  ) : (
@@ -38,7 +88,7 @@ const paragraphs = preserveBreaks ? text.split(/\r?\n(?:[ \t]*\r?\n)+/) : [];
38
88
  data-widget="text-block"
39
89
  data-tone={dataTone}
40
90
  >
41
- {text}
91
+ {typeof text === 'string' ? text : <AnnotatedText content={text} />}
42
92
  </p>
43
93
  )
44
94
  }
@@ -28,6 +28,8 @@
28
28
  @import '../components/content/CardLink/CardLink.css' layer(components);
29
29
  @import '../components/content/InlineDefinition/InlineDefinition.css'
30
30
  layer(components);
31
+ @import '../components/content/AnnotatedText/AnnotatedText.css'
32
+ layer(components);
31
33
  @import '../components/content/MarkdownContent/MarkdownContent.css'
32
34
  layer(components);
33
35
  @import '../components/data-display/BadgeList/BadgeList.css' layer(components);
@@ -61,6 +63,8 @@
61
63
  @import '../components/navigation/DesktopNavigation.css' layer(patterns);
62
64
  @import '../components/navigation/MobileNavigation.css' layer(patterns);
63
65
  @import '../patterns/PuzzleGrid/PuzzleGrid.css' layer(patterns);
66
+ @import '../patterns/PuzzleGrid/movement.css' layer(patterns);
67
+ @import '../patterns/SlidingPuzzle/SlidingPuzzle.css' layer(patterns);
64
68
  @import '../patterns/CircuitPuzzle/CircuitPuzzle.css' layer(patterns);
65
69
  @import '../patterns/Combobox/Combobox.css' layer(patterns);
66
70
  @import '../patterns/Dropdown/Dropdown.css' layer(patterns);