firefly-compiler 0.4.6 → 0.4.8

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 (90) hide show
  1. package/compiler/Compiler.ff +2 -0
  2. package/compiler/Deriver.ff +7 -0
  3. package/core/Array.ff +17 -4
  4. package/core/AssetSystem.ff +1 -1
  5. package/core/BrowserSystem.ff +27 -0
  6. package/core/List.ff +4 -0
  7. package/core/Lock.ff +2 -2
  8. package/core/Random.ff +148 -0
  9. package/core/SourceLocation.ff +27 -0
  10. package/core/Task.ff +3 -0
  11. package/core/WebSocket.ff +127 -0
  12. package/httpserver/HttpServer.ff +1 -1
  13. package/lux/Css.ff +648 -0
  14. package/lux/CssTest.ff +48 -0
  15. package/lux/Lux.ff +33 -18
  16. package/lux/Main.ff +4 -1
  17. package/output/js/ff/compiler/Builder.mjs +448 -444
  18. package/output/js/ff/compiler/Compiler.mjs +420 -416
  19. package/output/js/ff/compiler/Dependencies.mjs +393 -389
  20. package/output/js/ff/compiler/Deriver.mjs +1178 -1170
  21. package/output/js/ff/compiler/Dictionaries.mjs +1315 -1309
  22. package/output/js/ff/compiler/Environment.mjs +1025 -1015
  23. package/output/js/ff/compiler/Inference.mjs +4272 -4268
  24. package/output/js/ff/compiler/JsEmitter.mjs +5405 -5391
  25. package/output/js/ff/compiler/JsImporter.mjs +270 -266
  26. package/output/js/ff/compiler/LspHook.mjs +799 -793
  27. package/output/js/ff/compiler/Main.mjs +1691 -1675
  28. package/output/js/ff/compiler/Parser.mjs +4016 -4008
  29. package/output/js/ff/compiler/Patterns.mjs +935 -927
  30. package/output/js/ff/compiler/Resolver.mjs +2311 -2307
  31. package/output/js/ff/compiler/Substitution.mjs +1154 -1150
  32. package/output/js/ff/compiler/Syntax.mjs +12566 -12434
  33. package/output/js/ff/compiler/Token.mjs +3152 -3096
  34. package/output/js/ff/compiler/Tokenizer.mjs +597 -593
  35. package/output/js/ff/compiler/Unification.mjs +1762 -1752
  36. package/output/js/ff/compiler/Wildcards.mjs +612 -608
  37. package/output/js/ff/compiler/Workspace.mjs +695 -687
  38. package/output/js/ff/core/Any.mjs +147 -143
  39. package/output/js/ff/core/Array.mjs +573 -547
  40. package/output/js/ff/core/AssetSystem.mjs +278 -274
  41. package/output/js/ff/core/Atomic.mjs +158 -154
  42. package/output/js/ff/core/Bool.mjs +156 -152
  43. package/output/js/ff/core/Box.mjs +116 -112
  44. package/output/js/ff/core/BrowserSystem.mjs +181 -126
  45. package/output/js/ff/core/Buffer.mjs +399 -395
  46. package/output/js/ff/core/BuildSystem.mjs +300 -296
  47. package/output/js/ff/core/Channel.mjs +193 -189
  48. package/output/js/ff/core/Char.mjs +153 -149
  49. package/output/js/ff/core/Core.mjs +304 -300
  50. package/output/js/ff/core/Duration.mjs +120 -116
  51. package/output/js/ff/core/Equal.mjs +183 -179
  52. package/output/js/ff/core/Error.mjs +146 -142
  53. package/output/js/ff/core/FileHandle.mjs +154 -150
  54. package/output/js/ff/core/Float.mjs +229 -225
  55. package/output/js/ff/core/HttpClient.mjs +195 -191
  56. package/output/js/ff/core/Instant.mjs +113 -109
  57. package/output/js/ff/core/Int.mjs +269 -265
  58. package/output/js/ff/core/IntMap.mjs +284 -280
  59. package/output/js/ff/core/JsSystem.mjs +242 -238
  60. package/output/js/ff/core/JsValue.mjs +712 -708
  61. package/output/js/ff/core/List.mjs +2346 -2334
  62. package/output/js/ff/core/Lock.mjs +235 -231
  63. package/output/js/ff/core/Log.mjs +167 -163
  64. package/output/js/ff/core/Map.mjs +366 -362
  65. package/output/js/ff/core/NodeSystem.mjs +298 -294
  66. package/output/js/ff/core/Nothing.mjs +108 -104
  67. package/output/js/ff/core/Option.mjs +1023 -1015
  68. package/output/js/ff/core/Ordering.mjs +734 -730
  69. package/output/js/ff/core/Pair.mjs +337 -331
  70. package/output/js/ff/core/Path.mjs +549 -545
  71. package/output/js/ff/core/Random.mjs +340 -0
  72. package/output/js/ff/core/RbMap.mjs +1944 -1940
  73. package/output/js/ff/core/Serializable.mjs +432 -428
  74. package/output/js/ff/core/Set.mjs +258 -254
  75. package/output/js/ff/core/Show.mjs +209 -205
  76. package/output/js/ff/core/SourceLocation.mjs +273 -229
  77. package/output/js/ff/core/Stack.mjs +533 -529
  78. package/output/js/ff/core/Stream.mjs +1308 -1304
  79. package/output/js/ff/core/String.mjs +369 -365
  80. package/output/js/ff/core/StringMap.mjs +284 -280
  81. package/output/js/ff/core/Task.mjs +325 -319
  82. package/output/js/ff/core/Try.mjs +511 -507
  83. package/output/js/ff/core/Unit.mjs +155 -151
  84. package/output/js/ff/core/WebSocket.mjs +198 -0
  85. package/package.json +1 -1
  86. package/vscode/package.json +1 -1
  87. package/webserver/.firefly/include/package-lock.json +16 -0
  88. package/webserver/.firefly/include/package.json +5 -0
  89. package/webserver/.firefly/package.ff +2 -0
  90. package/webserver/WebServer.ff +608 -0
package/lux/CssTest.ff ADDED
@@ -0,0 +1,48 @@
1
+ import Lux
2
+ import LuxEvent
3
+ import Css
4
+ import HttpServer from ff:httpserver
5
+
6
+ mainComponent(lux: Lux, system: BrowserSystem) {
7
+ let redCss = CssClass([Css.color("red")], [], [])
8
+ let blueCss = CssClass([Css.color("blue")], [], [])
9
+
10
+ lux.useState(False): start, setStart =>
11
+ lux.div {
12
+ lux.cssClass(if(start) {redCss} else {blueCss})
13
+ lux.div {
14
+ lux.text(if(start) {"Start"} else {"Stop"})
15
+ lux.onClick {event =>
16
+ event.preventDefault()
17
+ setStart(!start)
18
+ }
19
+ }
20
+ }
21
+ }
22
+
23
+ browserMain(system: BrowserSystem) {
24
+ Lux.renderById(system, "main") {lux => mainComponent(lux, system)}
25
+ }
26
+
27
+ nodeMain(system: NodeSystem) {
28
+ let openAiKey = system.arguments().first()
29
+ HttpServer.listen(system, "localhost", 8080) {request, response =>
30
+ if(request.path() == "/") {
31
+ response.setHeader("Content-Type", ["text/html; charset=UTF-8"])
32
+ response.writeText("<!doctype html>")
33
+ response.writeText("<div id='main'></div>")
34
+ response.writeText("<script type='module' src='/js/script/script/CssTest.mjs'></script>")
35
+ } elseIf {request.path().startsWith("/js/") && !request.path().contains("..")} {
36
+ response.setHeader("Content-Type", ["text/javascript; charset=UTF-8"])
37
+ response.writeText(system.assets().readText(request.path()))
38
+ } else {
39
+ response.writeStatus(404, Some("Not found"))
40
+ }
41
+ }
42
+ }
43
+
44
+ buildMain(system: BuildSystem) {
45
+ let browser = system.compileForBrowser("CssTest.ff")
46
+ let assets = AssetSystem.create().addAssets("/js", browser.assets())
47
+ system.setAssets(assets)
48
+ }
package/lux/Lux.ff CHANGED
@@ -1,9 +1,11 @@
1
1
  import Lux
2
2
  import LuxEvent
3
+ import Css
3
4
 
4
5
  capability Lux(
5
6
  document: LuxDocument
6
7
  jsSystem: JsSystem
8
+ mutable cssClasses: StringMap[CssClass]
7
9
  mutable renderLock: Lock
8
10
  mutable task: Task
9
11
  mutable renderQueue: Stack[RenderQueueItem]
@@ -89,6 +91,7 @@ extend self: Lux {
89
91
  let savedElement = self.element
90
92
  self.attributes = None
91
93
  self.element = LuxElement(node, 0, keepChildren = False)
94
+ self.element.element.get("classList").set("value", "")
92
95
  self.key = ""
93
96
  self.depth += 1
94
97
  try {
@@ -143,43 +146,40 @@ extend self: Lux {
143
146
  }
144
147
 
145
148
  setId(value: String) {self.set("id", value)}
146
- setClassName(value: String) {self.set("className", value)}
147
- setStyle(value: String) {self.set("style", value)}
148
149
 
149
150
  setValue(value: String) { // TODO: Not an attribute
150
151
  self.element.element.set("value", value)
151
152
  }
152
153
 
153
- css(key: String, value: String) {
154
+ css(style: Css) {
154
155
  let attributes = self.attributes.else {
155
156
  let map = StringMap.make()
156
157
  self.attributes = Some(map)
157
158
  map
158
159
  }
159
160
  if(attributes.has("style")) {
160
- attributes.set("style", attributes.grab("style") + ";" + key + ":" + value)
161
+ attributes.set("style", attributes.grab("style") + ";" + style.property + ":" + style.value)
161
162
  } else {
162
- attributes.set("style", key + ":" + value)
163
+ attributes.set("style", style.property + ":" + style.value)
163
164
  }
164
165
  }
165
166
 
166
- cssColor(value: String) {self.css("color", value)}
167
-
167
+ cssClass(class: CssClass) {
168
+ if(!self.cssClasses.has(class.name())) {
169
+ self.cssClasses.set(class.name(), class)
170
+ let styleSheet = self.document.createElement("style")
171
+ styleSheet.set("textContent", class.show())
172
+ self.document.document.get("head").call1("appendChild", styleSheet)
173
+ }
174
+ self.element.element.get("classList").call1("add", class.name())
175
+ self.set("class", self.element.element.get("className").grabString())
176
+ }
177
+
168
178
  on(event: String, handler: LuxEvent => Unit) {
169
179
  let jsHandler = unsafeAsyncFunction1ToJs(self) {jsEvent =>
170
180
  self.renderLock.do(reentrant = False) {
171
181
  handler(unsafeJsToValue(jsEvent))
172
- self.renderQueue.sortBy {-_.luxCopy.depth}
173
- let newLux = self.Lux(element = self.element.LuxElement())
174
- try {
175
- while {!self.renderQueue.isEmpty()} {
176
- let item = self.renderQueue.pop().grab()
177
- self.copyFrom(item.luxCopy)
178
- item.render()
179
- }
180
- } finally {
181
- self.copyFrom(newLux)
182
- } grab()
182
+ processRenderQueue(self)
183
183
  }
184
184
  }
185
185
  self.element.element.call2("addEventListener", event, jsHandler)
@@ -319,6 +319,20 @@ extend self: Lux {
319
319
 
320
320
  }
321
321
 
322
+ processRenderQueue(self: Lux) {
323
+ self.renderQueue.sortBy {-_.luxCopy.depth}
324
+ let newLux = self.Lux(element = self.element.LuxElement())
325
+ try {
326
+ while {!self.renderQueue.isEmpty()} {
327
+ let item = self.renderQueue.pop().grab()
328
+ self.copyFrom(item.luxCopy)
329
+ item.render()
330
+ }
331
+ } finally {
332
+ self.copyFrom(newLux)
333
+ } grab()
334
+ }
335
+
322
336
  removeCurrentChild(self: Lux): Bool {
323
337
  let child = self.element.childAt(self.element.child)
324
338
  if(!child.isNullOrUndefined() && !child.get("children").isNullOrUndefined()) {
@@ -453,6 +467,7 @@ render(browserSystem: BrowserSystem, element: JsValue, body: Lux => Unit) {
453
467
  let lux = Lux(
454
468
  jsSystem = browserSystem.js()
455
469
  renderLock = browserSystem.mainTask().lock()
470
+ cssClasses = StringMap.make()
456
471
  task = browserSystem.mainTask()
457
472
  depth = 0
458
473
  document = LuxDocument(document)
package/lux/Main.ff CHANGED
@@ -2,6 +2,7 @@ import HttpServer from ff:httpserver
2
2
 
3
3
  import Lux
4
4
  import LuxEvent
5
+ import Css
5
6
 
6
7
  data ChatEntry(
7
8
  question: String
@@ -30,9 +31,11 @@ mainComponent(lux: Lux, http: HttpClient) {
30
31
  }
31
32
  }
32
33
 
34
+ questionCss = CssClass([Css.marginBottom("10px")], [], [])
35
+
33
36
  questionComponent(lux: Lux, http: HttpClient, question: String) {
34
37
  lux.div {
35
- //.with("style", "margin-bottom: 10px")
38
+ lux.cssClass(questionCss)
36
39
  lux.div {lux.text("User: " + question)}
37
40
  lux.useLazy1(question): _ =>
38
41
  lux.useSuspense {lux.div {lux.text("Assistant typing...")}}: lux =>