mirror of
https://github.com/NohamR/safari-internal-js.git
synced 2026-02-22 02:45:41 +00:00
Add 26.2 versioned JS files and move 15.7 files
This commit is contained in:
30
26.2/js/forms/AutomaticPasswords.js
Normal file
30
26.2/js/forms/AutomaticPasswords.js
Normal file
@@ -0,0 +1,30 @@
|
||||
//# sourceURL=__InjectedScript_AutomaticPasswords.js
|
||||
/* Copyright (c) 2025 Apple Inc. All rights reserved. */
|
||||
"use strict";
|
||||
class AutomaticPasswords {
|
||||
removeAutomaticPasswordElements(t, e, o) {
|
||||
for (let e of t)
|
||||
FormMetadataJS.removeAutomaticStrongPasswordFromPasswordElement(e);
|
||||
if (!o) return;
|
||||
let r = document.activeElement,
|
||||
a = e ? FormMetadataJS.formControlWithUniqueID(e) : null;
|
||||
(a && a.blur(), a && a === r && a.focus());
|
||||
}
|
||||
blurControlWithID(t) {
|
||||
let e = t ? FormMetadataJS.formControlWithUniqueID(t) : null;
|
||||
e && e.blur();
|
||||
}
|
||||
setStrongPasswordElementViewableIfAppropriate(t, e) {
|
||||
for (let o of t) {
|
||||
let t = FormMetadataJS.formControlWithUniqueID(o);
|
||||
if (!t) return;
|
||||
if ("text" === t.type)
|
||||
return (
|
||||
FormMetadataJSController.setInputElementAutoFilledAndViewable(t, !1),
|
||||
void FormMetadataJSController.setInputElementAutofilled(t, !1)
|
||||
);
|
||||
FormMetadataJSController.setInputElementAutoFilledAndViewable(t, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
var AutomaticPasswordsJS = new AutomaticPasswords();
|
||||
5188
26.2/js/forms/FormMetadata.js
Normal file
5188
26.2/js/forms/FormMetadata.js
Normal file
File diff suppressed because it is too large
Load Diff
674
26.2/js/forms/FormMetadataClassification.js
Normal file
674
26.2/js/forms/FormMetadataClassification.js
Normal file
@@ -0,0 +1,674 @@
|
||||
//# sourceURL=__InjectedScript_FormMetadataClassification.js
|
||||
/* Copyright (c) 2025 Apple Inc. All rights reserved. */
|
||||
"use strict";
|
||||
function datePlaceholderParser(e) {
|
||||
for (const t of e) {
|
||||
const e = t.toLowerCase();
|
||||
if (e >= "a" && e <= "z" && !["d", "y", "m"].includes(e)) return null;
|
||||
}
|
||||
return e.includes("d")
|
||||
? e.includes("yyyy")
|
||||
? { year: "numeric", month: "2-digit", day: "2-digit" }
|
||||
: { year: "2-digit", month: "2-digit", day: "2-digit" }
|
||||
: e.includes("M")
|
||||
? e.includes("yyyy")
|
||||
? { year: "numeric", month: "2-digit" }
|
||||
: { year: "2-digit", month: "2-digit" }
|
||||
: e.includes("y")
|
||||
? e.includes("yyyy")
|
||||
? { year: "numeric" }
|
||||
: { year: "2-digit" }
|
||||
: null;
|
||||
}
|
||||
function referenceDateToDateFormat(e) {
|
||||
let t = e.replace("12", "MM");
|
||||
return (
|
||||
(t = t.replace("30", "dd")),
|
||||
(t = t.replace("1999", "y")),
|
||||
(t = t.replace("99", "yy")),
|
||||
t
|
||||
);
|
||||
}
|
||||
const WBSABAddressProperty = "Address",
|
||||
WBSABPhoneProperty = "Phone",
|
||||
_WBSABAddressZIPKey = "ZIP",
|
||||
WBSFormControlMetadataDefaultMaxLength = 524288,
|
||||
WBSIgnoredClassificationToken = "-sf-ignored",
|
||||
WBSDateDayOrderedPartToken = "-sf-day",
|
||||
WBSDateMonthOrderedPartToken = "-sf-month",
|
||||
WBSDateYearOrderedPartToken = "-sf-year",
|
||||
WBSGivenNameOrderedPartToken = "given-name",
|
||||
WBSAdditionalNameOrderedPartToken = "additional-name",
|
||||
WBSFamilyNameOrderedPartToken = "family-name",
|
||||
WBSLocaleForCreditCardExpirationDate = "en-US-POSIX",
|
||||
WBSCreditCardTypeClassificationToken = "cc-type",
|
||||
WBSCreditCardHolderNameClassificationToken = "cc-name",
|
||||
WBSCreditCardNumberClassificationToken = "cc-number",
|
||||
WBSCreditCardExpirationClassificationToken = "cc-exp",
|
||||
WBSCreditCardSecurityCodeClassificationToken = "cc-csc",
|
||||
WBSCreditCardHolderNameClassificationDefaultOrderedParts = [
|
||||
WBSGivenNameOrderedPartToken,
|
||||
WBSAdditionalNameOrderedPartToken,
|
||||
WBSFamilyNameOrderedPartToken,
|
||||
],
|
||||
WBSCreditCardExpirationClassificationDefaultOrderedParts = [
|
||||
WBSDateMonthOrderedPartToken,
|
||||
WBSDateYearOrderedPartToken,
|
||||
],
|
||||
WBSCredentialUsernameClassificationToken = "username",
|
||||
WBSCredentialCurrentPasswordClassificationToken = "current-password",
|
||||
WBSCredentialNewPasswordClassificationToken = "new-password",
|
||||
WBSContactNameClassificationToken = "name",
|
||||
WBSContactNameClassificationDefaultOrderedParts = [
|
||||
WBSGivenNameOrderedPartToken,
|
||||
WBSAdditionalNameOrderedPartToken,
|
||||
WBSFamilyNameOrderedPartToken,
|
||||
],
|
||||
WBSNameOrderedPartTokensSet = new Set(
|
||||
WBSContactNameClassificationDefaultOrderedParts,
|
||||
),
|
||||
WBSContactInstantMessageClassificationToken = "-sf-instant-message",
|
||||
WBSContactPostalCodeClassificationToken = "postal-code",
|
||||
WBSContactStreetAddressClassificationToken = "street-address",
|
||||
WBSContactStreetAddressLine1OrderedPartToken = "address-line1",
|
||||
WBSContactStreetAddressLine2OrderedPartToken = "address-line2",
|
||||
WBSContactStreetAddressLine3OrderedPartToken = "address-line3",
|
||||
WBSContactTelephoneClassificationToken = "tel",
|
||||
WBSTelephoneCountryCodeOrderedPartToken = "tel-country-code",
|
||||
WBSTelephoneAreaCodeOrderedPartToken = "tel-area-code",
|
||||
WBSTelephoneLocalPrefixOrderedPartToken = "tel-local-prefix",
|
||||
WBSTelephoneLocalSuffixOrderedPartToken = "tel-local-suffix",
|
||||
WBSTelephoneExtensionOrderedPartToken = "tel-extension",
|
||||
WBSTelephoneDefaultOrderedParts = [
|
||||
WBSTelephoneCountryCodeOrderedPartToken,
|
||||
WBSTelephoneAreaCodeOrderedPartToken,
|
||||
WBSTelephoneLocalPrefixOrderedPartToken,
|
||||
WBSTelephoneLocalSuffixOrderedPartToken,
|
||||
WBSTelephoneExtensionOrderedPartToken,
|
||||
],
|
||||
WBSContactBirthdayClassificationToken = "bday",
|
||||
WBSContactEmailClassificationToken = "email",
|
||||
WBSDeviceEIDClassificationToken = "device-eid",
|
||||
WBSDeviceIMEIClassificationToken = "device-imei",
|
||||
AllowedControlTagsForStandaloneCreditCardCompositeExpirationControl = new Set(
|
||||
["input", "select", "textarea"],
|
||||
);
|
||||
class FormMetadataClassification {
|
||||
#e(e) {
|
||||
return null != e && "object" == typeof e;
|
||||
}
|
||||
#t(e) {
|
||||
return this.#e(e) && "string" == typeof e.ControlTagName;
|
||||
}
|
||||
#o(e) {
|
||||
return this.#e(e) && "string" == typeof e.property;
|
||||
}
|
||||
fieldLooksLikeDateField(e) {
|
||||
return !!(
|
||||
e.ControlLooksLikeDayField ||
|
||||
e.ControlLooksLikeMonthField ||
|
||||
e.ControlLooksLikeYearField
|
||||
);
|
||||
}
|
||||
#r(e) {
|
||||
let t = e.ControlMaxLength;
|
||||
return (
|
||||
(void 0 === t || t < 0 || t > WBSFormControlMetadataDefaultMaxLength) &&
|
||||
(t = WBSFormControlMetadataDefaultMaxLength),
|
||||
t
|
||||
);
|
||||
}
|
||||
fieldLooksLikeItExpectsDataOfSize(e, t) {
|
||||
return (e.ControlSize ?? 0) <= t || this.#r(e) <= t;
|
||||
}
|
||||
fieldCouldBeCreditCardNumberContinuation(e, t) {
|
||||
const o = 4;
|
||||
if (t.length >= o) return !1;
|
||||
if (!t[0]?.ControlLooksLikeCreditCardNumberField) return !1;
|
||||
const r = 2;
|
||||
if (e.ControlMaxLength === r) return !1;
|
||||
if (e.ControlLooksLikeCreditCardNumberField) return !0;
|
||||
if (e.ControlLooksLikeCreditCardSecurityCodeField) return !1;
|
||||
if (e.ControlLooksLikeCreditCardCompositeExpirationDateField) return !1;
|
||||
const n = 6;
|
||||
if (!this.fieldLooksLikeItExpectsDataOfSize(e, n)) return !1;
|
||||
const i = t.at(-1);
|
||||
return !(i && !this.fieldLooksLikeItExpectsDataOfSize(i, n));
|
||||
}
|
||||
labelsCouldRepresentContinuation(e, t, o, r) {
|
||||
return (
|
||||
!(!e || !o) &&
|
||||
(e === o ||
|
||||
(!!t &&
|
||||
(!r ||
|
||||
(t.property === r.property &&
|
||||
(!r.component || t.component === r.component)))))
|
||||
);
|
||||
}
|
||||
#n(e) {
|
||||
const t = [
|
||||
WBSContactStreetAddressLine1OrderedPartToken,
|
||||
WBSContactStreetAddressLine2OrderedPartToken,
|
||||
WBSContactStreetAddressLine3OrderedPartToken,
|
||||
],
|
||||
o = [
|
||||
WBSContactStreetAddressLine2OrderedPartToken,
|
||||
WBSContactStreetAddressLine3OrderedPartToken,
|
||||
];
|
||||
if (e.AutocompleteTokens)
|
||||
for (let o of e.AutocompleteTokens)
|
||||
switch (o) {
|
||||
case "street-address":
|
||||
return t;
|
||||
case "address-line1":
|
||||
return [WBSContactStreetAddressLine1OrderedPartToken];
|
||||
case "address-line2":
|
||||
case "address-level2":
|
||||
return [WBSContactStreetAddressLine2OrderedPartToken];
|
||||
case "address-line3":
|
||||
case "address-level1":
|
||||
return [WBSContactStreetAddressLine3OrderedPartToken];
|
||||
}
|
||||
let r = e.ControlFieldName,
|
||||
n = r?.indexOf("1") ?? -1,
|
||||
i = r?.indexOf("2") ?? -1;
|
||||
return -1 === n
|
||||
? -1 === i
|
||||
? t
|
||||
: o
|
||||
: -1 === i || n < i
|
||||
? [WBSContactStreetAddressLine1OrderedPartToken]
|
||||
: o;
|
||||
}
|
||||
fieldCouldBePhoneNumberContinuation(e, t) {
|
||||
const o = 5;
|
||||
if (t.length >= o) return !1;
|
||||
if (t[0]?.AddressBookValueSpecifier?.property !== WBSABPhoneProperty)
|
||||
return !1;
|
||||
const r = 5;
|
||||
return !!this.fieldLooksLikeItExpectsDataOfSize(e, r);
|
||||
}
|
||||
fieldCouldBePostCodeContinuation(e, t) {
|
||||
const o = 3;
|
||||
if (t.length >= o) return !1;
|
||||
if (t[0]?.AddressBookValueSpecifier?.component != _WBSABAddressZIPKey)
|
||||
return !1;
|
||||
const r = 6;
|
||||
return !!this.fieldLooksLikeItExpectsDataOfSize(e, r);
|
||||
}
|
||||
fieldLooksLikeSameDataType(e, t) {
|
||||
const o = t.at(-1);
|
||||
return (
|
||||
!!this.labelsCouldRepresentContinuation(
|
||||
o?.AddressBookLabel,
|
||||
o?.AddressBookValueSpecifier,
|
||||
e?.AddressBookLabel,
|
||||
e?.AddressBookValueSpecifier,
|
||||
) ||
|
||||
!!(
|
||||
o &&
|
||||
this.fieldLooksLikeDateField(o) &&
|
||||
this.fieldLooksLikeDateField(e)
|
||||
) ||
|
||||
!!this.fieldCouldBePhoneNumberContinuation(e, t) ||
|
||||
!!this.fieldCouldBePostCodeContinuation(e, t) ||
|
||||
!!this.fieldCouldBeCreditCardNumberContinuation(e, t)
|
||||
);
|
||||
}
|
||||
#i(e) {
|
||||
if (
|
||||
(globalThis.DOMRect ||
|
||||
(globalThis.DOMRect = class {
|
||||
constructor(e, t, o, r) {
|
||||
((this.left = e),
|
||||
(this.right = e + o),
|
||||
(this.top = t),
|
||||
(this.bottom = t + r),
|
||||
(this.width = o),
|
||||
(this.height = r));
|
||||
}
|
||||
}),
|
||||
e.ControlRectLeft ||
|
||||
e.ControlRectTop ||
|
||||
e.ControlRectWidth ||
|
||||
e.ControlRectHeight)
|
||||
)
|
||||
return new DOMRect(
|
||||
e.ControlRectLeft,
|
||||
e.ControlRectTop,
|
||||
e.ControlRectWidth,
|
||||
e.ControlRectHeight,
|
||||
);
|
||||
let t = globalThis.FormMetadataJS?.formControlWithUniqueID(
|
||||
e.ControlUniqueID,
|
||||
);
|
||||
return t ? t.getBoundingClientRect() : new DOMRect(0, 0, 0, 0);
|
||||
}
|
||||
fieldLooksLikeContinuation(e, t, o) {
|
||||
if (!e.ControlIsTextField && "SELECT" !== e.ControlTagName.toUpperCase())
|
||||
return !1;
|
||||
if (!this.fieldLooksLikeSameDataType(e, t)) return !1;
|
||||
if (o) return !0;
|
||||
const r = this.#i(t.at(-1)),
|
||||
n = this.#i(e);
|
||||
if (Math.abs(r.top - n.top) > 3) return !1;
|
||||
let i, a;
|
||||
return (
|
||||
r.left < n.left ? ((i = r), (a = n)) : ((i = n), (a = r)),
|
||||
!(a.left - i.right > 60)
|
||||
);
|
||||
}
|
||||
continuingFieldsInFormControls(e, t, o, r) {
|
||||
const n = [e[t]];
|
||||
for (let i = t + 1; i < e.length; ++i) {
|
||||
const t = e[i];
|
||||
if (o && !t.ControlIsTextField) break;
|
||||
if (!this.fieldLooksLikeContinuation(t, n, r)) break;
|
||||
n.push(t);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
classifyControlsRelatedToNameParts(e, t, o) {
|
||||
const r = e[t];
|
||||
((r.ControlClassification = o),
|
||||
(r.ControlOrderedParts = [r.AddressBookValueSpecifier?.classification]));
|
||||
const n = new Set([r.AddressBookValueSpecifier?.classification]),
|
||||
i = [e[t]];
|
||||
for (let r = t + 1; r < e.length; ++r) {
|
||||
const t = e[r];
|
||||
if (!t.ControlIsTextField) break;
|
||||
const a = t.AddressBookValueSpecifier?.classification;
|
||||
if (!a) break;
|
||||
if (!WBSNameOrderedPartTokensSet.has(a) || n.has(a)) break;
|
||||
((t.ControlClassification = o),
|
||||
(t.ControlOrderedParts = [a]),
|
||||
n.add(a),
|
||||
i.push(t));
|
||||
}
|
||||
return i;
|
||||
}
|
||||
identifyDateFields(e) {
|
||||
let t,
|
||||
o,
|
||||
r,
|
||||
n = !1;
|
||||
for (let i of e)
|
||||
if (i.ControlLooksLikeDayField) {
|
||||
if (t) return [!1, null, null, null];
|
||||
((t = i), (n = !0));
|
||||
} else if (i.ControlLooksLikeMonthField) {
|
||||
if (o) return [!1, null, null, null];
|
||||
((o = i), (n = !0));
|
||||
} else if (i.ControlLooksLikeYearField) {
|
||||
if (r) return [!1, null, null, null];
|
||||
((r = i), (n = !0));
|
||||
}
|
||||
return [n, r, o, t];
|
||||
}
|
||||
canonicalizedDateTemplate(e) {
|
||||
if (e && (e = e.replace(/\s/g, "")).length && !/[^dmyDMY\/.-]/g.test(e))
|
||||
return (e = (e = (e = e.replace(/D/g, "d")).replace(/m/g, "M")).replace(
|
||||
/Y/g,
|
||||
"y",
|
||||
));
|
||||
}
|
||||
classifyDateFields(e, t, o, r, n, i, a) {
|
||||
if (e.length > 3) return !1;
|
||||
if ((a || (a = navigator.language), 1 === e.length)) {
|
||||
if (!e[0].ControlIsTextField) return !1;
|
||||
let i = e[0].ControlRequiredFormatForDateTimeInput;
|
||||
if (!i) {
|
||||
const t = new Date(1999, 11, 30);
|
||||
let o = this.#r(e[0]),
|
||||
r = this.canonicalizedDateTemplate(e[0].ControlPlaceholder),
|
||||
s = "";
|
||||
if (r?.length) {
|
||||
const e = datePlaceholderParser(r);
|
||||
e &&
|
||||
((s = new Intl.DateTimeFormat(a, e).format(t)),
|
||||
(i = referenceDateToDateFormat(s)));
|
||||
}
|
||||
if (!s || s.length > o) {
|
||||
const e = n
|
||||
? [
|
||||
{ year: "numeric", month: "2-digit", day: "2-digit" },
|
||||
{ year: "2-digit", month: "2-digit", day: "2-digit" },
|
||||
]
|
||||
: [{ year: "2-digit", month: "2-digit" }];
|
||||
for (const r of e)
|
||||
if (
|
||||
((s = new Intl.DateTimeFormat(a, r).format(t)),
|
||||
(i = referenceDateToDateFormat(s)),
|
||||
s.length <= o)
|
||||
)
|
||||
break;
|
||||
}
|
||||
if (s.length > o) return !1;
|
||||
}
|
||||
const s = [];
|
||||
for (const e of i) {
|
||||
let t;
|
||||
("y" === e ? (t = o) : "M" === e ? (t = r) : "d" === e && (t = n),
|
||||
t && !s.includes(t) && s.push(t));
|
||||
}
|
||||
return (
|
||||
(e[0].ControlClassification = t),
|
||||
(e[0].ControlOrderedParts = s),
|
||||
(e[0].ControlRequiredFormatForDateTimeInput = i),
|
||||
!0
|
||||
);
|
||||
}
|
||||
let [s, l, d, C] = this.identifyDateFields(e);
|
||||
if (!s) return !1;
|
||||
if (C && !d) return !1;
|
||||
let c = 0;
|
||||
for (const a of e)
|
||||
((a.ControlClassification = t),
|
||||
(a.ControlContinuationID = i),
|
||||
(a.ControlContinuationIndex = c++),
|
||||
a === C
|
||||
? (a.ControlOrderedParts = [n])
|
||||
: a === d
|
||||
? (a.ControlOrderedParts = [r])
|
||||
: a === l && (a.ControlOrderedParts = [o]));
|
||||
return !0;
|
||||
}
|
||||
classify(e) {
|
||||
const t = e.FormControls,
|
||||
o = t.length,
|
||||
r = e.AutoFillFormType === WBSAutoFillFormTypeNewAccount,
|
||||
n = e.AutoFillFormType === WBSAutoFillFormTypeChangePassword,
|
||||
i = e.UsernameElementUniqueID,
|
||||
a = e.PasswordElementUniqueID,
|
||||
s = e.OldPasswordElementUniqueID,
|
||||
l = e.ConfirmPasswordElementUniqueID;
|
||||
for (let e of t)
|
||||
(e.AutocompleteTokens || e.AddressBookLabel) &&
|
||||
(e.AddressBookValueSpecifier =
|
||||
FormMetadataJSController.specifierForAutocompleteTokensAndAddressBookLabel(
|
||||
e.AutocompleteTokens,
|
||||
e.AddressBookLabel,
|
||||
));
|
||||
let d = !1,
|
||||
C = !1,
|
||||
c = !1,
|
||||
f = !1,
|
||||
u = !1,
|
||||
k = 0;
|
||||
for (let S = 0, T = 1; S < o; S += T, T = 1) {
|
||||
const o = t[S];
|
||||
if (o.ControlLooksLikeIgnoredDataTypeField) {
|
||||
o.ControlClassification = WBSIgnoredClassificationToken;
|
||||
continue;
|
||||
}
|
||||
const h = o.ControlUniqueID;
|
||||
if (h === a || h === l) {
|
||||
o.ControlClassification =
|
||||
r || n
|
||||
? WBSCredentialNewPasswordClassificationToken
|
||||
: WBSCredentialCurrentPasswordClassificationToken;
|
||||
continue;
|
||||
}
|
||||
if (h === s) {
|
||||
o.ControlClassification =
|
||||
WBSCredentialCurrentPasswordClassificationToken;
|
||||
continue;
|
||||
}
|
||||
const B = o.AddressBookValueSpecifier?.classification;
|
||||
if (B === WBSContactEmailClassificationToken) {
|
||||
o.ControlClassification = WBSContactEmailClassificationToken;
|
||||
continue;
|
||||
}
|
||||
if (h === i) {
|
||||
o.ControlClassification = WBSCredentialUsernameClassificationToken;
|
||||
continue;
|
||||
}
|
||||
if (!C && o.ControlLooksLikeCreditCardCardholderField) {
|
||||
if (((C = !0), B && WBSNameOrderedPartTokensSet.has(B))) {
|
||||
const e = this.classifyControlsRelatedToNameParts(
|
||||
t,
|
||||
S,
|
||||
WBSCreditCardHolderNameClassificationToken,
|
||||
);
|
||||
if (e.length > 1) {
|
||||
let t = ++k,
|
||||
o = 0;
|
||||
for (let r of e)
|
||||
((r.ControlContinuationID = t),
|
||||
(r.ControlContinuationIndex = o++));
|
||||
}
|
||||
T = e.length;
|
||||
continue;
|
||||
}
|
||||
((o.ControlClassification = WBSCreditCardHolderNameClassificationToken),
|
||||
(o.ControlOrderedParts =
|
||||
WBSCreditCardHolderNameClassificationDefaultOrderedParts));
|
||||
continue;
|
||||
}
|
||||
if (!d && o.ControlLooksLikeCreditCardNumberField) {
|
||||
d = !0;
|
||||
const e = this.continuingFieldsInFormControls(t, S, !0, !1);
|
||||
let o = 0,
|
||||
r = e.length > 1 ? ++k : 0;
|
||||
for (let t of e)
|
||||
((t.ControlClassification = WBSCreditCardNumberClassificationToken),
|
||||
(t.ControlContinuationID = r),
|
||||
(t.ControlContinuationIndex = o++));
|
||||
T = e.length;
|
||||
continue;
|
||||
}
|
||||
const P =
|
||||
this.fieldLooksLikeDateField(o) ||
|
||||
o.ControlLooksLikeCreditCardCompositeExpirationDateField;
|
||||
if (!c && P) {
|
||||
let e = f || C || d;
|
||||
if (
|
||||
((e ||=
|
||||
!o.ControlLooksLikeOneTimeCodeField &&
|
||||
1 ===
|
||||
t.filter((e) =>
|
||||
AllowedControlTagsForStandaloneCreditCardCompositeExpirationControl.has(
|
||||
e.ControlTagName.toLowerCase(),
|
||||
),
|
||||
).length),
|
||||
e)
|
||||
) {
|
||||
c = !0;
|
||||
const e = this.continuingFieldsInFormControls(t, S, !1, !0);
|
||||
let o = e.length > 1 ? ++k : 0;
|
||||
(this.classifyDateFields(
|
||||
e,
|
||||
WBSCreditCardExpirationClassificationToken,
|
||||
WBSDateYearOrderedPartToken,
|
||||
WBSDateMonthOrderedPartToken,
|
||||
void 0,
|
||||
o,
|
||||
WBSLocaleForCreditCardExpirationDate,
|
||||
),
|
||||
(T = e.length));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (u || !o.ControlLooksLikeCreditCardSecurityCodeField)
|
||||
if (f || !o.ControlLooksLikeCreditCardTypeField)
|
||||
if (B) {
|
||||
const r = o.AddressBookValueSpecifier.classificationHint;
|
||||
if (B === WBSContactNameClassificationToken) {
|
||||
((o.ControlClassification = B),
|
||||
(o.ControlOrderedParts =
|
||||
WBSContactNameClassificationDefaultOrderedParts));
|
||||
continue;
|
||||
}
|
||||
if (WBSNameOrderedPartTokensSet.has(B)) {
|
||||
const e = this.classifyControlsRelatedToNameParts(
|
||||
t,
|
||||
S,
|
||||
WBSContactNameClassificationToken,
|
||||
);
|
||||
if (e.length > 1) {
|
||||
let t = ++k,
|
||||
o = 0;
|
||||
for (let r of e)
|
||||
((r.ControlContinuationID = t),
|
||||
(r.ControlContinuationIndex = o++));
|
||||
}
|
||||
T = e.length;
|
||||
continue;
|
||||
}
|
||||
if (B === WBSContactPostalCodeClassificationToken) {
|
||||
const e = this.continuingFieldsInFormControls(t, S, !0, !1);
|
||||
let o = e.length > 1 ? ++k : 0,
|
||||
r = 0;
|
||||
for (let t of e)
|
||||
((t.ControlClassification =
|
||||
WBSContactPostalCodeClassificationToken),
|
||||
(t.ControlContinuationID = o),
|
||||
(t.ControlContinuationIndex = r++));
|
||||
T = e.length;
|
||||
continue;
|
||||
}
|
||||
if (B === WBSContactStreetAddressClassificationToken) {
|
||||
const e = this.continuingFieldsInFormControls(t, S, !0, !0);
|
||||
let o = e.length > 1 ? ++k : 0,
|
||||
r = 0;
|
||||
for (let t of e)
|
||||
((t.ControlClassification =
|
||||
WBSContactStreetAddressClassificationToken),
|
||||
(t.ControlContinuationID = o),
|
||||
(t.ControlContinuationIndex = r++));
|
||||
if (1 === e.length) {
|
||||
let t = e[0];
|
||||
t.ControlOrderedParts = this.#n(t);
|
||||
} else
|
||||
2 === e.length
|
||||
? ((e[0].ControlOrderedParts = [
|
||||
WBSContactStreetAddressLine1OrderedPartToken,
|
||||
]),
|
||||
(e[1].ControlOrderedParts = [
|
||||
WBSContactStreetAddressLine2OrderedPartToken,
|
||||
WBSContactStreetAddressLine3OrderedPartToken,
|
||||
]))
|
||||
: e.length >= 3 &&
|
||||
((e[0].ControlOrderedParts = [
|
||||
WBSContactStreetAddressLine1OrderedPartToken,
|
||||
]),
|
||||
(e[1].ControlOrderedParts = [
|
||||
WBSContactStreetAddressLine2OrderedPartToken,
|
||||
]),
|
||||
(e[2].ControlOrderedParts = [
|
||||
WBSContactStreetAddressLine3OrderedPartToken,
|
||||
]));
|
||||
T = e.length;
|
||||
continue;
|
||||
}
|
||||
if (B === WBSContactInstantMessageClassificationToken) {
|
||||
const e = this.continuingFieldsInFormControls(t, S, !0, !0);
|
||||
(1 === e.length &&
|
||||
((e[0].ControlClassification =
|
||||
WBSContactInstantMessageClassificationToken),
|
||||
r && (e[0].ControlClassificationHints = [r])),
|
||||
(T = e.length));
|
||||
continue;
|
||||
}
|
||||
if (B.startsWith(WBSContactTelephoneClassificationToken)) {
|
||||
const e = this.continuingFieldsInFormControls(t, S, !0, !1);
|
||||
if (1 == e.length) {
|
||||
((e[0].ControlClassification =
|
||||
WBSContactTelephoneClassificationToken),
|
||||
(e[0].ControlOrderedParts = WBSTelephoneDefaultOrderedParts),
|
||||
r && (e[0].ControlClassificationHints = [r]));
|
||||
continue;
|
||||
}
|
||||
let o = ++k,
|
||||
n = 0;
|
||||
for (let t of e)
|
||||
((t.ControlClassification =
|
||||
WBSContactTelephoneClassificationToken),
|
||||
(t.ControlContinuationID = o),
|
||||
(t.ControlContinuationIndex = n++),
|
||||
r && (t.ControlClassificationHints = [r]));
|
||||
(2 === e.length
|
||||
? ((e[0].ControlOrderedParts = [
|
||||
WBSTelephoneAreaCodeOrderedPartToken,
|
||||
]),
|
||||
(e[1].ControlOrderedParts = [
|
||||
WBSTelephoneLocalPrefixOrderedPartToken,
|
||||
WBSTelephoneLocalSuffixOrderedPartToken,
|
||||
]))
|
||||
: 3 === e.length
|
||||
? ((e[0].ControlOrderedParts = [
|
||||
WBSTelephoneAreaCodeOrderedPartToken,
|
||||
]),
|
||||
(e[1].ControlOrderedParts = [
|
||||
WBSTelephoneLocalPrefixOrderedPartToken,
|
||||
]),
|
||||
(e[2].ControlOrderedParts = [
|
||||
WBSTelephoneLocalSuffixOrderedPartToken,
|
||||
]))
|
||||
: 4 === e.length
|
||||
? ((e[0].ControlOrderedParts = [
|
||||
WBSTelephoneCountryCodeOrderedPartToken,
|
||||
]),
|
||||
(e[1].ControlOrderedParts = [
|
||||
WBSTelephoneAreaCodeOrderedPartToken,
|
||||
]),
|
||||
(e[2].ControlOrderedParts = [
|
||||
WBSTelephoneLocalPrefixOrderedPartToken,
|
||||
]),
|
||||
(e[3].ControlOrderedParts = [
|
||||
WBSTelephoneLocalSuffixOrderedPartToken,
|
||||
]))
|
||||
: ((e[0].ControlOrderedParts = [
|
||||
WBSTelephoneCountryCodeOrderedPartToken,
|
||||
]),
|
||||
(e[1].ControlOrderedParts = [
|
||||
WBSTelephoneAreaCodeOrderedPartToken,
|
||||
]),
|
||||
(e[2].ControlOrderedParts = [
|
||||
WBSTelephoneLocalPrefixOrderedPartToken,
|
||||
]),
|
||||
(e[3].ControlOrderedParts = [
|
||||
WBSTelephoneLocalSuffixOrderedPartToken,
|
||||
]),
|
||||
(e[4].ControlOrderedParts = [
|
||||
WBSTelephoneExtensionOrderedPartToken,
|
||||
])),
|
||||
(T = e.length));
|
||||
continue;
|
||||
}
|
||||
if (B === WBSContactBirthdayClassificationToken) {
|
||||
const o = this.continuingFieldsInFormControls(t, S, !1, !1),
|
||||
r = o.length > 1 ? ++k : void 0,
|
||||
n =
|
||||
e.RequestType === WBSFormMetadataRequestTesting
|
||||
? "en-US"
|
||||
: void 0;
|
||||
(this.classifyDateFields(
|
||||
o,
|
||||
WBSContactBirthdayClassificationToken,
|
||||
WBSDateYearOrderedPartToken,
|
||||
WBSDateMonthOrderedPartToken,
|
||||
WBSDateDayOrderedPartToken,
|
||||
r,
|
||||
n,
|
||||
),
|
||||
(T = o.length));
|
||||
continue;
|
||||
}
|
||||
o.ControlClassification = B;
|
||||
} else
|
||||
o.ControlLooksLikeEIDField
|
||||
? (o.ControlClassification = WBSDeviceEIDClassificationToken)
|
||||
: o.ControlLooksLikeIMEIField &&
|
||||
(o.ControlClassification = WBSDeviceIMEIClassificationToken);
|
||||
else
|
||||
((f = !0),
|
||||
(o.ControlClassification = WBSCreditCardTypeClassificationToken));
|
||||
else
|
||||
((u = !0),
|
||||
(o.ControlClassification =
|
||||
WBSCreditCardSecurityCodeClassificationToken));
|
||||
}
|
||||
}
|
||||
}
|
||||
globalThis.FormMetadataClassificationJS = new FormMetadataClassification();
|
||||
9051
26.2/js/forms/FormMetadataContactsAutoFillMappings.js
Normal file
9051
26.2/js/forms/FormMetadataContactsAutoFillMappings.js
Normal file
File diff suppressed because it is too large
Load Diff
617
26.2/js/forms/FormMetadataJSController.js
Normal file
617
26.2/js/forms/FormMetadataJSController.js
Normal file
@@ -0,0 +1,617 @@
|
||||
//# sourceURL=__InjectedScript_FormMetadataJSController.js
|
||||
/* Copyright (c) 2025 Apple Inc. All rights reserved. */
|
||||
"use strict";
|
||||
function addGlobalEventHandler(e, t) {
|
||||
function* a(e) {
|
||||
const t = document.createTreeWalker(
|
||||
e,
|
||||
NodeFilter.SHOW_ELEMENT,
|
||||
function (e) {
|
||||
return e.shadowRoot
|
||||
? "user-agent" === e.shadowRoot.mode
|
||||
? NodeFilter.FILTER_REJECT
|
||||
: NodeFilter.FILTER_ACCEPT
|
||||
: NodeFilter.FILTER_SKIP;
|
||||
},
|
||||
);
|
||||
for (; t.nextNode(); ) {
|
||||
const e = t.currentNode;
|
||||
(yield* a(e.shadowRoot), yield e);
|
||||
}
|
||||
}
|
||||
const o = "focus" === e || "blur" === e,
|
||||
r = (() => {
|
||||
switch (e) {
|
||||
case "focus":
|
||||
case "blur":
|
||||
case "input":
|
||||
return !0;
|
||||
case "submit":
|
||||
case "webkitassociateformcontrols":
|
||||
return !1;
|
||||
default:
|
||||
throw new Error(`uncategorized event ${e}. Please categorize it`);
|
||||
}
|
||||
})();
|
||||
let l = t;
|
||||
if (
|
||||
(o &&
|
||||
(l = function (e) {
|
||||
e.target === e.composedPath()[0] && t(e);
|
||||
}),
|
||||
window.addEventListener(e, t, { capture: !0 }),
|
||||
!r || o)
|
||||
) {
|
||||
for (const t of a(document.documentElement))
|
||||
t.shadowRoot.addEventListener(e, l, { capture: !0 });
|
||||
window.addEventListener("webkitshadowrootattached", function (t) {
|
||||
t.composedPath()[0].shadowRoot.addEventListener(e, l, { capture: !0 });
|
||||
});
|
||||
}
|
||||
}
|
||||
const WBSMinimumLogicalWidthToShowManualAutoFillButton = 100;
|
||||
class FormMetadataFieldPatternMatcher {
|
||||
searchRegularExpression;
|
||||
constructor(e, t = !1) {
|
||||
const a = (Array.isArray(e) ? e : Object.keys(e))
|
||||
.toSorted((e, t) => t.length - e.length)
|
||||
.map(RegExp.escape),
|
||||
o = "(?=(\\W|$))",
|
||||
r = "(?<=(\\W|^))";
|
||||
this.searchRegularExpression = t
|
||||
? new RegExp("(?:" + a.join("|") + ")" + o, "ig")
|
||||
: new RegExp(r + "(?:" + a.join("|") + ")" + o, "ig");
|
||||
}
|
||||
longestMatch(e) {
|
||||
const t = e.match(this.searchRegularExpression);
|
||||
if (!t) return null;
|
||||
let a = "";
|
||||
for (const e of t) e.length > a.length && (a = e);
|
||||
if (!a) return null;
|
||||
const o = fieldLabelMap[a.toLowerCase()];
|
||||
if (!o) return [a, "", "", ""];
|
||||
const r = o.valueSpecifier;
|
||||
return [a, r.property, r.category, r.parentProperty];
|
||||
}
|
||||
searchReverse(e) {
|
||||
const t = e.match(this.searchRegularExpression);
|
||||
if (!t) return null;
|
||||
const a = t.at(-1);
|
||||
if (!a) return null;
|
||||
const o = fieldLabelMap[a.toLowerCase()];
|
||||
if (!o) return [a, "", "", ""];
|
||||
const r = o.valueSpecifier;
|
||||
return [a, r.property, r.category, r.parentProperty];
|
||||
}
|
||||
}
|
||||
class FormMetadataJSController {
|
||||
static isDebugConsoleLoggingEnabled =
|
||||
AutoFillControllerConfig.isDebugConsoleLoggingEnabled;
|
||||
static _nextControlUniqueID = 1;
|
||||
static get nextControlUniqueID() {
|
||||
return this._nextControlUniqueID++;
|
||||
}
|
||||
static _nextFormUniqueID = 1;
|
||||
static get nextFormUniqueID() {
|
||||
return this._nextFormUniqueID++;
|
||||
}
|
||||
static regularExpressionsIndicatingNonAutoFillableFormType =
|
||||
FormAutoFillKeywords.NonAutoFillableFormTypeRegularExpressions;
|
||||
static loginFormTypePatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.LoginFormTypeKeywords,
|
||||
),
|
||||
];
|
||||
static oneTimeCodeFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.OneTimeCodeFieldLabels,
|
||||
),
|
||||
];
|
||||
static nonAccountPasswordSecureTextEntryFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.NonAccountPasswordSecureTextEntryFieldLabels,
|
||||
),
|
||||
];
|
||||
static ignoredDataTypeFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.IgnoredDataTypeFieldLabels,
|
||||
!0,
|
||||
),
|
||||
];
|
||||
static oldPasswordFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.OldPasswordFieldLabels,
|
||||
),
|
||||
];
|
||||
static confirmPasswordFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.ConfirmPasswordFieldLabels,
|
||||
),
|
||||
];
|
||||
static confirmEmailFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.ConfirmEmailFieldLabels,
|
||||
),
|
||||
];
|
||||
static showHideButtonLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.ShowHideButtonLabels,
|
||||
),
|
||||
];
|
||||
static searchFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(FormAutoFillKeywords.SearchFieldLabels),
|
||||
];
|
||||
static nonUsernameFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.NonUsernameFieldLabels,
|
||||
),
|
||||
];
|
||||
static passwordFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.PasswordFieldLabels,
|
||||
),
|
||||
];
|
||||
static usernameFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.UsernameFieldLabels,
|
||||
),
|
||||
];
|
||||
static nonEmailFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.NonEmailFieldLabels,
|
||||
),
|
||||
];
|
||||
static weakOneTimeCodeFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.WeakOneTimeCodeFieldLabels,
|
||||
!0,
|
||||
),
|
||||
];
|
||||
static codeButNotOneTimeCodeFieldLabelsPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.CodeButNotOneTimeCodeFieldLabels,
|
||||
!0,
|
||||
),
|
||||
];
|
||||
static dayFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.DayFieldLabels,
|
||||
!0,
|
||||
),
|
||||
];
|
||||
static monthFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.MonthFieldLabels,
|
||||
!0,
|
||||
),
|
||||
];
|
||||
static yearFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.YearFieldLabels,
|
||||
!0,
|
||||
),
|
||||
];
|
||||
static addressBookFieldLabelPatternMatchers =
|
||||
newAddressBookFieldLabelPatternMatchers();
|
||||
static emailFieldLabelPatternMatchers = newEmailFieldLabelPatternMatchers();
|
||||
static creditCardNumberFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.creditCardAutoFill.numberFieldLabels,
|
||||
),
|
||||
];
|
||||
static creditCardSecurityCodeFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.creditCardAutoFill.securityCodeFieldLabels,
|
||||
),
|
||||
];
|
||||
static creditCardCardholderFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.creditCardAutoFill.cardholderLabels,
|
||||
),
|
||||
];
|
||||
static creditCardTypeFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.creditCardAutoFill.cardTypeLabels,
|
||||
),
|
||||
];
|
||||
static nonCreditCardCardNumberFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.creditCardAutoFill.nonCreditCardNumberLabels,
|
||||
),
|
||||
];
|
||||
static creditCardCompositeExpirationDateFieldLabelPatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.creditCardAutoFill.compositeExpirationDateLabels,
|
||||
),
|
||||
];
|
||||
static newAccountFormTypePatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.NewAccountFormTypeKeywords,
|
||||
),
|
||||
];
|
||||
static federatedSignInAffordancePatternMatchers = [
|
||||
new FormMetadataFieldPatternMatcher(
|
||||
FormAutoFillKeywords.FederatedSignInAffordanceLabels,
|
||||
),
|
||||
];
|
||||
static mapOfKeywordsIndicatingLoginFormTypeToScoreForMatching =
|
||||
FormAutoFillKeywords.LoginFormTypeKeywords;
|
||||
static mapOfKeywordsIndicatingNewAccountFormTypeToScoreForMatching =
|
||||
FormAutoFillKeywords.NewAccountFormTypeKeywords;
|
||||
static mapOfKeywordsIndicatingChangePasswordFormTypeToScoreForMatching =
|
||||
FormAutoFillKeywords.ChangePasswordFormTypeKeywords;
|
||||
static regularExpressionsForForgotPasswordAffordance =
|
||||
FormAutoFillKeywords.ForgotPasswordAffordanceRegularExpressions;
|
||||
static regularExpressionsForForgotUserNameAffordance =
|
||||
FormAutoFillKeywords.ForgotUserNameAffordanceRegularExpressions;
|
||||
static regularExpressionsForForgotEmailAffordance =
|
||||
FormAutoFillKeywords.ForgotEmailAffordanceRegularExpressions;
|
||||
static specifierForAutocompleteTokensAndAddressBookLabel(e, t) {
|
||||
if (e) {
|
||||
if (!Array.isArray(e))
|
||||
throw new Error("Expected an array of autocomplete tokens");
|
||||
for (let t of e) {
|
||||
const e = autocompleteTokenMap[t]?.valueSpecifier;
|
||||
if (e) return e;
|
||||
}
|
||||
}
|
||||
if (t) {
|
||||
const e = fieldLabelMap[t]?.valueSpecifier;
|
||||
if (e) return e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
autoFillButtonManager;
|
||||
focusManager;
|
||||
didAssociateFormControlsTimeout;
|
||||
constructor() {
|
||||
((this.focusManager = new FocusManager(this)),
|
||||
this.focusManager.addEventListeners(),
|
||||
(this.autoFillButtonManager = new AutoFillButtonManager(this)),
|
||||
this.autoFillButtonManager.addEventListeners(),
|
||||
(this.didAssociateFormControlsTimeout = null),
|
||||
addGlobalEventHandler(
|
||||
"webkitassociateformcontrols",
|
||||
this.didAssociateFormControls.bind(this),
|
||||
),
|
||||
(this.shouldNotifyOnFormChanges = !1),
|
||||
window.addEventListener("pagehide", () => {
|
||||
window.webkit.messageHandlers.controller.postMessage({
|
||||
name: "pageHide",
|
||||
});
|
||||
}));
|
||||
}
|
||||
didAssociateFormControls(e) {
|
||||
if (!this.shouldNotifyOnFormChanges) return;
|
||||
if (this.didAssociateFormControlsTimeout) return;
|
||||
const t = e.composedPath()[0];
|
||||
if ("hidden" === t.type || "button" === t.type) return;
|
||||
const [a, o] = FormMetadataJS.formsAndMetadata(
|
||||
WBSFormMetadataRequestPreFill,
|
||||
);
|
||||
this.didAssociateFormControlsTimeout = setTimeout(
|
||||
this.sendDidAssociateFormControlsMessage.bind(this),
|
||||
0,
|
||||
);
|
||||
}
|
||||
sendDidAssociateFormControlsMessage() {
|
||||
((this.didAssociateFormControlsTimeout = null),
|
||||
window.webkit.messageHandlers.controller.postMessage({
|
||||
name: "didAssociateFormControls",
|
||||
}));
|
||||
}
|
||||
reset() {
|
||||
FormMetadataJS.clearTextFieldOrSelectElementMetadataCache();
|
||||
}
|
||||
textEditingStatus() {
|
||||
const [e, t] = FormMetadataJS.visibleNonEmptyFormTextControls(),
|
||||
a = e.filter((e) => e.lastChangeWasUserEdit),
|
||||
o = t.filter((e) => e.lastChangeWasUserEdit),
|
||||
r = document.body.onbeforeunload,
|
||||
l = null != r;
|
||||
return {
|
||||
numberOfTextInputElements: a.length,
|
||||
numberOfTextAreaElements: o.length,
|
||||
hasOnBeforeUnloadEventHandler: l,
|
||||
};
|
||||
}
|
||||
async fillFormWithPassword(e, t, a, o) {
|
||||
const r = await FormMetadataJS.fillFormWithPassword(e, a, t);
|
||||
for (let e of r) e.autofillVisibility = o ? "hidden" : "visible";
|
||||
o && AutomaticPasswords.blurControlWithID(t);
|
||||
}
|
||||
static #e(e) {
|
||||
const t = getComputedStyle(e).writingMode,
|
||||
a = !("horizontal-tb" === t || "horizontal-bt" === t),
|
||||
o = e.getBoundingClientRect();
|
||||
return (
|
||||
(a ? o.height : o.width) >=
|
||||
WBSMinimumLogicalWidthToShowManualAutoFillButton
|
||||
);
|
||||
}
|
||||
static #t(e) {
|
||||
return !!FormMetadataJSController.#e(e) && e === innermostActiveElement();
|
||||
}
|
||||
showAutoFillButtonInControl(e, t) {
|
||||
const a = FormMetadataJS.formControlWithUniqueID(e);
|
||||
(FormMetadataJSController.#t(a) || "none" === t) &&
|
||||
a._setAutofillButtonType(t);
|
||||
}
|
||||
setAutofillAvailable(e, t) {
|
||||
const a = FormMetadataJS.formControlWithUniqueID(e);
|
||||
a && (a.autofillAvailable = t);
|
||||
}
|
||||
setControlsAsAutoFilled(e, t) {
|
||||
this.#a(e).forEach((e) => {
|
||||
FormMetadataJSController.setInputElementAutofilled(e, t);
|
||||
});
|
||||
}
|
||||
blurControls(e) {
|
||||
this.#a.forEach((e) => e.blur());
|
||||
}
|
||||
clearControls(e) {
|
||||
this.#a.forEach(FormMetadataJS.clearField);
|
||||
}
|
||||
annotateForm(e, t) {
|
||||
FormMetadataJS.annotateFormWithID(e, t);
|
||||
}
|
||||
formsMetadata(e) {
|
||||
(e !== WBSFormMetadataRequestPreFill &&
|
||||
e !== WBSFormMetadataRequestTesting) ||
|
||||
(this.shouldNotifyOnFormChanges = !0);
|
||||
let [t, a] = FormMetadataJS.formsAndMetadata(e);
|
||||
for (const e of a)
|
||||
for (const t of e.FormControls) {
|
||||
const e = FormMetadataJS.formControlWithUniqueID(t.ControlUniqueID);
|
||||
this.populateRectFieldsInFormElementMetadata(t, e);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
getMetadataForControl(e, t = WBSFormMetadataRequestNormal) {
|
||||
const a = FormMetadataJS.formControlWithUniqueID(e);
|
||||
return a ? this._getMetadataForControl(a, t) : [null, null];
|
||||
}
|
||||
getMetadataForForm(e) {
|
||||
const [t, a] = FormMetadataJS.formsAndMetadata(
|
||||
WBSFormMetadataRequestNormal,
|
||||
);
|
||||
for (let o = 0; o < t.length; o++) if (t[o] === e) return a[o];
|
||||
return null;
|
||||
}
|
||||
_getMetadataForControl(e, t) {
|
||||
let [a, o] = FormMetadataJS.textFieldOrSelectElementMetadata(e, t, !1);
|
||||
return (
|
||||
this.populateRectFieldsInFormElementMetadata(a, e),
|
||||
FormMetadataJS.clearTextFieldOrSelectElementMetadataCache(),
|
||||
[a, o]
|
||||
);
|
||||
}
|
||||
focusControl(e, t = !1) {
|
||||
const a = FormMetadataJS.formControlWithUniqueID(e);
|
||||
a && (t ? FormMetadataJS._focusControlForStreamlinedLogin(a) : a.focus());
|
||||
}
|
||||
replaceRangeInControl(e, t, a, o, r) {
|
||||
FormMetadataJS.replaceFormFieldRangeAndSelectTail(e, t, a, o, r);
|
||||
const l = FormMetadataJS.formControlWithUniqueID(e);
|
||||
if (l)
|
||||
return FormMetadataJS.textFieldOrSelectElementMetadata(
|
||||
l,
|
||||
WBSFormMetadataRequestNormal,
|
||||
!0,
|
||||
);
|
||||
}
|
||||
selectRangeInControl(e, t, a) {
|
||||
FormMetadataJS.setFormFieldSelection(e, t, a);
|
||||
}
|
||||
static setInputElementSpellCheckEnabled(e, t) {
|
||||
e.autofillSpellcheck = !!t;
|
||||
}
|
||||
static setInputElementAutofilled(e, t) {
|
||||
((e.autofilled = t),
|
||||
t && FormMetadataJSController.autoFilledFieldWithMetadata(e));
|
||||
}
|
||||
static setInputElementAutoFilledAndViewable(e, t) {
|
||||
e.autofilledAndViewable = t;
|
||||
}
|
||||
static setInputElementAutofilledAndObscured(e, t) {
|
||||
((e.autofilledAndObscured = t),
|
||||
t && FormMetadataJSController.autoFilledFieldWithMetadata(e));
|
||||
}
|
||||
populateRectFieldsInFormElementMetadata(e, t) {
|
||||
const a = t.getBoundingClientRect();
|
||||
((e.ControlRectLeft = a.left),
|
||||
(e.ControlRectTop = a.top),
|
||||
(e.ControlRectWidth = a.width),
|
||||
(e.ControlRectHeight = a.height));
|
||||
}
|
||||
#a(e) {
|
||||
return e.flatMap(FormMetadataJS.formControlWithUniqueID);
|
||||
}
|
||||
static autoFilledFieldWithMetadata(e) {
|
||||
let [t, a] = FormMetadataJS.textFieldOrSelectElementMetadata(
|
||||
e,
|
||||
WBSFormMetadataRequestNormal,
|
||||
!1,
|
||||
);
|
||||
window.webkit.messageHandlers.controller.postMessage({
|
||||
name: "autoFilledFieldWithMetadata",
|
||||
controlMetadata: t,
|
||||
formMetadata: a,
|
||||
});
|
||||
}
|
||||
static logicalFormObservedChangeIndicatingFormSubmission(e, t) {
|
||||
window.webkit.messageHandlers.controller.postMessage({
|
||||
name: "formObservedChangeIndicatingFormSubmission",
|
||||
formMetadata: e,
|
||||
removedControlsMetadata: t,
|
||||
});
|
||||
}
|
||||
}
|
||||
class FieldMovementChecker {
|
||||
textField;
|
||||
textFieldMetadata;
|
||||
formMetadata;
|
||||
numberOfTimesFieldMovementTimerHasFired;
|
||||
checkForFieldMovementTimeout;
|
||||
pollingIntervals;
|
||||
onFieldMoved;
|
||||
constructor(e) {
|
||||
((this.textField = null),
|
||||
(this.textFieldMetadata = null),
|
||||
(this.numberOfTimesFieldMovementTimerHasFired = 0),
|
||||
(this.checkForFieldMovementTimeout = null),
|
||||
(this.pollingIntervals = [10, 50, 100, 850]),
|
||||
(this.onFieldMoved = e));
|
||||
}
|
||||
setTextFieldToMonitor(e, t, a) {
|
||||
((this.textField = e),
|
||||
(this.textFieldMetadata = t),
|
||||
(this.formMetadata = a));
|
||||
}
|
||||
performNextCheckForFieldMovement() {
|
||||
if (
|
||||
((this.checkForFieldMovementTimeout = null),
|
||||
!this.textField || !this.textFieldMetadata)
|
||||
)
|
||||
return void this.reset();
|
||||
const e = this.textField.getBoundingClientRect();
|
||||
(this.textFieldMetadata.ControlRectLeft != e.left ||
|
||||
this.textFieldMetadata.ControlRectTop != e.top ||
|
||||
this.textFieldMetadata.ControlRectWidth != e.width ||
|
||||
this.textFieldMetadata.ControlRectHeight != e.height
|
||||
? (this.onFieldMoved(
|
||||
this.textField,
|
||||
this.textFieldMetadata,
|
||||
this.formMetadata,
|
||||
),
|
||||
(this.numberOfTimesFieldMovementTimerHasFired = 0))
|
||||
: (this.numberOfTimesFieldMovementTimerHasFired += 1),
|
||||
this.numberOfTimesFieldMovementTimerHasFired >=
|
||||
this.pollingIntervals.length
|
||||
? this.reset()
|
||||
: this.scheduleNextCheckForFieldMovement());
|
||||
}
|
||||
reset() {
|
||||
(this.checkForFieldMovementTimeout &&
|
||||
window.clearTimeout(this.checkForFieldMovementTimeout),
|
||||
(this.checkForFieldMovementTimeout = null));
|
||||
}
|
||||
scheduleNextCheckForFieldMovement() {
|
||||
this.reset();
|
||||
const e =
|
||||
this.pollingIntervals[this.numberOfTimesFieldMovementTimerHasFired];
|
||||
this.checkForFieldMovementTimeout = window.setTimeout(
|
||||
this.performNextCheckForFieldMovement.bind(this),
|
||||
e,
|
||||
);
|
||||
}
|
||||
}
|
||||
class FocusManager {
|
||||
jsController;
|
||||
fieldMovementChecker;
|
||||
constructor(e) {
|
||||
((this.jsController = e),
|
||||
(this.fieldMovementChecker = new FieldMovementChecker(
|
||||
this.handleElementFocused.bind(this),
|
||||
)));
|
||||
}
|
||||
addEventListeners() {
|
||||
(addGlobalEventHandler("submit", this.submitEventHandler.bind(this)),
|
||||
addGlobalEventHandler("focus", this.focusInEventHandler.bind(this)),
|
||||
addGlobalEventHandler("blur", this.focusOutEventHandler.bind(this)),
|
||||
addGlobalEventHandler("input", this.inputEventHandler.bind(this)));
|
||||
}
|
||||
static #o(e) {
|
||||
for (const t of e.composedPath()) {
|
||||
if (FormMetadataJS._isTextField(t)) return t;
|
||||
if (t instanceof HTMLSelectElement) return t;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
focusInEventHandler(e) {
|
||||
this.fieldMovementChecker.reset();
|
||||
const t = FocusManager.#o(e);
|
||||
if (!t) return;
|
||||
let [a, o] = FormMetadataJS.textFieldOrSelectElementMetadata(
|
||||
t,
|
||||
WBSFormMetadataRequestNormal,
|
||||
!0,
|
||||
);
|
||||
a &&
|
||||
(t.setUserInfo({ form: o, textField: a }),
|
||||
this.fieldMovementChecker.setTextFieldToMonitor(t, a, o),
|
||||
this.fieldMovementChecker.scheduleNextCheckForFieldMovement(),
|
||||
this.handleElementFocused(t, a, o));
|
||||
}
|
||||
handleElementFocused(e, t, a) {
|
||||
(this.jsController.populateRectFieldsInFormElementMetadata(t, e),
|
||||
window.webkit.messageHandlers.controller.postMessage({
|
||||
name: "elementFocused",
|
||||
focusedElementMetadata: t,
|
||||
formMetadata: a,
|
||||
}));
|
||||
}
|
||||
focusOutEventHandler(e) {
|
||||
this.fieldMovementChecker.reset();
|
||||
const t = FocusManager.#o(e);
|
||||
if (!t) return;
|
||||
let [a, o] = FormMetadataJS.textFieldOrSelectElementMetadata(
|
||||
t,
|
||||
WBSFormMetadataRequestNormal,
|
||||
!0,
|
||||
);
|
||||
a &&
|
||||
window.webkit.messageHandlers.controller.postMessage({
|
||||
name: "elementBlurred",
|
||||
focusedElementMetadata: a,
|
||||
formMetadata: o,
|
||||
});
|
||||
}
|
||||
inputEventHandler(e) {
|
||||
const t = FocusManager.#o(e);
|
||||
if (!t) return;
|
||||
let [a, o] = FormMetadataJS.textFieldOrSelectElementMetadata(
|
||||
t,
|
||||
WBSFormMetadataRequestTextChange,
|
||||
!0,
|
||||
);
|
||||
a &&
|
||||
(this.jsController.populateRectFieldsInFormElementMetadata(a, t),
|
||||
window.webkit.messageHandlers.controller.postMessage({
|
||||
name: "elementInput",
|
||||
focusedElementMetadata: a,
|
||||
formMetadata: o,
|
||||
}));
|
||||
}
|
||||
submitEventHandler(e) {
|
||||
const t = e.target,
|
||||
a = this.jsController.getMetadataForForm(t);
|
||||
t.setUserInfo(a);
|
||||
}
|
||||
}
|
||||
class AutoFillButtonManager {
|
||||
jsController;
|
||||
constructor(e) {
|
||||
this.jsController = e;
|
||||
}
|
||||
addEventListeners() {
|
||||
document.addEventListener(
|
||||
"webkitautofillrequest",
|
||||
this.webKitAutofillRequestEventHandler.bind(this),
|
||||
{ capture: !0 },
|
||||
);
|
||||
}
|
||||
webKitAutofillRequestEventHandler(e) {
|
||||
const t = e.target;
|
||||
let [a, o] = this.jsController._getMetadataForControl(
|
||||
t,
|
||||
WBSFormMetadataRequestNormal,
|
||||
);
|
||||
window.webkit.messageHandlers.controller.postMessage({
|
||||
name: "manualAutoFillRequest",
|
||||
focusedElementMetadata: a,
|
||||
formMetadata: o,
|
||||
});
|
||||
}
|
||||
}
|
||||
let formMetadataJSController = new FormMetadataJSController();
|
||||
42
26.2/js/forms/FormMetadataUtilities.js
Normal file
42
26.2/js/forms/FormMetadataUtilities.js
Normal file
@@ -0,0 +1,42 @@
|
||||
//# sourceURL=__InjectedScript_FormMetadataUtilities.js
|
||||
/* Copyright (c) 2025 Apple Inc. All rights reserved. */
|
||||
// Copyright (c) 2025 Apple Inc. All rights reserved.
|
||||
"use strict";
|
||||
globalThis.FormMetadataUtilitiesJS = class {
|
||||
static #t(t, e) {
|
||||
const n = /([A-Za-z0-9])/;
|
||||
let o = null,
|
||||
s = -1,
|
||||
i = -1;
|
||||
const l = t.replaceAll(".", "").toLowerCase();
|
||||
for (let t = 0; t < e.length; t++) {
|
||||
const r = e[t].replaceAll(".", "").toLowerCase(),
|
||||
a = r.indexOf(l);
|
||||
if (-1 === a) continue;
|
||||
if (a > 0 && n.test(r.charAt(a - 1))) continue;
|
||||
let c = a + l.length;
|
||||
(c < r.length && n.test(r.charAt(c))) ||
|
||||
((!o || r.length < o.length) && ((o = r), (s = t), (i = a)));
|
||||
}
|
||||
return { index: s, startPosition: i };
|
||||
}
|
||||
static bestIndexToFillSelectControl(t, e) {
|
||||
const n = t.length,
|
||||
o = [];
|
||||
for (let e = 0; e < n; e++) {
|
||||
const n = t[e][1];
|
||||
o.push(n);
|
||||
}
|
||||
let s = -1,
|
||||
i = Number.MAX_SAFE_INTEGER;
|
||||
for (let t = e.length - 1; t >= 0; t--) {
|
||||
const n = e[t];
|
||||
Number.MAX_SAFE_INTEGER;
|
||||
const l = this.#t(n, o);
|
||||
-1 !== l.index &&
|
||||
l.startPosition < i &&
|
||||
((i = l.startPosition), (s = l.index));
|
||||
}
|
||||
return -1 === s ? -1 : t[s][0];
|
||||
}
|
||||
};
|
||||
374
26.2/js/forms/PasswordRulesParserJS.js
Normal file
374
26.2/js/forms/PasswordRulesParserJS.js
Normal file
@@ -0,0 +1,374 @@
|
||||
//# sourceURL=__InjectedScript_PasswordRulesParserJS.js
|
||||
/* Copyright (c) 2025 Apple Inc. All rights reserved. */
|
||||
// Copyright (c) 2019 - 2022 Apple Inc. Licensed under MIT License.
|
||||
"use strict";
|
||||
function _isIdentifierCharacter(e) {
|
||||
return (e >= "a" && e <= "z") || (e >= "A" && e <= "Z") || "-" === e;
|
||||
}
|
||||
function _isASCIIDigit(e) {
|
||||
return e >= "0" && e <= "9";
|
||||
}
|
||||
function _isASCIIPrintableCharacter(e) {
|
||||
return e >= " " && e <= "~";
|
||||
}
|
||||
function _isASCIIWhitespace(e) {
|
||||
return " " === e || "\f" === e || "\n" === e || "\r" === e || "\t" === e;
|
||||
}
|
||||
function _bitSetIndexForCharacter(e) {
|
||||
return e.codePointAt(0) - SPACE_CODE_POINT;
|
||||
}
|
||||
function _characterAtBitSetIndex(e) {
|
||||
return String.fromCodePoint(e + SPACE_CODE_POINT);
|
||||
}
|
||||
function _markBitsForNamedCharacterClass(e, r) {
|
||||
r.name === Identifier.UPPER
|
||||
? e.fill(
|
||||
!0,
|
||||
_bitSetIndexForCharacter("A"),
|
||||
_bitSetIndexForCharacter("Z") + 1,
|
||||
)
|
||||
: r.name === Identifier.LOWER
|
||||
? e.fill(
|
||||
!0,
|
||||
_bitSetIndexForCharacter("a"),
|
||||
_bitSetIndexForCharacter("z") + 1,
|
||||
)
|
||||
: r.name === Identifier.DIGIT
|
||||
? e.fill(
|
||||
!0,
|
||||
_bitSetIndexForCharacter("0"),
|
||||
_bitSetIndexForCharacter("9") + 1,
|
||||
)
|
||||
: r.name === Identifier.SPECIAL &&
|
||||
(e.fill(
|
||||
!0,
|
||||
_bitSetIndexForCharacter(" "),
|
||||
_bitSetIndexForCharacter("/") + 1,
|
||||
),
|
||||
e.fill(
|
||||
!0,
|
||||
_bitSetIndexForCharacter(":"),
|
||||
_bitSetIndexForCharacter("@") + 1,
|
||||
),
|
||||
e.fill(
|
||||
!0,
|
||||
_bitSetIndexForCharacter("["),
|
||||
_bitSetIndexForCharacter("`") + 1,
|
||||
),
|
||||
e.fill(
|
||||
!0,
|
||||
_bitSetIndexForCharacter("{"),
|
||||
_bitSetIndexForCharacter("~") + 1,
|
||||
));
|
||||
}
|
||||
function _markBitsForCustomCharacterClass(e, r) {
|
||||
for (let t of r.characters) e[_bitSetIndexForCharacter(t)] = !0;
|
||||
}
|
||||
function _canonicalizedPropertyValues(e, r) {
|
||||
function t(e, r) {
|
||||
let t = [];
|
||||
for (
|
||||
let n = _bitSetIndexForCharacter(e);
|
||||
n <= _bitSetIndexForCharacter(r);
|
||||
++n
|
||||
)
|
||||
a[n] && t.push(_characterAtBitSetIndex(n));
|
||||
let i =
|
||||
t.length ===
|
||||
_bitSetIndexForCharacter(r) - _bitSetIndexForCharacter(e) + 1;
|
||||
return (i || (n = n.concat(t)), i);
|
||||
}
|
||||
let a = new Array("~".codePointAt(0) - " ".codePointAt(0) + 1);
|
||||
for (let r of e)
|
||||
if (r instanceof NamedCharacterClass) {
|
||||
if (r.name === Identifier.UNICODE)
|
||||
return [new NamedCharacterClass(Identifier.UNICODE)];
|
||||
if (r.name === Identifier.ASCII_PRINTABLE)
|
||||
return [new NamedCharacterClass(Identifier.ASCII_PRINTABLE)];
|
||||
_markBitsForNamedCharacterClass(a, r);
|
||||
} else
|
||||
r instanceof CustomCharacterClass &&
|
||||
_markBitsForCustomCharacterClass(a, r);
|
||||
let n = [],
|
||||
i = t("A", "Z"),
|
||||
l = t("a", "z"),
|
||||
s = t("0", "9"),
|
||||
u = !1,
|
||||
c = !1,
|
||||
o = !1,
|
||||
_ = [];
|
||||
for (
|
||||
let e = _bitSetIndexForCharacter(" ");
|
||||
e <= _bitSetIndexForCharacter("/");
|
||||
++e
|
||||
) {
|
||||
if (!a[e]) continue;
|
||||
let t = _characterAtBitSetIndex(e);
|
||||
r && "-" === t ? (c = !0) : _.push(t);
|
||||
}
|
||||
for (
|
||||
let e = _bitSetIndexForCharacter(":");
|
||||
e <= _bitSetIndexForCharacter("@");
|
||||
++e
|
||||
)
|
||||
a[e] && _.push(_characterAtBitSetIndex(e));
|
||||
for (
|
||||
let e = _bitSetIndexForCharacter("[");
|
||||
e <= _bitSetIndexForCharacter("`");
|
||||
++e
|
||||
) {
|
||||
if (!a[e]) continue;
|
||||
let t = _characterAtBitSetIndex(e);
|
||||
r && "]" === t ? (o = !0) : _.push(t);
|
||||
}
|
||||
for (
|
||||
let e = _bitSetIndexForCharacter("{");
|
||||
e <= _bitSetIndexForCharacter("~");
|
||||
++e
|
||||
)
|
||||
a[e] && _.push(_characterAtBitSetIndex(e));
|
||||
(c && _.unshift("-"), o && _.push("]"));
|
||||
let C =
|
||||
_bitSetIndexForCharacter("/") -
|
||||
_bitSetIndexForCharacter(" ") +
|
||||
1 +
|
||||
(_bitSetIndexForCharacter("@") - _bitSetIndexForCharacter(":") + 1) +
|
||||
(_bitSetIndexForCharacter("`") - _bitSetIndexForCharacter("[") + 1) +
|
||||
(_bitSetIndexForCharacter("~") - _bitSetIndexForCharacter("{") + 1);
|
||||
((u = _.length === C), u || (n = n.concat(_)));
|
||||
let h = [];
|
||||
return i && l && s && u
|
||||
? [new NamedCharacterClass(Identifier.ASCII_PRINTABLE)]
|
||||
: (i && h.push(new NamedCharacterClass(Identifier.UPPER)),
|
||||
l && h.push(new NamedCharacterClass(Identifier.LOWER)),
|
||||
s && h.push(new NamedCharacterClass(Identifier.DIGIT)),
|
||||
u && h.push(new NamedCharacterClass(Identifier.SPECIAL)),
|
||||
n.length && h.push(new CustomCharacterClass(n)),
|
||||
h);
|
||||
}
|
||||
function _indexOfNonWhitespaceCharacter(e, r = 0) {
|
||||
let t = e.length;
|
||||
for (; r < t && _isASCIIWhitespace(e[r]); ) ++r;
|
||||
return r;
|
||||
}
|
||||
function _parseIdentifier(e, r) {
|
||||
let t = e.length,
|
||||
a = [];
|
||||
do {
|
||||
let t = e[r];
|
||||
if (!_isIdentifierCharacter(t)) break;
|
||||
(a.push(t), ++r);
|
||||
} while (r < t);
|
||||
return [a.join(""), r];
|
||||
}
|
||||
function _isValidRequiredOrAllowedPropertyValueIdentifier(e) {
|
||||
return e && Object.values(Identifier).includes(e.toLowerCase());
|
||||
}
|
||||
function _parseCustomCharacterClass(e, r) {
|
||||
let t = e.length;
|
||||
if (++r >= t) return [null, r];
|
||||
let a = r,
|
||||
n = [];
|
||||
do {
|
||||
let t = e[r];
|
||||
if (_isASCIIPrintableCharacter(t)) {
|
||||
if ("-" === t && r - a > 0) ++r;
|
||||
else if ((n.push(t), ++r, t === CHARACTER_CLASS_END_SENTINEL)) break;
|
||||
} else ++r;
|
||||
} while (r < t);
|
||||
return (r < t && e[r] !== CHARACTER_CLASS_END_SENTINEL) ||
|
||||
(r == t && e[r - 1] == CHARACTER_CLASS_END_SENTINEL)
|
||||
? (n.pop(), [n, r])
|
||||
: r < t && e[r] == CHARACTER_CLASS_END_SENTINEL
|
||||
? [n, r + 1]
|
||||
: [null, r];
|
||||
}
|
||||
function _parsePasswordRequiredOrAllowedPropertyValue(e, r) {
|
||||
let t = e.length,
|
||||
a = [];
|
||||
for (;;) {
|
||||
if (_isIdentifierCharacter(e[r])) {
|
||||
let t = r;
|
||||
var [n, r] = _parseIdentifier(e, r);
|
||||
if (!_isValidRequiredOrAllowedPropertyValueIdentifier(n))
|
||||
return [null, t];
|
||||
a.push(new NamedCharacterClass(n));
|
||||
} else {
|
||||
if (e[r] != CHARACTER_CLASS_START_SENTINEL) return [null, r];
|
||||
var [n, r] = _parseCustomCharacterClass(e, r);
|
||||
n && n.length && a.push(new CustomCharacterClass(n));
|
||||
}
|
||||
if (
|
||||
(r = _indexOfNonWhitespaceCharacter(e, r)) >= t ||
|
||||
e[r] === PROPERTY_SEPARATOR
|
||||
)
|
||||
break;
|
||||
if (e[r] !== PROPERTY_VALUE_SEPARATOR) return [null, r];
|
||||
if ((r = _indexOfNonWhitespaceCharacter(e, r + 1)) >= t) return [null, r];
|
||||
}
|
||||
return [a, r];
|
||||
}
|
||||
function _parsePasswordRule(e, r) {
|
||||
let t = e.length;
|
||||
var a = r,
|
||||
[n, r] = _parseIdentifier(e, r);
|
||||
if (!Object.values(RuleName).includes(n)) return [null, a];
|
||||
if (r >= t) return [null, r];
|
||||
if (e[r] !== PROPERTY_VALUE_START_SENTINEL) return [null, r];
|
||||
let i = { name: n, value: null };
|
||||
if (
|
||||
(r = _indexOfNonWhitespaceCharacter(e, r + 1)) >= t ||
|
||||
e[r] === PROPERTY_SEPARATOR
|
||||
)
|
||||
return [new Rule(i.name, i.value), r];
|
||||
switch (n) {
|
||||
case RuleName.ALLOWED:
|
||||
case RuleName.REQUIRED:
|
||||
var [l, r] = _parsePasswordRequiredOrAllowedPropertyValue(e, r);
|
||||
return (l && (i.value = l), [new Rule(i.name, i.value), r]);
|
||||
case RuleName.MAX_CONSECUTIVE:
|
||||
var [l, r] = _parseMaxConsecutivePropertyValue(e, r);
|
||||
return (l && (i.value = l), [new Rule(i.name, i.value), r]);
|
||||
case RuleName.MIN_LENGTH:
|
||||
case RuleName.MAX_LENGTH:
|
||||
var [l, r] = _parseMinLengthMaxLengthPropertyValue(e, r);
|
||||
return (l && (i.value = l), [new Rule(i.name, i.value), r]);
|
||||
}
|
||||
}
|
||||
function _parseMinLengthMaxLengthPropertyValue(e, r) {
|
||||
return _parseInteger(e, r);
|
||||
}
|
||||
function _parseMaxConsecutivePropertyValue(e, r) {
|
||||
return _parseInteger(e, r);
|
||||
}
|
||||
function _parseInteger(e, r) {
|
||||
if (!_isASCIIDigit(e[r])) return [null, r];
|
||||
let t = e.length,
|
||||
a = 0;
|
||||
do {
|
||||
((a = 10 * a + parseInt(e[r], 10)), ++r);
|
||||
} while (r < t && e[r] !== PROPERTY_SEPARATOR && _isASCIIDigit(e[r]));
|
||||
return r >= t || e[r] === PROPERTY_SEPARATOR ? [a, r] : [null, r];
|
||||
}
|
||||
function _parsePasswordRulesInternal(e) {
|
||||
let r = [],
|
||||
t = e.length;
|
||||
for (var a = _indexOfNonWhitespaceCharacter(e); a < t; ) {
|
||||
if (!_isIdentifierCharacter(e[a])) return r;
|
||||
var [n, a] = _parsePasswordRule(e, a);
|
||||
if (
|
||||
(n && n.value && r.push(n),
|
||||
(a = _indexOfNonWhitespaceCharacter(e, a)) >= t)
|
||||
)
|
||||
break;
|
||||
if (e[a] !== PROPERTY_SEPARATOR) return null;
|
||||
if ((a = _indexOfNonWhitespaceCharacter(e, a + 1)) >= t) return r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
function parsePasswordRules(e, r) {
|
||||
let t = _parsePasswordRulesInternal(e) || [],
|
||||
a = r,
|
||||
n = [],
|
||||
i = [],
|
||||
l = null,
|
||||
s = 0,
|
||||
u = null;
|
||||
for (let e of t)
|
||||
switch (e.name) {
|
||||
case RuleName.MAX_CONSECUTIVE:
|
||||
l = l ? Math.min(e.value, l) : e.value;
|
||||
break;
|
||||
case RuleName.MIN_LENGTH:
|
||||
s = Math.max(e.value, s);
|
||||
break;
|
||||
case RuleName.MAX_LENGTH:
|
||||
u = u ? Math.min(e.value, u) : e.value;
|
||||
break;
|
||||
case RuleName.REQUIRED:
|
||||
((e.value = _canonicalizedPropertyValues(e.value, r)),
|
||||
n.push(e),
|
||||
a || (i = i.concat(e.value)));
|
||||
break;
|
||||
case RuleName.ALLOWED:
|
||||
i = i.concat(e.value);
|
||||
}
|
||||
return (
|
||||
(i = _canonicalizedPropertyValues(i, a)),
|
||||
a ||
|
||||
i.length ||
|
||||
(i = [new NamedCharacterClass(Identifier.ASCII_PRINTABLE)]),
|
||||
i.length && n.push(new Rule(RuleName.ALLOWED, i)),
|
||||
null !== l && n.push(new Rule(RuleName.MAX_CONSECUTIVE, l)),
|
||||
s > 0 && n.push(new Rule(RuleName.MIN_LENGTH, s)),
|
||||
null !== u && n.push(new Rule(RuleName.MAX_LENGTH, u)),
|
||||
n
|
||||
);
|
||||
}
|
||||
console ||
|
||||
(console = {
|
||||
assert: function () {},
|
||||
error: function () {},
|
||||
warn: function () {},
|
||||
});
|
||||
const Identifier = {
|
||||
ASCII_PRINTABLE: "ascii-printable",
|
||||
DIGIT: "digit",
|
||||
LOWER: "lower",
|
||||
SPECIAL: "special",
|
||||
UNICODE: "unicode",
|
||||
UPPER: "upper",
|
||||
},
|
||||
RuleName = {
|
||||
ALLOWED: "allowed",
|
||||
MAX_CONSECUTIVE: "max-consecutive",
|
||||
REQUIRED: "required",
|
||||
MIN_LENGTH: "minlength",
|
||||
MAX_LENGTH: "maxlength",
|
||||
},
|
||||
CHARACTER_CLASS_START_SENTINEL = "[",
|
||||
CHARACTER_CLASS_END_SENTINEL = "]",
|
||||
PROPERTY_VALUE_SEPARATOR = ",",
|
||||
PROPERTY_SEPARATOR = ";",
|
||||
PROPERTY_VALUE_START_SENTINEL = ":",
|
||||
SPACE_CODE_POINT = " ".codePointAt(0),
|
||||
SHOULD_NOT_BE_REACHED = "Should not be reached";
|
||||
class Rule {
|
||||
constructor(e, r) {
|
||||
((this._name = e), (this.value = r));
|
||||
}
|
||||
get name() {
|
||||
return this._name;
|
||||
}
|
||||
toString() {
|
||||
return JSON.stringify(this);
|
||||
}
|
||||
}
|
||||
class NamedCharacterClass {
|
||||
constructor(e) {
|
||||
this._name = e;
|
||||
}
|
||||
get name() {
|
||||
return this._name.toLowerCase();
|
||||
}
|
||||
toString() {
|
||||
return this._name;
|
||||
}
|
||||
toHTMLString() {
|
||||
return this._name;
|
||||
}
|
||||
}
|
||||
class CustomCharacterClass {
|
||||
constructor(e) {
|
||||
this._characters = e;
|
||||
}
|
||||
get characters() {
|
||||
return this._characters;
|
||||
}
|
||||
toString() {
|
||||
return `[${this._characters.join("")}]`;
|
||||
}
|
||||
toHTMLString() {
|
||||
return `[${this._characters.join("").replace(/"/g, """)}]`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user