@split-window/core 0.0.0-stage → 0.1.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 (79) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +217 -2
  3. package/dist/animation/animation-engine.d.ts +176 -0
  4. package/dist/animation/animation-engine.d.ts.map +1 -0
  5. package/dist/animation/animation-engine.js +160 -0
  6. package/dist/animation/animation-engine.js.map +1 -0
  7. package/dist/controller/split-window-controller.d.ts +123 -0
  8. package/dist/controller/split-window-controller.d.ts.map +1 -0
  9. package/dist/controller/split-window-controller.js +660 -0
  10. package/dist/controller/split-window-controller.js.map +1 -0
  11. package/dist/controller/split-window-ref.d.ts +136 -0
  12. package/dist/controller/split-window-ref.d.ts.map +1 -0
  13. package/dist/controller/split-window-ref.js +225 -0
  14. package/dist/controller/split-window-ref.js.map +1 -0
  15. package/dist/engine/base-split-window-engine.d.ts +103 -0
  16. package/dist/engine/base-split-window-engine.d.ts.map +1 -0
  17. package/dist/engine/base-split-window-engine.js +221 -0
  18. package/dist/engine/base-split-window-engine.js.map +1 -0
  19. package/dist/engine/split-window-engine.d.ts +54 -0
  20. package/dist/engine/split-window-engine.d.ts.map +1 -0
  21. package/dist/engine/split-window-engine.js +2 -0
  22. package/dist/engine/split-window-engine.js.map +1 -0
  23. package/dist/errors/errors.d.ts +39 -0
  24. package/dist/errors/errors.d.ts.map +1 -0
  25. package/dist/errors/errors.js +86 -0
  26. package/dist/errors/errors.js.map +1 -0
  27. package/dist/geometry/geometry.d.ts +49 -0
  28. package/dist/geometry/geometry.d.ts.map +1 -0
  29. package/dist/geometry/geometry.js +115 -0
  30. package/dist/geometry/geometry.js.map +1 -0
  31. package/dist/index.d.ts +15 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +14 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/model/types.d.ts +269 -0
  36. package/dist/model/types.d.ts.map +1 -0
  37. package/dist/model/types.js +42 -0
  38. package/dist/model/types.js.map +1 -0
  39. package/dist/model/validation.d.ts +13 -0
  40. package/dist/model/validation.d.ts.map +1 -0
  41. package/dist/model/validation.js +142 -0
  42. package/dist/model/validation.js.map +1 -0
  43. package/dist/numbering/tab-group-resolver.d.ts +18 -0
  44. package/dist/numbering/tab-group-resolver.d.ts.map +1 -0
  45. package/dist/numbering/tab-group-resolver.js +51 -0
  46. package/dist/numbering/tab-group-resolver.js.map +1 -0
  47. package/dist/policies/capacity.d.ts +21 -0
  48. package/dist/policies/capacity.d.ts.map +1 -0
  49. package/dist/policies/capacity.js +75 -0
  50. package/dist/policies/capacity.js.map +1 -0
  51. package/dist/registry/split-container-registry.d.ts +79 -0
  52. package/dist/registry/split-container-registry.d.ts.map +1 -0
  53. package/dist/registry/split-container-registry.js +180 -0
  54. package/dist/registry/split-container-registry.js.map +1 -0
  55. package/dist/stack/split-container-stack.d.ts +32 -0
  56. package/dist/stack/split-container-stack.d.ts.map +1 -0
  57. package/dist/stack/split-container-stack.js +65 -0
  58. package/dist/stack/split-container-stack.js.map +1 -0
  59. package/dist/testing/fake-engine.d.ts +77 -0
  60. package/dist/testing/fake-engine.d.ts.map +1 -0
  61. package/dist/testing/fake-engine.js +149 -0
  62. package/dist/testing/fake-engine.js.map +1 -0
  63. package/dist/testing/index.d.ts +2 -0
  64. package/dist/testing/index.d.ts.map +1 -0
  65. package/dist/testing/index.js +2 -0
  66. package/dist/testing/index.js.map +1 -0
  67. package/dist/utils/dom.d.ts +86 -0
  68. package/dist/utils/dom.d.ts.map +1 -0
  69. package/dist/utils/dom.js +109 -0
  70. package/dist/utils/dom.js.map +1 -0
  71. package/dist/utils/index.d.ts +3 -0
  72. package/dist/utils/index.d.ts.map +1 -0
  73. package/dist/utils/index.js +3 -0
  74. package/dist/utils/index.js.map +1 -0
  75. package/dist/utils/promise.d.ts +3 -0
  76. package/dist/utils/promise.d.ts.map +1 -0
  77. package/dist/utils/promise.js +7 -0
  78. package/dist/utils/promise.js.map +1 -0
  79. package/package.json +46 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lucas Dornelas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,218 @@
1
- # Temporary Holding Version
1
+ # @split-window/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Estado e regras do SplitWindow, sem framework e sem DOM: registry de containers, stacks de abas, numeração, resolução de container, políticas de limite, fechamento, regras de arraste, estado de tela cheia, eventos (RxJS) e erros.
4
+
5
+ Este pacote é para **autores de adaptadores**. Quem usa Angular instala [`@split-window/angular`](../angular/README.md), que reexporta os tipos do core.
6
+
7
+ ```bash
8
+ npm install @split-window/core rxjs
9
+ ```
10
+
11
+ Única peer dependency: `rxjs` (^7.8).
12
+
13
+ ## O core decide, a engine executa
14
+
15
+ | Core (`@split-window/core`) | Engine (adaptador) |
16
+ | -------------------------------------------- | ---------------------------------------------------------- |
17
+ | Registry, stacks, ordem das abas e aba ativa | Criar e destruir o conteúdo da aba |
18
+ | Numeração por grupo + título | Renderizar a barra de abas, os botões e a área de conteúdo |
19
+ | Resolução de container e erros | Attach, detach e mover o conteúdo sem destruir |
20
+ | `maxTabs`, `onFull`, `onReject` | Drag and drop |
21
+ | `canClose`, `force` e fechar tudo sequencial | Zonas de soltura e painel flutuante |
22
+ | Aberto, fechado e expandido | Aplicar a tela cheia na tela |
23
+ | `canMove` e restrição de container expandido | Traduzir cliques e drops em comandos para o core |
24
+
25
+ **A engine nunca decide.** No drop, ela pergunta `canDrop(ref, destino)` e, se permitido, chama `moveTab(...)`; o core então chama `engine.move()` para executar. As regras ficam num lugar só e valem para qualquer adaptador.
26
+
27
+ ## Contrato `SplitWindowEngine`
28
+
29
+ ```ts
30
+ import type {
31
+ SplitWindowEngine,
32
+ ContainerState,
33
+ TabState,
34
+ SplitWindowRef,
35
+ } from '@split-window/core';
36
+
37
+ interface SplitWindowEngine<TContent, THost, TAdapterOptions> {
38
+ /* ... */
39
+ }
40
+ ```
41
+
42
+ - `TContent`: o que o `open()` do adaptador aceita (no Angular, `Type<T> | TemplateRef`).
43
+ - `THost`: o host de um container (no Angular, `HTMLElement`). O registry também é genérico em `THost`.
44
+ - `TAdapterOptions`: opções que só o adaptador entende (no Angular, `inputs` e `injector`). O core repassa sem ler.
45
+
46
+ | Método | Quando o core chama | O que a engine faz |
47
+ | ------------------------------------------------------------------------- | --------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
48
+ | `connect(controller)` / `disconnect()` (opcionais) | No construtor / no `destroy()` do controller | Guarda o controller (arraste, config) e libera recursos. |
49
+ | `prepareContainer(container)` / `releaseContainer(container)` (opcionais) | Container registrado / removido | Prepara o host antes da primeira aba (ex.: layout colapsado) e desfaz. |
50
+ | `mountContainer(container)` | Primeira aba aberta ou movida para o container | Cria o shell. Em containers do body, `container.host` é `null`: a engine cria o host. |
51
+ | `unmountContainer(container)` | Container desregistrado ou lado do body desabilitado | Destrói o shell (e o host criado por ela). |
52
+ | `setContainerOpen(container, open)` | Container abre (recebe aba) ou fecha (`closeWhenEmpty`) | Mostra ou oculta o shell, sem desmontar. Pode animar e devolver uma `Promise`. |
53
+ | `createTab(content, tab, ref, adapterOptions)` | `open()` aceito pelas políticas | Cria o conteúdo e devolve um `TabHandle` opaco. Pode preencher `ref.componentInstance` com `ref._setComponentInstance()`. Se lançar, o core desfaz a abertura. |
54
+ | `attach(handle, container, index)` | Logo após `createTab` | Coloca a aba no container, **inativa**. |
55
+ | `move(handle, to, index)` | `moveTab` aprovado para outro container | Move o conteúdo **sem destruir**. |
56
+ | `activate(handle)` / `deactivate(handle)` | Troca de aba ativa | Mostra/liga a aba ou oculta/desliga. |
57
+ | `destroy(handle)` | Aba fechada (depois de `closed`/`dismissed`, antes de `hidden`) | Destrói o conteúdo. Se o container estiver saindo animado, pode manter a aba e devolver uma `Promise`: o `hidden` espera por ela. |
58
+ | `setExpanded(container, expanded)` | `expandContainer` / `restoreContainer` | Aplica ou remove a tela cheia. |
59
+ | `cancelDrag()` | A expansão mudou durante um arraste | Encerra o arraste e devolve a aba à posição original. |
60
+
61
+ `TabState` e `ContainerState` são fotos somente leitura (`id`, `title`, `label`, `ordinal`, `closable`, `containerKey`; `key`, `kind`, `side`, `host`, `options`, `label`, `open`, `expanded`, `mounted`).
62
+
63
+ ## `BaseSplitWindowEngine`
64
+
65
+ Base recomendada para engines. Implementa `setContainerOpen` e `destroy` com transições: chama o motor de animação, cancela a transição em andamento quando outra começa, mantém na tela a aba fechada enquanto o container sai (`destroy` devolve uma `Promise`) e emite cada passo em `transitions` (`start`, `running`, `done`, `cancelled`). A engine do adaptador implementa só a renderização e os ganchos `isMounted`, `isEntered`, `enter`, `leave`, `transitionPlan`, `destroyTab` e `containerOfTab` (e, opcionalmente, `setLeaving`, `setAnimating`, `beforeTransition`, `afterShown`, `afterHidden`, `prefersReducedMotion`).
66
+
67
+ ## Motores de animação
68
+
69
+ O contrato fica no core: `SplitAnimationEngine` (`animate(ctx)` e `cleanup(ctx)`), `SplitAnimationContext` (fase, elementos, frames `from`/`to`, propriedades, opções, `signal`, `started()`, `progress()`) e `SplitAnimationEngineRegistry` (motores por nome, na ordem de registro). Sem motor escolhido, um container animado usa o primeiro registrado; o `NoopSplitAnimationEngine` é usado só quando nenhum foi registrado ou quando `'none'` é escolhido, e mesmo assim emite `started()` e `progress(1)` de forma síncrona.
70
+
71
+ Motores prontos: `@split-window/css-animation` (classes de estado e `transitionend`) e `@split-window/keyframes-animation` (Web Animations). Os dois estendem `SplitAnimationEngine` e podem ser estendidos.
72
+
73
+ ## Utilitários
74
+
75
+ `isPromiseLike`, `SplitStyleStash` (estilos, classes e atributos com desfazer), `toClassList`, `maxCssTime`, `transitionTimeMs` e `reflow`, usados pelos pacotes derivados. Os auxiliares de DOM usam tipos estruturais, então o core continua sem depender da lib DOM.
76
+
77
+ ## `SplitWindowController`
78
+
79
+ Um controller por aplicação, ligando um registry a uma engine:
80
+
81
+ ```ts
82
+ import { SplitContainerRegistry, SplitWindowController } from '@split-window/core';
83
+
84
+ const registry = new SplitContainerRegistry<HTMLElement>();
85
+ const engine = new MinhaEngine();
86
+ const controller = new SplitWindowController(registry, engine, {
87
+ labels: { defaultTitle: 'Nova aba' }, // SplitWindowConfigInput, opcional
88
+ });
89
+
90
+ registry.registerContainer('direito', document.querySelector('#direito')!, { maxTabs: 5 });
91
+ registry.setDefaultContainer('direito');
92
+
93
+ const ref = controller.open(conteudo, { title: 'Contrato' }, /* adapterOptions */ undefined);
94
+ ref.result.then(
95
+ (r) => console.log('fechou com', r),
96
+ () => {},
97
+ );
98
+
99
+ await controller.dismissAll({ containerKey: 'direito' });
100
+ controller.destroy(); // completa os observables
101
+ ```
102
+
103
+ API pública do controller:
104
+
105
+ | Membro | Descrição |
106
+ | ----------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
107
+ | `open(content, options?, adapterOptions?)` | Resolve o container, aplica `maxTabs`/`onFull`/`onReject` e pede à engine para criar a aba. Devolve `SplitWindowRef`. |
108
+ | `dismissAll(options?)` | Fechar tudo sequencial. Resolve com `{ closed, kept }`. |
109
+ | `requestTabClose(ref)` | Pedido de fechamento vindo do X da aba (`trigger: 'tab-button'`); passa pelo `canClose`. |
110
+ | `hasOpenWindows(key?)`, `getTabs(key)`, `isClosingAll(key)` | Consultas. |
111
+ | `getContainerView(key)` | Foto imutável para renderizar (ver abaixo). |
112
+ | `canDrop`, `moveTab`, `getDropTargets`, `beginDrag`, `endDrag`, `draggingTab` | Arraste (ver abaixo). |
113
+ | `changes`, `tabMoved`, `tabRejected` | Observables. |
114
+ | `config`, `registry`, `engine` | Configuração mesclada e dependências. |
115
+
116
+ ## Redesenhar: `changes` + `getContainerView`
117
+
118
+ O contrato não tem um método por propriedade. A engine assina `changes` (emite a chave do container alterado) e lê uma foto imutável:
119
+
120
+ ```ts
121
+ controller.changes.subscribe((key) => {
122
+ const view = controller.getContainerView(key); // null se o container não existe mais
123
+ if (!view) return;
124
+ render(view.tabs, view.activeId, {
125
+ closingAll: view.closingAll, // desabilita o botão de fechar tudo
126
+ canExpand: view.canExpand, // false com expand: false
127
+ dragging: view.dragging, // desabilita o botão de tela cheia durante o arraste
128
+ expanded: view.container.expanded,
129
+ });
130
+ });
131
+ ```
132
+
133
+ Cada `SplitTabView` tem `id`, `title`, `label` (título com número), `closable`, `active` e `ref`.
134
+
135
+ ## Arraste: `canDrop`, `moveTab`, `beginDrag`, `endDrag`
136
+
137
+ ```ts
138
+ // início do arraste: emite ref.dragStarted e avisa todos os containers (view.dragging)
139
+ controller.beginDrag(ref);
140
+
141
+ // zonas de soltura: containers (exceto o da aba) que aceitam a aba agora
142
+ const targets = controller.getDropTargets(ref);
143
+
144
+ // enquanto o cursor passa sobre um destino (sem efeitos colaterais)
145
+ const ok = controller.canDrop(ref, 'destino'); // source padrão: 'drag'
146
+
147
+ // no drop
148
+ let moved = false;
149
+ if (controller.canDrop(ref, 'destino', index)) {
150
+ moved = controller.moveTab(ref, 'destino', index, 'drag');
151
+ }
152
+ controller.endDrag(ref, moved); // emite ref.dragEnded({ moved })
153
+ ```
154
+
155
+ - `canDrop` aplica `canMove`, `maxTabs` (com `source: 'move'`; só aceita se houver espaço ou substituição) e, para `source: 'drag'`, a restrição de container expandido: com um container expandido, só se reordena dentro dele.
156
+ - `moveTab(ref, key, index?, source = 'api')` reordena no mesmo container ou move para outro sem destruir, recalcula o número no destino, ativa a aba movida, fecha a origem vazia com `closeWhenEmpty` e emite `reordered`/`containerChanged`, `titleChanged` (se o rótulo mudou) e `tabMoved`. Devolve `true` se a aba mudou de lugar. Se o destino recusar por limite, emite `tabRejected` com `resolution: 'move-refused'`.
157
+ - Se a expansão mudar durante o arraste, o core chama `engine.cancelDrag()` e recusa o drop seguinte.
158
+ - `ref.moveTo()` usa o mesmo caminho com `source: 'api'` (sem a restrição de container expandido).
159
+
160
+ ## Funções puras de geometria
161
+
162
+ A engine mede o DOM e aplica o resultado; o cálculo fica no core.
163
+
164
+ | Função | Uso |
165
+ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------- |
166
+ | `resolveLength(value, axis, viewport, area)` | Converte `number` ou `'px' \| 'vw' \| 'vh' \| '%'` em px. Lança `SplitInvalidOptionError` para outro formato. |
167
+ | `computeExpandedRect(area, { maxWidth, maxHeight, margin, align })` | Retângulo do container expandido dentro da área de referência. |
168
+ | `computeClosedDropZoneRect({ size, viewport, bodySide, host, lastKnownRect, anchorRect })` | Posição do painel flutuante de um container fechado, ou `null` (sem zona; só recebe por `moveTo()`). |
169
+ | `centerOn(cx, cy, size)`, `clampToViewport(rect, viewport)`, `rectsMatch(a, b, tol?)` | Auxiliares. `rectsMatch` serve para detectar um ancestral que quebra o `position: fixed`. |
170
+
171
+ ```ts
172
+ import { computeExpandedRect, resolveLength } from '@split-window/core';
173
+
174
+ const viewport = { width: innerWidth, height: innerHeight };
175
+ const area = { x: 0, y: 0, ...viewport };
176
+ const rect = computeExpandedRect(area, {
177
+ maxWidth: resolveLength('90vw', 'x', viewport, area),
178
+ margin: 16,
179
+ align: 'center',
180
+ });
181
+ ```
182
+
183
+ ## Testes: `@split-window/core/testing`
184
+
185
+ `FakeSplitEngine` é uma engine em memória que registra cada chamada. Serve para testar o core e para testar o controller de um adaptador novo antes de ter UI.
186
+
187
+ ```ts
188
+ import { SplitContainerRegistry, SplitWindowController } from '@split-window/core';
189
+ import { FakeSplitEngine } from '@split-window/core/testing';
190
+
191
+ const registry = new SplitContainerRegistry();
192
+ const engine = new FakeSplitEngine();
193
+ const controller = new SplitWindowController(registry, engine);
194
+ registry.registerContainer('a', {});
195
+ registry.setDefaultContainer('a');
196
+
197
+ const ref = controller.open('conteúdo', { title: 'Contrato' });
198
+ expect(engine.sequence(ref.id)).toEqual(['createTab', 'attach', 'activate']);
199
+ expect(engine.containers.get('a')).toMatchObject({ mounted: true, open: true });
200
+ ```
201
+
202
+ | Membro | Descrição |
203
+ | -------------------- | ----------------------------------------------------------------------- |
204
+ | `calls` | Todas as chamadas `{ method, target, index?, value? }`, em ordem. |
205
+ | `callsOf(method)` | Chamadas de um método. |
206
+ | `sequence(target?)` | Nomes dos métodos chamados, opcionalmente só para uma aba ou container. |
207
+ | `tabs`, `containers` | Estado em memória (`FakeTab`, `FakeContainer`). |
208
+ | `cancelDragCount` | Quantas vezes `cancelDrag()` foi chamado. |
209
+ | `failNextCreate` | Atribua um `Error` para o próximo `createTab` lançar. |
210
+ | `reset()` | Limpa `calls`. |
211
+
212
+ ## Erros
213
+
214
+ Todos estendem `SplitWindowError`: `SplitContainerNotFoundError`, `SplitNoDefaultContainerError`, `SplitContainerFullError`, `SplitReservedContainerKeyError`, `SplitDuplicateContainerError` e `SplitInvalidOptionError`. Veja o [guia de erros](../../docs/guides/erros.md).
215
+
216
+ ## Referência da API
217
+
218
+ Gerada com TypeDoc a partir dos comentários do código: `npm run docs:api` na raiz do repositório (saída em `docs/api`).
@@ -0,0 +1,176 @@
1
+ import type { ContainerState, SplitBodySide, SplitContainerLayout, SplitRect } from '../model/types.js';
2
+ /** The part of `AbortSignal` the engines use. A DOM `AbortSignal` satisfies it. */
3
+ export interface SplitAbortSignal {
4
+ readonly aborted: boolean;
5
+ addEventListener(type: 'abort', listener: () => void, options?: {
6
+ once?: boolean;
7
+ }): void;
8
+ }
9
+ /**
10
+ * Elements of a container that a mode or an animation can touch.
11
+ * @typeParam TElement - the element type of the adapter (`HTMLElement` in Angular).
12
+ */
13
+ export interface SplitContainerElements<TElement = unknown> {
14
+ /** The shell (tab strip + content). */
15
+ readonly shell: TElement;
16
+ /** The app host of a custom container, or the fixed host of a body container. */
17
+ readonly host: TElement;
18
+ /** Backdrop of a body container with `backdrop: true`. */
19
+ readonly backdrop: TElement | null;
20
+ /** Element pushed by a body container in the `push` layout. */
21
+ readonly pushTarget: TElement | null;
22
+ }
23
+ /** State of the container at one end of a transition. */
24
+ export interface SplitAnimationFrame {
25
+ /** Rectangle of the shell, in viewport coordinates. */
26
+ readonly rect: SplitRect;
27
+ readonly opacity: number;
28
+ /** Size of the host on the side axis (custom containers in `push`), as a CSS length. */
29
+ readonly hostSize: string | null;
30
+ /** Value of the push property on the push target (body containers in `push`). */
31
+ readonly push: string | null;
32
+ }
33
+ /** CSS properties that change between the frames, when the layout has them. */
34
+ export interface SplitAnimationProperties {
35
+ /** `width` or `height` of the host (custom containers in `push`). */
36
+ readonly host: 'width' | 'height' | null;
37
+ /** `padding-<side>` of the push target (body containers in `push`). */
38
+ readonly push: string | null;
39
+ }
40
+ /** Looks the engines understand: `slide` from the side, `fade`, `collapse` (sizes only), `none`. */
41
+ export type SplitAnimationPreset = 'slide' | 'fade' | 'collapse' | 'none';
42
+ /** Animation options after merging the global defaults, the mode and the container. */
43
+ export interface SplitAnimationSettings {
44
+ readonly preset: SplitAnimationPreset;
45
+ /** In ms. Without a value, each engine uses its own default. */
46
+ readonly duration?: number;
47
+ readonly easing?: string;
48
+ /** In ms. */
49
+ readonly delay?: number;
50
+ readonly respectReducedMotion: boolean;
51
+ }
52
+ /**
53
+ * Everything an animation engine receives. On a show, the layout of the open state is
54
+ * already applied when `animate` runs; on a hide, it is still applied. The engine animates
55
+ * from `from` to `to` and resolves (or returns) when it is done.
56
+ */
57
+ export interface SplitAnimationContext<TElement = unknown> {
58
+ readonly phase: 'show' | 'hide';
59
+ readonly container: ContainerState<TElement>;
60
+ readonly layout: SplitContainerLayout;
61
+ readonly side: SplitBodySide;
62
+ /** Panel size on the side axis, when the layout has one. */
63
+ readonly size: string | null;
64
+ readonly elements: SplitContainerElements<TElement>;
65
+ readonly from: SplitAnimationFrame;
66
+ readonly to: SplitAnimationFrame;
67
+ readonly properties: SplitAnimationProperties;
68
+ readonly options: SplitAnimationSettings;
69
+ /** The user asked the system for reduced motion. */
70
+ readonly reducedMotion: boolean;
71
+ /** Aborted when another transition interrupts this one: stop and resolve. */
72
+ readonly signal: SplitAbortSignal;
73
+ /** Tells the adapter that elements started moving. */
74
+ started(): void;
75
+ /** Optional progress report, from 0 to 1. */
76
+ progress(value: number): void;
77
+ }
78
+ /**
79
+ * Base class of every animation engine. Extend it, or one of the engines of
80
+ * `@split-window/css-animation` and `@split-window/keyframes-animation`.
81
+ */
82
+ export declare abstract class SplitAnimationEngine<TElement = unknown> {
83
+ /** Runs one transition. Return (or resolve) when it is over. */
84
+ abstract animate(ctx: SplitAnimationContext<TElement>): Promise<void> | void;
85
+ /**
86
+ * Called when the transition ends or is interrupted, before the adapter applies the
87
+ * final state (on a hide, before the open layout is removed). Undo temporary changes here.
88
+ */
89
+ cleanup(_ctx: SplitAnimationContext<TElement>): void;
90
+ }
91
+ /**
92
+ * Default engine, used when no engine is registered, when `'none'` is chosen and with
93
+ * reduced motion. Nothing moves, but the transition goes through every step synchronously:
94
+ * `started()`, `progress(1)` and the end, so the adapter emits the same events.
95
+ */
96
+ export declare class NoopSplitAnimationEngine<TElement = unknown> extends SplitAnimationEngine<TElement> {
97
+ animate(ctx: SplitAnimationContext<TElement>): void;
98
+ }
99
+ /** A function used as an animation engine. */
100
+ export type SplitAnimationFn<TElement = unknown> = (ctx: SplitAnimationContext<TElement>) => Promise<void> | void;
101
+ /** Wraps a function as an engine. */
102
+ export declare class SplitFunctionAnimationEngine<TElement = unknown> extends SplitAnimationEngine<TElement> {
103
+ private readonly fn;
104
+ constructor(fn: SplitAnimationFn<TElement>);
105
+ animate(ctx: SplitAnimationContext<TElement>): Promise<void> | void;
106
+ }
107
+ /** A class of engine. Adapters may create it with their dependency injection. */
108
+ export type SplitAnimationEngineClass<TElement = unknown> = new (...args: any[]) => SplitAnimationEngine<TElement>;
109
+ /**
110
+ * What `animation.engine` accepts: the name of a registered engine, `'none'` (the noop
111
+ * engine), an instance, a class or a function. Without a value: the first registered engine,
112
+ * or the noop engine when none is registered.
113
+ */
114
+ export type SplitAnimationEngineInput<TElement = unknown> = 'none' | (string & {}) | SplitAnimationEngine<TElement> | SplitAnimationEngineClass<TElement> | SplitAnimationFn<TElement>;
115
+ /** Animation options. */
116
+ export interface SplitAnimationOptions<TElement = unknown> {
117
+ /** `false` turns the animation off. An options object without it turns it on. */
118
+ enabled?: boolean;
119
+ /** Default: the first registered engine, or `NoopSplitAnimationEngine` when there is none. */
120
+ engine?: SplitAnimationEngineInput<TElement>;
121
+ /** Default: `slide` for overlay and body push, `collapse` for custom push, `fade` for inline. */
122
+ preset?: SplitAnimationPreset;
123
+ duration?: number;
124
+ easing?: string;
125
+ delay?: number;
126
+ /** With reduced motion, transitions end at once. Default: `true`. */
127
+ respectReducedMotion?: boolean;
128
+ }
129
+ /**
130
+ * What the `animation` option accepts: `true`/`false`, a preset, options, or an engine
131
+ * (instance, class or function).
132
+ */
133
+ export type SplitAnimationInput<TElement = unknown> = boolean | SplitAnimationPreset | SplitAnimationOptions<TElement> | SplitAnimationEngine<TElement> | SplitAnimationEngineClass<TElement> | SplitAnimationFn<TElement>;
134
+ /** Easing used when nothing else is configured. */
135
+ export declare const SPLIT_DEFAULT_EASING = "cubic-bezier(0.2, 0, 0, 1)";
136
+ /** Whether a value is an engine instance (duck typed, so it works across bundles). */
137
+ export declare function isAnimationEngine(value: unknown): value is SplitAnimationEngine<any>;
138
+ /** Whether a function is an engine class (its prototype has `animate`). */
139
+ export declare function isAnimationEngineClass(value: unknown): value is SplitAnimationEngineClass<any>;
140
+ /** Turns any animation input into options, so layers can be merged. */
141
+ export declare function normalizeAnimation<TElement>(input: SplitAnimationInput<TElement> | undefined): SplitAnimationOptions<TElement>;
142
+ /** Merges two animation inputs; the second wins key by key. */
143
+ export declare function mergeAnimation<TElement>(first: SplitAnimationInput<TElement> | undefined, second: SplitAnimationInput<TElement> | undefined): SplitAnimationOptions<TElement>;
144
+ /** Name of the noop engine, always available. */
145
+ export declare const SPLIT_NOOP_ANIMATION_ENGINE = "none";
146
+ /**
147
+ * Named animation engines, in registration order. A container picks one by name (or gives
148
+ * an engine directly); without a choice, the first registered engine is used, and the noop
149
+ * engine only when nothing is registered or `'none'` is chosen.
150
+ */
151
+ export declare class SplitAnimationEngineRegistry<TElement = unknown> {
152
+ private readonly instantiate;
153
+ private readonly entries;
154
+ private readonly instances;
155
+ private readonly noop;
156
+ /**
157
+ * @param instantiate - creates engine classes (adapters pass their dependency injection).
158
+ */
159
+ constructor(instantiate?: (type: SplitAnimationEngineClass<TElement>) => SplitAnimationEngine<TElement>);
160
+ /** Registers an engine (instance or class) under a name. A name registered again is replaced in place. */
161
+ register(name: string, engine: SplitAnimationEngine<TElement> | SplitAnimationEngineClass<TElement>): void;
162
+ has(name: string): boolean;
163
+ /** Registered names, in order (without `'none'`). */
164
+ names(): string[];
165
+ /** Engine of a name, or `undefined`. */
166
+ get(name: string): SplitAnimationEngine<TElement> | undefined;
167
+ /**
168
+ * Resolves an engine input. Without a value: the first registered engine, or the noop
169
+ * engine when nothing is registered. Unknown names throw `SplitInvalidOptionError`.
170
+ */
171
+ resolve(input?: SplitAnimationEngineInput<TElement>): SplitAnimationEngine<TElement>;
172
+ private create;
173
+ }
174
+ /** Preset used when none is given. */
175
+ export declare function defaultAnimationPreset(layout: SplitContainerLayout, kind: 'custom' | 'body'): SplitAnimationPreset;
176
+ //# sourceMappingURL=animation-engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animation-engine.d.ts","sourceRoot":"","sources":["../../src/animation/animation-engine.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,oBAAoB,EACpB,SAAS,EACV,MAAM,mBAAmB,CAAC;AAE3B,mFAAmF;AACnF,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;CAC3F;AAED;;;GAGG;AACH,MAAM,WAAW,sBAAsB,CAAC,QAAQ,GAAG,OAAO;IACxD,uCAAuC;IACvC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,iFAAiF;IACjF,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IACxB,0DAA0D;IAC1D,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IACnC,+DAA+D;IAC/D,QAAQ,CAAC,UAAU,EAAE,QAAQ,GAAG,IAAI,CAAC;CACtC;AAED,yDAAyD;AACzD,MAAM,WAAW,mBAAmB;IAClC,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,wFAAwF;IACxF,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,iFAAiF;IACjF,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,+EAA+E;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sB,CACpC,MAAM,EAAE,oBAAoB,EAC5B,IAAI,EAAE,QAAQ,GAAG,MAAM,GACtB,oBAAoB,CAItB"}
@@ -0,0 +1,160 @@
1
+ import { SplitInvalidOptionError } from '../errors/errors.js';
2
+ /**
3
+ * Base class of every animation engine. Extend it, or one of the engines of
4
+ * `@split-window/css-animation` and `@split-window/keyframes-animation`.
5
+ */
6
+ export class SplitAnimationEngine {
7
+ /**
8
+ * Called when the transition ends or is interrupted, before the adapter applies the
9
+ * final state (on a hide, before the open layout is removed). Undo temporary changes here.
10
+ */
11
+ cleanup(_ctx) {
12
+ // nothing to undo
13
+ }
14
+ }
15
+ /**
16
+ * Default engine, used when no engine is registered, when `'none'` is chosen and with
17
+ * reduced motion. Nothing moves, but the transition goes through every step synchronously:
18
+ * `started()`, `progress(1)` and the end, so the adapter emits the same events.
19
+ */
20
+ export class NoopSplitAnimationEngine extends SplitAnimationEngine {
21
+ animate(ctx) {
22
+ ctx.started();
23
+ ctx.progress(1);
24
+ }
25
+ }
26
+ /** Wraps a function as an engine. */
27
+ export class SplitFunctionAnimationEngine extends SplitAnimationEngine {
28
+ fn;
29
+ constructor(fn) {
30
+ super();
31
+ this.fn = fn;
32
+ }
33
+ animate(ctx) {
34
+ return this.fn(ctx);
35
+ }
36
+ }
37
+ /** Easing used when nothing else is configured. */
38
+ export const SPLIT_DEFAULT_EASING = 'cubic-bezier(0.2, 0, 0, 1)';
39
+ /** Whether a value is an engine instance (duck typed, so it works across bundles). */
40
+ export function isAnimationEngine(value) {
41
+ return (typeof value === 'object' &&
42
+ value !== null &&
43
+ typeof value.animate === 'function');
44
+ }
45
+ /** Whether a function is an engine class (its prototype has `animate`). */
46
+ export function isAnimationEngineClass(value) {
47
+ return (typeof value === 'function' &&
48
+ typeof value.prototype?.animate === 'function');
49
+ }
50
+ /** Turns any animation input into options, so layers can be merged. */
51
+ export function normalizeAnimation(input) {
52
+ if (input === undefined)
53
+ return {};
54
+ if (typeof input === 'boolean')
55
+ return { enabled: input };
56
+ if (input === 'none')
57
+ return { enabled: false };
58
+ if (typeof input === 'string')
59
+ return { enabled: true, preset: input };
60
+ if (typeof input === 'function' || isAnimationEngine(input)) {
61
+ return { enabled: true, engine: input };
62
+ }
63
+ return { enabled: true, ...input };
64
+ }
65
+ /** Merges two animation inputs; the second wins key by key. */
66
+ export function mergeAnimation(first, second) {
67
+ return { ...normalizeAnimation(first), ...normalizeAnimation(second) };
68
+ }
69
+ /** Name of the noop engine, always available. */
70
+ export const SPLIT_NOOP_ANIMATION_ENGINE = 'none';
71
+ /**
72
+ * Named animation engines, in registration order. A container picks one by name (or gives
73
+ * an engine directly); without a choice, the first registered engine is used, and the noop
74
+ * engine only when nothing is registered or `'none'` is chosen.
75
+ */
76
+ export class SplitAnimationEngineRegistry {
77
+ instantiate;
78
+ entries = new Map();
79
+ instances = new Map();
80
+ noop = new NoopSplitAnimationEngine();
81
+ /**
82
+ * @param instantiate - creates engine classes (adapters pass their dependency injection).
83
+ */
84
+ constructor(instantiate = (type) => new type()) {
85
+ this.instantiate = instantiate;
86
+ }
87
+ /** Registers an engine (instance or class) under a name. A name registered again is replaced in place. */
88
+ register(name, engine) {
89
+ if (typeof name !== 'string' || name.trim() === '' || name === SPLIT_NOOP_ANIMATION_ENGINE) {
90
+ throw new SplitInvalidOptionError('animationEngines', name, `nome não vazio, diferente de '${SPLIT_NOOP_ANIMATION_ENGINE}'`);
91
+ }
92
+ if (!isAnimationEngine(engine) && !isAnimationEngineClass(engine)) {
93
+ throw new SplitInvalidOptionError(`animationEngines.${name}`, engine, 'motor ou classe de motor');
94
+ }
95
+ this.entries.set(name, engine);
96
+ }
97
+ has(name) {
98
+ return name === SPLIT_NOOP_ANIMATION_ENGINE || this.entries.has(name);
99
+ }
100
+ /** Registered names, in order (without `'none'`). */
101
+ names() {
102
+ return [...this.entries.keys()];
103
+ }
104
+ /** Engine of a name, or `undefined`. */
105
+ get(name) {
106
+ if (name === SPLIT_NOOP_ANIMATION_ENGINE)
107
+ return this.noop;
108
+ const entry = this.entries.get(name);
109
+ return entry === undefined ? undefined : this.create(entry);
110
+ }
111
+ /**
112
+ * Resolves an engine input. Without a value: the first registered engine, or the noop
113
+ * engine when nothing is registered. Unknown names throw `SplitInvalidOptionError`.
114
+ */
115
+ resolve(input) {
116
+ if (input === undefined) {
117
+ const first = this.entries.values().next();
118
+ return first.done ? this.noop : this.create(first.value);
119
+ }
120
+ if (typeof input === 'string') {
121
+ const engine = this.get(input);
122
+ if (!engine) {
123
+ throw new SplitInvalidOptionError('animation.engine', input, [SPLIT_NOOP_ANIMATION_ENGINE, ...this.names()].join(' | '));
124
+ }
125
+ return engine;
126
+ }
127
+ if (isAnimationEngine(input))
128
+ return input;
129
+ if (isAnimationEngineClass(input))
130
+ return this.create(input);
131
+ if (typeof input === 'function') {
132
+ let wrapped = this.instances.get(input);
133
+ if (!wrapped) {
134
+ wrapped = new SplitFunctionAnimationEngine(input);
135
+ this.instances.set(input, wrapped);
136
+ }
137
+ return wrapped;
138
+ }
139
+ throw new SplitInvalidOptionError('animation.engine', input, 'nome, motor, classe ou função');
140
+ }
141
+ create(entry) {
142
+ if (isAnimationEngine(entry))
143
+ return entry;
144
+ let instance = this.instances.get(entry);
145
+ if (!instance) {
146
+ instance = this.instantiate(entry);
147
+ this.instances.set(entry, instance);
148
+ }
149
+ return instance;
150
+ }
151
+ }
152
+ /** Preset used when none is given. */
153
+ export function defaultAnimationPreset(layout, kind) {
154
+ if (layout === 'overlay')
155
+ return 'slide';
156
+ if (layout === 'push')
157
+ return kind === 'body' ? 'slide' : 'collapse';
158
+ return 'fade';
159
+ }
160
+ //# sourceMappingURL=animation-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animation-engine.js","sourceRoot":"","sources":["../../src/animation/animation-engine.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAyF9D;;;GAGG;AACH,MAAM,OAAgB,oBAAoB;IAIxC;;;OAGG;I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