@airalogy/aimd-recorder 1.14.1

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 (178) hide show
  1. package/README.md +240 -0
  2. package/README.zh-CN.md +224 -0
  3. package/dist/AimdCodeField-DC3DPvgc.js +172 -0
  4. package/dist/AimdDnaSequenceField-__jdnFS9.js +59466 -0
  5. package/dist/AimdEditor.vue_vue_type_style_index_0_lang-Bq79rKNw.js +28370 -0
  6. package/dist/AimdMarkdownField-98ImHGbc.js +66 -0
  7. package/dist/AimdMarkdownNoteField-CuUJZkgT.js +185 -0
  8. package/dist/_.contribution-IP0cDNhs.js +38 -0
  9. package/dist/_commonjsHelpers-CZXJ37nu.js +40 -0
  10. package/dist/abap-Bs8kvjsq.js +1398 -0
  11. package/dist/aimd-recorder.css +1 -0
  12. package/dist/apex-Dspwrl5m.js +326 -0
  13. package/dist/assets/css.worker-Dmf38jDD.js +79 -0
  14. package/dist/assets/editor.worker-CpuX8TSY.js +12 -0
  15. package/dist/assets/html.worker-DotaEs7v.js +456 -0
  16. package/dist/assets/json.worker-B4VHhH6h.js +44 -0
  17. package/dist/assets/ts.worker-sl17zBDo.js +51316 -0
  18. package/dist/azcli-k1BiOau1.js +68 -0
  19. package/dist/bat-BIP72KWc.js +100 -0
  20. package/dist/bicep-VhQeYhS3.js +102 -0
  21. package/dist/cameligo-DnuAXtHg.js +174 -0
  22. package/dist/clojure-BAuDPsal.js +761 -0
  23. package/dist/coffee-BV06qSnj.js +232 -0
  24. package/dist/components.js +3595 -0
  25. package/dist/composables.js +72 -0
  26. package/dist/cpp-Cz8Jeyrf.js +389 -0
  27. package/dist/csharp-F6hhlXFb.js +326 -0
  28. package/dist/csp-KzlEHCyI.js +53 -0
  29. package/dist/css-e4FKntZ3.js +187 -0
  30. package/dist/cssMode-uz9U6SUU.js +1571 -0
  31. package/dist/cypher-CpvDGKRr.js +263 -0
  32. package/dist/dart-DdHeFWR0.js +281 -0
  33. package/dist/dockerfile-aoNXDcio.js +130 -0
  34. package/dist/ecl-C4Q0DYuA.js +456 -0
  35. package/dist/editor.api-CgD9w0gG.js +77091 -0
  36. package/dist/editor.main-Du02abDl.js +33783 -0
  37. package/dist/elixir-C9X42b0T.js +569 -0
  38. package/dist/flow9-Bff42pfB.js +142 -0
  39. package/dist/freemarker2-DFLX4iQ-.js +989 -0
  40. package/dist/fsharp-C6vPAsHG.js +217 -0
  41. package/dist/go-DEr8zx9f.js +218 -0
  42. package/dist/graphql-BiNBBRFh.js +151 -0
  43. package/dist/handlebars-aiZbIuWY.js +419 -0
  44. package/dist/hcl-2T9lKuFg.js +183 -0
  45. package/dist/html-phzTMObN.js +308 -0
  46. package/dist/htmlMode-BF7wMi3N.js +1581 -0
  47. package/dist/index.js +89 -0
  48. package/dist/ini-CZGtssYM.js +71 -0
  49. package/dist/ini.contribution-DyWtiacL.js +8 -0
  50. package/dist/java-B260NeH3.js +232 -0
  51. package/dist/javascript-BKKOItMi.js +70 -0
  52. package/dist/jsonMode-CDYK4B5l.js +1996 -0
  53. package/dist/julia-kuNLM9c5.js +511 -0
  54. package/dist/kotlin-Bz6kAefA.js +253 -0
  55. package/dist/less-AZUtS89I.js +162 -0
  56. package/dist/lexon-BcmgnyRb.js +157 -0
  57. package/dist/liquid-B2eRz5SA.js +240 -0
  58. package/dist/lua-Dz1RbATg.js +162 -0
  59. package/dist/m3-CIMooLFn.js +210 -0
  60. package/dist/markdown-C1BsCK9P.js +229 -0
  61. package/dist/markdown.contribution-DYYk6zUU.js +7 -0
  62. package/dist/mdx-BfV1HDRG.js +165 -0
  63. package/dist/mips-BovsnfLQ.js +198 -0
  64. package/dist/monaco.contribution-C-bQhUTI.js +114 -0
  65. package/dist/monaco.contribution-CCVvl3Jx.js +72 -0
  66. package/dist/monaco.contribution-Col-f0XR.js +164 -0
  67. package/dist/monaco.contribution-b5xkgQ-s.js +112 -0
  68. package/dist/msdax-CiRB2ZB-.js +375 -0
  69. package/dist/mysql-BwdpPE19.js +878 -0
  70. package/dist/objective-c-D4nfHfso.js +183 -0
  71. package/dist/pascal--j5-PYtz.js +251 -0
  72. package/dist/pascaligo-C7TcJxNL.js +164 -0
  73. package/dist/perl-BzEWqUb5.js +626 -0
  74. package/dist/pgsql-B_KZ0mGX.js +851 -0
  75. package/dist/php-A19QHzQV.js +500 -0
  76. package/dist/pla-COeKY1hA.js +137 -0
  77. package/dist/postiats-BfMp7zJL.js +907 -0
  78. package/dist/powerquery-B0TS_5Gb.js +890 -0
  79. package/dist/powershell-5jSbKdYB.js +239 -0
  80. package/dist/protobuf-YgnOutn3.js +420 -0
  81. package/dist/pug-DLej6kn5.js +402 -0
  82. package/dist/python-CQrZx9mR.js +301 -0
  83. package/dist/python.contribution-CcKs2Ktm.js +8 -0
  84. package/dist/qsharp-AhjqtSHB.js +301 -0
  85. package/dist/r-D-F4P80w.js +243 -0
  86. package/dist/razor-DWmpHMcx.js +550 -0
  87. package/dist/redis-hwwIlMnV.js +302 -0
  88. package/dist/redshift-Bcm_kjEG.js +809 -0
  89. package/dist/restructuredtext-CrdzfPP-.js +174 -0
  90. package/dist/ruby-QC2UNm1s.js +511 -0
  91. package/dist/rust-5aqiQ3L5.js +343 -0
  92. package/dist/sb-B1g1ZfLJ.js +115 -0
  93. package/dist/scala-C2U4R5Gb.js +370 -0
  94. package/dist/scheme-DeFRbslr.js +108 -0
  95. package/dist/scss-RSTCiCmI.js +262 -0
  96. package/dist/shell-BpF-iNu8.js +221 -0
  97. package/dist/shell.contribution-B80NZ3iO.js +7 -0
  98. package/dist/solidity-C00r2mbQ.js +1367 -0
  99. package/dist/sophia-DVW5ZKDB.js +199 -0
  100. package/dist/sparql-B0nmpxeX.js +201 -0
  101. package/dist/sql-CJwKPERn.js +853 -0
  102. package/dist/sql.contribution-DQy36aE5.js +7 -0
  103. package/dist/st-DPlKG5DT.js +416 -0
  104. package/dist/swift-YZBAbVHV.js +309 -0
  105. package/dist/systemverilog-CDQSaH63.js +576 -0
  106. package/dist/tcl-Dlu8sp6Q.js +232 -0
  107. package/dist/tsMode-Bh-v12OL.js +887 -0
  108. package/dist/twig-C5TO7-kw.js +392 -0
  109. package/dist/typescript-c7y6IZVP.js +343 -0
  110. package/dist/typespec-BsmjDEu7.js +117 -0
  111. package/dist/useFieldRendering-BIqeE3qo.js +6083 -0
  112. package/dist/vb-ChHvIDrk.js +372 -0
  113. package/dist/wgsl-XEp1ju8c.js +439 -0
  114. package/dist/xml-MAEprTnF.js +95 -0
  115. package/dist/xml.contribution-XMOaon8i.js +27 -0
  116. package/dist/yaml-C1p8rXG7.js +206 -0
  117. package/dist/yaml.contribution-DRRVhJmJ.js +8 -0
  118. package/package.json +88 -0
  119. package/src/__tests__/client-assigner.test.ts +341 -0
  120. package/src/__tests__/code-types.test.ts +30 -0
  121. package/src/__tests__/markdown-field.test.ts +34 -0
  122. package/src/__tests__/markdown-note-field.test.ts +135 -0
  123. package/src/__tests__/quiz-recorder.test.ts +195 -0
  124. package/src/__tests__/recorder-editor-content-sync.test.ts +172 -0
  125. package/src/__tests__/recorder-editor.test.ts +143 -0
  126. package/src/__tests__/recorder-render.test.ts +57 -0
  127. package/src/__tests__/recorder-wysiwyg-field-host.test.ts +33 -0
  128. package/src/__tests__/step-field.test.ts +270 -0
  129. package/src/__tests__/type-plugins.test.ts +59 -0
  130. package/src/__tests__/var-field-render.test.ts +26 -0
  131. package/src/client-assigner.ts +269 -0
  132. package/src/code-types.ts +94 -0
  133. package/src/components/AimdCodeField.vue +228 -0
  134. package/src/components/AimdDnaSequenceField.vue +983 -0
  135. package/src/components/AimdMarkdownField.vue +168 -0
  136. package/src/components/AimdMarkdownNoteField.vue +457 -0
  137. package/src/components/AimdQuizRecorder.vue +792 -0
  138. package/src/components/AimdRecorder.vue +1959 -0
  139. package/src/components/AimdRecorderEditor.vue +2281 -0
  140. package/src/components/AimdRecorderWysiwygFieldHost.vue +93 -0
  141. package/src/components/AimdRecorderWysiwygSurface.vue +487 -0
  142. package/src/components/AimdSeqVizViewer.vue +122 -0
  143. package/src/components/AimdStepCheckField.vue +453 -0
  144. package/src/components/AimdVarField.vue +213 -0
  145. package/src/components/AimdVarTableField.vue +516 -0
  146. package/src/components/DnaAnnotationEditor.vue +477 -0
  147. package/src/components/DnaSequenceEditor.vue +44 -0
  148. package/src/components/DnaSequenceToolbar.vue +98 -0
  149. package/src/components/DnaSequenceViewer.vue +162 -0
  150. package/src/components/index.ts +21 -0
  151. package/src/components/recorderMilkdownPlugin.ts +632 -0
  152. package/src/composables/__tests__/useDnaSequence.test.ts +467 -0
  153. package/src/composables/__tests__/useFieldAdapters.test.ts +115 -0
  154. package/src/composables/__tests__/useFocusManagement.test.ts +66 -0
  155. package/src/composables/__tests__/useRecordState.test.ts +586 -0
  156. package/src/composables/__tests__/useStepTimers.test.ts +64 -0
  157. package/src/composables/__tests__/useVarHelpers.test.ts +424 -0
  158. package/src/composables/__tests__/workbenchFieldEditing.test.ts +97 -0
  159. package/src/composables/index.ts +94 -0
  160. package/src/composables/useClientAssignerRunner.ts +74 -0
  161. package/src/composables/useDnaSequence.ts +400 -0
  162. package/src/composables/useDnaSequenceField.ts +316 -0
  163. package/src/composables/useFieldAdapters.ts +61 -0
  164. package/src/composables/useFieldRendering.ts +269 -0
  165. package/src/composables/useFocusManagement.ts +144 -0
  166. package/src/composables/useRecordState.ts +429 -0
  167. package/src/composables/useStepTimers.ts +243 -0
  168. package/src/composables/useVarHelpers.ts +545 -0
  169. package/src/composables/useVarTableDragDrop.ts +236 -0
  170. package/src/composables/workbenchFieldEditing.ts +705 -0
  171. package/src/css.d.ts +9 -0
  172. package/src/index.ts +65 -0
  173. package/src/locales.ts +559 -0
  174. package/src/monaco-code.ts +75 -0
  175. package/src/styles/aimd.css +994 -0
  176. package/src/type-plugins.ts +132 -0
  177. package/src/type-utils.ts +3 -0
  178. package/src/types.ts +191 -0
@@ -0,0 +1,400 @@
1
+ import type {
2
+ AimdDnaSequenceAnnotation,
3
+ AimdDnaSequenceQualifier,
4
+ AimdDnaSequenceSegment,
5
+ AimdDnaSequenceValue,
6
+ } from "../types"
7
+
8
+ export const AIMD_DNA_SEQUENCE_FORMAT = "airalogy_dna_v1" as const
9
+
10
+ const ALLOWED_DNA_CHARACTERS = new Set("ACGTRYSWKMBDHVN".split(""))
11
+ const GENBANK_MONTHS = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"] as const
12
+
13
+ function toPositiveInteger(value: unknown, fallback: number): number {
14
+ const text = typeof value === "string" ? value.trim() : String(value ?? "")
15
+ const parsed = Number.parseInt(text, 10)
16
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback
17
+ }
18
+
19
+ function toBoolean(value: unknown): boolean {
20
+ return value === true || value === "true" || value === 1 || value === "1"
21
+ }
22
+
23
+ function toStrand(value: unknown): 1 | -1 {
24
+ return value === -1 || value === "-1" ? -1 : 1
25
+ }
26
+
27
+ export function normalizeDnaSequenceText(value: unknown): string {
28
+ if (typeof value !== "string") {
29
+ return ""
30
+ }
31
+ return value.toUpperCase().replace(/\s+/g, "")
32
+ }
33
+
34
+ export function normalizeDnaSequenceName(value: unknown): string {
35
+ if (typeof value !== "string") {
36
+ return ""
37
+ }
38
+ return value.replace(/\s+/g, " ").trim()
39
+ }
40
+
41
+ export function collectInvalidDnaSequenceCharacters(sequence: string): string[] {
42
+ const invalid = new Set<string>()
43
+ for (const char of sequence.toUpperCase()) {
44
+ if (!ALLOWED_DNA_CHARACTERS.has(char)) {
45
+ invalid.add(char)
46
+ }
47
+ }
48
+ return [...invalid]
49
+ }
50
+
51
+ export function createEmptyDnaSequenceSegment(): AimdDnaSequenceSegment {
52
+ return {
53
+ start: 1,
54
+ end: 1,
55
+ partial_start: false,
56
+ partial_end: false,
57
+ }
58
+ }
59
+
60
+ export function createEmptyDnaSequenceQualifier(key = "note"): AimdDnaSequenceQualifier {
61
+ return {
62
+ key,
63
+ value: "",
64
+ }
65
+ }
66
+
67
+ export function createEmptyDnaSequenceAnnotation(id = "ann_1"): AimdDnaSequenceAnnotation {
68
+ return {
69
+ id,
70
+ name: "Feature",
71
+ type: "misc_feature",
72
+ strand: 1,
73
+ color: "#2563eb",
74
+ segments: [createEmptyDnaSequenceSegment()],
75
+ qualifiers: [],
76
+ }
77
+ }
78
+
79
+ export function getNextDnaSequenceAnnotationId(annotations: AimdDnaSequenceAnnotation[]): string {
80
+ const used = new Set(annotations.map(annotation => annotation.id))
81
+ let index = 1
82
+ while (used.has(`ann_${index}`)) {
83
+ index += 1
84
+ }
85
+ return `ann_${index}`
86
+ }
87
+
88
+ export function normalizeDnaSequenceSegment(value: unknown): AimdDnaSequenceSegment {
89
+ const fallback = createEmptyDnaSequenceSegment()
90
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
91
+ return fallback
92
+ }
93
+
94
+ const obj = value as Record<string, unknown>
95
+ const start = toPositiveInteger(obj.start, fallback.start)
96
+ const end = toPositiveInteger(obj.end, Math.max(start, fallback.end))
97
+
98
+ return {
99
+ start,
100
+ end,
101
+ partial_start: toBoolean(obj.partial_start),
102
+ partial_end: toBoolean(obj.partial_end),
103
+ }
104
+ }
105
+
106
+ export function normalizeDnaSequenceQualifier(
107
+ value: unknown,
108
+ index = 0,
109
+ ): AimdDnaSequenceQualifier {
110
+ const fallback = createEmptyDnaSequenceQualifier(index === 0 ? "note" : "qualifier")
111
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
112
+ return fallback
113
+ }
114
+
115
+ const obj = value as Record<string, unknown>
116
+ return {
117
+ key: typeof obj.key === "string" && obj.key.trim() ? obj.key.trim() : fallback.key,
118
+ value: typeof obj.value === "string" ? obj.value : String(obj.value ?? ""),
119
+ }
120
+ }
121
+
122
+ function normalizeLegacyQualifierValue(
123
+ key: string,
124
+ rawValue: unknown,
125
+ ): AimdDnaSequenceQualifier[] {
126
+ if (Array.isArray(rawValue)) {
127
+ return rawValue.map(item => ({
128
+ key,
129
+ value: typeof item === "string" ? item : String(item ?? ""),
130
+ }))
131
+ }
132
+
133
+ return [{
134
+ key,
135
+ value: typeof rawValue === "string" ? rawValue : String(rawValue ?? ""),
136
+ }]
137
+ }
138
+
139
+ function normalizeDnaSequenceQualifiers(
140
+ value: unknown,
141
+ legacyNote?: unknown,
142
+ ): AimdDnaSequenceQualifier[] {
143
+ const qualifiers: AimdDnaSequenceQualifier[] = []
144
+
145
+ if (Array.isArray(value)) {
146
+ qualifiers.push(...value.map((item, index) => normalizeDnaSequenceQualifier(item, index)))
147
+ }
148
+ else if (value && typeof value === "object") {
149
+ for (const [rawKey, rawValue] of Object.entries(value as Record<string, unknown>)) {
150
+ const key = rawKey.trim()
151
+ if (!key) continue
152
+ qualifiers.push(...normalizeLegacyQualifierValue(key, rawValue))
153
+ }
154
+ }
155
+
156
+ if (legacyNote !== undefined && legacyNote !== null && String(legacyNote).trim()) {
157
+ qualifiers.push({
158
+ key: "note",
159
+ value: typeof legacyNote === "string" ? legacyNote : String(legacyNote),
160
+ })
161
+ }
162
+
163
+ return qualifiers
164
+ }
165
+
166
+ export function normalizeDnaSequenceAnnotation(
167
+ value: unknown,
168
+ index = 0,
169
+ ): AimdDnaSequenceAnnotation {
170
+ const fallback = createEmptyDnaSequenceAnnotation(`ann_${index + 1}`)
171
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
172
+ return fallback
173
+ }
174
+
175
+ const obj = value as Record<string, unknown>
176
+ const segments = Array.isArray(obj.segments) && obj.segments.length > 0
177
+ ? obj.segments.map(segment => normalizeDnaSequenceSegment(segment))
178
+ : ("start" in obj || "end" in obj)
179
+ ? [normalizeDnaSequenceSegment({
180
+ start: obj.start,
181
+ end: obj.end,
182
+ partial_start: obj.partial_start,
183
+ partial_end: obj.partial_end,
184
+ })]
185
+ : fallback.segments
186
+
187
+ return {
188
+ id: typeof obj.id === "string" && obj.id.trim() ? obj.id.trim() : fallback.id,
189
+ name: typeof obj.name === "string" && obj.name.trim() ? obj.name.trim() : fallback.name,
190
+ type: typeof obj.type === "string" && obj.type.trim() ? obj.type.trim() : fallback.type,
191
+ strand: toStrand(obj.strand),
192
+ color: typeof obj.color === "string" && obj.color.trim() ? obj.color.trim() : fallback.color,
193
+ segments,
194
+ qualifiers: normalizeDnaSequenceQualifiers(obj.qualifiers, obj.note),
195
+ }
196
+ }
197
+
198
+ export function normalizeDnaSequenceValue(value: unknown): AimdDnaSequenceValue {
199
+ if (typeof value === "string") {
200
+ return {
201
+ format: AIMD_DNA_SEQUENCE_FORMAT,
202
+ name: "",
203
+ sequence: normalizeDnaSequenceText(value),
204
+ topology: "linear",
205
+ annotations: [],
206
+ }
207
+ }
208
+
209
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
210
+ return {
211
+ format: AIMD_DNA_SEQUENCE_FORMAT,
212
+ name: "",
213
+ sequence: "",
214
+ topology: "linear",
215
+ annotations: [],
216
+ }
217
+ }
218
+
219
+ const obj = value as Record<string, unknown>
220
+ return {
221
+ format: AIMD_DNA_SEQUENCE_FORMAT,
222
+ name: normalizeDnaSequenceName(obj.name),
223
+ sequence: normalizeDnaSequenceText(obj.sequence),
224
+ topology: obj.topology === "circular" ? "circular" : "linear",
225
+ annotations: Array.isArray(obj.annotations)
226
+ ? obj.annotations.map((annotation, index) => normalizeDnaSequenceAnnotation(annotation, index))
227
+ : [],
228
+ }
229
+ }
230
+
231
+ export function calculateDnaSequenceGcPercent(sequence: string): number | null {
232
+ let canonicalBases = 0
233
+ let gcBases = 0
234
+
235
+ for (const char of sequence.toUpperCase()) {
236
+ if (char === "A" || char === "T" || char === "C" || char === "G") {
237
+ canonicalBases += 1
238
+ if (char === "C" || char === "G") {
239
+ gcBases += 1
240
+ }
241
+ }
242
+ }
243
+
244
+ if (canonicalBases === 0) {
245
+ return null
246
+ }
247
+
248
+ return (gcBases / canonicalBases) * 100
249
+ }
250
+
251
+ export function getDnaSequenceSegmentIssue(
252
+ segment: AimdDnaSequenceSegment,
253
+ sequenceLength: number,
254
+ ): "requires_sequence" | "range" | "out_of_bounds" | null {
255
+ if (segment.end < segment.start) {
256
+ return "range"
257
+ }
258
+ if (sequenceLength <= 0) {
259
+ return "requires_sequence"
260
+ }
261
+ if (segment.end > sequenceLength) {
262
+ return "out_of_bounds"
263
+ }
264
+ return null
265
+ }
266
+
267
+ function sanitizeGenBankIdentifier(value: string): string {
268
+ const normalized = value.trim().replace(/\s+/g, "_").replace(/[^A-Za-z0-9_.-]/g, "_")
269
+ return normalized || "DNA_SEQUENCE"
270
+ }
271
+
272
+ function formatGenBankDate(date = new Date()): string {
273
+ const day = String(date.getDate()).padStart(2, "0")
274
+ const month = GENBANK_MONTHS[date.getMonth()] ?? "JAN"
275
+ const year = String(date.getFullYear())
276
+ return `${day}-${month}-${year}`
277
+ }
278
+
279
+ function wrapGenBankText(prefix: string, value: string, continuationPrefix = prefix, width = 79): string[] {
280
+ const normalized = value.replace(/\s+/g, " ").trim()
281
+ if (!normalized) {
282
+ return [prefix.trimEnd()]
283
+ }
284
+
285
+ const lines: string[] = []
286
+ let remaining = normalized
287
+ let currentPrefix = prefix
288
+
289
+ while (remaining.length > 0) {
290
+ const available = Math.max(width - currentPrefix.length, 12)
291
+ if (remaining.length <= available) {
292
+ lines.push(`${currentPrefix}${remaining}`)
293
+ break
294
+ }
295
+
296
+ let splitIndex = remaining.lastIndexOf(" ", available)
297
+ if (splitIndex <= 0) {
298
+ splitIndex = available
299
+ }
300
+
301
+ lines.push(`${currentPrefix}${remaining.slice(0, splitIndex)}`)
302
+ remaining = remaining.slice(splitIndex).trimStart()
303
+ currentPrefix = continuationPrefix
304
+ }
305
+
306
+ return lines
307
+ }
308
+
309
+ function formatGenBankSegmentLocation(segment: AimdDnaSequenceSegment): string {
310
+ const start = `${segment.partial_start ? "<" : ""}${segment.start}`
311
+ const end = `${segment.partial_end ? ">" : ""}${segment.end}`
312
+ return `${start}..${end}`
313
+ }
314
+
315
+ function formatGenBankAnnotationLocation(annotation: AimdDnaSequenceAnnotation): string {
316
+ const joined = annotation.segments.map(formatGenBankSegmentLocation).join(",")
317
+ const location = annotation.segments.length > 1 ? `join(${joined})` : joined
318
+ return annotation.strand === -1 ? `complement(${location})` : location
319
+ }
320
+
321
+ function formatGenBankQualifier(key: string, value: string): string[] {
322
+ const safeKey = key.trim() || "note"
323
+ const safeValue = value.replace(/"/g, "'").trim()
324
+ if (!safeValue) {
325
+ return [` /${safeKey}`]
326
+ }
327
+
328
+ return wrapGenBankText(
329
+ " ",
330
+ `/${safeKey}="${safeValue}"`,
331
+ " ",
332
+ )
333
+ }
334
+
335
+ function getExportQualifiers(annotation: AimdDnaSequenceAnnotation): AimdDnaSequenceQualifier[] {
336
+ const qualifiers = [...annotation.qualifiers]
337
+ const hasLabel = qualifiers.some(qualifier => qualifier.key.trim().toLowerCase() === "label")
338
+ if (!hasLabel && annotation.name.trim()) {
339
+ qualifiers.unshift({
340
+ key: "label",
341
+ value: annotation.name.trim(),
342
+ })
343
+ }
344
+ return qualifiers
345
+ }
346
+
347
+ export function serializeDnaSequenceToGenBank(
348
+ value: AimdDnaSequenceValue,
349
+ options?: {
350
+ name?: string
351
+ definition?: string
352
+ date?: Date
353
+ },
354
+ ): string {
355
+ const sequence = normalizeDnaSequenceText(value.sequence)
356
+ const rawName = normalizeDnaSequenceName(value.name) || normalizeDnaSequenceName(options?.name) || "DNA_SEQUENCE"
357
+ const locusName = sanitizeGenBankIdentifier(rawName)
358
+ const accession = locusName.slice(0, 16) || "DNA_SEQUENCE"
359
+ const topology = value.topology === "circular" ? "circular" : "linear"
360
+ const definition = options?.definition?.trim() || rawName || `${locusName} exported from Airalogy AIMD recorder.`
361
+ const locusLine = [
362
+ "LOCUS".padEnd(12, " "),
363
+ accession.padEnd(16, " "),
364
+ String(sequence.length).padStart(11, " "),
365
+ "bp".padEnd(6, " "),
366
+ "DNA".padEnd(8, " "),
367
+ topology.padEnd(9, " "),
368
+ formatGenBankDate(options?.date),
369
+ ].join("")
370
+
371
+ const lines: string[] = [
372
+ locusLine,
373
+ ...wrapGenBankText("DEFINITION ", definition, " "),
374
+ `ACCESSION ${accession}`,
375
+ `VERSION ${accession}.1`,
376
+ "KEYWORDS .",
377
+ "SOURCE synthetic construct",
378
+ " ORGANISM synthetic construct",
379
+ " other sequences; artificial sequences.",
380
+ "FEATURES Location/Qualifiers",
381
+ ]
382
+
383
+ for (const annotation of value.annotations) {
384
+ lines.push(` ${(annotation.type.trim() || "misc_feature").slice(0, 16).padEnd(16, " ")}${formatGenBankAnnotationLocation(annotation)}`)
385
+ for (const qualifier of getExportQualifiers(annotation)) {
386
+ lines.push(...formatGenBankQualifier(qualifier.key, qualifier.value))
387
+ }
388
+ }
389
+
390
+ lines.push("ORIGIN")
391
+
392
+ for (let index = 0; index < sequence.length; index += 60) {
393
+ const chunk = sequence.slice(index, index + 60).toLowerCase()
394
+ const grouped = chunk.match(/.{1,10}/g)?.join(" ") ?? chunk
395
+ lines.push(`${String(index + 1).padStart(9, " ")} ${grouped}`)
396
+ }
397
+
398
+ lines.push("//")
399
+ return `${lines.join("\n")}\n`
400
+ }
@@ -0,0 +1,316 @@
1
+ /**
2
+ * Pure helper logic extracted from AimdDnaSequenceField.
3
+ *
4
+ * Contains viewer-annotation ID helpers, selection/segment conversion,
5
+ * import/export utilities, and file-download logic. None of the functions
6
+ * here touch Vue reactivity — they are plain, testable functions.
7
+ */
8
+ import type {
9
+ AimdDnaSequenceAnnotation,
10
+ AimdDnaSequenceSegment,
11
+ AimdDnaSequenceValue,
12
+ } from "../types"
13
+ import {
14
+ collectInvalidDnaSequenceCharacters,
15
+ normalizeDnaSequenceName,
16
+ serializeDnaSequenceToGenBank,
17
+ } from "./useDnaSequence"
18
+
19
+ // ---- Types shared between sub-components ----
20
+
21
+ export type DnaEditorMode = "interactive" | "raw"
22
+
23
+ export interface ViewerAnnotation {
24
+ id: string
25
+ name: string
26
+ start: number
27
+ end: number
28
+ direction?: 1 | -1
29
+ color?: string
30
+ }
31
+
32
+ export interface ViewerSelection {
33
+ clockwise?: boolean
34
+ direction?: number
35
+ end?: number
36
+ id?: string
37
+ length?: number
38
+ name?: string
39
+ start?: number
40
+ type: string
41
+ viewer?: "LINEAR" | "CIRCULAR"
42
+ }
43
+
44
+ export interface ViewerExternalSelection {
45
+ clockwise?: boolean
46
+ end: number
47
+ start: number
48
+ }
49
+
50
+ // ---- Constants ----
51
+
52
+ export const VIEWER_ANNOTATION_PREFIX = "dna_annotation"
53
+
54
+ // ---- Viewer annotation ID helpers ----
55
+
56
+ export function buildViewerAnnotationId(annotationId: string, segmentIndex: number): string {
57
+ return `${VIEWER_ANNOTATION_PREFIX}:${annotationId}:${segmentIndex}`
58
+ }
59
+
60
+ export function parseViewerAnnotationId(id: string | undefined): { annotationId: string; segmentIndex: number } | null {
61
+ if (!id || !id.startsWith(`${VIEWER_ANNOTATION_PREFIX}:`)) {
62
+ return null
63
+ }
64
+
65
+ const [, annotationId = "", rawSegmentIndex = "0"] = id.split(":")
66
+ const segmentIndex = Number.parseInt(rawSegmentIndex, 10)
67
+ if (!annotationId || !Number.isFinite(segmentIndex) || segmentIndex < 0) {
68
+ return null
69
+ }
70
+
71
+ return {
72
+ annotationId,
73
+ segmentIndex,
74
+ }
75
+ }
76
+
77
+ // ---- Numeric guard ----
78
+
79
+ export function isFiniteNumber(value: unknown): value is number {
80
+ return typeof value === "number" && Number.isFinite(value)
81
+ }
82
+
83
+ // ---- Segment / Selection formatting & conversion ----
84
+
85
+ export function formatSegment(segment: AimdDnaSequenceSegment): string {
86
+ const start = segment.partial_start ? `<${segment.start}` : String(segment.start)
87
+ const end = segment.partial_end ? `>${segment.end}` : String(segment.end)
88
+ return `${start}..${end}`
89
+ }
90
+
91
+ export function annotationSegmentsLabel(annotation: AimdDnaSequenceAnnotation): string {
92
+ return annotation.segments.map(formatSegment).join(", ")
93
+ }
94
+
95
+ export function normalizeViewerSelection(value: unknown): ViewerSelection | null {
96
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
97
+ return null
98
+ }
99
+
100
+ const selection = value as Record<string, unknown>
101
+ const hasRange = isFiniteNumber(selection.start) && isFiniteNumber(selection.end)
102
+ const type = typeof selection.type === "string" && selection.type
103
+ ? selection.type
104
+ : hasRange
105
+ ? "SEQ"
106
+ : ""
107
+ if (!type) {
108
+ return null
109
+ }
110
+
111
+ return {
112
+ type,
113
+ clockwise: selection.clockwise === true,
114
+ direction: isFiniteNumber(selection.direction) ? selection.direction : undefined,
115
+ end: isFiniteNumber(selection.end) ? selection.end : undefined,
116
+ id: typeof selection.id === "string" ? selection.id : undefined,
117
+ length: isFiniteNumber(selection.length) ? selection.length : undefined,
118
+ name: typeof selection.name === "string" ? selection.name : undefined,
119
+ start: isFiniteNumber(selection.start) ? selection.start : undefined,
120
+ viewer: selection.viewer === "CIRCULAR" ? "CIRCULAR" : selection.viewer === "LINEAR" ? "LINEAR" : undefined,
121
+ }
122
+ }
123
+
124
+ export function createSegmentsFromSelection(
125
+ nextSelection: ViewerSelection | null,
126
+ topology: "linear" | "circular",
127
+ totalLength: number,
128
+ ): AimdDnaSequenceSegment[] {
129
+ if (!nextSelection || totalLength <= 0) {
130
+ return []
131
+ }
132
+
133
+ if (!isFiniteNumber(nextSelection.start) || !isFiniteNumber(nextSelection.end)) {
134
+ return []
135
+ }
136
+
137
+ const rawStart = Math.max(0, Math.min(nextSelection.start, totalLength - 1))
138
+ const rawEnd = Math.max(0, Math.min(nextSelection.end, totalLength))
139
+
140
+ if (rawEnd === rawStart) {
141
+ return []
142
+ }
143
+
144
+ if (topology === "circular" && rawEnd < rawStart) {
145
+ const segments: AimdDnaSequenceSegment[] = []
146
+
147
+ if (rawStart < totalLength) {
148
+ segments.push({
149
+ start: rawStart + 1,
150
+ end: totalLength,
151
+ partial_start: false,
152
+ partial_end: false,
153
+ })
154
+ }
155
+
156
+ if (rawEnd > 0) {
157
+ segments.push({
158
+ start: 1,
159
+ end: rawEnd,
160
+ partial_start: false,
161
+ partial_end: false,
162
+ })
163
+ }
164
+
165
+ return segments.filter(segment => segment.end >= segment.start)
166
+ }
167
+
168
+ const start = Math.min(rawStart, rawEnd)
169
+ const end = Math.max(rawStart, rawEnd)
170
+ return [{
171
+ start: start + 1,
172
+ end,
173
+ partial_start: false,
174
+ partial_end: false,
175
+ }]
176
+ }
177
+
178
+ export function createExternalSelectionFromSegment(segment: AimdDnaSequenceSegment): ViewerExternalSelection {
179
+ return {
180
+ start: Math.max(segment.start - 1, 0),
181
+ end: segment.end,
182
+ clockwise: true,
183
+ }
184
+ }
185
+
186
+ export function createExternalSelectionFromSelection(nextSelection: ViewerSelection | null): ViewerExternalSelection | null {
187
+ if (!nextSelection || !isFiniteNumber(nextSelection.start) || !isFiniteNumber(nextSelection.end)) {
188
+ return null
189
+ }
190
+
191
+ return {
192
+ start: nextSelection.start,
193
+ end: nextSelection.end,
194
+ clockwise: nextSelection.clockwise,
195
+ }
196
+ }
197
+
198
+ // ---- Viewer annotations builder ----
199
+
200
+ export function buildViewerAnnotations(
201
+ annotations: AimdDnaSequenceAnnotation[],
202
+ totalLength: number,
203
+ ): ViewerAnnotation[] {
204
+ const result: ViewerAnnotation[] = []
205
+
206
+ for (const annotation of annotations) {
207
+ annotation.segments.forEach((segment, segmentIndex) => {
208
+ const start = Math.max(segment.start - 1, 0)
209
+ const end = Math.min(segment.end, totalLength)
210
+ if (totalLength <= 0 || end <= start) {
211
+ return
212
+ }
213
+
214
+ result.push({
215
+ id: buildViewerAnnotationId(annotation.id, segmentIndex),
216
+ name: annotation.segments.length > 1
217
+ ? `${annotation.name} ${segmentIndex + 1}/${annotation.segments.length}`
218
+ : annotation.name,
219
+ start,
220
+ end,
221
+ direction: annotation.strand,
222
+ color: annotation.color,
223
+ })
224
+ })
225
+ }
226
+
227
+ return result
228
+ }
229
+
230
+ // ---- Import helpers ----
231
+
232
+ export function detectImportedTopology(text: string): "linear" | "circular" | null {
233
+ const normalized = text.replace(/\r\n?/g, "\n")
234
+ const locusLine = normalized.match(/(?:^|\n)LOCUS[^\n]*/i)?.[0]
235
+ if (!locusLine) {
236
+ return null
237
+ }
238
+ if (/\bcircular\b/i.test(locusLine)) {
239
+ return "circular"
240
+ }
241
+ if (/\blinear\b/i.test(locusLine)) {
242
+ return "linear"
243
+ }
244
+ return null
245
+ }
246
+
247
+ export function stripFileExtension(value: string): string {
248
+ return value.replace(/\.[^.]+$/, "")
249
+ }
250
+
251
+ export function detectImportedName(text: string, fallbackName = ""): string {
252
+ const normalized = text.replace(/\r\n?/g, "\n")
253
+ const locusMatch = normalized.match(/(?:^|\n)LOCUS\s+([^\s]+)/i)
254
+ if (locusMatch?.[1]) {
255
+ return normalizeDnaSequenceName(locusMatch[1])
256
+ }
257
+
258
+ const fastaMatch = normalized.match(/^\s*>(.+)$/m)
259
+ if (fastaMatch?.[1]) {
260
+ return normalizeDnaSequenceName(fastaMatch[1])
261
+ }
262
+
263
+ return normalizeDnaSequenceName(fallbackName)
264
+ }
265
+
266
+ export function normalizeImportedSequenceText(text: string): string {
267
+ const normalized = text.replace(/\r\n?/g, "\n")
268
+ const genBankMatch = normalized.match(/(?:^|\n)ORIGIN\b([\s\S]*?)(?:\n\/\/|\s*$)/i)
269
+ if (genBankMatch?.[1]) {
270
+ return genBankMatch[1].replace(/[^A-Za-z]/g, "").toUpperCase()
271
+ }
272
+
273
+ if (/^\s*>/m.test(normalized)) {
274
+ return normalized
275
+ .split("\n")
276
+ .filter(line => !line.trimStart().startsWith(">"))
277
+ .join("")
278
+ .replace(/[^A-Za-z]/g, "")
279
+ .toUpperCase()
280
+ }
281
+
282
+ return normalized.replace(/[^A-Za-z]/g, "").toUpperCase()
283
+ }
284
+
285
+ // ---- Export / download helpers ----
286
+
287
+ export function sanitizeDownloadBaseName(value: string): string {
288
+ const normalized = value.trim().replace(/\s+/g, "_").replace(/[^A-Za-z0-9_.-]/g, "_")
289
+ return normalized || "dna_sequence"
290
+ }
291
+
292
+ export function downloadGenBankFile(
293
+ sequenceValue: AimdDnaSequenceValue,
294
+ varId: string,
295
+ ): void {
296
+ if (sequenceValue.sequence.length <= 0 || typeof document === "undefined" || typeof URL === "undefined") {
297
+ return
298
+ }
299
+
300
+ const content = serializeDnaSequenceToGenBank(sequenceValue, {
301
+ name: sequenceValue.name || varId,
302
+ })
303
+ const blob = new Blob([content], {
304
+ type: "text/plain;charset=utf-8",
305
+ })
306
+ const objectUrl = URL.createObjectURL(blob)
307
+ const anchor = document.createElement("a")
308
+ anchor.href = objectUrl
309
+ anchor.download = `${sanitizeDownloadBaseName(sequenceValue.name || varId)}.gbk`
310
+ document.body.append(anchor)
311
+ anchor.click()
312
+ anchor.remove()
313
+ window.setTimeout(() => {
314
+ URL.revokeObjectURL(objectUrl)
315
+ }, 0)
316
+ }