@1337exp/taoux 0.18.1 → 0.18.2

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.18.2
4
+
5
+ Nothing to migrate: a fix of `History`.
6
+
7
+ - **A series that came back to its start no longer merges into the step before.** Edits with one key replace each other; when they bring the state back to where the series began, its entry goes. The key stayed, so an edit that went on (a drag that passed its own start, a number typed, erased and typed again) was merged into the PREVIOUS step, an edit of another field, and one undo took both back. Now the series ends with its entry, and an edit that goes on is a new step.
8
+
3
9
  ## 0.18.1
4
10
 
5
11
  Nothing to migrate: the skill and the tests only.
package/dist/history.js CHANGED
@@ -90,6 +90,9 @@ var History = class {
90
90
  this.states.pop();
91
91
  this.labels.pop();
92
92
  this.index--;
93
+ this.lastKey = void 0;
94
+ this.lastTime = t;
95
+ return true;
93
96
  }
94
97
  } else {
95
98
  this.states.length = this.index + 1;
@@ -1 +1 @@
1
- {"version":3,"file":"history.js","names":[],"sources":["../src/history.ts"],"sourcesContent":["/**\r\n * Edits with the same key made faster than this many ms apart merge into one entry (typing a number into a field and the like).\r\n * Правки с одним ключом, сделанные чаще чем раз в столько мс, склеиваются в одну запись (набор числа в поле и т.п.).\r\n */\r\nexport const COALESCE_MS = 800;\r\n\r\n/**\r\n * A history taken out of a `History` to be put back later: for an editor with several documents, each keeps its own.\r\n * It is plain data (strings and a number), so it can be stored anywhere.\r\n * История, вынутая из `History`, чтобы вернуть её позже: у редактора с несколькими документами у каждого своя.\r\n * Это простые данные (строки и число), их можно хранить где угодно.\r\n */\r\nexport interface HistoryState {\r\n states: readonly string[];\r\n index: number;\r\n /**\r\n * The label of the step that made each snapshot (the first has none), when the history has labels. A history saved before labels existed has none: it is put back unlabelled.\r\n * Подпись шага, который сделал каждый снимок (у первого её нет), если в истории есть подписи. История, сохранённая до подписей, их не имеет: возвращается без подписей.\r\n */\r\n labels?: readonly (string | undefined)[];\r\n /**\r\n * The snapshot marked saved by `markSaved()`, when it is not the first one (so a history that never saved is the plain data it always was). Without it `restore` takes the first snapshot as the saved one.\r\n * Снимок, отмеченный `markSaved()`, если это не первый снимок (так история, которая не сохранялась, остаётся теми же простыми данными). Без него `restore` считает сохранённым первый снимок.\r\n */\r\n saved?: string;\r\n}\r\n\r\nexport interface HistoryOptions {\r\n /**\r\n * How long, ms, edits with one key merge. `Infinity`: until `seal()` or another key, however long the pause (an editor that ends a drag itself). Default `COALESCE_MS`.\r\n * Сколько мс правки с одним ключом склеиваются. `Infinity`: до `seal()` или другого ключа, как бы долго ни длилась пауза (редактор, который сам заканчивает перетаскивание). По умолчанию `COALESCE_MS`.\r\n */\r\n coalesceMs?: number;\r\n}\r\n\r\n/**\r\n * Undo/redo state history: a linear list of snapshots and a pointer to the current one.\r\n * Snapshots are strings (graph JSON): they are immutable, easy to compare and need no copying.\r\n * История состояний для undo/redo: линейный список снимков и указатель на текущий.\r\n * Снимки — строки (JSON графа): они неизменяемы, их легко сравнивать и не нужно копировать.\r\n */\r\nexport class History {\r\n private states: string[];\r\n private labels: (string | undefined)[] = [undefined];\r\n private index = 0;\r\n private lastKey: string | undefined;\r\n private lastTime = 0;\r\n private saved: string;\r\n private readonly coalesceMs: number;\r\n\r\n constructor(\r\n initial: string,\r\n private readonly limit = 100,\r\n private readonly now: () => number = Date.now,\r\n options: HistoryOptions = {},\r\n ) {\r\n this.states = [initial];\r\n this.saved = initial;\r\n this.coalesceMs = options.coalesceMs ?? COALESCE_MS;\r\n }\r\n\r\n get canUndo(): boolean {\r\n return this.index > 0;\r\n }\r\n\r\n get canRedo(): boolean {\r\n return this.index < this.states.length - 1;\r\n }\r\n\r\n /**\r\n * The label of the step an undo would take back, or undefined (nothing to undo, or the step has no label).\r\n * Подпись шага, который отменит undo, или undefined (отменять нечего или у шага нет подписи).\r\n */\r\n get undoLabel(): string | undefined {\r\n return this.canUndo ? this.labels[this.index] : undefined;\r\n }\r\n\r\n /**\r\n * The label of the step a redo would bring back.\r\n * Подпись шага, который вернёт redo.\r\n */\r\n get redoLabel(): string | undefined {\r\n return this.canRedo ? this.labels[this.index + 1] : undefined;\r\n }\r\n\r\n /**\r\n * Whether the current snapshot differs from the one marked by `markSaved()` (the start, or the one `reset` began from). It follows the history: undoing back to the saved\r\n * snapshot is clean again.\r\n * Отличается ли текущий снимок от отмеченного `markSaved()` (начального или того, с которого начал `reset`). Следует за историей: откат до сохранённого снимка снова чист.\r\n */\r\n get dirty(): boolean {\r\n return this.states[this.index] !== this.saved;\r\n }\r\n\r\n /**\r\n * Marks the current snapshot as the saved one.\r\n * Отмечает текущий снимок сохранённым.\r\n */\r\n markSaved(): void {\r\n this.saved = this.states[this.index]!;\r\n }\r\n\r\n /**\r\n * Ends a series of merged edits: the next edit with the same key is a new step. An editor that knows where a gesture ends (a pointer was released, a field lost focus) calls it\r\n * there; one that does not leaves it to the time window.\r\n * Заканчивает серию склеенных правок: следующая правка с тем же ключом это новый шаг. Редактор, который знает, где кончается жест (отпустили указатель, поле потеряло фокус),\r\n * зовёт его там; тот, кто не знает, оставляет это окну времени.\r\n */\r\n seal(): void {\r\n this.lastKey = undefined;\r\n }\r\n\r\n /**\r\n * Records a new state. If it does not differ from the current one, does nothing (returns false).\r\n * An edit discards the \"future\" (redo). With the same `key` in a row and within `COALESCE_MS`,\r\n * edits replace each other instead of piling up.\r\n * Записывает новое состояние. Если оно не отличается от текущего, ничего не делает (вернёт false).\r\n * Правка отбрасывает «будущее» (redo). С одинаковым `key` подряд и в пределах `COALESCE_MS`\r\n * правки заменяют друг друга, а не копятся. `label` называет шаг (для «Отменить: …»); у склеенной серии подпись первой правки.\r\n * The `label` names the step (for \"Undo: …\"); a merged series keeps the label of its first edit.\r\n */\r\n commit(state: string, key?: string, label?: string): boolean {\r\n if (state === this.states[this.index]) return false;\r\n\r\n const t = this.now();\r\n const atTop = this.index === this.states.length - 1;\r\n const coalesce = key !== undefined && key === this.lastKey && t - this.lastTime <= this.coalesceMs && this.index > 0 && atTop;\r\n\r\n if (coalesce) {\r\n this.states[this.index] = state;\r\n // Back to the state before the series of edits: no entry is needed.\r\n // Вернулись к состоянию до серии правок: запись не нужна.\r\n if (this.states[this.index - 1] === state) {\r\n this.states.pop();\r\n this.labels.pop();\r\n this.index--;\r\n }\r\n } else {\r\n this.states.length = this.index + 1;\r\n this.labels.length = this.index + 1;\r\n this.states.push(state);\r\n this.labels.push(label);\r\n this.index++;\r\n if (this.states.length > this.limit + 1) {\r\n this.states.shift();\r\n this.labels.shift();\r\n this.index--;\r\n }\r\n }\r\n\r\n this.lastKey = key;\r\n this.lastTime = t;\r\n return true;\r\n }\r\n\r\n /**\r\n * Returns the previous state, or null if there is nothing to undo.\r\n * Возвращает предыдущее состояние или null, если отменять нечего.\r\n */\r\n undo(): string | null {\r\n if (!this.canUndo) return null;\r\n this.lastKey = undefined;\r\n return this.states[--this.index]!;\r\n }\r\n\r\n redo(): string | null {\r\n if (!this.canRedo) return null;\r\n this.lastKey = undefined;\r\n return this.states[++this.index]!;\r\n }\r\n\r\n /**\r\n * A copy of the whole history (the snapshots and the position), to put back with `restore`.\r\n * Копия всей истории (снимки и положение), чтобы вернуть её через `restore`.\r\n */\r\n save(): HistoryState {\r\n const state: HistoryState = { states: [...this.states], index: this.index };\r\n // only a history that has labels carries them, so one without is the plain data it always was / подписи несёт только история, у которой они есть, так что без них это те же простые данные, что и раньше\r\n const withLabels = this.labels.some(l => l !== undefined) ? { ...state, labels: [...this.labels] } : state;\r\n return this.saved !== this.states[0] ? { ...withLabels, saved: this.saved } : withLabels;\r\n }\r\n\r\n /**\r\n * Puts a saved history back. The current snapshot of it should be the state of the document the app shows now;\r\n * what is not (an index out of range, no snapshots) is refused with an error. A series of merged edits is not\r\n * continued across a restore.\r\n * Возвращает сохранённую историю. Текущий снимок в ней должен быть состоянием документа, который приложение показывает\r\n * сейчас; негодное (положение вне списка, нет снимков) отклоняется ошибкой. Серия склеенных правок через возврат не продолжается.\r\n */\r\n restore(state: HistoryState): void {\r\n if (!Number.isInteger(state.index) || state.index < 0 || state.index >= state.states.length) {\r\n throw new RangeError('History.restore: the position is outside the saved snapshots');\r\n }\r\n this.states = [...state.states];\r\n // a label that went through JSON is null, not undefined / подпись, прошедшая через JSON, это null, а не undefined\r\n this.labels = state.states.map((_, i) => state.labels?.[i] ?? undefined);\r\n this.index = state.index;\r\n this.saved = state.saved ?? state.states[0]!;\r\n this.lastKey = undefined;\r\n }\r\n\r\n /**\r\n * Start the history over (for example, after loading a file).\r\n * Начать историю заново (например, после загрузки файла).\r\n */\r\n reset(state: string): void {\r\n this.states = [state];\r\n this.labels = [undefined];\r\n this.saved = state;\r\n this.index = 0;\r\n this.lastKey = undefined;\r\n }\r\n}\r\n"],"mappings":";;;;;AAIA,IAAa,cAAc;;;;;;;AAqC3B,IAAa,UAAb,MAAqB;CAWI;CACA;CAXrB;CACA,SAAyC,CAAC,KAAA,CAAS;CACnD,QAAgB;CAChB;CACA,WAAmB;CACnB;CACA;CAEA,YACI,SACA,QAAyB,KACzB,MAAqC,KAAK,KAC1C,UAA0B,CAAC,GAC7B;EAHmB,KAAA,QAAA;EACA,KAAA,MAAA;EAGjB,KAAK,SAAS,CAAC,OAAO;EACtB,KAAK,QAAQ;EACb,KAAK,aAAa,QAAQ,cAAA;CAC9B;CAEA,IAAI,UAAmB;EACnB,OAAO,KAAK,QAAQ;CACxB;CAEA,IAAI,UAAmB;EACnB,OAAO,KAAK,QAAQ,KAAK,OAAO,SAAS;CAC7C;;;;;CAMA,IAAI,YAAgC;EAChC,OAAO,KAAK,UAAU,KAAK,OAAO,KAAK,SAAS,KAAA;CACpD;;;;;CAMA,IAAI,YAAgC;EAChC,OAAO,KAAK,UAAU,KAAK,OAAO,KAAK,QAAQ,KAAK,KAAA;CACxD;;;;;;CAOA,IAAI,QAAiB;EACjB,OAAO,KAAK,OAAO,KAAK,WAAW,KAAK;CAC5C;;;;;CAMA,YAAkB;EACd,KAAK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,IAAI;GAAE,GAAG;GAAO,QAAQ,CAAC,GAAG,KAAK,MAAM;EAAE,IAAI;EACrG,OAAO,KAAK,UAAU,KAAK,OAAO,KAAK;GAAE,GAAG;GAAY,OAAO,KAAK;EAAM,IAAI;CAClF;;;;;;;;CASA,QAAQ,OAA2B;EAC/B,IAAI,CAAC,OAAO,UAAU,MAAM,KAAK,KAAK,MAAM,QAAQ,KAAK,MAAM,SAAS,MAAM,OAAO,QACjF,MAAM,IAAI,WAAW,8DAA8D;EAEvF,KAAK,SAAS,CAAC,GAAG,MAAM,MAAM;EAE9B,KAAK,SAAS,MAAM,OAAO,KAAK,GAAG,MAAM,MAAM,SAAS,MAAM,KAAA,CAAS;EACvE,KAAK,QAAQ,MAAM;EACnB,KAAK,QAAQ,MAAM,SAAS,MAAM,OAAO;EACzC,KAAK,UAAU,KAAA;CACnB;;;;;CAMA,MAAM,OAAqB;EACvB,KAAK,SAAS,CAAC,KAAK;EACpB,KAAK,SAAS,CAAC,KAAA,CAAS;EACxB,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,UAAU,KAAA;CACnB;AACJ"}
1
+ {"version":3,"file":"history.js","names":[],"sources":["../src/history.ts"],"sourcesContent":["/**\r\n * Edits with the same key made faster than this many ms apart merge into one entry (typing a number into a field and the like).\r\n * Правки с одним ключом, сделанные чаще чем раз в столько мс, склеиваются в одну запись (набор числа в поле и т.п.).\r\n */\r\nexport const COALESCE_MS = 800;\r\n\r\n/**\r\n * A history taken out of a `History` to be put back later: for an editor with several documents, each keeps its own.\r\n * It is plain data (strings and a number), so it can be stored anywhere.\r\n * История, вынутая из `History`, чтобы вернуть её позже: у редактора с несколькими документами у каждого своя.\r\n * Это простые данные (строки и число), их можно хранить где угодно.\r\n */\r\nexport interface HistoryState {\r\n states: readonly string[];\r\n index: number;\r\n /**\r\n * The label of the step that made each snapshot (the first has none), when the history has labels. A history saved before labels existed has none: it is put back unlabelled.\r\n * Подпись шага, который сделал каждый снимок (у первого её нет), если в истории есть подписи. История, сохранённая до подписей, их не имеет: возвращается без подписей.\r\n */\r\n labels?: readonly (string | undefined)[];\r\n /**\r\n * The snapshot marked saved by `markSaved()`, when it is not the first one (so a history that never saved is the plain data it always was). Without it `restore` takes the first snapshot as the saved one.\r\n * Снимок, отмеченный `markSaved()`, если это не первый снимок (так история, которая не сохранялась, остаётся теми же простыми данными). Без него `restore` считает сохранённым первый снимок.\r\n */\r\n saved?: string;\r\n}\r\n\r\nexport interface HistoryOptions {\r\n /**\r\n * How long, ms, edits with one key merge. `Infinity`: until `seal()` or another key, however long the pause (an editor that ends a drag itself). Default `COALESCE_MS`.\r\n * Сколько мс правки с одним ключом склеиваются. `Infinity`: до `seal()` или другого ключа, как бы долго ни длилась пауза (редактор, который сам заканчивает перетаскивание). По умолчанию `COALESCE_MS`.\r\n */\r\n coalesceMs?: number;\r\n}\r\n\r\n/**\r\n * Undo/redo state history: a linear list of snapshots and a pointer to the current one.\r\n * Snapshots are strings (graph JSON): they are immutable, easy to compare and need no copying.\r\n * История состояний для undo/redo: линейный список снимков и указатель на текущий.\r\n * Снимки — строки (JSON графа): они неизменяемы, их легко сравнивать и не нужно копировать.\r\n */\r\nexport class History {\r\n private states: string[];\r\n private labels: (string | undefined)[] = [undefined];\r\n private index = 0;\r\n private lastKey: string | undefined;\r\n private lastTime = 0;\r\n private saved: string;\r\n private readonly coalesceMs: number;\r\n\r\n constructor(\r\n initial: string,\r\n private readonly limit = 100,\r\n private readonly now: () => number = Date.now,\r\n options: HistoryOptions = {},\r\n ) {\r\n this.states = [initial];\r\n this.saved = initial;\r\n this.coalesceMs = options.coalesceMs ?? COALESCE_MS;\r\n }\r\n\r\n get canUndo(): boolean {\r\n return this.index > 0;\r\n }\r\n\r\n get canRedo(): boolean {\r\n return this.index < this.states.length - 1;\r\n }\r\n\r\n /**\r\n * The label of the step an undo would take back, or undefined (nothing to undo, or the step has no label).\r\n * Подпись шага, который отменит undo, или undefined (отменять нечего или у шага нет подписи).\r\n */\r\n get undoLabel(): string | undefined {\r\n return this.canUndo ? this.labels[this.index] : undefined;\r\n }\r\n\r\n /**\r\n * The label of the step a redo would bring back.\r\n * Подпись шага, который вернёт redo.\r\n */\r\n get redoLabel(): string | undefined {\r\n return this.canRedo ? this.labels[this.index + 1] : undefined;\r\n }\r\n\r\n /**\r\n * Whether the current snapshot differs from the one marked by `markSaved()` (the start, or the one `reset` began from). It follows the history: undoing back to the saved\r\n * snapshot is clean again.\r\n * Отличается ли текущий снимок от отмеченного `markSaved()` (начального или того, с которого начал `reset`). Следует за историей: откат до сохранённого снимка снова чист.\r\n */\r\n get dirty(): boolean {\r\n return this.states[this.index] !== this.saved;\r\n }\r\n\r\n /**\r\n * Marks the current snapshot as the saved one.\r\n * Отмечает текущий снимок сохранённым.\r\n */\r\n markSaved(): void {\r\n this.saved = this.states[this.index]!;\r\n }\r\n\r\n /**\r\n * Ends a series of merged edits: the next edit with the same key is a new step. An editor that knows where a gesture ends (a pointer was released, a field lost focus) calls it\r\n * there; one that does not leaves it to the time window.\r\n * Заканчивает серию склеенных правок: следующая правка с тем же ключом это новый шаг. Редактор, который знает, где кончается жест (отпустили указатель, поле потеряло фокус),\r\n * зовёт его там; тот, кто не знает, оставляет это окну времени.\r\n */\r\n seal(): void {\r\n this.lastKey = undefined;\r\n }\r\n\r\n /**\r\n * Records a new state. If it does not differ from the current one, does nothing (returns false).\r\n * An edit discards the \"future\" (redo). With the same `key` in a row and within `COALESCE_MS`,\r\n * edits replace each other instead of piling up.\r\n * Записывает новое состояние. Если оно не отличается от текущего, ничего не делает (вернёт false).\r\n * Правка отбрасывает «будущее» (redo). С одинаковым `key` подряд и в пределах `COALESCE_MS`\r\n * правки заменяют друг друга, а не копятся. `label` называет шаг (для «Отменить: …»); у склеенной серии подпись первой правки.\r\n * The `label` names the step (for \"Undo: …\"); a merged series keeps the label of its first edit.\r\n */\r\n commit(state: string, key?: string, label?: string): boolean {\r\n if (state === this.states[this.index]) return false;\r\n\r\n const t = this.now();\r\n const atTop = this.index === this.states.length - 1;\r\n const coalesce = key !== undefined && key === this.lastKey && t - this.lastTime <= this.coalesceMs && this.index > 0 && atTop;\r\n\r\n if (coalesce) {\r\n this.states[this.index] = state;\r\n // Back to the state before the series of edits: no entry is needed.\r\n // The series is gone with it: an edit that goes on (a drag that passed its start) is a new step, not a part of the step before.\r\n // Вернулись к состоянию до серии правок: запись не нужна. Серия ушла вместе с ней: правка дальше (протяжка прошла своё начало) это новый шаг,\r\n // а не часть предыдущего.\r\n if (this.states[this.index - 1] === state) {\r\n this.states.pop();\r\n this.labels.pop();\r\n this.index--;\r\n this.lastKey = undefined;\r\n this.lastTime = t;\r\n return true;\r\n }\r\n } else {\r\n this.states.length = this.index + 1;\r\n this.labels.length = this.index + 1;\r\n this.states.push(state);\r\n this.labels.push(label);\r\n this.index++;\r\n if (this.states.length > this.limit + 1) {\r\n this.states.shift();\r\n this.labels.shift();\r\n this.index--;\r\n }\r\n }\r\n\r\n this.lastKey = key;\r\n this.lastTime = t;\r\n return true;\r\n }\r\n\r\n /**\r\n * Returns the previous state, or null if there is nothing to undo.\r\n * Возвращает предыдущее состояние или null, если отменять нечего.\r\n */\r\n undo(): string | null {\r\n if (!this.canUndo) return null;\r\n this.lastKey = undefined;\r\n return this.states[--this.index]!;\r\n }\r\n\r\n redo(): string | null {\r\n if (!this.canRedo) return null;\r\n this.lastKey = undefined;\r\n return this.states[++this.index]!;\r\n }\r\n\r\n /**\r\n * A copy of the whole history (the snapshots and the position), to put back with `restore`.\r\n * Копия всей истории (снимки и положение), чтобы вернуть её через `restore`.\r\n */\r\n save(): HistoryState {\r\n const state: HistoryState = { states: [...this.states], index: this.index };\r\n // only a history that has labels carries them, so one without is the plain data it always was / подписи несёт только история, у которой они есть, так что без них это те же простые данные, что и раньше\r\n const withLabels = this.labels.some(l => l !== undefined) ? { ...state, labels: [...this.labels] } : state;\r\n return this.saved !== this.states[0] ? { ...withLabels, saved: this.saved } : withLabels;\r\n }\r\n\r\n /**\r\n * Puts a saved history back. The current snapshot of it should be the state of the document the app shows now;\r\n * what is not (an index out of range, no snapshots) is refused with an error. A series of merged edits is not\r\n * continued across a restore.\r\n * Возвращает сохранённую историю. Текущий снимок в ней должен быть состоянием документа, который приложение показывает\r\n * сейчас; негодное (положение вне списка, нет снимков) отклоняется ошибкой. Серия склеенных правок через возврат не продолжается.\r\n */\r\n restore(state: HistoryState): void {\r\n if (!Number.isInteger(state.index) || state.index < 0 || state.index >= state.states.length) {\r\n throw new RangeError('History.restore: the position is outside the saved snapshots');\r\n }\r\n this.states = [...state.states];\r\n // a label that went through JSON is null, not undefined / подпись, прошедшая через JSON, это null, а не undefined\r\n this.labels = state.states.map((_, i) => state.labels?.[i] ?? undefined);\r\n this.index = state.index;\r\n this.saved = state.saved ?? state.states[0]!;\r\n this.lastKey = undefined;\r\n }\r\n\r\n /**\r\n * Start the history over (for example, after loading a file).\r\n * Начать историю заново (например, после загрузки файла).\r\n */\r\n reset(state: string): void {\r\n this.states = [state];\r\n this.labels = [undefined];\r\n this.saved = state;\r\n this.index = 0;\r\n this.lastKey = undefined;\r\n }\r\n}\r\n"],"mappings":";;;;;AAIA,IAAa,cAAc;;;;;;;AAqC3B,IAAa,UAAb,MAAqB;CAWI;CACA;CAXrB;CACA,SAAyC,CAAC,KAAA,CAAS;CACnD,QAAgB;CAChB;CACA,WAAmB;CACnB;CACA;CAEA,YACI,SACA,QAAyB,KACzB,MAAqC,KAAK,KAC1C,UAA0B,CAAC,GAC7B;EAHmB,KAAA,QAAA;EACA,KAAA,MAAA;EAGjB,KAAK,SAAS,CAAC,OAAO;EACtB,KAAK,QAAQ;EACb,KAAK,aAAa,QAAQ,cAAA;CAC9B;CAEA,IAAI,UAAmB;EACnB,OAAO,KAAK,QAAQ;CACxB;CAEA,IAAI,UAAmB;EACnB,OAAO,KAAK,QAAQ,KAAK,OAAO,SAAS;CAC7C;;;;;CAMA,IAAI,YAAgC;EAChC,OAAO,KAAK,UAAU,KAAK,OAAO,KAAK,SA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AClB,IAAI,CAAC,KAAK,SAAS,OAAO;EAC1B,KAAK,UAAU,KAAA;EACf,OAAO,KAAK,OAAO,EAAE,KAAK;CAC9B;;;;;CAMA,OAAqB;EACjB,MAAM,QAAsB;GAAE,QAAQ,CAAC,GAAG,KAAK,MAAM;GAAG,OAAO,KAAK;EAAM;EAE1E,MAAM,aAAa,KAAK,OAAO,MAAK,MAAK,MAAM,KAAA,CAAS,IAAI;GAAE,GAAG;GAAO,QAAQ,CAAC,GAAG,KAAK,MAAM;EAAE,IAAI;EACrG,OAAO,KAAK,UAAU,KAAK,OAAO,KAAK;GAAE,GAAG;GAAY,OAAO,KAAK;EAAM,IAAI;CAClF;;;;;;;;CASA,QAAQ,OAA2B;EAC/B,IAAI,CAAC,OAAO,UAAU,MAAM,KAAK,KAAK,MAAM,QAAQ,KAAK,MAAM,SAAS,MAAM,OAAO,QACjF,MAAM,IAAI,WAAW,8DAA8D;EAEvF,KAAK,SAAS,CAAC,GAAG,MAAM,MAAM;EAE9B,KAAK,SAAS,MAAM,OAAO,KAAK,GAAG,MAAM,MAAM,SAAS,MAAM,KAAA,CAAS;EACvE,KAAK,QAAQ,MAAM;EACnB,KAAK,QAAQ,MAAM,SAAS,MAAM,OAAO;EACzC,KAAK,UAAU,KAAA;CACnB;;;;;CAMA,MAAM,OAAqB;EACvB,KAAK,SAAS,CAAC,KAAK;EACpB,KAAK,SAAS,CAAC,KAAA,CAAS;EACxB,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,KAAK,UAAU,KAAA;CACnB;AACJ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1337exp/taoux",
3
- "version": "0.18.1",
3
+ "version": "0.18.2",
4
4
  "description": "Interaction and behavior building blocks for Vue apps: curve and gradient editors, canvas, undo/redo, playback. Import only what you need, bring your own design.",
5
5
  "keywords": [
6
6
  "vue",