2024-04-22 10:02:43 +02:00
var _ _extends = ( this && this . _ _extends ) || ( function ( ) {
var extendStatics = function ( d , b ) {
extendStatics = Object . setPrototypeOf ||
( { _ _proto _ _ : [ ] } instanceof Array && function ( d , b ) { d . _ _proto _ _ = b ; } ) ||
function ( d , b ) { for ( var p in b ) if ( Object . prototype . hasOwnProperty . call ( b , p ) ) d [ p ] = b [ p ] ; } ;
return extendStatics ( d , b ) ;
} ;
return function ( d , b ) {
if ( typeof b !== "function" && b !== null )
throw new TypeError ( "Class extends value " + String ( b ) + " is not a constructor or null" ) ;
extendStatics ( d , b ) ;
function _ _ ( ) { this . constructor = d ; }
d . prototype = b === null ? Object . create ( b ) : ( _ _ . prototype = b . prototype , new _ _ ( ) ) ;
} ;
} ) ( ) ;
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
// }
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
;
/ *
declare class console {
static log ( ... args : any [ ] ) : void ;
static info ( ... args : any [ ] ) : void ;
static warn ( ... args : any [ ] ) : void ;
static error ( ... args : any [ ] ) : void ;
} ;
* /
var lib _plankton ;
( function ( lib _plankton ) {
var base ;
( function ( base ) {
/ * *
* @ author fenris
* /
function environment ( ) {
return "web" ;
}
base . environment = environment ;
} ) ( base = lib _plankton . base || ( lib _plankton . base = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _null ( ) {
return {
"value" : null
} ;
}
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _make ( value ) {
return {
"value" : value
} ;
}
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _isset ( pseudopointer ) {
return ( pseudopointer . value != null ) ;
}
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _read ( pseudopointer ) {
if ( pseudopointer . value != null ) {
return pseudopointer . value ;
}
else {
var message = "nullpointer dereferencation" ;
throw ( new Error ( message ) ) ;
}
}
/ * *
* @ author fenris
* /
/*export*/ function pseudopointer _write ( pseudopointer , value ) {
pseudopointer . value = value ;
}
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ author fenris
* /
var instance _verbosity = 0 ;
/ * *
* @ author fenris
* /
function instance _collate ( value1 , value2 ) {
if ( typeof ( value1 ) === "object" ) {
if ( value1 == null ) {
return ( value2 == null ) ;
}
else {
if ( "_collate" in value1 ) {
return value1 [ "_collate" ] ( value2 ) ;
}
else {
throw ( new Error ( "[collate]" + " " + "object has no such method" ) ) ;
}
}
}
else {
if ( instance _verbosity >= 1 ) {
// lib_plankton.log.warn("[collate]" + " " + "primitive value; using default implementation");
}
return ( value1 === value2 ) ;
}
}
/ * *
* @ author fenris
* /
function instance _compare ( value1 , value2 ) {
if ( typeof ( value1 ) === "object" ) {
if ( "_compare" in value1 ) {
return value1 [ "_compare" ] ( value2 ) ;
}
else {
throw ( new Error ( "[compare]" + " " + "object has no such method" ) ) ;
}
}
else {
if ( instance _verbosity >= 1 ) {
// lib_plankton.log.warn("[compare]" + " " + "primitive value; using default implementation");
}
return ( value1 <= value2 ) ;
}
}
/ * *
* @ author fenris
* /
function instance _clone ( value ) {
if ( typeof ( value ) === "object" ) {
if ( "_clone" in value ) {
return value [ "_clone" ] ( ) ;
}
else {
throw ( new Error ( "[clone]" + " " + "object has no such method" ) ) ;
}
}
else {
if ( instance _verbosity >= 1 ) {
// lib_plankton.log.warn("[clone]" + " " + "primitive value; using default implementation");
}
return value ;
}
}
/ * *
* @ desc the ability to generate a string out of the element , which identifies it to a high degree
* @ author fenris
* /
function instance _hash ( value ) {
if ( typeof ( value ) === "object" ) {
if ( "_hash" in value ) {
return value [ "_hash" ] ( ) ;
}
else {
throw ( new Error ( "[hash]" + " " + "object has no such method" ) ) ;
}
}
else {
if ( instance _verbosity >= 1 ) {
// lib_plankton.log.warn("[hash]" + " " + "primitive value; using default implementation");
}
return String ( value ) ;
}
}
/ * *
* @ desc the ability to map the element to a textual representation ( most likely not injective )
* @ author fenris
* /
function instance _show ( value ) {
if ( typeof ( value ) === "object" ) {
if ( value == null ) {
return "NULL" ;
}
else {
if ( "_show" in value ) {
return value [ "_show" ] ( ) ;
}
else {
// throw (new Error("[show]" + " " + "object has no such method"));
return JSON . stringify ( value ) ;
}
}
}
else {
if ( instance _verbosity >= 1 ) {
// lib_plankton.log.warn("[show]" + " " + "primitive value; using default implementation");
}
return String ( value ) ;
}
}
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ author frac
* /
var class _observer = /** @class */ ( function ( ) {
/ * *
* @ author frac
* /
function class _observer ( ) {
this . counter = 0 ;
this . actions = { } ;
this . buffer = [ ] ;
}
/ * *
* @ author frac
* /
class _observer . prototype . empty = function ( ) {
return ( Object . keys ( this . actions ) . length == 0 ) ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . flush = function ( ) {
this . actions = { } ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . set = function ( id , action ) {
this . actions [ id ] = action ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . del = function ( id ) {
delete this . actions [ id ] ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . add = function ( action ) {
this . set ( ( this . counter ++ ) . toString ( ) , action ) ;
} ;
/ * *
* @ author frac
* /
class _observer . prototype . notify = function ( information , delayed ) {
var _this = this ;
if ( information === void 0 ) { information = { } ; }
if ( delayed === void 0 ) { delayed = false ; }
if ( delayed ) {
this . buffer . push ( information ) ;
}
else {
Object . keys ( this . actions ) . forEach ( function ( id ) { return _this . actions [ id ] ( information ) ; } ) ;
}
} ;
/ * *
* @ author frac
* /
class _observer . prototype . rollout = function ( ) {
var _this = this ;
this . buffer . forEach ( function ( information ) { return _this . notify ( information , false ) ; } ) ;
this . buffer = [ ] ;
} ;
return class _observer ;
} ( ) ) ;
/ * *
* @ author frac
* /
/ *
export interface interface _readable < type _value > {
| * *
* @ author frac
* |
read ( ) : type _executor < type _value , Error > ;
}
* /
/ * *
* @ author frac
* /
/ *
export interface interface _writeable < type _value > {
| * *
* @ author frac
* |
write ( value : type _value ) : type _executor < void , Error > ;
}
* /
/ *
This file is part of » bacterio - plankton : base « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ author frac
* /
var class _error = /** @class */ ( function ( _super ) {
_ _extends ( class _error , _super ) ;
/ * *
* @ author frac
* /
function class _error ( message , suberrors ) {
if ( suberrors === void 0 ) { suberrors = [ ] ; }
var _this = _super . call ( this , message ) || this ;
_this . suberrors = suberrors ;
_this . mess = message ;
return _this ;
}
/ * *
* @ override
* @ author frac
* /
class _error . prototype . toString = function ( ) {
return ( /*super.toString()*/ this . mess + " " + ( "[" + this . suberrors . map ( function ( x ) { return x . toString ( ) ; } ) . join ( "," ) + "]" ) ) ;
} ;
return class _error ;
} ( Error ) ) ;
var lib _plankton ;
( function ( lib _plankton ) {
var base ;
( function ( base ) {
/ * *
* returns the current UNIX timestamp
*
* @ author fenris
* /
function get _current _timestamp ( rounded ) {
if ( rounded === void 0 ) { rounded = false ; }
var x = ( Date . now ( ) / 1000 ) ;
return ( rounded ? Math . round ( x ) : x ) ;
;
}
base . get _current _timestamp = get _current _timestamp ;
/ * *
* /
function object _merge ( core , mantle ) {
return Object . assign ( core , mantle ) ;
}
base . object _merge = object _merge ;
} ) ( base = lib _plankton . base || ( lib _plankton . base = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : pod « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : pod « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : pod « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : pod « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var pod ;
( function ( pod _1 ) {
/ * *
* @ author fenris
* /
function make _empty ( ) {
return {
"kind" : "empty"
} ;
}
pod _1 . make _empty = make _empty ;
/ * *
* @ author fenris
* /
function make _filled ( value ) {
return {
"kind" : "filled" ,
"value" : value
} ;
}
pod _1 . make _filled = make _filled ;
/ * *
* whether the pod is filled
*
* @ author fenris
* /
function is _filled ( pod ) {
return ( pod . kind === "filled" ) ;
}
pod _1 . is _filled = is _filled ;
/ * *
* return the value , stored in the pod - wrapper
*
* @ author fenris
* /
function cull ( pod ) {
if ( ! is _filled ( pod ) ) {
throw ( new Error ( "cull from empty" ) ) ;
}
else {
return pod . value ;
}
}
pod _1 . cull = cull ;
/ * *
* to pass on a empty - pod or to use a filled - pod
*
* @ author fenris
* /
function propagate ( pod , function _ ) {
if ( ! is _filled ( pod ) ) {
return make _empty ( ) ;
}
else {
return make _filled ( function _ ( pod . value ) ) ;
}
}
pod _1 . propagate = propagate ;
/ * *
* @ author fenris
* /
function distinguish ( pod , function _empty , function _filled ) {
return ( ( ! is _filled ( pod ) )
? function _empty ( )
: function _filled ( pod . value ) ) ;
}
pod _1 . distinguish = distinguish ;
/ * *
* /
function show ( pod , options = { } ) {
options = Object . assign ( {
"show_value" : value => String ( value ) ,
} , options ) ;
if ( ! is _filled ( pod ) ) {
return "<·>" ;
}
else {
return ( "<- " + options . show _value ( pod . value ) + " ->" ) ;
}
}
pod _1 . show = show ;
} ) ( pod = lib _plankton . pod || ( lib _plankton . pod = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : pod « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : pod « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : pod « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : pod « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var pod ;
( function ( pod ) {
/ * *
* /
class class _pod {
constructor ( subject ) { this . subject = subject ; }
is _empty ( ) { return ( ! pod . is _filled ( this . subject ) ) ; }
is _filled ( ) { return pod . is _filled ( this . subject ) ; }
cull ( ) { return pod . cull ( this . subject ) ; }
show ( show _value = undefined ) { return pod . show ( this . subject , show _value ) ; }
toString ( ) { return this . show ( ) ; }
propagate ( function _ ) { return new class _pod ( pod . propagate ( this . subject , function _ ) ) ; }
distinguish ( function _empty , function _filled ) { return pod . distinguish ( this . subject , function _empty , function _filled ) ; }
}
pod . class _pod = class _pod ;
} ) ( pod = lib _plankton . pod || ( lib _plankton . pod = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : call « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : call « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : call « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : call « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* might be completely obsolete
* /
var lib _plankton ;
( function ( lib _plankton ) {
var call ;
( function ( call ) {
/ * *
* @ author fenris
* /
function promise _reject ( reason ) {
return Promise . reject ( reason ) ;
}
call . promise _reject = promise _reject ;
/ * *
* @ author fenris
* /
function promise _resolve ( result ) {
return Promise . resolve ( result ) ;
}
call . promise _resolve = promise _resolve ;
/ * *
* @ author fenris
* /
function promise _make ( executor ) {
return ( new Promise ( executor ) ) ;
}
call . promise _make = promise _make ;
/ * *
* @ author fenris
* /
function promise _then _close ( promise , resolver , rejector ) {
promise . then ( resolver , rejector ) ;
}
call . promise _then _close = promise _then _close ;
/ * *
* @ author fenris
* /
function promise _then _append ( promise , resolver , rejector = null ) {
if ( rejector == null ) {
rejector = ( reason ) => promise _reject ( reason ) ;
}
return ( promise . then ( resolver , rejector ) ) ;
}
call . promise _then _append = promise _then _append ;
/ * *
* @ author fenris
* /
function promise _all ( promises ) {
return Promise . all ( promises ) ;
}
call . promise _all = promise _all ;
/ * *
* @ author fenris
* /
function promise _chain ( promises , start = undefined ) {
return ( promises . reduce ( ( chain , promise ) => promise _then _append ( chain , promise ) , promise _resolve ( start ) ) ) ;
}
call . promise _chain = promise _chain ;
/ * *
* @ author fenris
* /
function promise _condense ( promises ) {
return ( promise _chain ( promises . map ( promise => result => promise _then _append ( promise ( ) , element => promise _resolve ( result . concat ( [ element ] ) ) ) ) , [ ] ) ) ;
}
call . promise _condense = promise _condense ;
/ * *
* @ author fenris
* /
function promise _group ( promises , options = {
"serial" : false ,
} ) {
const decorate = function ( promise , name ) {
return ( ( ) => promise _then _append ( promise ( ) , value => promise _resolve ( { "key" : name , "value" : value } ) ) ) ;
} ;
if ( options . serial ) {
return ( promise _then _append ( promise _condense ( Object . keys ( promises )
. map ( name => decorate ( promises [ name ] , name ) ) ) , list => promise _resolve ( Object . fromEntries ( list . map ( ( { "key" : key , "value" : value } ) => ( [ key , value ] ) ) ) ) ) ) ;
}
else {
return ( promise _then _append ( promise _all ( Object . keys ( promises )
. map ( name => decorate ( promises [ name ] , name ) )
. map ( promise => promise ( ) ) ) , list => promise _resolve ( Object . fromEntries ( list . map ( ( { "key" : key , "value" : value } ) => ( [ key , value ] ) ) ) ) ) ) ;
}
}
call . promise _group = promise _group ;
/ * *
* @ author fenris
* /
function promise _wrap ( promise , transformator _result , transformator _reason = lib _plankton . call . id ) {
return ( promise _make ( ( resolve , reject ) => {
promise _then _close ( promise , result => resolve ( transformator _result ( result ) ) , reason => reject ( transformator _reason ( reason ) ) ) ;
} ) ) ;
}
call . promise _wrap = promise _wrap ;
/ * *
* @ author fenris
* /
/ *
export function promise _show < type _result , type _reason > ( label : string ) : ( result : type _result ) => type _promise < type _result , type _reason > {
return (
result => promise _make < type _result , type _reason > (
( resolve , reject ) => {
// lib_plankton.log.info(label + ": " + instance_show(result));
process . stdout . write ( label + ": " + instance _show ( result ) ) ;
resolve ( result ) ;
}
)
) ;
}
* /
/ * *
* @ author fenris
* /
/ *
export function promise _log < type _result , type _reason > ( result : type _result ) : ( result : type _result ) => type _promise < type _result , type _reason > {
return promise _show < type _result , type _reason > ( "log" ) ;
}
* /
/ * *
* @ author fenris
* /
function promise _attach ( state , promise , name ) {
return ( promise _wrap ( promise , result => {
state [ name ] = result ;
return state ;
} ) ) ;
}
call . promise _attach = promise _attach ;
/ * *
* @ author fenris
* /
function promise _delay ( promise , delay ) {
return promise _make ( ( resolve , reject ) => {
call . timeout ( ( ) => {
promise _then _close ( promise , resolve , reject ) ;
return null ;
} , delay ) ;
} ) ;
}
call . promise _delay = promise _delay ;
} ) ( call = lib _plankton . call || ( lib _plankton . call = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : call « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : call « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : call « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : call « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var call ;
( function ( call ) {
/ * *
* /
class CancellablePromise extends Promise {
/ * *
* /
constructor ( executor ) {
super ( ( resolve , reject ) => { } ) ;
this . subject = ( new Promise ( ( resolve , reject ) => {
Promise . race ( [
new Promise ( executor ) ,
new Promise ( ( resolve _ , reject _ ) => {
this . interval = setInterval ( ( ) => {
if ( ! this . cancelled ) {
// do nothing
}
else {
reject _ ( new Error ( "cancelled" ) ) ;
this . clear ( ) ;
}
} , 0 ) ;
} ) ,
] )
. then ( resolve , reject ) ;
} ) ) ;
this . cancelled = false ;
this . interval = null ;
}
/ * *
* /
clear ( ) {
if ( this . interval === null ) {
// do nothing
}
else {
clearInterval ( this . interval ) ;
this . interval = null ;
}
}
/ * *
* /
then ( onfulfilled , onrejected ) {
this . clear ( ) ;
return this . subject . then ( onfulfilled , onrejected ) ;
}
/ * *
* /
catch ( x ) {
this . clear ( ) ;
return this . subject . catch ( x ) ;
}
/ * *
* /
cancel ( ) {
this . cancelled = true ;
this . clear ( ) ;
}
}
call . CancellablePromise = CancellablePromise ;
} ) ( call = lib _plankton . call || ( lib _plankton . call = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : call « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : call « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : call « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : call « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* initializer might be obsolete , since promises are reusable after having been resolved or rejected
* /
var lib _plankton ;
( function ( lib _plankton ) {
var call ;
( function ( call ) {
/ * *
* @ author fenris
* /
let enum _initializer _state ;
( function ( enum _initializer _state ) {
enum _initializer _state [ enum _initializer _state [ "initial" ] = 0 ] = "initial" ;
enum _initializer _state [ enum _initializer _state [ "waiting" ] = 1 ] = "waiting" ;
enum _initializer _state [ enum _initializer _state [ "successful" ] = 2 ] = "successful" ;
enum _initializer _state [ enum _initializer _state [ "failed" ] = 3 ] = "failed" ;
} ) ( enum _initializer _state = call . enum _initializer _state || ( call . enum _initializer _state = { } ) ) ;
/ * *
* @ author fenris
* /
function initializer _make ( fetcher ) {
let subject = {
"fetcher" : fetcher ,
"state" : enum _initializer _state . initial ,
"queue" : [ ] ,
"result" : undefined ,
"reason" : undefined ,
} ;
return subject ;
}
call . initializer _make = initializer _make ;
/ * *
* @ author fenris
* /
function initializer _actuate ( subject ) {
switch ( subject . state ) {
case enum _initializer _state . successful : {
subject . queue . forEach ( entry => entry . resolve ( subject . result ) ) ;
break ;
}
case enum _initializer _state . failed : {
subject . queue . forEach ( entry => entry . reject ( subject . reason ) ) ;
break ;
}
default : {
throw ( new Error ( ` unhandled state ${ subject . state } ` ) ) ;
break ;
}
}
}
/ * *
* @ author fenris
* /
function initializer _reset ( subject ) {
subject . state = enum _initializer _state . initial ;
subject . queue = [ ] ;
}
call . initializer _reset = initializer _reset ;
/ * *
* @ author fenris
* /
function initializer _state ( subject ) {
return subject . state ;
}
call . initializer _state = initializer _state ;
/ * *
* @ author fenris
* /
function initializer _get ( subject ) {
switch ( subject . state ) {
case enum _initializer _state . initial : {
subject . state = enum _initializer _state . waiting ;
return ( call . promise _make ( ( resolve , reject ) => {
subject . queue . push ( { "resolve" : resolve , "reject" : reject } ) ;
subject . fetcher ( ) . then ( result => {
subject . state = enum _initializer _state . successful ;
subject . result = result ;
initializer _actuate ( subject ) ;
} , reason => {
subject . state = enum _initializer _state . failed ;
subject . reason = reason ;
initializer _actuate ( subject ) ;
} ) ;
} ) ) ;
break ;
}
case enum _initializer _state . waiting : {
return ( call . promise _make ( ( resolve , reject ) => {
subject . queue . push ( { "resolve" : resolve , "reject" : reject } ) ;
} ) ) ;
break ;
}
case enum _initializer _state . successful : {
return ( call . promise _resolve ( subject . result ) ) ;
break ;
}
case enum _initializer _state . failed : {
return ( call . promise _reject ( subject . reason ) ) ;
break ;
}
default : {
throw ( new Error ( ` unhandled state ${ subject . state } ` ) ) ;
break ;
}
}
}
call . initializer _get = initializer _get ;
/ * *
* @ author fenris
* /
function initializer _get _sync ( subject ) {
switch ( subject . state ) {
case enum _initializer _state . successful : {
return subject . result ;
break ;
}
case enum _initializer _state . failed : {
throw subject . reason ;
break ;
}
default : {
throw ( new Error ( ` unhandled state ${ subject . state } ` ) ) ;
break ;
}
}
}
/ * *
* @ author fenris
* /
function initializer _set _sync ( subject , result ) {
switch ( subject . state ) {
case enum _initializer _state . successful : {
subject . result = result ;
break ;
}
case enum _initializer _state . failed : {
subject . state = enum _initializer _state . successful ;
subject . result = result ;
break ;
}
default : {
throw ( new Error ( ` unhandled state ${ subject . state } ` ) ) ;
break ;
}
}
}
} ) ( call = lib _plankton . call || ( lib _plankton . call = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : call « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : call « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : call « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : call « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var call ;
( function ( call ) {
/ *
The core idea of this library is to provide means for asynchronous program flow . The old - school way to do is ,
is to use callbacks . While this approach is simple and easy to understand , it has some disadvantages . As an
attempt to relief and improve this , the promise - system was introduced . In principle it solves most of the
problems found in the callback - approach ; however it has some downsides as well :
- Convolution of multiple principles
Promises unite the ideas of asynchronous program flow and error handling .
- Instant execution
Creating a promise results in the instant execution of the given executor prodecure . While this might be
convenient in some cases , it can be quite disturbing and counter - intuitive in others .
- Broken typing
The Promise system doesn ' t distinguish between an appending "then" ( i . e . passing a function , which returns a
new promise ) and a closing "then" ( i . e . passing a function , which has no return value ) . On top of that it
allows returning simple values in an appending "then" , which results in an implicit call of the executors
"resolve" - function . The price for these "pragmatic" features is that the whole system can ' t be typed well .
And even though JavaScript is not a strictly typed language , it was a quite questionable decision to design
the promise system in a way , which breaks typing from the start .
The deferral - system forseeks to solve these issues while retaining the advantages of the promise - system .
* /
/ * *
* @ author fenris
* @ desc activates the deferral and handles its output according to a given procedure
* @ param { ( value : type _value ) => void } procedure a function which receives the output of the deferral as argument
* /
function deferral _use ( deferral , input , procedure ) {
deferral . representation ( input ) . then ( value => {
procedure ( value ) ;
} , reason => {
throw reason ;
} ) ;
}
call . deferral _use = deferral _use ;
/ * *
* @ author fenris
* @ desc creates a deferral - subject ( similar to "new Promise" , where "convey" reflects "resolve" / "reject" )
* /
function deferral _make ( handler ) {
return ( {
"representation" : ( ( input ) => ( new Promise ( ( resolve , reject ) => {
handler ( input , resolve ) ;
} ) ) )
} ) ;
}
call . deferral _make = deferral _make ;
/ * *
* @ author fenris
* @ desc wraps a simple function into a deferral ( similar to "Promise.resolve" / "Promise.reject" )
* /
function deferral _wrap ( function _ ) {
return ( deferral _make ( ( input , convey ) => convey ( function _ ( input ) ) ) ) ;
}
call . deferral _wrap = deferral _wrap ;
/ * *
* @ author fenris
* /
function deferral _id ( ) {
return ( deferral _make ( ( input , convey ) => convey ( input ) ) ) ;
}
call . deferral _id = deferral _id ;
/ * *
* @ author fenris
* /
function deferral _const ( value ) {
return ( deferral _make ( ( input , convey ) => convey ( value ) ) ) ;
}
call . deferral _const = deferral _const ;
/ * *
* @ author fenris
* /
function deferral _delay ( output , delay ) {
return ( deferral _make ( ( input , convey ) => {
setTimeout ( ( ) => convey ( output ) , delay ) ;
} ) ) ;
}
call . deferral _delay = deferral _delay ;
/ * *
* @ author fenris
* @ desc connects two deferrals to form a new one ; the output of the first is taken as input for the second
* ( similar to "Promise.then" when passing a function which returns a new promise )
* @ param { type _deferral < type _value1 > } first a simple deferral
* @ param { ( value1 : type _value1 ) => type _deferral < type _value2 > } second a function depending from a value returning a deferral
* /
function deferral _compose _serial ( first , second ) {
return {
"representation" : ( ( input ) => first . representation ( input ) . then ( ( between ) => second . representation ( between ) ) )
} ;
}
call . deferral _compose _serial = deferral _compose _serial ;
/ * *
* @ author fenris
* /
function deferral _compose _parallel ( { "left" : deferral _left , "right" : deferral _right , } ) {
return ( deferral _make ( ( input , convey ) => {
let object = {
"left" : lib _plankton . pod . make _empty ( ) ,
"right" : lib _plankton . pod . make _empty ( ) ,
} ;
let finish = function ( ) {
if ( lib _plankton . pod . is _filled ( object . left )
&&
lib _plankton . pod . is _filled ( object . right ) ) {
let result = {
"left" : lib _plankton . pod . cull ( object . left ) ,
"right" : lib _plankton . pod . cull ( object . right ) ,
} ;
convey ( result ) ;
}
else {
// do nothing
}
} ;
deferral _use ( deferral _left , input , output _left => {
object . left = lib _plankton . pod . make _filled ( output _left ) ;
finish ( ) ;
} ) ;
deferral _use ( deferral _right , input , output _right => {
object . right = lib _plankton . pod . make _filled ( output _right ) ;
finish ( ) ;
} ) ;
} ) ) ;
}
call . deferral _compose _parallel = deferral _compose _parallel ;
/ * *
* @ author fenris
* @ desc repeatedly applied serial composition
* /
function deferral _chain ( members ) {
return ( members . reduce (
// (result, current) => deferral_compose_serial<type_value, type_value, type_value>(result, current),
deferral _compose _serial , deferral _id ( ) ) ) ;
}
call . deferral _chain = deferral _chain ;
/ * *
* @ author fenris
* /
/ *
export function deferral _bunch < type _input , type _output > (
members : { [ name : string ] : type _deferral < type _input , type _output > }
) : type _deferral < type _input , { [ name : string ] : type _output } > {
}
* /
} ) ( call = lib _plankton . call || ( lib _plankton . call = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : call « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : call « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : call « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : call « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var call ;
( function ( call ) {
/ * *
* @ author fenris
* /
class class _deferral {
/ * *
* @ author fenris
* /
constructor ( subject ) {
this . subject = subject ;
}
/ * *
* @ author fenris
* /
static _cram ( subject ) {
return ( new class _deferral ( subject ) ) ;
}
/ * *
* @ author fenris
* /
static _tear ( instance ) {
return instance . subject ;
}
/ * *
* @ author fenris
* /
static make ( handler ) {
return ( class _deferral . _cram ( call . deferral _make ( handler ) ) ) ;
}
/ * *
* @ author fenris
* /
use ( input , procedure ) {
return ( call . deferral _use ( class _deferral . _tear ( this ) , input , procedure ) ) ;
}
/ * *
* @ author fenris
* /
compose _serial ( second ) {
return ( class _deferral . _cram ( call . deferral _compose _serial ( class _deferral . _tear ( this ) , class _deferral . _tear ( second ) ) ) ) ;
}
/ * *
* @ author fenris
* /
static chain ( members ) {
return ( class _deferral . _cram ( call . deferral _chain ( members . map ( member => class _deferral . _tear ( member ) ) ) ) ) ;
}
/ * *
* @ author fenris
* /
static wrap ( function _ ) {
return ( class _deferral . _cram ( call . deferral _wrap ( function _ ) ) ) ;
}
/ * *
* @ author fenris
* /
static const _ ( value ) {
return ( class _deferral . _cram ( call . deferral _const ( value ) ) ) ;
}
/ * *
* @ author fenris
* /
static delay ( output , delay ) {
return ( class _deferral . _cram ( call . deferral _delay ( output , delay ) ) ) ;
}
}
call . class _deferral = class _deferral ;
} ) ( call = lib _plankton . call || ( lib _plankton . call = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : call « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : call « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : call « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : call « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var call ;
( function ( call ) {
/ * *
* converts the "arguments" - map into an array
*
* @ param { Object } args
* @ author fenris
* /
function args2list ( args ) {
return Object . keys ( args ) . map ( key => args [ key ] ) ;
}
call . args2list = args2list ;
/ * *
* just the empty function ; useful for some callbacks etc .
*
* @ author fenris
* /
function nothing ( ) {
}
call . nothing = nothing ;
/ * *
* just the identity ; useful for some callbacks etc . ; defined as function instead of const for using type parameters
*
* @ author fenris
* /
function id ( x ) {
return x ;
}
call . id = id ;
/ * *
* just the identity ; useful for some callbacks etc .
*
* @ author fenris
* /
function const _ ( x ) {
return ( y => x ) ;
}
call . const _ = const _ ;
/ * *
* composes two functions ( i . e . returns a function that return the result of the successive execution of both input - functions )
*
* @ param { function } function _f
* @ param { function } function _g
* @ author fenris
* /
function compose ( function _f , function _g ) {
return ( function ( x ) {
// return function_g(function_f(x));
return function _g ( function _f . apply ( function _f , args2list ( arguments ) ) ) ;
} ) ;
}
call . compose = compose ;
/ * *
* @ author fenris
* /
function curryfy _real ( f , n ) {
switch ( n ) {
case 0 : {
throw ( new Error ( "[curryfy] impossible" ) ) ;
// break;
}
case 1 : {
return f ;
// break;
}
default : {
return ( function ( x ) {
return ( curryfy _real ( function ( ) { return f . apply ( f , [ x ] . concat ( args2list ( arguments ) ) ) ; } , n - 1 ) ) ;
} ) ;
// break;
}
}
}
/ * *
* transforms a function with sequential input to a function with leveled input ; example : add ( 2 , 3 ) = curryfy ( add ) ( 2 ) ( 3 )
*
* @ param { function } f
* @ return { function } the currified version of the in put function
* @ author fenris
* /
function curryfy ( f ) {
return curryfy _real ( f , f . length ) ;
}
call . curryfy = curryfy ;
/ * *
* @ author fenris
* /
function convey ( value , functions ) {
let result = value ;
functions . forEach ( function _ => {
result = function _ ( result ) ;
} ) ;
return result ;
}
call . convey = convey ;
/ * *
* @ author fenris
* /
function timeout ( procedure , delay _in _seconds ) {
return (
/*window.*/ setTimeout ( procedure , Math . floor ( delay _in _seconds * 1000 ) ) ) ;
}
call . timeout = timeout ;
/ * *
* Promise version of "setTimeout"
*
* @ author fenris
* /
function defer ( seconds , action ) {
return ( new Promise ( ( resolve , reject ) => {
setTimeout ( ( ) => resolve ( action ( ) ) , Math . floor ( seconds * 1000 ) ) ;
} ) ) ;
}
call . defer = defer ;
/ * *
* a definition for a value being "defined"
*
* @ author neuc
* /
function is _def ( obj , options = { } ) {
options = Object . assign ( {
"null_is_valid" : false ,
} , options ) ;
return ( ! ( ( typeof ( obj ) === "undefined" )
||
( ! options . null _is _valid && ( obj === null ) ) ) ) ;
}
call . is _def = is _def ;
/ * *
* returns the value if set and , when a type is specified , if the type is correct , if not return default _value
*
* @ author neuc
* /
function def _val ( value , default _value , options = { } ) {
options = Object . assign ( {
"type" : null ,
"null_is_valid" : false ,
} , options ) ;
if ( is _def ( value , { "null_is_valid" : options . null _is _valid } )
&&
( is _def ( options . type )
? ( ( typeof ( value ) === options . type )
||
( ( value === null )
&&
options . null _is _valid ) )
: true ) ) {
return value ;
}
else {
return default _value ;
}
}
call . def _val = def _val ;
;
/ * *
* provides the call for an attribute of a class as a regular function ; useful for processing lists of objects
*
* @ param { string } name the name of the attribute
* @ return { function }
* @ author fenris
* /
function attribute ( name ) {
return ( object => object [ name ] ) ;
}
call . attribute = attribute ;
/ * *
* provides a method of a class as a regular function ; useful for processing lists of objects
*
* @ param { string } name the name of the method
* @ return { function }
* @ author fenris
* /
function method ( name ) {
return ( function ( object ) { return object [ name ] . apply ( object , args2list ( arguments ) . slice ( 1 ) ) ; } ) ;
}
call . method = method ;
/ * *
* @ author fenris
* /
function distinguish ( coproduct , handlers , options = { } ) {
options = Object . assign ( {
"fallback" : null ,
} , options ) ;
if ( coproduct . kind in handlers ) {
const handler = handlers [ coproduct . kind ] ;
return handler ( coproduct . data ) ;
}
else {
const message = ( "unhandled kind '" + coproduct . kind + "'" ) ;
if ( options . fallback !== null ) {
console . warn ( message ) ;
return options . fallback ( coproduct ) ;
}
else {
throw ( new Error ( message ) ) ;
}
}
}
call . distinguish = distinguish ;
/ * *
* rate limiting algorithm , based on the idea of mana ( magic power ) in video games :
* - an actor has a fixed mana capacity , i . e . the maximum amount of available power
* - an actor has a fixed rate of mana regeneration , i . e . how fast the power is filled up ( linear growth )
* - an action has a defined mana heft , i . e . how much power is required and deducted in order to execute it
* - mana states are represented by snapshots , i . e . the amount of power at a certain point in time
*
* @ author fenris
* /
async function rate _limit _check ( setup , heft ) {
if ( heft > setup . capacity ) {
return Promise . resolve ( {
"granted" : false ,
"seconds" : null ,
} ) ;
}
else {
// get current value
const current _timestamp = ( Date . now ( ) / 1000 ) ;
const old _snapshot _raw = ( await setup . get _snapshot ( ) ) ;
const old _snapshot = ( old _snapshot _raw
? ?
{ "timestamp" : current _timestamp , "value" : setup . capacity } ) ;
const seconds _passed = ( current _timestamp - old _snapshot . timestamp ) ;
const current _value = Math . min ( setup . capacity , ( old _snapshot . value
+
( setup . regeneration _rate
*
seconds _passed ) ) ) ;
// analyze
if ( current _value < heft ) {
// too less
const seconds _needed = ( ( setup . regeneration _rate <= 0 )
? null
: ( ( heft - old _snapshot . value ) / setup . regeneration _rate ) ) ;
return Promise . resolve ( {
"granted" : false ,
"seconds" : ( ( seconds _needed === null ) ? null : ( seconds _needed - seconds _passed ) ) ,
} ) ;
}
else {
// enough -> update snapshot
const new _value = ( current _value - heft ) ;
// set_snapshot
if ( old _snapshot _raw === null ) {
await setup . set _snapshot ( { "timestamp" : current _timestamp , "value" : new _value } ) ;
}
else {
await setup . update _snapshot ( current _timestamp , ( new _value - old _snapshot . value ) ) ;
}
return Promise . resolve ( {
"granted" : true ,
"seconds" : 0 ,
} ) ;
}
}
}
call . rate _limit _check = rate _limit _check ;
} ) ( call = lib _plankton . call || ( lib _plankton . call = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : file « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : file « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : file « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : file « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var file ;
( function ( file ) {
/ * *
* @ author fenris
* /
function read ( path ) {
return ( fetch ( "/" + path )
. then ( function ( result ) { return result . text ( ) ; } ) ) ;
}
file . read = read ;
/ * *
* @ author fenris
* /
function write ( path , content ) {
return Promise . reject ( new Error ( "not implemented / not possible" ) ) ;
}
file . write = write ;
/ * *
* @ author fenris
* /
function blob _read _text ( blob ) {
return ( lib _plankton . call . promise _make ( function ( resolve , reject ) {
var reader = ( new FileReader ( ) ) ;
reader . addEventListener ( "load" , function ( event ) {
resolve ( ( reader . result ) ) ;
} ) ;
reader . addEventListener ( "error" , function ( event ) {
reject ( new Error ( "reading file failed" ) ) ;
} ) ;
reader . addEventListener ( "abort" , function ( event ) {
reject ( new Error ( "reading file aborted" ) ) ;
} ) ;
reader . readAsText ( blob ) ;
} ) ) ;
}
file . blob _read _text = blob _read _text ;
/ * *
* @ author fenris
* /
function blob _read _arraybuffer ( blob ) {
return ( lib _plankton . call . promise _make ( function ( resolve , reject ) {
var reader = ( new FileReader ( ) ) ;
reader . addEventListener ( "load" , function ( event ) {
resolve ( ( reader . result ) ) ;
} ) ;
reader . addEventListener ( "error" , function ( event ) {
reject ( new Error ( "reading file failed" ) ) ;
} ) ;
reader . addEventListener ( "abort" , function ( event ) {
reject ( new Error ( "reading file aborted" ) ) ;
} ) ;
reader . readAsArrayBuffer ( blob ) ;
} ) ) ;
}
file . blob _read _arraybuffer = blob _read _arraybuffer ;
/ * *
* @ author fenris
* /
function blob _read _dataurl ( blob ) {
return ( lib _plankton . call . promise _make ( function ( resolve , reject ) {
var reader = new FileReader ( ) ;
reader . addEventListener ( "load" , function ( event ) {
resolve ( ( reader . result ) ) ;
} ) ;
reader . addEventListener ( "error" , function ( event ) {
reject ( new Error ( "reading file failed" ) ) ;
} ) ;
reader . addEventListener ( "abort" , function ( event ) {
reject ( new Error ( "reading file aborted" ) ) ;
} ) ;
reader . readAsDataURL ( blob ) ;
} ) ) ;
}
file . blob _read _dataurl = blob _read _dataurl ;
/ * *
* @ author fenris
* /
function blob _write _text ( text ) {
var blob = ( new Blob ( [ text ] , { "type" : "text/plain" } ) ) ;
return lib _plankton . call . promise _resolve ( blob ) ;
}
file . blob _write _text = blob _write _text ;
} ) ( file = lib _plankton . file || ( lib _plankton . file = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
function inverse _encode ( decode , to ) {
return decode ( to ) ;
}
code . inverse _encode = inverse _encode ;
/ * *
* @ author fenris
* /
function inverse _decode ( encode , from ) {
return encode ( from ) ;
}
code . inverse _decode = inverse _decode ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
var class _code _inverse = /** @class */ ( function ( ) {
/ * *
* @ author fenris
* /
function class _code _inverse ( subject ) {
this . subject = subject ;
}
/ * *
* @ implementation
* @ author fenris
* /
class _code _inverse . prototype . encode = function ( to ) {
var _this = this ;
return code . inverse _encode ( function ( x ) { return _this . subject . decode ( x ) ; } , to ) ;
} ;
/ * *
* @ implementation
* @ author fenris
* /
class _code _inverse . prototype . decode = function ( from ) {
var _this = this ;
return code . inverse _decode ( function ( x ) { return _this . subject . encode ( x ) ; } , from ) ;
} ;
return class _code _inverse ;
} ( ) ) ;
code . class _code _inverse = class _code _inverse ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
function pair _encode ( encode _first , encode _second , from ) {
var between = encode _first ( from ) ;
var to = encode _second ( between ) ;
return to ;
}
code . pair _encode = pair _encode ;
/ * *
* @ author fenris
* /
function pair _decode ( decode _first , decode _second , to ) {
var between = decode _second ( to ) ;
var from = decode _first ( between ) ;
return from ;
}
code . pair _decode = pair _decode ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
var class _code _pair = /** @class */ ( function ( ) {
/ * *
* @ author fenris
* /
function class _code _pair ( first , second ) {
this . first = first ;
this . second = second ;
}
/ * *
* @ implementation
* @ author fenris
* /
class _code _pair . prototype . encode = function ( from ) {
var _this = this ;
return code . pair _encode ( function ( x ) { return _this . first . encode ( x ) ; } , function ( x ) { return _this . second . encode ( x ) ; } , from ) ;
} ;
/ * *
* @ implementation
* @ author fenris
* /
class _code _pair . prototype . decode = function ( to ) {
var _this = this ;
return code . pair _decode ( function ( x ) { return _this . first . decode ( x ) ; } , function ( x ) { return _this . second . decode ( x ) ; } , to ) ;
} ;
return class _code _pair ;
} ( ) ) ;
code . class _code _pair = class _code _pair ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
function chain _encode ( encode _links , from ) {
var value = from ;
encode _links
. forEach ( function ( link ) {
value = link ( value ) ;
} ) ;
return value ;
}
code . chain _encode = chain _encode ;
/ * *
* @ author fenris
* /
function chain _decode ( decode _links , to ) {
var value = to ;
decode _links
. reverse ( )
. forEach ( function ( link ) {
value = link ( value ) ;
} ) ;
return value ;
}
code . chain _decode = chain _decode ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
var class _code _chain = /** @class */ ( function ( ) {
/ * *
* @ author fenris
* /
function class _code _chain ( links ) {
this . links = links ;
}
/ * *
* @ implementation
* @ author fenris
* /
class _code _chain . prototype . encode = function ( from ) {
return code . chain _encode ( this . links . map ( function ( link ) { return ( function ( x ) { return link . encode ( x ) ; } ) ; } ) , from ) ;
} ;
/ * *
* @ implementation
* @ author fenris
* /
class _code _chain . prototype . decode = function ( to ) {
return code . chain _decode ( this . links . map ( function ( link ) { return ( function ( x ) { return link . decode ( x ) ; } ) ; } ) , to ) ;
} ;
return class _code _chain ;
} ( ) ) ;
code . class _code _chain = class _code _chain ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author Christian Fraß < frass @ greenscale . de >
* /
function flatten _encode ( from , keys ) {
if ( keys === void 0 ) { keys = null ; }
if ( keys === null ) {
if ( from . length > 0 ) {
keys = Object . keys ( from [ 0 ] ) ;
}
else {
throw ( new Error ( "encoding impossible" ) ) ;
}
}
return {
"keys" : keys ,
"data" : from . map ( function ( line ) { return keys . map ( function ( name ) { return line [ name ] ; } ) ; } )
} ;
}
code . flatten _encode = flatten _encode ;
/ * *
* @ author Christian Fraß < frass @ greenscale . de >
* /
function flatten _decode ( to ) {
return ( to . data
. map ( function ( dataset ) {
var dataset _ = { } ;
dataset
. forEach ( function ( value , index ) {
var name = to . keys [ index ] ;
dataset _ [ name ] = value ;
} ) ;
return dataset _ ;
} ) ) ;
}
code . flatten _decode = flatten _decode ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : code « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : code « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : code « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : code « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var code ;
( function ( code ) {
/ * *
* @ author fenris
* /
var class _code _flatten = /** @class */ ( function ( ) {
/ * *
* @ author fenris
* /
function class _code _flatten ( ) {
}
/ * *
* @ implementation
* @ author fenris
* /
class _code _flatten . prototype . encode = function ( x ) {
return code . flatten _encode ( x ) ;
} ;
/ * *
* @ implementation
* @ author fenris
* /
class _code _flatten . prototype . decode = function ( x ) {
return code . flatten _decode ( x ) ;
} ;
return class _code _flatten ;
} ( ) ) ;
code . class _code _flatten = class _code _flatten ;
} ) ( code = lib _plankton . code || ( lib _plankton . code = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : json « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : json « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : json « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : json « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var json ;
( function ( json ) {
/ * *
* @ author fenris
* /
function encode ( x , formatted = false ) {
return JSON . stringify ( x , undefined , formatted ? "\t" : undefined ) ;
}
json . encode = encode ;
/ * *
* @ author fenris
* /
function decode ( x ) {
return JSON . parse ( x ) ;
}
json . decode = decode ;
} ) ( json = lib _plankton . json || ( lib _plankton . json = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : json « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : json « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : json « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : json « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var json ;
( function ( json ) {
/ * *
* @ author fenris
* /
class class _json {
/ * *
* @ author fenris
* /
constructor ( ) {
}
/ * *
* @ implementation
* @ author fenris
* /
encode ( x ) {
return json . encode ( x ) ;
}
/ * *
* @ implementation
* @ author fenris
* /
decode ( x ) {
return json . decode ( x ) ;
}
}
json . class _json = class _json ;
} ) ( json = lib _plankton . json || ( lib _plankton . json = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : base64 « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base64 « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base64 « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base64 « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var base64 ;
( function ( base64 ) {
/ * *
* @ author fenris
* /
function encode ( x ) {
return btoa ( x ) ;
}
base64 . encode = encode ;
/ * *
* @ author fenris
* /
function decode ( x ) {
return atob ( x ) ;
}
base64 . decode = decode ;
} ) ( base64 = lib _plankton . base64 || ( lib _plankton . base64 = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : base64 « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : base64 « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : base64 « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : base64 « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var base64 ;
( function ( base64 ) {
/ * *
* @ author fenris
* /
class class _base64 {
/ * *
* @ author fenris
* /
constructor ( ) {
}
/ * *
* @ implementation
* @ author fenris
* /
encode ( x ) {
return base64 . encode ( x ) ;
}
/ * *
* @ implementation
* @ author fenris
* /
decode ( x ) {
return base64 . decode ( x ) ;
}
}
base64 . class _base64 = class _base64 ;
} ) ( base64 = lib _plankton . base64 || ( lib _plankton . base64 = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
var _ _extends = ( this && this . _ _extends ) || ( function ( ) {
var extendStatics = function ( d , b ) {
extendStatics = Object . setPrototypeOf ||
( { _ _proto _ _ : [ ] } instanceof Array && function ( d , b ) { d . _ _proto _ _ = b ; } ) ||
function ( d , b ) { for ( var p in b ) if ( Object . prototype . hasOwnProperty . call ( b , p ) ) d [ p ] = b [ p ] ; } ;
return extendStatics ( d , b ) ;
} ;
return function ( d , b ) {
if ( typeof b !== "function" && b !== null )
throw new TypeError ( "Class extends value " + String ( b ) + " is not a constructor or null" ) ;
extendStatics ( d , b ) ;
function _ _ ( ) { this . constructor = d ; }
d . prototype = b === null ? Object . create ( b ) : ( _ _ . prototype = b . prototype , new _ _ ( ) ) ;
} ;
} ) ( ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : log « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
var enum _level ;
( function ( enum _level ) {
enum _level [ enum _level [ "debug" ] = 0 ] = "debug" ;
enum _level [ enum _level [ "info" ] = 1 ] = "info" ;
enum _level [ enum _level [ "notice" ] = 2 ] = "notice" ;
enum _level [ enum _level [ "warning" ] = 3 ] = "warning" ;
enum _level [ enum _level [ "error" ] = 4 ] = "error" ;
} ) ( enum _level = log . enum _level || ( log . enum _level = { } ) ) ;
;
/ * *
* /
function level _order ( level1 , level2 ) {
return ( level1 <= level2 ) ;
}
log . level _order = level _order ;
/ * *
* /
function level _show ( level ) {
switch ( level ) {
case enum _level . debug : return "debug" ;
case enum _level . info : return "info" ;
case enum _level . notice : return "notice" ;
case enum _level . warning : return "warning" ;
case enum _level . error : return "error" ;
default : return "(unknown)" ;
}
}
log . level _show = level _show ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : lang « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ * *
* @ deprecated
* @ todo remove
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* @ author fenris
* /
/*export*/ var level _stack = [ 0 ] ;
function level _push ( level ) { level _stack . push ( level ) ; }
log . level _push = level _push ;
function level _pop ( ) { if ( level _stack . length > 1 ) {
level _stack . pop ( ) ;
} }
log . level _pop = level _pop ;
function level _get ( ) { return level _stack . slice ( - 1 ) [ 0 ] ; }
/ *
export function level _inc ( ) : void { level _push ( level _get ( ) + 1 ) ; }
export function level _dec ( ) : void { level _push ( level _get ( ) - 1 ) ; }
* /
/ * *
* @ author fenris
* /
var indent _stack = [ 0 ] ;
function indent _push ( indent ) { indent _stack . push ( indent ) ; }
log . indent _push = indent _push ;
function indent _pop ( ) { if ( indent _stack . length > 1 ) {
indent _stack . pop ( ) ;
} }
log . indent _pop = indent _pop ;
function indent _get ( ) { return level _stack . slice ( - 1 ) [ 0 ] ; }
function indent _inc ( ) { level _push ( level _get ( ) + 1 ) ; }
log . indent _inc = indent _inc ;
function indent _dec ( ) { level _push ( level _get ( ) - 1 ) ; }
log . indent _dec = indent _dec ;
/ * *
* @ author fenris
* /
function write ( _a ) {
var message = _a [ "message" ] , _b = _a [ "type" ] , type = _b === void 0 ? null : _b , _c = _a [ "prefix" ] , prefix = _c === void 0 ? null : _c , _d = _a [ "level" ] , level = _d === void 0 ? 0 : _d , _e = _a [ "indent" ] , indent = _e === void 0 ? 0 : _e ;
var entry = {
"level" : ( ( type === null )
? lib _plankton . log . enum _level . info
: {
"debug" : lib _plankton . log . enum _level . debug ,
"info" : lib _plankton . log . enum _level . info ,
"notice" : lib _plankton . log . enum _level . notice ,
"warning" : lib _plankton . log . enum _level . warning ,
"error" : lib _plankton . log . enum _level . error
} [ type ] ) ,
"incident" : message ,
"details" : {
"prefix" : prefix ,
"level" : level ,
"indent" : indent
}
} ;
lib _plankton . log . add ( entry ) ;
}
log . write = write ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : log « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
var class _channel = /** @class */ ( function ( ) {
function class _channel ( ) {
}
return class _channel ;
} ( ) ) ;
log . class _channel = class _channel ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : log « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* output for writing log entries to web console
* /
var class _channel _console = /** @class */ ( function ( _super ) {
_ _extends ( class _channel _console , _super ) ;
function class _channel _console ( ) {
return _super !== null && _super . apply ( this , arguments ) || this ;
}
/ * *
* /
class _channel _console . prototype . add = function ( entry ) {
var _a ;
var renderers = ( _a = { } ,
_a [ log . enum _level . debug ] = {
"renderer" : function ( i , d ) { return console . log ( i , d ) ; } ,
"show_level" : true
} ,
_a [ log . enum _level . info ] = {
"renderer" : function ( i , d ) { return console . info ( i , d ) ; } ,
"show_level" : false
} ,
_a [ log . enum _level . notice ] = {
"renderer" : function ( i , d ) { return console . log ( i , d ) ; } ,
"show_level" : true
} ,
_a [ log . enum _level . warning ] = {
"renderer" : function ( i , d ) { return console . warn ( i , d ) ; } ,
"show_level" : false
} ,
_a [ log . enum _level . error ] = {
"renderer" : function ( i , d ) { return console . error ( i , d ) ; } ,
"show_level" : false
} ,
_a ) ;
var setting = renderers [ entry . level ] ;
setting . renderer ( ( ( setting . show _level
? ( "[" + log . level _show ( entry . level ) + "]" + " " )
: "" )
+
( "" + entry . incident + "" ) ) , entry . details ) ;
} ;
return class _channel _console ;
} ( log . class _channel ) ) ;
log . class _channel _console = class _channel _console ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : log « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* decorator for filtering out log entries below a certain level threshold
* /
var class _channel _minlevel = /** @class */ ( function ( _super ) {
_ _extends ( class _channel _minlevel , _super ) ;
/ * *
* /
function class _channel _minlevel ( core , threshold ) {
var _this = _super . call ( this ) || this ;
_this . core = core ;
_this . threshold = threshold ;
return _this ;
}
/ * *
* /
class _channel _minlevel . prototype . add = function ( entry ) {
if ( ! log . level _order ( this . threshold , entry . level ) ) {
// do nothing
}
else {
this . core . add ( entry ) ;
}
} ;
return class _channel _minlevel ;
} ( log . class _channel ) ) ;
log . class _channel _minlevel = class _channel _minlevel ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : log « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
function translate _level ( level _string ) {
return {
"debug" : log . enum _level . debug ,
"info" : log . enum _level . info ,
"notice" : log . enum _level . notice ,
"warning" : log . enum _level . warning ,
"error" : log . enum _level . error
} [ level _string ] ;
}
/ * *
* /
function channel _make ( description ) {
var _a ;
switch ( description . kind ) {
default : {
throw ( new Error ( "unhandled log channel kind: " + description . kind ) ) ;
break ;
}
case "console" : {
return ( new log . class _channel _minlevel ( new log . class _channel _console ( ) , translate _level ( ( _a = description . data [ "threshold" ] ) !== null && _a !== void 0 ? _a : "debug" ) ) ) ;
break ;
}
}
}
log . channel _make = channel _make ;
/ * *
* /
function conf _default ( ) {
return [
new log . class _channel _minlevel ( new log . class _channel _console ( ) , log . enum _level . notice ) ,
] ;
}
log . conf _default = conf _default ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : log « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : log « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : lang « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : log « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var log ;
( function ( log ) {
/ * *
* /
var _channel _stack = null ;
/ * *
* pushes a new configuration on the stack and activates it
* /
function conf _push ( channels ) {
if ( _channel _stack === null ) {
_channel _stack = [ ] ;
}
_channel _stack . push ( channels ) ;
}
log . conf _push = conf _push ;
/ * *
* pops the current active configuration from the stack
* /
function conf _pop ( ) {
if ( _channel _stack . length > 0 ) {
_channel _stack . pop ( ) ;
}
else {
// do nothing
}
}
log . conf _pop = conf _pop ;
/ * *
* makes the logging system ready
* /
function setup ( ) {
if ( _channel _stack === null ) {
_channel _stack = [ ] ;
conf _push ( log . conf _default ( ) ) ;
}
else {
// do nothing
}
}
/ * *
* consumes a log entry , i . e . sends it to the currently active outputs
* /
function add ( entry ) {
setup ( ) ;
_channel _stack . slice ( - 1 ) [ 0 ] . forEach ( function ( channel ) { return channel . add ( entry ) ; } ) ;
}
log . add = add ;
/ * *
* /
function debug ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . debug , "incident" : incident , "details" : details } ) ;
}
log . debug = debug ;
/ * *
* /
function info ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . info , "incident" : incident , "details" : details } ) ;
}
log . info = info ;
/ * *
* /
function notice ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . notice , "incident" : incident , "details" : details } ) ;
}
log . notice = notice ;
/ * *
* /
function warning ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . warning , "incident" : incident , "details" : details } ) ;
}
log . warning = warning ;
/ * *
* /
function error ( incident , details ) {
if ( details === void 0 ) { details = { } ; }
add ( { "level" : log . enum _level . error , "incident" : incident , "details" : details } ) ;
}
log . error = error ;
} ) ( log = lib _plankton . log || ( lib _plankton . log = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : string « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : string « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : string « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : string « . If not , see < http : //www.gnu.org/licenses/>.
* /
var plain _text _to _html = function ( text ) {
let ret = text ;
ret = ret . replace ( / /g , " " ) ; // convert multiple whitespace to forced ones
ret = ret . split ( "\n" ) . join ( "<br/>" ) ;
return ret ;
} ;
/ * *
* @ desc makes a valid
* /
var format _sentence = function ( str , rtl = false , caseSense = true ) {
if ( str === "" ) {
return str ;
}
else {
let marks = {
"." : true ,
"?" : true ,
"!" : true
} ;
let default _mark = "." ;
let ret = str . split ( "" ) ;
if ( ! rtl ) {
ret [ 0 ] = ret [ 0 ] . toLocaleUpperCase ( ) ;
if ( ! ( ret [ ret . length - 1 ] in marks ) ) {
ret . push ( default _mark ) ;
}
}
else {
ret [ ret . length - 1 ] = ret [ ret . length - 1 ] . toLocaleUpperCase ( ) ;
if ( ! ( ret [ 0 ] in marks ) ) {
ret . unshift ( default _mark ) ;
}
}
return ret . join ( "" ) ;
}
} ;
var fill _string _template = function ( template _string , object , fabric = function ( object , key ) { return object [ key ] ; } , delimiter = "%" , default _string = null , sloppy ) {
function get _tags ( str ) {
let r = new RegExp ( delimiter + "[^\\s^" + delimiter + "]+" + delimiter , "gi" ) ;
return ( ( str . match ( r ) || [ ] ) . map ( function ( e ) {
return e . slice ( delimiter . length , e . length - delimiter . length ) ;
} ) ) ;
}
function replace _tag ( str , tag , value ) {
let r = new RegExp ( delimiter + tag + delimiter , "gi" ) ;
return str . replace ( r , value ) ;
}
function replace _tags ( str , obj ) {
return ( get _tags ( str ) . reduce ( function ( ret , key ) {
let value = "" ;
try {
value = fabric ( obj , key ) ;
if ( ( ! sloppy && ( value === void 0 ) ) || ( sloppy && ( value == void 0 ) ) ) {
value = default _string ;
}
}
catch ( e ) {
console . warn ( "invalid placeholder " + key ) ;
value = default _string ;
}
return replace _tag ( ret , key , value ) ;
} , str ) ) ;
}
return replace _tags ( template _string , object ) ;
} ;
var make _string _template = function ( _template , _fabrics = { } ) {
function replace _tag ( str , tag , value ) {
var r = new RegExp ( "%" + tag + "%" , "gi" ) ;
return str . replace ( r , value ) ;
}
function replace _tags ( str , obj ) {
return ( Object . keys ( obj ) . reduce ( function ( ret , key ) {
return replace _tag ( ret , key , _fabrics [ key ] || obj [ key ] ) ;
} , str ) ) ;
}
return ( function ( tags ) {
return replace _tags ( _template , tags ) ;
} ) ;
} ;
var make _eml _header = ( function ( ) {
let _template = "" ;
_template += "From: %from%\n" ;
_template += "To: %recipient%\n" ;
_template += "Subject: %subject%\n" ;
_template += "X-Mailer: greenscale-plankton.emlgen\n" ;
return make _string _template ( _template ) ;
} ) ( ) ;
var make _eml _body = ( function ( ) {
let exports = { } ;
exports [ "simple_body" ] = make _string _template ( "Content-Type: %contenttype%\n\n%body%\n\n" ) ;
// very basic implementation
// parts = [{contenttype:"text/html; charset=UTF-8", body: "<h1>foo</h1>" }, {...}]
exports [ "body_boundrary" ] = function ( parts , boundrary ) {
let _template = "" ;
_template += "--%boundrary%\n" ;
_template += "Content-Type: %contenttype%\n\n%body%\n\n" ;
//_template += "--%boundrary%--\n\n";
let maker = make _string _template ( _template ) ;
return ( parts . reduce ( function ( prev , curr ) {
curr . boundrary = boundrary ;
return [ prev , maker ( curr ) ] . join ( "" ) ;
} , "" ) ) ;
} ;
// body must be base64 encoded!
exports [ "attachment_boundrary" ] = function ( parts , boundrary ) {
let _template = "" ;
_template += "--%boundrary%\n" ;
_template += "Content-Type: %contenttype%\n" ;
_template += "Content-Transfer-Encoding: base64\n" ;
_template += "Content-Disposition: %disposition%; filename=\"%name%\"\n\n" ;
_template += "%body%\n\n" ;
//_template += "--%boundrary%--\n\n";
let maker = make _string _template ( _template ) ;
return ( parts . reduce ( function ( prev , curr ) {
curr . boundrary = boundrary ;
if ( curr . disposition === void 0 )
curr . disposition = "inline" ;
return [ prev , maker ( curr ) ] . join ( "" ) ;
} , "" ) ) ;
} ;
exports [ "gen_boundrary" ] = function ( ) {
return ( "xxxxxxxxxxxxxxxxxxxxxx" . replace ( /[xy]/g , function ( c ) {
let r = crypto . getRandomValues ( new Uint8Array ( 1 ) ) [ 0 ] % 16 | 0 , v = c == "x" ? r : ( r & 0x3 | 0x8 ) ;
return v . toString ( 16 ) ;
} ) ) ;
} ;
// simple implementation without alternatives (old rfc)
exports [ "complete_boundrary" ] = function ( bodyparts , attachments ) {
let ret = "" ;
let boundrary = exports [ "gen_boundrary" ] ( ) ;
ret += exports [ "body_boundrary" ] ( bodyparts , boundrary ) ;
ret += exports [ "attachment_boundrary" ] ( attachments , boundrary ) ;
ret += "--" + boundrary + "--\n\nINVISIBLE!!!!" ;
return ( exports [ "simple_body" ] ( {
"contenttype" : sprintf ( "multipart/mixed; boundary=%s" , [ boundrary ] ) ,
"body" : ret
} ) ) ;
} ;
return exports ;
} ) ( ) ;
/ *
This file is part of » bacterio - plankton : string « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : string « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : string « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : string « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var string ;
( function ( string ) {
/ * *
* @ author fenris
* /
const hexdigits = 4 ;
/ * *
* @ author fenris
* /
const index _max = ( 1 << ( 4 * hexdigits ) ) ;
/ * *
* @ author fenris
* /
var index _is = 0 ;
/ * *
* @ author neuc , frac
* /
function empty ( str ) {
return ( str . trim ( ) === "" ) ;
}
string . empty = empty ;
/ * *
* @ desc returns a unique string
* @ param { string } prefix an optional prefix for the generated string
* @ return { string }
* @ author fenris
* /
function generate ( prefix = "string_" ) {
if ( index _is > index _max ) {
throw ( new Error ( "[string_generate] out of valid indices" ) ) ;
}
else {
return string . sprintf ( prefix + "%0" + hexdigits . toString ( ) + "X" , [ index _is ++ ] ) ;
}
}
string . generate = generate ;
/ * *
* @ author fenris
* /
function join ( parts , glue = " " ) {
if ( parts . length == 0 ) {
return "" ;
}
else {
return parts . join ( glue ) ;
}
}
string . join = join ;
/ * *
* @ desc splits a string , but returns an empty list , if the string is empty
* @ param { string } chain
* @ param { string } separator
* @ return { Array < string > }
* @ author fenris
* /
function split ( chain , separator = " " ) {
if ( chain . length == 0 ) {
return [ ] ;
}
else {
return chain . split ( separator ) ;
}
}
string . split = split ;
/ * *
* @ author neu3no
* /
function explode ( str , needle , max ) {
let temp = str . split ( needle ) ;
const right = temp . splice ( max - 1 ) ;
temp . push ( right . join ( needle ) ) ;
return temp ;
}
string . explode = explode ;
/ * *
* @ desc concats a given word with itself n times
* @ param { string } word
* @ param { int }
* @ return { string }
* @ author fenris
* /
function repeat ( word , count ) {
// return ((count == 0) ? "" : (word + repeat(word, count-1)));
let result = "" ;
for ( let n = 0 ; n < count ; n += 1 ) {
result += word ;
}
return result ;
}
string . repeat = repeat ;
/ * *
* @ desc lengthens a string by repeatedly appending or prepending another string
* @ param { string } word the string to pad
* @ param { int } length the length , which the result shall have
* @ param { string } symbol the string , which will be added ( multiple times )
* @ param { boolean } [ prepend ] ; whether to prepend ( ~ true ) or append ( ~ false ) ; default : false
* @ return { string } the padded string
* @ author fenris
* /
function pad ( word , length , symbol = " " , mode = "append" ) {
switch ( mode ) {
case "prepend" : {
// insert symbols only at the beginning
while ( word . length < length )
word = symbol + word ;
return word . substring ( word . length - length ) ;
break ;
}
case "append" : {
// insert symbols only at the end
while ( word . length < length )
word = word + symbol ;
return word . substring ( 0 , length ) ;
break ;
}
case "widen" : {
// insert symbols at both sides
let left = ( ( ( length - word . length ) & 1 ) === 0 ) ;
while ( word . length < length ) {
word = ( left
? ( symbol + word )
: ( word + symbol ) ) ;
left = ( ! left ) ;
}
return word . substring ( 0 , length ) ;
break ;
}
default : {
const message = ( "unhandled mode '" + mode + "'" ) ;
console . warn ( message ) ;
return word ;
break ;
}
}
}
string . pad = pad ;
/ * *
* @ desc checks if a given string conttains a certain substring
* @ param { string } string
* @ param { string } part
* @ return { boolean }
* @ author fenris
* /
function contains ( chain , part ) {
if ( typeof ( chain ) !== "string" ) {
return false ;
}
return ( chain . indexOf ( part ) >= 0 ) ;
}
string . contains = contains ;
/ * *
* @ desc checks if a given string starts with a certain substring
* @ param { string } string
* @ param { string } part
* @ return { boolean }
* @ author fenris
* /
function startsWith ( chain , part ) {
if ( typeof ( chain ) !== "string" ) {
return false ;
}
// return (string.indexOf(part) === 0);
return ( ( function ( m , n ) {
if ( n === 0 ) {
return true ;
}
else {
if ( m === 0 ) {
return false ;
}
else {
return ( ( chain [ 0 ] == part [ 0 ] )
&&
startsWith ( chain . substring ( 1 ) , part . substring ( 1 ) ) ) ;
}
}
} ) ( chain . length , part . length ) ) ;
}
string . startsWith = startsWith ;
/ * *
* @ desc checks if a given string ends with a certain substring
* @ param { string } string
* @ param { string } part
* @ return { boolean }
* @ author fenris
* /
function endsWith ( chain , part ) {
if ( typeof ( chain ) !== "string" ) {
return false ;
}
// return (string.lastIndexOf(part) === string.length-part.length);
return ( ( function ( m , n ) {
if ( n === 0 ) {
return true ;
}
else {
if ( m === 0 ) {
return false ;
}
else {
// console.info(("(" + string[m-1] + " == " + part[n-1] + ")") + " = " + String(string[m-1] == part[n-1]));
return ( ( chain [ m - 1 ] === part [ n - 1 ] )
&&
endsWith ( chain . substring ( 0 , m - 1 ) , part . substring ( 0 , n - 1 ) ) ) ;
}
}
} ) ( chain . length , part . length ) ) ;
}
string . endsWith = endsWith ;
/ * *
* @ desc count the occourrences of a string in a string
* @ param string haystack _string the string wich should be examined
* @ param string needle _string the string which should be counted
* @ author neuc
* /
function count _occourrences ( haystack _string , needle _string , check _escape ) {
let cnt = 0 ;
let pos = - 1 ;
do {
pos = haystack _string . indexOf ( needle _string , pos + 1 ) ;
if ( ( ! check _escape ) || ( haystack _string [ pos - 1 ] != "\\" ) ) {
cnt ++ ;
}
} while ( pos >= 0 ) ;
return ( cnt - 1 ) ;
}
string . count _occourrences = count _occourrences ;
/ * *
* @ author fenris
* /
function replace ( str , replacements , options = { } ) {
options = Object . assign ( { } , options ) ;
let result = str ;
replacements . forEach ( replacement => {
lib _plankton . log . debug ( "lib_plankton.string.replace" , {
"from" : replacement . from ,
"to" : replacement . to ,
} ) ;
result = result . replace ( new RegExp ( replacement . from , "g" ) , replacement . to ) ;
} ) ;
return result ;
}
string . replace = replace ;
/ * *
* @ desc replaces occurences of "{{name}}" in a string by the corresponding values of an argument object
* @ author fenris
* /
function coin ( str , args , options = { } ) {
options = Object . assign ( {
"legacy" : false ,
"open" : "{{" ,
"close" : "}}" ,
} , options ) ;
Object . keys ( args ) . forEach ( ( key ) => {
// old syntax
{
if ( options . legacy ) {
const value = args [ key ] ;
const regexp _argument = new RegExp ( "\\${" + key + "}" , "g" ) ;
lib _plankton . log . debug ( "lib_plankton.string.coin" , {
"key" : key ,
"regex" : regexp _argument . toString ( ) ,
"value" : value ,
} ) ;
str = str . replace ( regexp _argument , value ) ;
}
}
// new syntax
{
const value = args [ key ] ;
const regexp _argument = new RegExp ( options . open + key + options . close , "g" ) ;
lib _plankton . log . debug ( "lib_plankton.string.coin" , {
"key" : key ,
"regex" : regexp _argument . toString ( ) ,
"value" : value ,
} ) ;
str = str . replace ( regexp _argument , value ) ;
}
} ) ;
return str ;
}
string . coin = coin ;
/ * *
* @ author fenris
* @ deprecated use limit
* /
function cut ( str , length , delimiter = "…" ) {
if ( str . length <= length ) {
return str ;
}
else {
return ( str . slice ( 0 , length - delimiter . length ) + delimiter ) ;
}
}
string . cut = cut ;
/ * *
* /
function limit ( str , options = { } ) {
options = Object . assign ( {
"length" : 120 ,
"indicator" : "…" ,
} , options ) ;
return ( ( str . length <= options . length )
? str
: ( str . slice ( 0 , options . length - options . indicator . length ) + options . indicator ) ) ;
}
string . limit = limit ;
/ * *
* /
function slice ( str , size ) {
let slices = [ ] ;
let rest = str ;
while ( rest . length > 0 ) {
slices . push ( rest . slice ( 0 , size ) ) ;
rest = rest . slice ( size ) ;
}
return slices ;
}
string . slice = slice ;
} ) ( string = lib _plankton . string || ( lib _plankton . string = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ * *
* @ deprecated
* /
var lib _string ;
( function ( lib _string ) {
lib _string . empty = lib _plankton . string . empty ;
lib _string . generate = lib _plankton . string . generate ;
lib _string . split = lib _plankton . string . split ;
lib _string . explode = lib _plankton . string . repeat ;
lib _string . repeat = lib _plankton . string . repeat ;
lib _string . pad = lib _plankton . string . pad ;
lib _string . contains = lib _plankton . string . contains ;
lib _string . startsWith = lib _plankton . string . startsWith ;
lib _string . endsWith = lib _plankton . string . endsWith ;
lib _string . count _occourrences = lib _plankton . string . count _occourrences ;
lib _string . coin = lib _plankton . string . coin ;
lib _string . stance = lib _plankton . string . coin ;
lib _string . cut = lib _plankton . string . cut ;
} ) ( lib _string || ( lib _string = { } ) ) ;
/ *
This file is part of » bacterio - plankton : string « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : string « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : string « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : string « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var string ;
( function ( string ) {
var pattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/ ;
var gpattern = /%([-+#0 ]*)([0-9]*)[\.]{0,1}([0-9]*)([\w]{1})/g ;
function split _format ( format ) {
var tmp = format . match ( pattern ) ;
if ( tmp === null )
return null ;
return {
'flags' : tmp [ 1 ] . split ( "" ) ,
'width' : Number ( tmp [ 2 ] ) ,
'precision' : tmp [ 3 ] === '' ? null : Number ( tmp [ 3 ] ) ,
'specifier' : tmp [ 4 ] ,
'string' : format
} ;
}
function make _err ( format , arg , should ) {
return ( "[sprintf]" + " " + "argument for '" + format . string + "' has to be '" + should + "' but '" + arg + "' is '" + typeof arg + "'!" ) ;
}
function test _arg ( format , arg , should ) {
if ( typeof arg !== should ) {
console . warn ( make _err ( format , arg , should ) ) ;
return false ;
}
return true ;
}
function string _fill ( str , char , len , left ) {
while ( str . length < len ) {
if ( left ) {
str += char ;
}
else {
str = char + str ;
}
}
return str ;
}
/ * *
* the known _parameters are used to parse the different identifiers for the welln known syntax :
* flag width precision identifier
* % { [ 0 # + - ] } { [ 0 - 9 ] * } . { [ 0 - 9 ] * } [ fFdiueEgGsoxXaAsn ]
* flags :
* 0 - fill with '0' instead of ' ' if the string length < width
* # - not implemented
* - - left - justified - > fill on the right side to reach width
* + - force using '+' on positive numbers
* ' ' - add a single space before positive numbers
*
* identifiers
* % f , % F - interpret given number as float , width : the minimal total width ( fill with ' ' or '0' if the
* resulting string is too short , precision : cut more then given decimal places
* % d , % i , % u - interpret number as integer , decimal places will be cut . width : like float , precision :
* fill with '0' on right side until length given in precision is reached
* % e - interpret as float and write as scientifical number , width & precision like in float
* % E - same es % e but uppercase 'E'
* % g - use the shortest string of % f or % e
* % G - use the shortest string of % E or % E
* % s - simply print a string
* % o - print the given number in octal notation
* % x - print the given number in hex notation
* % X - same as % x but with uppercase characters
* % a - alias to % x
* % A - alias to % X
* % n - just print nothing
* @ type { { } }
* /
var known _params = { } ;
known _params [ "f" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , "number" ) )
return "Ø" ;
var tmp = Math . abs ( arg ) ;
var sign = ( arg < 0 ) ? - 1 : 1 ;
var tmp _result = null ;
if ( format . precision !== null ) {
tmp = Math . floor ( Math . pow ( 10 , format . precision ) * tmp ) / Math . pow ( 10 , format . precision ) ;
var tmp _ = ( tmp * sign ) . toString ( ) . split ( "." ) ;
if ( tmp _ . length === 1 )
tmp _ . push ( "" ) ;
tmp _ [ 1 ] = string _fill ( tmp _ [ 1 ] , "0" , format . precision , true ) ;
tmp _result = tmp _ . join ( "." ) ;
}
else {
tmp _result = ( sign * tmp ) . toString ( ) ;
}
if ( ( format . flags . indexOf ( " " ) >= 0 ) && ( arg >= 0 ) ) {
tmp _result = " " + tmp ;
}
else if ( ( format . flags . indexOf ( "+" ) >= 0 ) && ( arg >= 0 ) ) {
tmp _result = "+" + tmp ;
}
tmp _result = string _fill ( tmp , ( format . flags . indexOf ( "0" ) >= 0 ) ? "0" : " " , format . width , ( format . flags . indexOf ( "-" ) >= 0 ) ) ;
return tmp _result ;
} ;
known _params [ "F" ] = known _params [ "f" ] ;
known _params [ "d" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'number' ) )
return 'Ø' ;
var tmp = ( ( ( arg < 0 && format . specifier !== 'u' ) ? - 1 : 1 ) * Math . floor ( Math . abs ( arg ) ) ) . toString ( ) ;
if ( ( format . specifier === 'd' || format . specifier === 'i' ) && format . flags . indexOf ( ' ' ) >= 0 && arg >= 0 ) {
tmp = ' ' + tmp ;
}
else if ( ( format . specifier === 'd' || format . specifier === 'i' ) && format . flags . indexOf ( '+' ) >= 0 && arg >= 0 ) {
tmp = '+' + tmp ;
}
tmp = string _fill ( tmp , format . flags . indexOf ( '0' ) >= 0 ? '0' : ' ' , format . width , format . flags . indexOf ( '-' ) >= 0 ) ;
tmp = string _fill ( tmp , '0' , format . precision === null ? 0 : format . precision , false ) ;
return tmp ;
} ;
known _params [ "i" ] = known _params [ "d" ] ;
known _params [ "u" ] = known _params [ "d" ] ;
known _params [ "e" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'number' ) )
return 'Ø' ;
var tmp = arg . toExponential ( format . precision === null ? undefined : format . precision ) . toString ( ) ;
if ( format . flags . indexOf ( ' ' ) >= 0 && arg >= 0 ) {
tmp = ' ' + tmp ;
}
else if ( format . flags . indexOf ( '+' ) >= 0 && arg >= 0 ) {
tmp = '+' + tmp ;
}
tmp = string _fill ( tmp , format . flags . indexOf ( '0' ) >= 0 ? '0' : ' ' , format . width , format . flags . indexOf ( '-' ) >= 0 ) ;
return tmp ;
} ;
known _params [ "E" ] = function ( format , arg ) {
return known _params [ "e" ] ( format , arg ) . toUpperCase ( ) ;
} ;
known _params [ "g" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'number' ) )
return 'Ø' ;
var tmpf = known _params [ "f" ] ( format , arg ) ;
var tmpe = known _params [ "e" ] ( format , arg ) ;
if ( tmpf . length < tmpe . length ) {
return tmpf ;
}
else {
return tmpe ;
}
} ;
known _params [ "G" ] = function ( format , arg ) {
return known _params [ "g" ] ( format , arg ) . toUpperCase ( ) ;
} ;
known _params [ "s" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'string' ) )
return 'o.O' ;
var tmp = format . precision !== null ? arg . substr ( 0 , format . precision ) : arg ;
tmp = string _fill ( tmp , format . flags . indexOf ( '0' ) >= 0 ? '0' : ' ' , format . width , format . flags . indexOf ( '-' ) >= 0 ) ;
return tmp ;
} ;
known _params [ "o" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'number' ) )
return 'Ø' ;
var tmp = Math . floor ( Math . round ( Math . abs ( arg ) ) ) * ( ( arg < 0 ) ? - 1 : 1 ) ;
return known _params [ "s" ] ( format , tmp . toString ( 8 ) ) ;
} ;
known _params [ "x" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'number' ) )
return 'Ø' ;
var tmp = Math . floor ( Math . round ( Math . abs ( arg ) ) ) * ( ( arg < 0 ) ? - 1 : 1 ) ;
return known _params [ "s" ] ( format , tmp . toString ( 16 ) ) ;
} ;
known _params [ "a" ] = known _params [ "x" ] ;
known _params [ "X" ] = function ( format , arg ) {
if ( ! test _arg ( format , arg , 'number' ) )
return 'Ø' ;
return known _params [ "x" ] ( format , arg ) . toUpperCase ( ) ;
} ;
known _params [ "A" ] = known _params [ "X" ] ;
known _params [ "c" ] = function ( format , arg ) {
var tmp = "" ;
if ( typeof arg === "number" ) {
tmp = String . fromCharCode ( arg ) ;
}
else if ( ( typeof arg === "string" ) && ( arg . length === 1 ) ) {
tmp = arg [ 0 ] ;
}
else {
console . warn ( make _err ( format , arg , "number|string" ) + " and if string it needs to have the length of 1!" ) ;
}
return known _params [ "s" ] ( format , tmp ) ;
} ;
known _params [ "n" ] = function ( ) {
return "" ;
} ;
var decompose = function ( chain , regexp ) {
var result = regexp . exec ( chain ) ;
if ( result == null ) {
return null ;
}
else {
var front = chain . substring ( 0 , result . index ) ;
var back = chain . substring ( result . index + result [ 0 ] . length ) ;
return { "front" : front , "match" : result [ 0 ] , "back" : back } ;
}
} ;
/ * *
* an implementation of c sprintf
* @ param { string } string format string
* @ param { array } args arguments which should be filled into
* @ returns { string }
* /
string . sprintf = function ( input , args = [ ] , original = null ) {
if ( original == null )
original = input ;
var components = decompose ( input , pattern ) ;
if ( components == null ) {
if ( args . length > 0 ) {
console . warn ( "[sprintf] superfluous arguments while formatting '" + original + "': " , args ) ;
}
return input ;
}
else {
var arg ;
var rest ;
if ( args . length > 0 ) {
arg = args [ 0 ] ;
rest = args . slice ( 1 ) ;
}
else {
console . warn ( "[sprintf] out of arguments while formatting '" + original + "'" ) ;
arg = null ;
rest = [ ] ;
return input ;
}
var fmt = split _format ( components [ "match" ] ) ;
return ( components [ "front" ]
+ known _params [ fmt . specifier ] ( fmt , arg )
+ string . sprintf ( components [ "back" ] , rest , original ) ) ;
}
} ;
/ * *
* an implementation of c printf
* @ param { string } string format string
* @ param { array } args arguments which should be filled into
* @ returns { string }
* /
function printf ( format , args ) {
console . log ( string . sprintf ( format , args ) ) ;
}
string . printf = printf ;
} ) ( string = lib _plankton . string || ( lib _plankton . string = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
var sprintf = lib _plankton . string . sprintf ;
var printf = lib _plankton . string . printf ;
/ *
This file is part of » bacterio - plankton : string « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : string « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : string « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : string « . If not , see < http : //www.gnu.org/licenses/>.
* /
var make _logger = ( function ( ) {
var _loggers = { } ;
var make _logger = function ( prefix , current _loglevel ) {
var log = [ ] ;
var level = [
"LOG" , "INFO" , "WARNING" , "DEBUG"
] ;
var logger = function ( obj , lvl ) {
var txt = obj . txt || obj ;
if ( lvl == void 0 )
lvl = 0 ;
var date = new Date ( ) ;
log . push ( {
"message" : sprintf ( "%s [%s:%s] %s" , [ date . toString ( ) , level [ lvl ] , prefix , txt ] ) ,
"timeStamp" : + ( date )
} ) ;
if ( lvl <= current _loglevel ) {
var msg = [ "[" + prefix + "]" , txt ] ;
if ( obj . arg )
msg = [ "[" + prefix + "]" ] . concat ( Array . prototype . slice . call ( obj . arg ) ) ;
if ( lvl === 0 )
console [ "_log" ] . apply ( console , msg ) ;
else if ( lvl === 1 )
console [ "_info" ] . apply ( console , msg ) ;
else if ( lvl === 2 )
console [ "_warn" ] . apply ( console , msg ) ;
else if ( lvl >= 3 )
console [ "_log" ] . apply ( console , msg ) ;
}
} ;
_loggers [ prefix ] = {
"logger" : logger ,
"log" : log
} ;
return logger ;
} ;
make _logger [ "loggers" ] = _loggers ;
make _logger [ "complete_log" ] = function ( ) {
var logs = Object . keys ( _loggers )
. reduce ( function ( p , c ) {
return [ ] . concat ( p , _loggers [ c ] . log ) ;
} , [ ] ) ;
logs . sort ( function ( x , y ) {
return ( ( x . timeStamp > y . timeStamp ) ? - 1 : + 1 ) ;
} ) ;
return logs . map ( function ( x , i , a ) {
return x . message ;
} ) ;
} ;
if ( /*!track_exports*/ true ) {
var _log _all = function ( log , lvl , next = function ( ) { } ) {
return function ( ) {
var msg = [ ] ;
for ( var i = 0 ; i < arguments . length ; i ++ ) {
if ( typeof arguments [ i ] === "string" ) {
msg . push ( arguments [ i ] ) ;
}
else {
msg . push ( JSON . stringify ( arguments [ i ] ) ) ;
}
}
var obj = {
txt : msg . join ( "\t" ) ,
arg : arguments
} ;
log ( obj , lvl ) ;
next ( ) ;
} ;
} ;
{
var _ _warn = make _logger ( "deprecated console.warn" , 99 ) ;
var _ _error = make _logger ( "deprecated console.error" , 99 ) ;
var _ _log = make _logger ( "deprecated console.log" , 99 ) ;
var _ _info = make _logger ( "deprecated console.info" , 99 ) ;
// bad ass
console [ "_log" ] = console . log ;
console [ "_error" ] = console . error ;
console [ "_warn" ] = console . warn ;
console [ "_info" ] = console . info ;
/ *
console [ "log" ] = _log _all ( _ _log , 0 ) ;
console [ "error" ] = _log _all ( _ _error , 2 ) ;
console [ "warn" ] = _log _all ( _ _warn , 2 ) ;
console [ "info" ] = _log _all ( _ _info , 0 ) ;
* /
}
/ *
{
make _logger [ "send_log" ] = function ( ) {
eml _log (
function ( ) {
alert ( "fehlerbericht wurde gesendet!" ) ;
}
) ;
} ;
var error _log = make _logger ( "global.error" , 99 ) ;
window . onerror = _log _all (
error _log ,
1 ,
function ( ) {
if ( global _config == undefined ) {
return false ;
}
if ( global _config . report _error ) {
make _logger [ "send_log" ] ( ) ;
}
}
) ;
}
* /
}
return make _logger ;
} ) ( ) ;
/ *
2024-04-30 14:17:22 +02:00
This file is part of » bacterio - plankton : object « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : object « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : object « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : object « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var object ;
( function ( object _1 ) {
/ * *
* @ author fenris
* /
function fetch ( object , fieldname , fallback , escalation ) {
if ( fallback === void 0 ) { fallback = null ; }
if ( escalation === void 0 ) { escalation = 1 ; }
if ( ( fieldname in object ) && ( object [ fieldname ] !== undefined ) ) {
return object [ fieldname ] ;
}
else {
switch ( escalation ) {
case 0 : {
return fallback ;
break ;
}
case 1 : {
var message = ( "field '" . concat ( fieldname , "' not in structure" ) ) ;
message += ( "; using fallback value '" . concat ( String ( fallback ) , "'" ) ) ;
// console.warn(message);
return fallback ;
break ;
}
case 2 : {
var message = ( "field '" . concat ( fieldname , "' not in structure" ) ) ;
throw ( new Error ( message ) ) ;
break ;
}
default : {
throw ( new Error ( "invalid escalation level " . concat ( escalation ) ) ) ;
break ;
}
}
}
}
object _1 . fetch = fetch ;
/ * *
* @ author fenris
* /
function map ( object _from , transformator ) {
var object _to = { } ;
Object . keys ( object _from ) . forEach ( function ( key ) { return ( object _to [ key ] = transformator ( object _from [ key ] , key ) ) ; } ) ;
return object _to ;
}
object _1 . map = map ;
/ * *
* @ desc gibt ein Objekt mit bestimmten Einträgen des Eingabe - Objekts zurück
* @ author fenris
* /
function filter ( object _from , predicate ) {
var object _to = { } ;
Object . keys ( object _from ) . forEach ( function ( key ) {
var value = object _from [ key ] ;
if ( predicate ( value , key ) ) {
object _to [ key ] = value ;
}
} ) ;
return object _to ;
}
object _1 . filter = filter ;
/ * *
* @ desc wandelt ein Array mit Einträgen der Form { key , value } in ein entsprechendes Objekt um
* @ author fenris
* /
function from _array ( array ) {
var object = { } ;
array . forEach ( function ( entry ) { return ( object [ entry . key ] = entry . value ) ; } ) ;
return object ;
}
object _1 . from _array = from _array ;
/ * *
* @ desc wandelt ein Objekt in ein entsprechendes Array mit Einträgen der Form { key , value } um
* @ author fenris
* /
function to _array ( object ) {
var array = [ ] ;
Object . keys ( object ) . forEach ( function ( key ) { return array . push ( { "key" : key , "value" : object [ key ] } ) ; } ) ;
return array ;
}
object _1 . to _array = to _array ;
/ * *
* @ desc gibt eine Liste von Schlüsseln eines Objekts zurück
* @ author fenris
* /
function keys ( object ) {
return Object . keys ( object ) ;
}
object _1 . keys = keys ;
/ * *
* @ desc gibt eine Liste von Werten eines Objekts zurück
* @ author fenris
* /
function values ( object ) {
return to _array ( object ) . map ( function ( entry ) { return entry . value ; } ) ;
}
object _1 . values = values ;
/ * *
* @ desc liest ein Baum - artiges Objekt an einer bestimmten Stelle aus
* @ author fenris
* /
function path _read ( object , path , fallback , escalation ) {
if ( fallback === void 0 ) { fallback = null ; }
if ( escalation === void 0 ) { escalation = 1 ; }
var steps = ( ( path . length == 0 ) ? [ ] : path . split ( "." ) ) ;
if ( steps . length == 0 ) {
throw ( new Error ( "empty path" ) ) ;
}
else {
var position _1 = object ;
var reachable = ( position _1 != null ) && steps . slice ( 0 , steps . length - 1 ) . every ( function ( step ) {
position _1 = lib _plankton . object . fetch ( position _1 , step , null , 0 ) ;
return ( position _1 != null ) ;
} ) ;
if ( reachable ) {
return lib _plankton . object . fetch ( position _1 , steps [ steps . length - 1 ] , fallback , escalation ) ;
}
else {
return lib _plankton . object . fetch ( { } , "_dummy_" , fallback , escalation ) ;
}
}
}
object _1 . path _read = path _read ;
/ * *
* @ desc schreibt einen Wert an eine bestimmte Stelle in einem Baum - artigen Objekt
* @ author fenris
* /
function path _write ( object , path , value , construct ) {
if ( construct === void 0 ) { construct = true ; }
var steps = ( ( path . length == 0 ) ? [ ] : path . split ( "." ) ) ;
if ( steps . length == 0 ) {
throw ( new Error ( "empty path" ) ) ;
}
else {
var position _2 = object ;
var reachable = steps . slice ( 0 , steps . length - 1 ) . every ( function ( step ) {
var position _ = lib _plankton . object . fetch ( position _2 , step , null , 0 ) ;
if ( position _ == null ) {
if ( construct ) {
position _2 [ step ] = { } ;
position _2 = position _2 [ step ] ;
return true ;
}
else {
return false ;
}
}
else {
position _2 = position _ ;
return true ;
}
} ) ;
if ( reachable ) {
position _2 [ steps [ steps . length - 1 ] ] = value ;
}
else {
var message = ( "path '" . concat ( path , "' does not exist and may not be constructed" ) ) ;
throw ( new Error ( message ) ) ;
}
}
}
object _1 . path _write = path _write ;
/ * *
* @ desc prüft ob ein Objekt einem bestimmten Muster entspricht
* @ param { Object } object das zu prüfende Objekt
* @ param { Object } pattern das einzuhaltende Muster
* @ param { Function } connlate eine Funktion zum Feststellen der Gleichheit von Einzelwerten
* @ author fenris
* /
function matches ( object , pattern , collate ) {
if ( collate === void 0 ) { collate = instance _collate ; }
return Object . keys ( pattern ) . every ( function ( key ) { return collate ( pattern [ key ] , object [ key ] ) ; } ) ;
}
object _1 . matches = matches ;
/ * *
* @ desc erzeugt eine Projektion eines Baum - artigen Objekts in ein Listen - artiges Objekt
* @ param { string } [ separator ] welches Zeichen als Trenner zwischen zwei Pfad - Schritten verwendet werden soll
* @ author fenris
* /
function flatten ( value , separator , key _for _element ) {
if ( separator === void 0 ) { separator = "." ; }
if ( key _for _element === void 0 ) { key _for _element = ( function ( index ) { return ( "element_" + index . toFixed ( 0 ) ) ; } ) ; }
var integrate = function ( result , key _ , value _ ) {
if ( value _ == null ) {
result [ key _ ] = value _ ;
}
else {
// primitive Werte direkt übernehmen
if ( typeof ( value _ ) != "object" ) {
result [ key _ ] = value _ ;
}
// sonst durch rekursiven Aufruf die flache Variante des Wertes ermitteln und einarbeiten
else {
var result _1 = flatten ( value _ ) ;
Object . keys ( result _1 )
. forEach ( function ( key _ _ ) {
var value _ _ = result _1 [ key _ _ ] ;
var key _new = ( key _ + separator + key _ _ ) ;
result [ key _new ] = value _ _ ;
} ) ;
}
}
} ;
if ( ( value === null ) || ( value === undefined ) ) {
return null ;
}
else {
var result _2 = { } ;
if ( typeof ( value ) != "object" ) {
result _2 [ "value" ] = value ;
}
else {
if ( value instanceof Array ) {
var array = ( value ) ;
array
. forEach ( function ( element , index ) {
integrate ( result _2 , key _for _element ( index ) , element ) ;
} ) ;
}
else {
var object _2 = ( value ) ;
Object . keys ( object _2 )
. forEach ( function ( key ) {
integrate ( result _2 , key , object _2 [ key ] ) ;
} ) ;
}
}
return result _2 ;
}
}
object _1 . flatten = flatten ;
/ * *
* @ author fenris
* /
function clash ( x , y , _a ) {
var _b = _a === void 0 ? { } : _a , _c = _b [ "overwrite" ] , overwrite = _c === void 0 ? true : _c , _d = _b [ "hooks" ] , _e = _d === void 0 ? { } : _d , _f = _e [ "existing" ] , hook _existing = _f === void 0 ? null : _f ;
if ( hook _existing == null ) {
( function ( key , value _old , value _new ) { return console . warn ( "field " . concat ( key , " already defined" ) ) ; } ) ;
}
var z = { } ;
Object . keys ( x ) . forEach ( function ( key ) {
z [ key ] = x [ key ] ;
} ) ;
Object . keys ( y ) . forEach ( function ( key ) {
if ( key in z ) {
if ( hook _existing != null ) {
hook _existing ( key , z [ key ] , y [ key ] ) ;
}
if ( overwrite ) {
z [ key ] = y [ key ] ;
}
}
else {
z [ key ] = y [ key ] ;
}
} ) ;
return z ;
}
object _1 . clash = clash ;
/ * *
* @ author fenris
* /
function patch ( core , mantle , deep , path ) {
if ( deep === void 0 ) { deep = true ; }
if ( path === void 0 ) { path = null ; }
if ( mantle == null ) {
console . warn ( "mantle is null; core was" , core ) ;
}
else {
Object . keys ( mantle ) . forEach ( function ( key ) {
var path _ = ( ( path == null ) ? key : "" . concat ( path , "." ) . concat ( key ) ) ;
var value _mantle = mantle [ key ] ;
if ( ! ( key in core ) ) {
if ( ( typeof ( value _mantle ) == "object" ) && ( value _mantle != null ) && deep ) {
if ( value _mantle instanceof Array ) {
core [ key ] = [ ] ;
value _mantle . forEach ( function ( element ) {
if ( ( typeof ( element ) == "object" ) && ( element != null ) ) {
var element _ = { } ;
patch ( element _ , element ) ;
core [ key ] . push ( element _ ) ;
}
else {
core [ key ] . push ( element ) ;
}
} ) ;
}
else {
core [ key ] = { } ;
patch ( core [ key ] , value _mantle , deep , path _ ) ;
}
}
else {
core [ key ] = value _mantle ;
}
}
else {
var value _core = core [ key ] ;
if ( typeof ( value _core ) == typeof ( value _mantle ) ) {
if ( ( typeof ( value _mantle ) == "object" ) && ( value _mantle != null ) && deep ) {
patch ( core [ key ] , value _mantle , deep , path _ ) ;
}
else {
core [ key ] = value _mantle ;
}
}
else {
if ( ( value _core != null ) && ( value _mantle != null ) ) {
var message = "objects have different shapes at path '" . concat ( path _ , "'; core has type '" ) . concat ( typeof ( value _core ) , "' and mantle has type '" ) . concat ( typeof ( value _mantle ) , "'" ) ;
console . warn ( message ) ;
}
core [ key ] = value _mantle ;
// throw (new Error(message));
}
}
} ) ;
}
}
object _1 . patch = patch ;
/ * *
* @ author fenris
* /
function patched ( core , mantle , deep ) {
if ( deep === void 0 ) { deep = undefined ; }
var result = { } ;
patch ( result , core , deep ) ;
patch ( result , mantle , deep ) ;
return result ;
}
object _1 . patched = patched ;
/ * *
* @ author fenris
* /
function attached ( object , key , value ) {
var mantle = { } ;
mantle [ key ] = value ;
return patched ( object , mantle , false ) ;
}
object _1 . attached = attached ;
/ * *
* @ author fenris
* /
function copy ( object ) {
return patched ( { } , object ) ;
}
object _1 . copy = copy ;
} ) ( object = lib _plankton . object || ( lib _plankton . object = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : translate « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : translate « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : translate « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : translate « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var translate ;
( function ( translate ) {
/ * *
* @ desc contains the sets of strings
* @ author fenris
* /
var _packages = { } ;
/ * *
* @ desc specifies in which order the languages shall be queried ; if getting a string from language # 0 fails , the
* system tries to get it from language # 1 , and so on
* @ author fenris
* /
var _order = [ ] ;
/ * *
* @ desc whether to automatically promote the language of a newly added package
* @ author fenris
* /
var _autopromote = false ;
/ * *
* @ desc the level of verbosity , specifiying how much output the system shall provide about its actions
* @ author fenris
* /
translate . _verbosity = 1 ;
/ * *
* @ desc which initial string to use for log - outputs
* @ author fenris
* /
var _logprefix = "[lib_translate]" ;
/ * *
* @ desc moves a language to the top of the order , making it the primary one
* @ author fenris
* /
function promote ( identifier ) {
if ( Object . keys ( _packages ) . indexOf ( identifier ) < 0 ) {
if ( translate . _verbosity >= 1 ) {
console . warn ( ` ${ _logprefix } package ' ${ identifier } ' doesn't exist yet ` ) ;
}
}
let position = _order . indexOf ( identifier ) ;
if ( position >= 0 ) {
if ( translate . _verbosity >= 2 ) {
console . info ( ` ${ _logprefix } ' ${ identifier } ' already in order; will promote it ` ) ;
}
_order . splice ( position , 1 ) ;
}
_order . unshift ( identifier ) ;
if ( translate . _verbosity >= 2 ) {
console . info ( ` ${ _logprefix } order is now ${ _order . toString ( ) } ` ) ;
}
}
translate . promote = promote ;
/ * *
* @ desc adds a package to the sytem
* @ author fenris
* /
function add ( package _ ) {
let identifier = package _ . meta . identifier ;
if ( identifier in _packages ) {
if ( translate . _verbosity >= 1 ) {
console . warn ( ` ${ _logprefix } package ' ${ identifier } ' has already been added; will overwrite ` ) ;
}
}
else {
if ( translate . _verbosity >= 2 ) {
console . log ( ` ${ _logprefix } got package ' ${ identifier } ' ` ) ;
}
}
_packages [ identifier ] = package _ ;
if ( _autopromote ) {
promote ( identifier ) ;
}
}
translate . add = add ;
/ * *
* @ desc integrates a package to the system , i . e . creates a new one if none existed so far or merges with an existing one
* @ author fenris
* /
function feed ( package _ ) {
let identifier = package _ . meta . identifier ;
if ( identifier in _packages ) {
lib _plankton . object . patch ( _packages [ identifier ] . tree , package _ . tree , true ) ;
}
else {
if ( translate . _verbosity >= 2 ) {
console . info ( ` ${ _logprefix } package ' ${ identifier } ' didn't exist so far; will create it now ` ) ;
}
add ( package _ ) ;
}
}
translate . feed = feed ;
/ * *
* @ desc tries to retrieve a translation for a specific package identifier
* @ author fenris
* /
function fetch ( identifier , path , args = { } ) {
if ( ! ( identifier in _packages ) ) {
if ( translate . _verbosity >= 1 ) {
console . warn ( ` ${ _logprefix } no package ' ${ identifier } ' ` ) ;
}
return ( lib _plankton . pod . make _empty ( ) ) ;
}
else {
// let str : string = lib_plankton.object.path_read<string>(_packages[identifier].tree, path);
let str = _packages [ identifier ] . tree [ path ] ;
if ( str == undefined ) {
if ( translate . _verbosity >= 1 ) {
console . warn ( ` ${ _logprefix } string ' ${ path } ' missing in package ' ${ identifier } ' ` ) ;
}
return ( lib _plankton . pod . make _empty ( ) ) ;
}
else {
// resolve references
{
let regexp _reference = new RegExp ( "#\\(([\\w\\.]*)(?:\\?(\\w+)=(\\w+)(?:&(\\w+)=(\\w+))*)?\\)" ) ;
while ( true ) {
let matching = regexp _reference . exec ( str ) ;
if ( matching != null ) {
let path _ = matching [ 1 ] ;
let args _ = { } ;
if ( translate . _verbosity >= 2 ) {
// console.info(`${_logprefix} found reference to '${path_}' with args ${JSON.stringify(args_)}`);
console . info ( ` ${ _logprefix } found reference to ' ${ path _ } ' ` ) ;
}
// parse args
{
for ( let index = 2 ; index <= matching . length - 1 ; index += 2 ) {
let id = matching [ index + 0 ] ;
let value = matching [ index + 1 ] ;
if ( id != undefined ) {
args _ [ id ] = value ;
}
}
}
// fetch referenced string
{
let result _ = fetch ( identifier , path _ , args _ ) ;
if ( lib _plankton . pod . is _filled ( result _ ) ) {
let front = str . slice ( 0 , matching . index ) ;
let back = str . slice ( matching . index + matching [ 0 ] . length ) ;
str = ( front + lib _plankton . pod . cull ( result _ ) + back ) ;
}
else {
return ( lib _plankton . pod . make _empty ( ) ) ;
break ;
}
}
}
else {
break ;
}
}
}
// insert arguments
{
str = lib _plankton . string . coin ( str , args ) ;
}
return ( lib _plankton . pod . make _filled ( str ) ) ;
}
}
}
translate . fetch = fetch ;
/ * *
* @ desc retrieves a string by going through the order and trying to fetch it for the current entry
* @ author fenris
* /
function get ( path , args = { } , fallback = null ) {
if ( fallback == null ) {
fallback = ` { ${ path } } ` ;
}
if ( translate . _verbosity >= 2 ) {
console . info ( ` ${ _logprefix } getting translation for string ' ${ path } ' with arguments ${ JSON . stringify ( args ) } … ` ) ;
}
let result = lib _plankton . pod . make _empty ( ) ;
let found = _order . some ( identifier => {
if ( translate . _verbosity >= 2 ) {
console . info ( ` ${ _logprefix } trying package ' ${ identifier } ' … ` ) ;
}
let result _ = fetch ( identifier , path , args ) ;
if ( lib _plankton . pod . is _filled ( result _ ) ) {
result = result _ ;
return true ;
}
else {
return false ;
}
} ) ;
if ( found ) {
let str = lib _plankton . pod . cull ( result ) ;
if ( translate . _verbosity >= 3 ) {
console . info ( ` ${ _logprefix } found translation: ' ${ str } ' ` ) ;
}
return str ;
}
else {
let str = fallback ;
if ( translate . _verbosity >= 1 ) {
console . warn ( ` ${ _logprefix } no package provides a translation for string ' ${ path } '; will use the fallback translation ' ${ str } ' ` ) ;
}
return str ;
}
}
translate . get = get ;
/ * *
* @ author fenris
* /
function list ( ) {
return lib _plankton . object . to _array ( _packages ) . map ( x => x . value . meta ) ;
}
translate . list = list ;
/ * *
* @ author fenris
* @ todo get rid of this ; it ' s currenly needed only for the cdh - internal lib _completion
* /
function paths ( ) {
return lib _plankton . object . keys ( lib _plankton . object . flatten ( _packages [ _order [ 0 ] ] . tree ) ) ;
}
translate . paths = paths ;
/ * *
* @ author fenris
* /
function initialize ( { "logprefix" : logprefix = undefined , "verbosity" : verbosity = undefined , "packages" : packages = [ ] , "order" : order = undefined , "autopromote" : autopromote = undefined , } = { } ) {
return ( Promise . resolve ( undefined )
// set variables
. then ( _ => {
if ( logprefix != undefined )
_logprefix = logprefix ;
if ( verbosity != undefined )
translate . _verbosity = verbosity ;
// _packages = {};
if ( order != undefined )
_order = order ;
if ( autopromote != undefined )
_autopromote = autopromote ;
return Promise . resolve ( undefined ) ;
} )
// feed
. then ( _ => {
packages . forEach ( feed ) ;
return Promise . resolve ( undefined ) ;
} ) ) ;
}
translate . initialize = initialize ;
} ) ( translate = lib _plankton . translate || ( lib _plankton . translate = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : translate « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : translate « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : translate « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : translate « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var translate ;
( function ( translate ) {
/ * *
* @ author fenris
* /
function iso _639 _1 _to _iso _639 _2 ( iso6391 ) {
let mapping = {
"af" : "afr" ,
"ar" : "ara" ,
"bg" : "bul" ,
"cs" : "ces" ,
"da" : "dan" ,
"de" : "deu" ,
"el" : "ell" ,
"en" : "eng" ,
"eo" : "epo" ,
"es" : "esp" ,
"fa" : "fas" ,
"fi" : "fin" ,
"fr" : "fra" ,
"hi" : "hin" ,
"hr" : "hrv" ,
"hu" : "hun" ,
"is" : "isl" ,
"it" : "ita" ,
"ja" : "jpn" ,
"ko" : "kor" ,
"nb" : "nob" ,
"nl" : "nld" ,
"nn" : "nno" ,
"pt" : "por" ,
"pl" : "pol" ,
"ro" : "ron" ,
"ru" : "rus" ,
"sk" : "slk" ,
"sv" : "swe" ,
"zh" : "zho" ,
} ;
return mapping [ iso6391 ] ;
}
translate . iso _639 _1 _to _iso _639 _2 = iso _639 _1 _to _iso _639 _2 ;
/ * *
* @ author fenris
* /
function stance ( str ) {
let regexp = new RegExp ( "^translate:(.*)$" ) ;
let matching = regexp . exec ( str ) ;
if ( matching != null ) {
return translate . get ( matching [ 1 ] ) ;
}
else {
return str ;
}
}
translate . stance = stance ;
} ) ( translate = lib _plankton . translate || ( lib _plankton . translate = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
2024-04-22 10:02:43 +02:00
This file is part of » bacterio - plankton : database « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : database « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : database « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : database « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var database ;
( function ( database ) {
/ * *
* /
let enum _type ;
( function ( enum _type ) {
enum _type [ "boolean" ] = "boolean" ;
enum _type [ "integer" ] = "integer" ;
enum _type [ "string_short" ] = "string_short" ;
enum _type [ "string_medium" ] = "string_medium" ;
enum _type [ "string_long" ] = "string_long" ;
enum _type [ "float" ] = "float" ;
} ) ( enum _type = database . enum _type || ( database . enum _type = { } ) ) ;
} ) ( database = lib _plankton . database || ( lib _plankton . database = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : storage « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : storage « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : storage « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : storage « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : storage « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : storage « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : storage « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : storage « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : storage « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : storage « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : storage « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : storage « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var storage ;
( function ( storage ) {
var memory ;
( function ( memory ) {
/ * *
* @ author fenris
* /
function make ( parameters ) {
return {
"data" : { }
} ;
}
memory . make = make ;
/ * *
* @ author fenris
* /
function clear ( subject ) {
subject . data = { } ;
}
memory . clear = clear ;
/ * *
* @ author fenris
* /
function write ( subject , key , value ) {
var exists = ( key in subject . data ) ;
subject . data [ key ] = value ;
return exists ;
}
memory . write = write ;
/ * *
* @ author fenris
* /
function delete _ ( subject , key ) {
if ( ! ( key in subject . data ) ) {
throw ( new Error ( "no value for key '" + key + "'" ) ) ;
}
else {
delete subject . data [ key ] ;
}
}
memory . delete _ = delete _ ;
/ * *
* @ author fenris
* /
function read ( subject , key ) {
if ( ! ( key in subject . data ) ) {
throw ( new Error ( "no value for key '" + key + "'" ) ) ;
}
else {
return subject . data [ key ] ;
}
}
memory . read = read ;
/ * *
* @ author fenris
* /
function list ( subject ) {
return Object . keys ( subject . data ) ;
}
memory . list = list ;
/ * *
* @ author fenris
* /
function search ( subject , term ) {
return ( list ( subject )
. map ( function ( key ) { return ( { "key" : key , "preview" : key } ) ; } ) ) ;
}
memory . search = search ;
/ * *
* @ author fenris
* /
function implementation _chest ( parameters ) {
function wrap ( core ) {
return ( new Promise ( function ( resolve , reject ) { resolve ( core ( ) ) ; } ) ) ;
}
var subject = make ( parameters ) ;
return {
"setup" : function ( input ) { return Promise . resolve ( undefined ) ; } ,
"clear" : function ( ) { return wrap ( function ( ) { return clear ( subject ) ; } ) ; } ,
"write" : function ( key , value ) { return wrap ( function ( ) { return write ( subject , key , value ) ; } ) ; } ,
"delete" : function ( key ) { return wrap ( function ( ) { return delete _ ( subject , key ) ; } ) ; } ,
"read" : function ( key ) { return wrap ( function ( ) { return read ( subject , key ) ; } ) ; } ,
"search" : function ( term ) { return wrap ( function ( ) { return search ( subject , term ) ; } ) ; }
} ;
}
memory . implementation _chest = implementation _chest ;
} ) ( memory = storage . memory || ( storage . memory = { } ) ) ;
} ) ( storage = lib _plankton . storage || ( lib _plankton . storage = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : storage « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : storage « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : storage « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : storage « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var storage ;
( function ( storage ) {
var memory ;
( function ( memory ) {
/ * *
* @ author fenris
* /
var class _chest = /** @class */ ( function ( ) {
function class _chest ( parameters ) {
this . subject = memory . make ( parameters ) ;
}
class _chest . prototype . setup = function ( input ) { return Promise . resolve ( undefined ) ; } ;
class _chest . prototype . clear = function ( ) { memory . clear ( this . subject ) ; return Promise . resolve ( undefined ) ; } ;
class _chest . prototype . write = function ( key , value ) { return Promise . resolve ( memory . write ( this . subject , key , value ) ) ; } ;
class _chest . prototype [ "delete" ] = function ( key ) { memory . delete _ ( this . subject , key ) ; return Promise . resolve ( undefined ) ; } ;
class _chest . prototype . read = function ( key ) { return Promise . resolve ( memory . read ( this . subject , key ) ) ; } ;
class _chest . prototype . search = function ( term ) { return Promise . resolve ( memory . search ( this . subject , term ) ) ; } ;
return class _chest ;
} ( ) ) ;
memory . class _chest = class _chest ;
} ) ( memory = storage . memory || ( storage . memory = { } ) ) ;
} ) ( storage = lib _plankton . storage || ( lib _plankton . storage = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : storage « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : storage « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : storage « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : storage « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var storage ;
( function ( storage ) {
var localstorage ;
( function ( localstorage ) {
/ * *
* @ author fenris
* /
function make ( parameters ) {
parameters = Object . assign ( {
"corner" : "plankton"
} , parameters ) ;
return {
"corner" : parameters . corner
} ;
}
localstorage . make = make ;
/ * *
* /
function compose _full _key ( subject , key ) {
return ( subject . corner + "_" + key ) ;
}
/ * *
* /
function decompose _full _key ( subject , full _key ) {
var parts = full _key . split ( "_" ) ;
return ( ( parts [ 0 ] === subject . corner )
? parts . slice ( 1 ) . join ( "_" )
: null ) ;
}
/ * *
* @ author fenris
* /
function has ( subject , key ) {
return localStorage . hasOwnProperty ( compose _full _key ( subject , key ) ) ;
}
/ * *
* @ author fenris
* /
function clear ( subject ) {
( Object . keys ( localStorage )
. map ( function ( x ) { return decompose _full _key ( subject , x ) ; } )
. filter ( function ( x ) { return ( x !== null ) ; } )
. forEach ( function ( x ) { return localStorage . removeItem ( x ) ; } ) ) ;
}
localstorage . clear = clear ;
/ * *
* @ author fenris
* /
function write ( subject , key , item ) {
var exists = has ( subject , key ) ;
localStorage . setItem ( compose _full _key ( subject , key ) , item ) ;
return exists ;
}
localstorage . write = write ;
/ * *
* @ author fenris
* /
function delete _ ( subject , key ) {
localStorage . removeItem ( compose _full _key ( subject , key ) ) ;
}
localstorage . delete _ = delete _ ;
/ * *
* @ author fenris
* /
function read ( subject , key ) {
var full _key = compose _full _key ( subject , key ) ;
if ( ! localStorage . hasOwnProperty ( full _key ) ) {
throw ( new Error ( "not found" ) ) ;
}
else {
return localStorage . getItem ( full _key ) ;
}
}
localstorage . read = read ;
/ * *
* @ author fenris
* /
function list ( subject ) {
return ( Object . keys ( localStorage )
. map ( function ( x ) { return decompose _full _key ( subject , x ) ; } )
. filter ( function ( x ) { return ( x !== null ) ; } ) ) ;
}
localstorage . list = list ;
/ * *
* /
function implementation _chest ( parameters ) {
function wrap ( core ) {
return ( new Promise ( function ( resolve , reject ) { resolve ( core ( ) ) ; } ) ) ;
}
var subject = make ( parameters ) ;
return {
"setup" : function ( input ) { return Promise . resolve ( undefined ) ; } ,
"clear" : function ( ) { return wrap ( function ( ) { return clear ( subject ) ; } ) ; } ,
"write" : function ( key , item ) { return wrap ( function ( ) { return write ( subject , key , item ) ; } ) ; } ,
"delete" : function ( key ) { return wrap ( function ( ) { return delete _ ( subject , key ) ; } ) ; } ,
"read" : function ( key ) { return wrap ( function ( ) { return read ( subject , key ) ; } ) ; } ,
"search" : function ( term ) { return Promise . resolve ( list ( subject )
. map ( function ( key ) { return ( { "key" : key , "preview" : key } ) ; } ) ) ; }
} ;
}
localstorage . implementation _chest = implementation _chest ;
} ) ( localstorage = storage . localstorage || ( storage . localstorage = { } ) ) ;
} ) ( storage = lib _plankton . storage || ( lib _plankton . storage = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : storage « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : storage « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : storage « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : storage « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var storage ;
( function ( storage ) {
var localstorage ;
( function ( localstorage ) {
/ * *
* uses the browsers localstorage as chest
*
* @ author fenris
* /
var class _chest = /** @class */ ( function ( ) {
function class _chest ( parameters ) {
this . subject = localstorage . make ( parameters ) ;
}
class _chest . prototype . setup = function ( input ) { return Promise . resolve ( undefined ) ; } ;
class _chest . prototype . clear = function ( ) { return Promise . resolve ( localstorage . clear ( this . subject ) ) ; } ;
class _chest . prototype . write = function ( key , value ) { return Promise . resolve ( localstorage . write ( this . subject , key , value ) ) ; } ;
class _chest . prototype [ "delete" ] = function ( key ) { return Promise . resolve ( localstorage . delete _ ( this . subject , key ) ) ; } ;
class _chest . prototype . read = function ( key ) { return Promise . resolve ( localstorage . read ( this . subject , key ) ) ; } ;
class _chest . prototype . search = function ( term ) {
return Promise . resolve ( localstorage . list ( this . subject )
. map ( function ( key ) { return ( { "key" : key , "preview" : key } ) ; } ) ) ;
} ;
return class _chest ;
} ( ) ) ;
localstorage . class _chest = class _chest ;
} ) ( localstorage = storage . localstorage || ( storage . localstorage = { } ) ) ;
} ) ( storage = lib _plankton . storage || ( lib _plankton . storage = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* @ author fenris
* /
class class _input _wrapped {
/ * *
* /
constructor ( core , wrap , unwrap , options = { } ) {
options = Object . assign ( { } , options ) ;
this . core = core ;
this . wrap = wrap ;
this . unwrap = unwrap ;
}
/ * *
* [ implementation ]
* /
setup ( parent ) {
return this . core . setup ( parent ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
return ( this . core . read ( )
. then ( value _inner => Promise . resolve ( this . wrap ( value _inner ) ) ) ) ;
}
/ * *
* [ implementation ]
* /
write ( value ) {
return this . core . write ( this . unwrap ( value ) ) ;
}
}
zoo _input . class _input _wrapped = class _input _wrapped ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* @ author fenris
* /
class class _input _hidden {
/ * *
* /
constructor ( options = { } ) {
options = Object . assign ( {
"initial_value" : null ,
} , options ) ;
this . dom _input = null ;
this . value = options . initial _value ;
}
/ * *
* [ implementation ]
* /
setup ( parent ) {
this . dom _input = document . createElement ( "input" ) ;
this . dom _input . setAttribute ( "type" , "hidden" ) ;
parent . appendChild ( this . dom _input ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
return Promise . resolve ( this . value ) ;
}
/ * *
* [ implementation ]
* /
write ( value ) {
this . value = value ;
return Promise . resolve ( undefined ) ;
}
}
zoo _input . class _input _hidden = class _input _hidden ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* @ author fenris
* @ todo abstract
* /
class class _input _text {
/ * *
* /
constructor ( options = { } ) {
options = Object . assign ( {
"read_only" : false ,
"pattern" : null ,
// "autocompletion_list": null,
} , options ) ;
this . read _only = options . read _only ;
this . pattern = options . pattern ;
// this.autocompletion_list = options.autocompletion_list;
this . dom _input = null ;
}
/ * *
* [ implementation ]
* /
setup ( parent ) {
this . dom _input = document . createElement ( "input" ) ;
this . dom _input . setAttribute ( "type" , "text" ) ;
{
if ( ! this . read _only ) {
// do nothing
}
else {
this . dom _input . setAttribute ( "disabled" , "disabled" ) ;
}
}
{
if ( this . pattern === null ) {
// do nothing
}
else {
this . dom _input . setAttribute ( "pattern" , this . pattern ) ;
}
}
{
/ *
if ( this . autocompletion _list === null ) {
// do nothing
}
else {
const autocomplete : class _autocomplete = new class _autocomplete (
this . dom _input ,
this . autocompletion _list
) ;
autocomplete . init ( ) ;
}
* /
}
parent . appendChild ( this . dom _input ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
return Promise . resolve ( this . dom _input . value ) ;
}
/ * *
* [ implementation ]
* /
write ( value ) {
this . dom _input . value = value ;
return Promise . resolve ( undefined ) ;
}
}
zoo _input . class _input _text = class _input _text ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* @ author fenris
* /
class class _input _email {
/ * *
* /
constructor ( ) {
this . dom _input = null ;
}
/ * *
* [ implementation ]
* /
setup ( parent ) {
this . dom _input = document . createElement ( "input" ) ;
this . dom _input . setAttribute ( "type" , "email" ) ;
parent . appendChild ( this . dom _input ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
return Promise . resolve ( this . dom _input . value ) ;
}
/ * *
* [ implementation ]
* /
write ( value ) {
this . dom _input . value = value ;
return Promise . resolve ( undefined ) ;
}
}
zoo _input . class _input _email = class _input _email ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* @ author fenris
* /
class class _input _textarea {
/ * *
* /
constructor ( ) {
this . dom _textarea = null ;
}
/ * *
* [ implementation ]
* /
setup ( parent ) {
this . dom _textarea = document . createElement ( "textarea" ) ;
parent . appendChild ( this . dom _textarea ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
return Promise . resolve ( this . dom _textarea . value ) ;
}
/ * *
* [ implementation ]
* /
write ( value ) {
this . dom _textarea . value = value ;
return Promise . resolve ( undefined ) ;
}
}
zoo _input . class _input _textarea = class _input _textarea ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* /
function value _decode ( datestring ) {
const parts = datestring . split ( "-" ) ;
return {
"year" : parseInt ( parts [ 0 ] ) ,
"month" : parseInt ( parts [ 1 ] ) ,
"day" : parseInt ( parts [ 2 ] ) ,
} ;
}
/ * *
* /
function value _encode ( date ) {
return lib _plankton . string . coin ( "{{year}}-{{month}}-{{day}}" , {
"year" : date . year . toFixed ( 0 ) . padStart ( 4 , "0" ) ,
"month" : date . month . toFixed ( 0 ) . padStart ( 2 , "0" ) ,
"day" : date . day . toFixed ( 0 ) . padStart ( 2 , "0" ) ,
} ) ;
}
/ * *
* @ author fenris
* /
class class _input _date {
/ * *
* /
constructor ( options = { } ) {
options = Object . assign ( {
"required" : false ,
} , options ) ;
this . required = options . required ;
this . dom _input = null ;
}
/ * *
* [ implementation ]
* /
setup ( parent ) {
this . dom _input = document . createElement ( "input" ) ;
this . dom _input . setAttribute ( "type" , "date" ) ;
if ( ! this . required ) {
// do nothing
}
else {
this . dom _input . setAttribute ( "required" , "required" ) ;
}
parent . appendChild ( this . dom _input ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
if ( this . required && ( ! this . dom _input . reportValidity ( ) ) ) {
return Promise . reject ( "required" ) ;
}
else {
return Promise . resolve ( ( this . dom _input . value === "" )
? null
: value _decode ( this . dom _input . value ) ) ;
}
}
/ * *
* [ implementation ]
* /
write ( value ) {
this . dom _input . value = ( ( value === null )
? ""
: value _encode ( value ) ) ;
return Promise . resolve ( undefined ) ;
}
}
zoo _input . class _input _date = class _input _date ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* @ author fenris
* @ todo abstract
* /
class class _input _number {
/ * *
* /
constructor ( options = { } ) {
options = Object . assign ( {
"read_only" : false ,
"step" : null ,
} , options ) ;
this . read _only = options . read _only ;
this . step = options . step ;
this . dom _input = null ;
}
/ * *
* [ implementation ]
* /
setup ( parent ) {
this . dom _input = document . createElement ( "input" ) ;
this . dom _input . setAttribute ( "type" , "number" ) ;
// readonly
{
if ( ! this . read _only ) {
// do nothing
}
else {
this . dom _input . setAttribute ( "disabled" , "disabled" ) ;
}
}
// step
{
if ( this . step === null ) {
// do nothing
}
else {
this . dom _input . setAttribute ( "step" , this . step . toString ( ) ) ;
}
}
parent . appendChild ( this . dom _input ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
return Promise . resolve ( Number ( this . dom _input . value ) ) ;
}
/ * *
* [ implementation ]
* /
write ( value ) {
this . dom _input . value = value . toString ( ) ;
return Promise . resolve ( undefined ) ;
}
}
zoo _input . class _input _number = class _input _number ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* @ author fenris
* /
class class _input _checkbox {
/ * *
* /
2024-04-24 08:33:22 +02:00
constructor ( options = { } ) {
options = Object . assign ( {
"read_only" : false ,
2024-04-25 23:30:16 +02:00
"hooks_change" : [ ] ,
2024-04-24 08:33:22 +02:00
} , options ) ;
this . read _only = options . read _only ;
2024-04-22 10:02:43 +02:00
this . dom _input = null ;
2024-04-25 23:30:16 +02:00
this . hooks _change = options . hooks _change ;
2024-04-22 10:02:43 +02:00
}
/ * *
* [ implementation ]
* /
setup ( parent ) {
this . dom _input = document . createElement ( "input" ) ;
this . dom _input . setAttribute ( "type" , "checkbox" ) ;
2024-04-24 08:33:22 +02:00
{
if ( this . read _only ) {
this . dom _input . setAttribute ( "disabled" , "disabled" ) ;
}
else {
// do nothing
}
}
2024-04-25 23:30:16 +02:00
this . dom _input . addEventListener ( "change" , ( event ) => {
const value = event . target . checked ;
this . hooks _change . forEach ( procedure => {
procedure ( value ) ;
} ) ;
} ) ;
2024-04-22 10:02:43 +02:00
// this.dom_input.style.display = "initial"; // n3o!!!
parent . appendChild ( this . dom _input ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
return Promise . resolve ( this . dom _input . checked ) ;
}
/ * *
* [ implementation ]
* /
write ( value ) {
this . dom _input . checked = value ;
return Promise . resolve ( undefined ) ;
}
}
zoo _input . class _input _checkbox = class _input _checkbox ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* @ author fenris
* /
class class _input _selection {
/ * *
* /
constructor ( options ) {
this . options = options ;
this . dom _select = null ;
}
/ * *
* [ implementation ]
* /
setup ( parent ) {
this . dom _select = document . createElement ( "select" ) ;
this . options . forEach ( ( option ) => {
let dom _option = document . createElement ( "option" ) ;
dom _option . setAttribute ( "value" , option . value ) ;
dom _option . textContent = option . label ;
this . dom _select . appendChild ( dom _option ) ;
} ) ;
parent . appendChild ( this . dom _select ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
return Promise . resolve ( this . dom _select . value ) ;
}
/ * *
* [ implementation ]
* /
write ( value ) {
this . dom _select . value = value ;
return Promise . resolve ( undefined ) ;
}
}
zoo _input . class _input _selection = class _input _selection ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* @ author fenris
* /
class class _input _enumeration {
/ * *
* /
constructor ( options ) {
this . options = options ;
this . dom _inputs = [ ] ;
}
/ * *
* [ implementation ]
* @ todo unique name
* /
setup ( parent ) {
let dom _container = document . createElement ( "div" ) ;
dom _container . classList . add ( "plankton_input_enumeration" ) ;
const name = "radio" ;
this . options . forEach ( ( option ) => {
let dom _label = document . createElement ( "label" ) ;
let dom _input = document . createElement ( "input" ) ;
dom _input . setAttribute ( "type" , "radio" ) ;
dom _input . setAttribute ( "name" , name ) ;
dom _input . setAttribute ( "value" , option . value ) ;
dom _label . appendChild ( dom _input ) ;
let dom _span = document . createElement ( "span" ) ;
dom _span . textContent = option . label ;
dom _label . appendChild ( dom _span ) ;
dom _container . appendChild ( dom _label ) ;
this . dom _inputs . push ( dom _input ) ;
} ) ;
parent . appendChild ( dom _container ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
const active = ( this . dom _inputs
. filter ( dom _input => dom _input . checked )
. map ( dom _input => dom _input . value ) ) ;
if ( active . length != 1 ) {
return Promise . reject ( "nothing picked" ) ;
}
else {
return Promise . resolve ( active [ 0 ] ) ;
}
}
/ * *
* [ implementation ]
* /
write ( value ) {
this . dom _inputs . forEach ( dom _input => {
dom _input . checked = ( value === dom _input . value ) ;
} ) ;
return Promise . resolve ( undefined ) ;
}
}
zoo _input . class _input _enumeration = class _input _enumeration ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* @ author fenris
* /
class class _input _list {
/ * *
* /
constructor ( element _input _factory , options = { } ) {
options = Object . assign ( {
"translations" : {
"add" : "add" ,
"remove" : "remove" ,
} ,
} , options ) ;
this . element _input _factory = element _input _factory ;
this . elements = [ ] ;
this . elements _container _dom = null ;
this . translations = options . translations ;
}
/ * *
* /
clear ( ) {
this . elements _container _dom . innerHTML = "" ;
this . elements = [ ] ;
return Promise . resolve ( undefined ) ;
}
/ * *
* /
async add ( ) {
// model
let element _dom = document . createElement ( "div" ) ;
const input = this . element _input _factory ( ) ;
this . elements . push ( { "dom" : element _dom , "input" : input } ) ;
// view & control
{
element _dom . classList . add ( "plankton_input_list_element" ) ;
// remover
{
let remover _dom = document . createElement ( "button" ) ;
remover _dom . classList . add ( "plankton_input_list_button" ) ;
remover _dom . classList . add ( "plankton_input_list_element_remover" ) ;
remover _dom . setAttribute ( "title" , this . translations . remove ) ;
remover _dom . textContent = "x" ;
remover _dom . addEventListener ( "click" , ( event ) => {
event . preventDefault ( ) ;
const index = this . elements . findIndex ( element => ( element . input === input ) ) ;
const element = this . elements [ index ] ;
this . elements _container _dom . removeChild ( element . dom ) ;
this . elements . splice ( index , 1 ) ;
} ) ;
element _dom . appendChild ( remover _dom ) ;
}
// input
{
let input _dom = document . createElement ( "div" ) ;
input _dom . classList . add ( "plankton_input_list_element_input" ) ;
await input . setup ( input _dom ) ;
element _dom . appendChild ( input _dom ) ;
}
this . elements _container _dom . appendChild ( element _dom ) ;
}
return Promise . resolve ( input ) ;
}
/ * *
* [ implementation ]
* /
setup ( parent ) {
let container _dom = document . createElement ( "div" ) ;
container _dom . classList . add ( "plankton_input_list" ) ;
// elements
{
this . elements _container _dom = document . createElement ( "div" ) ;
this . elements _container _dom . classList . add ( "plankton_input_list_elements" ) ;
container _dom . appendChild ( this . elements _container _dom ) ;
}
// foot
{
let footer _dom = document . createElement ( "div" ) ;
footer _dom . classList . add ( "plankton_input_list_foot" ) ;
// adder
{
let adder _dom = document . createElement ( "button" ) ;
adder _dom . classList . add ( "plankton_input_list_button" ) ;
adder _dom . classList . add ( "plankton_input_list_adder" ) ;
adder _dom . setAttribute ( "title" , this . translations . add ) ;
adder _dom . textContent = "+" ;
adder _dom . addEventListener ( "click" , ( event ) => {
event . preventDefault ( ) ;
this . add ( ) ;
} ) ;
footer _dom . appendChild ( adder _dom ) ;
}
container _dom . appendChild ( footer _dom ) ;
}
parent . appendChild ( container _dom ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
return ( Promise . all ( this . elements
. map ( ( element , index ) => ( element . input . read ( )
. then ( ( element _value ) => Promise . resolve ( {
"index" : index ,
"value" : element _value ,
} ) ) ) ) )
. then ( ( elements ) => Promise . resolve ( elements
. sort ( ( x , y ) => ( ( x . index <= y . index ) ? 0 : 1 ) )
. map ( element => element . value ) ) ) ) ;
}
/ * *
* [ implementation ]
* /
write ( value ) {
return ( this . clear ( )
. then ( ( ) => Promise . all ( value
. map ( ( element _value ) => ( this . add ( )
. then ( element _input => element _input . write ( element _value ) ) ) ) ) )
. then ( ( ) => Promise . resolve ( undefined ) ) ) ;
}
}
zoo _input . class _input _list = class _input _list ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* @ author fenris
* /
class class _input _password {
/ * *
* /
constructor ( ) {
this . dom _input = null ;
}
/ * *
* [ implementation ]
* /
setup ( parent ) {
this . dom _input = document . createElement ( "input" ) ;
this . dom _input . setAttribute ( "type" , "password" ) ;
parent . appendChild ( this . dom _input ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
return Promise . resolve ( this . dom _input . value ) ;
}
/ * *
* [ implementation ]
* /
write ( value ) {
this . dom _input . value = value ;
return Promise . resolve ( undefined ) ;
}
}
zoo _input . class _input _password = class _input _password ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* @ author fenris
* /
class class _input _switch {
/ * *
* /
constructor ( ) {
this . dom _element = null ;
this . value = false ;
}
/ * *
* [ implementation ]
* /
setup ( parent ) {
this . dom _element = document . createElement ( "input" ) ;
this . dom _element . setAttribute ( "type" , "text" ) ;
this . dom _element . setAttribute ( "readonly" , "readonly" ) ;
this . dom _element . addEventListener ( "click" , ( event ) => {
this . write ( ! this . value ) ;
} ) ;
parent . appendChild ( this . dom _element ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
return Promise . resolve ( this . value ) ;
}
/ * *
* [ implementation ]
* /
write ( value ) {
this . value = value ;
if ( value ) {
this . dom _element . value = "✔" ;
}
else {
this . dom _element . value = " " ;
}
return Promise . resolve ( undefined ) ;
}
}
zoo _input . class _input _switch = class _input _switch ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* /
function value _encode ( time ) {
return lib _plankton . string . coin ( "{{hour}}:{{minute}}" , {
"hour" : time . hour . toFixed ( 0 ) . padStart ( 2 , "0" ) ,
"minute" : time . minute . toFixed ( 0 ) . padStart ( 2 , "0" ) ,
} ) ;
}
/ * *
* /
function value _decode ( timestring ) {
const parts = timestring . split ( ":" ) ;
return {
"hour" : parseInt ( parts [ 0 ] ) ,
"minute" : parseInt ( parts [ 1 ] ) ,
"second" : 0 ,
} ;
}
/ * *
* @ author fenris
* /
class class _input _time {
/ * *
* /
constructor ( ) {
this . dom _input = null ;
}
/ * *
* [ implementation ]
* /
setup ( parent ) {
this . dom _input = document . createElement ( "input" ) ;
this . dom _input . setAttribute ( "type" , "time" ) ;
parent . appendChild ( this . dom _input ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
read ( ) {
return Promise . resolve ( ( this . dom _input . value === "" )
? null
: value _decode ( this . dom _input . value ) ) ;
}
/ * *
* [ implementation ]
* /
write ( value ) {
this . dom _input . value = ( ( value === null )
? ""
: value _encode ( value ) ) ;
return Promise . resolve ( undefined ) ;
}
}
zoo _input . class _input _time = class _input _time ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - input « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - input « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - input « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - input « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _input ;
( function ( zoo _input ) {
/ * *
* @ author fenris
* /
class class _input _group {
/ * *
* /
constructor ( fields _raw ) {
this . fields = ( fields _raw
. map ( field _raw => ( {
"name" : field _raw . name ,
"input" : field _raw . input ,
"label" : ( field _raw . label ? ? null ) ,
"help" : ( field _raw . help ? ? null ) ,
} ) ) ) ;
}
/ * *
* [ implementation ]
* /
async setup ( parent ) {
let dom _group = document . createElement ( "div" ) ;
dom _group . classList . add ( "plankton_input_group" ) ;
await Promise . all ( this . fields . map ( async ( field ) => {
let dom _field = document . createElement ( "div" ) ;
dom _field . classList . add ( "plankton_input_group_field" ) ;
dom _field . setAttribute ( "rel" , field . name ) ;
await Promise . all ( [
// label
new Promise ( ( resolve , reject ) => {
if ( field . label === null ) {
// do nothing
}
else {
let dom _label = document . createElement ( "label" ) ;
dom _label . classList . add ( "plankton_input_group_field_label" ) ;
dom _label . textContent = field . label ;
dom _field . appendChild ( dom _label ) ;
}
resolve ( undefined ) ;
} ) ,
// help
new Promise ( ( resolve , reject ) => {
if ( field . help === null ) {
// do nothing
}
else {
let dom _help = document . createElement ( "span" ) ;
dom _help . classList . add ( "plankton_input_group_field_help" ) ;
dom _help . textContent = "(?)" ;
dom _help . setAttribute ( "title" , field . help ) ;
dom _field . appendChild ( dom _help ) ;
}
resolve ( undefined ) ;
} ) ,
// input
field . input . setup ( dom _field ) ,
] ) ;
dom _group . appendChild ( dom _field ) ;
return Promise . resolve ( undefined ) ;
} ) ) ;
parent . appendChild ( dom _group ) ;
return Promise . resolve ( undefined ) ;
}
/ * *
* [ implementation ]
* /
async read ( ) {
return ( Promise . all ( this . fields . map ( ( field ) => ( field . input . read ( )
. then ( ( value ) => Promise . resolve ( { "key" : field . name , "value" : value } ) ) ) ) )
. then ( pairs => Promise . resolve ( Object . fromEntries ( pairs . map ( ( pair ) => ( [ pair . key , pair . value ] ) ) ) ) ) ) ;
}
/ * *
* [ implementation ]
* /
write ( value ) {
return ( Promise . resolve ( Object . entries ( value ) . map ( ( [ key , value ] ) => ( { "key" : key , "value" : value } ) ) )
. then ( ( pairs ) => Promise . all ( pairs . map ( ( pair ) => ( Promise . all ( this . fields . filter ( ( field ) => ( field . name === pair . key ) )
. map ( ( field ) => field . input . write ( pair . value ) ) )
. then ( ( ) => Promise . resolve ( undefined ) ) ) ) ) )
. then ( ( ) => Promise . resolve ( undefined ) ) ) ;
}
}
zoo _input . class _input _group = class _input _group ;
} ) ( zoo _input = lib _plankton . zoo _input || ( lib _plankton . zoo _input = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - form « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - form « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - form « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - form « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _form ;
( function ( zoo _form ) {
/ * *
* /
function make ( method , fields , encode , decode , options = { } ) {
options = Object . assign ( {
"class_prefix" : "plankton_form_" ,
} , options ) ;
return {
"method" : method ,
"fields" : fields . map ( field _raw => ( {
"name" : field _raw . name ,
"type" : field _raw . type ,
"label" : ( field _raw . label ? ? null ) ,
} ) ) ,
"encode" : encode ,
"decode" : decode ,
"class_prefix" : options . class _prefix ,
"root_element" : null ,
} ;
}
zoo _form . make = make ;
/ * *
* /
function make _simple ( method , fields , options = { } ) {
options = Object . assign ( {
"class_prefix" : "plankton_form_" ,
} , options ) ;
return {
"method" : method ,
"fields" : fields . map ( field _raw => ( {
"name" : field _raw . name ,
"type" : field _raw . type ,
"label" : ( field _raw . label ? ? null ) ,
} ) ) ,
"encode" : x => x ,
"decode" : x => x ,
"class_prefix" : options . class _prefix ,
"root_element" : null ,
} ;
}
zoo _form . make _simple = make _simple ;
/ * *
* /
function class _name ( subject , name ) {
return lib _plankton . string . coin ( "{{class_prefix}}{{name}}" , {
"class_prefix" : subject . class _prefix ,
"name" : name ,
} ) ;
}
/ * *
* /
function field _input ( subject , field ) {
return subject . root _element . querySelector ( lib _plankton . string . coin ( ".{{class}}[name=\"{{name}}\"]" , {
"class" : class _name ( subject , "input" ) ,
"name" : field . name ,
} ) ) ;
}
/ * *
* /
function clear ( subject ) {
subject . fields . forEach ( field => {
switch ( field . type ) {
default : {
field _input ( subject , field ) . value = "" ;
break ;
}
case "checkbox" : {
field _input ( subject , field ) . checked = false ;
break ;
}
}
} ) ;
}
zoo _form . clear = clear ;
/ * *
* /
function write ( subject , value ) {
let raw = subject . encode ( value ) ;
subject . fields . forEach ( field => {
switch ( field . type ) {
default : {
field _input ( subject , field ) . value = raw [ field . name ] ;
break ;
}
case "checkbox" : {
field _input ( subject , field ) . checked = ( raw [ field . name ] === "on" ) ;
break ;
}
}
} ) ;
}
zoo _form . write = write ;
/ * *
* /
function read ( subject ) {
let raw = { } ;
subject . fields . forEach ( field => {
switch ( field . type ) {
default : {
raw [ field . name ] = field _input ( subject , field ) . value ;
break ;
}
case "checkbox" : {
raw [ field . name ] = ( field _input ( subject , field ) . checked ? "on" : "off" ) ;
break ;
}
}
} ) ;
const value = subject . decode ( raw ) ;
return value ;
}
zoo _form . read = read ;
/ * *
* /
async function render ( subject , target ) {
let element _form = document . createElement ( "form" ) ;
element _form . classList . add ( class _name ( subject , "form" ) ) ;
subject . fields . forEach ( field => {
let element _field = document . createElement ( "div" ) ;
element _field . classList . add ( class _name ( subject , "field" ) ) ;
// label
{
let element _label = document . createElement ( "label" ) ;
element _label . classList . add ( class _name ( subject , "label" ) ) ;
element _field . appendChild ( element _label ) ;
element _label . textContent = ( field . label
? ?
field . name . split ( "_" ) . join ( " " ) ) ;
}
// input
{
let element _input = document . createElement ( "input" ) ;
element _input . classList . add ( class _name ( subject , "input" ) ) ;
element _input . setAttribute ( "name" , field . name ) ;
element _input . setAttribute ( "type" , field . type ) ;
element _field . appendChild ( element _input ) ;
}
element _form . appendChild ( element _field ) ;
} ) ;
subject . root _element = element _form ;
target . appendChild ( element _form ) ;
return Promise . resolve ( undefined ) ;
}
zoo _form . render = render ;
} ) ( zoo _form = lib _plankton . zoo _form || ( lib _plankton . zoo _form = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - form « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - form « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - form « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - form « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _form ;
( function ( zoo _form ) {
/ * *
* @ author fenris
* /
class class _form {
/ * *
* /
constructor ( encode , decode , input , actions ) {
this . encode = encode ;
this . decode = decode ;
this . input = input ;
this . actions = actions ;
}
/ * *
* /
async setup ( parent ) {
let dom _form = document . createElement ( "form" ) ;
dom _form . classList . add ( "plankton_form" ) ;
// input
{
let dom _container = document . createElement ( "div" ) ;
dom _container . classList . add ( "plankton_form_input" ) ;
await this . input . setup ( dom _container ) ;
dom _form . appendChild ( dom _container ) ;
}
// actions
{
let dom _container = document . createElement ( "div" ) ;
dom _container . classList . add ( "plankton_form_actions" ) ;
this . actions . forEach ( ( action ) => {
let dom _button = document . createElement ( "button" ) ;
// dom_button.setAttribute("type", "submit");
dom _button . textContent = action . label ;
if ( action . target !== undefined ) {
dom _button . setAttribute ( "formaction" , action . target ) ;
}
if ( action . procedure !== undefined ) {
dom _button . addEventListener ( "click" , ( event ) => {
event . preventDefault ( ) ;
action . procedure ( ( ) => this . input _read ( ) , ( ) => this . input _read _raw ( ) ) ;
} ) ;
}
dom _container . appendChild ( dom _button ) ;
} ) ;
dom _form . appendChild ( dom _container ) ;
}
parent . appendChild ( dom _form ) ;
}
/ * *
* /
input _read _raw ( ) {
return this . input . read ( ) ;
}
/ * *
* /
async input _read ( ) {
return this . decode ( await this . input . read ( ) ) ;
}
/ * *
* /
input _write ( value ) {
return this . input . write ( this . encode ( value ) ) ;
}
}
zoo _form . class _form = class _form ;
} ) ( zoo _form = lib _plankton . zoo _form || ( lib _plankton . zoo _form = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - search « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - search « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - search « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - search « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _search ;
( function ( zoo _search ) {
/ * *
* /
function class _name ( subject , name ) {
return lib _plankton . string . coin ( "{{class_prefix}}{{name}}" , {
"class_prefix" : subject . class _prefix ,
"name" : name ,
} ) ;
}
/ * *
* /
function make ( routine , options ) {
options = Object . assign ( {
"encode_item" : ( item ) => JSON . stringify ( item ) ,
"hooks_select" : [ ] ,
"hooks_begin" : [ ] ,
"hooks_end" : [ ] ,
"class_prefix" : "plankton_search_" ,
} , options ) ;
return {
"routine" : routine ,
"encode_item" : options . encode _item ,
"hooks_select" : options . hooks _select ,
"hooks_begin" : options . hooks _begin ,
"hooks_end" : options . hooks _end ,
"class_prefix" : options . class _prefix ,
"root_element" : null ,
"state" : null ,
} ;
}
zoo _search . make = make ;
/ * *
* /
function hook _begin ( subject , action ) {
subject . hooks _begin . push ( action ) ;
}
zoo _search . hook _begin = hook _begin ;
/ * *
* /
function hook _end ( subject , action ) {
subject . hooks _end . push ( action ) ;
}
zoo _search . hook _end = hook _end ;
/ * *
* /
function hook _select ( subject , action ) {
subject . hooks _select . push ( action ) ;
}
zoo _search . hook _select = hook _select ;
/ * *
* /
function clear ( subject ) {
// term
{
let term _element = subject . root _element . querySelector ( "." + class _name ( subject , "input" ) ) ;
term _element . value = "" ;
}
// list
{
let list _element = subject . root _element . querySelector ( "." + class _name ( subject , "hits" ) ) ;
list _element . innerHTML = "" ;
}
return Promise . resolve ( undefined ) ;
}
/ * *
* /
async function fill ( subject , term ) {
subject . hooks _begin . forEach ( action => { action ( term ) ; } ) ;
// term
{
let term _element = subject . root _element . querySelector ( "." + class _name ( subject , "input" ) ) ;
term _element . setAttribute ( "placeholder" , "search" ) ;
term _element . value = term ;
}
// list
{
let list _element = subject . root _element . querySelector ( "." + class _name ( subject , "hits" ) ) ;
list _element . innerHTML = "searching …" ;
const hits = await subject . routine ( term ) ;
list _element . innerHTML = "" ;
hits . forEach ( item => {
let item _element = document . createElement ( "li" ) ;
item _element . classList . add ( class _name ( subject , "item" ) ) ;
item _element . textContent = subject . encode _item ( item ) ;
item _element . addEventListener ( "click" , ( ) => {
subject . hooks _select . forEach ( action => { action ( item ) ; } ) ;
} ) ;
list _element . appendChild ( item _element ) ;
} ) ;
}
// external
{
subject . hooks _end . forEach ( action => { action ( ) ; } ) ;
}
return Promise . resolve ( undefined ) ;
}
/ * *
* /
async function set _state ( subject , state ) {
if ( ( subject . state !== null )
&&
( state . term === subject . state . term ) ) {
// do nothing
}
else {
subject . state = state ;
if ( state . term === null ) {
await clear ( subject ) ;
}
else {
await fill ( subject , state . term ) ;
}
}
return Promise . resolve ( undefined ) ;
}
zoo _search . set _state = set _state ;
/ * *
* /
async function render ( subject , target , options = { } ) {
options = Object . assign ( {
"state" : { "term" : null } ,
} , options ) ;
let container _element = document . createElement ( "div" ) ;
container _element . classList . add ( class _name ( subject , "search" ) ) ;
// form
{
let form _element = document . createElement ( "form" ) ;
// term
{
let term _element = document . createElement ( "input" ) ;
term _element . setAttribute ( "type" , "search" ) ;
term _element . setAttribute ( "name" , "term" ) ;
term _element . classList . add ( class _name ( subject , "input" ) ) ;
form _element . appendChild ( term _element ) ;
}
// submit
{
let submit _element = document . createElement ( "input" ) ;
submit _element . setAttribute ( "type" , "submit" ) ;
submit _element . classList . add ( class _name ( subject , "submit" ) ) ;
form _element . appendChild ( submit _element ) ;
}
form _element . addEventListener ( "submit" , ( event ) => {
event . preventDefault ( ) ;
const form _data = new FormData ( form _element ) ;
const term = form _data . get ( "term" ) ;
set _state ( subject , { "term" : term } ) ;
} ) ;
container _element . appendChild ( form _element ) ;
}
// hits
{
let hits _element = document . createElement ( "ul" ) ;
hits _element . classList . add ( class _name ( subject , "hits" ) ) ;
container _element . appendChild ( hits _element ) ;
}
subject . root _element = container _element ;
target . appendChild ( container _element ) ;
await set _state ( subject , options . state ) ;
return Promise . resolve ( undefined ) ;
}
zoo _search . render = render ;
} ) ( zoo _search = lib _plankton . zoo _search || ( lib _plankton . zoo _search = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - editor « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - editor « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - editor « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - editor « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _editor ;
( function ( zoo _editor ) {
/ * *
* /
let enum _mode ;
( function ( enum _mode ) {
enum _mode [ "find" ] = "find" ;
enum _mode [ "view" ] = "view" ;
enum _mode [ "make" ] = "make" ;
} ) ( enum _mode = zoo _editor . enum _mode || ( zoo _editor . enum _mode = { } ) ) ;
;
/ * *
* /
let enum _action ;
( function ( enum _action ) {
enum _action [ "keep" ] = "keep" ;
enum _action [ "save" ] = "save" ;
enum _action [ "delete" ] = "delete" ;
enum _action [ "find" ] = "find" ;
enum _action [ "make" ] = "make" ;
} ) ( enum _action = zoo _editor . enum _action || ( zoo _editor . enum _action = { } ) ) ;
;
/ * *
* /
let enum _function ;
( function ( enum _function ) {
enum _function [ "seek" ] = "seek" ;
enum _function [ "read" ] = "read" ;
enum _function [ "create" ] = "create" ;
enum _function [ "update" ] = "update" ;
enum _function [ "delete" ] = "delete" ;
} ) ( enum _function = zoo _editor . enum _function || ( zoo _editor . enum _function = { } ) ) ;
;
/ * *
* /
function make ( store , form , options = { } ) {
options = Object . assign ( {
"functions" : [
enum _function . seek ,
enum _function . read ,
enum _function . create ,
enum _function . update ,
enum _function . delete ,
] ,
"encode_hit" : ( hit ) => lib _plankton . string . coin ( "[{{key}}] {{preview}}" , {
"key" : JSON . stringify ( hit . key ) ,
"preview" : JSON . stringify ( hit . preview ) ,
} ) ,
"hook_switch" : null ,
"class_prefix" : "plankton_editor_" ,
} , options ) ;
return {
"functions" : options . functions ,
"store" : store ,
/ *
// wrap store in order to restrict access according to allowed functions
"store" : new RestrictedStorage (
store ,
ArrayListHelper : : map (
$this - > functions ,
function ( string $function ) : string { return self : : $actionMap [ $function ] ; }
)
) ,
* /
"search" : lib _plankton . zoo _search . make ( ( term ) => store . search ( term ) , {
"encode_item" : options . encode _hit ,
} ) ,
"form" : form ,
"hook_switch" : options . hook _switch ,
"state" : null ,
"class_prefix" : options . class _prefix ,
"root_element" : null ,
} ;
}
zoo _editor . make = make ;
/ * *
* /
function class _name ( subject , name ) {
return lib _plankton . string . coin ( "{{class_prefix}}{{name}}" , {
"class_prefix" : subject . class _prefix ,
"name" : name ,
} ) ;
}
/ * *
* /
function map _function _to _store _action ( function _ ) {
switch ( function _ ) {
case enum _function . seek : return "seek" ;
case enum _function . read : return "read" ;
case enum _function . create : return "create" ;
case enum _function . update : return "update" ;
case enum _function . delete : return "delete" ;
}
}
/ * *
* /
function map _mode _to _functions ( mode ) {
switch ( mode ) {
case enum _mode . find : return [ enum _function . seek ] ;
case enum _mode . view : return [ enum _function . read ] ;
case enum _mode . make : return [ enum _function . create ] ;
}
}
/ * *
* /
function map _mode _to _actions ( mode ) {
switch ( mode ) {
case enum _mode . find : return [ enum _action . make ] ;
case enum _mode . view : return [ enum _action . save , enum _action . delete , enum _action . find , enum _action . make ] ;
case enum _mode . make : return [ enum _action . keep , enum _action . find ] ;
}
}
/ * *
* /
function map _action _to _class _body ( action ) {
return ( "action_" + action ) ;
}
/ * *
* /
function wait ( subject , mode ) {
subject . root _element . classList . toggle ( "waiting" , mode ) ;
// loader
{
// view
{
subject . root _element . querySelector ( "." + class _name ( subject , "loader" ) ) . style . display = ( mode ? "" : "none" ) ;
}
}
/ *
// search
{
// view
{
(
subject . root _element . querySelector (
"." + class _name < type _key , type _value > ( subject , "search" )
) as HTMLElement
) . style . display = ( ( ! mode ) ? "" : "none" ) ;
}
}
// form
{
// view
{
(
subject . root _element . querySelector (
"." + class _name < type _key , type _value > ( subject , "form" )
) as HTMLElement
) . style . display = ( ( ! mode ) ? "" : "none" ) ;
}
}
// actions
{
// view
{
(
subject . root _element . querySelector (
"." + class _name < type _key , type _value > ( subject , "actions" )
) as HTMLElement
) . style . display = ( ( ! mode ) ? "" : "none" ) ;
}
}
* /
}
/ * *
* /
async function set _state ( subject , state ) {
const state _old = subject . state ;
subject . state = state ;
// container
{
if ( state _old === null ) {
// do nothing
}
else {
subject . root _element . classList . remove ( state _old . mode ) ;
}
subject . root _element . classList . add ( state . mode ) ;
}
// search
{
// model
{
await lib _plankton . zoo _search . set _state ( subject . search , state . search _state ) ;
}
// view
{
subject . root _element . querySelector ( "." + class _name ( subject , "search" ) ) . style . display = ( [ enum _mode . find ] . includes ( state . mode )
? ""
: "none" ) ;
}
}
// form
{
// model
{
if ( state . key === null ) {
lib _plankton . zoo _form . clear ( subject . form ) ;
}
else {
lib _plankton . zoo _form . write ( subject . form , await subject . store . read ( state . key ) ) ;
}
}
// view
{
subject . root _element . querySelector ( "." + class _name ( subject , "form" ) ) . style . display = ( [ enum _mode . view , enum _mode . make ] . includes ( state . mode )
? ""
: "none" ) ;
}
}
// actions
{
// view
{
[
enum _action . keep ,
enum _action . save ,
enum _action . delete ,
enum _action . find ,
enum _action . make ,
]
. forEach ( action => {
subject . root _element . querySelector ( "." + class _name ( subject , map _action _to _class _body ( action ) ) ) . style . visibility = ( map _mode _to _actions ( state . mode ) . includes ( action )
? ""
: "hidden" ) ;
} ) ;
}
}
// external
{
if ( subject . hook _switch === null ) {
// do nothing
}
else {
subject . hook _switch ( state ) ;
}
}
}
/ * *
* /
async function render ( subject , target , options = { } ) {
options = Object . assign ( {
"state" : {
"mode" : enum _mode . find ,
"key" : null ,
"search_state" : { "term" : null } ,
} ,
} , options ) ;
subject . state = options . state ;
const element _all = document . createElement ( "div" ) ;
element _all . classList . add ( class _name ( subject , "container" ) ) ;
{
// loader
{
const container _element = document . createElement ( "div" ) ;
container _element . classList . add ( class _name ( subject , "loader" ) ) ;
// text
{
const text _element = document . createElement ( "div" ) ;
text _element . textContent = "…" ;
container _element . appendChild ( text _element ) ;
}
element _all . appendChild ( container _element ) ;
}
// search
{
const container _element = document . createElement ( "div" ) ;
container _element . classList . add ( class _name ( subject , "search" ) ) ;
// search core
{
lib _plankton . zoo _search . hook _select ( subject . search , async ( hit ) => {
wait ( subject , true ) ;
await set _state ( subject , {
"mode" : enum _mode . view ,
"key" : hit . key ,
"search_state" : { "term" : null } ,
} ) ;
wait ( subject , false ) ;
} ) ;
lib _plankton . zoo _search . hook _begin ( subject . search , ( term ) => {
set _state ( subject , {
"mode" : subject . state . mode ,
"key" : subject . state . key ,
"search_state" : { "term" : term } ,
} ) ;
} ) ;
await lib _plankton . zoo _search . render ( subject . search , container _element , {
"state" : options . state . search _state ,
} ) ;
}
element _all . appendChild ( container _element ) ;
}
// form
{
const container _element = document . createElement ( "div" ) ;
container _element . classList . add ( class _name ( subject , "form" ) ) ;
// form core
{
await lib _plankton . zoo _form . render ( subject . form , container _element ) ;
}
element _all . appendChild ( container _element ) ;
}
// actions
{
let container _element = document . createElement ( "div" ) ;
container _element . classList . add ( class _name ( subject , "actions" ) ) ;
{
[
{
"value" : enum _action . find ,
// TODO translate
"label" : "search" ,
"procedure" : async ( ) => {
wait ( subject , true ) ;
set _state ( subject , {
"mode" : enum _mode . find ,
"key" : null ,
"search_state" : { "term" : null } ,
} ) ;
wait ( subject , false ) ;
} ,
} ,
{
"value" : enum _action . make ,
// TODO translate
"label" : "new" ,
"procedure" : async ( ) => {
wait ( subject , true ) ;
set _state ( subject , {
"mode" : enum _mode . make ,
"key" : null ,
"search_state" : { "term" : null } ,
} ) ;
wait ( subject , false ) ;
} ,
} ,
{
"value" : enum _action . keep ,
// TODO translate
"label" : "save" ,
"procedure" : async ( ) => {
wait ( subject , true ) ;
const value = lib _plankton . zoo _form . read ( subject . form ) ;
const key = await subject . store . create ( value ) ;
set _state ( subject , {
"mode" : enum _mode . view ,
"key" : key ,
"search_state" : { "term" : null } ,
} ) ;
wait ( subject , false ) ;
} ,
} ,
{
"value" : enum _action . save ,
// TODO translate
"label" : "apply" ,
"procedure" : async ( ) => {
wait ( subject , true ) ;
const value = lib _plankton . zoo _form . read ( subject . form ) ;
await subject . store . update ( subject . state . key , value ) ;
/ *
set _state < type _key , type _value > (
subject ,
{
"mode" : enum _mode . view ,
"key" : subject . state . key ,
"search_state" : { "term" : null } ,
}
) ;
* /
wait ( subject , false ) ;
} ,
} ,
{
"value" : enum _action . delete ,
// TODO translate
"label" : "delete" ,
"procedure" : async ( ) => {
if ( confirm ( "sure?" ) ) {
wait ( subject , true ) ;
await subject . store . delete ( subject . state . key ) ;
set _state ( subject , {
"mode" : enum _mode . find ,
"key" : null ,
"search_state" : { "term" : null } ,
} ) ;
wait ( subject , false ) ;
}
else {
// no nothing
}
} ,
} ,
]
. forEach ( action => {
let button _element = document . createElement ( "button" ) ;
button _element . classList . add ( class _name ( subject , "action" ) ) ;
button _element . classList . add ( class _name ( subject , map _action _to _class _body ( action . value ) ) ) ;
button _element . textContent = action . label ;
button _element . addEventListener ( "click" , ( ) => {
action . procedure ( ) ;
} ) ;
container _element . appendChild ( button _element ) ;
} ) ;
}
element _all . appendChild ( container _element ) ;
}
target . appendChild ( element _all ) ;
}
subject . root _element = element _all ;
set _state ( subject , options . state ) ;
wait ( subject , false ) ;
}
zoo _editor . render = render ;
} ) ( zoo _editor = lib _plankton . zoo _editor || ( lib _plankton . zoo _editor = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;
/ *
This file is part of » bacterio - plankton : zoo - page « .
Copyright 2016 - 2023 'Christian Fraß, Christian Neubauer, Martin Springwald GbR'
< info @ greenscale . de >
» bacterio - plankton : zoo - page « is free software : you can redistribute it and / or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
» bacterio - plankton : zoo - page « is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU Lesser General Public License for more details .
You should have received a copy of the GNU Lesser General Public License
along with » bacterio - plankton : zoo - page « . If not , see < http : //www.gnu.org/licenses/>.
* /
var lib _plankton ;
( function ( lib _plankton ) {
var zoo _page ;
( function ( zoo _page ) {
/ * *
* /
zoo _page . _pool = { } ;
/ * *
* /
let _fallback = null ;
/ * *
* /
let _current = null ;
/ * *
* /
let _target _element = null ;
/ * *
* /
function encode ( location ) {
return ( "#"
+
( [ location . name ]
. concat ( Object . entries ( location . parameters )
. filter ( ( [ key , value ] ) => ( value !== null ) )
. map ( ( [ key , value ] ) => ( key + "=" + value ) ) ) ) ) ;
}
zoo _page . encode = encode ;
/ * *
* /
function decode ( encoded ) {
if ( encoded === "" ) {
return null ;
}
else {
if ( ! encoded . startsWith ( "#" ) ) {
return null ;
}
else {
const parts = encoded . slice ( 1 ) . split ( "," ) ;
return {
"name" : parts [ 0 ] ,
"parameters" : Object . fromEntries ( parts . slice ( 1 )
. map ( part => {
const parts _ = part . split ( "=" ) ;
return [ parts _ [ 0 ] , parts _ [ 1 ] ] ;
} ) ) ,
} ;
}
}
}
/ * *
* renders a page to the main element
* /
async function load ( location ) {
// _target_element.innerHTML = "[loading …]";
_target _element . innerHTML = "" ;
if ( location === null ) {
// do nothing
}
else {
if ( ! ( location . name in zoo _page . _pool ) ) {
_target _element . innerHTML = "not found" ;
}
else {
await zoo _page . _pool [ location . name ] ( location . parameters , _target _element ) ;
_current = location ;
}
}
}
/ * *
* /
function add _nav _entry ( location , options = { } ) {
options = Object . assign ( {
"label" : null ,
} , options ) ;
let ul _element = document . querySelector ( "nav > ul" ) ;
{
let li _element = document . createElement ( "li" ) ;
{
let a _element = document . createElement ( "a" ) ;
a _element . setAttribute ( "href" , encode ( location ) ) ;
a _element . textContent = ( options . label ? ? location . name ) ;
li _element . appendChild ( a _element ) ;
}
ul _element . appendChild ( li _element ) ;
}
}
zoo _page . add _nav _entry = add _nav _entry ;
/ * *
* retrieves the location from the set URL
* /
function get ( ) {
return decode ( window . location . hash ) ;
}
/ * *
* encodes a location in the URL and loads it
* /
function set ( location ) {
window . location . hash = encode ( location ) ;
}
zoo _page . set = set ;
/ * *
* /
function register ( location _name , handler , options = { } ) {
options = Object . assign ( { } , options ) ;
zoo _page . _pool [ location _name ] = handler ;
}
zoo _page . register = register ;
/ * *
* /
function init ( target _element , options = { } ) {
options = Object . assign ( {
"pool" : { } ,
"fallback" : null ,
} , options ) ;
_target _element = target _element ;
_fallback = options . fallback ;
Object . entries ( options . pool ) . forEach ( ( [ location _name , handler ] ) => {
register ( location _name , handler ) ;
} ) ;
window . addEventListener ( "hashchange" , ( ) => {
const location _old = _current ;
const location _new = ( get ( ) ? ? _fallback ) ;
if ( ( ( location _old === null )
&&
( location _new !== null ) )
||
( ( location _old !== null )
&&
( location _new !== null )
&&
( location _old . name !== location _new . name ) ) ) {
load ( location _new ) ;
}
else {
// do nothing
}
} ) ;
}
zoo _page . init = init ;
/ * *
* /
function start ( ) {
const location = ( get ( ) ? ? _fallback ) ;
set ( location ) ;
load ( location ) ;
}
zoo _page . start = start ;
} ) ( zoo _page = lib _plankton . zoo _page || ( lib _plankton . zoo _page = { } ) ) ;
} ) ( lib _plankton || ( lib _plankton = { } ) ) ;