41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import * as plugins from './tapbundle.plugins.js';
|
|
import { tap } from './tapbundle.classes.tap.js';
|
|
|
|
class WebHelpers {
|
|
html: any;
|
|
fixture: any;
|
|
|
|
constructor() {
|
|
const smartenv = new plugins.smartenv.Smartenv();
|
|
|
|
// Initialize HTML template tag function
|
|
this.html = (strings: TemplateStringsArray, ...values: any[]) => {
|
|
let result = '';
|
|
for (let i = 0; i < strings.length; i++) {
|
|
result += strings[i];
|
|
if (i < values.length) {
|
|
result += values[i];
|
|
}
|
|
}
|
|
return result;
|
|
};
|
|
|
|
// Initialize fixture function based on environment
|
|
if (smartenv.isBrowser) {
|
|
this.fixture = async (htmlString: string): Promise<HTMLElement> => {
|
|
const container = document.createElement('div');
|
|
container.innerHTML = htmlString.trim();
|
|
const element = container.firstChild as HTMLElement;
|
|
return element;
|
|
};
|
|
} else {
|
|
// Node.js environment - provide a stub or alternative implementation
|
|
this.fixture = async (htmlString: string): Promise<any> => {
|
|
throw new Error('WebHelpers.fixture is only available in browser environment');
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
export const webhelpers = new WebHelpers();
|