Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(atomic): replace getAssetPath #4844

Merged
merged 7 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/atomic/src/components/common/interface/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {getAssetPath} from '@stencil/core';
import DOMPurify from 'dompurify';
import {getAssetPath} from '../../../utils/utils';

Check failure on line 2 in packages/atomic/src/components/common/interface/i18n.ts

View workflow job for this annotation

GitHub Actions / Check with linter

Delete `{getAssetPath}·from·'../../../utils/utils';⏎import·`
import Backend, {HttpBackendOptions} from 'i18next-http-backend';
import availableLocales from '../../../generated/availableLocales.json';

Check failure on line 4 in packages/atomic/src/components/common/interface/i18n.ts

View workflow job for this annotation

GitHub Actions / Check with linter

Insert `';⏎import·{getAssetPath}·from·'../../../utils/utils`
import {AnyEngineType} from './bindings';
import {BaseAtomicInterface} from './interface-common';

Expand Down
12 changes: 8 additions & 4 deletions packages/atomic/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {getAssetPath} from '@stencil/core';
import {NODE_TYPES} from '@stencil/core/mock-doc';
import DOMPurify from 'dompurify';

/**
Expand Down Expand Up @@ -57,11 +55,11 @@ export function parseHTML(string: string) {
}

export function isElementNode(node: Node): node is Element {
return node.nodeType === NODE_TYPES.ELEMENT_NODE;
return node.nodeType === Node.ELEMENT_NODE;
}
y-lakhdar marked this conversation as resolved.
Show resolved Hide resolved

export function isTextNode(node: Node): node is Text {
return node.nodeType === NODE_TYPES.TEXT_NODE;
return node.nodeType === Node.TEXT_NODE;
}

export function isVisualNode(node: Node) {
Expand All @@ -84,6 +82,12 @@ export function containsVisualElement(node: Node) {
return false;
}

export function getAssetPath(path: string): string {
const baseUrl = window.location.origin;
const assetUrl = new URL(path, baseUrl);
return assetUrl.origin !== baseUrl ? assetUrl.href : assetUrl.pathname;
}

export function parseAssetURL(url: string, assetPath = './assets') {
const [, protocol, remainder] =
url.match(/^([a-z]+):\/\/(.*?)(\.svg)?$/) || [];
Expand Down
Loading