Skip to content

Commit c56ed44

Browse files
feat: Add speed control variable (#81)
1 parent 6ce840f commit c56ed44

File tree

10 files changed

+38
-27
lines changed

10 files changed

+38
-27
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,18 @@ Feel free to [open a PR](https://github.com/DenverCoder1/readme-typing-svg/issue
5959

6060
## 🔧 Options
6161

62-
| Parameter | Details | Type | Example |
63-
| :---------: | :----------------------------------------------------------------------: | :-----: | :---------------------------------: |
64-
| `lines` | Text to display with lines separated by `;` and `+` for spaces | string | `First+line;Second+line;Third+line` |
65-
| `center` | `true` to center text or `false` for left aligned (default: `false`) | boolean | `true` or `false` |
66-
| `vCenter` | `true` to center vertically or `false`(default) to align above the center | boolean | `true` or `false` |
67-
| `height` | Height of the output SVG in pixels (default: `50`) | integer | Any positive number |
68-
| `width` | Width of the output SVG in pixels (default: `400`) | integer | Any positive number |
69-
| `font` | Font family (default: `monospace`) | string | Any font from Google Fonts |
70-
| `size` | Font size in pixels (default: `20`) | integer | Any positive number |
71-
| `color` | Color of the text (default: `36BCF7`) | string | Hex code without # (eg. `00ff00`) |
72-
| `multiline` | `true` to wrap lines or `false` to retype on one line (default: `false`) | boolean | `true` or `false` |
62+
| Parameter | Details | Type | Example |
63+
| :---------: | :--------------------------------------------------------------------------: | :-----: | :---------------------------------: |
64+
| `lines` | Text to display with lines separated by `;` and `+` for spaces | string | `First+line;Second+line;Third+line` |
65+
| `center` | `true` to center text or `false` for left aligned (default: `false`) | boolean | `true` or `false` |
66+
| `vCenter` | `true` to center vertically or `false`(default) to align above the center | boolean | `true` or `false` |
67+
| `height` | Height of the output SVG in pixels (default: `50`) | integer | Any positive number |
68+
| `width` | Width of the output SVG in pixels (default: `400`) | integer | Any positive number |
69+
| `font` | Font family (default: `monospace`) | string | Any font from Google Fonts |
70+
| `size` | Font size in pixels (default: `20`) | integer | Any positive number |
71+
| `color` | Color of the text (default: `36BCF7`) | string | Hex code without # (eg. `00ff00`) |
72+
| `multiline` | `true` to wrap lines or `false` to retype on one line (default: `false`) | boolean | `true` or `false` |
73+
| `duration` | Duration of the printing of a single line in milliseconds (default: `5000`) | integer | Any positive number |
7374

7475
## 📤 Deploying it on your own
7576

src/demo/index.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ function gtag() { dataLayer.push(arguments); }
6565
<label for="size">Font size</label>
6666
<input class="param" type="number" id="size" name="size" placeholder="20" value="20">
6767

68+
<label for="duration">Print duration (ms per line)</label>
69+
<input class="param" type="number" id="duration" name="duration" placeholder="5000" value="5000">
70+
6871
<label for="center">Horizontally Centered</label>
6972
<select class="param" id="center" name="center" value="false">
7073
<option>false</option>

src/demo/js/script.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ let preview = {
88
vCenter: "false",
99
multiline: "false",
1010
width: "400",
11-
height: "50"
11+
height: "50",
12+
duration: "5000"
1213
},
1314
dummyText: [
1415
"The five boxing wizards jump quickly",

src/models/RendererModel.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ class RendererModel
3232
/** @var bool $multiline True = wrap to new lines, False = retype on same line */
3333
public $multiline;
3434

35+
/** @var int $duration print duration in milliseconds */
36+
public $duration;
37+
3538
/** @var string $fontCSS CSS required for displaying the selected font */
3639
public $fontCSS;
3740

@@ -51,6 +54,7 @@ class RendererModel
5154
"width" => "400",
5255
"height" => "50",
5356
"multiline" => "false",
57+
"duration" => "5000"
5458
);
5559

5660
/**
@@ -73,6 +77,7 @@ public function __construct($template, $params, $database)
7377
$this->width = $this->checkNumber($params["width"] ?? $this->DEFAULTS["width"], "Width");
7478
$this->height = $this->checkNumber($params["height"] ?? $this->DEFAULTS["height"], "Height");
7579
$this->multiline = $this->checkBoolean($params["multiline"] ?? $this->DEFAULTS["multiline"]);
80+
$this->duration = $this->checkNumber($params["duration"] ?? $this->DEFAULTS["duration"], "duration");
7681
$this->fontCSS = $this->fetchFontCSS($this->font);
7782
}
7883

src/templates/main.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
<?php for ($i = 0; $i < count($lines); ++$i): ?>
1111
<path id='path<?php echo $i ?>'>
1212
<?php if (!$multiline): ?>
13-
<animate id='d<?php echo $i ?>' attributeName='d' begin='<?php echo ($i == 0 ? "0s;" : "") . $previousId ?>.end' dur='5s'
13+
<animate id='d<?php echo $i ?>' attributeName='d' begin='<?php echo ($i == 0 ? "0s;" : "") . $previousId ?>.end' dur='<?php echo $duration ?>ms'
1414
values='m0,<?php echo $height / 2 ?> h0 ; m0,<?php echo $height / 2 ?> h<?php echo $width ?> ; m0,<?php echo $height / 2 ?> h0' keyTimes='0;0.8;1' />
1515
<?php else: ?>
1616
<?php $lineHeight = $size + 5;?>
17-
<animate id='d<?php echo $i ?>' attributeName='d' dur='<?php echo 5 * ($i + 1) ?>s' fill="freeze"
17+
<animate id='d<?php echo $i ?>' attributeName='d' dur='<?php echo $duration * ($i + 1) ?>ms' fill="freeze"
1818
begin='0s;<?php echo "d" . (count($lines) - 1) ?>.end' keyTimes="0;<?php echo $i / ($i + 1); ?>;1"
1919
values='m0,<?php echo ($i + 1) * $lineHeight ?> h0 ; m0,<?php echo ($i + 1) * $lineHeight ?> h0 ; m0,<?php echo ($i + 1) * $lineHeight ?> h<?php echo $width ?>' />
2020
<?php endif;?>

src/views/RendererView.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function render()
3737
"height" => $this->model->height,
3838
"multiline" => $this->model->multiline,
3939
"fontCSS" => $this->model->fontCSS,
40+
"duration" => $this->model->duration,
4041
));
4142
// render SVG with output buffering
4243
ob_start();

tests/svg/test_fonts.svg

Lines changed: 1 addition & 1 deletion
Loading

tests/svg/test_multiline.svg

Lines changed: 4 additions & 4 deletions
Loading

tests/svg/test_normal.svg

Lines changed: 4 additions & 4 deletions
Loading

tests/svg/test_normal_vertical_alignment.svg

Lines changed: 4 additions & 4 deletions
Loading

0 commit comments

Comments
 (0)