@lingxia/elements 0.5.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.
Files changed (46) hide show
  1. package/dist/component.d.ts +50 -0
  2. package/dist/component.js +139 -0
  3. package/dist/dom.d.ts +10 -0
  4. package/dist/dom.js +70 -0
  5. package/dist/index.d.ts +9 -0
  6. package/dist/index.js +9 -0
  7. package/dist/input.d.ts +117 -0
  8. package/dist/input.js +699 -0
  9. package/dist/native_component_wrapper_shared.d.ts +74 -0
  10. package/dist/native_component_wrapper_shared.js +193 -0
  11. package/dist/nativecomponent.d.ts +6 -0
  12. package/dist/nativecomponent.js +82 -0
  13. package/dist/navigator.d.ts +83 -0
  14. package/dist/navigator.js +388 -0
  15. package/dist/picker-web.d.ts +2 -0
  16. package/dist/picker-web.js +727 -0
  17. package/dist/picker.d.ts +77 -0
  18. package/dist/picker.js +342 -0
  19. package/dist/platform.d.ts +6 -0
  20. package/dist/platform.js +24 -0
  21. package/dist/text_component_native_attrs.d.ts +53 -0
  22. package/dist/text_component_native_attrs.js +111 -0
  23. package/dist/text_component_shared.d.ts +7 -0
  24. package/dist/text_component_shared.js +148 -0
  25. package/dist/textarea.d.ts +129 -0
  26. package/dist/textarea.js +841 -0
  27. package/dist/types.d.ts +21 -0
  28. package/dist/types.js +1 -0
  29. package/dist/video.d.ts +134 -0
  30. package/dist/video.js +741 -0
  31. package/package.json +39 -0
  32. package/src/component.ts +164 -0
  33. package/src/dom.ts +83 -0
  34. package/src/index.ts +69 -0
  35. package/src/input.ts +799 -0
  36. package/src/native_component_wrapper_shared.ts +243 -0
  37. package/src/nativecomponent.ts +97 -0
  38. package/src/navigator.ts +533 -0
  39. package/src/picker-web.ts +719 -0
  40. package/src/picker.ts +418 -0
  41. package/src/platform.ts +25 -0
  42. package/src/text_component_native_attrs.ts +137 -0
  43. package/src/text_component_shared.ts +147 -0
  44. package/src/textarea.ts +959 -0
  45. package/src/types.ts +20 -0
  46. package/src/video.ts +855 -0
@@ -0,0 +1,148 @@
1
+ export function getPropOrAttr(el, name) {
2
+ const attr = el.getAttribute(name);
3
+ if (attr !== null)
4
+ return attr;
5
+ const camelName = name.replace(/-([a-z])/g, (_m, ch) => ch.toUpperCase());
6
+ const self = el;
7
+ if (Object.prototype.hasOwnProperty.call(self, camelName)) {
8
+ const value = self[camelName];
9
+ if (value !== undefined && value !== null)
10
+ return value;
11
+ }
12
+ return undefined;
13
+ }
14
+ export function parseNumberLike(value) {
15
+ if (typeof value === "number") {
16
+ return Number.isFinite(value) ? value : undefined;
17
+ }
18
+ if (typeof value === "string") {
19
+ const parsed = Number(value);
20
+ return Number.isFinite(parsed) ? parsed : undefined;
21
+ }
22
+ return undefined;
23
+ }
24
+ export function getBoolAttr(el, name) {
25
+ const raw = getPropOrAttr(el, name);
26
+ if (raw === undefined || raw === null)
27
+ return false;
28
+ if (typeof raw === "boolean")
29
+ return raw;
30
+ const val = String(raw).trim().toLowerCase();
31
+ if (val === "false" || val === "0" || val === "null" || val === "undefined") {
32
+ return false;
33
+ }
34
+ return true;
35
+ }
36
+ export function getNumAttr(el, name) {
37
+ const raw = getPropOrAttr(el, name);
38
+ if (raw === undefined || raw === null)
39
+ return undefined;
40
+ if (typeof raw === "number")
41
+ return Number.isFinite(raw) ? raw : undefined;
42
+ const val = String(raw).trim();
43
+ if (val === "")
44
+ return undefined;
45
+ const n = Number(val);
46
+ return Number.isNaN(n) ? undefined : n;
47
+ }
48
+ export function shouldRefreshForDataAttribute(name) {
49
+ const normalized = name.trim().toLowerCase();
50
+ return normalized.startsWith("data-");
51
+ }
52
+ function dataAttrToDatasetKey(attr) {
53
+ const raw = attr.slice(5).trim();
54
+ if (!raw)
55
+ return "";
56
+ const parts = raw.split("-").filter(Boolean);
57
+ if (parts.length === 0)
58
+ return "";
59
+ return parts
60
+ .map((segment, index) => {
61
+ if (index === 0)
62
+ return segment.toLowerCase();
63
+ return segment.charAt(0).toUpperCase() + segment.slice(1);
64
+ })
65
+ .join("");
66
+ }
67
+ export function collectDataset(el) {
68
+ const dataset = {};
69
+ const attrs = el.getAttributeNames();
70
+ for (const attr of attrs) {
71
+ if (!attr.startsWith("data-"))
72
+ continue;
73
+ const key = dataAttrToDatasetKey(attr);
74
+ if (!key)
75
+ continue;
76
+ const value = el.getAttribute(attr);
77
+ if (value == null)
78
+ continue;
79
+ dataset[key] = value;
80
+ }
81
+ return dataset;
82
+ }
83
+ function findScrollableAncestor(el) {
84
+ let node = el.parentElement;
85
+ while (node) {
86
+ const style = getComputedStyle(node);
87
+ const overflowY = style.overflowY;
88
+ const scrollable = (overflowY === "auto" || overflowY === "scroll") && node.scrollHeight > node.clientHeight + 1;
89
+ if (scrollable) {
90
+ return node;
91
+ }
92
+ node = node.parentElement;
93
+ }
94
+ return null;
95
+ }
96
+ function applyScrollDelta(el, deltaY) {
97
+ if (Math.abs(deltaY) <= 1)
98
+ return;
99
+ const target = findScrollableAncestor(el);
100
+ if (target) {
101
+ target.scrollTop += Math.round(deltaY);
102
+ return;
103
+ }
104
+ window.scrollBy(0, Math.round(deltaY));
105
+ }
106
+ export function ensureElementVisibleForKeyboard(el, explicitKeyboardHeight = 0, forceCenter = false, extraDelays = [120]) {
107
+ const tryScroll = () => {
108
+ if (!el.isConnected)
109
+ return;
110
+ const rect = el.getBoundingClientRect();
111
+ const layoutViewportHeight = window.innerHeight || document.documentElement.clientHeight || 0;
112
+ const visualViewport = window.visualViewport;
113
+ const visualBottom = visualViewport ? (visualViewport.offsetTop + visualViewport.height) : layoutViewportHeight;
114
+ const keyboardHeight = Math.max(0, explicitKeyboardHeight || 0);
115
+ const keyboardLikelyVisible = keyboardHeight > 0 ||
116
+ (!!visualViewport && visualViewport.height < (layoutViewportHeight - 40));
117
+ if (!keyboardLikelyVisible) {
118
+ return;
119
+ }
120
+ const viewportHeight = keyboardHeight > 0
121
+ ? Math.min(layoutViewportHeight, layoutViewportHeight - keyboardHeight)
122
+ : Math.min(layoutViewportHeight, visualBottom);
123
+ if (viewportHeight <= 0)
124
+ return;
125
+ const topSafe = 12;
126
+ const bottomSafe = 24;
127
+ let delta = 0;
128
+ const visibleBottom = Math.max(topSafe, viewportHeight - bottomSafe);
129
+ if (rect.bottom > visibleBottom) {
130
+ delta = rect.bottom - visibleBottom;
131
+ }
132
+ else if (rect.top < topSafe) {
133
+ delta = rect.top - topSafe;
134
+ }
135
+ if (Math.abs(delta) > 1) {
136
+ applyScrollDelta(el, delta);
137
+ return;
138
+ }
139
+ if (forceCenter && rect.bottom > layoutViewportHeight * 0.6) {
140
+ el.scrollIntoView({ block: "center", inline: "nearest", behavior: "auto" });
141
+ }
142
+ };
143
+ tryScroll();
144
+ requestAnimationFrame(() => tryScroll());
145
+ extraDelays.forEach((delay) => {
146
+ setTimeout(() => tryScroll(), delay);
147
+ });
148
+ }
@@ -0,0 +1,129 @@
1
+ export interface LxTextareaEventDetail {
2
+ value?: string;
3
+ cursor?: number;
4
+ lineCount?: number;
5
+ height?: number;
6
+ duration?: number;
7
+ selectionStart?: number;
8
+ selectionEnd?: number;
9
+ heightRpx?: number;
10
+ }
11
+ export interface LxTextareaEvent extends CustomEvent<LxTextareaEventDetail> {
12
+ detail: LxTextareaEventDetail;
13
+ }
14
+ export type LxTextareaAttributes = {
15
+ id?: string;
16
+ value?: string;
17
+ placeholder?: string;
18
+ 'placeholder-style'?: string;
19
+ 'placeholder-class'?: string;
20
+ maxlength?: number | string;
21
+ disabled?: boolean | string;
22
+ 'auto-focus'?: boolean | string;
23
+ focus?: boolean | string;
24
+ 'auto-height'?: boolean | string;
25
+ 'cursor-spacing'?: number | string;
26
+ 'show-confirm-bar'?: boolean | string;
27
+ 'adjust-position'?: boolean | string;
28
+ 'hold-keyboard'?: boolean | string;
29
+ 'disable-default-padding'?: boolean | string;
30
+ 'confirm-type'?: 'send' | 'search' | 'next' | 'go' | 'done' | 'return';
31
+ 'confirm-hold'?: boolean | string;
32
+ fixed?: boolean | string;
33
+ 'adjust-keyboard-to'?: 'cursor' | 'bottom';
34
+ cursor?: number | string;
35
+ 'selection-start'?: number | string;
36
+ 'selection-end'?: number | string;
37
+ className?: string;
38
+ style?: any;
39
+ ref?: any;
40
+ onInput?: (e: LxTextareaEvent) => void;
41
+ onChange?: (e: LxTextareaEvent) => void;
42
+ onFocus?: (e: LxTextareaEvent) => void;
43
+ onBlur?: (e: LxTextareaEvent) => void;
44
+ onConfirm?: (e: LxTextareaEvent) => void;
45
+ onLinechange?: (e: LxTextareaEvent) => void;
46
+ onKeyboardheightchange?: (e: LxTextareaEvent) => void;
47
+ pageBindings?: Record<string, string>;
48
+ };
49
+ declare global {
50
+ namespace JSX {
51
+ interface IntrinsicElements {
52
+ "lx-textarea": LxTextareaAttributes;
53
+ }
54
+ }
55
+ }
56
+ export declare class LxTextareaElement extends HTMLElement {
57
+ static get observedAttributes(): string[];
58
+ private componentId;
59
+ private mounted;
60
+ private unregister?;
61
+ private _handlers;
62
+ private rawHandlers;
63
+ private harmonyEmbed?;
64
+ private lastHarmonyProps?;
65
+ private pendingHarmonyProps?;
66
+ private pendingHarmonyRetryTimer;
67
+ private pendingHarmonyRetryCount;
68
+ private attrObserver?;
69
+ private shadow?;
70
+ private innerTextarea?;
71
+ private lastNativeAutoHeight?;
72
+ private autoHeightMinHeight?;
73
+ private lastKeyboardHeight;
74
+ private readonly updateState;
75
+ private resizeObserver?;
76
+ private pendingLayoutFrame;
77
+ private focusLayoutSyncTimer;
78
+ private readonly layoutEventListener;
79
+ private removeLayoutInvalidationListener?;
80
+ private _pageBindings;
81
+ set pageBindings(bindings: Record<string, string>);
82
+ get pageBindings(): Record<string, string>;
83
+ private upgradeProperty;
84
+ private registerNativeHandler;
85
+ private normalizeNativeDetail;
86
+ private unmountNativeComponentById;
87
+ private teardownHarmonyEmbed;
88
+ connectedCallback(): void;
89
+ disconnectedCallback(): void;
90
+ attributeChangedCallback(name: string): void;
91
+ private getAttr;
92
+ private getBoolAttr;
93
+ private getNumAttr;
94
+ private getPropOrAttr;
95
+ private shouldTrackNativeLayout;
96
+ private startTracking;
97
+ private stopTracking;
98
+ private startSizeObserver;
99
+ private stopSizeObserver;
100
+ private schedulePositionSync;
101
+ private applyNativeAutoHeightIfNeeded;
102
+ private parseHeight;
103
+ private collectProps;
104
+ private getHostTextColor;
105
+ private shouldAdjustPosition;
106
+ private ensureVisibleForKeyboard;
107
+ private resyncHarmonyLayoutAfterFocus;
108
+ private startFocusLayoutSync;
109
+ private stopFocusLayoutSync;
110
+ private shouldRefreshForAttribute;
111
+ private startAttrObserver;
112
+ private stopAttrObserver;
113
+ private collectDataset;
114
+ private autoResizeTextarea;
115
+ private getLineCount;
116
+ private mountDesktopTextarea;
117
+ private mountTextarea;
118
+ syncNativeProps(): void;
119
+ private ensureHostLayout;
120
+ set oninput(cb: EventListener | null);
121
+ get oninput(): EventListener | null;
122
+ set onchange(cb: EventListener | null);
123
+ get onchange(): EventListener | null;
124
+ private ensureHarmonyEmbed;
125
+ private encodeHarmonyProps;
126
+ private pushHarmonyPropsUpdate;
127
+ private scheduleHarmonyPropsRetry;
128
+ }
129
+ export declare function registerTextareaComponent(): void;