termgui 0.0.4 → 0.0.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/termgui.rb +1 -1
- metadata +40 -107
- data/Gemfile +0 -14
- data/README.md +0 -321
- data/src/action.rb +0 -58
- data/src/box.rb +0 -90
- data/src/color.rb +0 -174
- data/src/cursor.rb +0 -69
- data/src/editor/editor_base.rb +0 -152
- data/src/editor/editor_base_handlers.rb +0 -116
- data/src/element.rb +0 -61
- data/src/element_bounds.rb +0 -111
- data/src/element_box.rb +0 -64
- data/src/element_render.rb +0 -102
- data/src/element_style.rb +0 -51
- data/src/emitter.rb +0 -102
- data/src/emitter_state.rb +0 -19
- data/src/enterable.rb +0 -93
- data/src/event.rb +0 -92
- data/src/focus.rb +0 -102
- data/src/geometry.rb +0 -53
- data/src/image.rb +0 -60
- data/src/input.rb +0 -85
- data/src/input_grab.rb +0 -17
- data/src/input_time.rb +0 -97
- data/src/key.rb +0 -114
- data/src/log.rb +0 -24
- data/src/node.rb +0 -117
- data/src/node_attributes.rb +0 -27
- data/src/node_visit.rb +0 -52
- data/src/renderer.rb +0 -119
- data/src/renderer_cursor.rb +0 -18
- data/src/renderer_draw.rb +0 -28
- data/src/renderer_image.rb +0 -31
- data/src/renderer_print.rb +0 -40
- data/src/screen.rb +0 -96
- data/src/screen_element.rb +0 -59
- data/src/screen_input.rb +0 -43
- data/src/screen_renderer.rb +0 -53
- data/src/style.rb +0 -149
- data/src/tco/colouring.rb +0 -248
- data/src/tco/config.rb +0 -57
- data/src/tco/palette.rb +0 -603
- data/src/tco/tco_termgui.rb +0 -30
- data/src/termgui.rb +0 -29
- data/src/util.rb +0 -110
- data/src/util/css.rb +0 -98
- data/src/util/css_query.rb +0 -23
- data/src/util/easing.rb +0 -364
- data/src/util/hash_object.rb +0 -131
- data/src/util/imagemagick.rb +0 -27
- data/src/util/justify.rb +0 -20
- data/src/util/unicode-categories.rb +0 -572
- data/src/util/wrap.rb +0 -102
- data/src/widget/button.rb +0 -33
- data/src/widget/checkbox.rb +0 -47
- data/src/widget/col.rb +0 -30
- data/src/widget/image.rb +0 -106
- data/src/widget/inline.rb +0 -40
- data/src/widget/input_number.rb +0 -73
- data/src/widget/inputbox.rb +0 -85
- data/src/widget/label.rb +0 -33
- data/src/widget/modal.rb +0 -69
- data/src/widget/row.rb +0 -26
- data/src/widget/selectbox.rb +0 -100
- data/src/widget/textarea.rb +0 -54
- data/src/xml/xml.rb +0 -80
- data/test/action_test.rb +0 -34
- data/test/box_test.rb +0 -15
- data/test/css_test.rb +0 -39
- data/test/editor/editor_base_test.rb +0 -201
- data/test/element_bounds_test.rb +0 -77
- data/test/element_box_test.rb +0 -8
- data/test/element_render_test.rb +0 -124
- data/test/element_style_test.rb +0 -85
- data/test/element_test.rb +0 -10
- data/test/emitter_test.rb +0 -108
- data/test/event_test.rb +0 -19
- data/test/focus_test.rb +0 -37
- data/test/geometry_test.rb +0 -12
- data/test/input_test.rb +0 -47
- data/test/key_test.rb +0 -14
- data/test/log_test.rb +0 -21
- data/test/node_test.rb +0 -105
- data/test/performance/performance1.rb +0 -48
- data/test/renderer_test.rb +0 -74
- data/test/renderer_test_rect.rb +0 -4
- data/test/screen_test.rb +0 -58
- data/test/style_test.rb +0 -18
- data/test/termgui_test.rb +0 -10
- data/test/test_all.rb +0 -30
- data/test/util_hash_object_test.rb +0 -93
- data/test/util_test.rb +0 -26
- data/test/widget/checkbox_test.rb +0 -99
- data/test/widget/col_test.rb +0 -87
- data/test/widget/inline_test.rb +0 -40
- data/test/widget/label_test.rb +0 -94
- data/test/widget/row_test.rb +0 -40
- data/test/wrap_test.rb +0 -11
- data/test/xml_test.rb +0 -77
data/src/tco/tco_termgui.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
require_relative 'colouring'
|
2
|
-
require_relative 'config'
|
3
|
-
|
4
|
-
module TermGui
|
5
|
-
@colouring_config = Tco::Config.new
|
6
|
-
@colouring = Tco::Colouring.new @colouring_config
|
7
|
-
|
8
|
-
def self.open_style(style, colouring = @colouring)
|
9
|
-
s = colouring.decorate('__', style)
|
10
|
-
s = s.slice(0, s.length - 4 - 2)
|
11
|
-
s
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.close_style(_colouring = @colouring)
|
15
|
-
@colouring.decorate('', TermGui::Style.new(fg: 'red', bg: 'red', bold: true, underline: true))
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.print(s, style)
|
19
|
-
@colouring.decorate(s, style)
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.fast_colouring(value)
|
23
|
-
Tco::Colour.fast = value
|
24
|
-
@colouring.palette.reset_cache
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.to_rgb(value)
|
28
|
-
@colouring.get_colour_instance(value).rgb
|
29
|
-
end
|
30
|
-
end
|
data/src/termgui.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
require_relative 'emitter'
|
2
|
-
require_relative 'event'
|
3
|
-
require_relative 'input'
|
4
|
-
require_relative 'node'
|
5
|
-
require_relative 'renderer'
|
6
|
-
require_relative 'style'
|
7
|
-
require_relative 'screen'
|
8
|
-
require_relative 'tco/tco_termgui'
|
9
|
-
require_relative 'element'
|
10
|
-
require_relative 'focus'
|
11
|
-
require_relative 'image'
|
12
|
-
require_relative 'action'
|
13
|
-
require_relative 'cursor'
|
14
|
-
require_relative 'enterable'
|
15
|
-
require_relative 'geometry'
|
16
|
-
require_relative 'util/css'
|
17
|
-
require_relative 'widget/button'
|
18
|
-
require_relative 'widget/col'
|
19
|
-
require_relative 'widget/inputbox'
|
20
|
-
require_relative 'widget/image'
|
21
|
-
require_relative 'widget/inline'
|
22
|
-
require_relative 'widget/checkbox'
|
23
|
-
require_relative 'widget/selectbox'
|
24
|
-
require_relative 'widget/input_number'
|
25
|
-
require_relative 'widget/label'
|
26
|
-
require_relative 'widget/modal'
|
27
|
-
require_relative 'widget/row'
|
28
|
-
require_relative 'editor/editor_base_handlers'
|
29
|
-
require_relative 'editor/editor_base'
|
data/src/util.rb
DELETED
@@ -1,110 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
def json_parse(str)
|
4
|
-
JSON.parse(str)
|
5
|
-
end
|
6
|
-
|
7
|
-
def json_stringify(obj)
|
8
|
-
JSON.generate(obj)
|
9
|
-
end
|
10
|
-
|
11
|
-
# TODO: why is it so hard in ruby to access an outer local variable from a method ? I needed to create a
|
12
|
-
# module and a wrapper for somethig very trivial
|
13
|
-
|
14
|
-
module Util
|
15
|
-
@uc = 0
|
16
|
-
def self.unique(s = '')
|
17
|
-
@uc += 1
|
18
|
-
s + @uc.to_s
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def to_array(v)
|
23
|
-
v.is_a?(Array) ? v : [v]
|
24
|
-
end
|
25
|
-
|
26
|
-
def unique(s = '')
|
27
|
-
Util.unique(s)
|
28
|
-
end
|
29
|
-
|
30
|
-
# TODO: hack because \n chars are not printed with puts or print:
|
31
|
-
def print_string(str)
|
32
|
-
str.split('\n').map { |s| puts s || '' }
|
33
|
-
end
|
34
|
-
|
35
|
-
def print_ms(t0)
|
36
|
-
"#{((Time.now - t0) * 1000).to_i} ms"
|
37
|
-
end
|
38
|
-
|
39
|
-
def parse_integer(s, default = nil)
|
40
|
-
Integer(s)
|
41
|
-
rescue StandardError
|
42
|
-
default
|
43
|
-
end
|
44
|
-
|
45
|
-
def parse_float(s, default = nil)
|
46
|
-
Float(s)
|
47
|
-
rescue StandardError
|
48
|
-
default
|
49
|
-
end
|
50
|
-
|
51
|
-
# returns true if given value is between 0.0 and 1.0
|
52
|
-
def is_percent(val)
|
53
|
-
val && val > 0 && val < 1
|
54
|
-
end
|
55
|
-
|
56
|
-
def unquote(s)
|
57
|
-
s[1..s.length - 1]
|
58
|
-
end
|
59
|
-
|
60
|
-
def next_tick
|
61
|
-
sleep 0.0000001
|
62
|
-
end
|
63
|
-
|
64
|
-
def random_int(min = 0, max = 10)
|
65
|
-
(min..max).to_a.sample
|
66
|
-
end
|
67
|
-
|
68
|
-
def random_float(min = 0.0, max = 1.0)
|
69
|
-
rand * (max - min) + min
|
70
|
-
end
|
71
|
-
|
72
|
-
CHARS = ('a'..'z').to_a.concat(('A'..'Z').to_a).push('_', '-', '@', '!', '#', '$', '%', '^', '&', '*', '=', '+')
|
73
|
-
|
74
|
-
def random_char
|
75
|
-
CHARS.sample
|
76
|
-
end
|
77
|
-
|
78
|
-
def random_color
|
79
|
-
[random_int(0, 255), random_int(0, 255), random_int(0, 255)]
|
80
|
-
end
|
81
|
-
|
82
|
-
# similar to JS Array.prototype.some
|
83
|
-
def some(array, predicate)
|
84
|
-
i = 0
|
85
|
-
value = nil
|
86
|
-
while i < array.length
|
87
|
-
e = array[i]
|
88
|
-
value = predicate.call e
|
89
|
-
if value
|
90
|
-
value = array[i]
|
91
|
-
break
|
92
|
-
else
|
93
|
-
value = nil
|
94
|
-
end
|
95
|
-
i += 1
|
96
|
-
end
|
97
|
-
value
|
98
|
-
end
|
99
|
-
|
100
|
-
# TODO: this is the same as event.rb Event. Move Event classes to individual - non dependency file
|
101
|
-
module TermGui
|
102
|
-
class Event
|
103
|
-
# @return {String}
|
104
|
-
attr_reader :name
|
105
|
-
# @param {String} name
|
106
|
-
def initialize(name)
|
107
|
-
@name = name
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
data/src/util/css.rb
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
# css like language parser
|
2
|
-
# TODO: move this to its own project
|
3
|
-
|
4
|
-
module TermGui
|
5
|
-
# given a string like `foo {bg: red; padding-top: 3} .bar .primary {}`
|
6
|
-
# Rules:
|
7
|
-
# * values cannot contain any of the following chars: `:;{}`
|
8
|
-
# * No inmediate children ('>') supported. Example, `a b` is supported. `a>b` is not supported.
|
9
|
-
class CSSParser
|
10
|
-
def parse(code)
|
11
|
-
rules = parse_rules code
|
12
|
-
rules = parse_rules_properties rules
|
13
|
-
rules = parse_rules_selectors rules
|
14
|
-
rules
|
15
|
-
end
|
16
|
-
|
17
|
-
def parse_rules(code)
|
18
|
-
code.split('}').map do |rule|
|
19
|
-
a = rule.split('{')
|
20
|
-
throw "Syntax error in rule '#{rule}'" if a.length != 2
|
21
|
-
{
|
22
|
-
selector: a[0].strip,
|
23
|
-
body: a[1].strip
|
24
|
-
}
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
# given rules are the output of `parse_rules`. It will return a similar object but for each rule, instead `body` string have name-value `properies`
|
29
|
-
def parse_rules_properties(rules)
|
30
|
-
rules.map do |rule|
|
31
|
-
properties = rule[:body].split(';').map(&:strip)
|
32
|
-
properties = properties.map do |property|
|
33
|
-
a = property.split(':').map(&:strip)
|
34
|
-
throw "Syntax error in property '#{property}', rule: '#{rule}'" if a.length != 2
|
35
|
-
{
|
36
|
-
name: a[0],
|
37
|
-
value: a[1]
|
38
|
-
}
|
39
|
-
end
|
40
|
-
{
|
41
|
-
selector: rule[:selector],
|
42
|
-
properties: properties
|
43
|
-
}
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
# given rules are the output of `parse_rules_properties`, it returns a similar object but for each rule, instead `selector` string have
|
48
|
-
# a parsed selector object: `Array<Array<{name: string, operator: nil|'>'|' '}>>`
|
49
|
-
def parse_rules_selectors(rules)
|
50
|
-
rules.map do |rule|
|
51
|
-
selectors = rule[:selector].split(',').map(&:strip)
|
52
|
-
selectors = selectors.map do |s|
|
53
|
-
parse_selector s
|
54
|
-
end
|
55
|
-
{
|
56
|
-
selectors: selectors,
|
57
|
-
properies: rule[:properties]
|
58
|
-
}
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
# independent method to parse string selectors like 'a>b c' to `Array<{name: string, operator: nil|'>'|' '}>`
|
63
|
-
def parse_selector(s)
|
64
|
-
a = s.split(/([\s>])/)
|
65
|
-
i = 0
|
66
|
-
results = []
|
67
|
-
while i < a.length
|
68
|
-
results.push(name: a[i], operator: a[i + 1])
|
69
|
-
i += 2
|
70
|
-
end
|
71
|
-
results = results.reject { |result| result[:name].strip == '' }
|
72
|
-
results
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
CSSParser = TermGui::CSSParser
|
78
|
-
|
79
|
-
# p = CSSParser.new
|
80
|
-
# # p.parse('foo {bg: red; padding-top: 3} .bar .primary {border: double black}; .sidebar .container { padding: 1}')
|
81
|
-
# s = 'a> b c>d f'
|
82
|
-
# p CSSParser.new.parse_selector 'a> b c>d f'
|
83
|
-
# a = s.split(/([\s>])/) # .select{|s|s.strip!=''}
|
84
|
-
# p a
|
85
|
-
# i = 0
|
86
|
-
# results = []
|
87
|
-
# while i < a.length
|
88
|
-
# results.push(name: a[i], operator: a[i + 1])
|
89
|
-
# i += 2
|
90
|
-
# end
|
91
|
-
# results = results.reject { |result| result[:name].strip == '' }
|
92
|
-
# p results
|
93
|
-
|
94
|
-
# parser = CSSParser.new
|
95
|
-
# expected = '[{:selector=>"foo", :properties=>[{:name=>"bg", :value=>"red"}, {:name=>"padding-top", :value=>"3"}]}, {:selector=>".bar .primary", :properties=>[{:name=>"border", :value=>"double black"}]}, {:selector=>"; .sidebar .container", :properties=>[{:name=>"padding", :value=>"1"}]}]'
|
96
|
-
# rules = parser.parse_rules_properties(parser.parse_rules('foo {bg: red; padding-top: 3} .bar .primary {border: double black}; .sidebar .container { padding: 1}'))
|
97
|
-
# actual = parser.parse_rules_selectors(rules)
|
98
|
-
# p actual
|
data/src/util/css_query.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# will select descendants from given `root` Node that matches given string selector (like `a>.b c`).
|
2
|
-
# The semantic mapping between ' ' and '>' "operators" and Node attributes can be overriden by subclassing
|
3
|
-
module NodeSelector
|
4
|
-
# def initialize
|
5
|
-
# @parser = CSSParser.new
|
6
|
-
# end
|
7
|
-
def css(root, selector)
|
8
|
-
@parser |= CSSParser.new
|
9
|
-
parsed = @parser.parse_selector(selector)
|
10
|
-
results = []
|
11
|
-
css_impl([root], parsed, results)
|
12
|
-
end
|
13
|
-
|
14
|
-
protected
|
15
|
-
|
16
|
-
# actual recursive css() implementation. each recursion will consume the first parsed passing the rest to the next call.
|
17
|
-
# roots will be also updated accordingly to current matches.
|
18
|
-
# The recursion condition is meet when parsed.length==1 (the last match step) which will return total matched elements
|
19
|
-
# flatten storing it on given imput result argument.
|
20
|
-
def css_impl(_roots, _parsed)
|
21
|
-
throw 'TODO'
|
22
|
-
end
|
23
|
-
end
|
data/src/util/easing.rb
DELETED
@@ -1,364 +0,0 @@
|
|
1
|
-
# module TermGui
|
2
|
-
# module Easing
|
3
|
-
# def self.animate(
|
4
|
-
# duration: 1000,
|
5
|
-
# draw: nil, # (n: number) => void
|
6
|
-
# timing: nil, # (n: number, c?: number, d?: number, x?: number, y?: number) => number
|
7
|
-
# lapse: 0.1
|
8
|
-
# )
|
9
|
-
# end
|
10
|
-
# end
|
11
|
-
# end
|
12
|
-
|
13
|
-
# # import { isObject } from 'misc-utils-of-mine-generic'
|
14
|
-
|
15
|
-
# # type Timing = (n: number, c?: number, d?: number, x?: number, y?: number) => number
|
16
|
-
# # type TimingObject = { fn: (duration: number) => Timing }
|
17
|
-
# # export function animate({ duration, draw, timing, lapse }: {
|
18
|
-
# # duration: number
|
19
|
-
# # draw: (n: number) => void
|
20
|
-
# # timing: Timing | TimingObject
|
21
|
-
# # lapse?: number
|
22
|
-
# # }) {
|
23
|
-
# # if (isObject(timing)) {
|
24
|
-
# # timing = (timing as any).fn(duration)
|
25
|
-
# # }
|
26
|
-
# # let start = Date.now()
|
27
|
-
# # let progress = 0
|
28
|
-
# # requestAnimationFrame(function anim(time) {
|
29
|
-
# # let timeFraction = (time - start) / duration
|
30
|
-
# # if (timeFraction > 1) timeFraction = 1
|
31
|
-
# # progress = (timing as Timing)(timeFraction, time - start, duration)
|
32
|
-
# # draw(progress)
|
33
|
-
# # if (timeFraction < 1) {
|
34
|
-
# # requestAnimationFrame(anim, lapse)
|
35
|
-
# # }
|
36
|
-
# # })
|
37
|
-
# # }
|
38
|
-
|
39
|
-
# # function requestAnimationFrame(f: (...args: any[]) => any, lapse = 0) {
|
40
|
-
# # setTimeout(() => f(Date.now()), lapse)
|
41
|
-
# # }
|
42
|
-
|
43
|
-
# # export namespace easing {
|
44
|
-
# # function makeEaseOut(timing: Timing) {
|
45
|
-
# # return function(timeFraction: any) {
|
46
|
-
# # return 1 - timing(1 - timeFraction)
|
47
|
-
# # }
|
48
|
-
# # }
|
49
|
-
|
50
|
-
# # function bounceFn(timeFraction: number) {
|
51
|
-
# # for (let a = 0, b = 1, result; 1; a += b, b /= 2) {
|
52
|
-
# # if (timeFraction >= (7 - 4 * a) / 11) {
|
53
|
-
# # return -Math.pow((11 - 6 * a - 11 * timeFraction) / 4, 2) + Math.pow(b, 2)
|
54
|
-
# # }
|
55
|
-
# # }
|
56
|
-
# # }
|
57
|
-
|
58
|
-
# # /** Imagine we are dropping a ball. It falls down, then bounces back a few times and stops. The bounce function does the same, but in the reverse order: “bouncing” starts immediately. */
|
59
|
-
# # export const bounceEasyOut: () => Timing = () => makeEaseOut(bounceFn as any)
|
60
|
-
|
61
|
-
# # /** parabolic curve */
|
62
|
-
# # export function quad(timeFraction: number) {
|
63
|
-
# # return Math.pow(timeFraction, 2)
|
64
|
-
# # }
|
65
|
-
# # // export const swing = t => 0.5 - Math.cos(t * Math.PI) / 2
|
66
|
-
|
67
|
-
# # /**
|
68
|
-
# # * “bow shooting”. First we “pull the bowstring”, and then “shoot”.
|
69
|
-
# # * @param x “elasticity coefficient”. The distance of “bowstring pulling” is defined by it. Default value 1.5.
|
70
|
-
# # */
|
71
|
-
# # export const back = (x = 1.5) => (timeFraction: number) => Math.pow(timeFraction, 2) * ((x + 1) * timeFraction - x)
|
72
|
-
# # /**
|
73
|
-
# # * @param x “initial range”
|
74
|
-
# # */
|
75
|
-
# # export const elastic = (x = 1.5) => (timeFraction: number) =>
|
76
|
-
# # Math.pow(2, 10 * (timeFraction - 1)) * Math.cos(((20 * Math.PI * x) / 3) * timeFraction)
|
77
|
-
|
78
|
-
# # function makeEaseInOut(timing: Timing) {
|
79
|
-
# # return function(timeFraction: number) {
|
80
|
-
# # if (timeFraction < 0.5) return timing(2 * timeFraction) / 2
|
81
|
-
# # else return (2 - timing(2 * (1 - timeFraction))) / 2
|
82
|
-
# # }
|
83
|
-
# # }
|
84
|
-
|
85
|
-
# # export const bounceEaseInOut: () => Timing = () => makeEaseInOut(bounceFn as any)
|
86
|
-
|
87
|
-
# # let c = 1,
|
88
|
-
# # b = 0
|
89
|
-
# # export const easeInQuad: () => Timing = () =>
|
90
|
-
# # ({ fn: (d: number) => (x: number, t: number) => c * (t /= d) * t + b } as any)
|
91
|
-
|
92
|
-
# # export const easeOutQuad: () => Timing = () =>
|
93
|
-
# # ({ fn: (d: number) => (x: number, t: number) => -c * (t /= d) * (t - 2) + b } as any)
|
94
|
-
# # export const easeInOutQuad: () => Timing = () =>
|
95
|
-
# # ({
|
96
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
97
|
-
# # if ((t /= d / 2) < 1) return (c / 2) * t * t + b
|
98
|
-
# # return (-c / 2) * (--t * (t - 2) - 1) + b
|
99
|
-
# # }
|
100
|
-
# # } as any)
|
101
|
-
# # export const easeInElastic: () => Timing = () =>
|
102
|
-
# # ({
|
103
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
104
|
-
# # let s = 1.70158
|
105
|
-
# # let p = 0
|
106
|
-
# # let a = c
|
107
|
-
# # if (t == 0) return b
|
108
|
-
# # if ((t /= d) == 1) return b + c
|
109
|
-
# # if (!p) p = d * 0.3
|
110
|
-
# # if (a < Math.abs(c)) {
|
111
|
-
# # a = c
|
112
|
-
# # let s = p / 4
|
113
|
-
# # } else {
|
114
|
-
# # s = (p / (2 * Math.PI)) * Math.asin(c / a)
|
115
|
-
# # }
|
116
|
-
# # return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin(((t * d - s) * (2 * Math.PI)) / p)) + b
|
117
|
-
# # }
|
118
|
-
# # } as any)
|
119
|
-
|
120
|
-
# # export const easeOutBounce: () => TimingObject = () =>
|
121
|
-
# # ({
|
122
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
123
|
-
# # if ((t /= d) < 1 / 2.75) {
|
124
|
-
# # return c * (7.5625 * t * t) + b
|
125
|
-
# # } else if (t < 2 / 2.75) {
|
126
|
-
# # return c * (7.5625 * (t -= 1.5 / 2.75) * t + 0.75) + b
|
127
|
-
# # } else if (t < 2.5 / 2.75) {
|
128
|
-
# # return c * (7.5625 * (t -= 2.25 / 2.75) * t + 0.9375) + b
|
129
|
-
# # } else {
|
130
|
-
# # return c * (7.5625 * (t -= 2.625 / 2.75) * t + 0.984375) + b
|
131
|
-
# # }
|
132
|
-
# # }
|
133
|
-
# # } as any)
|
134
|
-
|
135
|
-
# # export const easeInCubic: () => Timing = () =>
|
136
|
-
# # ({
|
137
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
138
|
-
# # return c * (t /= d) * t * t + b
|
139
|
-
# # }
|
140
|
-
# # } as any)
|
141
|
-
|
142
|
-
# # export const easeOutCubic: () => Timing = () =>
|
143
|
-
# # ({
|
144
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
145
|
-
# # return c * ((t = t / d - 1) * t * t + 1) + b
|
146
|
-
# # }
|
147
|
-
# # } as any)
|
148
|
-
|
149
|
-
# # export const easeInOutCubic: () => Timing = () =>
|
150
|
-
# # ({
|
151
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
152
|
-
# # if ((t /= d / 2) < 1) return (c / 2) * t * t * t + b
|
153
|
-
# # return (c / 2) * ((t -= 2) * t * t + 2) + b
|
154
|
-
# # }
|
155
|
-
# # } as any)
|
156
|
-
|
157
|
-
# # export const easeInQuart: Timing = () =>
|
158
|
-
# # ({
|
159
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
160
|
-
# # return c * (t /= d) * t * t * t + b
|
161
|
-
# # }
|
162
|
-
# # } as any)
|
163
|
-
|
164
|
-
# # export const easeInOutQuart: Timing = () =>
|
165
|
-
# # ({
|
166
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
167
|
-
# # if ((t /= d / 2) < 1) return (c / 2) * t * t * t * t + b
|
168
|
-
# # return (-c / 2) * ((t -= 2) * t * t * t - 2) + b
|
169
|
-
# # }
|
170
|
-
# # } as any)
|
171
|
-
|
172
|
-
# # export const easeInQuint: Timing = () =>
|
173
|
-
# # ({
|
174
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
175
|
-
# # return c * (t /= d) * t * t * t * t + b
|
176
|
-
# # }
|
177
|
-
# # } as any)
|
178
|
-
|
179
|
-
# # export const easeOutQuint: () => Timing = () =>
|
180
|
-
# # ({
|
181
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
182
|
-
# # return c * ((t = t / d - 1) * t * t * t * t + 1) + b
|
183
|
-
# # }
|
184
|
-
# # } as any)
|
185
|
-
|
186
|
-
# # export const easeInExpo: () => Timing = () =>
|
187
|
-
# # ({
|
188
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
189
|
-
# # return t == 0 ? b : c * Math.pow(2, 10 * (t / d - 1)) + b
|
190
|
-
# # }
|
191
|
-
# # } as any)
|
192
|
-
|
193
|
-
# # export const easeInOutQuint: () => Timing = () =>
|
194
|
-
# # ({
|
195
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
196
|
-
# # if ((t /= d / 2) < 1) return (c / 2) * t * t * t * t * t + b
|
197
|
-
# # return (c / 2) * ((t -= 2) * t * t * t * t + 2) + b
|
198
|
-
# # }
|
199
|
-
# # } as any)
|
200
|
-
|
201
|
-
# # export const easeInSine: () => Timing = () =>
|
202
|
-
# # ({
|
203
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
204
|
-
# # return -c * Math.cos((t / d) * (Math.PI / 2)) + c + b
|
205
|
-
# # }
|
206
|
-
# # } as any)
|
207
|
-
# # export const easeInOutElastic: () => Timing = () =>
|
208
|
-
# # ({
|
209
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
210
|
-
# # let s = 1.70158
|
211
|
-
# # let p = 0
|
212
|
-
# # let a = c
|
213
|
-
# # if (t == 0) return b
|
214
|
-
# # if ((t /= d / 2) == 2) return b + c
|
215
|
-
# # if (!p) p = d * (0.3 * 1.5)
|
216
|
-
# # if (a < Math.abs(c)) {
|
217
|
-
# # a = c
|
218
|
-
# # let s = p / 4
|
219
|
-
# # } else {
|
220
|
-
# # s = (p / (2 * Math.PI)) * Math.asin(c / a)
|
221
|
-
# # }
|
222
|
-
# # if (t < 1) return -0.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin(((t * d - s) * (2 * Math.PI)) / p)) + b
|
223
|
-
# # return a * Math.pow(2, -10 * (t -= 1)) * Math.sin(((t * d - s) * (2 * Math.PI)) / p) * 0.5 + c + b
|
224
|
-
# # }
|
225
|
-
# # } as any)
|
226
|
-
|
227
|
-
# # export const easeOutElastic: () => Timing = () =>
|
228
|
-
# # ({
|
229
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
230
|
-
# # let s = 1.70158
|
231
|
-
# # let p = 0
|
232
|
-
# # let a = c
|
233
|
-
# # if (t == 0) return b
|
234
|
-
# # if ((t /= d) == 1) return b + c
|
235
|
-
# # if (!p) p = d * 0.3
|
236
|
-
# # if (a < Math.abs(c)) {
|
237
|
-
# # a = c
|
238
|
-
# # let s = p / 4
|
239
|
-
# # } else {
|
240
|
-
# # s = (p / (2 * Math.PI)) * Math.asin(c / a)
|
241
|
-
# # }
|
242
|
-
# # return a * Math.pow(2, -10 * t) * Math.sin(((t * d - s) * (2 * Math.PI)) / p) + c + b
|
243
|
-
# # }
|
244
|
-
# # } as any)
|
245
|
-
# # export const easeInOutExpo: () => Timing = () =>
|
246
|
-
# # ({
|
247
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
248
|
-
# # if (t == 0) return b
|
249
|
-
# # if (t == d) return b + c
|
250
|
-
# # if ((t /= d / 2) < 1) return (c / 2) * Math.pow(2, 10 * (t - 1)) + b
|
251
|
-
# # return (c / 2) * (-Math.pow(2, -10 * --t) + 2) + b
|
252
|
-
# # }
|
253
|
-
# # } as any)
|
254
|
-
|
255
|
-
# # export const easeInOutBack: () => Timing = () =>
|
256
|
-
# # ({
|
257
|
-
# # fn: (d: number) => (x: number, t: number) => {
|
258
|
-
# # let s = 1.70158
|
259
|
-
# # if ((t /= d / 2) < 1) return (c / 2) * (t * t * (((s *= 1.525) + 1) * t - s)) + b
|
260
|
-
# # return (c / 2) * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b
|
261
|
-
# # }
|
262
|
-
# # } as any)
|
263
|
-
|
264
|
-
# # export const easeOutBack: () => Timing = () =>
|
265
|
-
# # ({
|
266
|
-
# # fn: (d: number) => (x: number, t: number, d: number) => {
|
267
|
-
# # let s = 1.70158
|
268
|
-
# # return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b
|
269
|
-
# # }
|
270
|
-
# # } as any)
|
271
|
-
|
272
|
-
# # export const easeInBounce: () => TimingObject = () =>
|
273
|
-
# # ({
|
274
|
-
# # fn: (d: number) => (x: number, t: number, d: number) => {
|
275
|
-
# # return c - easeOutBounce().fn(d)(x, d - t, 0, c, d) + b
|
276
|
-
# # }
|
277
|
-
# # } as any)
|
278
|
-
|
279
|
-
# # export const easeInOutBounce: () => Timing = () =>
|
280
|
-
# # ({
|
281
|
-
# # fn: (d: number) => (x: number, t: number, d: number) => {
|
282
|
-
# # if (t < d / 2) return easeInBounce().fn(d)(x, t * 2, 0, c, d) * 0.5 + b
|
283
|
-
# # return easeOutBounce().fn(d)(x, t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b
|
284
|
-
# # }
|
285
|
-
# # } as any)
|
286
|
-
# # }
|
287
|
-
|
288
|
-
# # // animate({
|
289
|
-
# # // duration: 2000,
|
290
|
-
# # // timing: easeInQuad(),
|
291
|
-
# # // lapse: 20,
|
292
|
-
# # // draw(progress) {
|
293
|
-
# # // console.log(progress * 100 + '%');
|
294
|
-
# # // }
|
295
|
-
# # // });
|
296
|
-
|
297
|
-
# # // TODO:
|
298
|
-
# # // easeInOutSine: function (x, t, b, c, d) {
|
299
|
-
# # // return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
|
300
|
-
# # // },
|
301
|
-
# # // easeOutExpo: function (x, t, b, c, d) {
|
302
|
-
# # // return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
|
303
|
-
# # // },
|
304
|
-
# # // easeInCirc: function (x, t, b, c, d) {
|
305
|
-
# # // return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
|
306
|
-
# # // },
|
307
|
-
# # // easeOutCirc: function (x, t, b, c, d) {
|
308
|
-
# # // return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
|
309
|
-
# # // },
|
310
|
-
# # // easeInOutCirc: function (x, t, b, c, d) {
|
311
|
-
# # // if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
|
312
|
-
# # // return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
|
313
|
-
# # // },
|
314
|
-
# # // easeInBack: function (x, t, b, c, d, s) {
|
315
|
-
# # // if (s == undefined) s = 1.70158;
|
316
|
-
# # // return c*(t/=d)*t*((s+1)*t - s) + b;
|
317
|
-
# # // },
|
318
|
-
# # // easeInBounce: function (x, t, b, c, d) {
|
319
|
-
# # // return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b;
|
320
|
-
# # // },
|
321
|
-
# # // easeInOutBounce: function (x, t, b, c, d) {
|
322
|
-
# # // if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b;
|
323
|
-
# # // return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b;
|
324
|
-
# # // }
|
325
|
-
|
326
|
-
# # // animate({
|
327
|
-
# # // duration: 1000,
|
328
|
-
# # // timing(timeFraction) {
|
329
|
-
# # // return timeFraction;
|
330
|
-
# # // },
|
331
|
-
# # // draw(progress) {
|
332
|
-
# # // console.log(progress * 100 + '%');
|
333
|
-
|
334
|
-
# # // }
|
335
|
-
# # // });
|
336
|
-
|
337
|
-
# # // setImmediate((t)=>{
|
338
|
-
# # // console.log(t);
|
339
|
-
|
340
|
-
# # // })
|
341
|
-
|
342
|
-
# # // function requestAnimationFrame(f){
|
343
|
-
# # // setImmediate(()=>f(Date.now()))
|
344
|
-
# # // }
|
345
|
-
|
346
|
-
# # // function animate({duration, draw, timing}) {
|
347
|
-
|
348
|
-
# # // let start = performance.now();
|
349
|
-
|
350
|
-
# # // requestAnimationFrame(function animate(time) {
|
351
|
-
# # // let timeFraction = (time - start) / duration;
|
352
|
-
# # // if (timeFraction > 1) timeFraction = 1;
|
353
|
-
|
354
|
-
# # // let progress = timing(timeFraction)
|
355
|
-
|
356
|
-
# # // draw(progress);
|
357
|
-
|
358
|
-
# # // if (timeFraction < 1) {
|
359
|
-
# # // requestAnimationFrame(animate);
|
360
|
-
# # // }
|
361
|
-
|
362
|
-
# # // });
|
363
|
-
# # // }
|
364
|
-
# # // The code for it:
|