fika-editor 3.5.10 → 3.5.11

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.
@@ -100,7 +100,7 @@ function bodyColumns(boxes, from) {
100
100
  }
101
101
  function scalePixels(html, scale) {
102
102
  // CSS lengths only: do not rewrite lesson text containing quantities in px.
103
- return html.replace(/style=(['"])(.*?)\1/gi, (_, quote, css) => `style=${quote}${css.replace(/(-?\d+(?:\.\d+)?)px\b/g, (_m, n) => `${Number((Number(n) * scale).toFixed(4))}px`)}${quote}`);
103
+ return html.replace(/style=(['"])(.*?)\1/gi, (_, quote, css) => `style=${quote}${css.replace(/(-?\d+(?:\.\d+)?)(px|pt)\b/gi, (_m, n, unit) => `${Number(n) * scale}${unit}`)}${quote}`);
104
104
  }
105
105
  function scaleNumber(record, key, scale) {
106
106
  const obj = record;
@@ -129,6 +129,9 @@ function scaleTypography(el, scale) {
129
129
  cell.text = scalePixels(cell.text, scale);
130
130
  if (cell.style?.fontsize)
131
131
  cell.style.fontsize = cell.style.fontsize.replace(/^(\d+(?:\.\d+)?)(px|pt)$/i, (_, value, unit) => `${Number(value) * scale}${unit}`);
132
+ if (cell.style)
133
+ for (const key of ['borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth'])
134
+ scaleNumber(cell.style, key, scale);
132
135
  }
133
136
  }
134
137
  if (el.type === 'chart')
@@ -137,12 +140,97 @@ function scaleTypography(el, scale) {
137
140
  el.fontSize *= scale;
138
141
  if (el.type === 'latex')
139
142
  el.strokeWidth *= scale;
140
- if ('outline' in el && el.outline)
143
+ if ('outline' in el && el.outline) {
141
144
  scaleNumber(el.outline, 'width', scale);
145
+ if ((el.outline.radius ?? 0) > 1)
146
+ scaleNumber(el.outline, 'radius', scale);
147
+ }
142
148
  if ('shadow' in el && el.shadow)
143
149
  for (const key of ['h', 'v', 'blur'])
144
150
  scaleNumber(el.shadow, key, scale);
145
151
  }
152
+ /** Change document units with one factor. No reflow, rounding of geometry, or
153
+ * independent text-box constraints: every distance keeps the same proportion.
154
+ */
155
+ export function scaleDeckSlides(slides, factor) {
156
+ if (!Number.isFinite(factor) || factor <= 0)
157
+ throw new Error('Scale must be finite and positive.');
158
+ const result = structuredClone(slides);
159
+ for (const slide of result) {
160
+ if (slide.guides)
161
+ for (const guide of slide.guides)
162
+ guide.position *= factor;
163
+ for (const el of slide.elements) {
164
+ el.left *= factor;
165
+ el.top *= factor;
166
+ el.width *= factor;
167
+ if (el.type === 'line') {
168
+ const point = (p) => [p[0] * factor, p[1] * factor];
169
+ el.start = point(el.start);
170
+ el.end = point(el.end);
171
+ if (el.broken)
172
+ el.broken = point(el.broken);
173
+ if (el.broken2)
174
+ el.broken2 = point(el.broken2);
175
+ if (el.curve)
176
+ el.curve = point(el.curve);
177
+ if (el.cubic)
178
+ el.cubic = [point(el.cubic[0]), point(el.cubic[1])];
179
+ }
180
+ else
181
+ el.height *= factor;
182
+ scaleTypography(el, factor);
183
+ if ('radius' in el)
184
+ scaleNumber(el, 'radius', factor);
185
+ }
186
+ }
187
+ return result;
188
+ }
189
+ /** Smallest authored font in editable text, table cells, charts and code. */
190
+ export function minimumDeckFontSize(slides) {
191
+ const sizes = [];
192
+ const add = (n) => { if (Number.isFinite(n) && n > 0)
193
+ sizes.push(n); };
194
+ const cssSize = (value) => {
195
+ const match = /^([\d.]+)(px|pt)?$/i.exec(value.trim());
196
+ if (match)
197
+ add(Number(match[1]) * (match[2]?.toLowerCase() === 'pt' ? 4 / 3 : 1));
198
+ };
199
+ const html = (content, fallback = 16) => {
200
+ if (!content.replace(/<[^>]*>/g, '').trim())
201
+ return;
202
+ let found = false;
203
+ for (const attribute of content.matchAll(/style=(['"])(.*?)\1/gi)) {
204
+ for (const declaration of attribute[2].matchAll(/(?:^|;)\s*font-size\s*:\s*([\d.]+(?:px|pt)?)/gi)) {
205
+ cssSize(declaration[1]);
206
+ found = true;
207
+ }
208
+ }
209
+ if (!found)
210
+ add(fallback);
211
+ };
212
+ for (const slide of slides)
213
+ for (const el of slide.elements) {
214
+ if (el.type === 'text')
215
+ html(el.content);
216
+ if (el.type === 'shape' && el.text)
217
+ html(el.text.content);
218
+ if (el.type === 'table')
219
+ for (const row of el.data)
220
+ for (const cell of row) {
221
+ if (!cell.text?.trim())
222
+ continue;
223
+ if (cell.style?.fontsize)
224
+ cssSize(cell.style.fontsize);
225
+ html(cell.text, parseFloat(cell.style?.fontsize ?? '16') * (/pt$/i.test(cell.style?.fontsize ?? '') ? 4 / 3 : 1));
226
+ }
227
+ if (el.type === 'chart')
228
+ add(el.options?.fontSize ?? 12);
229
+ if (el.type === 'code')
230
+ add(el.fontSize);
231
+ }
232
+ return sizes.length ? Math.min(...sizes) : undefined;
233
+ }
146
234
  /** Resize a deck without distorting media or changing reading order.
147
235
  * Uniformly scale content and typography, redistribute available space through
148
236
  * empty tracks, and keep decorative edge shapes attached to their canvas edge.
@@ -156,6 +244,9 @@ export function resizeDeckSlides(slides, from, to) {
156
244
  const result = structuredClone(slides);
157
245
  if (from.width === to.width && from.height === to.height)
158
246
  return result;
247
+ const factor = to.width / from.width;
248
+ if (Math.abs(to.height / from.height - factor) < 1e-9)
249
+ return scaleDeckSlides(slides, factor);
159
250
  for (const slide of result) {
160
251
  // Guides describe page coordinates; resize them proportionally along their own axis.
161
252
  if (slide.guides)
@@ -19,6 +19,8 @@ export type FikaCommandType = FikaKnownCommandType | (string & {});
19
19
  export interface FikaDeckViewport {
20
20
  size: number;
21
21
  ratio: number;
22
+ /** Physical page width for export. Legacy decks default to ten inches. */
23
+ widthInches?: number;
22
24
  }
23
25
  export type FikaSlideThemePatch = Omit<Partial<SlideTheme>, 'outline' | 'shadow'> & {
24
26
  outline?: Partial<SlideTheme['outline']>;
@@ -7,6 +7,7 @@ export interface PresentationExportState {
7
7
  theme: SlideTheme;
8
8
  viewportRatio: number;
9
9
  viewportSize: number;
10
+ viewportWidthInches?: number;
10
11
  title: string;
11
12
  }
12
13
  export interface PresentationExportOptions {
@@ -16,7 +17,7 @@ export interface PresentationExportOptions {
16
17
  mediaResolver?: FikaExportMediaResolver | null;
17
18
  watermark?: FikaExportWatermarkResolver | null;
18
19
  }
19
- export declare function createPresentationExporter({ slides, theme, viewportRatio, title, viewportSize }: PresentationExportState, options?: PresentationExportOptions, job?: import("../utils/jobProgress").JobProgress): {
20
+ export declare function createPresentationExporter({ slides, theme, viewportRatio, title, viewportSize, viewportWidthInches }: PresentationExportState, options?: PresentationExportOptions, job?: import("../utils/jobProgress").JobProgress): {
20
21
  exporting: boolean;
21
22
  exportProgress: number;
22
23
  exportSlide: number;
@@ -25,6 +25,7 @@ export interface SlidesState {
25
25
  slideIndex: number;
26
26
  viewportSize: number;
27
27
  viewportRatio: number;
28
+ viewportWidthInches: number | undefined;
28
29
  templates: SlideTemplate[];
29
30
  importedTemplates: ImportedSlideTemplate[];
30
31
  /** Used for newly added slides after "Use on every slide". Defaults to Rise. */
@@ -35,6 +36,7 @@ export interface SlidesActions {
35
36
  setTheme: (themeProps: Partial<SlideTheme>) => void;
36
37
  setViewportSize: (size: number) => void;
37
38
  setViewportRatio: (viewportRatio: number) => void;
39
+ setViewportWidthInches: (width: number | undefined) => void;
38
40
  setSlides: (slides: Slide[], themeProps?: Partial<SlideTheme>, options?: {
39
41
  clone?: boolean;
40
42
  }) => void;
@@ -938,6 +940,7 @@ export declare const useSlidesStore: import("zustand").UseBoundStore<Omit<import
938
940
  slideIndex: number;
939
941
  viewportSize: number;
940
942
  viewportRatio: number;
943
+ viewportWidthInches: number | undefined;
941
944
  templates: {
942
945
  name: string;
943
946
  id: string;
@@ -1803,6 +1806,7 @@ export declare const useSlidesStore: import("zustand").UseBoundStore<Omit<import
1803
1806
  setTheme: (themeProps: Partial<SlideTheme>) => void;
1804
1807
  setViewportSize: (size: number) => void;
1805
1808
  setViewportRatio: (viewportRatio: number) => void;
1809
+ setViewportWidthInches: (width: number | undefined) => void;
1806
1810
  setSlides: (slides: Slide[], themeProps?: Partial<SlideTheme>, options?: {
1807
1811
  clone?: boolean;
1808
1812
  }) => void;
@@ -2689,6 +2693,7 @@ export declare const useSlidesStore: import("zustand").UseBoundStore<Omit<import
2689
2693
  slideIndex: number;
2690
2694
  viewportSize: number;
2691
2695
  viewportRatio: number;
2696
+ viewportWidthInches: number | undefined;
2692
2697
  templates: {
2693
2698
  name: string;
2694
2699
  id: string;
@@ -3554,6 +3559,7 @@ export declare const useSlidesStore: import("zustand").UseBoundStore<Omit<import
3554
3559
  setTheme: (themeProps: Partial<SlideTheme>) => void;
3555
3560
  setViewportSize: (size: number) => void;
3556
3561
  setViewportRatio: (viewportRatio: number) => void;
3562
+ setViewportWidthInches: (width: number | undefined) => void;
3557
3563
  setSlides: (slides: Slide[], themeProps?: Partial<SlideTheme>, options?: {
3558
3564
  clone?: boolean;
3559
3565
  }) => void;
@@ -12,6 +12,7 @@ export interface Snapshot {
12
12
  theme?: SlideTheme;
13
13
  viewportSize?: number;
14
14
  viewportRatio?: number;
15
+ viewportWidthInches?: number;
15
16
  templates?: SlideTemplate[];
16
17
  slides?: Slide[];
17
18
  patches?: Patch[];
@@ -11,6 +11,7 @@ export interface SourcePackageDocument {
11
11
  theme: unknown;
12
12
  viewportSize: number;
13
13
  viewportRatio: number;
14
+ viewportWidthInches?: number;
14
15
  }
15
16
  /** Certify only a fully applied import; retaining bytes alone is not sufficient. */
16
17
  export declare function certifySourcePackageDocument(packageId: string, document: SourcePackageDocument): void;
@@ -3,6 +3,12 @@ export interface SlideCanvas {
3
3
  width: number;
4
4
  height: number;
5
5
  }
6
+ /** Change document units with one factor. No reflow, rounding of geometry, or
7
+ * independent text-box constraints: every distance keeps the same proportion.
8
+ */
9
+ export declare function scaleDeckSlides(slides: readonly Slide[], factor: number): Slide[];
10
+ /** Smallest authored font in editable text, table cells, charts and code. */
11
+ export declare function minimumDeckFontSize(slides: readonly Slide[]): number | undefined;
6
12
  /** Resize a deck without distorting media or changing reading order.
7
13
  * Uniformly scale content and typography, redistribute available space through
8
14
  * empty tracks, and keep decorative edge shapes attached to their canvas edge.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fika-editor",
3
- "version": "3.5.10",
3
+ "version": "3.5.11",
4
4
  "description": "Fika presentation editor embed bundle with a typed agentic bridge.",
5
5
  "type": "module",
6
6
  "main": "dist/embed/fika-embed.js",