@toghen/figma 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 (118) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -2
  3. package/cli/bin.mjs +19 -0
  4. package/cli/bridge.ts +243 -0
  5. package/cli/check.ts +62 -0
  6. package/cli/figcraft.ts +764 -0
  7. package/cli/figcraftApply.ts +1058 -0
  8. package/cli/figcraftFile.ts +476 -0
  9. package/cli/figcraftLibrary.ts +147 -0
  10. package/cli/figcraftRecord.ts +121 -0
  11. package/cli/figcraftScene.ts +661 -0
  12. package/cli/main.ts +218 -0
  13. package/cli/members.ts +65 -0
  14. package/cli/run.ts +756 -0
  15. package/component-files.md +665 -0
  16. package/dist/code.js +24147 -0
  17. package/dist/manifest.json +23 -0
  18. package/dist/ui.html +6918 -0
  19. package/guide.md +985 -0
  20. package/main/code.ts +50 -0
  21. package/main/components/apply.ts +704 -0
  22. package/main/components/endOfRun.ts +168 -0
  23. package/main/components/errors.ts +17 -0
  24. package/main/components/fieldWriter.ts +497 -0
  25. package/main/components/file.ts +263 -0
  26. package/main/components/receipt.ts +228 -0
  27. package/main/components/resolve.ts +1193 -0
  28. package/main/components/run.ts +273 -0
  29. package/main/components/snapshot.ts +341 -0
  30. package/main/components/stamp.ts +312 -0
  31. package/main/components/update.ts +465 -0
  32. package/main/dispatcher.ts +33 -0
  33. package/main/engines/batchRunner.ts +200 -0
  34. package/main/engines/ioAdapter.ts +132 -0
  35. package/main/engines/operationExecutor.ts +512 -0
  36. package/main/engines/propertyMapper.ts +221 -0
  37. package/main/engines/queryEngine.ts +45 -0
  38. package/main/engines/styleSyncEngine.ts +444 -0
  39. package/main/engines/variableSyncEngine.ts +561 -0
  40. package/main/handlers/auditSelection.ts +60 -0
  41. package/main/handlers/boundLayers.ts +51 -0
  42. package/main/handlers/cancelOperation.ts +18 -0
  43. package/main/handlers/executeApplyBindings.ts +69 -0
  44. package/main/handlers/executeScaffold.ts +59 -0
  45. package/main/handlers/executeStyleSync.ts +121 -0
  46. package/main/handlers/executeVariableSync.ts +82 -0
  47. package/main/handlers/exportDocument.ts +114 -0
  48. package/main/handlers/getSelection.ts +43 -0
  49. package/main/handlers/index.ts +30 -0
  50. package/main/handlers/inspectCorrespondence.ts +172 -0
  51. package/main/handlers/loadConventions.ts +86 -0
  52. package/main/handlers/loadDocument.ts +253 -0
  53. package/main/handlers/lock.ts +270 -0
  54. package/main/handlers/planApply.ts +157 -0
  55. package/main/handlers/planApplyBindings.ts +79 -0
  56. package/main/handlers/planScaffold.ts +84 -0
  57. package/main/handlers/planStyleSync.ts +49 -0
  58. package/main/handlers/planVariableSync.ts +49 -0
  59. package/main/handlers/readSelectionBindings.ts +160 -0
  60. package/main/handlers/resizeUi.ts +105 -0
  61. package/main/handlers/runComponent.ts +65 -0
  62. package/main/handlers/templates.ts +462 -0
  63. package/main/handlers/tokenGraph.ts +122 -0
  64. package/main/runtimeState.ts +66 -0
  65. package/main/utils/abortController.ts +11 -0
  66. package/main/utils/boundVariables.ts +84 -0
  67. package/main/utils/buildPayloads.ts +85 -0
  68. package/main/utils/correspondence.ts +658 -0
  69. package/main/utils/designSource.ts +122 -0
  70. package/main/utils/figmaCollectionIndex.ts +120 -0
  71. package/main/utils/figmaStyleAdapter.ts +268 -0
  72. package/main/utils/figmaTokenAdapter.ts +255 -0
  73. package/main/utils/flattenDesignSystem.ts +38 -0
  74. package/main/utils/folds.ts +203 -0
  75. package/main/utils/fontStack.ts +57 -0
  76. package/main/utils/lists.ts +4 -0
  77. package/main/utils/lockStore.ts +72 -0
  78. package/main/utils/moves.ts +67 -0
  79. package/main/utils/pageRoots.ts +58 -0
  80. package/main/utils/planSymbols.ts +96 -0
  81. package/main/utils/purpose.ts +351 -0
  82. package/main/utils/recentStore.ts +166 -0
  83. package/main/utils/resolverModes.ts +271 -0
  84. package/main/utils/rootRecord.ts +137 -0
  85. package/main/utils/shardedData.ts +142 -0
  86. package/main/utils/standing.ts +106 -0
  87. package/main/utils/styleTarget.ts +51 -0
  88. package/main/utils/sum.ts +612 -0
  89. package/main/utils/symbolicIdRegistry.ts +26 -0
  90. package/main/utils/syncState.ts +133 -0
  91. package/main/utils/templateStore.ts +73 -0
  92. package/main/utils/tokenPath.ts +28 -0
  93. package/main/utils/tokenStamps.ts +91 -0
  94. package/manifest.json +15 -0
  95. package/package.json +64 -4
  96. package/reference.md +1609 -0
  97. package/shared/components/artboard.ts +126 -0
  98. package/shared/components/axes.ts +420 -0
  99. package/shared/components/bindings.ts +64 -0
  100. package/shared/components/blueprint.ts +248 -0
  101. package/shared/components/check.ts +705 -0
  102. package/shared/components/diff.ts +668 -0
  103. package/shared/components/fields.ts +404 -0
  104. package/shared/components/groups.ts +306 -0
  105. package/shared/components/index.ts +140 -0
  106. package/shared/components/members.ts +280 -0
  107. package/shared/components/model.ts +273 -0
  108. package/shared/components/order.ts +53 -0
  109. package/shared/components/read.ts +480 -0
  110. package/shared/components/stack.ts +124 -0
  111. package/shared/components/steps.ts +186 -0
  112. package/shared/components/validate.ts +548 -0
  113. package/shared/conventions.ts +28 -0
  114. package/shared/inputs.ts +40 -0
  115. package/shared/operations.ts +233 -0
  116. package/shared/pendingNames.ts +39 -0
  117. package/shared/protocol.ts +588 -0
  118. package/shared/tokenTypeMap.ts +21 -0
@@ -0,0 +1,186 @@
1
+ /**
2
+ * What the Figma-side engine is given, what it plans, and what it reports.
3
+ *
4
+ * These are the contract between the command that prints a script and the engine
5
+ * the script runs, so they are plain JSON and free of any Figma type. The shapes
6
+ * are owned by `reference.md`, *Component files*.
7
+ */
8
+
9
+ import type { Component, Layer, Member, Property } from './model.js';
10
+
11
+ /** What the file says about a set, apart from its members. */
12
+ export type SetSpec = Pick<Component, 'name' | 'description' | 'properties' | 'across'>;
13
+
14
+ /** A component file after `readComponentFile`: the set's name and properties, and the members to build. */
15
+ export interface Desired {
16
+ component: SetSpec;
17
+ members: Member[];
18
+ /** An artboard file: `component` holds only its name, and `members` its one frame. */
19
+ artboard?: true;
20
+ }
21
+
22
+ /**
23
+ * What an earlier step of the same run would create, by the names the engine's lookup compares.
24
+ *
25
+ * A dry run of several steps writes nothing, so what a later step names does not exist yet. The plans of
26
+ * the earlier steps say it will, and `pending` carries that: a variable by its collection, its full name and
27
+ * its type, a text or effect style by its full name.
28
+ */
29
+ export interface Pending {
30
+ variables: { collection: string; name: string; type: VariableResolvedDataType }[];
31
+ textStyles: string[];
32
+ /** Effect styles a plan would create, by full name; absent reads as none. */
33
+ effectStyles?: string[];
34
+ /** Modes a plan would create, by collection name: a new collection's modes, or one added to an existing collection. */
35
+ modes?: { collection: string; mode: string }[];
36
+ /** Variables a plan would remove because their token moved to another collection, by collection and full name: counted as gone. */
37
+ removed?: { collection: string; name: string }[];
38
+ /** Component sets a file earlier in the same dry run would create, by name: counted as present, their instances' properties and slots unchecked. */
39
+ components?: string[];
40
+ }
41
+
42
+ export interface RunOptions {
43
+ /** The page the set lives on, by name. The current page when absent. */
44
+ page?: string;
45
+ /** Plan and return the steps, and write nothing. */
46
+ dryRun?: boolean;
47
+ /** Take the steps that break instances elsewhere. Without it a real run that has any stops before its first write. */
48
+ allowBreaking?: boolean;
49
+ /** Write the file's value over a field someone changed by hand since Toghen wrote it. Without it the edit is kept and said. */
50
+ overwriteDrift?: boolean;
51
+ /** Names a dry run counts as present because an earlier step would create them. A real run refuses it. */
52
+ pending?: Pending;
53
+ /** The libraries the file declares, whose names resolve through the lock: a blueprint's `library` lines. None for a component or artboard file alone. */
54
+ libraries?: string[];
55
+ }
56
+
57
+ /**
58
+ * One thing the engine will do, or the reason it will not, or something it found
59
+ * and left alone.
60
+ *
61
+ * A step is data: the diff makes them without touching Figma, and a dry run
62
+ * returns them as they are. Steps that name a node carry its id from the
63
+ * snapshot; steps that name a layer of a member carry its address, since a layer
64
+ * the same run creates has no id yet.
65
+ */
66
+ export type Step =
67
+ | { kind: 'CREATE_SET'; component: SetSpec; members: Member[] }
68
+ /** An artboard that does not exist yet: its frame and everything in it, built in one go. */
69
+ | { kind: 'CREATE_ARTBOARD'; member: Member }
70
+ /** A set of the component's name that Toghen did not make. It is never adopted by name. */
71
+ | { kind: 'REFUSE_FOREIGN'; component: string; nodeIds: string[]; message: string }
72
+
73
+ // Properties, on the set.
74
+ | { kind: 'ADD_PROPERTY'; property: Property }
75
+ /** `changes` names what differs: `defaultValue`, `description`, `preferredValues`, `slotSettings`. */
76
+ | { kind: 'EDIT_PROPERTY'; property: Property; changes: string[] }
77
+ | { kind: 'DELETE_PROPERTY'; name: string; breaks?: string }
78
+
79
+ // Members.
80
+ /** An axis the file renamed and nothing else about the axes: every member keeps its node and its stamp is written again. Breaks nothing. */
81
+ | { kind: 'RENAME_AXIS'; from: string; to: string }
82
+ | { kind: 'CREATE_MEMBER'; member: Member }
83
+ /** `strip`: the ids of the person's copies of the member and of what is in it, whose stamps the deletion strips (decisions, *A copy whose original Toghen removes*); `breaks` then names them. Each deletion below carries it the same way. */
84
+ | { kind: 'DELETE_MEMBER'; memberId: string; name: string; breaks: string; strip?: string[] }
85
+
86
+ // Layers of a member that exists. `layer` never carries children: they are steps of their own.
87
+ | { kind: 'CREATE_LAYER'; member: string; memberId: string; layer: Layer; parent: string; after?: string }
88
+ | {
89
+ kind: 'REPLACE_LAYER';
90
+ member: string;
91
+ memberId: string;
92
+ nodeId: string;
93
+ layer: Layer;
94
+ parent: string;
95
+ after?: string;
96
+ breaks: string;
97
+ strip?: string[];
98
+ }
99
+ | { kind: 'MOVE_LAYER'; member: string; memberId: string; nodeId: string; address: string; parent: string; after?: string }
100
+ /** Writes `fields`, those of the layer's fields its receipt says to write (`diff.ts`, `patch`), names the layer for the file and stamps it. The root layer is the member itself: `nodeId` is `memberId`. `restamp` names fields Figma already holds the file's value in, though not their receipt's: their receipt is taken again, and nothing is written. */
101
+ | { kind: 'PATCH_LAYER'; member: string; memberId: string; nodeId: string; layer: Layer; fields: string[]; restamp?: string[] }
102
+ /**
103
+ * An instance whose component the locator now answers with another one (the lock sent its name to another key, or the
104
+ * file names another): swapped with `swapComponent`, one row per instance. `component` is the set or artboard the
105
+ * instance is in; `from` names the component the instance shows now, `fromLibrary` the library it came from (its
106
+ * name as the lock holds its key, or empty when the lock holds it under none; absent: this file); `to` names the one
107
+ * it will show, and `library` the declared library the locator took it from (absent: this file).
108
+ */
109
+ | {
110
+ kind: 'SWAP_COMPONENT';
111
+ member: string;
112
+ memberId: string;
113
+ nodeId: string;
114
+ address: string;
115
+ component: string;
116
+ from: string;
117
+ fromLibrary?: string;
118
+ to: string;
119
+ library?: string;
120
+ }
121
+ /** `breaks` is set for an artboard, where a layer the file stopped producing is removed with whatever a person put in it. Where it is not, `message` names the copies it strips. */
122
+ | {
123
+ kind: 'DELETE_LAYER';
124
+ member: string;
125
+ memberId: string;
126
+ nodeId: string;
127
+ address: string;
128
+ breaks?: string;
129
+ strip?: string[];
130
+ message?: string;
131
+ }
132
+ /** A field someone changed by hand since Toghen wrote it, which `overwriteDrift` writes again: said before the patch that does it. */
133
+ | { kind: 'OVERWRITE'; member: string; address: string; message: string }
134
+
135
+ /**
136
+ * A member outside any set, left by an earlier run or dragged out of its set. Found once per run, on every page, and
137
+ * always breaking: its instances may be in other files that use this one as a library.
138
+ */
139
+ | { kind: 'REMOVE_STRAY'; id: string; name: string; breaks: string }
140
+
141
+ /** Something found and left alone, reported. A `copy` is a node a person copied from one of Toghen's, which carries its stamp. */
142
+ | { kind: 'LEAVE'; what: 'unstamped-node' | 'unstamped-member' | 'field' | 'property' | 'drift' | 'copy'; message: string }
143
+ /** Re-lays the members out and resizes the set. */
144
+ | { kind: 'RELAYOUT' };
145
+
146
+ export interface Report {
147
+ /** An artboard run: `created`, `updated` and `deleted` then name layers, not members. */
148
+ artboard?: true;
149
+ dryRun: boolean;
150
+ /** The steps planned, and for a real run the ones applied. */
151
+ steps: Step[];
152
+ /** The set built or patched. Absent for a dry run and for a refusal. */
153
+ setId?: string;
154
+ /** Names of the members created, in the order they were made. */
155
+ created: string[];
156
+ /** Names of the members whose layers were patched. */
157
+ updated: string[];
158
+ /** Names of the members deleted. */
159
+ deleted: string[];
160
+ /** What was found and left alone: nodes with no stamp, fields no longer declared, fields edited by hand (drift), foreign properties. */
161
+ notes: string[];
162
+ /** What breaks instances elsewhere: a member deleted, a layer replaced, a property deleted. */
163
+ breaking: string[];
164
+ /** Things the engine noticed that did not stop it. */
165
+ warnings: string[];
166
+ /** Names a dry run counted as present because `pending` said an earlier step would create them. Empty for a real run. */
167
+ pending: string[];
168
+ }
169
+
170
+ /** One step as the plugin reports it: what it did and to what, without the layer it carried. */
171
+ export interface StepSummary {
172
+ kind: Step['kind'];
173
+ member?: string;
174
+ address?: string;
175
+ property?: string;
176
+ /** A renamed axis. */
177
+ from?: string;
178
+ to?: string;
179
+ changes?: string[];
180
+ members?: number;
181
+ message?: string;
182
+ breaks?: string;
183
+ }
184
+
185
+ /** The report the plugin sends: the full one, with each step summarised (a step carries its whole layer, which the screen and the terminal do not need). */
186
+ export type CompactReport = Omit<Report, 'steps'> & { steps: StepSummary[] };