# frozen_string_literal: true new({ renderer: :html, method: :web }) do |params, &user_proc| params end new({ renderer: :html, method: :renderers, type: :string }) new({ renderer: :html, method: :delete, type: :string }) do |params| html.delete(id) end new({ renderer: :html, method: :hypertext }) do |params| html.hypertext(params) end new({ renderer: :html, method: :hyperedit }) do |params| html.hyperedit(params) end new({ renderer: :html, method: :read, type: :string }) do |value, &bloc| html.read(id, value) end new({ renderer: :html, method: :browse, type: :string }) do |value, &bloc| html.browse(id, value) end new({ renderer: :html, method: :terminal, type: :string }) do |value, &bloc| html.terminal(id, value) end new({renderer: :html, method: :match}) do |params, bloc| case id when :atome || :view result = bloc.call result = { alterations: result } params = params.merge(result) html.match(params) end end new({ renderer: :html, method: :import, type: :blob }) do |_params, bloc| if Atome::host == 'web-opal' file_for_opal(@id, bloc) do |file_content| bloc.call(file_content) end else # Wasm version def create_file_browser(_options = '', &bloc) div_element = JS.global[:document].getElementById(@id.to_s) input_element = JS.global[:document].createElement("input") input_element[:type] = "file" input_element[:style][:position] = "absolute" input_element[:style][:display] = "none" input_element[:style][:width] = "0px" input_element[:style][:height] = "0px" input_element.addEventListener("change") do |native_event| event = Native(native_event) file = event[:target][:files][0] if file puts "file requested: #{file[:name]}" file_reader = JS.global[:FileReader].new file_reader.addEventListener("load") do |load_event| file_content = load_event[:target][:result] Atome.file_handler(@id, file_content, bloc) end file_reader.readAsText(file) end end div_element.addEventListener("mousedown") do |event| input_element.click end div_element.appendChild(input_element) end create_file_browser(:options) do |file_content| # puts "wasm ===>#{file_content}" bloc.call(file_content) end end end new({ renderer: :html, method: :selected, specific: :text }) do |value, &bloc| html.select_text(value) end new({ method: :compute, type: :hash, renderer: :html }) do |params| element = JS.global[:document].getElementById(@id.to_s) bounding_box = element.getBoundingClientRect() top = bounding_box[:top] left = bounding_box[:left] width = bounding_box[:width] height = bounding_box[:height] value_found = case params[:particle] when :left left.to_f when :top top.to_f when :width width.to_f when :height height.to_f else nil end @compute[:value] = value_found end