Browse Source

DRAFT: modulization of base scripts

dev-feat-module-bundler
chris 1 month ago
parent
commit
7a28a76380
  1. 30
      src/base/extStore.js
  2. 38
      src/base/index.mjs
  3. 2
      src/base/webTrinity.js

30
src/base/extStore.js

@ -1,7 +1,7 @@
/**
* ESAggregation := Extensions Storage Aggregation (method)
*/
const ESAggregation = Object.freeze({
export const ESAggregation = Object.freeze({
INTERNALIZED: "intern",
INDIVIDUALLY: "individual",
COLLECTED: "collected",
@ -15,7 +15,7 @@ const ESAggregation = Object.freeze({
* Only relevant if ExtStorage is not 'internalized'.
* Determines where the tag (if individually) or the extensions are positioned.
*/
const ExtStorePosition = Object.freeze({
export const ExtStorePosition = Object.freeze({
WITHIN: "WITHIN",
BEFORE: "BEFORE",
SEGMENT_BEGIN: "SEGMENT_BEGIN",
@ -31,7 +31,7 @@ const ExtStorePosition = Object.freeze({
* DROP_NEW:
* MOVE_ELEMENT_SPECIFIC: @ATTENTION implementation pending
*/
const OverwriteBehaviour = Object.freeze({
export const OverwriteBehaviour = Object.freeze({
REPLACE: "REPLACE",
RENAME: "RENAME",
RENAME_OLD: "RENAME_OLD",
@ -45,7 +45,7 @@ const OverwriteBehaviour = Object.freeze({
* @param {Function} func
* @returns {string}
*/
function clearFunctionDeclarationText(func) {
export function clearFunctionDeclarationText(func) {
function shrinkEmptyStrings(text) {
for (let i = 1; i < 10; i++) {
text = text.replaceAll(" ".slice(i), ' ');
@ -70,7 +70,7 @@ function clearFunctionDeclarationText(func) {
* @param {string} registrationName
* @returns {string}
*/
function getScriptTagInjectionText(func, registrationName) {
export function getScriptTagInjectionText(func, registrationName) {
let funcHasName;
if (typeof func === 'function') {
funcHasName = ((func.name) && func.name.trim() !== '');
@ -94,7 +94,7 @@ function getScriptTagInjectionText(func, registrationName) {
* Then the additional informations of the store wil be applied
* and the funcitons added to the page.
*/
class FunctionStoreBuffer {
export class FunctionStoreBuffer {
/**
* Stores a function until generate is called.
* Then the additional informations of the store wil be applied
@ -127,7 +127,7 @@ class FunctionStoreBuffer {
* Extracted this super class to differentiate between
* internal and external store.
*/
class ExtStorage {
export class ExtStorage {
constructor(
aggregation = ESAggregation.INTERNALIZED,
position = ExtStorePosition.WITHIN,
@ -472,7 +472,7 @@ class ExtStorage {
* centralized: the extensions are send to the Page to be joined in a centralized tag/position of the document
* (either head or footer tag)
*/
const ExtStoreType = Object.freeze({
export const ExtStoreType = Object.freeze({
INTERNALIZED_WITHIN: new ExtStorage(ESAggregation.INDIVIDUALLY, ExtStorePosition.WITHIN),
INDIVIDUALLY_WITHIN: new ExtStorage(ESAggregation.INDIVIDUALLY, ExtStorePosition.WITHIN),
INDIVIDUALLY_BEFORE: new ExtStorage(ESAggregation.INDIVIDUALLY, ExtStorePosition.BEFORE),
@ -495,7 +495,7 @@ const ExtStoreType = Object.freeze({
* @property {any} _additionaly;
* @property {ExtStorage} _extStore;
*/
class SStoreDefinition {
export class SStoreDefinition {
constructor(identifier, definition, extStore = null, additions = null) {
/**
* Usually the name or the selector
@ -528,7 +528,7 @@ class SStoreDefinition {
* @param {OverwriteBehaviour} overwriteBehaviour
* @returns {string} the key to be used
*/
function resolveOverwrite(key, container, overwriteBehaviour) {
export function resolveOverwrite(key, container, overwriteBehaviour) {
let dealAsMap = container instanceof Map;
let occurances = [...(
dealAsMap
@ -573,7 +573,7 @@ function resolveOverwrite(key, container, overwriteBehaviour) {
* @param {OverwriteBehaviour} overwriteBehaviour
* @returns {string} the "resolved" compareKey
*/
function identifyAndResolveOverwrite(targetContainer, compareKey, newValue, overwriteBehaviour) {
export function identifyAndResolveOverwrite(targetContainer, compareKey, newValue, overwriteBehaviour) {
let keys = Object.keys(targetContainer);
if (keys.includes(compareKey)) {
if (overwriteBehaviour === OverwriteBehaviour.DROP_NEW) {
@ -594,7 +594,7 @@ function identifyAndResolveOverwrite(targetContainer, compareKey, newValue, over
* @param {Array<SStoreDefinition>} ssdArray
* @returns {HTMLScriptElement}
*/
function generateAndFillScriptTag(ssdArray) {
export function generateAndFillScriptTag(ssdArray) {
let tag = document.createElement("script");
tag.setAttribute("data-compel-gen", "true");
@ -616,7 +616,7 @@ function generateAndFillScriptTag(ssdArray) {
* @param {Map<string,string>} stylingMap
* @returns {string}
*/
function getStylingInjectionText(selector, stylingMap) {
export function getStylingInjectionText(selector, stylingMap) {
function keyValueToString(key) {
return `${key}: ${stylingMap[key]}; `;
}
@ -633,7 +633,7 @@ function getStylingInjectionText(selector, stylingMap) {
* @param {Array<SStoreDefinition>} ssdArray
* @returns {HTMLStyleElement}
*/
function generateAndFillStyleTag(ssdArray) {
export function generateAndFillStyleTag(ssdArray) {
let tag = document.createElement("style");
tag.setAttribute("data-compel-gen", "true");
@ -651,7 +651,7 @@ function generateAndFillStyleTag(ssdArray) {
* @param {Function} func
* @returns {Map<ExtStoreType, *}
*/
function executeOnExtStoreTypeCollectedTriple(func) {
export function executeOnExtStoreTypeCollectedTriple(func) {
return new Map([
{ [ExtStoreType.COLLECTED_SEGMENT_BEGIN]: func(ExtStoreType.COLLECTED_SEGMENT_BEGIN) },
{ [ExtStoreType.COLLECTED_DOC_HEAD]: func(ExtStoreType.COLLECTED_DOC_HEAD) },

38
src/base/index.mjs

@ -0,0 +1,38 @@
import {
ESAggregation,
ExtStorePosition,
OverwriteBehaviour,
clearFunctionDeclarationText,
getScriptTagInjectionText,
FunctionStoreBuffer,
ExtStorage,
ExtStoreType,
SStoreDefinition,
resolveOverwrite,
identifyAndResolveOverwrite,
generateAndFillScriptTag,
getStylingInjectionText,
generateAndFillStyleTag,
executeOnExtStoreTypeCollectedTriple
} from "./extStore";
import { WebTrinity } from "./webTrinity"
export {
ESAggregation,
ExtStorePosition,
OverwriteBehaviour,
clearFunctionDeclarationText,
getScriptTagInjectionText,
FunctionStoreBuffer,
ExtStorage,
ExtStoreType,
SStoreDefinition,
resolveOverwrite,
identifyAndResolveOverwrite,
generateAndFillScriptTag,
getStylingInjectionText,
generateAndFillStyleTag,
executeOnExtStoreTypeCollectedTriple,
WebTrinity
}

2
src/base/webTrinity.js

@ -1,7 +1,7 @@
/**
* Wenity := Web Trinity
*/
class WebTrinity {
export class WebTrinity {
/**
* @deprecated renamed - use copext instead
* @type {HTMLElement|Component|string} = compext, for a migration period

Loading…
Cancel
Save