atome 0.5.1.4 → 0.5.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +23 -2
  3. data/lib/atome/atome.rb +40 -18
  4. data/lib/atome/extensions/atome.rb +5 -26
  5. data/lib/atome/extensions/geolocation.rb +0 -1
  6. data/lib/atome/extensions/matrix.rb +171 -0
  7. data/lib/atome/extensions/ping.rb +9 -11
  8. data/lib/atome/genesis/generators/atome.rb +14 -2
  9. data/lib/atome/genesis/generators/communication.rb +1 -1
  10. data/lib/atome/genesis/generators/event.rb +36 -0
  11. data/lib/atome/genesis/generators/identity.rb +28 -2
  12. data/lib/atome/genesis/generators/material.rb +21 -0
  13. data/lib/atome/genesis/generators/spatial.rb +1 -0
  14. data/lib/atome/genesis/generators/utility.rb +20 -2
  15. data/lib/atome/genesis/genesis.rb +2 -2
  16. data/lib/atome/genesis/sparkle.rb +1 -1
  17. data/lib/atome/helpers/callbacks.rb +76 -0
  18. data/lib/atome/helpers/essentials.rb +10 -5
  19. data/lib/atome/helpers/utilities.rb +52 -8
  20. data/lib/atome/kernel/universe.rb +0 -4
  21. data/lib/atome/presets/atome.rb +12 -8
  22. data/lib/atome/renderers/browser/atome.rb +8 -19
  23. data/lib/atome/renderers/browser/browser.rb +15 -210
  24. data/lib/atome/renderers/browser/effect.rb +2 -2
  25. data/lib/atome/renderers/browser/event.rb +49 -11
  26. data/lib/atome/renderers/browser/geometry.rb +2 -2
  27. data/lib/atome/renderers/browser/helpers/animation_helper.rb +69 -0
  28. data/lib/atome/renderers/browser/helpers/browser_helper.rb +17 -0
  29. data/lib/atome/renderers/browser/helpers/color_helper.rb +33 -0
  30. data/lib/atome/renderers/browser/helpers/drag_helper.rb +39 -0
  31. data/lib/atome/renderers/browser/helpers/effect_helper.rb +26 -0
  32. data/lib/atome/renderers/browser/helpers/event_helper.rb +59 -0
  33. data/lib/atome/renderers/browser/helpers/image_helper.rb +27 -0
  34. data/lib/atome/renderers/browser/helpers/shadow_helper.rb +33 -0
  35. data/lib/atome/renderers/browser/helpers/shape_helper.rb +22 -0
  36. data/lib/atome/renderers/browser/helpers/text_helper.rb +26 -0
  37. data/lib/atome/renderers/browser/helpers/video_helper.rb +43 -0
  38. data/lib/atome/renderers/browser/helpers/web_helper.rb +30 -0
  39. data/lib/atome/renderers/browser/identity.rb +10 -3
  40. data/lib/atome/renderers/browser/material.rb +28 -5
  41. data/lib/atome/renderers/browser/spatial.rb +36 -5
  42. data/lib/atome/renderers/browser/utility.rb +21 -12
  43. data/lib/atome/renderers/headless/utility.rb +2 -2
  44. data/lib/atome/renderers/html/atome.rb +5 -5
  45. data/lib/atome/renderers/html/effect.rb +1 -1
  46. data/lib/atome/renderers/html/event.rb +1 -1
  47. data/lib/atome/renderers/html/geometry.rb +2 -2
  48. data/lib/atome/renderers/html/html.rb +1 -1
  49. data/lib/atome/renderers/html/identity.rb +2 -2
  50. data/lib/atome/renderers/html/spatial.rb +5 -5
  51. data/lib/atome/renderers/html/utility.rb +7 -7
  52. data/lib/atome/renderers/server/utility.rb +2 -2
  53. data/lib/atome/version.rb +1 -1
  54. data/lib/atome.rb +6 -4
  55. data/sig/atome.rbs +1 -0
  56. data/sig/atome_js.rbs +1 -0
  57. data/vendor/assets/build/css/style.css +25 -17
  58. data/vendor/assets/build/index.html +12 -3
  59. data/vendor/assets/build/js/atome/atome.js +150 -145
  60. data/vendor/assets/build/js/atome/atome_helpers/atome_animate.js +65 -0
  61. data/vendor/assets/build/js/atome/atome_helpers/atome_drag.js +85 -0
  62. data/vendor/assets/build/js/atome/atome_helpers/atome_file.js +7 -0
  63. data/vendor/assets/build/js/atome/atome_helpers/atome_sort.js +20 -0
  64. data/vendor/assets/build/js/atome/atome_helpers/atome_time.js +10 -0
  65. data/vendor/assets/build/js/atome/atome_helpers/atome_video.js +12 -0
  66. data/vendor/assets/build/js/third_parties/popmotion.min.js +1 -1
  67. data/vendor/assets/build/js/third_parties/sortable.min.js +2 -0
  68. data/vendor/assets/build/js/third_parties/wad.min.js +9 -0
  69. data/vendor/assets/build/medias/audios/Binrpilot.mp3 +0 -0
  70. data/vendor/assets/build/medias/rubies/examples/_2_solve.rb +45 -0
  71. data/vendor/assets/build/medias/rubies/examples/_audio.rb +178 -0
  72. data/vendor/assets/build/medias/rubies/examples/_dataset.rb +82 -0
  73. data/vendor/assets/build/medias/rubies/examples/_markers.rb +57 -0
  74. data/vendor/assets/build/medias/rubies/examples/_os.rb +29 -0
  75. data/vendor/assets/build/medias/rubies/examples/_vie.rb +211 -0
  76. data/vendor/assets/build/medias/rubies/examples/animation.rb +81 -0
  77. data/vendor/assets/build/medias/rubies/examples/at.rb +21 -0
  78. data/vendor/assets/build/medias/rubies/examples/{atome.new.rb → atome_new.rb} +5 -5
  79. data/vendor/assets/build/medias/rubies/examples/bottom.rb +1 -1
  80. data/vendor/assets/build/medias/rubies/examples/center.rb +21 -0
  81. data/vendor/assets/build/medias/rubies/examples/clone.rb +20 -0
  82. data/vendor/assets/build/medias/rubies/examples/color.rb +20 -15
  83. data/vendor/assets/build/medias/rubies/examples/cursor.rb +7 -0
  84. data/vendor/assets/build/medias/rubies/examples/delete.rb +25 -3
  85. data/vendor/assets/build/medias/rubies/examples/drag.rb +39 -0
  86. data/vendor/assets/build/medias/rubies/examples/edit.rb +12 -0
  87. data/vendor/assets/build/medias/rubies/examples/empty_atome.rb +12 -0
  88. data/vendor/assets/build/medias/rubies/examples/hide.rb +7 -0
  89. data/vendor/assets/build/medias/rubies/examples/matrix.rb +58 -0
  90. data/vendor/assets/build/medias/rubies/examples/monitoring.rb +22 -11
  91. data/vendor/assets/build/medias/rubies/examples/mute.rb +22 -0
  92. data/vendor/assets/build/medias/rubies/examples/on.rb +7 -1
  93. data/vendor/assets/build/medias/rubies/examples/{parent.rb → parents.rb} +6 -6
  94. data/vendor/assets/build/medias/rubies/examples/pause.rb +15 -0
  95. data/vendor/assets/build/medias/rubies/examples/play.rb +15 -0
  96. data/vendor/assets/build/medias/rubies/examples/read.rb +7 -4
  97. data/vendor/assets/build/medias/rubies/examples/remove.rb +16 -0
  98. data/vendor/assets/build/medias/rubies/examples/right.rb +1 -1
  99. data/vendor/assets/build/medias/rubies/examples/schedule.rb +2 -2
  100. data/vendor/assets/build/medias/rubies/examples/shadow.rb +8 -1
  101. data/vendor/assets/build/medias/rubies/examples/sort.rb +19 -0
  102. data/vendor/assets/build/medias/rubies/examples/style.rb +4 -0
  103. data/vendor/assets/build/medias/rubies/examples/time.rb +14 -0
  104. data/vendor/assets/build/medias/rubies/examples/touch.rb +50 -7
  105. data/vendor/assets/build/medias/texts/lorem.txt +1 -0
  106. metadata +50 -7
  107. data/lib/atome/processors/utilities.rb +0 -10
  108. data/vendor/assets/build/medias/rubies/examples/_animation.rb +0 -0
  109. data/vendor/assets/build/medias/rubies/examples/_drag.rb +0 -44
@@ -2,6 +2,14 @@
2
2
 
3
3
  # callbacks methods here
4
4
  class Atome
5
+ private
6
+
7
+ attr_accessor :drag_start_proc, :drag_move_proc, :drag_end_proc,
8
+ :play_start_proc, :play_active_proc, :play_end_proc,
9
+ :animation_start_proc, :animation_active_proc, :animation_stop_proc
10
+
11
+ public
12
+
5
13
  def schedule_callback(proc)
6
14
  instance_exec(&proc) if proc.is_a?(Proc)
7
15
  end
@@ -9,4 +17,72 @@ class Atome
9
17
  def read_callback(file, proc)
10
18
  instance_exec(file, &proc) if proc.is_a?(Proc)
11
19
  end
20
+
21
+ def time_callback(current_time)
22
+ # puts "time_callback = #{current_time.round(1)}\n#{current_time}"
23
+ @atome[:time] = current_time
24
+ # the line below is used only to set up a one shot event
25
+ # return unless @at_time[:time] && (current_time > @at_time[:time] && @at_time[:used].nil?)
26
+
27
+ return unless @at_time[:time] && (current_time > @at_time[:time])
28
+ proc = @at_time[:code]
29
+ instance_exec(current_time, &proc) if proc.is_a?(Proc)
30
+ # @at_time[:used] = true
31
+ end
32
+
33
+ def drag_start_callback(page_x, page_y, left_val, top_val)
34
+ @atome[:left] = left_val
35
+ @atome[:top] = top_val
36
+ proc = @drag_start_proc
37
+ instance_exec({ pageX: page_x, pageY: page_y, left: left_val, top: top_val }, &proc) if proc.is_a?(Proc)
38
+ end
39
+
40
+ def drag_move_callback(page_x, page_y, left_val, top_val)
41
+ proc = @drag_move_proc
42
+ @atome[:left] = left_val
43
+ @atome[:top] = top_val
44
+ instance_exec({ pageX: page_x, pageY: page_y, left: left_val, top: top_val }, &proc) if proc.is_a?(Proc)
45
+ end
46
+
47
+ def drag_end_callback(page_x, page_y, left_val, top_val)
48
+ @atome[:left] = left_val
49
+ @atome[:top] = top_val
50
+ proc = @drag_end_proc
51
+ instance_exec({ pageX: page_x, pageY: page_y, left: left_val, top: top_val }, &proc) if proc.is_a?(Proc)
52
+ end
53
+
54
+ # sort callbacks
55
+ def sort_callback(atome)
56
+ sort_proc = @sort_proc
57
+ instance_exec(atome, &sort_proc) if sort_proc.is_a?(Proc)
58
+ end
59
+
60
+ # animation
61
+ def browser_animate_callback(particle_found, value, animation_hash, original_particle, animation_atome)
62
+ anim_proc = animation_hash[:code]
63
+ # we exec the callback bloc from :animate
64
+ instance_exec({ original_particle => value }, &anim_proc) if anim_proc.is_a?(Proc)
65
+ # we exec the callback bloc from :play
66
+ play_proc = animation_atome.play_active_proc
67
+ instance_exec({ @atome[particle_found] => value }, &play_proc) if play_proc.is_a?(Proc)
68
+ # we animate:
69
+ browser_object.style[particle_found] = value if browser_object
70
+ # we update the atome property
71
+ @atome[original_particle] = value
72
+ end
73
+
74
+ def play_start_callback(_particle_found, _start_value, animation_hash, original_particle, atome_found)
75
+ value = animation_hash[:begin][original_particle]
76
+ value = atome_found.atome[original_particle] if value == :self
77
+ start_proc = @animation_start_proc
78
+ @atome[original_particle] = value
79
+ instance_exec({ original_particle => value }, &start_proc) if start_proc.is_a?(Proc)
80
+ end
81
+
82
+ def play_stop_callback(_particle_found, _end_value, animation_hash, original_particle, _atome_found)
83
+ value = animation_hash[:end][original_particle]
84
+ end_proc = @animation_stop_proc
85
+ @atome[original_particle] = value
86
+ instance_exec({ original_particle => value }, &end_proc) if end_proc.is_a?(Proc)
87
+ end
12
88
  end
@@ -4,15 +4,20 @@
4
4
  module Essentials
5
5
  @default_params = {
6
6
  render_engines: [:browser],
7
+ animation: { type: :animation },
7
8
  element: { type: :element, renderers: [] },
8
- box: { renderers: '', id: '', type: :shape, parents: [], children: [], width: 99, height: 99 },
9
+ box: { renderers: '', id: '', type: :shape, parents: [], children: [], width: 99, height: 99,
10
+ color: { left: 0, top: 0, red: 0.1, green: 0.9, blue: 0.9, alpha: 1, diffusion: :linear },
11
+ left: 100, top: 100 },
9
12
  circle: { renderers: '', id: '', type: :shape, parents: [], children: [], width: 99, height: 99,
10
- smooth: '100%' },
13
+ color: { left: 0, top: 0, red: 0.1, green: 0.9, blue: 0.9, alpha: 1, diffusion: :linear },
14
+ left: 100, top: 100, smooth: '100%' },
11
15
  shape: { renderers: '', id: '', width: 100, type: :shape, height: 100, left: 100, top: 100,
12
- color: { left: 0, top: 0, z: 0, red: 0.1, green: 0.9, blue: 0.9, alpha: 1, diffusion: :linear },
16
+ color: { left: 0, top: 0, red: 0.1, green: 0.9, blue: 0.9, alpha: 1, diffusion: :linear },
13
17
  generator: :manual },
14
- text: { type: :text, parents: [:view], children: [], visual: { size: 25 },
15
- data: 'this is a text sample', width: 199, height: 33 },
18
+ text: { renderers: '', id: '',type: :text, parents: [:view], children: [], visual: { size: 25 },
19
+ color: { left: 0, top: 0, red: 0.3, green: 0.3, blue: 0.3, alpha: 1, diffusion: :linear },
20
+ data: 'this is a text sample', width: 199, height: 33 },
16
21
  drm: { type: :drm },
17
22
  shadow: {}
18
23
  }
@@ -24,22 +24,66 @@ class Atome
24
24
  { date: Time.now, location: geolocation }
25
25
  end
26
26
 
27
- def broadcasting(element, value)
28
- return unless @broadcast[:particles]&.include?(element)
29
-
30
- bloc_found = @broadcast[:bloc]
31
- instance_exec(self, element, value, &bloc_found) if bloc_found.is_a?(Proc)
32
- end
33
-
34
27
  def history(property, value)
35
28
  "historize : #{property} #{value}"
36
29
  end
37
30
 
31
+ # def broadcasting(modified_particle, value)
32
+ # @broadcast.each_value do |particle_monitored|
33
+ # if particle_monitored[modified_particle]
34
+ # code_found = particle_monitored[modified_particle]
35
+ # instance_exec(self, modified_particle, value, &code_found) if code_found.is_a?(Proc)
36
+ # end
37
+ # end
38
+ # end
39
+ #
40
+ # public
41
+ #
42
+ # def monitor(params, &proc_monitoring)
43
+ # atome[:monitor] ||= {}
44
+ # params[:atomes].each do |atome_id|
45
+ # target_broadcaster = grab(atome_id).instance_variable_get('@broadcast')
46
+ # monitor_id = params[:id] || "monitor#{target_broadcaster.length}"
47
+ # atome[:monitor] [monitor_id]=params.merge({code: proc_monitoring})
48
+ # params[:particles].each do |targeted_particle|
49
+ # target_broadcaster[monitor_id] = { targeted_particle => proc_monitoring }
50
+ # end
51
+ # end
52
+ # end
53
+
54
+ def broadcasting(altered_particle, value)
55
+ @broadcast.each_value do |particle_monitored|
56
+ if particle_monitored[:particles].include?(altered_particle)
57
+ code_found=particle_monitored[:code]
58
+ instance_exec(self, altered_particle, value, &code_found) if code_found.is_a?(Proc)
59
+ end
60
+ end
61
+ end
62
+
38
63
  public
39
64
 
40
65
  def monitor(params, &proc_monitoring)
66
+ atome[:monitor] ||= {}
41
67
  params[:atomes].each do |atome_id|
42
- grab(atome_id).instance_variable_set('@broadcast', { particles: params[:particles], bloc: proc_monitoring })
68
+ target_broadcaster = grab(atome_id).instance_variable_get('@broadcast')
69
+ monitor_id = params[:id] || "monitor#{target_broadcaster.length}"
70
+ atome[:monitor] [monitor_id]=params.merge({code: proc_monitoring})
71
+ target_broadcaster[monitor_id] = { particles: params[:particles], code: proc_monitoring }
72
+ end
73
+ end
74
+ def store_code_bloc(element, &user_proc)
75
+ Object.attr_accessor "#{element}_code"
76
+
77
+ instance_variable_set("@#{element}_code", user_proc)
78
+ end
79
+
80
+ def particles(particles_found = nil)
81
+ if particles_found
82
+ particles_found.each do |particle_found, value_found|
83
+ atome[particle_found] = value_found
84
+ end
85
+ else
86
+ atome
43
87
  end
44
88
  end
45
89
 
@@ -58,10 +58,6 @@ class Universe
58
58
  # and finally the object is 3 as this the third object created by the main server
59
59
  end
60
60
 
61
- # def change_atome_id(prev_id, new_id)
62
- # @atomes[new_id] = @atomes.delete(prev_id)
63
- # end
64
-
65
61
  def delete(id)
66
62
  @atomes.delete(id)
67
63
  end
@@ -8,9 +8,10 @@
8
8
  # shaper creation
9
9
  class Atome
10
10
  def atome_common(atome_type, generated_id, generated_render, generated_parents, params)
11
- temp_default = Essentials.default_params[atome_type]
11
+ temp_default = Essentials.default_params[atome_type] || {}
12
12
  temp_default[:id] = generated_id
13
13
  temp_default[:parents] = generated_parents
14
+ temp_default[:clones] = []
14
15
  temp_default[:renderers] = generated_render
15
16
  temp_default.merge(params)
16
17
  end
@@ -22,8 +23,6 @@ class Atome
22
23
  generated_id = params[:id] || "#{atome_type}_#{Universe.atomes.length}"
23
24
  generated_parents = params[:parents] || [id.value]
24
25
  params = atome_common(atome_type, generated_id, generated_render, generated_parents, params)
25
- color_generated = sanitize(:color, { parents: [generated_id], red: 0.3, green: 0.3, blue: 0.3 })
26
- params[:color] = color_generated
27
26
  Atome.new({ atome_type => params }, &bloc)
28
27
  end
29
28
 
@@ -34,14 +33,11 @@ class Atome
34
33
  generated_id = params[:id] || "#{atome_type}_#{Universe.atomes.length}"
35
34
  generated_parents = params[:parents] || [id.value]
36
35
  params = atome_common(atome_type, generated_id, generated_render, generated_parents, params)
37
- color_generated = sanitize(:color, { parents: [generated_id], red: 0.6, green: 0.6, blue: 0.6 })
38
- params[:color] = color_generated
39
36
  Atome.new({ atome_type => params }, &bloc)
40
37
  end
41
38
 
42
39
  def image(params = {}, &bloc)
43
40
  default_renderer = Essentials.default_params[:render_engines]
44
-
45
41
  generated_id = params[:id] || "image_#{Universe.atomes.length}"
46
42
  generated_render = params[:renderers] || default_renderer
47
43
  generated_parents = params[:parents] || id.value
@@ -59,8 +55,6 @@ class Atome
59
55
  generated_id = params[:id] || "#{atome_type}_#{Universe.atomes.length}"
60
56
  generated_parents = params[:parents] || [id.value]
61
57
  params = atome_common(atome_type, generated_id, generated_render, generated_parents, params)
62
- color_generated = sanitize(:color, { parents: [generated_id], red: 0.9, green: 0.9, blue: 0.9 })
63
- params[:color] = color_generated
64
58
  Atome.new({ atome_type => params }, &bloc)
65
59
  end
66
60
 
@@ -85,4 +79,14 @@ class Atome
85
79
  params = temp_default.merge(params)
86
80
  Atome.new({ image: params }, &bloc)
87
81
  end
82
+
83
+ def animation(params = {}, &bloc)
84
+ default_renderer = Essentials.default_params[:render_engines]
85
+ atome_type = :animation
86
+ generated_render = params[:renderers] || default_renderer
87
+ generated_id = params[:id] || "#{atome_type}_#{Universe.atomes.length}"
88
+ generated_parents = params[:parents] || []
89
+ params = atome_common(atome_type, generated_id, generated_render, generated_parents, params)
90
+ Atome.new({ atome_type => params }, &bloc)
91
+ end
88
92
  end
@@ -10,18 +10,16 @@ def parents(_val) end
10
10
 
11
11
  generator = Genesis.generator
12
12
 
13
- generator.build_render_method(:browser_shape) do
13
+ generator.build_render(:browser_shape) do
14
14
  @browser_type = :div
15
15
  id_found = @atome[:id]
16
16
  DOM do
17
17
  div(id: id_found).atome
18
18
  end.append_to(BrowserHelper.browser_document[:user_view])
19
19
  @browser_object = BrowserHelper.browser_document[id_found]
20
- # Render particles below
21
- # collapse
22
20
  end
23
21
 
24
- generator.build_render_method(:browser_color) do |_value|
22
+ generator.build_render(:browser_color) do |_value|
25
23
  @browser_type = :style
26
24
  id_found = @atome[:id]
27
25
  type_found = @atome[:type]
@@ -36,13 +34,9 @@ generator.build_render_method(:browser_color) do |_value|
36
34
  #{green_found * 255},#{blue_found * 255},#{alpha_found})}</style>")
37
35
  # TODO/ use the code below to modify the style tag
38
36
  @browser_object = BrowserHelper.browser_document[id_found]
39
- # now we just have to attach the color atome
40
- # parents(@atome[:parents])
41
- # children(@atome[:children])
42
- # collapse
43
37
  end
44
38
 
45
- generator.build_render_method(:browser_shadow) do |_value|
39
+ generator.build_render(:browser_shadow) do |_value|
46
40
  @browser_type = :style
47
41
  id_found = @atome[:id]
48
42
  type_found = @atome[:type]
@@ -64,29 +58,25 @@ generator.build_render_method(:browser_shadow) do |_value|
64
58
  @browser_object = BrowserHelper.browser_document[id_found]
65
59
  end
66
60
 
67
- generator.build_render_method(:browser_image) do |_user_prc|
61
+ generator.build_render(:browser_image) do |_user_prc|
68
62
  @browser_type = :div
69
63
  id_found = @atome[:id]
70
64
  DOM do
71
65
  img({ id: id_found }).atome
72
66
  end.append_to(BrowserHelper.browser_document[:user_view])
73
67
  @browser_object = BrowserHelper.browser_document[id_found]
74
- # Render particles below
75
- # collapse
76
68
  end
77
69
 
78
- generator.build_render_method(:browser_text) do |_value, _user_proc|
70
+ generator.build_render(:browser_text) do |_value, _user_proc|
79
71
  id_found = @atome[:id]
80
72
  DOM do
81
73
  div(id: id_found).atome.text
82
74
  end.append_to(BrowserHelper.browser_document[:user_view])
83
75
  @browser_object = BrowserHelper.browser_document[id_found]
84
76
  @browser_type = :div
85
- # Render particles below
86
- # collapse
87
77
  end
88
78
 
89
- generator.build_render_method(:browser_web) do
79
+ generator.build_render(:browser_web) do
90
80
  @browser_type = :web
91
81
  id_found = @atome[:id]
92
82
  DOM do
@@ -95,14 +85,13 @@ generator.build_render_method(:browser_web) do
95
85
  @browser_object = BrowserHelper.browser_document[id_found]
96
86
  @browser_object.attributes[:allow] = 'accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture'
97
87
  @browser_object.attributes[:allowfullscreen] = true
98
- @html_type = :web
99
88
  end
100
89
 
101
- generator.build_render_method(:browser_video) do |_value, _user_proc|
90
+ generator.build_render(:browser_video) do |_value, _user_proc|
102
91
  @browser_type = :div
103
92
  id_found = @atome[:id]
104
93
  DOM do
105
- video({ id: id_found, autoplay: false, loop: false, muted: true }).atome
94
+ video({ id: id_found, autoplay: false, loop: false, muted: false }).atome
106
95
  end.append_to(BrowserHelper.browser_document[:user_view])
107
96
  @browser_object = BrowserHelper.browser_document[id_found]
108
97
  end
@@ -8,218 +8,23 @@ require 'atome/renderers/browser/material'
8
8
  require 'atome/renderers/browser/spatial'
9
9
  require 'atome/renderers/browser/atome'
10
10
  require 'atome/renderers/browser/utility'
11
+ require 'atome/renderers/browser/helpers/browser_helper'
12
+ require 'atome/renderers/browser/helpers/animation_helper'
13
+ require 'atome/renderers/browser/helpers/color_helper'
14
+ require 'atome/renderers/browser/helpers/drag_helper'
15
+ require 'atome/renderers/browser/helpers/effect_helper'
16
+ require 'atome/renderers/browser/helpers/event_helper'
17
+ require 'atome/renderers/browser/helpers/image_helper'
18
+ require 'atome/renderers/browser/helpers/shadow_helper'
19
+ require 'atome/renderers/browser/helpers/shape_helper'
20
+ require 'atome/renderers/browser/helpers/text_helper'
21
+ require 'atome/renderers/browser/helpers/video_helper'
22
+ require 'atome/renderers/browser/helpers/web_helper'
11
23
 
12
24
  class Atome
13
- attr_accessor :browser_object
25
+ attr_accessor 'browser_object'
14
26
  end
15
27
 
16
- # for opal rendering
17
- module BrowserHelper
18
- def self.browser_document
19
- # Work because of the patched version of opal-browser(0.39)
20
- Browser.window
21
- end
22
-
23
- def self.browser_attach_div(parents, html_object, _atome)
24
- html_object.append_to(browser_document[parents])
25
- end
26
-
27
- def self.browser_attach_web(parents, html_object, _atome)
28
- html_object.append_to(browser_document[parents])
29
- end
30
-
31
- def self.browser_attach_style(parents, _html_object, atome)
32
- browser_document[parents].add_class(atome[:id])
33
- end
34
-
35
- def self.browser_blur_style(_browser_object, value, atome)
36
- b_left = "#{atome[:left]}px"
37
- b_top = "#{atome[:top]}px"
38
- b_blur = "#{atome[:blur] = value}px"
39
- b_red = atome[:red] * 255
40
- b_green = atome[:green] * 255
41
- b_blue = (atome[:blue]) * 255
42
- b_direction = atome[:direction]
43
- b_alpha = atome[:alpha]
44
-
45
- shadow_updated = "#{b_left} #{b_top} #{b_blur} rgba(#{b_red}, #{b_green}, #{b_blue}, #{b_alpha}) #{b_direction}"
46
- `document.getElementById(#{atome[:id]}).sheet.cssRules[0].style.boxShadow = #{shadow_updated}`
47
- end
48
-
49
- def self.browser_blur_div(browser_object, value, _atome)
50
- browser_object.style[:filter] = "blur(#{value}px)"
51
- end
52
-
53
- def self.browser_colorize_color(color_updated, atome)
54
- `document.getElementById(#{atome[:id]}).sheet.cssRules[0].style.backgroundColor = #{color_updated}`
55
- end
56
-
57
- def self.browser_colorize_shadow(color_updated, atome)
58
- left = atome[:left]
59
- top = atome[:top]
60
- blur = atome[:blur]
61
- direction = atome[:direction]
62
- shadow_updated = "#{left}px #{top}px #{blur}px #{color_updated} #{direction}"
63
- `document.getElementById(#{atome[:id]}).sheet.cssRules[0].style.boxShadow = #{shadow_updated}`
64
- end
65
-
66
- def self.browser_left_shape(value, browser_object, _atome)
67
- browser_object.style[:left] = "#{value}px"
68
- end
69
-
70
- def self.browser_right_shape(value, browser_object, _atome)
71
- browser_object.style[:right] = "#{value}px"
72
- end
73
-
74
- def self.browser_top_shape(value, browser_object, _atome)
75
- browser_object.style[:top] = "#{value}px"
76
- end
77
-
78
- def self.browser_bottom_shape(value, browser_object, _atome)
79
- browser_object.style[:bottom] = "#{value}px"
80
- end
81
-
82
- # image
83
- def self.browser_left_image(value, browser_object, _atome)
84
- browser_object.style[:left] = "#{value}px"
85
- end
86
-
87
- def self.browser_right_image(value, browser_object, _atome)
88
- browser_object.style[:right] = "#{value}px"
89
- end
90
-
91
- def self.browser_top_image(value, browser_object, _atome)
92
- browser_object.style[:top] = "#{value}px"
93
- end
94
-
95
- def self.browser_bottom_image(value, browser_object, _atome)
96
- browser_object.style[:bottom] = "#{value}px"
97
- end
98
-
99
- def self.browser_path_image(value, browser_object, _atome)
100
- browser_object[:src] = value
101
- end
102
-
103
- # shadow
104
- def self.browser_left_shadow(value, _browser_object, atome)
105
- ls_left = "#{atome[:left] = value}px"
106
- ls_top = "#{atome[:top]}px"
107
- ls_blur = "#{atome[:blur]}px"
108
- red = atome[:red] * 255
109
- green = atome[:green] * 255
110
- blue = (atome[:blue]) * 255
111
- direction = atome[:direction]
112
- alpha = atome[:alpha]
113
-
114
- shadow_updated = "#{ls_left} #{ls_top} #{ls_blur} rgba(#{red}, #{green}, #{blue}, #{alpha}) #{direction}"
115
- `document.getElementById(#{atome[:id]}).sheet.cssRules[0].style.boxShadow = #{shadow_updated}`
116
- end
117
-
118
- def self.browser_top_shadow(value, _browser_object, atome)
119
- rs_left = "#{atome[:left]}px"
120
- rs_top = "#{atome[:top] = value}px"
121
- rs_blur = "#{atome[:blur]}px"
122
- red = atome[:red] * 255
123
- green = atome[:green] * 255
124
- blue = (atome[:blue]) * 255
125
- direction = atome[:direction]
126
- alpha = atome[:alpha]
127
-
128
- shadow_updated = "#{rs_left}px #{rs_top}px #{rs_blur}px rgba(#{red}, #{green}, #{blue}, #{alpha}) #{direction}"
129
- `document.getElementById(#{atome[:id]}).sheet.cssRules[0].style.boxShadow = #{shadow_updated}`
130
- end
131
-
132
- def self.browser_left_color(_value, _browser_object, _atome)
133
- puts 'code to write when implementing gradient'
134
- end
135
-
136
- def self.browser_right_color(_value, _browser_object, _atome)
137
- puts 'code to write when implementing gradient'
138
- end
139
-
140
- def self.browser_top_color(_value, _browser_object, _atome)
141
- puts 'code to write when implementing gradient'
142
- end
143
-
144
- def self.browser_bottom_color(_value, _browser_object, _atome)
145
- puts 'code to write when implementing gradient'
146
- end
147
-
148
- # text
149
- def self.browser_left_text(value, browser_object, _atome)
150
- browser_object.style[:left] = "#{value}px"
151
- end
152
-
153
- def self.browser_right_text(value, browser_object, _atome)
154
- browser_object.style[:right] = "#{value}px"
155
- end
156
-
157
- def self.browser_top_text(value, browser_object, _atome)
158
- browser_object.style[:top] = "#{value}px"
159
- end
160
-
161
- def self.browser_bottom_text(value, browser_object, _atome)
162
- browser_object.style[:bottom] = "#{value}px"
163
- end
164
-
165
- def self.browser_data_text(value)
166
- browser_object.text = value
167
- end
168
-
169
- # web
170
- def self.browser_left_web(value, browser_object, _atome)
171
- browser_object.style[:left] = "#{value}px"
172
- end
173
-
174
- def self.browser_right_web(value, browser_object, _atome)
175
- browser_object.style[:right] = "#{value}px"
176
- end
177
-
178
- def self.browser_top_web(value, browser_object, _atome)
179
- browser_object.style[:top] = "#{value}px"
180
- end
181
-
182
- def self.browser_bottom_web(value, browser_object, _atome)
183
- browser_object.style[:bottom] = "#{value}px"
184
- end
185
-
186
- def self.browser_path_web(value, browser_object, _atome)
187
- browser_object[:src] = value
188
- end
189
-
190
- # video
191
- def self.browser_left_video(value, browser_object, _atome)
192
- browser_object.style[:left] = "#{value}px"
193
- end
194
-
195
- def self.browser_right_videob(value, browser_object, _atome)
196
- browser_object.style[:right] = "#{value}px"
197
- end
198
-
199
- def self.browser_top_video(value, browser_object, _atome)
200
- browser_object.style[:top] = "#{value}px"
201
- end
202
-
203
- def self.browser_bottom_video(value, browser_object, _atome)
204
- browser_object.style[:bottom] = "#{value}px"
205
- end
206
-
207
- def self.browser_path_video(value, browser_object, _atome)
208
- browser_object[:src] = value
209
- end
210
-
211
- def self.browser_play_video(_value, browser_object_found, atome_found, atome_object, proc)
212
- browser_object_found.play
213
- # TODO : change timeupdate for when possible requestVideoFrameCallback
214
- # (opal-browser/opal/browser/event.rb line 36)
215
- video_callback = atome_found[:code] # this is the video callback not the play callback
216
- play_callback = proc # this is the video callback not the play callback
217
- browser_object_found.on(:timeupdate) do |e|
218
- e.prevent # Prevent the default action (eg. form submission)
219
- # You can also use `e.stop` to stop propagating the event to other handlers.
220
- current_time = browser_object_found.currentTime
221
- atome_object.instance_exec(current_time, &video_callback) if video_callback.is_a?(Proc)
222
- atome_object.instance_exec(current_time, &play_callback) if play_callback.is_a?(Proc)
223
- end
224
- end
28
+ def atome_js
29
+ `atomeJS`
225
30
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  generator = Genesis.generator
4
4
 
5
- generator.build_render_method(:browser_smooth) do |value|
5
+ generator.build_render(:browser_smooth) do |value|
6
6
  format_params = case value
7
7
  when Array
8
8
  properties = []
@@ -18,6 +18,6 @@ generator.build_render_method(:browser_smooth) do |value|
18
18
  @browser_object.style['border-radius'] = format_params
19
19
  end
20
20
 
21
- generator.build_render_method(:browser_blur) do |value|
21
+ generator.build_render(:browser_blur) do |value|
22
22
  BrowserHelper.send("browser_blur_#{@browser_type}", @browser_object, value, @atome)
23
23
  end
@@ -2,17 +2,20 @@
2
2
 
3
3
  generator = Genesis.generator
4
4
 
5
- generator.build_render_method(:browser_touch) do |_value, proc|
6
- @browser_object.on :click do |e|
7
- instance_exec(e, &proc) if proc.is_a?(Proc)
8
- end
5
+ generator.build_render(:browser_touch) do |value, proc|
6
+ atome_id = @browser_object.attribute(:id)
7
+ BrowserHelper.send("browser_touch_#{value}", atome_id, proc)
8
+ # end
9
9
  end
10
10
 
11
- generator.build_render_method(:browser_play) do |value, proc|
11
+ generator.build_render(:browser_play) do |value, proc|
12
+ # first we reinit the 'at' event so the condition will be met again
13
+ # @at_time[:used] = nil
14
+ @browser_object.currentTime = value if value != true
12
15
  BrowserHelper.send("browser_play_#{@atome[:type]}", value, @browser_object, @atome, self, proc)
13
16
  end
14
17
 
15
- generator.build_render_method(:browser_time) do |value = nil, _proc|
18
+ generator.build_render(:browser_time) do |value = nil, _proc|
16
19
  if value
17
20
  @browser_object.currentTime = value
18
21
  else
@@ -20,18 +23,53 @@ generator.build_render_method(:browser_time) do |value = nil, _proc|
20
23
  end
21
24
  end
22
25
 
23
- generator.build_render_method(:browser_pause) do |_value, proc|
26
+ generator.build_render(:browser_pause) do |_value, proc|
24
27
  instance_exec(@browser_object.currentTime, &proc) if proc.is_a?(Proc)
25
28
  @browser_object.pause
26
29
  end
27
30
 
28
- generator.build_render_method(:on) do |value, proc|
31
+ generator.build_render(:on) do |value, proc|
29
32
  @browser_object.on(value) do |e|
30
33
  instance_exec(e, &proc) if proc.is_a?(Proc)
31
34
  end
32
35
  end
33
36
 
34
- generator.build_render_method(:fullscreen) do |value, proc|
35
- atome_id=atome[:id]
36
- `atome.js_Fullscreen(#{atome_id})`
37
+ generator.build_render(:fullscreen) do |_value, _proc|
38
+ atome_id = atome[:id]
39
+ atome_js.JS.fullscreen(atome_id)
40
+ end
41
+
42
+ generator.build_render(:mute) do |value, _proc|
43
+ if value
44
+ browser_object.muted
45
+ else
46
+ browser_object.unmuted
47
+ end
48
+ end
49
+
50
+ generator.build_render(:browser_at) do |at, proc|
51
+ # @atime is check at each toick of frame in 'time_callback'
52
+ @at_time = { code: proc }.merge(at)
37
53
  end
54
+
55
+ generator.build_render(:browser_drag) do |options, proc|
56
+ options.each do |method, params|
57
+ atome_id = @atome[:id]
58
+ BrowserHelper.send("browser_drag_#{method}", params, atome_id, self, proc)
59
+ end
60
+ end
61
+
62
+ generator.build_render(:browser_sort) do |options, _proc|
63
+ atome_js.JS.sort(options, @atome[:id], self)
64
+ end
65
+
66
+ # TODO: for now unbind remove all touch event we should remove only the targeted one (store proc and restore it)
67
+ generator.build_render(:browser_unbind) do |options, _proc|
68
+ id_found = self.atome[:id]
69
+ `
70
+ const el = document.getElementById(#{id_found});
71
+ interact('#'+#{id_found}).unset(#{options});
72
+ `
73
+ end
74
+
75
+