From 7a28a76380aca803969d7dd6c382101a972200f4 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 15 May 2025 06:09:44 +0200 Subject: [PATCH] DRAFT: modulization of base scripts --- src/base/extStore.js | 30 +++++++++++++++--------------- src/base/index.mjs | 38 ++++++++++++++++++++++++++++++++++++++ src/base/webTrinity.js | 2 +- 3 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 src/base/index.mjs diff --git a/src/base/extStore.js b/src/base/extStore.js index 6edc109..582838a 100644 --- a/src/base/extStore.js +++ b/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} 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} 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} 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