atome 0.5.5.8.1 → 0.5.5.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +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/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 +299 -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/utility.rb +25 -1
- data/vendor/assets/application/examples/atomizer.rb +86 -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/js/atome/atome_helpers/communication.js +5 -4
- metadata +9 -2
data/lib/renderers/html/html.rb
CHANGED
@@ -4,6 +4,23 @@
|
|
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
|
+
|
23
|
+
|
7
24
|
def initialize(id_found, current_atome)
|
8
25
|
@element ||= JS.global[:document].getElementById(id_found.to_s)
|
9
26
|
@id = id_found
|
@@ -38,7 +55,7 @@ class HTML
|
|
38
55
|
condition_strings << "(min-height: #{conditions[:min][:height]}px)" if conditions[:min][:height]
|
39
56
|
end
|
40
57
|
|
41
|
-
operator = conditions[:operator] == :and ?
|
58
|
+
operator = conditions[:operator] == :and ? 'and' : 'or'
|
42
59
|
|
43
60
|
# Convert properties to apply
|
44
61
|
property_strings = []
|
@@ -86,9 +103,9 @@ class HTML
|
|
86
103
|
data[:apply][key] ||= {}
|
87
104
|
properties.each do |property|
|
88
105
|
prop, value = property.split(':').map(&:strip)
|
89
|
-
if prop ==
|
106
|
+
if prop == 'background-color'
|
90
107
|
data[:apply][key][:color] = value.to_sym
|
91
|
-
elsif value[-2..] ==
|
108
|
+
elsif value[-2..] == 'px'
|
92
109
|
data[:apply][key][prop.to_sym] = value.to_i
|
93
110
|
else
|
94
111
|
data[:apply][key][prop.to_sym] = value.to_sym
|
@@ -121,30 +138,30 @@ class HTML
|
|
121
138
|
|
122
139
|
style_tags.each do |line|
|
123
140
|
line = line.strip
|
124
|
-
next if line.empty? || line.start_with?(
|
141
|
+
next if line.empty? || line.start_with?('/*')
|
125
142
|
|
126
143
|
if inside_media
|
127
|
-
if line ==
|
128
|
-
hash_result[
|
144
|
+
if line == '}'
|
145
|
+
hash_result['@media'] << media_hash
|
129
146
|
inside_media = false
|
130
147
|
next
|
131
148
|
end
|
132
149
|
|
133
150
|
selector, properties = line.split('{').map(&:strip)
|
134
|
-
next unless properties&.end_with?(
|
151
|
+
next unless properties&.end_with?('}')
|
135
152
|
|
136
153
|
properties = properties[0...-1].strip
|
137
154
|
media_hash[selector] = extract_properties(properties)
|
138
|
-
elsif line.start_with?(
|
155
|
+
elsif line.start_with?('@media')
|
139
156
|
media_content = line.match(/@media\s*\(([^)]+)\)\s*{/)
|
140
157
|
next unless media_content
|
141
158
|
|
142
159
|
media_query = media_content[1]
|
143
|
-
hash_result[
|
160
|
+
hash_result['@media'] = [media_query]
|
144
161
|
inside_media = true
|
145
162
|
else
|
146
163
|
selector, properties = line.split('{').map(&:strip)
|
147
|
-
next unless properties&.end_with?(
|
164
|
+
next unless properties&.end_with?('}')
|
148
165
|
|
149
166
|
properties = properties[0...-1].strip
|
150
167
|
hash_result[selector] = extract_properties(properties)
|
@@ -294,6 +311,7 @@ class HTML
|
|
294
311
|
style[:innerHTML] = "::selection { background-color: #{back_color_rgba}; color: #{text_color_rgba}; }"
|
295
312
|
JS.global[:document][:head].appendChild(style)
|
296
313
|
return unless @element[:innerText].to_s.length == 1
|
314
|
+
|
297
315
|
@element[:innerHTML] = '​'
|
298
316
|
end
|
299
317
|
|
@@ -306,6 +324,7 @@ class HTML
|
|
306
324
|
JS.global[:document][:body].appendChild(@element)
|
307
325
|
add_class('atome')
|
308
326
|
self.id(id)
|
327
|
+
|
309
328
|
self
|
310
329
|
end
|
311
330
|
|
@@ -351,8 +370,8 @@ class HTML
|
|
351
370
|
check_double(id)
|
352
371
|
markup_found = @original_atome.markup || 'svg'
|
353
372
|
@element_type = markup_found.to_s
|
354
|
-
svg_ns =
|
355
|
-
@element = JS.global[:document].createElementNS(svg_ns,
|
373
|
+
svg_ns = 'http://www.w3.org/2000/svg'
|
374
|
+
@element = JS.global[:document].createElementNS(svg_ns, 'svg')
|
356
375
|
JS.global[:document][:body].appendChild(@element)
|
357
376
|
@element.setAttribute('viewBox', '0 0 1024 1024')
|
358
377
|
@element.setAttribute('version', '1.1')
|
@@ -363,7 +382,7 @@ class HTML
|
|
363
382
|
|
364
383
|
def svg_data(data)
|
365
384
|
data.each do |type_passed, datas|
|
366
|
-
svg_ns =
|
385
|
+
svg_ns = 'http://www.w3.org/2000/svg'
|
367
386
|
new_path = JS.global[:document].createElementNS(svg_ns.to_s, type_passed.to_s)
|
368
387
|
JS.global[:document][:body].appendChild(new_path)
|
369
388
|
datas.each do |property, value|
|
@@ -419,7 +438,7 @@ class HTML
|
|
419
438
|
.gsub('&', "\&")
|
420
439
|
.gsub('<', "\<")
|
421
440
|
.gsub('>', "\>")
|
422
|
-
.gsub('"', "
|
441
|
+
.gsub('"', '"')
|
423
442
|
.gsub("'", "\'")
|
424
443
|
end
|
425
444
|
|
@@ -1099,7 +1118,7 @@ class HTML
|
|
1099
1118
|
if Atome.host == 'tauri'
|
1100
1119
|
JS.eval("readFile('#{id}','#{file}')")
|
1101
1120
|
else
|
1102
|
-
puts
|
1121
|
+
puts ' work in progress'
|
1103
1122
|
end
|
1104
1123
|
end
|
1105
1124
|
|
@@ -1107,12 +1126,12 @@ class HTML
|
|
1107
1126
|
if Atome.host == 'tauri'
|
1108
1127
|
JS.eval("browseFile('#{id}','#{file}')")
|
1109
1128
|
else
|
1110
|
-
puts
|
1129
|
+
puts 'work in progress'
|
1111
1130
|
end
|
1112
1131
|
end
|
1113
1132
|
|
1114
1133
|
def handle_input
|
1115
|
-
@original_atome.instance_variable_set(
|
1134
|
+
@original_atome.instance_variable_set('@data', @element[:innerText].to_s)
|
1116
1135
|
end
|
1117
1136
|
|
1118
1137
|
# this method update the data content of the atome
|
@@ -1151,7 +1170,7 @@ class HTML
|
|
1151
1170
|
puts 'change for standard method : action'
|
1152
1171
|
required_keys = [:from, :to, :duration]
|
1153
1172
|
unless properties.is_a?(Hash) && (required_keys - properties.keys).empty?
|
1154
|
-
raise ArgumentError,
|
1173
|
+
raise ArgumentError, 'Properties must be a hash with :from, :to, and :duration keys'
|
1155
1174
|
end
|
1156
1175
|
|
1157
1176
|
animate(properties)
|
@@ -1159,7 +1178,268 @@ class HTML
|
|
1159
1178
|
end
|
1160
1179
|
|
1161
1180
|
def stop_animation
|
1162
|
-
JS.eval(
|
1181
|
+
JS.eval('if (window.currentAnimation) window.currentAnimation.stop();')
|
1182
|
+
end
|
1183
|
+
|
1184
|
+
# Table manipulation
|
1185
|
+
|
1186
|
+
def table(data)
|
1187
|
+
table_html = JS.global[:document].createElement('table')
|
1188
|
+
thead = JS.global[:document].createElement('thead')
|
1189
|
+
|
1190
|
+
max_length = data.max_by { |row| row.keys.length }.keys.length
|
1191
|
+
|
1192
|
+
if @original_atome.option[:header]
|
1193
|
+
header_row = JS.global[:document].createElement('tr')
|
1194
|
+
|
1195
|
+
max_length.times do |i|
|
1196
|
+
th = JS.global[:document].createElement('th')
|
1197
|
+
th[:textContent] = data.map { |row| row.keys[i].to_s }.compact.first || ''
|
1198
|
+
header_row.appendChild(th)
|
1199
|
+
end
|
1200
|
+
|
1201
|
+
thead.appendChild(header_row)
|
1202
|
+
end
|
1203
|
+
|
1204
|
+
table_html.appendChild(thead)
|
1205
|
+
tbody = JS.global[:document].createElement('tbody')
|
1206
|
+
|
1207
|
+
data.each_with_index do |row, row_index|
|
1208
|
+
tr = JS.global[:document].createElement('tr')
|
1209
|
+
|
1210
|
+
max_length.times do |cell_index|
|
1211
|
+
td = JS.global[:document].createElement('td')
|
1212
|
+
cell_size = set_td_style(td)
|
1213
|
+
cell_height = cell_size[:cell_height]
|
1214
|
+
|
1215
|
+
cell_value = row.values[cell_index]
|
1216
|
+
if cell_value.instance_of? Atome
|
1217
|
+
cell_value.fit(cell_height)
|
1218
|
+
html_element = JS.global[:document].getElementById(cell_value.id.to_s)
|
1219
|
+
td.appendChild(html_element)
|
1220
|
+
html_element[:style][:transformOrigin] = 'top left'
|
1221
|
+
html_element[:style][:position] = 'relative'
|
1222
|
+
cell_value.top(0)
|
1223
|
+
cell_value.left(0)
|
1224
|
+
else
|
1225
|
+
td[:textContent] = cell_value.to_s
|
1226
|
+
end
|
1227
|
+
tr.appendChild(td)
|
1228
|
+
end
|
1229
|
+
|
1230
|
+
tbody.appendChild(tr)
|
1231
|
+
end
|
1232
|
+
table_html.appendChild(tbody)
|
1233
|
+
JS.global[:document].querySelector("##{@id}").appendChild(table_html)
|
1234
|
+
end
|
1235
|
+
|
1236
|
+
def refresh_table(_params)
|
1237
|
+
# first we need to extact all atome from the table or they will be deleted by the table refres
|
1238
|
+
data = @original_atome.data
|
1239
|
+
data.each do |row|
|
1240
|
+
row.each do |k, v|
|
1241
|
+
v.attach(:view) if v.instance_of? Atome
|
1242
|
+
end
|
1243
|
+
end
|
1244
|
+
table_element = JS.global[:document].querySelector("##{@id} table")
|
1245
|
+
if table_element.nil?
|
1246
|
+
puts 'Table not found'
|
1247
|
+
return
|
1248
|
+
end
|
1249
|
+
(table_element[:rows].to_a.length - 1).downto(1) do |i|
|
1250
|
+
table_element.deleteRow(i)
|
1251
|
+
end
|
1252
|
+
|
1253
|
+
max_cells = data.map { |row| row.keys.length }.max
|
1254
|
+
|
1255
|
+
data.each do |row|
|
1256
|
+
new_row = table_element.insertRow(-1)
|
1257
|
+
max_cells.times do |i|
|
1258
|
+
key = row.keys[i]
|
1259
|
+
value = row[key]
|
1260
|
+
cell = new_row.insertCell(-1)
|
1261
|
+
if value.instance_of? Atome
|
1262
|
+
html_element = JS.global[:document].getElementById(value.id.to_s)
|
1263
|
+
cell.appendChild(html_element)
|
1264
|
+
else
|
1265
|
+
cell[:textContent] = value.to_s
|
1266
|
+
end
|
1267
|
+
set_td_style(cell)
|
1268
|
+
end
|
1269
|
+
end
|
1270
|
+
end
|
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
|
+
|
1287
|
+
def insert_cell(params)
|
1288
|
+
row_index, cell_index = params[:cell]
|
1289
|
+
new_content = params[:content]
|
1290
|
+
container = JS.global[:document].getElementById(@id.to_s)
|
1291
|
+
|
1292
|
+
table = container.querySelector('table')
|
1293
|
+
if table.nil?
|
1294
|
+
puts 'No table found in the container'
|
1295
|
+
return
|
1296
|
+
end
|
1297
|
+
|
1298
|
+
row = table.querySelectorAll('tr')[row_index]
|
1299
|
+
if row.nil?
|
1300
|
+
puts "Row at index #{row_index} not found"
|
1301
|
+
return
|
1302
|
+
end
|
1303
|
+
|
1304
|
+
cell = row.querySelectorAll('td')[cell_index]
|
1305
|
+
if cell.nil?
|
1306
|
+
puts "Cell at index #{cell_index} in row #{row_index} not found"
|
1307
|
+
return
|
1308
|
+
end
|
1309
|
+
|
1310
|
+
if new_content.instance_of? Atome
|
1311
|
+
cell.innerHTML = ''
|
1312
|
+
html_element = JS.global[:document].getElementById(new_content.id.to_s)
|
1313
|
+
cell.appendChild(html_element)
|
1314
|
+
else
|
1315
|
+
cell[:textContent] = new_content.to_s
|
1316
|
+
end
|
1317
|
+
end
|
1318
|
+
|
1319
|
+
def insert_row(params)
|
1320
|
+
insert_at_index = params[:row]
|
1321
|
+
table_element = JS.global[:document].querySelector("##{@id} table")
|
1322
|
+
|
1323
|
+
if table_element.nil?
|
1324
|
+
puts 'Tableau non trouvé'
|
1325
|
+
return
|
1326
|
+
end
|
1327
|
+
|
1328
|
+
tbody = table_element.querySelector('tbody')
|
1329
|
+
|
1330
|
+
header_row = table_element.querySelector('thead tr')
|
1331
|
+
column_count = header_row ? header_row.querySelectorAll('th').to_a.length : 0
|
1332
|
+
|
1333
|
+
new_row = JS.global[:document].createElement('tr')
|
1334
|
+
column_count.times do |cell_index|
|
1335
|
+
td = JS.global[:document].createElement('td')
|
1336
|
+
set_td_style(td)
|
1337
|
+
new_row.appendChild(td)
|
1338
|
+
end
|
1339
|
+
|
1340
|
+
if insert_at_index.zero?
|
1341
|
+
tbody.insertBefore(new_row, tbody.firstChild)
|
1342
|
+
else
|
1343
|
+
reference_row = tbody.querySelectorAll('tr').to_a[insert_at_index]
|
1344
|
+
tbody.insertBefore(new_row, reference_row)
|
1345
|
+
end
|
1346
|
+
|
1347
|
+
end
|
1348
|
+
|
1349
|
+
def insert_column(params)
|
1350
|
+
insert_at_index = params[:column]
|
1351
|
+
table_element = JS.global[:document].querySelector("##{@id} table")
|
1352
|
+
if table_element.nil?
|
1353
|
+
puts 'Table not found'
|
1354
|
+
return
|
1355
|
+
end
|
1356
|
+
rows = table_element.querySelectorAll('tr').to_a
|
1357
|
+
rows.each_with_index do |row, index|
|
1358
|
+
if index == 0
|
1359
|
+
# case1
|
1360
|
+
else
|
1361
|
+
new_cell = JS.global[:document].createElement('td')
|
1362
|
+
new_cell[:innerText] = ''
|
1363
|
+
set_td_style(new_cell)
|
1364
|
+
if insert_at_index.zero?
|
1365
|
+
row.insertBefore(new_cell, row.firstChild)
|
1366
|
+
else
|
1367
|
+
child_nodes = row.querySelectorAll('td').to_a
|
1368
|
+
|
1369
|
+
if insert_at_index < child_nodes.length
|
1370
|
+
reference_cell = child_nodes[insert_at_index]
|
1371
|
+
row.insertBefore(new_cell, reference_cell)
|
1372
|
+
else
|
1373
|
+
row.appendChild(new_cell)
|
1374
|
+
end
|
1375
|
+
end
|
1376
|
+
end
|
1377
|
+
|
1378
|
+
end
|
1379
|
+
|
1380
|
+
end
|
1381
|
+
|
1382
|
+
def table_insert(params)
|
1383
|
+
if params[:cell]
|
1384
|
+
insert_cell(params)
|
1385
|
+
elsif params[:row]
|
1386
|
+
insert_row(params)
|
1387
|
+
elsif params[:column]
|
1388
|
+
insert_column(params)
|
1389
|
+
end
|
1390
|
+
|
1391
|
+
end
|
1392
|
+
|
1393
|
+
|
1394
|
+
def table_remove(params)
|
1395
|
+
if params[:row]
|
1396
|
+
row_index = params[:row]
|
1397
|
+
table_element = JS.global[:document].querySelector("##{@id} table")
|
1398
|
+
|
1399
|
+
if table_element.nil?
|
1400
|
+
puts 'Table not found'
|
1401
|
+
return
|
1402
|
+
end
|
1403
|
+
|
1404
|
+
rows = table_element.querySelectorAll('tbody tr').to_a
|
1405
|
+
|
1406
|
+
if row_index >= rows.length
|
1407
|
+
puts "row not found : #{row_index}"
|
1408
|
+
return
|
1409
|
+
end
|
1410
|
+
row_to_remove = rows[row_index]
|
1411
|
+
|
1412
|
+
row_to_remove[:parentNode].removeChild(row_to_remove)
|
1413
|
+
|
1414
|
+
rows.each_with_index do |row, i|
|
1415
|
+
next if i <= row_index
|
1416
|
+
end
|
1417
|
+
elsif params[:column]
|
1418
|
+
column_index = params[:column]
|
1419
|
+
table_element = JS.global[:document].querySelector("##{@id} table")
|
1420
|
+
|
1421
|
+
if table_element.nil?
|
1422
|
+
puts 'Table not found'
|
1423
|
+
return
|
1424
|
+
end
|
1425
|
+
|
1426
|
+
rows = table_element.querySelectorAll('tbody tr').to_a
|
1427
|
+
rows.each do |row|
|
1428
|
+
cells = row.querySelectorAll('td').to_a
|
1429
|
+
if column_index < cells.length
|
1430
|
+
cell_to_remove = cells[column_index]
|
1431
|
+
cell_to_remove[:parentNode].removeChild(cell_to_remove)
|
1432
|
+
end
|
1433
|
+
end
|
1434
|
+
|
1435
|
+
end
|
1163
1436
|
end
|
1164
1437
|
|
1438
|
+
# atomisation!
|
1439
|
+
def atomized(html_object)
|
1440
|
+
html_object=html_object[0] if html_object.instance_of? Array
|
1441
|
+
@element = html_object
|
1442
|
+
end
|
1165
1443
|
end
|
1444
|
+
|
1445
|
+
|
@@ -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].call(: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].call(: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].call(: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
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
|
4
|
+
c = circle({ height: 400, width: 200, top: 100, left:99, top: 79 })
|
5
|
+
b = c.box({ width: 200, height: 100, left: 280, top: 190, id: :my_box })
|
6
|
+
i= image(:red_planet)
|
7
|
+
c.touch(true) do
|
8
|
+
c.fit({ value: 100, axis: :x })
|
9
|
+
end
|
10
|
+
|
11
|
+
puts '------'
|
12
|
+
puts "b.compute left return the position on the screen of the item : #{b.compute({reference: c.id, particle: :left, unit: :pixel})}"
|
13
|
+
puts "b.compute left : #{b.compute({ particle: :left })[:value]}, c left : #{b.left}"
|
14
|
+
puts "b.compute top :#{b.compute({ particle: :top })[:value]}, c top: #{b.top}"
|
15
|
+
alert "i.compute width :#{i.compute({ particle: :width })[:value]}, i width: #{i.width}"
|
16
|
+
alert "i.compute height :#{i.compute({ particle: :height })[:value]}, i height: #{i.height}"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
|
4
|
+
c = circle({ height: 400, width: 200, top: 100, left: 0, top: 100 , id: :the_circle})
|
5
|
+
b = c.box({ width: 200, height: 100, left: 600, top: 200, id: :my_box })
|
6
|
+
c.circle({ width: 200, height: 100, left: 120, top: -80, id: :my_text, data: :hi })
|
7
|
+
b.circle({ color: :yellow, width: 55, height: 88, left: 100 })
|
8
|
+
b.box
|
9
|
+
|
10
|
+
|
11
|
+
atome_founds = c.dig
|
12
|
+
puts "dig allow to retrieve all attached atomes recursively,
|
13
|
+
it return a table of ID including the ID of the parent (here : :the_circle) :\n#{atome_founds}"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
c = circle({ height: 400, width: 200, top: 100, left: 0, top: 100 })
|
4
|
+
b = c.box({ width: 200, height: 100, left: 600, top: 200, id: :my_box })
|
5
|
+
c.circle({ width: 200, height: 100, left: 120, top: -80, id: :my_text, data: :hi })
|
6
|
+
b.circle({ color: :yellow, width: 55, height: 88, left: 100 })
|
7
|
+
b.box
|
8
|
+
i=c.image({path: 'medias/images/red_planet.png', id: :the_pix })
|
9
|
+
# b.text(:red_planet)
|
10
|
+
|
11
|
+
wait 1 do
|
12
|
+
|
13
|
+
c.fit({ value: 100, axis: :x })
|
14
|
+
|
15
|
+
wait 1 do
|
16
|
+
c.fit({ value: 66, axis: :y })
|
17
|
+
wait 1 do
|
18
|
+
c.fit({ value: 600, axis: :x })
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
# alert i.width
|
23
|
+
# alert i.height
|
24
|
+
# i.fit({ value: 66, axis: :x })
|
25
|
+
# i.width(66)
|
26
|
+
# i.height(66)
|
@@ -12,10 +12,10 @@ shortcut(key: :b, affect: :all) do |key, object_id|
|
|
12
12
|
end
|
13
13
|
text({data: "Key 'b' on :all", top: 0})
|
14
14
|
|
15
|
-
shortcut(key: :
|
15
|
+
shortcut(key: :e, option: :meta,affect: [:my_circle, :red_box]) do |key, object_id|
|
16
16
|
puts "Key #{key} press on #{object_id}"
|
17
17
|
end
|
18
|
-
text({data: "Key '
|
18
|
+
text({data: "Key 'e' with Meta on [:my_circle, :red_box]", top: 30, left: 0, position: :absolute})
|
19
19
|
|
20
20
|
|
21
21
|
shortcut(key: :j, option: :ctrl, affect: :all, exclude: [:my_circle, :my_box]) do |key, object_id|
|