amateras 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +1 -0
- package/package.json +32 -30
- package/packages/core/package.json +32 -0
- package/packages/core/src/env.browser.ts +21 -0
- package/packages/core/src/env.node.ts +21 -0
- package/packages/core/src/global.ts +18 -0
- package/{src/core.ts → packages/core/src/index.ts} +42 -30
- package/{src → packages/core/src}/lib/assignProperties.ts +1 -1
- package/packages/core/src/lib/chain.ts +17 -0
- package/packages/core/src/lib/dom.ts +20 -0
- package/packages/core/src/main.ts +4 -0
- package/{src → packages/core/src}/node/$Element.ts +22 -10
- package/{src → packages/core/src}/node/$EventTarget.ts +13 -10
- package/{src → packages/core/src}/node/$HTMLElement.ts +1 -1
- package/{src → packages/core/src}/node/$Node.ts +7 -11
- package/{src → packages/core/src}/node/$Virtual.ts +5 -5
- package/packages/css/package.json +17 -0
- package/{ext/css/src/lib → packages/css/src/ext}/colors/amber.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/blackwhite.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/blue.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/cyan.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/emerald.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/fuchsia.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/gray.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/green.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/indigo.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/lime.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/neutral.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/orange.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/pink.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/purple.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/red.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/rose.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/sky.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/slate.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/stone.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/teal.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/violet.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/yellow.ts +2 -2
- package/{ext/css/src/lib → packages/css/src/ext}/colors/zinc.ts +2 -2
- package/packages/css/src/ext/container.ts +32 -0
- package/packages/css/src/ext/keyframes.ts +54 -0
- package/packages/css/src/ext/media.ts +32 -0
- package/packages/css/src/ext/property.ts +48 -0
- package/packages/css/src/ext/variable.ts +51 -0
- package/{ext → packages}/css/src/index.ts +107 -183
- package/{ext → packages}/css/src/lib/colorAssign.ts +1 -1
- package/packages/css/src/lib/utils.ts +11 -0
- package/{ext → packages}/css/src/structure/$CSSContainerRule.ts +1 -1
- package/{ext → packages}/css/src/structure/$CSSKeyframesRule.ts +0 -1
- package/{ext → packages}/css/src/structure/$CSSMediaRule.ts +1 -1
- package/packages/css/src/structure/$CSSProperty.ts +19 -0
- package/{ext → packages}/css/src/structure/$CSSRule.ts +1 -1
- package/{ext → packages}/css/src/structure/$CSSStyleRule.ts +1 -1
- package/packages/css/src/structure/$CSSVariable.ts +30 -0
- package/packages/dom/package.json +20 -0
- package/packages/dom/src/lib/HTMLElementMap.ts +213 -0
- package/packages/dom/src/lib/assignAttributes.ts +16 -0
- package/packages/dom/src/structure/CSS.ts +7 -0
- package/packages/dom/src/structure/CSSStyleSheet.ts +10 -0
- package/packages/dom/src/structure/DOMTokenList.ts +19 -0
- package/packages/dom/src/structure/Document.ts +36 -0
- package/packages/dom/src/structure/Element.ts +106 -0
- package/packages/dom/src/structure/HTMLElement.ts +34 -0
- package/packages/dom/src/structure/History.ts +11 -0
- package/packages/dom/src/structure/Location.ts +9 -0
- package/packages/dom/src/structure/Node.ts +51 -0
- package/packages/dom/src/structure/NodeList.ts +10 -0
- package/packages/dom/src/structure/Storage.ts +8 -0
- package/packages/dom/src/structure/Text.ts +20 -0
- package/packages/dom/src/structure/Window.ts +14 -0
- package/packages/dom/src/structure/html/HTMLAbbrElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLAddressElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLAnchorElement.ts +25 -0
- package/packages/dom/src/structure/html/HTMLAreaElement.ts +26 -0
- package/packages/dom/src/structure/html/HTMLArticleElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLAsideElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLAudioElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLBDIElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLBDOElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLBElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLBRElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLBaseElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLBodyElement.ts +22 -0
- package/packages/dom/src/structure/html/HTMLButtonElement.ts +26 -0
- package/packages/dom/src/structure/html/HTMLCanvasElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLCiteElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLCodeElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDDElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDFNElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDListElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLDTElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDataElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLDataListElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLDetailsElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLDialogElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLDivElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLEMElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLEmbedElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLFieldSetElement.ts +19 -0
- package/packages/dom/src/structure/html/HTMLFigCaptionElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLFigureElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLFooterElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLFormElement.ts +24 -0
- package/packages/dom/src/structure/html/HTMLHGroupElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLHRElement.ts +21 -0
- package/packages/dom/src/structure/html/HTMLHeadElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLHeaderElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLHeadingElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLHtmlElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLIElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLIFrameElement.ts +31 -0
- package/packages/dom/src/structure/html/HTMLImageElement.ts +38 -0
- package/packages/dom/src/structure/html/HTMLInputElement.ts +55 -0
- package/packages/dom/src/structure/html/HTMLKBDElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLLIElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLLabelElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLLegendElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLLinkElement.ts +31 -0
- package/packages/dom/src/structure/html/HTMLMainElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLMapElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLMarkElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLMediaElement.ts +48 -0
- package/packages/dom/src/structure/html/HTMLMenuElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLMetaElement.ts +22 -0
- package/packages/dom/src/structure/html/HTMLMeterElement.ts +23 -0
- package/packages/dom/src/structure/html/HTMLModElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLNavElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLNoscriptElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLOListElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLObjectElement.ts +34 -0
- package/packages/dom/src/structure/html/HTMLOptGroupElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLOptionElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLOutputElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLParagraphElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLPictureElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLPreElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLProgressElement.ts +19 -0
- package/packages/dom/src/structure/html/HTMLQuoteElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLRPElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLRTElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLRubyElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSampElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLScriptElement.ts +27 -0
- package/packages/dom/src/structure/html/HTMLSectionElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSelectElement.ts +27 -0
- package/packages/dom/src/structure/html/HTMLSlotElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLSmallElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSourceElement.ts +21 -0
- package/packages/dom/src/structure/html/HTMLSpanElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLStrongElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLStyleElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLSubElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSummaryElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLSupElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLTableCaptionElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLTableCellElement.ts +31 -0
- package/packages/dom/src/structure/html/HTMLTableColElement.ts +23 -0
- package/packages/dom/src/structure/html/HTMLTableElement.ts +26 -0
- package/packages/dom/src/structure/html/HTMLTableRowElement.ts +23 -0
- package/packages/dom/src/structure/html/HTMLTableSectionElement.ts +20 -0
- package/packages/dom/src/structure/html/HTMLTemplateElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLTextAreaElement.ts +33 -0
- package/packages/dom/src/structure/html/HTMLTimeElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLTitleElement.ts +17 -0
- package/packages/dom/src/structure/html/HTMLTrackElement.ts +21 -0
- package/packages/dom/src/structure/html/HTMLUElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLUListElement.ts +18 -0
- package/packages/dom/src/structure/html/HTMLVarElement.ts +16 -0
- package/packages/dom/src/structure/html/HTMLVideoElement.ts +22 -0
- package/packages/dom/src/structure/html/HTMLWBRElement.ts +16 -0
- package/packages/html/package.json +18 -0
- package/{ext/html/html.ts → packages/html/src/index.ts} +1 -1
- package/{ext/html → packages/html/src}/node/$Anchor.ts +3 -3
- package/packages/html/src/node/$Canvas.ts +38 -0
- package/{ext/html → packages/html/src}/node/$Dialog.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Form.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Image.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Input.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Label.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Media.ts +3 -3
- package/{ext/html → packages/html/src}/node/$OptGroup.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Option.ts +3 -3
- package/{ext/html → packages/html/src}/node/$Select.ts +3 -3
- package/{ext/html → packages/html/src}/node/$TextArea.ts +3 -3
- package/packages/i18n/package.json +19 -0
- package/{ext → packages}/i18n/src/index.ts +6 -14
- package/{ext → packages}/i18n/src/structure/I18n.ts +2 -2
- package/{ext → packages}/i18n/src/structure/I18nDictionary.ts +1 -1
- package/{ext → packages}/i18n/src/structure/I18nTranslation.ts +10 -4
- package/packages/idb/package.json +19 -0
- package/{ext → packages}/idb/src/index.ts +2 -2
- package/{ext → packages}/idb/src/lib/$IDBRequest.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDB.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBCursor.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBIndex.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBStore.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBStoreBase.ts +1 -1
- package/{ext → packages}/idb/src/structure/$IDBTransaction.ts +1 -1
- package/{ext → packages}/idb/src/structure/builder/$IDBBuilder.ts +1 -2
- package/{ext → packages}/idb/src/structure/builder/$IDBStoreBuilder.ts +1 -1
- package/packages/markdown/package.json +19 -0
- package/{ext → packages}/markdown/src/lib/util.ts +1 -1
- package/{ext → packages}/markdown/src/structure/MarkdownLexer.ts +2 -2
- package/{ext → packages}/markdown/src/structure/MarkdownParser.ts +2 -1
- package/{ext → packages}/markdown/src/syntax/alert.ts +1 -1
- package/{ext → packages}/markdown/src/syntax/codeblock.ts +1 -1
- package/{ext → packages}/markdown/src/syntax/link.ts +2 -2
- package/{ext → packages}/markdown/src/syntax/list.ts +1 -1
- package/{ext → packages}/markdown/src/syntax/table.ts +1 -1
- package/packages/router/package.json +19 -0
- package/{ext → packages}/router/src/index.ts +4 -5
- package/{ext → packages}/router/src/node/Page.ts +8 -4
- package/{ext → packages}/router/src/node/Router.ts +79 -58
- package/{ext → packages}/router/src/node/RouterAnchor.ts +2 -2
- package/{ext → packages}/router/src/structure/PageBuilder.ts +3 -3
- package/{ext → packages}/router/src/structure/Route.ts +1 -1
- package/packages/signal/package.json +18 -0
- package/packages/signal/src/index.ts +221 -0
- package/{ext → packages}/signal/src/structure/Signal.ts +1 -1
- package/packages/ssr/package.json +19 -0
- package/packages/ssr/src/index.ts +38 -0
- package/{ext → packages}/ui/lib/VirtualScroll.ts +5 -5
- package/{ext → packages}/ui/node/Accordian.ts +4 -4
- package/packages/ui/node/Carousel.ts +20 -0
- package/{ext → packages}/ui/node/Form.ts +7 -6
- package/packages/ui/node/Modal.ts +45 -0
- package/{ext → packages}/ui/node/Table.ts +1 -1
- package/{ext → packages}/ui/node/Tabs.ts +28 -13
- package/{ext → packages}/ui/node/Toast.ts +2 -2
- package/packages/ui/node/Waterfall.ts +94 -0
- package/packages/ui/package.json +21 -0
- package/packages/utils/package.json +17 -0
- package/{src → packages/utils/src}/global.ts +5 -18
- package/{src/lib/native.ts → packages/utils/src/index.ts} +34 -1
- package/tsconfig.json +1 -1
- package/ext/css/package.json +0 -9
- package/ext/css/src/structure/$CSSVariable.ts +0 -12
- package/ext/html/node/$Canvas.ts +0 -16
- package/ext/i18n/package.json +0 -10
- package/ext/idb/package.json +0 -13
- package/ext/markdown/package.json +0 -15
- package/ext/router/package.json +0 -10
- package/ext/signal/package.json +0 -9
- package/ext/signal/src/index.ts +0 -128
- package/ext/ssr/env.ts +0 -61
- package/ext/ssr/index.ts +0 -49
- package/ext/ssr/package.json +0 -10
- package/ext/ui/node/Waterfall.ts +0 -72
- package/ext/ui/package.json +0 -11
- package/src/index.ts +0 -2
- package/src/lib/chain.ts +0 -13
- package/src/lib/debounce.ts +0 -7
- package/src/lib/env.ts +0 -2
- package/src/lib/randomId.ts +0 -9
- package/src/lib/sleep.ts +0 -3
- package/src/lib/toArray.ts +0 -9
- package/src/lib/trycatch.ts +0 -17
- package/src/lib/uppercase.ts +0 -3
- /package/{src/node.ts → packages/core/src/lib/assignNodeProperties.ts} +0 -0
- /package/{ext → packages}/css/README.md +0 -0
- /package/{ext/css/src/lib → packages/css/src/ext}/colors.ts +0 -0
- /package/{ext → packages}/css/src/structure/$CSSDeclaration.ts +0 -0
- /package/{ext → packages}/i18n/README.md +0 -0
- /package/{ext → packages}/idb/README.md +0 -0
- /package/{ext → packages}/idb/src/core.ts +0 -0
- /package/{ext → packages}/markdown/README.md +0 -0
- /package/{ext → packages}/markdown/src/index.ts +0 -0
- /package/{ext → packages}/markdown/src/lib/type.ts +0 -0
- /package/{ext → packages}/markdown/src/structure/Markdown.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/blockquote.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/bold.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/code.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/heading.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/horizontalRule.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/image.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/italic.ts +0 -0
- /package/{ext → packages}/markdown/src/syntax/text.ts +0 -0
- /package/{ext → packages}/router/README.md +0 -0
- /package/{ext → packages}/signal/README.md +0 -0
- /package/{ext → packages}/ui/node/Grid.ts +0 -0
|
@@ -1,228 +1,152 @@
|
|
|
1
|
-
import { _Array_from, _instanceof, _JSON_stringify, _Object_assign, _Object_entries, _Object_fromEntries, forEach, isObject, isUndefined, startsWith } from "amateras/
|
|
2
|
-
import {
|
|
3
|
-
import { $Element } from "amateras/node/$Element";
|
|
1
|
+
import { _Array_from, _instanceof, _JSON_stringify, _Object_assign, _Object_entries, _Object_fromEntries, forEach, isObject, isUndefined, startsWith } from "@amateras/utils";
|
|
2
|
+
import { $Element } from "@amateras/core/node/$Element";
|
|
4
3
|
import { $CSSDeclaration } from "#structure/$CSSDeclaration";
|
|
5
|
-
import { $CSSMediaRule } from "#structure/$CSSMediaRule";
|
|
6
4
|
import { $CSSRule } from "#structure/$CSSRule";
|
|
7
5
|
import { $CSSStyleRule } from "#structure/$CSSStyleRule";
|
|
8
|
-
import {
|
|
9
|
-
import { $CSSVariable } from "#structure/$CSSVariable";
|
|
10
|
-
import { $CSSContainerRule } from "#structure/$CSSContainerRule";
|
|
6
|
+
import { generateId } from "./lib/utils";
|
|
11
7
|
|
|
12
|
-
declare module 'amateras/core' {
|
|
8
|
+
declare module '@amateras/core' {
|
|
13
9
|
export namespace $ {
|
|
14
|
-
export function css(options: $
|
|
15
|
-
export function CSS(options: $
|
|
10
|
+
export function css(options: $CSSMap | $CSSStyleRule): $CSSStyleRule
|
|
11
|
+
export function CSS(options: $CSSSelectors | $CSSGlobalDeclarationExtends): void
|
|
16
12
|
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
export interface $CSSValueTypeExtendsMap {}
|
|
14
|
+
export type $CSSValueTypeExtends = $CSSValueTypeExtendsMap[keyof $CSSValueTypeExtendsMap]
|
|
15
|
+
|
|
16
|
+
export interface $CSSGlobalDeclarationExtendsMap {}
|
|
17
|
+
export type $CSSGlobalDeclarationExtends = $CSSGlobalDeclarationExtendsMap[keyof $CSSGlobalDeclarationExtendsMap];
|
|
22
18
|
}
|
|
23
19
|
}
|
|
24
20
|
|
|
25
|
-
declare module 'amateras/node/$Element' {
|
|
21
|
+
declare module '@amateras/core/node/$Element' {
|
|
26
22
|
export interface $Element {
|
|
27
|
-
css(...options: ($
|
|
23
|
+
css(...options: ($CSSMap | $CSSStyleRule)[]): this;
|
|
28
24
|
}
|
|
29
25
|
}
|
|
30
26
|
|
|
31
|
-
const generatedIds = new Set<string>();
|
|
32
|
-
const generateId = (lettercase: 'any' | 'lower' | 'upper' = 'any'): string => {
|
|
33
|
-
const id = randomId({lettercase: lettercase});
|
|
34
|
-
if (generatedIds.has(id)) return generateId(lettercase);
|
|
35
|
-
generatedIds.add(id);
|
|
36
|
-
return id;
|
|
37
|
-
}
|
|
38
27
|
|
|
39
|
-
|
|
40
|
-
const cssTextMap = new Map<string, $CSSStyleRule>();
|
|
41
|
-
const [MEDIA, KEYFRAMES, CONTAINER] = ['@media', '@keyframes', '@container'] as const;
|
|
28
|
+
export namespace $CSS {
|
|
42
29
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
options: $CSSOptions,
|
|
46
|
-
): T => {
|
|
47
|
-
for (const [key, value] of _Object_entries(options)) {
|
|
48
|
-
if (isUndefined(value)) continue;
|
|
49
|
-
else if (_instanceof(value, $CSSDeclaration)) rule.declarations.set(value.key, value);
|
|
50
|
-
else if (isObject(value) && !_instanceof(value, $CSSKeyframesRule, $CSSVariable))
|
|
51
|
-
rule.rules.add( createRule(key, value, rule.selector) );
|
|
52
|
-
else {
|
|
53
|
-
const declaration = new $CSSDeclaration(key, `${value}`);
|
|
54
|
-
rule.declarations.set(declaration.key, declaration);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return rule;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** Create rule with several type depend on selector content.
|
|
61
|
-
* @param context - for media rule creation, it should be style rule selector same as nested parent of media rule.
|
|
62
|
-
*/
|
|
63
|
-
const createRule = (selector: string, options: $CSSOptions, context?: string) => {
|
|
64
|
-
if (startsWith(selector, CONTAINER, MEDIA)) return createMediaOrContainerRule(selector, options, context);
|
|
65
|
-
if (startsWith(selector, KEYFRAMES)) return createKeyframesRule(selector.replace('@keyframes ', ''), options as $CSSKeyframesType)
|
|
66
|
-
return createStyleRule(selector, options);
|
|
67
|
-
}
|
|
30
|
+
const stylesheet = $.stylesheet;
|
|
31
|
+
const cssTextMap = new Map<string, $CSSStyleRule>();
|
|
68
32
|
|
|
69
|
-
const
|
|
33
|
+
export const valueInstances = new Set<any>();
|
|
34
|
+
export const cssTextProcessors = new Set<$TextProcessor>();
|
|
35
|
+
export type $TextProcessor = (rule: $CSSRule, context: string, data?: {mediaContext?: string[], containerContext?: string[]}) => string[] | undefined;
|
|
36
|
+
export const createRuleProcessors = new Set<$CreateRuleProcessor>();
|
|
37
|
+
export type $CreateRuleProcessor = (selector: string, options: $CSSMap, context?: string) => $CSSRule | undefined;
|
|
70
38
|
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
})
|
|
85
|
-
return rule;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
const insertRule = (rule: $CSSRule) => {
|
|
89
|
-
cssText(rule).forEach(text => {
|
|
90
|
-
const selector = text.match(/^(.+?) {/)?.[1];
|
|
91
|
-
if (!selector) return;
|
|
92
|
-
if (!startsWith(selector, '@') && selector.split(',').find(str => !CSS.supports(`selector(${str})`))) return;
|
|
93
|
-
$.style(text, stylesheet.cssRules.length);
|
|
94
|
-
})
|
|
95
|
-
return rule
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const cssText = (rule: $CSSRule, context: string = '', options?: {mediaContext?: string[], containerContext?: string[]}): string[] => {
|
|
99
|
-
if (_instanceof(rule, $CSSStyleRule)) {
|
|
100
|
-
const split = (str: string) => str.split(',');
|
|
101
|
-
const relation = (str: string, ctx: string): string => {
|
|
102
|
-
if (str.includes('&')) return str.replaceAll('&', ctx);
|
|
103
|
-
else return `${ctx ? ctx + ' ': ''}${str}`
|
|
39
|
+
export const CSSOptions = <T extends $CSSStyleRule>(
|
|
40
|
+
rule: T,
|
|
41
|
+
options: $CSSMap,
|
|
42
|
+
): T => {
|
|
43
|
+
for (const [key, value] of _Object_entries(options)) {
|
|
44
|
+
if (isUndefined(value)) continue;
|
|
45
|
+
else if (_instanceof(value, $CSSDeclaration)) rule.declarations.set(value.key, value);
|
|
46
|
+
else if (isObject(value) && !_instanceof(value, ...valueInstances))
|
|
47
|
+
rule.rules.add( createRule(key, value, rule.selector) );
|
|
48
|
+
else {
|
|
49
|
+
const declaration = new $CSSDeclaration(key, `${value}`);
|
|
50
|
+
rule.declarations.set(declaration.key, declaration);
|
|
51
|
+
}
|
|
104
52
|
}
|
|
105
|
-
|
|
106
|
-
const selector = split(context).map(ctx => selectors.map(selector => relation(selector, ctx))).join(', ');
|
|
107
|
-
const text = `${selector} { ${_Array_from(rule.declarations).map(([_, dec]) => `${dec}`).join(' ')} }`
|
|
108
|
-
return [text, ..._Array_from(rule.rules).map(childRule => cssText(childRule, selector, options)).flat()]
|
|
109
|
-
}
|
|
110
|
-
if (_instanceof(rule, $CSSMediaRule)) {
|
|
111
|
-
const mediaContext = [...options?.mediaContext ?? [], rule.condition];
|
|
112
|
-
const media: string[] = [], style: string[] = []
|
|
113
|
-
forEach(
|
|
114
|
-
_Array_from(rule.rules)
|
|
115
|
-
.map(childRule => cssText(childRule, '', {...options, mediaContext}))
|
|
116
|
-
.flat(),
|
|
117
|
-
(childText => startsWith(childText, MEDIA) ? media.push(childText) : style.push(childText))
|
|
118
|
-
);
|
|
119
|
-
return [`${MEDIA} ${mediaContext.join(' and ')} { ${style.join('\n')} }`, ...media]
|
|
53
|
+
return rule;
|
|
120
54
|
}
|
|
121
|
-
if (_instanceof(rule, $CSSContainerRule)) {
|
|
122
|
-
const containerContext = [...options?.containerContext ?? [], rule.condition];
|
|
123
|
-
const container: string[] = [], style: string[] = [];
|
|
124
|
-
forEach(
|
|
125
|
-
_Array_from(rule.rules)
|
|
126
|
-
.map(childRule => cssText(childRule, '', {...options, containerContext}))
|
|
127
|
-
.flat(),
|
|
128
|
-
(childText => startsWith(childText, CONTAINER) ? container.push(childText) : style.push(childText))
|
|
129
|
-
);
|
|
130
|
-
return [`${CONTAINER} ${rule.name} ${containerContext.join(' and ')} { ${style.join('\n')} }`, ...container]
|
|
131
|
-
}
|
|
132
|
-
if (_instanceof(rule, $CSSKeyframesRule)) {
|
|
133
|
-
return [`${KEYFRAMES} ${rule.name} { ${_Array_from(rule.rules).map(childRule => cssText(childRule, context, options)).join('\n')} }`]
|
|
134
|
-
}
|
|
135
|
-
throw '$CSS RULE TYPE ERROR'
|
|
136
|
-
}
|
|
137
55
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return insertRule( rule );
|
|
148
|
-
},
|
|
149
|
-
CSS(options: $CSSSelectorType | $CSSMediaRule) {
|
|
150
|
-
return _Object_entries(options).map(([selector, declarations]) => {
|
|
151
|
-
return insertRule( createRule(selector, declarations) );
|
|
152
|
-
})
|
|
56
|
+
/** Create rule with several type depend on selector content.
|
|
57
|
+
* @param context - for media rule creation, it should be style rule selector same as nested parent of media rule.
|
|
58
|
+
*/
|
|
59
|
+
export const createRule = (selector: string, options: $CSSMap, context?: string) => {
|
|
60
|
+
for (const processor of createRuleProcessors) {
|
|
61
|
+
const result = processor(selector, options, context);
|
|
62
|
+
if (!isUndefined(result)) return result;
|
|
63
|
+
}
|
|
64
|
+
return createStyleRule(selector, options);
|
|
153
65
|
}
|
|
154
|
-
})
|
|
155
66
|
|
|
156
|
-
|
|
157
|
-
variables<T extends $CSSVariableType | string>(options: T, conditions?: $CSSVariableConditionType<T>) {
|
|
158
|
-
if (isObject(options)) {
|
|
159
|
-
const variables = _Object_fromEntries(_Object_entries(options).map(([key, value]) => [
|
|
160
|
-
key,
|
|
161
|
-
new $CSSVariable(`${key.replaceAll(/([A-Z])/g, ((_, $1: string) => `-${$1.toLowerCase()}`))}_${generateId('lower')}`, `${value}`)
|
|
162
|
-
]))
|
|
67
|
+
const createStyleRule = <T extends $CSSMap>(selector: string, options: T) => CSSOptions(new $CSSStyleRule(selector), options);
|
|
163
68
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
$.
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
69
|
+
export const insertRule = (rule: $CSSRule) => {
|
|
70
|
+
cssText(rule).forEach(text => {
|
|
71
|
+
const selector = text.match(/^(.+?) {/)?.[1];
|
|
72
|
+
if (!selector) return;
|
|
73
|
+
if (!startsWith(selector, '@') && selector.split(',').find(str => !CSS.supports(`selector(${str})`))) return;
|
|
74
|
+
$.style(text, stylesheet.cssRules.length);
|
|
75
|
+
})
|
|
76
|
+
return rule
|
|
77
|
+
}
|
|
173
78
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
79
|
+
export const cssText = (rule: $CSSRule, context: string = '', data?: {mediaContext?: string[], containerContext?: string[]}): string[] => {
|
|
80
|
+
if (_instanceof(rule, $CSSStyleRule)) {
|
|
81
|
+
const split = (str: string) => str.split(',');
|
|
82
|
+
const relation = (str: string, ctx: string): string => {
|
|
83
|
+
if (str.includes('&')) return str.replaceAll('&', ctx);
|
|
84
|
+
else return `${ctx ? ctx + ' ': ''}${str}`
|
|
85
|
+
}
|
|
86
|
+
const selectors = split(rule.selector);
|
|
87
|
+
const selector = split(context).map(ctx => selectors.map(selector => relation(selector, ctx))).join(', ');
|
|
88
|
+
const text = `${selector} { ${_Array_from(rule.declarations).map(([_, dec]) => `${dec}`).join(' ')} }`
|
|
89
|
+
return [text, ..._Array_from(rule.rules).map(childRule => cssText(childRule, selector, data)).flat()]
|
|
90
|
+
}
|
|
91
|
+
for (const processor of cssTextProcessors) {
|
|
92
|
+
const result = processor(rule, context, data);
|
|
93
|
+
if (!isUndefined(result)) return result;
|
|
179
94
|
}
|
|
180
|
-
|
|
181
|
-
keyframes(options: $CSSKeyframesType) {
|
|
182
|
-
return _Object_fromEntries( _Object_entries(options).map(([name, value]) => {
|
|
183
|
-
return [name, insertRule( createKeyframesRule(`${name}_${generateId()}`, value) )];
|
|
184
|
-
}) )
|
|
95
|
+
throw '$CSS RULE TYPE ERROR'
|
|
185
96
|
}
|
|
186
|
-
})
|
|
187
97
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
98
|
+
// Add $.css and $.CSS methods
|
|
99
|
+
_Object_assign($, {
|
|
100
|
+
css(options: $CSSMap | $CSSStyleRule) {
|
|
101
|
+
if (_instanceof(options, $CSSRule)) return options;
|
|
102
|
+
const cssText = _JSON_stringify(options);
|
|
103
|
+
const cacheRule = cssTextMap.get(cssText);
|
|
104
|
+
if (cacheRule) return cacheRule;
|
|
105
|
+
const className = `.${generateId()}`;
|
|
106
|
+
const rule = createStyleRule(className, options);
|
|
107
|
+
cssTextMap.set(_JSON_stringify(options), rule);
|
|
108
|
+
return insertRule( rule );
|
|
109
|
+
},
|
|
110
|
+
CSS(options: $CSSSelectors) {
|
|
111
|
+
return _Object_entries(options).map(([selector, declarations]) => {
|
|
112
|
+
return insertRule( createRule(selector, declarations) );
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
// Add $Element.css method
|
|
118
|
+
_Object_assign($Element.prototype, {
|
|
119
|
+
css(this: $Element, ...options: ($CSSMap | $CSSStyleRule)[]) {
|
|
120
|
+
forEach(options, options => {
|
|
121
|
+
const rule = $.css(options);
|
|
122
|
+
this.addClass(rule.selector.replace(/^./, ''));
|
|
123
|
+
})
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
}
|
|
197
128
|
|
|
198
129
|
export * from "#structure/$CSSDeclaration";
|
|
199
|
-
export * from "#structure/$CSSKeyframesRule";
|
|
200
|
-
export * from "#structure/$CSSMediaRule";
|
|
201
130
|
export * from "#structure/$CSSRule";
|
|
202
131
|
export * from "#structure/$CSSStyleRule";
|
|
203
|
-
export * from "#structure/$CSSVariable";
|
|
204
132
|
|
|
205
|
-
export type $
|
|
206
|
-
export type $CSSValueType = '' | 'unset' | 'initial' | 'inherit' | string & {} | number |
|
|
207
|
-
export type $
|
|
208
|
-
export type $
|
|
209
|
-
export type $CSSVariableType<T = any> = { [key in keyof T]: $CSSValueType }
|
|
210
|
-
export type $CSSVariableConditionType<T extends $CSSVariableType | string> = T extends string ? { [key: string]: $CSSValueType } : { [key: string]: Partial<$CSSVariableType<T>> }
|
|
211
|
-
export type $CSSKeyframesSelectorType = { [key: `@keyframes ${string}`]: $CSSKeyframesType }
|
|
212
|
-
export type $CSSKeyframesType = { [key: `${number}%`]: $CSSDeclarationType } | { from?: $CSSDeclarationType, to?: $CSSDeclarationType }
|
|
133
|
+
export type $CSSMap = $CSSDeclarations | $CSSSelectors;
|
|
134
|
+
export type $CSSValueType = '' | 'unset' | 'initial' | 'inherit' | string & {} | number | $.$CSSValueTypeExtends
|
|
135
|
+
export type $CSSDeclarations = { [key in keyof $CSSDeclarationMap]?: $CSSDeclarationMap[key] | $CSSValueType } | { [key: string]: $CSSValueType }
|
|
136
|
+
export type $CSSSelectors = { [key: string & {}]: $CSSMap }
|
|
213
137
|
|
|
214
|
-
|
|
138
|
+
interface $CSSDeclarationMap {
|
|
215
139
|
alignContent: 'flex-start' | 'flex-end' | 'center' | 'space-between' | 'space-around' | 'space-evenly' | 'stretch' | 'normal';
|
|
216
140
|
alignItems: 'normal' | 'stretch' | 'center' | 'flex-start' | 'flex-end' | 'baseline';
|
|
217
141
|
alignSelf: 'auto' | 'normal' | 'stretch' | 'center' | 'flex-start' | 'flex-end' | 'baseline';
|
|
218
142
|
all: 'initial' | 'inherit' | 'unset';
|
|
219
|
-
animation: string
|
|
143
|
+
animation: string;
|
|
220
144
|
animationDelay: string;
|
|
221
145
|
animationDirection: 'normal' | 'reverse' | 'alternate' | 'alternate-reverse';
|
|
222
146
|
animationDuration: string;
|
|
223
147
|
animationFillMode: 'none' | 'forwards' | 'backwards' | 'both';
|
|
224
148
|
animationIterationCount: 'infinite' | number;
|
|
225
|
-
animationName: string
|
|
149
|
+
animationName: string;
|
|
226
150
|
animationPlayState: 'running' | 'paused';
|
|
227
151
|
animationTimingFunction: 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out' | 'linear' | 'step-start' | 'step-end';
|
|
228
152
|
animationComposition: 'replace' | 'add' | 'accumulate';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { randomId } from "@amateras/utils";
|
|
2
|
+
|
|
3
|
+
const generatedIds = new Set<string>();
|
|
4
|
+
export const generateId = (lettercase: 'any' | 'lower' | 'upper' = 'any'): string => {
|
|
5
|
+
const id = randomId({lettercase: lettercase});
|
|
6
|
+
if (generatedIds.has(id)) return generateId(lettercase);
|
|
7
|
+
generatedIds.add(id);
|
|
8
|
+
return id;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const camelCaseToDash = (str: string) => str.replaceAll(/([A-Z])/g, ((_, $1: string) => `-${$1.toLowerCase()}`))
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { _Object_assign } from "@amateras/utils";
|
|
2
|
+
|
|
3
|
+
export interface $CSSPropertyOptions {
|
|
4
|
+
name: string;
|
|
5
|
+
syntax: string;
|
|
6
|
+
initialValue: string;
|
|
7
|
+
inherits: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface $CSSProperty extends $CSSPropertyOptions {}
|
|
11
|
+
export class $CSSProperty {
|
|
12
|
+
constructor(options: $CSSPropertyOptions) {
|
|
13
|
+
_Object_assign(this, options);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
toString() {
|
|
17
|
+
return `var(${this.name})`
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { $CSSDeclaration } from "#structure/$CSSDeclaration";
|
|
2
2
|
import { $CSSRule } from "#structure/$CSSRule";
|
|
3
|
-
import { _Array_from, _instanceof, _Object_fromEntries } from "amateras/
|
|
3
|
+
import { _Array_from, _instanceof, _Object_fromEntries } from "@amateras/utils";
|
|
4
4
|
|
|
5
5
|
export class $CSSStyleRule extends $CSSRule {
|
|
6
6
|
declarations = new Map<string, $CSSDeclaration>();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { _document } from "@amateras/core/env";
|
|
2
|
+
|
|
3
|
+
const documentElementStyle = _document.documentElement.style;
|
|
4
|
+
|
|
5
|
+
export class $CSSVariable<V = string> {
|
|
6
|
+
name: string;
|
|
7
|
+
value: V;
|
|
8
|
+
constructor(key: string, value: V) {
|
|
9
|
+
this.name = key;
|
|
10
|
+
this.value = value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
set(value: string) {
|
|
14
|
+
documentElementStyle.setProperty(`${this.name}`, value);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
reset() {
|
|
19
|
+
documentElementStyle.removeProperty(`${this.name}`);
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
default(value: string | $CSSVariable) {
|
|
24
|
+
return `var(${this.name}, ${value})`
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
toString() {
|
|
28
|
+
return `var(${this.name})`
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amateras/dom",
|
|
3
|
+
"peerDependencies": {
|
|
4
|
+
"@amateras/core": "workspace:*",
|
|
5
|
+
"@amateras/utils": "workspace:*"
|
|
6
|
+
},
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"node-html-parser": "^7.0.1"
|
|
9
|
+
},
|
|
10
|
+
"imports": {
|
|
11
|
+
"#structure/*": "./src/structure/*.ts",
|
|
12
|
+
"#lib/*": "./src/lib/*.ts",
|
|
13
|
+
"#node/*": "./src/node/*.ts"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
"./structure/*": "./src/structure/*.ts",
|
|
17
|
+
"./lib/*": "./src/lib/*.ts",
|
|
18
|
+
"./node/*": "./src/node/*.ts"
|
|
19
|
+
}
|
|
20
|
+
}
|