@lvce-editor/shared-process 0.10.0 → 0.10.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.
@@ -14,6 +14,7 @@ export const State = {
14
14
  AfterQuery: 10,
15
15
  InsideRound: 11,
16
16
  AfterQueryWithRules: 12,
17
+ InsideRule: 13,
17
18
  }
18
19
 
19
20
  export const StateMap = {
@@ -60,7 +61,7 @@ export const TokenMap = {
60
61
  [TokenType.CurlyClose]: 'Punctuation',
61
62
  [TokenType.PropertyColon]: 'Punctuation',
62
63
  [TokenType.CssPropertySemicolon]: 'Punctuation',
63
- [TokenType.Variable]: 'Variable',
64
+ [TokenType.Variable]: 'VariableName',
64
65
  [TokenType.None]: 'None',
65
66
  [TokenType.CssPropertyValue]: 'CssPropertyValue',
66
67
  [TokenType.Unknown]: 'Unknown',
@@ -68,12 +69,12 @@ export const TokenMap = {
68
69
  [TokenType.Numeric]: 'Numeric',
69
70
  [TokenType.NewLine]: 'NewLine',
70
71
  [TokenType.Comment]: 'Comment',
71
- [TokenType.Query]: 'Query',
72
+ [TokenType.Query]: 'CssAtRule',
72
73
  [TokenType.Text]: 'Text',
73
74
  [TokenType.CssSelectorId]: 'CssSelectorId',
74
75
  }
75
76
 
76
- const RE_SELECTOR = /^[\.a-zA-Z\d\-\:>\+\~]+/
77
+ const RE_SELECTOR = /^[\.a-zA-Z\d\-\:>\+\~\_%]+/
77
78
  const RE_SELECTOR_ID = /^#\w+/
78
79
  const RE_WHITESPACE = /^ +/
79
80
  const RE_CURLY_OPEN = /^\{/
@@ -151,17 +152,19 @@ export const tokenizeLine = (line, lineState) => {
151
152
  token = TokenType.Punctuation
152
153
  state = State.InsideAttributeSelector
153
154
  } else if ((next = part.match(RE_QUERY))) {
154
- if (
155
- next[0] === '@font-face' ||
156
- next[0] === '@-ms-viewport' ||
157
- next[0] === '@-o-viewport' ||
158
- next[0] === '@viewport'
159
- ) {
160
- token = TokenType.Query
161
- state = State.AfterQueryWithRules
162
- } else {
163
- token = TokenType.Query
164
- state = State.AfterQuery
155
+ switch (next[0]) {
156
+ case '@font-face':
157
+ case '@-ms-viewport':
158
+ case '@-o-viewport':
159
+ case '@viewport':
160
+ token = TokenType.Query
161
+ state = State.AfterQueryWithRules
162
+ break
163
+ case '@keyframes':
164
+ default:
165
+ token = TokenType.Query
166
+ state = State.AfterQuery
167
+ break
165
168
  }
166
169
  } else if ((next = part.match(RE_STAR))) {
167
170
  token = TokenType.CssSelector
@@ -238,7 +241,7 @@ export const tokenizeLine = (line, lineState) => {
238
241
  case State.InsideBlockComment:
239
242
  if ((next = part.match(RE_BLOCK_COMMENT_END))) {
240
243
  token = TokenType.Comment
241
- state = State.TopLevelContent
244
+ state = stack.pop() || State.TopLevelContent
242
245
  } else if ((next = part.match(RE_BLOCK_COMMENT_CONTENT))) {
243
246
  token = TokenType.Comment
244
247
  state = State.InsideBlockComment
@@ -257,6 +260,10 @@ export const tokenizeLine = (line, lineState) => {
257
260
  if (next[0].startsWith('--')) {
258
261
  token = TokenType.Variable
259
262
  }
263
+ } else if ((next = part.match(RE_BLOCK_COMMENT_START))) {
264
+ token = TokenType.Comment
265
+ state = State.InsideBlockComment
266
+ stack.push(State.InsideSelector)
260
267
  } else if ((next = part.match(RE_ANYTHING_UNTIL_CLOSE_BRACE))) {
261
268
  token = TokenType.Unknown
262
269
  state = State.InsideSelector
@@ -85,6 +85,7 @@ const RE_COMMA = /^,/
85
85
  const RE_COLON = /^:/
86
86
  const RE_NUMERIC =
87
87
  /^((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)\b/
88
+ const RE_NUMERIC_OCTAL = /0(?:o|O)?[0-7][0-7_]*(n)?\b/
88
89
  const RE_LINE_COMMENT_START = /^\/\//
89
90
  const RE_LINE_COMMENT_CONTENT = /^[^\n]+/
90
91
  const RE_NEWLINE_WHITESPACE = /^\n\s*/
@@ -94,14 +95,14 @@ const RE_BLOCK_COMMENT_END = /^\*\//
94
95
  const RE_UNKNOWN_VALUE = /^[^\}\{\s,"]+/
95
96
  const RE_IMPORT = /^[a-zA-Z\.]+/
96
97
  const RE_SEMICOLON = /^;/
97
- const RE_VARIABLE_NAME = /^[a-zA-Z_][a-zA-Z\d\_]*/
98
+ const RE_VARIABLE_NAME = /^[a-zA-Z_$][a-zA-Z\d\_]*/
98
99
  const RE_LINE_COMMENT = /^\/\/[^\n]*/
99
100
  const RE_ROUND_OPEN = /^\(/
100
101
  const RE_ROUND_CLOSE = /^\)/
101
102
  const RE_DOT = /^\./
102
103
  const RE_EQUAL_SIGN = /^=/
103
104
  const RE_SINGLE_QUOTE = /^'/
104
- const RE_PUNCTUATION = /^[\(\)=\+\-><\.:;\{\}\[\]!,&\|\^\?\*]/
105
+ const RE_PUNCTUATION = /^[\(\)=\+\-><\.:;\{\}\[\]!,&\|\^\?\*%]/
105
106
  const RE_SLASH = /^\//
106
107
  const RE_ANYTHING_UNTIL_END = /^.+/s
107
108
  const RE_WHITESPACE = /^\s+/
@@ -198,7 +199,7 @@ export const tokenizeLine = (line, lineState) => {
198
199
  token = TokenType.Comment
199
200
  state = State.InsideLineComment
200
201
  } else {
201
- next = part.match(RE_PUNCTUATION)
202
+ next = part.match(RE_SLASH)
202
203
  token = TokenType.Punctuation
203
204
  state = State.TopLevelContent
204
205
  }
@@ -211,6 +212,9 @@ export const tokenizeLine = (line, lineState) => {
211
212
  } else if ((next = part.match(RE_QUOTE_BACKTICK))) {
212
213
  token = TokenType.Punctuation
213
214
  state = State.InsideBacktickString
215
+ } else if ((next = part.match(RE_NUMERIC_OCTAL))) {
216
+ token = TokenType.Numeric
217
+ state = State.TopLevelContent
214
218
  } else {
215
219
  line.slice(0, index) //?
216
220
  part //?
@@ -93,8 +93,10 @@ const RE_ANYTHING = /^.+/s
93
93
  const RE_NUMERIC =
94
94
  /^((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)\b/
95
95
  const RE_TEXT = /^[^\s\{\}\[\]]+/
96
- const RE_ESCAPED_QUOTE = /^\\"/
97
- const RE_BACK_SLASH = /^\\/
96
+ // const RE_ESCAPED_QUOTE = /^\\"/
97
+ // const RE_BACK_SLASH = /^\\/
98
+ const RE_STRING_ESCAPE = /^\\.?/
99
+ const RE_WORD = /^\w+/
98
100
 
99
101
  export const initialLineState = {
100
102
  state: State.TopLevelContent,
@@ -165,7 +167,6 @@ export const tokenizeLine = (line, lineState) => {
165
167
  }
166
168
  break
167
169
  case State.AfterCurlyOpen:
168
- part
169
170
  if ((next = part.match(RE_WHITESPACE))) {
170
171
  token = TokenType.Whitespace
171
172
  state = State.AfterCurlyOpen
@@ -182,6 +183,12 @@ export const tokenizeLine = (line, lineState) => {
182
183
  } else if ((next = part.match(RE_LINE_COMMENT))) {
183
184
  token = TokenType.Comment
184
185
  state = State.AfterCurlyOpen
186
+ } else if ((next = part.match(RE_WORD))) {
187
+ token = TokenType.Text
188
+ state = State.AfterPropertyName
189
+ } else if ((next = part.match(RE_ANYTHING))) {
190
+ token = TokenType.Text
191
+ state = State.AfterCurlyOpen
185
192
  } else {
186
193
  part //?
187
194
  throw new Error('no')
@@ -195,10 +202,7 @@ export const tokenizeLine = (line, lineState) => {
195
202
  token = TokenType.Punctuation
196
203
  state = stack.pop()
197
204
  state
198
- } else if ((next = part.match(RE_ESCAPED_QUOTE))) {
199
- token = TokenType.JsonPropertyName
200
- state = State.InsidePropertyNameString
201
- } else if ((next = part.match(RE_BACK_SLASH))) {
205
+ } else if ((next = part.match(RE_STRING_ESCAPE))) {
202
206
  token = TokenType.JsonPropertyName
203
207
  state = State.InsidePropertyNameString
204
208
  } else {
@@ -212,10 +216,7 @@ export const tokenizeLine = (line, lineState) => {
212
216
  } else if ((next = part.match(RE_DOUBLE_QUOTE))) {
213
217
  token = TokenType.Punctuation
214
218
  state = stack.pop()
215
- } else if ((next = part.match(RE_ESCAPED_QUOTE))) {
216
- token = TokenType.String
217
- state = State.InsideString
218
- } else if ((next = part.match(RE_BACK_SLASH))) {
219
+ } else if ((next = part.match(RE_STRING_ESCAPE))) {
219
220
  token = TokenType.String
220
221
  state = State.InsideString
221
222
  } else {
@@ -239,7 +240,6 @@ export const tokenizeLine = (line, lineState) => {
239
240
  }
240
241
  break
241
242
  case State.AfterPropertyNameAfterColon:
242
- part
243
243
  if ((next = part.match(RE_WHITESPACE))) {
244
244
  token = TokenType.Whitespace
245
245
  state = State.AfterPropertyNameAfterColon
@@ -38,6 +38,8 @@ export const TokenType = {
38
38
  String: 188,
39
39
  YamlPropertyName: 123,
40
40
  YamlPropertyValueString: 124,
41
+ Alias: 125,
42
+ Anchor: 126,
41
43
  }
42
44
 
43
45
  export const TokenMap = {
@@ -55,6 +57,8 @@ export const TokenMap = {
55
57
  [TokenType.String]: 'String',
56
58
  [TokenType.YamlPropertyName]: 'YamlPropertyName',
57
59
  [TokenType.YamlPropertyValueString]: 'YamlPropertyValueString',
60
+ [TokenType.Alias]: 'VariableName',
61
+ [TokenType.Anchor]: 'VariableName',
58
62
  }
59
63
 
60
64
  const RE_LINE_COMMENT_START = /^#/
@@ -64,7 +68,7 @@ const RE_CURLY_CLOSE = /^\}/
64
68
  const RE_PROPERTY_NAME = /^[\:@\/\\a-zA-Z\-\_\d\.]+(?=\s*:(\s+|$))/
65
69
  const RE_PROPERTY_NAME_2 =
66
70
  /^[\:@\/\\a-zA-Z\-\_\d\.\s]*[@\/\\a-zA-Z\-\_\d\.](?=\s*:(\s+|$))/
67
- const RE_PROPERTY_VALUE_1 = /^.+(?=\s+#)/s
71
+ const RE_PROPERTY_VALUE_1 = /^[^&].*(?=\s+#)/s
68
72
  const RE_SEMICOLON = /^;/
69
73
  const RE_COMMA = /^,/
70
74
  const RE_ANYTHING = /^.+/s
@@ -93,6 +97,9 @@ const RE_MULTI_LINE_STRING_START = /^(?:\||>\-|>)/
93
97
  const RE_KEY_PRE = /^\s*(\-\s*)?/
94
98
  const RE_SINGLE_QUOTE = /^'/
95
99
  const RE_STRING_SINGLE_QUOTE_CONTENT = /^[^']+/
100
+ const RE_ALIAS = /^\*.+/
101
+ const RE_ANCHOR = /^\&.+/
102
+ const RE_MERGE_KEY = /^<<\:(?=\s)/
96
103
 
97
104
  export const initialLineState = {
98
105
  state: State.TopLevelContent,
@@ -158,6 +165,9 @@ export const tokenizeLine = (line, lineState) => {
158
165
  } else if ((next = part.match(RE_SINGLE_QUOTE))) {
159
166
  token = TokenType.Punctuation
160
167
  state = State.InsidePropertyNameString
168
+ } else if ((next = part.match(RE_MERGE_KEY))) {
169
+ token = TokenType.Punctuation
170
+ state = State.AfterPropertyNameAfterColon
161
171
  } else if ((next = part.match(RE_ANYTHING))) {
162
172
  token = TokenType.Text
163
173
  state = State.TopLevelContent
@@ -204,6 +214,9 @@ export const tokenizeLine = (line, lineState) => {
204
214
  } else if ((next = part.match(RE_PROPERTY_VALUE_1))) {
205
215
  token = TokenType.YamlPropertyValueString
206
216
  state = State.AfterPropertyValue
217
+ } else if ((next = part.match(RE_ANCHOR))) {
218
+ token = TokenType.Anchor
219
+ state = State.AfterPropertyNameAfterColon
207
220
  } else if ((next = part.match(RE_ANYTHING))) {
208
221
  token = TokenType.YamlPropertyValueString
209
222
  state = State.TopLevelContent
@@ -247,6 +260,9 @@ export const tokenizeLine = (line, lineState) => {
247
260
  } else if ((next = part.match(RE_MULTI_LINE_STRING_START))) {
248
261
  token = TokenType.Punctuation
249
262
  state = State.AfterPipe
263
+ } else if ((next = part.match(RE_ALIAS))) {
264
+ token = TokenType.Alias
265
+ state = State.TopLevelContent
250
266
  } else if ((next = part.match(RE_ANYTHING))) {
251
267
  token = TokenType.YamlPropertyValueString
252
268
  state = State.TopLevelContent
@@ -309,6 +325,9 @@ export const tokenizeLine = (line, lineState) => {
309
325
  } else if ((next = part.match(RE_DASH))) {
310
326
  token = TokenType.Punctuation
311
327
  state = State.AfterDash
328
+ } else if ((next = part.match(RE_LINE_COMMENT_START))) {
329
+ token = TokenType.Comment
330
+ state = State.InsideLineComment
312
331
  } else if ((next = part.match(RE_ANYTHING))) {
313
332
  token = TokenType.Text
314
333
  state = State.TopLevelContent
@@ -85,6 +85,10 @@
85
85
  "name": "CssSelector",
86
86
  "foreground": "#BEB558"
87
87
  },
88
+ {
89
+ "name": "CssSelectorId",
90
+ "foreground": "#BE7C81"
91
+ },
88
92
  {
89
93
  "name": "CssPropertyValue",
90
94
  "foreground": "#C0C0C3"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/shared-process",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -20,8 +20,8 @@
20
20
  "node": ">=16"
21
21
  },
22
22
  "dependencies": {
23
- "@lvce-editor/extension-host": "0.10.0",
24
- "@lvce-editor/pty-host": "0.10.0",
23
+ "@lvce-editor/extension-host": "0.10.1",
24
+ "@lvce-editor/pty-host": "0.10.1",
25
25
  "debug": "^4.3.4",
26
26
  "execa": "^6.1.0",
27
27
  "exit-hook": "^3.1.0",
@@ -10,6 +10,10 @@ const readExtensionManifest = (path) => {
10
10
  return { ...JSON.parse(content), path }
11
11
  }
12
12
 
13
+ const getThemeName = (dirent) => {
14
+ return dirent.slice('builtin.theme-'.length)
15
+ }
16
+
13
17
  /**
14
18
  *
15
19
  * @param {{root:string, pathPrefix:string }} param0
@@ -25,13 +29,21 @@ export const exportStatic = async ({ root, pathPrefix }) => {
25
29
  const commitHash = dirents.find(isCommitHash) || ''
26
30
 
27
31
  const extensionJson = readExtensionManifest(join(root, 'extension.json'))
28
- const name = extensionJson.id.slice('builtin.theme-'.length)
32
+ const colorThemeName = extensionJson.id.slice('builtin.theme-'.length)
33
+ const name = extensionJson.name || extensionJson.id || ''
34
+ const description = extensionJson.description || ''
29
35
  fs.rmSync(join(root, 'dist'), { recursive: true, force: true })
30
36
 
31
37
  fs.mkdirSync(path.join(root, 'dist'))
32
38
 
33
39
  fs.mkdirSync(
34
- join(root, 'dist', commitHash, 'extensions', `builtin.theme-${name}`),
40
+ join(
41
+ root,
42
+ 'dist',
43
+ commitHash,
44
+ 'extensions',
45
+ `builtin.theme-${colorThemeName}`
46
+ ),
35
47
  {
36
48
  recursive: true,
37
49
  }
@@ -187,7 +199,7 @@ export const exportStatic = async ({ root, pathPrefix }) => {
187
199
  replaceSync(
188
200
  join(root, 'dist', commitHash, 'config', 'defaultSettings.json'),
189
201
  `"workbench.colorTheme": "slime"`,
190
- `"workbench.colorTheme": "${name}"`
202
+ `"workbench.colorTheme": "${colorThemeName}"`
191
203
  )
192
204
  replaceSync(
193
205
  join(root, 'dist', commitHash, 'config', 'defaultSettings.json'),
@@ -267,10 +279,6 @@ export const exportStatic = async ({ root, pathPrefix }) => {
267
279
  )
268
280
  }
269
281
 
270
- const getThemeName = (dirent) => {
271
- return dirent.slice('builtin.theme-'.length)
272
- }
273
-
274
282
  for (const themeDirent of themeDirents) {
275
283
  const themeId = getThemeName(themeDirent)
276
284
  cpSync(
@@ -312,7 +320,7 @@ export const exportStatic = async ({ root, pathPrefix }) => {
312
320
  return sorted
313
321
  }
314
322
 
315
- const themeIds = mergeThemes(themeDirents.map(getThemeName), [name])
323
+ const themeIds = mergeThemes(themeDirents.map(getThemeName), [colorThemeName])
316
324
  writeJson(join(root, 'dist', commitHash, 'config', 'themes.json'), themeIds)
317
325
 
318
326
  for (const iconThemeDirent of iconThemeDirents) {
@@ -348,7 +356,7 @@ export const exportStatic = async ({ root, pathPrefix }) => {
348
356
 
349
357
  cpSync(
350
358
  join(root, 'color-theme.json'),
351
- join(root, 'dist', commitHash, 'themes', `${name}.json`)
359
+ join(root, 'dist', commitHash, 'themes', `${colorThemeName}.json`)
352
360
  )
353
361
  replaceSync(
354
362
  join(root, 'dist', 'index.html'),
@@ -360,11 +368,36 @@ export const exportStatic = async ({ root, pathPrefix }) => {
360
368
  `/manifest.json`,
361
369
  `${pathPrefix}/manifest.json`
362
370
  )
371
+ replaceSync(
372
+ join(root, 'dist', 'index.html'),
373
+ '<title>Code Editor</title>',
374
+ `<title>${name}</title>`
375
+ )
376
+ replaceSync(
377
+ join(root, 'dist', 'manifest.json'),
378
+ `"name": "Code Editor Web - OSS"`,
379
+ `"name": "${name}"`
380
+ )
381
+ replaceSync(
382
+ join(root, 'dist', 'manifest.json'),
383
+ `"short_name": "Web - OSS"`,
384
+ `"short_name": "${name}"`
385
+ )
386
+ replaceSync(
387
+ join(root, 'dist', 'manifest.json'),
388
+ `"description": "Web Code Editor."`,
389
+ `"description": "${description}"`
390
+ )
391
+ replaceSync(
392
+ join(root, 'dist', 'index.html'),
393
+ '<meta name="description" content="Online Code Editor" />',
394
+ `<meta name="description" content="${description}" />`
395
+ )
363
396
  replaceSync(
364
397
  join(root, 'dist', 'index.html'),
365
398
  '</title>',
366
399
  `</title>
367
- <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">`
400
+ <link rel="shortcut icon" type="image/x-icon" href="favicon.ico">`
368
401
  )
369
402
  replaceSync(
370
403
  join(root, 'dist', 'manifest.json'),
@@ -379,7 +412,7 @@ export const exportStatic = async ({ root, pathPrefix }) => {
379
412
  'dist',
380
413
  commitHash,
381
414
  'extensions',
382
- `builtin.theme-${name}`,
415
+ `builtin.theme-${colorThemeName}`,
383
416
  'README.md'
384
417
  )
385
418
  )
@@ -390,7 +423,7 @@ export const exportStatic = async ({ root, pathPrefix }) => {
390
423
  'dist',
391
424
  commitHash,
392
425
  'extensions',
393
- `builtin.theme-${name}`,
426
+ `builtin.theme-${colorThemeName}`,
394
427
  'extension.json'
395
428
  )
396
429
  )
@@ -401,7 +434,7 @@ export const exportStatic = async ({ root, pathPrefix }) => {
401
434
  'dist',
402
435
  commitHash,
403
436
  'extensions',
404
- `builtin.theme-${name}`,
437
+ `builtin.theme-${colorThemeName}`,
405
438
  'color-theme.json'
406
439
  )
407
440
  )