atome 0.5.7.5.4 → 0.5.7.5.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/documentation/deep learning/basic_infos.txt +5 -0
  3. data/lib/atome/genesis/atomes.rb +12 -0
  4. data/lib/atome/genesis/particles/event.rb +141 -97
  5. data/lib/atome/genesis/particles/identity.rb +2 -1
  6. data/lib/atome/genesis/particles/spatial.rb +25 -0
  7. data/lib/atome/genesis/particles/utility.rb +13 -5
  8. data/lib/atome/utilities/essentials.rb +5 -2
  9. data/lib/atome/version.rb +1 -1
  10. data/lib/molecules/intuition/tools.rb +1 -1
  11. data/lib/molecules/intuition/utilities.rb +3 -0
  12. data/lib/platform_specific/opal/extensions/object.rb +3 -1
  13. data/lib/platform_specific/wasm/atome_wasm_extensions.rb +2 -1
  14. data/lib/renderers/html/event.rb +20 -6
  15. data/lib/renderers/html/html.rb +753 -446
  16. data/lib/renderers/html/identity.rb +33 -6
  17. data/lib/renderers/html/spatial.rb +27 -0
  18. data/lib/renderers/html/utility.rb +4 -0
  19. data/vendor/assets/application/examples/audio.rb +25 -9
  20. data/vendor/assets/application/examples/calendar.rb +186 -0
  21. data/vendor/assets/application/examples/drop.rb +1 -0
  22. data/vendor/assets/application/examples/editor.rb +139 -0
  23. data/vendor/assets/application/examples/inspector.rb +129 -0
  24. data/vendor/assets/application/examples/keyboard.rb +20 -10
  25. data/vendor/assets/application/examples/map.rb +42 -0
  26. data/vendor/assets/application/examples/meteo.rb +8 -0
  27. data/vendor/assets/application/examples/midi.rb +4 -0
  28. data/vendor/assets/application/examples/on_resize.rb +14 -0
  29. data/vendor/assets/application/examples/over.rb +0 -1
  30. data/vendor/assets/application/examples/overflow.rb +20 -5
  31. data/vendor/assets/application/examples/particles.rb +1 -1
  32. data/vendor/assets/application/examples/preset.rb +1 -1
  33. data/vendor/assets/application/examples/resize.rb +11 -0
  34. data/vendor/assets/application/examples/tick.rb +10 -0
  35. data/vendor/assets/application/examples/tools.rb +6 -1
  36. data/vendor/assets/application/examples/touch.rb +2 -14
  37. data/vendor/assets/application/examples/trigger_abstraction.rb +165 -0
  38. data/vendor/assets/application/examples/vr.rb +3 -0
  39. data/vendor/assets/src/css/codemirror.min.css +472 -0
  40. data/vendor/assets/src/css/fonts/tui/icon.eot +0 -0
  41. data/vendor/assets/src/css/fonts/tui/icon.svg +17 -0
  42. data/vendor/assets/src/css/fonts/tui/icon.ttf +0 -0
  43. data/vendor/assets/src/css/fonts/tui/icon.woff +0 -0
  44. data/vendor/assets/src/css/fonts/tui/noto.woff +72 -0
  45. data/vendor/assets/src/css/images/leaflet/layers-2x.png +0 -0
  46. data/vendor/assets/src/css/images/leaflet/layers.png +0 -0
  47. data/vendor/assets/src/css/images/leaflet/marker-icon-2x.png +0 -0
  48. data/vendor/assets/src/css/images/leaflet/marker-icon.png +0 -0
  49. data/vendor/assets/src/css/images/leaflet/marker-shadow.png +0 -0
  50. data/vendor/assets/src/css/images/tui/ic-arrow-line-left.png +0 -0
  51. data/vendor/assets/src/css/images/tui/ic-arrow-line-left@2x.png +0 -0
  52. data/vendor/assets/src/css/images/tui/ic-arrow-line-left@3x.png +0 -0
  53. data/vendor/assets/src/css/images/tui/ic-arrow-line-right.png +0 -0
  54. data/vendor/assets/src/css/images/tui/ic-arrow-line-right@2x.png +0 -0
  55. data/vendor/assets/src/css/images/tui/ic-arrow-line-right@3x.png +0 -0
  56. data/vendor/assets/src/css/images/tui/ic-traveltime-w.png +0 -0
  57. data/vendor/assets/src/css/images/tui/ic-view-day.png +0 -0
  58. data/vendor/assets/src/css/images/tui/ic-view-day@2x.png +0 -0
  59. data/vendor/assets/src/css/images/tui/ic-view-day@3x.png +0 -0
  60. data/vendor/assets/src/css/images/tui/ic-view-month.png +0 -0
  61. data/vendor/assets/src/css/images/tui/ic-view-month@2x.png +0 -0
  62. data/vendor/assets/src/css/images/tui/ic-view-month@3x.png +0 -0
  63. data/vendor/assets/src/css/images/tui/ic-view-week.png +0 -0
  64. data/vendor/assets/src/css/images/tui/ic-view-week@2x.png +0 -0
  65. data/vendor/assets/src/css/images/tui/ic-view-week@3x.png +0 -0
  66. data/vendor/assets/src/css/images/tui/icon.png +0 -0
  67. data/vendor/assets/src/css/images/tui/img-bi.png +0 -0
  68. data/vendor/assets/src/css/images/tui/img-bi@2x.png +0 -0
  69. data/vendor/assets/src/css/images/tui/img-bi@3x.png +0 -0
  70. data/vendor/assets/src/css/leaflet.css +664 -0
  71. data/vendor/assets/src/css/monokai.min.css +127 -0
  72. data/vendor/assets/src/css/style.css +1 -1
  73. data/vendor/assets/src/css/toastui-calendar.min.css +6 -0
  74. data/vendor/assets/src/index.html +12 -1
  75. data/vendor/assets/src/index_opal.html +16 -1
  76. data/vendor/assets/src/index_server.html +11 -1
  77. data/vendor/assets/src/index_server_wasm.html +10 -1
  78. data/vendor/assets/src/index_wasm.html +12 -1
  79. data/vendor/assets/src/js/atome/specific/tauri.js +32 -0
  80. data/vendor/assets/src/js/atome/utilities/importmap.js +9 -0
  81. data/vendor/assets/src/js/atome/utilities/three_module.js +88 -0
  82. data/vendor/assets/src/js/test.js +42 -0
  83. data/vendor/assets/src/js/third_parties/Three/build/three.cjs +54216 -0
  84. data/vendor/assets/src/js/third_parties/Three/build/three.module.min.js +6 -0
  85. data/vendor/assets/src/js/third_parties/Three/build/three.webgpu.min.js +6 -0
  86. data/vendor/assets/src/js/third_parties/Three/jsm/controls/OrbitControls.js +1532 -0
  87. data/vendor/assets/src/js/third_parties/codemirror.min.js +1 -0
  88. data/vendor/assets/src/js/third_parties/leaflet.js +6 -0
  89. data/vendor/assets/src/js/third_parties/leaflet.js.map +1 -0
  90. data/vendor/assets/src/js/third_parties/ruby.min.js +1 -0
  91. data/vendor/assets/src/js/third_parties/toastui-calendar.min.js +9 -0
  92. data/vendor/assets/src/medias/images/puydesancy.jpg +0 -0
  93. data/vendor/assets/src-tauri/Cargo.toml +6 -5
  94. data/vendor/assets/src-tauri/Info.plist +12 -0
  95. data/vendor/assets/src-tauri/src/main.rs +32 -3
  96. data/vendor/assets/src-tauri/src/midi.rs +25 -0
  97. data/vendor/assets/src-tauri/tauri.conf.json +4 -4
  98. metadata +60 -3
  99. data/vendor/assets/src/js/third_parties/three.min.js +0 -6
@@ -14,6 +14,10 @@ new({ method: :type, type: :string, renderer: :html, specific: :image }) do |_va
14
14
  html.image(@id)
15
15
  end
16
16
 
17
+ new({ method: :type, type: :string, renderer: :html, specific: :editor }) do |_value, _user_proc|
18
+ html.editor(@id)
19
+ end
20
+
17
21
  new({ method: :type, type: :string, renderer: :html, specific: :video }) do |_value, _user_proc|
18
22
  html.video(@id)
19
23
  end
@@ -38,6 +42,11 @@ new({ method: :type, type: :string, specific: :text, renderer: :html }) do |_val
38
42
  html.add_class(:text)
39
43
  end
40
44
 
45
+ new({ method: :type, type: :string, specific: :vr, renderer: :html }) do |_value, _user_proc|
46
+ html.vr(@id)
47
+
48
+ end
49
+
41
50
  new({ method: :type, type: :string, specific: :paint, renderer: :html }) do
42
51
  end
43
52
 
@@ -53,21 +62,27 @@ new({ method: :data, type: :string, specific: :text, renderer: :html }) do |para
53
62
  # end
54
63
 
55
64
  # alert "#{Universe.translation} /// #{params} /// #{Universe.language}"
56
- if Universe.translation[params]
57
- params= Universe.translation[params][Universe.language]
65
+ if Universe.translation[params]
66
+ params = Universe.translation[params][Universe.language]
58
67
  end
59
68
  js[:innerHTML] = params.to_s
60
69
 
61
70
  end
71
+ new({ method: :code, type: :string, specific: :editor, renderer: :html }) do |params|
72
+ if Universe.translation[params]
73
+ params = Universe.translation[params][Universe.language]
74
+ end
75
+ js[:innerHTML] = params.to_s
76
+ end
62
77
 
63
78
  new({ method: :data, type: :string, specific: :vector, renderer: :html }) do |value|
64
79
  unless value.instance_of? Array
65
- value=[value]
80
+ value = [value]
66
81
  end
67
82
  html.svg_data(value)
68
83
  end
69
84
 
70
- new({ method: :component, type: :hash, specific: :text, renderer: :html }) do |params, _user_proc|
85
+ new({ method: :component, type: :hash, renderer: :html }) do |params, _user_proc|
71
86
  params.each do |prop, value|
72
87
  # we send component data directly to the text html renderer
73
88
  send("html_text_#{prop}", value)
@@ -90,6 +105,12 @@ new({ method: :path, type: :string, renderer: :html, specific: :www }) do |value
90
105
  html.path(value)
91
106
  end
92
107
 
108
+ new({ method: :path, type: :string, renderer: :html, specific: :vr }) do |value, _user_proc|
109
+ # wait 0.1 do # we have to wait for ruby wasm else it won't work
110
+ html.vr_path(value)
111
+ # end
112
+ end
113
+
93
114
  new({ method: :data, type: :string, renderer: :html, specific: :raw }) do |value, _user_proc|
94
115
  html.raw_data(value)
95
116
  end
@@ -108,7 +129,13 @@ new({ method: :type, type: :hash, specific: :atomized, renderer: :html }) do |va
108
129
  html.atomized(alien)
109
130
  end
110
131
 
111
-
112
132
  new({ renderer: :html, method: :selected, specific: :text }) do |value, &bloc|
113
133
  html.select_text(value)
114
- end
134
+ end
135
+
136
+ new({ renderer: :html, method: :markup }) do |value, &bloc|
137
+ html.markup(value, bloc)
138
+ end
139
+
140
+
141
+
@@ -64,3 +64,30 @@ end
64
64
  new({ renderer: :html, method: :center }) do |params|
65
65
  html.center(params, attach)
66
66
  end
67
+
68
+
69
+ new({ method: :map, renderer: :html, type: :int }) do |params, _user_proc|
70
+ #TODO : missing zoom params
71
+ if params== :auto
72
+ params={longitude: :auto, latitude: :auto}
73
+ end
74
+ latitude_found=@latitude
75
+ longitude_found=@longitude
76
+ location_hash={longitude: longitude_found, latitude: latitude_found}.merge(params)
77
+ html.location(location_hash)
78
+ end
79
+
80
+ new({ method: :map_zoom, renderer: :html, type: :int }) do |params, _user_proc|
81
+ html.map_zoom(params)
82
+ end
83
+
84
+ new({ method: :map_pan, renderer: :html, type: :int }) do |params, _user_proc|
85
+ html.map_pan(params)
86
+ end
87
+
88
+
89
+
90
+
91
+
92
+
93
+
@@ -4,6 +4,10 @@ new({ renderer: :html, method: :web }) do |params, &user_proc|
4
4
  params
5
5
  end
6
6
 
7
+ new({ renderer: :html, method: :meteo }) do |params, &user_proc|
8
+ html.meteo(params)
9
+ end
10
+
7
11
  new({ renderer: :html, method: :renderers, type: :string })
8
12
  new({ renderer: :html, method: :delete, type: :string }) do |params|
9
13
  html.delete(id)
@@ -18,7 +18,7 @@ end
18
18
  @track = @audio_context.createMediaElementSource(@audio_element)
19
19
 
20
20
  @gain_node = @audio_context.createGain()
21
- @gain_node[:gain][:value] = 0.5
21
+ @gain_node[:gain][:value] = 0.6
22
22
 
23
23
  @track.connect(@gain_node)
24
24
  @gain_node.connect(@audio_context[:destination])
@@ -35,20 +35,36 @@ end
35
35
 
36
36
 
37
37
  # ######### wadjs
38
+
38
39
  bb=box({left: 333})
39
40
  bb.text(:wadjs)
41
+
42
+
43
+
44
+ # Initialize window.snare
45
+
40
46
  init_code = "window.snare = new Wad({source : 'medias/audios/clap.wav'});"
41
47
  JS.eval(init_code)
42
48
 
43
- play_code = <<~STRDEL
44
- window.snare.play();
45
- setTimeout(function() {
46
- window.snare.stop();
47
- }, 300);
48
- STRDEL
49
+ # Define the JavaScript playSnare function
50
+ js_code = <<~JAVASCRIPT
51
+ window.playSnare = function() {
52
+ window.snare.play();
53
+ // setTimeout(function() {
54
+ // window.snare.stop();
55
+ //}, 30);
56
+ }
57
+ JAVASCRIPT
49
58
 
59
+ # Evaluate the JavaScript code once
60
+ JS.eval(js_code)
50
61
 
51
- bb.touch(:down) do
52
- JS.eval(play_code)
62
+ # Define the Ruby method to call the JavaScript function
63
+ def play_snare
64
+ JS.eval('window.playSnare()')
53
65
  end
54
66
 
67
+ # Attach the method to the touch event
68
+ bb.touch(:down) do
69
+ play_snare
70
+ end
@@ -0,0 +1,186 @@
1
+ # frozen_string_literal: true
2
+
3
+ new(molecule: :calendar) do |params, &bloc|
4
+
5
+ cal = box(params)
6
+ cal.resize(true)
7
+ cal_id = cal.id
8
+
9
+ ########################## create calendar ##########################
10
+ cal_name = cal_id
11
+ calendar = <<~JAVASCRIPT
12
+ window.#{cal_name} = new tui.Calendar('##{cal_id}', {
13
+ defaultView: 'month',
14
+ usageStatistics: false,
15
+ month: {
16
+ startDayOfWeek: 0,
17
+ },
18
+ week: {
19
+ showTimezoneCollapseButton: true,
20
+ timezones: [{ timezoneOffset: 0, displayLabel: 'UTC', tooltip: 'UTC' }],
21
+ },
22
+ });
23
+
24
+
25
+
26
+
27
+ JAVASCRIPT
28
+
29
+ JS.eval(calendar)
30
+
31
+ ######################### Update view methode ############################
32
+
33
+
34
+
35
+
36
+ cal.define_singleton_method(:view) do |view_mode|
37
+ update_calendar = <<~JAVASCRIPT
38
+ function changeCalendarView(view) {
39
+ const validViews = ['day', 'week', 'month'];
40
+ if (!validViews.includes(view)) {
41
+ console.error(`Vue non valide: ${view}. Les vues valides sont: ${validViews.join(', ')}`);
42
+ return;
43
+ }
44
+ window.#{cal_name}.changeView(view);
45
+ }
46
+ changeCalendarView('#{view_mode}');
47
+
48
+ // changeCalendarView('day');
49
+ JAVASCRIPT
50
+ JS.eval(update_calendar)
51
+ end
52
+
53
+ cal.define_singleton_method(:event) do |new_event|
54
+ add_event = <<~JAVASCRIPT
55
+ window.#{cal_name}.createEvents([
56
+ {
57
+ id: '#{new_event[:id]}',
58
+ calendarId: '#{new_event[:calendarId]}',
59
+ title: '#{new_event[:title]}',
60
+ category: '#{new_event[:category]}',
61
+ dueDateClass: '#{new_event[:dueDateClass]}',
62
+ start: '#{new_event[:start]}',
63
+ end: '#{new_event[:end]}',
64
+ },
65
+ ]);
66
+ JAVASCRIPT
67
+ JS.eval(add_event)
68
+
69
+ end
70
+
71
+
72
+
73
+ #################
74
+ cal.define_singleton_method(:update_event) do |event_id, calendar_id, updates|
75
+ update_event = <<~JAVASCRIPT
76
+ window.#{cal_name}.updateEvent(
77
+ '#{event_id}', // ID de l'événement
78
+ '#{calendar_id}', // ID du calendrier
79
+ {
80
+ title: '#{updates[:title]}',
81
+ start: new Date('#{updates[:start]}'),
82
+ end: new Date('#{updates[:end]}'),
83
+ category: '#{updates[:category]}',
84
+ dueDateClass: '#{updates[:dueDateClass]}',
85
+ isAllDay: #{updates[:isAllDay] ? 'true' : 'false'},
86
+ location: '#{updates[:location]}',
87
+ raw: #{updates[:raw] || '{}'},
88
+ state: '#{updates[:state]}'
89
+ }
90
+ );
91
+ JAVASCRIPT
92
+ JS.eval(update_event)
93
+ end
94
+ #################
95
+
96
+ cal.define_singleton_method(:delete_event) do |event_id, calendar_id|
97
+ delete_event = <<~JAVASCRIPT
98
+ window.#{cal_name}.deleteEvent('#{event_id}', '#{calendar_id}');
99
+ JAVASCRIPT
100
+ JS.eval(delete_event)
101
+ end
102
+
103
+ ####################
104
+
105
+ cal.define_singleton_method(:log_event_range) do
106
+ log_range = <<~JAVASCRIPT
107
+ var selectedRanges = [];
108
+
109
+ window.#{cal_name}.on('selectDateTime', function(info) {
110
+ var range = { start: new Date(info.start), end: new Date(info.end) };
111
+ selectedRanges.push(range);
112
+ console.log('Selected ranges:', selectedRanges);
113
+
114
+ // Exemple de traitement de chaque plage
115
+ selectedRanges.forEach(function(range) {
116
+ console.log('Processing range:', range.start, 'to', range.end);
117
+ });
118
+
119
+ // Réinitialisation après traitement
120
+ selectedRanges = [];
121
+ });
122
+ JAVASCRIPT
123
+ JS.eval(log_range)
124
+ end
125
+ ######################
126
+
127
+ cal.define_singleton_method(:handle_range_clear) do
128
+ clear_range = <<~JAVASCRIPT
129
+ window.#{cal_name}.on('selectDateTime', function(info) {
130
+ // Log the selected range (optional)
131
+ console.log('Selected range:', new Date(info.start), 'to', new Date(info.end));
132
+
133
+ // Clear the selected range
134
+ window.#{cal_name}.clearGridSelections();
135
+
136
+ console.log('Range selection cleared');
137
+ });
138
+ JAVASCRIPT
139
+ JS.eval(clear_range)
140
+ end
141
+
142
+ ######################
143
+ # now we return main atome
144
+ cal
145
+ end
146
+ cal = calendar({ id: :the_cal, width: 396, height: 396 })
147
+ # below we get range when drag on the calendar
148
+ cal.log_event_range
149
+ # below we remove teh range newly created to avoid graphical pollution
150
+ cal.handle_range_clear
151
+ wait 1 do
152
+ cal.event( {
153
+ id: '1',
154
+ calendarId: '1',
155
+ title: 'nouvel example',
156
+ category: 'time',
157
+ dueDateClass: '',
158
+ start: '2024-08-20T10:12:00+00:00',
159
+ end: '2024-08-20T12:17:00+00:00',
160
+ })
161
+ end
162
+
163
+ wait 2 do
164
+ grab(:the_cal).view(:day)
165
+ wait 2 do
166
+ cal.view(:week)
167
+ wait 2 do
168
+ cal.view(:month)
169
+ wait 1 do
170
+ wait 1 do
171
+ cal.update_event('1', '1', {
172
+ title: 'Événement mis à jour',
173
+ start: '2024-08-20T11:00:00+00:00',
174
+ end: '2024-08-20T13:00:00+00:00',
175
+ category: 'time'
176
+ })
177
+ end
178
+ cal.delete_event('1', '1')
179
+ end
180
+ end
181
+ end
182
+ end
183
+
184
+
185
+
186
+
@@ -27,6 +27,7 @@ dragged.drop(:deactivate) do |event|
27
27
  grab(event[:destination]).color(:orange)
28
28
  end
29
29
  box({ left: 333, color: :blue,top: 222, smooth: 6, id: :the_box, drag: true })
30
+ box({ left: 333, color: :red,top: 180, smooth: 9, id: :the_box2, drag: true })
30
31
 
31
32
  t=text({data: 'touch me to unbind drop enter'})
32
33
  t.touch(true) do
@@ -0,0 +1,139 @@
1
+ # frozen_string_literal: true
2
+ box
3
+ dragger = box({ width: 333, height: 16, top: 0 })
4
+ back = box({ width: 333, height: 222, top: dragger.height })
5
+ body = back.box({ top: 0, width: '100%', height: '100%', component: { size: 12 }, id: :poil })
6
+ code_runner = dragger.circle({ left: 3, top: 3, width: 12, height: 12, color: :red })
7
+ code_closer = dragger.circle({ left: :auto ,right: 3, top: 3, width: 12, height: 12, color: :black })
8
+
9
+ body.editor({ id: :the_ed, code: "def my_script\n
10
+ return 100\n
11
+ end", width: 333, height: 192, color: :lightgray, top: 0 })
12
+
13
+ def create_editor(code_id)
14
+ js_code = <<~JAVASCRIPT
15
+ var editor = CodeMirror.fromTextArea(document.getElementById("#{code_id}"), {
16
+ lineNumbers: true,
17
+ mode: "ruby",
18
+ theme: "monokai"
19
+ });
20
+ editor.getWrapperElement().id = "atome_editor_#{code_id}";
21
+ document.getElementById("atome_editor_#{code_id}").CodeMirrorInstance = editor;
22
+
23
+ JAVASCRIPT
24
+ JS.eval(js_code)
25
+ end
26
+
27
+ def set_code(code_id, content)
28
+ js_code = <<~JAVASCRIPT
29
+ var editorWrapper = document.getElementById("atome_editor_#{code_id}");
30
+ var editorInstance = editorWrapper.CodeMirrorInstance;
31
+ var newContent = "#{content}";
32
+ editorInstance.setValue(newContent);
33
+ JAVASCRIPT
34
+ JS.eval(js_code)
35
+ end
36
+
37
+ def get_code(code_id)
38
+ js_code = <<~JAVASCRIPT
39
+ var editorWrapper = document.getElementById("atome_editor_#{code_id}");
40
+
41
+ var editorInstance = editorWrapper.CodeMirrorInstance;
42
+ return editorInstance.getValue();
43
+ JAVASCRIPT
44
+ JS.eval(js_code)
45
+ end
46
+
47
+ create_editor("the_ed")
48
+
49
+ wait 1 do
50
+ editor_id = "the_ed"
51
+ set_code(editor_id, "def new_script\\n puts 'so cool'\\ncircle({top: rand(333), color: :red})\\nend\\nnew_script")
52
+ end
53
+
54
+ code_closer.touch(true) do
55
+ back.delete(true)
56
+ dragger.delete(true)
57
+ end
58
+
59
+ code_runner.touch(true) do
60
+ editor_id = "the_ed"
61
+ data_found = get_code("the_ed").to_s
62
+ grab(:the_t).code(data_found.to_s)
63
+ atome_before = Universe.user_atomes
64
+ eval(data_found)
65
+ code_editor = grab(editor_id)
66
+ atome_to_delete = code_editor.data
67
+ atome_to_delete.each do |atome_id_found|
68
+ grab(atome_id_found).delete(false)
69
+ end
70
+ atome_after = Universe.user_atomes
71
+ new_atomes = atome_after - atome_before
72
+ code_editor.data(new_atomes)
73
+ end
74
+ dragger.drag(restrict: :view ) do |event|
75
+ view = grab(:view)
76
+ view_width = view.to_px(:width)
77
+ view_height = view.to_px(:height)
78
+
79
+ dx = event[:dx]
80
+ dy = event[:dy]
81
+
82
+ # Calculer les nouvelles positions
83
+ x = (back.left || 0) + dx.to_f
84
+ y = (back.top || 0) + dy.to_f
85
+
86
+ # Contrainte de `x` entre 0 et `view_width`
87
+ if x > 0 && x < view_width - back.width
88
+ back.left(x)
89
+ else
90
+ # Contrainte si `x` dépasse les limites
91
+ x = [0, [x, view_width - back.width].min].max
92
+ back.left(x)
93
+ end
94
+
95
+ # Contrainte de `y` pour qu'il soit supérieur à une certaine valeur
96
+ if y > 0 + dragger.height && y < view_height + dragger.height
97
+ back.top(y)
98
+ else
99
+ # Contrainte si `y` dépasse les limites
100
+ y = [0 + dragger.height, [y, view_height + dragger.height].min].max
101
+ back.top(y)
102
+ end
103
+ end
104
+ back.resize({ size: { min: { width: 120, height: 90 }, max: { width: 3000, height: 3000 } } }) do |event|
105
+ dx = event[:dx]
106
+ # dy = event[:dy]
107
+ x = (dragger.width || 0) + dx.to_f
108
+ # y = (back.top || 0) + dy.to_f
109
+ dragger.width(x)
110
+ # back.top(y)
111
+ end
112
+
113
+ back.shadow({ alpha: 0.6, blur: 16, left: 3, top: 16 })
114
+
115
+ back.drag(false)
116
+ dragger.touch(:double) do
117
+ if back.display == :none
118
+ back.display(:block)
119
+ else
120
+ back.display(:none)
121
+ end
122
+ end
123
+
124
+ # a_list=[]
125
+ # Universe.atome_list.each do |k, v|
126
+ # a_list << k
127
+ # end
128
+ #
129
+ # alert a_list
130
+ #
131
+ # p_list=[]
132
+ # Universe.particle_list.each do |k, v|
133
+ # p_list << k
134
+ # end
135
+ #
136
+ # alert p_list
137
+ #
138
+ # box(id: :mon_carre, width: 300, height: 300)
139
+ alert "pseudo element and trigger absctrator"
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ b = text({ id: :toto, left: 0, data: :inspect, depth: 12 })
4
+
5
+ c = text({ id: :the_c, left: 190, data: 'stop inspect', depth: 12 })
6
+ box({ left: 120, top: 120, width: 333, height: 333, id: :helper })
7
+
8
+ class Atome
9
+
10
+ def follow_cursor(div_id, item_to_be_monitored, &proc)
11
+ @inspector_active = true
12
+ last_collided_element = nil
13
+
14
+ JS.global[:document].addEventListener('mousemove', @mousemove_listener = proc do |native_event|
15
+ next unless @inspector_active
16
+ event = Native(native_event)
17
+ element = JS.global[:document].getElementById(div_id)
18
+ width = element[:offsetWidth].to_i
19
+ height = element[:offsetHeight].to_i
20
+
21
+ left = event[:clientX].to_i - (width / 2)
22
+ top = event[:clientY].to_i - (height / 2)
23
+
24
+ element[:style][:left] = "#{left}px"
25
+ element[:style][:top] = "#{top}px"
26
+
27
+ last_collided_element = check_collision(element, item_to_be_monitored, last_collided_element,&proc)
28
+ end)
29
+
30
+ JS.global[:document].addEventListener('touchmove', @touchmove_listener = proc do |native_event|
31
+ next unless @inspector_active
32
+ event = Native(native_event)
33
+
34
+ touch = event[:touches][0]
35
+ element = JS.global[:document].getElementById(div_id)
36
+ width = element[:offsetWidth].to_i
37
+ height = element[:offsetHeight].to_i
38
+
39
+ left = touch[:clientX].to_i - (width / 2)
40
+ top = touch[:clientY].to_i - (height / 2)
41
+
42
+ element[:style][:left] = "#{left}px"
43
+ element[:style][:top] = "#{top}px"
44
+
45
+ last_collided_element = check_collision(element, item_to_be_monitored, last_collided_element)
46
+ end)
47
+ end
48
+
49
+ def unbind_inspector(div_id)
50
+ @inspector_active = false
51
+ JS.global[:console].log("Inspector disabled for element: #{div_id}")
52
+ end
53
+
54
+ # private
55
+
56
+ def check_collision(follow_div, item_to_be_monitored, last_collided_element,&proc)
57
+ ids_to_check = item_to_be_monitored
58
+
59
+ ids_to_check.each do |id|
60
+ element = JS.global[:document].getElementById(id.to_s)
61
+
62
+ if element && is_colliding(follow_div, element)
63
+ if last_collided_element != element[:id]
64
+ proc.call(element[:id].to_s.to_sym) unless element[:id] == follow_div[:id]
65
+ return element[:id] # Return the current collided element
66
+ else
67
+ return last_collided_element # Return the same element if it's still the same
68
+ end
69
+ end
70
+ end
71
+
72
+ return nil # Return nil if no collision is detected
73
+ end
74
+
75
+ def is_colliding(div1, div2)
76
+ rect1 = div1.getBoundingClientRect()
77
+ rect2 = div2.getBoundingClientRect()
78
+
79
+ rect1_right = rect1[:right].to_f
80
+ rect1_left = rect1[:left].to_f
81
+ rect1_bottom = rect1[:bottom].to_f
82
+ rect1_top = rect1[:top].to_f
83
+
84
+ rect2_right = rect2[:right].to_f
85
+ rect2_left = rect2[:left].to_f
86
+ rect2_bottom = rect2[:bottom].to_f
87
+ rect2_top = rect2[:top].to_f
88
+
89
+ !(rect1_right < rect2_left ||
90
+ rect1_left > rect2_right ||
91
+ rect1_bottom < rect2_top ||
92
+ rect1_top > rect2_bottom)
93
+ end
94
+
95
+ def inspection(active)
96
+ if active
97
+ circle({ width: 15, height: 15, left: 99,
98
+ color: {red: 0.7, green: 0.7,blue: 0.7,alpha: 0.3},
99
+ id: :inspector_satellite,
100
+ shadow: {alpha: 0.7, blur: 9}})
101
+ follow_cursor('inspector_satellite', fasten) do |id|
102
+ puts "collision detected with element: #{id}"
103
+ current_obj=grab(id)
104
+ puts current_obj.infos
105
+ end
106
+ else
107
+ unbind_inspector(:inspector_satellite)
108
+ grab(:inspector_satellite).delete(true)
109
+ end
110
+ end
111
+ end
112
+
113
+ ########
114
+ events_list = []
115
+ Universe.particle_list.each do |particle, content|
116
+ if content[:category] == :event
117
+ events_list << particle
118
+ end
119
+ end
120
+
121
+ b.touch(true) do
122
+ grab(:view).inspection(true)
123
+ end
124
+
125
+ c.touch(true) do
126
+ grab(:view).inspection(false)
127
+ end
128
+
129
+ ##############################
@@ -42,18 +42,28 @@ end
42
42
  # end
43
43
 
44
44
  c = circle({ top: 123, left: 0, width: 55, height: 55 })
45
- c2 = circle({ top: 123, left: 80, width: 55, height: 55 })
46
- c3 = circle({ top: 123, left: 150, width: 55, height: 55 })
45
+ # c2 = circle({ top: 123, left: 80, width: 55, height: 55 })
46
+ # c3 = circle({ top: 123, left: 150, width: 55, height: 55 })
47
47
 
48
48
  c.touch(true) do
49
49
  text({ data: 'stop up', top: 150 })
50
50
  t.keyboard({ remove: :up })
51
51
  end
52
- c2.touch(true) do
53
- text({ data: 'remove all', top: 150 })
54
- t.keyboard(:remove)
55
- end
56
- c3.touch(true) do
57
- t.edit(false)
58
- text({ data: 'stop editing', top: 150 })
59
- end
52
+ # c2.touch(true) do
53
+ # text({ data: 'remove all', top: 150 })
54
+ # t.keyboard(:remove)
55
+ # end
56
+ # c3.touch(true) do
57
+ # t.edit(false)
58
+ # text({ data: 'stop editing', top: 150 })
59
+ # end
60
+
61
+
62
+ # b33=box({left: 99, top: 99})
63
+ #
64
+ # b33.touch(true) do
65
+ # t.keyboard({ remove: :up }) do
66
+ # event = Native(native_event)
67
+ # puts "heyeeee up!!"
68
+ # end
69
+ # end