From bd14f335588f93257fa86bc42db4db4a6a935a66 Mon Sep 17 00:00:00 2001 From: FabioPinheiro Date: Sat, 12 Aug 2023 13:48:58 +0100 Subject: [PATCH 1/3] Add support for Web NFC API Apply suggestions from code review Co-authored-by: zetashift Co-authored-by: Arman Bilge --- api-reports/2_12.txt | 50 ++++++++++++++++ api-reports/2_13.txt | 50 ++++++++++++++++ .../scala/org/scalajs/dom/NDEFMessage.scala | 19 ++++++ .../scala/org/scalajs/dom/NDEFReader.scala | 60 +++++++++++++++++++ .../org/scalajs/dom/NDEFReadingEvent.scala | 22 +++++++ .../scala/org/scalajs/dom/NDEFRecord.scala | 41 +++++++++++++ .../org/scalajs/dom/NDEFRecordInit.scala | 51 ++++++++++++++++ .../org/scalajs/dom/NDEFScanOptions.scala | 9 +++ .../org/scalajs/dom/NDEFWriteOptions.scala | 14 +++++ 9 files changed, 316 insertions(+) create mode 100644 dom/src/main/scala/org/scalajs/dom/NDEFMessage.scala create mode 100644 dom/src/main/scala/org/scalajs/dom/NDEFReader.scala create mode 100644 dom/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala create mode 100644 dom/src/main/scala/org/scalajs/dom/NDEFRecord.scala create mode 100644 dom/src/main/scala/org/scalajs/dom/NDEFRecordInit.scala create mode 100644 dom/src/main/scala/org/scalajs/dom/NDEFScanOptions.scala create mode 100644 dom/src/main/scala/org/scalajs/dom/NDEFWriteOptions.scala diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index 5d3785054..8f088efd6 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -16464,6 +16464,56 @@ MutationRecord[JT] def previousSibling: Node MutationRecord[JT] def removedNodes: NodeList[Node] MutationRecord[JT] def target: Node MutationRecord[JT] def `type`: String +NDEFMessage[JC] var records: FrozenArray[NDEFRecord] +NDEFReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit +NDEFReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit +NDEFReader[JC] def dispatchEvent(evt: Event): Boolean +NDEFReader[JC] var onreading: js.Function1[NDEFReadingEvent, Any] +NDEFReader[JC] var onreadingerror: js.Function1[Event, Any] +NDEFReader[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit +NDEFReader[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit +NDEFReader[JC] def scan(options: NDEFScanOptions?): js.Promise[Unit] +NDEFReader[JC] def write(message: String): js.Promise[Unit] +NDEFReader[JC] def write(message: String, options: NDEFWriteOptions): js.Promise[Unit] +NDEFReader[JC] def write(message: js.Array[NDEFRecord]): js.Promise[Unit] +NDEFReader[JC] def write(message: js.Array[NDEFRecord], options: NDEFWriteOptions): js.Promise[Unit] +NDEFReader[JC] def write(message: js.typedarray.ArrayBuffer): js.Promise[Unit] +NDEFReader[JC] def write(message: js.typedarray.ArrayBuffer, options: NDEFWriteOptions): js.Promise[Unit] +NDEFReader[JC] def write(message: js.typedarray.DataView): js.Promise[Unit] +NDEFReader[JC] def write(message: js.typedarray.DataView, options: NDEFWriteOptions): js.Promise[Unit] +NDEFReader[JC] def write(message: js.typedarray.TypedArray[_, _], options: NDEFWriteOptions?): js.Promise[Unit] +NDEFReadingEvent[JT] def bubbles: Boolean +NDEFReadingEvent[JT] def cancelBubble: Boolean +NDEFReadingEvent[JT] def cancelable: Boolean +NDEFReadingEvent[JT] def composed: Boolean +NDEFReadingEvent[JT] def currentTarget: EventTarget +NDEFReadingEvent[JT] def defaultPrevented: Boolean +NDEFReadingEvent[JT] def eventPhase: Int +NDEFReadingEvent[JT] def isTrusted: Boolean +NDEFReadingEvent[JT] var message: NDEFMessage +NDEFReadingEvent[JT] def preventDefault(): Unit +NDEFReadingEvent[JT] var serialNumber: String +NDEFReadingEvent[JT] def stopImmediatePropagation(): Unit +NDEFReadingEvent[JT] def stopPropagation(): Unit +NDEFReadingEvent[JT] def target: EventTarget +NDEFReadingEvent[JT] def timeStamp: Double +NDEFReadingEvent[JT] def `type`: String +NDEFRecord[JC] var data: js.typedarray.DataView +NDEFRecord[JC] var encoding: js.UndefOr[String] +NDEFRecord[JC] var id: js.UndefOr[String] +NDEFRecord[JC] var lang: js.UndefOr[String] +NDEFRecord[JC] var mediaType: js.UndefOr[String] +NDEFRecord[JC] var recordType: String +NDEFRecord[JC] def toRecords(): js.Array[NDEFRecord] +NDEFRecordInit[JT] var data: js.UndefOr[String | js.typedarray.DataView | js.typedarray.ArrayBuffer | js.typedarray.TypedArray[_, _] | js.typedarray.DataView | js.Array[NDEFRecord]] +NDEFRecordInit[JT] var encoding: js.UndefOr[String] +NDEFRecordInit[JT] var id: js.UndefOr[String] +NDEFRecordInit[JT] var lang: js.UndefOr[String] +NDEFRecordInit[JT] var mediaType: js.UndefOr[String] +NDEFRecordInit[JT] var recordType: js.UndefOr[String] +NDEFScanOptions[JT] var signal: js.UndefOr[AbortSignal] +NDEFWriteOptions[JT] var overwrite: js.UndefOr[Boolean] +NDEFWriteOptions[JT] var signal: js.UndefOr[AbortSignal] NamedNodeMap[JC] @scala.scalajs.js.annotation.JSBracketAccess def apply(index: Int): Attr NamedNodeMap[JC] def getNamedItem(name: String): Attr NamedNodeMap[JC] def getNamedItemNS(namespaceURI: String, localName: String): Attr diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index 5d3785054..8f088efd6 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -16464,6 +16464,56 @@ MutationRecord[JT] def previousSibling: Node MutationRecord[JT] def removedNodes: NodeList[Node] MutationRecord[JT] def target: Node MutationRecord[JT] def `type`: String +NDEFMessage[JC] var records: FrozenArray[NDEFRecord] +NDEFReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit +NDEFReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit +NDEFReader[JC] def dispatchEvent(evt: Event): Boolean +NDEFReader[JC] var onreading: js.Function1[NDEFReadingEvent, Any] +NDEFReader[JC] var onreadingerror: js.Function1[Event, Any] +NDEFReader[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit +NDEFReader[JC] def removeEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit +NDEFReader[JC] def scan(options: NDEFScanOptions?): js.Promise[Unit] +NDEFReader[JC] def write(message: String): js.Promise[Unit] +NDEFReader[JC] def write(message: String, options: NDEFWriteOptions): js.Promise[Unit] +NDEFReader[JC] def write(message: js.Array[NDEFRecord]): js.Promise[Unit] +NDEFReader[JC] def write(message: js.Array[NDEFRecord], options: NDEFWriteOptions): js.Promise[Unit] +NDEFReader[JC] def write(message: js.typedarray.ArrayBuffer): js.Promise[Unit] +NDEFReader[JC] def write(message: js.typedarray.ArrayBuffer, options: NDEFWriteOptions): js.Promise[Unit] +NDEFReader[JC] def write(message: js.typedarray.DataView): js.Promise[Unit] +NDEFReader[JC] def write(message: js.typedarray.DataView, options: NDEFWriteOptions): js.Promise[Unit] +NDEFReader[JC] def write(message: js.typedarray.TypedArray[_, _], options: NDEFWriteOptions?): js.Promise[Unit] +NDEFReadingEvent[JT] def bubbles: Boolean +NDEFReadingEvent[JT] def cancelBubble: Boolean +NDEFReadingEvent[JT] def cancelable: Boolean +NDEFReadingEvent[JT] def composed: Boolean +NDEFReadingEvent[JT] def currentTarget: EventTarget +NDEFReadingEvent[JT] def defaultPrevented: Boolean +NDEFReadingEvent[JT] def eventPhase: Int +NDEFReadingEvent[JT] def isTrusted: Boolean +NDEFReadingEvent[JT] var message: NDEFMessage +NDEFReadingEvent[JT] def preventDefault(): Unit +NDEFReadingEvent[JT] var serialNumber: String +NDEFReadingEvent[JT] def stopImmediatePropagation(): Unit +NDEFReadingEvent[JT] def stopPropagation(): Unit +NDEFReadingEvent[JT] def target: EventTarget +NDEFReadingEvent[JT] def timeStamp: Double +NDEFReadingEvent[JT] def `type`: String +NDEFRecord[JC] var data: js.typedarray.DataView +NDEFRecord[JC] var encoding: js.UndefOr[String] +NDEFRecord[JC] var id: js.UndefOr[String] +NDEFRecord[JC] var lang: js.UndefOr[String] +NDEFRecord[JC] var mediaType: js.UndefOr[String] +NDEFRecord[JC] var recordType: String +NDEFRecord[JC] def toRecords(): js.Array[NDEFRecord] +NDEFRecordInit[JT] var data: js.UndefOr[String | js.typedarray.DataView | js.typedarray.ArrayBuffer | js.typedarray.TypedArray[_, _] | js.typedarray.DataView | js.Array[NDEFRecord]] +NDEFRecordInit[JT] var encoding: js.UndefOr[String] +NDEFRecordInit[JT] var id: js.UndefOr[String] +NDEFRecordInit[JT] var lang: js.UndefOr[String] +NDEFRecordInit[JT] var mediaType: js.UndefOr[String] +NDEFRecordInit[JT] var recordType: js.UndefOr[String] +NDEFScanOptions[JT] var signal: js.UndefOr[AbortSignal] +NDEFWriteOptions[JT] var overwrite: js.UndefOr[Boolean] +NDEFWriteOptions[JT] var signal: js.UndefOr[AbortSignal] NamedNodeMap[JC] @scala.scalajs.js.annotation.JSBracketAccess def apply(index: Int): Attr NamedNodeMap[JC] def getNamedItem(name: String): Attr NamedNodeMap[JC] def getNamedItemNS(namespaceURI: String, localName: String): Attr diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFMessage.scala b/dom/src/main/scala/org/scalajs/dom/NDEFMessage.scala new file mode 100644 index 000000000..bc5d71a2a --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/NDEFMessage.scala @@ -0,0 +1,19 @@ +package org.scalajs.dom + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSGlobal + +/** The [[NDEFMessage]] interface of the Web NFC API represents the content of an NDEF message that has been read from + * or could be written to an NFC tag. An instance is acquired by calling the NDEFMessage() constructor or from the + * NDEFReadingEvent.message property, which is passed to the reading event. + * + * @param records + * The records property of NDEFMessage interface represents a list of NDEFRecords present in the NDEF message. + */ +@js.native +@JSGlobal +class NDEFMessage(recordsAgr: js.Array[NDEFRecordInit]) extends js.Object { + + /** Returns the list of NDEF records contained in the message. */ + var records: FrozenArray[NDEFRecord] = js.native +} diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFReader.scala b/dom/src/main/scala/org/scalajs/dom/NDEFReader.scala new file mode 100644 index 000000000..5d1c7531c --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/NDEFReader.scala @@ -0,0 +1,60 @@ +package org.scalajs.dom + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSGlobal + +/** The [[NDEFReader]] interface of the Web NFC API (https://developer.mozilla.org/en-US/docs/Web/API/Web_NFC_API) is + * used to read from and write data to compatible NFC devices, e.g. NFC tags supporting NDEF, when these devices are + * within the reader's magnetic induction field. + */ +@JSGlobal("NDEFReader") +@js.native +class NDEFReader() extends EventTarget { + + /** Activates a reading device and returns a Promise that either resolves when an NFC tag read operation is scheduled + * or rejects if a hardware or permission error is encountered. This method triggers a permission prompt if the "nfc" + * permission has not been previously granted. + * + * @return + * a Promise that resolves immediately after scheduling read operations for the NFC adapter. + */ + def scan(options: NDEFScanOptions = js.native): js.Promise[Unit] = js.native + + /** Attempts to write an NDEF message to a tag and returns a Promise that either resolves when a message has been + * written to the tag or rejects if a hardware or permission error is encountered. This method triggers a permission + * prompt if the "nfc" permission has not been previously granted. + * + * @param message + * The message to be written, either a string object or literal, an ArrayBuffer, a TypedArray, a DataView, or an + * array of records. A record has the following members: + * @param options + * An object with the following properties: + * + * @return + * a Promise that either resolves when a message has been written to the tag or rejects if a hardware or permission + * error is encountered. + */ + def write(message: String, options: NDEFWriteOptions): js.Promise[Unit] = js.native + def write(message: js.typedarray.ArrayBuffer, options: NDEFWriteOptions): js.Promise[Unit] = js.native + + def write(message: js.typedarray.TypedArray[_, _], + options: NDEFWriteOptions = js.native): js.Promise[Unit] = js.native + def write(message: js.typedarray.DataView, options: NDEFWriteOptions): js.Promise[Unit] = js.native + def write(message: js.Array[NDEFRecord], options: NDEFWriteOptions): js.Promise[Unit] = js.native + + def write(message: String): js.Promise[Unit] = js.native + def write(message: js.typedarray.ArrayBuffer): js.Promise[Unit] = js.native + // def write(message:js.typedarray.TypedArray[NDEFRecord, ???]): js.Promise[Unit] = js.native + def write(message: js.typedarray.DataView): js.Promise[Unit] = js.native + def write(message: js.Array[NDEFRecord]): js.Promise[Unit] = js.native + + /** The reading event of the NDEFReader interface is fired whenever a new reading is available from compatible NFC + * devices (e.g. NFC tags supporting NDEF) when these devices are within the reader's magnetic induction field. + */ + var onreading: js.Function1[NDEFReadingEvent, Any] = js.native + + /** The readingerror event of the NDEFReader interface is fired whenever an error occurs during reading of NFC tags, + * e.g. when tags leave the reader's magnetic induction field. + */ + var onreadingerror: js.Function1[Event, Any] = js.native +} diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala b/dom/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala new file mode 100644 index 000000000..3bc402a90 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala @@ -0,0 +1,22 @@ +package org.scalajs.dom + +import scala.scalajs.js + +/** The NDEFReadingEvent interface of the Web NFC API represents events dispatched on new NFC readings obtained by + * NDEFReader. + * + * @see + * https://developer.mozilla.org/en-US/docs/Web/API/NDEFReadingEvent + */ +@js.native +trait NDEFReadingEvent extends Event { + + /** Returns an NDEFMessage object containing the received message. */ + var message: NDEFMessage = js.native + + /** Returns the serial number of the device, which is used for anti-collision and identification, or an empty string + * if no serial number is available. + */ + var serialNumber: String = js.native + +} diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFRecord.scala b/dom/src/main/scala/org/scalajs/dom/NDEFRecord.scala new file mode 100644 index 000000000..31e097e7a --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/NDEFRecord.scala @@ -0,0 +1,41 @@ +package org.scalajs.dom + +import scala.scalajs.js +import scala.scalajs.js.annotation.JSGlobal + +/** The [[NDEFRecord]] interface of the Web NFC API provides data that can be read from, or written to, compatible NFC + * devices, e.g. NFC tags supporting NDEF. + */ +@js.native +@JSGlobal +class NDEFRecord(options: NDEFRecordInit) extends js.Object { + + /** Returns the record type of the record. Records must have either a standardized well-known type name such as + * "empty", "text", "url", "smart-poster", "absolute-url", "mime", or "unknown" or else an external type name, which + * consists of a domain name and custom type name separated by a colon (":"). + */ + var recordType: String = js.native + + /** Returns the MIME type of the record. This value will be null if recordType is not equal to "mime". */ + var mediaType: js.UndefOr[String] = js.native + + /** Returns the record identifier, which is an absolute or relative URL used to identify the record. + * + * Note: The uniqueness of the identifier is enforced only by the generator of the record. + */ + var id: js.UndefOr[String] = js.native + + /** Returns a DataView containing the raw bytes of the record's payload. */ + var data: js.typedarray.DataView = js.native + + /** Returns the encoding of a textual payload, or null otherwise. */ + var encoding: js.UndefOr[String] = js.native + + /** Returns the language of a textual payload, or null if one was not supplied. */ + var lang: js.UndefOr[String] = js.native + + /** Converts [[NDEFRecord.data]] to a sequence of records. This allows parsing the payloads of record types which may + * contain nested records, such as smart poster and external type records. + */ + def toRecords(): js.Array[NDEFRecord] = js.native +} diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFRecordInit.scala b/dom/src/main/scala/org/scalajs/dom/NDEFRecordInit.scala new file mode 100644 index 000000000..0069f2a5b --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/NDEFRecordInit.scala @@ -0,0 +1,51 @@ +package org.scalajs.dom + +import scala.scalajs.js +import scala.scalajs.js.| + +/** @see + * https://developer.mozilla.org/en-US/docs/Web/API/NDEFMessage/NDEFMessage + * @see + * https://developer.mozilla.org/en-US/docs/Web/API/NDEFRecord/NDEFRecord + */ +trait NDEFRecordInit extends js.Object { + + /** Contains the data to be transmitted. It can be a string object or literal, an ArrayBuffer, a TypedArray, a + * DataView, or an array of nested records. + */ + var data: js.UndefOr[ + String | + js.typedarray.DataView | + js.typedarray.ArrayBuffer | + js.typedarray.TypedArray[_, _] | + js.typedarray.DataView | + js.Array[NDEFRecord] + ] = js.undefined + + /** A string specifying the record's encoding. */ + var encoding: js.UndefOr[String] = js.undefined + + /** A developer-defined identifier for the record. */ + var id: js.UndefOr[String] = js.undefined + + /** A valid language tag according to [RFC 5646: Tags for Identifying Languages (also known as BCP + * 47)](https://datatracker.ietf.org/doc/html/rfc5646). + */ + var lang: js.UndefOr[String] = js.undefined + + /** A valid MIME type. */ + var mediaType: js.UndefOr[String] = js.undefined + + /** A string indicating the type of data stored in data. + * + * It must be one of the following values: + * - "absolute-url" - An absolute URL to the data. + * - "empty" - An empty NDEFRecord. + * - "mime" - A valid MIME type. + * - "smart-poster" - A smart poster as defined by the NDEF-SMARTPOSTER specification. + * - "text" - Text as defined by the NDEF-TEXT specification. + * - "unknown" - The record type is not known. + * - "URL" - A URL as defined by the NDEF-URI specification. + */ + var recordType: js.UndefOr[String] = js.undefined +} diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFScanOptions.scala b/dom/src/main/scala/org/scalajs/dom/NDEFScanOptions.scala new file mode 100644 index 000000000..421071978 --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/NDEFScanOptions.scala @@ -0,0 +1,9 @@ +package org.scalajs.dom + +import scala.scalajs.js + +trait NDEFScanOptions extends js.Object { + + /** An AbortSignal that allows the current write operation to be canceled. */ + var `signal`: js.UndefOr[AbortSignal] = js.undefined +} diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFWriteOptions.scala b/dom/src/main/scala/org/scalajs/dom/NDEFWriteOptions.scala new file mode 100644 index 000000000..bc70bc4ea --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/NDEFWriteOptions.scala @@ -0,0 +1,14 @@ +package org.scalajs.dom + +import scala.scalajs.js + +/** @see https://developer.mozilla.org/en-US/docs/Web/API/NDEFReader/write */ +trait NDEFWriteOptions extends js.Object { + + /** A boolean value specifying whether or not existing records should be overwritten, if such exists. */ + var `overwrite`: js.UndefOr[Boolean] = js.undefined + + /** An AbortSignal that allows the current write operation to be canceled. */ + var `signal`: js.UndefOr[AbortSignal] = js.undefined + +} From 4f7043a9e64e61cc551a1babeaa373b4d977ae42 Mon Sep 17 00:00:00 2001 From: Fabio Pinheiro Date: Fri, 29 Sep 2023 16:47:02 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Arman Bilge --- dom/src/main/scala/org/scalajs/dom/NDEFMessage.scala | 2 +- .../scala/org/scalajs/dom/NDEFReadingEvent.scala | 4 ++-- dom/src/main/scala/org/scalajs/dom/NDEFRecord.scala | 12 ++++++------ 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFMessage.scala b/dom/src/main/scala/org/scalajs/dom/NDEFMessage.scala index bc5d71a2a..a2ada28b5 100644 --- a/dom/src/main/scala/org/scalajs/dom/NDEFMessage.scala +++ b/dom/src/main/scala/org/scalajs/dom/NDEFMessage.scala @@ -15,5 +15,5 @@ import scala.scalajs.js.annotation.JSGlobal class NDEFMessage(recordsAgr: js.Array[NDEFRecordInit]) extends js.Object { /** Returns the list of NDEF records contained in the message. */ - var records: FrozenArray[NDEFRecord] = js.native + def records: FrozenArray[NDEFRecord] = js.native } diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala b/dom/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala index 3bc402a90..dcf95b633 100644 --- a/dom/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala +++ b/dom/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala @@ -12,11 +12,11 @@ import scala.scalajs.js trait NDEFReadingEvent extends Event { /** Returns an NDEFMessage object containing the received message. */ - var message: NDEFMessage = js.native + def message: NDEFMessage = js.native /** Returns the serial number of the device, which is used for anti-collision and identification, or an empty string * if no serial number is available. */ - var serialNumber: String = js.native + def serialNumber: String = js.native } diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFRecord.scala b/dom/src/main/scala/org/scalajs/dom/NDEFRecord.scala index 31e097e7a..38ec604ad 100644 --- a/dom/src/main/scala/org/scalajs/dom/NDEFRecord.scala +++ b/dom/src/main/scala/org/scalajs/dom/NDEFRecord.scala @@ -14,25 +14,25 @@ class NDEFRecord(options: NDEFRecordInit) extends js.Object { * "empty", "text", "url", "smart-poster", "absolute-url", "mime", or "unknown" or else an external type name, which * consists of a domain name and custom type name separated by a colon (":"). */ - var recordType: String = js.native + def recordType: String = js.native /** Returns the MIME type of the record. This value will be null if recordType is not equal to "mime". */ - var mediaType: js.UndefOr[String] = js.native + def mediaType: js.UndefOr[String] = js.native /** Returns the record identifier, which is an absolute or relative URL used to identify the record. * * Note: The uniqueness of the identifier is enforced only by the generator of the record. */ - var id: js.UndefOr[String] = js.native + def id: js.UndefOr[String] = js.native /** Returns a DataView containing the raw bytes of the record's payload. */ - var data: js.typedarray.DataView = js.native + def data: js.typedarray.DataView = js.native /** Returns the encoding of a textual payload, or null otherwise. */ - var encoding: js.UndefOr[String] = js.native + def encoding: js.UndefOr[String] = js.native /** Returns the language of a textual payload, or null if one was not supplied. */ - var lang: js.UndefOr[String] = js.native + def lang: js.UndefOr[String] = js.native /** Converts [[NDEFRecord.data]] to a sequence of records. This allows parsing the payloads of record types which may * contain nested records, such as smart poster and external type records. From 65a35e3f3bd93597a451e51a6a1187ef8dcb9712 Mon Sep 17 00:00:00 2001 From: FabioPinheiro Date: Fri, 29 Sep 2023 18:00:21 +0100 Subject: [PATCH 3/3] Add trait NDEFReadingEventInit and other fixes --- api-reports/2_12.txt | 56 ++++++++++--------- api-reports/2_13.txt | 56 ++++++++++--------- .../scala/org/scalajs/dom/NDEFMessage.scala | 9 ++- .../scala/org/scalajs/dom/NDEFReader.scala | 3 + .../org/scalajs/dom/NDEFReadingEvent.scala | 7 ++- .../scalajs/dom/NDEFReadingEventInit.scala | 24 ++++++++ .../scala/org/scalajs/dom/NDEFRecord.scala | 7 ++- .../org/scalajs/dom/NDEFRecordInit.scala | 8 ++- .../org/scalajs/dom/NDEFScanOptions.scala | 1 + .../org/scalajs/dom/NDEFWriteOptions.scala | 9 ++- 10 files changed, 119 insertions(+), 61 deletions(-) create mode 100644 dom/src/main/scala/org/scalajs/dom/NDEFReadingEventInit.scala diff --git a/api-reports/2_12.txt b/api-reports/2_12.txt index 8f088efd6..e2c196e4c 100644 --- a/api-reports/2_12.txt +++ b/api-reports/2_12.txt @@ -16464,7 +16464,7 @@ MutationRecord[JT] def previousSibling: Node MutationRecord[JT] def removedNodes: NodeList[Node] MutationRecord[JT] def target: Node MutationRecord[JT] def `type`: String -NDEFMessage[JC] var records: FrozenArray[NDEFRecord] +NDEFMessage[JC] def records: FrozenArray[NDEFRecord] NDEFReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit NDEFReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit NDEFReader[JC] def dispatchEvent(evt: Event): Boolean @@ -16482,35 +16482,41 @@ NDEFReader[JC] def write(message: js.typedarray.ArrayBuffer, options: NDEFWriteO NDEFReader[JC] def write(message: js.typedarray.DataView): js.Promise[Unit] NDEFReader[JC] def write(message: js.typedarray.DataView, options: NDEFWriteOptions): js.Promise[Unit] NDEFReader[JC] def write(message: js.typedarray.TypedArray[_, _], options: NDEFWriteOptions?): js.Promise[Unit] -NDEFReadingEvent[JT] def bubbles: Boolean -NDEFReadingEvent[JT] def cancelBubble: Boolean -NDEFReadingEvent[JT] def cancelable: Boolean -NDEFReadingEvent[JT] def composed: Boolean -NDEFReadingEvent[JT] def currentTarget: EventTarget -NDEFReadingEvent[JT] def defaultPrevented: Boolean -NDEFReadingEvent[JT] def eventPhase: Int -NDEFReadingEvent[JT] def isTrusted: Boolean -NDEFReadingEvent[JT] var message: NDEFMessage -NDEFReadingEvent[JT] def preventDefault(): Unit -NDEFReadingEvent[JT] var serialNumber: String -NDEFReadingEvent[JT] def stopImmediatePropagation(): Unit -NDEFReadingEvent[JT] def stopPropagation(): Unit -NDEFReadingEvent[JT] def target: EventTarget -NDEFReadingEvent[JT] def timeStamp: Double -NDEFReadingEvent[JT] def `type`: String -NDEFRecord[JC] var data: js.typedarray.DataView -NDEFRecord[JC] var encoding: js.UndefOr[String] -NDEFRecord[JC] var id: js.UndefOr[String] -NDEFRecord[JC] var lang: js.UndefOr[String] -NDEFRecord[JC] var mediaType: js.UndefOr[String] -NDEFRecord[JC] var recordType: String -NDEFRecord[JC] def toRecords(): js.Array[NDEFRecord] +NDEFReadingEvent[JC] def bubbles: Boolean +NDEFReadingEvent[JC] def cancelBubble: Boolean +NDEFReadingEvent[JC] def cancelable: Boolean +NDEFReadingEvent[JC] def composed: Boolean +NDEFReadingEvent[JC] def currentTarget: EventTarget +NDEFReadingEvent[JC] def defaultPrevented: Boolean +NDEFReadingEvent[JC] def eventPhase: Int +NDEFReadingEvent[JC] def isTrusted: Boolean +NDEFReadingEvent[JC] def message: NDEFMessage +NDEFReadingEvent[JC] def preventDefault(): Unit +NDEFReadingEvent[JC] def serialNumber: String +NDEFReadingEvent[JC] def stopImmediatePropagation(): Unit +NDEFReadingEvent[JC] def stopPropagation(): Unit +NDEFReadingEvent[JC] def target: EventTarget +NDEFReadingEvent[JC] def timeStamp: Double +NDEFReadingEvent[JC] def `type`: String +NDEFReadingEventInit[JT] var bubbles: js.UndefOr[Boolean] +NDEFReadingEventInit[JT] var cancelable: js.UndefOr[Boolean] +NDEFReadingEventInit[JT] var composed: js.UndefOr[Boolean] +NDEFReadingEventInit[JT] var message: NDEFRecordInit +NDEFReadingEventInit[JT] var scoped: js.UndefOr[Boolean] +NDEFReadingEventInit[JT] var serialNumber: js.UndefOr[AbortSignal] +NDEFRecord[JC] def data: js.typedarray.DataView +NDEFRecord[JC] def encoding: js.UndefOr[String] +NDEFRecord[JC] def id: js.UndefOr[String] +NDEFRecord[JC] def lang: js.UndefOr[String] +NDEFRecord[JC] def mediaType: js.UndefOr[String] +NDEFRecord[JC] def recordType: String +NDEFRecord[JC] def toRecords(): js.UndefOr[js.Array[NDEFRecord]] NDEFRecordInit[JT] var data: js.UndefOr[String | js.typedarray.DataView | js.typedarray.ArrayBuffer | js.typedarray.TypedArray[_, _] | js.typedarray.DataView | js.Array[NDEFRecord]] NDEFRecordInit[JT] var encoding: js.UndefOr[String] NDEFRecordInit[JT] var id: js.UndefOr[String] NDEFRecordInit[JT] var lang: js.UndefOr[String] NDEFRecordInit[JT] var mediaType: js.UndefOr[String] -NDEFRecordInit[JT] var recordType: js.UndefOr[String] +NDEFRecordInit[JT] var recordType: String NDEFScanOptions[JT] var signal: js.UndefOr[AbortSignal] NDEFWriteOptions[JT] var overwrite: js.UndefOr[Boolean] NDEFWriteOptions[JT] var signal: js.UndefOr[AbortSignal] diff --git a/api-reports/2_13.txt b/api-reports/2_13.txt index 8f088efd6..e2c196e4c 100644 --- a/api-reports/2_13.txt +++ b/api-reports/2_13.txt @@ -16464,7 +16464,7 @@ MutationRecord[JT] def previousSibling: Node MutationRecord[JT] def removedNodes: NodeList[Node] MutationRecord[JT] def target: Node MutationRecord[JT] def `type`: String -NDEFMessage[JC] var records: FrozenArray[NDEFRecord] +NDEFMessage[JC] def records: FrozenArray[NDEFRecord] NDEFReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], options: EventListenerOptions): Unit NDEFReader[JC] def addEventListener[T <: Event](`type`: String, listener: js.Function1[T, _], useCapture: Boolean?): Unit NDEFReader[JC] def dispatchEvent(evt: Event): Boolean @@ -16482,35 +16482,41 @@ NDEFReader[JC] def write(message: js.typedarray.ArrayBuffer, options: NDEFWriteO NDEFReader[JC] def write(message: js.typedarray.DataView): js.Promise[Unit] NDEFReader[JC] def write(message: js.typedarray.DataView, options: NDEFWriteOptions): js.Promise[Unit] NDEFReader[JC] def write(message: js.typedarray.TypedArray[_, _], options: NDEFWriteOptions?): js.Promise[Unit] -NDEFReadingEvent[JT] def bubbles: Boolean -NDEFReadingEvent[JT] def cancelBubble: Boolean -NDEFReadingEvent[JT] def cancelable: Boolean -NDEFReadingEvent[JT] def composed: Boolean -NDEFReadingEvent[JT] def currentTarget: EventTarget -NDEFReadingEvent[JT] def defaultPrevented: Boolean -NDEFReadingEvent[JT] def eventPhase: Int -NDEFReadingEvent[JT] def isTrusted: Boolean -NDEFReadingEvent[JT] var message: NDEFMessage -NDEFReadingEvent[JT] def preventDefault(): Unit -NDEFReadingEvent[JT] var serialNumber: String -NDEFReadingEvent[JT] def stopImmediatePropagation(): Unit -NDEFReadingEvent[JT] def stopPropagation(): Unit -NDEFReadingEvent[JT] def target: EventTarget -NDEFReadingEvent[JT] def timeStamp: Double -NDEFReadingEvent[JT] def `type`: String -NDEFRecord[JC] var data: js.typedarray.DataView -NDEFRecord[JC] var encoding: js.UndefOr[String] -NDEFRecord[JC] var id: js.UndefOr[String] -NDEFRecord[JC] var lang: js.UndefOr[String] -NDEFRecord[JC] var mediaType: js.UndefOr[String] -NDEFRecord[JC] var recordType: String -NDEFRecord[JC] def toRecords(): js.Array[NDEFRecord] +NDEFReadingEvent[JC] def bubbles: Boolean +NDEFReadingEvent[JC] def cancelBubble: Boolean +NDEFReadingEvent[JC] def cancelable: Boolean +NDEFReadingEvent[JC] def composed: Boolean +NDEFReadingEvent[JC] def currentTarget: EventTarget +NDEFReadingEvent[JC] def defaultPrevented: Boolean +NDEFReadingEvent[JC] def eventPhase: Int +NDEFReadingEvent[JC] def isTrusted: Boolean +NDEFReadingEvent[JC] def message: NDEFMessage +NDEFReadingEvent[JC] def preventDefault(): Unit +NDEFReadingEvent[JC] def serialNumber: String +NDEFReadingEvent[JC] def stopImmediatePropagation(): Unit +NDEFReadingEvent[JC] def stopPropagation(): Unit +NDEFReadingEvent[JC] def target: EventTarget +NDEFReadingEvent[JC] def timeStamp: Double +NDEFReadingEvent[JC] def `type`: String +NDEFReadingEventInit[JT] var bubbles: js.UndefOr[Boolean] +NDEFReadingEventInit[JT] var cancelable: js.UndefOr[Boolean] +NDEFReadingEventInit[JT] var composed: js.UndefOr[Boolean] +NDEFReadingEventInit[JT] var message: NDEFRecordInit +NDEFReadingEventInit[JT] var scoped: js.UndefOr[Boolean] +NDEFReadingEventInit[JT] var serialNumber: js.UndefOr[AbortSignal] +NDEFRecord[JC] def data: js.typedarray.DataView +NDEFRecord[JC] def encoding: js.UndefOr[String] +NDEFRecord[JC] def id: js.UndefOr[String] +NDEFRecord[JC] def lang: js.UndefOr[String] +NDEFRecord[JC] def mediaType: js.UndefOr[String] +NDEFRecord[JC] def recordType: String +NDEFRecord[JC] def toRecords(): js.UndefOr[js.Array[NDEFRecord]] NDEFRecordInit[JT] var data: js.UndefOr[String | js.typedarray.DataView | js.typedarray.ArrayBuffer | js.typedarray.TypedArray[_, _] | js.typedarray.DataView | js.Array[NDEFRecord]] NDEFRecordInit[JT] var encoding: js.UndefOr[String] NDEFRecordInit[JT] var id: js.UndefOr[String] NDEFRecordInit[JT] var lang: js.UndefOr[String] NDEFRecordInit[JT] var mediaType: js.UndefOr[String] -NDEFRecordInit[JT] var recordType: js.UndefOr[String] +NDEFRecordInit[JT] var recordType: String NDEFScanOptions[JT] var signal: js.UndefOr[AbortSignal] NDEFWriteOptions[JT] var overwrite: js.UndefOr[Boolean] NDEFWriteOptions[JT] var signal: js.UndefOr[AbortSignal] diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFMessage.scala b/dom/src/main/scala/org/scalajs/dom/NDEFMessage.scala index a2ada28b5..b2add223a 100644 --- a/dom/src/main/scala/org/scalajs/dom/NDEFMessage.scala +++ b/dom/src/main/scala/org/scalajs/dom/NDEFMessage.scala @@ -7,12 +7,15 @@ import scala.scalajs.js.annotation.JSGlobal * or could be written to an NFC tag. An instance is acquired by calling the NDEFMessage() constructor or from the * NDEFReadingEvent.message property, which is passed to the reading event. * - * @param records - * The records property of NDEFMessage interface represents a list of NDEFRecords present in the NDEF message. + * @see + * https://w3c.github.io/web-nfc/#the-ndefmessage-interface + * + * @param messageInit + * property of NDEFMessage interface represents a list of NDEFRecords present in the NDEF message. */ @js.native @JSGlobal -class NDEFMessage(recordsAgr: js.Array[NDEFRecordInit]) extends js.Object { +class NDEFMessage(messageInit: js.Array[NDEFRecordInit]) extends js.Object { /** Returns the list of NDEF records contained in the message. */ def records: FrozenArray[NDEFRecord] = js.native diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFReader.scala b/dom/src/main/scala/org/scalajs/dom/NDEFReader.scala index 5d1c7531c..d13ae5f2f 100644 --- a/dom/src/main/scala/org/scalajs/dom/NDEFReader.scala +++ b/dom/src/main/scala/org/scalajs/dom/NDEFReader.scala @@ -6,6 +6,9 @@ import scala.scalajs.js.annotation.JSGlobal /** The [[NDEFReader]] interface of the Web NFC API (https://developer.mozilla.org/en-US/docs/Web/API/Web_NFC_API) is * used to read from and write data to compatible NFC devices, e.g. NFC tags supporting NDEF, when these devices are * within the reader's magnetic induction field. + * + * @see + * https://w3c.github.io/web-nfc/#the-ndefreader-object */ @JSGlobal("NDEFReader") @js.native diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala b/dom/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala index dcf95b633..bb2aaa28a 100644 --- a/dom/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala +++ b/dom/src/main/scala/org/scalajs/dom/NDEFReadingEvent.scala @@ -1,15 +1,19 @@ package org.scalajs.dom import scala.scalajs.js +import scala.scalajs.js.annotation.JSGlobal /** The NDEFReadingEvent interface of the Web NFC API represents events dispatched on new NFC readings obtained by * NDEFReader. * * @see * https://developer.mozilla.org/en-US/docs/Web/API/NDEFReadingEvent + * @see + * https://w3c.github.io/web-nfc/#the-ndefreader-object */ @js.native -trait NDEFReadingEvent extends Event { +@JSGlobal +class NDEFReadingEvent(typeArg: String, init: NDEFReadingEventInit) extends Event(typeArg, init) { /** Returns an NDEFMessage object containing the received message. */ def message: NDEFMessage = js.native @@ -18,5 +22,4 @@ trait NDEFReadingEvent extends Event { * if no serial number is available. */ def serialNumber: String = js.native - } diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFReadingEventInit.scala b/dom/src/main/scala/org/scalajs/dom/NDEFReadingEventInit.scala new file mode 100644 index 000000000..b6b5364fd --- /dev/null +++ b/dom/src/main/scala/org/scalajs/dom/NDEFReadingEventInit.scala @@ -0,0 +1,24 @@ +package org.scalajs.dom + +import scala.scalajs.js + +/** NDEFReadingEventInit is used to initialize a new event with a serial number and the NDEFMessageInit data via the + * message member. If serialNumber is not present or is null, empty string will be used to init the event. + * + * @see + * https://developer.mozilla.org/en-US/docs/Web/API/NDEFReadingEvent/NDEFReadingEvent#parameters + * @see + * https://w3c.github.io/web-nfc/#the-ndefreader-object + */ +trait NDEFReadingEventInit extends EventInit { + + /** A string with the name of the event. It is case-sensitive and browsers always set it to reading. Default is "" an + * empty string + */ + var serialNumber: js.UndefOr[AbortSignal] = js.undefined + + /** An object that, in addition of the properties defined in Event(), can have the following properties: serialNumber; + * message + */ + var message: NDEFRecordInit +} diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFRecord.scala b/dom/src/main/scala/org/scalajs/dom/NDEFRecord.scala index 38ec604ad..0e0aead4e 100644 --- a/dom/src/main/scala/org/scalajs/dom/NDEFRecord.scala +++ b/dom/src/main/scala/org/scalajs/dom/NDEFRecord.scala @@ -5,10 +5,13 @@ import scala.scalajs.js.annotation.JSGlobal /** The [[NDEFRecord]] interface of the Web NFC API provides data that can be read from, or written to, compatible NFC * devices, e.g. NFC tags supporting NDEF. + * + * @see + * https://w3c.github.io/web-nfc/#the-ndefrecord-interface */ @js.native @JSGlobal -class NDEFRecord(options: NDEFRecordInit) extends js.Object { +class NDEFRecord(init: NDEFRecordInit) extends js.Object { /** Returns the record type of the record. Records must have either a standardized well-known type name such as * "empty", "text", "url", "smart-poster", "absolute-url", "mime", or "unknown" or else an external type name, which @@ -37,5 +40,5 @@ class NDEFRecord(options: NDEFRecordInit) extends js.Object { /** Converts [[NDEFRecord.data]] to a sequence of records. This allows parsing the payloads of record types which may * contain nested records, such as smart poster and external type records. */ - def toRecords(): js.Array[NDEFRecord] = js.native + def toRecords(): js.UndefOr[js.Array[NDEFRecord]] = js.native } diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFRecordInit.scala b/dom/src/main/scala/org/scalajs/dom/NDEFRecordInit.scala index 0069f2a5b..b88ac6177 100644 --- a/dom/src/main/scala/org/scalajs/dom/NDEFRecordInit.scala +++ b/dom/src/main/scala/org/scalajs/dom/NDEFRecordInit.scala @@ -3,10 +3,14 @@ package org.scalajs.dom import scala.scalajs.js import scala.scalajs.js.| -/** @see +/** The NDEFRecordInit dictionary is used to initialize an NDEF record with its record type recordType, and optional + * record identifier id and payload data data. + * @see * https://developer.mozilla.org/en-US/docs/Web/API/NDEFMessage/NDEFMessage * @see * https://developer.mozilla.org/en-US/docs/Web/API/NDEFRecord/NDEFRecord + * @see + * https://w3c.github.io/web-nfc/#the-ndefrecord-interface */ trait NDEFRecordInit extends js.Object { @@ -47,5 +51,5 @@ trait NDEFRecordInit extends js.Object { * - "unknown" - The record type is not known. * - "URL" - A URL as defined by the NDEF-URI specification. */ - var recordType: js.UndefOr[String] = js.undefined + var recordType: String } diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFScanOptions.scala b/dom/src/main/scala/org/scalajs/dom/NDEFScanOptions.scala index 421071978..2b2946b7a 100644 --- a/dom/src/main/scala/org/scalajs/dom/NDEFScanOptions.scala +++ b/dom/src/main/scala/org/scalajs/dom/NDEFScanOptions.scala @@ -2,6 +2,7 @@ package org.scalajs.dom import scala.scalajs.js +/** @see https://w3c.github.io/web-nfc/#the-ndefscanoptions-dictionary */ trait NDEFScanOptions extends js.Object { /** An AbortSignal that allows the current write operation to be canceled. */ diff --git a/dom/src/main/scala/org/scalajs/dom/NDEFWriteOptions.scala b/dom/src/main/scala/org/scalajs/dom/NDEFWriteOptions.scala index bc70bc4ea..c7836b55a 100644 --- a/dom/src/main/scala/org/scalajs/dom/NDEFWriteOptions.scala +++ b/dom/src/main/scala/org/scalajs/dom/NDEFWriteOptions.scala @@ -2,10 +2,15 @@ package org.scalajs.dom import scala.scalajs.js -/** @see https://developer.mozilla.org/en-US/docs/Web/API/NDEFReader/write */ +/** @see + * https://w3c.github.io/web-nfc/#the-ndefwriteoptions-dictionary + * @see + * https://developer.mozilla.org/en-US/docs/Web/API/NDEFReader/write + */ trait NDEFWriteOptions extends js.Object { - /** A boolean value specifying whether or not existing records should be overwritten, if such exists. */ + /** A boolean value specifying whether or not existing records should be overwritten, if such exists. Default is true + */ var `overwrite`: js.UndefOr[Boolean] = js.undefined /** An AbortSignal that allows the current write operation to be canceled. */