@widgetic/canvas 0.5.17 → 0.5.19

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 (49) hide show
  1. package/README.md +110 -0
  2. package/dist/canvas/Canvas.svelte +190 -55
  3. package/dist/canvas/Canvas.svelte.d.ts +6 -0
  4. package/dist/canvas/CanvasToolbar.svelte +146 -178
  5. package/dist/canvas/CanvasToolbar.svelte.d.ts +2 -2
  6. package/dist/canvas/ContextMenu.svelte +52 -28
  7. package/dist/canvas/PanZoomPanel.svelte +32 -23
  8. package/dist/canvas/WidgetSelectionLayer.svelte +1 -1
  9. package/dist/canvas/eventScope.d.ts +56 -0
  10. package/dist/canvas/eventScope.js +89 -0
  11. package/dist/canvas/props-panel/PropsPanel.svelte +117 -146
  12. package/dist/canvas/props-panel/TextPropsICSection.svelte +18 -14
  13. package/dist/canvas/shadowRootText.d.ts +5 -0
  14. package/dist/canvas/shadowRootText.js +43 -0
  15. package/dist/canvas/shapes/FrameShape.js +4 -2
  16. package/dist/canvas/shapes/ImageShape.js +9 -11
  17. package/dist/canvas/shapes/ShapeLibrary.d.ts +3 -1
  18. package/dist/canvas/shapes/ShapeLibrary.js +26 -26
  19. package/dist/canvas/shapes/WidgetShape.js +6 -3
  20. package/dist/canvas/widgetPreviewGeometry.js +5 -8
  21. package/dist/components/Tooltip.svelte +5 -2
  22. package/dist/components/index.d.ts +3 -0
  23. package/dist/components/index.js +4 -0
  24. package/dist/components/input-controls/ColorIC.svelte +15 -10
  25. package/dist/components/input-controls/ColorIC.svelte.d.ts +1 -1
  26. package/dist/components/input-controls/FontSelectorIC.svelte +12 -3
  27. package/dist/components/input-controls/SliderUnitIC.svelte +21 -7
  28. package/dist/components/input-controls/SliderUnitIC.svelte.d.ts +1 -1
  29. package/dist/components/input-controls/TextAlignIC.svelte +10 -5
  30. package/dist/components/input-controls/TextStyleIC.svelte +11 -7
  31. package/dist/components/preferenceStorage.d.ts +14 -0
  32. package/dist/components/preferenceStorage.js +25 -0
  33. package/dist/i18n/index.d.ts +2 -0
  34. package/dist/i18n/index.js +2 -0
  35. package/dist/i18n/labels.d.ts +23 -0
  36. package/dist/i18n/labels.js +75 -0
  37. package/dist/i18n/language.d.ts +23 -0
  38. package/dist/i18n/language.js +33 -0
  39. package/dist/i18n/messages.d.ts +277 -0
  40. package/dist/i18n/messages.js +292 -0
  41. package/dist/i18n/shapeWords.d.ts +30 -0
  42. package/dist/i18n/shapeWords.js +36 -0
  43. package/dist/i18n/shortcuts.d.ts +52 -0
  44. package/dist/i18n/shortcuts.js +104 -0
  45. package/dist/i18n/slots.d.ts +20 -0
  46. package/dist/i18n/slots.js +40 -0
  47. package/dist/index.d.ts +4 -0
  48. package/dist/index.js +5 -0
  49. package/package.json +11 -2
@@ -1,5 +1,10 @@
1
1
  <script lang="ts">
2
2
  import { onMount } from 'svelte';
3
+ import { getCanvasPreferenceStorage } from '../preferenceStorage';
4
+ import { useCanvasLanguage } from '../../i18n/language.js';
5
+
6
+ // The words of the control, in the language of the canvas it is on (English when it is used on its own)
7
+ const { t } = useCanvasLanguage();
3
8
 
4
9
  let className = '';
5
10
  export { className as class };
@@ -8,8 +13,8 @@
8
13
  // Current color value
9
14
  export let value: string = '#000000';
10
15
 
11
- // Label for the color picker
12
- export let label: string = 'Color';
16
+ // Label for the color picker. Without one it says "Color", in the page's language.
17
+ export let label: string | null = null;
13
18
 
14
19
  // Callback when color changes
15
20
  export let onChange: (color: string) => void = () => {};
@@ -94,10 +99,10 @@
94
99
  return `#${toHex(r)}${toHex(g)}${toHex(b)}`.toUpperCase();
95
100
  }
96
101
 
97
- // Load custom presets from localStorage on mount
102
+ // Load custom presets from the preference store (localStorage unless the host installed another) on mount
98
103
  onMount(() => {
99
104
  try {
100
- const stored = localStorage.getItem(PRESETS_STORAGE_KEY);
105
+ const stored = getCanvasPreferenceStorage()?.getItem(PRESETS_STORAGE_KEY);
101
106
  if (stored) {
102
107
  customPresets = JSON.parse(stored);
103
108
  }
@@ -106,10 +111,10 @@
106
111
  }
107
112
  });
108
113
 
109
- // Save custom presets to localStorage
114
+ // Save custom presets to the preference store
110
115
  function saveCustomPresets() {
111
116
  try {
112
- localStorage.setItem(PRESETS_STORAGE_KEY, JSON.stringify(customPresets));
117
+ getCanvasPreferenceStorage()?.setItem(PRESETS_STORAGE_KEY, JSON.stringify(customPresets));
113
118
  } catch (e) {
114
119
  console.warn('ColorPicker: Failed to save custom presets', e);
115
120
  }
@@ -197,7 +202,7 @@
197
202
  </script>
198
203
 
199
204
  <div class="{className ? className + ' ' : ''}color-picker-component" style={style}>
200
- <span class="prop-label">{label}</span>
205
+ <span class="prop-label">{label ?? $t('canvas.control.color')}</span>
201
206
 
202
207
  {#if showPicker}
203
208
  <div class="color-input-row">
@@ -207,7 +212,7 @@
207
212
  oninput={handleColorPickerInput}
208
213
  onchange={handleColorPickerChange}
209
214
  class="color-swatch"
210
- title="Open color picker"
215
+ title={$t('canvas.control.openPicker')}
211
216
  />
212
217
  <input
213
218
  type="text"
@@ -235,7 +240,7 @@
235
240
  {#if !presets && isCustomPreset(color)}
236
241
  <button
237
242
  class="delete-btn"
238
- title="Remove color"
243
+ title={$t('canvas.control.removeColor')}
239
244
  onclick={(e) => handleDeletePreset(e, color)}
240
245
  >×</button>
241
246
  {/if}
@@ -360,7 +365,7 @@
360
365
  .delete-btn {
361
366
  position: absolute;
362
367
  top: -4px;
363
- right: -4px;
368
+ inset-inline-end: -4px;
364
369
  width: 14px;
365
370
  height: 14px;
366
371
  padding: 0;
@@ -4,7 +4,7 @@ declare const __propDef: {
4
4
  class?: string;
5
5
  style?: string;
6
6
  value?: string;
7
- label?: string;
7
+ label?: string | null;
8
8
  onChange?: (color: string) => void;
9
9
  presets?: string[] | null;
10
10
  showPicker?: boolean;
@@ -1,4 +1,8 @@
1
1
  <script lang="ts">
2
+ import { useCanvasLanguage } from '../../i18n/language.js';
3
+
4
+ // The words of the control, in the language of the canvas it is on (English when it is used on its own)
5
+ const { t } = useCanvasLanguage();
2
6
  // Font Selector Input Controller - Reusable component
3
7
  export let value: string = 'Arial';
4
8
  export let onChange: (family: string) => void = () => {};
@@ -16,7 +20,7 @@
16
20
  </script>
17
21
 
18
22
  <div class="font-selector-ic">
19
- <span class="label">Font Family</span>
23
+ <span class="label">{$t('canvas.control.fontFamily')}</span>
20
24
  <select
21
25
  class="font-select"
22
26
  {value}
@@ -53,8 +57,13 @@
53
57
  appearance: none;
54
58
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
55
59
  background-repeat: no-repeat;
56
- background-position: right 12px center;
57
- padding-right: 32px;
60
+ background-position: right 12px center; /* rtl-ok: the arrow is at the end of the line, which is the right edge; the rule below moves it on a right to left screen */
61
+ padding-inline-end: 32px;
62
+ }
63
+
64
+ /* The arrow of the list is at the end of the line: the left edge on a right to left screen. */
65
+ .font-select:dir(rtl) {
66
+ background-position: left 12px center; /* rtl-ok: the end of a right to left line */
58
67
  }
59
68
 
60
69
  .font-select:hover {
@@ -1,4 +1,8 @@
1
1
  <script lang="ts">
2
+ import { useCanvasLanguage } from '../../i18n/language.js';
3
+
4
+ // The words of the control, in the language of the canvas it is on (English when it is used on its own)
5
+ const { t } = useCanvasLanguage();
2
6
  let className = '';
3
7
  export { className as class };
4
8
  export let style = '';
@@ -6,8 +10,8 @@
6
10
  // Current value
7
11
  export let value: number = 0;
8
12
 
9
- // Label for the slider
10
- export let label: string = 'Value';
13
+ // Label for the slider. Without one it says "Value", in the page's language.
14
+ export let label: string | null = null;
11
15
 
12
16
  // Min/max/step for the slider
13
17
  export let min: number = 0;
@@ -73,7 +77,7 @@
73
77
  </script>
74
78
 
75
79
  <div class="{className ? className + ' ' : ''}slider-input-component" style={style}>
76
- <span class="prop-label">{label}</span>
80
+ <span class="prop-label">{label ?? $t('canvas.control.value')}</span>
77
81
 
78
82
  <div class="slider-row">
79
83
  <input
@@ -133,6 +137,13 @@
133
137
  padding: 9px 0;
134
138
  box-sizing: content-box;
135
139
  margin: 0;
140
+ /* The fill starts where the track starts: at the left, and at the right on a right to left screen, where the browser
141
+ puts the smallest value. */
142
+ --fill-direction: to right;
143
+ }
144
+
145
+ .slider:dir(rtl) {
146
+ --fill-direction: to left;
136
147
  }
137
148
 
138
149
  /* Track with rounded ends and progress fill */
@@ -140,7 +151,7 @@
140
151
  height: 8px;
141
152
  border-radius: 4px;
142
153
  background: linear-gradient(
143
- to right,
154
+ var(--fill-direction),
144
155
  var(--accent, #314F2F) 0%,
145
156
  var(--accent, #314F2F) var(--progress, 0%),
146
157
  #e5e7eb var(--progress, 0%),
@@ -158,7 +169,9 @@
158
169
  /* Firefox progress fill */
159
170
  .slider::-moz-range-progress {
160
171
  height: 8px;
161
- border-radius: 4px 0 0 4px;
172
+ border-radius: 4px;
173
+ border-start-end-radius: 0;
174
+ border-end-end-radius: 0;
162
175
  background: var(--accent, #314F2F);
163
176
  }
164
177
 
@@ -196,7 +209,7 @@
196
209
  padding: 4px 6px;
197
210
  border: none;
198
211
  font-size: 12px;
199
- text-align: right;
212
+ text-align: end;
200
213
  outline: none;
201
214
  }
202
215
 
@@ -209,7 +222,8 @@
209
222
  }
210
223
 
211
224
  .unit {
212
- padding: 4px 6px 4px 0;
225
+ padding: 4px 0;
226
+ padding-inline-end: 6px;
213
227
  font-size: 11px;
214
228
  color: #6b7280;
215
229
  background: white;
@@ -4,7 +4,7 @@ declare const __propDef: {
4
4
  class?: string;
5
5
  style?: string;
6
6
  value?: number;
7
- label?: string;
7
+ label?: string | null;
8
8
  min?: number;
9
9
  max?: number;
10
10
  step?: number;
@@ -1,16 +1,21 @@
1
1
  <script lang="ts">
2
+ import { useCanvasLanguage } from '../../i18n/language.js';
3
+
4
+ // The words of the control, in the language of the canvas it is on (English when it is used on its own)
5
+ const { t } = useCanvasLanguage();
2
6
  // Text Align Input Controller - Reusable component
3
7
  export let value: 'left' | 'center' | 'right' = 'left';
4
8
  export let onChange: (align: 'left' | 'center' | 'right') => void = () => {};
5
9
  </script>
6
10
 
7
11
  <div class="text-align-ic">
8
- <span class="label">Text Align</span>
9
- <div class="buttons">
12
+ <span class="label">{$t('canvas.control.textAlign')}</span>
13
+ <!-- The buttons draw a side (left, centre, right) of the text box, so they keep their order on every screen. -->
14
+ <div class="buttons" dir="ltr">
10
15
  <button
11
16
  class="align-btn {value === 'left' ? 'active' : ''}"
12
17
  onclick={() => onChange('left')}
13
- title="Align Left"
18
+ title={$t('canvas.control.alignLeft')}
14
19
  >
15
20
  <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
16
21
  <path d="M3 3h18v2H3V3zm0 4h12v2H3V7zm0 4h18v2H3v-2zm0 4h12v2H3v-2zm0 4h18v2H3v-2z"/>
@@ -19,7 +24,7 @@
19
24
  <button
20
25
  class="align-btn {value === 'center' ? 'active' : ''}"
21
26
  onclick={() => onChange('center')}
22
- title="Align Center"
27
+ title={$t('canvas.control.alignCenter')}
23
28
  >
24
29
  <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
25
30
  <path d="M3 3h18v2H3V3zm3 4h12v2H6V7zm-3 4h18v2H3v-2zm3 4h12v2H6v-2zm-3 4h18v2H3v-2z"/>
@@ -28,7 +33,7 @@
28
33
  <button
29
34
  class="align-btn {value === 'right' ? 'active' : ''}"
30
35
  onclick={() => onChange('right')}
31
- title="Align Right"
36
+ title={$t('canvas.control.alignRight')}
32
37
  >
33
38
  <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
34
39
  <path d="M3 3h18v2H3V3zm6 4h12v2H9V7zm-6 4h18v2H3v-2zm6 4h12v2H9v-2zm-6 4h18v2H3v-2z"/>
@@ -1,4 +1,8 @@
1
1
  <script lang="ts">
2
+ import { useCanvasLanguage } from '../../i18n/language.js';
3
+
4
+ // The words of the control, in the language of the canvas it is on (English when it is used on its own)
5
+ const { t } = useCanvasLanguage();
2
6
  // Text Style Input Controller - Reusable component for Bold, Italic, Underline
3
7
  export let fontWeight: 'normal' | 'bold' = 'normal';
4
8
  export let fontStyle: 'normal' | 'italic' = 'normal';
@@ -10,28 +14,28 @@
10
14
  </script>
11
15
 
12
16
  <div class="text-style-ic">
13
- <span class="label">Text Style</span>
17
+ <span class="label">{$t('canvas.control.textStyle')}</span>
14
18
  <div class="buttons">
15
19
  <button
16
20
  class="style-btn {fontWeight === 'bold' ? 'active' : ''}"
17
21
  onclick={() => onFontWeightChange(fontWeight === 'bold' ? 'normal' : 'bold')}
18
- title="Bold"
22
+ title={$t('canvas.control.bold')}
19
23
  >
20
- <strong>B</strong>
24
+ <strong>{$t('canvas.control.boldMark')}</strong>
21
25
  </button>
22
26
  <button
23
27
  class="style-btn {fontStyle === 'italic' ? 'active' : ''}"
24
28
  onclick={() => onFontStyleChange(fontStyle === 'italic' ? 'normal' : 'italic')}
25
- title="Italic"
29
+ title={$t('canvas.control.italic')}
26
30
  >
27
- <em>I</em>
31
+ <em>{$t('canvas.control.italicMark')}</em>
28
32
  </button>
29
33
  <button
30
34
  class="style-btn {underline ? 'active' : ''}"
31
35
  onclick={() => onUnderlineChange(!underline)}
32
- title="Underline"
36
+ title={$t('canvas.control.underline')}
33
37
  >
34
- <u>U</u>
38
+ <u>{$t('canvas.control.underlineMark')}</u>
35
39
  </button>
36
40
  </div>
37
41
  </div>
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Where the canvas keeps the choices of the person using it (the custom colors they saved in a color picker).
3
+ *
4
+ * By default that is the browser's `localStorage`, as it always was. A page that embeds the canvas for visitors who are
5
+ * not the page's owner (a partner's page, with the creator mounted in it) installs a store of its own, so that nothing
6
+ * is written into the page's storage and a browser that several visitors share does not pass one visitor's choices on
7
+ * to the next. The host does this once, before the canvas is shown.
8
+ */
9
+ /** The three calls the canvas makes on a store, so a stand-in only has to offer these. */
10
+ export type CanvasPreferenceStorage = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
11
+ /** Installs the store the canvas keeps the visitor's choices in; `null` goes back to the browser's `localStorage`. */
12
+ export declare function setCanvasPreferenceStorage(storage: CanvasPreferenceStorage | null): void;
13
+ /** The store to use now: the one the host installed, else `localStorage`, else nothing (where the browser blocks it). */
14
+ export declare function getCanvasPreferenceStorage(): CanvasPreferenceStorage | null;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Where the canvas keeps the choices of the person using it (the custom colors they saved in a color picker).
3
+ *
4
+ * By default that is the browser's `localStorage`, as it always was. A page that embeds the canvas for visitors who are
5
+ * not the page's owner (a partner's page, with the creator mounted in it) installs a store of its own, so that nothing
6
+ * is written into the page's storage and a browser that several visitors share does not pass one visitor's choices on
7
+ * to the next. The host does this once, before the canvas is shown.
8
+ */
9
+ let installedStorage = null;
10
+ /** Installs the store the canvas keeps the visitor's choices in; `null` goes back to the browser's `localStorage`. */
11
+ export function setCanvasPreferenceStorage(storage) {
12
+ installedStorage = storage;
13
+ }
14
+ /** The store to use now: the one the host installed, else `localStorage`, else nothing (where the browser blocks it). */
15
+ export function getCanvasPreferenceStorage() {
16
+ if (installedStorage)
17
+ return installedStorage;
18
+ try {
19
+ return typeof localStorage === 'undefined' ? null : localStorage;
20
+ }
21
+ catch {
22
+ // Reading `localStorage` itself throws where the browser blocks storage for the page.
23
+ return null;
24
+ }
25
+ }
@@ -0,0 +1,2 @@
1
+ export { CANVAS_MESSAGES, type CanvasMessageKey } from './messages.js';
2
+ export { checkCanvasMessages, provideCanvasLanguage, useCanvasLanguage } from './language.js';
@@ -0,0 +1,2 @@
1
+ export { CANVAS_MESSAGES } from './messages.js';
2
+ export { checkCanvasMessages, provideCanvasLanguage, useCanvasLanguage } from './language.js';
@@ -0,0 +1,23 @@
1
+ import type { Translate } from '@widgetic/design-system/i18n';
2
+ import type { CanvasMessageKey } from './messages.js';
3
+ type Translator = Translate<CanvasMessageKey>;
4
+ /**
5
+ * The hint of a button that has a key: its name and the key that does the same, "Draw (D)". A button with no key is
6
+ * just its name.
7
+ */
8
+ export declare function toolTitle(name: CanvasMessageKey, shortcut: string | null | undefined, t: Translator): string;
9
+ /** The name of a group of the shape library, by the English name the library keeps it under. */
10
+ export declare function categoryLabel(category: string, t: Translator): string;
11
+ /** What the properties panel needs to know about the selected object to name it. */
12
+ export interface NamedObject {
13
+ type?: string | null;
14
+ _customType?: string | null;
15
+ _isWidgetImage?: boolean | null;
16
+ _shapeKey?: string | null;
17
+ }
18
+ /**
19
+ * What the properties panel calls the selected object, in the page's language: "Frame", "Widget", "Star (Drawing)".
20
+ * A kind of object it has no name for is shown by the name the canvas library gave it.
21
+ */
22
+ export declare function displayTypeText(object: NamedObject | null | undefined, t: Translator): string;
23
+ export {};
@@ -0,0 +1,75 @@
1
+ import { getShapeByKey } from '../canvas/shapes/ShapeLibrary.js';
2
+ /**
3
+ * The hint of a button that has a key: its name and the key that does the same, "Draw (D)". A button with no key is
4
+ * just its name.
5
+ */
6
+ export function toolTitle(name, shortcut, t) {
7
+ const written = t(name);
8
+ return shortcut ? t('canvas.tool.withKey', { name: written, key: shortcut }) : written;
9
+ }
10
+ // The groups of the shape library are kept under their English names (a shape of a saved canvas knows its group by that
11
+ // name); this says each in the page's language.
12
+ const CATEGORY_KEYS = {
13
+ 'Geometric Shapes': 'canvas.category.geometric',
14
+ 'Arrow Shapes': 'canvas.category.arrows',
15
+ 'Media Icons': 'canvas.category.media',
16
+ 'UI Icons': 'canvas.category.ui',
17
+ 'Symbol Shapes': 'canvas.category.symbols'
18
+ };
19
+ /** The name of a group of the shape library, by the English name the library keeps it under. */
20
+ export function categoryLabel(category, t) {
21
+ // Only the table's own entries: a group called "constructor" is not a method of the table.
22
+ const key = Object.prototype.hasOwnProperty.call(CATEGORY_KEYS, category) ? CATEGORY_KEYS[category] : undefined;
23
+ return key ? t(key) : category;
24
+ }
25
+ // The kinds of object that have a name of their own, by the `type` the canvas library gives them.
26
+ const OBJECT_TYPE_KEYS = {
27
+ rect: 'canvas.tool.rectangle',
28
+ circle: 'canvas.tool.circle',
29
+ ellipse: 'canvas.tool.ellipse',
30
+ triangle: 'canvas.tool.triangle',
31
+ textbox: 'canvas.tool.text',
32
+ path: 'canvas.type.drawing',
33
+ line: 'canvas.type.line',
34
+ group: 'canvas.type.group',
35
+ activeSelection: 'canvas.type.selection',
36
+ activeselection: 'canvas.type.selection'
37
+ };
38
+ /**
39
+ * What the properties panel calls the selected object, in the page's language: "Frame", "Widget", "Star (Drawing)".
40
+ * A kind of object it has no name for is shown by the name the canvas library gave it.
41
+ */
42
+ export function displayTypeText(object, t) {
43
+ if (!object)
44
+ return t('canvas.type.none');
45
+ if (object._isWidgetImage)
46
+ return t('canvas.type.widget');
47
+ if (object._customType === 'frame')
48
+ return t('canvas.tool.frame');
49
+ if (object._customType === 'arrow')
50
+ return t('canvas.tool.arrow');
51
+ if (object._customType === 'triangle')
52
+ return t('canvas.tool.triangle');
53
+ if (object._customType === 'video')
54
+ return t('canvas.tool.video');
55
+ if (object._customType === 'image' || object.type === 'image')
56
+ return t('canvas.tool.image');
57
+ // A shape of the library is named by its entry there ("Star (Drawing)"). One the library does not know (an old save)
58
+ // is named after its key ("arrow-right" → "Arrow Right"), and one with no key at all is a custom shape.
59
+ if (object._customType === 'libraryShape') {
60
+ const shapeKey = object._shapeKey;
61
+ if (!shapeKey)
62
+ return t('canvas.type.customShape');
63
+ const known = getShapeByKey(shapeKey);
64
+ const name = known
65
+ ? t(known.labelKey)
66
+ : shapeKey
67
+ .split('-')
68
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
69
+ .join(' ');
70
+ return t('canvas.type.drawingOf', { name });
71
+ }
72
+ const type = object.type ?? '';
73
+ const key = Object.prototype.hasOwnProperty.call(OBJECT_TYPE_KEYS, type) ? OBJECT_TYPE_KEYS[type] : undefined;
74
+ return key ? t(key) : type;
75
+ }
@@ -0,0 +1,23 @@
1
+ import { type MessageOverrides, type MessageProblem } from '@widgetic/design-system/i18n';
2
+ /**
3
+ * Called by the root component of a canvas while it is created, so everything inside it speaks the page's language.
4
+ * It gives back the words as stores and `update(settings)` for when the page sets the language again.
5
+ */
6
+ export declare const provideCanvasLanguage: any;
7
+ /**
8
+ * Called by a part of the canvas while it is created. Gives its words as stores, so a part that is already on the screen
9
+ * changes when the page sets the language again. Outside a canvas (a part used on its own, such as the colour control)
10
+ * it speaks English.
11
+ */
12
+ export declare const useCanvasLanguage: any;
13
+ /**
14
+ * The English `t` of the canvas, for code that has no component around it. The screens of the canvas get their words, in
15
+ * the page's language, from `useCanvasLanguage`.
16
+ */
17
+ export declare const translateEnglish: any;
18
+ /**
19
+ * Checks a page's `messages` against the canvas's catalog without showing anything: a key that does not exist (with the
20
+ * nearest real one), a value that is not text, a template that does not parse, or one that asks for a value the message
21
+ * is never given. An empty list means every message will be used. For a test or a build step of the page.
22
+ */
23
+ export declare function checkCanvasMessages(messages: MessageOverrides): MessageProblem[];
@@ -0,0 +1,33 @@
1
+ import { createI18n, findMessageProblems } from '@widgetic/design-system/i18n';
2
+ import { CANVAS_MESSAGES } from './messages.js';
3
+ /**
4
+ * The language of a canvas on a page. `Canvas` is the root: it takes `locale` and `messages`, makes the language here, and
5
+ * everything on it (the toolbar, the zoom panel, the context menu, the properties panel and the words drawn onto the
6
+ * canvas) reads its words from it (`useCanvasLanguage`). The context belongs to one root, so two canvases on a page can
7
+ * speak two languages.
8
+ */
9
+ const canvasWords = createI18n({ catalog: CANVAS_MESSAGES, label: 'Canvas' });
10
+ /**
11
+ * Called by the root component of a canvas while it is created, so everything inside it speaks the page's language.
12
+ * It gives back the words as stores and `update(settings)` for when the page sets the language again.
13
+ */
14
+ export const provideCanvasLanguage = canvasWords.provideI18n;
15
+ /**
16
+ * Called by a part of the canvas while it is created. Gives its words as stores, so a part that is already on the screen
17
+ * changes when the page sets the language again. Outside a canvas (a part used on its own, such as the colour control)
18
+ * it speaks English.
19
+ */
20
+ export const useCanvasLanguage = canvasWords.useI18n;
21
+ /**
22
+ * The English `t` of the canvas, for code that has no component around it. The screens of the canvas get their words, in
23
+ * the page's language, from `useCanvasLanguage`.
24
+ */
25
+ export const translateEnglish = canvasWords.translateEnglish;
26
+ /**
27
+ * Checks a page's `messages` against the canvas's catalog without showing anything: a key that does not exist (with the
28
+ * nearest real one), a value that is not text, a template that does not parse, or one that asks for a value the message
29
+ * is never given. An empty list means every message will be used. For a test or a build step of the page.
30
+ */
31
+ export function checkCanvasMessages(messages) {
32
+ return findMessageProblems(CANVAS_MESSAGES, messages);
33
+ }