@shipload/item-renderer 0.1.0 → 0.1.2

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": "@shipload/item-renderer",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Deterministic SVG rendering for Shipload items",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
package/src/index.ts CHANGED
@@ -14,7 +14,7 @@ export { renderByType, type RenderByTypeOpts } from './templates/index.ts'
14
14
 
15
15
  // Links + meta
16
16
  export { linkToItemPage, linkToItemImage } from './links.ts'
17
- export { itemPageMeta } from './meta.ts'
17
+ export { itemPageMeta, svgDimensions } from './meta.ts'
18
18
  export type { ItemPageMeta, ItemPageMetaOptions } from './meta.ts'
19
19
 
20
20
  // Tokens (consumed by testmap tailwind.config)
package/src/links.ts CHANGED
@@ -2,7 +2,7 @@ import type { CargoItem } from './payload/codec.ts'
2
2
  import { encodePayload } from './payload/codec.ts'
3
3
 
4
4
  const DEFAULT_WEBSITE_BASE = 'https://shiploadgame.com'
5
- const DEFAULT_IMAGE_BASE = 'https://img.shiploadgame.com'
5
+ const DEFAULT_IMAGE_BASE = 'https://item.shiploadgame.com'
6
6
 
7
7
  export function linkToItemPage(item: CargoItem, baseUrl = DEFAULT_WEBSITE_BASE): string {
8
8
  const payload = encodePayload(item)
package/src/meta.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { ResolvedItem } from '@shipload/sdk'
2
2
  import type { CargoItem } from './payload/codec.ts'
3
3
  import { linkToItemImage } from './links.ts'
4
+ import { renderItem } from './render.ts'
4
5
 
5
6
  function tierLabel(tier: string): string {
6
7
  return tier.toUpperCase()
@@ -19,14 +20,25 @@ function describeItem(resolved: ResolvedItem): string {
19
20
  return parts.join(' · ')
20
21
  }
21
22
 
23
+ const DIMS_RE = /<svg[^>]*?\bwidth="(\d+)"[^>]*?\bheight="(\d+)"/
24
+
25
+ export function svgDimensions(svg: string): { width: number; height: number } {
26
+ const m = DIMS_RE.exec(svg)
27
+ if (!m) throw new Error('svgDimensions: could not locate width/height on root <svg>')
28
+ return { width: Number(m[1]), height: Number(m[2]) }
29
+ }
30
+
22
31
  export interface ItemPageMeta {
23
32
  title: string
24
33
  description: string
25
34
  ogImage: string
35
+ ogImageWidth: number
36
+ ogImageHeight: number
26
37
  }
27
38
 
28
39
  export interface ItemPageMetaOptions {
29
40
  imageBaseUrl?: string
41
+ svg?: string
30
42
  }
31
43
 
32
44
  export function itemPageMeta(
@@ -34,9 +46,13 @@ export function itemPageMeta(
34
46
  resolved: ResolvedItem,
35
47
  opts?: ItemPageMetaOptions,
36
48
  ): ItemPageMeta {
49
+ const svg = opts?.svg ?? renderItem(item, resolved)
50
+ const { width, height } = svgDimensions(svg)
37
51
  return {
38
52
  title: `${resolved.name} · Shipload Guide`,
39
53
  description: describeItem(resolved),
40
54
  ogImage: linkToItemImage(item, 'png', opts?.imageBaseUrl),
55
+ ogImageWidth: width,
56
+ ogImageHeight: height,
41
57
  }
42
58
  }
@@ -16,7 +16,7 @@ test('linkToItemPage accepts a custom base URL', () => {
16
16
 
17
17
  test('linkToItemImage builds a PNG URL', () => {
18
18
  const url = linkToItemImage(FIXTURES.iron, 'png')
19
- expect(url).toMatch(/^https:\/\/img\.shiploadgame\.com\/item\/[A-Za-z0-9_-]+\.png$/)
19
+ expect(url).toMatch(/^https:\/\/item\.shiploadgame\.com\/item\/[A-Za-z0-9_-]+\.png$/)
20
20
  })
21
21
 
22
22
  test('linkToItemImage builds an SVG URL', () => {
@@ -30,5 +30,5 @@ test('itemPageMeta produces title, description, and ogImage', () => {
30
30
  const meta = itemPageMeta(item, resolved)
31
31
  expect(meta.title).toContain('Iron')
32
32
  expect(meta.description.length).toBeGreaterThan(0)
33
- expect(meta.ogImage).toMatch(/^https:\/\/img\.shiploadgame\.com\/item\/[A-Za-z0-9_-]+\.png$/)
33
+ expect(meta.ogImage).toMatch(/^https:\/\/item\.shiploadgame\.com\/item\/[A-Za-z0-9_-]+\.png$/)
34
34
  })