AnP/Public/ecma/Components/LicensesComponent.ecma.js

161 lines
5.2 KiB
JavaScript

"use strict";
import {Utils} from "../Utils/Utils.ecma.js";
import {Check} from "../Utils/Check.ecma.js";
/**
* @typedef {import("../Application/AnP.ecma.js").AnP} AnP
*/
/**
* @class
* @constructor
* @param {!AnP} anp
* @returns {void}
* @access private
*/
export const LicensesComponent = (function(){
/**
* @constructs LicensesComponent
* @param {!AnP} anp
* @returns {void}
* @access private
*/
const LicensesComponent = function(anp){
/** @type {LicensesComponent} */
const self = this;
/** @type {boolean} */
let started = false;
/**
* @returns {void}
* @access private
*/
const constructor = () => {};
/**
* @param {?anp_start_callback} callback
* @returns {boolean}
* @access public
*/
this.start = (callback = null) => {
/** @type {!anp_start_callback} */
const end = ok => {
Utils.execute(callback, ok);
return ok;
};
return end(started ? false : started = true);
};
/**
* @param {!...Array.<any|null>} [licenses]
* @returns {Array.<any|null>}
* @access public
*/
this.build = (...licenses) => ["span", {
class : "licenses"
}, licenses.map(([name, ...inputs]) => (
Check.is_function(self[name]) ? self[name](...inputs) :
[]))];
/**
* @returns {Array.<any|null>}
* @access public
*/
this.gplv3 = () => ["a", {
class : "license gpl-v3",
href : "https://www.gnu.org/licenses/gpl-3.0.txt",
target : "_blank",
title : "GPLv3"
}, [
["span", {class : "text"}, "GPLv3"],
["image", {
sources : "https://www.gnu.org/graphics/gplv3-88x31.png",
alt : "GPLv3"
}]
]];
/**
* @returns {Array.<any|null>}
* @access public
*/
this.cc_by_nc_sa_4 = () => {
/** @type {string} */
const text = anp.i18n.get([
"Creative Commons Attribution-NonCommertial-ShareAlike 4.0 International (CC-SA-NC-BY 4.0)",
"cc_by_nc_sa_4"
]);
return ["a", {
class : "license cc-by-nc-sa-4",
href : "https://creativecommons.org/licenses/by-nc-sa/4.0/",
target : "_blank",
data_i18n : "cc_by_nc_sa_4",
data_i18n_without : true,
title : text
}, [
["span", {class : "text"}, text],
["image", {
sources : "https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png",
data_i18n : "cc_by_nc_sa_4",
data_i18n_without : true,
alt : text
}]
]];
};
/**
* @param {?(number|string|Array.<number|string>)} [year = null]
* @param {?(string|Array.<string>)} [authors = null]
* @param {!boolean} [all_rights_reserved = false]
* @returns {Array.<any|null>}
* @access public
*/
this.copyright = (year = null, authors = null, all_rights_reserved = false) => {
/** @type {Object.<string, string>} */
const variables = {
year : Check.is_array(year) ? (
year.length == 1 ? year[0] :
year.length == 2 ? year.join("-") :
year.length ? year.slice(0, year.length - 1).join(", ") + " & " + year.slice(-1)[0] :
"") : year || "",
authors : Check.is_array(authors) ? (
authors.length == 1 ? authors[0] :
authors.length == 2 ? authors.join(" & ") :
authors.length ? authors.slice(0, authors.length - 1).join(", ") + " & " + authors.slice(-1)[0] :
"") : authors || "",
all_rights_reserved : all_rights_reserved ? anp.i18n.get([
"All rights reserved.",
"all_rights_reserved"
]) : ""
},
/** @type {string} */
text = anp.i18n.get([
"© Copyright{year}{authors}{all_rights_reserved}",
"copyright"
], {
year : variables.year = variables.year ? " " + variables.year + "." : "",
authors : variables.authors = variables.authors ? " " + variables.authors + "." : "",
all_rights_reserved : variables.all_rights_reserved = variables.all_rights_reserved ? (variables.year || variables.authors ? "" : ". ") + variables.all_rights_reserved : ""
});
return ["span", {
class : "license copyright",
data_i18n : "copyriht",
data_i18n_variables : variables,
title : text
}, text];
};
constructor();
};
return LicensesComponent;
})();