@r2digisolutions/components 0.23.0 → 0.24.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 (50) hide show
  1. package/dist/components/atoms/Avatar/Avatar.stories.js +1 -1
  2. package/dist/components/atoms/BrandMark/BrandMark.svelte +47 -7
  3. package/dist/components/atoms/BrandMark/BrandMark.svelte.d.ts +4 -0
  4. package/dist/components/atoms/Input/Input.svelte +5 -4
  5. package/dist/components/atoms/Slider/Slider.svelte +19 -15
  6. package/dist/components/atoms/Slider/Slider.svelte.d.ts +2 -0
  7. package/dist/components/molecules/AuthCard/AuthCard.svelte +19 -4
  8. package/dist/components/molecules/AuthCard/AuthCard.svelte.d.ts +4 -0
  9. package/dist/components/molecules/CanvasElementsPanel/CanvasElementsPanel.svelte +90 -26
  10. package/dist/components/molecules/CanvasInspector/CanvasInspector.svelte +176 -5
  11. package/dist/components/molecules/ChipBar/ChipBar.svelte +18 -5
  12. package/dist/components/molecules/ChipBar/ChipBar.svelte.d.ts +1 -1
  13. package/dist/components/molecules/Combobox/Combobox.svelte +2 -2
  14. package/dist/components/molecules/DateTimePicker/DateTimePicker.svelte +121 -33
  15. package/dist/components/molecules/FormSection/FormSection.svelte +25 -28
  16. package/dist/components/molecules/ImageEditor/ImageEditor.svelte +183 -0
  17. package/dist/components/molecules/ImageEditor/ImageEditor.svelte.d.ts +19 -0
  18. package/dist/components/molecules/KnowledgeCard/KnowledgeCard.svelte +5 -5
  19. package/dist/components/molecules/LocaleSwitcher/LocaleSwitcher.svelte +58 -35
  20. package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte +293 -39
  21. package/dist/components/molecules/MediaLayerItem/MediaLayerItem.svelte.d.ts +6 -1
  22. package/dist/components/molecules/MediaStage/MediaStage.svelte +302 -245
  23. package/dist/components/molecules/MentionInput/MentionInput.svelte +332 -120
  24. package/dist/components/molecules/MentionInput/MentionInput.svelte.d.ts +13 -2
  25. package/dist/components/molecules/SearchBar/SearchBar.svelte +7 -1
  26. package/dist/components/molecules/SearchInput/SearchInput.svelte +77 -18
  27. package/dist/components/molecules/SearchInput/SearchInput.svelte.d.ts +4 -0
  28. package/dist/components/molecules/SearchInput/SearchInputStory.svelte +1 -0
  29. package/dist/components/molecules/Select/Select.svelte +14 -1
  30. package/dist/components/molecules/Select/Select.svelte.d.ts +3 -0
  31. package/dist/components/molecules/UserMenu/UserMenu.svelte +30 -27
  32. package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte +200 -17
  33. package/dist/components/molecules/WidgetFrame/WidgetFrame.svelte.d.ts +14 -0
  34. package/dist/components/organisms/AppShell/AppShell.svelte +7 -1
  35. package/dist/components/organisms/AppShell/AppShell.svelte.d.ts +2 -0
  36. package/dist/components/organisms/AuthShell/AuthShell.svelte +61 -29
  37. package/dist/components/organisms/AuthShell/AuthShell.svelte.d.ts +4 -0
  38. package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte +156 -7
  39. package/dist/components/organisms/CanvasEditor/CanvasEditor.svelte.d.ts +5 -0
  40. package/dist/components/organisms/Navbar/Navbar.svelte +2 -2
  41. package/dist/components/organisms/ProfileHeaderUploader/ProfileHeaderUploader.svelte +314 -141
  42. package/dist/components/organisms/ProfileHeaderUploader/ProfileHeaderUploader.svelte.d.ts +20 -1
  43. package/dist/index.d.ts +3 -1
  44. package/dist/index.js +2 -1
  45. package/dist/styles.css +17 -0
  46. package/dist/utils/canvasDocument.d.ts +56 -4
  47. package/dist/utils/canvasDocument.js +91 -2
  48. package/dist/utils/canvasExport.d.ts +1 -1
  49. package/dist/utils/canvasExport.js +15 -25
  50. package/package.json +1 -1
package/dist/styles.css CHANGED
@@ -286,3 +286,20 @@
286
286
  stroke: var(--border);
287
287
  }
288
288
  }
289
+
290
+ /* Autocompletado del navegador: sin esto pinta un bloque gris/amarillo
291
+ que no sigue la superficie del campo. */
292
+ input:-webkit-autofill,
293
+ input:-webkit-autofill:hover,
294
+ input:-webkit-autofill:focus,
295
+ textarea:-webkit-autofill,
296
+ textarea:-webkit-autofill:hover,
297
+ textarea:-webkit-autofill:focus,
298
+ select:-webkit-autofill,
299
+ select:-webkit-autofill:hover,
300
+ select:-webkit-autofill:focus {
301
+ -webkit-text-fill-color: var(--text-primary);
302
+ caret-color: var(--text-primary);
303
+ box-shadow: inset 0 0 0 1000px var(--surface-elevated);
304
+ transition: background-color 99999s ease-out;
305
+ }
@@ -79,10 +79,15 @@ export interface CanvasLayer {
79
79
  lineHeight?: number;
80
80
  textAlign?: CanvasTextAlign;
81
81
  /**
82
- * When true, resizing the text box scales `fontSize` with the box
83
- * (geometric mean of width/height scale — Unreal/Canva-style).
82
+ * When true, the box hugs the text.
83
+ * Side handles set `textMaxWidth` so lines wrap; height always follows the type.
84
84
  */
85
85
  autoSize?: boolean;
86
+ /**
87
+ * Wrap width in layer pixels. Unset means the box grows with the longest line,
88
+ * including manual line breaks. Set by dragging the left or right handle.
89
+ */
90
+ textMaxWidth?: number;
86
91
  /**
87
92
  * When true, resizing this container scales children (position + size + text)
88
93
  * relative to the parent — same idea as text `autoSize`. Groups default on.
@@ -99,6 +104,19 @@ export interface CanvasLayer {
99
104
  shadowBlur?: number;
100
105
  shadowColor?: string;
101
106
  blur?: number;
107
+ /** CSS filter percents. `100` is unchanged. Used by image and video layers. */
108
+ brightness?: number;
109
+ contrast?: number;
110
+ saturate?: number;
111
+ /**
112
+ * Extra zoom inside an image or video, on top of `objectFit`.
113
+ * `1` is the fit itself. The layer rect does not change.
114
+ */
115
+ mediaScale?: number;
116
+ /** Horizontal alignment of the fitted bitmap inside the layer. `0.5` is centered. */
117
+ mediaX?: number;
118
+ /** Vertical alignment of the fitted bitmap inside the layer. `0.5` is centered. */
119
+ mediaY?: number;
102
120
  /** For `path`: normalized points (0–1) relative to rect. */
103
121
  points?: CanvasPoint[];
104
122
  /** For `path`: close the shape into a filled polygon. */
@@ -166,14 +184,14 @@ export declare function ensureLayerSlot(layer: CanvasLayer): CanvasLayer;
166
184
  export declare function createCanvasGuide(orientation: CanvasGuideOrientation, position: number, partial?: Partial<Omit<CanvasGuide, 'id' | 'orientation' | 'position'>>): CanvasGuide;
167
185
  export declare function createCanvasLayer(kind: CanvasLayerKind, partial?: Partial<Omit<CanvasLayer, 'id' | 'kind'>>): CanvasLayer;
168
186
  /** Scalar fields that can reset to createCanvasLayer defaults (UE-style details). */
169
- export type CanvasResettableField = 'opacity' | 'rotation' | 'visible' | 'locked' | 'flipX' | 'flipY' | 'blur' | 'shadowBlur' | 'shadowColor' | 'fill' | 'stroke' | 'strokeWidth' | 'fontSize' | 'fontWeight' | 'fontFamily' | 'fontStyle' | 'textDecoration' | 'letterSpacing' | 'lineHeight' | 'textAlign' | 'autoSize' | 'color' | 'textBackground' | 'objectFit' | 'borderRadius' | 'gap' | 'columns' | 'clipChildren' | 'autoSizeChildren' | 'text' | 'name';
187
+ export type CanvasResettableField = 'opacity' | 'rotation' | 'visible' | 'locked' | 'flipX' | 'flipY' | 'blur' | 'brightness' | 'contrast' | 'saturate' | 'mediaScale' | 'mediaX' | 'mediaY' | 'shadowBlur' | 'shadowColor' | 'fill' | 'stroke' | 'strokeWidth' | 'fontSize' | 'fontWeight' | 'fontFamily' | 'fontStyle' | 'textDecoration' | 'letterSpacing' | 'lineHeight' | 'textAlign' | 'autoSize' | 'color' | 'textBackground' | 'objectFit' | 'borderRadius' | 'gap' | 'columns' | 'clipChildren' | 'autoSizeChildren' | 'text' | 'name';
170
188
  /** Default value for a layer field (same as createCanvasLayer would use). */
171
189
  export declare function canvasLayerFieldDefault(kind: CanvasLayerKind, field: CanvasResettableField): unknown;
172
190
  export declare function isCanvasFieldModified(layer: CanvasLayer, field: CanvasResettableField): boolean;
173
191
  export declare function resetCanvasField(layer: CanvasLayer, field: CanvasResettableField): Partial<CanvasLayer>;
174
192
  /**
175
193
  * Scale fontSize with the box when `autoSize` is on (text / sticky).
176
- * Uses geometric mean of width & height scale so both axes affect size.
194
+ * Side handles reflow and the frame grows with the lines. Only a corner scales the type.
177
195
  */
178
196
  export declare function applyTextAutoSize(from: CanvasLayer, to: CanvasLayer, prev: Pick<CanvasLayerRect, 'w' | 'h'>, next: Pick<CanvasLayerRect, 'w' | 'h'>): CanvasLayer;
179
197
  export declare function reorderCanvasLayers(layers: CanvasLayer[], orderedIds: string[]): CanvasLayer[];
@@ -189,7 +207,41 @@ export declare function alignLayerRect(rect: CanvasLayerRect, bounds: {
189
207
  width: number;
190
208
  height: number;
191
209
  }, align: CanvasAlign): CanvasLayerRect;
210
+ export declare const COVER_ARTBOARD: {
211
+ readonly width: 1800;
212
+ readonly height: 600;
213
+ };
214
+ /** Artboard with the photo fully visible. Scaling that layer is the zoom. */
215
+ export declare function coverDocumentFromImage(src: string, name?: string): CanvasDocument;
216
+ /** Drop session blob URLs on the cover layer so the JSON can be stored. */
217
+ export declare function persistCoverDocument(doc: CanvasDocument): CanvasDocument;
218
+ /** Point the stored cover layer at the original file URL. */
219
+ export declare function hydrateCoverDocument(doc: CanvasDocument, src: string): CanvasDocument;
220
+ /** Where the bitmap sits inside the layer box, in the same units as `box`. */
221
+ export declare function mediaContentBox(box: {
222
+ w: number;
223
+ h: number;
224
+ }, natural: {
225
+ w: number;
226
+ h: number;
227
+ }, fit: CanvasObjectFit | undefined, zoom?: number, mediaX?: number, mediaY?: number): {
228
+ x: number;
229
+ y: number;
230
+ w: number;
231
+ h: number;
232
+ };
233
+ export declare function canvasLayerFilter(layer: {
234
+ blur?: number;
235
+ brightness?: number;
236
+ contrast?: number;
237
+ saturate?: number;
238
+ }): string | undefined;
192
239
  export declare const CANVAS_PRESETS: readonly [{
240
+ readonly id: "cover";
241
+ readonly label: "Cover · 1800×600";
242
+ readonly width: 1800;
243
+ readonly height: 600;
244
+ }, {
193
245
  readonly id: "hd";
194
246
  readonly label: "HD · 1280×720";
195
247
  readonly width: 1280;
@@ -170,6 +170,12 @@ export function createCanvasLayer(kind, partial) {
170
170
  shadowBlur: partial?.shadowBlur,
171
171
  shadowColor: partial?.shadowColor,
172
172
  blur: partial?.blur,
173
+ brightness: partial?.brightness ?? (kind === 'image' || kind === 'video' ? 100 : undefined),
174
+ contrast: partial?.contrast ?? (kind === 'image' || kind === 'video' ? 100 : undefined),
175
+ saturate: partial?.saturate ?? (kind === 'image' || kind === 'video' ? 100 : undefined),
176
+ mediaScale: partial?.mediaScale ?? (kind === 'image' || kind === 'video' ? 1 : undefined),
177
+ mediaX: partial?.mediaX ?? (kind === 'image' || kind === 'video' ? 0.5 : undefined),
178
+ mediaY: partial?.mediaY ?? (kind === 'image' || kind === 'video' ? 0.5 : undefined),
173
179
  points: partial?.points,
174
180
  closed: partial?.closed ?? false,
175
181
  parentId: partial?.parentId ?? null,
@@ -217,6 +223,15 @@ export function canvasLayerFieldDefault(kind, field) {
217
223
  case 'blur':
218
224
  case 'shadowBlur':
219
225
  return undefined;
226
+ case 'brightness':
227
+ case 'contrast':
228
+ case 'saturate':
229
+ return kind === 'image' || kind === 'video' ? 100 : undefined;
230
+ case 'mediaScale':
231
+ return kind === 'image' || kind === 'video' ? 1 : undefined;
232
+ case 'mediaX':
233
+ case 'mediaY':
234
+ return kind === 'image' || kind === 'video' ? 0.5 : undefined;
220
235
  case 'shadowColor':
221
236
  return undefined;
222
237
  case 'fill':
@@ -274,7 +289,7 @@ export function resetCanvasField(layer, field) {
274
289
  }
275
290
  /**
276
291
  * Scale fontSize with the box when `autoSize` is on (text / sticky).
277
- * Uses geometric mean of width & height scale so both axes affect size.
292
+ * Side handles reflow and the frame grows with the lines. Only a corner scales the type.
278
293
  */
279
294
  export function applyTextAutoSize(from, to, prev, next) {
280
295
  if (from.kind !== 'text' && from.kind !== 'sticky')
@@ -288,7 +303,11 @@ export function applyTextAutoSize(from, to, prev, next) {
288
303
  return to;
289
304
  const sx = next.w / Math.max(1, prev.w);
290
305
  const sy = next.h / Math.max(1, prev.h);
291
- const scale = Math.sqrt(sx * sy);
306
+ const widthChanged = Math.abs(sx - 1) > 0.02;
307
+ const heightChanged = Math.abs(sy - 1) > 0.02;
308
+ // Side handles reflow. A shorter box cannot squash the type: the frame grows instead.
309
+ // Only a corner scales the font, and the box hugs the glyphs again on release.
310
+ const scale = widthChanged && heightChanged ? sy : 1;
292
311
  if (!Number.isFinite(scale) || Math.abs(scale - 1) < 0.001)
293
312
  return to;
294
313
  const base = from.fontSize ?? (from.kind === 'sticky' ? 20 : 32);
@@ -410,7 +429,77 @@ export function alignLayerRect(rect, bounds, align) {
410
429
  }
411
430
  return { x, y, w, h };
412
431
  }
432
+ export const COVER_ARTBOARD = { width: 1800, height: 600 };
433
+ /** Artboard with the photo fully visible. Scaling that layer is the zoom. */
434
+ export function coverDocumentFromImage(src, name = 'Cover') {
435
+ return emptyCanvasDocument({
436
+ width: COVER_ARTBOARD.width,
437
+ height: COVER_ARTBOARD.height,
438
+ background: '#111111',
439
+ layers: [
440
+ createCanvasLayer('image', {
441
+ name,
442
+ src,
443
+ objectFit: 'contain',
444
+ rect: { x: 0, y: 0, w: COVER_ARTBOARD.width, h: COVER_ARTBOARD.height }
445
+ })
446
+ ]
447
+ });
448
+ }
449
+ /** Drop session blob URLs on the cover layer so the JSON can be stored. */
450
+ export function persistCoverDocument(doc) {
451
+ return {
452
+ ...doc,
453
+ layers: doc.layers.map((layer) => layer.kind === 'image' && layer.name === 'Cover' && layer.src?.startsWith('blob:')
454
+ ? { ...layer, src: '' }
455
+ : layer)
456
+ };
457
+ }
458
+ /** Point the stored cover layer at the original file URL. */
459
+ export function hydrateCoverDocument(doc, src) {
460
+ return {
461
+ ...doc,
462
+ layers: doc.layers.map((layer) => layer.kind === 'image' && layer.name === 'Cover' && !layer.src ? { ...layer, src } : layer)
463
+ };
464
+ }
465
+ /** Where the bitmap sits inside the layer box, in the same units as `box`. */
466
+ export function mediaContentBox(box, natural, fit, zoom = 1, mediaX = 0.5, mediaY = 0.5) {
467
+ const mode = fit ?? 'cover';
468
+ const z = zoom > 0 ? zoom : 1;
469
+ let dw;
470
+ let dh;
471
+ if (mode === 'fill' || natural.w <= 0 || natural.h <= 0) {
472
+ dw = box.w * z;
473
+ dh = box.h * z;
474
+ }
475
+ else {
476
+ const base = mode === 'contain'
477
+ ? Math.min(box.w / natural.w, box.h / natural.h)
478
+ : Math.max(box.w / natural.w, box.h / natural.h);
479
+ dw = natural.w * base * z;
480
+ dh = natural.h * base * z;
481
+ }
482
+ return {
483
+ x: (box.w - dw) * mediaX,
484
+ y: (box.h - dh) * mediaY,
485
+ w: dw,
486
+ h: dh
487
+ };
488
+ }
489
+ export function canvasLayerFilter(layer) {
490
+ const parts = [];
491
+ if (layer.blur)
492
+ parts.push(`blur(${layer.blur}px)`);
493
+ if (layer.brightness != null && layer.brightness !== 100)
494
+ parts.push(`brightness(${layer.brightness}%)`);
495
+ if (layer.contrast != null && layer.contrast !== 100)
496
+ parts.push(`contrast(${layer.contrast}%)`);
497
+ if (layer.saturate != null && layer.saturate !== 100)
498
+ parts.push(`saturate(${layer.saturate}%)`);
499
+ return parts.length ? parts.join(' ') : undefined;
500
+ }
413
501
  export const CANVAS_PRESETS = [
502
+ { id: 'cover', label: 'Cover · 1800×600', width: 1800, height: 600 },
414
503
  { id: 'hd', label: 'HD · 1280×720', width: 1280, height: 720 },
415
504
  { id: 'fhd', label: 'Full HD · 1920×1080', width: 1920, height: 1080 },
416
505
  { id: 'square', label: 'Instagram · 1080×1080', width: 1080, height: 1080 },
@@ -1,4 +1,4 @@
1
- import type { CanvasDocument } from './canvasDocument.js';
1
+ import { type CanvasDocument } from './canvasDocument.js';
2
2
  export type CanvasExportFormat = 'png' | 'jpeg' | 'json';
3
3
  /** Parse CSS color alpha; `transparent` / missing → 0. */
4
4
  export declare function backgroundAlpha(color: string | undefined): number;
@@ -1,3 +1,4 @@
1
+ import { canvasLayerFilter, mediaContentBox } from './canvasDocument.js';
1
2
  import { computeAbsoluteRects, isEffectivelyVisible } from './canvasHierarchy.js';
2
3
  import { flattenLayersWithWidgets } from './canvasWidget.js';
3
4
  import { CANVAS_SVG_SHAPES, drawCanvasSvgShape } from './canvasShapes.js';
@@ -196,7 +197,8 @@ function drawShapePath(ctx, layer) {
196
197
  function drawText(ctx, layer) {
197
198
  const { x, y, w, h } = layer.rect;
198
199
  if (layer.kind === 'sticky' || layer.textBackground) {
199
- ctx.fillStyle = layer.kind === 'sticky' ? (layer.fill ?? '#fef08a') : layer.textBackground;
200
+ ctx.fillStyle =
201
+ layer.kind === 'sticky' ? (layer.fill ?? '#fef08a') : layer.textBackground;
200
202
  const r = layer.borderRadius ?? (layer.kind === 'sticky' ? 4 : 0);
201
203
  ctx.beginPath();
202
204
  if (r > 0 && typeof ctx.roundRect === 'function')
@@ -212,7 +214,8 @@ function drawText(ctx, layer) {
212
214
  ctx.font = `${style} ${weight} ${size}px ${family}`;
213
215
  ctx.fillStyle = layer.color ?? (layer.kind === 'sticky' ? '#713f12' : '#0f172a');
214
216
  ctx.textBaseline = 'middle';
215
- ctx.textAlign = layer.textAlign === 'center' ? 'center' : layer.textAlign === 'right' ? 'right' : 'left';
217
+ ctx.textAlign =
218
+ layer.textAlign === 'center' ? 'center' : layer.textAlign === 'right' ? 'right' : 'left';
216
219
  const pad = 8;
217
220
  const tx = layer.textAlign === 'center' ? x + w / 2 : layer.textAlign === 'right' ? x + w - pad : x + pad;
218
221
  const text = layer.text ?? (layer.kind === 'sticky' ? 'Note' : 'Text');
@@ -276,36 +279,23 @@ async function drawLayer(ctx, layer, byId, absMap) {
276
279
  ctx.shadowColor = layer.shadowColor ?? 'rgba(0,0,0,0.35)';
277
280
  ctx.shadowOffsetY = Math.round(layer.shadowBlur / 3);
278
281
  }
279
- if (layer.blur) {
280
- ctx.filter = `blur(${layer.blur}px)`;
281
- }
282
+ const filter = canvasLayerFilter(layer);
283
+ if (filter)
284
+ ctx.filter = filter;
282
285
  if ((layer.kind === 'image' || layer.kind === 'video') && layer.src) {
283
286
  try {
284
287
  const img = await loadImage(layer.src);
285
288
  const fit = layer.objectFit ?? 'cover';
286
- if (layer.borderRadius) {
287
- ctx.beginPath();
288
- if (typeof ctx.roundRect === 'function') {
289
- ctx.roundRect(x, y, w, h, layer.borderRadius);
290
- }
291
- else {
292
- ctx.rect(x, y, w, h);
293
- }
294
- ctx.clip();
295
- }
296
- if (fit === 'fill') {
297
- ctx.drawImage(img, x, y, w, h);
289
+ ctx.beginPath();
290
+ if (layer.borderRadius && typeof ctx.roundRect === 'function') {
291
+ ctx.roundRect(x, y, w, h, layer.borderRadius);
298
292
  }
299
293
  else {
300
- const scale = fit === 'contain'
301
- ? Math.min(w / img.naturalWidth, h / img.naturalHeight)
302
- : Math.max(w / img.naturalWidth, h / img.naturalHeight);
303
- const dw = img.naturalWidth * scale;
304
- const dh = img.naturalHeight * scale;
305
- const dx = x + (w - dw) / 2;
306
- const dy = y + (h - dh) / 2;
307
- ctx.drawImage(img, dx, dy, dw, dh);
294
+ ctx.rect(x, y, w, h);
308
295
  }
296
+ ctx.clip();
297
+ const placed = mediaContentBox({ w, h }, { w: img.naturalWidth, h: img.naturalHeight }, fit, layer.mediaScale ?? 1, layer.mediaX ?? 0.5, layer.mediaY ?? 0.5);
298
+ ctx.drawImage(img, x + placed.x, y + placed.y, placed.w, placed.h);
309
299
  }
310
300
  catch {
311
301
  ctx.fillStyle = '#e2e8f0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/components",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "private": false,
5
5
  "description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
6
6
  "license": "MIT",