Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
xeolabs committed Nov 21, 2024
2 parents 6ddc9fc + 6114f05 commit f14582a
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 39 deletions.
78 changes: 78 additions & 0 deletions packages/demos/build-docs-lookup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const fs = require('fs');
const path = require('path');

function buildDocsLookup(docsDir) {

const jsonDir = `${docsDir}/json/`;

const index = new Map();

try {
const files = fs.readdirSync(jsonDir);

files.forEach(file => {
const filePath = path.join(jsonDir, file);
const stats = fs.statSync(filePath);
if (stats.isFile()) {
try {
const data = fs.readFileSync(filePath, 'utf8');
const moduleData = JSON.parse(data);
const packageId = moduleData.name;
const packageLocalName = packageId.substring("@xeokit/".length);
const children = moduleData.children;
if (children) {
for (let child of children) {
const kind = child.kind;
let path = null;
const entry = {
path:null,
kind:null
};
switch (kind) {
case 128:
entry.path = `https://xeokit.github.io/sdk/docs/api/classes/_xeokit_${packageLocalName}.${child.name}.html`;
entry.kind="class";
break;
case 32:
entry.path = `https://xeokit.github.io/sdk/docs/api/variables/_xeokit_${packageLocalName}.${child.name}.html`;
entry.kind="variable";
break;
case 64:
entry.path = `https://xeokit.github.io/sdk/docs/api/functions/_xeokit_${packageLocalName}.${child.name}.html`;
entry.kind="function";
break;
case 87:
case 256:
entry.path = `https://xeokit.github.io/sdk/docs/api/interfaces/_xeokit_${packageLocalName}.${child.name}.html`;
entry.kind="interface";
break;
case 2097152:
entry.path = `https://xeokit.github.io/sdk/docs/api/types/_xeokit_${packageLocalName}.${child.name}.html`;
entry.kind="type";
break;
default:
console.log(`kind not handled: ${kind}`)
}
index.set(child.name, entry);
}
}


} catch (err) {
console.error(`Error reading or parsing JSON in file: ${filePath}`, err);
}
}
});
} catch (err) {
console.error(`Error reading directory: ${err}`);
}

const sortedIndex = Object.fromEntries([...index.entries()].sort((a, b) => a[0].localeCompare(b[0])));

return sortedIndex;
}

const docsDirectory = '../../docs';
const index = buildDocsLookup(docsDirectory);

fs.writeFileSync("./docsLookup.json", JSON.stringify(index, null, 2), 'utf8');
8 changes: 6 additions & 2 deletions packages/demos/css/pageStyle.css
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,18 @@ h3 {
}

a {
/*text-decoration: none;*/
/*color: #212529;*/
text-decoration: none;
box-sizing: border-box;
}

a:hover {
text-decoration: underline;
}

code{
/*background: #e8e8e8;*/
}

#log {
width: 100%;
height: 100%;
Expand Down
68 changes: 32 additions & 36 deletions packages/demos/js/DemoHelper.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {DOC_LINKS} from "./docLinks.js";
let DOC_LINKS;

export class DemoHelper {

Expand Down Expand Up @@ -38,29 +38,34 @@ export class DemoHelper {
descElement.innerHTML = this.index.description;
this.statusContainer.appendChild(descElement);
}
if (cfg.index) {
const index = cfg.index;
this.index = index;
logDescription();
if (index.summary) {
this.logTitle("Steps");
this.logItems(index.summary.split('.').filter(Boolean));
}
this.startTime = performance.now();
resolve();
} else {
fetch("./index.json").then(response => {
response.json().then(index => {
fetch("./../../../docsLookup.json").then(response => {
response.json().then(docsLookup => {
DOC_LINKS = docsLookup;
if (cfg.index) {
const index = cfg.index;
this.index = index;
logDescription();
this.logTitle("Steps");
// this.log(index.summary);
this.logItems(index.summary.split('.').filter(Boolean));
if (index.summary) {
this.logTitle("Steps");
this.logItems(index.summary.split('.').filter(Boolean));
}
this.startTime = performance.now();
resolve();
});
} else {
fetch("./index.json").then(response => {
response.json().then(index => {
this.index = index;
logDescription();
this.logTitle("Steps");
// this.log(index.summary);
this.logItems(index.summary.split('.').filter(Boolean));
this.startTime = performance.now();
resolve();
});
});
}
});
}
});
});
}

Expand Down Expand Up @@ -177,7 +182,7 @@ export class DemoHelper {
this.logTitle("Assets Loaded");
const assets = [];
for (let asset of this.assets) {
assets.push(`<a target="_parent" href="${this.gitHubDataDir}/${truncateUntilSubstring(asset.src, "models")}">${truncateUntilSubstring(asset.src, "models")}</a>`);
assets.push(`<a target="_parent" href="${this.gitHubDataDir}/${truncateUntilSubstring(asset.src, "models")}"><pre>${truncateUntilSubstring(asset.src, "models")}</pre></a>`);
}
this.logUnorderedItems(assets);
}
Expand All @@ -186,11 +191,12 @@ export class DemoHelper {

function trunc(vec) {
const vec2 = [];
for (let i =0, len = vec.length; i < len; i++) {
for (let i = 0, len = vec.length; i < len; i++) {
vec2[i] = Math.trunc(vec[i] * 100) / 100;
}
return vec2;
}

function truncateUntilSubstring(str, substring) {
const index = str.indexOf(substring);
if (index !== -1) {
Expand All @@ -203,23 +209,13 @@ function wrapWordsWithLinks(text, wordMap) {
Object.keys(wordMap).forEach(function (key) {
const regex = new RegExp(`\\b${key}s?\\b`, 'gi');
text = text.replace(regex, (match) => {
const entry = wordMap[key];
const path = entry.path || "";
const kind = entry.kind || "";
return /s$/i.test(match)
? `<a href="${wordMap[key]}" target="_blank">${key}</a>s`
: `<a href="${wordMap[key]}" target="_blank">${key}</a>`;
? `<a href="${path}" class="${kind}" target="_blank"><span>${key}s</span></a>`
: `<a href="${path}" class="${kind}" target="_blank"><span>${key}</span></a>`;
});
});
return text;
}

function replaceWithPlural(inputString, targetWord, replacementWord) {


// Create a regex to match singular and plural forms of the target word
const regex = new RegExp(`\\b${escapedWord}s?\\b`, 'gi');

// Replace with the appropriate singular or plural form
return inputString.replace(regex, (match) => {
// If the matched word is plural, return the plural form of the replacement
return /s$/i.test(match) ? `${replacementWord}s` : replacementWord;
});
}
2 changes: 1 addition & 1 deletion packages/demos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"main": "src/index.ts",
"scripts": {
"dist": "node build-xeokit-demo-bundle.js",
"demos": "node build-viewer-demos-index.js;",
"demos": "node build-docs_lookup.js; node build-viewer-demos-index.js;",
"models": "node build-convert-models.js; sh convert-models.sh",

"lint": "eslint . --fix"
Expand Down

0 comments on commit f14582a

Please sign in to comment.