@lvce-editor/virtual-dom-worker 2.17.0 → 3.0.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 (64) hide show
  1. package/dist/index.d.ts +2 -532
  2. package/dist/index.js +1 -1299
  3. package/dist/parts/AddPatch/AddPatch.js +1 -0
  4. package/dist/parts/ApplyPendingPatches/ApplyPendingPatches.js +17 -0
  5. package/dist/parts/AriaLive/AriaLive.js +1 -0
  6. package/dist/parts/AttributePatch/AttributePatch.js +1 -0
  7. package/dist/parts/DomEventListener/DomEventListener.js +1 -0
  8. package/dist/parts/GetKeys/GetKeys.js +5 -0
  9. package/dist/parts/GetTotalChildCount/GetTotalChildCount.js +11 -0
  10. package/dist/parts/InputEventType/InputEventType.js +8 -0
  11. package/dist/parts/IsKey/IsKey.js +3 -0
  12. package/dist/parts/Main/Main.js +6 -0
  13. package/dist/parts/MergeClassNames/MergeClassNames.js +3 -0
  14. package/dist/parts/MouseEventType/MouseEventType.js +2 -0
  15. package/dist/parts/NavigateChildPatch/NavigateChildPatch.js +1 -0
  16. package/dist/parts/NavigateParentPatch/NavigateParentPatch.js +1 -0
  17. package/dist/parts/NavigateSiblingPatch/NavigateSiblingPatch.js +1 -0
  18. package/dist/parts/Patch/Patch.js +1 -0
  19. package/dist/parts/PatchType/PatchType.js +10 -0
  20. package/dist/parts/Px/Px.js +6 -0
  21. package/dist/parts/RemoveAttributePatch/RemoveAttributePatch.js +1 -0
  22. package/dist/parts/RemoveChildPatch/RemoveChildPatch.js +1 -0
  23. package/dist/parts/RemovePatch/RemovePatch.js +1 -0
  24. package/dist/parts/ReplacePatch/ReplacePatch.js +1 -0
  25. package/dist/parts/Text/Text.js +8 -0
  26. package/dist/parts/TextPatch/TextPatch.js +1 -0
  27. package/dist/parts/VirtualDomDiff/VirtualDomDiff.js +176 -0
  28. package/dist/parts/VirtualDomElements/VirtualDomElements.js +2 -0
  29. package/dist/parts/VirtualDomNode/VirtualDomNode.js +1 -0
  30. package/dist/parts/WhenExpression/WhenExpression.js +54 -0
  31. package/package.json +4 -1
  32. package/src/index.ts +0 -1
  33. package/src/parts/AddPatch/AddPatch.ts +0 -6
  34. package/src/parts/ApplyPendingPatches/ApplyPendingPatches.ts +0 -22
  35. package/src/parts/AriaLive/AriaLive.ts +0 -1
  36. package/src/parts/AriaRoles/AriaRoles.ts +0 -17
  37. package/src/parts/AttributePatch/AttributePatch.ts +0 -5
  38. package/src/parts/ClassNames/ClassNames.ts +0 -233
  39. package/src/parts/DomEventListener/DomEventListener.ts +0 -6
  40. package/src/parts/GetKeys/GetKeys.ts +0 -7
  41. package/src/parts/GetTotalChildCount/GetTotalChildCount.ts +0 -16
  42. package/src/parts/InputEventType/InputEventType.ts +0 -15
  43. package/src/parts/IsKey/IsKey.ts +0 -3
  44. package/src/parts/KeyCode/KeyCode.ts +0 -149
  45. package/src/parts/KeyModifier/KeyModifier.ts +0 -4
  46. package/src/parts/Main/Main.ts +0 -14
  47. package/src/parts/MergeClassNames/MergeClassNames.ts +0 -3
  48. package/src/parts/MouseEventType/MouseEventType.ts +0 -3
  49. package/src/parts/NavigateChildPatch/NavigateChildPatch.ts +0 -4
  50. package/src/parts/NavigateParentPatch/NavigateParentPatch.ts +0 -3
  51. package/src/parts/NavigateSiblingPatch/NavigateSiblingPatch.ts +0 -4
  52. package/src/parts/Patch/Patch.ts +0 -22
  53. package/src/parts/PatchType/PatchType.ts +0 -10
  54. package/src/parts/Px/Px.ts +0 -7
  55. package/src/parts/RemoveAttributePatch/RemoveAttributePatch.ts +0 -4
  56. package/src/parts/RemoveChildPatch/RemoveChildPatch.ts +0 -4
  57. package/src/parts/RemovePatch/RemovePatch.ts +0 -4
  58. package/src/parts/ReplacePatch/ReplacePatch.ts +0 -7
  59. package/src/parts/Text/Text.ts +0 -10
  60. package/src/parts/TextPatch/TextPatch.ts +0 -4
  61. package/src/parts/VirtualDomDiff/VirtualDomDiff.ts +0 -202
  62. package/src/parts/VirtualDomElements/VirtualDomElements.ts +0 -57
  63. package/src/parts/VirtualDomNode/VirtualDomNode.ts +0 -4
  64. package/src/parts/WhenExpression/WhenExpression.ts +0 -53
@@ -1,202 +0,0 @@
1
- import type { Patch } from '../Patch/Patch.ts'
2
- import type { VirtualDomNode } from '../VirtualDomNode/VirtualDomNode.ts'
3
- import * as ApplyPendingPatches from '../ApplyPendingPatches/ApplyPendingPatches.ts'
4
- import * as GetKeys from '../GetKeys/GetKeys.ts'
5
- import * as GetTotalChildCount from '../GetTotalChildCount/GetTotalChildCount.ts'
6
- import * as PatchType from '../PatchType/PatchType.ts'
7
- import * as VirtualDomElements from '../VirtualDomElements/VirtualDomElements.ts'
8
-
9
- export const diff = (
10
- oldNodes: readonly VirtualDomNode[],
11
- newNodes: readonly VirtualDomNode[],
12
- ): readonly Patch[] => {
13
- const patches: Patch[] = []
14
- const pendingPatches: number[] = []
15
- let i = 0
16
- let j = 0
17
- let siblingOffset = 0
18
- let maxSiblingOffset = 1
19
- const indexStack: number[] = [0, 1]
20
- while (i < oldNodes.length && j < newNodes.length) {
21
- const oldNode = oldNodes[i]
22
- const newNode = newNodes[j]
23
-
24
- if (siblingOffset > 0) {
25
- // pendingPatches.push(PatchType.NavigateSibling, siblingOffset)
26
- }
27
-
28
- // TODO maybe don't have the current element in indexstack
29
- if (siblingOffset === maxSiblingOffset) {
30
- indexStack.pop()
31
- indexStack.pop()
32
- pendingPatches.push(PatchType.NavigateParent, 0)
33
- maxSiblingOffset = indexStack.pop() as number
34
- siblingOffset = (indexStack.pop() as number) + 1
35
- }
36
-
37
- while (siblingOffset === maxSiblingOffset) {
38
- pendingPatches.push(PatchType.NavigateParent, 0)
39
- maxSiblingOffset = indexStack.pop() as number
40
- siblingOffset = (indexStack.pop() as number) + 1
41
- }
42
-
43
- if (oldNode.type !== newNode.type) {
44
- let skip = 0
45
- if (
46
- pendingPatches.length > 0 &&
47
- pendingPatches.at(-2) === PatchType.NavigateChild
48
- ) {
49
- skip = 2
50
- }
51
- ApplyPendingPatches.applyPendingPatches(patches, pendingPatches, skip)
52
- const oldTotal = GetTotalChildCount.getTotalChildCount(oldNodes, i)
53
- const newTotal = GetTotalChildCount.getTotalChildCount(newNodes, j)
54
-
55
- patches.push({
56
- type: PatchType.RemoveChild,
57
- index: siblingOffset,
58
- })
59
- patches.push({
60
- type: PatchType.Add,
61
- nodes: newNodes.slice(j, j + newTotal),
62
- })
63
- siblingOffset++
64
- i += oldTotal
65
- j += newTotal
66
- continue
67
- }
68
-
69
- if (
70
- oldNode.type === VirtualDomElements.Text &&
71
- newNode.type === VirtualDomElements.Text
72
- ) {
73
- if (oldNode.text !== newNode.text) {
74
- if (siblingOffset !== 0) {
75
- pendingPatches.push(PatchType.NavigateSibling, siblingOffset)
76
- }
77
- ApplyPendingPatches.applyPendingPatches(patches, pendingPatches, 0)
78
- patches.push({
79
- type: PatchType.SetText,
80
- value: newNode.text,
81
- })
82
- }
83
- i++
84
- j++
85
- siblingOffset++
86
- continue
87
- }
88
-
89
- const oldKeys = GetKeys.getKeys(oldNode)
90
- const newKeys = GetKeys.getKeys(newNode)
91
- let hasAttributeChanges = false
92
- for (const key of newKeys) {
93
- if (oldNode[key] !== newNode[key]) {
94
- hasAttributeChanges = true
95
- break
96
- }
97
- }
98
- for (const key of oldKeys) {
99
- if (!(key in newNode)) {
100
- hasAttributeChanges = true
101
- break
102
- }
103
- }
104
-
105
- if (hasAttributeChanges) {
106
- if (siblingOffset > 0) {
107
- pendingPatches.push(PatchType.NavigateSibling, siblingOffset)
108
- }
109
- ApplyPendingPatches.applyPendingPatches(patches, pendingPatches, 0)
110
-
111
- for (const key of newKeys) {
112
- if (oldNode[key] !== newNode[key]) {
113
- patches.push({
114
- type: PatchType.SetAttribute,
115
- key,
116
- value: newNode[key],
117
- })
118
- }
119
- }
120
- for (const key of oldKeys) {
121
- if (!(key in newNode)) {
122
- patches.push({
123
- type: PatchType.RemoveAttribute,
124
- key,
125
- })
126
- }
127
- }
128
- }
129
-
130
- if (oldNode.childCount && newNode.childCount) {
131
- maxSiblingOffset = oldNode.childCount
132
- indexStack.push(0, maxSiblingOffset)
133
- pendingPatches.push(PatchType.NavigateChild, 0)
134
- i++
135
- j++
136
- continue
137
- }
138
-
139
- if (oldNode.childCount) {
140
- ApplyPendingPatches.applyPendingPatches(patches, pendingPatches, 0)
141
- for (let k = 0; k < oldNode.childCount; k++) {
142
- patches.push({
143
- type: PatchType.RemoveChild,
144
- index: 0,
145
- })
146
- }
147
- i += GetTotalChildCount.getTotalChildCount(oldNodes, i)
148
- j++
149
- siblingOffset++
150
- continue
151
- }
152
-
153
- if (newNode.childCount) {
154
- ApplyPendingPatches.applyPendingPatches(patches, pendingPatches, 0)
155
- const total = GetTotalChildCount.getTotalChildCount(newNodes, j)
156
- patches.push({
157
- type: PatchType.Add,
158
- nodes: newNodes.slice(j + 1, j + total),
159
- })
160
- i++
161
- j += total
162
- continue
163
- }
164
-
165
- i++
166
- j++
167
- siblingOffset++
168
- }
169
-
170
- while (i < oldNodes.length) {
171
- if (indexStack.length !== 2) {
172
- patches.push({
173
- type: PatchType.NavigateParent,
174
- })
175
- }
176
- patches.push({
177
- type: PatchType.RemoveChild,
178
- index: siblingOffset,
179
- })
180
- i += GetTotalChildCount.getTotalChildCount(oldNodes, i)
181
- indexStack.pop()
182
- indexStack.pop()
183
- }
184
-
185
- while (j < newNodes.length) {
186
- if (siblingOffset > 0) {
187
- patches.push({
188
- type: PatchType.NavigateSibling,
189
- index: siblingOffset,
190
- })
191
- siblingOffset = 0
192
- }
193
- const count = GetTotalChildCount.getTotalChildCount(newNodes, j)
194
- patches.push({
195
- type: PatchType.Add,
196
- nodes: newNodes.slice(j, j + count),
197
- })
198
- j += count
199
- }
200
-
201
- return patches
202
- }
@@ -1,57 +0,0 @@
1
- export const Audio = 0
2
- export const Button = 1
3
- export const Col = 2
4
- export const ColGroup = 3
5
- export const Div = 4
6
- export const H1 = 5
7
- export const Input = 6
8
- export const Kbd = 7
9
- export const Span = 8
10
- export const Table = 9
11
- export const TBody = 10
12
- export const Td = 11
13
- export const Text = 12
14
- export const Th = 13
15
- export const THead = 14
16
- export const Tr = 15
17
- export const I = 16
18
- export const Img = 17
19
- export const Root = 0
20
- export const Ins = 20
21
- export const Del = 21
22
- export const H2 = 22
23
- export const H3 = 23
24
- export const H4 = 24
25
- export const H5 = 25
26
- export const H6 = 26
27
- export const Article = 27
28
- export const Aside = 28
29
- export const Footer = 29
30
- export const Header = 30
31
- export const Nav = 40
32
- export const Section = 41
33
- export const Search = 42
34
- export const Dd = 43
35
- export const Dl = 44
36
- export const Figcaption = 45
37
- export const Figure = 46
38
- export const Hr = 47
39
- export const Li = 48
40
- export const Ol = 49
41
- export const P = 50
42
- export const Pre = 51
43
- export const A = 53
44
- export const Abbr = 54
45
- export const Br = 55
46
- export const Cite = 56
47
- export const Data = 57
48
- export const Time = 58
49
- export const Tfoot = 59
50
- export const Ul = 60
51
- export const Video = 61
52
- export const TextArea = 62
53
- export const Select = 63
54
- export const Option = 64
55
- export const Code = 65
56
- export const Label = 66
57
- export const Dt = 67
@@ -1,4 +0,0 @@
1
- export interface VirtualDomNode {
2
- readonly type: number
3
- readonly [key: string]: any
4
- }
@@ -1,53 +0,0 @@
1
- export const Empty = 0
2
- export const BrowserChromium = 1
3
- export const BrowserElectron = 2
4
- export const BrowserFirefox = 3
5
- export const FocusAbout = 4
6
- export const FocusActivityBar = 5
7
- export const FocusDebugInput = 6
8
- export const FocusDialog = 7
9
- export const FocusEditor = 12
10
- export const FocusEditorCompletions = 9
11
- export const FocusEditorImage = 10
12
- export const FocusEditorRename = 11
13
- export const FocusEditorText = 12
14
- export const FocusExplorer = 13
15
- export const FocusExplorerEditBox = 14
16
- export const FocusExtensions = 15
17
- export const FocusFindWidget = 16
18
- export const FocusLocationList = 17
19
- export const FocusMenu = 18
20
- export const FocusProblems = 19
21
- export const FocusQuickPickInput = 20
22
- export const FocusSearchInput = 21
23
- export const FocusSearchResults = 22
24
- export const FocusSimpleBrowserInput = 23
25
- export const FocusSourceControlInput = 24
26
- export const FocusTerminal = 25
27
- export const FocusTitleBarMenuBar = 26
28
- export const FocusViewletList = 27
29
- export const FocusOutput = 28
30
- export const FocusDebugConsoleInput = 29
31
- export const FocusDebugScope = 30
32
- export const FocusSearchReplaceInput = 31
33
- export const FocusSearchMatchCase = 32
34
- export const FocusSearchRegex = 33
35
- export const FocusSearchWholeWord = 34
36
- export const FocusSearchReplaceAll = 35
37
- export const FocusSearchPreserveCase = 36
38
- export const FocusSimpleBrowser = 37
39
- export const FocusSourceActions = 38
40
- export const FocusKeyBindingsTable = 39
41
- export const FocusConfirm = 40
42
- export const FocusColorPicker = 41
43
- export const FocusFindWidgetToggleReplace = 42
44
- export const FocusFindWidgetReplace = 43
45
- export const FocusFindWidgetRegex = 44
46
- export const FocusFindWidgetMatchCase = 45
47
- export const FocusFindWidgetReplaceButton = 46
48
- export const FocusFindWidgetReplaceAllButton = 47
49
- export const FocusFindWidgetCloseButton = 48
50
- export const FocusFindWidgetNextMatchButton = 49
51
- export const FocusFindWidgetPreviousMatchButton = 50
52
- export const FocusEditorHover = 51
53
- export const FocusEditorCodeGenerator = 52