@terrafirmagreg-team/recipe 0.0.0-stage → 1.2.0

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 (221) hide show
  1. package/package.json +62 -3
  2. package/src/components/button-copy.tsx +43 -0
  3. package/src/components/cards/card/index.tsx +214 -0
  4. package/src/components/cards/card/scene.tsx +107 -0
  5. package/src/components/cards/card/strip.tsx +198 -0
  6. package/src/components/cards/card/text.tsx +46 -0
  7. package/src/components/cards/card/tips.tsx +63 -0
  8. package/src/components/cards/default-item.tsx +47 -0
  9. package/src/components/cards/glare-filter.tsx +29 -0
  10. package/src/components/cards/paged-card.tsx +222 -0
  11. package/src/components/cards/slot-hitbox.tsx +213 -0
  12. package/src/components/cards/strip-card/buttons.tsx +106 -0
  13. package/src/components/cards/strip-card/index.tsx +214 -0
  14. package/src/components/cards/strip-card/member-cell.tsx +167 -0
  15. package/src/components/cards/strip-card/sprite.tsx +36 -0
  16. package/src/components/embed-card.tsx +44 -0
  17. package/src/components/mdx/recipe.tsx +129 -0
  18. package/src/components/tool-list.tsx +49 -0
  19. package/src/components/tree.tsx +98 -0
  20. package/src/components/views/alloy/index.tsx +112 -0
  21. package/src/components/views/alloy/list.tsx +85 -0
  22. package/src/components/views/alloy/mix/index.tsx +35 -0
  23. package/src/components/views/alloy/mix/ratio.tsx +94 -0
  24. package/src/components/views/alloy/mix/rows.tsx +145 -0
  25. package/src/components/views/alloy/mix/status.tsx +122 -0
  26. package/src/components/views/alloy/mix/total.tsx +132 -0
  27. package/src/components/views/alloy/range-bar.tsx +65 -0
  28. package/src/components/views/alloy/stack-bar.tsx +88 -0
  29. package/src/components/views/browser/axis-switcher.tsx +54 -0
  30. package/src/components/views/browser/card-grid.tsx +275 -0
  31. package/src/components/views/browser/favorite-button.tsx +46 -0
  32. package/src/components/views/browser/frame.tsx +112 -0
  33. package/src/components/views/browser/index.tsx +114 -0
  34. package/src/components/views/browser/item-panel/index.tsx +229 -0
  35. package/src/components/views/browser/item-panel/skeleton.tsx +26 -0
  36. package/src/components/views/browser/item-panel-grid/cell.tsx +178 -0
  37. package/src/components/views/browser/item-panel-grid/favorite-cell.tsx +129 -0
  38. package/src/components/views/browser/item-panel-grid/index.tsx +105 -0
  39. package/src/components/views/browser/item-view/index.tsx +186 -0
  40. package/src/components/views/browser/item-view/tags.tsx +85 -0
  41. package/src/components/views/browser/item-view-header.tsx +131 -0
  42. package/src/components/views/browser/pane-tabs.tsx +61 -0
  43. package/src/components/views/browser/place-header.tsx +72 -0
  44. package/src/components/views/browser/query-controls.tsx +105 -0
  45. package/src/components/views/browser/recipe-item-header.tsx +60 -0
  46. package/src/components/views/browser/settings.tsx +52 -0
  47. package/src/components/views/browser/toolbar.tsx +54 -0
  48. package/src/components/views/browser/type-tabs.tsx +71 -0
  49. package/src/components/views/browser/type-view.tsx +184 -0
  50. package/src/components/views/browser/workstation-rail.tsx +43 -0
  51. package/src/components/views/calc/calculator/actions.tsx +47 -0
  52. package/src/components/views/calc/calculator/help.tsx +189 -0
  53. package/src/components/views/calc/calculator/index.tsx +172 -0
  54. package/src/components/views/calc/dot-overlay.tsx +80 -0
  55. package/src/components/views/calc/edge.tsx +152 -0
  56. package/src/components/views/calc/flow/index.tsx +305 -0
  57. package/src/components/views/calc/flow/picker-dialogs.tsx +146 -0
  58. package/src/components/views/calc/flow/toolbar.tsx +60 -0
  59. package/src/components/views/calc/flow/view-menu.tsx +117 -0
  60. package/src/components/views/calc/member-picker.tsx +120 -0
  61. package/src/components/views/calc/node-card/actions.tsx +90 -0
  62. package/src/components/views/calc/node-card/badges.tsx +59 -0
  63. package/src/components/views/calc/node-card/chips.tsx +187 -0
  64. package/src/components/views/calc/node-card/far.tsx +123 -0
  65. package/src/components/views/calc/node-card/full.tsx +332 -0
  66. package/src/components/views/calc/node-card/index.tsx +27 -0
  67. package/src/components/views/calc/node-card/menu.tsx +282 -0
  68. package/src/components/views/calc/node-card/port-cells.tsx +186 -0
  69. package/src/components/views/calc/node-card/port-rails.tsx +251 -0
  70. package/src/components/views/calc/node-card/ports.tsx +86 -0
  71. package/src/components/views/calc/recipe-picker/body.tsx +207 -0
  72. package/src/components/views/calc/recipe-picker/footer.tsx +131 -0
  73. package/src/components/views/calc/recipe-picker/index.tsx +52 -0
  74. package/src/components/views/calc/sidebar.tsx +171 -0
  75. package/src/components/views/calc/trees/icon-picker.tsx +97 -0
  76. package/src/components/views/calc/trees/index.tsx +134 -0
  77. package/src/components/views/calc/trees/label.tsx +67 -0
  78. package/src/components/views/calc/trees/rows.tsx +140 -0
  79. package/src/components/views/forge/gui.tsx +131 -0
  80. package/src/components/views/forge/index.tsx +112 -0
  81. package/src/components/views/forge/list.tsx +113 -0
  82. package/src/components/views/forge/workbench/controls.tsx +103 -0
  83. package/src/components/views/forge/workbench/index.tsx +85 -0
  84. package/src/components/views/forge/workbench/panel.tsx +228 -0
  85. package/src/components/views/forge/workbench/ruler.tsx +133 -0
  86. package/src/components/views/forge/workbench/status.tsx +55 -0
  87. package/src/components/views/forge/workbench/tape.tsx +70 -0
  88. package/src/hooks/alloy/use-fluid-colors.ts +125 -0
  89. package/src/hooks/alloy/use-mix-state.ts +240 -0
  90. package/src/hooks/calc/flow/use-engage.ts +129 -0
  91. package/src/hooks/calc/flow/use-handlers.ts +192 -0
  92. package/src/hooks/calc/flow/use-layout.ts +105 -0
  93. package/src/hooks/calc/flow/use-mount.ts +97 -0
  94. package/src/hooks/calc/flow/use-nodes.ts +260 -0
  95. package/src/hooks/calc/flow/use-pickers.ts +57 -0
  96. package/src/hooks/calc/flow/use-viewport.ts +141 -0
  97. package/src/hooks/calc/flow/use-window.ts +87 -0
  98. package/src/hooks/calc/use-actions.ts +355 -0
  99. package/src/hooks/calc/use-amounts.ts +64 -0
  100. package/src/hooks/calc/use-data.ts +203 -0
  101. package/src/hooks/calc/use-defaults.ts +40 -0
  102. package/src/hooks/calc/use-far-mode.ts +37 -0
  103. package/src/hooks/calc/use-focus.ts +31 -0
  104. package/src/hooks/calc/use-maps.ts +76 -0
  105. package/src/hooks/calc/use-reset.ts +15 -0
  106. package/src/hooks/calc/use-resolver.ts +70 -0
  107. package/src/hooks/calc/use-session.ts +13 -0
  108. package/src/hooks/calc/use-share.ts +64 -0
  109. package/src/hooks/calc/use-storage.ts +126 -0
  110. package/src/hooks/calc/use-tier.ts +13 -0
  111. package/src/hooks/calc/use-view-mode.ts +24 -0
  112. package/src/hooks/calc/use-worker.ts +204 -0
  113. package/src/hooks/forge/use-anvil-gui.ts +16 -0
  114. package/src/hooks/forge/use-forge-state.ts +135 -0
  115. package/src/hooks/forge/use-ruler.ts +100 -0
  116. package/src/hooks/use-add-to-calc.ts +51 -0
  117. package/src/hooks/use-categories-by-id.ts +18 -0
  118. package/src/hooks/use-favorite-hotkey.ts +39 -0
  119. package/src/hooks/use-favorites.ts +135 -0
  120. package/src/hooks/use-group-outlines.ts +65 -0
  121. package/src/hooks/use-hide-unused.ts +12 -0
  122. package/src/hooks/use-index.ts +72 -0
  123. package/src/hooks/use-item-feeds.ts +46 -0
  124. package/src/hooks/use-item-pane.ts +106 -0
  125. package/src/hooks/use-item-press.ts +89 -0
  126. package/src/hooks/use-item-tag-groups.ts +54 -0
  127. package/src/hooks/use-item-tooltips.ts +18 -0
  128. package/src/hooks/use-left-sidebar-tree.ts +34 -0
  129. package/src/hooks/use-mod-names.ts +17 -0
  130. package/src/hooks/use-mount-limit.ts +22 -0
  131. package/src/hooks/use-panel-cells.ts +117 -0
  132. package/src/hooks/use-panel-page.ts +54 -0
  133. package/src/hooks/use-panel-tabs.ts +43 -0
  134. package/src/hooks/use-query.ts +186 -0
  135. package/src/hooks/use-session.ts +88 -0
  136. package/src/hooks/use-sidebar-group.ts +16 -0
  137. package/src/hooks/use-tag-members.ts +16 -0
  138. package/src/hooks/use-tool-recipes.ts +26 -0
  139. package/src/hooks/use-type-filter.ts +73 -0
  140. package/src/lib/alloy/mix.ts +210 -0
  141. package/src/lib/alloy/parse.ts +37 -0
  142. package/src/lib/calc/defaults.ts +47 -0
  143. package/src/lib/calc/flow.ts +315 -0
  144. package/src/lib/calc/focus.ts +15 -0
  145. package/src/lib/calc/meta.ts +17 -0
  146. package/src/lib/calc/pack.ts +77 -0
  147. package/src/lib/calc/ports.ts +43 -0
  148. package/src/lib/calc/resolve.ts +198 -0
  149. package/src/lib/calc/route/buckets.ts +49 -0
  150. package/src/lib/calc/route/geometry.ts +51 -0
  151. package/src/lib/calc/route/index.ts +3 -0
  152. package/src/lib/calc/route/polyline.ts +103 -0
  153. package/src/lib/calc/route/router.ts +394 -0
  154. package/src/lib/calc/scheme.ts +226 -0
  155. package/src/lib/calc/storage/entry.ts +97 -0
  156. package/src/lib/calc/storage/index.ts +20 -0
  157. package/src/lib/calc/storage/keys.ts +38 -0
  158. package/src/lib/calc/storage/store.ts +198 -0
  159. package/src/lib/calc/tree/index.ts +4 -0
  160. package/src/lib/calc/tree/materials.ts +29 -0
  161. package/src/lib/calc/tree/recipe.ts +104 -0
  162. package/src/lib/calc/tree/share.ts +135 -0
  163. package/src/lib/calc/worker/api.ts +25 -0
  164. package/src/lib/calc/worker/fetch.ts +66 -0
  165. package/src/lib/calc/worker/flush.ts +39 -0
  166. package/src/lib/calc/worker/index.ts +8 -0
  167. package/src/lib/calc/worker/protocol.ts +35 -0
  168. package/src/lib/calc/worker/resolve.ts +49 -0
  169. package/src/lib/calc/worker/state.ts +48 -0
  170. package/src/lib/card-model.ts +65 -0
  171. package/src/lib/client/recipe-categories.ts +14 -0
  172. package/src/lib/client/recipe.ts +85 -0
  173. package/src/lib/client-index/catalog.ts +91 -0
  174. package/src/lib/client-index/chrome.ts +180 -0
  175. package/src/lib/client-index/index.ts +20 -0
  176. package/src/lib/client-index/registry.ts +121 -0
  177. package/src/lib/client-index/rows.ts +260 -0
  178. package/src/lib/client-index/tooltips.ts +74 -0
  179. package/src/lib/config.ts +18 -0
  180. package/src/lib/data/category/dto.ts +25 -0
  181. package/src/lib/data/category/load.ts +47 -0
  182. package/src/lib/data/category/parse.ts +71 -0
  183. package/src/lib/data/dto.ts +152 -0
  184. package/src/lib/data/grid.ts +40 -0
  185. package/src/lib/data/parse/entry.ts +85 -0
  186. package/src/lib/data/parse/index.ts +3 -0
  187. package/src/lib/data/parse/layout.ts +138 -0
  188. package/src/lib/data/parse/slots.ts +85 -0
  189. package/src/lib/data/parse/widgets.ts +81 -0
  190. package/src/lib/data/scene.ts +103 -0
  191. package/src/lib/data/slot-io.ts +44 -0
  192. package/src/lib/dump.ts +6 -0
  193. package/src/lib/embed.ts +22 -0
  194. package/src/lib/favorite-hover.ts +13 -0
  195. package/src/lib/fluid-outputs.ts +70 -0
  196. package/src/lib/forge/actions.ts +59 -0
  197. package/src/lib/forge/data.ts +51 -0
  198. package/src/lib/forge/solve.ts +80 -0
  199. package/src/lib/group.ts +23 -0
  200. package/src/lib/index-store.ts +70 -0
  201. package/src/lib/links.ts +131 -0
  202. package/src/lib/lookup.ts +119 -0
  203. package/src/lib/panel-outline.ts +86 -0
  204. package/src/lib/panel.ts +105 -0
  205. package/src/lib/preview.ts +32 -0
  206. package/src/lib/recipe-slots.ts +8 -0
  207. package/src/lib/search.ts +139 -0
  208. package/src/lib/sidebar.ts +47 -0
  209. package/src/lib/used-items.ts +25 -0
  210. package/src/locales/en_us.json +172 -0
  211. package/src/locales/ru_ru.json +172 -0
  212. package/src/locales.ts +6 -0
  213. package/src/types/alloy.ts +20 -0
  214. package/src/types/calc-flow-props.ts +44 -0
  215. package/src/types/calc.ts +92 -0
  216. package/src/types/forge.ts +21 -0
  217. package/src/types/index.ts +136 -0
  218. package/styles/calc.css +308 -0
  219. package/styles/strip.css +7 -0
  220. package/styles.css +2 -0
  221. package/README.md +0 -3
@@ -0,0 +1,214 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import { Fragment, useRef, useState } from 'react';
5
+ import { SlotHitbox } from '@terrafirmagreg-team/recipe/components/cards/slot-hitbox';
6
+ import { recipeGlareFilter } from '@terrafirmagreg-team/recipe/components/cards/glare-filter';
7
+ import { StripCardSprite } from '@terrafirmagreg-team/recipe/components/cards/strip-card/sprite';
8
+ import {
9
+ StripCardTagCopy,
10
+ StripCardTagPager,
11
+ } from '@terrafirmagreg-team/recipe/components/cards/strip-card/buttons';
12
+ import { StripCardMember } from '@terrafirmagreg-team/recipe/components/cards/strip-card/member-cell';
13
+ import { recipeGrid } from '@terrafirmagreg-team/recipe/lib/data/grid';
14
+ import { recipeSlots } from '@terrafirmagreg-team/recipe/lib/recipe-slots';
15
+ import { cn } from '@terrafirmagreg-team/ui/lib/utils/cn';
16
+ import { useInView } from '@terrafirmagreg-team/ui/hooks/use-in-view';
17
+ import { Hint } from '@terrafirmagreg-team/ui/components/blocks/tooltip/hint';
18
+ import type { EntryTooltipLevel } from '@terrafirmagreg-team/game/components/entry/tooltip';
19
+ import type { Recipe } from '@terrafirmagreg-team/recipe/lib/data/dto';
20
+ import type { RecipeHrefOpts } from '@terrafirmagreg-team/recipe/types';
21
+
22
+ const SCALE = 2;
23
+
24
+ export function StripCard({
25
+ recipe,
26
+ dataset,
27
+ lang,
28
+ langMap,
29
+ nav,
30
+ title,
31
+ src,
32
+ onFail,
33
+ naturalW,
34
+ interactive = true,
35
+ slotTooltip,
36
+ eager,
37
+ frameOnly,
38
+ }: {
39
+ recipe: Recipe;
40
+ dataset: DatasetRef;
41
+ lang: string;
42
+ langMap?: Record<string, string>;
43
+ nav?: Pick<RecipeHrefOpts, 'tab' | 'search'>;
44
+ title: string;
45
+ src: string;
46
+ onFail: () => void;
47
+ naturalW?: number;
48
+ naturalH?: number;
49
+ interactive?: boolean;
50
+ slotTooltip?: EntryTooltipLevel;
51
+ eager?: boolean;
52
+
53
+ frameOnly?: boolean;
54
+ }) {
55
+ const scale = recipe.scale ?? SCALE;
56
+ const margin = recipe.margin ?? 0;
57
+ const info = recipeGrid(recipe.properties);
58
+ const rootRef = useRef<HTMLDivElement>(null);
59
+ const observedInView = useInView(rootRef);
60
+ const inView = eager || observedInView;
61
+ const [page, setPage] = useState(0);
62
+ const [measured, setMeasured] = useState<{ src: string; h: number }>();
63
+ if (!info) return null;
64
+ const { grid, members } = info;
65
+ const pageSize = grid.cols * grid.rows;
66
+ const pages = Math.max(1, Math.ceil(members.length / pageSize));
67
+ const clamped = Math.min(page, pages - 1);
68
+ const shown = members.slice(clamped * pageSize, (clamped + 1) * pageSize);
69
+ const shownRows = Math.max(1, Math.ceil(shown.length / grid.cols));
70
+
71
+ const imgW = recipe.w ?? naturalW ?? 0;
72
+ const imgH = measured?.src === src ? measured.h : 0;
73
+ const topH = (grid.y + margin) * scale;
74
+ const rowH = grid.row * scale;
75
+ const bottomH = (grid.tail + margin) * scale;
76
+ const rowSrc = (margin + grid.y) * scale;
77
+ const bottomSrc = Math.max(0, imgH - bottomH);
78
+ const edgeW = margin * scale;
79
+ const guiW = imgW / scale - margin * 2;
80
+ const buttonTop = margin * scale;
81
+
82
+ return (
83
+ <div
84
+ ref={rootRef}
85
+ className={cn(
86
+ 'relative w-fit overflow-hidden rounded-sm',
87
+
88
+ measured?.src === src && 'bg-mc-panel',
89
+ )}
90
+ style={{
91
+ width: imgW,
92
+ height: topH + shownRows * rowH + bottomH,
93
+ }}
94
+ >
95
+ {/* eslint-disable-next-line @next/next/no-img-element -- dump asset */}
96
+ <img
97
+ src={src}
98
+ alt=""
99
+ aria-hidden
100
+ className="absolute h-0 w-0 opacity-0"
101
+ onError={onFail}
102
+ onLoad={(event) =>
103
+ setMeasured({ src, h: event.currentTarget.naturalHeight })
104
+ }
105
+ />
106
+ <div className="absolute inset-0" style={recipeGlareFilter}>
107
+ <Hint label={title}>
108
+ <StripCardSprite
109
+ src={src}
110
+ pos="0 0"
111
+ width={imgW}
112
+ height={topH}
113
+ className="absolute left-0 top-0"
114
+ />
115
+ </Hint>
116
+ {Array.from({ length: shownRows }, (_, rowIndex) => {
117
+ const cells = Math.min(
118
+ grid.cols,
119
+ shown.length - rowIndex * grid.cols,
120
+ );
121
+ return (
122
+ <Fragment key={rowIndex}>
123
+ <StripCardSprite
124
+ src={src}
125
+ pos={`0 -${rowSrc}px`}
126
+ width={edgeW + cells * rowH}
127
+ height={rowH}
128
+ className="absolute left-0"
129
+ style={{ top: topH + rowIndex * rowH }}
130
+ />
131
+ <StripCardSprite
132
+ src={src}
133
+ pos={`${edgeW - imgW}px -${rowSrc}px`}
134
+ width={edgeW}
135
+ height={rowH}
136
+ className="absolute right-0"
137
+ style={{ top: topH + rowIndex * rowH }}
138
+ />
139
+ </Fragment>
140
+ );
141
+ })}
142
+ {imgH > 0 && (
143
+ <StripCardSprite
144
+ src={src}
145
+ pos={`0 -${bottomSrc}px`}
146
+ width={imgW}
147
+ height={bottomH}
148
+ className="absolute bottom-0 left-0"
149
+ />
150
+ )}
151
+ </div>
152
+ {inView && !frameOnly
153
+ ? recipeSlots(recipe).map((widget, index) => (
154
+ <SlotHitbox
155
+ key={`${widget.id}:${index}`}
156
+ widget={widget}
157
+ dataset={dataset}
158
+ lang={lang}
159
+ langMap={langMap}
160
+ nav={nav}
161
+ scale={scale}
162
+ margin={margin}
163
+ interactive={interactive}
164
+ tooltipLevel={slotTooltip}
165
+ />
166
+ ))
167
+ : null}
168
+ {inView && !frameOnly
169
+ ? shown.map((member, index) => (
170
+ <StripCardMember
171
+ key={`${member.id}:${index}`}
172
+ member={member}
173
+ dataset={dataset}
174
+ lang={lang}
175
+ langMap={langMap}
176
+ nav={nav}
177
+ x={edgeW + (index % grid.cols) * rowH}
178
+ y={topH + Math.floor(index / grid.cols) * rowH}
179
+ pitch={rowH}
180
+ interactive={interactive}
181
+ tooltipLevel={slotTooltip}
182
+ />
183
+ ))
184
+ : null}
185
+ {pages > 1 && (
186
+ <>
187
+ <StripCardTagPager
188
+ left={(margin + 2) * scale}
189
+ top={buttonTop}
190
+ dir={-1}
191
+ scale={scale}
192
+ disabled={clamped <= 0}
193
+ onClick={() => setPage(clamped - 1)}
194
+ />
195
+ <StripCardTagPager
196
+ left={(margin + guiW - 14) * scale}
197
+ top={buttonTop}
198
+ dir={1}
199
+ scale={scale}
200
+ disabled={clamped + 1 >= pages}
201
+ onClick={() => setPage(clamped + 1)}
202
+ />
203
+ </>
204
+ )}
205
+ <StripCardTagCopy
206
+ left={(margin + 24) * scale}
207
+ top={margin * scale}
208
+ scale={scale}
209
+ value={recipe.id}
210
+ />
211
+ </div>
212
+ );
213
+ }
214
+
@@ -0,0 +1,167 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import Link from 'next/link';
5
+ import { EntryIcon } from '@terrafirmagreg-team/game/components/entry/icon';
6
+ import {
7
+ EntryTooltip,
8
+ type EntryTooltipLevel,
9
+ } from '@terrafirmagreg-team/game/components/entry/tooltip';
10
+ import { stackDisplayName } from '@terrafirmagreg-team/game/lib/entry/display';
11
+ import { entryHref } from '@terrafirmagreg-team/game/lib/entry/href';
12
+ import { loadStackDisplay } from '@terrafirmagreg-team/game/lib/entry/tooltip';
13
+ import { favoriteHover } from '@terrafirmagreg-team/recipe/lib/favorite-hover';
14
+ import { useAsyncResult } from '@terrafirmagreg-team/ui/hooks/use-async-value';
15
+ import type { ReferenceKind } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
16
+ import type { RecipeGridMember } from '@terrafirmagreg-team/recipe/lib/data/dto';
17
+ import type { RecipeHrefOpts } from '@terrafirmagreg-team/recipe/types';
18
+
19
+ const MEMBER_KIND: Record<string, ReferenceKind> = {
20
+ fluid: 'fluid',
21
+ entity: 'entity',
22
+ block: 'block',
23
+ };
24
+
25
+ export function StripCardMember({
26
+ member,
27
+ dataset,
28
+ lang,
29
+ langMap,
30
+ nav,
31
+ x,
32
+ y,
33
+ pitch,
34
+ interactive = true,
35
+ tooltipLevel,
36
+ }: {
37
+ member: RecipeGridMember;
38
+ dataset: DatasetRef;
39
+ lang: string;
40
+ langMap?: Record<string, string>;
41
+ nav?: Pick<RecipeHrefOpts, 'tab' | 'search'>;
42
+ x: number;
43
+ y: number;
44
+ pitch: number;
45
+ interactive?: boolean;
46
+ tooltipLevel?: EntryTooltipLevel;
47
+ }) {
48
+ const kind = MEMBER_KIND[member.kind ?? 'item'] ?? 'item';
49
+ const name = stackDisplayName(langMap, member.id);
50
+ const checkKind = kind === 'item' || kind === 'fluid' ? kind : undefined;
51
+ const stackPeek =
52
+ dataset && checkKind
53
+ ? loadStackDisplay.peek(dataset, member.id, checkKind)
54
+ : undefined;
55
+ const stackRes = useAsyncResult(
56
+ dataset && checkKind && stackPeek === undefined
57
+ ? async () => ({
58
+ key: member.id,
59
+ display: await loadStackDisplay(dataset, member.id, checkKind),
60
+ })
61
+ : false,
62
+ [dataset, member.id, checkKind, stackPeek],
63
+ );
64
+ const missingItem =
65
+ checkKind !== undefined &&
66
+ stackPeek === undefined &&
67
+ !stackRes.pending &&
68
+ stackRes.value?.key === member.id &&
69
+ stackRes.value.display === undefined;
70
+ const badges: string[] = [];
71
+ if (member.amount !== undefined && member.amount > 1) {
72
+ badges.push(`×${member.amount}`);
73
+ }
74
+ if (member.chance !== undefined && member.chance < 1) {
75
+ const percent = member.chance <= 1 ? member.chance * 100 : member.chance;
76
+ badges.push(`${Number(percent.toFixed(1))}%`);
77
+ }
78
+ const inner = (
79
+ <>
80
+ <span className="pointer-events-none flex size-full items-center justify-center">
81
+ <EntryIcon
82
+ id={member.id}
83
+ kind={kind}
84
+ dataset={dataset}
85
+ size={Math.max(8, pitch - 4)}
86
+ missing="placeholder"
87
+ />
88
+ </span>
89
+ {badges.length > 0 && (
90
+ <span
91
+ className="font-mc pointer-events-none absolute right-0 bottom-0 leading-none text-white [text-shadow:1px_1px_0_var(--color-mc-arrow)]"
92
+ style={{ fontSize: pitch / 4 }}
93
+ >
94
+ {badges.join(' ')}
95
+ </span>
96
+ )}
97
+ </>
98
+ );
99
+ const faceStyle = { left: x, top: y, width: pitch, height: pitch };
100
+ const hover = {
101
+ onMouseEnter: () => {
102
+ favoriteHover.slot =
103
+ kind === 'item' || kind === 'fluid'
104
+ ? {
105
+ kind: 'stack' as const,
106
+ id: member.id,
107
+ ...(kind === 'fluid' ? { ref: 'fluid' as const } : {}),
108
+ }
109
+ : undefined;
110
+ },
111
+ onMouseLeave: () => {
112
+ favoriteHover.slot = undefined;
113
+ },
114
+ };
115
+ if (!interactive) {
116
+ return (
117
+ <EntryTooltip
118
+ dataset={dataset}
119
+ id={member.id}
120
+ name={name}
121
+ kind={kind === 'fluid' ? 'fluid' : kind === 'entity' ? 'entity' : 'item'}
122
+ lang={lang}
123
+ langMap={langMap}
124
+ level={tooltipLevel}
125
+ >
126
+ <span
127
+ {...hover}
128
+ aria-label={name}
129
+ className="absolute block"
130
+ style={faceStyle}
131
+ >
132
+ {inner}
133
+ </span>
134
+ </EntryTooltip>
135
+ );
136
+ }
137
+ return (
138
+ <EntryTooltip
139
+ dataset={dataset}
140
+ id={member.id}
141
+ name={name}
142
+ kind={kind === 'fluid' ? 'fluid' : kind === 'entity' ? 'entity' : 'item'}
143
+ lang={lang}
144
+ langMap={langMap}
145
+ level={tooltipLevel}
146
+ >
147
+ <span
148
+ {...hover}
149
+ className="absolute block"
150
+ style={faceStyle}
151
+ aria-label={name}
152
+ >
153
+ {!missingItem ? (
154
+ <Link
155
+ href={entryHref(dataset, lang, { kind, id: member.id }, nav)}
156
+ className="absolute inset-0 block"
157
+ >
158
+ {inner}
159
+ </Link>
160
+ ) : (
161
+ <span className="absolute inset-0 block">{inner}</span>
162
+ )}
163
+ </span>
164
+ </EntryTooltip>
165
+ );
166
+ }
167
+
@@ -0,0 +1,36 @@
1
+ 'use client';
2
+
3
+ import type { CSSProperties } from 'react';
4
+
5
+ export function StripCardSprite({
6
+ src,
7
+ pos,
8
+ width,
9
+ height,
10
+ className,
11
+ style,
12
+ }: {
13
+ src: string;
14
+
15
+ pos: string;
16
+ width?: number;
17
+ height?: number;
18
+ className?: string;
19
+ style?: CSSProperties;
20
+ }) {
21
+ return (
22
+ <div
23
+ className={className}
24
+ style={{
25
+ ...(width !== undefined ? { width } : {}),
26
+ ...(height !== undefined ? { height } : {}),
27
+ backgroundImage: `url(${src})`,
28
+ backgroundPosition: pos,
29
+ backgroundRepeat: 'no-repeat',
30
+ imageRendering: 'pixelated',
31
+ ...style,
32
+ }}
33
+ />
34
+ );
35
+ }
36
+
@@ -0,0 +1,44 @@
1
+ 'use client';
2
+ import { useState } from 'react';
3
+ import Link from 'next/link';
4
+ import { PagedCard } from '@terrafirmagreg-team/recipe/components/cards/paged-card';
5
+ import { FitBox } from '@terrafirmagreg-team/ui/components/blocks/fit-box';
6
+ import { recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
7
+ import { recipeCardImageUrl } from '@terrafirmagreg-team/recipe/lib/links';
8
+ import { recipeImageUrl } from '@terrafirmagreg-team/dump/lib/dump/assets/urls';
9
+ import { recipeTitle } from '@terrafirmagreg-team/recipe/lib/data/parse';
10
+ import type { Recipe } from '@terrafirmagreg-team/recipe/lib/data/dto';
11
+ import type { EmbedRecipeCardProps } from '@terrafirmagreg-team/kit/types/embeds';
12
+
13
+ export function RecipeEmbedCard({
14
+ id,
15
+ recipe,
16
+ dataset,
17
+ lang,
18
+ langMap,
19
+ }: EmbedRecipeCardProps) {
20
+ const [failed, setFailed] = useState(false);
21
+ if (failed) return null;
22
+ const full = recipe as unknown as Recipe;
23
+ const src = recipeImageUrl(dataset, full) ?? recipeCardImageUrl(dataset, id);
24
+ if (!src) return null;
25
+ const title = recipeTitle(full, langMap);
26
+ return (
27
+ <Link
28
+ href={recipeHref(dataset, lang, { id })}
29
+ className="not-prose block w-fit max-w-full"
30
+ >
31
+ <FitBox w={full.w ?? 0}>
32
+ <PagedCard
33
+ recipe={full}
34
+ dataset={dataset}
35
+ lang={lang}
36
+ langMap={langMap}
37
+ title={title}
38
+ src={src}
39
+ onFail={() => setFailed(true)}
40
+ />
41
+ </FitBox>
42
+ </Link>
43
+ );
44
+ }
@@ -0,0 +1,129 @@
1
+ 'use client';
2
+ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
3
+
4
+ import Link from 'next/link';
5
+ import { useRouter } from 'next/navigation';
6
+ import { useState } from 'react';
7
+ import { PagedCard } from '@terrafirmagreg-team/recipe/components/cards/paged-card';
8
+ import { FitBox } from '@terrafirmagreg-team/ui/components/blocks/fit-box';
9
+ import { EmptyState } from '@terrafirmagreg-team/ui/components/blocks/page/empty-state';
10
+ import { Skeleton } from '@terrafirmagreg-team/ui/components/ui/skeleton';
11
+ import { useAsyncResult } from '@terrafirmagreg-team/ui/hooks/use-async-value';
12
+ import { useSectionCatalog } from '@terrafirmagreg-team/kit/hooks/use-catalog';
13
+ import { useCurrentDataset } from '@terrafirmagreg-team/kit/hooks/use-current-dataset';
14
+ import { useResolvedLang } from '@terrafirmagreg-team/translate/hooks/use-resolved-lang';
15
+ import { useRecipeIndex } from '@terrafirmagreg-team/recipe/hooks/use-index';
16
+ import {
17
+ loadRecipeChromeClient,
18
+ recipeItemName,
19
+ resolveRecipeRows,
20
+ } from '@terrafirmagreg-team/recipe/lib/client-index';
21
+ import { loadClientRecipe } from '@terrafirmagreg-team/recipe/lib/client/recipe';
22
+ import { clientDumpLang } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
23
+ import { recipeTitle } from '@terrafirmagreg-team/recipe/lib/data/parse';
24
+ import { recipeImageUrl } from '@terrafirmagreg-team/dump/lib/dump/assets/urls';
25
+ import { recipeCardImageUrl, recipeHref } from '@terrafirmagreg-team/recipe/lib/links';
26
+
27
+ export type RecipeProps = {
28
+ id?: string;
29
+ dataset?: DatasetRef;
30
+ maxH?: number;
31
+ };
32
+
33
+ export function Recipe({
34
+ id,
35
+ dataset: datasetProp,
36
+ maxH = 360,
37
+ }: RecipeProps) {
38
+ const catalog = useSectionCatalog();
39
+ const current = useCurrentDataset(catalog.recipe);
40
+ const dataset =
41
+ datasetProp ??
42
+ current ??
43
+ (catalog.recipe[0] ? { id: catalog.recipe[0].id } : undefined);
44
+ const lang = useResolvedLang();
45
+ const router = useRouter();
46
+ const { index, indexLoading } = useRecipeIndex(dataset, lang);
47
+ const [failed, setFailed] = useState(false);
48
+
49
+ const { value, pending } = useAsyncResult(
50
+ index && dataset && id
51
+ ? async () => {
52
+ const [row] = await resolveRecipeRows(dataset, index, [id]);
53
+ if (!row) return { missing: true as const };
54
+ const [recipe, chrome, langMap] = await Promise.all([
55
+ loadClientRecipe(dataset, row.id, row.bucket),
56
+ loadRecipeChromeClient(dataset, lang),
57
+ clientDumpLang(dataset, lang),
58
+ ]);
59
+ const title = recipe
60
+ ? recipeTitle(recipe, langMap)
61
+ : recipeItemName(chrome.names, lang, row.out[0] ?? row.id);
62
+ const src =
63
+ (recipe ? recipeImageUrl(dataset, recipe) : undefined) ??
64
+ (row.image
65
+ ? recipeImageUrl(dataset, {
66
+ modId: row.id.split(':', 1)[0],
67
+ image: row.image,
68
+ })
69
+ : undefined) ??
70
+ recipeCardImageUrl(dataset, row.id);
71
+ return { row, recipe, langMap, title, src };
72
+ }
73
+ : undefined,
74
+ [dataset, index, id, lang],
75
+ );
76
+
77
+ if (!dataset || !id) return null;
78
+ const resolvedRow = value && 'row' in value ? value.row : undefined;
79
+ const type = resolvedRow ? index?.types[resolvedRow.type] : undefined;
80
+ const href = recipeHref(dataset, lang, { id, type });
81
+ if (!value && (pending || indexLoading)) {
82
+ return <Skeleton className="not-prose h-40 w-full max-w-112 rounded-md" />;
83
+ }
84
+ if (!value || 'missing' in value || !value.recipe) {
85
+ return (
86
+ <Link href={href} className="not-prose text-primary underline">
87
+ {id}
88
+ </Link>
89
+ );
90
+ }
91
+ const { row, recipe, langMap, title, src } = value;
92
+ return (
93
+ <div
94
+ role="link"
95
+ tabIndex={0}
96
+ title={title}
97
+ className="not-prose mb-4 block w-fit max-w-full cursor-pointer rounded-md"
98
+ onClick={(event) => {
99
+ if ((event.target as HTMLElement).closest('a,button')) return;
100
+ router.push(href);
101
+ }}
102
+ onKeyDown={(event) => {
103
+ if (event.key === 'Enter' && event.target === event.currentTarget)
104
+ router.push(href);
105
+ }}
106
+ >
107
+ {src && !failed ? (
108
+ <FitBox w={recipe.w ?? row.d?.w ?? 0}>
109
+ <PagedCard
110
+ recipe={recipe}
111
+ dataset={dataset}
112
+ lang={lang}
113
+ langMap={langMap}
114
+ title={title}
115
+ src={src}
116
+ onFail={() => setFailed(true)}
117
+ naturalW={row.d?.w}
118
+ naturalH={row.d?.h}
119
+ maxH={Number(maxH) || 360}
120
+ interactive
121
+ />
122
+ </FitBox>
123
+ ) : (
124
+ <EmptyState variant="missing">{title}</EmptyState>
125
+ )}
126
+ </div>
127
+ );
128
+ }
129
+
@@ -0,0 +1,49 @@
1
+ 'use client';
2
+
3
+ import type * as PageTree from 'fumadocs-core/page-tree';
4
+ import { TreeContextProvider } from '@terrafirmagreg-team/ui/components/layouts/tree-context';
5
+ import {
6
+ LeftSidebarPortal,
7
+ LeftSidebarTree,
8
+ } from '@terrafirmagreg-team/ui/components/layouts/left-sidebar';
9
+ import { Input } from '@terrafirmagreg-team/ui/components/ui/input';
10
+ import { EmptyState } from '@terrafirmagreg-team/ui/components/blocks/page/empty-state';
11
+
12
+ export function ToolList({
13
+ tree,
14
+ loaded,
15
+ query,
16
+ onQuery,
17
+ searchLabel,
18
+ emptyLabel,
19
+ }: {
20
+ tree: PageTree.Root;
21
+ loaded: boolean;
22
+ query: string;
23
+ onQuery: (query: string) => void;
24
+ searchLabel: string;
25
+ emptyLabel: string;
26
+ }) {
27
+ return (
28
+ <LeftSidebarPortal>
29
+ <div className="space-y-2 p-2">
30
+ <Input
31
+ type="search"
32
+ name="tool-search"
33
+ autoComplete="off"
34
+ aria-label={searchLabel}
35
+ placeholder={searchLabel}
36
+ value={query}
37
+ onChange={(event) => onQuery(event.target.value)}
38
+ />
39
+ <TreeContextProvider tree={tree}>
40
+ <LeftSidebarTree />
41
+ </TreeContextProvider>
42
+ {loaded && !tree.children.length ? (
43
+ <EmptyState>{emptyLabel}</EmptyState>
44
+ ) : null}
45
+ </div>
46
+ </LeftSidebarPortal>
47
+ );
48
+ }
49
+