@sealpixel/ui 1.0.0-rc.2 → 1.0.0-rc.21

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 (148) hide show
  1. package/LICENSE.md +2 -2
  2. package/README.md +1 -1
  3. package/dist/components/sealpixel-button.d.ts +0 -1
  4. package/dist/components/sealpixel-button.js +1 -1
  5. package/dist/components/sealpixel-button.js.map +1 -1
  6. package/dist/components/sealpixel-editor.d.ts +71 -20
  7. package/dist/components/sealpixel-editor.js +265 -57
  8. package/dist/components/sealpixel-editor.js.map +1 -1
  9. package/dist/components/sealpixel-nav.d.ts +0 -1
  10. package/dist/components/sealpixel-nav.js +1 -1
  11. package/dist/components/sealpixel-nav.js.map +1 -1
  12. package/dist/components/sealpixel-slider.d.ts +12 -17
  13. package/dist/components/sealpixel-slider.js +64 -10
  14. package/dist/components/sealpixel-slider.js.map +1 -1
  15. package/dist/components/sealpixel-stage.d.ts +17 -1
  16. package/dist/components/sealpixel-stage.js +57 -6
  17. package/dist/components/sealpixel-stage.js.map +1 -1
  18. package/dist/components/sealpixel-stepper.d.ts +0 -1
  19. package/dist/components/sealpixel-stepper.js +4 -4
  20. package/dist/components/sealpixel-stepper.js.map +1 -1
  21. package/dist/components/sealpixel-toolbar.d.ts +6 -2
  22. package/dist/components/sealpixel-toolbar.js +71 -5
  23. package/dist/components/sealpixel-toolbar.js.map +1 -1
  24. package/dist/controllers/gesture-controller.d.ts +5 -1
  25. package/dist/controllers/gesture-controller.js +24 -4
  26. package/dist/controllers/gesture-controller.js.map +1 -1
  27. package/dist/controllers/session-controller.d.ts +0 -1
  28. package/dist/controllers/session-controller.js +2 -0
  29. package/dist/controllers/session-controller.js.map +1 -1
  30. package/dist/define.d.ts +0 -1
  31. package/dist/define.js.map +1 -1
  32. package/dist/i18n.d.ts +0 -1
  33. package/dist/i18n.js.map +1 -1
  34. package/dist/icons.d.ts +1 -1
  35. package/dist/icons.js +1 -0
  36. package/dist/icons.js.map +1 -1
  37. package/dist/index.d.ts +1 -2
  38. package/dist/index.js +1 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/locales/de.d.ts +0 -1
  41. package/dist/locales/de.js +22 -0
  42. package/dist/locales/de.js.map +1 -1
  43. package/dist/locales/en.d.ts +0 -1
  44. package/dist/locales/en.js +22 -0
  45. package/dist/locales/en.js.map +1 -1
  46. package/dist/locales/es.d.ts +0 -1
  47. package/dist/locales/es.js +22 -0
  48. package/dist/locales/es.js.map +1 -1
  49. package/dist/locales/fr.d.ts +0 -1
  50. package/dist/locales/fr.js +22 -0
  51. package/dist/locales/fr.js.map +1 -1
  52. package/dist/locales/index.d.ts +0 -1
  53. package/dist/locales/index.js.map +1 -1
  54. package/dist/locales/ja.d.ts +0 -1
  55. package/dist/locales/ja.js +22 -0
  56. package/dist/locales/ja.js.map +1 -1
  57. package/dist/locales/pt.d.ts +0 -1
  58. package/dist/locales/pt.js +22 -0
  59. package/dist/locales/pt.js.map +1 -1
  60. package/dist/theme.d.ts +0 -1
  61. package/dist/theme.js.map +1 -1
  62. package/dist/tool.d.ts +12 -1
  63. package/dist/tool.js.map +1 -1
  64. package/dist/tools/annotate.d.ts +0 -1
  65. package/dist/tools/annotate.js +277 -28
  66. package/dist/tools/annotate.js.map +1 -1
  67. package/dist/tools/assist.d.ts +103 -0
  68. package/dist/tools/assist.js +361 -0
  69. package/dist/tools/assist.js.map +1 -0
  70. package/dist/tools/crop-mask.d.ts +0 -1
  71. package/dist/tools/crop-mask.js.map +1 -1
  72. package/dist/tools/crop-rotation.d.ts +64 -0
  73. package/dist/tools/crop-rotation.js +172 -0
  74. package/dist/tools/crop-rotation.js.map +1 -0
  75. package/dist/tools/crop.d.ts +0 -1
  76. package/dist/tools/crop.js +99 -15
  77. package/dist/tools/crop.js.map +1 -1
  78. package/dist/tools/delete-handle.d.ts +0 -1
  79. package/dist/tools/delete-handle.js +6 -0
  80. package/dist/tools/delete-handle.js.map +1 -1
  81. package/dist/tools/filter.d.ts +0 -1
  82. package/dist/tools/filter.js.map +1 -1
  83. package/dist/tools/finetune.d.ts +0 -1
  84. package/dist/tools/finetune.js.map +1 -1
  85. package/dist/tools/frame.d.ts +0 -1
  86. package/dist/tools/frame.js.map +1 -1
  87. package/dist/tools/handles.d.ts +26 -0
  88. package/dist/tools/handles.js +51 -0
  89. package/dist/tools/handles.js.map +1 -0
  90. package/dist/tools/index.d.ts +2 -2
  91. package/dist/tools/index.js +3 -1
  92. package/dist/tools/index.js.map +1 -1
  93. package/dist/tools/keys.d.ts +59 -0
  94. package/dist/tools/keys.js +120 -0
  95. package/dist/tools/keys.js.map +1 -0
  96. package/dist/tools/redact.d.ts +10 -1
  97. package/dist/tools/redact.js +176 -12
  98. package/dist/tools/redact.js.map +1 -1
  99. package/dist/tools/region-transform.d.ts +69 -0
  100. package/dist/tools/region-transform.js +192 -0
  101. package/dist/tools/region-transform.js.map +1 -0
  102. package/dist/tools/resize.d.ts +0 -1
  103. package/dist/tools/resize.js +19 -6
  104. package/dist/tools/resize.js.map +1 -1
  105. package/dist/tools/sticker.d.ts +0 -1
  106. package/dist/tools/sticker.js +57 -2
  107. package/dist/tools/sticker.js.map +1 -1
  108. package/dist/tools/watermark.d.ts +0 -1
  109. package/dist/tools/watermark.js.map +1 -1
  110. package/dist/view-mapping.d.ts +1 -2
  111. package/dist/view-mapping.js +1 -1
  112. package/dist/view-mapping.js.map +1 -1
  113. package/package.json +8 -8
  114. package/dist/components/sealpixel-button.d.ts.map +0 -1
  115. package/dist/components/sealpixel-editor.d.ts.map +0 -1
  116. package/dist/components/sealpixel-nav.d.ts.map +0 -1
  117. package/dist/components/sealpixel-slider.d.ts.map +0 -1
  118. package/dist/components/sealpixel-stage.d.ts.map +0 -1
  119. package/dist/components/sealpixel-stepper.d.ts.map +0 -1
  120. package/dist/components/sealpixel-toolbar.d.ts.map +0 -1
  121. package/dist/controllers/gesture-controller.d.ts.map +0 -1
  122. package/dist/controllers/session-controller.d.ts.map +0 -1
  123. package/dist/define.d.ts.map +0 -1
  124. package/dist/i18n.d.ts.map +0 -1
  125. package/dist/icons.d.ts.map +0 -1
  126. package/dist/index.d.ts.map +0 -1
  127. package/dist/locales/de.d.ts.map +0 -1
  128. package/dist/locales/en.d.ts.map +0 -1
  129. package/dist/locales/es.d.ts.map +0 -1
  130. package/dist/locales/fr.d.ts.map +0 -1
  131. package/dist/locales/index.d.ts.map +0 -1
  132. package/dist/locales/ja.d.ts.map +0 -1
  133. package/dist/locales/pt.d.ts.map +0 -1
  134. package/dist/theme.d.ts.map +0 -1
  135. package/dist/tool.d.ts.map +0 -1
  136. package/dist/tools/annotate.d.ts.map +0 -1
  137. package/dist/tools/crop-mask.d.ts.map +0 -1
  138. package/dist/tools/crop.d.ts.map +0 -1
  139. package/dist/tools/delete-handle.d.ts.map +0 -1
  140. package/dist/tools/filter.d.ts.map +0 -1
  141. package/dist/tools/finetune.d.ts.map +0 -1
  142. package/dist/tools/frame.d.ts.map +0 -1
  143. package/dist/tools/index.d.ts.map +0 -1
  144. package/dist/tools/redact.d.ts.map +0 -1
  145. package/dist/tools/resize.d.ts.map +0 -1
  146. package/dist/tools/sticker.d.ts.map +0 -1
  147. package/dist/tools/watermark.d.ts.map +0 -1
  148. package/dist/view-mapping.d.ts.map +0 -1
@@ -7,20 +7,22 @@ import { resolveLocale } from '../locales/index.js';
7
7
  import { base, tokens } from '../theme.js';
8
8
  import { toolsFor } from '../tools/index.js';
9
9
  /** `plugin-options='{"filter":{...}}'` attribute ↔ property. */
10
- const jsonAttribute = {
11
- fromAttribute: (value) => {
12
- if (value === null || value.trim() === '')
13
- return null;
14
- try {
15
- return JSON.parse(value);
16
- }
17
- catch {
18
- console.warn('[sealpixel] plugin-options is not valid JSON');
19
- return null;
20
- }
21
- },
22
- toAttribute: (value) => (value ? JSON.stringify(value) : null),
23
- };
10
+ function jsonAttribute(name) {
11
+ return {
12
+ fromAttribute: (value) => {
13
+ if (value === null || value.trim() === '')
14
+ return null;
15
+ try {
16
+ return JSON.parse(value);
17
+ }
18
+ catch {
19
+ console.warn(`[sealpixel] ${name} is not valid JSON`);
20
+ return null;
21
+ }
22
+ },
23
+ toAttribute: (value) => (value ? JSON.stringify(value) : null),
24
+ };
25
+ }
24
26
  /**
25
27
  * The default editor. Headless `EditorSession` underneath; this element adds
26
28
  * the responsive shell, tools and events.
@@ -28,6 +30,11 @@ const jsonAttribute = {
28
30
  * Events: `sealpixel:ready`, `sealpixel:load`, `sealpixel:change` ({ log, index }),
29
31
  * `sealpixel:process` (ExportResult), `sealpixel:error` (SealpixelError).
30
32
  */
33
+ /**
34
+ * What makes a settings bar worth its height: a control, or anything that
35
+ * draws. Plain `div`s are the tools' own scaffolding and never count.
36
+ */
37
+ const PANEL_CONTENT = 'select, input, textarea, button, img, svg, canvas, a, [role]';
31
38
  export class SealpixelEditor extends LitElement {
32
39
  static { this.styles = [
33
40
  tokens,
@@ -78,11 +85,18 @@ export class SealpixelEditor extends LitElement {
78
85
  border-top: 1px solid var(--sealpixel-color-border);
79
86
  padding: var(--sealpixel-space) calc(var(--sealpixel-space) * 1.5);
80
87
  /*
81
- * A fixed height, not a fitted one. A bar that grew and shrank as the
82
- * user moved between tools would resize the stage under them, and the
83
- * image would shift every time they changed their mind.
88
+ * The configured height, not a fitted one: a bar that grew and shrank
89
+ * as the user moved between tools would resize the stage under them,
90
+ * and the image would shift every time they changed their mind.
91
+ *
92
+ * The exception is a tool whose settings do not fit at all. Then the
93
+ * bar takes the height they need, measured by syncPanelFit(), because
94
+ * the alternative is worse: a fixed-height wrapping flex container has
95
+ * no scrollable cross-axis overflow, so nothing scrolls and the sticky
96
+ * choice row is pulled up over the settings. 34cqh caps both heights,
97
+ * so a busy tool can never take the stage on a short viewport.
84
98
  */
85
- height: min(34cqh, var(--sealpixel-panel-size));
99
+ height: min(34cqh, max(var(--sealpixel-panel-size), var(--sealpixel-panel-fit, 0px)));
86
100
  overflow: auto;
87
101
  /*
88
102
  * A bottom bar lays its blocks across the width and wraps, where the
@@ -104,6 +118,17 @@ export class SealpixelEditor extends LitElement {
104
118
  scrollbar-width: thin;
105
119
  scroll-behavior: smooth;
106
120
  }
121
+ /*
122
+ * A tool whose panel lays out to nothing gets no bar. Without this the
123
+ * fixed height above reserves an empty surface and takes it off the
124
+ * stage; see syncPanelFill(), which sets the attribute.
125
+ */
126
+ .panel[data-empty] {
127
+ height: 0;
128
+ padding: 0;
129
+ border-top: 0;
130
+ overflow: hidden;
131
+ }
107
132
  /*
108
133
  * A dial needs room to be worth dragging, but it must not grow into all
109
134
  * of it: a dial that stretches pushes the controls beside it against the
@@ -260,7 +285,7 @@ export class SealpixelEditor extends LitElement {
260
285
  padding: 0;
261
286
  min-height: 0;
262
287
  height: auto;
263
- font-size: 11px;
288
+ font-size: calc(var(--sealpixel-font-size) * 11 / 14);
264
289
  background: transparent;
265
290
  color: var(--sealpixel-color-fg-muted);
266
291
  }
@@ -416,7 +441,7 @@ export class SealpixelEditor extends LitElement {
416
441
  border: 1px solid var(--sealpixel-color-border);
417
442
  box-shadow: var(--sealpixel-shadow, 0 8px 24px rgba(0, 0, 0, 0.3));
418
443
  color: var(--sealpixel-color-fg);
419
- font-size: 13px;
444
+ font-size: calc(var(--sealpixel-font-size) * 13 / 14);
420
445
  white-space: nowrap;
421
446
  backdrop-filter: blur(8px);
422
447
  cursor: pointer;
@@ -459,9 +484,13 @@ export class SealpixelEditor extends LitElement {
459
484
  'toolbar panel' auto / var(--sealpixel-toolbar-size) 1fr;
460
485
  }
461
486
  .panel {
462
- height: var(--sealpixel-panel-size);
487
+ height: max(var(--sealpixel-panel-size), var(--sealpixel-panel-fit, 0px));
463
488
  padding: var(--sealpixel-space) calc(var(--sealpixel-space) * 2);
464
489
  }
490
+ .panel[data-empty] {
491
+ height: 0;
492
+ padding: 0;
493
+ }
465
494
  .toast {
466
495
  bottom: calc(var(--sealpixel-space) * 2);
467
496
  }
@@ -511,14 +540,14 @@ export class SealpixelEditor extends LitElement {
511
540
  /* The label names the control; it is not the thing being read. */
512
541
  .panel .field > span,
513
542
  .panel .field > .lab {
514
- font-size: 11px;
543
+ font-size: calc(var(--sealpixel-font-size) * 11 / 14);
515
544
  letter-spacing: 0.012em;
516
545
  line-height: 1.2;
517
546
  }
518
547
  .panel .hint {
519
548
  margin: 0;
520
549
  color: var(--sealpixel-color-fg-muted);
521
- font-size: 12px;
550
+ font-size: calc(var(--sealpixel-font-size) * 12 / 14);
522
551
  }
523
552
  /*
524
553
  * Width and height are one measurement, so they sit against the link that
@@ -614,7 +643,7 @@ export class SealpixelEditor extends LitElement {
614
643
  .panel input:not([type='checkbox']):not([type='color']),
615
644
  .panel select {
616
645
  font: inherit;
617
- font-size: 13px;
646
+ font-size: calc(var(--sealpixel-font-size) * 13 / 14);
618
647
  color: var(--sealpixel-color-fg);
619
648
  background: var(--sealpixel-color-surface-2);
620
649
  border: 1px solid transparent;
@@ -660,6 +689,36 @@ export class SealpixelEditor extends LitElement {
660
689
  background: var(--sealpixel-color-accent-soft, transparent);
661
690
  color: var(--sealpixel-color-fg);
662
691
  }
692
+ /*
693
+ * A source is loading: the mark, its core breathing. The outer square
694
+ * stands still and the inner one swells and fades, in the muted
695
+ * foreground so nothing reads as a warning. It stops under
696
+ * prefers-reduced-motion and still reads as the mark.
697
+ */
698
+ .empty.loading {
699
+ justify-items: center;
700
+ gap: calc(var(--sealpixel-space) * 2);
701
+ }
702
+ .empty.loading p {
703
+ margin: 0;
704
+ }
705
+ .mark {
706
+ display: block;
707
+ width: 40px;
708
+ height: 40px;
709
+ color: var(--sealpixel-color-fg-muted);
710
+ }
711
+ .mark .core {
712
+ transform-origin: 16px 16px;
713
+ animation: sealpixel-loading-breathe 1.8s var(--sealpixel-ease) infinite;
714
+ }
715
+ @keyframes sealpixel-loading-breathe {
716
+ 50% {
717
+ opacity: 0.45;
718
+ transform: scale(0.62);
719
+ }
720
+ }
721
+ }
663
722
  .error {
664
723
  grid-area: nav;
665
724
  align-self: end;
@@ -670,7 +729,7 @@ export class SealpixelEditor extends LitElement {
670
729
  border-radius: var(--sealpixel-radius);
671
730
  background: var(--sealpixel-color-danger);
672
731
  color: white;
673
- font-size: 12px;
732
+ font-size: calc(var(--sealpixel-font-size) * 12 / 14);
674
733
  box-shadow: var(--sealpixel-shadow-raised, none);
675
734
  animation: sealpixel-panel-in var(--sealpixel-duration) var(--sealpixel-ease-out) both;
676
735
  }
@@ -678,12 +737,17 @@ export class SealpixelEditor extends LitElement {
678
737
  ]; }
679
738
  static { this.properties = {
680
739
  plugins: { attribute: false },
681
- pluginOptions: { attribute: 'plugin-options', converter: jsonAttribute },
740
+ pluginOptions: {
741
+ attribute: 'plugin-options',
742
+ converter: jsonAttribute('plugin-options'),
743
+ },
682
744
  session: { attribute: false },
683
745
  renderer: { attribute: false },
684
746
  assets: { attribute: false },
685
- server: { attribute: false },
686
- serverEndpoint: { type: String, attribute: 'server-endpoint' },
747
+ limits: {
748
+ attribute: 'limits',
749
+ converter: jsonAttribute('limits'),
750
+ },
687
751
  src: { attribute: false },
688
752
  editLog: { attribute: false },
689
753
  defaultEditLog: { attribute: false },
@@ -720,11 +784,17 @@ export class SealpixelEditor extends LitElement {
720
784
  this.lastAppliedControlled = '';
721
785
  this.hint = null;
722
786
  this.previousTool = null;
787
+ /** The source the tools last heard about; `load` replaces the object, so identity is the guard. */
788
+ this.lastSource = null;
723
789
  this.loadedSrc = null;
790
+ /** The edit log of a session released while the element was out of the document. */
791
+ this.detachedLog = null;
792
+ /** Whether the owned session was released while the element was out of the document. */
793
+ this.released = false;
724
794
  this.lastError = null;
725
795
  this.sessionRenderer = null;
726
796
  this.sessionAssets = null;
727
- this.sessionServer = null;
797
+ this.sessionLimits = null;
728
798
  this.onPointerDown = () => {
729
799
  if (!this.matches(':focus-within'))
730
800
  this.focus({ preventScroll: true });
@@ -733,6 +803,10 @@ export class SealpixelEditor extends LitElement {
733
803
  const session = this.ctl.session;
734
804
  if (!session || session.getState().status !== 'ready')
735
805
  return;
806
+ // Undo inside a text field belongs to the field: it takes back the typing,
807
+ // not the last edit of the image.
808
+ if (isTextEntry(e.composedPath()[0]))
809
+ return;
736
810
  const mod = e.metaKey || e.ctrlKey;
737
811
  if (this.showHistory === 'none')
738
812
  return;
@@ -754,8 +828,7 @@ export class SealpixelEditor extends LitElement {
754
828
  this.session = null;
755
829
  this.renderer = null;
756
830
  this.assets = null;
757
- this.server = null;
758
- this.serverEndpoint = null;
831
+ this.limits = null;
759
832
  this.src = null;
760
833
  this.editLog = undefined;
761
834
  this.defaultEditLog = undefined;
@@ -844,14 +917,13 @@ export class SealpixelEditor extends LitElement {
844
917
  const renderer = this.renderer ?? SealpixelEditor.defaultRendererFactory?.(plugins) ?? null;
845
918
  this.sessionRenderer = renderer;
846
919
  const assets = this.assets ?? createAssetResolver({ assets: plugins.flatMap((p) => p.assets ?? []) });
847
- const server = this.server ?? (this.serverEndpoint ? { endpoint: this.serverEndpoint } : null);
848
- this.sessionServer = server;
849
920
  this.sessionAssets = this.assets;
921
+ this.sessionLimits = this.limits;
850
922
  const session = createEditorSession({
851
923
  plugins,
852
924
  assets,
853
925
  ...(renderer ? { renderer } : {}),
854
- ...(server ? { server } : {}),
926
+ ...(this.limits ? { limits: this.limits } : {}),
855
927
  });
856
928
  this.ownsSession = true;
857
929
  this.ctl.session = session;
@@ -860,6 +932,15 @@ export class SealpixelEditor extends LitElement {
860
932
  connectedCallback() {
861
933
  super.connectedCallback();
862
934
  this.ensureSession();
935
+ // Out of the document long enough to lose the session: the source comes
936
+ // back with the edit log it had when it left.
937
+ if (this.released) {
938
+ const restore = this.detachedLog ?? undefined;
939
+ this.released = false;
940
+ this.detachedLog = null;
941
+ if (this.loadedSrc)
942
+ void this.loadSource(this.loadedSrc, restore);
943
+ }
863
944
  // Keyboard shortcuts need focus inside the editor. WebKit does not focus
864
945
  // buttons on click, so pull focus in on any pointer interaction.
865
946
  if (!this.hasAttribute('tabindex'))
@@ -877,16 +958,41 @@ export class SealpixelEditor extends LitElement {
877
958
  this.removeEventListener('keydown', this.onKeydown);
878
959
  this.removeEventListener('pointerdown', this.onPointerDown);
879
960
  this.resizeObserver?.disconnect();
961
+ // A move in the DOM (an append into another parent, a portal, a keyed
962
+ // reorder) disconnects and connects again in the same task. Disposing here
963
+ // would throw the image and its history away on every move, so the
964
+ // session goes only if the element is still out after the task.
880
965
  if (this.ownsSession) {
881
- this.ctl.session?.dispose();
882
- this.disposeOwnedRenderer();
883
- this.ctl.session = null;
884
- this.ownsSession = false;
966
+ queueMicrotask(() => {
967
+ if (!this.isConnected)
968
+ this.releaseSession();
969
+ });
885
970
  }
886
971
  }
972
+ /** Disposes the owned session and keeps its edit log for a later connection. */
973
+ releaseSession() {
974
+ const session = this.ctl.session;
975
+ if (!this.ownsSession || !session)
976
+ return;
977
+ this.released = true;
978
+ this.detachedLog = session.getState().status === 'ready' ? session.getEditLog() : null;
979
+ session.dispose();
980
+ this.disposeOwnedRenderer();
981
+ this.ctl.session = null;
982
+ this.ownsSession = false;
983
+ this.lastEmittedVersion = -1;
984
+ this.lastSource = null;
985
+ // The tools activate again on the session that replaces this one.
986
+ this.previousTool = null;
987
+ }
887
988
  willUpdate(changed) {
888
989
  if (changed.has('locale') || changed.has('dictionary')) {
889
- this.i18n = createI18n(this.locale, this.dictionary ?? resolveLocale(this.locale));
990
+ // A dictionary changes the strings it names; every other string stays
991
+ // in the shipped locale.
992
+ this.i18n = createI18n(this.locale, {
993
+ ...resolveLocale(this.locale),
994
+ ...(this.dictionary ?? {}),
995
+ });
890
996
  }
891
997
  if (changed.has('session') && this.session && this.session !== this.ctl.session) {
892
998
  if (this.ownsSession) {
@@ -901,8 +1007,7 @@ export class SealpixelEditor extends LitElement {
901
1007
  changed.has('pluginOptions') ||
902
1008
  changed.has('renderer') ||
903
1009
  changed.has('assets') ||
904
- changed.has('server') ||
905
- changed.has('serverEndpoint')) &&
1010
+ changed.has('limits')) &&
906
1011
  this.ownsSession &&
907
1012
  !this.sessionMatchesProps()) {
908
1013
  this.ctl.session?.dispose();
@@ -912,6 +1017,7 @@ export class SealpixelEditor extends LitElement {
912
1017
  this.toolLoads.clear();
913
1018
  this._pluginTools = {};
914
1019
  this.lastEmittedVersion = -1;
1020
+ this.lastSource = null;
915
1021
  this.ensureSession();
916
1022
  if (this.loadedSrc)
917
1023
  void this.loadSource(this.loadedSrc);
@@ -920,7 +1026,7 @@ export class SealpixelEditor extends LitElement {
920
1026
  this.loadedSrc = this.src;
921
1027
  void this.loadSource(this.src);
922
1028
  }
923
- if (changed.has('editLog') && this.editLog !== undefined)
1029
+ if (changed.has('editLog') && this.editLog != null)
924
1030
  this.applyControlled();
925
1031
  }
926
1032
  updated() {
@@ -939,11 +1045,81 @@ export class SealpixelEditor extends LitElement {
939
1045
  this.dispatchEvent(new CustomEvent('sealpixel:error', { detail: state.error, bubbles: true, composed: true }));
940
1046
  }
941
1047
  this.syncActiveTool();
1048
+ this.syncSource(state);
1049
+ this.syncPanelFill();
1050
+ }
1051
+ /** Tells every tool, active or not, that a new source has loaded. Once per source. */
1052
+ syncSource(state) {
1053
+ if (state.status !== 'ready' || !state.source || state.source === this.lastSource)
1054
+ return;
1055
+ this.lastSource = state.source;
1056
+ const ctx = this.toolContext(state);
1057
+ for (const tool of this.currentTools())
1058
+ tool.onSource?.(ctx);
942
1059
  }
943
- async loadSource(src) {
1060
+ /**
1061
+ * Collapses the settings bar when the open tool has nothing to put in it.
1062
+ *
1063
+ * A tool renders its own structure, and a structure can hold nothing: crop
1064
+ * with `rotation`, `flip` and `reset` off and a single enforced aspect emits
1065
+ * two empty wrappers. The bar is a fixed height on purpose — see `.panel` —
1066
+ * so that reserved an empty bordered surface and took the same height off
1067
+ * the stage. On the landing page's avatar card that was 240 px of nothing
1068
+ * against a 178 px stage, and the photo rendered at 10 percent.
1069
+ *
1070
+ * Read from the DOM rather than asked of the tool: every tool would
1071
+ * otherwise have to declare it, and a tool whose panel empties out only
1072
+ * under some options would get it wrong.
1073
+ *
1074
+ * Not measured by size either. The empty wrappers still lay out — the row
1075
+ * is 8px from its own gap and the group 4px from its border — so a
1076
+ * bounding box tells content and scaffolding apart not at all. What counts
1077
+ * is a control or a word: a custom element, a form control, or any text.
1078
+ */
1079
+ syncPanelFill() {
1080
+ const panel = this.renderRoot.querySelector('.panel');
1081
+ if (!panel)
1082
+ return;
1083
+ const filled = (panel.textContent ?? '').trim().length > 0 ||
1084
+ Array.from(panel.querySelectorAll('*')).some((node) => node.tagName.includes('-') || node.matches(PANEL_CONTENT));
1085
+ panel.toggleAttribute('data-empty', !filled);
1086
+ this.syncPanelFit(panel, filled);
1087
+ }
1088
+ /**
1089
+ * Lets the settings bar grow to the height its content needs.
1090
+ *
1091
+ * The bar is a fixed height so that moving between tools does not resize
1092
+ * the stage under the user. When a tool needs more than that height, the
1093
+ * overflow has nowhere to go: a wrapping flex container of fixed height has
1094
+ * no scrollable cross-axis overflow, so `overflow: auto` never produces a
1095
+ * scrollbar, and the sticky choice row — which pins itself inside the
1096
+ * scrollport — is dragged up over the settings instead. The colour swatch
1097
+ * ends up half covered and the fill toggle disappears behind the shapes.
1098
+ *
1099
+ * WebKit is where this surfaced, on a real iPhone: it lays these controls
1100
+ * taller than Blink does, and at phone width crop, finetune and annotate
1101
+ * needed 138, 140 and 136 pixels against the 112 the bar had. Raising the
1102
+ * default would have taken those pixels off every stage in every engine, so
1103
+ * the height is measured instead and only the bar that needs more gets it.
1104
+ * `34cqh` still caps it, so a busy tool cannot eat the stage.
1105
+ */
1106
+ syncPanelFit(panel, filled) {
1107
+ panel.style.removeProperty('--sealpixel-panel-fit');
1108
+ if (!filled)
1109
+ return;
1110
+ // Read after the reset, so a bar that has since shrunk measures its own
1111
+ // content and not the height it was given last time.
1112
+ const needed = panel.scrollHeight;
1113
+ if (needed > panel.clientHeight) {
1114
+ panel.style.setProperty('--sealpixel-panel-fit', `${needed}px`);
1115
+ }
1116
+ }
1117
+ async loadSource(src, restore) {
944
1118
  const session = this.getSession();
945
1119
  try {
946
- const saved = this.editLog !== undefined ? this.editLog : this.defaultEditLog;
1120
+ // `null` is "no saved log", the same as `undefined`: framework props
1121
+ // commonly type an absent log as null.
1122
+ const saved = this.editLog ?? restore ?? this.defaultEditLog ?? undefined;
947
1123
  const bytes = src instanceof Uint8Array ? src : src;
948
1124
  const descriptor = await session.load(bytes, saved === undefined ? {} : { editLog: saved });
949
1125
  // Option defaults become real ops in an otherwise empty log.
@@ -963,16 +1139,17 @@ export class SealpixelEditor extends LitElement {
963
1139
  }
964
1140
  }
965
1141
  catch (error) {
1142
+ // A newer `src` replaced this load. That load reports its own outcome.
1143
+ if (error?.name === 'ABORTED')
1144
+ return;
966
1145
  this.dispatchEvent(new CustomEvent('sealpixel:error', { detail: error, bubbles: true, composed: true }));
967
1146
  }
968
1147
  }
969
1148
  applyControlled() {
970
1149
  const session = this.ctl.session;
971
- if (!session || session.getState().status !== 'ready' || this.editLog === undefined)
1150
+ if (!session || session.getState().status !== 'ready' || this.editLog == null)
972
1151
  return;
973
1152
  const wanted = this.editLog;
974
- if (wanted === null)
975
- return;
976
1153
  const key = canonicalJson(wanted);
977
1154
  if (key === this.lastAppliedControlled)
978
1155
  return;
@@ -984,7 +1161,7 @@ export class SealpixelEditor extends LitElement {
984
1161
  this.dispatchEvent(new CustomEvent('sealpixel:error', { detail: error, bubbles: true, composed: true }));
985
1162
  }
986
1163
  }
987
- /** Whether the owned session was built from the current `plugins` and `renderer`. */
1164
+ /** Whether the owned session was built from the current `plugins`, `renderer`, `assets` and `limits`. */
988
1165
  sessionMatchesProps() {
989
1166
  const session = this.ctl.session;
990
1167
  if (!session)
@@ -993,11 +1170,7 @@ export class SealpixelEditor extends LitElement {
993
1170
  return false;
994
1171
  if (this.assets && this.assets !== this.sessionAssets)
995
1172
  return false;
996
- const wantServer = this.server ?? (this.serverEndpoint ? { endpoint: this.serverEndpoint } : null);
997
- if (JSON.stringify(wantServer?.endpoint ?? null) !==
998
- JSON.stringify(this.sessionServer?.endpoint ?? null))
999
- return false;
1000
- if (wantServer !== this.sessionServer && wantServer?.fetch !== this.sessionServer?.fetch)
1173
+ if (canonicalJson(this.limits ?? null) !== canonicalJson(this.sessionLimits ?? null))
1001
1174
  return false;
1002
1175
  // Compare id, version and resolved options (options JSON may contain commas, so no string splitting).
1003
1176
  const key = (plugins) => canonicalJson([...plugins]
@@ -1064,6 +1237,7 @@ export class SealpixelEditor extends LitElement {
1064
1237
  if (s) {
1065
1238
  s.hintFilter = hint?.filter ?? '';
1066
1239
  s.hintTransform = hint?.transform ?? '';
1240
+ s.hintRotate = hint?.rotate ?? 0;
1067
1241
  }
1068
1242
  },
1069
1243
  refresh: () => this.requestUpdate(),
@@ -1127,7 +1301,7 @@ export class SealpixelEditor extends LitElement {
1127
1301
  /** Brief confirmation over the stage: format, size and hash of the result. */
1128
1302
  toast(key, result) {
1129
1303
  const format = result.mimeType.replace('image/', '').toUpperCase();
1130
- const size = result.bytes ? formatBytes(result.bytes.byteLength) : 'server';
1304
+ const size = formatBytes(result.bytes.byteLength);
1131
1305
  const text = this.i18n.t(key, { format, width: result.width, height: result.height, size });
1132
1306
  this._toast = { text, hash: result.hash.slice(0, 12) };
1133
1307
  this.announce(text);
@@ -1149,6 +1323,14 @@ export class SealpixelEditor extends LitElement {
1149
1323
  const tool = tools.find((t) => t.id === this.activeTool) ?? null;
1150
1324
  const ready = state?.status === 'ready';
1151
1325
  const ctx = state && ready ? this.toolContext(state) : null;
1326
+ const badges = {};
1327
+ if (ctx) {
1328
+ for (const t of tools) {
1329
+ const n = t.badge?.(ctx);
1330
+ if (n)
1331
+ badges[t.id] = n;
1332
+ }
1333
+ }
1152
1334
  const wide = this._wide;
1153
1335
  return html `
1154
1336
  <div class="root" part="root">
@@ -1158,7 +1340,7 @@ export class SealpixelEditor extends LitElement {
1158
1340
  .state=${state}
1159
1341
  .t=${this.i18n.t}
1160
1342
  .busy=${this._busy}
1161
- .canExport=${(state?.resident ?? false) || this.server !== null || this.serverEndpoint !== null}
1343
+ .canExport=${state?.resident ?? false}
1162
1344
  .showExport=${this.showExport === 'always' || (this.showExport === 'auto' && this._processListeners > 0)}
1163
1345
  .showDownload=${this.showDownload !== 'never'}
1164
1346
  .showHistory=${this.showHistory}
@@ -1183,8 +1365,9 @@ export class SealpixelEditor extends LitElement {
1183
1365
  <div class="panel" part="panel">${ctx && tool ? tool.panel(ctx) : nothing}</div>
1184
1366
  <sealpixel-toolbar
1185
1367
  part="toolbar"
1186
- exportparts="tool"
1368
+ exportparts="tool, badge"
1187
1369
  .tools=${tools}
1370
+ .badges=${badges}
1188
1371
  .active=${this.activeTool}
1189
1372
  .t=${this.i18n.t}
1190
1373
  .orientation=${wide ? 'vertical' : 'horizontal'}
@@ -1207,7 +1390,13 @@ export class SealpixelEditor extends LitElement {
1207
1390
  }
1208
1391
  renderEmpty(state) {
1209
1392
  if (state?.status === 'loading') {
1210
- return html `<div class="empty" part="empty" role="status">${this.i18n.t('editor.loading')}</div>`;
1393
+ return html `<div class="empty loading" part="empty" role="status">
1394
+ <svg class="mark" viewBox="0 0 32 32" aria-hidden="true">
1395
+ <rect x="3" y="3" width="26" height="26" rx="5" fill="none" stroke="currentColor" stroke-width="2" />
1396
+ <rect class="core" x="11" y="11" width="10" height="10" rx="1.5" fill="currentColor" />
1397
+ </svg>
1398
+ <p>${this.i18n.t('editor.loading')}</p>
1399
+ </div>`;
1211
1400
  }
1212
1401
  return html `<div
1213
1402
  class="empty ${this._dragover ? 'dragover' : ''}"
@@ -1235,6 +1424,25 @@ export class SealpixelEditor extends LitElement {
1235
1424
  </div>`;
1236
1425
  }
1237
1426
  }
1427
+ /** Input types that hold no text, so Cmd/Ctrl+Z on them has nothing of their own to undo. */
1428
+ const NON_TEXT_INPUTS = new Set([
1429
+ 'button',
1430
+ 'checkbox',
1431
+ 'color',
1432
+ 'file',
1433
+ 'image',
1434
+ 'radio',
1435
+ 'range',
1436
+ 'reset',
1437
+ 'submit',
1438
+ ]);
1439
+ function isTextEntry(target) {
1440
+ if (!(target instanceof HTMLElement))
1441
+ return false;
1442
+ if (target.isContentEditable || target instanceof HTMLTextAreaElement)
1443
+ return true;
1444
+ return target instanceof HTMLInputElement && !NON_TEXT_INPUTS.has(target.type);
1445
+ }
1238
1446
  function formatBytes(n) {
1239
1447
  if (n < 1024)
1240
1448
  return `${n} B`;