ONO::Lib::Math::HTML

package ONO::Lib::Math::HTML;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program 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.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################

use CGI;
use strict;

use ONO::IO;
use ONO::Lib::Math;

sub display_number {

my (
$self,
$number,
$switches,
$id,
$altnum,
) = @_;

#: Display a number, optimized for HTML output.
#:
#: $number is the correct number, $altnum may be used to display user input
#:
#: -D dev mode, will display number(s) as placeholder
#: -f process fractions
#: -i input (form mode)
#: -I input, use number as default, add as placeholder
#: -l margins left
#: -L margins left
#: -m margins left & right
#: -M margins left & right
#: -r margins right
#: -R margins right

my $HTML = $number;

if ($switches =~ /i/) {

my $length = length $number;
my $size = $length + 1;
my $maxlength = $length + 2;

my $PLA;
if (ONO::IO->devstation && $switches =~ /D/) {
$PLA = qq~ placeholder="$number"~;
}

$HTML = qq~<input id="$id\_id" type="text" name="$id" value="" size="$size" maxlength="$maxlength"$PLA>~;

if ($switches =~ /I/) {

$HTML = qq~<input id="$id\_id" type="text" name="$id" value="$number" size="$size" maxlength="$maxlength" placeholder="$number">~;

}

if ($altnum) {

$HTML = qq~<input id="$id\_id" type="text" name="$id" value="$altnum" size="$size" maxlength="$maxlength" placeholder="$altnum">~;

}

}

if ($switches =~ /f/ && $number =~ m~/~) {

my @np = split(/\//,$number);

$HTML = qq~<table class="default_table mt3 auto">
<tr><td class="pad5_0 center">$np[0]</td></tr>
<tr><td class="p0"><div class="p1" style="background-color:#000"></div></td></tr>
<tr><td class="pad5_0 center">$np[1]</td></tr>
</table>
~;

if ($switches =~ /i/) {

my @IN;

my $length = length $np[0];
if (length $np[1] > $length) {
$length = length $np[1];
}
my $size = $length + 1;
my $maxlength = $length + 2;

$altnum =~ m~^(.*?)/(.*?)$~;
my @ap = ($1,$2);

for (my $i = 0; $i < 2; $i++) {
my $PLA;
if (ONO::IO->devstation && $switches =~ /D/) {
$PLA = qq~ placeholder="$np[$i]"~;
}
$IN[$i] = qq~<input id="$id\_$i\_id" type="text" name="$id\_$i" value="" class="center" size="$size" maxlength="$maxlength"$PLA>~;
if ($switches =~ /I/) {
$IN[$i] = qq~<input id="$id\_$i\_id" type="text" name="$id\_$i" value="$np[$i]" class="center" size="$size" maxlength="$maxlength" placeholder="$np[$i]">~;
}
if ($ap[$i] =~ /[0-9]/) {
$IN[$i] = qq~<input id="$id\_$i\_id" type="text" name="$id\_$i" value="$ap[$i]" class="center" size="$size" maxlength="$maxlength" placeholder="$ap[$i]">~;
}
}

$HTML = qq~<table class="default_table mt3 auto">
<tr><td class="pad5_0 center">$IN[0]</td></tr>
<tr><td class="p0"><div class="p1 mt5 mb4" style="background-color:#000"></div></td></tr>
<tr><td class="pad5_0 center">$IN[1]</td></tr>
</table>
~;

}

}

if ($switches =~ /(l|L|m|M|r|R)/) {

my $CLASS;

if ($switches =~ /(l||m)/) {
$CLASS .= "ml5 ";
}
if ($switches =~ /(r||m)/) {
$CLASS .= "mr5 ";
}
if ($switches =~ /(L||M)/) {
$CLASS .= "ml10 ";
}
if ($switches =~ /(R||M)/) {
$CLASS .= "mr10 ";
}

$HTML = qq~<div class="$CLASS">$HTML</div>~;

}

return $HTML;

}

sub op_to_symbol {

#: see ONO_Lib_Math

return ONO::Lib::Math->op_to_symbol($_[1],"H$_[2]");

}

###############################################################################
# end of script
###############################################################################

1;

__END__