gulp-mu-gulp-api 0.3.0 → 0.3.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.mjs +95 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gulp-mu-gulp-api",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Public task API for the µGulp orchestrator: progress reporting, sound signals, speech output, localized console output (i18x) and interactive UI inputs (text, password, number, textarea, color, font, select, radio, multi-select checkbox, range slider, date/time, file) from within gulp tasks — with graceful CLI fallbacks when running without µGulp.",
5
5
  "type": "module",
6
6
  "main": "src/index.mjs",
package/src/index.mjs CHANGED
@@ -147,6 +147,72 @@ export function LogTree(_spec) {
147
147
  for (let line of _AsciiTreeLines(payload)) console.log(line);
148
148
  }
149
149
 
150
+ /**
151
+ * Sends an image gallery to the dashboard log pane. Each item needs a `src`
152
+ * (data URI or https URL) and a `label`; optional `caption` and per-item `title`.
153
+ * CLI fallback: lists labels and src lengths on stdout.
154
+ *
155
+ * @param {object} _spec `{ title?, columns?, items: { label, src, caption?, title? }[] }`
156
+ */
157
+ export function LogGallery(_spec) {
158
+ let payload = _NormalizeGallerySpec(_spec);
159
+ if (IsMicroGulp()) {
160
+ process.send({ type: 'structured-log', format: 'gallery', payload });
161
+ return;
162
+ }
163
+ console.log(_AsciiGallery(payload));
164
+ }
165
+
166
+ /**
167
+ * Renders µCSS BuildSkin `report.debug.previews` as a thumbnail gallery.
168
+ * Items without `thumbDataUri` are omitted (paths-only assets stay in the text log).
169
+ *
170
+ * @param {object[]} _previews preview entries from `report.debug.previews`
171
+ * @param {object} [_options] `{ title?, columns? }`
172
+ */
173
+ export function LogAssetPreviews(_previews, _options = {}) {
174
+ let items = (_previews ?? [])
175
+ .filter((_entry) => _entry?.thumbDataUri)
176
+ .map((_entry) => ({
177
+ label: String(_entry.relPath ?? _entry.path ?? ''),
178
+ src: _entry.thumbDataUri,
179
+ caption: [
180
+ _entry.step,
181
+ _entry.skipped ? 'cached' : null,
182
+ _entry.width && _entry.height ? `${_entry.width}\u00d7${_entry.height}` : null,
183
+ ].filter(Boolean).join(' \u00b7 '),
184
+ }));
185
+ if (!items.length) return;
186
+ LogGallery({
187
+ title: _options.title,
188
+ columns: _options.columns ?? 4,
189
+ items,
190
+ });
191
+ }
192
+
193
+ /**
194
+ * Convenience wrapper for a full µCSS `BuildSkin` debug block: summary table
195
+ * plus thumbnail gallery when `report.debug` is present.
196
+ *
197
+ * @param {object} _report BuildSkin return value
198
+ * @param {object} [_options] `{ title?, columns?, table?: boolean }`
199
+ */
200
+ export function LogBuildDebugReport(_report, _options = {}) {
201
+ let debug = _report?.debug;
202
+ if (!debug) return;
203
+ if (_options.table !== false && debug.summary) {
204
+ LogTable({
205
+ columns: [{ id: 'metric', label: 'Metric' }, { id: 'value', label: 'Value' }],
206
+ rows: Object.entries(debug.summary).map(([metric, value]) => ({ metric, value: String(value) })),
207
+ hyphenate: false,
208
+ });
209
+ }
210
+ LogAssetPreviews(debug.previews, {
211
+ title: _options.title ?? 'Generated assets',
212
+ columns: _options.columns,
213
+ });
214
+ }
215
+
150
216
  // -------------------------------------------------
151
217
  // sound & speech
152
218
  // -------------------------------------------------
@@ -425,6 +491,32 @@ function _AsciiTreeLines(_payload, _indent = '', _roots = null) {
425
491
  return lines;
426
492
  }
427
493
 
494
+ function _NormalizeGallerySpec(_spec) {
495
+ let columns = Math.max(1, Math.min(8, Number(_spec?.columns) || 4));
496
+ let items = (_spec?.items ?? []).map((_item) => ({
497
+ label: String(_item?.label ?? ''),
498
+ src: String(_item?.src ?? ''),
499
+ caption: _item?.caption != null ? String(_item.caption) : '',
500
+ title: _item?.title != null ? String(_item.title) : '',
501
+ })).filter((_item) => _item.src);
502
+ return {
503
+ title: _spec?.title != null ? String(_spec.title) : '',
504
+ columns,
505
+ items,
506
+ };
507
+ }
508
+
509
+ function _AsciiGallery(_payload) {
510
+ let lines = [];
511
+ if (_payload.title) lines.push(_payload.title);
512
+ for (let item of _payload.items) {
513
+ let meta = item.caption ? ` (${item.caption})` : '';
514
+ let srcHint = item.src.startsWith('data:') ? `[data URI, ${item.src.length} chars]` : item.src;
515
+ lines.push(` ${item.label}${meta}: ${srcHint}`);
516
+ }
517
+ return lines.join('\n');
518
+ }
519
+
428
520
  export default {
429
521
  IsMicroGulp,
430
522
  IsµGulp,
@@ -450,4 +542,7 @@ export default {
450
542
  InstallStringExtensions: I18x.InstallStringExtensions,
451
543
  LogTable,
452
544
  LogTree,
545
+ LogGallery,
546
+ LogAssetPreviews,
547
+ LogBuildDebugReport,
453
548
  };