Skip to content

Commit

Permalink
0.0.59
Browse files Browse the repository at this point in the history
  • Loading branch information
bahrus committed May 11, 2024
1 parent b625025 commit b91de2c
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 9 deletions.
56 changes: 56 additions & 0 deletions be-based.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {config as beCnfg} from 'be-enhanced/config.js';
import {BE, BEConfig} from 'be-enhanced/BE.js';
import {Actions, PAP, AllProps} from './types';
import {MountObserver} from 'mount-observer/MountObserver.js';

export class BeBased extends BE<Element> implements Actions{
hydrate(self: this): PAP {
const {enhancedElement, forAll, base, puntOn, fileName} = self;
if(!base!.endsWith('/')){
return {
base: base + '/',
}
}
const mo = new MountObserver({
on: forAll!.join(','),
do: {
mount: (matchingElement) => {
for(const attrib of forAll!){
this.#processEl(matchingElement, attrib, base!, fileName);
}
}
}
})
return {
resolved: true,
}
}

#processEl(node: Element, attrib: string, base: string, fileName?: string){
if(!(node as Element).hasAttribute(attrib)) return;
let val = (node as Element).getAttribute(attrib)!;
if(val.indexOf('//') !== -1) return;
if(val.startsWith('data:')) return;
if(val[0] === '#') return;
//TODO: support paths that start with ..
//console.log({attrib, base, val, fileName});
let newVal: string | undefined;
if(val.startsWith('../')){
let split = base.split('/');
split.pop();
while(val.startsWith('../')){
val = val.substring(3);
split.pop();
}
newVal = split.join('/') + '/' + val;
// }else if(val[0] === '#'){
// newVal = base + fileName + val;
}else{
if(val[0] ==='/') val = val.substring(1); // this doesn't seem right - need to start from domain (?)
newVal = base + val;
}
(node as Element).setAttribute(attrib, newVal);
}
}

export interface BeBased extends AllProps{}
7 changes: 7 additions & 0 deletions behance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {BeBased} from './be-based.js';
import {def} from 'trans-render/lib/def.js';

await BeBased.bootUp();

def('be-based', BeBased);

10 changes: 10 additions & 0 deletions behivior.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import './behance.js';
import {BeHive} from 'be-hive/be-hive.js';


BeHive.registry.register({
base: 'be-based',
map: {
'0.0': 'ni'
}
});
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"custom element"
],
"dependencies": {
"be-enhanced": "0.0.81",
"be-enhanced": "0.0.82",
"be-hive": "0.0.148",
"trans-render": "0.0.764",
"xtal-element": "0.0.602"
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"strict": true
},
"files":[
"legacy/behivior.ts"
"behivior.ts"
],
"exclude":[
"node_modules"
Expand Down

0 comments on commit b91de2c

Please sign in to comment.