kyd-shared-badge 0.3.22 → 0.3.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kyd-shared-badge",
3
- "version": "0.3.22",
3
+ "version": "0.3.23",
4
4
  "private": false,
5
5
  "main": "./src/index.ts",
6
6
  "module": "./src/index.ts",
@@ -40,7 +40,7 @@ type ChatWidgetProps = Partial<{
40
40
  // return `rgba(${r}, ${g}, ${b}, ${alpha})`;
41
41
  // };
42
42
 
43
- const SharedBadgeDisplay = ({ badgeData, chatProps }: { badgeData: PublicBadgeData, chatProps?: ChatWidgetProps }) => {
43
+ const SharedBadgeDisplay = ({ badgeData, chatProps, headless }: { badgeData: PublicBadgeData, chatProps?: ChatWidgetProps, headless?: boolean }) => {
44
44
  const {
45
45
  badgeId,
46
46
  developerName,
@@ -61,6 +61,7 @@ const SharedBadgeDisplay = ({ badgeData, chatProps }: { badgeData: PublicBadgeDa
61
61
 
62
62
 
63
63
  const wrapperMaxWidth = 'max-w-5xl';
64
+ const isHeadless = !!headless;
64
65
 
65
66
  // Overall and genre scores
66
67
  const overallFinalPercent = assessmentResult?.final_percent || 0;
@@ -145,6 +146,19 @@ const SharedBadgeDisplay = ({ badgeData, chatProps }: { badgeData: PublicBadgeDa
145
146
  return (
146
147
  <BusinessRulesProvider items={graphInsights?.business_rules_all}>
147
148
  <div className={`${wrapperMaxWidth} mx-auto`}>
149
+ {isHeadless && (
150
+ <style>
151
+ {`@page { margin: 0; }
152
+ html, body { margin: 0 !important; padding: 0 !important; background: #fff !important; }
153
+ #__next, main { margin: 0 !important; padding: 0 !important; }
154
+ @media print {
155
+ .kyd-break-before { break-before: page; page-break-before: always; }
156
+ .kyd-break-after { break-after: page; page-break-after: always; }
157
+ .kyd-avoid-break { break-inside: avoid; page-break-inside: avoid; }
158
+ .kyd-keep-with-next { break-after: avoid; page-break-after: avoid; }
159
+ }`}
160
+ </style>
161
+ )}
148
162
  {/* Share controls removed; app-level pages render their own actions */}
149
163
  <Reveal offsetY={8} durationMs={500}>
150
164
  <ReportHeader
@@ -165,14 +179,14 @@ const SharedBadgeDisplay = ({ badgeData, chatProps }: { badgeData: PublicBadgeDa
165
179
  />
166
180
  </Reveal>
167
181
  <div
168
- className={'rounded-xl shadow-xl p-6 sm:p-8 mt-8 border'}
182
+ className={isHeadless ? 'p-6 sm:p-8 mt-2 border' : 'rounded-xl shadow-xl p-6 sm:p-8 mt-8 border'}
169
183
  style={{ backgroundColor: 'var(--content-card-background)', borderColor: 'var(--icon-button-secondary)' }}
170
184
  >
171
185
  <div className={'space-y-12 divide-y'} style={{ borderColor: 'var(--icon-button-secondary)' }}>
172
- <div className="pt-8 first:pt-0">
186
+ <div className="pt-8 first:pt-0 kyd-avoid-break">
173
187
  <Reveal as={'h4'} offsetY={8} durationMs={500} className={'text-2xl font-semibold mb-3'} style={{ color: 'var(--text-main)' }}>Report Summary</Reveal>
174
188
  <Reveal as={'div'} offsetY={8} durationMs={500} className={'space-y-12 divide-y'} style={{ borderColor: 'var(--icon-button-secondary)' }}>
175
- <div className="grid grid-cols-1 sm:grid-cols-3 gap-4 *:min-h-full">
189
+ <div className="grid grid-cols-1 sm:grid-cols-3 gap-4 *:min-h-full kyd-avoid-break">
176
190
  {/* Technical semicircle gauge (refactored) */}
177
191
  {(() => {
178
192
  const ui = graphInsights?.uiSummary?.technical || {};
@@ -236,7 +250,7 @@ const SharedBadgeDisplay = ({ badgeData, chatProps }: { badgeData: PublicBadgeDa
236
250
 
237
251
  {/* Technical Scores */}
238
252
  <div className="mt-8" >
239
- <div key={'Technical'} className='pt-8 space-y-8' style={{ borderColor: 'var(--icon-button-secondary)'}}>
253
+ <div key={'Technical'} className='pt-8 space-y-8 kyd-avoid-break' style={{ borderColor: 'var(--icon-button-secondary)'}}>
240
254
  <Reveal as={'h4'} offsetY={8} className={'text-2xl font-semibold mb-3'} style={{ color: 'var(--text-main)' }}>KYD Technical</Reveal>
241
255
  {/* technical graph insights */}
242
256
  <Reveal>
@@ -246,6 +260,7 @@ const SharedBadgeDisplay = ({ badgeData, chatProps }: { badgeData: PublicBadgeDa
246
260
  categories={genreMapping?.['Technical'] as string[]}
247
261
  genre={'Technical'}
248
262
  scoringSummary={scoringSummary}
263
+ headless={isHeadless}
249
264
  />
250
265
  </div>
251
266
  </Reveal>
@@ -299,8 +314,8 @@ const SharedBadgeDisplay = ({ badgeData, chatProps }: { badgeData: PublicBadgeDa
299
314
  </div>
300
315
 
301
316
  <Reveal>
302
- <div className="pt-8 border-t" style={{ borderColor: 'var(--icon-button-secondary)'}}>
303
- <h3 className={'text-xl font-bold mb-3'} style={{ color: 'var(--text-main)' }}>KYD Technical - Skills Insights</h3>
317
+ <div className="pt-8 border-t kyd-avoid-break" style={{ borderColor: 'var(--icon-button-secondary)'}}>
318
+ <h3 className={'text-xl font-bold mb-3 kyd-keep-with-next'} style={{ color: 'var(--text-main)' }}>KYD Technical - Skills Insights</h3>
304
319
  <div className={'prose prose-sm max-w-none mb-6 space-y-4'} style={{ color: 'var(--text-secondary)' }}>
305
320
  <Skills skillsMatrix={skillsMatrix} skillsCategoryRadar={graphInsights?.skillsCategoryRadar} />
306
321
  </div>
@@ -313,7 +328,7 @@ const SharedBadgeDisplay = ({ badgeData, chatProps }: { badgeData: PublicBadgeDa
313
328
 
314
329
 
315
330
  <div className="pt-8 space-y-8">
316
- <Reveal as={'h3'} offsetY={8} className={'text-2xl font-bold'} style={{ color: 'var(--text-main)' }}>KYD Risk - Overview</Reveal>
331
+ <Reveal as={'h3'} offsetY={8} className={`text-2xl font-bold ${isHeadless ? 'kyd-break-before' : ''}`} style={{ color: 'var(--text-main)' }}>KYD Risk - Overview</Reveal>
317
332
 
318
333
  {/* Risk Graph Insights and Category Bars */}
319
334
  <Reveal>
@@ -323,10 +338,11 @@ const SharedBadgeDisplay = ({ badgeData, chatProps }: { badgeData: PublicBadgeDa
323
338
  categories={genreMapping?.['Risk'] as string[]}
324
339
  genre={'Risk'}
325
340
  scoringSummary={scoringSummary}
341
+ headless={isHeadless}
326
342
  />
327
343
  </div>
328
344
  </Reveal>
329
- <div className="grid grid-cols-1 lg:grid-cols-12 gap-8 w-full items-stretch py-8 border-y" style={{ borderColor: 'var(--icon-button-secondary)' }}>
345
+ <div className="grid grid-cols-1 lg:grid-cols-12 gap-8 w-full items-stretch py-8 border-y kyd-avoid-break" style={{ borderColor: 'var(--icon-button-secondary)' }}>
330
346
  {/* Left: Bars */}
331
347
  <Reveal className="lg:col-span-8 h-full">
332
348
  <CategoryBars
@@ -473,7 +489,7 @@ const SharedBadgeDisplay = ({ badgeData, chatProps }: { badgeData: PublicBadgeDa
473
489
 
474
490
 
475
491
  <div className="pt-8">
476
- <h3 className={'text-2xl font-bold mb-4'} style={{ color: 'var(--text-main)' }}>Appendix</h3>
492
+ <h3 className={`text-2xl font-bold mb-4 ${isHeadless ? 'kyd-break-before' : ''}`} style={{ color: 'var(--text-main)' }}>Appendix</h3>
477
493
  <div className="space-y-8">
478
494
 
479
495
  {/* Skills */}
@@ -551,7 +567,9 @@ const SharedBadgeDisplay = ({ badgeData, chatProps }: { badgeData: PublicBadgeDa
551
567
  </footer>
552
568
  </Reveal>
553
569
  {/* Floating chat widget */}
554
- <ChatWidget api={chatProps?.api || '/api/chat'} badgeId={badgeId} title={chatProps?.title} hintText={chatProps?.hintText} loginPath={chatProps?.loginPath} headerOffset={chatProps?.headerOffset} developerName={developerName} />
570
+ {!headless && (
571
+ <ChatWidget api={chatProps?.api || '/api/chat'} badgeId={badgeId} title={chatProps?.title} hintText={chatProps?.hintText} loginPath={chatProps?.loginPath} headerOffset={chatProps?.headerOffset} developerName={developerName} />
572
+ )}
555
573
  </div>
556
574
  </BusinessRulesProvider>
557
575
  );
@@ -299,9 +299,11 @@ const AppendixTables: React.FC<AppendixTableProps> = ({ type, sources, searchedA
299
299
  <td className={'px-4 py-4 whitespace-normal text-sm'} style={{ color: 'var(--text-secondary)' }}>{br.category || '—'}</td>
300
300
  <td className={'px-4 py-4 whitespace-normal text-sm font-medium'} style={{ color: 'var(--text-main)' }}>{br.label || '—'}</td>
301
301
  <td className={'px-4 py-4 whitespace-normal text-sm'} style={{ color: 'var(--text-secondary)' }}>{(() => {
302
- const weight = Number(br.weight || 0);
303
- if (!Number.isFinite(weight)) return '';
304
- return weight.toFixed(3).replace(/\.000$/, '.0');
302
+ const weight = Number(br.weight);
303
+ if (!Number.isFinite(weight)) return 'Neutral';
304
+ if (weight > 0) return 'Positive';
305
+ if (weight < 0) return 'Negative';
306
+ return 'Neutral';
305
307
  })()}</td>
306
308
  </tr>
307
309
  );
@@ -48,12 +48,34 @@ const GraphInsights = ({
48
48
  categories,
49
49
  genre,
50
50
  scoringSummary,
51
+ headless,
51
52
  }: {
52
53
  graphInsights: GraphInsightsPayload;
53
54
  categories?: string[];
54
55
  genre: string;
55
56
  scoringSummary?: ScoringSummary;
57
+ headless?: boolean;
56
58
  }) => {
59
+ const disableAnimations = React.useMemo(() => {
60
+ // Disable chart animations for headless/PDF/print to avoid capturing initial frames
61
+ if (headless) return true;
62
+ if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
63
+ try {
64
+ return window.matchMedia('print').matches;
65
+ } catch {}
66
+ }
67
+ return false;
68
+ }, [headless]);
69
+
70
+ // Nudge ResponsiveContainer to measure after mount in headless contexts
71
+ React.useEffect(() => {
72
+ if (typeof window !== 'undefined') {
73
+ const id = window.setTimeout(() => {
74
+ try { window.dispatchEvent(new Event('resize')); } catch {}
75
+ }, 0);
76
+ return () => window.clearTimeout(id);
77
+ }
78
+ }, []);
57
79
  const getCategoryTooltipCopy = (category: string): string => {
58
80
  const name = (category || '').toLowerCase();
59
81
 
@@ -231,12 +253,12 @@ const GraphInsights = ({
231
253
  <div className="grid grid-cols-1 gap-6">
232
254
  {/* Spider Chart: Category Balance (genre-scoped) */}
233
255
  {radarData && radarData.length > 2 && (
234
- <div className={'rounded-lg p-4 pb-4 border'} style={{ backgroundColor: 'var(--content-card-background)', borderColor: 'var(--icon-button-secondary)' }}>
235
- <div className="grid grid-cols-1 md:grid-cols-2 gap-6" >
256
+ <div className={'rounded-lg p-4 pb-4 border kyd-avoid-break'} style={{ backgroundColor: 'var(--content-card-background)', borderColor: 'var(--icon-button-secondary)', breakInside: 'avoid', pageBreakInside: 'avoid' as unknown as undefined }}>
257
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-6 kyd-avoid-break" >
236
258
 
237
259
  {/* Spider Chart: Category Scores */}
238
- <div className="" style={{ width: '100%', height: 450 }}>
239
- <div className="relative" style={{ width: '100%', height: 375 }}>
260
+ <div className="kyd-avoid-break" style={{ width: '100%', height: 450, breakInside: 'avoid', pageBreakInside: 'avoid' as unknown as undefined }}>
261
+ <div className="relative kyd-avoid-break" style={{ width: '100%', height: 375, breakInside: 'avoid', pageBreakInside: 'avoid' as unknown as undefined }}>
240
262
  <div className="mb-2">
241
263
  <div className={'font-medium'} style={{ color: 'var(--text-main)' }}>{genre ? `${genre} ` : ''} Category Contributions - Percentages</div>
242
264
  <div className={'text-xs'} style={{ color: 'var(--text-secondary)' }}>The spider diagram displays the KYD {genre} score across its sub-categories, with each point representing the strength of available evidence signals</div>
@@ -247,13 +269,13 @@ const GraphInsights = ({
247
269
  <PolarAngleAxis dataKey="axis" tick={renderAngleTick} />
248
270
  <PolarRadiusAxis angle={55} domain={[0, 100]} tick={{ fill: 'var(--text-secondary)' }} className="text-sm" />
249
271
  {/* Primary area */}
250
- <Radar name="Category Score" dataKey="score" stroke={'var(--text-main)'} fill={'var(--text-main)'} fillOpacity={0.22} />
272
+ <Radar name="Category Score" dataKey="score" stroke={'var(--text-main)'} fill={'var(--text-main)'} fillOpacity={0.22} isAnimationActive={!disableAnimations} />
251
273
  {/* Subtle average ring (arbitrary benchmark for comparison) */}
252
- <Radar name="Avg" dataKey="avg" stroke="rgba(128,128,128,0.6)" fill="rgba(128,128,128,0.08)" strokeDasharray="4 4" fillOpacity={1} />
274
+ <Radar name="Avg" dataKey="avg" stroke="rgba(128,128,128,0.6)" fill="rgba(128,128,128,0.08)" strokeDasharray="4 4" fillOpacity={1} isAnimationActive={!disableAnimations} />
253
275
  <Tooltip content={<RadarCategoryTooltip />} />
254
276
  </RadarChart>
255
277
  </ResponsiveContainer>
256
- {labelHover && (
278
+ {!headless && labelHover && (
257
279
  <div
258
280
  className="pointer-events-none absolute z-30"
259
281
  style={{
@@ -285,8 +307,8 @@ const GraphInsights = ({
285
307
  </div>
286
308
 
287
309
  {/* Pie Chart: Category Distribution */}
288
- <div className="md:border-l md:pl-6" style={{ borderColor: 'var(--icon-button-secondary)', width: '100%', height: 450 }}>
289
- <div className="" style={{ borderColor: 'var(--icon-button-secondary)', width: '100%', height: 375 }}>
310
+ <div className="md:border-l md:pl-6 kyd-avoid-break" style={{ borderColor: 'var(--icon-button-secondary)', width: '100%', height: 450, breakInside: 'avoid', pageBreakInside: 'avoid' as unknown as undefined }}>
311
+ <div className="kyd-avoid-break" style={{ borderColor: 'var(--icon-button-secondary)', width: '100%', height: 375, breakInside: 'avoid', pageBreakInside: 'avoid' as unknown as undefined }}>
290
312
  <div className="mb-2">
291
313
  <div className={'font-medium'} style={{ color: 'var(--text-main)' }}>{genre ? `${genre} ` : ''} Category Contributions - Proportions</div>
292
314
  <div className={'text-xs'} style={{ color: 'var(--text-secondary)' }}>The donut diagram illustrates the relative contribution of each {genre} category to the pillar’s composite score.</div>
@@ -325,7 +347,7 @@ const GraphInsights = ({
325
347
  startAngle={90}
326
348
  endAngle={-270}
327
349
  paddingAngle={1.5}
328
- isAnimationActive
350
+ isAnimationActive={!disableAnimations}
329
351
  label={renderLabel}
330
352
  labelLine={false}
331
353
  >