atome 0.5.5.7.7 → 0.5.5.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/exe/atome +110 -91
  3. data/lib/atome/atome.rb +4 -1
  4. data/lib/atome/extensions/atome.rb +319 -2
  5. data/lib/atome/genesis/generators/atome.rb +10 -1
  6. data/lib/atome/genesis/generators/communication.rb +10 -2
  7. data/lib/atome/genesis/generators/effect.rb +7 -1
  8. data/lib/atome/genesis/generators/event.rb +4 -3
  9. data/lib/atome/genesis/generators/geometry.rb +31 -4
  10. data/lib/atome/genesis/generators/identity.rb +3 -0
  11. data/lib/atome/genesis/generators/material.rb +1 -0
  12. data/lib/atome/genesis/generators/property.rb +76 -0
  13. data/lib/atome/genesis/generators/security.rb +4 -2
  14. data/lib/atome/genesis/generators/utility.rb +27 -12
  15. data/lib/atome/genesis/sparkle.rb +3 -2
  16. data/lib/atome/helpers/essentials.rb +3 -2
  17. data/lib/atome/version.rb +1 -1
  18. data/lib/platform_specific/opal/extensions/js.rb +1 -2
  19. data/lib/renderers/html/atome.rb +0 -1
  20. data/lib/renderers/html/effect.rb +7 -3
  21. data/lib/renderers/html/geometry.rb +11 -5
  22. data/lib/renderers/html/hierarchy.rb +1 -1
  23. data/lib/renderers/html/html.rb +304 -19
  24. data/lib/renderers/html/identity.rb +8 -0
  25. data/lib/renderers/html/material.rb +14 -0
  26. data/lib/renderers/html/property.rb +35 -0
  27. data/lib/renderers/html/spatial.rb +14 -5
  28. data/lib/renderers/html/utility.rb +25 -1
  29. data/sig/global_variables.rbs +1 -0
  30. data/vendor/assets/application/examples/a_concat.rb +3 -0
  31. data/vendor/assets/application/examples/atomizer.rb +86 -0
  32. data/vendor/assets/application/examples/blur.rb +6 -0
  33. data/vendor/assets/application/examples/border.rb +6 -0
  34. data/vendor/assets/application/examples/compute.rb +16 -0
  35. data/vendor/assets/application/examples/console.rb +4 -0
  36. data/vendor/assets/application/examples/dig.rb +13 -0
  37. data/vendor/assets/application/examples/fit.rb +26 -0
  38. data/vendor/assets/application/examples/import.rb +33 -0
  39. data/vendor/assets/application/examples/infos.rb +10 -0
  40. data/vendor/assets/application/examples/messaging.rb +17 -4
  41. data/vendor/assets/application/examples/shortcut.rb +25 -0
  42. data/vendor/assets/application/examples/size.rb +17 -0
  43. data/vendor/assets/application/examples/table.rb +76 -0
  44. data/vendor/assets/application/examples/text.rb +1 -1
  45. data/vendor/assets/application/works/vie.rb +3 -0
  46. data/vendor/assets/server/atome_server.rb +40 -7
  47. data/vendor/assets/server/capture.rb +1 -1
  48. data/vendor/assets/src/index.html +7 -6
  49. data/vendor/assets/src/index_opal.html +11 -6
  50. data/vendor/assets/src/index_server.html +11 -7
  51. data/vendor/assets/src/index_server_wasm.html +7 -6
  52. data/vendor/assets/src/js/atome/atome.js +0 -95
  53. data/vendor/assets/src/js/atome/atome_helpers/communication.js +9 -7
  54. metadata +15 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a47df79a8df1efe611c135f99a343afefe4e76b8a23bec82385f6f4a95890b4
4
- data.tar.gz: b1315627fd2df81fbc1bb45d19bbc1d6d8a25c8b49e13ab409bc5d0a5b565456
3
+ metadata.gz: fe95794110662e88b3aac3f5a49c75859e6d8f82bc8d54a1413b99f868139893
4
+ data.tar.gz: a755990f9a94ee89f4b3d3271b2c6b822c971a225ae5b4b7465c1f845d99a920
5
5
  SHA512:
6
- metadata.gz: 809b5491aa72a6f62ac9c4765bc4ed7f6910f444ee1447e2ce394c6f1217c72ad1e15f39fd5e0f07c13ca0706acca5e7c66a4fb573c8418d54eef532342ffd3b
7
- data.tar.gz: 3df3f9ab29f3d5775fc16d4372cc65f8c9b902771958806eedb7f5fbf05706e5042771248083b6b97a3476eb27055346510a7c3c0772c60e68740ab88bf9ef47
6
+ metadata.gz: '09a7452177a47e2720aec7f93a48f113a12087b5bd64fcdeb0ffbe30831f70e40ac7fab9f64dcdf8e7636bccbb2d5eb7f7b1b9e8db1cd4ddf1852ad135d2bdbe'
7
+ data.tar.gz: a3832fda01f201a82ef0182a2275af3a1d650195c308a4cde13594bcf3e6a83e15c6db2c58e19a3e329960d89f9fe6ef3ee3d52c0c557327afe7d272f84fad37
data/exe/atome CHANGED
@@ -413,6 +413,8 @@ def find_requires(file)
413
413
  end
414
414
 
415
415
  def copy_file(source, destination)
416
+ return if source == 'server.rb'
417
+
416
418
  FileUtils.mkdir_p(File.dirname(destination))
417
419
  FileUtils.cp(source, destination)
418
420
  end
@@ -577,52 +579,113 @@ STR
577
579
 
578
580
  end
579
581
 
580
- if ARGV.include?('opal')
581
- puts 'building Opal'
582
+ if ARGV.include?('sparkle')
583
+ temp_dir = if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
584
+ 'C:\Windows\Temp'
585
+ # code to exec with Windows
586
+ elsif RbConfig::CONFIG['host_os'] =~ /darwin|mac os/
587
+ '/tmp'
588
+ # code to exec with MacOS
589
+ else
590
+ '/tmp'
591
+ # code to exec with Unix/Linux
592
+ end
593
+
594
+ `cd #{temp_dir}; atome create atome_app` unless Dir.exist?("#{temp_dir}/atome_app")
595
+ # search for server file
596
+ if File.exist?('server.rb')
597
+ file_content = File.read('server.rb')
598
+ File.write("#{temp_dir}/atome_app/server/atome_server.rb", file_content)
599
+ base_folder = File.dirname(project_name)
600
+ copy_with_requires('server.rb', "#{temp_dir}/atome_app/server", base_folder)
601
+ end
602
+ project_name = ARGV[1]
603
+ if project_name.nil? || project_name == 'opal' || project_name == 'wasm' || project_name == 'server'
604
+ project_name = 'index.rb'
605
+ end
606
+ project_name = ensure_rb_extension(project_name)
607
+ base_folder = File.dirname(project_name)
608
+ copy_with_requires(project_name, "#{temp_dir}/atome_app/application", base_folder)
582
609
 
583
- build_opal_application(nil, destination, project_name)
584
- # build host_mode
585
- build_host_mode(destination, project_name, 'web-opal')
586
- # build Opal extensions
587
- if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
588
- # code to exec for Windows
589
- `start "" "#{destination}\\#{project_name}\\src\\index_opal.html"`
590
- elsif RbConfig::CONFIG['host_os'] =~ /darwin|mac os/
591
- # code to exec for MacOS
592
- `open #{destination}/#{project_name}/src/index_opal.html`
610
+ if ARGV.include?('opal')
611
+ `cd #{temp_dir}/atome_app;atome run opal`
612
+
613
+ elsif ARGV.include?('wasm')
614
+ `cd #{temp_dir}/atome_app;atome run wasm`
615
+
616
+ elsif ARGV.include?('server')
617
+ `cd #{temp_dir}/atome_app;atome run server`
593
618
  else
594
- # code to exec for Unix/Linux
595
- `open #{destination}/#{project_name}/src/index_opal.html`
619
+ `cd #{temp_dir}/atome_app;atome run opal`
596
620
  end
621
+ else
622
+ if ARGV.include?('opal')
623
+ puts 'building Opal'
597
624
 
598
- puts "opal ready!"
599
- end
625
+ build_opal_application(nil, destination, project_name)
626
+ # build host_mode
627
+ build_host_mode(destination, project_name, 'web-opal')
628
+ # build Opal extensions
629
+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
630
+ # code to exec for Windows
631
+ `start "" "#{destination}\\#{project_name}\\src\\index_opal.html"`
632
+ elsif RbConfig::CONFIG['host_os'] =~ /darwin|mac os/
633
+ # code to exec for MacOS
634
+ `open #{destination}/#{project_name}/src/index_opal.html`
635
+ else
636
+ # code to exec for Unix/Linux
637
+ `open #{destination}/#{project_name}/src/index_opal.html`
638
+ end
600
639
 
601
- if ARGV.include?('wasm')
602
- puts 'building Ruby wasm'
603
- wasi_file = 'wasi-vfs-osx_arm'
604
- wasm_common(source, destination, project_name, wasi_file, :pure_wasi)
640
+ puts "opal ready!"
641
+ end
642
+
643
+ if ARGV.include?('wasm')
644
+ puts 'building Ruby wasm'
645
+ wasi_file = 'wasi-vfs-osx_arm'
646
+ wasm_common(source, destination, project_name, wasi_file, :pure_wasi)
647
+
648
+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
649
+ # code to exec for Windows
650
+ `start "" "#{destination}\\#{project_name}\\src\\index.html"`
651
+ elsif RbConfig::CONFIG['host_os'] =~ /darwin|mac os/
652
+ # code to exec for MacOS
653
+ `open #{destination}/#{project_name}/src/index.html`
654
+ else
655
+ # code to exec for Unix/Linux
656
+ `open #{destination}/#{project_name}/src/index.html`
657
+ end
605
658
 
606
- if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
607
- # code to exec for Windows
608
- `start "" "#{destination}\\#{project_name}\\src\\index.html"`
609
- elsif RbConfig::CONFIG['host_os'] =~ /darwin|mac os/
610
- # code to exec for MacOS
611
- `open #{destination}/#{project_name}/src/index.html`
612
- else
613
- # code to exec for Unix/Linux
614
- `open #{destination}/#{project_name}/src/index.html`
615
659
  end
616
660
 
617
- end
661
+ if ARGV.include?('server')
662
+ puts 'building Server'
663
+ build_opal_application(nil, destination, project_name)
664
+ build_host_mode(destination, project_name, 'web-opal')
665
+ threads = []
666
+ threads << Thread.new do
667
+ sleep 1
668
+ if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
669
+ # code to exec with Windows
670
+ `start "" "#{destination}\\#{project_name}\\src\\index_opal.html`
671
+ elsif RbConfig::CONFIG['host_os'] =~ /darwin|mac os/
672
+ # code to exec with MacOS
673
+ `open http://localhost:9292`
674
+ else
675
+ # code to exec with Unix/Linux
676
+ `open http://localhost:9292`
677
+ end
678
+ end
679
+ threads << Thread.new do
680
+ build_for_server(destination, project_name, 9292, false)
681
+ end
618
682
 
619
- if ARGV.include?('server')
620
- puts 'building Server'
621
- build_opal_application(nil, destination, project_name)
622
- build_host_mode(destination, project_name, 'web-opal')
623
- threads = []
624
- threads << Thread.new do
625
- sleep 1
683
+ threads.each(&:join)
684
+ end
685
+
686
+ if ARGV.include?('server_refresh')
687
+ puts 're building Server'
688
+ build_opal_application(nil, destination, project_name)
626
689
  if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
627
690
  # code to exec with Windows
628
691
  `start "" "#{destination}\\#{project_name}\\src\\index_opal.html`
@@ -634,63 +697,19 @@ if ARGV.include?('server')
634
697
  `open http://localhost:9292`
635
698
  end
636
699
  end
637
- threads << Thread.new do
638
- build_for_server(destination, project_name, 9292, false)
639
- end
640
-
641
- threads.each(&:join)
642
- end
643
700
 
644
- if ARGV.include?('server_refresh')
645
- puts 're building Server'
646
- build_opal_application(nil, destination, project_name)
647
- if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
648
- # code to exec with Windows
649
- `start "" "#{destination}\\#{project_name}\\src\\index_opal.html`
650
- elsif RbConfig::CONFIG['host_os'] =~ /darwin|mac os/
651
- # code to exec with MacOS
652
- `open http://localhost:9292`
653
- else
654
- # code to exec with Unix/Linux
655
- `open http://localhost:9292`
701
+ if ARGV.include?('osx')
702
+ puts 'building osx'
703
+ wasi_file = 'wasi-vfs-osx_arm'
704
+ wasm_common(source, destination, project_name, wasi_file, :tauri)
705
+ build_for_osx(destination)
656
706
  end
657
- end
658
-
659
- if ARGV.include?('osx')
660
- puts 'building osx'
661
- wasi_file = 'wasi-vfs-osx_arm'
662
- wasm_common(source, destination, project_name, wasi_file, :tauri)
663
- build_for_osx(destination)
664
- end
665
707
 
666
- puts 'building Android' if ARGV.include?('android')
708
+ puts 'building Android' if ARGV.include?('android')
667
709
 
668
- puts 'building iOS' if ARGV.include?('ios')
669
- puts 'building Windows' if ARGV.include?('windows')
670
- puts 'building Linux' if ARGV.include?('linux')
671
- puts 'building Freebsd' if ARGV.include?('freebsd')
672
-
673
- if ARGV.include?('sparkle')
674
- if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
675
- temp_dir = 'C:\Windows\Temp'
676
- # code to exec with Windows
677
- elsif RbConfig::CONFIG['host_os'] =~ /darwin|mac os/
678
- temp_dir = '/tmp'
679
- # code to exec with MacOS
680
- else
681
- temp_dir = '/tmp'
682
- # code to exec with Unix/Linux
683
- end
684
- unless Dir.exist?("#{temp_dir}/atome_app")
685
- # `cd #{temp_dir}; atome create atome_app;cd atome_app;atome run opal`
686
- `cd #{temp_dir}; atome create atome_app`
687
- end
688
-
689
- project_name = ARGV[1]
690
- project_name = ensure_rb_extension(project_name)
691
- base_folder = File.dirname(project_name)
692
-
693
- copy_with_requires(project_name, "#{temp_dir}/atome_app/application", base_folder)
694
- `cd #{temp_dir}/atome_app;atome run opal`
710
+ puts 'building iOS' if ARGV.include?('ios')
711
+ puts 'building Windows' if ARGV.include?('windows')
712
+ puts 'building Linux' if ARGV.include?('linux')
713
+ puts 'building Freebsd' if ARGV.include?('freebsd')
695
714
 
696
715
  end
data/lib/atome/atome.rb CHANGED
@@ -5,6 +5,9 @@ class Atome
5
5
  include Essentials
6
6
 
7
7
  def initialize(new_atome = {}, &atomes_proc)
8
+ # TODO: atome format should always be as followed : {value: 0.44, unit: :px, opt1: 554}
9
+ # when using optimised version of atome you must type eg : a.set({left: {value: 33, unit: '%', reference: :center}})
10
+
8
11
  # the keys :renderers, :type and :id should be placed in the first position in the hash
9
12
  @history = {}
10
13
  @callback = {}
@@ -23,7 +26,7 @@ class Atome
23
26
  # now we store the proc in a an atome's property called :bloc
24
27
  new_atome[:code] = atomes_proc if atomes_proc
25
28
  # we reorder the hash
26
- ordered_keys = %i[renderers id type]
29
+ ordered_keys = %i[renderers id alien type]
27
30
  ordered_part = ordered_keys.map { |k| [k, new_atome[k]] }.to_h
28
31
  other_part = new_atome.reject { |k, _| ordered_keys.include?(k) }
29
32
  # merge the parts to obtain an re-ordered hash
@@ -101,7 +101,7 @@ class Object
101
101
  @repeat ||= []
102
102
  @repeat << proc
103
103
  repeat_id = @repeat.length - 1
104
- intervalId = JS.eval(<<~JS)
104
+ JS.eval(<<~JS)
105
105
  function repeat(action, interval, repetitions) {
106
106
  let count = 0;
107
107
  let intervalId = null;
@@ -128,7 +128,6 @@ class Object
128
128
 
129
129
  return intervalId;
130
130
  JS
131
- intervalId
132
131
 
133
132
  end
134
133
 
@@ -166,4 +165,322 @@ class Object
166
165
  atome_get
167
166
  end
168
167
 
168
+ # shortcut
169
+
170
+ # we initialise $current_hovered_element
171
+ $current_hovered_element = nil
172
+
173
+ def shortcut(key:, option: nil, affect: :all, exclude: [], &block)
174
+ element_ids = (Array(affect) + Array(exclude)).uniq
175
+
176
+ element_ids.each do |element_id|
177
+ element = JS.global[:document].querySelector("##{element_id}")
178
+ unless element_id.to_sym == :all
179
+ element.addEventListener("mouseenter") { $current_hovered_element = element_id }
180
+ element.addEventListener("mouseleave") { $current_hovered_element = nil }
181
+ end
182
+ end
183
+
184
+ JS.global[:document].addEventListener("keydown") do |native_event|
185
+ event = Native(native_event)
186
+ key_pressed = event[:key].to_s.downcase
187
+ ctrl_pressed = event[:ctrlKey].to_s
188
+ alt_pressed = event[:altKey].to_s
189
+ meta_pressed = event[:metaKey].to_s
190
+
191
+ modifier_matched = case option
192
+ when :ctrl then ctrl_pressed
193
+ when :alt then alt_pressed
194
+ when :meta then meta_pressed
195
+ else true
196
+ end
197
+
198
+ affect_condition = affect == :all || Array(affect).include?($current_hovered_element)
199
+ exclude_condition = !Array(exclude).include?($current_hovered_element)
200
+ $current_hovered_element = :view if $current_hovered_element.nil?
201
+ if key_pressed == key.to_s.downcase && modifier_matched && affect_condition && exclude_condition
202
+ block.call(key_pressed, $current_hovered_element)
203
+ end
204
+ end
205
+ end
206
+
207
+ def console(debug)
208
+ if debug
209
+ console = box({ id: :console, width: :auto, height: 225, bottom: 0, top: :auto, left: 0, right: 0, depth: 30, color: { alpha: 0, red: 0, green: 0, blue: 0 } })
210
+ console_back = console.box({ id: :console_back, blur: { value: 5, affect: :back }, overflow: :auto, width: :auto, height: :auto, top: 25, bottom: 0, left: 0, right: 0, depth: 30, color: { alpha: 0.5, red: 0, green: 0, blue: 0 } })
211
+ console_top = console.box({ id: :console_top, overflow: :auto, width: :auto, height: 25, top: 0, bottom: 0, left: 0, right: 0, depth: 30, color: { alpha: 1, red: 0.3, green: 0.3, blue: 0.3 } })
212
+
213
+ console_top.touch(:double) do
214
+ console.height(25)
215
+ console.bottom(0)
216
+ console.top(:auto)
217
+ end
218
+ console_top.shadow({
219
+ id: :s1,
220
+ # affect: [:the_circle],
221
+ left: 0, top: 3, blur: 9,
222
+ invert: false,
223
+ red: 0, green: 0, blue: 0, alpha: 1
224
+ })
225
+ console.drag(:locked) do |event|
226
+ dy = event[:dy]
227
+ y = console.to_px(:top) + dy.to_f
228
+ console.top(y)
229
+ console.height(:auto)
230
+ total_height = grab(:view).to_px(:height)
231
+ # console_back.height(total_height-console.top)
232
+ end
233
+ console_output = console_back.text({ data: '', id: :console_output, component: { size: 12 } })
234
+ JS.eval <<~JS
235
+ (function() {
236
+ var oldLog = console.log;
237
+ var consoleDiv = document.getElementById("console_output");
238
+ console.log = function(message) {
239
+ if (consoleDiv) {
240
+ consoleDiv.innerHTML += '<p>' + message + '</p>';
241
+ }
242
+ oldLog.apply(console, arguments);
243
+ };
244
+ }());
245
+ JS
246
+
247
+ console_clear = console_top.circle({ id: :console_clear, color: :red, top: 3, left: 3, width: 19, height: 19 })
248
+ console_clear.touch(true) do
249
+ console_output.data("")
250
+ end
251
+ JS.global[:document].addEventListener("contextmenu") do |event|
252
+ end
253
+ # element[:style][:WebkitUserSelect] = 'none'
254
+ # element[:style][:MozUserSelect] = 'none'
255
+ else
256
+ grab(:console_back).delete(true)
257
+ JS.global[:document].addEventListener("contextmenu") do |native_event|
258
+ event = Native(native_event)
259
+ event.preventDefault
260
+ end
261
+ end
262
+ end
263
+
264
+ # import methode below
265
+ def importer_all(&proc)
266
+ JS.global[:document][:body].addEventListener('dragover') do |native_event|
267
+ event = Native(native_event)
268
+ event.preventDefault
269
+ end
270
+
271
+ JS.global[:document][:body].addEventListener('drop') do |native_event|
272
+ event = Native(native_event)
273
+ event.preventDefault
274
+ files = event[:dataTransfer][:files]
275
+
276
+ if files[:length].to_i > 0
277
+ (0...files[:length].to_i).each do |i|
278
+ file = files[i]
279
+ reader = JS.eval('let a= new FileReader(); return a')
280
+ reader.readAsText(file)
281
+ reader.addEventListener('load') do
282
+ proc.call({ content: reader[:result].to_s, name: file[:name].to_s, type: file[:type].to_s, size: file[:size].to_s })
283
+ end
284
+ reader.addEventListener('error') do
285
+ puts 'Error: ' + file[:name].to_s
286
+ end
287
+ end
288
+ end
289
+ end
290
+ end
291
+
292
+ def exception_import(atome_id, &proc)
293
+ if Universe.user_atomes.include?(atome_id.to_sym)
294
+ special_div = JS.global[:document].getElementById(atome_id)
295
+ special_div.addEventListener('dragover') do |native_event|
296
+ event = Native(native_event)
297
+ special_div[:style][:backgroundColor] = 'red'
298
+ event.preventDefault
299
+ event.stopPropagation
300
+ end
301
+
302
+ special_div.addEventListener('dragleave') do |native_event|
303
+ event = Native(native_event)
304
+ special_div[:style][:backgroundColor] = 'yellow'
305
+ event.stopPropagation
306
+ end
307
+
308
+ special_div.addEventListener('drop') do |native_event|
309
+ event = Native(native_event)
310
+ event.preventDefault
311
+ event.stopPropagation
312
+
313
+ files = event[:dataTransfer][:files]
314
+
315
+ if files[:length].to_i > 0
316
+ (0...files[:length].to_i).each do |i|
317
+ file = files[i]
318
+ reader = JS.eval('let a= new FileReader(); return a')
319
+ reader.readAsText(file)
320
+ reader.addEventListener('load') do
321
+ proc.call({ content: reader[:result].to_s, name: file[:name].to_s, type: file[:type].to_s, size: file[:size].to_s })
322
+ end
323
+ reader.addEventListener('error') do
324
+ puts 'Error: ' + file[:name].to_s
325
+ end
326
+ end
327
+ end
328
+ end
329
+ JS.global[:document][:body].addEventListener('drop') do |native_event|
330
+ event = Native(native_event)
331
+ event.preventDefault
332
+ event.stopPropagation
333
+ # puts 'File drop out of the special zonne'
334
+ end
335
+ end
336
+ end
337
+
338
+ def importer(target = :all, &proc)
339
+ if target == :all
340
+ importer_all(&proc)
341
+ else
342
+ exception_import(target, &proc)
343
+ end
344
+ end
345
+
346
+ def infos
347
+ particle_list = Universe.particle_list.dup
348
+ particle_list.delete(:password)
349
+ particle_list.delete(:selection)
350
+ infos = {}
351
+ particle_list.each do |particle_found|
352
+ infos[particle_found[0]] = send(particle_found[0]) unless send(particle_found[0]).nil?
353
+ end
354
+ infos
355
+ end
356
+
357
+ def dig
358
+ ids = []
359
+ dig_recursive = lambda do |atome|
360
+ ids << atome.id
361
+ atome.attached.each { |attached_atome| dig_recursive.call(grab(attached_atome)) }
362
+ end
363
+ dig_recursive.call(self)
364
+ ids
365
+ end
366
+
367
+ def fit(params)
368
+ unless params.instance_of?(Hash)
369
+ params = { value: params }
370
+ end
371
+ target_size = params[:value]
372
+ axis = params[:axis]
373
+ objet_atome = self
374
+ atomes_found = objet_atome.dig
375
+ total_width = found_area_used(atomes_found)[:max][:x] - found_area_used(atomes_found)[:min][:x]
376
+ total_height = found_area_used(atomes_found)[:max][:y] - found_area_used(atomes_found)[:min][:y]
377
+ if axis == :x
378
+ ratio = target_size / total_width
379
+ # now we resize and re-position all atomes
380
+ atomes_found.each do |atome_id|
381
+ current_atome = grab(atome_id)
382
+ current_atome.left(current_atome.left * ratio)
383
+ current_atome.top(current_atome.top * ratio)
384
+ new_width = current_atome.to_px(:width) * ratio
385
+ new_height = current_atome.to_px(:height) * ratio
386
+ current_atome.width(new_width)
387
+ current_atome.height(new_height)
388
+ end
389
+ else
390
+ ratio = target_size / total_height
391
+ # now we resize and re-position all atomes
392
+ atomes_found.each do |atome_id|
393
+ current_atome = grab(atome_id)
394
+ current_atome.left(current_atome.left * ratio)
395
+ current_atome.top(current_atome.top * ratio)
396
+ current_atome.width(current_atome.to_px(:width) * ratio)
397
+ current_atome.height(current_atome.to_px(:height) * ratio)
398
+ end
399
+ end
400
+ # total_size, max_other_axis_size = calculate_total_size(objet_atome, axis)
401
+ # scale_factor = target_size.to_f / total_size
402
+ # resize_and_reposition(objet_atome, scale_factor, axis, max_other_axis_size)
403
+ end
404
+
405
+ def found_area_used(ids)
406
+
407
+ min_x, min_y = Float::INFINITY, Float::INFINITY
408
+ max_x, max_y = 0, 0
409
+
410
+ ids.each do |id|
411
+ atome = grab(id)
412
+
413
+ x = atome.compute({ particle: :left })[:value]
414
+ y = atome.compute({ particle: :top })[:value]
415
+ width = atome.to_px(:width)
416
+ height = atome.to_px(:height)
417
+ min_x = [min_x, x].min
418
+ min_y = [min_y, y].min
419
+ max_x = [max_x, x + width].max
420
+ max_y = [max_y, y + height].max
421
+ end
422
+
423
+ { min: { x: min_x, y: min_y }, max: { x: max_x, y: max_y } }
424
+
425
+ end
426
+
427
+ def calculate_total_size(objet_atome, axis)
428
+ total_size = (axis == :x) ? objet_atome.to_px(:width) : objet_atome.to_px(:height)
429
+ max_other_axis_size = (axis == :x) ? objet_atome.to_px(:height) : objet_atome.to_px(:width)
430
+
431
+ objet_atome.attached.each do |child_id|
432
+ child = grab(child_id)
433
+ child_size = (axis == :x) ? child.to_px(:width) : child.to_px(:height)
434
+ other_axis_size = (axis == :x) ? child.to_px(:height) : child.to_px(:width)
435
+
436
+ total_size += child_size
437
+ max_other_axis_size = [max_other_axis_size, other_axis_size].max
438
+ end
439
+
440
+ [total_size, max_other_axis_size]
441
+ end
442
+
443
+ def resize_and_reposition(objet_atome, scale_factor, axis, max_other_axis_size)
444
+ current_position = 0
445
+ resize_object(objet_atome, scale_factor, axis, max_other_axis_size)
446
+ current_position += (axis == :x) ? objet_atome.to_px(:width) : objet_atome.to_px(:height)
447
+ objet_atome.attached.each do |child_id|
448
+ child = grab(child_id)
449
+ resize_object(child, scale_factor, axis, max_other_axis_size)
450
+ child.top(child.top * scale_factor)
451
+ child.left(child.left * scale_factor)
452
+ current_position += child.to_px(:height)
453
+ end
454
+ end
455
+
456
+ def resize_object(objet, scale_factor, axis, max_other_axis_size)
457
+ if axis == :x
458
+ new_width = objet.width * scale_factor
459
+ new_height = new_width / (objet.width.to_f / objet.height)
460
+ objet.width(new_width)
461
+ objet.height([new_height, max_other_axis_size].min)
462
+ else
463
+ new_height = objet.height * scale_factor
464
+ new_width = new_height / (objet.height.to_f / objet.width)
465
+ objet.height(new_height)
466
+ objet.width([new_width, max_other_axis_size].min)
467
+ end
468
+ end
469
+
470
+ def atomizer(params)
471
+ unless params.instance_of? Hash
472
+ params = { target: params }
473
+ end
474
+ id = params[:id]
475
+ if id
476
+ id_wanted = { id: id }
477
+ else
478
+ id_wanted = {}
479
+ end
480
+ basis = { alien: params[:target],renderers: [:html], type: :atomized }.merge(id_wanted)
481
+ a = Atome.new(basis)
482
+ return a
483
+ # convert any foreign object (think HTML) to a pseudo atome objet , that embed foreign objet
484
+ end
485
+
169
486
  end
@@ -18,12 +18,17 @@ new({ sanitizer: :image }) do |params|
18
18
  # TODO : we have to convert all image to png or maintain a database with extension
19
19
  # FIXME : temporary patch that add .png to the string if no extension is found
20
20
  params = "#{params}.png" if params.to_s.split('.').length == 1
21
-
22
21
  params = { path: "./medias/images/#{params}" }
23
22
  end
24
23
  # TODO : the line below should get the value from default params Essentials
25
24
  params
26
25
  end
26
+ new({ post: :image }) do
27
+ # we have find the size od the image to set it in the atome
28
+ instance_variable_set("@width", compute({ particle: :width })[:value])
29
+ instance_variable_set("@height", compute({ particle: :height })[:value])
30
+ end
31
+
27
32
  new({ atome: :video })
28
33
  new({ sanitizer: :video }) do |params|
29
34
  unless params.instance_of? Hash
@@ -87,4 +92,8 @@ new({ atome: :machine })
87
92
  new({ atome: :paint })
88
93
  new({ atome: :vector })
89
94
 
95
+ new({ atome: :matrix })
96
+ new({ atome: :atomized, type: :hash })
97
+
98
+
90
99
 
@@ -6,6 +6,14 @@ new({ particle: :connection }) do |params, bloc|
6
6
  end
7
7
 
8
8
  new({ particle: :message }) do |params, bloc|
9
- params = { server: params } unless params.instance_of? Hash
10
- html.send_message(params[:server], &bloc)
9
+
10
+ params = {message: params } unless params.instance_of? Hash
11
+ params[:user]=Universe.current_user
12
+ params[:pass]=Black_matter.password
13
+
14
+ html.send_message(params, &bloc)
11
15
  end
16
+
17
+ new({ particle: :controller }) do |msg|
18
+ Atome.controller_sender(msg)
19
+ end
@@ -1,4 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  new({ particle: :smooth })
4
- new({ particle: :blur })
4
+
5
+
6
+ new({ particle: :blur }) do |params|
7
+ # alert params
8
+ { value: params, affect: :self } unless params.instance_of?(Hash)
9
+ # params
10
+ end
@@ -229,9 +229,10 @@ new({ sanitizer: :over }) do |params, user_bloc|
229
229
  params
230
230
 
231
231
  end
232
- new({ particle: :sort }) do |_value, sort_proc|
233
- @sort_proc = sort_proc
234
- end
232
+ # new({ particle: :sort }) do |_value, sort_proc|
233
+ # @sort_proc = sort_proc
234
+ # end
235
+
235
236
  new({ particle: :targets })
236
237
  new({ particle: :start })
237
238
  new({ pre: :start }) do |_value, user_proc|