@dxos/ui 0.8.4-main.ef1bc66f44 → 0.8.4-main.f466a3d56e
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/LICENSE +102 -5
- package/README.md +1 -1
- package/dist/lib/browser/index.mjs +25 -5
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +25 -5
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/domino.d.ts +21 -2
- package/dist/types/src/domino.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -7
- package/src/domino.test.ts +29 -1
- package/src/domino.ts +48 -6
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2022 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
package/README.md
CHANGED
|
@@ -18,4 +18,4 @@ pnpm i @dxos/ui
|
|
|
18
18
|
|
|
19
19
|
Your ideas, issues, and code are most welcome. Please take a look at our [community code of conduct](https://github.com/dxos/dxos/blob/main/CODE_OF_CONDUCT.md), the [issue guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-issues), and the [PR contribution guide](https://github.com/dxos/dxos/blob/main/CONTRIBUTING.md#submitting-prs).
|
|
20
20
|
|
|
21
|
-
License: [
|
|
21
|
+
License: [FSL-1.1-Apache-2.0](./LICENSE) Copyright 2022 © DXOS
|
|
@@ -8,10 +8,22 @@ var hasIosKeyboard = () => {
|
|
|
8
8
|
|
|
9
9
|
// src/domino.ts
|
|
10
10
|
import { mx } from "@dxos/ui-theme";
|
|
11
|
-
var
|
|
11
|
+
var DEFAULT_ICONS_URL = "/icons.svg";
|
|
12
12
|
var Domino = class _Domino {
|
|
13
13
|
static SVG = "http://www.w3.org/2000/svg";
|
|
14
|
-
|
|
14
|
+
/** Overridable at module level so `Domino.svg()` can resolve from any origin. */
|
|
15
|
+
static iconsUrl = DEFAULT_ICONS_URL;
|
|
16
|
+
// TODO(burdon): Make private.
|
|
17
|
+
static icon = (icon) => _Domino.iconsUrl + "#" + icon;
|
|
18
|
+
/**
|
|
19
|
+
* Creates an SVG icon element from the icon sprite sheet.
|
|
20
|
+
*/
|
|
21
|
+
// TODO(burdon): Rename icon.
|
|
22
|
+
static svg = (icon) => _Domino.of("svg", _Domino.SVG).classNames("shrink-0 h-[1em] w-[1em]").attributes({
|
|
23
|
+
viewBox: "0 0 256 256"
|
|
24
|
+
}).append(_Domino.of("use", _Domino.SVG).attributes({
|
|
25
|
+
href: _Domino.icon(icon)
|
|
26
|
+
}));
|
|
15
27
|
static of(tag, namespace) {
|
|
16
28
|
return new _Domino(tag, namespace);
|
|
17
29
|
}
|
|
@@ -48,12 +60,20 @@ var Domino = class _Domino {
|
|
|
48
60
|
Object.assign(this._el.style, styles);
|
|
49
61
|
return this;
|
|
50
62
|
}
|
|
51
|
-
|
|
63
|
+
append(...children) {
|
|
52
64
|
children.forEach((child) => this._el.appendChild(child.root));
|
|
53
65
|
return this;
|
|
54
66
|
}
|
|
55
|
-
on(event, handler) {
|
|
56
|
-
this._el.addEventListener(event, handler);
|
|
67
|
+
on(event, handler, options) {
|
|
68
|
+
this._el.addEventListener(event, handler, options);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Convenience for attaching the root element to a parent node — useful at
|
|
73
|
+
* the end of a chain to avoid a trailing `.root` / `parent.appendChild()`.
|
|
74
|
+
*/
|
|
75
|
+
mount(parent) {
|
|
76
|
+
parent.appendChild(this._el);
|
|
57
77
|
return this;
|
|
58
78
|
}
|
|
59
79
|
get root() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/device.ts", "../../../src/domino.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport { mx } from '@dxos/ui-theme';\nexport type { ThemedClassName } from '@dxos/ui-types';\n\nexport * from './device';\nexport * from './domino';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nexport const hasIosKeyboard = () => {\n // TODO(thure): UA sniffing is never good, however I haven’t found a better way to query for whether the on-screen keyboard will appear on `focus` outside of a click handler.\n return !!navigator.userAgent.match(/(iPad|iPod|iPhone).+Safari/);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { mx } from '@dxos/ui-theme';\nimport { type ClassNameValue } from '@dxos/ui-types';\n\n
|
|
5
|
-
"mappings": ";AAIA,SAASA,MAAAA,WAAU;;;ACAZ,IAAMC,iBAAiB,MAAA;AAE5B,SAAO,CAAC,CAACC,UAAUC,UAAUC,MAAM,4BAAA;AACrC;;;ACHA,SAASC,UAAU;
|
|
6
|
-
"names": ["mx", "hasIosKeyboard", "navigator", "userAgent", "match", "mx", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport { mx } from '@dxos/ui-theme';\nexport type { ThemedClassName } from '@dxos/ui-types';\n\nexport * from './device';\nexport * from './domino';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nexport const hasIosKeyboard = () => {\n // TODO(thure): UA sniffing is never good, however I haven’t found a better way to query for whether the on-screen keyboard will appear on `focus` outside of a click handler.\n return !!navigator.userAgent.match(/(iPad|iPod|iPhone).+Safari/);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { mx } from '@dxos/ui-theme';\nimport { type ClassNameValue } from '@dxos/ui-types';\n\n/**\n * Base URL of the icon sprite sheet emitted by `@dxos/vite-plugin-icons`.\n * Defaults to `/icons.svg` which works inside hosted apps served at the\n * site root. Callers running in a different origin context (e.g. browser\n * extensions that inject into arbitrary pages) can override by assigning\n * `Domino.iconsUrl` before first use.\n */\nconst DEFAULT_ICONS_URL = '/icons.svg';\n\n/**\n * Super lightweight chainable DOM builder.\n */\nexport class Domino<T extends HTMLElement | SVGElement> {\n static SVG = 'http://www.w3.org/2000/svg';\n\n /** Overridable at module level so `Domino.svg()` can resolve from any origin. */\n static iconsUrl: string = DEFAULT_ICONS_URL;\n\n // TODO(burdon): Make private.\n static icon = (icon: string) => Domino.iconsUrl + '#' + icon;\n\n /**\n * Creates an SVG icon element from the icon sprite sheet.\n */\n // TODO(burdon): Rename icon.\n static svg = (icon: string) =>\n Domino.of('svg', Domino.SVG)\n .classNames('shrink-0 h-[1em] w-[1em]')\n .attributes({ viewBox: '0 0 256 256' })\n .append(Domino.of('use', Domino.SVG).attributes({ href: Domino.icon(icon) }));\n\n /**\n * Create builder from DOM node.\n */\n static of<K extends keyof HTMLElementTagNameMap>(tag: K): Domino<HTMLElementTagNameMap[K]>;\n static of<K extends keyof SVGElementTagNameMap>(tag: K, namespace: string): Domino<SVGElementTagNameMap[K]>;\n static of(tag: string, namespace?: string): Domino<HTMLElement | SVGElement> {\n return new Domino(tag, namespace);\n }\n\n private readonly _el: T;\n\n private constructor(tag: string, namespace?: string) {\n if (namespace) {\n this._el = document.createElementNS(namespace, tag) as T;\n } else {\n this._el = document.createElement(tag) as T;\n }\n }\n\n classNames(...classNames: ClassNameValue[]): this {\n const merged = mx(classNames);\n if (this._el instanceof HTMLElement || this._el instanceof SVGElement) {\n this._el.setAttribute('class', merged);\n }\n return this;\n }\n\n text(value: string): this {\n this._el.textContent = value;\n return this;\n }\n\n data(key: string, value: string): this {\n if (this._el instanceof HTMLElement) {\n this._el.dataset[key] = value;\n }\n return this;\n }\n\n attributes(attr: Record<string, string | undefined>): this {\n Object.entries(attr)\n .filter(([_, value]) => value !== undefined)\n .map(([key, value]) => this._el.setAttribute(key, value!));\n return this;\n }\n\n style(styles: Partial<CSSStyleDeclaration>): this {\n Object.assign(this._el.style, styles);\n return this;\n }\n\n append<C extends HTMLElement | SVGElement>(...children: Domino<C>[]): this {\n children.forEach((child) => this._el.appendChild(child.root));\n return this;\n }\n\n /**\n * Typed event listener. Accepts the standard `AddEventListenerOptions`\n * third argument so callers can opt into `capture`, `once`, `passive`.\n */\n on<K extends keyof HTMLElementEventMap>(\n event: K,\n handler: (e: HTMLElementEventMap[K]) => void,\n options?: boolean | AddEventListenerOptions,\n ): this;\n on(event: string, handler: (e: Event) => void, options?: boolean | AddEventListenerOptions): this;\n on(event: string, handler: (e: Event) => void, options?: boolean | AddEventListenerOptions): this {\n this._el.addEventListener(event, handler, options);\n return this;\n }\n\n /**\n * Convenience for attaching the root element to a parent node — useful at\n * the end of a chain to avoid a trailing `.root` / `parent.appendChild()`.\n */\n mount(parent: Node): this {\n parent.appendChild(this._el);\n return this;\n }\n\n get root(): T {\n return this._el;\n }\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,MAAAA,WAAU;;;ACAZ,IAAMC,iBAAiB,MAAA;AAE5B,SAAO,CAAC,CAACC,UAAUC,UAAUC,MAAM,4BAAA;AACrC;;;ACHA,SAASC,UAAU;AAUnB,IAAMC,oBAAoB;AAKnB,IAAMC,SAAN,MAAMA,QAAAA;EACX,OAAOC,MAAM;;EAGb,OAAOC,WAAmBH;;EAG1B,OAAOI,OAAO,CAACA,SAAiBH,QAAOE,WAAW,MAAMC;;;;;EAMxD,OAAOC,MAAM,CAACD,SACZH,QAAOK,GAAG,OAAOL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ACT;EAYAC,GAAGC,OAAeC,SAA6BC,SAAmD;AAChG,SAAKhC,IAAIiC,iBAAiBH,OAAOC,SAASC,OAAAA;AAC1C,WAAO;EACT;;;;;EAMAE,MAAMC,QAAoB;AACxBA,WAAOR,YAAY,KAAK3B,GAAG;AAC3B,WAAO;EACT;EAEA,IAAI4B,OAAU;AACZ,WAAO,KAAK5B;EACd;AACF;",
|
|
6
|
+
"names": ["mx", "hasIosKeyboard", "navigator", "userAgent", "match", "mx", "DEFAULT_ICONS_URL", "Domino", "SVG", "iconsUrl", "icon", "svg", "of", "classNames", "attributes", "viewBox", "append", "href", "tag", "namespace", "_el", "document", "createElementNS", "createElement", "merged", "HTMLElement", "SVGElement", "setAttribute", "text", "value", "textContent", "data", "key", "dataset", "attr", "Object", "entries", "filter", "_", "undefined", "map", "style", "styles", "assign", "children", "forEach", "child", "appendChild", "root", "on", "event", "handler", "options", "addEventListener", "mount", "parent"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/device.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/device.ts":{"bytes":1162,"imports":[],"format":"esm"},"src/domino.ts":{"bytes":11242,"imports":[{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":665,"imports":[{"path":"@dxos/ui-theme","kind":"import-statement","external":true},{"path":"src/device.ts","kind":"import-statement","original":"./device"},{"path":"src/domino.ts","kind":"import-statement","original":"./domino"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":6753},"dist/lib/browser/index.mjs":{"imports":[{"path":"@dxos/ui-theme","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"exports":["Domino","hasIosKeyboard","mx"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":44},"src/device.ts":{"bytesInOutput":100},"src/domino.ts":{"bytesInOutput":2119}},"bytes":2402}}}
|
|
@@ -10,10 +10,22 @@ var hasIosKeyboard = () => {
|
|
|
10
10
|
|
|
11
11
|
// src/domino.ts
|
|
12
12
|
import { mx } from "@dxos/ui-theme";
|
|
13
|
-
var
|
|
13
|
+
var DEFAULT_ICONS_URL = "/icons.svg";
|
|
14
14
|
var Domino = class _Domino {
|
|
15
15
|
static SVG = "http://www.w3.org/2000/svg";
|
|
16
|
-
|
|
16
|
+
/** Overridable at module level so `Domino.svg()` can resolve from any origin. */
|
|
17
|
+
static iconsUrl = DEFAULT_ICONS_URL;
|
|
18
|
+
// TODO(burdon): Make private.
|
|
19
|
+
static icon = (icon) => _Domino.iconsUrl + "#" + icon;
|
|
20
|
+
/**
|
|
21
|
+
* Creates an SVG icon element from the icon sprite sheet.
|
|
22
|
+
*/
|
|
23
|
+
// TODO(burdon): Rename icon.
|
|
24
|
+
static svg = (icon) => _Domino.of("svg", _Domino.SVG).classNames("shrink-0 h-[1em] w-[1em]").attributes({
|
|
25
|
+
viewBox: "0 0 256 256"
|
|
26
|
+
}).append(_Domino.of("use", _Domino.SVG).attributes({
|
|
27
|
+
href: _Domino.icon(icon)
|
|
28
|
+
}));
|
|
17
29
|
static of(tag, namespace) {
|
|
18
30
|
return new _Domino(tag, namespace);
|
|
19
31
|
}
|
|
@@ -50,12 +62,20 @@ var Domino = class _Domino {
|
|
|
50
62
|
Object.assign(this._el.style, styles);
|
|
51
63
|
return this;
|
|
52
64
|
}
|
|
53
|
-
|
|
65
|
+
append(...children) {
|
|
54
66
|
children.forEach((child) => this._el.appendChild(child.root));
|
|
55
67
|
return this;
|
|
56
68
|
}
|
|
57
|
-
on(event, handler) {
|
|
58
|
-
this._el.addEventListener(event, handler);
|
|
69
|
+
on(event, handler, options) {
|
|
70
|
+
this._el.addEventListener(event, handler, options);
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Convenience for attaching the root element to a parent node — useful at
|
|
75
|
+
* the end of a chain to avoid a trailing `.root` / `parent.appendChild()`.
|
|
76
|
+
*/
|
|
77
|
+
mount(parent) {
|
|
78
|
+
parent.appendChild(this._el);
|
|
59
79
|
return this;
|
|
60
80
|
}
|
|
61
81
|
get root() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts", "../../../src/device.ts", "../../../src/domino.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport { mx } from '@dxos/ui-theme';\nexport type { ThemedClassName } from '@dxos/ui-types';\n\nexport * from './device';\nexport * from './domino';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nexport const hasIosKeyboard = () => {\n // TODO(thure): UA sniffing is never good, however I haven’t found a better way to query for whether the on-screen keyboard will appear on `focus` outside of a click handler.\n return !!navigator.userAgent.match(/(iPad|iPod|iPhone).+Safari/);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { mx } from '@dxos/ui-theme';\nimport { type ClassNameValue } from '@dxos/ui-types';\n\n
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,MAAAA,WAAU;;;ACAZ,IAAMC,iBAAiB,MAAA;AAE5B,SAAO,CAAC,CAACC,UAAUC,UAAUC,MAAM,4BAAA;AACrC;;;ACHA,SAASC,UAAU;
|
|
6
|
-
"names": ["mx", "hasIosKeyboard", "navigator", "userAgent", "match", "mx", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport { mx } from '@dxos/ui-theme';\nexport type { ThemedClassName } from '@dxos/ui-types';\n\nexport * from './device';\nexport * from './domino';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nexport const hasIosKeyboard = () => {\n // TODO(thure): UA sniffing is never good, however I haven’t found a better way to query for whether the on-screen keyboard will appear on `focus` outside of a click handler.\n return !!navigator.userAgent.match(/(iPad|iPod|iPhone).+Safari/);\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { mx } from '@dxos/ui-theme';\nimport { type ClassNameValue } from '@dxos/ui-types';\n\n/**\n * Base URL of the icon sprite sheet emitted by `@dxos/vite-plugin-icons`.\n * Defaults to `/icons.svg` which works inside hosted apps served at the\n * site root. Callers running in a different origin context (e.g. browser\n * extensions that inject into arbitrary pages) can override by assigning\n * `Domino.iconsUrl` before first use.\n */\nconst DEFAULT_ICONS_URL = '/icons.svg';\n\n/**\n * Super lightweight chainable DOM builder.\n */\nexport class Domino<T extends HTMLElement | SVGElement> {\n static SVG = 'http://www.w3.org/2000/svg';\n\n /** Overridable at module level so `Domino.svg()` can resolve from any origin. */\n static iconsUrl: string = DEFAULT_ICONS_URL;\n\n // TODO(burdon): Make private.\n static icon = (icon: string) => Domino.iconsUrl + '#' + icon;\n\n /**\n * Creates an SVG icon element from the icon sprite sheet.\n */\n // TODO(burdon): Rename icon.\n static svg = (icon: string) =>\n Domino.of('svg', Domino.SVG)\n .classNames('shrink-0 h-[1em] w-[1em]')\n .attributes({ viewBox: '0 0 256 256' })\n .append(Domino.of('use', Domino.SVG).attributes({ href: Domino.icon(icon) }));\n\n /**\n * Create builder from DOM node.\n */\n static of<K extends keyof HTMLElementTagNameMap>(tag: K): Domino<HTMLElementTagNameMap[K]>;\n static of<K extends keyof SVGElementTagNameMap>(tag: K, namespace: string): Domino<SVGElementTagNameMap[K]>;\n static of(tag: string, namespace?: string): Domino<HTMLElement | SVGElement> {\n return new Domino(tag, namespace);\n }\n\n private readonly _el: T;\n\n private constructor(tag: string, namespace?: string) {\n if (namespace) {\n this._el = document.createElementNS(namespace, tag) as T;\n } else {\n this._el = document.createElement(tag) as T;\n }\n }\n\n classNames(...classNames: ClassNameValue[]): this {\n const merged = mx(classNames);\n if (this._el instanceof HTMLElement || this._el instanceof SVGElement) {\n this._el.setAttribute('class', merged);\n }\n return this;\n }\n\n text(value: string): this {\n this._el.textContent = value;\n return this;\n }\n\n data(key: string, value: string): this {\n if (this._el instanceof HTMLElement) {\n this._el.dataset[key] = value;\n }\n return this;\n }\n\n attributes(attr: Record<string, string | undefined>): this {\n Object.entries(attr)\n .filter(([_, value]) => value !== undefined)\n .map(([key, value]) => this._el.setAttribute(key, value!));\n return this;\n }\n\n style(styles: Partial<CSSStyleDeclaration>): this {\n Object.assign(this._el.style, styles);\n return this;\n }\n\n append<C extends HTMLElement | SVGElement>(...children: Domino<C>[]): this {\n children.forEach((child) => this._el.appendChild(child.root));\n return this;\n }\n\n /**\n * Typed event listener. Accepts the standard `AddEventListenerOptions`\n * third argument so callers can opt into `capture`, `once`, `passive`.\n */\n on<K extends keyof HTMLElementEventMap>(\n event: K,\n handler: (e: HTMLElementEventMap[K]) => void,\n options?: boolean | AddEventListenerOptions,\n ): this;\n on(event: string, handler: (e: Event) => void, options?: boolean | AddEventListenerOptions): this;\n on(event: string, handler: (e: Event) => void, options?: boolean | AddEventListenerOptions): this {\n this._el.addEventListener(event, handler, options);\n return this;\n }\n\n /**\n * Convenience for attaching the root element to a parent node — useful at\n * the end of a chain to avoid a trailing `.root` / `parent.appendChild()`.\n */\n mount(parent: Node): this {\n parent.appendChild(this._el);\n return this;\n }\n\n get root(): T {\n return this._el;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,MAAAA,WAAU;;;ACAZ,IAAMC,iBAAiB,MAAA;AAE5B,SAAO,CAAC,CAACC,UAAUC,UAAUC,MAAM,4BAAA;AACrC;;;ACHA,SAASC,UAAU;AAUnB,IAAMC,oBAAoB;AAKnB,IAAMC,SAAN,MAAMA,QAAAA;EACX,OAAOC,MAAM;;EAGb,OAAOC,WAAmBH;;EAG1B,OAAOI,OAAO,CAACA,SAAiBH,QAAOE,WAAW,MAAMC;;;;;EAMxD,OAAOC,MAAM,CAACD,SACZH,QAAOK,GAAG,OAAOL,QAAOC,GAAG,EACxBK,WAAW,0BAAA,EACXC,WAAW;IAAEC,SAAS;EAAc,CAAA,EACpCC,OAAOT,QAAOK,GAAG,OAAOL,QAAOC,GAAG,EAAEM,WAAW;IAAEG,MAAMV,QAAOG,KA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,KAAK3B,GAAG;AAC3B,WAAO;EACT;EAEA,IAAI4B,OAAU;AACZ,WAAO,KAAK5B;EACd;AACF;",
|
|
6
|
+
"names": ["mx", "hasIosKeyboard", "navigator", "userAgent", "match", "mx", "DEFAULT_ICONS_URL", "Domino", "SVG", "iconsUrl", "icon", "svg", "of", "classNames", "attributes", "viewBox", "append", "href", "tag", "namespace", "_el", "document", "createElementNS", "createElement", "merged", "HTMLElement", "SVGElement", "setAttribute", "text", "value", "textContent", "data", "key", "dataset", "attr", "Object", "entries", "filter", "_", "undefined", "map", "style", "styles", "assign", "children", "forEach", "child", "appendChild", "root", "on", "event", "handler", "options", "addEventListener", "mount", "parent"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/device.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/device.ts":{"bytes":1162,"imports":[],"format":"esm"},"src/domino.ts":{"bytes":11242,"imports":[{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":665,"imports":[{"path":"@dxos/ui-theme","kind":"import-statement","external":true},{"path":"src/device.ts","kind":"import-statement","original":"./device"},{"path":"src/domino.ts","kind":"import-statement","original":"./domino"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":6755},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"@dxos/ui-theme","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"exports":["Domino","hasIosKeyboard","mx"],"entryPoint":"src/index.ts","inputs":{"src/index.ts":{"bytesInOutput":44},"src/device.ts":{"bytesInOutput":100},"src/domino.ts":{"bytesInOutput":2119}},"bytes":2495}}}
|
|
@@ -4,7 +4,16 @@ import { type ClassNameValue } from '@dxos/ui-types';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare class Domino<T extends HTMLElement | SVGElement> {
|
|
6
6
|
static SVG: string;
|
|
7
|
+
/** Overridable at module level so `Domino.svg()` can resolve from any origin. */
|
|
8
|
+
static iconsUrl: string;
|
|
7
9
|
static icon: (icon: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Creates an SVG icon element from the icon sprite sheet.
|
|
12
|
+
*/
|
|
13
|
+
static svg: (icon: string) => Domino<SVGSVGElement>;
|
|
14
|
+
/**
|
|
15
|
+
* Create builder from DOM node.
|
|
16
|
+
*/
|
|
8
17
|
static of<K extends keyof HTMLElementTagNameMap>(tag: K): Domino<HTMLElementTagNameMap[K]>;
|
|
9
18
|
static of<K extends keyof SVGElementTagNameMap>(tag: K, namespace: string): Domino<SVGElementTagNameMap[K]>;
|
|
10
19
|
private readonly _el;
|
|
@@ -14,8 +23,18 @@ export declare class Domino<T extends HTMLElement | SVGElement> {
|
|
|
14
23
|
data(key: string, value: string): this;
|
|
15
24
|
attributes(attr: Record<string, string | undefined>): this;
|
|
16
25
|
style(styles: Partial<CSSStyleDeclaration>): this;
|
|
17
|
-
|
|
18
|
-
|
|
26
|
+
append<C extends HTMLElement | SVGElement>(...children: Domino<C>[]): this;
|
|
27
|
+
/**
|
|
28
|
+
* Typed event listener. Accepts the standard `AddEventListenerOptions`
|
|
29
|
+
* third argument so callers can opt into `capture`, `once`, `passive`.
|
|
30
|
+
*/
|
|
31
|
+
on<K extends keyof HTMLElementEventMap>(event: K, handler: (e: HTMLElementEventMap[K]) => void, options?: boolean | AddEventListenerOptions): this;
|
|
32
|
+
on(event: string, handler: (e: Event) => void, options?: boolean | AddEventListenerOptions): this;
|
|
33
|
+
/**
|
|
34
|
+
* Convenience for attaching the root element to a parent node — useful at
|
|
35
|
+
* the end of a chain to avoid a trailing `.root` / `parent.appendChild()`.
|
|
36
|
+
*/
|
|
37
|
+
mount(parent: Node): this;
|
|
19
38
|
get root(): T;
|
|
20
39
|
}
|
|
21
40
|
//# sourceMappingURL=domino.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"domino.d.ts","sourceRoot":"","sources":["../../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