@lingxia/elements 0.6.0 → 0.6.5

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.
@@ -1,5 +1,6 @@
1
1
  import type { NavigatorEnvVersion, NavigatorOpenType, NavigatorTarget } from "./navigator.js";
2
2
  import type { NavigatorQuery } from "./navigator.js";
3
+ import type { LxMediaSwiperItem } from "./media_swiper.js";
3
4
  import type { LxVideoQuality } from "./video.js";
4
5
  export declare function appendDataAttrs(attrs: Record<string, unknown>, target: Record<string, string>): void;
5
6
  export declare function appendPassthroughAttrs(attrs: Record<string, unknown>, target: Record<string, string>): void;
@@ -77,3 +78,37 @@ export interface VideoNativeAttrOptions {
77
78
  playbackRates?: number[];
78
79
  }
79
80
  export declare function buildVideoNativeAttrs(options: VideoNativeAttrOptions, extraAttrs?: Record<string, unknown>): Record<string, string | number>;
81
+ export declare const MEDIA_SWIPER_DOM_EVENT_MAP: {
82
+ readonly onChange: "change";
83
+ readonly onTransitionEnd: "transitionend";
84
+ readonly onEndReached: "endreached";
85
+ readonly onTap: "tap";
86
+ readonly onVideoEnded: "videoended";
87
+ readonly onError: "error";
88
+ };
89
+ export interface MediaSwiperNativeAttrOptions {
90
+ id?: string;
91
+ items?: LxMediaSwiperItem[];
92
+ index?: number;
93
+ initialIndex?: number;
94
+ loop?: boolean;
95
+ autoplay?: boolean;
96
+ interval?: number;
97
+ animation?: "slide" | "none";
98
+ animationDuration?: number;
99
+ direction?: "horizontal" | "vertical";
100
+ contentRotate?: 0 | 90 | 180 | 270;
101
+ objectFit?: "cover" | "contain" | "fill" | "fit";
102
+ controls?: boolean;
103
+ muted?: boolean;
104
+ dots?: boolean | {
105
+ color?: string;
106
+ activeColor?: string;
107
+ };
108
+ swipeEnabled?: boolean;
109
+ peek?: number | {
110
+ previous?: number;
111
+ next?: number;
112
+ };
113
+ }
114
+ export declare function buildMediaSwiperNativeAttrs(options: MediaSwiperNativeAttrOptions, extraAttrs?: Record<string, unknown>): Record<string, string | number>;
@@ -199,3 +199,64 @@ export function buildVideoNativeAttrs(options, extraAttrs = {}) {
199
199
  appendPassthroughAttrs(extraAttrs, extraNativeAttrs);
200
200
  return { ...result, ...extraNativeAttrs };
201
201
  }
202
+ export const MEDIA_SWIPER_DOM_EVENT_MAP = {
203
+ onChange: "change",
204
+ onTransitionEnd: "transitionend",
205
+ onEndReached: "endreached",
206
+ onTap: "tap",
207
+ onVideoEnded: "videoended",
208
+ onError: "error",
209
+ };
210
+ export function buildMediaSwiperNativeAttrs(options, extraAttrs = {}) {
211
+ const result = {};
212
+ const explicitId = typeof options.id === "string" ? options.id.trim() : "";
213
+ if (explicitId.length > 0)
214
+ result.id = explicitId;
215
+ if (Array.isArray(options.items))
216
+ result.items = JSON.stringify(options.items);
217
+ if (typeof options.index === "number")
218
+ result.index = options.index;
219
+ if (typeof options.initialIndex === "number")
220
+ result["initial-index"] = options.initialIndex;
221
+ if (options.loop)
222
+ result.loop = "";
223
+ if (options.autoplay)
224
+ result.autoplay = "";
225
+ if (typeof options.interval === "number")
226
+ result.interval = options.interval;
227
+ if (options.animation)
228
+ result.animation = options.animation;
229
+ if (typeof options.animationDuration === "number")
230
+ result["animation-duration"] = options.animationDuration;
231
+ if (options.direction)
232
+ result.direction = options.direction;
233
+ if (typeof options.contentRotate === "number")
234
+ result["content-rotate"] = options.contentRotate;
235
+ if (options.objectFit)
236
+ result["object-fit"] = options.objectFit;
237
+ if (options.controls)
238
+ result.controls = "";
239
+ if (options.muted === false)
240
+ result.muted = "false";
241
+ if (options.muted === true)
242
+ result.muted = "";
243
+ if (options.dots === true)
244
+ result.dots = "";
245
+ if (options.dots && typeof options.dots === "object")
246
+ result.dots = JSON.stringify(options.dots);
247
+ if (options.swipeEnabled === false)
248
+ result["swipe-enabled"] = "false";
249
+ if (typeof options.peek === "number" && options.peek > 0) {
250
+ result.peek = options.peek;
251
+ }
252
+ else if (options.peek && typeof options.peek === "object") {
253
+ const previous = Math.max(0, Number(options.peek.previous) || 0);
254
+ const next = Math.max(0, Number(options.peek.next) || 0);
255
+ if (previous > 0 || next > 0) {
256
+ result.peek = JSON.stringify({ previous, next });
257
+ }
258
+ }
259
+ const extraNativeAttrs = {};
260
+ appendPassthroughAttrs(extraAttrs, extraNativeAttrs);
261
+ return { ...result, ...extraNativeAttrs };
262
+ }
package/dist/video.d.ts CHANGED
@@ -8,7 +8,7 @@ export type LxVideoAttributes = {
8
8
  src?: string;
9
9
  poster?: string;
10
10
  objectFit?: "cover" | "contain" | "fill" | "fit";
11
- rotate?: 0 | 90 | 180 | 270;
11
+ contentRotate?: 0 | 90 | 180 | 270;
12
12
  autoplay?: boolean;
13
13
  loop?: boolean;
14
14
  muted?: boolean;
@@ -72,11 +72,13 @@ export declare class LxVideoElement extends HTMLElement {
72
72
  private parseObjectFitValue;
73
73
  set pageBindings(bindings: Record<string, string>);
74
74
  get pageBindings(): Record<string, string>;
75
+ set src(value: string | null | undefined);
76
+ get src(): string | null;
75
77
  private dataAttrToDatasetKey;
76
78
  private collectDataset;
77
79
  private upgradeProperty;
78
- set rotate(value: unknown);
79
- get rotate(): 0 | 90 | 180 | 270 | undefined;
80
+ set contentRotate(value: unknown);
81
+ get contentRotate(): 0 | 90 | 180 | 270 | undefined;
80
82
  connectedCallback(): void;
81
83
  disconnectedCallback(): void;
82
84
  attributeChangedCallback(name: string): void;
package/dist/video.js CHANGED
@@ -33,7 +33,7 @@ export class LxVideoElement extends HTMLElement {
33
33
  "src",
34
34
  "poster",
35
35
  "object-fit",
36
- "rotate",
36
+ "content-rotate",
37
37
  "autoplay",
38
38
  "loop",
39
39
  "muted",
@@ -84,6 +84,16 @@ export class LxVideoElement extends HTMLElement {
84
84
  get pageBindings() {
85
85
  return this._pageBindings;
86
86
  }
87
+ set src(value) {
88
+ if (value == null) {
89
+ this.removeAttribute("src");
90
+ return;
91
+ }
92
+ this.setAttribute("src", String(value));
93
+ }
94
+ get src() {
95
+ return this.getAttribute("src");
96
+ }
87
97
  dataAttrToDatasetKey(attr) {
88
98
  const raw = attr.slice(5).trim();
89
99
  if (!raw)
@@ -123,21 +133,22 @@ export class LxVideoElement extends HTMLElement {
123
133
  delete self[propName];
124
134
  self[propName] = value;
125
135
  }
126
- set rotate(value) {
136
+ set contentRotate(value) {
127
137
  const normalized = this.parseRotateValue(value);
128
138
  if (normalized === undefined) {
129
- this.removeAttribute("rotate");
139
+ this.removeAttribute("content-rotate");
130
140
  return;
131
141
  }
132
- this.setAttribute("rotate", String(normalized));
142
+ this.setAttribute("content-rotate", String(normalized));
133
143
  }
134
- get rotate() {
135
- return this.parseRotateValue(this.getAttribute("rotate"));
144
+ get contentRotate() {
145
+ return this.parseRotateValue(this.getAttribute("content-rotate"));
136
146
  }
137
147
  connectedCallback() {
138
148
  // React may set custom-element properties before upgrade; replay through setters.
139
149
  this.upgradeProperty("pageBindings");
140
- this.upgradeProperty("rotate");
150
+ this.upgradeProperty("contentRotate");
151
+ this.upgradeProperty("src");
141
152
  this.upgradeProperty("onplayrequest");
142
153
  this.upgradeProperty("onplay");
143
154
  this.upgradeProperty("onplaying");
@@ -230,8 +241,8 @@ export class LxVideoElement extends HTMLElement {
230
241
  }
231
242
  if (!this.isConnected)
232
243
  return;
233
- // Keep rotate/object-fit updates immediate across all native platforms.
234
- const forcePropsUpdate = name === "rotate" || name === "object-fit" || name === "objectfit";
244
+ // Keep content-rotate/object-fit updates immediate across all native platforms.
245
+ const forcePropsUpdate = name === "content-rotate" || name === "object-fit" || name === "objectfit";
235
246
  if (isHarmony() && forcePropsUpdate) {
236
247
  // Bridge callbacks can race on Harmony; force a deterministic embed recreate for visual props.
237
248
  this.forceHarmonyEmbedRecreate = true;
@@ -340,13 +351,13 @@ export class LxVideoElement extends HTMLElement {
340
351
  const progressBar = isLive
341
352
  ? (progressBarAttr !== null && progressBarAttr !== "false")
342
353
  : (progressBarAttr !== "false");
343
- const rawRotate = this.getAttribute("rotate");
344
- const validRotate = this.parseRotateValue(rawRotate);
354
+ const rawContentRotate = this.getAttribute("content-rotate");
355
+ const validContentRotate = this.parseRotateValue(rawContentRotate);
345
356
  const pageFuncBindings = this._pageBindings;
346
357
  const dataset = this.collectDataset();
347
358
  const clearProps = [];
348
- if (rawRotate === null || validRotate === undefined) {
349
- clearProps.push("rotate");
359
+ if (rawContentRotate === null || validContentRotate === undefined) {
360
+ clearProps.push("contentRotate");
350
361
  }
351
362
  if (rawObjectFit == null || objectFit === undefined) {
352
363
  clearProps.push("objectFit");
@@ -362,7 +373,7 @@ export class LxVideoElement extends HTMLElement {
362
373
  live: isLive,
363
374
  volume: !Number.isNaN(volume !== null && volume !== void 0 ? volume : NaN) ? volume : undefined,
364
375
  objectFit,
365
- rotate: validRotate,
376
+ contentRotate: validContentRotate,
366
377
  ...(clearProps.length > 0 ? { __clearProps: clearProps } : {}),
367
378
  qualities,
368
379
  playbackRates,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lingxia/elements",
3
- "version": "0.6.0",
3
+ "version": "0.6.5",
4
4
  "private": false,
5
5
  "description": "LingXia custom elements — native-backed web components for LxApp pages",
6
6
  "type": "module",
package/src/index.ts CHANGED
@@ -4,6 +4,25 @@ export {
4
4
  type LxVideoAttributes,
5
5
  } from "./video.js";
6
6
 
7
+ export {
8
+ registerMediaSwiperComponent,
9
+ LxMediaSwiperElement,
10
+ type LxMediaSwiperAttributes,
11
+ type LxMediaSwiperItem,
12
+ type LxMediaSwiperChangeEvent,
13
+ type LxMediaSwiperChangeEventDetail,
14
+ type LxMediaSwiperTransitionEndEvent,
15
+ type LxMediaSwiperTransitionEndEventDetail,
16
+ type LxMediaSwiperItemEvent,
17
+ type LxMediaSwiperEventDetail,
18
+ type LxMediaSwiperEndReachedEvent,
19
+ type LxMediaSwiperEndReachedEventDetail,
20
+ type LxMediaSwiperErrorEvent,
21
+ type LxMediaSwiperErrorEventDetail,
22
+ type LxMediaSwiperChangeSource,
23
+ type LxMediaSwiperErrorCode,
24
+ } from "./media_swiper.js";
25
+
7
26
  export {
8
27
  registerPickerComponent,
9
28
  LxPickerElement,
@@ -43,11 +62,13 @@ export {
43
62
 
44
63
  export {
45
64
  buildVideoNativeAttrs,
65
+ buildMediaSwiperNativeAttrs,
46
66
  buildNavigatorNativeAttrs,
47
67
  buildPickerNativeAttrs,
48
68
  getPickerDisplayText,
49
69
  getPickerValueFromIndex,
50
70
  VIDEO_DOM_EVENT_MAP,
71
+ MEDIA_SWIPER_DOM_EVENT_MAP,
51
72
  } from "./native_component_wrapper_shared.js";
52
73
 
53
74
  export {