Skip to content

Latest commit

 

History

History
130 lines (92 loc) · 5.98 KB

README.md

File metadata and controls

130 lines (92 loc) · 5.98 KB

Dotsy

Dotsy is a JavaScript library with which you can create HTML for randomly positioned, non-overlapping, customized dots. You can set:

  • the height and width of the container
  • the radius and color of each dot

Then Dotsy calculates the locations and creates the HTML for you.

This library can be used, for example, in software that may focus on:

  • subitizing
  • counting
  • arithmetic

How to use this library

For an online example to play with, see symbolinker.github.io/dotsy. The source code of the example can be found in the docs folder.

Of the source code of the library itself, you only need to have a look inside the src/public folder. A note about getHtml: it returns a container div with class="dotsy-rectangle" and this contains for each dot a div with class="dotsy-dot". This allows you to easily add touch/click event handlers.

How to add it to your project? There are various ways:

Using a <script> element

There is no need to download or install anything. Your website just needs to have a <script> element that results in getting one of the following files from jsDelivr:

  • dotsy.es2020-esm.js
  • dotsy.es2017-esm.js
  • dotsy.es2015-iife.js

esYEAR: those are JavaScript language versions.
esm: the ECMAScript module is simply the best choice: easy, safe, future proof.
iife: an immediately invoked function expression for browsers that do not support ESM.

For each of those ".js" files there is a minified version (".min.js") - a smaller file (of only 2 kB) with the same capabilities.

A <script> element using the recommended "dotsy.es2017-esm.min.js":

<script type="module">
  import * as dotsy from 'https://cdn.jsdelivr.net/npm/dotsy@0.1.0/dist/dotsy.es2017-esm.min.js';
  let settings = new dotsy.Settings();
  // ...(set settings here)...
  let html = dotsy.getHtml(settings);
  // ...(get your HTML element)...
  yourElement.innerHTML = html;
</script>

A <script> element using the with-older-browsers-compatible "dotsy.es2015-iife.min.js":

<script src="https://cdn.jsdelivr.net/npm/dotsy@0.1.0/dist/dotsy.es2015-iife.min.js"></script>
<script type="text/javascript">
  window.addEventListener('DOMContentLoaded', (event) => {
    let settings = new dotsy.Settings();
    // ...(set settings here)...
    let html = dotsy.getHtml(settings);
    // ...(get your HTML element)...
    yourElement.innerHTML = html;
  });
</script>

Using npm

This library has been published to npm. After opening a folder in VS Code, run in the terminal:

npm i dotsy

Verify that dotsy has been added to the node_modules folder. Then you can choose:

Using the CommonJS module (the .cjs file) in myFile.js:

const dotsy = require('dotsy');
const settings = new dotsy.Settings();

Using the ESM module (the .mjs file) in myFile.js or myFile.ts:

import * as dotsy from 'dotsy';
const settings = new dotsy.Settings();

How to use this repo

Follow these steps to set up (and verify) a development environment for this repository:

  1. Install Node.js, Git and VS Code.
  2. Fork (or clone), checkout and then open the root folder of this repository in VS Code.
  3. Open the VS Code Terminal and run:
    npm ci
    This loads all the devDependencies from the tree as specified in package-lock.json.
  4. Compiling the library:
    All of the following commands run some script as defined in package.json:
    npm run strictcheck to do type checking, to check whether a successful compilation is possible.
    npm run clean to run eslint (performing auto-fixes).
    npm test to run all unit tests from the 'tests' folder.
    npm run build creates a single-file library in different formats and language versions in the 'dist' folder. Note: the 'src' folder contains all the source code files.
  5. Testing localhost:
    For testing localhost with live reload from VS Code, you could install the VS Code extension Five Server. Then open '/localhost/index.html' in VS Code and click > Go Live in the bottom right corner of VS Code. The browser starts up automatically.

License

The Dotsy repository uses the most permissive licensing available. The "BSD Zero Clause License" (0BSD) allows for
commercial + non-commercial use, closed + open source, with + without modifications, etc. and is equivalent to licenses like:

The "BSD Zero Clause License" (0BSD) does not have the condition

(...), provided that the above copyright notice and this permission notice appear in all copies.

which is part of the "MIT License" (MIT) and its shorter equivalent "ISC License" (ISC). Apart from that they are all equivalent.

Ask or contribute