atome 0.5.5.8.1 → 0.5.5.8.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -1
- data/exe/atome +4 -4
- data/lib/atome/atome.rb +1 -1
- data/lib/atome/extensions/atome.rb +171 -34
- data/lib/atome/genesis/generators/atome.rb +10 -1
- data/lib/atome/genesis/generators/communication.rb +4 -0
- data/lib/atome/genesis/generators/event.rb +4 -3
- data/lib/atome/genesis/generators/geometry.rb +31 -4
- data/lib/atome/genesis/generators/identity.rb +3 -0
- data/lib/atome/genesis/generators/material.rb +1 -0
- data/lib/atome/genesis/generators/property.rb +75 -1
- data/lib/atome/genesis/generators/spatial.rb +2 -0
- data/lib/atome/genesis/generators/utility.rb +26 -12
- data/lib/atome/helpers/essentials.rb +3 -2
- data/lib/atome/version.rb +1 -1
- data/lib/renderers/html/atome.rb +0 -1
- data/lib/renderers/html/geometry.rb +11 -5
- data/lib/renderers/html/html.rb +374 -19
- data/lib/renderers/html/identity.rb +8 -0
- data/lib/renderers/html/material.rb +14 -0
- data/lib/renderers/html/property.rb +21 -0
- data/lib/renderers/html/spatial.rb +5 -1
- data/lib/renderers/html/utility.rb +25 -1
- data/vendor/assets/application/examples/atomizer.rb +86 -0
- data/vendor/assets/application/examples/center.rb +8 -0
- data/vendor/assets/application/examples/compute.rb +16 -0
- data/vendor/assets/application/examples/dig.rb +13 -0
- data/vendor/assets/application/examples/fit.rb +26 -0
- data/vendor/assets/application/examples/infos.rb +10 -0
- data/vendor/assets/application/examples/shortcut.rb +2 -2
- data/vendor/assets/application/examples/size.rb +17 -0
- data/vendor/assets/application/examples/table.rb +76 -0
- data/vendor/assets/application/examples/text.rb +1 -1
- data/vendor/assets/src/index.html +15 -15
- data/vendor/assets/src/index_wasm.html +47 -0
- data/vendor/assets/src/js/atome/atome_helpers/communication.js +5 -4
- metadata +11 -2
data/lib/renderers/html/html.rb
CHANGED
@@ -4,6 +4,22 @@
|
|
4
4
|
|
5
5
|
class HTML
|
6
6
|
|
7
|
+
def self.locate(selector, base_element = JS.global[:document][:body])
|
8
|
+
return base_element if selector.empty?
|
9
|
+
|
10
|
+
if selector.has_key?(:id)
|
11
|
+
base_element.querySelector("##{selector[:id]}")
|
12
|
+
elsif selector.has_key?(:parent)
|
13
|
+
parent = base_element.querySelector("##{selector[:parent]}")
|
14
|
+
return nil if parent.nil?
|
15
|
+
parent.querySelectorAll("*").to_a
|
16
|
+
elsif selector.has_key?(:html)
|
17
|
+
html_element = selector[:html]
|
18
|
+
return nil if html_element.nil?
|
19
|
+
html_element.querySelectorAll("*").to_a
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
7
23
|
def initialize(id_found, current_atome)
|
8
24
|
@element ||= JS.global[:document].getElementById(id_found.to_s)
|
9
25
|
@id = id_found
|
@@ -38,7 +54,7 @@ class HTML
|
|
38
54
|
condition_strings << "(min-height: #{conditions[:min][:height]}px)" if conditions[:min][:height]
|
39
55
|
end
|
40
56
|
|
41
|
-
operator = conditions[:operator] == :and ?
|
57
|
+
operator = conditions[:operator] == :and ? 'and' : 'or'
|
42
58
|
|
43
59
|
# Convert properties to apply
|
44
60
|
property_strings = []
|
@@ -86,9 +102,9 @@ class HTML
|
|
86
102
|
data[:apply][key] ||= {}
|
87
103
|
properties.each do |property|
|
88
104
|
prop, value = property.split(':').map(&:strip)
|
89
|
-
if prop ==
|
105
|
+
if prop == 'background-color'
|
90
106
|
data[:apply][key][:color] = value.to_sym
|
91
|
-
elsif value[-2..] ==
|
107
|
+
elsif value[-2..] == 'px'
|
92
108
|
data[:apply][key][prop.to_sym] = value.to_i
|
93
109
|
else
|
94
110
|
data[:apply][key][prop.to_sym] = value.to_sym
|
@@ -121,30 +137,30 @@ class HTML
|
|
121
137
|
|
122
138
|
style_tags.each do |line|
|
123
139
|
line = line.strip
|
124
|
-
next if line.empty? || line.start_with?(
|
140
|
+
next if line.empty? || line.start_with?('/*')
|
125
141
|
|
126
142
|
if inside_media
|
127
|
-
if line ==
|
128
|
-
hash_result[
|
143
|
+
if line == '}'
|
144
|
+
hash_result['@media'] << media_hash
|
129
145
|
inside_media = false
|
130
146
|
next
|
131
147
|
end
|
132
148
|
|
133
149
|
selector, properties = line.split('{').map(&:strip)
|
134
|
-
next unless properties&.end_with?(
|
150
|
+
next unless properties&.end_with?('}')
|
135
151
|
|
136
152
|
properties = properties[0...-1].strip
|
137
153
|
media_hash[selector] = extract_properties(properties)
|
138
|
-
elsif line.start_with?(
|
154
|
+
elsif line.start_with?('@media')
|
139
155
|
media_content = line.match(/@media\s*\(([^)]+)\)\s*{/)
|
140
156
|
next unless media_content
|
141
157
|
|
142
158
|
media_query = media_content[1]
|
143
|
-
hash_result[
|
159
|
+
hash_result['@media'] = [media_query]
|
144
160
|
inside_media = true
|
145
161
|
else
|
146
162
|
selector, properties = line.split('{').map(&:strip)
|
147
|
-
next unless properties&.end_with?(
|
163
|
+
next unless properties&.end_with?('}')
|
148
164
|
|
149
165
|
properties = properties[0...-1].strip
|
150
166
|
hash_result[selector] = extract_properties(properties)
|
@@ -294,6 +310,7 @@ class HTML
|
|
294
310
|
style[:innerHTML] = "::selection { background-color: #{back_color_rgba}; color: #{text_color_rgba}; }"
|
295
311
|
JS.global[:document][:head].appendChild(style)
|
296
312
|
return unless @element[:innerText].to_s.length == 1
|
313
|
+
|
297
314
|
@element[:innerHTML] = '​'
|
298
315
|
end
|
299
316
|
|
@@ -306,6 +323,7 @@ class HTML
|
|
306
323
|
JS.global[:document][:body].appendChild(@element)
|
307
324
|
add_class('atome')
|
308
325
|
self.id(id)
|
326
|
+
|
309
327
|
self
|
310
328
|
end
|
311
329
|
|
@@ -351,8 +369,8 @@ class HTML
|
|
351
369
|
check_double(id)
|
352
370
|
markup_found = @original_atome.markup || 'svg'
|
353
371
|
@element_type = markup_found.to_s
|
354
|
-
svg_ns =
|
355
|
-
@element = JS.global[:document].createElementNS(svg_ns,
|
372
|
+
svg_ns = 'http://www.w3.org/2000/svg'
|
373
|
+
@element = JS.global[:document].createElementNS(svg_ns, 'svg')
|
356
374
|
JS.global[:document][:body].appendChild(@element)
|
357
375
|
@element.setAttribute('viewBox', '0 0 1024 1024')
|
358
376
|
@element.setAttribute('version', '1.1')
|
@@ -363,7 +381,7 @@ class HTML
|
|
363
381
|
|
364
382
|
def svg_data(data)
|
365
383
|
data.each do |type_passed, datas|
|
366
|
-
svg_ns =
|
384
|
+
svg_ns = 'http://www.w3.org/2000/svg'
|
367
385
|
new_path = JS.global[:document].createElementNS(svg_ns.to_s, type_passed.to_s)
|
368
386
|
JS.global[:document][:body].appendChild(new_path)
|
369
387
|
datas.each do |property, value|
|
@@ -419,7 +437,7 @@ class HTML
|
|
419
437
|
.gsub('&', "\&")
|
420
438
|
.gsub('<', "\<")
|
421
439
|
.gsub('>', "\>")
|
422
|
-
.gsub('"', "
|
440
|
+
.gsub('"', '"')
|
423
441
|
.gsub("'", "\'")
|
424
442
|
end
|
425
443
|
|
@@ -1099,7 +1117,7 @@ class HTML
|
|
1099
1117
|
if Atome.host == 'tauri'
|
1100
1118
|
JS.eval("readFile('#{id}','#{file}')")
|
1101
1119
|
else
|
1102
|
-
puts
|
1120
|
+
puts ' work in progress'
|
1103
1121
|
end
|
1104
1122
|
end
|
1105
1123
|
|
@@ -1107,12 +1125,12 @@ class HTML
|
|
1107
1125
|
if Atome.host == 'tauri'
|
1108
1126
|
JS.eval("browseFile('#{id}','#{file}')")
|
1109
1127
|
else
|
1110
|
-
puts
|
1128
|
+
puts 'work in progress'
|
1111
1129
|
end
|
1112
1130
|
end
|
1113
1131
|
|
1114
1132
|
def handle_input
|
1115
|
-
@original_atome.instance_variable_set(
|
1133
|
+
@original_atome.instance_variable_set('@data', @element[:innerText].to_s)
|
1116
1134
|
end
|
1117
1135
|
|
1118
1136
|
# this method update the data content of the atome
|
@@ -1151,7 +1169,7 @@ class HTML
|
|
1151
1169
|
puts 'change for standard method : action'
|
1152
1170
|
required_keys = [:from, :to, :duration]
|
1153
1171
|
unless properties.is_a?(Hash) && (required_keys - properties.keys).empty?
|
1154
|
-
raise ArgumentError,
|
1172
|
+
raise ArgumentError, 'Properties must be a hash with :from, :to, and :duration keys'
|
1155
1173
|
end
|
1156
1174
|
|
1157
1175
|
animate(properties)
|
@@ -1159,7 +1177,344 @@ class HTML
|
|
1159
1177
|
end
|
1160
1178
|
|
1161
1179
|
def stop_animation
|
1162
|
-
JS.eval(
|
1180
|
+
JS.eval('if (window.currentAnimation) window.currentAnimation.stop();')
|
1181
|
+
end
|
1182
|
+
|
1183
|
+
# Table manipulation
|
1184
|
+
|
1185
|
+
def table(data)
|
1186
|
+
table_html = JS.global[:document].createElement('table')
|
1187
|
+
thead = JS.global[:document].createElement('thead')
|
1188
|
+
|
1189
|
+
max_length = data.max_by { |row| row.keys.length }.keys.length
|
1190
|
+
|
1191
|
+
if @original_atome.option[:header]
|
1192
|
+
header_row = JS.global[:document].createElement('tr')
|
1193
|
+
|
1194
|
+
max_length.times do |i|
|
1195
|
+
th = JS.global[:document].createElement('th')
|
1196
|
+
th[:textContent] = data.map { |row| row.keys[i].to_s }.compact.first || ''
|
1197
|
+
header_row.appendChild(th)
|
1198
|
+
end
|
1199
|
+
|
1200
|
+
thead.appendChild(header_row)
|
1201
|
+
end
|
1202
|
+
|
1203
|
+
table_html.appendChild(thead)
|
1204
|
+
tbody = JS.global[:document].createElement('tbody')
|
1205
|
+
|
1206
|
+
data.each_with_index do |row, row_index|
|
1207
|
+
tr = JS.global[:document].createElement('tr')
|
1208
|
+
|
1209
|
+
max_length.times do |cell_index|
|
1210
|
+
td = JS.global[:document].createElement('td')
|
1211
|
+
cell_size = set_td_style(td)
|
1212
|
+
cell_height = cell_size[:cell_height]
|
1213
|
+
|
1214
|
+
cell_value = row.values[cell_index]
|
1215
|
+
if cell_value.instance_of? Atome
|
1216
|
+
cell_value.fit(cell_height)
|
1217
|
+
html_element = JS.global[:document].getElementById(cell_value.id.to_s)
|
1218
|
+
td.appendChild(html_element)
|
1219
|
+
html_element[:style][:transformOrigin] = 'top left'
|
1220
|
+
html_element[:style][:position] = 'relative'
|
1221
|
+
cell_value.top(0)
|
1222
|
+
cell_value.left(0)
|
1223
|
+
else
|
1224
|
+
td[:textContent] = cell_value.to_s
|
1225
|
+
end
|
1226
|
+
tr.appendChild(td)
|
1227
|
+
end
|
1228
|
+
|
1229
|
+
tbody.appendChild(tr)
|
1230
|
+
end
|
1231
|
+
table_html.appendChild(tbody)
|
1232
|
+
JS.global[:document].querySelector("##{@id}").appendChild(table_html)
|
1233
|
+
end
|
1234
|
+
|
1235
|
+
def refresh_table(_params)
|
1236
|
+
# first we need to extact all atome from the table or they will be deleted by the table refres
|
1237
|
+
data = @original_atome.data
|
1238
|
+
data.each do |row|
|
1239
|
+
row.each do |k, v|
|
1240
|
+
v.attach(:view) if v.instance_of? Atome
|
1241
|
+
end
|
1242
|
+
end
|
1243
|
+
table_element = JS.global[:document].querySelector("##{@id} table")
|
1244
|
+
if table_element.nil?
|
1245
|
+
puts 'Table not found'
|
1246
|
+
return
|
1247
|
+
end
|
1248
|
+
(table_element[:rows].to_a.length - 1).downto(1) do |i|
|
1249
|
+
table_element.deleteRow(i)
|
1250
|
+
end
|
1251
|
+
|
1252
|
+
max_cells = data.map { |row| row.keys.length }.max
|
1253
|
+
|
1254
|
+
data.each do |row|
|
1255
|
+
new_row = table_element.insertRow(-1)
|
1256
|
+
max_cells.times do |i|
|
1257
|
+
key = row.keys[i]
|
1258
|
+
value = row[key]
|
1259
|
+
cell = new_row.insertCell(-1)
|
1260
|
+
if value.instance_of? Atome
|
1261
|
+
html_element = JS.global[:document].getElementById(value.id.to_s)
|
1262
|
+
cell.appendChild(html_element)
|
1263
|
+
else
|
1264
|
+
cell[:textContent] = value.to_s
|
1265
|
+
end
|
1266
|
+
set_td_style(cell)
|
1267
|
+
end
|
1268
|
+
end
|
1269
|
+
end
|
1270
|
+
|
1271
|
+
def set_td_style(td)
|
1272
|
+
cell_height = 50
|
1273
|
+
td[:style][:border] = '1px solid black'
|
1274
|
+
td[:style][:backgroundColor] = 'white'
|
1275
|
+
td[:style][:boxShadow] = '10px 10px 5px #888888'
|
1276
|
+
td[:style][:width] = "#{cell_height}px"
|
1277
|
+
td[:style]['min-width'] = "#{cell_height}px"
|
1278
|
+
td[:style]['max-width'] = "#{cell_height}px"
|
1279
|
+
td[:style]['min-height'] = "#{cell_height}px"
|
1280
|
+
td[:style]['max-height'] = "#{cell_height}px"
|
1281
|
+
td[:style][:height] = "#{cell_height}px"
|
1282
|
+
td[:style][:overflow] = 'hidden'
|
1283
|
+
{ cell_height: cell_height, cell_width: cell_height }
|
1284
|
+
end
|
1285
|
+
|
1286
|
+
def insert_cell(params)
|
1287
|
+
row_index, cell_index = params[:cell]
|
1288
|
+
new_content = params[:content]
|
1289
|
+
container = JS.global[:document].getElementById(@id.to_s)
|
1290
|
+
|
1291
|
+
table = container.querySelector('table')
|
1292
|
+
if table.nil?
|
1293
|
+
puts 'No table found in the container'
|
1294
|
+
return
|
1295
|
+
end
|
1296
|
+
|
1297
|
+
row = table.querySelectorAll('tr')[row_index]
|
1298
|
+
if row.nil?
|
1299
|
+
puts "Row at index #{row_index} not found"
|
1300
|
+
return
|
1301
|
+
end
|
1302
|
+
|
1303
|
+
cell = row.querySelectorAll('td')[cell_index]
|
1304
|
+
if cell.nil?
|
1305
|
+
puts "Cell at index #{cell_index} in row #{row_index} not found"
|
1306
|
+
return
|
1307
|
+
end
|
1308
|
+
|
1309
|
+
if new_content.instance_of? Atome
|
1310
|
+
cell.innerHTML = ''
|
1311
|
+
html_element = JS.global[:document].getElementById(new_content.id.to_s)
|
1312
|
+
cell.appendChild(html_element)
|
1313
|
+
else
|
1314
|
+
cell[:textContent] = new_content.to_s
|
1315
|
+
end
|
1316
|
+
end
|
1317
|
+
|
1318
|
+
def insert_row(params)
|
1319
|
+
insert_at_index = params[:row]
|
1320
|
+
table_element = JS.global[:document].querySelector("##{@id} table")
|
1321
|
+
|
1322
|
+
if table_element.nil?
|
1323
|
+
puts 'Tableau non trouvé'
|
1324
|
+
return
|
1325
|
+
end
|
1326
|
+
|
1327
|
+
tbody = table_element.querySelector('tbody')
|
1328
|
+
|
1329
|
+
header_row = table_element.querySelector('thead tr')
|
1330
|
+
column_count = header_row ? header_row.querySelectorAll('th').to_a.length : 0
|
1331
|
+
|
1332
|
+
new_row = JS.global[:document].createElement('tr')
|
1333
|
+
column_count.times do |cell_index|
|
1334
|
+
td = JS.global[:document].createElement('td')
|
1335
|
+
set_td_style(td)
|
1336
|
+
new_row.appendChild(td)
|
1337
|
+
end
|
1338
|
+
|
1339
|
+
if insert_at_index.zero?
|
1340
|
+
tbody.insertBefore(new_row, tbody.firstChild)
|
1341
|
+
else
|
1342
|
+
reference_row = tbody.querySelectorAll('tr').to_a[insert_at_index]
|
1343
|
+
tbody.insertBefore(new_row, reference_row)
|
1344
|
+
end
|
1345
|
+
|
1346
|
+
end
|
1347
|
+
|
1348
|
+
def insert_column(params)
|
1349
|
+
insert_at_index = params[:column]
|
1350
|
+
table_element = JS.global[:document].querySelector("##{@id} table")
|
1351
|
+
if table_element.nil?
|
1352
|
+
puts 'Table not found'
|
1353
|
+
return
|
1354
|
+
end
|
1355
|
+
rows = table_element.querySelectorAll('tr').to_a
|
1356
|
+
rows.each_with_index do |row, index|
|
1357
|
+
if index == 0
|
1358
|
+
# case1
|
1359
|
+
else
|
1360
|
+
new_cell = JS.global[:document].createElement('td')
|
1361
|
+
new_cell[:innerText] = ''
|
1362
|
+
set_td_style(new_cell)
|
1363
|
+
if insert_at_index.zero?
|
1364
|
+
row.insertBefore(new_cell, row.firstChild)
|
1365
|
+
else
|
1366
|
+
child_nodes = row.querySelectorAll('td').to_a
|
1367
|
+
|
1368
|
+
if insert_at_index < child_nodes.length
|
1369
|
+
reference_cell = child_nodes[insert_at_index]
|
1370
|
+
row.insertBefore(new_cell, reference_cell)
|
1371
|
+
else
|
1372
|
+
row.appendChild(new_cell)
|
1373
|
+
end
|
1374
|
+
end
|
1375
|
+
end
|
1376
|
+
|
1377
|
+
end
|
1378
|
+
|
1379
|
+
end
|
1380
|
+
|
1381
|
+
def table_insert(params)
|
1382
|
+
if params[:cell]
|
1383
|
+
insert_cell(params)
|
1384
|
+
elsif params[:row]
|
1385
|
+
insert_row(params)
|
1386
|
+
elsif params[:column]
|
1387
|
+
insert_column(params)
|
1388
|
+
end
|
1389
|
+
|
1390
|
+
end
|
1391
|
+
|
1392
|
+
def table_remove(params)
|
1393
|
+
if params[:row]
|
1394
|
+
row_index = params[:row]
|
1395
|
+
table_element = JS.global[:document].querySelector("##{@id} table")
|
1396
|
+
|
1397
|
+
if table_element.nil?
|
1398
|
+
puts 'Table not found'
|
1399
|
+
return
|
1400
|
+
end
|
1401
|
+
|
1402
|
+
rows = table_element.querySelectorAll('tbody tr').to_a
|
1403
|
+
|
1404
|
+
if row_index >= rows.length
|
1405
|
+
puts "row not found : #{row_index}"
|
1406
|
+
return
|
1407
|
+
end
|
1408
|
+
row_to_remove = rows[row_index]
|
1409
|
+
|
1410
|
+
row_to_remove[:parentNode].removeChild(row_to_remove)
|
1411
|
+
|
1412
|
+
rows.each_with_index do |row, i|
|
1413
|
+
next if i <= row_index
|
1414
|
+
end
|
1415
|
+
elsif params[:column]
|
1416
|
+
column_index = params[:column]
|
1417
|
+
table_element = JS.global[:document].querySelector("##{@id} table")
|
1418
|
+
|
1419
|
+
if table_element.nil?
|
1420
|
+
puts 'Table not found'
|
1421
|
+
return
|
1422
|
+
end
|
1423
|
+
|
1424
|
+
rows = table_element.querySelectorAll('tbody tr').to_a
|
1425
|
+
rows.each do |row|
|
1426
|
+
cells = row.querySelectorAll('td').to_a
|
1427
|
+
if column_index < cells.length
|
1428
|
+
cell_to_remove = cells[column_index]
|
1429
|
+
cell_to_remove[:parentNode].removeChild(cell_to_remove)
|
1430
|
+
end
|
1431
|
+
end
|
1432
|
+
|
1433
|
+
end
|
1434
|
+
end
|
1435
|
+
|
1436
|
+
# atomisation!
|
1437
|
+
def atomized(html_object)
|
1438
|
+
html_object = html_object[0] if html_object.instance_of? Array
|
1439
|
+
@element = html_object
|
1440
|
+
end
|
1441
|
+
|
1442
|
+
|
1443
|
+
# def center(options, attach)
|
1444
|
+
# parent = grab(attach)
|
1445
|
+
#
|
1446
|
+
# # Centre sur l'axe X
|
1447
|
+
# if options[:x]
|
1448
|
+
# x_position = calculate_position(options[:x], parent.to_px(:width), @original_atome.to_px(:width))
|
1449
|
+
# @original_atome.left(x_position)
|
1450
|
+
# end
|
1451
|
+
#
|
1452
|
+
# # Centre sur l'axe Y
|
1453
|
+
# if options[:y]
|
1454
|
+
# y_position = calculate_position(options[:y], parent.to_px(:height), @original_atome.to_px(:height))
|
1455
|
+
# @original_atome.top(y_position)
|
1456
|
+
# end
|
1457
|
+
# end
|
1458
|
+
#
|
1459
|
+
# # Méthode auxiliaire pour calculer la position
|
1460
|
+
# def calculate_position(option, parent_dimension, self_dimension)
|
1461
|
+
# if option.is_a?(String) && option.end_with?('%')
|
1462
|
+
# percent = option.chop.to_f / 100.0
|
1463
|
+
# (parent_dimension - self_dimension) * percent
|
1464
|
+
# elsif option == 0
|
1465
|
+
# # Cas spécial pour centrer l'objet
|
1466
|
+
# (parent_dimension - self_dimension) / 2.0
|
1467
|
+
# else
|
1468
|
+
# option
|
1469
|
+
# end
|
1470
|
+
# end
|
1471
|
+
|
1472
|
+
def center(options, attach)
|
1473
|
+
@center_options = options
|
1474
|
+
@parent = grab(attach)
|
1475
|
+
|
1476
|
+
# Appliquer le centrage initial
|
1477
|
+
apply_centering(@center_options, @parent)
|
1478
|
+
|
1479
|
+
# Si l'option dynamique est activée, ajouter un écouteur d'événements
|
1480
|
+
if @center_options[:dynamic]
|
1481
|
+
event_handler = ->(event) do
|
1482
|
+
apply_centering(@center_options, @parent)
|
1483
|
+
end
|
1484
|
+
JS.global[:window].addEventListener('resize', event_handler)
|
1485
|
+
end
|
1486
|
+
end
|
1487
|
+
|
1488
|
+
private
|
1489
|
+
|
1490
|
+
# Méthode auxiliaire pour appliquer le centrage
|
1491
|
+
def apply_centering(options, parent)
|
1492
|
+
# Centre sur l'axe X
|
1493
|
+
if options[:x]
|
1494
|
+
x_position = calculate_position(options[:x], parent.to_px(:width), @original_atome.to_px(:width))
|
1495
|
+
@original_atome.left(x_position)
|
1496
|
+
end
|
1497
|
+
|
1498
|
+
# Centre sur l'axe Y
|
1499
|
+
if options[:y]
|
1500
|
+
y_position = calculate_position(options[:y], parent.to_px(:height), @original_atome.to_px(:height))
|
1501
|
+
@original_atome.top(y_position)
|
1502
|
+
end
|
1503
|
+
end
|
1504
|
+
|
1505
|
+
# Méthode auxiliaire pour calculer la position
|
1506
|
+
def calculate_position(option, parent_dimension, self_dimension)
|
1507
|
+
if option.is_a?(String) && option.end_with?('%')
|
1508
|
+
percent = option.chop.to_f / 100.0
|
1509
|
+
(parent_dimension - self_dimension) * percent
|
1510
|
+
elsif option == 0
|
1511
|
+
# Cas spécial pour centrer l'objet
|
1512
|
+
(parent_dimension - self_dimension) / 2.0
|
1513
|
+
else
|
1514
|
+
option
|
1515
|
+
end
|
1163
1516
|
end
|
1164
1517
|
|
1165
1518
|
end
|
1519
|
+
|
1520
|
+
|
@@ -82,3 +82,11 @@ new({ renderer: :html, method: :category, type: :symbol }) do |category_names|
|
|
82
82
|
html.add_class(category_name)
|
83
83
|
end
|
84
84
|
end
|
85
|
+
|
86
|
+
new({ method: :data, type: :string, specific: :matrix, renderer: :html }) do |value, _user_proc|
|
87
|
+
html.table(value)
|
88
|
+
end
|
89
|
+
|
90
|
+
new({ method: :type, type: :hash, specific: :atomized, renderer: :html }) do |value, _user_proc|
|
91
|
+
html.atomized(alien)
|
92
|
+
end
|
@@ -51,3 +51,17 @@ new({ method: :remove, renderer: :html, type: :string }) do |object_id_to_remove
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
54
|
+
|
55
|
+
|
56
|
+
new({ method: :border, type: :hash, renderer: :html }) do |value, _user_proc|
|
57
|
+
thickness = value[:thickness] || 5
|
58
|
+
type = value[:pattern] || :solid
|
59
|
+
color = if value[:color]
|
60
|
+
color_found = value[:color]
|
61
|
+
"#{color_found.red * 255},#{color_found.green * 255},#{color_found.blue * 255},#{color_found.alpha} "
|
62
|
+
else
|
63
|
+
"0,0,0,1"
|
64
|
+
end
|
65
|
+
|
66
|
+
html.style(:border, "#{type} #{thickness}px rgba(#{color})")
|
67
|
+
end
|
@@ -35,4 +35,25 @@ new({ method: :border, type: :hash, renderer: :html }) do |value, _user_proc|
|
|
35
35
|
end
|
36
36
|
|
37
37
|
html.style(:border, "#{type} #{thickness}px rgba(#{color})")
|
38
|
+
end
|
39
|
+
|
40
|
+
new({ method: :clean, renderer: :html, type: :hash }) do |params|
|
41
|
+
html.table_clean(params)
|
42
|
+
end
|
43
|
+
|
44
|
+
new({ method: :insert, renderer: :html, type: :hash }) do |params|
|
45
|
+
html.table_insert(params)
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
new({ method: :remove, renderer: :html, type: :hash }) do |params|
|
51
|
+
html.table_remove(params)
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
new({ method: :sort, renderer: :html, type: :hash }) do |params|
|
58
|
+
html.refresh_table(params)
|
38
59
|
end
|
@@ -84,7 +84,31 @@ new({ renderer: :html, method: :import, type: :blob }) do |_params, bloc|
|
|
84
84
|
end
|
85
85
|
|
86
86
|
|
87
|
-
new({ renderer: :html, method: :selected, specific: :text
|
87
|
+
new({ renderer: :html, method: :selected, specific: :text }) do |value, &bloc|
|
88
88
|
html.select_text(value)
|
89
89
|
end
|
90
90
|
|
91
|
+
new({ method: :compute, type: :hash, renderer: :html }) do |params|
|
92
|
+
element = JS.global[:document].getElementById(@id.to_s)
|
93
|
+
bounding_box = element.getBoundingClientRect()
|
94
|
+
|
95
|
+
top = bounding_box[:top]
|
96
|
+
left = bounding_box[:left]
|
97
|
+
width = bounding_box[:width]
|
98
|
+
height = bounding_box[:height]
|
99
|
+
value_found = case params[:particle]
|
100
|
+
when :left
|
101
|
+
left.to_f
|
102
|
+
when :top
|
103
|
+
top.to_f
|
104
|
+
when :width
|
105
|
+
width.to_f
|
106
|
+
when :height
|
107
|
+
height.to_f
|
108
|
+
else
|
109
|
+
nil
|
110
|
+
end
|
111
|
+
@compute[:value] = value_found
|
112
|
+
end
|
113
|
+
|
114
|
+
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# dummies html objects :
|
4
|
+
|
5
|
+
#object 1
|
6
|
+
div_rouge = JS.global[:document].createElement( "div")
|
7
|
+
|
8
|
+
div_rouge[:style][:backgroundColor] = "red"
|
9
|
+
div_rouge[:style][:width] = "100px"
|
10
|
+
div_rouge[:style][:height] = "100px"
|
11
|
+
div_rouge.setAttribute('id', "my_div")
|
12
|
+
div_view = JS.global[:document].getElementById('view')
|
13
|
+
div_view.appendChild(div_rouge)
|
14
|
+
|
15
|
+
|
16
|
+
#object 2
|
17
|
+
span_bleu = JS.global[:document].createElement( "span")
|
18
|
+
span_bleu[:style][:backgroundColor] = "blue"
|
19
|
+
span_bleu[:innerHTML] = "blue"
|
20
|
+
span_bleu[:style][:width] = "10px"
|
21
|
+
span_bleu[:style][:height] = "8px"
|
22
|
+
div_rouge.appendChild(span_bleu)
|
23
|
+
|
24
|
+
|
25
|
+
#object 2
|
26
|
+
span_white = JS.global[:document].createElement( "h1")
|
27
|
+
span_white[:style][:color] = "white"
|
28
|
+
span_white[:innerHTML] = "Hello"
|
29
|
+
span_white[:style][:width] = "10px"
|
30
|
+
span_white[:style][:height] = "80px"
|
31
|
+
span_white[:style][:top] = "80px"
|
32
|
+
span_bleu.appendChild(span_white)
|
33
|
+
|
34
|
+
|
35
|
+
# usage example
|
36
|
+
# div_result = HTML.locate(id: 'my_div') # Recherche par ID
|
37
|
+
# alert "id found : #{div_result[:id]}" if div_result
|
38
|
+
|
39
|
+
# first_result = HTML.locate(parent: :view)[1]
|
40
|
+
# result_found = HTML.locate(html: first_result)
|
41
|
+
# alert result_found[0][:tagName]
|
42
|
+
|
43
|
+
# if span_result
|
44
|
+
# span_result.to_a.each do |child|
|
45
|
+
# alert "child found: #{child[:tagName]}"
|
46
|
+
# end
|
47
|
+
# enfants = span_result.to_a.map do |child|
|
48
|
+
# "tag: #{child[:tagName]}, ID: #{child[:id] || 'non défini'}"
|
49
|
+
# end
|
50
|
+
# alert "children found : #{enfants.join(', ')}"
|
51
|
+
# end
|
52
|
+
|
53
|
+
|
54
|
+
wait 1 do
|
55
|
+
div_result = HTML.locate(parent: :view)[0]
|
56
|
+
atomized_el= atomizer({ target: div_result, id: :my_html_obj })
|
57
|
+
atomized_el.color(:pink)
|
58
|
+
atomized_el.position(:absolute)
|
59
|
+
atomized_el.left(66)
|
60
|
+
atomized_el.top(99)
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
wait 2 do
|
65
|
+
div_result = HTML.locate(id: 'my_div') # find by ID
|
66
|
+
|
67
|
+
atomized_el= atomizer({ target: div_result, id: :my_second_html_obj })
|
68
|
+
atomized_el.rotate(55)
|
69
|
+
atomized_el.color(:purple)
|
70
|
+
# atomized_el.display(:block)
|
71
|
+
atomized_el.position(:absolute)
|
72
|
+
atomized_el.left(255)
|
73
|
+
atomized_el.top(255)
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
wait 3 do
|
78
|
+
first_result = HTML.locate(parent: :view)[1]
|
79
|
+
result_found = HTML.locate(html: first_result) # Attention HTML.locate always return an array you have to chose
|
80
|
+
new_atomized_el= atomizer({ target: result_found, id: :my_third_html_obj })
|
81
|
+
new_atomized_el.display(:block)
|
82
|
+
new_atomized_el.position(:absolute)
|
83
|
+
new_atomized_el.rotate(12)
|
84
|
+
end
|
85
|
+
|
86
|
+
|