@prunellejs/images 0.7.3 → 0.7.7

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 (3) hide show
  1. package/llms.txt +1 -1
  2. package/package.json +2 -2
  3. package/src/card.ts +59 -10
package/llms.txt CHANGED
@@ -11,7 +11,7 @@
11
11
 
12
12
  - `widths`: responsive widths in px (default `[320, 640, 960, 1280, 1920]`).
13
13
  - `formats`: `('avif' | 'webp')[]` (default `['avif', 'webp']`; uses ImageMagick `magick` on `PATH`, falls back to original file with parsed dimensions when unavailable). Each image is decoded once per format, one `magick` run writing all its widths; runs share one budget for the whole build (half the cores, at most 8 `magick` at once), each limited to one thread and 512 MiB and killed after 2 min; a failed run warns with the file, the widths and `magick`'s error and leaves those variants out until the next build retries them (the original ships when none succeeds).
14
- - Every image the build ships, original included, loses its EXIF (GPS position, camera serial), XMP, IPTC and text metadata; JPEG, PNG and WebP keep only their Orientation, and every variant keeps its ICC colour profile (`magick ... +profile "!icc,*"`, not `-strip`). `prunelle check` warns about each JPEG, PNG or WebP under `public/` still carrying EXIF, XMP or IPTC, since `public/` is copied as is.
14
+ - Every image the build ships, original included, loses its EXIF (GPS position, camera serial), XMP, IPTC and text metadata; JPEG, PNG and WebP keep only their Orientation, and every variant keeps its ICC colour profile (`magick ... +profile "!icc,*"`, not `-strip`). `prunelle check` warns, in path order, about each JPEG, PNG or WebP under `publicDir` (`public/` by default) still carrying EXIF, XMP or IPTC, since it is copied as is.
15
15
  - `quality` (WebP, default `80`), `avifQuality` (default `55`), `cacheDir` (default `'.prunelle-cache/images'`), `pruneCache` (default `true`: after a build that prerendered pages, `og-` and `md-` cache files no page registered are deleted, together with the imported-image cache the build did not load). The runtime `/og/` and `/img/` stores are LRUs of twice the files the build registered, at least 256 and 4096.
16
16
  - `card`: `ShareCardDefaults` (`{ site?, publicDir?, cacheDir?, background?, color?, accent?, mutedColor?, fontFamily?, width? (1200), height? (630) }`).
17
17
  - `markdownSizes`: default `sizes` attribute for relative images inside `@prunellejs/content` Markdown (auto-wired via `CONTENT_IMAGE_RESOLVER_SERVICE`).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prunellejs/images",
3
- "version": "0.7.3",
3
+ "version": "0.7.7",
4
4
  "description": "Build-time responsive AVIF/WebP image optimization plugin for Prunelle",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -22,6 +22,6 @@
22
22
  "directory": "packages/plugin-images"
23
23
  },
24
24
  "peerDependencies": {
25
- "prunelle": "^0.7.3"
25
+ "prunelle": "^0.7.7"
26
26
  }
27
27
  }
package/src/card.ts CHANGED
@@ -69,24 +69,73 @@ function getCardConfig(): ShareCardDefaults {
69
69
  }
70
70
 
71
71
 
72
- function wrapLines(text: string, maxChars: number, maxLines: number): string[] {
72
+ function splitTokens(text: string, maxChars: number): string[] {
73
73
  const words = text.trim().split(/\s+/).filter(Boolean)
74
+ const tokens: string[] = []
75
+ for (const w of words) {
76
+ const chars = Array.from(w)
77
+ if (chars.length <= maxChars) {
78
+ tokens.push(w)
79
+ }
80
+ else {
81
+ for (let i = 0; i < chars.length; i += maxChars)
82
+ tokens.push(chars.slice(i, i + maxChars).join(''))
83
+ }
84
+ }
85
+ return tokens
86
+ }
87
+
88
+ function addEllipsis(line: string, maxChars: number): string {
89
+ const chars = Array.from(line)
90
+ if (line.endsWith('…') && chars.length <= maxChars)
91
+ return line
92
+ if (chars.length < maxChars)
93
+ return `${line}…`
94
+ if (maxChars <= 1)
95
+ return '…'
96
+ const lastSpace = line.lastIndexOf(' ')
97
+ if (lastSpace > 0 && Array.from(line.slice(0, lastSpace)).length < maxChars)
98
+ return `${line.slice(0, lastSpace).trimEnd()}…`
99
+ return `${chars.slice(0, maxChars - 1).join('').trimEnd()}…`
100
+ }
101
+
102
+ function wrapLines(text: string, maxChars: number, maxLines: number): string[] {
103
+ if (maxChars < 1 || maxLines < 1)
104
+ return []
105
+ const tokens = splitTokens(text, maxChars)
106
+ if (tokens.length === 0)
107
+ return []
108
+
74
109
  const lines: string[] = []
75
110
  let cur = ''
76
- for (const w of words) {
77
- const next = cur ? `${cur} ${w}` : w
78
- if (next.length > maxChars && cur) {
111
+ let curLen = 0
112
+ let truncated = false
113
+
114
+ for (let i = 0; i < tokens.length; i++) {
115
+ const token = tokens[i]!
116
+ const tokenLen = Array.from(token).length
117
+ if (curLen === 0) {
118
+ cur = token
119
+ curLen = tokenLen
120
+ }
121
+ else if (curLen + 1 + tokenLen <= maxChars) {
122
+ cur = `${cur} ${token}`
123
+ curLen += 1 + tokenLen
124
+ }
125
+ else if (lines.length < maxLines - 1) {
79
126
  lines.push(cur)
80
- cur = w
81
- if (lines.length >= maxLines - 1)
82
- break
127
+ cur = token
128
+ curLen = tokenLen
83
129
  }
84
130
  else {
85
- cur = next
131
+ truncated = true
132
+ break
86
133
  }
87
134
  }
88
- if (cur && lines.length < maxLines)
89
- lines.push(cur)
135
+
136
+ if (cur)
137
+ lines.push(truncated ? addEllipsis(cur, maxChars) : cur)
138
+
90
139
  return lines
91
140
  }
92
141