@edadma/logo 0.2.4 → 0.2.6
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.
- package/dist/main.js +13194 -13042
- package/dist/main.js.map +4 -4
- package/package.json +1 -1
- package/src/main/scala/io/github/edadma/logo/LogoJS.scala +65 -21
package/package.json
CHANGED
|
@@ -57,6 +57,8 @@ class LogoJS(canvas: html.Canvas) extends js.Object:
|
|
|
57
57
|
private var autoRender: Boolean = true
|
|
58
58
|
private var initialized: Boolean = false
|
|
59
59
|
private var backgroundColor: String = "white"
|
|
60
|
+
private var foregroundColor: (Int, Int, Int) = (0, 0, 0) // RGB for theme-aware drawing
|
|
61
|
+
private var isDarkMode: Boolean = false
|
|
60
62
|
private var eventHandler: Option[js.Function0[Unit]] = None
|
|
61
63
|
|
|
62
64
|
private val logo = new Logo:
|
|
@@ -98,11 +100,16 @@ class LogoJS(canvas: html.Canvas) extends js.Object:
|
|
|
98
100
|
/** Set the canvas background color */
|
|
99
101
|
def setBackgroundColor(color: String): Unit =
|
|
100
102
|
backgroundColor = color
|
|
103
|
+
val (r, g, b) = parseColor(color)
|
|
104
|
+
// Calculate luminance to determine if dark mode
|
|
105
|
+
val luminance = (0.299 * r + 0.587 * g + 0.114 * b) / 255
|
|
106
|
+
isDarkMode = luminance < 0.5
|
|
101
107
|
render()
|
|
102
108
|
|
|
103
|
-
/** Set the default pen color (used after clear) */
|
|
109
|
+
/** Set the default pen color (used after clear and for theme-aware drawing) */
|
|
104
110
|
def setForegroundColor(color: String): Unit =
|
|
105
111
|
val rgb = parseColor(color)
|
|
112
|
+
foregroundColor = rgb
|
|
106
113
|
logo.setDefaultColor(rgb)
|
|
107
114
|
render()
|
|
108
115
|
|
|
@@ -172,21 +179,33 @@ class LogoJS(canvas: html.Canvas) extends js.Object:
|
|
|
172
179
|
val lines = js.Array[LineData]()
|
|
173
180
|
val labels = js.Array[LabelData]()
|
|
174
181
|
val arcs = js.Array[ArcData]()
|
|
182
|
+
var currentColor: (Int, Int, Int) = foregroundColor
|
|
183
|
+
var currentWidth: Double = 1.0
|
|
175
184
|
|
|
176
185
|
logo.drawing.foreach {
|
|
177
|
-
case
|
|
186
|
+
case DrawSetColor(colorOpt) =>
|
|
187
|
+
currentColor = colorOpt.getOrElse(foregroundColor)
|
|
188
|
+
|
|
189
|
+
case DrawSetWidth(width) =>
|
|
190
|
+
currentWidth = width
|
|
191
|
+
|
|
192
|
+
case DrawLine(x1, y1, x2, y2) =>
|
|
193
|
+
val (r, g, b) = currentColor
|
|
178
194
|
lines.push(js.Dynamic.literal(
|
|
179
195
|
x1 = x1, y1 = y1, x2 = x2, y2 = y2,
|
|
180
|
-
color = s"rgb($r,$g,$b)", width =
|
|
196
|
+
color = s"rgb($r,$g,$b)", width = currentWidth
|
|
181
197
|
).asInstanceOf[LineData])
|
|
198
|
+
|
|
182
199
|
case DrawLabel(x, y, heading, text) =>
|
|
183
200
|
labels.push(js.Dynamic.literal(
|
|
184
201
|
x = x, y = y, heading = heading, text = text
|
|
185
202
|
).asInstanceOf[LabelData])
|
|
186
|
-
|
|
203
|
+
|
|
204
|
+
case DrawArc(x, y, heading, angle, radius) =>
|
|
205
|
+
val (r, g, b) = currentColor
|
|
187
206
|
arcs.push(js.Dynamic.literal(
|
|
188
207
|
x = x, y = y, heading = heading, angle = angle, radius = radius,
|
|
189
|
-
color = s"rgb($r,$g,$b)", width =
|
|
208
|
+
color = s"rgb($r,$g,$b)", width = currentWidth
|
|
190
209
|
).asInstanceOf[ArcData])
|
|
191
210
|
}
|
|
192
211
|
|
|
@@ -203,6 +222,8 @@ class LogoJS(canvas: html.Canvas) extends js.Object:
|
|
|
203
222
|
private def renderWithPaths(): Unit =
|
|
204
223
|
case class Style(color: (Int, Int, Int), width: Double)
|
|
205
224
|
|
|
225
|
+
var currentColor: (Int, Int, Int) = foregroundColor
|
|
226
|
+
var currentWidth: Double = 1.0
|
|
206
227
|
var currentStyle: Option[Style] = None
|
|
207
228
|
var pathStarted = false
|
|
208
229
|
var lastX: Double = 0
|
|
@@ -220,8 +241,14 @@ class LogoJS(canvas: html.Canvas) extends js.Object:
|
|
|
220
241
|
currentStyle = None
|
|
221
242
|
|
|
222
243
|
logo.drawing.foreach {
|
|
223
|
-
case
|
|
224
|
-
|
|
244
|
+
case DrawSetColor(colorOpt) =>
|
|
245
|
+
currentColor = colorOpt.getOrElse(foregroundColor)
|
|
246
|
+
|
|
247
|
+
case DrawSetWidth(width) =>
|
|
248
|
+
currentWidth = width
|
|
249
|
+
|
|
250
|
+
case DrawLine(x1, y1, x2, y2) =>
|
|
251
|
+
val style = Style(currentColor, currentWidth)
|
|
225
252
|
|
|
226
253
|
if !currentStyle.contains(style) then
|
|
227
254
|
flushPath()
|
|
@@ -243,9 +270,9 @@ class LogoJS(canvas: html.Canvas) extends js.Object:
|
|
|
243
270
|
lastX = x2
|
|
244
271
|
lastY = y2
|
|
245
272
|
|
|
246
|
-
case DrawArc(x, y, heading, angleDeg, radius
|
|
273
|
+
case DrawArc(x, y, heading, angleDeg, radius) =>
|
|
247
274
|
flushPath()
|
|
248
|
-
renderArc(x, y, heading, angleDeg, radius,
|
|
275
|
+
renderArc(x, y, heading, angleDeg, radius, currentColor, currentWidth)
|
|
249
276
|
|
|
250
277
|
case DrawLabel(x, y, heading, text) =>
|
|
251
278
|
flushPath()
|
|
@@ -255,17 +282,27 @@ class LogoJS(canvas: html.Canvas) extends js.Object:
|
|
|
255
282
|
flushPath()
|
|
256
283
|
|
|
257
284
|
private def renderWithLines(): Unit =
|
|
285
|
+
var currentColor: (Int, Int, Int) = foregroundColor
|
|
286
|
+
var currentWidth: Double = 1.0
|
|
287
|
+
|
|
258
288
|
logo.drawing.foreach {
|
|
259
|
-
case
|
|
289
|
+
case DrawSetColor(colorOpt) =>
|
|
290
|
+
currentColor = colorOpt.getOrElse(foregroundColor)
|
|
291
|
+
|
|
292
|
+
case DrawSetWidth(width) =>
|
|
293
|
+
currentWidth = width
|
|
294
|
+
|
|
295
|
+
case DrawLine(x1, y1, x2, y2) =>
|
|
296
|
+
val (r, g, b) = currentColor
|
|
260
297
|
ctx.strokeStyle = s"rgb($r,$g,$b)"
|
|
261
|
-
ctx.lineWidth =
|
|
298
|
+
ctx.lineWidth = currentWidth
|
|
262
299
|
ctx.beginPath()
|
|
263
300
|
ctx.moveTo(x1, y1)
|
|
264
301
|
ctx.lineTo(x2, y2)
|
|
265
302
|
ctx.stroke()
|
|
266
303
|
|
|
267
|
-
case DrawArc(x, y, heading, angleDeg, radius
|
|
268
|
-
renderArc(x, y, heading, angleDeg, radius,
|
|
304
|
+
case DrawArc(x, y, heading, angleDeg, radius) =>
|
|
305
|
+
renderArc(x, y, heading, angleDeg, radius, currentColor, currentWidth)
|
|
269
306
|
|
|
270
307
|
case DrawLabel(x, y, heading, text) =>
|
|
271
308
|
renderLabel(x, y, heading, text)
|
|
@@ -316,18 +353,25 @@ class LogoJS(canvas: html.Canvas) extends js.Object:
|
|
|
316
353
|
ctx.translate(x, y)
|
|
317
354
|
ctx.rotate(heading + Pi / 2)
|
|
318
355
|
|
|
356
|
+
// Theme-aware colors
|
|
357
|
+
val (shellFill, shellOutline, shellPattern, skinColor, skinOutline) =
|
|
358
|
+
if isDarkMode then
|
|
359
|
+
("#2d5a27", "#1a3a18", "#3d7a37", "#4a7a44", "#1a3a18")
|
|
360
|
+
else
|
|
361
|
+
("#5a9a50", "#3a6a38", "#7aba70", "#7ab070", "#3a6a38")
|
|
362
|
+
|
|
319
363
|
// Tail (behind shell)
|
|
320
364
|
ctx.beginPath()
|
|
321
365
|
ctx.moveTo(0, 10)
|
|
322
366
|
ctx.lineTo(0, 14)
|
|
323
|
-
ctx.strokeStyle =
|
|
367
|
+
ctx.strokeStyle = skinColor
|
|
324
368
|
ctx.lineWidth = 2
|
|
325
369
|
ctx.lineCap = "round"
|
|
326
370
|
ctx.stroke()
|
|
327
371
|
|
|
328
372
|
// Legs (behind shell)
|
|
329
|
-
ctx.fillStyle =
|
|
330
|
-
ctx.strokeStyle =
|
|
373
|
+
ctx.fillStyle = skinColor
|
|
374
|
+
ctx.strokeStyle = skinOutline
|
|
331
375
|
ctx.lineWidth = 1
|
|
332
376
|
// Front legs
|
|
333
377
|
ctx.beginPath()
|
|
@@ -351,9 +395,9 @@ class LogoJS(canvas: html.Canvas) extends js.Object:
|
|
|
351
395
|
// Head (behind shell)
|
|
352
396
|
ctx.beginPath()
|
|
353
397
|
ctx.ellipse(0, -14, 4, 5, 0, 0, 2 * Pi)
|
|
354
|
-
ctx.fillStyle =
|
|
398
|
+
ctx.fillStyle = skinColor
|
|
355
399
|
ctx.fill()
|
|
356
|
-
ctx.strokeStyle =
|
|
400
|
+
ctx.strokeStyle = skinOutline
|
|
357
401
|
ctx.lineWidth = 1.5
|
|
358
402
|
ctx.stroke()
|
|
359
403
|
|
|
@@ -367,14 +411,14 @@ class LogoJS(canvas: html.Canvas) extends js.Object:
|
|
|
367
411
|
// Shell (on top)
|
|
368
412
|
ctx.beginPath()
|
|
369
413
|
ctx.ellipse(0, 0, 8, 10, 0, 0, 2 * Pi)
|
|
370
|
-
ctx.fillStyle =
|
|
414
|
+
ctx.fillStyle = shellFill
|
|
371
415
|
ctx.fill()
|
|
372
|
-
ctx.strokeStyle =
|
|
416
|
+
ctx.strokeStyle = shellOutline
|
|
373
417
|
ctx.lineWidth = 1.5
|
|
374
418
|
ctx.stroke()
|
|
375
419
|
|
|
376
420
|
// Shell pattern
|
|
377
|
-
ctx.strokeStyle =
|
|
421
|
+
ctx.strokeStyle = shellPattern
|
|
378
422
|
ctx.lineWidth = 1
|
|
379
423
|
ctx.beginPath()
|
|
380
424
|
ctx.ellipse(0, 0, 5, 6, 0, 0, 2 * Pi)
|