Skip to content

Commit

Permalink
$mol_view_tree2 generics, mol refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkalica committed Nov 18, 2023
1 parent 4a9afb8 commit 6831b8f
Show file tree
Hide file tree
Showing 20 changed files with 104 additions and 86 deletions.
2 changes: 1 addition & 1 deletion audio/demo/vibe/vibe.web.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $mol_audio_demo_vibe $mol_example_small
Filter null
value? <=> shape? null
options /$mol_audio_vibe_shape
\sine
\sine
\square
\sawtooth
\triangle
Expand Down
2 changes: 1 addition & 1 deletion drag/drag.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace $.$$ {

const transfer = this.transfer()
for( let type in transfer ) {
event.dataTransfer!.setData( type , transfer[ type ] )
event.dataTransfer!.setData( type , transfer[ type as keyof typeof transfer] )
}

event.dataTransfer!.setDragImage( this.image() , 0 , -32 )
Expand Down
8 changes: 4 additions & 4 deletions map/yandex/mark/mark.view.tree
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
$mol_map_yandex_mark $mol_object
pos $mol_vector_2d /
pos $mol_vector_2d<number> /
0
0
box $mol_vector_2d /
<= box_lat $mol_vector_range /
box $mol_vector_2d<$mol_vector_range<number>> /
<= box_lat $mol_vector_range<number> /
0
0
<= box_lon $mol_vector_range /
<= box_lon $mol_vector_range<number> /
0
0
hint \
Expand Down
28 changes: 14 additions & 14 deletions plot/graph/graph.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ $mol_plot_graph $mol_svg_group
^
color <= color \
-
viewport $mol_vector_2d /
<= viewport_x $mol_vector_range /
viewport $mol_vector_2d<$mol_vector_range<number>> /
<= viewport_x $mol_vector_range<number> /
Infinity
-Infinity
<= viewport_y $mol_vector_range /
<= viewport_y $mol_vector_range<number> /
Infinity
-Infinity
shift /number
Expand All @@ -23,31 +23,31 @@ $mol_plot_graph $mol_svg_group
scale /number
1
1
cursor_position $mol_vector_2d /
cursor_position $mol_vector_2d<number> /
NaN
NaN
dimensions_pane $mol_vector_2d /
<= dimensions_pane_x $mol_vector_range /
dimensions_pane $mol_vector_2d<$mol_vector_range<number>> /
<= dimensions_pane_x $mol_vector_range<number> /
Infinity
-Infinity
<= dimensions_pane_y $mol_vector_range /
<= dimensions_pane_y $mol_vector_range<number> /
Infinity
-Infinity
dimensions $mol_vector_2d /
<= dimensions_x $mol_vector_range /
dimensions $mol_vector_2d<$mol_vector_range<number>> /
<= dimensions_x $mol_vector_range<number> /
Infinity
-Infinity
<= dimensions_y $mol_vector_range /
<= dimensions_y $mol_vector_range<number> /
Infinity
-Infinity
size_real $mol_vector_2d /
size_real $mol_vector_2d<number> /
0
0
gap $mol_vector_2d /
<= gap_x $mol_vector_range /
gap $mol_vector_2d<$mol_vector_range<number>> /
<= gap_x $mol_vector_range<number> /
0
0
<= gap_y $mol_vector_range /
<= gap_y $mol_vector_range<number> /
0
0
repos_x* 0
Expand Down
6 changes: 3 additions & 3 deletions plot/mark/cross/cross.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ $mol_plot_mark_cross $mol_plot_graph
title_y_gap 22
threshold 16
graphs /$mol_plot_graph
dimensions $mol_vector_2d /
<= dimensions_x $mol_vector_range /
dimensions $mol_vector_2d<$mol_vector_range<number>> /
<= dimensions_x $mol_vector_range<number> /
Infinity
-Infinity
<= dimensions_y $mol_vector_range /
<= dimensions_y $mol_vector_range<number> /
Infinity
-Infinity
sub /
Expand Down
42 changes: 21 additions & 21 deletions plot/pane/pane.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -10,60 +10,60 @@ $mol_plot_pane $mol_svg_root
gap_right <= gap_hor
gap_top <= gap_vert
gap_bottom <= gap_vert
gap $mol_vector_2d /
<= gap_x $mol_vector_range /
gap $mol_vector_2d<$mol_vector_range<number>> /
<= gap_x $mol_vector_range<number> /
<= gap_left
<= gap_right
<= gap_y $mol_vector_range /
<= gap_y $mol_vector_range<number> /
<= gap_bottom
<= gap_top
-
shift_limit $mol_vector_2d /
<= shift_limit_x $mol_vector_range /
shift_limit $mol_vector_2d<$mol_vector_range<number>> /
<= shift_limit_x $mol_vector_range<number> /
0
0
<= shift_limit_y $mol_vector_range /
<= shift_limit_y $mol_vector_range<number> /
0
0
shift_default $mol_vector_2d /
shift_default $mol_vector_2d<number> /
0
0
shift? $mol_vector_2d /
shift? $mol_vector_2d<number> /
0
0
scale_limit $mol_vector_2d /
<= scale_limit_x $mol_vector_range /
scale_limit $mol_vector_2d<$mol_vector_range<number>> /
<= scale_limit_x $mol_vector_range<number> /
0
Infinity
<= scale_limit_y $mol_vector_range /
<= scale_limit_y $mol_vector_range<number> /
0
-Infinity
scale_default $mol_vector_2d /
scale_default $mol_vector_2d<number> /
0
0
scale? $mol_vector_2d /
scale? $mol_vector_2d<number> /
1
-1
scale_x? 1
scale_y? -1
size $mol_vector_2d /
size $mol_vector_2d<number> /
0
0
size_real $mol_vector_2d /
size_real $mol_vector_2d<number> /
1
1
dimensions $mol_vector_2d /
<= dimensions_x $mol_vector_range /
dimensions $mol_vector_2d<$mol_vector_range<number>> /
<= dimensions_x $mol_vector_range<number> /
Infinity
-Infinity
<= dimensions_y $mol_vector_range /
<= dimensions_y $mol_vector_range<number> /
Infinity
-Infinity
dimensions_viewport $mol_vector_2d /
<= dimensions_viewport_x $mol_vector_range /
dimensions_viewport $mol_vector_2d<$mol_vector_range<number>> /
<= dimensions_viewport_x $mol_vector_range<number> /
Infinity
-Infinity
<= dimensions_viewport_y $mol_vector_range /
<= dimensions_viewport_y $mol_vector_range<number> /
Infinity
-Infinity
-
Expand Down
4 changes: 2 additions & 2 deletions plot/ruler/ruler.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ $mol_plot_ruler $mol_plot_graph
scale_axis 1
scale_step 1
shift_axis 1
dimensions_axis $mol_vector_range /
dimensions_axis $mol_vector_range<number> /
Infinity
-Infinity
viewport_axis $mol_vector_range /
viewport_axis $mol_vector_range<number> /
Infinity
-Infinity
axis_points /number
Expand Down
2 changes: 1 addition & 1 deletion select/list/demo/demo.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $mol_select_list_demo $mol_example_small
rows /
<= Friends $mol_select_list
value? <=> friends? /
dictionary <= suggestions *
dictionary <= suggestions *string
jocker \Jocker
harley \Harley Quinn
penguin \Penguin
Expand Down
4 changes: 2 additions & 2 deletions textarea/textarea.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $mol_textarea $mol_stack
row_numb* <= row_numb* 0
sidebar_showed <= sidebar_showed
highlight <= highlight \
symbols_alt *
symbols_alt *string
comma \<
period \>
dash \−
Expand All @@ -45,7 +45,7 @@ $mol_textarea $mol_stack
bracketOpen \[
bracketClose \]
slashBack \|
symbols_alt_shift *
symbols_alt_shift *string
V \✅
X \❌
O \⭕
Expand Down
4 changes: 2 additions & 2 deletions textarea/textarea.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ namespace $.$$ {
symbol_insert( event: KeyboardEvent ) {

const symbol = event.shiftKey
? this.symbols_alt_shift()[ $mol_keyboard_code[ event.keyCode ] ]
: this.symbols_alt()[ $mol_keyboard_code[ event.keyCode ] ]
? this.symbols_alt_shift()[ $mol_keyboard_code[ event.keyCode ] as keyof ReturnType<typeof this.symbols_alt_shift>]
: this.symbols_alt()[ $mol_keyboard_code[ event.keyCode ]]

if( !symbol ) return

Expand Down
6 changes: 3 additions & 3 deletions touch/touch.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ $mol_touch $mol_plugin
allow_pan true
allow_zoom true
action_type? \
action_point? $mol_vector_2d /
action_point? $mol_vector_2d<number> /
NaN
NaN
-
start_pan? /
0
0
pan? $mol_vector_2d /
pan? $mol_vector_2d<number> /
0
0
pointer_center $mol_vector_2d /
pointer_center $mol_vector_2d<number> /
NaN
NaN
-
Expand Down
4 changes: 2 additions & 2 deletions video/camera/camera.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ namespace $.$$ {

}

} else if( settings[ param ] !== null ) {
} else if( settings[ param as keyof typeof settings ] !== null ) {

try {
track.applyConstraints({ [ param ]: settings[ param ] })
track.applyConstraints({ [ param ]: settings[ param as keyof typeof settings ] })
} catch( error ) {
$mol_fail_log( error )
}
Expand Down
48 changes: 24 additions & 24 deletions view/tree2/to/dts/dts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,44 +190,44 @@ namespace $ {
}

if( input.type[0] === '/' ) {
const dups = new Set<string>()

const infered = input.kids.map( (kid, index) => {
const result = kid.hack_self(belt, context) as $mol_tree2[]
const val = result[0].value
const array_type = [
input.type.length > 1
? input.data(input.type.slice(1))
: input.data('any')
]

if (val === 'number' || val === 'string' || val === 'boolean') {
if (dups.has(val)) return []
dups.add(val)
}
if (array_type[0].value === 'any') {
return readonly_arr.call(this, input, array_type)
}

if (index !== 0) result.unshift(kid.data('| '))
if (kid.type[0] === '^') result.push((kid.kids[0] ?? prop).data('[number]'))
for (const kid of input.kids) {
let result = kid.hack_self(belt, context) as $mol_tree2[]

return kid.struct('line', result)
} )
const val = result[0].value

const array_type = input.type.length > 1 ? input.data(input.type.slice(1)) : undefined
if (val === 'string') {
result = kid.value.includes('`')
? [ kid.data(JSON.stringify(kid.value))]
: [ kid.data('`'), kid , kid.data('`') ]
} else if (val === 'boolean') result = [ kid.data(kid.type) ]
else if (kid.type[0] === '^') {
result.push((kid.kids[0] ?? prop).data('[number]'))
} else continue

if (infered.length && array_type) {
types.push(
type_enforce.call(
this,
input.data(`${ klass.type }_${prop.type.replace(/[\?\*]*/g, '')}`),
readonly_arr.call(this, input, infered),
readonly_arr.call(this, input, [ array_type ]),
result,
array_type
)
)
}

const result = array_type || ! infered.length
? [ array_type ?? input.data('any') ]
: infered

return readonly_arr.call(this, input, result)
return readonly_arr.call(this, input, array_type)
}

if( input.type !== 'NaN' && /^[$A-Z]/.test( input.type ) ) {
if( input.type !== 'NaN' && input.type !== 'Infinity' && /^[$A-Z]/.test( input.type ) ) {
const first = input.kids[0]
if( first?.type[0] === '/' ) {

Expand All @@ -241,7 +241,7 @@ namespace $ {
types.push(
type_enforce.call(
this,
first.data(`${ input.type }`),
first.data(`${ input.type.replace(/<.*>$/, '') }`),
[
first.data('[ '),
...args,
Expand Down
2 changes: 1 addition & 1 deletion view/tree2/to/js/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ namespace $ {
input.data( '$' ),
]),
input.struct('[]', [
input.data( input.type ),
input.data( input.type.replace(/<.+>$/, '') ),
]),
input.struct( '(,)', input.select( '/', null ).hack( belt ) ),
] ),
Expand Down
2 changes: 1 addition & 1 deletion view/tree2/to/js/test/ex/array_constructor_tuple.view.tree
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
$mol_view_tree2_to_js_test_ex_array_constructor_tuple_foo $mol_object
blobs /
<= text_blob? $mol_view_tree2_to_js_test_ex_klass_tuple /
<= text_blob? $mol_view_tree2_to_js_test_ex_klass_tuple<string> /
/string
<= text \123
* type \text/plain
5 changes: 5 additions & 0 deletions view/tree2/to/js/test/ex/array_union.view.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$mol_view_tree2_to_js_test_ex_array_union_foo $mol_object
bar /$mol_view_tree2_to_js_test_ex_klass_tuple_type
\a
<= foo \c
\b
5 changes: 3 additions & 2 deletions view/tree2/to/js/test/ex/klass.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace $ {
export type $mol_view_tree2_to_js_test_ex_klass_tuple_type = 'a' | 'b' | 'c'

export class $mol_view_tree2_to_js_test_ex_klass_tuple extends $mol_object {
constructor(readonly tuple: readonly string[] = [], readonly some?: { type: string }) {
export class $mol_view_tree2_to_js_test_ex_klass_tuple<V = string> extends $mol_object {
constructor(readonly tuple: readonly string[] = [], readonly some?: { type: V }) {
super()
}
}
Expand Down
2 changes: 2 additions & 0 deletions view/tree2/to/js/test/ex/simple_nan.view.tree
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ $mol_view_tree2_to_js_test_ex_simple_nan_foo $mol_object
c -NaN
d +Infinity
e -Infinity
f Infinity

Loading

0 comments on commit 6831b8f

Please sign in to comment.