diff --git a/index.html b/index.html index ae2ad06..67c5af3 100644 --- a/index.html +++ b/index.html @@ -495,6 +495,288 @@

+
+

+ user_preferences member +

+

+ The `user_preferences` member of the [=application manifest=] is an + object that can be used to override values of manfiest members depending + on which user preferences are set. It has the following members: +

+ +

+ This list of members is expected to expand in the future to include + other user + preference media features such as contrast and + forced-colors, + as defined in CSS. +

+

+ The user agent SHOULD use the override values instead of the value of + the corresponding member defined at the top level of the manifest. +

+

+ To process the `user_preferences` member, given + [=ordered map=] |json:ordered_map|, [=ordered map=] |manifest:ordered map|, + run the following during the [=application manifest/processing + extension-point=] in [=processing a manifest=]: +

+
    +
  1. If |json|["user_preferences"] does not [=map/exist=], return. +
  2. +
  3. If the type of |json|["user_preferences"] is not [=ordered map=], + return. +
  4. +
  5. Set |manifest|["user_preferences"] to a new [=ordered map=]. +
  6. +
  7. [=Process the `color_scheme` member=] passing + |json|["user_preferences"] and |manifest|["user_preferences"]. +
  8. +
+
+

+ color_scheme + member +

+

+ The [=user_preferences=] `color_scheme` member is an object that + contains the overrides for color scheme preferences. It has the + following members: +

+

+ The dark member + specifies the manifest overrides to use when the user prefers a + dark theme. +

+

+ The light member + specifies the manifest overrides to use when the user prefers a + light theme. +

+

+ To process the `color_scheme` member, given [=ordered map=] + |json_user_preferences:ordered_map|, [=ordered map=] + |manifest_user_preferences:ordered map|, run the following: +

+
    +
  1. If |json_user_preferences|["color_scheme"] does not [=map/exist=], + return. +
  2. +
  3. If the type of |json_user_preferences|["color_scheme"] is not + [=ordered map=], return. +
  4. +
  5. Set |manifest_user_preferences|["color_scheme"] to a new + [=ordered map=]. +
  6. +
  7. [=list/For each=] |member:string| of [=list=] « "dark", "light" »: +
      +
    1. Let |overrides:ordered map| be the result of processing a + manifest override object. +
    2. +
    3. Set |manifest_user_preferences|["color_scheme"][|member:string|] + to |overrides|. +
    4. +
    +
  8. +
+
+
+

+ Overridable properties +

+

+ The proterties that [=user_preferences=] can override in the + [=manifest override object=] are: +

+ +
+
+
+

+ Manifest override objects +

+

+ Each manifest override object is a generic object value + that allows for certain manifest properties to be overridden within + a particular context. +

+

The structure of a [=manifest override object=] is as follows:

+
+        {
+          "context_key": {
+            "property": "new value"
+          }
+        }
+      
+

+ Each manifest property that accepts a [=manifest override object=] + as its value will define the contexts it supports and which + properties it supports overriding. User agents MUST ignore any contexts + that are not supported by the property as well as any override + properties not explicitly allowed within it. +

+

+ When the manifest property’s context is applicable, the value of each + allowable override will be used in place of the original value defined + in the Manifest. +

+

+ Redefined array items will be overridden in the order they are authored. + When redefining objects (e.g., [=manifest/shortcuts=], [=manifest/icons=]), + authors will only be able to redefine specific properties of that object. + In order to ensure all overrides are applied correctly, the order must + match the original array (i.e., each [=manifest/shortcut=] must be redefined + in order, as must their icons, if they also require re-definition). +

+ Redefined array items must also be equal in number to the array being + overridden. If there is a mismatch in the number of items in either array, + any excess items will be ignored. This is only an issue if the original + array has more items than the override array, because any excess items + within the original array will not be re-defined. +

+

+ When there is a conflict because two different properties are attempting + to override the same value in their respective active contexts, the one + defined last will win. By way of example, consider the following: +

+
+        {
+          "lang": "en-US",
+          "icons": [
+            {
+              "src": "icon.png",
+              "sizes": "128x128",
+              "type": "image/png"
+            }
+          ],
+          "translations": {
+            "es": {
+              "icons": [
+                {
+                  "src": "icon-es.png"
+                }
+              ]
+            }
+          },
+          "user_preferences": {
+            "color_scheme": {
+              "dark": {
+                "icons": [
+                  {
+                    "src": "icon-dark.png"
+                  }
+                ]
+              }
+            }
+          }
+        }
+      
+

+ In this example, if the user’s primary language is Español, but + their preferred color scheme was set to "dark", the icon supplied + would be the dark version and not the localized one. For this reason, + it is imperative that properties taking a [=manifest override object=] + as their value consider whether any other properties that also enable + overrides should be able to be redefined within them. In the above + example, the author’s intent would likely have been better realized + if `user_preferences` was put before `translations` and the localized + context block redefined the `user_preferences` value for that language: +

+
+        {
+          "lang": "en-US",
+          "icons": [
+            {
+              "src": "icon.png",
+              "sizes": "128x128",
+              "type": "image/png"
+            }
+          ],
+          "user_preferences": {
+            "color_scheme": {
+              "dark": {
+                "icons": [
+                  {
+                    "src": "icon-dark.png"
+                  }
+                ]
+              }
+            }
+          },
+          "translations": {
+            "es": {
+              "icons": [
+                {
+                  "src": "icon-es.png"
+                }
+              ],
+              "user_preferences": {
+                "color_scheme": {
+                  "dark": {
+                    "icons": [
+                      {
+                        "src": "icon-es-dark.png"
+                      }
+                    ]
+                  }
+                }
+              }
+            }
+          },
+          
+        }
+      
+

+ User agents MAY ignore any override properties they do not support. +

+

+ To apply a manifest override object, given [=ordered_map=] + |overrides:json|, [=ordered map=] + |manifest:ordered map|, and [=array=] |allowed_properties:array| run the following: +

+
    +
  1. Let |allowed_overrides| be a new [=ordered map=]. +
  2. +
  3. [=list/For each=] |member:string| of |overrides|: +
      +
    1. If |member| is not in |allowed_properties|, continue. +
    2. +
    3. Set |allowed_overrides|[|member|] to |overrides[|member|]|. +
    4. +
    +
  4. +
  5. Let |overriden_manifest| be the result of creating a new [=ordered map=] + by merging |manifest| with |allowed_overrides|. +
  6. +
  7. + Set |manifest| to |overriden_manifest|. +
  8. +
+

Installation prompts