ikura 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1bb2349181cc4df0d6b283dd60cad31479b35fa9aaa4fd2706857e05ffe6aec8
4
- data.tar.gz: 42630b8463ae9d1831526b6d848bf02e203efb7c56cc9ab6d2cd11345d05426a
3
+ metadata.gz: 6598a8e3b71f9d4829f84df9b9f749fe1c5554c280309014874c89c308cfeeeb
4
+ data.tar.gz: 25497c3bb74a38ee2728903cbd5f5406d4fab661ba1a25fd0e79efa467487338
5
5
  SHA512:
6
- metadata.gz: 1e69c4800ad5ab641ce70548356e9d83119b7b88d7bce07bae3dd6475f4921d64d4783bef0db92a8ff855265bf70ca63cbe41bba2fc2f0ca43062654e52a3479
7
- data.tar.gz: 24cbd3a99b3c9505bd9d4ca0c77155e206ae000ffdc35014245e564f9ae1fee17b6cdde1dbbccc8d442e9b253b888ed914a4347a12cc9697de8133a26c4e63c2
6
+ metadata.gz: 448522c0c1db5e326bdcedb394c7604dfd9b6ff8ee1366cf251be8023b98dbfc1c49d1d71932f32e239327b3ff388a53e28eab225477473642cdc14bf8fefeef
7
+ data.tar.gz: 76447fe1e54a22edc8573bc0e48aa2e611a27471b4a0f54f720310095b7fdcb804e6142714d2396025a8e3ba4a2a1ddf1c04d22851e768ec08adbbdc56c954cd
data/lib/ikura/server.rb CHANGED
@@ -12,12 +12,13 @@ module Ikura
12
12
  new(port:).run
13
13
  end
14
14
 
15
- COORDS = [
15
+ IKURA_POINTS = [
16
16
  [50, 50], [35, 50], [65, 50], [20, 50], [80, 50],
17
17
  [50, 15], [35, 22], [65, 22], [20, 35], [80, 35],
18
- [50, 85], [35, 78], [65, 78], [20, 65], [80, 65],
19
- [10, 50], [90, 50],
20
- [50, 30], [50, 70], [28, 38], [72, 38], [28, 62], [72, 62],
18
+ [50, 8], [42, 12], [58, 12], [28, 18], [72, 18],
19
+ [12, 28], [88, 28], [50, 85], [35, 78], [65, 78],
20
+ [20, 65], [80, 65], [10, 50], [90, 50], [72, 62],
21
+ [50, 30], [50, 70], [28, 38], [72, 38], [28, 62],
21
22
  ].freeze
22
23
 
23
24
  def initialize(port: 8080)
@@ -28,7 +29,8 @@ module Ikura
28
29
  def run
29
30
  server = TCPServer.new(@port)
30
31
  $stdout.sync = true
31
- puts "🍣 http://localhost:#{@port}"
32
+ url = "http://localhost:#{@port}"
33
+ puts "🍣 #{terminal_link(url)}"
32
34
  puts " (Ctrl+C to stop)\n\n"
33
35
 
34
36
  loop do
@@ -47,18 +49,24 @@ module Ikura
47
49
 
48
50
  private
49
51
 
52
+ def terminal_link(url, label = url)
53
+ return label unless $stdout.tty?
54
+
55
+ "\e]8;;#{url}\a#{label}\e]8;;\a"
56
+ end
57
+
50
58
  def handle(client, req)
51
59
  case [req[:method], req[:path]]
52
60
  in ["GET", "/"]
53
61
  respond(client, type: "text/html; charset=utf-8", body: html_page)
54
62
  in ["POST", "/ikura"]
55
- coord_idx = parse_form(req[:body])["coord"]&.to_i || 0
56
- x, y = COORDS[coord_idx] || [50, 50]
63
+ ikura_point_idx = parse_form(req[:body])["ikura_point"]&.to_i || 0
64
+ x, y = IKURA_POINTS[ikura_point_idx] || [50, 50]
57
65
  id = @ikura_count
58
66
  @ikura_count += 1
59
67
 
60
- jx = (x + rand(-8..8)).clamp(5, 95)
61
- jy = (y + rand(-8..8)).clamp(5, 95)
68
+ jx = (x + rand(-10..10))
69
+ jy = (y + rand(-10..10))
62
70
 
63
71
  respond(client,
64
72
  type: "text/vnd.turbo-stream.html; charset=utf-8",
@@ -72,8 +80,8 @@ module Ikura
72
80
  end
73
81
 
74
82
  def html_page
75
- coords_html = COORDS.each_with_index.map { |(x, y), i|
76
- "<div class='coord' style='left:#{x}%;top:#{y}%'></div>"
83
+ ikura_points_html = IKURA_POINTS.each_with_index.map { |(x, y), i|
84
+ "<div class='ikura_point' style='left:#{x}%;top:#{y}%'></div>"
77
85
  }.join("\n")
78
86
 
79
87
  ERB.new(File.read(TEMPLATE_PATH)).result(binding)
@@ -7,11 +7,10 @@
7
7
  import { DefaultRubyVM } from "https://cdn.jsdelivr.net/npm/@ruby/wasm-wasi@2.8.1/dist/browser/+esm";
8
8
  const res = await fetch("https://cdn.jsdelivr.net/npm/@ruby/4.0-wasm-wasi@2.8.1/dist/ruby+stdlib.wasm");
9
9
  const { vm } = await DefaultRubyVM(await WebAssembly.compileStreaming(res));
10
- window.rubyVM = vm;
11
10
  vm.eval(`
12
11
  require "js"
13
12
  doc = JS.global[:document]
14
- nodes = doc.call(:querySelectorAll, ".coord")
13
+ nodes = doc.call(:querySelectorAll, ".ikura_point")
15
14
  nodes[:length].to_i.times do |i|
16
15
  node = nodes.call(:item, i)
17
16
  node[:style][:opacity] = "1"
@@ -19,7 +18,7 @@ nodes[:length].to_i.times do |i|
19
18
  opts = JS.eval("return {
20
19
  method: 'POST',
21
20
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
22
- body: 'coord=#{i}'
21
+ body: 'ikura_point=#{i}'
23
22
  }")
24
23
  JS.global.fetch("/ikura", opts).call(:then, ->(response) {
25
24
  response.text().call(:then, ->(text) {
@@ -61,7 +60,6 @@ end
61
60
  border-radius: 50% / 20%;
62
61
  box-shadow: inset 0 -10px 20px rgba(0,0,0,0.5);
63
62
  z-index: 10;
64
- pointer-events: none;
65
63
  }
66
64
  .gunkan-top {
67
65
  position: absolute;
@@ -71,12 +69,11 @@ end
71
69
  border-radius: 50%;
72
70
  }
73
71
 
74
- .coord {
72
+ .ikura_point {
75
73
  position: absolute;
76
74
  transform: translate(-50%, -50%);
77
75
  width: 16px; height: 16px;
78
76
  cursor: crosshair;
79
- pointer-events: all;
80
77
  opacity: 0;
81
78
  }
82
79
 
@@ -104,11 +101,10 @@ end
104
101
  <div id="board">
105
102
  <div class="gunkan">
106
103
  <div class="gunkan-top">
107
- <%= coords_html %>
104
+ <%= ikura_points_html %>
108
105
  <ul id="ikura-layer"></ul>
109
106
  </div>
110
107
  </div>
111
108
  </div>
112
-
113
109
  </body>
114
110
  </html>
data/lib/ikura/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ikura
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ikura
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - haruna-tsujita