fika-editor 3.5.9 → 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;
@@ -1,25 +1,25 @@
1
1
  import type { Locales, TranslationFunctions } from './i18n-types';
2
2
  declare const TypesafeI18n: import("react").FunctionComponent<import("typesafe-i18n/react").TypesafeI18nProps<Locales>>, I18nContext: import("react").Context<import("typesafe-i18n/react").I18nContextType<Locales, {
3
- export: import("./i18n-types").NamespaceExportTranslation;
4
- components: import("./i18n-types").NamespaceComponentsTranslation;
5
- myna: import("./i18n-types").NamespaceMynaTranslation;
6
- mobile: import("./i18n-types").NamespaceMobileTranslation;
7
- editor: import("./i18n-types").NamespaceEditorTranslation;
8
3
  configs: import("./i18n-types").NamespaceConfigsTranslation;
9
- common: import("./i18n-types").NamespaceCommonTranslation;
4
+ mobile: import("./i18n-types").NamespaceMobileTranslation;
5
+ myna: import("./i18n-types").NamespaceMynaTranslation;
6
+ export: import("./i18n-types").NamespaceExportTranslation;
10
7
  canvas: import("./i18n-types").NamespaceCanvasTranslation;
8
+ common: import("./i18n-types").NamespaceCommonTranslation;
9
+ editor: import("./i18n-types").NamespaceEditorTranslation;
11
10
  screen: import("./i18n-types").NamespaceScreenTranslation;
11
+ components: import("./i18n-types").NamespaceComponentsTranslation;
12
12
  }, TranslationFunctions>>;
13
13
  export { TypesafeI18n, I18nContext };
14
14
  export declare function useI18nContext(): import("typesafe-i18n/react").I18nContextType<Locales, {
15
- export: import("./i18n-types").NamespaceExportTranslation;
16
- components: import("./i18n-types").NamespaceComponentsTranslation;
17
- myna: import("./i18n-types").NamespaceMynaTranslation;
18
- mobile: import("./i18n-types").NamespaceMobileTranslation;
19
- editor: import("./i18n-types").NamespaceEditorTranslation;
20
15
  configs: import("./i18n-types").NamespaceConfigsTranslation;
21
- common: import("./i18n-types").NamespaceCommonTranslation;
16
+ mobile: import("./i18n-types").NamespaceMobileTranslation;
17
+ myna: import("./i18n-types").NamespaceMynaTranslation;
18
+ export: import("./i18n-types").NamespaceExportTranslation;
22
19
  canvas: import("./i18n-types").NamespaceCanvasTranslation;
20
+ common: import("./i18n-types").NamespaceCommonTranslation;
21
+ editor: import("./i18n-types").NamespaceEditorTranslation;
23
22
  screen: import("./i18n-types").NamespaceScreenTranslation;
23
+ components: import("./i18n-types").NamespaceComponentsTranslation;
24
24
  }, TranslationFunctions>;
25
25
  export declare const useI18nReact: typeof useI18nContext;