opal-browser 0.2.0 → 0.3.3
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 +5 -5
- data/.github/workflows/build.yml +78 -0
- data/.gitignore +3 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +17 -3
- data/LICENSE +2 -1
- data/README.md +131 -54
- data/Rakefile +29 -1
- data/config.ru +20 -3
- data/docs/polyfills.md +24 -0
- data/examples/2048/Gemfile +6 -0
- data/examples/2048/README.md +13 -0
- data/examples/2048/app/application.rb +169 -0
- data/examples/2048/config.ru +9 -0
- data/examples/canvas/Gemfile +6 -0
- data/examples/canvas/README.md +9 -0
- data/examples/canvas/app/application.rb +55 -0
- data/examples/canvas/config.ru +9 -0
- data/examples/component/Gemfile +6 -0
- data/examples/component/README.md +10 -0
- data/examples/component/app/application.rb +66 -0
- data/examples/component/config.ru +9 -0
- data/examples/integrations/README.md +24 -0
- data/examples/integrations/dynamic-rack-opal-sprockets-server/Gemfile +6 -0
- data/examples/integrations/dynamic-rack-opal-sprockets-server/README.md +16 -0
- data/examples/integrations/dynamic-rack-opal-sprockets-server/app/application.rb +6 -0
- data/examples/integrations/dynamic-rack-opal-sprockets-server/config.ru +9 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/.gitignore +1 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/Gemfile +7 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/README.md +22 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/Rakefile +4 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/app/application.rb +6 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/app.rb +32 -0
- data/examples/integrations/dynamic-roda-roda-sprockets/config.ru +3 -0
- data/examples/integrations/dynamic-roda-tilt/.gitignore +1 -0
- data/examples/integrations/dynamic-roda-tilt/Gemfile +8 -0
- data/examples/integrations/dynamic-roda-tilt/README.md +17 -0
- data/examples/integrations/dynamic-roda-tilt/Rakefile +6 -0
- data/examples/integrations/dynamic-roda-tilt/app/application.rb +6 -0
- data/examples/integrations/dynamic-roda-tilt/app.rb +50 -0
- data/examples/integrations/dynamic-roda-tilt/config.ru +3 -0
- data/examples/integrations/dynamic-sinatra-opal-sprockets-server/Gemfile +7 -0
- data/examples/integrations/dynamic-sinatra-opal-sprockets-server/README.md +16 -0
- data/examples/integrations/dynamic-sinatra-opal-sprockets-server/app/application.rb +6 -0
- data/examples/integrations/dynamic-sinatra-opal-sprockets-server/config.ru +29 -0
- data/examples/integrations/static-bash/.gitignore +2 -0
- data/examples/integrations/static-bash/Gemfile +3 -0
- data/examples/integrations/static-bash/README.md +8 -0
- data/examples/integrations/static-bash/app/application.rb +6 -0
- data/examples/integrations/static-bash/build.sh +4 -0
- data/examples/integrations/static-bash/index.html +10 -0
- data/examples/integrations/static-bash-opal-parser/.gitignore +3 -0
- data/examples/integrations/static-bash-opal-parser/Gemfile +3 -0
- data/examples/integrations/static-bash-opal-parser/README.md +10 -0
- data/examples/integrations/static-bash-opal-parser/build.sh +4 -0
- data/examples/integrations/static-bash-opal-parser/index.html +19 -0
- data/examples/integrations/static-rake/.gitignore +1 -0
- data/examples/integrations/static-rake/Gemfile +4 -0
- data/examples/integrations/static-rake/README.md +7 -0
- data/examples/integrations/static-rake/Rakefile +10 -0
- data/examples/integrations/static-rake/app/application.rb +6 -0
- data/examples/integrations/static-rake/index.html +9 -0
- data/examples/integrations/static-rake-guard/.gitignore +1 -0
- data/examples/integrations/static-rake-guard/Gemfile +6 -0
- data/examples/integrations/static-rake-guard/Guardfile +3 -0
- data/examples/integrations/static-rake-guard/README.md +10 -0
- data/examples/integrations/static-rake-guard/Rakefile +10 -0
- data/examples/integrations/static-rake-guard/app/application.rb +6 -0
- data/examples/integrations/static-rake-guard/index.html +9 -0
- data/examples/svg/.gitignore +1 -0
- data/examples/svg/Gemfile +4 -0
- data/examples/svg/README.md +7 -0
- data/examples/svg/Rakefile +10 -0
- data/examples/svg/app/application.rb +11 -0
- data/examples/svg/index.html +17 -0
- data/examples/svg/index.svg +6 -0
- data/index.html.erb +2 -3
- data/opal/browser/audio/node.rb +121 -0
- data/opal/browser/audio/param_schedule.rb +43 -0
- data/opal/browser/audio.rb +66 -0
- data/opal/browser/blob.rb +94 -0
- data/opal/browser/canvas/data.rb +1 -1
- data/opal/browser/canvas/gradient.rb +1 -1
- data/opal/browser/canvas/style.rb +3 -1
- data/opal/browser/canvas/text.rb +1 -1
- data/opal/browser/canvas.rb +17 -3
- data/opal/browser/console.rb +3 -1
- data/opal/browser/cookies.rb +72 -34
- data/opal/browser/crypto.rb +79 -0
- data/opal/browser/css/declaration.rb +1 -1
- data/opal/browser/css/rule.rb +1 -1
- data/opal/browser/css/style_sheet.rb +2 -2
- data/opal/browser/css.rb +23 -7
- data/opal/browser/database/sql.rb +7 -8
- data/opal/browser/delay.rb +16 -0
- data/opal/browser/dom/attribute.rb +1 -1
- data/opal/browser/dom/builder.rb +29 -10
- data/opal/browser/dom/document.rb +81 -13
- data/opal/browser/dom/document_fragment.rb +18 -0
- data/opal/browser/dom/document_or_shadow_root.rb +19 -0
- data/opal/browser/dom/element/attributes.rb +28 -4
- data/opal/browser/dom/element/button.rb +31 -0
- data/opal/browser/dom/element/custom.rb +177 -0
- data/opal/browser/dom/element/data.rb +17 -2
- data/opal/browser/dom/element/editable.rb +47 -0
- data/opal/browser/dom/element/form.rb +38 -0
- data/opal/browser/dom/element/iframe.rb +37 -0
- data/opal/browser/dom/element/image.rb +2 -0
- data/opal/browser/dom/element/input.rb +36 -0
- data/opal/browser/dom/element/media.rb +17 -0
- data/opal/browser/dom/element/scroll.rb +106 -74
- data/opal/browser/dom/element/select.rb +6 -0
- data/opal/browser/dom/element/size.rb +12 -0
- data/opal/browser/dom/element/template.rb +2 -0
- data/opal/browser/dom/element/textarea.rb +2 -0
- data/opal/browser/dom/element.rb +194 -50
- data/opal/browser/dom/mutation_observer.rb +2 -2
- data/opal/browser/dom/node.rb +53 -13
- data/opal/browser/dom/node_set.rb +13 -2
- data/opal/browser/dom/shadow_root.rb +12 -0
- data/opal/browser/dom/text.rb +2 -2
- data/opal/browser/dom.rb +38 -5
- data/opal/browser/effects.rb +170 -4
- data/opal/browser/event/all.rb +26 -0
- data/opal/browser/event/animation.rb +2 -0
- data/opal/browser/event/audio_processing.rb +2 -0
- data/opal/browser/event/base.rb +35 -4
- data/opal/browser/event/before_unload.rb +2 -0
- data/opal/browser/event/clipboard.rb +9 -0
- data/opal/browser/event/close.rb +2 -0
- data/opal/browser/event/composition.rb +2 -0
- data/opal/browser/event/custom.rb +1 -1
- data/opal/browser/event/data_transfer.rb +95 -0
- data/opal/browser/event/device_light.rb +2 -0
- data/opal/browser/event/device_motion.rb +2 -0
- data/opal/browser/event/device_orientation.rb +2 -0
- data/opal/browser/event/device_proximity.rb +2 -0
- data/opal/browser/event/drag.rb +9 -5
- data/opal/browser/event/focus.rb +2 -0
- data/opal/browser/event/gamepad.rb +3 -1
- data/opal/browser/event/hash_change.rb +2 -0
- data/opal/browser/event/keyboard.rb +14 -1
- data/opal/browser/event/message.rb +2 -0
- data/opal/browser/event/mouse.rb +10 -6
- data/opal/browser/event/page_transition.rb +2 -0
- data/opal/browser/event/pop_state.rb +2 -0
- data/opal/browser/event/progress.rb +2 -0
- data/opal/browser/event/sensor.rb +2 -0
- data/opal/browser/event/storage.rb +2 -0
- data/opal/browser/event/touch.rb +2 -0
- data/opal/browser/event/wheel.rb +2 -0
- data/opal/browser/event.rb +26 -116
- data/opal/browser/event_source.rb +1 -1
- data/opal/browser/form_data.rb +225 -0
- data/opal/browser/history.rb +4 -8
- data/opal/browser/http/request.rb +32 -10
- data/opal/browser/http/response.rb +5 -1
- data/opal/browser/http.rb +0 -2
- data/opal/browser/immediate.rb +0 -2
- data/opal/browser/location.rb +7 -1
- data/opal/browser/navigator.rb +105 -4
- data/opal/browser/polyfill/visual_viewport.rb +216 -0
- data/opal/browser/screen.rb +2 -2
- data/opal/browser/setup/base.rb +6 -0
- data/opal/browser/setup/full.rb +13 -0
- data/opal/browser/setup/large.rb +17 -0
- data/opal/browser/setup/mini.rb +8 -0
- data/opal/browser/setup/traditional.rb +10 -0
- data/opal/browser/socket.rb +3 -3
- data/opal/browser/storage.rb +2 -2
- data/opal/browser/support.rb +46 -22
- data/opal/browser/utils.rb +94 -14
- data/opal/browser/version.rb +1 -1
- data/opal/browser/visual_viewport.rb +39 -0
- data/opal/browser/window/size.rb +14 -0
- data/opal/browser/window/view.rb +15 -0
- data/opal/browser/window.rb +29 -16
- data/opal/browser.rb +1 -11
- data/opal-browser.gemspec +3 -3
- data/spec/database/sql_spec.rb +43 -35
- data/spec/delay_spec.rb +15 -12
- data/spec/dom/document_spec.rb +10 -8
- data/spec/dom/element/custom_spec.rb +106 -0
- data/spec/dom/element/subclass_spec.rb +144 -0
- data/spec/dom/element_spec.rb +42 -0
- data/spec/dom/mutation_observer_spec.rb +12 -8
- data/spec/dom/node_spec.rb +48 -0
- data/spec/dom_spec.rb +8 -0
- data/spec/event_source_spec.rb +15 -12
- data/spec/{dom/event_spec.rb → event_spec.rb} +44 -15
- data/spec/history_spec.rb +23 -19
- data/spec/http_spec.rb +19 -31
- data/spec/immediate_spec.rb +5 -4
- data/spec/interval_spec.rb +18 -9
- data/spec/native_cached_wrapper_spec.rb +46 -0
- data/spec/runner.rb +37 -62
- data/spec/socket_spec.rb +15 -12
- data/spec/spec_helper.rb +2 -1
- data/spec/spec_helper_promise.rb.erb +25 -0
- metadata +120 -16
- data/.travis.yml +0 -74
- data/opal/browser/window/scroll.rb +0 -59
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>My Application</title>
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
7
|
+
<script src='opal-browser.js' onload='Opal.require("native"); Opal.require("promise"); Opal.require("browser/setup/full");'></script>
|
|
8
|
+
<script src='application.js'></script>
|
|
9
|
+
</body>
|
|
10
|
+
</html>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
Opal-Parser compilation example
|
|
2
|
+
===============================
|
|
3
|
+
|
|
4
|
+
To compile everything, run:
|
|
5
|
+
|
|
6
|
+
$ ./build.sh
|
|
7
|
+
|
|
8
|
+
NOTE: This kind of integration, while cool, is highly unrecommended for production purposes.
|
|
9
|
+
You would rather want to compile your application from Ruby to JavaScript yourself (on a server
|
|
10
|
+
or whatnot), than let it be compiled in a web browser.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>My Application</title>
|
|
5
|
+
|
|
6
|
+
<script src='opal-browser.js'></script>
|
|
7
|
+
<script src='opal-parser.js' onload='Opal.require("opal-parser")'></script>
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<script type='text/ruby'>
|
|
11
|
+
require 'native'
|
|
12
|
+
require 'promise'
|
|
13
|
+
require 'browser/setup/full'
|
|
14
|
+
|
|
15
|
+
# Your Opal code here
|
|
16
|
+
$document.body << "Hello world!"
|
|
17
|
+
</script>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/application.js
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/application.js
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/application.js
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>My Application</title>
|
|
5
|
+
|
|
6
|
+
<style>
|
|
7
|
+
body { margin: 0px; padding: 0px; overflow: hidden; }
|
|
8
|
+
svg { width: 100%; height: 100vh; }
|
|
9
|
+
</style>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
|
|
13
|
+
<ellipse cx="50" cy="50" rx="10" ry="10" stroke="#000" stroke-width=".253"/>
|
|
14
|
+
</svg>
|
|
15
|
+
<script src='application.js'></script>
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
data/index.html.erb
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
<html>
|
|
3
3
|
<head>
|
|
4
4
|
<title>Opal Browser - RSpec Runner</title>
|
|
5
|
-
|
|
5
|
+
</head>
|
|
6
|
+
<body>
|
|
6
7
|
<script>
|
|
7
8
|
window.onerror = function(msg, url, line) {
|
|
8
9
|
var error = document.createElement("div");
|
|
@@ -18,8 +19,6 @@
|
|
|
18
19
|
<script src="spec/wgxpath.install.js"></script>
|
|
19
20
|
|
|
20
21
|
<%= javascript_include_tag @server.main %>
|
|
21
|
-
</head>
|
|
22
|
-
<body>
|
|
23
22
|
</body>
|
|
24
23
|
</html>
|
|
25
24
|
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
module Browser; module Audio; module Node
|
|
2
|
+
|
|
3
|
+
class Base
|
|
4
|
+
include Native::Wrapper
|
|
5
|
+
|
|
6
|
+
def initialize(native)
|
|
7
|
+
@native = native
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def method_missing(name, value = nil)
|
|
11
|
+
if name.end_with? '='
|
|
12
|
+
`#@native[#{name.delete '='}].value = value`
|
|
13
|
+
elsif value.nil? || value == true
|
|
14
|
+
`#@native[#{name}].value`
|
|
15
|
+
elsif value == false
|
|
16
|
+
`#@native[#{name}]`
|
|
17
|
+
else
|
|
18
|
+
super
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def respond_to_missing?(method, include_all = false)
|
|
23
|
+
`#@native[#{method.delete('=')}] != null`
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def connect(destination)
|
|
27
|
+
`#@native.connect(#{Native.convert(destination)})`
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def disconnect(destination = nil, options = {})
|
|
31
|
+
destination = Native.try_convert(destination)
|
|
32
|
+
output = options[:output] || 0
|
|
33
|
+
input = options[:input] || 0
|
|
34
|
+
|
|
35
|
+
if options.any?
|
|
36
|
+
`#@native.disconnect(#{destination}, #{output}, #{input}) || nil`
|
|
37
|
+
elsif destination
|
|
38
|
+
`#@native.disconnect(#{destination})`
|
|
39
|
+
else
|
|
40
|
+
`#@native.disconnect()`
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
class Gain < Base
|
|
46
|
+
def initialize(audio_context)
|
|
47
|
+
super `#{audio_context.to_n}.createGain()`
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
class Oscillator < Base
|
|
52
|
+
TYPES = %i(sine square sawtooth triangle custom)
|
|
53
|
+
|
|
54
|
+
alias_native :start
|
|
55
|
+
alias_native :stop
|
|
56
|
+
|
|
57
|
+
alias_native :periodic_wave=, :setPeriodicWave
|
|
58
|
+
|
|
59
|
+
def initialize(audio_context)
|
|
60
|
+
super `#{audio_context.to_n}.createOscillator()`
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def type=(type)
|
|
64
|
+
unless TYPES.include?(type)
|
|
65
|
+
raise ArgumentError, "type #{type} doesn't exists"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
`#@native.type = type`
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def type
|
|
72
|
+
`#@native.type`
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
class Delay < Base
|
|
77
|
+
def initialize(audio_context, max_time = 1)
|
|
78
|
+
super `#{audio_context.to_n}.createDelay(max_time)`
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
class DynamicsCompressor < Base
|
|
83
|
+
|
|
84
|
+
alias_native :reduction
|
|
85
|
+
|
|
86
|
+
def initialize(audio_context)
|
|
87
|
+
super `#{audio_context.to_n}.createDynamicsCompressor()`
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
class BiquadFilter < Base
|
|
92
|
+
|
|
93
|
+
TYPES = %i(lowpass highpass bandpass lowshelf highshelf peaking notch allpass)
|
|
94
|
+
|
|
95
|
+
def initialize(audio_context)
|
|
96
|
+
super `#{audio_context.to_n}.createBiquadFilter()`
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def type=(type)
|
|
100
|
+
unless TYPES.include?(type)
|
|
101
|
+
raise ArgumentError, "type #{type} doesn't exists"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
`#@native.type = type`
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def type
|
|
108
|
+
`#@native.type`
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
class StereoPanner < Base
|
|
113
|
+
|
|
114
|
+
alias_native :normalize
|
|
115
|
+
|
|
116
|
+
def initialize(audio_context)
|
|
117
|
+
super `#{audio_context.to_n}.createStereoPanner()`
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
end; end; end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
module Browser; module Audio
|
|
2
|
+
|
|
3
|
+
class ParamSchedule
|
|
4
|
+
include Native::Wrapper
|
|
5
|
+
|
|
6
|
+
alias_native :cancel, :cancelScheduledValues
|
|
7
|
+
|
|
8
|
+
def initialize(audio_param, time = nil)
|
|
9
|
+
@time = time
|
|
10
|
+
@audio_param = audio_param
|
|
11
|
+
super Native.convert(audio_param)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def at(time)
|
|
15
|
+
new(@audio_param, time)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def value(value, time = nil)
|
|
19
|
+
@value = value
|
|
20
|
+
`#@native.setValueAtTime(#{@value}, #{@time || time})`
|
|
21
|
+
self
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def linear_ramp_to(value = nil, time = nil)
|
|
25
|
+
`#@native.linearRampToValueAtTime(#{@value || value}, #{@time || time})`
|
|
26
|
+
self
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def exponential_ramp_to(value = nil, time = nil)
|
|
30
|
+
`#@native.exponentialRampToValueAtTime(#{@value || value}, #{@time || time})`
|
|
31
|
+
self
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def target(target, time_hash)
|
|
35
|
+
`#@native.setTargetAtTime(target, #{time_hash[:start_time]}, #{time_hash[:time_constant]})`
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def curve(values, time_hash)
|
|
39
|
+
`#@native.setValueCurveAtTime(values, #{time_hash[:start_time]}, #{time_hash[:time_constant]})`
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
end; end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require 'browser/audio/node'
|
|
2
|
+
|
|
3
|
+
module Browser; module Audio
|
|
4
|
+
|
|
5
|
+
class Context
|
|
6
|
+
include Native::Wrapper
|
|
7
|
+
|
|
8
|
+
alias_native :destination
|
|
9
|
+
alias_native :listener
|
|
10
|
+
alias_native :state
|
|
11
|
+
|
|
12
|
+
alias_native :sample_rate, :sampleRate
|
|
13
|
+
alias_native :current_time, :currentTime
|
|
14
|
+
|
|
15
|
+
def self.supported?
|
|
16
|
+
Browser.support?('Audio') || Browser.support?('Audio (Chrome)')
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
if Browser.supports? 'Audio'
|
|
20
|
+
def initialize
|
|
21
|
+
super `new AudioContext()`
|
|
22
|
+
end
|
|
23
|
+
elsif Browser.supports? 'Audio (Chrome)'
|
|
24
|
+
def initialize
|
|
25
|
+
super `new webkitAudioContext()`
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
def initialize
|
|
29
|
+
raise NotImplementedError, 'Audio unsupported'
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def gain
|
|
34
|
+
Node::Gain.new(self)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def oscillator
|
|
38
|
+
Node::Oscillator.new(self)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def delay(max_time)
|
|
42
|
+
Node::Delay.new(self, max_time)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def dynamics_compressor
|
|
46
|
+
Node::DynamicsCompressor.new(self)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def biquad_filter
|
|
50
|
+
Node::BiquadFilter.new(self)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def stereo_panner
|
|
54
|
+
Node::StereoPanner.new(self)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def periodic_wave(real, imaginary)
|
|
58
|
+
`#{@native}.createPeriodicWave(new Float32Array(#{real}), new Float32Array(#{imaginary}));`
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
alias_native :suspend
|
|
62
|
+
alias_native :resume
|
|
63
|
+
alias_native :close
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end; end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
module Browser
|
|
2
|
+
|
|
3
|
+
class Blob
|
|
4
|
+
include NativeCachedWrapper
|
|
5
|
+
|
|
6
|
+
# Create a new blob from anything that Blob API supports
|
|
7
|
+
def self.create(from, options={})
|
|
8
|
+
new(`new Blob(#{Native.convert(from)}, #{options.to_n})`)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# @!attribute [r] size
|
|
12
|
+
# @return [Integer] blob size in bytes
|
|
13
|
+
def size
|
|
14
|
+
`#@native.size`
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# @!attribute [r] type
|
|
18
|
+
# @return [String] blob mime type
|
|
19
|
+
def type
|
|
20
|
+
`#@native.type`
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Convert a blob to a UTF-8 encoded string.
|
|
24
|
+
#
|
|
25
|
+
# If block is given it will be called with a parameter once we receive
|
|
26
|
+
# the text. Otherwise return a {Promise} which will resolve once we
|
|
27
|
+
# receive it.
|
|
28
|
+
def text(&block)
|
|
29
|
+
promise = nil
|
|
30
|
+
unless block_given?
|
|
31
|
+
promise = Promise.new
|
|
32
|
+
block = proc { |i| promise.resolve(i) }
|
|
33
|
+
end
|
|
34
|
+
`#@native.text().then(#{block.to_n})`
|
|
35
|
+
promise
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# {Buffer} view into the blob
|
|
39
|
+
#
|
|
40
|
+
# If block is given it will be called with a parameter once we receive
|
|
41
|
+
# the buffer. Otherwise return a {Promise} which will resolve once we
|
|
42
|
+
# receive it.
|
|
43
|
+
def buffer
|
|
44
|
+
promise = nil
|
|
45
|
+
unless block_given?
|
|
46
|
+
promise = Promise.new
|
|
47
|
+
block = proc { |i| promise.resolve(i) }
|
|
48
|
+
end
|
|
49
|
+
resblock = proc { |i| block.call(Buffer.new(i)) }
|
|
50
|
+
`#@native.arrayBuffer().then(#{resblock.to_n})`
|
|
51
|
+
promise
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Create a new blob by slicing this blob
|
|
55
|
+
def slice(start, finish=nil)
|
|
56
|
+
Blob.new(`#@native.slice(#{start}, #{finish})`)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Convert a blob to an URL that can be used to reference this blob in DOM
|
|
60
|
+
# eg. display some multimedia
|
|
61
|
+
def to_url(window=$window)
|
|
62
|
+
`#{window.to_n}.URL.createObjectURL(#@native)`
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Rename a blob and return a {File} with a new name.
|
|
66
|
+
#
|
|
67
|
+
# @return [File] a renamed blob
|
|
68
|
+
def rename(new_filename)
|
|
69
|
+
File.create([self], new_filename, type: type,
|
|
70
|
+
lastModified: respond_to?(:last_modified) ?
|
|
71
|
+
last_modified : Time.now)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
class File < Blob
|
|
76
|
+
# Create a new file from anything that File API supports
|
|
77
|
+
def self.create(from, name, options={})
|
|
78
|
+
new(`new File(#{Native.convert(from)}, #{name}, #{options.to_n})`)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# @!attribute [r] last_modified
|
|
82
|
+
# @return [Time] last modified date of this file
|
|
83
|
+
def last_modified
|
|
84
|
+
Time.at(`#@native.lastModified`/1000.0)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# @!attribute [r] name
|
|
88
|
+
# @return [String] filename
|
|
89
|
+
def name
|
|
90
|
+
`#@native.name`
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
end
|
data/opal/browser/canvas/data.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Browser; class Canvas
|
|
2
2
|
|
|
3
3
|
class StyleObject
|
|
4
|
-
include Native
|
|
4
|
+
include Native::Wrapper
|
|
5
5
|
|
|
6
6
|
attr_reader :context
|
|
7
7
|
|
|
@@ -56,10 +56,12 @@ class Style < StyleObject
|
|
|
56
56
|
|
|
57
57
|
def smooth!
|
|
58
58
|
`#@native.mozImageSmoothingEnabled = #{@smooth = true}`
|
|
59
|
+
`#@native.imageSmoothingEnabled = #{@smooth = true}`
|
|
59
60
|
end
|
|
60
61
|
|
|
61
62
|
def no_smooth!
|
|
62
63
|
`#@native.mozImageSmoothingEnabled = #{@smooth = false}`
|
|
64
|
+
`#@native.imageSmoothingEnabled = #{@smooth = false}`
|
|
63
65
|
end
|
|
64
66
|
end
|
|
65
67
|
|